PageRenderTime 59ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/blog/wp-content/plugins/shopp/core/model/Catalog.php

https://github.com/kennethreitz-archive/wordpress-skeleton
PHP | 612 lines | 522 code | 73 blank | 17 comment | 255 complexity | 7d64dca064dc88084e6fb40cee45d39e MD5 | raw file
  1. <?php
  2. /**
  3. * Catalog class
  4. *
  5. *
  6. * @author Jonathan Davis
  7. * @version 1.0
  8. * @copyright Ingenesis Limited, 9 April, 2008
  9. * @package shopp
  10. **/
  11. require_once("Category.php");
  12. require_once("Tag.php");
  13. class Catalog extends DatabaseObject {
  14. static $table = "catalog";
  15. var $smarts = array("FeaturedProducts","BestsellerProducts","NewProducts","OnSaleProducts");
  16. var $categories = array();
  17. var $outofstock = false;
  18. function Catalog ($type="catalog") {
  19. global $Shopp;
  20. $this->init(self::$table);
  21. $this->type = $type;
  22. $this->outofstock = ($Shopp->Settings->get('outofstock_catalog') == "on");
  23. }
  24. function load_categories ($filtering=false,$showsmart=false,$results=false) {
  25. $db = DB::get();
  26. if (empty($filtering['columns'])) $filtering['columns'] = "cat.id,cat.parent,cat.name,cat.description,cat.uri,cat.slug,count(DISTINCT pd.id) AS total,IF(SUM(IF(pt.inventory='off',1,0) OR pt.inventory IS NULL)>0,'off','on') AS inventory, SUM(pt.stock) AS stock";
  27. if (!empty($filtering['limit'])) $filtering['limit'] = "LIMIT ".$filtering['limit'];
  28. else $filtering['limit'] = "";
  29. // if (!$this->outofstock) $filtering['where'] .= (empty($filtering['where'])?"":" AND ")."(pt.inventory='off' OR (pt.inventory='on' AND pt.stock > 0))";
  30. if (empty($filtering['where'])) $filtering['where'] = "true";
  31. if (empty($filtering['orderby'])) $filtering['orderby'] = "name";
  32. switch(strtolower($filtering['orderby'])) {
  33. case "id": $orderby = "cat.id"; break;
  34. case "slug": $orderby = "cat.slug"; break;
  35. case "count": $orderby = "total"; break;
  36. default: $orderby = "cat.name";
  37. }
  38. if (empty($filtering['order'])) $filtering['order'] = "ASC";
  39. switch(strtoupper($filtering['order'])) {
  40. case "DESC": $order = "DESC"; break;
  41. default: $order = "ASC";
  42. }
  43. $category_table = DatabaseObject::tablename(Category::$table);
  44. $product_table = DatabaseObject::tablename(Product::$table);
  45. $price_table = DatabaseObject::tablename(Price::$table);
  46. $query = "SELECT {$filtering['columns']} FROM $category_table AS cat LEFT JOIN $this->_table AS sc ON sc.category=cat.id LEFT JOIN $product_table AS pd ON sc.product=pd.id LEFT JOIN $price_table AS pt ON pt.product=pd.id AND pt.type != 'N/A' WHERE {$filtering['where']} GROUP BY cat.id ORDER BY cat.parent DESC,$orderby $order {$filtering['limit']}";
  47. $categories = $db->query($query,AS_ARRAY);
  48. if (count($categories) > 1) $categories = sort_tree($categories);
  49. if ($results) return $categories;
  50. foreach ($categories as $category) {
  51. $category->outofstock = false;
  52. if (isset($category->inventory)) {
  53. if ($category->inventory == "on" && $category->stock == 0)
  54. $category->outofstock = true;
  55. if (!$this->outofstock && $category->outofstock) continue;
  56. }
  57. $this->categories[$category->id] = new Category();
  58. $this->categories[$category->id]->populate($category);
  59. if (isset($category->depth))
  60. $this->categories[$category->id]->depth = $category->depth;
  61. else $this->categories[$category->id]->depth = 0;
  62. if (isset($category->total))
  63. $this->categories[$category->id]->total = $category->total;
  64. else $this->categories[$category->id]->total = 0;
  65. if (isset($category->stock))
  66. $this->categories[$category->id]->stock = $category->stock;
  67. else $this->categories[$category->id]->stock = 0;
  68. if (isset($category->outofstock))
  69. $this->categories[$category->id]->outofstock = $category->outofstock;
  70. $this->categories[$category->id]->children = false;
  71. if ($category->total > 0 && isset($this->categories[$category->parent]))
  72. $this->categories[$category->parent]->children = true;
  73. }
  74. if ($showsmart == "before" || $showsmart == "after")
  75. $this->smart_categories($showsmart);
  76. return true;
  77. }
  78. function smart_categories ($method) {
  79. foreach ($this->smarts as $SmartCategory) {
  80. $category = new $SmartCategory(array("noload" => true));
  81. switch($method) {
  82. case "before": array_unshift($this->categories,$category); break;
  83. default: array_push($this->categories,$category);
  84. }
  85. }
  86. }
  87. function load_tags ($limits=false) {
  88. $db = DB::get();
  89. if ($limits) $limit = " LIMIT {$limits[0]},{$limits[1]}";
  90. else $limit = "";
  91. $tagtable = DatabaseObject::tablename(Tag::$table);
  92. $query = "SELECT t.*,count(sc.product) AS products FROM $this->_table AS sc LEFT JOIN $tagtable AS t ON sc.tag=t.id WHERE sc.tag != 0 GROUP BY t.id ORDER BY t.name ASC$limit";
  93. $this->tags = $db->query($query,AS_ARRAY);
  94. return true;
  95. }
  96. function load_category ($category,$options=array()) {
  97. switch ($category) {
  98. case SearchResults::$_slug: return new SearchResults($options); break;
  99. case TagProducts::$_slug: return new TagProducts($options); break;
  100. case BestsellerProducts::$_slug: return new BestsellerProducts(); break;
  101. case CatalogProducts::$_slug: return new CatalogProducts(); break;
  102. case NewProducts::$_slug: return new NewProducts(); break;
  103. case FeaturedProducts::$_slug: return new FeaturedProducts(); break;
  104. case OnSaleProducts::$_slug: return new OnSaleProducts(); break;
  105. case RandomProducts::$_slug: return new RandomProducts(); break;
  106. default:
  107. $key = "id";
  108. if (!preg_match("/^\d+$/",$category)) $key = "uri";
  109. return new Category($category,$key);
  110. }
  111. }
  112. function tag ($property,$options=array()) {
  113. global $Shopp;
  114. $pages = $Shopp->Settings->get('pages');
  115. if (SHOPP_PERMALINKS) $path = $Shopp->shopuri;
  116. else $page = add_query_arg('page_id',$pages['catalog']['id'],$Shopp->shopuri);
  117. switch ($property) {
  118. case "url": return $Shopp->link('catalog'); break;
  119. case "display":
  120. case "type": return $this->type; break;
  121. case "is-landing":
  122. case "is-catalog": return (is_shopp_page('catalog') && $this->type == "catalog"); break;
  123. case "is-category": return (is_shopp_page('catalog') && $this->type == "category"); break;
  124. case "is-product": return (is_shopp_page('catalog') && $this->type == "product"); break;
  125. case "is-cart": return (is_shopp_page('cart')); break;
  126. case "is-checkout": return (is_shopp_page('checkout')); break;
  127. case "is-account": return (is_shopp_page('account')); break;
  128. case "tagcloud":
  129. if (!empty($options['levels'])) $levels = $options['levels'];
  130. else $levels = 7;
  131. if (empty($this->tags)) $this->load_tags();
  132. $min = -1; $max = -1;
  133. foreach ($this->tags as $tag) {
  134. if ($min == -1 || $tag->products < $min) $min = $tag->products;
  135. if ($max == -1 || $tag->products > $max) $max = $tag->products;
  136. }
  137. if ($max == 0) $max = 1;
  138. $string = '<ul class="shopp tagcloud">';
  139. foreach ($this->tags as $tag) {
  140. $level = floor((1-$tag->products/$max)*$levels)+1;
  141. if (SHOPP_PERMALINKS) $link = $path.'tag/'.urlencode($tag->name).'/';
  142. else $link = add_query_arg('shopp_tag',urlencode($tag->name),$page);
  143. $string .= '<li class="level-'.$level.'"><a href="'.$link.'" rel="tag">'.$tag->name.'</a></li> ';
  144. }
  145. $string .= '</ul>';
  146. return $string;
  147. break;
  148. case "has-categories":
  149. if (empty($this->categories)) $this->load_categories(array('where'=>'true'),$options['showsmart']);
  150. if (count($this->categories) > 0) return true; else return false; break;
  151. case "categories":
  152. if (!$this->categoryloop) {
  153. reset($this->categories);
  154. $Shopp->Category = current($this->categories);
  155. $this->categoryloop = true;
  156. } else {
  157. $Shopp->Category = next($this->categories);
  158. }
  159. if (current($this->categories)) {
  160. $Shopp->Category = current($this->categories);
  161. return true;
  162. } else {
  163. $this->categoryloop = false;
  164. return false;
  165. }
  166. break;
  167. case "category-list":
  168. $defaults = array(
  169. 'title' => '',
  170. 'before' => '',
  171. 'after' => '',
  172. 'class' => '',
  173. 'exclude' => '',
  174. 'orderby' => 'name',
  175. 'order' => 'ASC',
  176. 'depth' => 0,
  177. 'childof' => 0,
  178. 'parent' => false,
  179. 'showall' => false,
  180. 'linkall' => false,
  181. 'linkcount' => false,
  182. 'dropdown' => false,
  183. 'hierarchy' => false,
  184. 'products' => false,
  185. 'wraplist' => true,
  186. 'showsmart' => false
  187. );
  188. $options = array_merge($defaults,$options);
  189. extract($options, EXTR_SKIP);
  190. $this->load_categories(array("where"=>"(pd.published='on' OR pd.id IS NULL)","orderby"=>$orderby,"order"=>$order),$showsmart);
  191. $string = "";
  192. $depthlimit = $depth;
  193. $depth = 0;
  194. $exclude = explode(",",$exclude);
  195. $classes = ' class="shopp_categories'.(empty($class)?'':' '.$class).'"';
  196. $wraplist = value_is_true($wraplist);
  197. if (value_is_true($dropdown)) {
  198. if (!isset($default)) $default = __('Select category&hellip;','Shopp');
  199. $string .= $title;
  200. $string .= '<form><select name="shopp_cats" id="shopp-categories-menu"'.$classes.'>';
  201. $string .= '<option value="">'.$default.'</option>';
  202. foreach ($this->categories as &$category) {
  203. if (!empty($category->id) && in_array($category->id,$exclude)) continue; // Skip excluded categories
  204. if ($category->total == 0 && !isset($category->smart)) continue; // Only show categories with products
  205. if ($depthlimit && $category->depth >= $depthlimit) continue;
  206. if (value_is_true($hierarchy) && $category->depth > $depth) {
  207. $parent = &$previous;
  208. if (!isset($parent->path)) $parent->path = '/'.$parent->slug;
  209. }
  210. if (value_is_true($hierarchy))
  211. $padding = str_repeat("&nbsp;",$category->depth*3);
  212. if (SHOPP_PERMALINKS) $link = $Shopp->shopuri.'category/'.$category->uri;
  213. else $link = add_query_arg('shopp_category',$category->id,$Shopp->shopuri);
  214. $total = '';
  215. if (value_is_true($products) && $category->total > 0) $total = ' ('.$category->total.')';
  216. $string .= '<option value="'.$link.'">'.$padding.$category->name.$total.'</option>';
  217. $previous = &$category;
  218. $depth = $category->depth;
  219. }
  220. $string .= '</select></form>';
  221. $string .= '<script type="text/javascript">';
  222. $string .= 'var menu = document.getElementById(\'shopp-categories-menu\');';
  223. $string .= 'if (menu) {';
  224. $string .= ' menu.onchange = function () {';
  225. $string .= ' document.location.href = this.options[this.selectedIndex].value;';
  226. $string .= ' }';
  227. $string .= '}';
  228. $string .= '</script>';
  229. } else {
  230. $string .= $title;
  231. if ($wraplist) $string .= '<ul'.$classes.'>';
  232. foreach ($this->categories as &$category) {
  233. if (!isset($category->total)) $category->total = 0;
  234. if (!isset($category->depth)) $category->depth = 0;
  235. if (!empty($category->id) && in_array($category->id,$exclude)) continue; // Skip excluded categories
  236. if ($depthlimit && $category->depth >= $depthlimit) continue;
  237. if (value_is_true($hierarchy) && $category->depth > $depth) {
  238. $parent = &$previous;
  239. if (!isset($parent->path)) $parent->path = $parent->slug;
  240. $string = substr($string,0,-5); // Remove the previous </li>
  241. $active = '';
  242. if (isset($Shopp->Category) && !empty($parent->slug)
  243. && preg_match('/(^|\/)'.$parent->path.'(\/|$)/',$Shopp->Category->uri)) {
  244. $active = ' active';
  245. }
  246. $subcategories = '<ul class="children'.$active.'">';
  247. $string .= $subcategories;
  248. }
  249. if (value_is_true($hierarchy) && $category->depth < $depth) {
  250. for ($i = $depth; $i > $category->depth; $i--) {
  251. if (substr($string,strlen($subcategories)*-1) == $subcategories) {
  252. // If the child menu is empty, remove the <ul> to avoid breaking standards
  253. $string = substr($string,0,strlen($subcategories)*-1).'</li>';
  254. } else $string .= '</ul></li>';
  255. }
  256. }
  257. if (SHOPP_PERMALINKS) $link = $Shopp->shopuri.'category/'.$category->uri;
  258. else $link = add_query_arg('shopp_category',(!empty($category->id)?$category->id:$category->uri),$Shopp->shopuri);
  259. $total = '';
  260. if (value_is_true($products) && $category->total > 0) $total = ' <span>('.$category->total.')</span>';
  261. $current = '';
  262. if (isset($Shopp->Category) && $Shopp->Category->slug == $category->slug)
  263. $current = ' class="current"';
  264. $listing = '';
  265. if ($category->total > 0 || isset($category->smart) || $linkall)
  266. $listing = '<a href="'.$link.'"'.$current.'>'.$category->name.($linkcount?$total:'').'</a>'.(!$linkcount?$total:'');
  267. else $listing = $category->name;
  268. if (value_is_true($showall) ||
  269. $category->total > 0 ||
  270. isset($category->smart) ||
  271. $category->children)
  272. $string .= '<li'.$current.'>'.$listing.'</li>';
  273. $previous = &$category;
  274. $depth = $category->depth;
  275. }
  276. if (value_is_true($hierarchy) && $depth > 0)
  277. for ($i = $depth; $i > 0; $i--) {
  278. if (substr($string,strlen($subcategories)*-1) == $subcategories) {
  279. // If the child menu is empty, remove the <ul> to avoid breaking standards
  280. $string = substr($string,0,strlen($subcategories)*-1).'</li>';
  281. } else $string .= '</ul></li>';
  282. }
  283. if ($wraplist) $string .= '</ul>';
  284. }
  285. return $string;
  286. break;
  287. case "views":
  288. if (isset($Shopp->Category->controls)) return false;
  289. $string = "";
  290. $string .= '<ul class="views">';
  291. if (isset($options['label'])) $string .= '<li>'.$options['label'].'</li>';
  292. $string .= '<li><button type="button" class="grid"></button></li>';
  293. $string .= '<li><button type="button" class="list"></button></li>';
  294. $string .= '</ul>';
  295. return $string;
  296. case "orderby-list":
  297. if (isset($Shopp->Category->controls)) return false;
  298. if (isset($Shopp->Category->smart)) return false;
  299. $menuoptions = Category::sortoptions();
  300. $title = "";
  301. $string = "";
  302. $default = $Shopp->Settings->get('default_product_order');
  303. if (empty($default)) $default = "title";
  304. if (isset($options['default'])) $default = $options['default'];
  305. if (isset($options['title'])) $title = $options['title'];
  306. if (value_is_true($options['dropdown'])) {
  307. if (isset($Shopp->Cart->data->Category['orderby']))
  308. $default = $Shopp->Cart->data->Category['orderby'];
  309. $string .= $title;
  310. $string .= '<form action="'.esc_url($_SERVER['REQUEST_URI']).'" method="get" id="shopp-'.$Shopp->Category->slug.'-orderby-menu">';
  311. if (!SHOPP_PERMALINKS) {
  312. foreach ($_GET as $key => $value)
  313. if ($key != 'shopp_orderby') $string .= '<input type="hidden" name="'.$key.'" value="'.$value.'" />';
  314. }
  315. $string .= '<select name="shopp_orderby" class="shopp-orderby-menu">';
  316. $string .= menuoptions($menuoptions,$default,true);
  317. $string .= '</select>';
  318. $string .= '</form>';
  319. $string .= '<script type="text/javascript">';
  320. $string .= "jQuery('#shopp-".$Shopp->Category->slug."-orderby-menu select.shopp-orderby-menu').change(function () { this.form.submit(); });";
  321. $string .= '</script>';
  322. } else {
  323. if (strpos($_SERVER['REQUEST_URI'],"?") !== false)
  324. list($link,$query) = explode("\?",$_SERVER['REQUEST_URI']);
  325. $query = $_GET;
  326. unset($query['shopp_orderby']);
  327. $query = http_build_query($query);
  328. if (!empty($query)) $query .= '&';
  329. foreach($menuoptions as $value => $option) {
  330. $label = $option;
  331. $href = esc_url($link.'?'.$query.'shopp_orderby='.$value);
  332. $string .= '<li><a href="'.$href.'">'.$label.'</a></li>';
  333. }
  334. }
  335. return $string;
  336. break;
  337. case "breadcrumb":
  338. if (isset($Shopp->Category->controls)) return false;
  339. if (empty($this->categories)) $this->load_categories();
  340. $separator = "&nbsp;&raquo; ";
  341. if (isset($options['separator'])) $separator = $options['separator'];
  342. $category = false;
  343. if (isset($Shopp->Cart->data->breadcrumb))
  344. $category = $Shopp->Cart->data->breadcrumb;
  345. $trail = false;
  346. $search = array();
  347. if (isset($Shopp->Cart->data->Search)) $search = array('search'=>$Shopp->Cart->data->Search);
  348. $path = explode("/",$category);
  349. if ($path[0] == "tag") {
  350. $category = "tag";
  351. $search = array('tag'=>urldecode($path[1]));
  352. }
  353. $Category = Catalog::load_category($category,$search);
  354. if (!empty($Category->uri)) {
  355. $type = "category";
  356. if (isset($Category->tag)) $type = "tag";
  357. if (SHOPP_PERMALINKS)
  358. $link = esc_url(add_query_arg($_GET,$Shopp->shopuri.$type.'/'.$Category->uri));
  359. else {
  360. if (isset($Category->smart))
  361. $link = esc_url(add_query_arg(array_merge($_GET,
  362. array('shopp_category'=>$Category->slug,'shopp_pid'=>null)),
  363. $Shopp->shopuri));
  364. else
  365. $link = esc_url(add_query_arg(array_merge($_GET,
  366. array('shopp_category'=>$Category->id,'shopp_pid'=>null)),
  367. $Shopp->shopuri));
  368. }
  369. $filters = false;
  370. if (!empty($Shopp->Cart->data->Category[$Category->slug]))
  371. $filters = ' (<a href="?shopp_catfilters=cancel">'.__('Clear Filters','Shopp').'</a>)';
  372. if (!empty($Shopp->Product))
  373. $trail .= '<li><a href="'.$link.'">'.$Category->name.(!$trail?'':$separator).'</a></li>';
  374. elseif (!empty($Category->name))
  375. $trail .= '<li>'.$Category->name.$filters.(!$trail?'':$separator).'</li>';
  376. // Build category names path by going from the target category up the parent chain
  377. $parentkey = (!empty($Category->id))?$this->categories[$Category->id]->parent:0;
  378. while ($parentkey != 0) {
  379. $tree_category = $this->categories[$parentkey];
  380. if (SHOPP_PERMALINKS) $link = $Shopp->shopuri.'category/'.$tree_category->uri;
  381. else $link = esc_url(add_query_arg(array_merge($_GET,
  382. array('shopp_category'=>$tree_category->id,'shopp_pid'=>null)),
  383. $Shopp->shopuri));
  384. $trail = '<li><a href="'.$link.'">'.$tree_category->name.'</a>'.
  385. (empty($trail)?'':$separator).'</li>'.$trail;
  386. $parentkey = $tree_category->parent;
  387. }
  388. }
  389. $trail = '<li><a href="'.$Shopp->link('catalog').'">'.$pages['catalog']['title'].'</a>'.(empty($trail)?'':$separator).'</li>'.$trail;
  390. return '<ul class="breadcrumb">'.$trail.'</ul>';
  391. break;
  392. case "search":
  393. global $wp;
  394. $type = "hidden";
  395. if (isset($options['type'])) $type = $options['type'];
  396. if ($type == "radio") {
  397. $option = "shopp";
  398. if (isset($options['option'])) $option = $options['option'];
  399. $default = false;
  400. if (isset($options['default'])) $default = value_is_true($options['default']);
  401. $selected = '';
  402. if ($default) $selected = ' checked="checked"';
  403. if (!empty($wp->query_vars['st'])) {
  404. $selected = '';
  405. if ($wp->query_vars['st'] == $option) $selected = ' checked="checked"';
  406. }
  407. if ($option == "blog") return '<input type="radio" name="st" value="blog"'.$selected.' />';
  408. else return '<input type="radio" name="st" value="shopp"'.$selected.' />';
  409. } elseif ($type == "menu") {
  410. if (empty($options['store'])) $options['store'] = __('Search the store','Shopp');
  411. if (empty($options['blog'])) $options['blog'] = __('Search the blog','Shopp');
  412. if (isset($wp->query_vars['st'])) $selected = $wp->query_vars['st'];
  413. $menu = '<select name="st">';
  414. if (isset($options['default']) && $options['default'] == "blog") {
  415. $menu .= '<option value="blog"'.($selected == "blog"?' selected="selected"':'').'>'.$options['blog'].'</option>';
  416. $menu .= '<option value="shopp"'.($selected == "shopp"?' selected="selected"':'').'>'.$options['store'].'</option>';
  417. } else {
  418. $menu .= '<option value="shopp"'.($selected == "shopp"?' selected="selected"':'').'>'.$options['store'].'</option>';
  419. $menu .= '<option value="blog"'.($selected == "blog"?' selected="selected"':'').'>'.$options['blog'].'</option>';
  420. }
  421. $menu .= '</select>';
  422. return $menu;
  423. } else return '<input type="hidden" name="st" value="shopp" />';
  424. break;
  425. case "catalog-products":
  426. if ($property == "catalog-products") $Shopp->Category = new CatalogProducts($options);
  427. case "new-products":
  428. if ($property == "new-products") $Shopp->Category = new NewProducts($options);
  429. case "featured-products":
  430. if ($property == "featured-products") $Shopp->Category = new FeaturedProducts($options);
  431. case "onsale-products":
  432. if ($property == "onsale-products") $Shopp->Category = new OnSaleProducts($options);
  433. case "bestseller-products":
  434. if ($property == "bestseller-products") $Shopp->Category = new BestsellerProducts($options);
  435. case "random-products":
  436. if ($property == "random-products") $Shopp->Category = new RandomProducts($options);
  437. case "tag-products":
  438. if ($property == "tag-products") $Shopp->Category = new TagProducts($options);
  439. case "related-products":
  440. if ($property == "related-products") $Shopp->Category = new RelatedProducts($options);
  441. case "search-products":
  442. if ($property == "search-products") $Shopp->Category = new SearchResults($options);
  443. case "category":
  444. if ($property == "category") {
  445. if (isset($options['name'])) $Shopp->Category = new Category($options['name'],'name');
  446. else if (isset($options['slug'])) $Shopp->Category = new Category($options['slug'],'slug');
  447. else if (isset($options['id'])) $Shopp->Category = new Category($options['id']);
  448. }
  449. if (isset($options['reset'])) return ($Shopp->Category = false);
  450. if (isset($options['title'])) $Shopp->Category->name = $options['title'];
  451. if (isset($options['show'])) $Shopp->Category->loading['limit'] = $options['show'];
  452. if (isset($options['pagination'])) $Shopp->Category->loading['pagination'] = $options['pagination'];
  453. if (isset($options['order'])) $Shopp->Category->loading['order'] = $options['order'];
  454. if (isset($options['load'])) return true;
  455. if (isset($options['controls']) && !value_is_true($options['controls']))
  456. $Shopp->Category->controls = false;
  457. if (isset($options['view'])) {
  458. if ($options['view'] == "grid") $Shopp->Category->view = "grid";
  459. else $Shopp->Category->view = "list";
  460. }
  461. ob_start();
  462. if (isset($Shopp->Category->smart) &&
  463. file_exists(SHOPP_TEMPLATES."/category-{$Shopp->Category->slug}.php"))
  464. include(SHOPP_TEMPLATES."/category-{$Shopp->Category->slug}.php");
  465. elseif (isset($Shopp->Category->id) &&
  466. file_exists(SHOPP_TEMPLATES."/category-{$Shopp->Category->id}.php"))
  467. include(SHOPP_TEMPLATES."/category-{$Shopp->Category->id}.php");
  468. else include(SHOPP_TEMPLATES."/category.php");
  469. $content = ob_get_contents();
  470. ob_end_clean();
  471. $Shopp->Category = false; // Reset the current category
  472. return $content;
  473. break;
  474. case "product":
  475. if (isset($options['name'])) $Shopp->Product = new Product($options['name'],'name');
  476. else if (isset($options['slug'])) $Shopp->Product = new Product($options['slug'],'slug');
  477. else if (isset($options['id'])) $Shopp->Product = new Product($options['id']);
  478. if (isset($options['load'])) return true;
  479. ob_start();
  480. if (file_exists(SHOPP_TEMPLATES."/product-{$Shopp->Product->id}.php"))
  481. include(SHOPP_TEMPLATES."/product-{$Shopp->Product->id}.php");
  482. else include(SHOPP_TEMPLATES."/product.php");
  483. $content = ob_get_contents();
  484. ob_end_clean();
  485. return $content;
  486. break;
  487. case "sideproduct":
  488. $content = false;
  489. $source = $options['source'];
  490. if ($source == "product" && isset($options['product'])) {
  491. // Save original requested product
  492. if ($Shopp->Product) $Requested = $Shopp->Product;
  493. $products = explode(",",$options['product']);
  494. if (!is_array($products)) $products = array($products);
  495. foreach ($products as $product) {
  496. $product = trim($product);
  497. if (empty($product)) continue;
  498. if (preg_match('/^[\d+]$/',$product))
  499. $Shopp->Product = new Product($product);
  500. else $Shopp->Product = new Product($product,'slug');
  501. if (empty($Shopp->Product->id)) continue;
  502. if (isset($options['load'])) return true;
  503. ob_start();
  504. if (file_exists(SHOPP_TEMPLATES."/sideproduct-{$Shopp->Product->id}.php"))
  505. include(SHOPP_TEMPLATES."/sideproduct-{$Shopp->Product->id}.php");
  506. else include(SHOPP_TEMPLATES."/sideproduct.php");
  507. $content .= ob_get_contents();
  508. ob_end_clean();
  509. }
  510. // Restore original requested category
  511. if (!empty($Requested)) $Shopp->Product = $Requested;
  512. else $Shopp->Product = false;
  513. }
  514. if ($source == "category" && isset($options['category'])) {
  515. // Save original requested category
  516. if ($Shopp->Category) $Requested = $Shopp->Category;
  517. if (empty($options['category'])) return false;
  518. $Shopp->Category = Catalog::load_category($options['category']);
  519. $Shopp->Category->load_products($options);
  520. if (isset($options['load'])) return true;
  521. foreach ($Shopp->Category->products as $product) {
  522. $Shopp->Product = $product;
  523. ob_start();
  524. if (file_exists(SHOPP_TEMPLATES."/sideproduct-{$Shopp->Product->id}.php"))
  525. include(SHOPP_TEMPLATES."/sideproduct-{$Shopp->Product->id}.php");
  526. else include(SHOPP_TEMPLATES."/sideproduct.php");
  527. $content .= ob_get_contents();
  528. ob_end_clean();
  529. }
  530. // Restore original requested category
  531. if (!empty($Requested)) $Shopp->Category = $Requested;
  532. else $Shopp->Category = false;
  533. }
  534. return $content;
  535. break;
  536. }
  537. }
  538. } // end Catalog class
  539. ?>