PageRenderTime 92ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://gitlab.com/endomorphosis/reservationtelco
PHP | 843 lines | 574 code | 150 blank | 119 comment | 129 complexity | 994f50d20d373a995eefef891c0c054a MD5 | raw 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. function wpsc_check_theme_versions(){
  11. $nag = false;
  12. $theme_array = wpsc_get_themes();
  13. //exit('<pre>'.print_r($theme_array, true).'</pre>');
  14. foreach((array)$theme_array as $theme){
  15. // exit($theme['Version']);
  16. if($theme['Name']=='Default Theme' ||$theme['Name']=='iShop Theme' ||$theme['Name']=='Marketplace Theme' ){
  17. if((float)$theme['Version'] < 3.6){
  18. $nag = true;
  19. }
  20. }
  21. }
  22. return $nag;
  23. }
  24. function wpsc_get_themes($themes_folder = '') {
  25. $wpsc_themes = array ();
  26. // exit(WPSC_THEMES_PATH);
  27. $themes_root = WPSC_THEMES_PATH;
  28. if( !empty($themes_folder) ){}
  29. //$themes_root .= $themes_folder;
  30. if ( !is_dir( $themes_root ) ) {
  31. return $wpsc_themes;
  32. }
  33. // Files in wp-content/uploads/themes directory
  34. //exit($themes_root);
  35. $themes_dir = opendir($themes_root);
  36. $theme_files = array();
  37. if ( $themes_dir ) {
  38. //exit('her');
  39. while (($file = readdir( $themes_dir ) ) !== false ) {
  40. if ( substr($file, 0, 1) == '.' )
  41. continue;
  42. if ( is_dir( $themes_root.'/'.$file ) ) {
  43. $themes_subdir = @ opendir( $themes_root.'/'.$file );
  44. if ( $themes_subdir ) {
  45. while (($subfile = readdir( $themes_subdir ) ) !== false ) {
  46. if ( substr($subfile, 0, 1) == '.' )
  47. continue;
  48. if ( substr($subfile, -4) == '.css' )
  49. $theme_files[] = "$file/$subfile";
  50. }
  51. }
  52. } else {
  53. if ( substr($file, -4) == '.css' )
  54. $theme_files[] = $file;
  55. }
  56. }
  57. }
  58. @closedir( $themes_dir );
  59. @closedir( $themes_subdir );
  60. if ( !$themes_dir || empty($theme_files) )
  61. return $wpsc_themes;
  62. foreach ( $theme_files as $theme_file ) {
  63. if ( !is_readable( "$themes_root/$theme_file" ) )
  64. continue;
  65. $theme_data = get_theme_data( "$themes_root/$theme_file", false, false ); //Do not apply markup/translate as it'll be cached.
  66. if ( empty ( $theme_data['Name'] ) )
  67. continue;
  68. $wpsc_themes[plugin_basename( $theme_file )] = $theme_data;
  69. }
  70. uasort( $wpsc_themes, create_function( '$a, $b', 'return strnatcasecmp( $a["Name"], $b["Name"] );' ));
  71. //$cache_plugins[ $plugin_folder ] = $wp_plugins;
  72. //wp_cache_set('plugins', $cache_plugins, 'plugins');
  73. return $wpsc_themes;
  74. }
  75. /**
  76. *wpsc_get_theme_file_path function, gets the path to the theme file, uses the plugin themes folder if the file is not in the uploads one
  77. */
  78. function wpsc_get_theme_file_path($file) {
  79. // get the theme folder here
  80. global $wpsc_theme_path;
  81. $file = basename($file);
  82. $cur_wpsc_theme_folder = apply_filters('wpsc_theme_folder',$wpsc_theme_path.WPSC_THEME_DIR);
  83. if(is_file($cur_wpsc_theme_folder."/".$file)) {
  84. $output = $cur_wpsc_theme_folder."/".$file;
  85. } else {
  86. $wpsc_theme_path = WPSC_FILE_PATH . "/themes/".WPSC_THEME_DIR;
  87. $output = $wpsc_theme_path."/".$file;
  88. }
  89. return $output;
  90. }
  91. /**
  92. *select_wpsc_theme_functions function, provides a place to override the e-commece theme path
  93. * add to switch "theme's functions file
  94. * © with xiligroup dev
  95. * @todo - 1bigidea - shouldn't this load theme/functions.php rather than theme/theme.php???? (handy feature though)
  96. */
  97. function wpsc_select_theme_functions() {
  98. global $wpsc_theme_path;
  99. $theme_dir = WPSC_THEME_DIR; /* done by plugins_loaded */
  100. $cur_wpsc_theme_folder = apply_filters('wpsc_theme_folder',$wpsc_theme_path.$theme_dir);
  101. if((get_option('wpsc_selected_theme') != '') && (file_exists($cur_wpsc_theme_folder."/".$theme_dir.".php") )) {
  102. include_once($cur_wpsc_theme_folder.'/'.$theme_dir.'.php');
  103. }
  104. // end add by xiligroup.dev
  105. }
  106. add_action('init','wpsc_select_theme_functions',1);
  107. /**
  108. * wpsc_user_enqueues products function,
  109. * enqueue all javascript and CSS for wp ecommerce
  110. */
  111. function wpsc_enqueue_user_script_and_css() {
  112. global $wp_styles, $wpsc_theme_url, $wpsc_theme_path;
  113. /**
  114. * added by xiligroup.dev to be compatible with touchshop
  115. */
  116. if (has_filter('wpsc_enqueue_user_script_and_css') && apply_filters('wpsc_mobile_scripts_css_filters',false)){
  117. do_action('wpsc_enqueue_user_script_and_css');
  118. } else {
  119. /**
  120. * end of added by xiligroup.dev to be compatible with touchshop
  121. */
  122. $version_identifier = WPSC_VERSION.".".WPSC_MINOR_VERSION;
  123. //$version_identifier = '';
  124. if(is_numeric($_GET['category']) || is_numeric($wp_query->query_vars['product_category']) || is_numeric(get_option('wpsc_default_category'))) {
  125. if(is_numeric($wp_query->query_vars['product_category'])) {
  126. $category_id = $wp_query->query_vars['product_category'];
  127. } else if(is_numeric($_GET['category'])) {
  128. $category_id = $_GET['category'];
  129. } else {
  130. $category_id = get_option('wpsc_default_category');
  131. }
  132. }
  133. if(is_ssl()) {
  134. $siteurl = str_replace("http://", "https://", $siteurl);
  135. }
  136. wp_enqueue_script( 'jQuery');
  137. wp_enqueue_script('wp-e-commerce', WPSC_URL.'/js/wp-e-commerce.js', array('jquery'), $version_identifier);
  138. wp_enqueue_script('wp-e-commerce-ajax-legacy', WPSC_URL.'/js/ajax.js', false, $version_identifier);
  139. wp_enqueue_script('wp-e-commerce-dynamic', $siteurl."/index.php?wpsc_user_dynamic_js=true", false, $version_identifier);
  140. wp_enqueue_script('livequery', WPSC_URL.'/wpsc-admin/js/jquery.livequery.js', array('jquery'), '1.0.3');
  141. wp_enqueue_script('jquery-rating', WPSC_URL.'/js/jquery.rating.js', array('jquery'), $version_identifier);
  142. wp_enqueue_script('wp-e-commerce-legacy', WPSC_URL.'/js/user.js', array('jquery'), WPSC_VERSION.WPSC_MINOR_VERSION);
  143. wp_enqueue_script('wpsc-thickbox',WPSC_URL.'/js/thickbox.js', array('jquery'), 'Instinct_e-commerce');
  144. if(file_exists($wpsc_theme_path.get_option('wpsc_selected_theme')."/".get_option('wpsc_selected_theme').".css")) {
  145. $theme_url = $wpsc_theme_url.get_option('wpsc_selected_theme')."/".get_option('wpsc_selected_theme').".css";
  146. } else {
  147. $theme_url = $wpsc_theme_url. '/default/default.css';
  148. }
  149. wp_enqueue_style( 'wpsc-theme-css', $theme_url, false, $version_identifier, 'all');
  150. wp_enqueue_style( 'wpsc-theme-css-compatibility', WPSC_URL. '/themes/compatibility.css', false, $version_identifier, 'all');
  151. wp_enqueue_style( 'wpsc-product-rater', WPSC_URL.'/js/product_rater.css', false, $version_identifier, 'all');
  152. wp_enqueue_style( 'wp-e-commerce-dynamic',$siteurl."/index.php?wpsc_user_dynamic_css=true&category=$category_id" , false, $version_identifier, 'all' );
  153. wp_enqueue_style( 'wpsc-thickbox', WPSC_URL.'/js/thickbox.css', false, $version_identifier, 'all');
  154. /* IE conditional css
  155. wp_enqueue_style( 'wpsc-ie-fixes', WPSC_URL.'/themes/wpsc-ie-fixes.css', false, $version_identifier, 'all');
  156. $wp_styles->add_data( 'wpsc-ie-fixes', 'conditional', 'lt IE 7' );
  157. */
  158. }
  159. if(!defined('WPSC_MP3_MODULE_USES_HOOKS') and function_exists('listen_button') ) {
  160. function wpsc_legacy_add_mp3_preview($product_id, &$product_data) {
  161. global $wpdb;
  162. // echo "<pre>".print_r($product_data,true)."</pre>";
  163. if(function_exists('listen_button')){
  164. $file_data = $wpdb->get_row("SELECT * FROM `".WPSC_TABLE_PRODUCT_FILES."` WHERE `id`='".$product_data['file']."' LIMIT 1",ARRAY_A);
  165. if($file_data != null) {
  166. echo listen_button($file_data['idhash'], $file_data['id']);
  167. }
  168. }
  169. }
  170. add_action('wpsc_product_before_description', 'wpsc_legacy_add_mp3_preview', 10, 2);
  171. }
  172. }
  173. if(strpos($_SERVER['SCRIPT_NAME'], "wp-admin") === false) {
  174. add_action('init', 'wpsc_enqueue_user_script_and_css');
  175. }
  176. function wpsc_product_list_rss_feed() {
  177. $rss_url = htmlentities(add_query_arg('wpsc_action', 'rss'));
  178. echo "<link rel='alternate' type='application/rss+xml' title='".get_option('blogname')." Product List RSS' href='{$rss_url}'/>";
  179. }
  180. add_action('wp_head', 'wpsc_product_list_rss_feed');
  181. function wpsc_user_dynamic_js() {
  182. header('Content-Type: text/javascript');
  183. header('Expires: '.gmdate('r',mktime(0,0,0,date('m'),(date('d')+12),date('Y'))).'');
  184. header('Cache-Control: public, must-revalidate, max-age=86400');
  185. header('Pragma: public');
  186. $siteurl = get_option('siteurl');
  187. ?>
  188. jQuery.noConflict();
  189. /* base url */
  190. var base_url = "<?php echo $siteurl; ?>";
  191. var WPSC_URL = "<?php echo WPSC_URL; ?>";
  192. var WPSC_IMAGE_URL = "<?php echo WPSC_IMAGE_URL; ?>";
  193. var WPSC_DIR_NAME = "<?php echo WPSC_DIR_NAME; ?>";
  194. /* LightBox Configuration start*/
  195. var fileLoadingImage = "<?php echo WPSC_URL; ?>/images/loading.gif";
  196. var fileBottomNavCloseImage = "<?php echo WPSC_URL; ?>/images/closelabel.gif";
  197. var fileThickboxLoadingImage = "<?php echo WPSC_URL; ?>/images/loadingAnimation.gif";
  198. var resizeSpeed = 9; // controls the speed of the image resizing (1=slowest and 10=fastest)
  199. var borderSize = 10; //if you adjust the padding in the CSS, you will need to update this variable
  200. <?php
  201. exit();
  202. }
  203. if(isset($_GET['wpsc_user_dynamic_js']) && $_GET['wpsc_user_dynamic_js'] == 'true') {
  204. add_action("init", 'wpsc_user_dynamic_js');
  205. }
  206. function wpsc_user_dynamic_css() {
  207. global $wpdb;
  208. header('Content-Type: text/css');
  209. header('Expires: '.gmdate('r',mktime(0,0,0,date('m'),(date('d')+12),date('Y'))).'');
  210. header('Cache-Control: public, must-revalidate, max-age=86400');
  211. header('Pragma: public');
  212. $category_id = absint($_GET['category']);
  213. $category_data = $wpdb->get_row("SELECT * FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `id`='{$category_id}' LIMIT 1",ARRAY_A);
  214. if($category_data['display_type'] != '') {
  215. $display_type = $category_data['display_type'];
  216. } else {
  217. $display_type = get_option('product_view');
  218. }
  219. if(!defined('WPSC_DISABLE_IMAGE_SIZE_FIXES') || (constant('WPSC_DISABLE_IMAGE_SIZE_FIXES') != true)) {
  220. $thumbnail_width = get_option('product_image_width');
  221. if($thumbnail_width <= 0) {
  222. $thumbnail_width = 96;
  223. }
  224. $thumbnail_height = get_option('product_image_height');
  225. if($thumbnail_height <= 0) {
  226. $thumbnail_height = 96;
  227. }
  228. $single_thumbnail_width = get_option('single_view_image_width');
  229. $single_thumbnail_height = get_option('single_view_image_height');
  230. if($single_thumbnail_width <= 0) {
  231. $single_thumbnail_width = 128;
  232. }
  233. $show_thumbnails = get_option('show_thumbnails');
  234. ?>
  235. /*
  236. * Default View Styling
  237. */
  238. <?php if ($show_thumbnails) : ?>
  239. div.default_product_display div.textcol{
  240. margin-left: <?php echo $thumbnail_width + 10; ?>px !important;
  241. <?php /*_margin-left: <?php echo ($thumbnail_width/2) + 5; ?>px !important; */ ?>
  242. min-height: <?php echo $thumbnail_height;?>px;
  243. _height: <?php echo $thumbnail_height;?>px;
  244. }
  245. <?php endif; ?>
  246. div.default_product_display div.textcol div.imagecol{
  247. position:absolute;
  248. top:0px;
  249. left: 0px;
  250. margin-left: -<?php echo $thumbnail_width + 10; ?>px !important;
  251. }
  252. div.default_product_display div.textcol div.imagecol a img {
  253. width: <?php echo $thumbnail_width; ?>px;
  254. height: <?php echo $thumbnail_height; ?>px;
  255. }
  256. div.default_product_display div.item_no_image {
  257. width: <?php echo $thumbnail_width-2; ?>px;
  258. height: <?php echo $thumbnail_height-2; ?>px;
  259. }
  260. div.default_product_display div.item_no_image a {
  261. width: <?php echo $thumbnail_width-2; ?>px;
  262. }
  263. /*
  264. * Grid View Styling
  265. */
  266. div.product_grid_display div.item_no_image {
  267. width: <?php echo $thumbnail_width-2; ?>px;
  268. height: <?php echo $thumbnail_height-2; ?>px;
  269. }
  270. div.product_grid_display div.item_no_image a {
  271. width: <?php echo $thumbnail_width-2; ?>px;
  272. }
  273. /*
  274. * Single View Styling
  275. */
  276. div.single_product_display div.item_no_image {
  277. width: <?php echo $single_thumbnail_width-2; ?>px;
  278. height: <?php echo $single_thumbnail_height-2; ?>px;
  279. }
  280. div.single_product_display div.item_no_image a {
  281. width: <?php echo $single_thumbnail_width-2; ?>px;
  282. }
  283. div.single_product_display div.textcol{
  284. margin-left: <?php if(get_option('show_thumbnails')){ echo $single_thumbnail_width + 10;}else{ echo 0;} ?>px !important;
  285. min-height: <?php echo $single_thumbnail_height;?>px;
  286. _height: <?php echo $single_thumbnail_height;?>px;
  287. }
  288. div.single_product_display div.textcol div.imagecol{
  289. position:absolute;
  290. top:0px;
  291. left: 0px;
  292. margin-left: -<?php echo $single_thumbnail_width + 10; ?>px !important;
  293. }
  294. div.single_product_display div.textcol div.imagecol a img {
  295. width: <?php echo $single_thumbnail_width; ?>px;
  296. height: <?php echo $single_thumbnail_height; ?>px;
  297. }
  298. <?php
  299. $product_image_size_list = $wpdb->get_results("SELECT `products`.`id`, `meta1`.`meta_value` AS `height`, `meta2`.`meta_value` AS `width` FROM `".WPSC_TABLE_PRODUCT_LIST."` AS `products` INNER JOIN `".WPSC_TABLE_PRODUCTMETA."` AS `meta1` INNER JOIN `".WPSC_TABLE_PRODUCTMETA."` AS `meta2` ON `products`.`id` = `meta1`.`product_id` AND `products`.`id` = `meta2`.`product_id` WHERE `products`.`thumbnail_state` IN(0,2,3) AND `meta1`.`meta_key` IN ('thumbnail_height') AND `meta2`.`meta_key` IN ('thumbnail_width')", ARRAY_A);
  300. //print_r($product_image_size_list);
  301. foreach((array)$product_image_size_list as $product_image_sizes) {
  302. $individual_thumbnail_height = $product_image_sizes['height'];
  303. $individual_thumbnail_width = $product_image_sizes['width'];
  304. $product_id = $product_image_sizes['id'];
  305. if($individual_thumbnail_height > $thumbnail_height) {
  306. echo " div.default_product_display.product_view_$product_id div.textcol{\n\r";
  307. echo " min-height: ".($individual_thumbnail_height + 10)."px !important;\n\r";
  308. echo " _height: ".($individual_thumbnail_height + 10)."px !important;\n\r";
  309. echo " }\n\r";
  310. }
  311. if($individual_thumbnail_width > $thumbnail_width) {
  312. echo " div.default_product_display.product_view_$product_id div.textcol{\n\r";
  313. echo " margin-left: ".($individual_thumbnail_width + 10)."px !important;\n\r";
  314. //echo " _margin-left: ".(($individual_thumbnail_width/2) + 5)."px !important;\n\r";
  315. echo " }\n\r";
  316. echo " div.default_product_display.product_view_$product_id div.textcol div.imagecol{\n\r";
  317. echo " position:absolute;\n\r";
  318. echo " top:0px;\n\r";
  319. echo " left: 0px;\n\r";
  320. echo " margin-left: -".($individual_thumbnail_width + 10)."px !important;\n\r";
  321. echo " }\n\r";
  322. }
  323. if(($individual_thumbnail_width > $thumbnail_width) || ($individual_thumbnail_height > $thumbnail_height)) {
  324. echo " div.default_product_display.product_view_$product_id div.textcol div.imagecol a img{\n\r";
  325. echo " width: ".$individual_thumbnail_width."px;\n\r";
  326. echo " height: ".$individual_thumbnail_height."px;\n\r";
  327. echo " }\n\r";
  328. }
  329. }
  330. }
  331. if(is_numeric($_GET['brand']) || (get_option('show_categorybrands') == 3)) {
  332. $brandstate = 'block';
  333. $categorystate = 'none';
  334. } else {
  335. $brandstate = 'none';
  336. $categorystate = 'block';
  337. }
  338. ?>
  339. div#categorydisplay{
  340. display: <?php echo $categorystate; ?>;
  341. }
  342. div#branddisplay{
  343. display: <?php echo $brandstate; ?>;
  344. }
  345. <?php
  346. exit();
  347. }
  348. if(isset($_GET['wpsc_user_dynamic_css']) && $_GET['wpsc_user_dynamic_css'] == 'true') {
  349. add_action("init", 'wpsc_user_dynamic_css');
  350. }
  351. // Template tags
  352. /**
  353. * wpsc display products function
  354. * @return string - html displaying one or more products
  355. */
  356. function wpsc_display_products_page($query) {
  357. global $wpdb, $wpsc_query, $wpsc_theme_path;
  358. /// added by xiligroup.dev to be compatible with touchshop
  359. $cur_wpsc_theme_folder = apply_filters('wpsc_theme_folder',$wpsc_theme_path.WPSC_THEME_DIR);
  360. /// end of added by xiligroup.dev to be compatible with touchshop
  361. $temp_wpsc_query = new WPSC_query($query);
  362. list($wpsc_query, $temp_wpsc_query) = array($temp_wpsc_query, $wpsc_query); // swap the wpsc_query objects
  363. $GLOBALS['nzshpcrt_activateshpcrt'] = true;
  364. ob_start();
  365. if(wpsc_is_single_product()) {
  366. include($cur_wpsc_theme_folder."/single_product.php");
  367. } else {
  368. // get the display type for the selected category
  369. if(is_numeric($wpsc_query->query_vars['category_id'])) {
  370. $category_id =(int) $wpsc_query->query_vars['category_id'];
  371. $display_type = $wpdb->get_var("SELECT `display_type` FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `id`='{$category_id}' LIMIT 1");
  372. }
  373. if($display_type == '') {
  374. $display_type = get_option('product_view');
  375. }
  376. if(isset($_SESSION['wpsc_display_type'])) {
  377. $display_type = $_SESSION['wpsc_display_type'];
  378. }
  379. if(isset($_GET['view_type'])) {
  380. switch($_GET['view_type']) {
  381. case 'grid':
  382. $display_type = 'grid';
  383. $_SESSION['wpsc_display_type'] = $display_type;
  384. break;
  385. case 'list':
  386. $display_type = 'list';
  387. $_SESSION['wpsc_display_type'] = $display_type;
  388. break;
  389. case 'default':
  390. $display_type = 'default';
  391. $_SESSION['wpsc_display_type'] = $display_type;
  392. break;
  393. default:
  394. break;
  395. }
  396. }
  397. //exit($display_type);
  398. // switch the display type, based on the display type variable...
  399. switch($display_type) {
  400. case "grid":
  401. if(file_exists($cur_wpsc_theme_folder."/grid_view.php")) {
  402. include($cur_wpsc_theme_folder."/grid_view.php");
  403. break; // only break if we have the file;
  404. }
  405. case "list":
  406. if(file_exists($cur_wpsc_theme_folder."/list_view.php")) {
  407. include($cur_wpsc_theme_folder."/list_view.php");
  408. break; // only break if we have the file;
  409. }
  410. case "default": // this may be redundant :D
  411. default:
  412. include($cur_wpsc_theme_folder."/products_page.php");
  413. break;
  414. }
  415. }
  416. $output = ob_get_contents();
  417. ob_end_clean();
  418. //$output = str_replace('$','\$', $output);
  419. list($temp_wpsc_query, $wpsc_query) = array($wpsc_query, $temp_wpsc_query); // swap the wpsc_query objects back
  420. return $output;
  421. }
  422. //handles replacing the tags in the pages
  423. function wpsc_products_page($content = '') {
  424. global $wpdb, $wp_query, $wpsc_query, $wpsc_theme_path;
  425. /// added by xiligroup.dev to be compatible with touchshop
  426. $cur_wpsc_theme_folder = apply_filters('wpsc_theme_folder',$wpsc_theme_path.WPSC_THEME_DIR);
  427. /// end of added by xiligroup.dev to be compatible with touchshop
  428. $output = '';
  429. if(preg_match("/\[productspage\]/",$content)) {
  430. $wpsc_query->get_products();
  431. $GLOBALS['nzshpcrt_activateshpcrt'] = true;
  432. ob_start();
  433. if(wpsc_is_single_product()) {
  434. include($cur_wpsc_theme_folder."/single_product.php");
  435. } else {
  436. // get the display type for the selected category
  437. if(is_numeric($_GET['category']) || is_numeric($wp_query->query_vars['category_id']) || is_numeric(get_option('wpsc_default_category'))) {
  438. if(is_numeric($wp_query->query_vars['category_id'])) {
  439. $category_id =(int) $wp_query->query_vars['category_id'];
  440. } else if(is_numeric($_GET['category'])) {
  441. $category_id = (int)$_GET['category'];
  442. } else {
  443. $category_id = (int)get_option('wpsc_default_category');
  444. }
  445. }
  446. $display_type = $wpdb->get_var("SELECT `display_type` FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `id`='{$category_id}' LIMIT 1");
  447. if($display_type == '') {
  448. $display_type = get_option('product_view');
  449. }
  450. if(isset($_SESSION['wpsc_display_type'])) {
  451. $display_type = $_SESSION['wpsc_display_type'];
  452. }
  453. if(isset($_GET['view_type'])) {
  454. switch($_GET['view_type']) {
  455. case 'grid':
  456. $display_type = 'grid';
  457. $_SESSION['wpsc_display_type'] = $display_type;
  458. break;
  459. case 'list':
  460. $display_type = 'list';
  461. $_SESSION['wpsc_display_type'] = $display_type;
  462. break;
  463. case 'default':
  464. $display_type = 'default';
  465. $_SESSION['wpsc_display_type'] = $display_type;
  466. break;
  467. default:
  468. break;
  469. }
  470. }
  471. // switch the display type, based on the display type variable...
  472. switch($display_type) {
  473. case "grid":
  474. if(file_exists($cur_wpsc_theme_folder."/grid_view.php")) {
  475. include($cur_wpsc_theme_folder."/grid_view.php");
  476. break; // only break if we have the function;
  477. }
  478. case "list":
  479. if(file_exists($cur_wpsc_theme_folder."/list_view.php")) {
  480. include($cur_wpsc_theme_folder."/list_view.php");
  481. break; // only break if we have the file;
  482. }
  483. case "default": // this may be redundant :D
  484. default:
  485. include($cur_wpsc_theme_folder."/products_page.php");
  486. break;
  487. }
  488. }
  489. $output .= ob_get_contents();
  490. ob_end_clean();
  491. $output = str_replace('$','\$', $output);
  492. // } else {
  493. // $GLOBALS['nzshpcrt_activateshpcrt'] = true;
  494. // ob_start();
  495. // include_once(WPSC_FILE_PATH . "/products_page.php");
  496. // $output = ob_get_contents();
  497. // ob_end_clean();
  498. // }
  499. return preg_replace("/(<p>)*\[productspage\](<\/p>)*/",$output, $content);
  500. } else {
  501. return $content;
  502. }
  503. }
  504. /**
  505. * wpsc_count_themes_in_uploads_directory, does exactly what the name says
  506. */
  507. function wpsc_count_themes_in_uploads_directory() {
  508. if ( !is_dir( WPSC_THEMES_PATH ) ) {
  509. return 0;
  510. }
  511. $uploads_dir = @opendir(WPSC_THEMES_PATH);
  512. $file_names = array();
  513. while(($file = @readdir($uploads_dir)) !== false) {
  514. if(is_dir(WPSC_THEMES_PATH.$file) && ($file != "..") && ($file != ".") && ($file != ".svn")){
  515. $file_names[] = $file;
  516. }
  517. }
  518. return count($file_names);
  519. }
  520. function wpsc_place_shopping_cart($content = '') {
  521. global $wpsc_theme_path;
  522. /// added by xiligroup.dev to be compatible with touchshop
  523. $cur_wpsc_theme_folder = apply_filters('wpsc_theme_folder',$wpsc_theme_path.WPSC_THEME_DIR);
  524. /// end of added by xiligroup.dev to be compatible with touchshop
  525. if(preg_match("/\[shoppingcart\]/",$content)) {
  526. $GLOBALS['nzshpcrt_activateshpcrt'] = true;
  527. define('DONOTCACHEPAGE', true);
  528. ob_start();
  529. include($cur_wpsc_theme_folder."/shopping_cart_page.php");
  530. $output = ob_get_contents();
  531. ob_end_clean();
  532. $output = str_replace('$','\$', $output);
  533. return preg_replace("/(<p>)*\[shoppingcart\](<\/p>)*/",$output, $content);
  534. } else {
  535. return $content;
  536. }
  537. }
  538. /// wpsc_checkout is an obsolete function
  539. // function wpsc_checkout($content = '') {
  540. // if(preg_match("/\[checkout\]/",$content)) {
  541. // ob_start();
  542. // include_once(WPSC_FILE_PATH . "/checkout.php");
  543. // $output = ob_get_contents();
  544. // ob_end_clean();
  545. // return preg_replace("/(<p>)*\[checkout\](<\/p>)*/",$output, $content);
  546. // } else {
  547. // return $content;
  548. // }
  549. // }
  550. function wpsc_transaction_results($content = '') {
  551. if(preg_match("/\[transactionresults\]/",$content)) {
  552. define('DONOTCACHEPAGE', true);
  553. ob_start();
  554. include(WPSC_FILE_PATH . "/transaction_results.php");
  555. $output = ob_get_contents();
  556. ob_end_clean();
  557. return preg_replace("/(<p>)*\[transactionresults\](<\/p>)*/",$output, $content);
  558. } else {
  559. return $content;
  560. }
  561. }
  562. function wpsc_user_log($content = '') {
  563. if(preg_match("/\[userlog\]/",$content)) {
  564. define('DONOTCACHEPAGE', true);
  565. ob_start();
  566. include(WPSC_FILE_PATH . '/user-log.php');
  567. $output = ob_get_contents();
  568. ob_end_clean();
  569. return preg_replace("/(<p>)*\[userlog\](<\/p>)*/",$output, $content);
  570. } else {
  571. return $content;
  572. }
  573. }
  574. //displays a list of categories when the code [showcategories] is present in a post or page.
  575. function wpsc_show_categories($content = '') {
  576. if(preg_match("/\[showcategories\]/",$content)) {
  577. $GLOBALS['nzshpcrt_activateshpcrt'] = true;
  578. $output = nzshpcrt_display_categories_groups();
  579. return preg_replace("/(<p>)*\[showcategories\](<\/p>)*/",$output, $content);
  580. } else {
  581. return $content;
  582. }
  583. }
  584. // substitutes in the buy now buttons where the shortcode is in a post.
  585. function wpsc_substitute_buy_now_button($content = '') {
  586. if(preg_match_all("/\[buy_now_button=([\d]+)\]/", $content, $matches)) {
  587. //echo "<pre>".print_r($matches,true)."</pre>";
  588. foreach($matches[1] as $key => $product_id) {
  589. $original_string = $matches[0][$key];
  590. //print_r($matches);
  591. $output = wpsc_buy_now_button($product_id, true);
  592. $content = str_replace($original_string, $output, $content);
  593. }
  594. }
  595. return $content;
  596. }
  597. /* 19-02-09
  598. * add to cart shortcode function used for shortcodes calls the function in
  599. * product_display_functions.php
  600. */
  601. function add_to_cart_shortcode($content = '') {
  602. //exit($content);
  603. if(preg_match_all("/\[add_to_cart=([\d]+)\]/",$content, $matches)) {
  604. foreach($matches[1] as $key => $product_id){
  605. $original_string = $matches[0][$key];
  606. $output = wpsc_add_to_cart_button($product_id, true);
  607. $content = str_replace($original_string, $output, $content);
  608. }
  609. }
  610. return $content;
  611. }
  612. function wpsc_enable_page_filters($excerpt = ''){
  613. global $wp_query;
  614. add_filter('the_content', 'add_to_cart_shortcode', 12);//Used for add_to_cart_button shortcode
  615. add_filter('the_content', 'wpsc_products_page', 12);
  616. add_filter('the_content', 'wpsc_place_shopping_cart', 12);
  617. add_filter('the_content', 'wpsc_transaction_results', 12);
  618. //add_filter('the_content', 'wpsc_checkout', 12);
  619. add_filter('the_content', 'nszhpcrt_homepage_products', 12);
  620. add_filter('the_content', 'wpsc_user_log', 12);
  621. add_filter('the_content', 'nszhpcrt_category_tag', 12);
  622. add_filter('the_content', 'wpsc_show_categories', 12);
  623. add_filter('the_content', 'wpsc_substitute_buy_now_button', 12);
  624. return $excerpt;
  625. }
  626. function wpsc_disable_page_filters($excerpt = '') {
  627. remove_filter('the_content', 'add_to_cart_shortcode');//Used for add_to_cart_button shortcode
  628. remove_filter('the_content', 'wpsc_products_page');
  629. remove_filter('the_content', 'wpsc_place_shopping_cart');
  630. remove_filter('the_content', 'wpsc_transaction_results');
  631. //remove_filter('the_content', 'wpsc_checkout');
  632. remove_filter('the_content', 'nszhpcrt_homepage_products');
  633. remove_filter('the_content', 'wpsc_user_log');
  634. remove_filter('the_content', 'wpsc_category_tag');
  635. remove_filter('the_content', 'wpsc_show_categories');
  636. remove_filter('the_content', 'wpsc_substitute_buy_now_button');
  637. return $excerpt;
  638. }
  639. wpsc_enable_page_filters();
  640. add_filter('get_the_excerpt', 'wpsc_disable_page_filters', -1000000);
  641. add_filter('get_the_excerpt', 'wpsc_enable_page_filters', 1000000);
  642. /**
  643. * Body Class Filter
  644. * @modified: 2009-10-14 by Ben
  645. * @description: Adds additional wpsc classes to the body tag.
  646. * @param: $classes = Array of body classes
  647. * @return: (Array) of classes
  648. */
  649. function wpsc_body_class( $classes ) {
  650. global $wp_query, $wpsc_query;
  651. $post_id = $wp_query->post->ID;
  652. $page_url = get_permalink($post_id);
  653. // If on a product or category page...
  654. if ( get_option('product_list_url') == $page_url ) {
  655. $classes[] = 'wpsc';
  656. if ( !is_array($wpsc_query->query) ) {
  657. $classes[] = 'wpsc-home';
  658. }
  659. if ( wpsc_is_single_product() ) {
  660. $classes[] = 'wpsc-single-product';
  661. if ( absint($wpsc_query->products[0]['id']) > 0) {
  662. $classes[] = 'wpsc-single-product-' . $wpsc_query->products[0]['id'];
  663. }
  664. }
  665. if ( wpsc_is_in_category() && !wpsc_is_single_product() ) {
  666. $classes[] = 'wpsc-category';
  667. }
  668. if ( absint($wpsc_query->query_vars['category_id']) > 0) {
  669. $classes[] = 'wpsc-category-' . $wpsc_query->query_vars['category_id'];
  670. }
  671. if ( absint(wpsc_category_group()) > 0) {
  672. $classes[] = 'wpsc-group-' . wpsc_category_group();
  673. }
  674. }
  675. // If viewing the shopping cart...
  676. if ( get_option('shopping_cart_url') == $page_url ) {
  677. $classes[] = 'wpsc';
  678. $classes[] = 'wpsc-shopping-cart';
  679. }
  680. // If viewing the transaction...
  681. if ( get_option('transact_url') == $page_url ) {
  682. $classes[] = 'wpsc';
  683. $classes[] = 'wpsc-transaction-details';
  684. }
  685. // If viewing your account...
  686. if ( get_option('user_account_url') == $page_url ) {
  687. $classes[] = 'wpsc';
  688. $classes[] = 'wpsc-user-account';
  689. }
  690. return $classes;
  691. }
  692. add_filter( 'body_class', 'wpsc_body_class' );
  693. ?>