PageRenderTime 70ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://gitlab.com/endomorphosis/reservationtelco
PHP | 655 lines | 450 code | 91 blank | 114 comment | 142 complexity | 0c6928398f9386d2b61855be7ff38e1a MD5 | raw file
  1. <?php
  2. /**
  3. * WP eCommerce category display functions
  4. *
  5. * These are functions for the wp-eCommerce categories
  6. * I would like to use an object and the theme engine for this, but it uses a recursive function, and I cannot think of a way to make that work with an object like the rest of the theme engine.
  7. *
  8. * @package wp-e-commerce
  9. * @since 3.7
  10. */
  11. /// category template tags start here
  12. /**
  13. * wpsc starts category query function
  14. * gets passed the query and makes it into a global variable, then starts capturing the html for the category loop
  15. */
  16. function wpsc_start_category_query($arguments = array()) {
  17. global $wpdb, $wpsc_category_query;
  18. $wpsc_category_query = $arguments;
  19. ob_start();
  20. }
  21. /**
  22. * wpsc print category name function
  23. * places the shortcode for the category name
  24. */
  25. function wpsc_print_category_name() {
  26. echo "[wpsc_category_name]";
  27. }
  28. /**
  29. * wpsc print category description function
  30. * places the shortcode for the category description, accepts parameters for the description container
  31. * @param string starting HTML element
  32. * @param string ending HTML element
  33. */
  34. function wpsc_print_category_description($start_element = '', $end_element = '') {
  35. global $wpsc_category_query;
  36. $wpsc_category_query['description_container'] = array('start_element' => $start_element, 'end_element' => $end_element);
  37. echo "[wpsc_category_description]";
  38. }
  39. /**
  40. * wpsc print category url function
  41. * places the shortcode for the category URL
  42. */
  43. function wpsc_print_category_url() {
  44. echo "[wpsc_category_url]";
  45. }
  46. /**
  47. * wpsc print category id function
  48. * places the shortcode for the category URL
  49. */
  50. function wpsc_print_category_id() {
  51. echo "[wpsc_category_id]";
  52. }
  53. /**
  54. * wpsc print category classes function
  55. * places classes for the category including selected state
  56. */
  57. function wpsc_print_category_classes() {
  58. echo "[wpsc_category_classes]";
  59. }
  60. /**
  61. * wpsc print product list function
  62. * places the shortcode for the product list
  63. * @param string starting HTML element
  64. * @param string ending HTML element
  65. */
  66. function wpsc_print_product_list() {
  67. global $wpsc_category_query;
  68. if (get_option('catsprods_display_type') == 1) {
  69. echo "[wpsc_category_product_list]";
  70. }
  71. }
  72. /**
  73. * wpsc print subcategory function
  74. * places the shortcode for the subcategories, accepts parameters for the subcategories container, have this as <ul> and </ul> if using a list
  75. * @param string starting HTML element
  76. * @param string ending HTML element
  77. */
  78. function wpsc_print_subcategory($start_element = '', $end_element = '') {
  79. global $wpsc_category_query;
  80. $wpsc_category_query['subcategory_container'] = array('start_element' => $start_element, 'end_element' => $end_element);
  81. echo "[wpsc_subcategory]";
  82. }
  83. /**
  84. * wpsc print category image function
  85. * places the shortcode for the category image, accepts parameters for width and height
  86. * @param integer width
  87. * @param integer height
  88. */
  89. function wpsc_print_category_image($width = null, $height = null) {
  90. global $wpsc_category_query;
  91. $wpsc_category_query['image_size'] = array('width' => $width, 'height' => $height);
  92. echo "[wpsc_category_image]";
  93. }
  94. /**
  95. * wpsc print category products count function
  96. * places the shortcode for the category product count, accepts parameters for the container element
  97. * @param string starting HTML element
  98. * @param string ending HTML element
  99. */
  100. function wpsc_print_category_products_count($start_element = '', $end_element = '') {
  101. global $wpsc_category_query;
  102. $wpsc_category_query['products_count'] = array('start_element' => $start_element, 'end_element' => $end_element);
  103. echo "[wpsc_category_products_count]";
  104. }
  105. /**
  106. * wpsc end category query function
  107. */
  108. function wpsc_end_category_query() {
  109. global $wpdb, $wpsc_category_query;
  110. $category_html = ob_get_clean();
  111. echo wpsc_display_category_loop($wpsc_category_query, $category_html);
  112. unset($GLOBALS['wpsc_category_query']);
  113. }
  114. /**
  115. * wpsc category loop function
  116. * This function recursively loops throuh the categories to display the category tree.
  117. * WARNING: this function is recursive, be careful what you do with it.
  118. * @param array the category query
  119. * @param string the category html
  120. * @return string - the finished category html
  121. */
  122. function wpsc_display_category_loop($query, $category_html){
  123. global $wpdb, $wpsc_query;
  124. $category_sql_segment = array();
  125. $category_sql_segment[] = "`active`='1'";
  126. if(is_numeric($query['category_group']) ) {
  127. $category_group = absint($query['category_group']);
  128. $category_sql_segment[] = "`group_id`='$category_group'";
  129. } elseif($query['category_group']=='all' ||$query['category_group']=='all+list') {
  130. $category_group = 1;
  131. }
  132. /// select by parent category
  133. $category_sql_segment[] = "`category_parent` = '".absint($query['parent_category_id'])."'";
  134. if(!isset($query['order_by'])) {
  135. $query['order_by'] = array("column" => 'name', "direction" =>'asc');
  136. }
  137. $column = $wpdb->escape($query['order_by']['column']);
  138. if(strtolower($query['order_by']['direction']) == "desc") {
  139. $order = "DESC";
  140. } else {
  141. $order = "ASC";
  142. }
  143. $category_sql_segment = apply_filters('wpsc_display_category_loop_category_sql_segments', $category_sql_segment);
  144. $category_data = $wpdb->get_results("SELECT `id`, `name`, `nice-name`, `description`, `image` FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE ".implode(" AND ", $category_sql_segment)." ORDER BY `{$column}` $order",ARRAY_A);
  145. $output ='';
  146. foreach((array)$category_data as $category_row) {
  147. $modified_query = $query;
  148. $modified_query['parent_category_id'] = $category_row['id'];
  149. $category_count = $wpdb->get_var("SELECT COUNT(`p`.`id`) FROM `".WPSC_TABLE_ITEM_CATEGORY_ASSOC."` AS `a` JOIN `".WPSC_TABLE_PRODUCT_LIST."` AS `p` ON `a`.`product_id` = `p`.`id` WHERE `a`.`category_id` IN ('{$category_row['id']}') AND `p`.`active` IN ('1') AND `p`.`publish` IN('1')");
  150. $start_element = $query['products_count']['start_element'];
  151. $end_element = $query['products_count']['end_element'];
  152. $category_count_html = $start_element.$category_count.$end_element;
  153. $category_description = '';
  154. if($category_row['description'] != '') {
  155. $start_element = $query['description_container']['start_element'];
  156. $end_element = $query['description_container']['end_element'];
  157. $category_description = $start_element.wpautop(wptexturize( wp_kses(stripslashes($category_row['description']), $allowedtags ))).$end_element;
  158. }
  159. $category_classes = 'wpsc-cat-item wpsc-cat-item-' . $category_row['id'];
  160. if ( $wpsc_query->query_vars['category_id'] == $category_row['id']) {
  161. $category_classes .= ' wpsc-current-cat';
  162. }
  163. foreach ( $wpsc_query->breadcrumbs as $breadcrumb ) {
  164. if ( $breadcrumb['id'] == $category_row['id'] ) {
  165. $category_classes .= ' wpsc-cat-ancestor';
  166. break;
  167. }
  168. }
  169. $sub_categories = wpsc_display_category_loop($modified_query, $category_html);
  170. if($sub_categories != '') {
  171. $start_element = $query['subcategory_container']['start_element'];
  172. $end_element = $query['subcategory_container']['end_element'];
  173. $sub_categories = $start_element.$sub_categories.$end_element;
  174. }
  175. $category_image = wpsc_place_category_image($category_row['id'], $modified_query);
  176. $width = $query['image_size']['width'] - 4;
  177. $height = $query['image_size']['height'] - 4;
  178. $category_image_html = '';
  179. if(($query['show_thumbnails'] == 1)) {
  180. if(($category_row['image'] != '') && is_file(WPSC_CATEGORY_DIR.$category_row['image'])) {
  181. $category_image_html = "<img src='$category_image' alt='{$category_row['name']}' title='{$category_row['name']}' class='wpsc_category_image' />";
  182. } else {
  183. $category_image_html = "";
  184. $category_image_html .= " <span class='wpsc_category_image item_no_image ' style='width: {$width}px; height: {$height}px;'>\n\r";
  185. $category_image_html .= " <span class='link_substitute' >\n\r";
  186. $category_image_html .= " <span>".__('N/A', 'wpsc')."</span>\n\r";
  187. $category_image_html .= " </span>\n\r";
  188. $category_image_html .= " </span>\n\r";
  189. }
  190. }
  191. $category_product_list = wpsc_category_product_list($category_row['id']);
  192. $tags_to_replace = array('[wpsc_category_name]',
  193. '[wpsc_category_description]',
  194. '[wpsc_category_url]',
  195. '[wpsc_category_id]',
  196. '[wpsc_category_classes]',
  197. '[wpsc_category_image]',
  198. '[wpsc_subcategory]',
  199. '[wpsc_category_products_count]',
  200. '[wpsc_category_product_list]');
  201. $content_to_place = array(
  202. htmlentities($category_row['name'],ENT_QUOTES, 'UTF-8'),
  203. $category_description,
  204. wpsc_category_url($category_row['id']),
  205. $category_row['id'],
  206. $category_classes,
  207. $category_image_html,
  208. $sub_categories,
  209. $category_count_html,
  210. $category_product_list);
  211. $output .= str_replace($tags_to_replace, $content_to_place ,$category_html);
  212. }
  213. return $output;
  214. }
  215. /**
  216. * wpsc category image function
  217. * if no parameters are passed, the category is not resized, otherwise it is resized to the specified dimensions
  218. * @param integer category id
  219. * @param array category query array
  220. * @return string - the category image URL, or the URL of the resized version
  221. */
  222. function wpsc_place_category_image($category_id, $query) {
  223. // show the full sized image for the product, if supplied with dimensions, will resize image to those.
  224. global $wpsc_query, $wpdb;
  225. $width = $query['image_size']['width'];
  226. $height = $query['image_size']['height'];
  227. //echo "<pre>".print_r($query, true)."</pre>";
  228. $image_url = "index.php?wpsc_request_image=true&category_id=".$category_id."&width=".$width."&height=".$height;
  229. return htmlspecialchars($image_url);
  230. }
  231. function wpsc_category_product_list($category_id) {
  232. global $wpdb;
  233. $output = '';
  234. $category_id = (int)$category_id;
  235. if (get_option('catsprods_display_type') == 1) {
  236. $product_data = $wpdb->get_results("SELECT `products`.`id`, `products`.`name`
  237. FROM `".WPSC_TABLE_ITEM_CATEGORY_ASSOC."` AS `cats`
  238. JOIN `".WPSC_TABLE_PRODUCT_LIST."` as `products`
  239. ON `cats`.`product_id` = `products`.`id`
  240. WHERE `cats`.`category_id` = '$category_id'
  241. AND `products`.`publish`='1'
  242. AND `products`.`active` = '1'
  243. ORDER BY `products`.`name` ASC
  244. ", ARRAY_A);
  245. if(count($product_data) > 0){
  246. $output .= "<ul class='category-product-list'>\n\r";
  247. foreach($product_data as $product_row) {
  248. $output .= "<li class='cat-item'><a class='productlink' href='".wpsc_product_url($product_row['id'],$category_id)."'>".$product_row['name']."</a></li>\n\r";
  249. } //end foreach
  250. $output .= "</ul>\n\r";
  251. } //end if productsIDs
  252. }
  253. return $output;
  254. }
  255. /// category template tags end here
  256. // pe.{
  257. // To stick this in sidebar, main page (calling products_page.php) must be called before sidebar.php in the loop (think)
  258. function display_subcategories($id) {
  259. global $wpdb;
  260. if(get_option('permalink_structure') != '') {
  261. $seperator ="?";
  262. } else {
  263. $seperator ="&amp;";
  264. }
  265. $subcategory_sql = "SELECT * FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `active`='1' AND `category_parent` = '".absint($id)."' ORDER BY `nice-name`";
  266. $subcategories = $wpdb->get_results($subcategory_sql,ARRAY_A);
  267. if($subcategories != null) {
  268. $output .= "<ul class='SubCategories'>";
  269. foreach($subcategories as $subcategory) {
  270. if (get_option('show_category_count') == 1) {
  271. //show product count for each category
  272. $count = $wpdb->get_var("SELECT COUNT(`p`.`id`) FROM `".WPSC_TABLE_ITEM_CATEGORY_ASSOC."` AS `a` JOIN `".WPSC_TABLE_PRODUCT_LIST."` AS `p` ON `a`.`product_id` = `p`.`id` WHERE `a`.`category_id` IN ('{$subcategory['id']}') AND `p`.`active` IN ('1') AND `p`.`publish` IN('1')");
  273. $addCount = " (".$count.")";
  274. } //end get_option
  275. $output .= "<li class='cat-item'><a class='categorylink' href='".wpsc_category_url($subcategory['id'])."'>".stripslashes($subcategory['name'])."</a>$addCount".display_subcategories($subcategory['id'])."</li>";
  276. }
  277. $output .= "</ul>";
  278. } else {
  279. return '';
  280. }
  281. return $output;
  282. }
  283. // Marked for removal
  284. function show_cats_brands($category_group = null , $display_method = null, $order_by = 'name', $image = null) {
  285. global $wpdb;
  286. if($category_group == null) {
  287. $category_group = $wpdb->get_var("SELECT `id` FROM `".WPSC_TABLE_CATEGORISATION_GROUPS."` WHERE `active` IN ('1') AND `default` IN ('1') LIMIT 1 ");
  288. } else {
  289. $category_group = (int)$category_group;
  290. }
  291. // Show cats & brands list if displaying on every page or if on a shop page (bit hacky but out of time).
  292. if (get_option('cat_brand_loc') != 3 && !function_exists("nzshpcrt_display_categories_groups") && ($display_method != 'sidebar')) {
  293. return;
  294. }
  295. if(get_option('permalink_structure') != '') {
  296. $seperator ="?";
  297. } else {
  298. $seperator ="&amp;";
  299. }
  300. $output = "<div class='PeSwitcher'>";
  301. switch(get_option('show_categorybrands')) {
  302. case 1:
  303. $output .= "<ul id='PeCatsBrandsBoth' class='category_brand_header'><li id='PeSwitcherFirst'><a href='' onclick='return prodgroupswitch(\"categories\");'>".__('Categories', 'wpsc')."</a> | <a href='' onclick='return prodgroupswitch(\"brands\");'>".__('Brands', 'wpsc')."</a></li></ul>";
  304. break;
  305. }
  306. $output .= "</div>";
  307. $output .= "<div class='PeCatsBrands'>";
  308. if((get_option('show_categorybrands') == 1 ) || (get_option('show_categorybrands') == 2)) {
  309. $output .= "<div class='PeCategories categorydisplay'>";
  310. $categories = $wpdb->get_results("SELECT * FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `group_id` IN ('$category_group') AND `active`='1' AND `category_parent` = '0' ORDER BY `".$wpdb->escape($order_by)."` ASC",ARRAY_A);
  311. if($categories != null) {
  312. $output .= "<ul class='PeCategories'>";
  313. foreach($categories as $option) {
  314. // Adrian - check option for category count
  315. if (get_option('show_category_count') == 1) {
  316. //show product count for each category
  317. $count = $wpdb->get_var("SELECT COUNT(`p`.`id`) FROM `".WPSC_TABLE_ITEM_CATEGORY_ASSOC."` AS `a` JOIN `".WPSC_TABLE_PRODUCT_LIST."` AS `p` ON `a`.`product_id` = `p`.`id` WHERE `a`.`category_id` IN ('{$option['id']}') AND `p`.`active` IN ('1')");
  318. $addCount = " (".$count.")";
  319. } //end get_option
  320. // No more mootools
  321. if (get_option('catsprods_display_type') == 1){
  322. $output .= "<li class='cat-item'><span class='category'><a class='productlink' href='".wpsc_category_url($option['id'])."'>".stripslashes($option['name'])."</a>".$addCount."</span>";
  323. }else{
  324. // Adrian - otherwise create normal category text with or without product count
  325. if (!$image) {
  326. $output .= "<li class='cat-item'><span class='category'><a class='productlink' href='".wpsc_category_url($option['id'])."'>".stripslashes($option['name'])."</a>".$addCount."</span>";
  327. } else {
  328. $output .= "<li class='cat-item'><img src='" . WPSC_CATEGORY_URL . $option['image']."'><br><span class='category'><a class='productlink' href='".wpsc_category_url($option['id'])."'>".stripslashes($option['name'])."</a>".$addCount."</span>";
  329. }
  330. }//end get_option
  331. $subcategory_sql = "SELECT * FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `group_id` IN ('$category_group') AND `active`='1' AND `category_parent` = '".$option['id']."' ORDER BY `id`";
  332. $subcategories = $wpdb->get_results($subcategory_sql,ARRAY_A);
  333. if($subcategories != null) {
  334. $output .= display_subcategories($option['id']);
  335. } else {
  336. // Adrian - check if the user wants categories only or sliding categories
  337. if (get_option('permalink_structure')!=''){
  338. $uri = $_SERVER['REQUEST_URI'];
  339. $category = explode('/',$uri);
  340. $count = count($category);
  341. $category_nice_name = $category[$count-2];
  342. $category_nice_name2 = $wpdb->get_var("SELECT `nice-name` FROM ".WPSC_TABLE_PRODUCT_CATEGORIES." WHERE id='{$option['id']}'");
  343. if ($category_nice_name == $category_nice_name2) {
  344. $list_product=true;
  345. } else {
  346. $list_product=false;
  347. }
  348. }
  349. if ((get_option('catsprods_display_type') == 1) && (($option['id'] == $_GET['category']) || $list_product) ){
  350. // Adrian - display all products for that category
  351. $product_sql = "SELECT product_id FROM `".WPSC_TABLE_ITEM_CATEGORY_ASSOC."` WHERE `category_id` = '".$option['id']."'";
  352. $productIDs = $wpdb->get_results($product_sql,ARRAY_A);
  353. if($productIDs != null){
  354. $output .= "<ul class='category-product-list'>";
  355. foreach($productIDs as $productID) {
  356. $ID = $productID['product_id'];
  357. $productName_sql = "SELECT * FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `id` = '".$ID."'";
  358. $productName = $wpdb->get_results($productName_sql,ARRAY_A);
  359. if ($productName[0]['active'])
  360. $output .= "<li class='cat-item'><a class='productlink' href='".wpsc_product_url($ID,$option['id'])."'>".$productName[0]['name']."</a></li>";
  361. }//end foreach
  362. $output .= "</ul>";
  363. }//end if productsIDs
  364. }//end if get_option
  365. }//end else
  366. $output .= "</li>";
  367. }
  368. $output .= "</ul>";
  369. }
  370. $output .= "</div>";
  371. }
  372. if((get_option('show_categorybrands') == 1 ) || (get_option('show_categorybrands') == 3))
  373. {
  374. if(get_option('show_categorybrands') == 1) {
  375. $output .= "<ul class='PeBrands branddisplay' style='display: none;'>";
  376. } else {
  377. $output .= "<ul class='PeBrands branddisplay'>";
  378. }
  379. //$output ='';
  380. $brands = $wpdb->get_results("SELECT * FROM `".$wpdb->prefix."product_brands` WHERE `active`='1' ORDER BY `order` ASC",ARRAY_A);
  381. if($brands != null) {
  382. foreach($brands as $option) {
  383. $output .= "<li><a class='categorylink' href='".get_option('product_list_url').$seperator."brand=".$option['id']."'>".stripslashes($option['name'])."</a></li>";
  384. }
  385. }
  386. //$output .= $output;
  387. $output .= "</ul>";
  388. }
  389. $output .= "</div>";
  390. echo $output;
  391. }
  392. /**
  393. * wpsc_category_url function, makes permalink to the category or
  394. * @param integer category ID, can be 0
  395. * @param boolean permalink compatibility, adds a prefix to prevent permalink namespace conflicts
  396. */
  397. function wpsc_category_url($category_id, $permalink_compatibility = false) {
  398. global $wpdb, $wp_rewrite, $wpsc_category_url_cache;
  399. $home_page_id = get_option('page_on_front');
  400. if(((($wp_rewrite->rules != null) && ($wp_rewrite != null)) || (get_option('rewrite_rules') != null))) {
  401. if(!isset($wpsc_category_url_cache[$category_id]) || ($wpsc_category_url_cache[$category_id] == '') ) {
  402. if($category_id > 0) {
  403. $category_data = $wpdb->get_row("SELECT `nice-name`,`category_parent` FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `id` IN ('".(int)$category_id."') AND `active` IN('1') LIMIT 1", ARRAY_A);
  404. if($category_data['nice-name'] != '') {
  405. $category_name[] = $category_data['nice-name'];
  406. }
  407. if($category_data['category_parent'] > 0) {
  408. $num = 0;
  409. while($category_data['category_parent'] > 0) {
  410. $category_data = $wpdb->get_row("SELECT `nice-name`,`category_parent` FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `id` IN ('".(int)$category_data['category_parent']."') AND `active` IN('1') LIMIT 1", ARRAY_A);
  411. $category_name[] = $category_data['nice-name'];
  412. if($num > 10) { break; }
  413. $num++;
  414. }
  415. }
  416. } else {
  417. $products_page_details = $wpdb->get_row("SELECT `ID`, `post_name` FROM `".$wpdb->posts."` WHERE `post_content` LIKE '%[productspage]%' AND `post_type` NOT IN('revision') LIMIT 1", ARRAY_A);
  418. $products_page_name = '';
  419. if($home_page_id == $products_page_details['ID']) {
  420. $products_page_name = $products_page_details['post_name'];
  421. if($category_id < 1) {
  422. $category_name[] = $products_page_name;
  423. }
  424. }
  425. }
  426. $category_name_parts = array_reverse((array)$category_name);
  427. $category_names = implode($category_name_parts,"/");
  428. $wpsc_category_url_cache[$category_id] = $category_names;
  429. } else {
  430. $category_names = $wpsc_category_url_cache[$category_id];
  431. }
  432. if(!empty($category_names)) {
  433. if(substr(get_option('product_list_url'), -1, 1) == '/') {
  434. $category_url = get_option('product_list_url').$category_names."/";
  435. } else {
  436. $category_url = get_option('product_list_url')."/".$category_names."/";
  437. }
  438. } else {
  439. $category_url = get_option('product_list_url');
  440. }
  441. // if there is no trailing slash, add one
  442. if(substr($category_url, -1, 1) != '/') {
  443. $category_url .= "/";
  444. }
  445. } else {
  446. if($category_id > 0) {
  447. $category_url = add_query_arg('category', $category_id, get_option('product_list_url'));
  448. } else {
  449. $category_url = get_option('product_list_url');
  450. }
  451. }
  452. return htmlentities($category_url, ENT_QUOTES);
  453. }
  454. function wpsc_is_in_category() {
  455. global $wpdb, $wp_query;
  456. $category_id = null;
  457. if($wp_query->query_vars['category_id'] > 0) {
  458. $category_id = absint($wp_query->query_vars['category_id']);
  459. } else if(isset($_GET['category']) && ($_GET['category'] > 0)) {
  460. $category_id = absint($_GET['category']);
  461. }
  462. if($category_id > 0) {
  463. return true;
  464. }
  465. return false;
  466. }
  467. function wpsc_category_image($category_id = null) {
  468. global $wpdb, $wp_query;
  469. if($category_id < 1) {
  470. if($wp_query->query_vars['category_id'] > 0) {
  471. $category_id = $wp_query->query_vars['category_id'];
  472. } else if(isset($_GET['category']) && ($_GET['category'] > 0)) {
  473. $category_id = $_GET['category'];
  474. }
  475. }
  476. $category_id = absint($category_id);
  477. $category_image = $wpdb->get_var("SELECT `image` FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `id` IN ('{$category_id}') AND `active` IN('1') LIMIT 1");
  478. $category_path = WPSC_CATEGORY_DIR.basename($category_image);
  479. $category_url = WPSC_CATEGORY_URL.basename($category_image);
  480. if(file_exists($category_path) && is_file($category_path)) {
  481. return $category_url;
  482. } else {
  483. return false;
  484. }
  485. }
  486. function wpsc_category_description($category_id = null) {
  487. global $wpdb, $wp_query;
  488. if($category_id < 1) {
  489. if($wp_query->query_vars['category_id'] > 0) {
  490. $category_id = $wp_query->query_vars['category_id'];
  491. } else if(isset($_GET['category']) && ($_GET['category'] > 0)) {
  492. $category_id = $_GET['category'];
  493. }
  494. }
  495. $category_id = absint($category_id);
  496. $category_description = $wpdb->get_var("SELECT `description` FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `id` IN ('{$category_id}') AND `active` IN('1') LIMIT 1");
  497. return $category_description;
  498. }
  499. function wpsc_category_name($category_id = null) {
  500. global $wpdb, $wp_query;
  501. if($category_id < 1) {
  502. if($wp_query->query_vars['category_id'] > 0) {
  503. $category_id = $wp_query->query_vars['category_id'];
  504. } else if(isset($_GET['category']) && ($_GET['category'] > 0)) {
  505. $category_id = $_GET['category'];
  506. }
  507. }
  508. $category_id = absint($category_id);
  509. $category_name = $wpdb->get_var("SELECT `name` FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `id` IN ('{$category_id}') AND `active` IN('1') LIMIT 1");
  510. return $category_name;
  511. }
  512. /**
  513. * WPSC Category Group
  514. * @modified: 2009-09-28 by Ben
  515. * @description: Get a category's group id.
  516. * @param: $category_id = Category ID
  517. * @return: (Int) Group ID
  518. */
  519. function wpsc_category_group( $category_id = null ) {
  520. global $wpdb, $wp_query;
  521. if ( $category_id < 1 ) {
  522. if ( $wp_query->query_vars['category_id'] > 0 ) {
  523. $category_id = $wp_query->query_vars['category_id'];
  524. } else if ( isset($_GET['category']) && ($_GET['category'] > 0) ) {
  525. $category_id = $_GET['category'];
  526. }
  527. }
  528. $category_id = absint($category_id);
  529. // Is it better for this DB query be loaded in the main query or cached?
  530. $group_id = $wpdb->get_var("SELECT `group_id` FROM `" . WPSC_TABLE_PRODUCT_CATEGORIES . "` WHERE `id` IN ('{$category_id}') AND `active` IN('1') LIMIT 1");
  531. return absint($group_id);
  532. }
  533. // This function displays the category groups, it is used by the above function
  534. function nzshpcrt_display_categories_groups() {
  535. global $wpdb;
  536. if(get_option('permalink_structure') != '') {
  537. $seperator ="?";
  538. } else {
  539. $seperator ="&amp;";
  540. }
  541. ob_start();
  542. $category_settings = array('category_group'=> 1, 'show_thumbnails'=> get_option('show_category_thumbnails'));
  543. include(wpsc_get_theme_file_path("category_widget.php"));
  544. $output = ob_get_contents();
  545. ob_end_clean();
  546. return $output;
  547. }
  548. /** wpsc list subcategories function
  549. used to get an array of all the subcategories of a category.
  550. */
  551. function wpsc_list_subcategories($category_id = null) {
  552. global $wpdb,$category_data;
  553. if(is_numeric($category_id)) {
  554. $category_list = $wpdb->get_col("SELECT `id` FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `category_parent` = '".$category_id."'");
  555. }
  556. if($category_list != null) {
  557. foreach($category_list as $subcategory_id) {
  558. $category_list = array_merge((array)$category_list, (array)wpsc_list_subcategories($subcategory_id));
  559. }
  560. }
  561. return $category_list;
  562. }
  563. ?>