|
1
|
|
|
<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
2
|
|
|
|
|
3
|
|
|
/* Check if file is include. No direct access possible with file url */ |
|
4
|
|
|
if ( !defined( 'WPSHOP_VERSION' ) ) { |
|
5
|
|
|
die( __('Access is not allowed by this way', 'wpshop') ); |
|
6
|
|
|
} |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Plugin tools librairies file. |
|
10
|
|
|
* |
|
11
|
|
|
* This file contains the different common tools used in all the plugin |
|
12
|
|
|
* @author Eoxia <[email protected]> |
|
13
|
|
|
* @version 1.1 |
|
14
|
|
|
* @package wpshop |
|
15
|
|
|
* @subpackage librairies |
|
16
|
|
|
*/ |
|
17
|
|
|
class wpshop_display { |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Returns the header display of a classical HTML page. |
|
21
|
|
|
* |
|
22
|
|
|
* @see afficherFinPage |
|
23
|
|
|
* |
|
24
|
|
|
* @param string $pageTitle Title of the page. |
|
25
|
|
|
* @param string $pageIcon Path of the icon. |
|
26
|
|
|
* @param string $iconTitle Title attribute of the icon. |
|
27
|
|
|
* @param string $iconAlt Alt attribute of the icon. |
|
28
|
|
|
* @param boolean $hasAddButton Define if there must be a "add" button for this page |
|
29
|
|
|
* @param string $actionInformationMessage A message to display in case of action is send |
|
30
|
|
|
* |
|
31
|
|
|
* @return string Html code composing the page header |
|
32
|
|
|
*/ |
|
33
|
|
|
public static function displayPageHeader($pageTitle, $pageIcon, $iconTitle, $iconAlt, $hasAddButton = true, $addButtonLink = '', $actionInformationMessage = '', $current_page_slug = ''){ |
|
34
|
|
|
include(WPSHOP_TEMPLATES_DIR.'admin/admin_page_header.tpl.php'); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Returns the end of a classical page |
|
39
|
|
|
* |
|
40
|
|
|
* @see displayPageHeader |
|
41
|
|
|
* |
|
42
|
|
|
* @return string Html code composing the page footer |
|
43
|
|
|
*/ |
|
44
|
|
|
public static function displayPageFooter($formActionButton){ |
|
45
|
|
|
include(WPSHOP_TEMPLATES_DIR.'admin/admin_page_footer.tpl.php'); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Return The complete output page code |
|
50
|
|
|
* |
|
51
|
|
|
* @return string The complete html page output |
|
52
|
|
|
*/ |
|
53
|
|
|
public static function display_page(){ |
|
54
|
|
|
|
|
55
|
|
|
$pageAddButton = false; |
|
56
|
|
|
$pageMessage = $addButtonLink = $pageFormButton = $pageIcon = $pageIconTitle = $pageIconAlt = $objectType = ''; |
|
57
|
|
|
$outputType = 'listing'; |
|
58
|
|
|
$objectToEdit = isset($_REQUEST['id']) ? wpshop_tools::varSanitizer($_REQUEST['id']) : ''; |
|
59
|
|
|
$pageSlug = isset($_REQUEST['page']) ? wpshop_tools::varSanitizer($_REQUEST['page']) : ''; |
|
60
|
|
|
$action = isset($_REQUEST['action']) ? wpshop_tools::varSanitizer($_REQUEST['action']) : ''; |
|
61
|
|
|
|
|
62
|
|
|
/* Select the content to add to the page looking for the parameter */ |
|
63
|
|
|
switch($pageSlug){ |
|
64
|
|
|
case WPSHOP_URL_SLUG_ATTRIBUTE_LISTING: |
|
65
|
|
|
$objectType = new wpshop_attributes(); |
|
66
|
|
|
$current_user_can_edit = current_user_can('wpshop_edit_attributes'); |
|
67
|
|
|
$current_user_can_add = current_user_can('wpshop_add_attributes'); |
|
68
|
|
|
$current_user_can_delete = current_user_can('wpshop_delete_attributes'); |
|
69
|
|
|
if(current_user_can('wpshop_add_attributes')){ |
|
70
|
|
|
$pageAddButton = true; |
|
71
|
|
|
} |
|
72
|
|
|
break; |
|
73
|
|
|
case WPSHOP_URL_SLUG_ATTRIBUTE_SET_LISTING: |
|
74
|
|
|
$objectType = new wpshop_attributes_set(); |
|
75
|
|
|
$current_user_can_edit = current_user_can('wpshop_edit_attribute_set'); |
|
76
|
|
|
$current_user_can_add = current_user_can('wpshop_add_attribute_set'); |
|
77
|
|
|
$current_user_can_delete = current_user_can('wpshop_delete_attribute_set'); |
|
78
|
|
|
if(current_user_can('wpshop_add_attribute_set')){ |
|
79
|
|
|
$pageAddButton = true; |
|
80
|
|
|
} |
|
81
|
|
|
break; |
|
82
|
|
|
case WPSHOP_URL_SLUG_SHORTCODES: |
|
83
|
|
|
$pageAddButton = false; |
|
84
|
|
|
$current_user_can_edit = false; |
|
85
|
|
|
$objectType = new wps_shortcodes_ctr(); |
|
86
|
|
|
break; |
|
87
|
|
|
case WPSHOP_URL_SLUG_MESSAGES: |
|
88
|
|
|
$pageAddButton = false; |
|
89
|
|
|
$objectType = new wpshop_messages(); |
|
90
|
|
|
$current_user_can_edit = true; |
|
91
|
|
|
$mid = !empty( $_GET['mid'] ) ? sanitize_text_field( $_GET['mid'] ) : ''; |
|
92
|
|
|
if(!empty($mid)){ |
|
93
|
|
|
$action = 'edit'; |
|
94
|
|
|
} |
|
95
|
|
|
break; |
|
96
|
|
|
default:{ |
|
97
|
|
|
$pageTitle = sprintf(__('You have to add this page into %s at line %s', 'wpshop'), __FILE__, (__LINE__ - 4)); |
|
98
|
|
|
$pageAddButton = false; |
|
99
|
|
|
} |
|
100
|
|
|
break; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
if($objectType != ''){ |
|
104
|
|
|
if(($action != '') && ((($action == 'edit') && $current_user_can_edit) || (($action == 'add') && $current_user_can_add) || (($action == 'delete') && $current_user_can_delete))){ |
|
|
|
|
|
|
105
|
|
|
$outputType = 'adding'; |
|
106
|
|
|
} |
|
107
|
|
|
$objectType->elementAction(); |
|
108
|
|
|
|
|
109
|
|
|
$pageIcon = self::getPageIconInformation('path', $objectType); |
|
110
|
|
|
$pageIconTitle = self::getPageIconInformation('title', $objectType); |
|
111
|
|
|
$pageIconAlt = self::getPageIconInformation('alt', $objectType); |
|
112
|
|
|
|
|
113
|
|
|
if($outputType == 'listing'){ |
|
114
|
|
|
$pageContent = $objectType->elementList(); |
|
115
|
|
|
} |
|
116
|
|
|
elseif($outputType == 'adding'){ |
|
117
|
|
|
$pageAddButton = false; |
|
118
|
|
|
|
|
119
|
|
|
$pageFormButton = $objectType->getPageFormButton($objectToEdit); |
|
|
|
|
|
|
120
|
|
|
|
|
121
|
|
|
$pageContent = $objectType->elementEdition($objectToEdit); |
|
|
|
|
|
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
$pageTitle = $objectType->pageTitle(); |
|
125
|
|
|
$pageMessage = $objectType->pageMessage; |
|
126
|
|
|
if ( in_array( $objectType->getEditionSlug(), array(WPSHOP_URL_SLUG_ATTRIBUTE_LISTING, WPSHOP_URL_SLUG_ATTRIBUTE_SET_LISTING) ) ) { |
|
127
|
|
|
$addButtonLink = admin_url('admin.php?page=' . $objectType->getEditionSlug() . '&action=add'); |
|
128
|
|
|
} |
|
129
|
|
|
else { |
|
130
|
|
|
$addButtonLink = admin_url('edit.php?post_type='.WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES.'&page=' . $objectType->getEditionSlug() . '&action=add'); |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/* Page content header */ |
|
135
|
|
|
wpshop_display::displayPageHeader($pageTitle, $pageIcon, $pageIconTitle, $pageIconAlt, $pageAddButton, $addButtonLink, $pageMessage, $pageSlug); |
|
|
|
|
|
|
136
|
|
|
|
|
137
|
|
|
/* Page content */ |
|
138
|
|
|
echo $pageContent; |
|
|
|
|
|
|
139
|
|
|
|
|
140
|
|
|
/* Page content footer */ |
|
141
|
|
|
wpshop_display::displayPageFooter($pageFormButton); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Define the wat to display admin page: tabs shape or bloc shape |
|
146
|
|
|
* |
|
147
|
|
|
* @param array $content |
|
148
|
|
|
* @param string $output_type The type of output for the |
|
149
|
|
|
* |
|
150
|
|
|
* @return string The output builded from selected type |
|
151
|
|
|
*/ |
|
152
|
|
|
public static function custom_page_output_builder($content, $output_type='tab') { |
|
153
|
|
|
$output_custom_layout = ''; |
|
154
|
|
|
|
|
155
|
|
|
switch ( $output_type ) { |
|
156
|
|
|
case 'separated_bloc': |
|
157
|
|
|
foreach ( $content as $element_type => $element_type_details ) { |
|
158
|
|
|
$output_custom_layout.=' |
|
159
|
|
|
<div class="wpshop_separated_bloc wpshop_separated_bloc_'.$element_type.'" >'; |
|
160
|
|
|
foreach ( $element_type_details as $element_type_key => $element_type_content ) { |
|
161
|
|
|
$output_custom_layout.=' |
|
162
|
|
|
<div class="wpshop_admin_box wpshop_admin_box_'.$element_type.' wpshop_admin_box_'.$element_type.'_'.$element_type_key.'" > |
|
163
|
|
|
<h3>' . $element_type_content['title'] . '</h3>' . $element_type_content['content'] . ' |
|
164
|
|
|
</div>'; |
|
165
|
|
|
} |
|
166
|
|
|
$output_custom_layout.=' |
|
167
|
|
|
</div>'; |
|
168
|
|
|
} |
|
169
|
|
|
break; |
|
170
|
|
|
case 'tab': |
|
171
|
|
|
$tab_list=$tab_content_list=''; |
|
172
|
|
|
foreach ( $content as $element_type => $element_type_details ) { |
|
173
|
|
|
foreach ( $element_type_details as $element_type_key => $element_type_content ) { |
|
174
|
|
|
$tab_list.=' |
|
175
|
|
|
<li><a href="#wpshop_'.$element_type.'_'.$element_type_key.'" >'.$element_type_content['title'].'</a></li>'; |
|
176
|
|
|
$tab_content_list.=' |
|
177
|
|
|
<div id="wpshop_'.$element_type.'_'.$element_type_key.'" class="wpshop_admin_box wpshop_admin_box_'.$element_type.' wpshop_admin_box_'.$element_type.'_'.$element_type_key.'" >'.$element_type_content['content'].' |
|
178
|
|
|
</div>'; |
|
179
|
|
|
} |
|
180
|
|
|
} |
|
181
|
|
|
$output_custom_layout.=' |
|
182
|
|
|
<div id="wpshopFormManagementContainer" class="wpshop_tabs wpshop_full_page_tabs wpshop_'.$element_type.'_tabs" > |
|
|
|
|
|
|
183
|
|
|
<ul>' . $tab_list . '</ul>' . $tab_content_list . ' |
|
184
|
|
|
</div>'; |
|
185
|
|
|
break; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
return $output_custom_layout; |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* Return a complete html table with header, body and content |
|
193
|
|
|
* |
|
194
|
|
|
* @param string $tableId The unique identifier of the table in the document |
|
195
|
|
|
* @param array $tableTitles An array with the different element to put into the table's header and footer |
|
196
|
|
|
* @param array $tableRows An array with the different value to put into the table's body |
|
197
|
|
|
* @param array $tableClasses An array with the different class to affect to table rows and cols |
|
198
|
|
|
* @param array $tableRowsId An array with the different identifier for table lines |
|
199
|
|
|
* @param string $tableSummary A summary for the table |
|
200
|
|
|
* @param boolean $withFooter Allow to define if the table must be create with a footer or not |
|
201
|
|
|
* |
|
202
|
|
|
* @return string $table The html code of the table to output |
|
203
|
|
|
*/ |
|
204
|
|
|
public static function getTable($tableId, $tableTitles, $tableRows, $tableClasses, $tableRowsId, $tableSummary = '', $withFooter = true){ |
|
|
|
|
|
|
205
|
|
|
$tableTitleBar = $tableBody = ''; |
|
206
|
|
|
|
|
207
|
|
|
/* Create the header and footer row */ |
|
208
|
|
|
for($i=0; $i<count($tableTitles); $i++){ |
|
|
|
|
|
|
209
|
|
|
$tableTitleBar .= ' |
|
210
|
|
|
<th class="' . $tableClasses[$i] . '" scope="col" >' . $tableTitles[$i] . '</th>'; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
/* Create each table row */ |
|
214
|
|
|
for($lineNumber=0; $lineNumber<count($tableRows); $lineNumber++){ |
|
|
|
|
|
|
215
|
|
|
$tableRow = $tableRows[$lineNumber]; |
|
216
|
|
|
$tableBody .= ' |
|
217
|
|
|
<tr id="' . $tableRowsId[$lineNumber] . '" class="tableRow" >'; |
|
218
|
|
|
for($i=0; $i<count($tableRow); $i++){ |
|
|
|
|
|
|
219
|
|
|
$tableBody .= ' |
|
220
|
|
|
<td class="' . $tableClasses[$i] . ' ' . $tableRow[$i]['class'] . '" >' . $tableRow[$i]['value'] . '</td>'; |
|
221
|
|
|
} |
|
222
|
|
|
$tableBody .= ' |
|
223
|
|
|
</tr>'; |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
/* Create the table output */ |
|
227
|
|
|
$table = ' |
|
228
|
|
|
<table id="' . $tableId . '" cellspacing="0" cellpadding="0" class="widefat post fixed" >'; |
|
229
|
|
|
if($tableTitleBar != ''){ |
|
230
|
|
|
$table .= ' |
|
231
|
|
|
<thead> |
|
232
|
|
|
<tr class="tableTitleHeader" >' . $tableTitleBar . ' |
|
233
|
|
|
</tr> |
|
234
|
|
|
</thead>'; |
|
235
|
|
|
if($withFooter){ |
|
236
|
|
|
$table .= ' |
|
237
|
|
|
<tfoot> |
|
238
|
|
|
<tr class="tableTitleFooter" >' . $tableTitleBar . ' |
|
239
|
|
|
</tr> |
|
240
|
|
|
</tfoot>'; |
|
241
|
|
|
} |
|
242
|
|
|
} |
|
243
|
|
|
$table .= ' |
|
244
|
|
|
<tbody>' . $tableBody . ' |
|
245
|
|
|
</tbody> |
|
246
|
|
|
</table>'; |
|
247
|
|
|
|
|
248
|
|
|
return $table; |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
/** |
|
252
|
|
|
* Define the icon informations for the page |
|
253
|
|
|
* |
|
254
|
|
|
* @param string $infoType The information type we want to get Could be path / alt / title |
|
255
|
|
|
* |
|
256
|
|
|
* @return string $pageIconInformation The information to output in the page |
|
257
|
|
|
*/ |
|
258
|
|
|
public static function getPageIconInformation($infoType, $object){ |
|
259
|
|
|
switch($infoType){ |
|
260
|
|
|
case 'path': |
|
261
|
|
|
$pageIconInformation = $object->pageIcon; |
|
262
|
|
|
break; |
|
263
|
|
|
case 'alt': |
|
264
|
|
|
case 'title': |
|
265
|
|
|
default: |
|
266
|
|
|
$pageIconInformation = $object->pageTitle(); |
|
267
|
|
|
break; |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
return $pageIconInformation; |
|
271
|
|
|
} |
|
272
|
|
|
|
|
273
|
|
|
/** |
|
274
|
|
|
* Check if the templates file are available from the current theme. If not present return the default templates files |
|
275
|
|
|
* |
|
276
|
|
|
* @param string $file_name The file name to check if exists in current theme |
|
277
|
|
|
* @param string $dir_name Optionnal The directory name of the file to check Default : wpshop |
|
278
|
|
|
* |
|
279
|
|
|
* @return string $file_path The good filepath to include |
|
280
|
|
|
*/ |
|
281
|
|
|
public static function get_template_file($file_name, $default_dir = WPSHOP_TEMPLATES_DIR, $dir_name = 'wpshop', $usage_type = 'include', $check_only_custom = false){ |
|
282
|
|
|
$file_path = ''; |
|
283
|
|
|
$the_file = $dir_name . '/' . $file_name; |
|
284
|
|
|
|
|
285
|
|
|
if (is_file(get_stylesheet_directory() . '/' . $the_file)) { |
|
286
|
|
|
$default_dir = str_replace(WP_CONTENT_DIR, WP_CONTENT_URL, get_stylesheet_directory()); |
|
287
|
|
|
if($usage_type == 'include'){ |
|
288
|
|
|
$default_dir = get_stylesheet_directory(); |
|
289
|
|
|
} |
|
290
|
|
|
$file_path = $default_dir . '/' . $the_file; |
|
291
|
|
|
} |
|
292
|
|
|
else if ( !$check_only_custom ) { |
|
293
|
|
|
$file_path = $default_dir . $the_file; |
|
294
|
|
|
} |
|
295
|
|
|
|
|
296
|
|
|
return $file_path; |
|
297
|
|
|
} |
|
298
|
|
|
|
|
299
|
|
|
/** |
|
300
|
|
|
* Check if the current shop use the first method for templates. One file per element to display |
|
301
|
|
|
* |
|
302
|
|
|
* @param string $template_part The part to take display for, will be usefull to check what file take in care if there were a file in old method |
|
303
|
|
|
* @param string $default_template_dirThe part of website to check template for. Possible values : wpshop / admin |
|
|
|
|
|
|
304
|
|
|
* |
|
305
|
|
|
* @return array First index represent if there is a file for old version support, Second index represent the file to get for support old version |
|
306
|
|
|
*/ |
|
307
|
|
|
public static function check_way_for_template($template_part, $default_template_dir = 'wpshop') { |
|
308
|
|
|
$old_file_to_take_care = false; |
|
309
|
|
|
$old_file_to_take_care_url = null; |
|
|
|
|
|
|
310
|
|
|
|
|
311
|
|
|
/** Directory containing custom templates */ |
|
312
|
|
|
$custom_template_part = get_stylesheet_directory() . '/' . $default_template_dir . '/'; |
|
313
|
|
|
|
|
314
|
|
|
/** Let support the old way of template managing */ |
|
315
|
|
|
switch ( $template_part ) { |
|
316
|
|
|
case 'category_mini_list': |
|
317
|
|
|
$old_file_to_take_care_url = 'category-mini-list.tpl.php'; |
|
318
|
|
|
if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
319
|
|
|
$old_file_to_take_care = true; |
|
320
|
|
|
endif; |
|
321
|
|
|
break; |
|
322
|
|
|
case 'category_mini_grid': |
|
323
|
|
|
$old_file_to_take_care_url = 'category-mini-grid.tpl.php'; |
|
324
|
|
|
if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
325
|
|
|
$old_file_to_take_care = true; |
|
326
|
|
|
endif; |
|
327
|
|
|
break; |
|
328
|
|
|
case 'product_complete_tpl': |
|
329
|
|
|
$old_file_to_take_care_url = 'product.tpl.php'; |
|
330
|
|
|
if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
331
|
|
|
$old_file_to_take_care = true; |
|
332
|
|
|
endif; |
|
333
|
|
|
break; |
|
334
|
|
|
case 'product_mini_list': |
|
335
|
|
|
$old_file_to_take_care_url = 'product-mini-list.tpl.php'; |
|
336
|
|
|
if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
337
|
|
|
$old_file_to_take_care = true; |
|
338
|
|
|
endif; |
|
339
|
|
|
break; |
|
340
|
|
|
case 'product_mini_grid': |
|
341
|
|
|
$old_file_to_take_care_url = 'product-mini-grid.tpl.php'; |
|
342
|
|
|
if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
343
|
|
|
$old_file_to_take_care = true; |
|
344
|
|
|
endif; |
|
345
|
|
|
break; |
|
346
|
|
|
case 'product_listing_sorting': |
|
347
|
|
|
$old_file_to_take_care_url = 'product_listing_sorting.tpl.php'; |
|
348
|
|
|
if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
349
|
|
|
$old_file_to_take_care = true; |
|
350
|
|
|
endif; |
|
351
|
|
|
break; |
|
352
|
|
|
case 'unavailable_product_button': |
|
353
|
|
|
$old_file_to_take_care_url = 'not_available_product_button.tpl.php'; |
|
354
|
|
|
if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
355
|
|
|
$old_file_to_take_care = true; |
|
356
|
|
|
endif; |
|
357
|
|
|
break; |
|
358
|
|
|
case 'add_to_cart_button': |
|
359
|
|
|
$old_file_to_take_care_url = 'available_product_button.tpl.php'; |
|
360
|
|
|
if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
361
|
|
|
$old_file_to_take_care = true; |
|
362
|
|
|
endif; |
|
363
|
|
|
break; |
|
364
|
|
|
case 'ask_quotation_button': |
|
365
|
|
|
$old_file_to_take_care_url = 'quotation_button.tpl.php'; |
|
366
|
|
|
if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
367
|
|
|
$old_file_to_take_care = true; |
|
368
|
|
|
endif; |
|
369
|
|
|
break; |
|
370
|
|
|
case 'mini_cart_content': |
|
371
|
|
|
$old_file_to_take_care_url = 'wpshop_mini_cart.tpl.php'; |
|
372
|
|
|
if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
373
|
|
|
$old_file_to_take_care = true; |
|
374
|
|
|
endif; |
|
375
|
|
|
break; |
|
376
|
|
|
case 'product_is_new_sticker': |
|
377
|
|
|
$old_file_to_take_care_url = 'product-is-new.tpl.php'; |
|
378
|
|
|
if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
379
|
|
|
$old_file_to_take_care = true; |
|
380
|
|
|
endif; |
|
381
|
|
|
break; |
|
382
|
|
|
case 'product_is_featured_sticker': |
|
383
|
|
|
$old_file_to_take_care_url = 'product-is-featured.tpl.php'; |
|
384
|
|
|
if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
385
|
|
|
$old_file_to_take_care = true; |
|
386
|
|
|
endif; |
|
387
|
|
|
break; |
|
388
|
|
|
case 'product_attribute_container': |
|
389
|
|
|
$old_file_to_take_care_url = 'product-attribute-front-display-main-container.tpl.php'; |
|
390
|
|
|
if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
391
|
|
|
$old_file_to_take_care = true; |
|
392
|
|
|
endif; |
|
393
|
|
|
break; |
|
394
|
|
|
case 'product_attribute_tabs': |
|
395
|
|
|
$old_file_to_take_care_url = 'product-attribute-front-display-tabs.tpl.php'; |
|
396
|
|
|
if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
397
|
|
|
$old_file_to_take_care = true; |
|
398
|
|
|
endif; |
|
399
|
|
|
break; |
|
400
|
|
|
case 'product_attribute_tabs_detail': |
|
401
|
|
|
$old_file_to_take_care_url = 'product-attribute-front-display-tabs-content.tpl.php'; |
|
402
|
|
|
if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
403
|
|
|
$old_file_to_take_care = true; |
|
404
|
|
|
endif; |
|
405
|
|
|
break; |
|
406
|
|
|
case 'product_attachment_picture_galery': |
|
407
|
|
|
$old_file_to_take_care_url = 'product_picture_galery.tpl.php'; |
|
408
|
|
|
if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
409
|
|
|
$old_file_to_take_care = true; |
|
410
|
|
|
endif; |
|
411
|
|
|
break; |
|
412
|
|
|
case 'product_attachment_galery': |
|
413
|
|
|
$old_file_to_take_care_url = 'product_document_library.tpl.php'; |
|
414
|
|
|
if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
415
|
|
|
$old_file_to_take_care = true; |
|
416
|
|
|
endif; |
|
417
|
|
|
break; |
|
418
|
|
|
case 'product_attachment_item_picture': |
|
419
|
|
|
$old_file_to_take_care_url = 'product_attachment_picture_line.tpl.php'; |
|
420
|
|
|
if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
421
|
|
|
$old_file_to_take_care = true; |
|
422
|
|
|
endif; |
|
423
|
|
|
break; |
|
424
|
|
|
case 'product_attachment_item_document': |
|
425
|
|
|
$old_file_to_take_care_url = 'product_attachment_document_line.tpl.php'; |
|
426
|
|
|
if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
427
|
|
|
$old_file_to_take_care = true; |
|
428
|
|
|
endif; |
|
429
|
|
|
break; |
|
430
|
|
|
case 'product_added_to_cart_message': |
|
431
|
|
|
$old_file_to_take_care_url = 'product_added_to_cart_message.tpl.php'; |
|
432
|
|
|
if ( is_file($custom_template_part . $old_file_to_take_care_url ) ) : |
|
433
|
|
|
$old_file_to_take_care = true; |
|
434
|
|
|
endif; |
|
435
|
|
|
break; |
|
436
|
|
|
|
|
437
|
|
|
|
|
438
|
|
|
case 'product_attribute_display': |
|
439
|
|
|
case 'product_attribute_unit': |
|
440
|
|
|
case 'product_attribute_value_internal': |
|
441
|
|
|
default: |
|
442
|
|
|
$old_file_to_take_care = false; |
|
443
|
|
|
$old_file_to_take_care_url = null; |
|
444
|
|
|
break; |
|
445
|
|
|
} |
|
446
|
|
|
|
|
447
|
|
|
return array($old_file_to_take_care, $old_file_to_take_care_url); |
|
448
|
|
|
} |
|
449
|
|
|
|
|
450
|
|
|
/** |
|
451
|
|
|
* Return a template already fiiled with the good element to be displayed |
|
452
|
|
|
* |
|
453
|
|
|
* @param string $template_part The template element we want to display |
|
454
|
|
|
* @param array $template_part_component The different element to put into template to fill it before display |
|
455
|
|
|
* @param array $extras_args Optionnal Allows to define some parameters to spot a specific template for example |
|
456
|
|
|
* @param string $default_template_dir Optionnal The part of shop where to display the given template element |
|
457
|
|
|
* |
|
458
|
|
|
* @return string The template to display |
|
459
|
|
|
*/ |
|
460
|
|
|
public static function display_template_element($template_part, $template_part_component, $extras_args = array(), $default_template_dir = 'wpshop') { |
|
461
|
|
|
/** Set the template element to return by default before checking if custom exists in order to be sure to return something */ |
|
462
|
|
|
$default_template_element = wpshop_display::check_template_to_display( 'default', $template_part, $extras_args, $default_template_dir ); |
|
463
|
|
|
|
|
464
|
|
|
/** Check in custom template if there is not a custom element to display for current */ |
|
465
|
|
|
$custom_template_element = wpshop_display::check_template_to_display( 'custom', $template_part, $extras_args, $default_template_dir ); |
|
466
|
|
|
$tpl_element_to_return = !empty($custom_template_element) ? $custom_template_element : $default_template_element; |
|
467
|
|
|
|
|
468
|
|
|
$template_part_component = apply_filters( 'wps_filter_display_' . $template_part, $template_part_component, $extras_args, $default_template_dir ); |
|
469
|
|
|
|
|
470
|
|
|
return self::feed_template($tpl_element_to_return, $template_part_component); |
|
471
|
|
|
} |
|
472
|
|
|
|
|
473
|
|
|
/** |
|
474
|
|
|
* Load the different template file and store all template elements into an array and in a super global variable |
|
475
|
|
|
*/ |
|
476
|
|
|
function load_template() { |
|
|
|
|
|
|
477
|
|
|
/* Load template component */ |
|
478
|
|
|
/* Get default admin template */ |
|
479
|
|
|
require_once(WPSHOP_TEMPLATES_DIR . 'admin/main_elements.tpl.php'); |
|
480
|
|
|
$wpshop_template['admin']['default'] = ($tpl_element);unset($tpl_element); |
|
|
|
|
|
|
481
|
|
|
/* Get custom admin template */ |
|
482
|
|
View Code Duplication |
if ( is_file(get_stylesheet_directory() . '/admin/main_elements.tpl.php') ) { |
|
|
|
|
|
|
483
|
|
|
require_once(get_stylesheet_directory() . '/admin/main_elements.tpl.php'); |
|
484
|
|
|
if (!empty($tpl_element)) |
|
485
|
|
|
$wpshop_template['admin']['custom'] = ($tpl_element);unset($tpl_element); |
|
486
|
|
|
} |
|
487
|
|
View Code Duplication |
if ( is_file(get_stylesheet_directory() . '/admin/wpshop_elements_template.tpl.php') ) { |
|
|
|
|
|
|
488
|
|
|
require_once(get_stylesheet_directory() . '/admin/wpshop_elements_template.tpl.php'); |
|
489
|
|
|
if (!empty($tpl_element)) |
|
490
|
|
|
$wpshop_template['admin']['custom'] = ($tpl_element);unset($tpl_element); |
|
491
|
|
|
} |
|
492
|
|
|
/* Get default frontend template */ |
|
493
|
|
|
require_once(WPSHOP_TEMPLATES_DIR . 'wpshop/main_elements.tpl.php'); |
|
494
|
|
|
$wpshop_template['wpshop']['default'] = ($tpl_element);unset($tpl_element); |
|
495
|
|
|
/* Get custom frontend template */ |
|
496
|
|
View Code Duplication |
if ( is_file(get_stylesheet_directory() . '/wpshop/main_elements.tpl.php') ) { |
|
|
|
|
|
|
497
|
|
|
require_once(get_stylesheet_directory() . '/wpshop/main_elements.tpl.php'); |
|
498
|
|
|
if (!empty($tpl_element)) |
|
499
|
|
|
$wpshop_template['wpshop']['custom'] = ($tpl_element);unset($tpl_element); |
|
500
|
|
|
} |
|
501
|
|
View Code Duplication |
if ( is_file(get_stylesheet_directory() . '/wpshop/wpshop_elements_template.tpl.php') ) { |
|
|
|
|
|
|
502
|
|
|
require_once(get_stylesheet_directory() . '/wpshop/wpshop_elements_template.tpl.php'); |
|
503
|
|
|
if (!empty($tpl_element)) |
|
504
|
|
|
$wpshop_template['wpshop']['custom'] = ($tpl_element);unset($tpl_element); |
|
505
|
|
|
} |
|
506
|
|
|
foreach ( $wpshop_template as $site_side => $types ) { |
|
507
|
|
|
foreach ( $types as $type => $tpl_component ) { |
|
508
|
|
|
foreach ( $tpl_component as $tpl_key => $tpl_content ) { |
|
509
|
|
|
$wpshop_template[$site_side][$type][$tpl_key] = str_replace(" |
|
510
|
|
|
", '', $tpl_content); |
|
511
|
|
|
} |
|
512
|
|
|
} |
|
513
|
|
|
} |
|
514
|
|
|
|
|
515
|
|
|
$wpshop_template = apply_filters( 'wpshop_custom_template', $wpshop_template); |
|
516
|
|
|
|
|
517
|
|
|
DEFINE( 'WPSHOP_TEMPLATE', serialize($wpshop_template) ); |
|
518
|
|
|
} |
|
519
|
|
|
|
|
520
|
|
|
/** |
|
521
|
|
|
* Read a given array defining template in order to add them to the existing templates |
|
522
|
|
|
* |
|
523
|
|
|
* @param array $tpl_element The template to add to existing |
|
524
|
|
|
* @param array $templates Exsiting templates |
|
525
|
|
|
* |
|
526
|
|
|
* @return array The new array with all elment, internal and module templates |
|
527
|
|
|
*/ |
|
528
|
|
|
public static function add_modules_template_to_internal( $tpl_element, $templates ) { |
|
529
|
|
|
if ( !empty($tpl_element) ) { |
|
530
|
|
|
foreach ( $tpl_element as $template_part => $template_part_content) { |
|
531
|
|
|
if ( !empty($template_part_content) && is_array($template_part_content) ) { |
|
532
|
|
View Code Duplication |
foreach ( $template_part_content as $template_type => $template_type_content) { |
|
|
|
|
|
|
533
|
|
|
foreach ( $template_type_content as $template_key => $template) { |
|
534
|
|
|
$templates[$template_part][$template_type][$template_key] = $template; |
|
535
|
|
|
} |
|
536
|
|
|
} |
|
537
|
|
|
} |
|
538
|
|
|
} |
|
539
|
|
|
} |
|
540
|
|
|
|
|
541
|
|
|
return $templates; |
|
542
|
|
|
} |
|
543
|
|
|
|
|
544
|
|
|
/** |
|
545
|
|
|
* Check in the different defined template which ne to take for current template to display |
|
546
|
|
|
* |
|
547
|
|
|
* @param string $part The part of shop where to display the given template element |
|
548
|
|
|
* @param string $template_part The template element we want to display |
|
549
|
|
|
* @param array $extras_args Allows to define some parameters to spot a specific template for example |
|
550
|
|
|
* |
|
551
|
|
|
* @return string The good template to take in care, regarding on the given parameters |
|
552
|
|
|
*/ |
|
553
|
|
|
public static function check_template_to_display( $part, $template_part, $extras_args, $default_template_dir ) { |
|
554
|
|
|
$tpl_element_to_return = ''; |
|
555
|
|
|
|
|
556
|
|
|
/** Get the defined template */ |
|
557
|
|
|
$template = defined("WPSHOP_TEMPLATE") ? unserialize(WPSHOP_TEMPLATE) : array(); |
|
558
|
|
|
|
|
559
|
|
|
if ( !empty($extras_args['type']) && !empty($extras_args['id']) && !empty( $template[$default_template_dir][$part]) && !empty($extras_args['page']) && !empty( $template[$default_template_dir][$part][$extras_args['page']] ) && !empty( $template[$default_template_dir][$part][$extras_args['page']][$extras_args['type']]) && !empty( $template[$default_template_dir][$part][$extras_args['page']][$extras_args['type']][$extras_args['id']] ) && !empty( $template[$default_template_dir][$part][$extras_args['page']][$extras_args['type']][$extras_args['id']][$template_part] ) ) { |
|
560
|
|
|
$tpl_element_to_return = $template[$default_template_dir][$part][$extras_args['page']][$extras_args['type']][$extras_args['id']][$template_part]; |
|
561
|
|
|
} |
|
562
|
|
|
elseif ( !empty($extras_args['type']) && !empty($extras_args['id']) && !empty( $template[$default_template_dir][$part][$extras_args['type']]) && !empty( $template[$default_template_dir][$part][$extras_args['type']][$extras_args['id']] ) && !empty( $template[$default_template_dir][$part][$extras_args['type']][$extras_args['id']][$template_part] ) ) { |
|
563
|
|
|
$tpl_element_to_return = $template[$default_template_dir][$part][$extras_args['type']][$extras_args['id']][$template_part]; |
|
564
|
|
|
} |
|
565
|
|
|
/** Check if the file have been duplicated into theme directory for customization */ |
|
566
|
|
|
elseif ( !empty( $template[$default_template_dir][$part] ) && !empty( $template[$default_template_dir][$part][$template_part] ) ) { |
|
567
|
|
|
$tpl_element_to_return = $template[$default_template_dir][$part][$template_part]; |
|
568
|
|
|
} |
|
569
|
|
|
|
|
570
|
|
|
return $tpl_element_to_return; |
|
571
|
|
|
} |
|
572
|
|
|
|
|
573
|
|
|
/** |
|
574
|
|
|
* Fill a template with given element. Replace some code by content before output the html |
|
575
|
|
|
* |
|
576
|
|
|
* @param string $template_to_fill The complete html code we want to display with element to change |
|
577
|
|
|
* @param array $feed The different element to put in place of the code into the tempalte part |
|
578
|
|
|
* |
|
579
|
|
|
* @return string The html code to display |
|
580
|
|
|
*/ |
|
581
|
|
|
public static function feed_template($template_to_fill, $feed) { |
|
582
|
|
|
/* Add general element */ |
|
583
|
|
|
$feed['CURRENCY'] = wpshop_tools::wpshop_get_currency(); |
|
584
|
|
|
$feed['CURRENCY_CHOOSEN'] = wpshop_tools::wpshop_get_currency(); |
|
585
|
|
|
$feed['CURRENCY_SELECTOR'] = wpshop_attributes_unit::wpshop_shop_currency_list_field(); |
|
586
|
|
|
$feed['CART_LINK'] = get_permalink( wpshop_tools::get_page_id( get_option('wpshop_cart_page_id') ) ); |
|
587
|
|
|
|
|
588
|
|
|
$available_key = array(); |
|
589
|
|
|
foreach ($feed as $element => $value) { |
|
590
|
|
|
$available_key[] = '{WPSHOP_'.$element.'}'; |
|
591
|
|
|
if ( !is_array($value) ) { |
|
592
|
|
|
$template_to_fill = str_replace('{WPSHOP_'.$element.'}', $value, $template_to_fill); |
|
593
|
|
|
} |
|
594
|
|
|
} |
|
595
|
|
|
if (WPSHOP_DISPLAY_AVAILABLE_KEYS_FOR_TEMPLATE) $template_to_fill = '<!-- Available keys : ' . implode(' / ', $available_key) . ' -->' . $template_to_fill; |
|
596
|
|
|
|
|
597
|
|
|
return $template_to_fill; |
|
598
|
|
|
} |
|
599
|
|
|
|
|
600
|
|
|
/** |
|
601
|
|
|
* Check if template file exist in current theme directory. If not the case copy all template files into |
|
602
|
|
|
* |
|
603
|
|
|
* @param boolean $force_replacement Define if we overwrite in all case or just if it not exist |
|
604
|
|
|
*/ |
|
605
|
|
|
public static function check_template_file( $force_replacement = false ) { |
|
606
|
|
|
$wpshop_directory = get_stylesheet_directory() . '/wpshop'; |
|
607
|
|
|
|
|
608
|
|
|
/* Add different file template */ |
|
609
|
|
|
if(!is_dir($wpshop_directory)){ |
|
610
|
|
|
@mkdir($wpshop_directory, 0755, true); |
|
|
|
|
|
|
611
|
|
|
} |
|
612
|
|
|
/* On s'assure que le dossier principal est bien en 0755 */ |
|
613
|
|
|
@chmod($wpshop_directory, 0755); |
|
|
|
|
|
|
614
|
|
|
$upload_dir = wp_upload_dir(); |
|
|
|
|
|
|
615
|
|
|
|
|
616
|
|
|
/* Add the category template */ |
|
617
|
|
View Code Duplication |
if(!is_file(get_stylesheet_directory() . '/taxonomy-wpshop_product_category.php') || ($force_replacement)){ |
|
|
|
|
|
|
618
|
|
|
@copy(WPSHOP_TEMPLATES_DIR . 'taxonomy-wpshop_product_category.php', get_stylesheet_directory() . '/taxonomy-wpshop_product_category.php'); |
|
|
|
|
|
|
619
|
|
|
} |
|
620
|
|
|
|
|
621
|
|
|
/* Add the product template */ |
|
622
|
|
View Code Duplication |
if(!is_file(get_stylesheet_directory() . '/single-wpshop_product.php') || ($force_replacement)){ |
|
|
|
|
|
|
623
|
|
|
@copy(WPSHOP_TEMPLATES_DIR . 'single-wpshop_product.php', get_stylesheet_directory() . '/single-wpshop_product.php'); |
|
|
|
|
|
|
624
|
|
|
} |
|
625
|
|
|
} |
|
626
|
|
|
|
|
627
|
|
|
|
|
628
|
|
|
/** |
|
629
|
|
|
* Taxonomy display |
|
630
|
|
|
*/ |
|
631
|
|
|
/** |
|
632
|
|
|
* Transform product taxonomy descrition field into a wysiwyg editor |
|
633
|
|
|
*/ |
|
634
|
|
|
public static function wpshop_rich_text_tags() { |
|
635
|
|
|
global $wpdb, $user, $current_user, $pagenow, $wp_version; |
|
636
|
|
|
|
|
637
|
|
|
/* Check if user is on taxonomy edition page */ |
|
638
|
|
|
if ($pagenow == 'edit-tags.php') { |
|
639
|
|
|
|
|
640
|
|
|
if(!user_can_richedit()) { return; } |
|
641
|
|
|
|
|
642
|
|
|
$taxonomies = get_taxonomies(); |
|
643
|
|
|
|
|
644
|
|
|
foreach ($taxonomies as $tax) { |
|
645
|
|
|
if ( in_array($tax, array(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES)) ) { |
|
646
|
|
|
add_action($tax . '_edit_form_fields', array('wpshop_display','wpshop_add_form')); |
|
647
|
|
|
add_action($tax . '_add_form_fields', array('wpshop_display','wpshop_add_form')); |
|
648
|
|
|
} |
|
649
|
|
|
} |
|
650
|
|
|
$action = !empty( $_REQUEST['action'] ) ? sanitize_text_field( $_REQUEST['action'] ) : ''; |
|
651
|
|
|
$taxonomy = !empty( $_REQUEST['taxonomy'] ) ? sanitize_text_field( $_REQUEST['taxonomy'] ) : ''; |
|
652
|
|
|
|
|
653
|
|
|
if ($pagenow == 'edit-tags.php' && isset($action) && $action == 'edit' && empty($taxonomy)) { |
|
654
|
|
|
add_action('edit_term',array('wpshop_display','wpshop_rt_taxonomy_save')); |
|
655
|
|
|
} |
|
656
|
|
|
|
|
657
|
|
|
foreach ( array( 'pre_term_description', 'pre_link_description', 'pre_link_notes', 'pre_user_description' ) as $filter ) { |
|
658
|
|
|
remove_filter( $filter, 'wp_filter_kses' ); |
|
659
|
|
|
} |
|
660
|
|
|
|
|
661
|
|
|
} |
|
662
|
|
|
|
|
663
|
|
|
/* Enable shortcodes in category, taxonomy, tag descriptions */ |
|
664
|
|
|
if(function_exists('term_description')) { |
|
665
|
|
|
add_filter('term_description', 'do_shortcode'); |
|
666
|
|
|
} |
|
667
|
|
|
else { |
|
668
|
|
|
add_filter('category_description', 'do_shortcode'); |
|
669
|
|
|
} |
|
670
|
|
|
} |
|
671
|
|
|
|
|
672
|
|
|
/** |
|
673
|
|
|
* Save the category description field |
|
674
|
|
|
*/ |
|
675
|
|
|
function wpshop_rt_taxonomy_save() { |
|
|
|
|
|
|
676
|
|
|
global $tag_ID; |
|
677
|
|
|
|
|
678
|
|
|
$a = array('description'); |
|
679
|
|
|
foreach ($a as $v) { |
|
680
|
|
|
$term = (array) $_POST[$v]; |
|
681
|
|
|
wp_update_term($tag_ID,$v,$term); |
|
682
|
|
|
} |
|
683
|
|
|
} |
|
684
|
|
|
|
|
685
|
|
|
/** |
|
686
|
|
|
* Definition for the wyswiwyg editor |
|
687
|
|
|
* |
|
688
|
|
|
* @param object $object The type of element currently edited |
|
689
|
|
|
*/ |
|
690
|
|
|
public static function wpshop_add_form($object = '') { |
|
691
|
|
|
global $pagenow; |
|
692
|
|
|
|
|
693
|
|
|
$content = is_object($object) && isset($object->description) ? ( html_entity_decode( $object->description, ENT_COMPAT | ENT_HTML401, 'UTF-8' ) ) : ''; |
|
694
|
|
|
|
|
695
|
|
|
if( in_array($pagenow, array('edit-tags.php')) ) { |
|
696
|
|
|
$editor_id = 'tag_description'; |
|
697
|
|
|
$editor_selector = 'description'; |
|
698
|
|
|
} |
|
699
|
|
|
else { |
|
700
|
|
|
$editor_id = $editor_selector = 'category_description'; |
|
701
|
|
|
} |
|
702
|
|
|
|
|
703
|
|
|
|
|
704
|
|
|
/* |
|
705
|
|
|
* Template parameters |
|
706
|
|
|
*/ |
|
707
|
|
|
$template_part = 'wpshop_transform_taxonomy_description_field_into_wysiwyg_for_js_duplicate'; |
|
708
|
|
|
/*if ( !empty($_GET['action']) && ($_GET['action'] == 'edit') ) { |
|
|
|
|
|
|
709
|
|
|
$template_part = 'wpshop_transform_taxonomy_description_field_into_wysiwyg_for_js_duplicate'; |
|
710
|
|
|
}*/ |
|
711
|
|
|
$tpl_component = array(); |
|
712
|
|
|
ob_start(); |
|
713
|
|
|
wp_editor($content, $editor_id, array( |
|
714
|
|
|
'textarea_name' => $editor_selector, |
|
715
|
|
|
'editor_css' => wpshop_display::display_template_element('wpshop_taxonomy_wysiwyg_editor_css', array(), array(), 'admin'), |
|
716
|
|
|
)); |
|
717
|
|
|
$tpl_component['ADMIN_TAXONOMY_WYSIWYG'] = ob_get_contents(); |
|
718
|
|
|
ob_end_clean(); |
|
719
|
|
|
echo wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin'); |
|
720
|
|
|
unset($tpl_component); |
|
721
|
|
|
} |
|
722
|
|
|
|
|
723
|
|
|
public static function wps_hide_admin_bar_for_customers() { |
|
724
|
|
|
$wpshop_hide_admin_bar_option = get_option('wpshop_display_option'); |
|
725
|
|
|
if ( !empty($wpshop_hide_admin_bar_option) && !empty($wpshop_hide_admin_bar_option['wpshop_hide_admin_bar']) && ! current_user_can( 'manage_options' ) ) { |
|
726
|
|
|
show_admin_bar( false ); |
|
727
|
|
|
} |
|
728
|
|
|
} |
|
729
|
|
|
|
|
730
|
|
|
|
|
731
|
|
|
/** |
|
732
|
|
|
* Product display |
|
733
|
|
|
*/ |
|
734
|
|
|
/** |
|
735
|
|
|
* Change output for product page |
|
736
|
|
|
* |
|
737
|
|
|
* @param string $content The content of a post |
|
738
|
|
|
* @return Ambigous <mixed, string>|unknown |
|
739
|
|
|
*/ |
|
740
|
|
|
public static function products_page( $content = '' ) { |
|
741
|
|
|
global $wp_query; |
|
742
|
|
|
|
|
743
|
|
|
if (!empty($wp_query->queried_object) && !empty($wp_query->queried_object->post_type) && ($wp_query->queried_object->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)) { |
|
744
|
|
|
return wpshop_products::product_complete_sheet_output($content, $wp_query->post->ID); |
|
745
|
|
|
} |
|
746
|
|
|
else { |
|
747
|
|
|
return $content; |
|
748
|
|
|
} |
|
749
|
|
|
} |
|
750
|
|
|
|
|
751
|
|
|
/** |
|
752
|
|
|
* Format a string before outputting |
|
753
|
|
|
* |
|
754
|
|
|
* @param string $output_type The output type needed |
|
755
|
|
|
* @param mixed $value The value to format |
|
756
|
|
|
* |
|
757
|
|
|
* @return string The formated value |
|
758
|
|
|
*/ |
|
759
|
|
|
public static function format_field_output( $output_type, $value ) { |
|
760
|
|
|
$formated_value = $value; |
|
761
|
|
|
|
|
762
|
|
|
if ( !empty($value) ) { |
|
763
|
|
|
switch ( $output_type ) { |
|
764
|
|
|
case 'wpshop_product_price': |
|
765
|
|
|
$formated_value = (is_numeric($value) ) ? number_format($value, 2, ',', '') : $value; |
|
766
|
|
|
$formated_value_content = explode(',', $formated_value); |
|
767
|
|
|
if ( !empty($formated_value_content) && !empty($formated_value_content[1]) && $formated_value_content[1] <= 0 ) { |
|
768
|
|
|
$formated_value = $formated_value_content[0]; |
|
769
|
|
|
} |
|
770
|
|
|
break; |
|
771
|
|
|
case 'date': |
|
772
|
|
|
$formated_value = mysql2date('d/F/Y', $value, true); |
|
773
|
|
|
break; |
|
774
|
|
|
} |
|
775
|
|
|
} |
|
776
|
|
|
|
|
777
|
|
|
return $formated_value; |
|
778
|
|
|
} |
|
779
|
|
|
|
|
780
|
|
|
} |
|
781
|
|
|
|
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: