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

Smarty template browser 1.0 released

 
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
Subudhinath
Smarty Rookie


Joined: 24 Jul 2004
Posts: 11
Location: Finland

PostPosted: Fri Jul 30, 2004 12:01 am    Post subject: Smarty template browser 1.0 released Reply with quote

Makes all URI:s in templates absolute and converts all links to other .tpl-files quieries to parse through this script. A good interface between your own scripts and templates designed by a slightly lazy or not so technically advanced person.

Read description in the beginning of the code for more info.

Note! This script needs postfilter rel2abs:
http://www.phpinsider.com/smarty-forum/viewtopic.php?t=3114

[php:1:780a7c4cd3]<?php
/*
* Name of script: Smarty template browser 1.0 - released July 30, 2004
* Author: Simon Rönnqvist - http://ownmedia.net/products/
* NOTE! Filename must be: index.php
*
* Usage:
* Let's say you've got a web designer with little technical understanding making templates or
* that you're just fed up editing links in Smarty templates.
*
* This script converts all the relative URI:s to absolute ones, and also converts all the links
* to other .tpl files so that they'll be opened through this script. This way the web designer
* can go on designing pages just as he's used to and the only thing he needs to think about
* is to insert Smarty elements where he needs them.
*
* To make more use out of this you'll need to add your own code (see below) so that Smarty assigns
* some variables. It still works out of the box, so just go ahead and try it.
*
* Comments, questions, suggestions, improvements, implementations, etc.?
* Please let me know: simon(a t)ownmedia.net
*/

define('PATH', '/path/to/the/directory/of/the/script/'); //Document root
define('URI', 'http://domain.com/script/directory/'); //URI to document root

# If the directory containing Smarty.class.php isn't defined as an include_path in php.ini you need to define it here.
# Example: define("SMARTY_DIR","/enter/the/complete/path/like/this/");
define("SMARTY_DIR","");

require_once(SMARTY_DIR."Smarty.class.php");
require_once('postfilter.rel2abs.php'); //this postfilter is found at: http://ownmedia.net/products/

$SMARTY_LOCALDIR=PATH; //Here you can choose to have the Smarty-related directories elsewhere.
$smarty = new Smarty();
$smarty->template_dir = "{$SMARTY_LOCALDIR}/templates/";
$smarty->compile_dir = "{$SMARTY_LOCALDIR}/templates_c/";
$smarty->config_dir = "{$SMARTY_LOCALDIR}/configs/";
$smarty->cache_dir = "{$SMARTY_LOCALDIR}/cache/";



//Validates URI
$GLOBALS['valid_uri'] = eregi("^((http|https)://[[:alnum:].-]+\.[[:alpha:]]{2,4}(:[[:digit:]]{1,5})?)(/[[:alnum:]/+=%&_.~-]*)$", URI, $uri);
$GLOBALS['uri_nodomain'] = $uri[4]; //Extracts the part following the domain

$string = getenv("QUERY_STRING");

//Makes sure that nobody can access files other than .tpl files within the defined PATH.
if (ereg("^/", $string) || strstr($string, "..")) {
echo "You cannot access files in parent directories.";
exit;
} else {
$string = ereg_replace("/$", "", $string); //Removes possible ending / from $string
if ($string == "") {
$file=PATH."index.tpl"; //Views index.tpl as default
$GLOBALS['tpl_absuri'] = $uri_nodomain . "index";
} else {
$file=PATH.$string.".tpl"; //Generates the full path to the requested .tpl file
$GLOBALS['tpl_absuri'] = $uri_nodomain . $string;
}
}
/* * * YOUR OWN PHP CODE STARTS HERE * * */
# Here you'll find some suggested code which you should edit according to your needs.

if (!file_exists($file)) {
# Hint: Here you can make it look for a database entry too before giving in.
# i.e. /directory/template/database_entry
echo "The file $file does not exist";
exit;
} else {
# Here's some suggested code commented out
/*
//Code for all templates here

switch ($string) {
case 'template1':
//Code for "template1" here
break;
case 'directory/template2':
//Code for "template2" in "directory" here
break;
default:
//Code for all the others here
break;
}

//Code for all templates here
*/

# Finish by assigning variables for output
# Example: $smarty->assign("variable_in_template", $variable_in_your_php_code);
/* * * YOUR OWN PHP CODE ENDS HERE * * */

function quierify_tpluri($compiled, &$smarty) {
if ($GLOBALS['valid_uri'] == true) {
$compiled= eregi_replace("(<a href=\"(".URI."|".$GLOBALS['uri_nodomain']."))([[:alnum:]/+=%&_.~-]*)(\.tpl)", "\\1?\\3", $compiled);
} else {
$compiled="Please define a valid complete URI to the root CMS directory (i.e. http://domain.com/cms/)".$compiled;
}
return($compiled);
}

$smarty->register_postfilter('smarty_postfilter_rel2abs'); //Makes all links absolute
$smarty->register_postfilter('quierify_tpluri'); //Converts all links to .tpl files to quieries parsing them through this scritp
$smarty->display("file:$file");
}
?>[/php:1:780a7c4cd3]


Last edited by Subudhinath on Fri Jul 30, 2004 11:05 pm; edited 4 times in total
Back to top
View user's profile Send private message Visit poster's website
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