/wpsc-components/theme-engine-v1/helpers/page.php

  1. <?php 
  2.  
  3. add_action( 'wpsc_loaded', 'wpsc_core_load_page_titles' ); 
  4. add_action( 'init', 'wpsc_register_core_theme_files' ); 
  5. add_action( 'wpsc_move_theme', 'wpsc_flush_theme_transients', 10, true ); 
  6. add_action( 'wpsc_switch_theme', 'wpsc_flush_theme_transients', 10, true ); 
  7. add_action( 'switch_theme', 'wpsc_flush_theme_transients', 10, true ); 
  8. add_action( 'admin_init', 'wpsc_theme_admin_notices'); 
  9. add_action( 'update_option_product_image_width' , 'wpsc_cache_to_upload' ); 
  10. add_action( 'update_option_product_image_height' , 'wpsc_cache_to_upload' ); 
  11. add_action( 'update_option_single_view_image_width' , 'wpsc_cache_to_upload' ); 
  12. add_action( 'update_option_single_view_image_height', 'wpsc_cache_to_upload' ); 
  13. add_action( 'update_option_category_image_width' , 'wpsc_cache_to_upload' ); 
  14. add_action( 'update_option_category_image_height' , 'wpsc_cache_to_upload' ); 
  15. add_action( 'template_redirect', 'wpsc_all_products_on_page'); 
  16. add_filter( 'aioseop_description', 'wpsc_set_aioseop_description' ); 
  17. add_filter( 'request', 'wpsc_remove_page_from_query_string'); 
  18.  
  19. //Potentially unnecessary, as I believe this option is deprecated 
  20. add_action( 'update_option_show_categorybrands' , 'wpsc_cache_to_upload' ); 
  21.  
  22. if ( ! is_admin() ) 
  23. add_action( 'init', 'wpsc_enqueue_user_script_and_css' ); 
  24.  
  25. if ( isset( $_REQUEST['wpsc_flush_theme_transients'] ) && ( $_REQUEST['wpsc_flush_theme_transients'] == 'true' ) ) 
  26. add_action( 'admin_init', 'wpsc_force_flush_theme_transients' ); 
  27.  
  28. if ( isset( $_GET['wpsc_user_dynamic_css'] ) && 'true' == $_GET['wpsc_user_dynamic_css'] ) 
  29. add_action( 'plugins_loaded', 'wpsc_user_dynamic_css', 1 ); 
  30.  
  31. if ( ! is_admin() ) 
  32. add_filter('request', 'wpec_remap_shop_subpages'); 
  33.  
  34. if(get_option( 'wpsc_hide_featured_products' ) == 1) 
  35. add_action( 'wpsc_top_of_products_page', 'wpsc_display_featured_products_page', 12 ); 
  36.  
  37. $show_subcatsprods_in_cat = get_option( 'show_subcatsprods_in_cat' ); 
  38. if(!$show_subcatsprods_in_cat) 
  39. add_action( 'init', 'wpsc_hidesubcatprods_init' ); 
  40.  
  41. /** 
  42. * wpsc_register_theme_file( $file_name ) 
  43. * 
  44. * Adds a file name to a global list of 
  45. * 
  46. * @param string $file_name Name of file to add to global list of files 
  47. */ 
  48. function wpsc_register_theme_file( $file_name ) { 
  49. global $wpec_theme_files; 
  50.  
  51. if ( !in_array( $file_name, (array)$wpec_theme_files ) ) 
  52. $wpec_theme_files[] = $file_name; 
  53.  
  54. /** 
  55. * wpsc_register_core_theme_files() 
  56. * 
  57. * Registers the core WPEC files into the global array 
  58. */ 
  59. function wpsc_register_core_theme_files() { 
  60. wpsc_register_theme_file( 'wpsc-single_product.php' ); 
  61. wpsc_register_theme_file( 'wpsc-grid_view.php' ); 
  62. wpsc_register_theme_file( 'wpsc-list_view.php' ); 
  63. wpsc_register_theme_file( 'wpsc-products_page.php' ); 
  64. wpsc_register_theme_file( 'wpsc-shopping_cart_page.php' ); 
  65. wpsc_register_theme_file( 'wpsc-transaction_results.php' ); 
  66. wpsc_register_theme_file( 'wpsc-user-log.php' ); 
  67. wpsc_register_theme_file( 'wpsc-cart_widget.php' ); 
  68. wpsc_register_theme_file( 'wpsc-featured_product.php' ); 
  69. wpsc_register_theme_file( 'wpsc-category-list.php' ); 
  70. wpsc_register_theme_file( 'wpsc-category_widget.php' ); 
  71. wpsc_register_theme_file( 'wpsc-account-downloads.php' ); 
  72. wpsc_register_theme_file( 'wpsc-account-edit-profile.php' ); 
  73. wpsc_register_theme_file( 'wpsc-account-purchase-history.php' ); 
  74.  
  75. /** Let other plugins register their theme files */ 
  76. do_action( 'wpsc_register_core_theme_files' ); 
  77.  
  78. /** 
  79. * wpsc_get_theme_files() 
  80. * 
  81. * Returns the global wpec_theme_files 
  82. * 
  83. * @global array $wpec_theme_files 
  84. * @return array 
  85. */ 
  86. function wpsc_get_theme_files() { 
  87. global $wpec_theme_files; 
  88. if ( empty( $wpec_theme_files ) ) 
  89. return array(); 
  90. else 
  91. return apply_filters( 'wpsc_get_theme_files', (array)array_values( $wpec_theme_files ) ); 
  92.  
  93. /** 
  94. * wpsc_flush_theme_transients() 
  95. * 
  96. * This function will delete the temporary values stored in WordPress transients 
  97. * for all of the additional WPEC theme files and their locations. This is 
  98. * mostly used when the active theme changes, or when files are moved around. It 
  99. * does a complete flush of all possible path/url combinations of files. 
  100. * 
  101. * @uses wpsc_get_theme_files 
  102. */ 
  103. function wpsc_flush_theme_transients( $force = false ) { 
  104.  
  105. if ( true === $force || isset( $_REQUEST['wpsc_flush_theme_transients'] ) && !empty( $_REQUEST['wpsc_flush_theme_transients'] ) ) { 
  106.  
  107. // Loop through current theme files and remove transients 
  108. if ( $theme_files = wpsc_get_theme_files() ) { 
  109. foreach( $theme_files as $file ) { 
  110. delete_transient( WPEC_TRANSIENT_THEME_PATH_PREFIX . $file ); 
  111. delete_transient( WPEC_TRANSIENT_THEME_URL_PREFIX . $file ); 
  112.  
  113. delete_transient( 'wpsc_theme_path' ); 
  114.  
  115. return true; 
  116.  
  117. // No files were registered so return false 
  118. return false; 
  119.  
  120. function wpsc_force_flush_theme_transients() { 
  121.  
  122. if ( ! wpsc_is_store_admin() ) { 
  123. return; 
  124.  
  125. // Flush transients 
  126. wpsc_flush_theme_transients( true ); 
  127.  
  128. // Bounce back 
  129. $sendback = wp_get_referer(); 
  130. wp_redirect( $sendback ); 
  131.  
  132. exit(); 
  133.  
  134. /** 
  135. * wpsc_check_theme_location() 
  136. * 
  137. * Check theme location, compares the active theme and the themes within WPSC_CORE_THEME_PATH 
  138. * finds files of the same name. 
  139. * 
  140. * @access public 
  141. * @since 3.8 
  142. * @param null 
  143. * @return $results (Array) of Files OR false if no similar files are found 
  144. */ 
  145. function wpsc_check_theme_location() { 
  146. // Get the current theme 
  147. $current_theme = get_stylesheet_directory(); 
  148.  
  149. // Load up the files in the current theme 
  150. $current_theme_files = wpsc_list_product_templates( $current_theme . '/' ); 
  151.  
  152. // Load up the files in the wpec themes folder 
  153. $wpsc_template_files = wpsc_list_product_templates( WPSC_CORE_THEME_PATH ); 
  154.  
  155. // Compare the two 
  156. $results = array_intersect( $current_theme_files, $wpsc_template_files ); 
  157.  
  158. // Return the differences 
  159. if ( count( $results ) > 0 ) 
  160. return $results; 
  161.  
  162. // No differences so return false 
  163. else 
  164. return false; 
  165.  
  166. /** 
  167. * wpsc_list_product_templates( $path = '' ) 
  168. * 
  169. * Lists the files within the WPSC_CORE_THEME_PATH directory 
  170. * 
  171. * @access public 
  172. * @since 3.8 
  173. * @param $path - you can provide a path to find the files within it 
  174. * @return $templates (Array) List of files 
  175. */ 
  176. function wpsc_list_product_templates( $path = '' ) { 
  177.  
  178. $selected_theme = get_option( 'wpsc_selected_theme' ); 
  179.  
  180. // If no path, then try to make some assuptions 
  181. if ( empty( $path ) ) { 
  182. if ( file_exists( WPSC_OLD_THEMES_PATH . $selected_theme . '/' . $selected_theme . '.css' ) ) { 
  183. $path = WPSC_OLD_THEMES_PATH . $selected_theme . '/'; 
  184. } else { 
  185. $path = WPSC_CORE_THEME_PATH; 
  186.  
  187. // Open the path and get the file names 
  188. $dh = opendir( $path ); 
  189. while ( ( $file = readdir( $dh ) ) !== false ) { 
  190. if ( $file != "." && $file != ".." && !strstr( $file, ".svn" ) && !strstr( $file, "images" ) && is_file( $path . $file ) ) { 
  191. $templates[] = $file; 
  192.  
  193. // Return template names 
  194. return $templates; 
  195.  
  196. /** 
  197. * Displays the theme upgrade notice 
  198. * @access public 
  199. * 
  200. * @since 3.8 
  201. * @param null 
  202. * @return null 
  203. */ 
  204. function wpsc_theme_upgrade_notice() { ?> 
  205.  
  206. <div id="message" class="updated fade"> 
  207. <p><?php printf( __( '<strong>WP eCommerce is ready</strong>. If you plan on editing the look of your site, you should <a href="%1s">update your active theme</a> to include the additional WP eCommerce files. <a href="%2s">Click here</a> to ignore and remove this box.', 'wpsc' ), admin_url( 'admin.php?page=wpsc-settings&tab=presentation' ), admin_url( 'admin.php?page=wpsc-settings&tab=presentation&wpsc_notices=theme_ignore' ) ) ?></p> 
  208. </div> 
  209.  
  210. <?php 
  211.  
  212. /** 
  213. * Displays the database update notice 
  214. * @access public 
  215. * 
  216. * @since 3.8 
  217. * @param null 
  218. * @return null 
  219. */ 
  220. function wpsc_database_update_notice() { ?> 
  221.  
  222. <div class="error fade"> 
  223. <p><?php printf( __( '<strong>Your WP eCommerce data needs to be updated</strong>. You\'ve upgraded from a previous version of the WP eCommerce plugin, and your store needs updating.<br>You should <a href="%1s">update your database</a> for your store to continue working.', 'wpsc' ), admin_url( 'index.php?page=wpsc-update' ) ) ?></p> 
  224. </div> 
  225.  
  226. <?php 
  227.  
  228.  
  229. function wpsc_theme_admin_notices() { 
  230.  
  231. // Check to see if WP eCommerce is installed before showing upgrade notices. 
  232. if ( false !== get_option( 'wpsc_version' ) ) { 
  233.  
  234. // Database update notice is most important 
  235. if ( get_option ( 'wpsc_version' ) < 3.8 ) { 
  236.  
  237. add_action ( 'admin_notices', 'wpsc_database_update_notice' ); 
  238.  
  239. // If that's not an issue check if theme updates required 
  240. } else { 
  241.  
  242. if ( '' === get_option( 'wpsc_ignore_theme', '' ) ) { 
  243. add_option( 'wpsc_ignore_theme', false ); 
  244.  
  245. if ( ! get_option( 'wpsc_ignore_theme' ) ) { 
  246. add_action( 'admin_notices', 'wpsc_theme_upgrade_notice' ); 
  247.  
  248.  
  249.  
  250. // Flag config inconsistencies 
  251. if ( 1 == get_option( 'require_register' ) && 1 != get_option( 'users_can_register' ) ) { 
  252. add_action( 'admin_notices', 'wpsc_turn_on_wp_register' ); 
  253.  
  254.  
  255. function wpsc_turn_on_wp_register() {?> 
  256.  
  257. <div id="message" class="updated fade"> 
  258. <p><?php printf( __( '<strong>Store Settings</strong>: You have set \'users must register before checkout\', for this to work you need to check \'Anyone can register\' in your WordPress <a href="%1s">General Settings</a>.', 'wpsc' ), admin_url( 'options-general.php' ) ) ?></p> 
  259. </div> 
  260.  
  261. <?php 
  262.  
  263.  
  264.  
  265. /** 
  266. * wpsc_get_template_file_url( $file ) 
  267. * 
  268. * Checks the active theme folder for the particular file, if it exists then 
  269. * return the active theme url, otherwise return the global wpsc_theme_url 
  270. * 
  271. * @access public 
  272. * @since 3.8 
  273. * @param $file string filename 
  274. * @return PATH to the file 
  275. */ 
  276. function wpsc_get_template_file_url( $file = '' ) { 
  277. // If we're not looking for a file, do not proceed 
  278. if ( empty( $file ) ) 
  279. return; 
  280.  
  281. // Look for file in stylesheet 
  282. if ( file_exists( get_stylesheet_directory() . '/' . $file ) ) { 
  283. $file_url = get_stylesheet_directory_uri() . '/' . $file; 
  284.  
  285. // Look for file in template 
  286. } elseif ( file_exists( get_template_directory() . '/' . $file ) ) { 
  287. $file_url = get_template_directory_uri() . '/' . $file; 
  288.  
  289. // Backwards compatibility 
  290. } else { 
  291. // Look in old theme url 
  292. $selected_theme_check = WPSC_OLD_THEMES_PATH . get_option( 'wpsc_selected_theme' ) . '/' . str_ireplace( 'wpsc-', '', $file ); 
  293. // Check the selected theme 
  294. if ( file_exists( $selected_theme_check ) ) { 
  295.  
  296. $file_url = WPSC_OLD_THEMES_URL . get_option( 'wpsc_selected_theme' ) . '/' . str_ireplace( 'wpsc-', '', $file ); 
  297. // Use the bundled theme CSS 
  298. } else { 
  299. $file_url = WPSC_CORE_THEME_URL . $file; 
  300.  
  301. $file_url = set_url_scheme( $file_url ); 
  302.  
  303. // Return filtered result 
  304. return apply_filters( WPEC_TRANSIENT_THEME_URL_PREFIX . $file, $file_url ); 
  305.  
  306. /** 
  307. * wpsc_user_enqueues products function,  
  308. * enqueue all javascript and CSS for wp ecommerce 
  309. */ 
  310. function wpsc_enqueue_user_script_and_css() { 
  311. global $wp_styles, $wpsc_theme_url, $wp_query; 
  312. /** 
  313. * added by xiligroup.dev to be compatible with touchshop 
  314. */ 
  315. if ( has_filter( 'wpsc_enqueue_user_script_and_css' ) && apply_filters( 'wpsc_mobile_scripts_css_filters', false ) ) { 
  316. do_action( 'wpsc_enqueue_user_script_and_css' ); 
  317. } else { 
  318. /** 
  319. * end of added by xiligroup.dev to be compatible with touchshop 
  320. */ 
  321. $version_identifier = WPSC_VERSION . '.' . WPSC_MINOR_VERSION; 
  322.  
  323. $category_id = wpsc_get_current_category_id(); 
  324.  
  325. if ( get_option( 'wpsc_share_this' ) == 1 ) { 
  326. $remote_protocol = is_ssl() ? 'https://ws' : 'http://w'; 
  327. wp_enqueue_script( 'sharethis', $remote_protocol . '.sharethis.com/button/buttons.js', array(), false, true ); 
  328.  
  329. wp_enqueue_script( 'jQuery' ); 
  330. wp_enqueue_script( 'wp-e-commerce', WPSC_CORE_JS_URL . '/wp-e-commerce.js', array( 'jquery' ), $version_identifier ); 
  331.  
  332. if ( defined( 'WPEC_LOAD_DEPRECATED_JS' ) && WPEC_LOAD_DEPRECATED_JS ) { 
  333. wp_enqueue_script( 'wpsc-deprecated', WPSC_CORE_JS_URL . '/wpsc-deprecated.js', 'wp-e-commerce', $version_identifier ); 
  334. wp_localize_script( 'wpsc-deprecated', 'wpsc_deprecated_js_vars', _wpsc_deprecated_javascript_localization_vars() ); 
  335.  
  336. wp_enqueue_script( 'wp-e-commerce', WPSC_CORE_JS_URL . '/wp-e-commerce.js', array( 'jquery' ), $version_identifier ); 
  337. wp_localize_script( 'wp-e-commerce', 'wpsc_vars', wpsc_javascript_localizations() ); 
  338.  
  339. wp_enqueue_script( 'livequery', WPSC_URL . '/wpsc-admin/js/jquery.livequery.js', array( 'jquery' ), '1.0.3' ); 
  340. if ( get_option( 'product_ratings' ) == 1 ) 
  341. wp_enqueue_script( 'jquery-rating', WPSC_CORE_JS_URL . '/jquery.rating.js', array( 'jquery' ), $version_identifier ); 
  342. wp_enqueue_script( 'wp-e-commerce-legacy', WPSC_CORE_JS_URL . '/user.js', array( 'jquery' ), WPSC_VERSION . WPSC_MINOR_VERSION ); 
  343. if ( get_option( 'show_thumbnails_thickbox' ) == 1 ) { 
  344. $lightbox = get_option('wpsc_lightbox', 'thickbox'); 
  345. if( $lightbox == 'thickbox' ) { 
  346. wp_enqueue_script( 'wpsc-thickbox', WPSC_CORE_JS_URL . '/thickbox.js', array( 'jquery' ), 'Instinct_e-commerce' ); 
  347. wp_enqueue_style( 'wpsc-thickbox', WPSC_CORE_JS_URL . '/thickbox.css', false, $version_identifier, 'all' ); 
  348. } elseif( $lightbox == 'colorbox' ) { 
  349. wp_enqueue_script( 'colorbox-min', WPSC_CORE_JS_URL . '/jquery.colorbox-min.js', array( 'jquery' ), 'Instinct_e-commerce' ); 
  350. wp_enqueue_script( 'wpsc_colorbox', WPSC_CORE_JS_URL . '/wpsc_colorbox.js', array( 'jquery', 'colorbox-min' ), 'Instinct_e-commerce' ); 
  351. wp_enqueue_style( 'wpsc-colorbox-css', WPSC_CORE_JS_URL . '/wpsc_colorbox.css', false, $version_identifier, 'all' ); 
  352. wp_enqueue_style( 'wpsc-theme-css', wpsc_get_template_file_url( 'wpsc-' . get_option( 'wpsc_selected_theme' ) . '.css' ), false, $version_identifier, 'all' ); 
  353. wp_enqueue_style( 'wpsc-theme-css-compatibility', wpsc_get_template_file_url( 'compatibility.css' ), array( 'wpsc-theme-css' ), $version_identifier, 'all' ); 
  354.  
  355. if ( function_exists( 'wp_add_inline_style' ) ) 
  356. wp_add_inline_style( 'wpsc-theme-css', wpsc_get_user_dynamic_css() ); 
  357. else 
  358. wp_enqueue_style( 'wp-e-commerce-dynamic', wpsc_get_dynamic_user_css_url(), array( 'wpsc-theme-css' ), $version_identifier ); 
  359.  
  360. if( get_option( 'product_ratings' ) == 1 ) 
  361. wp_enqueue_style( 'wpsc-product-rater', WPSC_CORE_JS_URL . '/product_rater.css', false, $version_identifier, 'all' ); 
  362.  
  363.  
  364.  
  365. if ( !defined( 'WPSC_MP3_MODULE_USES_HOOKS' ) && function_exists( 'listen_button' ) ) { 
  366.  
  367. function wpsc_legacy_add_mp3_preview( $product_id, &$product_data ) { 
  368. global $wpdb; 
  369. if ( function_exists( 'listen_button' ) ) { 
  370. $file_data = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM `" . WPSC_TABLE_PRODUCT_FILES . "` WHERE `id` = %d LIMIT 1", $product_data['file'] ), ARRAY_A ); 
  371. if ( $file_data != null ) { 
  372. echo listen_button( $file_data['idhash'], $file_data['id'] ); 
  373.  
  374. add_action( 'wpsc_product_before_description', 'wpsc_legacy_add_mp3_preview', 10, 2 ); 
  375.  
  376. /** 
  377. * Checks the category slug for a display type, if none set returns default 
  378. * << May need reworking to be more specific to the taxonomy type >> 
  379. * @access public 
  380. * 
  381. * @since 3.8 
  382. * @param $slug(string) 
  383. * @return $slug either from db or 'default' if none set 
  384. */ 
  385.  
  386. function wpsc_get_the_category_display($slug) { 
  387. global $wpdb; 
  388. $default_display_type = get_option('product_view'); 
  389. if ( !empty($slug) && is_string($slug) ) { 
  390. $category_id = wpsc_get_the_category_id($slug , 'slug'); 
  391. $display_type = wpsc_get_categorymeta( $category_id, 'display_type' ); 
  392. if(!empty($display_type)) 
  393. return $display_type; 
  394. else 
  395. return $default_display_type; 
  396.  
  397. /** 
  398. * wpsc display products function 
  399. * @return string - html displaying one or more products 
  400. */ 
  401. function wpsc_display_products_page( $query ) { 
  402. global $wpdb, $wpsc_query, $wp_query, $wp_the_query; 
  403.  
  404. remove_filter('the_title', 'wpsc_the_category_title'); 
  405.  
  406. // If the data is coming from a shortcode parse the values into the args variable,  
  407. // I did it this was to preserve backwards compatibility 
  408. if(!empty($query)) { 
  409. $args = array(); 
  410.  
  411. $args['post_type'] = 'wpsc-product'; 
  412. if(!empty($query['product_id']) && is_array($query['product_id'])) { 
  413. $args['post__in'] = $query['product_id']; 
  414. }elseif(is_string($query['product_id'])) { 
  415. $args['post__in'] = (array)$query['product_id']; 
  416. if(!empty($query['old_product_id'])) { 
  417. $post_id = wpsc_get_the_new_id($query['old_product_id']); 
  418. $args['post__in'] = (array)$post_id; 
  419. if(!empty($query['price']) && 'sale' != $query['price']) { 
  420. $args['meta_key'] = '_wpsc_price'; 
  421. $args['meta_value'] = $query['price']; 
  422. }elseif(!empty($query['price']) && 'sale' == $query['price']) { 
  423. $args['meta_key'] = '_wpsc_special_price'; 
  424. $args['meta_compare'] = '>='; 
  425. $args['meta_value'] = '1'; 
  426. if(!empty($query['product_name'])) { 
  427. $args['pagename'] = $query['product_name']; 
  428. if(!empty($query['category_id'])) { 
  429. $term = get_term($query['category_id'], 'wpsc_product_category'); 
  430. $id = wpsc_get_meta($query['category_id'], 'category_id', 'wpsc_old_category'); 
  431. if( !empty($id)) { 
  432. $term = get_term($id, 'wpsc_product_category'); 
  433. $args['wpsc_product_category'] = $term->slug; 
  434. $args['wpsc_product_category__in'] = $term->term_id; 
  435. }else{ 
  436. $args['wpsc_product_category'] = $term->slug; 
  437. $args['wpsc_product_category__in'] = $term->term_id; 
  438. if(!empty($query['category_url_name'])) { 
  439. $args['wpsc_product_category'] = $query['category_url_name']; 
  440. $orderby = ( !empty($query['sort_order']) ) ? $query['sort_order'] : null; 
  441.  
  442. $args = array_merge( $args, wpsc_product_sort_order_query_vars($orderby) ); 
  443.  
  444. if(!empty($query['order'])) { 
  445. $args['order'] = $query['order']; 
  446. if(!empty($query['limit_of_items']) && '1' == get_option('use_pagination')) { 
  447. $args['posts_per_page'] = $query['limit_of_items']; 
  448. if(!empty($query['number_per_page']) && '1' == get_option('use_pagination')) { 
  449. $args['posts_per_page'] = $query['number_per_page']; 
  450. $args['paged'] = $query['page']; 
  451. if( '0' == get_option('use_pagination') ) { 
  452. $args['nopaging'] = true; 
  453. $args['posts_per_page'] = '-1'; 
  454.  
  455. if ( ! empty( $query['tag'] ) ) { 
  456. $args['product_tag'] = $query['tag']; 
  457.  
  458. query_posts( $args ); 
  459.  
  460.  
  461. // swap the wpsc_query objects 
  462.  
  463. $GLOBALS['nzshpcrt_activateshpcrt'] = true; 
  464.  
  465. // Pretty sure this single_product code is legacy...but fixing it up just in case. 
  466. // get the display type for the selected category 
  467. if(!empty($wpsc_query->query_vars['term'])) 
  468. $display_type = wpsc_get_the_category_display($wpsc_query->query_vars['term']); 
  469. elseif( !empty( $args['wpsc_product_category'] ) ) 
  470. $display_type = wpsc_get_the_category_display($args['wpsc_product_category']); 
  471. else 
  472. $display_type = 'default'; 
  473.  
  474. $saved_display = wpsc_get_customer_meta( 'display_type' ); 
  475. $display_type = ! empty( $saved_display ) ? $saved_display : $display_type; 
  476.  
  477. ob_start(); 
  478.  
  479. do_action( 'wpsc_display_products_page', $display_type ); 
  480.  
  481. if ( ( isset( $wp_query->post ) && 'wpsc-product' == $wp_query->post->post_type ) && ! is_archive() && $wp_query->post_count <= 1 ) 
  482. include( wpsc_get_template_file_path( 'wpsc-single_product.php' ) ); 
  483. else 
  484. wpsc_include_products_page_template( $display_type ); 
  485.  
  486. $output = ob_get_contents(); 
  487. ob_end_clean(); 
  488. $output = str_replace( '\$', '$', $output ); 
  489.  
  490. if ( ! empty( $query ) ) { 
  491. wp_reset_query(); 
  492. wp_reset_postdata(); 
  493.  
  494. return $output; 
  495.  
  496. /** 
  497. * Checks if wpsc-single_product.php has been moved to the active theme, if it has then include the 
  498. * template from the active theme. 
  499. * @access public 
  500. * 
  501. * @since 3.8 
  502. * @param $content content of the page 
  503. * @return $content with wpsc-single_product content if its a single product 
  504. */ 
  505. function wpsc_single_template( $content ) { 
  506. global $wpdb, $post, $wp_query, $wpsc_query, $_wpsc_is_in_custom_loop; 
  507. if ( ! in_the_loop() ) 
  508. return $content; 
  509.  
  510. //if we dont belong here exit out straight away 
  511. if((!isset($wp_query->is_product)) && !isset($wp_query->query_vars['wpsc_product_category']))return $content; 
  512.  
  513. // If we are a single products page 
  514. if ( !is_archive() && $wp_query->post_count > 0 && 'wpsc-product' == $wp_query->post->post_type && $wp_query->post_count <= 1 ) { 
  515. remove_filter( "the_content", "wpsc_single_template", 12 ); 
  516. $single_theme_path = wpsc_get_template_file_path( 'wpsc-single_product.php' ); 
  517.  
  518. $is_preview = isset( $wp_query->query_vars['preview'] ) && $wp_query->query_vars['preview']; 
  519.  
  520. $wpsc_temp_query = new WP_Query( array( 'p' => $wp_query->post->ID , 'post_type' => 'wpsc-product', 'posts_per_page' => 1, 'preview' => $is_preview ) ); 
  521.  
  522. list( $wp_query, $wpsc_temp_query ) = array( $wpsc_temp_query, $wp_query ); // swap the wpsc_query object 
  523. $_wpsc_is_in_custom_loop = true; 
  524. ob_start(); 
  525. include( $single_theme_path ); 
  526. $content = ob_get_contents(); 
  527. ob_end_clean(); 
  528. list( $wp_query, $wpsc_temp_query ) = array( $wpsc_temp_query, $wp_query ); // swap the wpsc_query objects back 
  529. $_wpsc_is_in_custom_loop = false; 
  530.  
  531. return $content; 
  532.  
  533. function wpsc_is_viewable_taxonomy() { 
  534. global $wp_query; 
  535. if(isset($wp_query->query_vars['taxonomy']) && ('wpsc_product_category' == $wp_query->query_vars['taxonomy'] || 'product_tag' == $wp_query->query_vars['taxonomy'] ) || isset($wp_query->query_vars['wpsc_product_category'])) 
  536. return true; 
  537. else 
  538. return false; 
  539.  
  540. function _wpsc_is_in_custom_loop() { 
  541. global $_wpsc_is_in_custom_loop; 
  542. return (bool) $_wpsc_is_in_custom_loop; 
  543.  
  544. /** 
  545. * Checks and replaces the Page title with the category title if on a category page 
  546. * 
  547. * @since 3.8 
  548. * @access public 
  549. * 
  550. * @param string $title The Page Title 
  551. * @param int $id The Page ID 
  552. * @return string $title The new title 
  553. * 
  554. * @uses in_the_loop() Returns true if you are in the loop 
  555. * @uses _wpsc_is_in_custom_loop() Returns true if in the WPSC custom loop 
  556. * @uses is_tax() Returns true if you are on the supplied registered taxonomy 
  557. * @uses get_term_by() Gets term object by defined item, and what you pass 
  558. * @uses get_query_var() Gets query var from wp_query 
  559. */ 
  560. function wpsc_the_category_title( $title='', $id='' ) { 
  561.  
  562. if ( ! empty( $id ) ) 
  563. _wpsc_deprecated_argument( __FUNCTION__, '3.8.10', 'The $id param is not used. If you are trying to get the title of the category use get_term' ); 
  564.  
  565. if ( ! in_the_loop() || _wpsc_is_in_custom_loop() ) 
  566. return $title; 
  567.  
  568. $term = null; 
  569. if ( is_tax( 'wpsc_product_category' ) ) { 
  570. $term = get_term_by( 'slug', get_query_var( 'wpsc_product_category' ), 'wpsc_product_category' ); 
  571. } elseif ( is_tax( 'product_tag' ) ) { 
  572. $term = get_term_by( 'slug', get_query_var( 'term' ), 'product_tag' ); 
  573. } // is_tax 
  574.  
  575. if ( $term ) 
  576. return $term->name; 
  577.  
  578. return $title; 
  579.  
  580.  
  581. //handles replacing the tags in the pages 
  582. function wpsc_products_page( $content = '' ) { 
  583. global $wpdb, $wp_query, $wpsc_query, $wpsc_query_vars, $_wpsc_is_in_custom_loop; 
  584. $output = ''; 
  585. if ( ! in_the_loop() ) 
  586. return $content; 
  587. if ( preg_match( "/\[productspage\]/", $content ) ) { 
  588. global $more; 
  589. $more = 0; 
  590. remove_filter( 'the_content', 'wpautop' ); 
  591.  
  592. list($wp_query, $wpsc_query) = array( $wpsc_query, $wp_query ); // swap the wpsc_query object 
  593. $_wpsc_is_in_custom_loop = true; 
  594.  
  595. $GLOBALS['nzshpcrt_activateshpcrt'] = true; 
  596.  
  597. // get the display type for the productspage 
  598. $saved_display = wpsc_get_customer_meta( 'display_type' ); 
  599. $display_type = ! empty( $saved_display ) ? $saved_display : wpsc_check_display_type(); 
  600.  
  601. ob_start(); 
  602.  
  603. do_action( 'wpsc_display_products_page', $display_type ); 
  604.  
  605. wpsc_include_products_page_template($display_type); 
  606. $is_single = false; 
  607. $output .= ob_get_contents(); 
  608. ob_end_clean(); 
  609. $output = str_replace( '$', '\$', $output ); 
  610.  
  611. if ( $wp_query->post_count > 0 ) { 
  612. $product_id = $wp_query->post->ID; 
  613. $product_meta = get_post_meta( $product_id, '_wpsc_product_metadata', true ); 
  614.  
  615. list($wp_query, $wpsc_query) = array( $wpsc_query, $wp_query ); // swap the wpsc_query objects back 
  616.  
  617. $_wpsc_is_in_custom_loop = false; 
  618.  
  619. if ( ($is_single == false) || ($product_meta['enable_comments'] == '0') ) 
  620. wp_reset_postdata(); 
  621. $wp_query->current_post = $wp_query->post_count; 
  622. return preg_replace( "/(<p>)*\[productspage\](<\/p>)*/", $output, $content ); 
  623. } elseif(is_archive() && wpsc_is_viewable_taxonomy()) { 
  624.  
  625. remove_filter( 'the_content', 'wpautop' ); 
  626. return wpsc_products_page('[productspage]'); 
  627. } else { 
  628. return $content; 
  629.  
  630. /** 
  631. * wpsc_the_category_template swaps the template used for product categories with pageif archive template is being used use 
  632. * @access public 
  633. * 
  634. * @since 3.8 
  635. * @param $template (string) template path 
  636. * @return $template (string) 
  637. */ 
  638. function wpsc_the_category_template($template) { 
  639. global $wp_query; 
  640. //this bit of code makes sure we use a nice standard page template for our products 
  641. if(wpsc_is_viewable_taxonomy() && false !== strpos($template, 'archive')) 
  642. return str_ireplace('archive', 'page', $template); 
  643. else 
  644. return $template; 
  645.  
  646.  
  647. /** 
  648. * Returns current product category ID or default category ID if one is set. If one is not set and there is no current category, returns empty string 
  649. * @return mixed 
  650. */ 
  651. function wpsc_get_current_category_id() { 
  652. global $wp_query; 
  653.  
  654. $category_id = ''; 
  655.  
  656. if ( isset( $wp_query ) && isset( $wp_query->query_vars['taxonomy'] ) && ('wpsc_product_category' == $wp_query->query_vars['taxonomy'] ) || is_numeric( get_option( 'wpsc_default_category' ) ) ) 
  657. $category_id = isset( $wp_query->query_vars['term'] ) && is_string( $wp_query->query_vars['term'] ) ? wpsc_get_category_id( $wp_query->query_vars['term'], 'slug' ) : get_option( 'wpsc_default_category' ); 
  658.  
  659. return $category_id; 
  660.  
  661. /** 
  662. * Returns Dynamic User CSS URL 
  663. * 
  664. * This produces the cached CSS file if it exists and the uploads folder is writeable. 
  665. * If the folder is not writeable, we return the dynamic URL 
  666. * If the folder is writeable, but for some reason a cached copy of the CSS doesn't exist, we attempt to create it and return that URL. 
  667. * 
  668. * @since 3.8.9 
  669. * @return string 
  670. */ 
  671.  
  672. function wpsc_get_dynamic_user_css_url() { 
  673.  
  674. $uploads_dir = wp_upload_dir(); 
  675. $upload_folder = $uploads_dir['path']; 
  676.  
  677. if ( is_writable( $upload_folder ) && file_exists( $upload_folder . '/wpsc_cached_styles.css' ) ) 
  678. return esc_url( add_query_arg( 'timestamp', get_option( 'wpsc_dynamic_css_hash', time() ), $uploads_dir['url'] . '/wpsc_cached_styles.css' ) ); 
  679.  
  680. if ( ! is_writable( $upload_folder ) ) 
  681. return esc_url( add_query_arg( 'wpsc_user_dynamic_css', 'true', home_url( 'index.php' ) ) ); 
  682.  
  683. if ( is_writable( $upload_folder ) && ! file_exists( $upload_folder . '/wpsc_cached_styles.css' ) ) 
  684. return wpsc_cache_to_upload(); 
  685.  
  686. /** 
  687. * Moves dynamically generated input into a file in the uploads folder. 
  688. * Also updates CSS hash timestamp. Timestamp is appended to URL 
  689. * 
  690. * @since 3.8.9 
  691. * @return mixed File URL on successful move, false on failure 
  692. */ 
  693. function wpsc_cache_to_upload() { 
  694.  
  695. $uploads_dir = wp_upload_dir(); 
  696. $upload_folder = $uploads_dir['path']; 
  697. $path = $upload_folder . '/wpsc_cached_styles.css'; 
  698.  
  699. if ( ! is_writable( $upload_folder ) ) 
  700. return false; 
  701.  
  702. if ( false === file_put_contents( $path, wpsc_get_user_dynamic_css() ) ) 
  703. return false; 
  704.  
  705. $timestamp = time(); 
  706.  
  707. update_option( 'wpsc_dynamic_css_hash', $timestamp ); 
  708.  
  709. return esc_url( add_query_arg( 'timestamp', $timestamp, $uploads_dir['url'] . '/wpsc_cached_styles.css' ) ); 
  710.  
  711.  
  712. /** 
  713. * Prints dynamic CSS. This function is run either when the dynamic URL is hit, or when we need to grab new CSS to cache. 
  714. * 
  715. * @since 3.8.9 
  716. * @return CSS 
  717. */ 
  718. function wpsc_user_dynamic_css() { 
  719.  
  720. header( 'Content-Type: text/css' ); 
  721. header( 'Expires: ' . gmdate( 'r', mktime( 0, 0, 0, date( 'm' ), ( date( 'd' ) + 12 ), date( 'Y' ) ) ) ); 
  722. header( 'Cache-Control: public, must-revalidate, max-age=86400' ); 
  723. header( 'Pragma: public' ); 
  724.  
  725. echo wpsc_get_user_dynamic_css(); 
  726. exit; 
  727.  
  728. /** 
  729. * Returns dynamic CSS as string. This function is run either when the dynamic URL is hit, or when we need to grab new CSS to cache. 
  730. * 
  731. * @since 3.8.9 
  732. * @return string 
  733. */ 
  734. function wpsc_get_user_dynamic_css() { 
  735. global $wpdb; 
  736.  
  737. ob_start(); 
  738.  
  739. if ( ! defined( 'WPSC_DISABLE_IMAGE_SIZE_FIXES' ) || (constant( 'WPSC_DISABLE_IMAGE_SIZE_FIXES' ) != true ) ) { 
  740.  
  741. $thumbnail_width = get_option( 'product_image_width' ); 
  742.  
  743. if ( $thumbnail_width <= 0 ) 
  744. $thumbnail_width = 96; 
  745.  
  746. $thumbnail_height = get_option( 'product_image_height' ); 
  747.  
  748. if ( $thumbnail_height <= 0 ) 
  749. $thumbnail_height = 96; 
  750.  
  751. $single_thumbnail_width = get_option( 'single_view_image_width' ); 
  752. $single_thumbnail_height = get_option( 'single_view_image_height' ); 
  753.  
  754. if ( $single_thumbnail_width <= 0 ) 
  755. $single_thumbnail_width = 128; 
  756.  
  757. $category_height = get_option( 'category_image_height' ); 
  758. $category_width = get_option( 'category_image_width' ); 
  759. ?> 
  760.  
  761. /* 
  762. * Default View Styling 
  763. */ 
  764. div.default_product_display div.textcol{ 
  765. margin-left: <?php echo $thumbnail_width + 10; ?>px !important; 
  766. min-height: <?php echo $thumbnail_height; ?>px; 
  767. _height: <?php echo $thumbnail_height; ?>px; 
  768.  
  769. div.default_product_display div.textcol div.imagecol{ 
  770. position:absolute; 
  771. top:0px; 
  772. left: 0px; 
  773. margin-left: -<?php echo $thumbnail_width + 10; ?>px !important; 
  774.  
  775. div.default_product_display div.textcol div.imagecol a img { 
  776. width: <?php echo $thumbnail_width; ?>px; 
  777. height: <?php echo $thumbnail_height; ?>px; 
  778.  
  779. .wpsc_category_grid_item { 
  780. display:block; 
  781. float:left; 
  782. width: <?php echo $category_width; ?>px; 
  783. height: <?php echo $category_height; ?>px; 
  784. .wpsc_category_grid_item span{ 
  785. position:relative; 
  786. top:<?php echo ($thumbnail_height - 2)/9; ?>px; 
  787. div.default_product_display div.item_no_image a { 
  788. width: <?php echo $thumbnail_width - 2; ?>px; 
  789.  
  790. div.default_product_display .imagecol img.no-image, #content div.default_product_display .imagecol img.no-image { 
  791. width: <?php echo $thumbnail_width; ?>px; 
  792. height: <?php echo $thumbnail_height; ?>px; 
  793.  
  794. <?php do_action( 'wpsc_dynamic_css' ); ?> 
  795.  
  796. /* 
  797. * Single View Styling 
  798. */ 
  799.  
  800. div.single_product_display div.item_no_image { 
  801. width: <?php echo $single_thumbnail_width - 2; ?>px; 
  802. height: <?php echo $single_thumbnail_height - 2; ?>px; 
  803. div.single_product_display div.item_no_image a { 
  804. width: <?php echo $single_thumbnail_width - 2; ?>px; 
  805.  
  806. div.single_product_display div.textcol{ 
  807. margin-left: <?php echo $single_thumbnail_width + 10; ?>px !important; 
  808. min-height: <?php echo $single_thumbnail_height; ?>px; 
  809. _height: <?php echo $single_thumbnail_height; ?>px; 
  810.  
  811.  
  812. div.single_product_display div.textcol div.imagecol{ 
  813. position:absolute; 
  814.  
  815. margin-left: -<?php echo $single_thumbnail_width + 10; ?>px !important; 
  816.  
  817. div.single_product_display div.textcol div.imagecol a img { 
  818. width: <?php echo $single_thumbnail_width; ?>px; 
  819. height: <?php echo $single_thumbnail_height; ?>px; 
  820.  
  821. <?php 
  822. if ( (isset($_GET['brand']) && is_numeric( $_GET['brand'] )) || (get_option( 'show_categorybrands' ) == 3) ) { 
  823. $brandstate = 'block'; 
  824. $categorystate = 'none'; 
  825. } else { 
  826. $brandstate = 'none'; 
  827. $categorystate = 'block'; 
  828. ?> 
  829. div#categorydisplay{ 
  830. display: <?php echo $categorystate; ?>; 
  831.  
  832. div#branddisplay{ 
  833. display: <?php echo $brandstate; ?>; 
  834. <?php 
  835.  
  836. $css = ob_get_contents(); 
  837.  
  838. ob_end_clean(); 
  839.  
  840. return $css; 
  841.  
  842. function wpsc_get_the_new_id($prod_id) { 
  843. global $wpdb; 
  844.  
  845. $post_id = (int) $wpdb->get_var($wpdb->prepare( "SELECT `post_id` FROM `{$wpdb->postmeta}` WHERE meta_key = %s AND `meta_value` = %d LIMIT 1", '_wpsc_original_id', $prod_id )); 
  846.  
  847. return $post_id; 
  848.  
  849. /** 
  850. * This switched between the 3 view types on category and products pages and includes the necessary template part 
  851. * @access public 
  852. * 
  853. * @since 3.8 
  854. * @param $display_type 
  855. * @return NULL 
  856. */ 
  857. function wpsc_include_products_page_template( $display_type = 'default' ) { 
  858.  
  859. if ( isset( $_GET['view_type'] ) ) { 
  860. switch ( $_GET['view_type'] ) { 
  861.  
  862. case 'grid': 
  863. $display_type = 'grid'; 
  864. wpsc_update_customer_meta( 'display_type', $display_type ); 
  865. break; 
  866.  
  867. case 'list': 
  868. $display_type = 'list'; 
  869. wpsc_update_customer_meta( 'display_type', $display_type ); 
  870. break; 
  871.  
  872. case 'default': 
  873. $display_type = 'default'; 
  874. wpsc_update_customer_meta( 'display_type', $display_type ); 
  875. break; 
  876.  
  877. default: 
  878. break; 
  879.  
  880. // switch the display type, based on the display type variable... 
  881. switch ( $display_type ) { 
  882. case "grid": 
  883. include( wpsc_get_template_file_path( 'wpsc-grid_view.php' ) ); 
  884. break; // only break if we have the function; 
  885.  
  886. case "list": 
  887. include( wpsc_get_template_file_path( 'wpsc-list_view.php' ) ); 
  888. break; // only break if we have the file; 
  889. default: 
  890. include( wpsc_get_template_file_path( 'wpsc-products_page.php' ) ); 
  891. break; 
  892.  
  893.  
  894. function wpsc_thesis_compat( $loop ) { 
  895. $loop[1] = 'page'; 
  896. return $loop; 
  897.  
  898. // Template tags 
  899. function wpsc_all_products_on_page() { 
  900.  
  901. if ( is_404() ) { 
  902. return; 
  903.  
  904. global $wp_query, $wpsc_query; 
  905. do_action('wpsc_swap_the_template'); 
  906. $products_page_id = wpsc_get_the_post_id_by_shortcode('[productspage]'); 
  907. $term = get_query_var( 'wpsc_product_category' ); 
  908. $tax_term = get_query_var ('product_tag' ); 
  909. $obj = $wp_query->get_queried_object(); 
  910.  
  911. $id = isset( $obj->ID ) ? $obj->ID : null; 
  912.  
  913. if( get_query_var( 'post_type' ) == 'wpsc-product' || $term || $tax_term || ( $id == $products_page_id )) { 
  914.  
  915. $templates = array(); 
  916.  
  917. if ( $term && ! is_single() ) { 
  918. array_push( $templates, "taxonomy-wpsc_product_category-{$term}.php", 'taxonomy-wpsc_product_category.php' ); 
  919.  
  920. if ( $tax_term && ! is_single() ) { 
  921. array_push( $templates, "taxonomy-product_tag-{$tax_term}.php", 'taxonomy-product_tag.php' ); 
  922.  
  923.  
  924. // Attempt to use the [productspage]'s custom page template as a higher priority than the normal page.php template 
  925. if ( false !== $productspage_page_template = get_post_meta($products_page_id, '_wp_page_template', true) ) 
  926. array_push( $templates, $productspage_page_template ); 
  927.  
  928. array_push( $templates, 'page.php', 'single.php' ); 
  929.  
  930. if ( is_single() ) 
  931. array_unshift( $templates, 'single-wpsc-product.php' ); 
  932.  
  933. // have to pass 'page' as the template type. This is lame, btw, and needs a rewrite in 4.0 
  934. if ( ! $template = get_query_template( 'page', $templates ) ) 
  935. $template = get_index_template(); 
  936.  
  937. add_filter( 'thesis_custom_loop', 'wpsc_thesis_compat' ); 
  938.  
  939. include( $template ); 
  940. exit; 
  941.  
  942. /** 
  943. * wpsc_count_themes_in_uploads_directory, does exactly what the name says 
  944. */ 
  945. function wpsc_count_themes_in_uploads_directory() { 
  946. $uploads_dir = false; 
  947. if ( is_dir( WPSC_OLD_THEMES_PATH.get_option('wpsc_selected_theme').'/' ) ) 
  948. $uploads_dir = @opendir( WPSC_OLD_THEMES_PATH.get_option('wpsc_selected_theme').'/' ); // might cause problems if dir doesnt exist 
  949.  
  950. if ( !$uploads_dir ) 
  951. return false; 
  952.  
  953. $file_names = array( ); 
  954. while ( ($file = @readdir( $uploads_dir )) !== false ) { 
  955. if ( is_dir( WPSC_OLD_THEMES_PATH . get_option('wpsc_selected_theme') . '/' . $file ) && ($file != "..") && ($file != ".") && ($file != ".svn") ) 
  956. $file_names[] = $file; 
  957.  
  958. @closedir( $uploads_dir ); 
  959. return count( $file_names ); 
  960.  
  961. function wpsc_place_shopping_cart( $content = '' ) { 
  962. if ( ! in_the_loop() ) 
  963. return $content; 
  964.  
  965. if ( preg_match( "/\[shoppingcart\]/", $content ) ) { 
  966. // BEGIN: compatibility fix for outdated theme files still relying on sessions 
  967. $_SESSION['coupon_numbers' ] = wpsc_get_customer_meta( 'coupon' ); 
  968. $_SESSION['wpsc_checkout_misc_error_messages' ] = wpsc_get_customer_meta( 'checkout_misc_error_messages' ); 
  969. $_SESSION['categoryAndShippingCountryConflict'] = wpsc_get_customer_meta( 'category_shipping_conflict' ); 
  970. $_SESSION['shippingSameBilling' ] = wpsc_get_customer_meta( 'shippingSameBilling' ); 
  971. $_SESSION['wpsc_checkout_user_error_messages' ] = wpsc_get_customer_meta( 'registration_error_messages' ); 
  972. // END: compatibility fix 
  973. $GLOBALS['nzshpcrt_activateshpcrt'] = true; 
  974. if ( ! defined( 'DONOTCACHEPAGE' ) ) 
  975. define( 'DONOTCACHEPAGE', true ); 
  976.  
  977. // call this function to detect conflicts when the cart page is first loaded, otherwise 
  978. // any conflict messages will only be displayed on the next page load 
  979. wpsc_get_acceptable_countries(); 
  980. ob_start(); 
  981. do_action( 'wpsc_before_shopping_cart_page' ); 
  982. include( wpsc_get_template_file_path( 'wpsc-shopping_cart_page.php' ) ); 
  983. do_action( 'wpsc_after_shopping_cart_page' ); 
  984. $output = ob_get_contents(); 
  985. ob_end_clean(); 
  986. $output = str_replace( '$', '\$', $output ); 
  987. wpsc_delete_customer_meta( 'checkout_misc_error_messages' ); 
  988. wpsc_delete_customer_meta( 'category_shipping_conflict' ); 
  989. wpsc_delete_customer_meta( 'registration_error_messages' ); 
  990. wpsc_delete_customer_meta( 'checkout_error_messages' ); 
  991. wpsc_delete_customer_meta( 'gateway_error_messages' ); 
  992. return preg_replace( "/(<p>)*\[shoppingcart\](<\/p>)*/", $output, $content ); 
  993. } else { 
  994. return $content; 
  995.  
  996. function wpsc_transaction_results( $content = '' ) { 
  997. if ( ! in_the_loop() ) 
  998. return $content; 
  999.  
  1000. if ( preg_match( "/\[transactionresults\]/", $content ) ) { 
  1001.  
  1002. if ( ! defined( 'DONOTCACHEPAGE' ) || ( defined( 'DONOTCACHEPAGE' ) && ! DONOTCACHEPAGE ) ) { 
  1003. define( 'DONOTCACHEPAGE', true ); 
  1004.  
  1005. ob_start(); 
  1006. include( wpsc_get_template_file_path( 'wpsc-transaction_results.php' ) ); 
  1007. $output = ob_get_contents(); 
  1008. ob_end_clean(); 
  1009. $output = preg_replace( '#(?<!\\\\)(\\$|\\\\)#', '\\\\$1', $output ); 
  1010. return preg_replace( "/(<p>)*\[transactionresults\](<\/p>)*/", $output, $content ); 
  1011. } else { 
  1012. return $content; 
  1013.  
  1014. function wpsc_user_log( $content = '' ) { 
  1015. if ( ! in_the_loop() ) 
  1016. return $content; 
  1017. if ( preg_match( "/\[userlog\]/", $content ) ) { 
  1018.  
  1019. if ( ! defined( 'DONOTCACHEPAGE' ) ) { 
  1020. define( 'DONOTCACHEPAGE', true ); 
  1021.  
  1022. ob_start(); 
  1023.  
  1024. include( wpsc_get_template_file_path('wpsc-user-log.php') ); 
  1025. $output = ob_get_clean(); 
  1026. $content = preg_replace( "/(<p>)*\[userlog\](<\/p>)*/", '[userlog]', $content ); 
  1027. return str_replace( '[userlog]', $output, $content ); 
  1028. } else { 
  1029. return $content; 
  1030.  
  1031. function wpsc_get_the_post_id_by_shortcode( $shortcode ) { 
  1032.  
  1033. $shortcode_options = array( 
  1034. '[productspage]' => 'product_list_url',  
  1035. '[shoppingcart]' => 'shopping_cart_url',  
  1036. '[checkout]' => 'shopping_cart_url',  
  1037. '[transactionresults]' => 'transact_url',  
  1038. '[userlog]' => 'user_account_url' 
  1039. ); 
  1040.  
  1041. if ( ! isset( $shortcode_options[$shortcode] ) ) 
  1042. return 0; 
  1043.  
  1044. $page_ids = get_option( 'wpsc_shortcode_page_ids', false ); 
  1045.  
  1046. if ( $page_ids === false ) { 
  1047. wpsc_update_permalink_slugs(); 
  1048. $page_ids = get_option( 'wpsc_shortcode_page_ids', false ); 
  1049.  
  1050. $post_id = isset( $page_ids[$shortcode] ) ? $page_ids[$shortcode] : null; 
  1051.  
  1052. // For back compat 
  1053. $post_id = apply_filters( 'wpec_get_the_post_id_by_shortcode', $post_id ); 
  1054.  
  1055. return apply_filters( 'wpsc_get_the_post_id_by_shortcode', $post_id, $shortcode ); 
  1056.  
  1057.  
  1058. function wpec_remap_shop_subpages( $vars ) { 
  1059. if( empty( $vars ) ) 
  1060. return $vars; 
  1061. $reserved_names = array('[shoppingcart]', '[userlog]', '[transactionresults]'); 
  1062. foreach($reserved_names as $reserved_name) { 
  1063. if ( isset( $vars['taxonomy'] ) && $vars['taxonomy'] == 'wpsc_product_category' && isset( $vars['term'] ) && $vars['term'] == $page->post_name ) { 
  1064. $page_id = wpsc_get_the_post_id_by_shortcode( $reserved_name ); 
  1065. $page = get_post( $page_id ); 
  1066. return array( 'page_id' => $page->ID ); 
  1067. return $vars; 
  1068.  
  1069. function wpsc_remove_page_from_query_string( $query_string ) { 
  1070.  
  1071. if ( false === strpos( implode( ' ', $query_string ), 'wpsc' ) ) { 
  1072. return $query_string; 
  1073.  
  1074. if ( isset( $query_string['name'] ) && $query_string['name'] == 'page' && isset( $query_string['page'] ) ) { 
  1075. unset( $query_string['name'] ); 
  1076.  
  1077. list( $delim, $page_index ) = explode( '/', $query_string['page'] ); 
  1078.  
  1079. $query_string['paged'] = $page_index; 
  1080.  
  1081. if ( isset( $query_string['wpsc-product'] ) && 'page' == $query_string['wpsc-product'] ) { 
  1082. $query_string['wpsc-product'] = ''; 
  1083.  
  1084. if ( isset( $query_string['name'] ) && is_numeric( $query_string['name'] ) ) { 
  1085. $query_string['paged'] = $query_string['name']; 
  1086. $query_string['page'] = '/'.$query_string['name']; 
  1087.  
  1088. $query_string['posts_per_page'] = get_option('wpsc_products_per_page'); 
  1089.  
  1090. if ( isset( $query_string['wpsc-product'] ) && is_numeric( $query_string['wpsc-product'] ) ) { 
  1091. unset( $query_string['wpsc-product'] ); 
  1092.  
  1093. if ( isset( $query_string['wpsc_product_category'] ) && 'page' == $query_string['wpsc_product_category'] ) { 
  1094. unset( $query_string['wpsc_product_category'] ); 
  1095.  
  1096. if ( isset( $query_string['name'] ) && is_numeric( $query_string['name'] ) ) { 
  1097. unset( $query_string['name'] ); 
  1098.  
  1099. if ( isset($query_string['term']) && 'page' == $query_string['term'] ) { 
  1100. unset( $query_string['term'] ); 
  1101. unset( $query_string['taxonomy'] ); 
  1102.  
  1103. return $query_string; 
  1104.  
  1105. function is_products_page() { 
  1106. global $post; 
  1107.  
  1108. if ( empty( $post ) || ! is_object( $post ) || empty( $post->ID ) ) 
  1109. return false; 
  1110.  
  1111. $product_page_id = wpsc_get_the_post_id_by_shortcode( '[productspage]' ); 
  1112.  
  1113. return $post->ID == $product_page_id; 
  1114.  
  1115.  
  1116. /** 
  1117. * wpsc_display_products_page function. 
  1118. * 
  1119. * @access public 
  1120. * @param mixed $query 
  1121. * @return void 
  1122. */ 
  1123. function wpsc_display_featured_products_page() { 
  1124. global $wp_query; 
  1125. $output = ''; 
  1126. $sticky_array = get_option( 'sticky_products' ); 
  1127. if ( (is_front_page() || is_home() || is_products_page() ) && !empty( $sticky_array ) && $wp_query->post_count > 1) { 
  1128. $query = get_posts( array( 
  1129. 'post__in' => $sticky_array,  
  1130. 'post_type' => 'wpsc-product',  
  1131. 'orderby' => 'rand',  
  1132. 'numberposts' => 1,  
  1133. 'posts_per_page' => 1 
  1134. ) ); 
  1135.  
  1136. if ( count( $query ) > 0 ) { 
  1137.  
  1138. $GLOBALS['nzshpcrt_activateshpcrt'] = true; 
  1139. $image_width = get_option( 'product_image_width' ); 
  1140. $image_height = get_option( 'product_image_height' ); 
  1141. $featured_product_theme_path = wpsc_get_template_file_path( 'wpsc-featured_product.php' ); 
  1142. ob_start(); 
  1143. include_once($featured_product_theme_path); 
  1144. $is_single = false; 
  1145. $output .= ob_get_contents(); 
  1146. ob_end_clean(); 
  1147.  
  1148. //Begin outputting featured product. We can worry about templating later, or folks can just CSS it up. 
  1149. echo $output; 
  1150. //End output 
  1151.  
  1152. function wpsc_hidesubcatprods_init() { 
  1153. $hide_subcatsprods = new WPSC_Hide_subcatsprods_in_cat; 
  1154. add_action( 'pre_get_posts', array( &$hide_subcatsprods, 'get_posts' ) ); 
  1155.  
  1156. // check for all in one SEO pack and the is_static_front_page function 
  1157. if ( is_callable( array( "All_in_One_SEO_Pack", 'is_static_front_page' ) ) ) { 
  1158.  
  1159. function wpsc_change_aioseop_home_title( $title ) { 
  1160. global $aiosp, $aioseop_options; 
  1161.  
  1162. if ( (get_class( $aiosp ) == 'All_in_One_SEO_Pack') && $aiosp->is_static_front_page() ) { 
  1163. $aiosp_home_title = $aiosp->internationalize( $aioseop_options['aiosp_home_title'] ); 
  1164. $new_title = wpsc_obtain_the_title(); 
  1165. if ( $new_title != '' ) { 
  1166. $title = str_replace( $aiosp_home_title, $new_title, $title ); 
  1167. return $title; 
  1168.  
  1169. add_filter( 'aioseop_home_page_title', 'wpsc_change_aioseop_home_title' ); 
  1170.  
  1171. /** 
  1172. * wpsc_obtain_the_title function, for replaacing the page title with the category or product 
  1173. * @return string - the new page title 
  1174. */ 
  1175. function wpsc_obtain_the_title() { 
  1176. global $wpdb, $wp_query, $wpsc_title_data; 
  1177. $output = null; 
  1178. $category_id = null; 
  1179. if( !isset( $wp_query->query_vars['wpsc_product_category']) && !isset( $wp_query->query_vars['wpsc-product'])) 
  1180. return; 
  1181.  
  1182. if ( !isset( $wp_query->query_vars['wpsc_product_category'] ) && isset($wp_query->query_vars['wpsc-product']) ) 
  1183. $wp_query->query_vars['wpsc_product_category'] = 0; 
  1184.  
  1185.  
  1186. if ( isset( $wp_query->query_vars['taxonomy'] ) && 'wpsc_product_category' == $wp_query->query_vars['taxonomy'] || isset($wp_query->query_vars['wpsc_product_category'])) 
  1187. $category_id = wpsc_get_the_category_id($wp_query->query_vars['wpsc_product_category'], 'slug'); 
  1188.  
  1189. if ( $category_id > 0 ) { 
  1190.  
  1191. if ( isset( $wpsc_title_data['category'][$category_id] ) ) { 
  1192. $output = $wpsc_title_data['category'][$category_id]; 
  1193. } else { 
  1194. $term = get_term($category_id, 'wpsc_product_category'); 
  1195. $output = $term->name; 
  1196. $wpsc_title_data['category'][$category_id] = $output; 
  1197.  
  1198. if ( !isset( $_GET['wpsc-product'] ) ) 
  1199. $_GET['wpsc-product'] = 0; 
  1200.  
  1201. if ( !isset( $wp_query->query_vars['wpsc-product'] ) ) 
  1202. $wp_query->query_vars['wpsc-product'] = ''; 
  1203.  
  1204. if ( isset( $wp_query->query_vars['wpsc-product'] ) || is_string( $_GET['wpsc-product'] ) ) { 
  1205. $product_name = $wp_query->query_vars['wpsc-product']; 
  1206. if ( isset( $wpsc_title_data['product'][$product_name] ) ) { 
  1207. $product_list = array( ); 
  1208. $full_product_name = $wpsc_title_data['product'][$product_name]; 
  1209. } else if ( $product_name != '' ) { 
  1210. $product_id = $wp_query->post->ID; 
  1211. $full_product_name = $wpdb->get_var( $wpdb->prepare( "SELECT `post_title` FROM `$wpdb->posts` WHERE `ID`= %d LIMIT 1", $product_id ) ); 
  1212. $wpsc_title_data['product'][$product_name] = $full_product_name; 
  1213. } else { 
  1214. if(isset($_REQUEST['product_id'])) { 
  1215. $product_id = absint( $_REQUEST['product_id'] ); 
  1216. $product_name = $wpdb->get_var( $wpdb->prepare( "SELECT `post_title` FROM `$wpdb->posts` WHERE `ID`= %d LIMIT 1", $product_id ) ); 
  1217. $full_product_name = $wpdb->get_var( $wpdb->prepare( "SELECT `post_title` FROM `$wpdb->posts` WHERE `ID`= %d LIMIT 1", $product_id ) ); 
  1218. $wpsc_title_data['product'][$product_name] = $full_product_name; 
  1219. }else{ 
  1220. //This has to exist, otherwise we would have bailed earlier. 
  1221. $category = $wp_query->query_vars['wpsc_product_category']; 
  1222. $cat_term = get_term_by('slug', $wp_query->query_vars['wpsc_product_category'], 'wpsc_product_category'); 
  1223. $full_product_name = $cat_term->name; 
  1224. $output = $full_product_name; 
  1225.  
  1226. if ( isset( $full_product_name ) && ($full_product_name != null) ) 
  1227. $output = esc_html( $full_product_name ); 
  1228. $seperator = ' | '; 
  1229. $seperator = apply_filters('wpsc_the_wp_title_seperator' , $seperator); 
  1230. return $output.$seperator; 
  1231.  
  1232. /** 
  1233. * Return category or product description depending on queried item 
  1234. */ 
  1235. function wpsc_obtain_the_description() { 
  1236.  
  1237. $output = null; 
  1238.  
  1239. // Return Category Description 
  1240. if ( is_numeric( get_query_var('category_id') ) ) { 
  1241. $output = wpsc_get_categorymeta( get_query_var('category_id'), 'description' ); 
  1242. } else if ( ! empty($_GET['category']) ) { 
  1243. $output = wpsc_get_categorymeta( absint( $_GET['category'] ), 'description' ); 
  1244.  
  1245. // Return product content as description if product page 
  1246. if ( !empty($_GET['product_id'] ) && is_numeric( $_GET['product_id'] ) ) { 
  1247. $product = get_post(absint( $_GET['product_id'] )); 
  1248. $output = $product->post_content; 
  1249.  
  1250. return $output; 
  1251.  
  1252. function wpsc_set_aioseop_description( $data ) { 
  1253. $replacement_data = wpsc_obtain_the_description(); 
  1254. if ( $replacement_data != '' ) { 
  1255. $data = $replacement_data; 
  1256. return $data; 
  1257.  
  1258. /** 
  1259. * this page url function, returns the URL of this page 
  1260. * @return string - the URL of the current page 
  1261. */ 
  1262. function wpsc_this_page_url() { 
  1263. global $wpsc_query, $wp_query; 
  1264. if ( $wpsc_query->is_single === true ) { 
  1265. $output = get_permalink( $wp_query->post->ID ); 
  1266. } else if ( isset( $wpsc_query->category ) && $wpsc_query->category != null ) { 
  1267. $output = wpsc_category_url( $wpsc_query->category ); 
  1268. if ( $wpsc_query->query_vars['page'] > 1 ) { 
  1269. if ( get_option( 'permalink_structure' ) ) { 
  1270. $output .= "page/{$wpsc_query->query_vars['page']}/"; 
  1271. } else { 
  1272. $output = add_query_arg( 'page_number', $wpsc_query->query_vars['page'], $output ); 
  1273. } elseif ( isset( $id ) ) { 
  1274. $output = get_permalink( $id ); 
  1275. } else { 
  1276. $output = get_permalink( get_the_ID() ); 
  1277.  
  1278. return esc_url( $output ); 
  1279.  
  1280. /** 
  1281. * Strips shortcode placeholders from excerpts returned in search results (and excerpts returned anywhere). 
  1282. * 
  1283. * @param string $text Trimmed excerpt 
  1284. * @return string $text Trimmed excerpt, sans placeholders 
  1285. * 
  1286. * @since 3.9.0 
  1287. */ 
  1288. function wpsc_strip_shortcode_placeholders( $text ) { 
  1289.  
  1290. $is_wpsc_placeholder = false; 
  1291.  
  1292. $wpsc_shortcodes = array( 
  1293. '[productspage]' ,  
  1294. '[shoppingcart]' ,  
  1295. '[checkout]' ,  
  1296. '[transactionresults]',  
  1297. '[userlog]' ,  
  1298. ); 
  1299.  
  1300. foreach ( $wpsc_shortcodes as $shortcode ) { 
  1301.  
  1302. if ( false !== strpos( $text, $shortcode ) ) { 
  1303. $is_wpsc_placeholder = $shortcode; 
  1304. break; 
  1305.  
  1306. if ( $is_wpsc_placeholder ) { 
  1307. $text = str_replace( $is_wpsc_placeholder, '', $text ); 
  1308.  
  1309. return $text; 
  1310.  
  1311.  
  1312. add_filter( 'wp_trim_excerpt', 'wpsc_strip_shortcode_placeholders' ); 
.