<?php
/** SMS - Selling Made Simple
* Copyright 2007 by Kevin Grandon (hide@address.com)
* This project's homepage is: http://sellingmadesimple.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* BUT withOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
**/
class PagesController extends AppController {
var $components = array('ConfigurationBase','ContentBase','Smarty');
var $uses = null;
function beforeFilter()
{
// This redirects the user to the install script if the config.php filesize is empty.
if($this->action == 'index')
{
$configfilesize = filesize(ROOT . DS . '/config.php');
if(empty($configfilesize))
{
$this->redirect('/install/');
die();
}
}
// Call the beforeFilter in the app_controller
parent::beforeFilter();
}
function getAliasFromParams ($params)
{
global $config;
if(!isset($params['content_alias']))
$content_alias = "";
else
$content_alias = substr($params['content_alias'],0,(strlen($params['content_alias']) - strlen($config['URL_EXTENSION'])));
return $content_alias;
}
/* function content_selflink ()
{
$alias = $this->getAliasFromParams($this->params);
$linked_content = $this->Content->findByAlias($alias);
$link_to = $this->Content->read(null,$linked_content['ContentSelflink']['url']);
global $config;
$this->redirect('/' . $link_to['ContentType']['name'] . '/' . $link_to['Content']['alias'] . $config['URL_EXTENSION']);
}*/
function index()
{
global $content;
global $config;
loadModel('Content');
$this->Content =& new Content();
$alias = $this->getAliasFromParams($this->params);
// Pull the content out of cache or generate it if it doesn't exist
// Cache is based on language_id and alias of the page.
$cache_name = 'sms_content_' . $_SESSION['Customer']['language_id'] . '_' . $alias;
$content = Cache::read($cache_name);
if($content === false)
{
$content = $this->ContentBase->get_content_information($alias);
$content_description = $this->ContentBase->get_content_description($content['Content']['id']);
$content['ContentDescription'] = $content_description['ContentDescription'];
$specific_model = $content['ContentType']['type'];
$specific_content = $this->Content->$specific_model->find(array('content_id' => $content['Content']['id']));
$content[$specific_model] = $specific_content[$specific_model];
Cache::write($cache_name, $content);
}
// Get the template information.
//Layout template cache is generated by the content_id appended to sms_layout_template_.
$cache_name = 'sms_layout_template_' . $content['Content']['id'];
$template = Cache::read($cache_name);
if($template === false)
{
$template = $this->Content->Template->find(array('template_type_id' => '1', 'parent_id' => $content['Template']['id']));
Cache::write($cache_name, $template);
}
// Save cache based on content_id for template_vars.
$cache_name = 'sms_template_vars_' . $content['Content']['id'];
$template_vars = Cache::read($cache_name);
if($template_vars === false)
{
$template_vars = array('content_id' => $content['Content']['id'],
'content_alias' => $content['Content']['alias'],
'parent_id' => $content['Content']['parent_id'],
'sub_count' => array(
'all_content' => $this->Content->findCount(array('Content.parent_id' => $content['Content']['id'])),
'categories' => $this->Content->findCount(array('Content.parent_id' => $content['Content']['id'],'ContentType.name' => 'Category')),
'products' => $this->Content->findCount(array('Content.parent_id' => $content['Content']['id'],'ContentType.name' => 'Product')),
'pages' => $this->Content->findCount(array('Content.parent_id' => $content['Content']['id'],'ContentType.name' => 'Page')),
'pages' => $this->Content->findCount(array('Content.parent_id' => $content['Content']['id'],'OR' => array('ContentType.name' => 'Link', 'ContentType.name' => 'Selflink')))
),
'show_in_menu' => $content['Content']['show_in_menu'],
'created' => $content['Content']['created'],
'modified' => $content['Content']['modified']);
Cache::write($cache_name, $template_vars);
}
$this->Smarty->display($template['Template']['template'],$template_vars);
echo '
<!-- Powered by: Selling Made Simple (www.sellingmadesimple.org) -->
';
die();
}
}
?>