forked from wp-plugins/wppizza
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wppizza.php
371 lines (342 loc) · 14.5 KB
/
wppizza.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
<?php
/*
Plugin Name: WPPizza
Description: Maintain your restaurant menu online and accept cash on delivery orders. Set categories, multiple prices per item and descriptions. Conceived for Pizza Delivery Businesses, but flexible enough to serve any type of restaurant.
Author: ollybach
Plugin URI: http://wordpress.org/extend/plugins/wppizza/
Author URI: https://www.wp-pizza.com
Version: 2.11.10
License:
Copyright 2012 ollybach (dev@wp-pizza.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**set the following as constants so we can use it throughout*/
/**although some/most of these are not necessary anymore, let's keep them for legacy reasons as they might have been used in extensions (notably add-ingredients < v1.1)*/
if(!defined('WPPIZZA_NAME')){
define('WPPIZZA_NAME', 'WPPizza');/*allow change of name in admin, just set define('WPPIZZA_NAME', 'New Name') in the wp-config.php*/
}
/*
to save us having to mess around with templates for single items (when linked from search results for example set an identifier in permalinks
to change the variable (in case there are namespace clashes or just if one prefers another var, set define('WPPIZZA_SINGLE_VAR', 'new-var') in the wp-config.php (lowercase , no spaces)
*/
if(!defined('WPPIZZA_SINGLE_PERMALINK_VAR')){
define('WPPIZZA_SINGLE_PERMALINK_VAR', 'menu_item');
}
define('WPPIZZA_VERSION', '2.11.10');
define('WPPIZZA_CLASS', 'WPPizza');
define('WPPIZZA_SLUG', 'wppizza');/*DO NOT EVEN THINK ABOUT CHANGING THIS*/
define('WPPIZZA_LOCALE', 'wppizza-locale');
define('WPPIZZA_POST_TYPE', ''.WPPIZZA_SLUG.'');
define('WPPIZZA_TAXONOMY', ''.WPPIZZA_POST_TYPE.'_menu');
define('WPPIZZA_PATH', plugin_dir_path(__FILE__) );
define('WPPIZZA_URL', plugin_dir_url(__FILE__) );
add_action('widgets_init', create_function('', 'register_widget("'.WPPIZZA_CLASS.'");'));
/***************************************************************
*
* [uninstall]
*
***************************************************************/
register_uninstall_hook( __FILE__, 'wppizza_uninstall' );
/***************************************************************
*
* [deactivate]
*
***************************************************************/
register_deactivation_hook( __FILE__, 'wppizza_deactivate' );
/***remove cronjobs****/
function wppizza_deactivate() {
wp_clear_scheduled_hook( 'wppizza_cron' );
}
/***************************************************************
*
* [CLASS]
*
***************************************************************/
if ( ! class_exists( ''.WPPIZZA_CLASS.'' ) ) {
class WPPizza extends WP_Widget {
public $pluginVersion;
protected $pluginSlug;
protected $pluginLocale;
public $pluginOptions;
public $pluginSession;
protected $pluginName;
protected $pluginSlugCategoryTaxonomy;
protected $pluginNagNotice;
protected $pluginGateways;
protected $pluginUrl;
public $pluginOrderTable;
/********************************************************
*
*
* [Constructor]
*
*
********************************************************/
function __construct() {
/**init constants***/
$this->pluginVersion=''.WPPIZZA_VERSION.'';//increment in line with stable tag in readme and version above
$this->pluginName="".WPPIZZA_NAME."";
$this->pluginSlug="".WPPIZZA_SLUG."";//set also in uninstall when deleting options
$this->pluginSlugCategoryTaxonomy="".WPPIZZA_TAXONOMY."";//also on uninstall delete wppizza_children as well as widget
$this->pluginOrderTable="".WPPIZZA_SLUG."_orders";
$this->pluginLocale="".WPPIZZA_LOCALE."";
$this->pluginOptions = get_option(WPPIZZA_SLUG,0);
$this->pluginNagNotice=0;//default off->for use in updates to this plugin
$this->pluginPath=__FILE__;
/**to get the template paths, uri's and possible subdir and set vars accordingly**/
$pathDirUri=$this->wppizza_template_paths();
$this->pluginTemplateDir=$pathDirUri['template_dir'];/**to amend get_stylesheet_directory() according to whether wppizza subdir exists*/
$this->pluginTemplateUri=$pathDirUri['template_uri'];/**to amend get_stylesheet_directory_uri() according to whether wppizza subdir exists*/
$this->pluginLocateDir=$pathDirUri['locate_dir'];/**to add relevant subdir - if exists - to locate_template*/
/**blog charset*/
$this->blogCharset=get_bloginfo('charset');
/********************************************************************************************
set session per blogid when multisite and enabled to avoid having same cart
contents between different network sites (unless we want this)
*********************************************************************************************/
if(is_multisite() ){
$multisession=true;
/*get settings from parent blog for this**/
switch_to_blog(BLOG_ID_CURRENT_SITE);
$wppOptions=get_option('wppizza');
if(!$wppOptions['plugin_data']['wp_multisite_session_per_site']){
$multisession=false;
}
restore_current_blog();
global $blog_id;
if($multisession){
$this->pluginSession=$this->pluginSlug.''.$blog_id;
}else{
$this->pluginSession=$this->pluginSlug;
}
}else{
$this->pluginSession=$this->pluginSlug;
}
/**session name for user data for example such as address etc that keeps it's values across multisites**/
$this->pluginSessionGlobal=$this->pluginSlug.'Global';
/***************************************
classname and description
***************************************/
$widget_opts = array (
'classname' => WPPIZZA_CLASS,
'description' => __('A Pizza Restaurant Plugin', $this->pluginLocale)
);
$this->WP_Widget(false, $name=$this->pluginName, $widget_opts);
add_action('init', array($this, 'wppizza_load_plugin_textdomain'));
/**allow overwriting of pluginVars in seperate class*/
add_action('init', array( $this, 'wppizza_extend'),1);
/**add wpml . must run front and backend (ajax request)***/
add_action('init', array( $this, 'wppizza_wpml_localization'),99);
}
/*****************************************************************************************************************
*
*
* [widget functions - apparently these have to be in main plugin when calling "extends WP_Widget"/"widgets_init"]
* [althoug one can probably load them via includes - one day]
*
*
******************************************************************************************************************/
/*****************************************************
* load text domain on init.
******************************************************/
public function wppizza_load_plugin_textdomain(){
load_plugin_textdomain(WPPIZZA_LOCALE, false, dirname(plugin_basename( __FILE__ ) ) . '/lang' );
}
/*****************************************************
* Generates the administration form for the widget.
* @instance The array of keys and values for the widget.
******************************************************/
function form($instance) {
include(WPPIZZA_PATH.'views/widget-admin.php');
}
/*******************************************************
* Outputs the content of the widget.
* @args The array of form elements
* @instance
******************************************************/
function widget($args, $instance) {
require(WPPIZZA_PATH.'views/widget.php');
}
/*******************************************************
*
* set default and return options for widget
*
******************************************************/
private function wppizza_default_widget_settings(){
$defaults=array(
'title' => __("Shoppingcart", $this->pluginLocale),
'type' => 'cart',
'suppresstitle' => '',
'noheader' => '',
'width' => '',
'height' => '',
'openingtimes' => 'checked="checked"',
'orderinfo' => 'checked="checked"'
);
return $defaults;
}
/*******************************************************
*
* available main options to choose from in widget
*
******************************************************/
private function wppizza_type_options(){
$items['category']=__('Category Page', $this->pluginLocale);
$items['navigation']=__('Navigation', $this->pluginLocale);
$items['cart']=__('Cart', $this->pluginLocale);
$items['orderpage']=__('Orderpage', $this->pluginLocale);
$items['openingtimes']=__('Openingtimes', $this->pluginLocale);
$items['search']=__('Search', $this->pluginLocale);
return $items;
}
/****************************************************************
*
* [get/set Template Directories/Uri's. also check for subdir 'wppizza']
*
***************************************************************/
function wppizza_template_paths(){
$paths['template_dir']='';
$paths['template_uri']='';
$paths['locate_dir']='';
$dir=get_stylesheet_directory();
$uri=get_stylesheet_directory_uri();
if(is_dir($dir.'/'.WPPIZZA_SLUG)){
$paths['template_dir']=$dir.'/'.WPPIZZA_SLUG;
$paths['template_uri']=$uri.'/'.WPPIZZA_SLUG;
$paths['locate_dir']=WPPIZZA_SLUG.'/';
}else{
$paths['template_dir']=$dir;
$paths['template_uri']=$uri;
$paths['locate_dir']='';
}
return $paths;
}
/*******************************************************
*
*
* [set/save submitted user post data in session, exclude tips though ]
* [moved from actions to be available throughout]
*
******************************************************/
function wppizza_sessionise_userdata($postUserData,$orderFormOptions) {
if (!session_id()) {session_start();}
$params = array();
parse_str($postUserData, $params);
/**selects are zero indexed*/
foreach($orderFormOptions as $elmKey=>$elm){
if($elm['type']=='select' && isset($params[$elm['key']])){
foreach($elm['value'] as $a=>$b){
if($params[$elm['key']]==$b){
$params[$elm['key']]=''.$a.'';
}
}
}
}
/******************************************
[get entered data to re-populate input fields but loose irrelevant vars
********************************************/
/**empty first and start over**/
if(isset($_SESSION[$this->pluginSessionGlobal]['userdata'])){
unset($_SESSION[$this->pluginSessionGlobal]['userdata']);
}
foreach($orderFormOptions as $oForm){
if($oForm['key']!='ctips'){/**tips should not be in the global user session**/
if(isset($params[$oForm['key']])){
$_SESSION[$this->pluginSessionGlobal]['userdata'][$oForm['key']]=$params[$oForm['key']];
}
}
}
/***eliminate notice of undefined index userdata**/
if(!isset($_SESSION[$this->pluginSessionGlobal]['userdata'])){$_SESSION[$this->pluginSessionGlobal]['userdata']=array();}
/*also keep selected gateway in session*/
if(isset($_SESSION[$this->pluginSessionGlobal]['userdata']['gateway'])){
/**store previously selected in case we need to fall back to it**/
//$prevGwFallback=$_SESSION[$this->pluginSessionGlobal]['userdata']['gateway'];
/*unset session*/
unset($_SESSION[$this->pluginSessionGlobal]['userdata']['gateway']);
}
$selectedGateway=!empty($params['wppizza-gateway']) ? strtoupper(wppizza_validate_string($params['wppizza-gateway'])) : '';
/*reset session if not empty*/
if($selectedGateway!=''){
$_SESSION[$this->pluginSessionGlobal]['userdata']['gateway']=$selectedGateway;
}
/**allow filtering of session data**/
$_SESSION[$this->pluginSessionGlobal]['userdata'] = apply_filters('wppizza_filter_sessionise_userdata', $_SESSION[$this->pluginSessionGlobal]['userdata'],$params);
return $params;
}
/*********************************************************************************
*
* [WPML : make strings wpml compatible]
* only include if icl_translate exists
* only include once in admin to register strings (as it saves a ton of icl queries)
********************************************************************************/
function wppizza_wpml_localization(){
/*get the wpml'd order page*/
if($this->pluginOptions!=0) {
if(function_exists('icl_object_id')){
$this->pluginOptions['order']['orderpage']=icl_object_id($this->pluginOptions['order']['orderpage'],'page', true);
}
}
if(function_exists('icl_translate')){
if( is_admin() && ( !defined( 'DOING_AJAX' ) || !DOING_AJAX )){
require_once(WPPIZZA_PATH .'inc/wpml.inc.php');
}else{
require(WPPIZZA_PATH .'inc/wpml.inc.php');
}
}
}
function wppizza_wpml_localization_gateways(){
if(function_exists('icl_translate')){/*only if wpml*/
if( is_admin() && ( !defined( 'DOING_AJAX' ) || !DOING_AJAX )){
require_once(WPPIZZA_PATH .'inc/wpml.gateways.inc.php');
}else{
require(WPPIZZA_PATH .'inc/wpml.gateways.inc.php');
}
}
}
/*******************************************************
*
* [EXTEND : class must start with WPPIZZA_EXTEND_]
*
******************************************************/
function wppizza_extend() {
$allClasses=get_declared_classes();
$wppizzaExtend=array();
foreach ($allClasses AS $oe=>$class){
$chkStr=substr($class,0,15);
if($chkStr=='WPPIZZA_EXTEND_'){
$wppizzaExtend[$oe]=new $class;
foreach($wppizzaExtend[$oe] as $k=>$v){
$this->$k=$v;
}
}
}
}
}
/*=======================================================================================*/
/*=========================load actions and gateways class===============================*/
/*=======================================================================================*/
add_action('plugins_loaded', 'wppizza_all_actions');
function wppizza_all_actions() {
require_once(WPPIZZA_PATH .'classes/wppizza.actions.inc.php');
$WPPIZZA_ACTIONS=new WPPIZZA_ACTIONS();
}
add_action('plugins_loaded', 'wppizza_get_gateways');
function wppizza_get_gateways() {
require_once(WPPIZZA_PATH .'classes/wppizza.gateways.inc.php');
$WPPIZZA_GATEWAYS=new WPPIZZA_GATEWAYS();
}
/*=======================================================================================*/
/*=======================================================================================*/
/*=======================================================================================*/
}
?>