[Openupload-svn-update] SF.net SVN: openupload:[10] trunk/lib
Status: Beta
Brought to you by:
tsdogs
|
From: <ts...@us...> - 2008-10-15 14:02:22
|
Revision: 10
http://openupload.svn.sourceforge.net/openupload/?rev=10&view=rev
Author: tsdogs
Date: 2008-10-15 13:58:01 +0000 (Wed, 15 Oct 2008)
Log Message:
-----------
First svn commit
Added Paths:
-----------
trunk/lib/modules/auth/
trunk/lib/modules/auth/default.inc.php
trunk/lib/modules/db/
trunk/lib/modules/default/
trunk/lib/modules/default/admin.inc.php
trunk/lib/modules/default/auth.inc.php
trunk/lib/modules/default/files.inc.php
trunk/lib/modules/tr/
trunk/lib/modules/tr/array.inc.php
trunk/lib/modules/tr/gettext.inc.php
trunk/lib/smarty/Config_File.class.php
trunk/lib/smarty/Smarty.class.php
trunk/lib/smarty/Smarty_Compiler.class.php
trunk/lib/smarty/debug.tpl
Added: trunk/lib/modules/auth/default.inc.php
===================================================================
--- trunk/lib/modules/auth/default.inc.php (rev 0)
+++ trunk/lib/modules/auth/default.inc.php 2008-10-15 13:58:01 UTC (rev 10)
@@ -0,0 +1,31 @@
+<?php
+/* use the db to Authenticate users */
+class defaultAuth extends authBase {
+
+ function defaultAuth() {
+ }
+
+ function init() {
+ $this->db = app()->db;
+ }
+
+ function authenticate($login,$password) {
+ $res = $this->db->queryUser($login);
+ //echo crypt($password); exit;
+ if ($res['login']==$login and crypt($password,$res['password'])==$res['password']) {
+ return true;
+ }
+ return false;
+ }
+
+ function userInfo($login) {
+ $result = $this->db->queryUser($login);
+ return $result;
+ }
+
+ function addUser($user) {
+ $user['password']=crypt($user['password']);
+ $this->db->addUser($user);
+ }
+}
+?>
\ No newline at end of file
Added: trunk/lib/modules/default/admin.inc.php
===================================================================
--- trunk/lib/modules/default/admin.inc.php (rev 0)
+++ trunk/lib/modules/default/admin.inc.php 2008-10-15 13:58:01 UTC (rev 10)
@@ -0,0 +1,66 @@
+<?php
+
+class AdminModule extends OpenUploadModule {
+var $actions = array (
+ "admin" => array (
+ 1 => "admin",
+ ),
+ "adminsettings" => array (
+ 1 => "settings",
+ ),
+ "adminplugins" => array (
+ 1 => "plugins",
+ ),
+ "adminfiles" => array (
+ 1 => "files",
+ ),
+ "adminusers" => array (
+ 1 => "users",
+ ),
+ "admingroups" => array (
+ 1 => "groups",
+ ),
+ "adminrights" => array (
+ 1 => "rights",
+ ),
+ );
+
+var $page;
+
+ function AdminModule() {
+ $this->menu = array (
+ "admin" => tr("Administration"),
+ );
+ foreach ($this->actions as $a => $v) {
+ $this->page[$a] = array ("title" => tr("Administration"));
+ }
+ }
+
+ function init() {
+ /* only if the user has admin privileges let it see the module */
+
+ }
+
+ function admin() {
+ }
+
+ function users() {
+ }
+
+ function groups() {
+ }
+
+ function rights() {
+ }
+
+ function files() {
+ }
+
+ function plugins() {
+ }
+
+ function settings() {
+ }
+
+}
+?>
\ No newline at end of file
Added: trunk/lib/modules/default/auth.inc.php
===================================================================
--- trunk/lib/modules/default/auth.inc.php (rev 0)
+++ trunk/lib/modules/default/auth.inc.php 2008-10-15 13:58:01 UTC (rev 10)
@@ -0,0 +1,149 @@
+<?php
+
+class AuthModule extends OpenUploadModule {
+var $actions = array (
+ "login" => array (
+ 1 => "loginForm",
+ 2 => "authenticate",
+ ),
+ "logout" => array (
+ 1 => "logout",
+ ),
+ "register" => array (
+ 1 => "registerForm",
+ 2 => "registerConfirm",
+ ),
+ );
+var $page;
+
+ function AuthModule() {
+ $this->page = array (
+ "login" => array (
+ "title" => tr("Login"),
+ ),
+ "register" => array (
+ "title" => tr("User registration"),
+ ),
+ );
+ }
+
+ function init() {
+ if (!app()->user->loggedin()) {
+ $this->menu['login']=tr('Login');
+ } else {
+ $this->menu['logout']=tr('Logout');
+ }
+ $this->tpl->assign('register',app()->checkACL(app()->user->userGroup(),'auth','register')=='allow');
+ }
+
+
+ function loginForm() {
+
+ /* disable login option link */
+ $this->tpl->assign('login',false);
+ $this->page['title']='Login';
+
+ $finfo = array();
+ app()->pluginAction('loginForm',$finfo,false);
+ //app()->mainPage = 'login';
+ }
+
+ function authenticate() {
+ if (!app()->user->authenticate()) {
+ app()->user->logout();
+ return false; /* never reached */
+ }
+ $finfo = array();
+ $result = app()->pluginAction('authenticate',$finfo,true);
+ if (!$result) { /* plugins forced a logout */
+ app()->user->logout();
+ return false; /* never reached */
+ }
+ /* authentication was successfull */
+ redirect();
+ }
+
+ function logout() {
+ app()->user->logout();
+ }
+
+ function registerForm() {
+ global $_SESSION;
+ global $_POST;
+
+ /* ask the plugins if require more options */
+ $result = app()->pluginAction('registerForm',$user);
+ if (!$result) {
+ /* some plugin disabled the registration */
+ redirect();
+ }
+ $this->tpl->assign('register',$_SESSION['register']);
+ }
+
+ function registerConfirm() {
+ global $_SESSION;
+ global $_POST;
+
+ if (isset($_POST['registerlogin'])) {
+ /* check for the unique login */
+ $u = app()->auth->userInfo($_POST['registerlogin']);
+ if ($u['login']!='') {
+ app()->error(tr('Username already taken, choose a new value'));
+ $failed = true;
+ }
+ if (strlen($_POST['registerlogin'])<5) {
+ app()->error(tr('Login name must be at least 5 characters long!'));
+ }
+ if ($_POST['registername']=='') {
+ app()->error(tr('Please insert Full Name'));
+ $failed = true;
+ }
+ if ($_POST['registeremail']=='' or !validEmail($_POST['registeremail'])) {
+ app()->error(tr('Please insert a valid e-mail!'));
+ $failed = true;
+ }
+ if (strlen(trim($_POST['registerpassword']))<5) {
+ app()->error(tr('Password must be at least 5 characters long!'));
+ $failed = true;
+ }
+ if ($_POST['registerpassword']!=$_POST['registerrepassword']) {
+ app()->error(tr('Passwords do not match! please retype.'));
+ $failed = true;
+ }
+ $user['login'] = $_POST['registerlogin'];
+ $user['name'] = $_POST['registername'];
+ $user['password'] = $_POST['registerpassword'];
+ $user['email'] = $_POST['registeremail'];
+ $user['group_id'] = app()->config['register']['default_group'];
+ $user['active'] = 1;
+ $result = app()->pluginAction('registerConfirm',$user);
+ $_SESSION['register']=$user;
+ unset($_SESSION['register']['password']);
+ if (!$result) {
+ $fauled = true;
+ }
+ if ($failed)
+ $this->prevStep(1); /* back to registration form */
+ app()->auth->addUser($user);
+ } else {
+ $this->prevStep(1); /* back to registration form */
+ }
+ unset($_SESSION['register']);
+ /* ask the plugins if require more options */
+ if ($user['active']=='1') {
+ app()->message(tr('Registration completed successfully. Have fun!'));
+ $_POST['username'] = $user['login'];
+ $_POST['pwd'] = $user['password'];
+ /* simulate the user login and proceed */
+ unset($_SESSION['user']);
+ $this->authenticate();
+ }
+ }
+
+ function registerEnable() {
+ /* if everything is ok register the user */
+
+ }
+
+}
+?>
\ No newline at end of file
Added: trunk/lib/modules/default/files.inc.php
===================================================================
--- trunk/lib/modules/default/files.inc.php (rev 0)
+++ trunk/lib/modules/default/files.inc.php 2008-10-15 13:58:01 UTC (rev 10)
@@ -0,0 +1,291 @@
+<?php
+
+class FilesModule extends OpenUploadModule {
+var $actions = array (
+ "u" => array (
+ 1 => "uploadForm",
+ 2 => "uploadOptions",
+ 3 => "uploadConfirm",
+ 4 => "uploadFileInfo",
+ ),
+ "d" => array (
+ 1 => "downloadForm",
+ 2 => "downloadRequest",
+ 3 => "downloadConfirm",
+ ),
+ "g" => array (
+ 1 => "serveFile",
+ ),
+ "r" => array (
+ 1 => "removeRequest",
+ 2 => "removeConfirm",
+ 3 => "removeResult",
+ ),
+ );
+var $page;
+var $menu;
+
+ function FilesModule() {
+ $this->page = array (
+ "u" => array (
+ "title" => tr("File upload"),
+ ),
+ "d" => array (
+ "title" => tr("File download"),
+ ),
+ "r" => array (
+ "title" => tr("File Removal"),
+ ),
+ );
+ $this->menu = array (
+ "u" => tr("File Upload"),
+ //"d" => tr("File Download"),
+ //"r" => tr("File Removal"),
+ );
+
+ }
+
+ function init() {
+ /* initialize */
+ }
+
+ /* real implementation */
+
+ function uploadForm() {
+ global $_SESSION;
+
+ unset($_SESSION['user']['u']);
+ $result = app()->pluginAction('uploadForm',$finfo);
+ }
+
+ function uploadOptions() {
+ global $_SESSION;
+ global $_FILES;
+
+ if (isset($_FILES['upload'])) {
+ /* prepare the file */
+ $tmpname = app()->config['DATA_PATH'].'/tmp/'.randomName();
+ move_uploaded_file($_FILES['upload']['tmp_name'],$tmpname);
+ $_SESSION['user']['u']['tmp']=$tmpname;
+ $_SESSION['user']['u']['mime']=$_FILES['upload']['type'];
+ $_SESSION['user']['u']['name']=$_FILES['upload']['name'];
+ $_SESSION['user']['u']['size']=$_FILES['upload']['size'];
+ $this->nextStep(app()->step);
+ } else if (!isset($_SESSION['user']['u'])) {
+ redirect();
+ }
+ $result = app()->pluginAction('uploadOptions',$_SESSION['user']['u']);
+ if (!$result) { /* some plugin blocked the upload */
+ /* remove the file */
+ redirect();
+ }
+ $this->tpl->assign('finfo',$_SESSION['user']['u']);
+ /* ask for information on the file */
+ }
+
+ function uploadConfirm() {
+ global $_POST;
+ global $_SESSION;
+
+ /* save the file */
+ /* send an e-mail if requested */
+ /* display the information on the upload */
+ if (isset($_POST['description'])) {
+ /* move the file to the actual location */
+ $finfo = $_SESSION['user']['u'];
+ $finfo['description'] = $_POST['description'];
+ /* now check plugins and if ok add file otherwise redirect */
+ $result = app()->pluginAction('uploadConfirm',$finfo);
+ if (!$result)
+ $this->prevStep();
+ /* everything ok then add the file */
+ $finfo['id']= app()->db->newFileId();
+ $finfo['remove']= app()->db->newFileId('remove');
+ app()->db->addFile($finfo);
+ foreach (app()->plugins as $plugin) {
+ if (count($plugin->fields)>0) {
+ foreach ($plugin->fields as $f) {
+ app()->db->addFileOption($finfo,$plugin->name,$f);
+ }
+ }
+ }
+ rename($_SESSION['user']['u']['tmp'],app()->config['DATA_PATH'].'/'.$finfo['id']);
+ $_SESSION['user']['u']=$finfo;
+ $this->nextStep();
+ }
+ }
+
+ function uploadFileInfo() {
+ if (isset($_SESSION['user']['u']['id'])) {
+ $finfo = $_SESSION['user']['u'];
+ /* get the file info */
+ $finfo['downloadlink']= app()->config['WWW_SERVER'].app()->config['WWW_ROOT'].'/?action=d&id='.$finfo['id'];
+ $finfo['removelink']= app()->config['WWW_SERVER'].app()->config['WWW_ROOT'].'/?action=r&id='.$finfo['id'].'&removeid='.$finfo['remove'];
+ $result = app()->pluginAction('uploadFileInfo',$finfo,false);
+ $this->tpl->assign('finfo',$finfo);
+ $this->tpl->assign('webbase',app()->config['WWW_SERVER'].app()->config['WWW_ROOT']);
+ } else {
+ redirect();
+ }
+ }
+
+ function downloadForm() {
+ global $_SESSION;
+ global $_GET;
+
+ unset($_SESSION['user']['d']);
+ if (isset($_GET['id'])) {
+ $_SESSION['user']['d']['id'] = $_GET['id'];
+ $this->nextStep();
+ }
+ $finfo = array();
+ app()->pluginAction('downloadForm',$finfo,false);
+ }
+
+ function downloadRequest() {
+ global $_GET;
+ global $_SESSION;
+
+ $id = '';
+ if (isset($_POST['id'])) {
+ $id = $_POST['id'];
+ } else if (isset($_SESSION['user']['d']['id'])) {
+ $id = $_SESSION['user']['d']['id'];
+ }
+ /* check if download exsists, and what are the properties */
+ if ($id != '') {
+ $finfo = app()->db->getFileInfo($id);
+ if ($finfo['id']!=$id) {
+ app()->error(tr('Requested file does not exsist!'));
+ $this->prevStep();
+ } else {
+ $_SESSION['user']['d']=$finfo;
+ $this->tpl->assign('finfo',$finfo);
+ $result = app()->pluginAction('downloadRequest',$finfo,false);
+ if ($result) {
+ $this->nextStep();
+ }
+ }
+ }
+ }
+
+ function downloadConfirm() {
+
+ /* here we do the actual download of the file */
+ if (!isset($_SESSION['user']['d'])) {
+ redirect();
+ } else if ($_SESSION['user']['d']['candownload']=='ok') {
+ $finfo = $_SESSION['user']['d'];
+ $this->tpl->assign('finfo',$finfo);
+ /* download is allowed */
+ } else {
+ $finfo = $_SESSION['user']['d'];
+ /* check wether the plugins are ok */
+ $result = app()->pluginAction('downloadConfirm',$finfo);
+ if (!$result)
+ $this->prevStep();
+ $_SESSION['user']['d']=$finfo;
+ $_SESSION['user']['d']['candownload']='ok';
+ /* now the user can download it */
+ $this->nextStep(app()->step);
+ }
+ }
+
+ function serveFile() {
+ global $_SESSION;
+ global $_POST;
+
+ /* here we do the actual download of the file */
+ if (!isset($_SESSION['user']['d'])) {
+ redirect();
+ } else if ($_SESSION['user']['d']['candownload']!='ok') {
+ $this->nextStep(2,'d');
+ } else {
+ $finfo = $_SESSION['user']['d'];
+ /* check wether the plugins are ok */
+ $result = app()->pluginAction('serveFile',$finfo);
+ if (!$result)
+ $this->nextStep(3,'d');
+ $_SESSION['user']['d']['candownload']='ok';
+ /* if we got this far the download should begin serving */
+ $file = app()->config['DATA_PATH'].'/'.$finfo['id'];
+ $filesize = filesize($file);
+ ob_clean();
+ header('Content-Type: '.$finfo['mime']);
+ header('Content-Length: '.$filesize);
+ header('Content-Disposition: attachment; filename="'.$finfo['name'].'"');
+ readfile($file);
+ /* file should have been sent now let's reset the download info */
+ $_SESSION['user']['d']['candownload']='ko';
+ exit(0);
+ }
+ }
+
+ function removeRequest() {
+ global $_GET;
+ global $_SESSION;
+
+ $id = '';
+ if (isset($_GET['id'])) {
+ $id = $_GET['id'];
+ } else if (isset($_SESSION['user']['r']['id'])) {
+ $id = $_SESSION['user']['r']['id'];
+ }
+ /* check if download exsists, and what are the properties */
+ if ($id != '') {
+ $finfo = app()->db->getFileInfo($id);
+ if ($finfo['id']!=$id) {
+ app()->error(tr('Wrong file id!'));
+ redirect();
+ } else if ($_GET['removeid']!=$finfo['remove']) {
+ app()->error(tr('Wrong file id!')); /* don't give the user much info on this */
+ redirect();
+ } else {
+ $_SESSION['user']['r']=$finfo;
+ $this->tpl->assign('finfo',$finfo);
+ $result = app()->pluginAction('removeRequest',$finfo,false);
+ if (!$result) {
+ redirect();
+ }
+ }
+ } else {
+ app()->error(tr('Wrong file id!'));
+ redirect();
+ }
+ }
+
+ function removeConfirm() {
+ $finfo = $_SESSION['user']['r'];
+
+ /* here we do the actual download of the file */
+ if (!isset($_SESSION['user']['r'])) {
+ redirect();
+ } else {
+ $finfo = $_SESSION['user']['r'];
+ /* check wether the plugins are ok */
+ $result = app()->pluginAction('removeConfirm',$finfo);
+ if (!$result)
+ $this->prevStep();
+ /* now we can remove the file */
+ app()->db->removeFile($finfo['id']);
+ $file = app()->config['DATA_PATH'].'/'.$finfo['id'];
+ unlink($file);
+ /* display removal confirmation */
+ $this->nextStep();
+ }
+ }
+
+ function removeResult() {
+ if (!isset($_SESSION['user']['r'])) {
+ redirect();
+ } else {
+ $finfo = $_SESSION['user']['r'];
+ $result = app()->pluginAction('removeResult',$finfo,false);
+ $this->tpl->assign('finfo',$finfo);
+ unset($_SESSION['user']['r']); /* remove any file reference */
+ }
+ }
+
+}
+
+?>
\ No newline at end of file
Added: trunk/lib/modules/tr/array.inc.php
===================================================================
--- trunk/lib/modules/tr/array.inc.php (rev 0)
+++ trunk/lib/modules/tr/array.inc.php 2008-10-15 13:58:01 UTC (rev 10)
@@ -0,0 +1,56 @@
+<?php
+
+/* simple array translation */
+
+class ArrayTranslator extends translatorBase {
+var $update = false;
+var $TR;
+
+ function ArrayTranslator() {
+ }
+
+ function init() {
+ $locale = app()->user->userInfo('lang');
+ $lang = app()->db->getLang($locale);
+ $tr = array();
+ $this->files['openupload']=app()->config['INSTALL_ROOT'].'/locale/'.$lang['id'].'.inc.php';
+ if (file_exists($this->files['openupload'])) {
+ require_once($this->files['openupload']);
+ $this->TR['openupload']=$tr;
+ }
+ $tr = array();
+ $this->files['template']=app()->config['INSTALL_ROOT'].'/templates/'.app()->config['site']['template'].'/locale/'.$lang['id'].'.inc.php';
+ if (file_exists($this->files['template'])) {
+ require_once($this->files['template']);
+ $this->TR['template']=$tr;
+ }
+ /* setup page encoding */
+ if (isset($lang['charset']))
+ header('Content-Type: text/html; charset='.$lang['charset']);
+ }
+
+
+ function translate($txt,$domain = 'openupload') {
+
+ if (isset($this->TR[$domain][$txt])) {
+ return $this->TR[$domain][$txt];
+ } else {
+ if ($this->update) {
+ /* add the translation to the file */
+ $f = @fopen($this->files[$domain],'w+');
+ if ($f) {
+ fwrite($f,'<?php'."\n");
+ foreach ($this->TR[$domain] as $k => $v) {
+ fwrite($f,'$tr[\''.str_replace("'","\'",$k).'\']=\''.str_replace("'","\'",$v).'\';'."\n");
+ }
+ fwrite($f,'$tr[\''.str_replace("'","\'",$txt).'\']=\''.str_replace("'","\'",$txt).'\';'."\n");
+ fwrite($f,'?>');
+ fclose($f);
+ $this->TR[$domain][$txt]=$txt;
+ }
+ }
+ return $txt;
+ }
+ }
+}
+?>
\ No newline at end of file
Added: trunk/lib/modules/tr/gettext.inc.php
===================================================================
--- trunk/lib/modules/tr/gettext.inc.php (rev 0)
+++ trunk/lib/modules/tr/gettext.inc.php 2008-10-15 13:58:01 UTC (rev 10)
@@ -0,0 +1,28 @@
+<?php
+
+/* gettext translation module */
+
+class GettextTranslator extends translatorBase {
+
+ function GetTextTranslator() {
+ }
+
+ function init() {
+ $locale = app()->user->userInfo('lang');
+ $lang = app()->db->getLang($locale);
+ putenv("LANG=".$lang['locale']);
+ bindtextdomain('openupload',app()->config['INSTALL_ROOT'].'/locale');
+ bindtextdomain('template',app()->config['INSTALL_ROOT'].'/templates/'.app()->config['site']['template'].'/locale');
+ setlocale(LC_ALL,$lang['locale']);
+ /* setup page encoding */
+ if (isset($lang['charset']))
+ header('Content-Type: text/html; charset='.$lang['charset']);
+ }
+
+
+ function translate($txt,$domain = 'openupload') {
+ textdomain($domain);
+ return gettext($txt);
+ }
+}
+?>
\ No newline at end of file
Added: trunk/lib/smarty/Config_File.class.php
===================================================================
--- trunk/lib/smarty/Config_File.class.php (rev 0)
+++ trunk/lib/smarty/Config_File.class.php 2008-10-15 13:58:01 UTC (rev 10)
@@ -0,0 +1,389 @@
+<?php
+
+/**
+ * Config_File class.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * @link http://smarty.php.net/
+ * @version 2.6.20
+ * @copyright Copyright: 2001-2005 New Digital Group, Inc.
+ * @author Andrei Zmievski <an...@ph...>
+ * @access public
+ * @package Smarty
+ */
+
+/* $Id: Config_File.class.php 2702 2007-03-08 19:11:22Z mohrt $ */
+
+/**
+ * Config file reading class
+ * @package Smarty
+ */
+class Config_File {
+ /**#@+
+ * Options
+ * @var boolean
+ */
+ /**
+ * Controls whether variables with the same name overwrite each other.
+ */
+ var $overwrite = true;
+
+ /**
+ * Controls whether config values of on/true/yes and off/false/no get
+ * converted to boolean values automatically.
+ */
+ var $booleanize = true;
+
+ /**
+ * Controls whether hidden config sections/vars are read from the file.
+ */
+ var $read_hidden = true;
+
+ /**
+ * Controls whether or not to fix mac or dos formatted newlines.
+ * If set to true, \r or \r\n will be changed to \n.
+ */
+ var $fix_newlines = true;
+ /**#@-*/
+
+ /** @access private */
+ var $_config_path = "";
+ var $_config_data = array();
+ /**#@-*/
+
+ /**
+ * Constructs a new config file class.
+ *
+ * @param string $config_path (optional) path to the config files
+ */
+ function Config_File($config_path = NULL)
+ {
+ if (isset($config_path))
+ $this->set_path($config_path);
+ }
+
+
+ /**
+ * Set the path where configuration files can be found.
+ *
+ * @param string $config_path path to the config files
+ */
+ function set_path($config_path)
+ {
+ if (!empty($config_path)) {
+ if (!is_string($config_path) || !file_exists($config_path) || !is_dir($config_path)) {
+ $this->_trigger_error_msg("Bad config file path '$config_path'");
+ return;
+ }
+ if(substr($config_path, -1) != DIRECTORY_SEPARATOR) {
+ $config_path .= DIRECTORY_SEPARATOR;
+ }
+
+ $this->_config_path = $config_path;
+ }
+ }
+
+
+ /**
+ * Retrieves config info based on the file, section, and variable name.
+ *
+ * @param string $file_name config file to get info for
+ * @param string $section_name (optional) section to get info for
+ * @param string $var_name (optional) variable to get info for
+ * @return string|array a value or array of values
+ */
+ function get($file_name, $section_name = NULL, $var_name = NULL)
+ {
+ if (empty($file_name)) {
+ $this->_trigger_error_msg('Empty config file name');
+ return;
+ } else {
+ $file_name = $this->_config_path . $file_name;
+ if (!isset($this->_config_data[$file_name]))
+ $this->load_file($file_name, false);
+ }
+
+ if (!empty($var_name)) {
+ if (empty($section_name)) {
+ return $this->_config_data[$file_name]["vars"][$var_name];
+ } else {
+ if(isset($this->_config_data[$file_name]["sections"][$section_name]["vars"][$var_name]))
+ return $this->_config_data[$file_name]["sections"][$section_name]["vars"][$var_name];
+ else
+ return array();
+ }
+ } else {
+ if (empty($section_name)) {
+ return (array)$this->_config_data[$file_name]["vars"];
+ } else {
+ if(isset($this->_config_data[$file_name]["sections"][$section_name]["vars"]))
+ return (array)$this->_config_data[$file_name]["sections"][$section_name]["vars"];
+ else
+ return array();
+ }
+ }
+ }
+
+
+ /**
+ * Retrieves config info based on the key.
+ *
+ * @param $file_name string config key (filename/section/var)
+ * @return string|array same as get()
+ * @uses get() retrieves information from config file and returns it
+ */
+ function &get_key($config_key)
+ {
+ list($file_name, $section_name, $var_name) = explode('/', $config_key, 3);
+ $result = &$this->get($file_name, $section_name, $var_name);
+ return $result;
+ }
+
+ /**
+ * Get all loaded config file names.
+ *
+ * @return array an array of loaded config file names
+ */
+ function get_file_names()
+ {
+ return array_keys($this->_config_data);
+ }
+
+
+ /**
+ * Get all section names from a loaded file.
+ *
+ * @param string $file_name config file to get section names from
+ * @return array an array of section names from the specified file
+ */
+ function get_section_names($file_name)
+ {
+ $file_name = $this->_config_path . $file_name;
+ if (!isset($this->_config_data[$file_name])) {
+ $this->_trigger_error_msg("Unknown config file '$file_name'");
+ return;
+ }
+
+ return array_keys($this->_config_data[$file_name]["sections"]);
+ }
+
+
+ /**
+ * Get all global or section variable names.
+ *
+ * @param string $file_name config file to get info for
+ * @param string $section_name (optional) section to get info for
+ * @return array an array of variables names from the specified file/section
+ */
+ function get_var_names($file_name, $section = NULL)
+ {
+ if (empty($file_name)) {
+ $this->_trigger_error_msg('Empty config file name');
+ return;
+ } else if (!isset($this->_config_data[$file_name])) {
+ $this->_trigger_error_msg("Unknown config file '$file_name'");
+ return;
+ }
+
+ if (empty($section))
+ return array_keys($this->_config_data[$file_name]["vars"]);
+ else
+ return array_keys($this->_config_data[$file_name]["sections"][$section]["vars"]);
+ }
+
+
+ /**
+ * Clear loaded config data for a certain file or all files.
+ *
+ * @param string $file_name file to clear config data for
+ */
+ function clear($file_name = NULL)
+ {
+ if ($file_name === NULL)
+ $this->_config_data = array();
+ else if (isset($this->_config_data[$file_name]))
+ $this->_config_data[$file_name] = array();
+ }
+
+
+ /**
+ * Load a configuration file manually.
+ *
+ * @param string $file_name file name to load
+ * @param boolean $prepend_path whether current config path should be
+ * prepended to the filename
+ */
+ function load_file($file_name, $prepend_path = true)
+ {
+ if ($prepend_path && $this->_config_path != "")
+ $config_file = $this->_config_path . $file_name;
+ else
+ $config_file = $file_name;
+
+ ini_set('track_errors', true);
+ $fp = @fopen($config_file, "r");
+ if (!is_resource($fp)) {
+ $this->_trigger_error_msg("Could not open config file '$config_file'");
+ return false;
+ }
+
+ $contents = ($size = filesize($config_file)) ? fread($fp, $size) : '';
+ fclose($fp);
+
+ $this->_config_data[$config_file] = $this->parse_contents($contents);
+ return true;
+ }
+
+ /**
+ * Store the contents of a file manually.
+ *
+ * @param string $config_file file name of the related contents
+ * @param string $contents the file-contents to parse
+ */
+ function set_file_contents($config_file, $contents)
+ {
+ $this->_config_data[$config_file] = $this->parse_contents($contents);
+ return true;
+ }
+
+ /**
+ * parse the source of a configuration file manually.
+ *
+ * @param string $contents the file-contents to parse
+ */
+ function parse_contents($contents)
+ {
+ if($this->fix_newlines) {
+ // fix mac/dos formatted newlines
+ $contents = preg_replace('!\r\n?!', "\n", $contents);
+ }
+
+ $config_data = array();
+ $config_data['sections'] = array();
+ $config_data['vars'] = array();
+
+ /* reference to fill with data */
+ $vars =& $config_data['vars'];
+
+ /* parse file line by line */
+ preg_match_all('!^.*\r?\n?!m', $contents, $match);
+ $lines = $match[0];
+ for ($i=0, $count=count($lines); $i<$count; $i++) {
+ $line = $lines[$i];
+ if (empty($line)) continue;
+
+ if ( substr($line, 0, 1) == '[' && preg_match('!^\[(.*?)\]!', $line, $match) ) {
+ /* section found */
+ if (substr($match[1], 0, 1) == '.') {
+ /* hidden section */
+ if ($this->read_hidden) {
+ $section_name = substr($match[1], 1);
+ } else {
+ /* break reference to $vars to ignore hidden section */
+ unset($vars);
+ $vars = array();
+ continue;
+ }
+ } else {
+ $section_name = $match[1];
+ }
+ if (!isset($config_data['sections'][$section_name]))
+ $config_data['sections'][$section_name] = array('vars' => array());
+ $vars =& $config_data['sections'][$section_name]['vars'];
+ continue;
+ }
+
+ if (preg_match('/^\s*(\.?\w+)\s*=\s*(.*)/s', $line, $match)) {
+ /* variable found */
+ $var_name = rtrim($match[1]);
+ if (strpos($match[2], '"""') === 0) {
+ /* handle multiline-value */
+ $lines[$i] = substr($match[2], 3);
+ $var_value = '';
+ while ($i<$count) {
+ if (($pos = strpos($lines[$i], '"""')) === false) {
+ $var_value .= $lines[$i++];
+ } else {
+ /* end of multiline-value */
+ $var_value .= substr($lines[$i], 0, $pos);
+ break;
+ }
+ }
+ $booleanize = false;
+
+ } else {
+ /* handle simple value */
+ $var_value = preg_replace('/^([\'"])(.*)\1$/', '\2', rtrim($match[2]));
+ $booleanize = $this->booleanize;
+
+ }
+ $this->_set_config_var($vars, $var_name, $var_value, $booleanize);
+ }
+ /* else unparsable line / means it is a comment / means ignore it */
+ }
+ return $config_data;
+ }
+
+ /**#@+ @access private */
+ /**
+ * @param array &$container
+ * @param string $var_name
+ * @param mixed $var_value
+ * @param boolean $booleanize determines whether $var_value is converted to
+ * to true/false
+ */
+ function _set_config_var(&$container, $var_name, $var_value, $booleanize)
+ {
+ if (substr($var_name, 0, 1) == '.') {
+ if (!$this->read_hidden)
+ return;
+ else
+ $var_name = substr($var_name, 1);
+ }
+
+ if (!preg_match("/^[a-zA-Z_]\w*$/", $var_name)) {
+ $this->_trigger_error_msg("Bad variable name '$var_name'");
+ return;
+ }
+
+ if ($booleanize) {
+ if (preg_match("/^(on|true|yes)$/i", $var_value))
+ $var_value = true;
+ else if (preg_match("/^(off|false|no)$/i", $var_value))
+ $var_value = false;
+ }
+
+ if (!isset($container[$var_name]) || $this->overwrite)
+ $container[$var_name] = $var_value;
+ else {
+ settype($container[$var_name], 'array');
+ $container[$var_name][] = $var_value;
+ }
+ }
+
+ /**
+ * @uses trigger_error() creates a PHP warning/error
+ * @param string $error_msg
+ * @param integer $error_type one of
+ */
+ function _trigger_error_msg($error_msg, $error_type = E_USER_WARNING)
+ {
+ trigger_error("Config_File error: $error_msg", $error_type);
+ }
+ /**#@-*/
+}
+
+?>
Property changes on: trunk/lib/smarty/Config_File.class.php
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/lib/smarty/Smarty.class.php
===================================================================
--- trunk/lib/smarty/Smarty.class.php (rev 0)
+++ trunk/lib/smarty/Smarty.class.php 2008-10-15 13:58:01 UTC (rev 10)
@@ -0,0 +1,1960 @@
+<?php
+
+/**
+ * Project: Smarty: the PHP compiling template engine
+ * File: Smarty.class.php
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * For questions, help, comments, discussion, etc., please join the
+ * Smarty mailing list. Send a blank e-mail to
+ * sma...@li...
+ *
+ * @link http://smarty.php.net/
+ * @copyright 2001-2005 New Digital Group, Inc.
+ * @author Monte Ohrt <monte at ohrt dot com>
+ * @author Andrei Zmievski <an...@ph...>
+ * @package Smarty
+ * @version 2.6.20
+ */
+
+/* $Id: Smarty.class.php 2722 2007-06-18 14:29:00Z danilo $ */
+
+/**
+ * DIR_SEP isn't used anymore, but third party apps might
+ */
+if(!defined('DIR_SEP')) {
+ define('DIR_SEP', DIRECTORY_SEPARATOR);
+}
+
+/**
+ * set SMARTY_DIR to absolute path to Smarty library files.
+ * if not defined, include_path will be used. Sets SMARTY_DIR only if user
+ * application has not already defined it.
+ */
+
+if (!defined('SMARTY_DIR')) {
+ define('SMARTY_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+}
+
+if (!defined('SMARTY_CORE_DIR')) {
+ define('SMARTY_CORE_DIR', SMARTY_DIR . 'internals' . DIRECTORY_SEPARATOR);
+}
+
+define('SMARTY_PHP_PASSTHRU', 0);
+define('SMARTY_PHP_QUOTE', 1);
+define('SMARTY_PHP_REMOVE', 2);
+define('SMARTY_PHP_ALLOW', 3);
+
+/**
+ * @package Smarty
+ */
+class Smarty
+{
+ /**#@+
+ * Smarty Configuration Section
+ */
+
+ /**
+ * The name of the directory where templates are located.
+ *
+ * @var string
+ */
+ var $template_dir = 'templates';
+
+ /**
+ * The directory where compiled templates are located.
+ *
+ * @var string
+ */
+ var $compile_dir = 'templates_c';
+
+ /**
+ * The directory where config files are located.
+ *
+ * @var string
+ */
+ var $config_dir = 'configs';
+
+ /**
+ * An array of directories searched for plugins.
+ *
+ * @var array
+ */
+ var $plugins_dir = array('plugins');
+
+ /**
+ * If debugging is enabled, a debug console window will display
+ * when the page loads (make sure your browser allows unrequested
+ * popup windows)
+ *
+ * @var boolean
+ */
+ var $debugging = false;
+
+ /**
+ * When set, smarty does uses this value as error_reporting-level.
+ *
+ * @var boolean
+ */
+ var $error_reporting = null;
+
+ /**
+ * This is the path to the debug console template. If not set,
+ * the default one will be used.
+ *
+ * @var string
+ */
+ var $debug_tpl = '';
+
+ /**
+ * This determines if debugging is enable-able from the browser.
+ * <ul>
+ * <li>NONE => no debugging control allowed</li>
+ * <li>URL => enable debugging when SMARTY_DEBUG is found in the URL.</li>
+ * </ul>
+ * @link http://www.foo.dom/index.php?SMARTY_DEBUG
+ * @var string
+ */
+ var $debugging_ctrl = 'NONE';
+
+ /**
+ * This tells Smarty whether to check for recompiling or not. Recompiling
+ * does not need to happen unless a template or config file is changed.
+ * Typically you enable this during development, and disable for
+ * production.
+ *
+ * @var boolean
+ */
+ var $compile_check = true;
+
+ /**
+ * This forces templates to compile every time. Useful for development
+ * or debugging.
+ *
+ * @var boolean
+ */
+ var $force_compile = false;
+
+ /**
+ * This enables template caching.
+ * <ul>
+ * <li>0 = no caching</li>
+ * <li>1 = use class cache_lifetime value</li>
+ * <li>2 = use cache_lifetime in cache file</li>
+ * </ul>
+ * @var integer
+ */
+ var $caching = 0;
+
+ /**
+ * The name of the directory for cache files.
+ *
+ * @var string
+ */
+ var $cache_dir = 'cache';
+
+ /**
+ * This is the number of seconds cached content will persist.
+ * <ul>
+ * <li>0 = always regenerate cache</li>
+ * <li>-1 = never expires</li>
+ * </ul>
+ *
+ * @var integer
+ */
+ var $cache_lifetime = 3600;
+
+ /**
+ * Only used when $caching is enabled. If true, then If-Modified-Since headers
+ * are respected with cached content, and appropriate HTTP headers are sent.
+ * This way repeated hits to a cached page do not send the entire page to the
+ * client every time.
+ *
+ * @var boolean
+ */
+ var $cache_modified_check = false;
+
+ /**
+ * This determines how Smarty handles "<?php ... ?>" tags in templates.
+ * possible values:
+ * <ul>
+ * <li>SMARTY_PHP_PASSTHRU -> print tags as plain text</li>
+ * <li>SMARTY_PHP_QUOTE -> escape tags as entities</li>
+ * <li>SMARTY_PHP_REMOVE -> remove php tags</li>
+ * <li>SMARTY_PHP_ALLOW -> execute php tags</li>
+ * </ul>
+ *
+ * @var integer
+ */
+ var $php_handling = SMARTY_PHP_PASSTHRU;
+
+ /**
+ * This enables template security. When enabled, many things are restricted
+ * in the templates that normally would go unchecked. This is useful when
+ * untrusted parties are editing templates and you want a reasonable level
+ * of security. (no direct execution of PHP in templates for example)
+ *
+ * @var boolean
+ */
+ var $security = false;
+
+ /**
+ * This is the list of template directories that are considered secure. This
+ * is used only if {@link $security} is enabled. One directory per array
+ * element. {@link $template_dir} is in this list implicitly.
+ *
+ * @var array
+ */
+ var $secure_dir = array();
+
+ /**
+ * These are the security settings for Smarty. They are used only when
+ * {@link $security} is enabled.
+ *
+ * @var array
+ */
+ var $security_settings = array(
+ 'PHP_HANDLING' => false,
+ 'IF_FUNCS' => array('array', 'list',
+ 'isset', 'empty',
+ 'count', 'sizeof',
+ 'in_array', 'is_array',
+ 'true', 'false', 'null'),
+ 'INCLUDE_ANY' => false,
+ 'PHP_TAGS' => false,
+ 'MODIFIER_FUNCS' => array('count'),
+ 'ALLOW_CONSTANTS' => false
+ );
+
+ /**
+ * This is an array of directories where trusted php scripts reside.
+ * {@link $security} is disabled during their inclusion/execution.
+ *
+ * @var array
+ */
+ var $trusted_dir = array();
+
+ /**
+ * The left delimiter used for the template tags.
+ *
+ * @var string
+ */
+ var $left_delimiter = '{';
+
+ /**
+ * The right delimiter used for the template tags.
+ *
+ * @var string
+ */
+ var $right_delimiter = '}';
+
+ /**
+ * The order in which request variables are registered, similar to
+ * variables_order in php.ini E = Environment, G = GET, P = POST,
+ * C = Cookies, S = Server
+ *
+ * @var string
+ */
+ var $request_vars_order = 'EGPCS';
+
+ /**
+ * Indicates wether $HTTP_*_VARS[] (request_use_auto_globals=false)
+ * are uses as request-vars or $_*[]-vars. note: if
+ * request_use_auto_globals is true, then $request_vars_order has
+ * no effect, but the php-ini-value "gpc_order"
+ *
+ * @var boolean
+ */
+ var $request_use_auto_globals = true;
+
+ /**
+ * Set this if you want different sets of compiled files for the same
+ * templates. This is useful for things like different languages.
+ * Instead of creating separate sets of templates per language, you
+ * set different compile_ids like 'en' and 'de'.
+ *
+ * @var string
+ */
+ var $compile_id = null;
+
+ /**
+ * This tells Smarty whether or not to use sub dirs in the cache/ and
+ * templates_c/ directories. sub directories better organized, but
+ * may not work well with PHP safe mode enabled.
+ *
+ * @var boolean
+ *
+ */
+ var $use_sub_dirs = false;
+
+ /**
+ * This is a list of the modifiers to apply to all template variables.
+ * Put each modifier in a separate array element in the order you want
+ * them applied. example: <code>array('escape:"htmlall"');</code>
+ *
+ * @var array
+ */
+ var $default_modifiers = array();
+
+ /**
+ * This is the resource type to be used when not specified
+ * at the beginning of the resource path. examples:
+ * $smarty->display('file:index.tpl');
+ * $smarty->display('db:index.tpl');
+ * $smarty->display('index.tpl'); // will use default resource type
+ * {include file="file:index.tpl"}
+ * {include file="db:index.tpl"}
+ * {include file="index.tpl"} {* will use default resource type *}
+ *
+ * @var array
+ */
+ var $default_resource_type = 'file';
+
+ /**
+ * The function used for cache file handling. If not set, built-in caching is used.
+ *
+ * @var null|string function name
+ */
+ var $cache_handler_func = null;
+
+ /**
+ * This indicates which filters are automatically loaded into Smarty.
+ *
+ * @var array array of filter names
+ */
+ var $autoload_filters = array();
+
+ /**#@+
+ * @var boolean
+ */
+ /**
+ * This tells if config file vars of the same name overwrite each other or not.
+ * if disabled, same name variables are accumulated in an array.
+ */
+ var $config_overwrite = true;
+
+ /**
+ * This tells whether or not to automatically booleanize config file variables.
+ * If enabled, then the strings "on", "true", and "yes" are treated as boolean
+ * true, and "off", "false" and "no" are treated as boolean false.
+ */
+ var $config_booleanize = true;
+
+ /**
+ * This tells whether hidden sections [.foobar] are readable from the
+ * tempalates or not. Normally you would never allow this since that is
+ * the point behind hidden sections: the application can access them, but
+ * the templates cannot.
+ */
+ var $config_read_hidden = false;
+
+ /**
+ * This tells whether or not automatically fix newlines in config files.
+ * It basically converts \r (mac) or \r\n (dos) to \n
+ */
+ var $config_fix_newlines = true;
+ /**#@-*/
+
+ /**
+ * If a template cannot be found, this PHP function will be executed.
+ * Useful for creating templates on-the-fly or other special action.
+ *
+ * @var string function name
+ */
+ var $default_template_handler_func = '';
+
+ /**
+ * The file that contains the compiler class. This can a full
+ * pathname, or relative to the php_include path.
+ *
+ * @var string
+ */
+ var $compiler_file = 'Smarty_Compiler.class.php';
+
+ /**
+ * The class used for compiling templates.
+ *
+ * @var string
+ */
+ var $compiler_class = 'Smarty_Compiler';
+
+ /**
+ * The class used to load config vars.
+ *
+ * @var string
+ */
+ var $config_class = 'Config_File';
+
+/**#@+
+ * END Smarty Configuration Section
+ * There should be no need to touch anything below this line.
+ * @access private
+ */
+ /**
+ * where assigned template vars are kept
+ *
+ * @var array
+ */
+ var $_tpl_vars = array();
+
+ /**
+ * stores run-time $smarty.* vars
+ *
+ * @var null|array
+ */
+ var $_smarty_vars = null;
+
+ /**
+ * keeps track of sections
+ *
+ * @var array
+ */
+ var $_sections = array();
+
+ /**
+ * keeps track of foreach blocks
+ *
+ * @var array
+ */
+ var $_foreach = array();
+
+ /**
+ * keeps track of tag hierarchy
+ *
+ * @var array
+ */
+ var $_tag_stack = array();
+
+ /**
+ * configuration object
+ *
+ * @var Config_file
+ */
+ var $_conf_obj = null;
+
+ /**
+ * loaded configuration settings
+ *
+ * @var array
+ */
+ var $_config = array(array('vars' => array(), 'files' => array()));
+
+ /**
+ * md5 checksum of the string 'Smarty'
+ *
+ * @var string
+ */
+ var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f';
+
+ /**
+ * Smarty version number
+ *
+ * @var string
+ */
+ var $_version = '2.6.20';
+
+ /**
+ * current template inclusion depth
+ *
+ * @var integer
+ */
+ var $_inclusion_depth = 0;
+
+ /**
+ * for different compiled templates
+ *
+ * @var string
+ */
+ var $_compile_id = null;
+
+ /**
+ * text in URL to enable debug mode
+ *
+ * @var string
+ */
+ var $_smarty_debug_id = 'SMARTY_DEBUG';
+
+ /**
+ * debugging information for debug console
+ *
+ * @var array
+ */
+ var $_smarty_debug_info = array();
+
+ /**
+ * info that makes up a cache file
+ *
+ * @var array
+ */
+ var $_cache_info = array();
+
+ /**
+ * default file permissions
+ *
+ * @var integer
+ */
+ var $_file_perms = 0644;
+
+ /**
+ * default dir permissions
+ *
+ * @var integer
+ */
+ var $_dir_perms = 0771;
+
+ /**
+ * registered objects
+ *
+ * @var array
+ */
+ var $_reg_objects = array();
+
+ /**
+ * table keeping track of plugins
+ *
+ * @var array
+ */
+ var $_plugins = array(
+ 'modifier' => array(),
+ 'function' => array(),
+ 'block' => array(),
+ 'compiler' => array(),
+ 'prefilter' => array(),
+ 'postfilter' => array(),
+ 'outputfilter' => array(),
+ 'resource' => array(),
+ 'insert' => array());
+
+
+ /**
+ * cache serials
+ *
+ * @var array
+ */
+ var $_cache_serials = array();
+
+ /**
+ * name of optional cache include file
+ *
+ * @var string
+ */
+ var $_cache_include = null;
+
+ /**
+ * indicate if the current code is used in a compiled
+ * include
+ *
+ * @var string
+ */
+ var $_cache_including = false;
+
+ /**#@-*/
+ /**
+ * The class constructor.
+ */
+ function Smarty()
+ {
+ $this->assign('SCRIPT_NAME', isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME']
+ : @$GLOBALS['HTTP_SERVER_VARS']['SCRIPT_NAME']);
+ }
+
+ /**
+ * assigns values to template variables
+ *
+ * @param array|string $tpl_var the template variable name(s)
+ * @param mixed $value the value to assign
+ */
+ function assign($tpl_var, $value = null)
+ {
+ if (is_array($tpl_var)){
+ foreach ($tpl_var as $key => $val) {
+ if ($key != '') {
+ $this->_tpl_vars[$key] = $val;
+ }
+ }
+ } else {
+ if ($tpl_var != '')
+ $this->_tpl_vars[$tpl_var] = $value;
+ }
+ }
+
+ /**
+ * assigns values to template variables by reference
+ *
+ * @param string $tpl_var the template variable name
+ * @param mixed $value the referenced value to assign
+ */
+ function assign_by_ref($tpl_var, &$value)
+ {
+ if ($tpl_var != '')
+ $this->_tpl_vars[$tpl_var] = &$value;
+ }
+
+ /**
+ * appends values to template variables
+ *
+ * @param array|string $tpl_var the template variable name(s)
+ * @param mixed $value the value to append
+ */
+ function append($tpl_var, $value=null, $merge=false)
+ {
+ if (is_array($tpl_var)) {
+ // $tpl_var is an array, ignore $value
+ foreach ($tpl_var as $_key => $_val) {
+ if ($_key != '') {
+ if(!@is_array($this->_tpl_vars[$_key])) {
+ settype($this->_tpl_vars[$_key],'array');
+ }
+ if($merge && is_array($_val)) {
+ foreach($_val as $_mkey => $_mval) {
+ $this->_tpl_vars[$_key][$_mkey] = $_mval;
+ }
+ } else {
+ $this->_tpl_vars[$_key][] = $_val;
+ }
+ }
+ }
+ } else {
+ if ($tpl_var != '' && isset($value)) {
+ if(!@is_array($this->_tpl_vars[$tpl_var])) {
+ settype($this->_tpl_vars[$tpl_var],'array');
+ }
+ if($merge && is_array($value)) {
+ foreach($value as $_mkey => $_mval) {
+ $this->_tpl_vars[$tpl_var][$_mkey] = $_mval;
+ }
+ } else {
+ $this->_tpl_vars[$tpl_var][] = $value;
+ }
+ }
+ }
+ }
+
+ /**
+ * appends values to template variables by reference
+ *
+ * @param string $tpl_var the template variable name
+ * @param mixed $value the referenced value to append
+ */
+ function append_by_ref($tpl_var, &$value, $merge=false)
+ {
+ if ($tpl_var != '' && isset($value)) {
+ if(!@is_array($this->_tpl_vars[$tpl_var])) {
+ settype($this->_tpl_vars[$tpl_var],'array');
+ }
+ if ($merge && is_array($value)) {
+ foreach($value as $_key => $_val) {
+ $this->_tpl_vars[$tpl_var][$_key] = &$value[$_key];
+ }
+ } else {
+ $this->_tpl_vars[$tpl_var][] = &$value;
+ }
+ }
+ }
+
+
+ /**
+ * clear the given assigned template variable.
+ *
+ * @param string $tpl_var the template variable to clear
+ */
+ function clear_assign($tpl_var)
+ {
+ if (is_array($tpl_var))
+ foreach ($tpl_var as $curr_var)
+ unset($this->_tpl_vars[$curr_var]);
+ else
+ unset($this->_tpl_vars[$tpl_var]);
+ }
+
+
+ /**
+ * Registers custom function to be used in templates
+ *
+ * @param string $function the name of the template function
+ * @param string $function_impl the name of the PHP function to register
+ */
+ function register_function($function, $function_impl, $cacheable=true, $cache_attrs=null)
+ {
+ $this->_plugins['function'][$function] =
+ array($function_impl, null, null, false, $cacheable, $cache_attrs);
+
+ }
+
+ /**
+ * Unregisters custom function
+ *
+ * @param string $function name of template function
+ */
+ function unregister_function($function)
+ {
+ unset($this->_plugins['function'][$function]);
+ }
+
+ /**
+ * Registers object to be used in templates
+ *
+ * @param string $object name of template object
+ * @param object &$object_impl the referenced PHP object to register
+ * @param null|array $allowed list of allowed methods (empty = all)
+ * @param boolean $smarty_args smarty argument format, else traditional
+ * @param null|array $block_functs list of methods that are block format
+ */
+ function register_object($object, &$object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())
+ {
+ settype($allowed, 'array');
+ settype($smarty_args, 'boolean');
+ $this->_reg_objects[$object] =
+ array(&$object_impl, $allowed, $smarty_args, $block_methods);
+ }
+
+ /**
+ * Unregisters object
+ *
+ * @param string $object name of template object
+ */
+ function unregister_object($object)
+ {
+ unset($this->_reg_objects[$object]);
+ }
+
+
+ /**
+ * Registers block function to be used in templates
+ *
+ * @param string $block name of template block
+ * @param string $block_impl PHP function to register
+ */
+ function register_block($block, $block_impl, $cacheable=true, $cache_attrs=null)
+ {
+ $this->_plugins['block'][$block] =
+ array($block_impl, null, null, false, $cacheable, $cache_attrs);
+ }
+
+ /**
+ * Unregisters block function
+ *
+ * @param string $block name of template function
+ */
+ function unregister_block($block)
+ {
+ unset($this->_plugins['block'][$block]);
+ }
+
+ /**
+ * Registers compiler function
+ *
+ * @param string $function name of template function
+ * @param string $function_impl name of PHP function to register
+ */
+ function register_compiler_function($function, $function_impl, $cacheable=true)
+ {
+ $this->_plugins['compiler'][$function] =
+ array($function_impl, null, null, false, $cacheable);
+ }
+
+ /**
+ * Unregisters compiler function
+ *
+ * @param string $function name of template function
+ */
+ function unregister_compiler_function($function)
+ {
+ unset($this->_plugins['compiler'][$function]);
+ }
+
+ /**
+ * Registers modifier to be used in templates
+ *
+ * @param string $modifier name of template modifier
+ * @param string $modifier_impl name of PHP function to register
+ */
+ function register_modifier($modifier, $modifier_impl)
+ {
+ $this->_plugins['modifier'][$modifier] =
+ array($modifier_impl, null, null, false);
+ }
+
+ /**
+ * Unregisters modifier
+ *
+ * @param string $modifier name of template modifier
+ */
+ function unregister_modifier($modifier)
+ {
+ unset($this->_plugins['modifier'][$modifier]);
+ }
+
+ /**
+ * Registers a resource to fetch a template
+ *
+ * @param string $type name of resource
+ * @param array $functions array of functions to handle resource
+ */
+ function register_resource($type, $functions)
+ {
+ if (count($functions)==4) {
+ $this->_plugins['resource'][$type] =
+ array($functions, false);
+
+ } elseif (count($functions)==5) {
+ $this->_plugins['resource'][$type] =
+ array(array(array(&$functions[0], $functions[1])
+ ,array(&$functions[0], $functions[2])
+ ,array(&$functions[0], $functions[3])
+ ,array(&$functions[0], $functions[4]))
+ ,false);
+
+ } else {
+ $this->trigger_error("malformed function-list for '$type' in register_resource");
+
+ }
+ }
+
+ /**
+ * Unregisters a resource
+ *
+ * @param string $type name of resource
+ */
+ function unregister_resource($type)
+ {
+ unset($this->_plugins['resource'][$type]);
+ }
+
+ /**
+ * Registers a prefilter function to apply
+ * to a template before compiling
+ *
+ * @param callback $function
+ */
+ function register_prefilter($function)
+ {
+ $this->_plugins['prefilter'][$this->_get_filter_name($function)]
+ = array($function, null, null, false);
+ }
+
+ /**
+ * Unregisters a prefilter function
+ *
+ * @param callback $function
+ */
+ function unregister_prefilter($function)
+ {
+ unset($this->_plugins['prefilter'][$this->_get_filter_name($function)]);
+ }
+
+ /**
+ * Registers a postfilter function to apply
+ * to a compiled template after compilation
+ *
+ * @param callback $function
+ */
+ function register_postfilter($function)
+ {
+ $this->_plugins['postfilter'][$this->_get_filter_name($function)]
+ = array($function, null, null, false);
+ }
+
+ /**
+ * Unregisters a postfilter function
+ *
+ * @param callback $function
+ */
+ function unregister_postfilter($function)
+ {
+ unset($this->_plugins['postfilter'][$this->_get_filter_name($function)]);
+ }
+
+ /**
+ * Registers an output filter function to apply
+ * to a template output
+ *
+ * @param callback $function
+ */
+ function register_outputfilter($function)
+ {
+ $this->_plugins['outputfilter'][$this->_get_filter_name($function)]
+ = array($function, null, null, false);
+ }
+
+ /**
+ * Unregisters an outputfilter function
+ *
+ * @param callback $function
+ */
+ function unregister_outputfilter($function)
+ {
+ unset($this->_plugins['outputfilter'][$this->_get_filter_name($function)]);
+ }
+
+ /**
+ * load a filter of specified type and name
+ *
+ * @param string $type filter type
+ * @param string $name filter name
+ */
+ function load_filter($type, $name)
+ {
+ switch ($type) {
+ case 'output':
+ $_params = array('plugins' => array(array($type . 'filter', $name, null, null, false)));
+ require_once(SMARTY_CORE_DIR . 'core.load_plugins.php');
+ smarty_core_load_plugins($_params, $this);
+ break;
+
+ case 'pre':
+ case 'post':
+ if (!isset($this->_plugins[$type . 'filter'][$name]))
+ $this->_plugins[$type . 'filter'][$name] ...
[truncated message content] |