<?php
// +----------------------------------------------------------------------+
// | Fantastic File Database |
// +----------------------------------------------------------------------+
// | By Tony Baird |
// | Copyright (c) 2003 Fantastic Scripts |
// | http://fscripts.com |
// +----------------------------------------------------------------------+
// | Fantastic File Database Can be modified freely as long as copyright |
// | is intact and this is left at the top of every source file |
// +----------------------------------------------------------------------+
// | template.php |
// | Date Started: March 13, 2003 |
// | Last Modified: March 15, 2003 |
// +----------------------------------------------------------------------+
Class Template {
//*************************************************/
// Just seing what we are doing
//*************************************************/
function Template() {
global $tpl,$mysql,$ffdb,$CONFIG,$admin;
if ($_REQUEST['action']=="edit_templates") {
$this->SkinList();
}elseif ($_REQUEST['action']=="template_list") {
$this->TemplateList();
}elseif ($_REQUEST['action']=="edit_template_form") {
$this->EditTemplateForm();
}elseif (isset($_REQUEST['update_template'])) {
$this->UpdateTemplate();
}
}
//*************************************************/
// Skin List
//*************************************************/
function SkinList() {
global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin,$admin;
$tpl->LoadTemplate("skin_list","Admin/templates/$admin_skin/skin_list.tpl");
$mysql->Query("SELECT * FROM ffdb_skins WHERE skin_name!='default' ORDER BY skin_name");
while ($show_skin=mysql_fetch_array($mysql->result_id)) {
$has_skin=1;
$skin_list_array=Array(
'skin_name'=>$show_skin[skin_name],
'skin_directory'=>$show_skin[skin_directory],
'skin_id'=>$show_skin[skin_id]
);
$tpl->ParseTemplate("skin_list",$skin_list_array,"Yes");
}
if ($has_skin==1) {
$tpl->PrintTemplate("skin_list");
} else {
$admin->Error("There are currently no skins other than the default which you can't edit it's templates");
}
}
//*************************************************/
// Template List
//*************************************************/
function TemplateList() {
global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin;
$mysql->Query("SELECT * FROM ffdb_skins WHERE skin_id=".$_REQUEST['id']."");
$show_skin=mysql_fetch_array($mysql->result_id);
// Top for the template list
$tpl->LoadTemplate("template_list_top","Admin/templates/$admin_skin/template_list_top.tpl");
$tpl->ParseTemplate("template_list_top",$template_list_top_array,"No");
$tpl->PrintTemplate("template_list_top");
$this->GetTemplates($CONFIG['templates_path'].$show_skin[skin_directory],$show_skin[skin_id]);
$tpl->LoadTemplate("template_list_bottom","Admin/templates/$admin_skin/template_list_bottom.tpl");
$tpl->ParseTemplate("template_list_bottom",$template_list_bottom_array,"No");
$tpl->PrintTemplate("template_list_bottom");
}
//*************************************************/
// Gets the templates and makes the list
//*************************************************/
function GetTemplates($dir, $skin_id) {
global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin;
$tpl->LoadTemplate("template_list","Admin/templates/$admin_skin/template_list.tpl");
$d = dir($dir);
$template_files = array();
while (false != ($file = $d->read())) {
if (preg_match("/.tpl/",$file)) {
$file=preg_replace("/.tpl/","",$file);
$template_list_array=Array(
'filename'=>$file,
'skin_id'=>$skin_id
);
$tpl->ParseTemplate("template_list",$template_list_array,"Yes");
}
}
$d->close();
$tpl->PrintTemplate("template_list");
}
//*************************************************/
// Gets the templates and makes the list
//*************************************************/
function EditTemplateForm() {
global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin;
$mysql->Query("SELECT * FROM ffdb_skins WHERE skin_id=".$_REQUEST['id']."");
$show_skin=mysql_fetch_array($mysql->result_id);
$tpl->LoadTemplate("edit_template_form","Admin/templates/$admin_skin/edit_template_form.tpl");
$filename=fopen($CONFIG['templates_path'].$show_skin[skin_directory]."/".$_REQUEST['template'].".tpl","r+"); $template_text=fread($filename,filesize($CONFIG['templates_path'].$show_skin[skin_directory]."/".$_REQUEST['template'].".tpl"));
$template_text=stripslashes($template_text);
$template_text=HTMLSpecialChars($template_text);
$edit_template_form_array=Array(
'template'=>$_REQUEST['template'],
'skin_id'=>$_REQUEST['id'],
'template_text'=>$template_text
);
$tpl->ParseTemplate("edit_template_form",$edit_template_form_array,"No");
$tpl->PrintTemplate("edit_template_form");
}
//*************************************************/
// Updates Template Page
//*************************************************/
function UpdateTemplate() {
global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin,$admin;
$_POST['template_text']=stripslashes($_POST['template_text']);
$mysql->Query("SELECT * FROM ffdb_skins WHERE skin_id=".$_REQUEST['id']."");
$show_skin=mysql_fetch_array($mysql->result_id);
$this->SaveTemplate($CONFIG['templates_path'].$show_skin[skin_directory]."/".$_REQUEST['template'].".tpl",$_POST['template_text']);
$admin->Success("Template updated successfully");
}
//*************************************************/
// Saves new template to it's file
//*************************************************/
function SaveTemplate($file,$text) {
global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin;
if ($template_file=fopen($file,"w+")) {
if(!fwrite($template_file,$text)) {
$admin->Error("Failed to write to file");
}
} else {
$admin->Error("Failed to open file");
}
}
}
?>