public
Description: Git mirror of the CMS Made Simple 2.0 rewrite
Homepage: http://cmsmadesimple.org
Clone URL: git://github.com/tedkulp/cmsmadesimple-2-0.git
cmsmadesimple-2-0 / index.php
100644 200 lines (166 sloc) 6.174 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?php
#CMS - CMS Made Simple
#(c)2004 by Ted Kulp (wishy@users.sf.net)
#This project's homepage is: http://cmsmadesimple.sf.net
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program 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 General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#$Id$
 
require_once(dirname(__FILE__).'/fileloc.php');
 
/**
* Entry point for all non-admin pages
*
* @package CMS
*/  
$starttime = microtime();
 
@ob_start();
 
clearstatcache();
 
if (!file_exists(CONFIG_FILE_LOCATION) || filesize(CONFIG_FILE_LOCATION) < 800)
{
    require_once("lib/misc.functions.php");
    redirect("install/install.php");
}
else if (file_exists(TMP_CACHE_LOCATION.'/SITEDOWN'))
{
  echo "<html><head><title>Maintenance</title></head><body><p>Site down for maintenance.</p></body></html>";
  exit;
}
 
if (!is_writable(TMP_TEMPLATES_C_LOCATION) || !is_writable(TMP_CACHE_LOCATION))
{
  echo '<html><title>Error</title></head><body>';
  echo '<p>The following directories must be writable by the web server:<br />';
  echo 'tmp/cache<br />';
  echo 'tmp/templates_c<br /></p>';
  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>';
  echo '</body></html>';
  exit;
}
 
require_once(dirname(__FILE__)."/include.php"); #Makes gCms object
 
$params = array_merge($_GET, $_POST);
 
global $gCms;
$smarty = &$gCms->smarty;
$smarty->params = $params;
 
$page = '';
 
$smarty->id = (isset($params['id'])?$params['id']:'');
if (isset($params['id']) && isset($params[$params['id'] . 'returnid']))
{
  $page = $params[$params['id'] . 'returnid'];
}
 
if (isset($config["query_var"]) && $config["query_var"] != "" && isset($_GET[$config["query_var"]]))
{
  $page = $_GET[$config["query_var"]];
}
#else if (isset($_SERVER["PATH_INFO"]) && (isset($_SERVER["SCRIPT_URL"]) && ($_SERVER["PATH_INFO"] != $_SERVER["SCRIPT_URL"])))
#{
#  $page = $_SERVER["PATH_INFO"];
#}
#else if (isset($_SERVER["QUERY_STRING"]) && strpos($_SERVER["QUERY_STRING"], 'deleteinstall') === false)
#{
#  $page = $_SERVER["QUERY_STRING"];
#}
 
if ($page == '')
{
  $page =& ContentManager::GetDefaultContent();
}
else
{
    $page = preg_replace('/\</','',$page);
}
 
$old_error_handler = '';
if ((get_site_preference('enablecustom404') == '' || get_site_preference('enablecustom404') == "0") && (!$config['debug']))
{
  $old_error_handler = set_error_handler("ErrorHandler404");
}
 
$pageinfo = PageInfoOperations::LoadPageInfoByContentAlias($page);
if (isset($pageinfo) && $pageinfo !== FALSE)
{
  $gCms->variables['pageinfo'] =& $pageinfo;
 
  $gCms->variables['content_id'] = $pageinfo->content_id;
  $gCms->variables['page'] = $page;
  $gCms->variables['page_id'] = $page;
 
  $gCms->variables['page_name'] = $pageinfo->content_alias;
  $gCms->variables['position'] = $pageinfo->content_hierarchy;
  $gCms->variables['friendly_position'] = ContentManager::CreateFriendlyHierarchyPosition($pageinfo->content_hierarchy);
  
}
 
$html = '';
$cached = '';
 
if (isset($_GET["print"]))
{
  ($smarty->is_cached('print:'.$page, '', $pageinfo->template_id)?$cached="":$cached="not ");
  $html = $smarty->fetch('print:'.$page, '', $pageinfo->template_id) . "\n";
}
else
{
  #If this is a case where a module doesn't want a template to be shown, just disable caching
  if (isset($_GET['id']) && isset($_GET[$_GET['id'].'showtemplate']) && $_GET[$_GET['id'].'showtemplate'] == 'false')
  {
    $html = $smarty->fetch('template:notemplate') . "\n";
  }
  else
  {
    ($smarty->is_cached('template:'.$pageinfo->template_id)?$cached="":$cached="not ");
    $html = $smarty->fetch('template:'.$pageinfo->template_id) . "\n";
  }
}
 
if ((get_site_preference('enablecustom404') == '' || get_site_preference('enablecustom404') == "0") && (!$config['debug']))
{
  set_error_handler($old_error_handler);
}
 
if (!$cached)
{
  #Perform the content postrendernoncached callback
  foreach($gCms->modules as $key=>$value)
  {
    if ($gCms->modules[$key]['installed'] == true &&
      $gCms->modules[$key]['active'] == true)
    {
      $gCms->modules[$key]['object']->ContentPostRenderNonCached($html);
    }
  }
}
 
#Perform the content postrender callback
foreach($gCms->modules as $key=>$value)
{
  if ($gCms->modules[$key]['installed'] == true &&
    $gCms->modules[$key]['active'] == true)
  {
    $gCms->modules[$key]['object']->ContentPostRender($html);
  }
}
 
header("Content-Type: " . $gCms->variables['content-type'] . "; charset=" . (isset($pageinfo->template_encoding) && $pageinfo->template_encoding != ''?$pageinfo->template_encoding:get_encoding()));
 
echo $html;
 
@ob_flush();
 
$endtime = microtime();
 
if ($config["debug"] == true)
{
  echo "<p>Generated in ".microtime_diff($starttime,$endtime)." seconds by CMS Made Simple $CMS_VERSION (".$cached."cached) using $sql_execs SQL queries and ".(function_exists('memory_get_usage')?memory_get_usage():'n/a')." bytes of memory</p>";
}
 
echo "<!-- Generated in ".microtime_diff($starttime,$endtime)." seconds by CMS Made Simple $CMS_VERSION (".$cached."cached) using $sql_execs SQL queries -->\n";
#echo "<p>Generated in ".microtime_diff($starttime,$endtime)." seconds by CMS Made Simple $CMS_VERSION (".$cached."cached) using $sql_execs SQL queries and ".(function_exists('memory_get_usage')?memory_get_usage():'n/a')." bytes of memory</p>";
echo "<!-- CMS Made Simple - Released under the GPL - http://cmsmadesimple.org -->\n";
 
if (get_site_preference('enablesitedownmessage') == "1")
{
  $smarty->clear_compiled_tpl();
  $smarty->clear_all_cache();
}
 
if ($config["debug"] == true)
{
  echo $sql_queries;
  foreach ($gCms->errors as $error)
  {
    echo $error;
  }
}
 
 
# vim:ts=4 sw=4 noet
?>