| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPPIZZA_SHORTCODES Class |
| 4 |
* |
| 5 |
* @package WPPIZZA |
| 6 |
* @subpackage WPPizza Shortcodes |
| 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 |
* WPPIZZA_SHORTCODES |
| 19 |
* |
| 20 |
* |
| 21 |
************************************************************************************************************************/ |
| 22 |
class WPPIZZA_SHORTCODES{ |
| 23 |
|
| 24 |
|
| 25 |
function __construct() { |
| 26 |
/* |
| 27 |
used in ajax request for cart contents too so must be available when ajax and on front AND backend! |
| 28 |
*/ |
| 29 |
add_shortcode(WPPIZZA_SLUG, array($this, 'add_shortcodes')); |
| 30 |
|
| 31 |
/* |
| 32 |
admin shortcodes (in case we want to be able to add certain admin parts to frontend pages) |
| 33 |
*/ |
| 34 |
add_shortcode(WPPIZZA_SLUG.'_admin', array($this, 'add_admin_shortcodes')); |
| 35 |
|
| 36 |
/* |
| 37 |
if using admin shortcodes in frontend pages, (compact admin order history for example) |
| 38 |
define wppizza_has_admin_shortcode() to return true for other plugins to check |
| 39 |
alongside is_admin() for example |
| 40 |
*/ |
| 41 |
add_action('init', array($this, 'has_admin_shortcode'), 9); |
| 42 |
|
| 43 |
} |
| 44 |
|
| 45 |
/***************************************************** |
| 46 |
* @return void |
| 47 |
* @since 3.5 |
| 48 |
******************************************************/ |
| 49 |
function has_admin_shortcode(){ |
| 50 |
|
| 51 |
/* |
| 52 |
as we are running on init , there is no post object yet |
| 53 |
and we have to get the id by url |
| 54 |
*/ |
| 55 |
$REQUEST_SCHEME = is_ssl() ? 'https' : 'http'; |
| 56 |
$HTTP_HOST = !empty($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''; |
| 57 |
|
| 58 |
$current_url = $REQUEST_SCHEME . '://' . $HTTP_HOST . $_SERVER['REQUEST_URI'] ; |
| 59 |
$post_id = url_to_postid($current_url); |
| 60 |
$post_content = get_post_field('post_content', $post_id); |
| 61 |
if(has_shortcode( $post_content, WPPIZZA_SLUG.'_admin')) { |
| 62 |
|
| 63 |
/* add thickbox */ |
| 64 |
add_action( 'wp_enqueue_scripts', array($this, 'add_admin_shortcode_thickbox') ); |
| 65 |
|
| 66 |
/* return true for global wppizza_is_admin_shortcode() function */ |
| 67 |
add_filter('wppizza_has_admin_shortcode', array($this, 'is_admin_shortcode')); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
/***************************************************** |
| 72 |
* make global is_admin_shortcode() function return true |
| 73 |
* @return bool (true) |
| 74 |
* @since 3.5 |
| 75 |
******************************************************/ |
| 76 |
function is_admin_shortcode($bool){ |
| 77 |
return true; |
| 78 |
} |
| 79 |
/***************************************************** |
| 80 |
* enqueue thickbox for pages that include admin shortcodes |
| 81 |
* @return void |
| 82 |
* @since 3.5 |
| 83 |
******************************************************/ |
| 84 |
function add_admin_shortcode_thickbox(){ |
| 85 |
add_thickbox(); |
| 86 |
} |
| 87 |
/***************************************************** |
| 88 |
* Generates wppizza admin shortcode output utilising templates |
| 89 |
* @atts The array of shortcode attributes |
| 90 |
* @since 3.5 |
| 91 |
* @return str |
| 92 |
******************************************************/ |
| 93 |
function add_admin_shortcodes($atts){ |
| 94 |
|
| 95 |
$type = !empty($atts['type']) ? $atts['type'] : '' ; |
| 96 |
|
| 97 |
$is_admin = true ; |
| 98 |
|
| 99 |
$markup=''; |
| 100 |
|
| 101 |
/********************************************** |
| 102 |
possible attributes: |
| 103 |
type='admin_orderhistory' (required [str]) |
| 104 |
|
| 105 |
name='cname' (optional str) |
| 106 |
address='caddress' (optional str) |
| 107 |
no_pagination='1' (optional bool) |
| 108 |
print_view='1' (optional bool) |
| 109 |
unprotected='1' (optional bool) |
| 110 |
delete_order='1' (optional bool - allow order delete button (if user has privileges)) |
| 111 |
|
| 112 |
# perhaps to add in the future |
| 113 |
# |
| 114 |
# compact=0|1 (optional [bool]) |
| 115 |
# maxpp=10 (optional [int]) |
| 116 |
# actions = '' (optional str, comma separated actions - allow adding of all/most other actions) |
| 117 |
# |
| 118 |
|
| 119 |
example: [wppizza_admin type='admin_orderhistory' name='cname' unprotected='1' delete_order='1'] |
| 120 |
|
| 121 |
**********************************************/ |
| 122 |
if($type == 'admin_orderhistory'){ |
| 123 |
$markup = WPPIZZA()->markup_pages->markup($type, $atts, $is_admin); |
| 124 |
return $markup; |
| 125 |
} |
| 126 |
|
| 127 |
/********************************************** |
| 128 |
possible attributes: |
| 129 |
type='admin_dashboard_widget' (required [str]) |
| 130 |
unprotected='1' (optional bool) |
| 131 |
example: [wppizza_admin type='admin_dashboard_widget' unprotected='1'] |
| 132 |
|
| 133 |
**********************************************/ |
| 134 |
if($type == 'admin_dashboard_widget'){ |
| 135 |
$markup = WPPIZZA()->markup_pages->markup($type, $atts, $is_admin); |
| 136 |
return $markup; |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
return $markup; |
| 141 |
die();//needed !!! |
| 142 |
} |
| 143 |
|
| 144 |
/***************************************************** |
| 145 |
* Generates shortcode output utilising templates |
| 146 |
* @atts The array of shortcode attributes |
| 147 |
******************************************************/ |
| 148 |
function add_shortcodes($atts){ |
| 149 |
|
| 150 |
$markup = ''; |
| 151 |
extract(shortcode_atts(array('type' => ''), $atts)); |
| 152 |
/* extract may result in an empty string, make sure to convert to empty array */ |
| 153 |
if(empty($atts)){$atts = array(); } |
| 154 |
|
| 155 |
/********************************************** |
| 156 |
[navigation] |
| 157 |
possible attributes: |
| 158 |
type='navigation' (required [str]) |
| 159 |
title='some title' (optional[str]: will render as h2 as first element in cart elemnt if set) |
| 160 |
parent='slug-name' (optionsl [str]): only show child categories of this slug |
| 161 |
exclude='6,5,8' (optional [comma separated category id's]): exclude some id's |
| 162 |
example: [wppizza type='navigation' title='some title' parent='slug-name' exclude='6,5,8'] |
| 163 |
**********************************************/ |
| 164 |
if($type=='navigation'){ |
| 165 |
$markup = WPPIZZA()->markup_navigation->attributes($atts); |
| 166 |
return $markup; |
| 167 |
} |
| 168 |
/********************************************** |
| 169 |
[orderinfo] |
| 170 |
possible attributes: |
| 171 |
type='orderinfo' (required [str]) |
| 172 |
width='200px' (optional [int + px|%] ) |
| 173 |
height='200px' (optional [int + px|%]) |
| 174 |
class='myclass' (optional [string] default='') |
| 175 |
info='discounts,deliveries' (optional [comma separated string of modules . discounts and/or deliveries ] if omitted == discounts, deliveries) |
| 176 |
example: [wppizza type='openingtimes' width='80%' height='200px' class='my_class' info='discounts, deliveries'] |
| 177 |
returns discounts/delivery costs etc in a string |
| 178 |
**********************************************/ |
| 179 |
if($type=='orderinfo'){ |
| 180 |
$markup = WPPIZZA()->markup_orderinfo->attributes($atts); |
| 181 |
return $markup; |
| 182 |
} |
| 183 |
|
| 184 |
/********************************************** |
| 185 |
[openingtimes] |
| 186 |
possible attributes: |
| 187 |
type='openingtimes' (required [str]) |
| 188 |
width='200px' (optional [int + px|%] ) |
| 189 |
height='200px' (optional [int + px|%]) |
| 190 |
class='myclass' (optional [string] default='') |
| 191 |
example: [wppizza type='openingtimes' class='my_class'] |
| 192 |
returns grouped opening times in a string |
| 193 |
**********************************************/ |
| 194 |
if($type=='openingtimes'){ |
| 195 |
$markup = WPPIZZA()->markup_openingtimes->attributes($atts); |
| 196 |
return $markup; |
| 197 |
} |
| 198 |
|
| 199 |
/********************************************** |
| 200 |
[additives] |
| 201 |
possible attributes: |
| 202 |
type='additives' (required [str]) |
| 203 |
class='myclass' (optional [string] default='') |
| 204 |
example: [wppizza type='additives' class='my_class'] |
| 205 |
returns all additives in an html string |
| 206 |
**********************************************/ |
| 207 |
if($type=='additives'){ |
| 208 |
$markup = WPPIZZA()->markup_additives->attributes($atts); |
| 209 |
return $markup; |
| 210 |
} |
| 211 |
|
| 212 |
/********************************************** |
| 213 |
[foodtype] |
| 214 |
possible attributes: |
| 215 |
type='foodtype' (required [str]) |
| 216 |
class='myclass' (optional [string] default='') |
| 217 |
example: [wppizza type='foodtype' class='my_class'] |
| 218 |
returns all foodtypes in an html string |
| 219 |
**********************************************/ |
| 220 |
if($type=='foodtype'){ |
| 221 |
$markup = WPPIZZA()->markup_foodtype->attributes($atts); |
| 222 |
return $markup; |
| 223 |
} |
| 224 |
|
| 225 |
/********************************************** |
| 226 |
[pickup choices] |
| 227 |
possible attributes: |
| 228 |
type='pickup_choices' (required [str]) |
| 229 |
class='myclass' (optional [string] default='') |
| 230 |
toggle='1' (bool - displays to buttons) |
| 231 |
example: [wppizza type='pickup_choices' class='my_class'] |
| 232 |
returns array with checkbox (un/selected) |
| 233 |
**********************************************/ |
| 234 |
if($type=='pickup_choices'){ |
| 235 |
$markup = WPPIZZA() -> markup_pickup_choice -> attributes($atts, $type); |
| 236 |
return $markup; |
| 237 |
} |
| 238 |
|
| 239 |
/********************************************** |
| 240 |
[searchbox] |
| 241 |
possible attributes: |
| 242 |
type='search' (required [str]) |
| 243 |
include='wppizza,post,page,attachment,revision,nav_menu_item' (optional[str]: include menu items, posts, pages and/or other cpts respectively) |
| 244 |
loggedinonly='1' (optional[bool]: anything. if defined searchform only gets displayed for logged in users) |
| 245 |
class='myclass' (optional [string] default='') |
| 246 |
example: [wppizza type='search' include='wppizza,post,page' loggedinonly='1'] |
| 247 |
**********************************************/ |
| 248 |
if($type=='search'){ |
| 249 |
$markup = WPPIZZA()->markup_search->attributes($atts); |
| 250 |
return $markup; |
| 251 |
} |
| 252 |
/********************************************** |
| 253 |
[totals] |
| 254 |
possible attributes: |
| 255 |
type='totals' (required [str]) |
| 256 |
class='myclass' (optional [string] default='') |
| 257 |
value='items' (optional[str]) - if used , only displays value of items as ooposed to totals including delivery etc |
| 258 |
itemcount='left|right' (optional [str]) - if used , count of item will be displayed left or right of the total |
| 259 |
checkout='bool' (optional) - will display a button to go to order page |
| 260 |
|
| 261 |
viewcart = '1' [bool] adds view cart button |
| 262 |
|
| 263 |
cart_view = 'itemised, summary'; if empty, will show both otherwise only selected |
| 264 |
|
| 265 |
|
| 266 |
example: [wppizza type='totals'] |
| 267 |
returns div that with current cart totals (loaded via js) |
| 268 |
**********************************************/ |
| 269 |
|
| 270 |
if($type=='totals'){ |
| 271 |
global $wppizza_options; |
| 272 |
/*disable when disable_online_order is set or is orderpage */ |
| 273 |
if(!empty($wppizza_options['layout']['disable_online_order']) || wppizza_is_orderpage()){ |
| 274 |
return; |
| 275 |
} |
| 276 |
$markup = WPPIZZA()->markup_totals->attributes($atts); |
| 277 |
return $markup; |
| 278 |
} |
| 279 |
|
| 280 |
/* |
| 281 |
lets split the minicart out of the main cart, which also allows us to only display this |
| 282 |
class='myclass' (optional [string] default='') |
| 283 |
example: [wppizza type='minicart'] |
| 284 |
*/ |
| 285 |
|
| 286 |
if($type=='minicart'){ |
| 287 |
global $wppizza_options; |
| 288 |
/*disable when disable_online_order is set or is orderpage */ |
| 289 |
if(!empty($wppizza_options['layout']['disable_online_order']) || wppizza_is_orderpage() ){ |
| 290 |
return; |
| 291 |
} |
| 292 |
/** static , only ever invoked once no matter how many carts have been put on page*/ |
| 293 |
$markup = WPPIZZA()->markup_minicart->attributes($atts); |
| 294 |
return $markup; |
| 295 |
} |
| 296 |
|
| 297 |
/********************************************** |
| 298 |
[cart] |
| 299 |
possible attributes: |
| 300 |
type='cart' (required [str]) |
| 301 |
openingtimes='1' (optional[bool]: anything. if its defined it gets displayed) |
| 302 |
orderinfo=1 (optional[bool]: anything. if its defined it gets displayed) |
| 303 |
minicart=1 | only (optional[bool]: anything. if its defined it gets displayed. setting to only is the same as just using minicart shortcode) |
| 304 |
width='200px' (optional[str]: value in px or % ) (although under 150px is probably bad) |
| 305 |
height='200' (optional[str]: value in px ) |
| 306 |
example: [wppizza type='cart'] |
| 307 |
**********************************************/ |
| 308 |
if($type=='cart'){ |
| 309 |
global $wppizza_options; |
| 310 |
/*disable when disable_online_order is set or is orderpage */ |
| 311 |
if(!empty($wppizza_options['layout']['disable_online_order']) || wppizza_is_orderpage() ){ |
| 312 |
return; |
| 313 |
} |
| 314 |
|
| 315 |
if(!empty($atts['minicart'])){ |
| 316 |
/** static , only ever invoked once no matter how many carts have been put on page*/ |
| 317 |
$markup = WPPIZZA()->markup_minicart->attributes($atts); |
| 318 |
} |
| 319 |
|
| 320 |
/* skip if only showing minicart */ |
| 321 |
$markup = (!empty($atts['minicart']) && $atts['minicart']==='only')? '' : WPPIZZA()->markup_maincart->attributes($atts); |
| 322 |
|
| 323 |
return $markup; |
| 324 |
} |
| 325 |
|
| 326 |
/********************************************** |
| 327 |
[$type==orderpage] |
| 328 |
possible attributes: |
| 329 |
type='orderpage' (required [str]) |
| 330 |
nocart='1' (optional) |
| 331 |
example: [wppizza type='orderpage'] |
| 332 |
|
| 333 |
|
| 334 |
[$type==orderhistory] |
| 335 |
possible attributes: |
| 336 |
type='orderhistory' (required [str]) |
| 337 |
multisite='1' (optional [bool]) |
| 338 |
maxpp='1' (optional [int]) |
| 339 |
example: [wppizza type='orderhistory'] |
| 340 |
**********************************************/ |
| 341 |
if($type=='orderpage' || $type=='orderhistory' ){ |
| 342 |
global $wppizza_options; |
| 343 |
/*disable when disable_online_order is set */ |
| 344 |
if(!empty($wppizza_options['layout']['disable_online_order'])){ |
| 345 |
return; |
| 346 |
} |
| 347 |
|
| 348 |
$markup = WPPIZZA()->markup_pages->markup($type, $atts); |
| 349 |
return $markup; |
| 350 |
} |
| 351 |
|
| 352 |
/********************************************** |
| 353 |
[default pages (item loops)] |
| 354 |
possible attributes: |
| 355 |
category='pizza' (optional: '[category-slug]') |
| 356 |
noheader='1' (optional: 'anything') |
| 357 |
style='' (optional: default | responsive | grid if omitted , style set in layout will be used. if set to other than style in layout, make sure to enable stylecheet (layout ->load additional styles) ) |
| 358 |
showadditives='1' (optional[bool]: 0 or 1) |
| 359 |
exclude='6,5,8' (optional [comma separated menu item id's]): exclude some id's |
| 360 |
include='6,5,8' (optional [comma separated menu item id's]): include only these id's (overrides exclude) |
| 361 |
bestsellers='11' (optional: integer - shows n number of bestsellers, sorted by number of purchases desc) |
| 362 |
viewonly='1' (optional[bool]: 0 or 1 - removes add-to-cart class and shopping cart icon) |
| 363 |
example: [wppizza category='pizza' noheader='1' exclude='6,7,8'] |
| 364 |
or |
| 365 |
example: [wppizza category='pizza' noheader='1' include='6,7,8'] |
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
[single] |
| 370 |
possible attributes: |
| 371 |
single='11' (required [str] single id of menu item) |
| 372 |
viewonly='1' (optional[bool]: 0 or 1 - removes add-to-cart class and shopping cart icon) |
| 373 |
example: [wppizza single='11' ] |
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
[bestsellers] |
| 378 |
attributes: |
| 379 |
|
| 380 |
bestsellers=’10’ (required: integer of how many items to display). |
| 381 |
showadditives=’0' (optional: ‘0’ or ‘1’. if omitted, a list of additives will be displayed if any of the items has additives added. if set (0 or 1): force to display/hide additives list. useful when displaying more than 1 category on a page) |
| 382 |
include=’6,5,8' (optional [comma separated menu item id’s]): ADDITIONALLY include these id’s to the bestsellers already displayed |
| 383 |
ifempty=’5,9,8,11' (optional [comma separated menu item id’s]): if no sales have been made yet and no include have been defined – mainly for new installations – set the menu item id’s you want to have displayed instead – ignores include attribute of appicable) |
| 384 |
viewonly='1' (optional[bool]: 0 or 1 - removes add-to-cart class and shopping cart icon) |
| 385 |
examples: [wppizza bestsellers='10' ifempty='5,9,8,11' showadditives='0' include='6,5,8'] |
| 386 |
|
| 387 |
**********************************************/ |
| 388 |
if($type==''){ |
| 389 |
$markup = WPPIZZA()->templates_menu_items->markup($atts); |
| 390 |
return $markup; |
| 391 |
} |
| 392 |
/********************************************** |
| 393 |
[add_item_to_cart_button] |
| 394 |
required attributes: |
| 395 |
type='add_to_cart_button' (required [str]) |
| 396 |
id='6' (required [int]) - id of wppizza menu item |
| 397 |
size='0' (optional [int]) - id (zero indexed) of wppizza menu size for that item |
| 398 |
single='1' (optional [bool]) - if set will only show single button without dropdown |
| 399 |
example: [wppizza type='add_item_to_cart_button' id='6' size='0'] |
| 400 |
returns a button (with or without dropdown) to add a menu item to cart |
| 401 |
**********************************************/ |
| 402 |
if($type=='add_item_to_cart_button'){ |
| 403 |
global $wppizza_options; |
| 404 |
/*disable when disable_online_order is set */ |
| 405 |
if(!empty($wppizza_options['layout']['disable_online_order'])){ |
| 406 |
return; |
| 407 |
} |
| 408 |
$markup = WPPIZZA()->templates_menu_items->markup($atts, $type); |
| 409 |
return $markup; |
| 410 |
} |
| 411 |
|
| 412 |
/********************************************** |
| 413 |
[output some option settings] |
| 414 |
required attributes: |
| 415 |
type='options' (required [str]) |
| 416 |
page='localization' (required [str]) - options of a particular admin page |
| 417 |
parameter='common_label_order_order_date' (required [str]) - option parameter |
| 418 |
example: [wppizza type='options' page='localization' parameter='common_label_order_order_date'] |
| 419 |
returns a string set for common_label_order_order_date set in localization |
| 420 |
NOTE: in some cases this might also return an array !!! |
| 421 |
**********************************************/ |
| 422 |
if($type=='options'){ |
| 423 |
$markup = WPPIZZA()->markup_options->attributes($atts, $type); |
| 424 |
return $markup; |
| 425 |
} |
| 426 |
|
| 427 |
|
| 428 |
return $markup; |
| 429 |
die();//needed !!! |
| 430 |
} |
| 431 |
} |
| 432 |
/*************************************************************** |
| 433 |
* |
| 434 |
* [ini] |
| 435 |
* |
| 436 |
***************************************************************/ |
| 437 |
$WPPIZZA_SHORTCODES = new WPPIZZA_SHORTCODES(); |
| 438 |
?> |