| [ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /**************************************************************************\ 3 * eGroupWare API - Wrapper for the savant2 template engine * 4 * Written by Pim Snel <pim@lingewoud.nl> * 5 * * 6 * Wrapper for the savant2 template engine www.phpsavant.com * 7 * Copyright (C) 2005 Lingewoud BV and Pim Snel * 8 * -------------------------------------------------------------------------* 9 * This library is part of the eGroupWare API * 10 * http://www.egroupware.org * 11 * ------------------------------------------------------------------------ * 12 * This library is free software; you can redistribute it and/or modify it * 13 * under the terms of the GNU Lesser General Public License as published by * 14 * the Free Software Foundation; either version 2.1 of the License, * 15 * or any later version. * 16 * This library is distributed in the hope that it will be useful, but * 17 * WITHOUT ANY WARRANTY; without even the implied warranty of * 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 19 * See the GNU Lesser General Public License for more details. * 20 * You should have received a copy of the GNU Lesser General Public License * 21 * along with this library; if not, write to the Free Software Foundation, * 22 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 23 \**************************************************************************/ 24 25 /* $Id: class.tplsavant2.inc.php 22774 2006-10-30 09:50:40Z mipmip $ */ 26 27 if(is_file(EGW_INCLUDE_ROOT.'/phpgwapi/inc/savant2/Savant2.php')) 28 { 29 include_once (EGW_INCLUDE_ROOT.'/phpgwapi/inc/savant2/Savant2.php'); 30 } 31 32 /*! 33 @class tplsavant2 34 @abstract wrapper class for the Savant2 template engine 35 */ 36 class tplsavant2 extends Savant2 37 { 38 /*! 39 @var $version 40 @abstract the version this wrapper is testet against 41 */ 42 var $version = '2.3.3'; 43 44 /*! 45 @var $do_version_check 46 @abstract set this to true to halt when versions of this wrapper and savant2 itself differ 47 */ 48 var $do_version_check = false; 49 50 /*! 51 @function tplsavant2 52 @abstract constructor function which calls the constructor of Savant2 and sets necesary things for eGroupware 53 */ 54 function tplsavant2() 55 { 56 // run constructor of the Savant2 class 57 $this->Savant2(); 58 59 if($this->do_version_check) 60 { 61 $this->version_check(); 62 } 63 64 $this->set_tpl_path(); 65 } 66 67 /** 68 @function version_check 69 @abstract check version of this wrapper with installed savant2 version and halts when version differs 70 @return void 71 */ 72 function version_check() 73 { 74 $Sav2Version = @file_get_contents(EGW_INCLUDE_ROOT.'/phpgwapi/inc/savant2/VERSION',"rb"); 75 76 if(trim($Sav2Version) != trim($this->version)) 77 { 78 $this->halt(lang('Savant2 version differs from Savant2 wrapper. <br/>This version: %1 <br/>Savants version: %2',$this->version, $Sav2Version)); 79 } 80 } 81 82 83 /*! 84 @function set_tpl_path 85 @abstract sets the preferred and fallback template search paths 86 @return void 87 */ 88 function set_tpl_path($man_dir=false) 89 { 90 $preferred_dir=$this->get_tpl_dir(); 91 $fallback_dir=$this->get_tpl_dir(true); 92 93 if(!$preferred_dir && $man_dir && $fallback_dir) 94 { 95 $this->halt(lang('No Savant2 template directories were found in:'.EGW_APP_ROOT)); 96 } 97 else 98 { 99 if($fallback_dir) 100 { 101 $this->addPath('template',$fallback_dir); 102 } 103 // add preferred tpl dir last because savant set the last added first in the search array 104 if($preferred_dir) 105 { 106 $this->addPath('template',$preferred_dir); 107 } 108 109 if($man_dir) 110 { 111 $this->addPath('template',$man_dir); 112 } 113 114 } 115 } 116 117 118 /*! 119 @function get_tpl_dir 120 @abstract get template dir of an application 121 @param $fallback if true the default fallback template dir is returned 122 @param $appname appication name optional can be derived from $GLOBALS['egw_info']['flags']['currentapp']; 123 */ 124 function get_tpl_dir($fallback=false,$appname = '') 125 { 126 if (! $appname) 127 { 128 $appname = $GLOBALS['egw_info']['flags']['currentapp']; 129 } 130 if ($appname == 'home' || $appname == 'logout' || $appname == 'login') 131 { 132 $appname = 'phpgwapi'; 133 } 134 135 if (!isset($GLOBALS['egw_info']['server']['template_set']) && isset($GLOBALS['egw_info']['user']['preferences']['common']['template_set'])) 136 { 137 $GLOBALS['egw_info']['server']['template_set'] = $GLOBALS['egw_info']['user']['preferences']['common']['template_set']; 138 } 139 140 // Setting this for display of template choices in user preferences 141 if ($GLOBALS['egw_info']['server']['template_set'] == 'user_choice') 142 { 143 $GLOBALS['egw_info']['server']['usrtplchoice'] = 'user_choice'; 144 } 145 146 if (($GLOBALS['egw_info']['server']['template_set'] == 'user_choice' || 147 !isset($GLOBALS['egw_info']['server']['template_set'])) && 148 isset($GLOBALS['egw_info']['user']['preferences']['common']['template_set'])) 149 { 150 $GLOBALS['egw_info']['server']['template_set'] = $GLOBALS['egw_info']['user']['preferences']['common']['template_set']; 151 } 152 elseif ($GLOBALS['egw_info']['server']['template_set'] == 'user_choice' || 153 !isset($GLOBALS['egw_info']['server']['template_set'])) 154 { 155 $GLOBALS['egw_info']['server']['template_set'] = 'default'; 156 } 157 158 $tpldir = EGW_SERVER_ROOT . '/' . $appname . '/templatesSavant2/' . $GLOBALS['egw_info']['server']['template_set']; 159 $tpldir_default = EGW_SERVER_ROOT . '/' . $appname . '/templatesSavant2/default'; 160 161 if (!$fallback && @is_dir($tpldir)) 162 { 163 return $tpldir; 164 } 165 elseif (@is_dir($tpldir_default)) 166 { 167 return $tpldir_default; 168 } 169 else 170 { 171 return False; 172 } 173 } 174 175 /***************************************************************************/ 176 /* public: halt(string $msg) 177 * msg: error message to show. 178 */ 179 function halt($msg) 180 { 181 $this->last_error = $msg; 182 183 if ($this->halt_on_error != 'no') 184 { 185 $this->haltmsg($msg); 186 } 187 188 if ($this->halt_on_error == 'yes') 189 { 190 echo('<strong>Halted.</strong>'); 191 } 192 193 $GLOBALS['phpgw']->common->phpgw_exit(True); 194 } 195 196 /* public, override: haltmsg($msg) 197 * msg: error message to show. 198 */ 199 function haltmsg($msg) 200 { 201 printf("<strong>Savant Template Error:</strong> %s<br/>\n", $msg); 202 echo "<strong>Backtrace</strong>: ".function_backtrace(2)."<br/>\n"; 203 } 204 205 function fetch_string($string) 206 { 207 $tmpfname = tempnam ("/tmp", "sav"); 208 $fp = fopen($tmpfname, "w"); 209 fwrite($fp, $string); 210 fclose($fp); 211 $this->addPath('template','/tmp'); 212 $file_arr= explode('/',$tmpfname); 213 return $this->fetch($file_arr[2]); 214 unlink($tmpfname); 215 } 216 217 /** 218 * set_var the same as assign() 219 * 220 * @param mixed $tplvar 221 * @param string $val 222 * @access public 223 * @return void 224 */ 225 function set_var($tplvar,$val='') 226 { 227 $this->assign($tplvar,$val); 228 } 229 230 231 232 233 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |