| [ Index ] |
|
Code source de CMS made simple 1.0.5 |
1 <?php 2 #CMS - CMS Made Simple 3 #(c)2004 by Ted Kulp (wishy@users.sf.net) 4 #This project's homepage is: http://cmsmadesimple.sf.net 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: index.php 3767 2007-01-23 17:23:45Z wishy $ 20 21 $dirname = dirname(__FILE__); 22 require_once ($dirname.'/fileloc.php'); 23 24 /** 25 * Entry point for all non-admin pages 26 * 27 * @package CMS 28 */ 29 #echo '<code style="align: left;">'; 30 #var_dump($_SERVER); 31 #echo '</code>'; 32 33 $starttime = microtime(); 34 35 @ob_start(); 36 37 clearstatcache(); 38 39 if (!isset($_SERVER['REQUEST_URI']) && isset($_SERVER['QUERY_STRING'])) 40 { 41 $_SERVER['REQUEST_URI'] = $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING']; 42 } 43 44 if (!file_exists(CONFIG_FILE_LOCATION) || filesize(CONFIG_FILE_LOCATION) < 800) 45 { 46 require_once ($dirname.'/lib/misc.functions.php'); 47 if (FALSE == is_file($dirname.'/install/install.php')) { 48 die ('There is no config.php file or install/install.php please correct one these errors!'); 49 } else { 50 redirect('install/install.php'); 51 } 52 } 53 else if (file_exists(TMP_CACHE_LOCATION.'/SITEDOWN')) 54 { 55 echo "<html><head><title>Maintenance</title></head><body><p>Site down for maintenance.</p></body></html>"; 56 exit; 57 } 58 59 if (!is_writable(TMP_TEMPLATES_C_LOCATION) || !is_writable(TMP_CACHE_LOCATION)) 60 { 61 echo '<html><title>Error</title></head><body>'; 62 echo '<p>The following directories must be writable by the web server:<br />'; 63 echo 'tmp/cache<br />'; 64 echo 'tmp/templates_c<br /></p>'; 65 echo '<p>Please correct by executing:<br /><em>chmod 777 tmp/cache<br />chmod 777 tmp/templates_c</em><br />or the equivilent for your platform before continuing.</p>'; 66 echo '</body></html>'; 67 exit; 68 } 69 70 require_once ($dirname.'/include.php'); #Makes gCms object 71 72 $params = array_merge($_GET, $_POST); 73 74 $smarty = &$gCms->smarty; 75 $smarty->params = $params; 76 77 $page = ''; 78 79 if (isset($params['mact'])) 80 { 81 $ary = explode(',', $params['mact'], 4); 82 $smarty->id = (isset($ary[1])?$ary[1]:''); 83 } 84 else 85 { 86 $smarty->id = (isset($params['id'])?$params['id']:''); 87 } 88 89 if (isset($smarty->id) && isset($params[$smarty->id . 'returnid'])) 90 { 91 $page = $params[$smarty->id . 'returnid']; 92 } 93 else if (isset($config["query_var"]) && $config["query_var"] != '' && isset($_GET[$config["query_var"]])) 94 { 95 $page = $_GET[$config["query_var"]]; 96 97 //trim off the extension, if there is one set 98 if ($config['page_extension'] != '' && endswith($page, $config['page_extension'])) 99 { 100 $page = substr($page, 0, strlen($page) - strlen($config['page_extension'])); 101 } 102 } 103 else 104 { 105 $calced = cms_calculate_url(); 106 if ($calced != '') 107 $page = $calced; 108 } 109 110 //See if our page matches any predefined routes 111 $page = rtrim($page, '/'); 112 if (strpos($page, '/') !== FALSE) 113 { 114 $routes =& $gCms->variables['routes']; 115 116 $matched = false; 117 foreach ($routes as $route) 118 { 119 $matches = array(); 120 if (preg_match($route->regex, $page, $matches)) 121 { 122 //Now setup some assumptions 123 if (!isset($matches['id'])) 124 $matches['id'] = 'cntnt01'; 125 if (!isset($matches['action'])) 126 $matches['action'] = 'defaulturl'; 127 if (!isset($matches['inline'])) 128 $matches['inline'] = 0; 129 if (!isset($matches['returnid'])) 130 $matches['returnid'] = ''; #Look for default page 131 if (!isset($matches['module'])) 132 $matches['module'] = $route->module; 133 134 //Get rid of numeric matches 135 foreach ($matches as $key=>$val) 136 { 137 if (is_int($key)) 138 { 139 unset($matches[$key]); 140 } 141 else 142 { 143 if ($key != 'id') 144 $_REQUEST[$matches['id'] . $key] = $val; 145 } 146 } 147 148 //Now set any defaults that might not have been in the url 149 if (isset($route->defaults) && count($route->defaults) > 0) 150 { 151 foreach ($route->defaults as $key=>$val) 152 { 153 $_REQUEST[$matches['id'] . $key] = $val; 154 if (array_key_exists($key, $matches)) 155 { 156 $matches[$key] = $val; 157 } 158 } 159 } 160 161 //Get a decent returnid 162 if ($matches['returnid'] == '') { 163 global $gCms; 164 $contentops =& $gCms->GetContentOperations(); 165 $matches['returnid'] = $contentops->GetDefaultPageID(); 166 } 167 168 $_REQUEST['mact'] = $matches['module'] . ',' . $matches['id'] . ',' . $matches['action'] . ',' . $matches['inline']; 169 $page = $matches['returnid']; 170 $smarty->id = $matches['id']; 171 172 $matched = true; 173 } 174 } 175 176 if (!$matched) 177 { 178 $page = substr($page, strrpos($page, '/') + 1); 179 } 180 } 181 182 if ($page == '') 183 { 184 global $gCms; 185 $contentops =& $gCms->GetContentOperations(); 186 $page =& $contentops->GetDefaultContent(); 187 } 188 else 189 { 190 $page = preg_replace('/\</','',$page); 191 } 192 193 $pageinfo = PageInfoOperations::LoadPageInfoByContentAlias($page); 194 195 if (isset($pageinfo) && $pageinfo !== FALSE) 196 { 197 $gCms->variables['pageinfo'] =& $pageinfo; 198 199 $gCms->variables['content_id'] = $pageinfo->content_id; 200 $gCms->variables['page'] = $page; 201 $gCms->variables['page_id'] = $page; 202 203 $gCms->variables['page_name'] = $pageinfo->content_alias; 204 $gCms->variables['position'] = $pageinfo->content_hierarchy; 205 global $gCms; 206 $contentops =& $gCms->GetContentOperations(); 207 $gCms->variables['friendly_position'] = $contentops->CreateFriendlyHierarchyPosition($pageinfo->content_hierarchy); 208 209 $smarty->assign('content_id', $pageinfo->content_id); 210 $smarty->assign('page', $page); 211 $smarty->assign('page_id', $page); 212 $smarty->assign('page_name', $pageinfo->content_alias); 213 $smarty->assign('page_alias', $pageinfo->content_alias); 214 $smarty->assign('position', $pageinfo->content_hierarchy); 215 $smarty->assign('friendly_position', $gCms->variables['friendly_position']); 216 } 217 else if (get_site_preference('enablecustom404') == '' || get_site_preference('enablecustom404') == "0") 218 { 219 ErrorHandler404(); 220 exit; 221 } 222 223 $html = ''; 224 $cached = ''; 225 226 if (isset($_GET["print"])) 227 { 228 ($smarty->is_cached('print:'.$page, '', $pageinfo->template_id)?$cached="":$cached="not "); 229 $html = $smarty->fetch('print:'.$page, '', $pageinfo->template_id) . "\n"; 230 } 231 else 232 { 233 #If this is a case where a module doesn't want a template to be shown, just disable caching 234 if (isset($smarty->id) && $smarty->id != '' && isset($_REQUEST[$smarty->id.'showtemplate']) && $_REQUEST[$smarty->id.'showtemplate'] == 'false') 235 { 236 $html = $smarty->fetch('template:notemplate') . "\n"; 237 } 238 else 239 { 240 $smarty->caching = false; 241 $smarty->compile_check = true; 242 ($smarty->is_cached('template:'.$pageinfo->template_id)?$cached="":$cached="not "); 243 $html = $smarty->fetch('template:'.$pageinfo->template_id) . "\n"; 244 } 245 } 246 247 #if ((get_site_preference('enablecustom404') == '' || get_site_preference('enablecustom404') == "0") && (!$config['debug'])) 248 #{ 249 # set_error_handler($old_error_handler); 250 #} 251 252 if (!$cached) 253 { 254 #Perform the content postrendernoncached callback 255 reset($gCms->modules); 256 while (list($key) = each($gCms->modules)) 257 { 258 $value =& $gCms->modules[$key]; 259 if ($gCms->modules[$key]['installed'] == true && 260 $gCms->modules[$key]['active'] == true) 261 { 262 $gCms->modules[$key]['object']->ContentPostRenderNonCached($html); 263 } 264 } 265 //Events::SendEvent('Core', 'ContentPostRenderNonCached', array(&$html)); 266 } 267 268 #Perform the content postrender callback 269 reset($gCms->modules); 270 while (list($key) = each($gCms->modules)) 271 { 272 $value =& $gCms->modules[$key]; 273 if ($gCms->modules[$key]['installed'] == true && 274 $gCms->modules[$key]['active'] == true) 275 { 276 $gCms->modules[$key]['object']->ContentPostRender($html); 277 } 278 } 279 280 Events::SendEvent('Core', 'ContentPostRender', array('content' => &$html)); 281 282 header("Content-Type: " . $gCms->variables['content-type'] . "; charset=" . (isset($pageinfo->template_encoding) && $pageinfo->template_encoding != ''?$pageinfo->template_encoding:get_encoding())); 283 284 echo $html; 285 286 @ob_flush(); 287 288 $endtime = microtime(); 289 290 $db =& $gCms->GetDb(); 291 292 if ($config["debug"] == true) 293 { 294 echo "<p>Generated in ".microtime_diff($starttime,$endtime)." seconds by CMS Made Simple using ".(isset($db->query_count)?$db->query_count:'')." SQL queries and ".(function_exists('memory_get_usage')?memory_get_usage():'n/a')." bytes of memory</p>"; 295 } 296 297 echo "<!-- Generated in ".microtime_diff($starttime,$endtime)." seconds by CMS Made Simple using ".(isset($db->query_count)?$db->query_count:'')." SQL queries -->\n"; 298 #echo "<p>Generated in ".microtime_diff($starttime,$endtime)." seconds by CMS Made Simple (".$cached."cached) using ".(isset($db->query_count)?$db->query_count:'')." SQL queries and ".(function_exists('memory_get_usage')?memory_get_usage():'n/a')." bytes of memory</p>"; 299 echo "<!-- CMS Made Simple - Released under the GPL - http://cmsmadesimple.org -->\n"; 300 301 if (get_site_preference('enablesitedownmessage') == "1" || $config['debug'] == true) 302 { 303 $smarty->clear_compiled_tpl(); 304 #$smarty->clear_all_cache(); 305 } 306 307 if ($config["debug"] == true) 308 { 309 #$db->LogSQL(false); // turn off logging 310 311 # output summary of SQL logging results 312 #$perf = NewPerfMonitor($db); 313 #echo $perf->SuspiciousSQL(); 314 #echo $perf->ExpensiveSQL(); 315 316 #echo $sql_queries; 317 foreach ($gCms->errors as $error) 318 { 319 echo $error; 320 } 321 } 322 323 # vim:ts=4 sw=4 noet 324 ?>
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 |