File: D:/HostingSpaces/PvdBoogaard/indoorski.nl/backup/oude-site/cms/includes/pages/viewcategory.php
<?php
/**
* This file contains the iwp_page_viewcategory class
*
* @version $Id$
*
*
* @package IWP
* @subpackage IWP_FrontEnd
*/
/**
* IWP Frontend View Category Class
* This class extends the iwp_engine abstract class.
* This class handles the actions for viewing categories on the frontend
*
* @package IWP
* @subpackage IWP_FrontEnd
*/
class iwp_page_viewcategory extends iwp_engine {
/**
* Calls the parent constructor
*
* @return void Doesn't return anything
*/
public function __construct(){
parent::__construct();
}
/**
* This function tells the controller to loads the view category page. It checks to make sure the ID number is valid and loads the category data from the database and sets up the database variables with the data.
*
* @return void Doesn't return anything
*/
public function ShowPage($categoryId){
$category = iwp_categories::getInstance();
$category->SetId($categoryId);
$category->Load();
$categoryName = $category->Get('name');
if($category->GetId() < 1){
$this->InvalidCategory();
}
$this->template->Assign('categoryTitle', $category->Get('name'));
$this->template->Assign('categoryDescription', $category->Get('description'), false);
$rssUrl = $this->urls->GetStaticUrl('viewcategoryrss', array('name'=> $category->Get('name'), 'idnumber'=>$category->GetId()));
$this->template->Append('headTagEnd', '<link rel="alternate" type="application/rss+xml" title="'. iwp_htmlentities($category->Get('name')) .'" href="'. iwp_htmlentities($rssUrl) .'" />', false);
if(!is_blank($category->Get('metadesc'))){
$this->template->Assign('metaDescription', $category->Get('metadesc'));
}
if(!is_blank($category->Get('metakeywords'))){
$this->template->Assign('metaKeywords', $category->Get('metakeywords'));
}
/** start paging **/
$requestPage = max((int)@$_GET['page'], 1);
$perpage = (int)iwp_config::Get('CategoryContentPerPage');
if($perpage < 1) {
$perpage = 10;
}
$limit = (($requestPage*$perpage)-$perpage) . ', '.$perpage;
$titleAppend = '';
$lists = new iwp_lists;
$sql = 'select SQL_CALC_FOUND_ROWS c.*, ct.* from '.IWP_TABLE_CONTENT.' as c left join '. IWP_TABLE_CONTENTTYPES .' as ct on c.typeid=ct.typeid left join '.IWP_TABLE_CATASSOC.' as ca on c.contentid=ca.contentid where /*%%visibility%%*/ (ca.categoryid='.$category->GetId().') order by c.startdate desc limit ' . $limit;
$contentList = $lists->OutputListByQuery($sql);
if(iwp_config::Get('ShowPageNumberOnCategories')) {
$titleAppend = sprintf($this->lang->Get('PageNumber'), $requestPage);
}
if(!is_blank($category->Get('metatitle'))){
$this->template->Assign('websiteTitle', $category->Get('metatitle') . $titleAppend);
}else{
$this->template->Assign('websiteTitle', $category->Get('name'). $titleAppend);
}
$cacheId = md5($sql.'paging');
$this->cache->SetDir('categories');
if(!$this->cache->HasExpired($cacheId)){
$this->template->Assign('categoryPaging', $this->cache->ReadCache($cacheId), false);
}else{
if($lists->foundRows > $perpage) {
$this->paging = new iwp_paging();
$this->paging->SetPaging($lists->foundRows, $perpage, $requestPage, '?page=%d', 5);
$paging = array();
$paging['PageCount'] = $this->paging->PageCount;
$paging['currentPage'] = $this->paging->CurrentPage;
$paging['prevPageLink'] = $this->paging->PreviousURL;
$paging['nextPageLink'] = $this->paging->NextURL;
$paging['links'] = $this->paging->PageList;
$paging['firstPageLink']= $this->paging->FirstURL;
$paging['lastPageLink'] = $this->paging->LastURL;
$this->template->Assign('paging', $paging);
$pagingHTML = $this->template->ParseSection('paginglinks_standard');
$this->template->Assign('categoryPaging', $pagingHTML, false);
$this->cache->WriteCache($cacheId, $pagingHTML);
}else{
$this->cache->WriteCache($cacheId, '');
$this->template->Assign('categoryPaging', '');
}
}
if($contentList === null){
$this->template->Assign('hasContent', false);
$this->template->Assign('noContentMsg', $this->lang->Get('CategoryHasNoContent'), false);
$this->template->Assign('categoryContentList', '', false);
}else{
$this->template->Assign('hasContent', true);
$this->template->Assign('categoryContentList', $contentList , false);
}
$breadCrumbTrailLinks = array();
$parentCategories = $category->GetParentsArray($category->GetId());
// we already have a list of parents so ViewCategoryURL doesn't need to look it up again
// pop each element off the end and pass through the remaining parent elements
// there's no easy way to get the popped array key from array_pop so grab a second array of ids (which were stored in the first array as keys)
$parentCategoryIds = array_keys($parentCategories);
while ($parentCategoryName = array_pop($parentCategories)) {
$parentCategoryId = array_pop($parentCategoryIds);
$url = $this->urls->GetURLPrepend(true, false) . $this->urls->ViewCategoryURL($parentCategoryId);
$breadCrumbTrailLinks[] = array('Url' => $url, 'Title' => $parentCategoryName);
}
$breadCrumbTrailLinks[] = array('Url' => $this->urls->GetStaticUrl('viewallcategories'), 'Title' => $this->lang->Get('CategoriesTitle'));
$breadCrumbTrailLinks[] = array('Url' => iwp_config::Get('siteURL') .'/', 'Title' => $this->lang->Get('HomePage'));
// this results in an array of parents going in the wrong direction (nearest to furthest ancestor) - so reverse it
$breadCrumbTrailLinks = array_reverse($breadCrumbTrailLinks);
// add an unlinked breadcrumb entry for the current category
$breadCrumbTrailLinks[] = array('Title' => $category->Get('name'));
$this->template->Assign(array('breadcrumbtrail', 'links'), $breadCrumbTrailLinks);
$this->template->Assign('categoryBreadcrumb', $this->template->ParseSection('breadcrumbtrail_standard'), false);
$this->template->Assign('categorySubCategories', $lists->OutputListByQuery('select SQL_CALC_FOUND_ROWS *, c.categoryid as rowid, (select count(*) from '. IWP_TABLE_CATEGORIES .' cc where cc.parentid = c.categoryid and cc.hidefrommenu=0) as childcount from '.IWP_TABLE_CATEGORIES.' c where c.parentid='.$category->GetId() .' and c.hidefrommenu=0 order by c.sortcache', 'linked_title', 'categories'), false);
if (!iwp_event::trigger(new iwp_event_categories_beforeshowtemplate($category, $this->template))) {
return;
}
$this->controller->SetContent($this->template->ParseSection('viewcategory_standard'));
if($category->Get('haslayout') == 1) {
$this->controller->ShowTemplate('category_' . $category->GetId());
} else {
$this->controller->ShowTemplate('category');
}
}
/**
* This function displays an error page with the Invalid Category message
*
* @return void Doesn't return anything
*/
public function InvalidCategory(){
$this->controller->SetContent('Invalid Category!');
$this->controller->ShowTemplate('error');
die();
}
}