<?php
/*
* @package ContentCMS
* @author Dan Goldsmith
* @copyright Dan Goldsmith 2012
* @link http://contentcms.d2g.org.uk/
* @version {SUBVERSION_BUILD_NUMBER}
*
* @licence MPL 2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
*
* A Plugin That Uses template would be better off extending this class.
*/
abstract class templated_plugin extends plugin
{
protected $id = null;
public function __construct($content_id)
{
$this->setID($content_id);
}
protected function setID($id)
{
$this->id = $id;
}
public function getID()
{
return $this->id;
}
public function getPlugin()
{
$content = new content($this->getID());
return $content->getPlugin();
}
public function getConfig()
{
$content = new content($this->getID());
return $content->getPluginConfig();
}
public function getTemplateDirectory()
{
$config = $this->getConfig();
if(array_key_exists('GLOBAL', $config))
{
if(array_key_exists('Templates', $config['GLOBAL']))
{
return $config['GLOBAL']['Templates'];
}
}
return 'templates/';
}
public function getAdminTemplateDirectory()
{
$config = $this->getConfig();
if(array_key_exists('GLOBAL', $config))
{
if(array_key_exists('Admin_Templates', $config['GLOBAL']))
{
return $config['GLOBAL']['Admin_Templates'];
}
}
return 'templates/admin/';
}
public function getTemplatePath($relative_url)
{
$template_path = null;
//Default the template path first
if(is_file(CONTENT_PLUGIN_DIRECTORY . "/" . $this->getPlugin() . "/templates/" . $relative_url))
{
$template_path = CONTENT_PLUGIN_DIRECTORY . "/" . $this->getPlugin() . "/templates/" . $relative_url;
}
if(is_file(CONTENT_PLUGIN_DIRECTORY . "/" . $this->getPlugin() . "/" . $this->getTemplateDirectory() . "/" . $relative_url))
{
$template_path = CONTENT_PLUGIN_DIRECTORY . "/" . $this->getPlugin() . "/" . $this->getTemplateDirectory() . "/" . $relative_url;
}
return $template_path;
}
public function getAdminTemplatePath($relative_url)
{
$template_path = null;
//Default the template path first
if(is_file(CONTENT_PLUGIN_DIRECTORY . "/" . $this->getPlugin() . "/templates/admin/" . $relative_url))
{
$template_path = CONTENT_PLUGIN_DIRECTORY . "/" . $this->getPlugin() . "/templates/admin/" . $relative_url;
}
if(is_file(CONTENT_PLUGIN_DIRECTORY . "/" . $this->getPlugin() . "/" . $this->getAdminTemplateDirectory() . "/" . $relative_url))
{
$template_path = CONTENT_PLUGIN_DIRECTORY . "/" . $this->getPlugin() . "/" . $this->getAdminTemplateDirectory() . "/" . $relative_url;
}
return $template_path;
}
}
?>