WordPress.org

Plugin Directory

Changeset 517192


Ignore:
Timestamp:
03/10/12 11:41:59 (2 years ago)
Author:
MZAWeb
Message:
  • Added the shortcodes
  • Added localization and english lang file
  • Added text-align=center; to: .business_hours_table_closed, .business_hours_table_heading, .business_hours_table_open and .business_hours_table_close
  • Fix: Spelling collapsable for collapsible.
Location:
business-hours-plugin/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • business-hours-plugin/trunk/README.txt

    r475697 r517192  
    3333This plugins uses the timezone configured in WordPress settings. ( Settings->General ) 
    3434 
     352. Shortcodes what?? 
     36 
     37The shortcode you need to use is this: [businesshours closed="TEXT FOR WHEN ITS CLOSED"]TEMPLATE[/businesshours] 
     38 
     39In the template you should use {{TodayOpen}} for today's open hours and {{TodayClose}} for closing hours. 
     40 
     41For example: 
     42 
     43[businesshours closed="Today is closed."]Today we work from {{TodayOpen}} to {{TodayClose}}[/businesshours] 
     44 
     45Also there's another shortcode that allows you to show the full week table: 
     46 
     47[businesshoursweek] 
     48 
     49You can also use 
     50 
     51[businesshoursweek collapsible="true"] 
     52 
     53to have the list collapsed by default and a link to open it. 
     54 
    3555 
    3656== Screenshots == 
     
    4262 
    4363== Changelog == 
     64 
     65= 1.3 = 
     66* Added the shortcodes 
     67* Added localization and english lang file 
     68* Added text-align=center; to: .business_hours_table_closed, .business_hours_table_heading, .business_hours_table_open and .business_hours_table_close 
     69* Fix: Spelling collapsable for collapsible. 
    4470 
    4571= 1.2 = 
  • business-hours-plugin/trunk/script.js

    r475697 r517192  
    11jQuery(document).ready(function($) { 
    22 
    3     $(".business_hours_collapsable_handler").click(function() { 
    4         $(".business_hours_collapsable").slideToggle(); 
     3    $(".business_hours_collapsible_handler").click(function() { 
     4        $(".business_hours_collapsible").slideToggle(); 
    55        return false; 
    66    }); 
  • business-hours-plugin/trunk/style.css

    r475697 r517192  
    1 .business_hours_collapsable{ 
     1.business_hours_collapsible{ 
    22    display: none; 
    33} 
     4.business_hours_table_closed{ 
     5    text-align: center; 
     6} 
     7 
     8.business_hours_table_heading{ 
     9    text-align: center; 
     10} 
     11 
     12.business_hours_table_open{ 
     13    text-align: center; 
     14} 
     15.business_hours_table_close{ 
     16    text-align: center; 
     17} 
  • business-hours-plugin/trunk/widget.php

    r475697 r517192  
    3333        } 
    3434 
    35         public function get_day_using_timezone(){ 
    36            $offset = get_option('gmt_offset'); 
    37            $offset = $offset*60*60; 
    38            $timestamp = time() + $offset; 
    39            return gmdate('l',$timestamp); 
    40         } 
    4135 
    4236        function widget( $args, $instance ) { 
     
    4842 
    4943 
    50             $day = strtolower( $this->get_day_using_timezone() ); 
     44            $day = strtolower( $workinghours->get_day_using_timezone() ); 
    5145            $open = $workinghours->settings->get_setting($day,"open"); 
    5246            $close = $workinghours->settings->get_setting($day,"close"); 
     
    7367            if ($instance['allweek'] == "1"){ 
    7468                 
    75                 echo '<a class="business_hours_collapsable_handler" href="#">[Show all days]</a>'; 
    76                 echo '<div class="business_hours_collapsable">'; 
    77  
    78                 $timestamp = strtotime('next Sunday'); 
    79                 $days = array(); 
    80                 for ($i = 0; $i < 7; $i++) { 
    81                     $days[] = strftime('%A', $timestamp); 
    82                     $timestamp = strtotime('+1 day', $timestamp); 
    83                 } 
    84  
    85                 echo "<table width='100%'>"; 
    86                 echo "<tr><th>Day</th><th>Open</th><th>Close</th></tr>"; 
    87                 foreach ($days as $day){ 
    88                     $day = strtolower($day); 
    89                     $open = $workinghours->settings->get_setting($day,"open"); 
    90                     $close = $workinghours->settings->get_setting($day,"close"); 
    91                     $working = $workinghours->settings->get_setting($day,"working"); 
    92  
    93                     echo "<tr>"; 
    94                     echo "<td class='business_hours_table_day'>". ucwords($day) ."</td>"; 
    95                     if ($working == "true"){ 
    96                         echo "<td class='business_hours_table_open'>". ucwords($open) ."</td>"; 
    97                         echo "<td class='business_hours_table_close'>". ucwords($close) ."</td>"; 
    98                     }else{ 
    99                         echo "<td class='business_hours_table_closed' colspan='2' align='center'>Closed</td>"; 
    100                     } 
    101  
    102  
    103                     echo "</tr>"; 
    104                 } 
    105                 echo "</table>"; 
    106                 echo '</div>'; 
     69                $workinghours->show_table(); 
    10770 
    10871            } 
     
    12992            $defaults = array( 
    13093                'title' => "Business Hours", 
    131                 'template_today' => "<div class='working_hours_title'>Business hours on {{Day}}:</div>", 
     94                'template_today' => "<div class='working_hours_title'>" . __("Business hours on", "business-hours" ) . " {{Day}}</div>", 
    13295                'template_hours' => "<span class='working_hours_open'>{{Open}}</span> - <span class='working_hours_close'>{{Close}}</span>", 
    133                 'template_closed' => "<div class='working_hours_closed'>Closed</div>", 
     96                'template_closed' => "<div class='working_hours_closed'>" . __("Closed", "business-hours" ) . "</div>", 
    13497                'allweek' => 0 
    13598            ); 
     
    141104            </p> 
    142105            <p> 
    143                 <label for="<?php echo $this->get_field_id( 'title' ); ?>">Title:</label><br/> 
     106                <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e("Title", "business-hours" );?>:</label><br/> 
    144107                <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance["title"]; ?>" type="text" /> 
    145108            </p> 
    146109 
    147110            <p> 
    148                 <label for="<?php echo $this->get_field_id( 'template_today' ); ?>">Template for heading:</label><br/> 
     111                <label for="<?php echo $this->get_field_id( 'template_today' ); ?>"><?php _e("Template for heading", "business-hours" );?>:</label><br/> 
    149112                <textarea class="widefat" id="<?php echo $this->get_field_id( 'template_today' ); ?>" name="<?php echo $this->get_field_name( 'template_today' ); ?>" type="text" rows="6" ><?php echo esc_textarea($instance["template_today"]); ?></textarea> 
    150113                <small>The tag {{Day}} will be replaced with the weekday name.</small> 
    151114            </p> 
    152115            <p> 
    153                 <label for="<?php echo $this->get_field_id( 'template_hours' ); ?>">Template for working hours:</label><br/> 
     116                <label for="<?php echo $this->get_field_id( 'template_hours' ); ?>"><?php _e("Template for working hours", "business-hours" );?>:</label><br/> 
    154117                <textarea class="widefat" id="<?php echo $this->get_field_id( 'template_hours' ); ?>" name="<?php echo $this->get_field_name( 'template_hours' ); ?>" type="text" rows="6" ><?php echo esc_textarea($instance["template_hours"]); ?></textarea> 
    155                 <small>The tags {{Open}} and {{Close}} will be replaced with the correct value.</small> 
     118                <small><?php _e("The tags {{Open}} and {{Close}} will be replaced with the correct value.", "business-hours" );?></small> 
    156119            </p> 
    157120            <p> 
    158                 <label for="<?php echo $this->get_field_id( 'template_closed' ); ?>">Template for "closed" text:</label><br/> 
     121                <label for="<?php echo $this->get_field_id( 'template_closed' ); ?>"><?php _e("Template for \"closed\" text", "business-hours" );?> :</label><br/> 
    159122                <textarea class="widefat" id="<?php echo $this->get_field_id( 'template_closed' ); ?>" name="<?php echo $this->get_field_name( 'template_closed' ); ?>" type="text" rows="6" ><?php echo esc_textarea($instance["template_closed"]); ?></textarea> 
    160123            </p> 
    161124 
    162125             <p> 
    163                 <label for="<?php echo $this->get_field_id( 'allweek' ); ?>">Show also a collapsable list with the business hours for each weekday: </label> 
     126                <label for="<?php echo $this->get_field_id( 'allweek' ); ?>"><?php _e("Show also a collapsible list with the business hours for each weekday:", "business-hours" );?> </label> 
    164127                <input type="checkbox" id="<?php echo $this->get_field_id( 'allweek' ); ?>" value="1" <?php checked($instance["allweek"] == "1");  ?> name="<?php echo $this->get_field_name( 'allweek' ); ?>"/> 
    165128             </p> 
  • business-hours-plugin/trunk/working-hours.class.php

    r475697 r517192  
    11<?php 
    2 class WorkingHours{ 
     2class WorkingHours { 
    33 
    4     public $settings; 
     4    public $settings; 
    55 
    6     public function  __construct(){ 
    7         $this->register_settings(); 
    8     } 
     6    public function  __construct() { 
     7        $this->register_settings(); 
     8        add_shortcode( 'businesshours', array( $this, 'shortcode' ) ); 
     9        add_shortcode( 'businesshoursweek', array( $this, 'shortcode_table' ) ); 
     10    } 
    911 
    10     private function register_settings(){ 
     12    public function shortcode( $atts, $content = null ) { 
     13        extract( shortcode_atts( array( 'closed'      => 'Closed' ), $atts ) ); 
     14        if ( $content ) { 
    1115 
    12         $timestamp = strtotime('next Sunday'); 
    13         $days = array(); 
    14         for ($i = 0; $i < 7; $i++) { 
    15             $days[] = strftime('%A', $timestamp); 
    16             $timestamp = strtotime('+1 day', $timestamp); 
    17         } 
    18         $sections = array(); 
     16            $day     = strtolower( $this->get_day_using_timezone() ); 
     17            $open    = $this->settings->get_setting( $day, "open" ); 
     18            $close   = $this->settings->get_setting( $day, "close" ); 
     19            $working = $this->settings->get_setting( $day, "working" ); 
    1920 
    20         foreach ($days as $day){ 
    21          
    22             $sections[strtolower($day)] = array( 
    23                     "title" => __($day,"Working Hours"), 
    24                     "fields" => array( 
    25                         "working" => array( 
    26                             "title" => __("Is it open on " . $day . "s?", "Working Hours"), 
    27                             "type" => "checkbox", 
    28                             "options" => array( 
    29                                 "true" => "" 
    30                             ) 
    31                         ), 
    32                         "open" => array( 
    33                             "title" => __("Open:","Working Hours"), 
    34                             "type" => "time", 
    35                             "description" => "HH:MM" 
     21            if ( $working == "true" ) { 
     22                $content = str_replace( "{{TodayOpen}}", $open, $content ); 
     23                $content = str_replace( "{{TodayClose}}", $close, $content ); 
     24            } else { 
     25                $content = $closed; 
     26            } 
     27        } 
     28        return $content; 
     29    } 
    3630 
    37                         ), 
    38                         "close" => array( 
    39                             "title" => __("Close:","Working Hours"), 
    40                             "type" => "time", 
    41                             "description" => "HH:MM" 
     31    public function shortcode_table( $atts ) { 
    4232 
    43                         ) 
    44                     ) 
    45             ); 
     33        extract( shortcode_atts( array( 'collapsible' => 'false', ), $atts ) ); 
    4634 
    47         } 
     35        if ( strtolower( $collapsible ) == "true" ) { 
     36            $collapsible = true; 
     37        } 
     38        if ( strtolower( $collapsible ) == "false" ) { 
     39            $collapsible = false; 
     40        } 
    4841 
    49         $sections["support"] = array( 
    50            "title" => __("Support","Working Hours"), 
    51                "fields" => array( 
    52                    "mzaweb" => array( 
    53                        "title" => "Bugs? Questions? Suggestions?", 
    54                        "type" => "support", 
    55                        "email" => "support@mzaweb.com" 
    56                    ) 
    57                ) 
    58         ); 
     42        if ( $collapsible ) { 
     43            wp_register_style( 'BusinessHoursStyle', plugins_url( 'style.css', __FILE__ ) ); 
     44            wp_enqueue_style( 'BusinessHoursStyle' ); 
    5945 
    60         $this->settings = new MZASettings("working-hours", 'options-general.php', $sections); 
    61         $this->settings->settingsPageTitle = __("Business Hours Settings", "Working Hours"); 
    62         $this->settings->settingsLinkTitle = __("Business Hours", "Working Hours"); 
     46            wp_register_script('BusinessHoursScript', plugins_url('script.js', __FILE__), array('jquery')); 
     47            wp_enqueue_script('BusinessHoursScript'); 
     48        } 
     49        return $this->get_table( $collapsible ); 
     50    } 
    6351 
    64         $this->settings->customJS .= "jQuery('#working-hours_settings_form input:checkbox').each(function() { 
     52 
     53    public function get_day_using_timezone() { 
     54        $offset    = get_option( 'gmt_offset' ); 
     55        $offset    = $offset * 60 * 60; 
     56        $timestamp = time() + $offset; 
     57        return gmdate( 'l', $timestamp ); 
     58    } 
     59 
     60    public function show_table( $collapsible_link = true ) { 
     61        echo $this->get_table( $collapsible_link ); 
     62    } 
     63 
     64    public function get_table( $collapsible_link = true ) { 
     65 
     66        global $workinghours; 
     67 
     68        $ret = ""; 
     69 
     70        if ( $collapsible_link ) { 
     71            $ret .= '<a class="business_hours_collapsible_handler" href="#">' . __("[Show all days]", "business-hours") . '</a>'; 
     72            $ret .= '<div class="business_hours_collapsible">'; 
     73        } 
     74 
     75 
     76        $timestamp = strtotime( 'next Sunday' ); 
     77        $days      = array(); 
     78        for ( $i = 0; $i < 7; $i++ ) { 
     79            $days[]    = strftime( '%A', $timestamp ); 
     80            $timestamp = strtotime( '+1 day', $timestamp ); 
     81        } 
     82 
     83        $ret .= "<table width='100%'>"; 
     84        $ret .= "<tr><th>" . __( "Day", "business-hours" ) . "</th><th  class='business_hours_table_heading'>" . __( "Open", "business-hours" ) . "</th><th  class='business_hours_table_heading'>" . __( "Close", "business-hours" ) . "</th></tr>"; 
     85        foreach ( $days as $day ) { 
     86            $day     = strtolower( $day ); 
     87            $open    = $workinghours->settings->get_setting( $day, "open" ); 
     88            $close   = $workinghours->settings->get_setting( $day, "close" ); 
     89            $working = $workinghours->settings->get_setting( $day, "working" ); 
     90 
     91            $ret .= "<tr>"; 
     92            $ret .= "<td class='business_hours_table_day'>" . ucwords( $day ) . "</td>"; 
     93            if ( $working == "true" ) { 
     94                $ret .= "<td class='business_hours_table_open'>" . ucwords( $open ) . "</td>"; 
     95                $ret .= "<td class='business_hours_table_close'>" . ucwords( $close ) . "</td>"; 
     96            } else { 
     97                $ret .= "<td class='business_hours_table_closed' colspan='2' align='center'>" . __("Closed", "business-hours" ) ."</td>"; 
     98            } 
     99 
     100 
     101            $ret .= "</tr>"; 
     102        } 
     103        $ret .= "</table>"; 
     104        if ( $collapsible_link ) { 
     105            $ret .= '</div>'; 
     106        } 
     107 
     108        return $ret; 
     109    } 
     110 
     111 
     112    private function register_settings() { 
     113 
     114        $timestamp = strtotime( 'next Sunday' ); 
     115        $days      = array(); 
     116        for ( $i = 0; $i < 7; $i++ ) { 
     117            $days[]    = strftime( '%A', $timestamp ); 
     118            $timestamp = strtotime( '+1 day', $timestamp ); 
     119        } 
     120        $sections = array(); 
     121 
     122        foreach ( $days as $day ) { 
     123 
     124            $sections[strtolower( $day )] = array( "title"  => __( $day, "business-hours" ), 
     125                                                   "fields" => array( "working" => array( "title"   => __( "Is it open on " . __($day, "business-hours" ) . "?", "business-hours" ), 
     126                                                                                          "type"    => "checkbox", 
     127                                                                                          "options" => array( "true" => "" ) ), 
     128                                                                      "open"    => array( "title"      => __( "Open", "business-hours" ) . ":", 
     129                                                                                          "type"        => "time", 
     130                                                                                          "description" => "HH:MM" 
     131 
     132                                                                      ), 
     133                                                                      "close"   => array( "title"      => __( "Close", "business-hours" ) . ":", 
     134                                                                                          "type"        => "time", 
     135                                                                                          "description" => "HH:MM" 
     136 
     137                                                                      ) ) ); 
     138 
     139        } 
     140 
     141        $sections["support"] = array( "title"  => __( "Support", "business-hours" ), 
     142                                      "fields" => array( "mzaweb" => array( "title" => __("Bugs? Questions? Suggestions?", "business-hours" ), 
     143                                                                            "type"  => "support", 
     144                                                                            "email" => "support@mzaweb.com" ) ) ); 
     145 
     146        $this->settings                    = new MZASettings( "working-hours", 'options-general.php', $sections ); 
     147        $this->settings->settingsPageTitle = __( "Business Hours Settings", "business-hours" ); 
     148        $this->settings->settingsLinkTitle = __( "Business Hours", "business-hours" ); 
     149 
     150        $this->settings->customJS .= "jQuery('#working-hours_settings_form input:checkbox').each(function() { 
    65151            index = jQuery(this).index('#working-hours_settings_form input:checkbox') * 2; 
    66152 
     
    75161        });"; 
    76162 
    77         $this->settings->customJS .= "jQuery('#working-hours_settings_form input:checkbox').change(function() { 
     163        $this->settings->customJS .= "jQuery('#working-hours_settings_form input:checkbox').change(function() { 
    78164            index = jQuery(this).index('#working-hours_settings_form input:checkbox') * 2; 
    79165 
     
    89175 
    90176 
    91     } 
     177    } 
    92178 
    93179} 
     180 
    94181?> 
  • business-hours-plugin/trunk/working-hours.php

    r475697 r517192  
    66Author: MZAWeb 
    77Author URI: http://mzaweb.com/en 
    8 Version: 1.2 
     8Version: 1.3 
    99*/ 
    1010 
     
    2222/* START */ 
    2323 
     24function bussiness_hours_init() { 
     25    load_plugin_textdomain( 'business-hours', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); 
     26} 
     27add_action('init', 'bussiness_hours_init'); 
     28 
    2429global $workinghours; 
    2530$workinghours = new WorkingHours(); 
Note: See TracChangeset for help on using the changeset viewer.