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.custom.php

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

274 lines 11.0 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_CUSTOM Class
4 *
5 * @package WPPIZZA
6 * @subpackage WPPIZZA_MODULE_OPENINGTIMES_CUSTOM
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_CUSTOM{
24
25 private $settings_page = 'openingtimes';/* which admin subpage (identified there by this->class_key) are we adding this to */
26 private $section_key = 'custom';/* 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'), 30, 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 opening time]
86 *****************************************************/
87 if($_POST['vars']['field']=='opening_times_custom'){
88
89 /**get next highest key available**/
90 $nextKey=0;
91 if(isset($_POST['vars']['setKeys']) && is_array($_POST['vars']['setKeys'])){
92 $currentKeys=array();
93 foreach($_POST['vars']['setKeys'] as $key_exists){
94 $currentKeys[$key_exists['value']]=$key_exists['value'];
95 }
96 $highestKey=max($currentKeys);
97 $nextKey=$highestKey+1;
98 }
99
100 $markup=$this->wppizza_admin_section_opening_times_custom($_POST['vars']['field'], false, $nextKey);
101 print $markup ;
102 exit();
103 }
104 }
105 /*------------------------------------------------------------------------------
106 #
107 #
108 # [settings page]
109 #
110 #
111 ------------------------------------------------------------------------------*/
112
113 /*------------------------------------------------------------------------------
114 # [settings section - setting page]
115 # @since 3.0
116 # @return array()
117 ------------------------------------------------------------------------------*/
118 function admin_options_settings($settings, $sections, $fields, $inputs, $help){
119
120 /*section*/
121 if($sections){
122 $settings['sections'][$this->section_key] = __('Custom Opening Times', 'wppizza-admin');
123 }
124
125 /*help*/
126 if($help){
127 $settings['help'][$this->section_key][] = array(
128 'label'=>__('Manage Custom Opening Times', 'wppizza-admin'),
129 'description'=>array(
130 __('Set any dates / days here where opening times differ from the standard times (such as christmas, holidays etc).', 'wppizza-admin'),
131 '<b>'.__('USE 24 HOUR CLOCK.', 'wppizza-admin').'</b>',
132 __('If you are closed on a given day set both times to be the same, if you are open 24 hours set times from 0:00 to 24:00', 'wppizza-admin'),
133 '<span class="wppizza-highlight">'.__('Ensure that the Wordpress timezone setting in Settings->Timezone is correct', 'wppizza-admin').'</span>'
134 )
135 );
136 }
137
138 /*fields*/
139 if($fields){
140 $field = 'opening_times_custom';
141 $settings['fields'][$this->section_key][$field] = array( '', array(
142 'value_key'=>$field,
143 'option_key'=>$this->settings_page,
144 'label'=>'',
145 'description'=>array()
146 ));
147 }
148
149 return $settings;
150 }
151 /*------------------------------------------------------------------------------
152 # [output option fields - setting page]
153 # @since 3.0
154 # @return array()
155 ------------------------------------------------------------------------------*/
156 function admin_options_fields_settings($wppizza_options, $options_key, $field, $label, $description){
157
158 if($field=='opening_times_custom'){
159
160 echo"<div id='wppizza_".$field."_options' class='wppizza_admin_options'>";
161 if(isset($wppizza_options[$this->settings_page][$field])){
162 /* sort by date */
163 asort($wppizza_options[$this->settings_page][$field]);
164 foreach($wppizza_options[$this->settings_page][$field] as $k=>$values){
165 echo"".$this->wppizza_admin_section_opening_times_custom($field, $values, $k);
166 }}
167 echo"</div>";
168
169 /** add new button **/
170 echo"<div id='wppizza-".$field."-add' class='wppizza_admin_add'>";
171 echo "<a href='javascript:void(0)' id='wppizza_add_".$field."' class='button'>".__('add', 'wppizza-admin')."</a>";
172 echo"</div>";
173 }
174 }
175 /*------------------------------------------------------------------------------
176 # [insert default option on install]
177 # $parameter $options array() | filter passing on filtered options
178 # @since 3.0
179 # @return array()
180 ------------------------------------------------------------------------------*/
181 function options_default($options){
182 $options[$this->settings_page]['opening_times_custom'][]=array(
183 'date'=>''.(date("Y")+1).'-01-01',
184 'open'=>'17:00',
185 'close'=>'01:00'
186 );
187 $options[$this->settings_page]['opening_times_custom'][]=array(
188 'date'=>''.date("Y").'-12-25',
189 'open'=>'17:00',
190 'close'=>'01:00'
191 );
192
193
194
195 return $options;
196 }
197
198 /*------------------------------------------------------------------------------
199 # [validate options on save/update]
200 #
201 # @since 3.0
202 # @return array()
203 ------------------------------------------------------------------------------*/
204 function options_validate($options, $input){
205 /**make sure we get the full array on install/update**/
206 if ( empty( $_POST['_wp_http_referer'] ) ) {
207 return $input;
208 }
209
210 if(isset($_POST[''.WPPIZZA_SLUG.'_'.$this->settings_page.''])){
211
212 $options[$this->settings_page]['opening_times_custom'] = array();//initialize array
213 if(isset($input[$this->settings_page]['opening_times_custom']['date'])){
214 foreach($input[$this->settings_page]['opening_times_custom']['date'] as $key=>$date){
215 /*
216 simply delete if date is empty
217 */
218 if(!empty($date)){
219 $options[$this->settings_page]['opening_times_custom'][$key]['date']=wppizza_validate_date($date,'Y-m-d');
220 $options[$this->settings_page]['opening_times_custom'][$key]['open']=wppizza_validate_24hourtime($input[$this->settings_page]['opening_times_custom']['open'][$key],'Y-m-d');
221 $options[$this->settings_page]['opening_times_custom'][$key]['close']=wppizza_validate_24hourtime($input[$this->settings_page]['opening_times_custom']['close'][$key],'Y-m-d');
222 $options[$this->settings_page]['opening_times_custom'][$key]['repeat_yearly']=!empty($input[$this->settings_page]['opening_times_custom']['repeat_yearly'][$key]) ? true : false;
223 }
224 }}
225
226 /* re - index array for sanity */
227 $options[$this->settings_page]['opening_times_custom'] = array_values($options[$this->settings_page]['opening_times_custom']);
228 }
229 return $options;
230 }
231 /*********************************************************
232 [helper - opening times custom also used when adding via ajax]
233 *********************************************************/
234 function wppizza_admin_section_opening_times_custom($field, $values = false, $key = false){
235
236 $date_formatted = !empty($values['date']) ? date_i18n("d M Y",strtotime($values['date'])) : '';
237 $date = !empty($values['date']) ? $values['date'] : '';
238
239 $str='';
240 $str.="<div class='wppizza_option'>";
241
242 /*
243 for easy checking for existing keys when adding new
244 */
245 $str.="<input id='".WPPIZZA_SLUG."_".$field."_".$key."' class='".WPPIZZA_SLUG."-".$field."-getkey' name='".WPPIZZA_SLUG."-".$field."-getkey[".$key."]' type='hidden' value='".$key."'>";
246
247 $str.="<input name='".WPPIZZA_SLUG."[".$this->settings_page."][".$field."][date_formatted][".$key."]' size='10' type='text' autocomplete='off' class='wppizza-date-select' value='".$date_formatted."' />";
248 $str.="<input name='".WPPIZZA_SLUG."[".$this->settings_page."][".$field."][date][".$key."]' type='hidden' class='wppizza-date' value='".$date."' />";
249
250 $str.="".__('Open from', 'wppizza-admin').":";
251 $str.="<input name='".WPPIZZA_SLUG."[".$this->settings_page."][".$field."][open][".$key."]' size='3' type='text' autocomplete='off' class='wppizza-time-select' value='". (!empty($values['open']) ? $values['open'] : '') ."' />";
252
253 $str.="".__('To', 'wppizza-admin').":";
254 $str.="<input name='".WPPIZZA_SLUG."[".$this->settings_page."][".$field."][close][".$key."]' size='3' type='text' autocomplete='off' class='wppizza-time-select' value='".(!empty($values['close']) ? $values['close'] : '')."' />";
255
256 $str.="<label>".__('Every year', 'wppizza-admin').":";
257 $str.="<input name='".WPPIZZA_SLUG."[".$this->settings_page."][".$field."][repeat_yearly][".$key."]' type='checkbox' ".checked(!empty($values['repeat_yearly']), true, false )." value='1' title='".__('Repeat every year for this date', 'wppizza-admin')."'/></label>";
258
259 $str.="<a href='javascript:void(0);' class='wppizza-delete ".$field." ".WPPIZZA_SLUG."-dashicons dashicons-trash' title='".__('delete', 'wppizza-admin')."'></a>";
260
261 $str.="</div>";
262
263 return $str;
264 }
265
266
267 }
268 /***************************************************************
269 *
270 * [ini]
271 *
272 ***************************************************************/
273 $WPPIZZA_MODULE_OPENINGTIMES_CUSTOM = new WPPIZZA_MODULE_OPENINGTIMES_CUSTOM();
274 ?>