[ Index ] |
|
Code source de CMS made simple 1.0.5 |
1 <?php 2 # CMS - CMS Made Simple 3 # (c)2004-6 by Ted Kulp (ted@cmsmadesimple.org) 4 # This project's homepage is: http://cmsmadesimple.org 5 # 6 # This program is free software; you can redistribute it and/or modify 7 # it under the terms of the GNU General Public License as published by 8 # the Free Software Foundation; either version 2 of the License, or 9 # (at your option) any later version. 10 # 11 # This program is distributed in the hope that it will be useful, 12 # BUT withOUT ANY WARRANTY; without even the implied warranty of 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 # GNU General Public License for more details. 15 # You should have received a copy of the GNU General Public License 16 # along with this program; if not, write to the Free Software 17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 # 19 #$Id$ 20 21 /** 22 * Methods for modules to do template related functions 23 * 24 * @since 1.0 25 * @package CMS 26 */ 27 28 function cms_module_ListTemplates(&$modinstance, $modulename = '') 29 { 30 global $gCms; 31 32 $db =& $gCms->GetDb(); 33 $config =& $gCms->GetConfig(); 34 35 $retresult = array(); 36 37 $query = 'SELECT * from '.cms_db_prefix().'module_templates WHERE module_name = ? ORDER BY template_name ASC'; 38 $result =& $db->Execute($query, array($modulename != ''?$modulename:$modinstance->GetName())); 39 40 while (isset($result) && !$result->EOF) 41 { 42 $retresult[] = $result->fields['template_name']; 43 $result->MoveNext(); 44 } 45 46 return $retresult; 47 } 48 49 /** 50 * Returns a database saved template. This should be used for admin functions only, as it doesn't 51 * follow any smarty caching rules. 52 */ 53 function cms_module_GetTemplate(&$modinstance, $tpl_name, $modulename = '') 54 { 55 global $gCms; 56 57 $db =& $gCms->GetDb(); 58 $config =& $gCms->GetConfig(); 59 60 $query = 'SELECT * from '.cms_db_prefix().'module_templates WHERE module_name = ? and template_name = ?'; 61 $result = $db->Execute($query, array($modulename != ''?$modulename:$modinstance->GetName(), $tpl_name)); 62 63 if ($result && $result->RecordCount() > 0) 64 { 65 $row = $result->FetchRow(); 66 return $row['content']; 67 } 68 69 return ''; 70 } 71 72 /** 73 * Returns contents of the template that resides in modules/ModuleName/templates/{template_name}.tpl 74 * Code adapted from the Guestbook module 75 */ 76 function cms_module_GetTemplateFromFile(&$modinstance, $template_name) 77 { 78 global $gCms; 79 $config = &$gCms->GetConfig(); 80 $tpl_base = $config['root_path'].DIRECTORY_SEPARATOR.'modules'.DIRECTORY_SEPARATOR; 81 $tpl_base .= $modinstance->GetName().DIRECTORY_SEPARATOR.'templates'; 82 $template = $tpl_base.DIRECTORY_SEPARATOR.$template_name.'.tpl'; 83 if (is_file($template)) { 84 return file_get_contents($template); 85 } 86 else 87 { 88 return lang('errorinsertingtemplate'); 89 } 90 } 91 92 function cms_module_SetTemplate(&$modinstance, $tpl_name, $content, $modulename = '') 93 { 94 global $gCms; 95 $db =& $gCms->GetDB(); 96 97 $query = 'SELECT module_name FROM '.cms_db_prefix().'module_templates WHERE module_name = ? and template_name = ?'; 98 $result = $db->Execute($query, array($modulename != ''?$modulename:$modinstance->GetName(), $tpl_name)); 99 100 $time = $db->DBTimeStamp(time()); 101 if ($result && $result->RecordCount() < 1) 102 { 103 $query = 'INSERT INTO '.cms_db_prefix().'module_templates (module_name, template_name, content, create_date, modified_date) VALUES (?,?,?,'.$time.','.$time.')'; 104 $db->Execute($query, array($modulename != ''?$modulename:$modinstance->GetName(), $tpl_name, $content)); 105 } 106 else 107 { 108 $query = 'UPDATE '.cms_db_prefix().'module_templates SET content = ?, modified_date = '.$time.' WHERE module_name = ? AND template_name = ?'; 109 $db->Execute($query, array($content, $modulename != ''?$modulename:$modinstance->GetName(), $tpl_name)); 110 } 111 } 112 113 function cms_module_DeleteTemplate(&$modinstance, $tpl_name = '', $modulename = '') 114 { 115 global $gCms; 116 $db =& $gCms->GetDB(); 117 118 $parms = array($modulename != ''?$modulename:$modinstance->GetName()); 119 $query = "DELETE FROM ".cms_db_prefix()."module_templates WHERE module_name = ?"; 120 if( $tpl_name != '' ) 121 { 122 $query .= 'AND template_name = ?'; 123 $parms[] = $tpl_name; 124 } 125 $result = $db->Execute($query, $parms); 126 return ($result == false)?false:true; 127 } 128 129 function cms_module_IsFileTemplateCached(&$modinstance, $tpl_name, $designation = '', $timestamp = '', $cacheid = '') 130 { 131 global $gCms; 132 $smarty = &$gCms->GetSmarty(); 133 $oldcache = $smarty->caching; 134 $smarty->caching = false; 135 $result = $smarty->is_cached('module_file_tpl:'.$modinstance->GetName().';'.$tpl_name, $cacheid, ($designation != ''?$designation:$modinstance->GetName())); 136 137 if ($result == true && $timestamp != '' && intval($smarty->_cache_info['timestamp']) < intval($timestamp)) 138 { 139 $smarty->clear_cache('module_file_tpl:'.$modinstance->GetName().';'.$tpl_name, $cacheid, ($designation != ''?$designation:$modinstance->GetName())); 140 $result = false; 141 } 142 143 $smarty->caching = $oldcache; 144 return $result; 145 } 146 147 function cms_module_ProcessTemplate(&$modinstance, $tpl_name, $designation = '', $cache = false, $cacheid = '') 148 { 149 global $gCms; 150 $smarty = &$gCms->GetSmarty(); 151 152 $oldcache = $smarty->caching; 153 $smarty->caching = false; 154 155 $result = $smarty->fetch('module_file_tpl:'.$modinstance->GetName().';'.$tpl_name, $cacheid, ($designation != ''?$designation:$modinstance->GetName())); 156 $smarty->caching = $oldcache; 157 158 return $result; 159 } 160 161 function cms_module_IsDatabaseTemplateCached(&$modinstance, $tpl_name, $designation = '', $timestamp = '') 162 { 163 global $gCms; 164 $smarty = &$gCms->GetSmarty(); 165 $oldcache = $smarty->caching; 166 $smarty->caching = false; 167 $result = $smarty->is_cached('module_db_tpl:'.$modinstance->GetName().';'.$tpl_name, '', ($designation != ''?$designation:$modinstance->GetName())); 168 169 if ($result == true && $timestamp != '' && intval($smarty->_cache_info['timestamp']) < intval($timestamp)) 170 { 171 $smarty->clear_cache('module_file_tpl:'.$modinstance->GetName().';'.$tpl_name, '', ($designation != ''?$designation:$modinstance->GetName())); 172 $result = false; 173 } 174 175 $smarty->caching = $oldcache; 176 return $result; 177 } 178 179 /** 180 * Given a template in a variable, this method processes it through smarty 181 * note, there is no caching involved. 182 */ 183 function cms_module_ProcessTemplateFromData(&$modinstance, $data) 184 { 185 global $gCms; 186 $smarty = &$gCms->GetSmarty(); 187 $smarty->_compile_source('temporary template', $data, $_compiled ); 188 @ob_start(); 189 $smarty->_eval('?>' . $_compiled); 190 $_contents = @ob_get_contents(); 191 @ob_end_clean(); 192 return $_contents; 193 } 194 195 function cms_module_ProcessTemplateFromDatabase(&$modinstance, $tpl_name, $designation = '', $cache = false) 196 { 197 global $gCms; 198 $smarty = &$gCms->GetSmarty(); 199 200 $oldcache = $smarty->caching; 201 $smarty->caching = false; 202 203 $result = $smarty->fetch('module_db_tpl:'.$modinstance->GetName().';'.$tpl_name, '', ($designation != ''?$designation:$modinstance->GetName())); 204 205 $smarty->caching = $oldcache; 206 207 return $result; 208 } 209 210 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Tue Apr 3 18:50:37 2007 | par Balluche grâce à PHPXref 0.7 |