themeclass) ? $Options->themeclass: __class__;
self::$fInstance = &GetInstance($TemplateClass);
$GLOBALS['Template'] = &self::$fInstance;
return self::$fInstance;
}
protected function CreateData() {
parent::CreateData();
$this->basename = 'template';
$this->AddEvents('WidgetAdded', 'WidgetDeleted',
'BeforeContent', 'AfterContent'
//'BeforeParse', 'AfterParse'
);
$this->Data['themename'] = 'default';
$this->Data['sitebarcount'] = 2;
$this->Data['footer']= 'Powered by blogolet CMS';
$this->Data['idwidget'] = 0;
$this->Data['submenuinwidget'] = true;
$this->AddDataMap('sitebars', array(0 => array(), 1 => array(), 2 => array()));
$this->AddDataMap('widgets', array());
$this->AddDataMap('tags', array());
$this->fFiles = array();
}
public function Load() {
parent::Load();
$this->LoadTheme();
}
public function __get($name) {
if (method_exists($this, $get = "Get$name")) {
return $this->$get();
}
if (key_exists($name, $this->tags)) {
return $this->GetTag($name);
}
if ($this->DataObjectHasProp($name)) {
return $this->DataObject->$name;
}
return parent::__get($name);
}
protected function DataObjectHasProp($name) {
return isset($this->DataObject) && (isset($this->DataObject->$name) || (method_exists($this->DataObject, 'PropExists') && $this->DataObject->PropExists($name)));
}
protected function LoadTheme() {
global $paths, $Options;
if ($this->themename == '' || !@file_exists($paths['themes']. $this->themename . DIRECTORY_SEPARATOR . 'index.tml')) {
$this->themename = 'default';
return;
}
$this->path = $paths['themes'] . $this->themename . DIRECTORY_SEPARATOR ;
$this->url = $Options->url . '/themes/'. $this->themename;
$this->theme = parse_ini_file($this->path . 'theme.ini', true);
}
protected function Setthemename($name) {
global $paths, $Options;
if ($this->themename <> $name) {
$this->Lock();
//echo "uninstall prev theme plugin if exists\n";
if ($about = $this->GetAbout($this->themename)) {
if (!empty($about['pluginclassname'])) {
//echo "uninstall theme plugin
\n";
$plugins = &TPlugins::Instance();
$plugins->Delete($this->themename);
//echo "plugin successfuly deleted
\n";
}
}
$this->Data['themename'] = $name;
$this->path = $paths['themes'] . $name . DIRECTORY_SEPARATOR ;
//echo "load info about new theme\n";
$about = $this->GetAbout($name);
$this->sitebarcount = $about['sitebars'];
// install theme plugin if exists
if (!empty($about['pluginclassname'])) {
$plugins = &TPlugins::Instance();
$plugins->AddExt($name, $about['pluginclassname'], $about['pluginfilename']);
}
$urlmap = &TUrlmap::Instance();
$urlmap->ClearCache();
$this->url = $Options->url . '/themes/'. $this->themename;
$this->LoadTheme();
$this->Unlock();
}
}
public function AddWidget($class, $echotype, $order = -1, $index = 0) {
if ($index >= $this->sitebarcount) return $this->Error("sitebar index $index cant more than sitebars count in template");
if (!in_array($echotype, array('echo', 'include', 'nocache'))) $echotype = 'echo';
$this->widgets[++$this->Data['idwidget']] = array(
'class' => $class,
'index' => $index,
'echotype' => $echotype
);
if (($order < 0) || ($order > count($this->sitebars[$index]))) $order = count($this->sitebars[$index]);
array_splice($this->sitebars[$index], $order, 0, $this->idwidget);
$this->Save();
$this->WidgetAdded($this->idwidget);
return $this->idwidget;
}
public function ClassHasWidget($class) {
foreach ($this->widgets as $id => $item) {
if ($item['class'] == $class) {
return true;
}
}
return false;
}
public function DeleteWidget($ClassName) {
$this->Lock();
foreach ($this->widgets as $id => $item) {
if ($item['class'] == $ClassName) {
$this->DeleteIdWidget($id);
}
}
$this->Unlock();
}
public function DeleteIdWidget($id) {
global $paths;
if (isset($this->widgets[$id])) {
for ($i = count($this->sitebars) -1; $i >= 0; $i--) {
$j = array_search($id, $this->sitebars[$i]);
if (is_int($j)) array_splice($this->sitebars[$i], $j, 1);
}
@unlink($paths['cache']. "widget$id.php");
unset($this->widgets[$id]);
$this->Save();
$this->WidgetDeleted($id);
}
}
public static function WidgetExpired(&$widget) {
$self = &self::Instance();
$self->SetWidgetExpired(get_class($widget));
}
public function SetWidgetExpired($ClassName) {
global $paths;
foreach ($this->widgets as $id => $item) {
if ($item['class'] == $ClassName) {
@unlink($paths['cache']. "widget$id.php");
}
}
}
public function WidgetsExpire() {
global $paths;
foreach ($this->widgets as $id => $item) {
@unlink($paths['cache']. "widget$id.php");
}
}
protected function GetWidgetContent($id) {
global $paths;
$FileName = $paths['cache']. "widget$id.php";
$echotype = $this->widgets[$id]['echotype'];
if (($echotype == 'nocache') || !@file_exists($FileName)) {
$widget = &GetInstance($this->widgets[$id]['class']);
$result = $widget->GetWidgetContent($id);
if ($echotype != 'nocache') {
file_put_contents($FileName, $result);
@chmod($FileName, 0666);
}
if ($echotype != 'include') return $result;
}
if ($echotype == 'echo') return file_get_contents($FileName);
return "\n\n";
}
public function GetBeforeWidget($name, $title = '') {
$theme = &$this->theme['widget'];
if (isset($theme[$name])) {
$result = $theme[$name];
} elseif (isset($theme[$name . ($this->SitebarIndex + 1)])) {
$result = $theme[$name . ($this->SitebarIndex + 1)];
} elseif (isset($theme['before' . ($this->SitebarIndex + 1)])) {
$result = $theme['before' . ($this->SitebarIndex + 1)];
} else {
$result = $theme['before'];
}
if (empty($title) && isset(TLocal::$data['default'][$name])) {
$title= TLocal::$data['default'][$name];
}
eval("\$result =\"$result\n\";");
return str_replace("'", '"', $result);
}
public function GetAfterWidget() {
$theme = &$this->theme['widget'];
if (isset($theme["after$this->SitebarIndex"])) return $theme["after$this->SitebarIndex"];
return $theme['after'] . "\n";
}
public function Getsitebar() {
$result .= '';
//if ($this->submenuinwidget) $result .= $this->Getsubmenuwidget();
$result .= $this->GetSitebarIndex(0);
if ($this->sitebarcount == 1) {
$result .= $this->GetSitebarIndex(1);
$result .= $this->GetSitebarIndex(2);
}
return $result;
}
public function Getsitebar2() {
$result = $this->GetSitebarIndex(1);
if ($this->sitebarcount == 2) {
$result .= $this->GetSitebarIndex(2);
}
return $result;
}
public function Getsitebar3() {
return $this->GetSitebarIndex(2);
}
protected function GetSitebarIndex($index) {
$this->SitebarIndex = $index;
$result = '';
foreach ($this->sitebars[$index] as $id) {
$result .= $this->GetWidgetContent($id);
}
return $result;
}
public function MoveWidget($id, $index) {
if (!isset($this->widgets[$id])) return false;
$oldindex = $this->widgets[$id]['index'];
if ($index != $oldindex) {
$i = array_search($id, $this->sitebars[$oldindex]);
array_splice($this->sitebars[$oldindex], $i, 1);
$this->sitebars[$index][] = $id;
$this->widgets[$id]['index'] = $index;
$this->Save();
}
}
public function MoveWidgetOrder($id, $order) {
if (!isset($this->widgets[$id])) return false;
$index = $this->widgets[$id]['index'];
if (($order < 0) || ($order > count($this->sitebars[$index]))) $order = count($this->sitebars[$index]);
$oldorder = array_search($id, $this->sitebars[$index]);
if ($oldorder != $order) {
array_splice($this->sitebars[$index], $oldorder, 1);
array_splice($this->sitebars[$index], $order, 0, $id);
$this->Save();
}
}
protected function GetTag($name) {
if (!isset($this->tags[$name])) return '';
$result ='';
$function = $this->tags[$name]['function'];
$classname = $this->tags[$name]['class'];
if (empty($classname)) {
if (function_exists($function)) {
$result = $function($name);
} else {
unset($this->tags[$name]);
$this->Save();
}
} else {
if (!@class_exists($classname)) __autoload($classname);
if (!@class_exists($classname)) {
unset($this->tags[$name]);
$this->Save();
} else {
$obj = &GetInstance($classname);
$result = $obj->$function($name);
}
}
return $result;
}
public function AddTag($tag, $classname, $function) {
$this->tags[$tag] = array(
'class' => $classname,
'function' => $function
);
$this->Save();
}
public function DeleteTag($name) {
if (isset($this->tags[$name])) {
unset($this->tags[$name]);
$this->Save();
}
}
public function DeleteTagClass($classname) {
$this->Lock();
foreach ($this->tags as$tag => $item) {
if ($item['class'] == $classname) unset($this->tags[$tag]);
}
$this->Unlock();
}
public function&Request(&$DataObject) {
$this->DataObject = &$DataObject;
$GLOBALS['DataObject'] = &$DataObject;
$header = $this->ServerHeader();
$s = $this->ParseFile('index.tml');
$s = $header .$s;
return $s;
}
protected function ServerHeader() {
global $Options;
if (method_exists($this->DataObject, 'ServerHeader')) {
$s= $this->DataObject->ServerHeader();
if (!empty($s)) return $s;
}
$nocache = $this->DataObject->CacheEnabled ? '' : "
@Header( 'Cache-Control: no-cache, must-revalidate');
@Header( 'Pragma: no-cache');";
return "pingurl');
?>";
}
public function AuthHeader() {
return '';
}
public function ParseFile($FileName) {
global $Options, $Urlmap, $Template, $DataObject, $user, $post, $item, $tabindex;
if (!isset($this->fFiles[$FileName])) {
$this->fFiles[$FileName] = @file_get_contents($this->path . $FileName);
}
$Result = $this->fFiles[$FileName];
$Result = str_replace('"', '\"', $Result);
eval("\$Result = \"$Result\";");
return $Result;
}
public function GetAbout($themename) {
global $paths;
if (!isset($this->aboutFiles)) $this->aboutFiles = array();
if (!isset($this->aboutFiles[$themename])) {
$this->aboutFiles[$themename] = @parse_ini_file($paths['themes'] . $themename . DIRECTORY_SEPARATOR . 'about.ini', false);
}
return $this->aboutFiles[$themename];
}
//html tags
public function Gettitle() {
global $Options;
$result = '';
if ($this->DataObjectHasProp('title')) {
$result = $this->DataObject->title;
}
if (empty($result)) {
$result = $Options->name;
} else {
$result = "$result | $Options->name";
}
return $result;
}
public function Getkeywords() {
global $Options;
return $Options->keywords;
}
public function Getdescription() {
global $Options;
return $Options->description;
}
public function Getmenu() {
global $paths;
$filename = $paths['cache'] . 'menu.php';
if (@file_exists($filename)) {
return file_get_contents($filename);
}
$Menu = &TMenu::Instance();
$liclass = isset($this->theme['class']['menu']) ? $this->theme['class']['menu'] : '';
$liclass = empty($liclass) ? '' : "class=\"$liclass\"";
$idmenu = isset($this->theme['class']['idmenu']) ? $this->theme['class']['idmenu'] : '';
// if (empty($idmenu) || $this->submenuinwidget) {
if (true) {
$links = $Menu->GetHomeLinks();
if (count($links) == 0) return '';
$result = "\n