Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

[STControl] Smarty Template Control

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Add-ons
View previous topic :: View next topic  
Author Message
MaaSTaaR
Smarty Rookie


Joined: 08 Oct 2004
Posts: 8

PostPosted: Fri Oct 08, 2004 7:47 pm    Post subject: [STControl] Smarty Template Control Reply with quote

Hello all ..

yesterday i written simple class for smarty template .

this class used to show template name , and can you edit template from script control panel , finally can you add template .

you understand me Wink

class source code :

[php:1:75f65c1183]<?php
/*
*************************************************************************
* This class written by : MaaSTaaR <MaaSTaaR(at)hotmail.com>
*
* You can control in template with Smarty : http://smarty.php.net
*
* Version : 1.0.0
*
* License : GNU GPL <http://www.opensource.org/licenses/gpl-license.php>
*************************************************************************
*/

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="Go!" 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("Error select");
}
$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="Submit" 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("Success action");
$this->goto($this->mainpath,'2');
}
}
/*
AddTemplate :
this function will show add form
*/
function AddTemplate() {
echo '<p align="center"><font face="Tahoma" size="2">Template name : </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="Submit" 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("Success action");
$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:1:75f65c1183]

example use this class :
[php:1:75f65c1183]<?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();
}
?>[/php:1:75f65c1183]

thanks for all Rolling Eyes
Back to top
View user's profile Send private message
bokhalifa
Smarty n00b


Joined: 05 Oct 2004
Posts: 4

PostPosted: Mon Oct 11, 2004 3:27 pm    Post subject: Reply with quote

good work Smile
Back to top
View user's profile Send private message Send e-mail
MaaSTaaR
Smarty Rookie


Joined: 08 Oct 2004
Posts: 8

PostPosted: Mon Oct 11, 2004 3:42 pm    Post subject: Reply with quote

bokhalifa wrote:
good work Smile


thanks bokhalifa Embarassed
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Add-ons All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP