PluginProbe
WPPizza – A Restaurant Plugin / 3.20
WPPizza – A Restaurant Plugin v3.20
trunk 2.16.11.28 3.19 3.19.1 3.19.2 3.19.3 3.19.4 3.19.5 3.19.6 3.19.7 3.19.7.1 3.19.7.2 3.19.7.3 3.19.7.4 3.19.8 3.19.8.1 3.19.8.2 3.19.8.3 3.19.9 3.20 3.20.1
wppizza / classes / modules / mod.openingtimes.closed.php

mod.openingtimes.closed.php in WPPizza – A Restaurant Plugin 3.20, at classes/modules/mod.openingtimes.closed.php

238 lines 10.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPPIZZA_MODULE_OPENINGTIMES_CLOSED Class
4 *
5 * @package WPPIZZA
6 * @subpackage WPPIZZA_MODULE_OPENINGTIMES_CLOSED
7 * @copyright Copyright (c) 2015, Oliver Bach
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 3.0
10 *
11 */
12 if ( ! defined( 'ABSPATH' ) ) exit;/*Exit if accessed directly*/
13
14
15 /************************************************************************************************************************
16 *
17 *
18 *
19 *
20 *
21 *
22 ************************************************************************************************************************/
23 class WPPIZZA_MODULE_OPENINGTIMES_CLOSED{
24
25 private $settings_page = 'openingtimes';/* which admin subpage (identified there by this->class_key) are we adding this to */
26 private $section_key = 'closed';/* must be unique */
27
28
29 function __construct() {
30 /**********************************************************
31 [add settings to admin]
32 ***********************************************************/
33 if(is_admin()){
34 /* add admin options settings page*/
35 add_filter('wppizza_filter_settings_sections_'.$this->settings_page.'', array($this, 'admin_options_settings'), 40, 5);
36 /* add admin options settings page fields */
37 add_action('wppizza_admin_settings_section_fields_'.$this->settings_page.'', array($this, 'admin_options_fields_settings'), 10, 5);
38 /**add default options **/
39 add_filter('wppizza_filter_setup_default_options', array( $this, 'options_default'));
40 /**validate options**/
41 add_filter('wppizza_filter_options_validate', array( $this, 'options_validate'), 10, 2 );
42 /** admin ajax **/
43 add_action('wppizza_ajax_admin_'.$this->settings_page.'', array( $this, 'admin_ajax'));
44 }
45 /**********************************************************
46 [filter/actions depending on settings]
47 ***********************************************************/
48
49 }
50
51 /*******************************************************************************************************************************************************
52 *
53 *
54 *
55 * [frontend filters]
56 *
57 *
58 *
59 ********************************************************************************************************************************************************/
60
61
62 /*******************************************************************************************************************************************************
63 *
64 *
65 *
66 * [add admin page options]
67 *
68 *
69 *
70 ********************************************************************************************************************************************************/
71 /*******************************************************************************************************************************************************
72 *
73 * [admin ajax]
74 *
75 ********************************************************************************************************************************************************/
76 function admin_ajax($wppizza_options){
77
78 //need right caps for access
79 if( ! current_user_can('wppizza_cap_'.$this->settings_page.'')){
80 echo '<div class="wppizza-highlight">'.__('Access Denied', 'wppizza-admin').' ['.$this->section_key.']</div>';
81 exit();
82 }
83
84 /*****************************************************
85 [adding new custom closing time]
86 *****************************************************/
87 if($_POST['vars']['field']=='times_closed_standard'){
88 $markup=$this->wppizza_admin_section_times_closed_standard($_POST['vars']['field']);
89 print $markup ;
90 exit();
91 }
92 }
93 /*------------------------------------------------------------------------------
94 #
95 #
96 # [settings page]
97 #
98 #
99 ------------------------------------------------------------------------------*/
100
101 /*------------------------------------------------------------------------------
102 # [settings section - setting page]
103 # @since 3.0
104 # @return array()
105 ------------------------------------------------------------------------------*/
106 function admin_options_settings($settings, $sections, $fields, $inputs, $help){
107
108 /*section*/
109 if($sections){
110 $settings['sections'][$this->section_key] = __('Closed', 'wppizza-admin');
111 }
112
113 /*help*/
114 if($help){
115 $settings['help'][$this->section_key][] = array(
116 'label'=>__('Manage Times Closed', 'wppizza-admin'),
117 'description'=>array(
118 __('If you are closed on certain days for a number of hours, enter them here.', 'wppizza-admin'),
119 __('E.g: if you are generally open on Tuesdays - as set above - from 9:30 to 23:00, but close for lunch between 12:00 and 14:00, enter Tuesdays 12:00 - 14:00 here. If you are also closed on Tuesday between 17:30 and 18:00, set this as well and so on.', 'wppizza-admin'),
120 __('Furthermore, do not enter times here that span midnight. If you are however closed from - let\'s say - 11:00 PM Mondays to 1:00 AM Tuesdays, enter "Mondays 23:00 to 23:59" as well as "Tuesdays 0:00 to 1:00".', 'wppizza-admin'),
121 __('If you have setup any custom dates above (for example christmas or whatever), select "Custom Dates" instead of the day of week if you want to apply these closing times only to those dates.', 'wppizza-admin'),
122 '<span class="wppizza-highlight">'.__('Note: if you set anything here, it will not be reflected when displaying openingtimes via shortcode or in the widget, so you might want to display your openingtimes manually somewhere. It DOES, however close the shoppingcart, the ability to order etc as required)', 'wppizza-admin').'</span>'
123 )
124 );
125 }
126
127 /*fields*/
128 if($fields){
129 $field = 'times_closed_standard';
130 $settings['fields'][$this->section_key][$field] = array( '', array(
131 'value_key'=>$field,
132 'option_key'=>$this->settings_page,
133 'label'=>'',
134 'description'=>array()
135 ));
136 }
137
138 return $settings;
139 }
140 /*------------------------------------------------------------------------------
141 # [output option fields - setting page]
142 # @since 3.0
143 # @return array()
144 ------------------------------------------------------------------------------*/
145 function admin_options_fields_settings($wppizza_options, $options_key, $field, $label, $description){
146
147 if($field=='times_closed_standard'){
148
149 echo"<div id='wppizza_".$field."_options' class='wppizza_admin_options'>";
150 if(isset($wppizza_options[$this->settings_page][$field])){
151 /* sort by date */
152 asort($wppizza_options[$this->settings_page][$field]);
153 foreach($wppizza_options[$this->settings_page][$field] as $k=>$values){
154 echo"".$this->wppizza_admin_section_times_closed_standard($field, $values);
155 }}
156 echo"</div>";
157
158 /** add new button **/
159 echo"<div id='wppizza-".$field."-add' class='wppizza_admin_add'>";
160 echo "<a href='javascript:void(0)' id='wppizza_add_".$field."' class='button'>".__('add', 'wppizza-admin')."</a>";
161 echo"</div>";
162 }
163 }
164 /*------------------------------------------------------------------------------
165 # [insert default option on install]
166 # $parameter $options array() | filter passing on filtered options
167 # @since 3.0
168 # @return array()
169 ------------------------------------------------------------------------------*/
170 function options_default($options){
171
172 $options[$this->settings_page]['times_closed_standard']=array();
173
174 return $options;
175 }
176
177 /*------------------------------------------------------------------------------
178 # [validate options on save/update]
179 #
180 # @since 3.0
181 # @return array()
182 ------------------------------------------------------------------------------*/
183 function options_validate($options, $input){
184 /**make sure we get the full array on install/update**/
185 if ( empty( $_POST['_wp_http_referer'] ) ) {
186 return $input;
187 }
188
189 if(isset($_POST[''.WPPIZZA_SLUG.'_'.$this->settings_page.''])){
190
191 $options[$this->settings_page]['times_closed_standard'] = array();//initialize array
192 if(isset($input[$this->settings_page]['times_closed_standard']['day'])){
193 foreach($input[$this->settings_page]['times_closed_standard']['day'] as $key=>$day){
194 $options[$this->settings_page]['times_closed_standard'][$key]['day']=(int)$day;
195 $options[$this->settings_page]['times_closed_standard'][$key]['close_start']=wppizza_validate_24hourtime($input[$this->settings_page]['times_closed_standard']['close_start'][$key],'Y-m-d');
196 $options[$this->settings_page]['times_closed_standard'][$key]['close_end']=wppizza_validate_24hourtime($input[$this->settings_page]['times_closed_standard']['close_end'][$key],'Y-m-d');
197 }}
198 }
199 return $options;
200 }
201
202 /*********************************************************
203 [helper - opening times custom also used when adding via ajax]
204 *********************************************************/
205 function wppizza_admin_section_times_closed_standard($field, $values = false){
206
207 $str='';
208 $str.="<div class='wppizza_option'>";
209
210 $str.="<select name='".WPPIZZA_SLUG."[".$this->settings_page."][".$field."][day][]'>";
211 if(isset($values['day']) && $values['day'] =='-1'){$sel=" selected='selected'";}else{$sel="";}
212 $str.="<option value='-1'".$sel.">--".__('Custom Dates Above (if any)', 'wppizza-admin')."--</option>";
213 foreach(wppizza_days() as $k=>$v){
214 if(isset($values['day']) && $values['day'] == $k){$sel=" selected='selected'";}else{$sel="";}
215 $str.="<option value='".$k."'".$sel.">".$v."</option>";
216 }
217 $str.="</select>";
218
219 $str.="".__('closed from', 'wppizza-admin').":";
220
221 $str.="<input name='".WPPIZZA_SLUG."[".$this->settings_page."][".$field."][close_start][]' size='3' type='text' autocomplete='off' class='wppizza-time-select' value='".(empty($values['close_start']) ? '12:00' : $values['close_start'] )."' />";
222 $str.="".__('to', 'wppizza-admin').":";
223
224 $str.="<input name='".WPPIZZA_SLUG."[".$this->settings_page."][".$field."][close_end][]' size='3' type='text' autocomplete='off' class='wppizza-time-select' value='".(empty($values['close_end']) ? '13:00' : $values['close_end'] )."' />";
225 $str.="<a href='javascript:void(0);' class='wppizza-delete ".$field." ".WPPIZZA_SLUG."-dashicons dashicons-trash' title='".__('delete', 'wppizza-admin')."'></a>";
226
227 $str.="</div>";
228
229 return $str;
230 }
231 }
232 /***************************************************************
233 *
234 * [ini]
235 *
236 ***************************************************************/
237 $WPPIZZA_MODULE_OPENINGTIMES_CLOSED = new WPPIZZA_MODULE_OPENINGTIMES_CLOSED();
238 ?>