File: D:/HostingSpaces/PvdBoogaard/indoorski.nl/backup/oude-site/cms/includes/pages/archive.php
<?php
/**
* This file contains the iwp_page_archive class
*
* @version $Id$
*
*
* @package IWP
* @subpackage IWP_FrontEnd
*/
/**
* IWP Frontend Archive 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_archive 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(){
$sections = $this->urls->GetCurrentMatches();
$useAmericanDateUrl = false;
// set up the current request's date
$archiveYear = $sections['archive_year'];
$archiveMonth = $sections['archive_month'];
$archiveDay = $sections['archive_day'];
$archiveTimestamp = mktime(5,5,5,max(1,(int)$archiveMonth), max(1, (int)$archiveDay), (int)$archiveYear);
// work out the title of the page
$archiveDate = '';
if(!empty($archiveDay)) {
if(!$useAmericanDateUrl) {
$archiveDate = date("F jS Y", $archiveTimestamp);
}else{
$archiveDate = date("jS F Y", $archiveTimestamp);
}
} elseif (!empty($archiveMonth)) {
$archiveDate = date("F Y", $archiveTimestamp);
} elseif (!empty($archiveYear)) {
$archiveDate = date("Y", $archiveTimestamp);
}
$archiveTitle = $this->lang->Get('ArchiveTitleDefault');
if(!empty($archiveDate)) {
$archiveTitle = sprintf($this->lang->Get('ArchiveTitleFor'), $archiveDate);
}
$this->template->Assign('archiveTitle', $archiveTitle);
$this->template->Assign('websiteTitle', $archiveTitle);
// use the paging for the page to determine the query limits
$perPage = 10;
$requestPage = max((int)@$_GET['page'], 1);
$limit = (($requestPage*$perPage)-$perPage) . ', '.$perPage;
// determine what page we are on so we know what query to run for the content that will be displayed
if (!empty($archiveDay)) {
// they are on a page for a specific day - e.g. 23rd June 2009
$contentSQL = 'select SQL_CALC_FOUND_ROWS *, c.contentid as rowid, left(c.startdate, 4) as postyear, substring(c.startdate, 6, 2) as postmonth, substring(c.startdate, 9, 2) as postday from '.IWP_TABLE_CONTENT.' c inner join '. IWP_TABLE_CONTENTTYPES .' as ct on ct.typeid = c.typeid where /*%%visibility%%*/ 1=1 having postyear="' . (int)$archiveYear . '" and postmonth="' . $this->db->Quote($archiveMonth) . '" and postday="' . $this->db->Quote($archiveDay) . '" order by c.startdate desc limit ' . $limit;
} elseif (!empty($archiveMonth)) {
// they are on a page for a specific month - e.g. April 2003
$contentSQL = 'select SQL_CALC_FOUND_ROWS *, c.contentid as rowid, left(c.startdate, 4) as postyear, substring(c.startdate, 6, 2) as postmonth from '.IWP_TABLE_CONTENT.' c inner join '. IWP_TABLE_CONTENTTYPES .' as ct on ct.typeid = c.typeid where /*%%visibility%%*/ 1=1 having postyear="' . (int)$archiveYear . '" and postmonth="' . $this->db->Quote($archiveMonth) . '" order by c.startdate desc limit ' . $limit;
} elseif (!empty($archiveYear)) {
// they are on a page for a specific year - e.g. 2008
$contentSQL = 'select SQL_CALC_FOUND_ROWS *, c.contentid as rowid, left(c.startdate, 4) as postyear from '.IWP_TABLE_CONTENT.' c inner join '. IWP_TABLE_CONTENTTYPES .' as ct on ct.typeid = c.typeid where /*%%visibility%%*/ 1=1 having postyear="' . (int)$archiveYear . '" order by c.startdate desc limit ' . $limit;
} else {
// they are on the root archive page, no date information has been selecteds
$contentSQL = 'select SQL_CALC_FOUND_ROWS *, c.contentid as rowid from '.IWP_TABLE_CONTENT.' c inner join '. IWP_TABLE_CONTENTTYPES .' as ct on ct.typeid = c.typeid where /*%%visibility%%*/ 1=1 order by c.startdate desc limit ' . $limit;
}
$lists = new iwp_lists;
$contentList = $lists->OutputListByQuery($contentSQL);
// check the cache for the paging links
$cacheId = md5($contentSQL.'paging');
$this->cache->SetDir('archive');
if(!$this->cache->HasExpired($cacheId)){
$this->template->Assign('archivePaging', $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('archivePaging', $pagingHTML, false);
$this->cache->WriteCache($cacheId, $pagingHTML);
}else{
$this->cache->WriteCache($cacheId, '');
$this->template->Assign('archivePaging', '');
}
}
// check if there are any content items for this date, if not display a message
if($contentList === null){
$this->template->Assign('hasContent', false);
$this->template->Assign('noContentMsg', $this->lang->Get('ArchiveHasNoContent'), false);
$this->template->Assign('archiveContentList', '', false);
}else{
$this->template->Assign('hasContent', true);
$this->template->Assign('archiveContentList', $contentList , false);
}
// set up the breadcrumb trail
$breadCrumbTrailLinks = array();
// determine what links to add into the trail based on what page we're on
if(!empty($archiveDay)) {
$breadCrumbTrailLinks[] = array('Url' => $this->urls->GetStaticUrl('archive', array('archive_year'=>$archiveYear, 'archive_month'=>$archiveMonth, 'archive_day'=>$archiveDay)), 'Title' => $archiveDay);
}
if (!empty($archiveMonth)) {
$breadCrumbTrailLinks[] = array('Url' => $this->urls->GetStaticUrl('archive', array('archive_year'=>$archiveYear, 'archive_month'=>$archiveMonth)), 'Title' => date("F", $archiveTimestamp));
}
if (!empty($archiveYear)) {
$breadCrumbTrailLinks[] = array('Url' => $this->urls->GetStaticUrl('archive', array('archive_year'=>$archiveYear)), 'Title' => $archiveYear);
}
// add the base 2 links, one for the home page one for the base archive page
$breadCrumbTrailLinks[] = array('Url' => $this->urls->GetStaticUrl('archive'), 'Title' => $this->lang->Get('ArchiveTitleDefault'));
$breadCrumbTrailLinks[] = array('Url' => iwp_config::Get('siteURL') .'/', 'Title' => $this->lang->Get('HomePage'));
// remove the link from the current page
unset($breadCrumbTrailLinks[0]['Url']);
// this results in an array of parents going in the wrong direction (nearest to furthest ancestor) - so reverse it
$breadCrumbTrailLinks = array_reverse($breadCrumbTrailLinks);
$this->template->Assign(array('breadcrumbtrail', 'links'), $breadCrumbTrailLinks);
$this->template->Assign('archiveBreadcrumb', $this->template->ParseSection('breadcrumbtrail_standard'), false);
// work out any sub-date here - i.e. If we're on the 2008 page, find all the months with content and display + link them
if (!empty($archiveDay) || !empty($archiveMonth)) {
// if we're viewing specific month or a specific day, so the days of the month linked
$sql = $lists->InsertVisibility('select SQL_CALC_FOUND_ROWS *, c.contentid as rowid, left(c.startdate, 4) as postyear, substring(c.startdate, 6, 2) as postmonth, substring(c.startdate, 9, 2) as postday from '.IWP_TABLE_CONTENT.' c inner join '. IWP_TABLE_CONTENTTYPES .' as ct on ct.typeid = c.typeid where /*%%visibility%%*/ left(c.startdate, 4)="' . (int)$archiveYear . '" and substring(c.startdate, 6, 2)="' . $this->db->Quote($archiveMonth) . '" group by postday order by postday asc', 'content');
$resource = $this->db->Query($sql);
$outputList = array();
while($thisRow = $this->db->Fetch($resource)) {
$outputList[] = array (
'Title' => date('jS', mktime(5,5,5,(int)$archiveMonth, (int)$thisRow['postday'], $archiveYear)),
'Url' => $this->urls->GetStaticUrl('archive', array('archive_year'=>$archiveYear, 'archive_month'=>$archiveMonth, 'archive_day'=>$thisRow['postday'])),
);
}
} elseif (!empty($archiveYear)) {
// if we're viewing a year, show all the months with content
$sql = $lists->InsertVisibility('select SQL_CALC_FOUND_ROWS *, c.contentid as rowid, left(c.startdate, 4) as postyear, substring(c.startdate, 6, 2) as postmonth from '.IWP_TABLE_CONTENT.' c inner join '. IWP_TABLE_CONTENTTYPES .' as ct on ct.typeid = c.typeid where /*%%visibility%%*/ left(c.startdate, 4)="' . (int)$archiveYear . '" group by postmonth order by postmonth asc ', 'content');
$resource = $this->db->Query($sql);
$outputList = array();
while($thisRow = $this->db->Fetch($resource)) {
$outputList[] = array (
'Title' => date('F', mktime(5,5,5,(int)$thisRow['postmonth'], 5, $archiveYear)),
'Url' => $this->urls->GetStaticUrl('archive', array('archive_year'=>$archiveYear, 'archive_month'=>$thisRow['postmonth'])),
);
}
} else {
// we must be on the root archive page, display all the years that have content in them
$sql = $lists->InsertVisibility('select SQL_CALC_FOUND_ROWS *, c.contentid as rowid, left(c.startdate, 4) as postyear from '.IWP_TABLE_CONTENT.' c inner join '. IWP_TABLE_CONTENTTYPES .' as ct on ct.typeid = c.typeid where /*%%visibility%%*/ 1=1 group by postyear order by postyear desc', 'content');
$resource = $this->db->Query($sql);
$outputList = array();
while($thisRow = $this->db->Fetch($resource)) {
$outputList[] = array (
'Title' => $thisRow['postyear'],
'Url' => $this->urls->GetStaticUrl('archive', array('archive_year'=>$thisRow['postyear'])),
);
}
}
// default values for getting the list for the sub-archive links
$displayStyle = 'linked_title';
$section = "middle";
$this->template->Assign('OutputList', $outputList, false);
$this->template->Assign('blockTitle', '');
if($displayStyle !== null && is_file(IWP_CACHE_SECTION_HTML_PATH .'/list_'.$displayStyle.'.html')){
$outputHTML = $this->template->ParseSection('list_'.$displayStyle, true);
}elseif(is_file(IWP_CACHE_SECTION_HTML_PATH .'/list_'.iwp_strtolower($section).'_standard.html')){
$outputHTML = $this->template->ParseSection('list_'.iwp_strtolower($section).'_standard', true);
}elseif(is_file(IWP_CACHE_SECTION_HTML_PATH .'/list_'.iwp_strtolower($section).'_linked_title.html')){
$outputHTML = $this->template->ParseSection('list_'.iwp_strtolower($section).'_linked_title', true);
}else{
$outputHTML = '';
}
$this->template->Assign('archiveSubArchive', $outputHTML, false);
// finish up, so the archive page
$this->controller->SetContent($this->template->ParseSection('viewarchive_standard'));
$this->controller->ShowTemplate('archive');
}
}