PageRenderTime 48ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/wp-e-commerce/wpsc-includes/theme.functions.php

https://github.com/AaronFernandes/aquestionof
PHP | 1501 lines | 982 code | 225 blank | 294 comment | 288 complexity | a687ce61c2cdd7d1a4fd1f44fc167d11 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * WP eCommerce theme functions
  4. *
  5. * These are the functions for the wp-eCommerce theme engine
  6. *
  7. * @package wp-e-commerce
  8. * @since 3.7
  9. */
  10. /**
  11. * wpsc_register_theme_file( $file_name )
  12. *
  13. * Adds a file name to a global list of
  14. *
  15. * @param string $file_name Name of file to add to global list of files
  16. */
  17. function wpsc_register_theme_file( $file_name ) {
  18. global $wpec_theme_files;
  19. if ( !in_array( $file_name, (array)$wpec_theme_files ) )
  20. $wpec_theme_files[] = $file_name;
  21. }
  22. /**
  23. * wpsc_get_theme_files()
  24. *
  25. * Returns the global wpec_theme_files
  26. *
  27. * @global array $wpec_theme_files
  28. * @return array
  29. */
  30. function wpsc_get_theme_files() {
  31. global $wpec_theme_files;
  32. if ( empty( $wpec_theme_files ) )
  33. return array();
  34. else
  35. return apply_filters( 'wpsc_get_theme_files', (array)array_values( $wpec_theme_files ) );
  36. }
  37. /**
  38. * wpsc_register_core_theme_files()
  39. *
  40. * Registers the core WPEC files into the global array
  41. */
  42. function wpsc_register_core_theme_files() {
  43. wpsc_register_theme_file( 'wpsc-single_product.php' );
  44. wpsc_register_theme_file( 'wpsc-grid_view.php' );
  45. wpsc_register_theme_file( 'wpsc-list_view.php' );
  46. wpsc_register_theme_file( 'wpsc-products_page.php' );
  47. wpsc_register_theme_file( 'wpsc-shopping_cart_page.php' );
  48. wpsc_register_theme_file( 'wpsc-transaction_results.php' );
  49. wpsc_register_theme_file( 'wpsc-user-log.php' );
  50. wpsc_register_theme_file( 'wpsc-cart_widget.php' );
  51. wpsc_register_theme_file( 'wpsc-featured_product.php' );
  52. wpsc_register_theme_file( 'wpsc-category-list.php' );
  53. wpsc_register_theme_file( 'wpsc-category_widget.php' );
  54. // Let other plugins register their theme files
  55. do_action( 'wpsc_register_core_theme_files' );
  56. }
  57. add_action( 'init', 'wpsc_register_core_theme_files' );
  58. /**
  59. * wpsc_flush_theme_transients()
  60. *
  61. * This function will delete the temporary values stored in WordPress transients
  62. * for all of the additional WPEC theme files and their locations. This is
  63. * mostly used when the active theme changes, or when files are moved around. It
  64. * does a complete flush of all possible path/url combinations of files.
  65. *
  66. * @uses wpsc_get_theme_files
  67. */
  68. function wpsc_flush_theme_transients( $force = false ) {
  69. if ( true === $force || isset( $_REQUEST['wpsc_flush_theme_transients'] ) && !empty( $_REQUEST['wpsc_flush_theme_transients'] ) ) {
  70. // Loop through current theme files and remove transients
  71. if ( $theme_files = wpsc_get_theme_files() ) {
  72. foreach( $theme_files as $file ) {
  73. delete_transient( WPEC_TRANSIENT_THEME_PATH_PREFIX . $file );
  74. delete_transient( WPEC_TRANSIENT_THEME_URL_PREFIX . $file );
  75. }
  76. delete_transient( 'wpsc_theme_path' );
  77. return true;
  78. }
  79. }
  80. // No files were registered so return false
  81. return false;
  82. }
  83. add_action( 'wpsc_move_theme', 'wpsc_flush_theme_transients', 10, true );
  84. add_action( 'wpsc_switch_theme', 'wpsc_flush_theme_transients', 10, true );
  85. add_action( 'switch_theme', 'wpsc_flush_theme_transients', 10, true );
  86. /**
  87. * wpsc_check_theme_location()
  88. *
  89. * Check theme location, compares the active theme and the themes within WPSC_CORE_THEME_PATH
  90. * finds files of the same name.
  91. *
  92. * @access public
  93. * @since 3.8
  94. * @param null
  95. * @return $results (Array) of Files OR false if no similar files are found
  96. */
  97. function wpsc_check_theme_location() {
  98. // Get the current theme
  99. $current_theme = get_stylesheet_directory();
  100. // Load up the files in the current theme
  101. $current_theme_files = wpsc_list_product_templates( $current_theme . '/' );
  102. // Load up the files in the wpec themes folder
  103. $wpsc_template_files = wpsc_list_product_templates( WPSC_CORE_THEME_PATH );
  104. // Compare the two
  105. $results = array_intersect( $current_theme_files, $wpsc_template_files );
  106. // Return the differences
  107. if ( count( $results ) > 0 )
  108. return $results;
  109. // No differences so return false
  110. else
  111. return false;
  112. }
  113. /**
  114. * wpsc_list_product_templates( $path = '' )
  115. *
  116. * Lists the files within the WPSC_CORE_THEME_PATH directory
  117. *
  118. * @access public
  119. * @since 3.8
  120. * @param $path - you can provide a path to find the files within it
  121. * @return $templates (Array) List of files
  122. */
  123. function wpsc_list_product_templates( $path = '' ) {
  124. $selected_theme = get_option( 'wpsc_selected_theme' );
  125. // If no path, then try to make some assuptions
  126. if ( empty( $path ) ) {
  127. if ( file_exists( WPSC_OLD_THEMES_PATH . $selected_theme . '/' . $selected_theme . '.css' ) ) {
  128. $path = WPSC_OLD_THEMES_PATH . $selected_theme . '/';
  129. } else {
  130. $path = WPSC_CORE_THEME_PATH;
  131. }
  132. }
  133. // Open the path and get the file names
  134. $dh = opendir( $path );
  135. while ( ( $file = readdir( $dh ) ) !== false ) {
  136. if ( $file != "." && $file != ".." && !strstr( $file, ".svn" ) && !strstr( $file, "images" ) && is_file( $path . $file ) ) {
  137. $templates[] = $file;
  138. }
  139. }
  140. // Return template names
  141. return $templates;
  142. }
  143. /**
  144. * Displays the theme upgrade notice
  145. * @access public
  146. *
  147. * @since 3.8
  148. * @param null
  149. * @return null
  150. */
  151. function wpsc_theme_upgrade_notice() { ?>
  152. <div id="message" class="updated fade">
  153. <p><?php printf( __( '<strong>WP e-Commerce 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 e-Commerce 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>
  154. </div>
  155. <?php
  156. }
  157. /**
  158. * Displays the database update notice
  159. * @access public
  160. *
  161. * @since 3.8
  162. * @param null
  163. * @return null
  164. */
  165. function wpsc_database_update_notice() { ?>
  166. <div class="error fade">
  167. <p><?php printf( __( '<strong>Your WP e-Commerce data needs to be updated</strong>. You\'ve upgraded from a previous version of the WP e-Commerce 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>
  168. </div>
  169. <?php
  170. }
  171. function wpsc_theme_admin_notices() {
  172. // Database update notice is most important
  173. if ( get_option ( 'wpsc_version' ) < 3.8 ) {
  174. add_action ( 'admin_notices', 'wpsc_database_update_notice' );
  175. // If that's not an issue check if theme updates required
  176. } else {
  177. if ( get_option('wpsc_ignore_theme','') == '' ) {
  178. add_option('wpsc_ignore_theme',false);
  179. }
  180. if (!get_option('wpsc_ignore_theme')) {
  181. add_action( 'admin_notices', 'wpsc_theme_upgrade_notice' );
  182. }
  183. }
  184. // Flag config inconsistencies
  185. if ( 1 == get_option( 'require_register' ) && 1 != get_option( 'users_can_register' )) {
  186. add_action( 'admin_notices', 'wpsc_turn_on_wp_register' );
  187. }
  188. }
  189. add_action('admin_init','wpsc_theme_admin_notices');
  190. function wpsc_turn_on_wp_register() {?>
  191. <div id="message" class="updated fade">
  192. <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>
  193. </div>
  194. <?php
  195. }
  196. if ( isset( $_REQUEST['wpsc_notices'] ) && $_REQUEST['wpsc_notices'] == 'theme_ignore' ) {
  197. update_option( 'wpsc_ignore_theme', true );
  198. wp_redirect( remove_query_arg( 'wpsc_notices' ) );
  199. }
  200. /**
  201. * wpsc_get_template_file_url( $file )
  202. *
  203. * Checks the active theme folder for the particular file, if it exists then
  204. * return the active theme url, otherwise return the global wpsc_theme_url
  205. *
  206. * @access public
  207. * @since 3.8
  208. * @param $file string filename
  209. * @return PATH to the file
  210. */
  211. function wpsc_get_template_file_url( $file = '' ) {
  212. // If we're not looking for a file, do not proceed
  213. if ( empty( $file ) )
  214. return;
  215. // No cache, so find one and set it
  216. if ( false === ( $file_url = get_transient( WPEC_TRANSIENT_THEME_URL_PREFIX . $file ) ) ) {
  217. // Look for file in stylesheet
  218. if ( file_exists( get_stylesheet_directory() . '/' . $file ) ) {
  219. $file_url = get_stylesheet_directory_uri() . '/' . $file;
  220. // Look for file in template
  221. } elseif ( file_exists( get_template_directory() . '/' . $file ) ) {
  222. $file_url = get_template_directory_uri() . '/' . $file;
  223. // Backwards compatibility
  224. } else {
  225. // Look in old theme url
  226. $selected_theme_check = WPSC_OLD_THEMES_PATH . get_option( 'wpsc_selected_theme' ) . '/' . str_ireplace( 'wpsc-', '', $file );
  227. // Check the selected theme
  228. if ( file_exists( $selected_theme_check ) ) {
  229. $file_url = WPSC_OLD_THEMES_URL . get_option( 'wpsc_selected_theme' ) . '/' . str_ireplace( 'wpsc-', '', $file );
  230. // Use the bundled theme CSS
  231. } else {
  232. $file_url = WPSC_CORE_THEME_URL . $file;
  233. }
  234. }
  235. // Save the transient and update it every 12 hours
  236. if ( !empty( $file_url ) )
  237. set_transient( WPEC_TRANSIENT_THEME_URL_PREFIX . $file, $file_url, 60 * 60 * 12 );
  238. }else{
  239. delete_transient(WPEC_TRANSIENT_THEME_URL_PREFIX . $file);
  240. wpsc_get_template_file_url($file);
  241. }
  242. if( is_ssl() && !strstr( $file_url, 'https' ) ) $file_url = str_replace('http', 'https', $file_url);
  243. // Return filtered result
  244. return apply_filters( WPEC_TRANSIENT_THEME_URL_PREFIX . $file, $file_url );
  245. }
  246. /**
  247. * Checks the active theme folder for the particular file, if it exists then return the active theme directory otherwise
  248. * return the global wpsc_theme_path
  249. * @access public
  250. *
  251. * @since 3.8
  252. * @param $file string filename
  253. * @return PATH to the file
  254. */
  255. function wpsc_get_template_file_path( $file = '' ){
  256. // If we're not looking for a file, do not proceed
  257. if ( empty( $file ) )
  258. return;
  259. // No cache, so find one and set it
  260. if ( false === ( $file_path = get_transient( WPEC_TRANSIENT_THEME_PATH_PREFIX . $file ) ) ) {
  261. // Look for file in stylesheet
  262. if ( file_exists( get_stylesheet_directory() . '/' . $file ) ) {
  263. $file_path = get_stylesheet_directory() . '/' . $file;
  264. // Look for file in template
  265. } elseif ( file_exists( get_template_directory() . '/' . $file ) ) {
  266. $file_path = get_template_directory() . '/' . $file;
  267. // Backwards compatibility
  268. } else {
  269. // Look in old theme path
  270. $selected_theme_check = WPSC_OLD_THEMES_PATH . get_option( 'wpsc_selected_theme' ) . '/' . str_ireplace( 'wpsc-', '', $file );
  271. // Check the selected theme
  272. if ( file_exists( $selected_theme_check ) ) {
  273. $file_path = $selected_theme_check;
  274. // Use the bundled file
  275. } else {
  276. $file_path = WPSC_CORE_THEME_PATH . '/' . $file;
  277. }
  278. }
  279. // Save the transient and update it every 12 hours
  280. if ( !empty( $file_path ) )
  281. set_transient( WPEC_TRANSIENT_THEME_PATH_PREFIX . $file, $file_path, 60 * 60 * 12 );
  282. }elseif(!file_exists($file_path)){
  283. delete_transient(WPEC_TRANSIENT_THEME_PATH_PREFIX . $file);
  284. wpsc_get_template_file_path($file);
  285. }
  286. // Return filtered result
  287. return apply_filters( WPEC_TRANSIENT_THEME_PATH_PREFIX . $file, $file_path );
  288. }
  289. /**
  290. * Get the Product Category ID by either slug or name
  291. * @access public
  292. *
  293. * @since 3.8
  294. * @param $slug (string) to be searched
  295. * @param $type (string) column to search, i.e name or slug
  296. * @return $category_id (int) Category ID
  297. */
  298. function wpsc_get_the_category_id($slug, $type = 'name'){
  299. global $wpdb,$wp_query;
  300. if(isset($wp_query->query_vars['taxonomy']))
  301. $taxonomy = $wp_query->query_vars['taxonomy'];
  302. else
  303. $taxonomy = 'wpsc_product_category';
  304. $category = get_term_by($type,$slug,$taxonomy);
  305. return empty( $category ) ? false : $category->term_id;
  306. }
  307. /**
  308. * Checks the category slug for a display type, if none set returns default
  309. * << May need reworking to be more specific to the taxonomy type >>
  310. * @access public
  311. *
  312. * @since 3.8
  313. * @param $slug(string)
  314. * @return $slug either from db or 'default' if none set
  315. */
  316. function wpsc_get_the_category_display($slug){
  317. global $wpdb;
  318. $default_display_type = get_option('product_view');
  319. if ( !empty($slug) && is_string($slug) ) {
  320. $category_id = wpsc_get_the_category_id($slug , 'slug');
  321. $display_type = wpsc_get_categorymeta( $category_id, 'display_type' );
  322. }
  323. if(!empty($display_type))
  324. return $display_type;
  325. else
  326. return $default_display_type;
  327. }
  328. /**
  329. * Checks if wpsc-single_product.php has been moved to the active theme, if it has then include the
  330. * template from the active theme.
  331. * @access public
  332. *
  333. * @since 3.8
  334. * @param $content content of the page
  335. * @return $content with wpsc-single_product content if its a single product
  336. */
  337. function wpsc_single_template( $content ) {
  338. global $wpdb, $post, $wp_query, $wpsc_query;
  339. //if we dont belong here exit out straight away
  340. if((!isset($wp_query->is_product)) && !isset($wp_query->query_vars['wpsc_product_category']))return $content;
  341. //if we are a paged page
  342. if(isset($wpsc_query->query['paged']) && $wpsc_query->post_count <= 1 && $wp_query->is_single != 1){
  343. remove_filter( "the_content", "wpsc_single_template" );
  344. list($wp_query, $wpsc_query) = array( $wpsc_query, $wp_query ); // swap the wpsc_query object
  345. $GLOBALS['nzshpcrt_activateshpcrt'] = true;
  346. // get the display type for the productspage
  347. $display_type = get_option('product_view');
  348. if ( isset( $_SESSION['wpsc_display_type'] ) ) {
  349. $display_type = $_SESSION['wpsc_display_type'];
  350. unset($_SESSION['wpsc_display_type']);
  351. }
  352. $output = '';
  353. ob_start();
  354. wpsc_include_products_page_template($display_type);
  355. $is_single = false;
  356. $output .= ob_get_contents();
  357. ob_end_clean();
  358. $product_id = $wp_query->post->ID;
  359. $product_meta = get_post_meta( $product_id, '_wpsc_product_metadata', true );
  360. list($wp_query, $wpsc_query) = array( $wpsc_query, $wp_query ); // swap the wpsc_query objects back
  361. if ( ($is_single == false) || ($product_meta['enable_comments'] == '0') )
  362. $GLOBALS['post'] = $wp_query->post;
  363. $wp_query->current_post = $wp_query->post_count;
  364. return $output;
  365. }
  366. // If we are a single products page
  367. if ( 'wpsc-product' == $wp_query->post->post_type && !is_archive() && $wp_query->post_count <= 1 ) {
  368. remove_filter( "the_content", "wpsc_single_template" );
  369. $single_theme_path = wpsc_get_template_file_path( 'wpsc-single_product.php' );
  370. if( isset( $wp_query->query_vars['preview'] ) && $wp_query->query_vars['preview'])
  371. $is_preview = 'true';
  372. else
  373. $is_preview = 'false';
  374. $wpsc_temp_query = new WP_Query( array( 'p' => $wp_query->post->ID , 'post_type' => 'wpsc-product','posts_per_page'=>1, 'preview' => $is_preview ) );
  375. list( $wp_query, $wpsc_temp_query ) = array( $wpsc_temp_query, $wp_query ); // swap the wpsc_query object
  376. ob_start();
  377. include( $single_theme_path );
  378. $content = ob_get_contents();
  379. ob_end_clean();
  380. list( $wp_query, $wpsc_temp_query ) = array( $wpsc_temp_query, $wp_query ); // swap the wpsc_query objects back
  381. }elseif( is_archive() && wpsc_is_viewable_taxonomy() || ($wp_query->post_count > 1 && 1 == $wp_query->is_product)){
  382. // If we are a category page
  383. remove_filter( "the_content", "wpsc_single_template" );
  384. list( $wp_query, $wpsc_query ) = array( $wpsc_query, $wp_query ); // swap the wpsc_query object
  385. if(isset($wp_query->query['pagename']))
  386. $display_type = get_option( 'product_view' );
  387. else
  388. $display_type = wpsc_get_the_category_display($wp_query->query_vars['term'],'slug');
  389. if ( isset( $_SESSION['wpsc_display_type'] ) )
  390. $display_type = $_SESSION['wpsc_display_type'];
  391. ob_start();
  392. wpsc_include_products_page_template($display_type);
  393. $content = ob_get_contents();
  394. ob_end_clean();
  395. list( $wp_query, $wpsc_query ) = array( $wpsc_query, $wp_query ); // swap the wpsc_query object
  396. $wp_query->current_post = $wp_query->post_count;
  397. }
  398. return $content;
  399. }
  400. function wpsc_is_viewable_taxonomy(){
  401. global $wp_query;
  402. 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']))
  403. return true;
  404. else
  405. return false;
  406. }
  407. /**
  408. * Checks and replaces the Page title with the category title if on a category page
  409. * @access public
  410. *
  411. * @since 3.8
  412. * @param $title (string) The Page Title
  413. * @param $id (int) The Page ID
  414. * @return $title (string) the new title
  415. */
  416. function wpsc_the_category_title($title='', $id=''){
  417. global $wp_query;
  418. $post = get_post($id);
  419. // If its the category page
  420. if( wpsc_is_viewable_taxonomy() && isset( $wp_query->posts[0] ) && $wp_query->posts[0]->post_title == $post->post_title && $wp_query->is_archive && !is_admin() && isset($wp_query->query_vars['wpsc_product_category'])){
  421. $category = get_term_by('slug',$wp_query->query_vars['wpsc_product_category'],'wpsc_product_category');
  422. remove_filter('the_title','wpsc_the_category_title');
  423. }
  424. // If its the product_tag page
  425. if( isset($wp_query->query_vars['taxonomy']) && 'product_tag' == $wp_query->query_vars['taxonomy'] && $wp_query->posts[0]->post_title == $post->post_title ){
  426. $category = get_term_by('slug',$wp_query->query_vars['term'],'product_tag');
  427. remove_filter('the_title','wpsc_the_category_title');
  428. }
  429. //if this is paginated products_page
  430. if( $wp_query->in_the_loop && empty($category->name) && isset( $wp_query->query_vars['paged'] ) && $wp_query->query_vars['paged'] && isset( $wp_query->query_vars['page'] ) && $wp_query->query_vars['page'] && 'wpsc-product' == $wp_query->query_vars['post_type']){
  431. $post_id = wpec_get_the_post_id_by_shortcode('[productspage]');
  432. $post = get_post($post_id);
  433. $title = $post->post_title;
  434. remove_filter('the_title','wpsc_the_category_title');
  435. }
  436. if(!empty($category->name))
  437. return $category->name;
  438. else
  439. return $title;
  440. }
  441. /**
  442. * wpsc_the_category_template swaps the template used for product categories with pageif archive template is being used use
  443. * @access public
  444. *
  445. * @since 3.8
  446. * @param $template (string) template path
  447. * @return $template (string)
  448. */
  449. function wpsc_the_category_template($template){
  450. global $wp_query;
  451. //this bit of code makes sure we use a nice standard page template for our products
  452. if(wpsc_is_viewable_taxonomy() && false !== strpos($template,'archive'))
  453. return str_ireplace('archive', 'page',$template);
  454. else
  455. return $template;
  456. }
  457. /**
  458. * wpsc_form_action
  459. *
  460. * Echo the form action for use in the template files
  461. *
  462. * @global <type> $wpec_form_action
  463. * @return <type>
  464. */
  465. function wpsc_form_action() {
  466. echo wpsc_get_form_action();
  467. }
  468. /**
  469. * wpsc_get_form_action
  470. *
  471. * Return the form action for use in the template files
  472. *
  473. * @global <type> $wpec_form_action
  474. * @return <type>
  475. */
  476. function wpsc_get_form_action() {
  477. global $wpec_form_action;
  478. $product_id = wpsc_the_product_id();
  479. // Function has already ran in this page load
  480. if ( isset( $wpec_form_action ) ) {
  481. $action = $wpec_form_action;
  482. // No global so figure it out
  483. } else {
  484. // Use external if set
  485. if ( wpsc_is_product_external() ) {
  486. $action = wpsc_product_external_link( $product_id );
  487. // Otherwise use this page
  488. } else {
  489. $action = wpsc_this_page_url();
  490. }
  491. }
  492. // Return form action
  493. return $action;
  494. }
  495. /**
  496. * wpsc_user_enqueues products function,
  497. * enqueue all javascript and CSS for wp ecommerce
  498. */
  499. function wpsc_enqueue_user_script_and_css() {
  500. global $wp_styles, $wpsc_theme_url, $wp_query;
  501. /**
  502. * added by xiligroup.dev to be compatible with touchshop
  503. */
  504. if ( has_filter( 'wpsc_enqueue_user_script_and_css' ) && apply_filters( 'wpsc_mobile_scripts_css_filters', false ) ) {
  505. do_action( 'wpsc_enqueue_user_script_and_css' );
  506. } else {
  507. /**
  508. * end of added by xiligroup.dev to be compatible with touchshop
  509. */
  510. $version_identifier = WPSC_VERSION . "." . WPSC_MINOR_VERSION;
  511. $category_id = '';
  512. 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' ) )
  513. ) {
  514. if ( isset($wp_query->query_vars['term']) && is_string( $wp_query->query_vars['term'] ) ) {
  515. $category_id = wpsc_get_category_id($wp_query->query_vars['term'], 'slug');
  516. } else {
  517. $category_id = get_option( 'wpsc_default_category' );
  518. }
  519. }
  520. $siteurl = get_option( 'siteurl' );
  521. if ( is_ssl() )
  522. $siteurl = str_replace( "http://", "https://", $siteurl );
  523. if( get_option( 'wpsc_share_this' ) == 1 )
  524. wp_enqueue_script( 'sharethis', 'http://w.sharethis.com/button/buttons.js', array(), false, true );
  525. wp_enqueue_script( 'jQuery' );
  526. wp_enqueue_script( 'wp-e-commerce', WPSC_CORE_JS_URL . '/wp-e-commerce.js', array( 'jquery' ), $version_identifier );
  527. wp_enqueue_script( 'infieldlabel', WPSC_CORE_JS_URL . '/jquery.infieldlabel.min.js', array( 'jquery' ), $version_identifier );
  528. wp_enqueue_script( 'wp-e-commerce-ajax-legacy', WPSC_CORE_JS_URL . '/ajax.js', false, $version_identifier );
  529. wp_enqueue_script( 'wp-e-commerce-dynamic', $siteurl . "/index.php?wpsc_user_dynamic_js=true", false, $version_identifier );
  530. wp_localize_script( 'wp-e-commerce-dynamic', 'wpsc_ajax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
  531. wp_enqueue_script( 'livequery', WPSC_URL . '/wpsc-admin/js/jquery.livequery.js', array( 'jquery' ), '1.0.3' );
  532. wp_enqueue_script( 'jquery-rating', WPSC_CORE_JS_URL . '/jquery.rating.js', array( 'jquery' ), $version_identifier );
  533. wp_enqueue_script( 'wp-e-commerce-legacy', WPSC_CORE_JS_URL . '/user.js', array( 'jquery' ), WPSC_VERSION . WPSC_MINOR_VERSION );
  534. $lightbox = get_option('wpsc_lightbox', 'thickbox');
  535. if( $lightbox == 'thickbox' ) {
  536. wp_enqueue_script( 'wpsc-thickbox', WPSC_CORE_JS_URL . '/thickbox.js', array( 'jquery' ), 'Instinct_e-commerce' );
  537. wp_enqueue_style( 'wpsc-thickbox', WPSC_CORE_JS_URL . '/thickbox.css', false, $version_identifier, 'all' );
  538. } elseif( $lightbox == 'colorbox' ) {
  539. wp_enqueue_script( 'colorbox-min', WPSC_CORE_JS_URL . '/jquery.colorbox-min.js', array( 'jquery' ), 'Instinct_e-commerce' );
  540. wp_enqueue_script( 'wpsc_colorbox', WPSC_CORE_JS_URL . '/wpsc_colorbox.js', array( 'jquery', 'colorbox-min' ), 'Instinct_e-commerce' );
  541. wp_enqueue_style( 'wpsc-colorbox-css', WPSC_CORE_JS_URL . '/wpsc_colorbox.css', false, $version_identifier, 'all' );
  542. }
  543. wp_enqueue_style( 'wpsc-theme-css', wpsc_get_template_file_url( 'wpsc-' . get_option( 'wpsc_selected_theme' ) . '.css' ), false, $version_identifier, 'all' );
  544. wp_enqueue_style( 'wpsc-theme-css-compatibility', WPSC_CORE_THEME_URL . 'compatibility.css', false, $version_identifier, 'all' );
  545. wp_enqueue_style( 'wpsc-product-rater', WPSC_CORE_JS_URL . '/product_rater.css', false, $version_identifier, 'all' );
  546. wp_enqueue_style( 'wp-e-commerce-dynamic', $siteurl . "/index.php?wpsc_user_dynamic_css=true&category=$category_id", false, $version_identifier, 'all' );
  547. }
  548. if ( !defined( 'WPSC_MP3_MODULE_USES_HOOKS' ) && function_exists( 'listen_button' ) ) {
  549. function wpsc_legacy_add_mp3_preview( $product_id, &$product_data ) {
  550. global $wpdb;
  551. if ( function_exists( 'listen_button' ) ) {
  552. $file_data = $wpdb->get_row( "SELECT * FROM `" . WPSC_TABLE_PRODUCT_FILES . "` WHERE `id`='" . $product_data['file'] . "' LIMIT 1", ARRAY_A );
  553. if ( $file_data != null ) {
  554. echo listen_button( $file_data['idhash'], $file_data['id'] );
  555. }
  556. }
  557. }
  558. add_action( 'wpsc_product_before_description', 'wpsc_legacy_add_mp3_preview', 10, 2 );
  559. }
  560. }
  561. if ( !is_admin() )
  562. add_action( 'init', 'wpsc_enqueue_user_script_and_css' );
  563. function wpsc_product_list_rss_feed() {
  564. $rss_url = get_option('siteurl');
  565. $rss_url = add_query_arg( 'wpsc_action', 'rss', $rss_url );
  566. $rss_url = str_replace('&', '&amp;', $rss_url);
  567. $rss_url = esc_url( $rss_url ); // URL santization - IMPORTANT!
  568. echo "<link rel='alternate' type='application/rss+xml' title='" . get_option( 'blogname' ) . " Product List RSS' href='{$rss_url}'/>";
  569. }
  570. add_action( 'wp_head', 'wpsc_product_list_rss_feed' );
  571. function wpsc_user_dynamic_js() {
  572. header( 'Content-Type: text/javascript' );
  573. header( 'Expires: ' . gmdate( 'r', mktime( 0, 0, 0, date( 'm' ), (date( 'd' ) + 12 ), date( 'Y' ) ) ) . '' );
  574. header( 'Cache-Control: public, must-revalidate, max-age=86400' );
  575. header( 'Pragma: public' );
  576. $siteurl = get_option( 'siteurl' );
  577. ?>
  578. jQuery.noConflict();
  579. /* base url */
  580. var base_url = "<?php echo $siteurl; ?>";
  581. var WPSC_URL = "<?php echo WPSC_URL; ?>";
  582. var WPSC_IMAGE_URL = "<?php echo WPSC_IMAGE_URL; ?>";
  583. var WPSC_DIR_NAME = "<?php echo WPSC_DIR_NAME; ?>";
  584. var WPSC_CORE_IMAGES_URL = "<?php echo WPSC_CORE_IMAGES_URL; ?>";
  585. /* LightBox Configuration start*/
  586. var fileLoadingImage = "<?php echo WPSC_CORE_IMAGES_URL; ?>/loading.gif";
  587. var fileBottomNavCloseImage = "<?php echo WPSC_CORE_IMAGES_URL; ?>/closelabel.gif";
  588. var fileThickboxLoadingImage = "<?php echo WPSC_CORE_IMAGES_URL; ?>/loadingAnimation.gif";
  589. var resizeSpeed = 9; // controls the speed of the image resizing (1=slowest and 10=fastest)
  590. var borderSize = 10; //if you adjust the padding in the CSS, you will need to update this variable
  591. <?php
  592. exit();
  593. }
  594. if ( isset( $_GET['wpsc_user_dynamic_js'] ) && ($_GET['wpsc_user_dynamic_js'] == 'true') )
  595. add_action( "init", 'wpsc_user_dynamic_js' );
  596. function wpsc_user_dynamic_css() {
  597. global $wpdb;
  598. header( 'Content-Type: text/css' );
  599. header( 'Expires: ' . gmdate( 'r', mktime( 0, 0, 0, date( 'm' ), (date( 'd' ) + 12 ), date( 'Y' ) ) ) . '' );
  600. header( 'Cache-Control: public, must-revalidate, max-age=86400' );
  601. header( 'Pragma: public' );
  602. $category_id = absint( $_GET['category'] );
  603. if ( !defined( 'WPSC_DISABLE_IMAGE_SIZE_FIXES' ) || (constant( 'WPSC_DISABLE_IMAGE_SIZE_FIXES' ) != true) ) {
  604. $thumbnail_width = get_option( 'product_image_width' );
  605. if ( $thumbnail_width <= 0 ) {
  606. $thumbnail_width = 96;
  607. }
  608. $thumbnail_height = get_option( 'product_image_height' );
  609. if ( $thumbnail_height <= 0 ) {
  610. $thumbnail_height = 96;
  611. }
  612. $single_thumbnail_width = get_option( 'single_view_image_width' );
  613. $single_thumbnail_height = get_option( 'single_view_image_height' );
  614. if ( $single_thumbnail_width <= 0 ) {
  615. $single_thumbnail_width = 128;
  616. }
  617. $category_height = get_option('category_image_height');
  618. $category_width = get_option('category_image_width');
  619. ?>
  620. /*
  621. * Default View Styling
  622. */
  623. div.default_product_display div.textcol{
  624. margin-left: <?php echo $thumbnail_width + 10; ?>px !important;
  625. min-height: <?php echo $thumbnail_height; ?>px;
  626. _height: <?php echo $thumbnail_height; ?>px;
  627. }
  628. div.default_product_display div.textcol div.imagecol{
  629. position:absolute;
  630. top:0px;
  631. left: 0px;
  632. margin-left: -<?php echo $thumbnail_width + 10; ?>px !important;
  633. }
  634. div.default_product_display div.textcol div.imagecol a img {
  635. width: <?php echo $thumbnail_width; ?>px;
  636. height: <?php echo $thumbnail_height; ?>px;
  637. }
  638. .wpsc_category_grid_item {
  639. display:block;
  640. float:left;
  641. width: <?php echo $category_width; ?>px;
  642. height: <?php echo $category_height; ?>px;
  643. }
  644. .wpsc_category_grid_item span{
  645. position:relative;
  646. top:<?php echo ($thumbnail_height - 2)/9; ?>px;
  647. }
  648. div.default_product_display div.item_no_image a {
  649. width: <?php echo $thumbnail_width - 2; ?>px;
  650. }
  651. div.default_product_display .imagecol img.no-image, #content div.default_product_display .imagecol img.no-image {
  652. width: <?php echo $thumbnail_width; ?>px;
  653. height: <?php echo $thumbnail_height; ?>px;
  654. }
  655. /*
  656. * Grid View Styling
  657. */
  658. div.product_grid_display div.item_no_image {
  659. width: <?php echo $thumbnail_width - 2; ?>px;
  660. height: <?php echo $thumbnail_height - 2; ?>px;
  661. }
  662. div.product_grid_display div.item_no_image a {
  663. width: <?php echo $thumbnail_width - 2; ?>px;
  664. }
  665. .product_grid_display .product_grid_item {
  666. width: <?php echo $thumbnail_width; ?>px;
  667. }
  668. .product_grid_display .product_grid_item img.no-image, #content .product_grid_display .product_grid_item img.no-image {
  669. width: <?php echo $thumbnail_width; ?>px;
  670. height: <?php echo $thumbnail_height; ?>px;
  671. }
  672. <?php if(get_option('show_images_only') == 1): ?>
  673. .product_grid_display .product_grid_item {
  674. min-height:0 !important;
  675. width: <?php echo $thumbnail_width; ?>px;
  676. height: <?php echo $thumbnail_height; ?>px;
  677. }
  678. <?php endif; ?>
  679. /*
  680. * Single View Styling
  681. */
  682. div.single_product_display div.item_no_image {
  683. width: <?php echo $single_thumbnail_width - 2; ?>px;
  684. height: <?php echo $single_thumbnail_height - 2; ?>px;
  685. }
  686. div.single_product_display div.item_no_image a {
  687. width: <?php echo $single_thumbnail_width - 2; ?>px;
  688. }
  689. div.single_product_display div.textcol{
  690. margin-left: <?php echo $single_thumbnail_width + 10; ?>px !important;
  691. min-height: <?php echo $single_thumbnail_height; ?>px;
  692. _height: <?php echo $single_thumbnail_height; ?>px;
  693. }
  694. div.single_product_display div.textcol div.imagecol{
  695. position:absolute;
  696. margin-left: -<?php echo $single_thumbnail_width + 10; ?>px !important;
  697. }
  698. div.single_product_display div.textcol div.imagecol a img {
  699. width: <?php echo $single_thumbnail_width; ?>px;
  700. height: <?php echo $single_thumbnail_height; ?>px;
  701. }
  702. <?php
  703. if (isset($product_image_size_list)) {
  704. foreach ( (array)$product_image_size_list as $product_image_sizes ) {
  705. $individual_thumbnail_height = $product_image_sizes['height'];
  706. $individual_thumbnail_width = $product_image_sizes['width'];
  707. $product_id = $product_image_sizes['id'];
  708. if ( $individual_thumbnail_height > $thumbnail_height ) {
  709. echo " div.default_product_display.product_view_$product_id div.textcol{\n\r";
  710. echo " min-height: " . ($individual_thumbnail_height + 10) . "px !important;\n\r";
  711. echo " _height: " . ($individual_thumbnail_height + 10) . "px !important;\n\r";
  712. echo " }\n\r";
  713. }
  714. if ( $individual_thumbnail_width > $thumbnail_width ) {
  715. echo " div.default_product_display.product_view_$product_id div.textcol{\n\r";
  716. echo " margin-left: " . ($individual_thumbnail_width + 10) . "px !important;\n\r";
  717. echo " }\n\r";
  718. echo " div.default_product_display.product_view_$product_id div.textcol div.imagecol{\n\r";
  719. echo " position:absolute;\n\r";
  720. echo " top:0px;\n\r";
  721. echo " left: 0px;\n\r";
  722. echo " margin-left: -" . ($individual_thumbnail_width + 10) . "px !important;\n\r";
  723. echo " }\n\r";
  724. }
  725. if ( ($individual_thumbnail_width > $thumbnail_width) || ($individual_thumbnail_height > $thumbnail_height) ) {
  726. echo " div.default_product_display.product_view_$product_id div.textcol div.imagecol a img{\n\r";
  727. echo " width: " . $individual_thumbnail_width . "px;\n\r";
  728. echo " height: " . $individual_thumbnail_height . "px;\n\r";
  729. echo " }\n\r";
  730. }
  731. }
  732. }
  733. exit();
  734. }
  735. if ( (isset($_GET['brand']) && is_numeric( $_GET['brand'] )) || (get_option( 'show_categorybrands' ) == 3) ) {
  736. $brandstate = 'block';
  737. $categorystate = 'none';
  738. } else {
  739. $brandstate = 'none';
  740. $categorystate = 'block';
  741. }
  742. ?>
  743. div#categorydisplay{
  744. display: <?php echo $categorystate; ?>;
  745. }
  746. div#branddisplay{
  747. display: <?php echo $brandstate; ?>;
  748. }
  749. <?php
  750. exit();
  751. }
  752. if ( isset( $_GET['wpsc_user_dynamic_css'] ) && ($_GET['wpsc_user_dynamic_css'] == 'true') )
  753. add_action( "init", 'wpsc_user_dynamic_css' );
  754. function wpsc_get_the_new_id($prod_id){
  755. global $wpdb;
  756. $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 ));
  757. return $post_id;
  758. }
  759. // Template tags
  760. /**
  761. * wpsc display products function
  762. * @return string - html displaying one or more products
  763. */
  764. function wpsc_display_products_page( $query ) {
  765. global $wpdb, $wpsc_query,$wp_query;
  766. remove_filter('the_title','wpsc_the_category_title');
  767. // If the data is coming from a shortcode parse the values into the args variable,
  768. // I did it this was to preserve backwards compatibility
  769. if(!empty($query)){
  770. $args['post_type'] = 'wpsc-product';
  771. if(!empty($query['product_id']) && is_array($query['product_id'])){
  772. $args['post__in'] = $query['product_id'];
  773. }elseif(is_string($query['product_id'])){
  774. $args['post__in'] = (array)$query['product_id'];
  775. }
  776. if(!empty($query['old_product_id'])){
  777. $post_id = wpsc_get_the_new_id($query['old_product_id']);
  778. $args['post__in'] = (array)$post_id;
  779. }
  780. if(!empty($query['price']) && 'sale' != $query['price']){
  781. $args['meta_key'] = '_wpsc_price';
  782. $args['meta_value'] = $query['price'];
  783. }elseif(!empty($query['price']) && 'sale' == $query['price']){
  784. $args['meta_key'] = '_wpsc_special_price';
  785. $args['meta_compare'] = '>=';
  786. $args['meta_value'] = '1';
  787. }
  788. if(!empty($query['product_name'])){
  789. $args['pagename'] = $query['product_name'];
  790. }
  791. if(!empty($query['category_id'])){
  792. $term = get_term($query['category_id'],'wpsc_product_category');
  793. $id = wpsc_get_meta($query['category_id'], 'category_id','wpsc_old_category');
  794. if( !empty($id)){
  795. $term = get_term($id,'wpsc_product_category');
  796. $args['wpsc_product_category'] = $term->slug;
  797. $args['wpsc_product_category__in'] = $term->term_id;
  798. }else{
  799. $args['wpsc_product_category'] = $term->slug;
  800. $args['wpsc_product_category__in'] = $term->term_id;
  801. }
  802. }
  803. if(!empty($query['category_url_name'])){
  804. $args['wpsc_product_category'] = $query['category_url_name'];
  805. }
  806. if(!empty($query['sort_order'])){
  807. $args['orderby'] = $query['sort_order'];
  808. }
  809. if(!empty($query['order'])){
  810. $args['order'] = $query['order'];
  811. }
  812. if(!empty($query['limit_of_items']) && '1' == get_option('use_pagination')){
  813. $args['posts_per_page'] = $query['limit_of_items'];
  814. }
  815. if(!empty($query['number_per_page']) && '1' == get_option('use_pagination')){
  816. $args['posts_per_page'] = $query['number_per_page'];
  817. }
  818. if( '0' == get_option('use_pagination') ){
  819. $args['nopaging'] = true;
  820. $args['posts_per_page'] = '-1';
  821. }
  822. if(!empty($query['tag'])){
  823. $args['product_tag'] = $query['tag'];
  824. }
  825. $temp_wpsc_query = new WP_Query($args);
  826. }
  827. // swap the wpsc_query objects
  828. list( $wp_query, $temp_wpsc_query ) = array( $temp_wpsc_query, $wp_query );
  829. $GLOBALS['nzshpcrt_activateshpcrt'] = true;
  830. // Pretty sure this single_product code is legacy...but fixing it up just in case.
  831. // get the display type for the selected category
  832. if(!empty($temp_wpsc_query->query_vars['term']))
  833. $display_type = wpsc_get_the_category_display($temp_wpsc_query->query_vars['term']);
  834. elseif( !empty( $args['wpsc_product_category'] ) )
  835. $display_type = wpsc_get_the_category_display($args['wpsc_product_category']);
  836. else
  837. $display_type = 'default';
  838. if ( isset( $_SESSION['wpsc_display_type'] ) )
  839. $display_type = $_SESSION['wpsc_display_type'];
  840. ob_start();
  841. if( 'wpsc-product' == $wp_query->post->post_type && !is_archive() && $wp_query->post_count <= 1 )
  842. include( wpsc_get_template_file_path( 'wpsc-single_product.php' ) );
  843. else
  844. wpsc_include_products_page_template($display_type);
  845. $is_single = false;
  846. $output = ob_get_contents();
  847. ob_end_clean();
  848. $output = str_replace('\$','$', $output);
  849. list($temp_wpsc_query, $wp_query) = array( $wp_query, $temp_wpsc_query ); // swap the wpsc_query objects back
  850. if ( $is_single == false ) {
  851. $GLOBALS['post'] = $wp_query->post;
  852. }
  853. return $output;
  854. }
  855. /**
  856. * This switched between the 3 view types on category and products pages and includes the necessary tempalte part
  857. * @access public
  858. *
  859. * @since 3.8
  860. * @param $display_type
  861. * @return NULL
  862. */
  863. function wpsc_include_products_page_template($display_type = 'default'){
  864. if ( isset( $_GET['view_type'] ) ) {
  865. switch ( $_GET['view_type'] ) {
  866. case 'grid':
  867. $display_type = 'grid';
  868. $_SESSION['wpsc_display_type'] = $display_type;
  869. break;
  870. case 'list':
  871. $display_type = 'list';
  872. $_SESSION['wpsc_display_type'] = $display_type;
  873. break;
  874. case 'default':
  875. $display_type = 'default';
  876. $_SESSION['wpsc_display_type'] = $display_type;
  877. break;
  878. default:
  879. break;
  880. }
  881. }
  882. // switch the display type, based on the display type variable...
  883. switch ( $display_type ) {
  884. case "grid":
  885. include( wpsc_get_template_file_path( 'wpsc-grid_view.php' ) );
  886. break; // only break if we have the function;
  887. case "list":
  888. include( wpsc_get_template_file_path( 'wpsc-list_view.php' ) );
  889. break; // only break if we have the file;
  890. default:
  891. include( wpsc_get_template_file_path( 'wpsc-products_page.php' ) );
  892. break;
  893. }
  894. }
  895. //handles replacing the tags in the pages
  896. function wpsc_products_page( $content = '' ) {
  897. global $wpdb, $wp_query, $wpsc_query, $wpsc_query_vars;
  898. $output = '';
  899. if ( preg_match( "/\[productspage\]/", $content ) ) {
  900. global $more;
  901. $more = 0;
  902. remove_filter( 'the_content', 'wpautop' );
  903. list($wp_query, $wpsc_query) = array( $wpsc_query, $wp_query ); // swap the wpsc_query object
  904. $GLOBALS['nzshpcrt_activateshpcrt'] = true;
  905. // get the display type for the productspage
  906. $display_type = get_option('product_view');
  907. if ( isset( $_SESSION['wpsc_display_type'] ) )
  908. $display_type = $_SESSION['wpsc_display_type'];
  909. ob_start();
  910. wpsc_include_products_page_template($display_type);
  911. $is_single = false;
  912. $output .= ob_get_contents();
  913. ob_end_clean();
  914. $output = str_replace( '$', '\$', $output );
  915. $product_id = $wp_query->post->ID;
  916. $product_meta = get_post_meta( $product_id, '_wpsc_product_metadata', true );
  917. list($wp_query, $wpsc_query) = array( $wpsc_query, $wp_query ); // swap the wpsc_query objects back
  918. if ( ($is_single == false) || ($product_meta['enable_comments'] == '0') )
  919. $GLOBALS['post'] = $wp_query->post;
  920. return preg_replace( "/(<p>)*\[productspage\](<\/p>)*/", $output, $content );
  921. } elseif(is_archive() && wpsc_is_viewable_taxonomy()){
  922. remove_filter( 'the_content', 'wpautop' );
  923. return wpsc_products_page('[productspage]');
  924. } else {
  925. return $content;
  926. }
  927. }
  928. function wpsc_all_products_on_page(){
  929. global $wp_query,$wpsc_query;
  930. do_action('wpsc_swap_the_template');
  931. $products_page_id = wpec_get_the_post_id_by_shortcode('[productspage]');
  932. if($wp_query->query_vars['post_type'] == 'wpsc-product' || isset($wp_query->query_vars['wpsc_product_category']) || ( isset( $wp_query->post ) && $wp_query->post->ID == $products_page_id )){
  933. if (isset($wp_query->post_count) && 1 == $wp_query->post_count && file_exists(STYLESHEETPATH.'/single-wpsc-product.php')){
  934. include(STYLESHEETPATH. '/single-wpsc-product.php');
  935. exit();
  936. }elseif(file_exists(STYLESHEETPATH.'/page.php')){
  937. include(STYLESHEETPATH. '/page.php');
  938. exit();
  939. }elseif(file_exists(STYLESHEETPATH.'/single.php')){
  940. include(STYLESHEETPATH. '/single.php');
  941. exit();
  942. }elseif(file_exists(STYLESHEETPATH.'/index.php')){
  943. include(STYLESHEETPATH. '/index.php');
  944. exit();
  945. }
  946. }
  947. return;
  948. }
  949. add_action('template_redirect', 'wpsc_all_products_on_page');
  950. /**
  951. * wpsc_count_themes_in_uploads_directory, does exactly what the name says
  952. */
  953. function wpsc_count_themes_in_uploads_directory() {
  954. $uploads_dir = false;
  955. if ( is_dir( WPSC_OLD_THEMES_PATH.get_option('wpsc_selected_theme').'/' ) )
  956. $uploads_dir = @opendir( WPSC_OLD_THEMES_PATH.get_option('wpsc_selected_theme').'/' ); // might cause problems if dir doesnt exist
  957. if ( !$uploads_dir )
  958. return false;
  959. $file_names = array( );
  960. while ( ($file = @readdir( $uploads_dir )) !== false ) {
  961. if ( is_dir( WPSC_OLD_THEMES_PATH . get_option('wpsc_selected_theme') . '/' . $file ) && ($file != "..") && ($file != ".") && ($file != ".svn") )
  962. $file_names[] = $file;
  963. }
  964. @closedir( $uploads_dir );
  965. return count( $file_names );
  966. }
  967. function wpsc_place_shopping_cart( $content = '' ) {
  968. if ( preg_match( "/\[shoppingcart\]/", $content ) ) {
  969. $GLOBALS['nzshpcrt_activateshpcrt'] = true;
  970. define( 'DONOTCACHEPAGE', true );
  971. ob_start();
  972. include( wpsc_get_template_file_path( 'wpsc-shopping_cart_page.php' ) );
  973. $output = ob_get_contents();
  974. ob_end_clean();
  975. $output = str_replace( '$', '\$', $output );
  976. return preg_replace( "/(<p>)*\[shoppingcart\](<\/p>)*/", $output, $content );
  977. } else {
  978. return $content;
  979. }
  980. }
  981. function wpsc_transaction_results( $content = '' ) {
  982. if ( preg_match( "/\[transactionresults\]/", $content ) ) {
  983. define( 'DONOTCACHEPAGE', true );
  984. ob_start();
  985. include( wpsc_get_template_file_path( 'wpsc-transaction_results.php' ) );
  986. $output = ob_get_contents();
  987. ob_end_clean();
  988. return preg_replace( "/(<p>)*\[transactionresults\](<\/p>)*/", $output, $content );
  989. } else {
  990. return $content;
  991. }
  992. }
  993. function wpsc_user_log( $content = '' ) {
  994. if ( preg_match( "/\[userlog\]/", $content ) ) {
  995. define( 'DONOTCACHEPAGE', true );
  996. ob_start();
  997. include( wpsc_get_template_file_path('wpsc-user-log.php') );
  998. $output = ob_get_clean();
  999. $content = preg_replace( "/(<p>)*\[userlog\](<\/p>)*/", '[userlog]', $content );
  1000. return str_replace( '[userlog]', $output, $content );
  1001. } else {
  1002. return $content;
  1003. }
  1004. }
  1005. //displays a list of categories when the code [showcategories] is present in a post or page.
  1006. function wpsc_show_categories( $content ) {
  1007. ob_start();
  1008. include( wpsc_get_template_file_path( 'wpsc-category-list.php' ) );
  1009. $output = ob_get_contents();
  1010. ob_end_clean();
  1011. return $output;
  1012. }
  1013. add_shortcode('showcategories', 'wpsc_show_categories');
  1014. function wpec_get_the_post_id_by_shortcode($shortcode){
  1015. global $wpdb;
  1016. $sql = "SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_type` IN('page','post') AND `post_content` LIKE '%$shortcode%' LIMIT 1";
  1017. $page_id = $wpdb->get_var($sql);
  1018. return $page_id;
  1019. }
  1020. function wpec_remap_shop_subpages($vars) {
  1021. if(empty($vars))
  1022. return $vars;
  1023. $reserved_names = array('[shoppingcart]','[userlog]','[transactionresults]');
  1024. foreach($reserved_names as $reserved_name){
  1025. $page_id = wpec_get_the_post_id_by_shortcode($reserved_name);
  1026. $page = get_post($page_id);
  1027. if (isset($vars['taxonomy']) && $vars['taxonomy'] == 'wpsc_product_category') {
  1028. if (isset($vars['term']) && $vars['term'] == $page->post_name) {
  1029. return array('page_id' => $page->ID);
  1030. }
  1031. }
  1032. }
  1033. return $vars;
  1034. }
  1035. add_filter('request','wpec_remap_shop_subpages');
  1036. function wpsc_remove_page_from_query_string($query_string)
  1037. {
  1038. if ( isset($query_string['name']) && $query_string['name'] == 'page' && isset($query_string['page']) ) {
  1039. unset($query_string['name']);
  1040. list($delim, $page_index) = split('/', $query_string['page']);
  1041. $query_string['paged'] = $page_index;
  1042. }
  1043. if ( isset($query_string['wpsc-product']) && 'page' == $query_string['wpsc-product'] )
  1044. $query_string['wpsc-product'] = '';
  1045. if ( isset($query_string['name']) && is_numeric($query_string['name']) ) {
  1046. $query_string['paged'] = $query_string['name'];
  1047. $query_string['page'] = '/'.$query_string['name'];
  1048. $query_string['posts_per_page'] = get_option('wpsc_products_per_page');
  1049. }
  1050. if ( isset($query_string['wpsc-product']) && is_numeric($query_string['wpsc-product']) )
  1051. unset( $query_string['wpsc-product'] );
  1052. if ( isset($query_string['wpsc_product_category']) && 'page' == $query_string['wpsc_product_category'] )
  1053. unset( $query_string['wpsc_product_category'] );
  1054. if ( isset($query_string['name']) && is_numeric($query_string['name']) )
  1055. unset( $query_string['name'] );
  1056. if ( isset($query_string['term']) && 'page' == $query_string['term'] ) {
  1057. unset( $query_string['term'] );
  1058. unset( $query_string['taxonomy'] );
  1059. }
  1060. return $query_string;
  1061. }
  1062. add_filter('request', 'wpsc_remove_page_from_query_string');
  1063. /* 19-02-09
  1064. * add to cart shortcode function used for shortcodes calls the function in
  1065. * product_display_functions.php
  1066. */
  1067. function add_to_cart_shortcode( $content = '' ) {
  1068. //exit($content);
  1069. if ( preg_match_all( "/\[add_to_cart=([\d]+)\]/", $content, $matches ) ) {
  1070. foreach ( $matches[1] as $key => $product_id ) {
  1071. $original_string = $matches[0][$key];
  1072. $output = wpsc_add_to_cart_button( $product_id, true );
  1073. $content = str_replace( $original_string, $output, $content );
  1074. }
  1075. }
  1076. return $content;
  1077. }
  1078. function wpsc_enable_page_filters( $excerpt = '' ) {
  1079. add_filter( 'the_content', 'add_to_cart_shortcode', 12 ); //Used for add_to_cart_button shortcode
  1080. add_filter( 'the_content', 'wpsc_products_page', 1 );
  1081. add_filter( 'the_content', 'wpsc_single_template',12 );
  1082. add_filter( 'archive_template','wpsc_the_category_template');
  1083. add_filter( 'the_title', 'wpsc_the_category_title',10,2 );
  1084. add_filter( 'the_content', 'wpsc_place_shopping_cart', 12 );
  1085. add_filter( 'the_content', 'wpsc_transaction_results', 12 );
  1086. add_filter( 'the_content', 'wpsc_user_log', 12 );
  1087. return $excerpt;
  1088. }
  1089. wpsc_enable_page_filters();
  1090. /**
  1091. * Body Class Filter
  1092. * @modified: 2009-10-14 by Ben
  1093. * @description: Adds additional wpsc classes to the body tag.
  1094. * @param: $classes = Array of body classes
  1095. * @return: (Array) of classes
  1096. */
  1097. function wpsc_body_class( $classes ) {
  1098. global $wp_query, $wpsc_query;
  1099. $post_id = 0;
  1100. if ( isset( $wp_query->post->ID ) )
  1101. $post_id = $wp_query->post->ID;
  1102. $page_url = get_permalink( $post_id );
  1103. // If on a product or category page...
  1104. if ( get_option( 'product_list_url' ) == $page_url ) {
  1105. $classes[] = 'wpsc';
  1106. if ( !is_array( $wpsc_query->query ) )
  1107. $classes[] = 'wpsc-home';
  1108. if ( wpsc_is_single_product ( ) ) {
  1109. $classes[] = 'wpsc-single-product';
  1110. if ( absint( $wpsc_query->products[0]['id'] ) > 0 ) {
  1111. $classes[] = 'wpsc-single-product-' . $wpsc_query->products[0]['id'];
  1112. }
  1113. }
  1114. if ( wpsc_is_in_category() && !wpsc_is_single_product() )
  1115. $classes[] = 'wpsc-category';
  1116. if ( isset( $wpsc_query->query_vars['category_id'] ) && absint( $wpsc_query->query_vars['category_id'] ) > 0 )
  1117. $classes[] = 'wpsc-category-' . $wpsc_query->query_vars['category_id'];
  1118. }
  1119. // If viewing the shopping cart...
  1120. if ( get_option( 'shopping_cart_url' ) == $page_url ) {
  1121. $classes[] = 'wpsc';
  1122. $classes[] = 'wpsc-shopping-cart';
  1123. }
  1124. // If viewing the transaction...
  1125. if ( get_option( 'transact_url' ) == $page_url ) {
  1126. $classes[] = 'wpsc';
  1127. $classes[] = 'wpsc-transaction-details';
  1128. }
  1129. // If viewing your account...
  1130. if ( get_option( 'user_account_url' ) == $page_url ) {
  1131. $classes[] = 'wpsc';
  1132. $classes[] = 'wpsc-user-account';
  1133. }
  1134. return $classes;
  1135. }
  1136. add_filter( 'body_class', 'wpsc_body_class' );
  1137. /**
  1138. * Featured Product
  1139. *
  1140. * Refactoring Featured Product Plugin to utilize Sticky Post Status, available since WP 2.7
  1141. * also utilizes Featured Image functionality, available as post_thumbnail since 2.9, Featured Image since 3.0
  1142. * Main differences - Removed 3.8 conditions, removed meta box from admin, changed meta_values
  1143. * Removes shortcode, as it automatically ties in to top_of_page hook if sticky AND featured product exists.
  1144. *
  1145. * @package wp-e-commerce
  1146. * @since 3.8
  1147. */
  1148. function wpsc_the_sticky_image( $product_id ) {
  1149. $attached_images = (array)get_posts( array(
  1150. 'post_type' => 'attachment',
  1151. 'numberposts' => 1,
  1152. 'post_status' => null,
  1153. 'post_parent' => $product_id,
  1154. 'orderby' => 'menu_order',
  1155. 'order' => 'ASC'
  1156. ) );
  1157. if ( has_post_thumbnail( $product_id ) ) {
  1158. add_image_size( 'featured-product-thumbnails', 540, 260, TRUE );
  1159. $image = get_the_post_thumbnail( $product_id, 'featured-product-thumbnails' );
  1160. return $image;
  1161. } elseif ( !empty( $attached_images ) ) {
  1162. $attached_image = $attached_images[0];
  1163. $image_link = wpsc_product_image( $attached_image->ID, 540, 260 );
  1164. return '<img src="' . $image_link . '" alt="" />';
  1165. } else {
  1166. return false;
  1167. }
  1168. }
  1169. function is_products_page(){
  1170. global $post;
  1171. $product_page_id = wpec_get_the_post_id_by_shortcode('[productspage]');
  1172. if($post->ID == $product_page_id)
  1173. return true;
  1174. else
  1175. return false;
  1176. }
  1177. /**
  1178. * wpsc_display_products_page function.
  1179. *
  1180. * @access public
  1181. * @param mixed $query
  1182. * @return void
  1183. */
  1184. function wpsc_display_featured_products_page() {
  1185. global $wp_query;
  1186. $sticky_array = get_option( 'sticky_products' );
  1187. if ( (is_front_page() || is_home() || is_products_page() ) && !empty( $sticky_array ) && $wp_query->post_count > 1) {
  1188. $query = get_posts( array(
  1189. 'post__in' => $sticky_array,
  1190. 'post_type' => 'wpsc-product',
  1191. 'orderby' => 'rand',
  1192. 'numberposts' => 1,
  1193. 'posts_per_page' => 1
  1194. ) );
  1195. if ( count( $query ) > 0 ) {
  1196. $GLOBALS['nzshpcrt_activateshpcrt'] = true;
  1197. $image_width = get_option( 'product_image_width' );
  1198. $image_height = get_option( 'product_image_height' );
  1199. $featured_product_theme_path = wpsc_get_template_file_path( 'wpsc-featured_product.php' );
  1200. ob_start();
  1201. include_once($featured_product_theme_path);
  1202. $is_single = false;
  1203. $output .= ob_get_contents();
  1204. ob_end_clean();
  1205. //Begin outputting featured product. We can worry about templating later, or folks can just CSS it up.
  1206. echo $output;
  1207. //End output
  1208. }
  1209. }
  1210. }
  1211. if(get_option( 'wpsc_hide_featured_products' ) == 1){
  1212. add_action( 'wpsc_top_of_products_page', 'wpsc_display_featured_products_page', 12 );
  1213. }
  1214. /**
  1215. * wpsc_display_products_page class
  1216. *
  1217. * Shows only products from current category, but not from subcategories.
  1218. *
  1219. * @access public
  1220. * @return void
  1221. */
  1222. class WPSC_Hide_subcatsprods_in_cat {
  1223. var $q;
  1224. function get_posts( &$q ) {
  1225. $this->q =& $q;
  1226. if ( ( !isset($q->query_vars['taxonomy']) || ( "wpsc_product_category" != $q->query_vars['taxonomy'] )) )
  1227. return false;
  1228. add_action( 'posts_where', array( &$this, 'where' ) );
  1229. add_action( 'posts_join', array( &$this, 'join' ) );
  1230. }
  1231. function where( $where ) {
  1232. global $wpdb;
  1233. remove_action( 'posts_where', array( &$this, 'where' ) );
  1234. $term_id=$wpdb->get_var($wpdb->prepare('SELECT term_id FROM '.$wpdb->terms.' WHERE slug = %s ', $this->q->query_vars['term']));
  1235. if ( !is_numeric( $term_id ) || $term_id < 1 )
  1236. return $where;
  1237. $term_taxonomy_id =

Large files files are truncated, but you can click here to view the full file