السلام عليكم ..
امس قمت بكتابة كلاس بسيط خاص بـ Smarty .
هذا الكلاس يستخدم لعرض اسماء القوالب الموجوده في مجلد معين , و يمكنك تحرير قالب من خلال لوحة تحكم السكربت و اخيراً يمكنك اضافة قالب .
شيفرة الكلاس :
مثال لاستخدامه :كود PHP:
<?php
/*
*************************************************************************
* This class written by : MaaSTaaR <MaaSTaaR(at)hotmail.com>
*
* You can control in template with Smarty : [url]http://smarty.php.net[/url]
*
* Version : 1.0.0
*
* License : GNU GPL <[url]http://www.opensource.org/licenses/gpl-license.php[/url]>
*************************************************************************
*/
class STControl {
var $tdir; #Template dir
var $mainpath; #main file path
var $editpath; #edit file path
var $addpath; #add file path
var $starteditpath; #start edit file path
var $defualtex; #defualt extension .. example (.tpl)
/*
GetTemplate :
this function get template name and put it in list
*/
function GetTemplate() {
if (is_dir($this->tdir)) {
if ($dh = opendir($this->tdir)) {
echo '<form method="POST" action="' . $this->editpath . '">';
echo '<select size="1" name="D1" style="font-family: Tahoma; font-size: 10pt">';
while (($file = readdir($dh)) !== false) {
echo '<option value="' . $file . '">' . $file . '</option>';;
}
echo '</select><input type="submit" value="ÇÐåÈ" name="B1" style="font-family: Tahoma; font-size: 8pt">';
closedir($dh);
}
}
}
/*
EditTemplate :
edit form get one parameter and usualy it $D1 , this parameter = file name
*/
function EditTemplate($D1) {
$check = explode(".",$D1);
if (empty($check[1])) {
$this->msg_die("ÇáÇÎÊíÇÑ ÎÇØÆ");
}
$fp = file($this->tdir . $D1);
$ln = count($fp);
echo '<form method="POST" action="' . $this->starteditpath . '&filename=' . $D1 .'">';
echo '<p align="center"><textarea rows="10" name="S1" cols="56" dir="ltr" style="font-family: Tahoma; font-size: 10pt">';
for ($i=0;$i<=$ln;$i++) {
echo $fp[$i];
}
echo '</textarea>';
echo '<br><input type="submit" value="ãæÇÝÞ" name="B1" style="font-family: Tahoma; font-size: 8pt"></p>';
}
/*
StartEdit :
this function will change template code and get one parameter , it is usualy $S1
and $S1 = template code
*/
function StartEdit($S1) {
global $filename;
$S1 = stripslashes($S1);
$fp = fopen($this->tdir . $filename,'w+');
$fw = fwrite($fp,$S1);
if ($fw) {
$this->msg("Êã ÈäÌÇÍ !");
$this->goto($this->mainpath,'2');
}
}
/*
AddTemplate :
this function will show add form
*/
function AddTemplate() {
echo '<p align="center"><font face="Tahoma" size="2">ÇÓã ÇáÞÇáÈ : </font><form method="POST" action="' . $this->addpath . '"></p>';
echo '<p align="center"><input name="T1" type="text" style="font-family: Tahoma; font-size: 8pt">';
echo '<p align="center"><textarea rows="10" name="S1" cols="56" dir="ltr" style="font-family: Tahoma; font-size: 10pt">';
echo '</textarea>';
echo '<br><input type="submit" value="ãæÇÝÞ" name="B1" style="font-family: Tahoma; font-size: 8pt"></p>';
}
/*
StartAdd :
this function will add template
*/
function StartAdd() {
global $T1,$S1;
$S1 = stripslashes($S1);
$fp = fopen($this->tdir . $T1 . $this->defualtex,'w');
$fw = fwrite($fp,$S1);
if ($fw) {
$this->msg("Êã ÈäÌÇÍ !");
$this->goto($this->mainpath,'2');
}
}
function msg_die($msg) {
die('<p align="center" dir="rtl">' . $msg . '</p>');
}
function msg($msg) {
echo('<p align="center" dir="rtl">' . $msg . '</p>');
}
function goto($site,$m) {
echo "<META HTTP-EQUIV=\"refresh\" CONTENT=\"$m; URL=$site\">\n";
}
}
?>
كود PHP:
<?php
include("includes/STControl.php");
$STC = new STControl;
$STC->tdir = "style/template/";
$STC->mainpath = "test.php?action=index";
$STC->defualtex = ".tpl";
if (empty($action)) { $action = "index"; }
if ($action == "index") {
$STC->editpath = "test.php?action=show";
$STC->GetTemplate();
}
if ($action == "show") {
$STC->starteditpath = "test.php?action=startedit";
$STC->EditTemplate($D1);
}
if ($action == "startedit") {
$STC->StartEdit($S1);
}
if ($action == "add") {
$STC->addpath = "test.php?action=startadd";
$STC->AddTemplate();
}
if ($action == "startadd") {
$STC->StartAdd();
}
?>
تحياتي