diff --git a/public/include/pages/admin/templates.inc.php b/public/include/pages/admin/templates.inc.php deleted file mode 100644 index 00af9281..00000000 --- a/public/include/pages/admin/templates.inc.php +++ /dev/null @@ -1,48 +0,0 @@ -isAuthenticated() || !$user->isAdmin($_SESSION['USERDATA']['id'])) { - header("HTTP/1.1 404 Page not found"); - die("404 Page not found"); -} - -$aThemes = $template->getThemes(); -$aTemplates = $template->getTemplatesTree($aThemes); -$aActiveTemplates = $template->cachedGetActiveTemplates(); - -$aFlatTemplatesList = array(); -foreach($aThemes as $sTheme) { - $templates = $template->getTemplateFiles($sTheme); - $aFlatTemplatesList = array_merge($aFlatTemplatesList, $templates); -} - -//Fetch current slug and template -$sTemplate = @$_REQUEST['template']; -if(!in_array($sTemplate, $aFlatTemplatesList)) { - $sTemplate = $aFlatTemplatesList[0]; -} - -$sOriginalTemplate = $template->getTemplateContent($sTemplate); - -if (@$_REQUEST['do'] == 'save') { - if ($template->updateEntry(@$_REQUEST['template'], @$_REQUEST['content'], @$_REQUEST['active'])) { - $_SESSION['POPUP'][] = array('CONTENT' => 'Page updated', 'TYPE' => 'alert alert-success'); - } else { - $_SESSION['POPUP'][] = array('CONTENT' => 'Page update failed: ' . $template->getError(), 'TYPE' => 'alert alert-danger'); - } -} - -$oDatabaseTemplate = $template->getEntry($sTemplate); - -if ( $oDatabaseTemplate === false ) { - $_SESSION['POPUP'][] = array('CONTENT' => 'Can\'t fetch template from Database. Have you created `templates` table? Run 005_create_templates_table.sql from sql folder', 'TYPE' => 'alert alert-danger'); -} - -$smarty->assign("TEMPLATES", $aTemplates); -$smarty->assign("ACTIVE_TEMPLATES", $aActiveTemplates); -$smarty->assign("CURRENT_TEMPLATE", $sTemplate); -$smarty->assign("ORIGINAL_TEMPLATE", $sOriginalTemplate); -$smarty->assign("DATABASE_TEMPLATE", $oDatabaseTemplate); -$smarty->assign("CONTENT", "default.tpl"); -?> diff --git a/public/include/smarty.inc.php b/public/include/smarty.inc.php index df084e48..bb931fe5 100644 --- a/public/include/smarty.inc.php +++ b/public/include/smarty.inc.php @@ -7,145 +7,6 @@ define('SMARTY_DIR', INCLUDE_DIR . '/smarty/libs/'); // Include the actual smarty class file include(SMARTY_DIR . 'Smarty.class.php'); -/** - * Custom Smarty Template Resource for Pages - * Get templates from Database - * Allow admin to manage his templates from Backoffice - */ -class Smarty_Resource_Database extends Smarty_Resource_Custom { - protected $template; - - public function __construct($template) { - $this->template = $template; - } - /** - * Fetch a template and its modification time from database - * - * @param string $name template name - * @param string $source template source - * @param integer $mtime template modification timestamp (epoch) - * @return void - */ - protected function fetch($name, &$source, &$mtime) { - $oTemplate = $this->template->getEntry($this->fullTemplateName($name)); - if ( $oTemplate && $oTemplate['active'] ) { - $source = $oTemplate['content']; - $mtime = strtotime($oTemplate['modified_at']); - } else { - $source = null; - $mtime = null; - } - } - - /** - * Fetch a template's modification time from database - * - * @note implementing this method is optional. Only implement it if modification times can be accessed faster than loading the comple template source. - * @param string $name template name - * @return integer timestamp (epoch) the template was modified - */ - protected function fetchTimestamp($name) { - $templates = $this->template->cachedGetActiveTemplates(); - $mtime = @$templates[$this->fullTemplateName($name)]; - return $mtime ? $mtime : false; - } - - /** - * Prepend THEME name to template name to get valid DB primary key - * - * @param string $name template name - */ - protected function fullTemplateName($name) { - return $this->normalisePath(THEME . "/" . $name); - } - - /** - * Normalise a file path string so that it can be checked safely. - * - * Attempt to avoid invalid encoding bugs by transcoding the path. Then - * remove any unnecessary path components including '.', '..' and ''. - * - * @param $path string - * The path to normalise. - * @return string - * The path, normalised. - * @see https://gist.github.com/thsutton/772287 - */ - protected function normalisePath($path) { - // Process the components - $parts = explode('/', $path); - $safe = array(); - foreach ($parts as $idx => $part) { - if (empty($part) || ('.' == $part)) { - continue; - } elseif ('..' == $part) { - array_pop($safe); - continue; - } else { - $safe[] = $part; - } - } - // Return the "clean" path - $path = implode(DIRECTORY_SEPARATOR, $safe); - return $path; - } - -} - -class Smarty_Resource_Hybrid extends Smarty_Resource { - - protected $databaseResource; - - protected $fileResource; - - public function __construct($dbResource, $fileResource) { - $this->databaseResource = $dbResource; - $this->fileResource = $fileResource; - } - - /** - * populate Source Object with meta data from Resource - * - * @param Smarty_Template_Source $source source object - * @param Smarty_Internal_Template $_template template object - */ - public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null) { - if ( !@$_REQUEST['disable_template_override'] ) { - $this->databaseResource->populate($source, $_template); - if( $source->exists ) - return; - } - $source->type = 'file'; - return $this->fileResource->populate($source, $_template); - } - - /** - * Load template's source into current template object - * - * @param Smarty_Template_Source $source source object - * @return string template source - * @throws SmartyException if source cannot be loaded - */ - public function getContent(Smarty_Template_Source $source) { - try { - return $this->databaseResource->getContent($source); - } catch(SmartyException $e) { - return $this->fileResource->getContent($source); - } - } - - /** - * Determine basename for compiled filename - * - * @param Smarty_Template_Source $source source object - * @return string resource's basename - */ - public function getBasename(Smarty_Template_Source $source) { - return $this->fileResource->getBasename($source); - } - -} - // We initialize smarty here $debug->append('Instantiating Smarty Object', 3); $smarty = new Smarty; @@ -154,11 +15,6 @@ $smarty = new Smarty; $debug->append('Define Smarty Paths', 3); $smarty->template_dir = BASEPATH . 'templates/' . THEME . '/'; $smarty->compile_dir = BASEPATH . 'templates/compile/' . THEME . '/'; -$smarty->registerResource('hybrid', new Smarty_Resource_Hybrid( - new Smarty_Resource_Database($template), - new Smarty_Internal_Resource_File() -)); -$smarty->default_resource_type = "hybrid"; $smarty_cache_key = md5(serialize($_REQUEST) . serialize(@$_SESSION['USERDATA']['id'])); // Optional smarty caching, check Smarty documentation for details diff --git a/public/templates/bootstrap/admin/templates/browser.tpl b/public/templates/bootstrap/admin/templates/browser.tpl deleted file mode 100644 index 3f4178e1..00000000 --- a/public/templates/bootstrap/admin/templates/browser.tpl +++ /dev/null @@ -1,48 +0,0 @@ -
-
-
- Select Page -
-
- {include file="admin/templates/tree.tpl" files=$TEMPLATES prefix=""} -
- - - - - - - -
-
diff --git a/public/templates/bootstrap/admin/templates/default.tpl b/public/templates/bootstrap/admin/templates/default.tpl deleted file mode 100644 index 1d5adaea..00000000 --- a/public/templates/bootstrap/admin/templates/default.tpl +++ /dev/null @@ -1,4 +0,0 @@ -
- {include file="admin/templates/browser.tpl"} - {include file="admin/templates/editor.tpl"} -
diff --git a/public/templates/bootstrap/admin/templates/editor.tpl b/public/templates/bootstrap/admin/templates/editor.tpl deleted file mode 100644 index 41e010bb..00000000 --- a/public/templates/bootstrap/admin/templates/editor.tpl +++ /dev/null @@ -1,38 +0,0 @@ -
- - - - - -
-
- Edit template '{$CURRENT_TEMPLATE}' -
-
- - - - - - - - - - - - - -
- - -
- -
- -
-
- -
-
diff --git a/public/templates/bootstrap/admin/templates/tree.tpl b/public/templates/bootstrap/admin/templates/tree.tpl deleted file mode 100644 index af08822c..00000000 --- a/public/templates/bootstrap/admin/templates/tree.tpl +++ /dev/null @@ -1,27 +0,0 @@ - diff --git a/public/templates/bootstrap/global/navigation.tpl b/public/templates/bootstrap/global/navigation.tpl index 6982f8d2..ca5a4279 100644 --- a/public/templates/bootstrap/global/navigation.tpl +++ b/public/templates/bootstrap/global/navigation.tpl @@ -8,7 +8,7 @@
  • Dashboard
  • - +
  • My Account