<?php
/*
=============================================================
Script Name : Smarty Template Engine Loader
Auther : Payam khaninejad
Contact : hide@address.com
Follow me on twitter : http://twitter.com/khaninejad
Location : Iran-Azarbayjan
Year : 2011-02-25
Version : 1.0
=============================================================
*/
class load_theme
{
var $base_dir="\\theme";// default theme dir
var $default_theme="thm1";// default theme name
var $theme_url_path="http://127.0.0.1/theme-loader/theme/";// theme install address
var $theme_box="";
function read_dir()
{
// this function used to load dir by using directory listing
$rootdir=$this->return_root_dir();
$theme_folder=$this->base_dir;
$dir=scandir($this->return_root_dir().$this->base_dir);
foreach($dir as $base)
{
// check for valid dir
is_dir($this->read_theme_info($base));
}
}
function return_root_dir()
{
// return theme dir
return dirname ( __FILE__ );
}
function read_theme_info($theme)
{
// load xml file
$xmlfile_path=$this->return_root_dir().$this->base_dir."\\".$theme."\info.xml";
// if file exits
if (file_exists($xmlfile_path))
{
// I use @ so that it doesn't spit out content of my XML in an error message if the load fails.
$xml=@simplexml_load_file($xmlfile_path);
$child=$xml->children();
if($this->default_theme==$theme)
{
//check for active theme
$this->theme_box.= "\n".'<li>Active'."<br/>\n";
}
else
{
$this->theme_box.= '<li><a href="?thm='.$theme.'">Activate</a> | <a href="?del='.$theme.'">Delete</a>'."<br/>\n";
}
// load theme preview
$this->theme_box.= '<img src="'.$this->theme_url_path.$theme.'/'.$child->preview.'"/>'."<br/>\n";
$this->theme_box.= $child->name."<br/>\n";
$this->theme_box.= $child->version."<br/>\n";
$this->theme_box.= '<a href="mailto:'.$child->auther_contact.'">'.$child->auther.'</a>'."<br/>\n";
$this->theme_box.= '<a href="'.$child->auther_url.'">'.$child->auther_url.'</a>'."<br/>\n";
$this->theme_box.= $child->description."<br/>\n";
$this->theme_box.= $child->publish_date."</li>"."\n";
}
}
function delete_theme($theme)
{
// get theme dir
$theme=$this->return_root_dir().$this->base_dir."\\".$theme;
// check if dir exits
if (is_dir($theme))
{
// get dir handle
$dir_handle = opendir($theme);
while($file = readdir($dir_handle))
{
// break . and ..
if ($file != "." && $file != "..")
{
if (!is_dir($theme."/".$file))
unlink($theme."/".$file);
else
delete_directory($theme.'/'.$file);
}
}
closedir($dir_handle);
rmdir($theme);
return true;
}
else
{
return false;
}
}
}
?>