|
1
|
|
|
<?php |
|
2
|
|
|
add_action( 'save_post' , 'wpsc_refresh_page_urls', 10, 2 ); |
|
3
|
|
|
|
|
4
|
|
|
if ( get_option( 'wpsc_replace_page_title' ) == 1 ) { |
|
5
|
|
|
add_filter( 'wp_title', 'wpsc_replace_wp_title', 10, 2 ); |
|
6
|
|
|
} |
|
7
|
|
|
|
|
8
|
|
|
add_filter( 'post_type_link', 'wpsc_product_link', 10, 3 ); |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* wpsc_product_link function. |
|
12
|
|
|
* Gets the product link, hooks into post_link |
|
13
|
|
|
* Uses the currently selected, only associated or first listed category for the term URL |
|
14
|
|
|
* If the category slug is the same as the product slug, it prefixes the product slug with "product/" to counteract conflicts |
|
15
|
|
|
* |
|
16
|
|
|
* @access public |
|
17
|
|
|
* @return void |
|
18
|
|
|
*/ |
|
19
|
|
|
function wpsc_product_link( $permalink, $post, $leavename ) { |
|
20
|
|
|
global $wp_query, $wpsc_page_titles, $wpsc_query, $wp_current_filter; |
|
21
|
|
|
|
|
22
|
|
|
$rewritecode = array( |
|
23
|
|
|
'%wpsc_product_category%', |
|
24
|
|
|
$leavename ? '' : '%postname%', |
|
25
|
|
|
); |
|
26
|
|
|
if ( is_object( $post ) ) { |
|
27
|
|
|
// In wordpress 2.9 we got a post object |
|
28
|
|
|
$post_id = $post->ID; |
|
29
|
|
|
} else { |
|
30
|
|
|
// In wordpress 3.0 we get a post ID |
|
31
|
|
|
$post_id = $post; |
|
32
|
|
|
$post = get_post( $post_id ); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
// Only applies to WPSC products, don't stop on permalinks of other CPTs |
|
36
|
|
|
// Fixes http://code.google.com/p/wp-e-commerce/issues/detail?id=271 |
|
37
|
|
|
if ( 'wpsc-product' !== $post->post_type ) { |
|
38
|
|
|
return $permalink; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
if ( 'inherit' === $post->post_status && 0 !== $post->post_parent ) { |
|
42
|
|
|
$post_id = $post->post_parent; |
|
43
|
|
|
$post = get_post( $post_id ); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
global $wp_rewrite; |
|
47
|
|
|
|
|
48
|
|
|
$our_permalink_structure = $wp_rewrite->root; |
|
49
|
|
|
|
|
50
|
|
|
// This may become customiseable later |
|
51
|
|
|
$our_permalink_structure .= str_replace( basename( home_url() ), '', $wpsc_page_titles['products'] ) . "/%wpsc_product_category%/%postname%/"; |
|
52
|
|
|
|
|
53
|
|
|
// Mostly the same conditions used for posts, but restricted to items with a post type of "wpsc-product " |
|
54
|
|
|
if ( $wp_rewrite->using_permalinks() && ! in_array( $post->post_status, array( 'draft', 'pending' ) ) ) { |
|
55
|
|
|
|
|
56
|
|
|
$product_categories = wpsc_get_product_terms( $post_id, 'wpsc_product_category' ); |
|
57
|
|
|
$product_category_slugs = array( ); |
|
|
|
|
|
|
58
|
|
|
foreach ( $product_categories as $product_category ) { |
|
59
|
|
|
$product_category_slugs[] = $product_category->slug; |
|
60
|
|
|
} |
|
61
|
|
|
// If the product is associated with multiple categories, determine which one to pick |
|
62
|
|
|
if ( count( $product_categories ) == 0 ) { |
|
63
|
|
|
$category_slug = apply_filters( 'wpsc_uncategorized_product_category', 'uncategorized' ); |
|
64
|
|
|
} elseif ( count( $product_categories ) > 1 ) { |
|
65
|
|
|
if ( (isset( $wp_query->query_vars['products'] ) && $wp_query->query_vars['products'] != null) && in_array( $wp_query->query_vars['products'], $product_category_slugs ) ) { |
|
66
|
|
|
$product_category = $wp_query->query_vars['products']; |
|
67
|
|
|
} else { |
|
68
|
|
|
$link = $product_categories[0]->slug; |
|
69
|
|
|
if ( ! in_array( 'wp_head', $wp_current_filter) && isset( $wpsc_query->query_vars['wpsc_product_category'] ) ) { |
|
70
|
|
|
$current_cat = $wpsc_query->query_vars['wpsc_product_category']; |
|
71
|
|
|
if ( in_array( $current_cat, $product_category_slugs ) ) |
|
72
|
|
|
$link = $current_cat; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
$product_category = $link; |
|
76
|
|
|
} |
|
77
|
|
|
$category_slug = $product_category; |
|
78
|
|
|
} else { |
|
79
|
|
|
// If the product is associated with only one category, we only have one choice |
|
80
|
|
|
if ( !isset( $product_categories[0] ) ) |
|
81
|
|
|
$product_categories[0] = ''; |
|
82
|
|
|
|
|
83
|
|
|
$product_category = $product_categories[0]; |
|
84
|
|
|
|
|
85
|
|
|
if ( !is_object( $product_category ) ) |
|
86
|
|
|
$product_category = new stdClass(); |
|
87
|
|
|
|
|
88
|
|
|
if ( !isset( $product_category->slug ) ) |
|
89
|
|
|
$product_category->slug = null; |
|
90
|
|
|
|
|
91
|
|
|
$category_slug = $product_category->slug; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
$post_name = $post->post_name; |
|
95
|
|
|
|
|
96
|
|
|
if ( get_option( 'product_category_hierarchical_url', 0 ) ) { |
|
97
|
|
|
$selected_term = get_term_by( 'slug', $category_slug, 'wpsc_product_category' ); |
|
98
|
|
|
if ( is_object( $selected_term ) ) { |
|
99
|
|
|
$term_chain = array( $selected_term->slug ); |
|
100
|
|
|
while ( $selected_term->parent ) { |
|
101
|
|
|
$selected_term = get_term( $selected_term->parent, 'wpsc_product_category' ); |
|
102
|
|
|
array_unshift( $term_chain, $selected_term->slug ); |
|
103
|
|
|
} |
|
104
|
|
|
$category_slug = implode( '/', $term_chain ); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
if( isset( $category_slug ) && empty( $category_slug ) ) |
|
109
|
|
|
$category_slug = 'product'; |
|
110
|
|
|
|
|
111
|
|
|
$category_slug = apply_filters( 'wpsc_product_permalink_cat_slug', $category_slug, $post_id ); |
|
112
|
|
|
|
|
113
|
|
|
$rewritereplace = array( |
|
114
|
|
|
$category_slug, |
|
115
|
|
|
$post_name |
|
116
|
|
|
); |
|
117
|
|
|
|
|
118
|
|
|
$permalink = str_replace( $rewritecode, $rewritereplace, $our_permalink_structure ); |
|
119
|
|
|
$permalink = user_trailingslashit( $permalink, 'single' ); |
|
120
|
|
|
|
|
121
|
|
|
$permalink = home_url( $permalink ); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
return apply_filters( 'wpsc_product_permalink', $permalink, $post->ID ); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* wpsc_list_categories function. |
|
129
|
|
|
* |
|
130
|
|
|
* @access public |
|
131
|
|
|
* @param string $callback_function - The function name you want to use for displaying the data |
|
132
|
|
|
* @param mixed $parameters (default: null) - the additional parameters to the callback function |
|
133
|
|
|
* @param int $category_id. (default: 0) - The category id defaults to zero, for displaying all categories |
|
|
|
|
|
|
134
|
|
|
* @param int $level. (default: 0) |
|
|
|
|
|
|
135
|
|
|
*/ |
|
136
|
|
|
function wpsc_list_categories($callback_function, $parameters = null, $category_id = 0, $level = 0) { |
|
137
|
|
|
global $wpdb,$category_data; |
|
138
|
|
|
$output = ''; |
|
139
|
|
|
$category_list = get_terms('wpsc_product_category','hide_empty=0&parent='.$category_id); |
|
140
|
|
|
if($category_list != null) { |
|
141
|
|
|
foreach((array)$category_list as $category) { |
|
142
|
|
|
$callback_output = $callback_function($category, $level, $parameters); |
|
143
|
|
|
if(is_array($callback_output)) { |
|
144
|
|
|
$output .= array_shift($callback_output); |
|
145
|
|
|
} else { |
|
146
|
|
|
$output .= $callback_output; |
|
147
|
|
|
} |
|
148
|
|
|
$output .= wpsc_list_categories($callback_function, $parameters , $category->term_id, ($level+1)); |
|
149
|
|
|
if(is_array($callback_output) && (isset($callback_output[1]))) { |
|
150
|
|
|
$output .= $callback_output[1]; |
|
151
|
|
|
} |
|
152
|
|
|
} |
|
153
|
|
|
} |
|
154
|
|
|
return $output; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* Gets the Function Parent Image link and checks whether Image should be displayed or not |
|
159
|
|
|
* |
|
160
|
|
|
*/ |
|
161
|
|
|
function wpsc_parent_category_image($show_thumbnails , $category_image , $width, $height, $grid=false, $show_name){ |
|
|
|
|
|
|
162
|
|
|
|
|
163
|
|
|
if(!$show_thumbnails) return; |
|
164
|
|
|
|
|
165
|
|
|
if($category_image == WPSC_CATEGORY_URL){ |
|
166
|
|
|
if(!$show_name) return; |
|
167
|
|
|
?> |
|
168
|
|
|
<span class='wpsc_category_image item_no_image ' style='width:<?php echo $width; ?>px; height: <?php echo $height; ?>px;'> |
|
169
|
|
|
<span class='link_substitute' > |
|
170
|
|
|
<span><?php _e('N/A', 'wp-e-commerce'); ?></span> |
|
171
|
|
|
</span> |
|
172
|
|
|
</span> |
|
173
|
|
|
<?php |
|
174
|
|
|
}else{ |
|
175
|
|
|
?><img src='<?php echo $category_image; ?>' width='<?php echo $width; ?>' height='<?php echo $height; ?>' /><?php |
|
176
|
|
|
} |
|
177
|
|
|
} |
|
178
|
|
|
/// category template tags start here |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* Returns true if you're on a tag that is a WPeC tag |
|
182
|
|
|
* |
|
183
|
|
|
* @since 3.9 |
|
184
|
|
|
* |
|
185
|
|
|
* @uses is_tax() Returns true/false given taxonomy and takes second parameter of term |
|
186
|
|
|
* @param string|array|int $term optional The term you could be checking for |
|
187
|
|
|
* @return bool True if you are on a product_tag false if not |
|
188
|
|
|
*/ |
|
189
|
|
|
function wpsc_is_in_tag( $term = '' ) { |
|
190
|
|
|
|
|
191
|
|
|
return is_tax( 'product_tag', $term ); |
|
192
|
|
|
|
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* wpsc starts category query function |
|
197
|
|
|
* gets passed the query and makes it into a global variable, then starts capturing the html for the category loop |
|
198
|
|
|
*/ |
|
199
|
|
|
function wpsc_start_category_query($arguments = array()) { |
|
200
|
|
|
global $wpdb, $wpsc_category_query; |
|
201
|
|
|
$wpsc_category_query = $arguments; |
|
202
|
|
|
ob_start(); |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* wpsc print category name function |
|
207
|
|
|
* places the shortcode for the category name |
|
208
|
|
|
*/ |
|
209
|
|
|
function wpsc_print_category_name() { |
|
210
|
|
|
echo "[wpsc_category_name]"; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
|
|
* wpsc print category description function |
|
215
|
|
|
* places the shortcode for the category description, accepts parameters for the description container |
|
216
|
|
|
* @param string starting HTML element |
|
217
|
|
|
* @param string ending HTML element |
|
218
|
|
|
*/ |
|
219
|
|
|
function wpsc_print_category_description($start_element = '', $end_element = '') { |
|
220
|
|
|
global $wpsc_category_query; |
|
221
|
|
|
$wpsc_category_query['description_container'] = array('start_element' => $start_element, 'end_element' => $end_element); |
|
|
|
|
|
|
222
|
|
|
echo "[wpsc_category_description]"; |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
/** |
|
226
|
|
|
* wpsc print category url function |
|
227
|
|
|
* places the shortcode for the category URL |
|
228
|
|
|
*/ |
|
229
|
|
|
function wpsc_print_category_url() { |
|
230
|
|
|
echo "[wpsc_category_url]"; |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
/** |
|
234
|
|
|
* wpsc print category id function |
|
235
|
|
|
* places the shortcode for the category URL |
|
236
|
|
|
*/ |
|
237
|
|
|
function wpsc_print_category_id() { |
|
238
|
|
|
echo "[wpsc_category_id]"; |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
/** |
|
242
|
|
|
* wpsc print category classes function |
|
243
|
|
|
* places classes for the category including selected state |
|
244
|
|
|
* |
|
245
|
|
|
* please note that "current category" means the category that we are in now, |
|
246
|
|
|
* and not the category that we are printing for |
|
247
|
|
|
* |
|
248
|
|
|
* @param $category_to_print - the category for which we should print classes |
|
249
|
|
|
* @param $echo - whether to echo the result (true) or return (false) |
|
250
|
|
|
*/ |
|
251
|
|
|
function wpsc_print_category_classes($category_to_print = false, $echo = true) { |
|
252
|
|
|
global $wp_query, $wpdb; |
|
253
|
|
|
$result = ''; |
|
254
|
|
|
|
|
255
|
|
|
//if we are in wpsc category page then get the current category |
|
256
|
|
|
$curr_cat = false; |
|
257
|
|
|
$term = get_query_var( 'wpsc_product_category' ); |
|
258
|
|
|
if ( ! $term && get_query_var( 'taxonomy' ) == 'wpsc_product_category' ) |
|
259
|
|
|
$term = get_query_var( 'term' ); |
|
260
|
|
|
if ( $term ) |
|
261
|
|
|
$curr_cat = get_term_by( 'slug', $term, 'wpsc_product_category' ); |
|
262
|
|
|
|
|
263
|
|
|
//check if we are in wpsc category page and that we have a term_id of the category to print |
|
264
|
|
|
//this is done here because none of the following matters if we don't have one of those and we can |
|
265
|
|
|
//safely return |
|
266
|
|
|
if(isset($category_to_print['term_id']) && $curr_cat){ |
|
267
|
|
|
|
|
268
|
|
|
//we will need a list of current category parents for the following if statement |
|
269
|
|
|
$curr_cat_parents = wpsc_get_term_parents($curr_cat->term_id, 'wpsc_product_category'); |
|
270
|
|
|
|
|
271
|
|
|
//if current category is the same as the one we are printing - then add wpsc-current-cat class |
|
272
|
|
|
if( $category_to_print['term_id'] == $curr_cat->term_id ) |
|
273
|
|
|
$result = ' wpsc-current-cat '; |
|
274
|
|
|
//else check if the category that we are printing is parent of current category |
|
275
|
|
|
elseif ( in_array($category_to_print['term_id'], $curr_cat_parents) ) |
|
276
|
|
|
$result = ' wpsc-cat-ancestor '; |
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
$result = apply_filters( 'wpsc_print_category_classes', $result, $category_to_print ); |
|
280
|
|
|
|
|
281
|
|
|
if ( ! empty ( $result ) ) { |
|
|
|
|
|
|
282
|
|
|
if ( $echo ) { |
|
283
|
|
|
echo $result; |
|
284
|
|
|
} else { |
|
285
|
|
|
return $result; |
|
286
|
|
|
} |
|
287
|
|
|
} |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
/** |
|
291
|
|
|
* wpsc print subcategory function |
|
292
|
|
|
* places the shortcode for the subcategories, accepts parameters for the subcategories container, have this as <ul> and </ul> if using a list |
|
293
|
|
|
* @param string starting HTML element |
|
294
|
|
|
* @param string ending HTML element |
|
295
|
|
|
*/ |
|
296
|
|
|
function wpsc_print_subcategory($start_element = '', $end_element = '') { |
|
297
|
|
|
global $wpsc_category_query; |
|
298
|
|
|
$wpsc_category_query['subcategory_container'] = array('start_element' => $start_element, 'end_element' => $end_element); |
|
|
|
|
|
|
299
|
|
|
echo "[wpsc_subcategory]"; |
|
300
|
|
|
} |
|
301
|
|
|
function wpsc_print_category_classes_section(){ |
|
302
|
|
|
echo "[wpsc_category_classes]"; |
|
303
|
|
|
} |
|
304
|
|
|
|
|
305
|
|
|
/** |
|
306
|
|
|
* wpsc print category image function |
|
307
|
|
|
* places the shortcode for the category image, accepts parameters for width and height |
|
308
|
|
|
* @param integer width |
|
309
|
|
|
* @param integer height |
|
310
|
|
|
*/ |
|
311
|
|
|
function wpsc_print_category_image($width = null, $height = null) { |
|
312
|
|
|
global $wpsc_category_query; |
|
313
|
|
|
$wpsc_category_query['image_size'] = array('width' => $width, 'height' => $height); |
|
|
|
|
|
|
314
|
|
|
echo "[wpsc_category_image]"; |
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
|
|
/** |
|
318
|
|
|
* wpsc print category products count function |
|
319
|
|
|
* places the shortcode for the category product count, accepts parameters for the container element |
|
320
|
|
|
* @param string starting HTML element |
|
321
|
|
|
* @param string ending HTML element |
|
322
|
|
|
*/ |
|
323
|
|
|
function wpsc_print_category_products_count($start_element = '', $end_element = '') { |
|
324
|
|
|
global $wpsc_category_query; |
|
325
|
|
|
$wpsc_category_query['products_count'] = array('start_element' => $start_element, 'end_element' => $end_element); |
|
|
|
|
|
|
326
|
|
|
echo "[wpsc_category_products_count]"; |
|
327
|
|
|
} |
|
328
|
|
|
|
|
329
|
|
|
/** |
|
330
|
|
|
* wpsc end category query function |
|
331
|
|
|
*/ |
|
332
|
|
|
function wpsc_end_category_query() { |
|
333
|
|
|
global $wpdb, $wpsc_category_query; |
|
334
|
|
|
$category_html = ob_get_clean(); |
|
335
|
|
|
echo wpsc_display_category_loop($wpsc_category_query, $category_html); |
|
336
|
|
|
unset($GLOBALS['wpsc_category_query']); |
|
337
|
|
|
} |
|
338
|
|
|
|
|
339
|
|
|
/** |
|
340
|
|
|
* wpsc category loop function |
|
341
|
|
|
* This function recursively loops through the categories to display the category tree. |
|
342
|
|
|
* This function also generates a tree of categories at the same time |
|
343
|
|
|
* WARNING: as this function is recursive, be careful what you do with it. |
|
344
|
|
|
* @param array the category query |
|
345
|
|
|
* @param string the category html |
|
346
|
|
|
* @param array the category array branch, is an internal value, leave it alone. |
|
347
|
|
|
* @return string - the finished category html |
|
348
|
|
|
*/ |
|
349
|
|
|
function wpsc_display_category_loop($query, $category_html, &$category_branch = null){ |
|
350
|
|
|
static $category_count_data = array(); // the array tree is stored in this |
|
351
|
|
|
|
|
352
|
|
|
if( isset($query['parent_category_id']) ) |
|
353
|
|
|
$category_id = absint($query['parent_category_id']); |
|
354
|
|
|
else |
|
355
|
|
|
$category_id = 0; |
|
356
|
|
|
$category_data = get_terms('wpsc_product_category','hide_empty=0&parent='.$category_id, OBJECT, 'display'); |
|
357
|
|
|
$output =''; |
|
358
|
|
|
|
|
359
|
|
|
// if the category branch is identical to null, make it a reference to $category_count_data |
|
360
|
|
|
if($category_branch === null) { |
|
361
|
|
|
$category_branch =& $category_count_data; |
|
362
|
|
|
} |
|
363
|
|
|
$allowed_tags = array('a' => array('href' => array(),'title' => array()),'abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array(), 'b'=> array()); |
|
364
|
|
|
|
|
365
|
|
|
$allowedtags = apply_filters('wpsc_category_description_allowed_tags' , $allowed_tags); |
|
366
|
|
|
|
|
367
|
|
|
foreach((array)$category_data as $category_row) { |
|
368
|
|
|
|
|
369
|
|
|
// modifys the query for the next round |
|
370
|
|
|
$modified_query = $query; |
|
371
|
|
|
$modified_query['parent_category_id'] = $category_row->term_id; |
|
372
|
|
|
|
|
373
|
|
|
// gets the count of products associated with this category |
|
374
|
|
|
$category_count = $category_row->count; |
|
375
|
|
|
|
|
|
|
|
|
|
376
|
|
|
|
|
377
|
|
|
// Sticks the category description in |
|
378
|
|
|
$category_description = ''; |
|
379
|
|
|
if($category_row->description != '' && ! empty( $query['description_container'] ) ) { |
|
380
|
|
|
$start_element = $query['description_container']['start_element']; |
|
381
|
|
|
$end_element = $query['description_container']['end_element']; |
|
382
|
|
|
$category_description = $start_element.wpautop(wptexturize( wp_kses( $category_row->description, $allowedtags ))).$end_element; |
|
|
|
|
|
|
383
|
|
|
} |
|
384
|
|
|
|
|
|
|
|
|
|
385
|
|
|
|
|
386
|
|
|
// Creates the list of classes on the category item |
|
387
|
|
|
$category_classes = wpsc_print_category_classes((array)$category_row, false); |
|
388
|
|
|
|
|
389
|
|
|
// Set the variables for this category |
|
390
|
|
|
$category_branch[$category_row->term_id]['children'] = array(); |
|
391
|
|
|
$category_branch[$category_row->term_id]['count'] = (int)$category_count; |
|
392
|
|
|
|
|
|
|
|
|
|
393
|
|
|
|
|
394
|
|
|
// Recurse into the next level of categories |
|
395
|
|
|
$sub_categories = wpsc_display_category_loop($modified_query, $category_html, $category_branch[$category_row->term_id]['children']); |
|
396
|
|
|
|
|
397
|
|
|
// grab the product count from the subcategories |
|
398
|
|
|
foreach((array)$category_branch[$category_row->term_id]['children'] as $child_category) { |
|
399
|
|
|
$category_branch[$category_row->term_id]['count'] += (int)$child_category['count']; |
|
400
|
|
|
} |
|
401
|
|
|
|
|
402
|
|
|
// stick the category count array together here |
|
403
|
|
|
// this must run after the subcategories and the count of products belonging to them has been obtained |
|
404
|
|
|
|
|
405
|
|
|
$category_count = $category_branch[$category_row->term_id]['count']; |
|
406
|
|
|
|
|
407
|
|
|
$start_element = ''; |
|
408
|
|
|
$end_element = ''; |
|
409
|
|
|
|
|
410
|
|
|
if (isset($query['products_count']['start_element'])) { |
|
411
|
|
|
$start_element = $query['products_count']['start_element']; |
|
412
|
|
|
} |
|
413
|
|
|
|
|
414
|
|
|
if (isset($query['products_count']['end_element'])) { |
|
415
|
|
|
$end_element = $query['products_count']['end_element']; |
|
416
|
|
|
} |
|
417
|
|
|
|
|
418
|
|
|
$category_count_html = $start_element.$category_count.$end_element; |
|
|
|
|
|
|
419
|
|
|
|
|
|
|
|
|
|
420
|
|
|
|
|
421
|
|
|
if ( isset( $query['subcategory_container'] ) && ! empty( $sub_categories ) ) { |
|
422
|
|
|
$start_element = $query['subcategory_container']['start_element']; |
|
423
|
|
|
$end_element = $query['subcategory_container']['end_element']; |
|
424
|
|
|
$sub_categories = $start_element.$sub_categories.$end_element; |
|
425
|
|
|
} |
|
426
|
|
|
|
|
427
|
|
|
// get the category images |
|
428
|
|
|
$category_image = wpsc_place_category_image($category_row->term_id, $modified_query); |
|
429
|
|
|
|
|
430
|
|
|
if ( empty( $query['image_size']['width'] ) ) { |
|
431
|
|
|
if ( ! wpsc_category_grid_view() ) |
|
432
|
|
|
$width = wpsc_get_categorymeta( $category_row->term_id, 'image_width' ); |
|
433
|
|
|
if ( empty( $width ) ) |
|
434
|
|
|
$width = get_option( 'category_image_width' ); |
|
435
|
|
|
} else { |
|
436
|
|
|
$width = $query['image_size']['width']; |
|
437
|
|
|
} |
|
438
|
|
|
|
|
439
|
|
|
if ( empty( $query['image_size']['height'] ) ) { |
|
440
|
|
|
if ( ! wpsc_category_grid_view() ) |
|
441
|
|
|
$height = wpsc_get_categorymeta( $category_row->term_id, 'image_height' ); |
|
442
|
|
|
if ( empty( $height ) ) |
|
443
|
|
|
$height = get_option( 'category_image_height' ); |
|
444
|
|
|
} else { |
|
445
|
|
|
$height = $query['image_size']['height']; |
|
446
|
|
|
} |
|
447
|
|
|
|
|
448
|
|
|
$category_image = wpsc_get_categorymeta($category_row->term_id, 'image'); |
|
449
|
|
|
$category_image_html = ''; |
|
450
|
|
|
if(($query['show_thumbnails'] == 1)) { |
|
451
|
|
|
if((!empty($category_image)) && is_file(WPSC_CATEGORY_DIR.$category_image)) { |
|
452
|
|
|
$category_image_html = "<img src='".WPSC_CATEGORY_URL."$category_image' alt='{$category_row->name}' title='{$category_row->name}' style='width: {$width}px; height: {$height}px;' class='wpsc_category_image' />"; |
|
453
|
|
|
} elseif( isset( $query['show_name'] ) && 1 == $query['show_name']) { |
|
454
|
|
|
$category_image_html .= "<span class='wpsc_category_image item_no_image ' style='width: {$width}px; height: {$height}px;'>\n\r"; |
|
455
|
|
|
$category_image_html .= " <span class='link_substitute' >\n\r"; |
|
456
|
|
|
$category_image_html .= " <span>".__('N/A','wp-e-commerce')."</span>\n\r"; |
|
457
|
|
|
$category_image_html .= " </span>\n\r"; |
|
458
|
|
|
$category_image_html .= "</span>\n\r"; |
|
459
|
|
|
} |
|
|
|
|
|
|
460
|
|
|
|
|
461
|
|
|
} |
|
462
|
|
|
|
|
|
|
|
|
|
463
|
|
|
|
|
464
|
|
|
// get the list of products associated with this category. |
|
465
|
|
|
$tags_to_replace = array('[wpsc_category_name]', |
|
466
|
|
|
'[wpsc_category_description]', |
|
467
|
|
|
'[wpsc_category_url]', |
|
468
|
|
|
'[wpsc_category_id]', |
|
469
|
|
|
'[wpsc_category_classes]', |
|
470
|
|
|
'[wpsc_category_image]', |
|
471
|
|
|
'[wpsc_subcategory]', |
|
472
|
|
|
'[wpsc_category_products_count]'); |
|
473
|
|
|
|
|
474
|
|
|
$content_to_place = array( |
|
475
|
|
|
esc_html($category_row->name), |
|
476
|
|
|
$category_description, |
|
477
|
|
|
esc_url( get_term_link( $category_row->slug, 'wpsc_product_category' ) ), |
|
478
|
|
|
$category_row->term_id, |
|
479
|
|
|
$category_classes, |
|
480
|
|
|
$category_image_html, |
|
481
|
|
|
$sub_categories, |
|
482
|
|
|
$category_count_html); |
|
483
|
|
|
|
|
484
|
|
|
// Stick all the category html together and concatenate it to the previously generated HTML |
|
485
|
|
|
$output .= str_replace($tags_to_replace, $content_to_place ,$category_html); |
|
486
|
|
|
} |
|
487
|
|
|
return $output; |
|
488
|
|
|
} |
|
489
|
|
|
|
|
490
|
|
|
/** |
|
491
|
|
|
* wpsc category image function |
|
492
|
|
|
* if no parameters are passed, the category is not resized, otherwise it is resized to the specified dimensions |
|
493
|
|
|
* @param integer category id |
|
494
|
|
|
* @param array category query array |
|
495
|
|
|
* @return string - the category image URL, or the URL of the resized version |
|
496
|
|
|
*/ |
|
497
|
|
|
function wpsc_place_category_image($category_id, $query) { |
|
498
|
|
|
// show the full sized image for the product, if supplied with dimensions, will resize image to those. |
|
499
|
|
|
$width = (isset($query['image_size']['width'])) ? ($query['image_size']['width']) : get_option('category_image_width'); |
|
500
|
|
|
$height = (isset($query['image_size']['height'])) ? ($query['image_size']['height']) : get_option('category_image_height'); |
|
501
|
|
|
$image_url = "index.php?wpsc_request_image=true&category_id=".$category_id."&width=".$width."&height=".$height; |
|
502
|
|
|
return htmlspecialchars($image_url); |
|
503
|
|
|
} |
|
504
|
|
|
|
|
505
|
|
|
/// category template tags end here |
|
506
|
|
|
|
|
507
|
|
|
/** |
|
508
|
|
|
* wpsc_category_url function, makes permalink to the category or |
|
509
|
|
|
* @param integer category ID, can be 0 |
|
510
|
|
|
* @param boolean permalink compatibility, adds a prefix to prevent permalink namespace conflicts |
|
511
|
|
|
*/ |
|
512
|
|
|
function wpsc_category_url($category_id, $permalink_compatibility = false) { |
|
|
|
|
|
|
513
|
|
|
return get_term_link( $category_id, 'wpsc_product_category'); |
|
514
|
|
|
} |
|
515
|
|
|
|
|
516
|
|
|
|
|
517
|
|
|
/** |
|
518
|
|
|
* Returns true if you're on a category that is a WPeC category |
|
519
|
|
|
* |
|
520
|
|
|
* @uses is_tax() Returns true/false given taxonomy and takes second parameter of term |
|
521
|
|
|
* @param string|array|int $term optional The term you could be checking for |
|
522
|
|
|
* @return bool True if you are on a wpsc_product_category false if not |
|
523
|
|
|
*/ |
|
524
|
|
|
function wpsc_is_in_category( $term = '' ) { |
|
525
|
|
|
|
|
526
|
|
|
return is_tax( 'wpsc_product_category', $term ); |
|
527
|
|
|
|
|
528
|
|
|
} |
|
529
|
|
|
|
|
530
|
|
|
|
|
531
|
|
|
/** |
|
532
|
|
|
* Uses a category's, (in the wpsc_product_category taxonomy), slug to find its |
|
533
|
|
|
* ID, then returns it. |
|
534
|
|
|
* |
|
535
|
|
|
* @param string $category_slug The slug of the category who's ID we want. |
|
536
|
|
|
* @return (int | bool) Returns the integer ID of the category if found, or a |
|
|
|
|
|
|
537
|
|
|
* boolean false if the category is not found. |
|
538
|
|
|
* |
|
539
|
|
|
* @todo Cache the results of this somewhere. It could save quite a few trips |
|
540
|
|
|
* to the MySQL server. |
|
541
|
|
|
* |
|
542
|
|
|
*/ |
|
543
|
|
|
function wpsc_category_id($category_slug = '') { |
|
544
|
|
|
if(empty($category_slug)) |
|
545
|
|
|
$category_slug = get_query_var( 'wpsc_product_category' ); |
|
546
|
|
|
elseif(array_key_exists('wpsc_product_category', $_GET)) |
|
547
|
|
|
$category_slug = $_GET['wpsc_product_category']; |
|
548
|
|
|
|
|
549
|
|
|
if(!empty($category_slug)) { |
|
550
|
|
|
$category = get_term_by('slug', $category_slug, 'wpsc_product_category'); |
|
551
|
|
|
if(!empty($category->term_id)){ |
|
552
|
|
|
return $category->term_id; |
|
553
|
|
|
} else { |
|
554
|
|
|
return false; |
|
555
|
|
|
} |
|
556
|
|
|
} else { |
|
557
|
|
|
return false; |
|
558
|
|
|
} |
|
559
|
|
|
} |
|
560
|
|
|
|
|
561
|
|
|
/** |
|
562
|
|
|
* wpsc_category_description function, Gets the category description |
|
563
|
|
|
* @param integer category ID, can be 0 |
|
564
|
|
|
* @return string category description |
|
565
|
|
|
*/ |
|
566
|
|
|
function wpsc_category_description($category_id = null) { |
|
567
|
|
|
if($category_id < 1) |
|
568
|
|
|
$category_id = wpsc_category_id(); |
|
569
|
|
|
$category = get_term_by( 'id', $category_id, 'wpsc_product_category' ); |
|
570
|
|
|
return $category ? $category->description : ''; |
|
571
|
|
|
} |
|
572
|
|
|
|
|
573
|
|
|
function wpsc_category_name($category_id = null) { |
|
574
|
|
|
if ( $category_id < 1 ) |
|
575
|
|
|
$category_id = wpsc_category_id(); |
|
576
|
|
|
|
|
577
|
|
|
$category = get_term_by( 'id', $category_id, 'wpsc_product_category' ); |
|
578
|
|
|
return $category ? $category->name : ''; |
|
579
|
|
|
} |
|
580
|
|
|
|
|
581
|
|
|
function nzshpcrt_display_categories_groups() { |
|
582
|
|
|
return ''; |
|
583
|
|
|
} |
|
584
|
|
|
|
|
585
|
|
|
/** wpsc list subcategories function |
|
586
|
|
|
used to get an array of all the subcategories of a category. |
|
587
|
|
|
*/ |
|
588
|
|
|
function wpsc_list_subcategories($category_id = null) { |
|
589
|
|
|
global $wpdb,$category_data; |
|
590
|
|
|
|
|
591
|
|
|
$category_list = $wpdb->get_col( $wpdb->prepare( "SELECT `id` FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `category_parent` = %d", $category_id ) ); |
|
592
|
|
|
|
|
593
|
|
|
if($category_list != null) { |
|
594
|
|
|
foreach($category_list as $subcategory_id) { |
|
595
|
|
|
$category_list = array_merge((array)$category_list, (array)wpsc_list_subcategories($subcategory_id)); |
|
596
|
|
|
} |
|
597
|
|
|
} |
|
598
|
|
|
return $category_list; |
|
599
|
|
|
} |
|
600
|
|
|
|
|
601
|
|
|
/** |
|
602
|
|
|
* wpsc_show_category_thumbnails function |
|
603
|
|
|
* @return bool - whether to show category thumbnails or not |
|
604
|
|
|
*/ |
|
605
|
|
|
function wpsc_show_category_thumbnails(){ |
|
606
|
|
|
if(get_option('show_category_thumbnails') && wpsc_category_image()) |
|
|
|
|
|
|
607
|
|
|
return true; |
|
608
|
|
|
else |
|
609
|
|
|
return false; |
|
610
|
|
|
} |
|
611
|
|
|
|
|
612
|
|
|
/** |
|
613
|
|
|
* wpsc_show_category_description function |
|
614
|
|
|
* @return bool - whether to show category description or not |
|
615
|
|
|
*/ |
|
616
|
|
|
function wpsc_show_category_description(){ |
|
617
|
|
|
return get_option( 'wpsc_category_description' ); |
|
618
|
|
|
} |
|
619
|
|
|
|
|
620
|
|
|
/** |
|
621
|
|
|
* wpsc buy now button code products function |
|
622
|
|
|
* Sorry about the ugly code, this is just to get the functionality back, buy now will soon be overhauled, and this function will then be completely different |
|
623
|
|
|
* @return string - html displaying one or more products |
|
624
|
|
|
*/ |
|
625
|
|
|
function wpsc_buy_now_button( $product_id, $replaced_shortcode = false ) { |
|
626
|
|
|
|
|
627
|
|
|
$product_id = absint( $product_id ); |
|
628
|
|
|
|
|
629
|
|
|
$product = get_post( $product_id ); |
|
630
|
|
|
$supported_gateways = array( 'wpsc_merchant_paypal_standard', 'paypal_multiple' ); |
|
631
|
|
|
$selected_gateways = get_option( 'custom_gateway_options' ); |
|
632
|
|
|
|
|
633
|
|
|
if ( $replaced_shortcode ) { |
|
634
|
|
|
ob_start(); |
|
635
|
|
|
} |
|
636
|
|
|
|
|
637
|
|
|
if ( in_array( 'wpsc_merchant_paypal_standard', (array) $selected_gateways ) ) { |
|
638
|
|
|
if ( $product_id > 0 ) { |
|
639
|
|
|
|
|
640
|
|
|
$post_meta = get_post_meta( $product_id, '_wpsc_product_metadata', true ); |
|
641
|
|
|
$shipping = isset( $post_meta['shipping'] ) ? $post_meta['shipping']['local'] : ''; |
|
642
|
|
|
$price = get_post_meta( $product_id, '_wpsc_price', true ); |
|
643
|
|
|
$special_price = get_post_meta( $product_id, '_wpsc_special_price', true ); |
|
644
|
|
|
|
|
645
|
|
|
if ( $special_price ) |
|
646
|
|
|
$price = $special_price; |
|
647
|
|
|
|
|
648
|
|
|
if ( wpsc_uses_shipping ( ) ) { |
|
|
|
|
|
|
649
|
|
|
$handling = get_option( 'base_local_shipping' ); |
|
650
|
|
|
} else { |
|
651
|
|
|
$handling = $shipping; |
|
652
|
|
|
} |
|
653
|
|
|
|
|
654
|
|
|
$has_variants = wpsc_product_has_variations( $product_id ) || ! wpsc_product_has_stock( $product_id ); |
|
655
|
|
|
|
|
656
|
|
|
$src = apply_filters( 'wpsc_buy_now_button_src', _x( 'https://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif', 'PayPal Buy Now Button', 'wp-e-commerce' ) ); |
|
657
|
|
|
$classes = apply_filters( 'wpsc_buy_now_button_class', "wpsc-buy-now-form wpsc-buy-now-form-{$product_id}" ); |
|
658
|
|
|
|
|
659
|
|
|
$classes_array = array_map( 'sanitize_html_class', explode( ' ', $classes ) ); |
|
660
|
|
|
|
|
661
|
|
|
$classes = implode( ' ', $classes_array ); |
|
662
|
|
|
|
|
663
|
|
|
$button_html = sprintf( '<input%1$s class="wpsc-buy-now-button wpsc-buy-now-button-%2$s" type="image" name="submit" border="0" src="%3$s" alt="%4$s" />', |
|
664
|
|
|
disabled( $has_variants, true, false ), |
|
665
|
|
|
esc_attr( $product_id ), |
|
666
|
|
|
esc_url( $src ), |
|
667
|
|
|
esc_attr__( 'PayPal - The safer, easier way to pay online', 'wp-e-commerce' ) |
|
668
|
|
|
); |
|
669
|
|
|
|
|
670
|
|
|
$button_html = apply_filters( 'wpsc_buy_now_button_html', $button_html, $product_id ); |
|
671
|
|
|
?> |
|
672
|
|
|
<form class="<?php echo( $classes ); ?>" id="buy-now-product_<?php echo $product_id; ?>" target="paypal" action="<?php echo esc_url( home_url() ); ?>" method="post"> |
|
673
|
|
|
<input type="hidden" name="wpsc_buy_now_callback" value="1" /> |
|
674
|
|
|
<input type="hidden" name="product_id" value="<?php echo esc_attr( $product_id ); ?>" /> |
|
675
|
|
|
<?php |
|
676
|
|
|
if ( $has_variants ) : |
|
677
|
|
|
// grab the variation form fields here |
|
678
|
|
|
$wpsc_variations = new wpsc_variations( $product_id ); |
|
679
|
|
|
while ( wpsc_have_variation_groups() ) : wpsc_the_variation_group(); |
|
680
|
|
|
printf('<input type="hidden" class="variation-value" name="variation[%1$d]" id="%2$s" value="0"/>', wpsc_vargrp_id(), wpsc_vargrp_form_id() ); |
|
681
|
|
|
endwhile; |
|
682
|
|
|
endif; /* END wpsc_product_has_variations */ |
|
683
|
|
|
?> |
|
684
|
|
|
<?php if ( get_option( 'multi_add' ) ) : ?> |
|
685
|
|
|
<label for="quantity"><?php esc_html_e( 'Quantity', 'wp-e-commerce' ); ?></label> |
|
686
|
|
|
<input type="text" size="4" id="quantity" class="wpsc-buy-now-quantity" name="quantity" value="" /><br /> |
|
687
|
|
|
<?php else: ?> |
|
688
|
|
|
<input type="hidden" name="quantity" class="wpsc-buy-now-quantity" value="1" /> |
|
689
|
|
|
<?php endif ?> |
|
690
|
|
|
<?php echo $button_html; ?> |
|
691
|
|
|
<img alt='' border='0' width='1' height='1' src='<?php echo esc_url( _x( 'https://www.paypal.com/en_US/i/scr/pixel.gif', 'PayPal Pixel', 'wp-e-commerce' ) ); ?>' /> |
|
692
|
|
|
</form> |
|
693
|
|
|
<?php |
|
694
|
|
|
} |
|
695
|
|
|
} |
|
696
|
|
|
if ( $replaced_shortcode ) { |
|
697
|
|
|
return ob_get_clean(); |
|
698
|
|
|
} |
|
699
|
|
|
} |
|
700
|
|
|
|
|
701
|
|
|
/** |
|
702
|
|
|
* Displays products that were bought along with the product defined by $product_id. |
|
703
|
|
|
* This functionality will be deprecated and be provided by a plugin in a future version. |
|
704
|
|
|
*/ |
|
705
|
|
|
function wpsc_also_bought( $product_id ) { |
|
706
|
|
|
global $wpdb; |
|
707
|
|
|
|
|
708
|
|
|
if ( get_option( 'wpsc_also_bought' ) == 0 ) { |
|
709
|
|
|
return ''; |
|
710
|
|
|
} |
|
711
|
|
|
|
|
712
|
|
|
// To be made customiseable in a future release |
|
713
|
|
|
$also_bought_limit = 3; |
|
714
|
|
|
$element_widths = 96; |
|
715
|
|
|
$image_display_height = 96; |
|
716
|
|
|
$image_display_width = 96; |
|
717
|
|
|
|
|
718
|
|
|
// Filter will be used by a plugin to provide 'Also Bought' functionality when this is deprecated from core. |
|
719
|
|
|
// Filter is currently private and should not be used by plugin/theme devs as it may only be temporary. |
|
720
|
|
|
$output = apply_filters( '_wpsc_also_bought', '', $product_id ); |
|
721
|
|
|
if ( ! empty( $output ) ) { |
|
722
|
|
|
return $output; |
|
723
|
|
|
} |
|
724
|
|
|
|
|
725
|
|
|
// If above filter returns output then the following is ignore and can be deprecated in future. |
|
726
|
|
|
$also_bought = $wpdb->get_results( $wpdb->prepare( "SELECT `" . $wpdb->posts . "`.* FROM `" . WPSC_TABLE_ALSO_BOUGHT . "`, `" . $wpdb->posts . "` WHERE `selected_product`= %d AND `" . WPSC_TABLE_ALSO_BOUGHT . "`.`associated_product` = `" . $wpdb->posts . "`.`id` AND `" . $wpdb->posts . "`.`post_status` IN('publish','protected') ORDER BY `" . WPSC_TABLE_ALSO_BOUGHT . "`.`quantity` DESC LIMIT $also_bought_limit", $product_id ), ARRAY_A ); |
|
727
|
|
|
if ( is_array( $also_bought ) && count( $also_bought ) > 0 ) { |
|
728
|
|
|
$output .= '<h2 class="prodtitles wpsc_also_bought">' . __( 'People who bought this item also bought', 'wp-e-commerce' ) . '</h2>'; |
|
729
|
|
|
$output .= '<div class="wpsc_also_bought">'; |
|
730
|
|
|
foreach ( $also_bought as $also_bought_data ) { |
|
731
|
|
|
$output .= '<div class="wpsc_also_bought_item" style="width: ' . $element_widths . 'px;">'; |
|
732
|
|
|
if ( get_option( 'show_thumbnails' ) == 1 ) { |
|
733
|
|
|
$image_path = wpsc_the_product_thumbnail( $image_display_width, $image_display_height, $also_bought_data['ID'] ); |
|
734
|
|
|
if ( $image_path ) { |
|
735
|
|
|
$output .= '<a href="' . esc_attr( get_permalink( $also_bought_data['ID'] ) ) . '" class="preview_link" rel="' . esc_attr( sanitize_html_class( get_the_title( $also_bought_data['ID'] ) ) ) . '">'; |
|
736
|
|
|
$output .= '<img src="' . esc_attr( $image_path ) . '" id="product_image_' . $also_bought_data['ID'] . '" class="product_image" />'; |
|
737
|
|
|
$output .= '</a>'; |
|
738
|
|
|
} else { |
|
739
|
|
|
if ( get_option( 'product_image_width' ) != '' ) { |
|
740
|
|
|
$width_and_height = 'width="' . $image_display_height . '" height="' . $image_display_height . '" '; |
|
741
|
|
|
} else { |
|
742
|
|
|
$width_and_height = ''; |
|
743
|
|
|
} |
|
744
|
|
|
$output .= '<img src="' . WPSC_CORE_THEME_URL . '/wpsc-images/noimage.png" title="' . esc_attr( get_the_title( $also_bought_data['ID'] ) ) . '" alt="' . esc_attr( get_the_title( $also_bought_data['ID'] ) ) . '" id="product_image_' . $also_bought_data['ID'] . '" class="product_image" ' . $width_and_height . '/>'; |
|
745
|
|
|
} |
|
746
|
|
|
} |
|
747
|
|
|
|
|
748
|
|
|
$output .= '<a class="wpsc_product_name" href="' . get_permalink( $also_bought_data['ID'] ) . '">' . get_the_title( $also_bought_data['ID'] ) . '</a>'; |
|
749
|
|
|
if ( ! wpsc_product_is_donation( $also_bought_data['ID'] ) ) { |
|
750
|
|
|
// Ideally use the wpsc_the_product_price_display() function here but needs some tweaking |
|
751
|
|
|
$price = get_product_meta( $also_bought_data['ID'], 'price', true ); |
|
752
|
|
|
$special_price = get_product_meta( $also_bought_data['ID'], 'special_price', true ); |
|
753
|
|
|
if ( ! empty( $special_price ) ) { |
|
754
|
|
|
$output .= '<span style="text-decoration: line-through;">' . wpsc_currency_display( $price ) . '</span>'; |
|
755
|
|
|
$output .= wpsc_currency_display( $special_price ); |
|
756
|
|
|
} else { |
|
757
|
|
|
$output .= wpsc_currency_display( $price ); |
|
758
|
|
|
} |
|
759
|
|
|
} |
|
760
|
|
|
$output .= '</div>'; |
|
761
|
|
|
} |
|
762
|
|
|
$output .= '</div>'; |
|
763
|
|
|
$output .= '<br clear="all" />'; |
|
764
|
|
|
} |
|
765
|
|
|
return $output; |
|
766
|
|
|
} |
|
767
|
|
|
|
|
768
|
|
|
/** |
|
769
|
|
|
* Get the URL of the loading animation image. |
|
770
|
|
|
* Can be filtered using the wpsc_loading_animation_url filter. |
|
771
|
|
|
*/ |
|
772
|
|
|
function wpsc_loading_animation_url() { |
|
773
|
|
|
return apply_filters( 'wpsc_loading_animation_url', WPSC_CORE_THEME_URL . 'wpsc-images/indicator.gif' ); |
|
774
|
|
|
} |
|
775
|
|
|
|
|
776
|
|
|
/* |
|
777
|
|
|
* wpsc product url function, gets the URL of a product, |
|
778
|
|
|
* Deprecated, all parameters past the first unused. use get_permalink |
|
779
|
|
|
*/ |
|
780
|
|
|
|
|
781
|
|
|
function wpsc_product_url( $product_id, $category_id = null, $escape = true ) { |
|
|
|
|
|
|
782
|
|
|
$post = get_post($product_id); |
|
783
|
|
|
if ( isset($post->post_parent) && $post->post_parent > 0) { |
|
784
|
|
|
return get_permalink($post->post_parent); |
|
785
|
|
|
} else { |
|
786
|
|
|
return get_permalink($product_id); |
|
787
|
|
|
} |
|
788
|
|
|
} |
|
789
|
|
|
|
|
790
|
|
|
function external_link( $product_id ) { |
|
791
|
|
|
$link = get_product_meta( $product_id, 'external_link', true ); |
|
792
|
|
|
if ( !stristr( $link, 'http://' ) ) { |
|
793
|
|
|
$link = 'http://' . $link; |
|
794
|
|
|
} |
|
795
|
|
|
$target = wpsc_product_external_link_target( $product_id ); |
|
796
|
|
|
$output .= "<input class='wpsc_buy_button' type='button' value='" . wpsc_product_external_link_text( $product_id, __( 'Buy Now', 'wp-e-commerce' ) ) . "' onclick='return gotoexternallink(\"$link\", \"$target\")'>"; |
|
|
|
|
|
|
797
|
|
|
return $output; |
|
798
|
|
|
} |
|
799
|
|
|
|
|
800
|
|
|
/** |
|
801
|
|
|
* wpsc_refresh_page_urls |
|
802
|
|
|
* |
|
803
|
|
|
* Refresh page urls when pages are updated |
|
804
|
|
|
* |
|
805
|
|
|
* @param int $post_id |
|
806
|
|
|
* @param object $post |
|
807
|
|
|
* @uses wpsc_update_permalink_slugs() |
|
808
|
|
|
* @return int $post_id |
|
809
|
|
|
*/ |
|
810
|
|
|
function wpsc_refresh_page_urls( $post_id, $post ) { |
|
811
|
|
|
|
|
812
|
|
|
if ( ! current_user_can( 'manage_options' ) ) |
|
813
|
|
|
return; |
|
814
|
|
|
|
|
815
|
|
|
if ( 'page' != $post->post_type ) |
|
816
|
|
|
return; |
|
817
|
|
|
|
|
818
|
|
|
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) |
|
819
|
|
|
return; |
|
820
|
|
|
|
|
821
|
|
|
if ( ! in_array( $post->post_status, array( 'publish', 'private' ) ) ) |
|
822
|
|
|
return; |
|
823
|
|
|
|
|
824
|
|
|
wpsc_update_permalink_slugs(); |
|
825
|
|
|
|
|
826
|
|
|
return $post_id; |
|
827
|
|
|
} |
|
828
|
|
|
|
|
829
|
|
|
function wpsc_replace_wp_title( $input ) { |
|
830
|
|
|
global $wpdb, $wp_query; |
|
831
|
|
|
$output = wpsc_obtain_the_title(); |
|
832
|
|
|
if ( $output != null ) { |
|
|
|
|
|
|
833
|
|
|
return $output; |
|
834
|
|
|
} |
|
835
|
|
|
return $input; |
|
836
|
|
|
} |
|
837
|
|
|
|
|
838
|
|
|
function wpsc_replace_bloginfo_title( $input, $show ) { |
|
839
|
|
|
global $wpdb, $wp_query; |
|
840
|
|
|
if ( $show == 'description' ) { |
|
841
|
|
|
$output = wpsc_obtain_the_title(); |
|
842
|
|
|
if ( $output != null ) { |
|
|
|
|
|
|
843
|
|
|
return $output; |
|
844
|
|
|
} |
|
845
|
|
|
} |
|
846
|
|
|
return $input; |
|
847
|
|
|
} |
|
848
|
|
|
|
|
849
|
|
|
|