| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPPIZZA_MODULE_LAYOUT_MINICART Class |
| 4 |
* |
| 5 |
* @package WPPIZZA |
| 6 |
* @subpackage WPPIZZA_MODULE_LAYOUT_MINICART |
| 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_LAYOUT_MINICART{ |
| 24 |
|
| 25 |
private $settings_page = 'layout';/* which admin subpage (identified there by this->class_key) are we adding this to */ |
| 26 |
|
| 27 |
private $section_key = 'minicart';/* must be unique */ |
| 28 |
|
| 29 |
|
| 30 |
function __construct() { |
| 31 |
/********************************************************** |
| 32 |
[add settings to admin] |
| 33 |
***********************************************************/ |
| 34 |
if(is_admin()){ |
| 35 |
/* add admin options settings page*/ |
| 36 |
add_filter('wppizza_filter_settings_sections_'.$this->settings_page.'', array($this, 'admin_options_settings'), 90, 5); |
| 37 |
/* add admin options settings page fields */ |
| 38 |
add_action('wppizza_admin_settings_section_fields_'.$this->settings_page.'', array($this, 'admin_options_fields_settings'), 10, 5); |
| 39 |
/**add default options **/ |
| 40 |
add_filter('wppizza_filter_setup_default_options', array( $this, 'options_default')); |
| 41 |
/**validate options**/ |
| 42 |
add_filter('wppizza_filter_options_validate', array( $this, 'options_validate'), 10, 2 ); |
| 43 |
/**add text header*/ |
| 44 |
add_action('wppizza_settings_sections_header_'.$this->settings_page.'', array( $this, 'sections_header'), 10, 2 ); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
/******************************************************************************************************************************************************* |
| 49 |
* |
| 50 |
* |
| 51 |
* |
| 52 |
* [frontend filters] |
| 53 |
* |
| 54 |
* |
| 55 |
* |
| 56 |
********************************************************************************************************************************************************/ |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
/******************************************************************************************************************************************************* |
| 61 |
* |
| 62 |
* |
| 63 |
* |
| 64 |
* [add admin page options] |
| 65 |
* |
| 66 |
* |
| 67 |
* |
| 68 |
********************************************************************************************************************************************************/ |
| 69 |
|
| 70 |
/*------------------------------------------------------------------------------ |
| 71 |
# |
| 72 |
# |
| 73 |
# [settings page] |
| 74 |
# |
| 75 |
# |
| 76 |
------------------------------------------------------------------------------*/ |
| 77 |
|
| 78 |
/********************************************************* |
| 79 |
[more header info] |
| 80 |
*********************************************************/ |
| 81 |
function sections_header($arg, $section_count){ |
| 82 |
if($arg['id']==$this->section_key){ |
| 83 |
echo '<div>'.__('[only applicable if enabled in widget or when using shortcodes]', 'wppizza-admin').'</div>'; |
| 84 |
echo '<span class="wppizza-highlight">'.__('The "Minicart" could interfere with some layouts. If that is the case, using some of the options provided here with additional css declarations *might* let you get around this.', 'wppizza-admin').'</span>'; |
| 85 |
} |
| 86 |
} |
| 87 |
/*------------------------------------------------------------------------------ |
| 88 |
# [settings section - setting page] |
| 89 |
# @since 3.0 |
| 90 |
# @return array() |
| 91 |
------------------------------------------------------------------------------*/ |
| 92 |
function admin_options_settings($settings, $sections, $fields, $inputs, $help){ |
| 93 |
|
| 94 |
/*section*/ |
| 95 |
if($sections){ |
| 96 |
$settings['sections'][$this->section_key] = __('Minicart', 'wppizza-admin'); |
| 97 |
} |
| 98 |
|
| 99 |
/*help*/ |
| 100 |
if($help){ |
| 101 |
$settings['help'][$this->section_key][] = array( |
| 102 |
'label'=>__('Minicart Settings [if used in widget or shortcode]', 'wppizza-admin'), |
| 103 |
'description'=>array( |
| 104 |
__('Set options according to the settings available', 'wppizza-admin') |
| 105 |
) |
| 106 |
); |
| 107 |
} |
| 108 |
|
| 109 |
/*fields*/ |
| 110 |
if($fields){ |
| 111 |
|
| 112 |
$field = 'minicart_viewcart'; |
| 113 |
$settings['fields'][$this->section_key][$field] = array( __('Display "view cart" button', 'wppizza-admin') , array( |
| 114 |
'value_key'=>$field, |
| 115 |
'option_key'=>$this->settings_page, |
| 116 |
'label'=>'', |
| 117 |
'description'=>array() |
| 118 |
)); |
| 119 |
$field = 'minicart_checkout'; |
| 120 |
$settings['fields'][$this->section_key][$field] = array( __('Display "checkout" button', 'wppizza-admin') , array( |
| 121 |
'value_key'=>$field, |
| 122 |
'option_key'=>$this->settings_page, |
| 123 |
'label'=>__('only shown if user can actually order', 'wppizza-admin'), |
| 124 |
'description'=>array() |
| 125 |
)); |
| 126 |
$field = 'minicart_emptycart'; |
| 127 |
$settings['fields'][$this->section_key][$field] = array( __('Display "empty cart" button', 'wppizza-admin') , array( |
| 128 |
'value_key'=>$field, |
| 129 |
'option_key'=>$this->settings_page, |
| 130 |
'label'=>'', |
| 131 |
'description'=>array() |
| 132 |
)); |
| 133 |
$field = 'minicart_itemcount'; |
| 134 |
$settings['fields'][$this->section_key][$field] = array( __('Show count of items', 'wppizza-admin') , array( |
| 135 |
'value_key'=>$field, |
| 136 |
'option_key'=>$this->settings_page, |
| 137 |
'label'=>'', |
| 138 |
'description'=>array() |
| 139 |
)); |
| 140 |
$field = 'minicart_position'; |
| 141 |
$settings['fields'][$this->section_key][$field] = array( __('Position', 'wppizza-admin') , array( |
| 142 |
'value_key'=>$field, |
| 143 |
'option_key'=>$this->settings_page, |
| 144 |
'label'=>'', |
| 145 |
'description'=>array() |
| 146 |
)); |
| 147 |
$field = 'minicart_always_shown'; |
| 148 |
$settings['fields'][$this->section_key][$field] = array( __('Always show minicart', 'wppizza-admin') , array( |
| 149 |
'value_key'=>$field, |
| 150 |
'option_key'=>$this->settings_page, |
| 151 |
'label'=>__('always show minicart, even if main cart is in view (if no main cart has been added anywhere, this will automatically be the case)', 'wppizza-admin'), |
| 152 |
'description'=>array() |
| 153 |
)); |
| 154 |
$field = 'minicart_max_width_active'; |
| 155 |
$settings['fields'][$this->section_key][$field] = array( __('Max browser width', 'wppizza-admin') , array( |
| 156 |
'value_key'=>$field, |
| 157 |
'option_key'=>$this->settings_page, |
| 158 |
'label'=>__('max browser width up to which the minicart will be shown.', 'wppizza-admin'), |
| 159 |
'description'=>array( |
| 160 |
__('Useful for themes that, under a certain browser window width, change to a responsive design that moves elements to different places. [in px, 0 to ignore]', 'wppizza-admin') |
| 161 |
) |
| 162 |
)); |
| 163 |
$field = 'minicart_elm_padding_top'; |
| 164 |
$settings['fields'][$this->section_key][$field] = array( __('Top padding', 'wppizza-admin') , array( |
| 165 |
'value_key'=>$field, |
| 166 |
'option_key'=>$this->settings_page, |
| 167 |
'label'=>__('add additional top padding to body element if small cart is displayed. [in px, 0 to ignore]', 'wppizza-admin'), |
| 168 |
'description'=>array() |
| 169 |
)); |
| 170 |
$field = 'minicart_add_to_element'; |
| 171 |
$settings['fields'][$this->section_key][$field] = array( __('Append to element', 'wppizza-admin') , array( |
| 172 |
'value_key'=>$field, |
| 173 |
'option_key'=>$this->settings_page, |
| 174 |
'label'=>__('by default, the minicart will be added just before closing body tag with a css of position:fixed;top:0. if you want it appended elsewhere, set the relevant element here', 'wppizza-admin'), |
| 175 |
'description'=>array( |
| 176 |
__('use jQuery selectors, such as #my-elm-id or .my_elm_class etc. You might have to use additional css declarations for your theme.', 'wppizza-admin') |
| 177 |
) |
| 178 |
)); |
| 179 |
$field = 'minicart_elm_padding_selector'; |
| 180 |
$settings['fields'][$this->section_key][$field] = array( __('Alt Element Padding', 'wppizza-admin') , array( |
| 181 |
'value_key'=>$field, |
| 182 |
'option_key'=>$this->settings_page, |
| 183 |
'label'=>__('add above set padding to another element *instead* of the body tag.', 'wppizza-admin'), |
| 184 |
'description'=>array( |
| 185 |
__('use jQuery selectors, such as #my-elm-id or .my_elm_class etc', 'wppizza-admin') |
| 186 |
) |
| 187 |
)); |
| 188 |
} |
| 189 |
|
| 190 |
return $settings; |
| 191 |
} |
| 192 |
/*------------------------------------------------------------------------------ |
| 193 |
# [output option fields - setting page] |
| 194 |
# @since 3.0 |
| 195 |
# @return array() |
| 196 |
------------------------------------------------------------------------------*/ |
| 197 |
function admin_options_fields_settings($wppizza_options, $options_key, $field, $label, $description){ |
| 198 |
|
| 199 |
if($field=='minicart_viewcart'){ |
| 200 |
print'<label>'; |
| 201 |
echo "<input name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />"; |
| 202 |
print'' . $label . ''; |
| 203 |
print'</label>'; |
| 204 |
print'' . $description . ''; |
| 205 |
} |
| 206 |
if($field=='minicart_checkout'){ |
| 207 |
print'<label>'; |
| 208 |
echo "<input name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />"; |
| 209 |
print'' . $label . ''; |
| 210 |
print'</label>'; |
| 211 |
print'' . $description . ''; |
| 212 |
} |
| 213 |
if($field=='minicart_emptycart'){ |
| 214 |
print'<label>'; |
| 215 |
echo "<input name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />"; |
| 216 |
print'' . $label . ''; |
| 217 |
print'</label>'; |
| 218 |
print'' . $description . ''; |
| 219 |
} |
| 220 |
if($field=='minicart_itemcount'){ |
| 221 |
print'<label>'; |
| 222 |
echo "<select name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' />"; |
| 223 |
echo"<option value='' ".selected($wppizza_options[$options_key][$field],"",false).">".__('Do not show', 'wppizza-admin')."</option>"; |
| 224 |
echo"<option value='left' ".selected($wppizza_options[$options_key][$field],"left",false).">".__('Left', 'wppizza-admin')."</option>"; |
| 225 |
echo"<option value='right' ".selected($wppizza_options[$options_key][$field],"right",false).">".__('Right', 'wppizza-admin')."</option>"; |
| 226 |
echo "</select>"; |
| 227 |
print'</label>'; |
| 228 |
print'' . $description . ''; |
| 229 |
} |
| 230 |
if($field=='minicart_position'){ |
| 231 |
print'<label>'; |
| 232 |
echo "<select name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' />"; |
| 233 |
echo"<option value='top' ".selected($wppizza_options[$options_key][$field],"top",false).">".__('Top', 'wppizza-admin')."</option>"; |
| 234 |
echo"<option value='bottom' ".selected($wppizza_options[$options_key][$field],"bottom",false).">".__('Bottom', 'wppizza-admin')."</option>"; |
| 235 |
echo "</select>"; |
| 236 |
print'</label>'; |
| 237 |
print'' . $description . ''; |
| 238 |
} |
| 239 |
if($field=='minicart_always_shown'){ |
| 240 |
print'<label>'; |
| 241 |
echo "<input name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />"; |
| 242 |
print'' . $label . ''; |
| 243 |
print'</label>'; |
| 244 |
print'' . $description . ''; |
| 245 |
} |
| 246 |
if($field=='minicart_max_width_active'){ |
| 247 |
print'<label>'; |
| 248 |
echo "<input name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' size='2' type='text' value='".$wppizza_options[$options_key][$field]."' />"; |
| 249 |
print'' . $label . ''; |
| 250 |
print'</label>'; |
| 251 |
print'' . $description . ''; |
| 252 |
} |
| 253 |
if($field=='minicart_elm_padding_top'){ |
| 254 |
print'<label>'; |
| 255 |
echo "<input name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' size='2' type='text' value='".$wppizza_options[$options_key][$field]."' />"; |
| 256 |
print'' . $label . ''; |
| 257 |
print'</label>'; |
| 258 |
print'' . $description . ''; |
| 259 |
} |
| 260 |
if($field=='minicart_add_to_element'){ |
| 261 |
print'<label>'; |
| 262 |
echo "<input name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' size='20' type='text' value='".$wppizza_options[$options_key][$field]."' />"; |
| 263 |
print'' . $label . ''; |
| 264 |
print'</label>'; |
| 265 |
print'' . $description . ''; |
| 266 |
} |
| 267 |
if($field=='minicart_elm_padding_selector'){ |
| 268 |
print'<label>'; |
| 269 |
echo "<input name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' size='20' type='text' value='".$wppizza_options[$options_key][$field]."' />"; |
| 270 |
print'' . $label . ''; |
| 271 |
print'</label>'; |
| 272 |
print'' . $description . ''; |
| 273 |
} |
| 274 |
|
| 275 |
|
| 276 |
} |
| 277 |
|
| 278 |
/**************************************************************** |
| 279 |
* |
| 280 |
* [insert default option on install] |
| 281 |
* $parameter $options array() | filter passing on filtered options |
| 282 |
* @since 3.0 |
| 283 |
* @return array() |
| 284 |
* |
| 285 |
****************************************************************/ |
| 286 |
function options_default($options){ |
| 287 |
|
| 288 |
$options[$this->settings_page]['minicart_max_width_active'] = 0; |
| 289 |
$options[$this->settings_page]['minicart_elm_padding_top'] = 0; |
| 290 |
$options[$this->settings_page]['minicart_elm_padding_selector'] = ''; |
| 291 |
$options[$this->settings_page]['minicart_add_to_element'] = ''; |
| 292 |
$options[$this->settings_page]['minicart_always_shown'] = false; |
| 293 |
$options[$this->settings_page]['minicart_viewcart'] = true; |
| 294 |
$options[$this->settings_page]['minicart_checkout'] = true; |
| 295 |
$options[$this->settings_page]['minicart_emptycart'] = false; |
| 296 |
$options[$this->settings_page]['minicart_itemcount'] = 'left'; |
| 297 |
$options[$this->settings_page]['minicart_position'] = 'top'; |
| 298 |
|
| 299 |
return $options; |
| 300 |
} |
| 301 |
|
| 302 |
/*------------------------------------------------------------------------------ |
| 303 |
# [validate options on save/update] |
| 304 |
# |
| 305 |
# @since 3.0 |
| 306 |
# @return array() |
| 307 |
------------------------------------------------------------------------------*/ |
| 308 |
function options_validate($options, $input){ |
| 309 |
/**make sure we get the full array on install/update**/ |
| 310 |
if ( empty( $_POST['_wp_http_referer'] ) ) { |
| 311 |
return $input; |
| 312 |
} |
| 313 |
if(isset($_POST[''.WPPIZZA_SLUG.'_'.$this->settings_page.''])){ |
| 314 |
|
| 315 |
$options[$this->settings_page]['minicart_always_shown'] = !empty($input[$this->settings_page]['minicart_always_shown']) ? true : false; |
| 316 |
$options[$this->settings_page]['minicart_viewcart'] = !empty($input[$this->settings_page]['minicart_viewcart']) ? true : false; |
| 317 |
$options[$this->settings_page]['minicart_checkout'] = !empty($input[$this->settings_page]['minicart_checkout']) ? true : false; |
| 318 |
$options[$this->settings_page]['minicart_emptycart'] = !empty($input[$this->settings_page]['minicart_emptycart']) ? true : false; |
| 319 |
$options[$this->settings_page]['minicart_itemcount']=wppizza_validate_string($input[$this->settings_page]['minicart_itemcount']); |
| 320 |
$options[$this->settings_page]['minicart_position']=wppizza_validate_string($input[$this->settings_page]['minicart_position']); |
| 321 |
|
| 322 |
$options[$this->settings_page]['minicart_max_width_active']=wppizza_validate_int_only($input[$this->settings_page]['minicart_max_width_active']); |
| 323 |
$options[$this->settings_page]['minicart_elm_padding_top']=wppizza_validate_int_only($input[$this->settings_page]['minicart_elm_padding_top']); |
| 324 |
$options[$this->settings_page]['minicart_add_to_element']=preg_replace("/[^a-zA-Z0-9#>\-_\., ]/","",$input[$this->settings_page]['minicart_add_to_element']); |
| 325 |
$options[$this->settings_page]['minicart_elm_padding_selector']=preg_replace("/[^a-zA-Z0-9#>\-_\., ]/","",$input[$this->settings_page]['minicart_elm_padding_selector']); |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
} |
| 330 |
|
| 331 |
return $options; |
| 332 |
} |
| 333 |
} |
| 334 |
/*************************************************************** |
| 335 |
* |
| 336 |
* [ini] |
| 337 |
* |
| 338 |
***************************************************************/ |
| 339 |
$WPPIZZA_MODULE_LAYOUT_MINICART = new WPPIZZA_MODULE_LAYOUT_MINICART(); |
| 340 |
?> |