| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPPIZZA_MODULE_LAYOUT_PRICES_FORMAT Class |
| 4 |
* |
| 5 |
* @package WPPIZZA |
| 6 |
* @subpackage WPPIZZA_MODULE_LAYOUT_PRICES_FORMAT |
| 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_PRICES_FORMAT{ |
| 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 = 'prices_format';/* 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'), 40, 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 |
} |
| 44 |
} |
| 45 |
|
| 46 |
/******************************************************************************************************************************************************* |
| 47 |
* |
| 48 |
* |
| 49 |
* |
| 50 |
* [frontend filters] |
| 51 |
* |
| 52 |
* |
| 53 |
* |
| 54 |
********************************************************************************************************************************************************/ |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
/******************************************************************************************************************************************************* |
| 59 |
* |
| 60 |
* |
| 61 |
* |
| 62 |
* [add admin page options] |
| 63 |
* |
| 64 |
* |
| 65 |
* |
| 66 |
********************************************************************************************************************************************************/ |
| 67 |
|
| 68 |
/*------------------------------------------------------------------------------ |
| 69 |
# |
| 70 |
# |
| 71 |
# [settings page] |
| 72 |
# |
| 73 |
# |
| 74 |
------------------------------------------------------------------------------*/ |
| 75 |
|
| 76 |
/*------------------------------------------------------------------------------ |
| 77 |
# [settings section - setting page] |
| 78 |
# @since 3.0 |
| 79 |
# @return array() |
| 80 |
------------------------------------------------------------------------------*/ |
| 81 |
function admin_options_settings($settings, $sections, $fields, $inputs, $help){ |
| 82 |
|
| 83 |
/*section*/ |
| 84 |
if($sections){ |
| 85 |
$settings['sections'][$this->section_key] = __('Prices / Currency Symbols', 'wppizza-admin'); |
| 86 |
} |
| 87 |
|
| 88 |
/*help*/ |
| 89 |
if($help){ |
| 90 |
$settings['help'][$this->section_key][] = array( |
| 91 |
'label'=>__('Prices / Currency Symbols', 'wppizza-admin'), |
| 92 |
'description'=>array( |
| 93 |
__('Format prices and currency symbols output according to the settings available', 'wppizza-admin') |
| 94 |
) |
| 95 |
); |
| 96 |
} |
| 97 |
|
| 98 |
/*fields*/ |
| 99 |
if($fields){ |
| 100 |
|
| 101 |
$field = 'hide_prices'; |
| 102 |
$settings['fields'][$this->section_key][$field] = array( __('Hide prices', 'wppizza-admin') , array( |
| 103 |
'value_key'=>$field, |
| 104 |
'option_key'=>$this->settings_page, |
| 105 |
'label'=>'<span class="wppizza-highlight">'.__('this will disable the adding of any item to the shoppingcart.', 'wppizza-admin'),'</span>', |
| 106 |
'description'=>array( |
| 107 |
__('Really only useful if you want to display your menu without offering online orders', 'wppizza-admin') |
| 108 |
) |
| 109 |
)); |
| 110 |
$field = 'hide_decimals'; |
| 111 |
$settings['fields'][$this->section_key][$field] = array( __('No decimals', 'wppizza-admin') , array( |
| 112 |
'value_key'=>$field, |
| 113 |
'option_key'=>$this->settings_page, |
| 114 |
'label'=>__('Do no display any decimals', 'wppizza-admin'), |
| 115 |
'description'=>array( |
| 116 |
__('prices will be rounded if necessary', 'wppizza-admin') |
| 117 |
) |
| 118 |
)); |
| 119 |
$field = 'show_currency_with_price'; |
| 120 |
$settings['fields'][$this->section_key][$field] = array( __('Show a currency symbol directly next to each price', 'wppizza-admin') , array( |
| 121 |
'value_key'=>$field, |
| 122 |
'option_key'=>$this->settings_page, |
| 123 |
'label'=>'', |
| 124 |
'description'=>array() |
| 125 |
)); |
| 126 |
$field = 'hide_item_currency_symbol'; |
| 127 |
$settings['fields'][$this->section_key][$field] = array( __('*Main* currency symbol', 'wppizza-admin') , array( |
| 128 |
'value_key'=>$field, |
| 129 |
'option_key'=>$this->settings_page, |
| 130 |
'label'=>__('Hide *main* currency symbol next to each menu item', 'wppizza-admin'), |
| 131 |
'description'=>array( |
| 132 |
__('will not affect cart, summaries or emails', 'wppizza-admin') |
| 133 |
) |
| 134 |
)); |
| 135 |
$field = 'currency_symbol_left'; |
| 136 |
$settings['fields'][$this->section_key][$field] = array( __('*Main* currency symbol position', 'wppizza-admin') , array( |
| 137 |
'value_key'=>$field, |
| 138 |
'option_key'=>$this->settings_page, |
| 139 |
'label'=>__('Show *main* currency symbol on the left - if not set to hidden', 'wppizza-admin'), |
| 140 |
'description'=>array( |
| 141 |
__('by default, the main currency symbol is displayed on the right of all prices / sizes when listing menu items', 'wppizza-admin') |
| 142 |
) |
| 143 |
)); |
| 144 |
$field = 'currency_symbol_position'; |
| 145 |
$settings['fields'][$this->section_key][$field] = array( __('All other [cart, order page, email] currency symbols', 'wppizza-admin') , array( |
| 146 |
'value_key'=>$field, |
| 147 |
'option_key'=>$this->settings_page, |
| 148 |
'label'=>'', |
| 149 |
'description'=>array() |
| 150 |
)); |
| 151 |
$field = 'currency_symbol_spacing'; |
| 152 |
$settings['fields'][$this->section_key][$field] = array( __('Currency symbol spacing', 'wppizza-admin') , array( |
| 153 |
'value_key'=>$field, |
| 154 |
'option_key'=>$this->settings_page, |
| 155 |
'label'=>__('add space between currency symbol and price', 'wppizza-admin'), |
| 156 |
'description'=>array() |
| 157 |
)); |
| 158 |
$field = 'localize_zero_price'; |
| 159 |
$settings['fields'][$this->section_key][$field] = array( __('Zero price as "Free"', 'wppizza-admin') , array( |
| 160 |
'value_key'=>$field, |
| 161 |
'option_key'=>$this->settings_page, |
| 162 |
'label'=>__('Display price as "Free" if it equals zero (Set string in Localization->Miscellaneous))', 'wppizza-admin'), |
| 163 |
'description'=>array() |
| 164 |
)); |
| 165 |
} |
| 166 |
|
| 167 |
|
| 168 |
return $settings; |
| 169 |
} |
| 170 |
/*------------------------------------------------------------------------------ |
| 171 |
# [output option fields - setting page] |
| 172 |
# @since 3.0 |
| 173 |
# @return array() |
| 174 |
------------------------------------------------------------------------------*/ |
| 175 |
function admin_options_fields_settings($wppizza_options, $options_key, $field, $label, $description){ |
| 176 |
|
| 177 |
if($field=='hide_prices'){ |
| 178 |
print'<label>'; |
| 179 |
echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$this->section_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$this->section_key][$field],true,false)." value='1' />"; |
| 180 |
print'' . $label . ''; |
| 181 |
print'</label>'; |
| 182 |
print'' . $description . ''; |
| 183 |
} |
| 184 |
if($field=='hide_decimals' ){ |
| 185 |
print'<label>'; |
| 186 |
echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$this->section_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$this->section_key][$field],true,false)." value='1' />"; |
| 187 |
print'' . $label . ''; |
| 188 |
print'</label>'; |
| 189 |
print'' . $description . ''; |
| 190 |
} |
| 191 |
if($field=='show_currency_with_price'){ |
| 192 |
print'<label>'; |
| 193 |
echo "".__('do not show', 'wppizza-admin')." <input id='".$field."' name='".WPPIZZA_SLUG."[".$this->section_key."][".$field."]' type='radio' ".checked($wppizza_options[$this->section_key][$field],0,false)." value='0' /> "; |
| 194 |
echo "".__('on left', 'wppizza-admin')." <input id='".$field."' name='".WPPIZZA_SLUG."[".$this->section_key."][".$field."]' type='radio' ".checked($wppizza_options[$this->section_key][$field],1,false)." value='1' />"; |
| 195 |
echo "".__('on right', 'wppizza-admin')." <input id='".$field."' name='".WPPIZZA_SLUG."[".$this->section_key."][".$field."]' type='radio' ".checked($wppizza_options[$this->section_key][$field],2,false)." value='2' />"; |
| 196 |
print'' . $label . ''; |
| 197 |
print'</label>'; |
| 198 |
print'' . $description . ''; |
| 199 |
} |
| 200 |
if($field=='hide_item_currency_symbol'){ |
| 201 |
print'<label>'; |
| 202 |
echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$this->section_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$this->section_key][$field],true,false)." value='1' />"; |
| 203 |
print'' . $label . ''; |
| 204 |
print'</label>'; |
| 205 |
print'' . $description . ''; |
| 206 |
} |
| 207 |
if($field=='currency_symbol_left'){ |
| 208 |
print'<label>'; |
| 209 |
echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$this->section_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$this->section_key][$field],true,false)." value='1' />"; |
| 210 |
print'' . $label . ''; |
| 211 |
print'</label>'; |
| 212 |
print'' . $description . ''; |
| 213 |
} |
| 214 |
if($field=='currency_symbol_position'){ |
| 215 |
print'<label>'; |
| 216 |
echo "".__('on left', 'wppizza-admin')." <input id='".$field."' name='".WPPIZZA_SLUG."[".$this->section_key."][".$field."]' type='radio' ".checked($wppizza_options[$this->section_key][$field],'left',false)." value='left' />"; |
| 217 |
echo "".__('on right', 'wppizza-admin')." <input id='".$field."' name='".WPPIZZA_SLUG."[".$this->section_key."][".$field."]' type='radio' ".checked($wppizza_options[$this->section_key][$field],'right',false)." value='right' />"; |
| 218 |
print'' . $label . ''; |
| 219 |
print'</label>'; |
| 220 |
print'' . $description . ''; |
| 221 |
} |
| 222 |
if($field=='currency_symbol_spacing'){ |
| 223 |
print'<label>'; |
| 224 |
echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$this->section_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$this->section_key][$field],true,false)." value='1' />"; |
| 225 |
print'' . $label . ''; |
| 226 |
print'</label>'; |
| 227 |
print'' . $description . ''; |
| 228 |
} |
| 229 |
if($field=='localize_zero_price'){ |
| 230 |
print'<label>'; |
| 231 |
echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$this->section_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$this->section_key][$field],true,false)." value='1' />"; |
| 232 |
print'' . $label . ''; |
| 233 |
print'</label>'; |
| 234 |
print'' . $description . ''; |
| 235 |
} |
| 236 |
|
| 237 |
} |
| 238 |
|
| 239 |
/**************************************************************** |
| 240 |
* |
| 241 |
* [insert default option on install] |
| 242 |
* $parameter $options array() | filter passing on filtered options |
| 243 |
* @since 3.0 |
| 244 |
* @return array() |
| 245 |
* |
| 246 |
****************************************************************/ |
| 247 |
function options_default($options){ |
| 248 |
|
| 249 |
|
| 250 |
$options[$this->section_key]['hide_prices'] = false; |
| 251 |
$options[$this->section_key]['hide_decimals'] = false; |
| 252 |
$options[$this->section_key]['show_currency_with_price'] = 0; |
| 253 |
$options[$this->section_key]['hide_item_currency_symbol'] = false; |
| 254 |
$options[$this->section_key]['currency_symbol_left'] = false; |
| 255 |
$options[$this->section_key]['currency_symbol_position'] = 'left'; |
| 256 |
$options[$this->section_key]['currency_symbol_spacing'] = true; |
| 257 |
$options[$this->section_key]['localize_zero_price'] = false; |
| 258 |
|
| 259 |
|
| 260 |
return $options; |
| 261 |
} |
| 262 |
|
| 263 |
/*------------------------------------------------------------------------------ |
| 264 |
# [validate options on save/update] |
| 265 |
# |
| 266 |
# @since 3.0 |
| 267 |
# @return array() |
| 268 |
------------------------------------------------------------------------------*/ |
| 269 |
function options_validate($options, $input){ |
| 270 |
/**make sure we get the full array on install/update**/ |
| 271 |
if ( empty( $_POST['_wp_http_referer'] ) ) { |
| 272 |
return $input; |
| 273 |
} |
| 274 |
if(isset($_POST[''.WPPIZZA_SLUG.'_'.$this->settings_page.''])){ |
| 275 |
$options[$this->section_key]['hide_prices'] = !empty($input[$this->section_key]['hide_prices']) ? true : false; |
| 276 |
$options[$this->section_key]['hide_decimals'] = !empty($input[$this->section_key]['hide_decimals']) ? true : false; |
| 277 |
$options[$this->section_key]['show_currency_with_price'] = wppizza_validate_int_only($input[$this->section_key]['show_currency_with_price']); |
| 278 |
$options[$this->section_key]['hide_item_currency_symbol'] = !empty($input[$this->section_key]['hide_item_currency_symbol']) ? true : false; |
| 279 |
$options[$this->section_key]['currency_symbol_left'] = !empty($input[$this->section_key]['currency_symbol_left']) ? true : false; |
| 280 |
$options[$this->section_key]['currency_symbol_position'] = preg_replace("/[^a-z]/","",$input[$this->section_key]['currency_symbol_position']); |
| 281 |
$options[$this->section_key]['currency_symbol_spacing'] = !empty($input[$this->section_key]['currency_symbol_spacing']) ? true : false; |
| 282 |
$options[$this->section_key]['localize_zero_price'] = !empty($input[$this->section_key]['localize_zero_price']) ? true : false; |
| 283 |
} |
| 284 |
|
| 285 |
return $options; |
| 286 |
} |
| 287 |
} |
| 288 |
/*************************************************************** |
| 289 |
* |
| 290 |
* [ini] |
| 291 |
* |
| 292 |
***************************************************************/ |
| 293 |
$WPPIZZA_MODULE_LAYOUT_PRICES_FORMAT = new WPPIZZA_MODULE_LAYOUT_PRICES_FORMAT(); |
| 294 |
?> |