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
calguy1000 (author)
Fri May 18 12:29:44 -0700 2007
commit  a938e5396352c123475725965c78992c8fe726ed
tree    abb6f396b1d10c1007f9d0b409f638c403a0ecb1
parent  add49c7685647c9ec1ab4a1c4cb435a50d60d9fe
cmsmadesimple-2-0 / include.php
100644 246 lines (213 sloc) 8.181 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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<?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$
 
$dirname = dirname(__FILE__);
require_once($dirname.DIRECTORY_SEPARATOR.'fileloc.php');
 
$session_key = substr(md5($dirname), 0, 8);
 
#Setup session with different id and start it
@session_name('CMSSESSID' . $session_key);
@ini_set('url_rewriter.tags', '');
@ini_set('session.use_trans_sid', 0);
if(!@session_id())
{
    #Trans SID sucks also...
    @ini_set('url_rewriter.tags', '');
    @ini_set('session.use_trans_sid', 0);
    @session_start();
}
 
/**
* This file is included in every page. It does all seutp functions including
* importing additional functions/classes, setting up sessions and nls, and
* construction of various important variables like $gCms.
*
* @package CMS
*/
#magic_quotes_runtime is a nuisance... turn it off before it messes something up
set_magic_quotes_runtime(false);
 
require_once($dirname.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'misc.functions.php');
require_once($dirname.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'module.functions.php');
debug_buffer('', 'Start of include');
 
# sanitize $_GET
array_walk_recursive($_GET, 'sanitize_get_var');
 
#Make a new CMS object
require(cms_join_path($dirname,'lib','classes','class.global.inc.php'));
$gCms =& new CmsObject();
if (isset($starttime))
{
    $gCms->variables['starttime'] = $starttime;
}
 
#Load the config file (or defaults if it doesn't exist)
require(cms_join_path($dirname,'version.php'));
require(cms_join_path($dirname,'lib','config.functions.php'));
 
#Grab the current configuration
$config =& $gCms->GetConfig();
 
#Hack for changed directory and no way to upgrade config.php
$config['previews_path'] = str_replace('smarty/cms', 'tmp', $config['previews_path']);
 
#Add users if they exist in the session
$gCms->variables['user_id'] = '';
if (isset($_SESSION['cms_admin_user_id']))
{
    $gCms->variables['user_id'] = $_SESSION['cms_admin_user_id'];
}
 
$gCms->variables['username'] = '';
if (isset($_SESSION['cms_admin_username']))
{
    $gCms->variables['username'] = $_SESSION['cms_admin_username'];
}
 
debug_buffer('loading smarty');
require(cms_join_path($dirname,'lib','smarty','Smarty.class.php'));
debug_buffer('loading adodb');
require(cms_join_path($dirname,'lib','adodb.functions.php'));
load_adodb();
debug_buffer('loading page functions');
require_once(cms_join_path($dirname,'lib','page.functions.php'));
debug_buffer('loading content functions');
require_once(cms_join_path($dirname,'lib','content.functions.php'));
debug_buffer('loading pageinfo functions');
require_once(cms_join_path($dirname,'lib','classes','class.pageinfo.inc.php'));
debug_buffer('loading translation functions');
require_once(cms_join_path($dirname,'lib','translation.functions.php'));
debug_buffer('loading events functions');
require_once(cms_join_path($dirname,'lib','classes','class.events.inc.php'));
 
if (isset($config['backwards_compatible']) && $config['backwards_compatible'] == true)
{
  load_backwards_compatibility();
}
 
debug_buffer('done loading files');
 
#Load them into the usual variables. This'll go away a little later on.
global $DONT_LOAD_DB;
if (!isset($DONT_LOAD_DB))
{
    $cmsdb =& $gCms->GetDB();
// $cmsdb->Execute('set names utf8'); // database connection with utf-8
}
 
$smarty =& $gCms->GetSmarty();
$contenttypes =& $gCms->contenttypes;
 
#Load content types
$dir = cms_join_path($dirname,'lib','classes','contenttypes');
$handle=opendir($dir);
while ($file = readdir ($handle))
{
    $path_parts = pathinfo($file);
    if (isset($path_parts['extension']) && $path_parts['extension'] == 'php')
    {
    $obj =& new CmsContentTypePlaceholder();
    $obj->type = strtolower(basename($file, '.inc.php'));
    $obj->filename = cms_join_path($dir,$file);
    $obj->loaded = false;
    $obj->friendlyname = basename($file, '.inc.php');
    $contenttypes[strtolower(basename($file, '.inc.php'))] =& $obj;
    }
}
closedir($handle);
 
if (!defined('SMARTY_DIR')) {
    define('SMARTY_DIR', cms_join_path($dirname,'lib','smarty') . DIRECTORY_SEPARATOR);
}
 
#Stupid magic quotes...
if(get_magic_quotes_gpc())
{
    stripslashes_deep($_GET);
    stripslashes_deep($_POST);
    stripslashes_deep($_REQUEST);
    stripslashes_deep($_COOKIE);
    stripslashes_deep($_SESSION);
}
 
#Fix for IIS (and others) to make sure REQUEST_URI is filled in
if (!isset($_SERVER['REQUEST_URI']))
{
    $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
    if(isset($_SERVER['QUERY_STRING']))
    {
        $_SERVER['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];
    }
}
 
#Setup the object sent to modules
$gCms->variables['pluginnum'] = 1;
if (isset($page))
{
  $gCms->variables['page'] = $page;
}
 
#Set a umask
$global_umask = get_site_preference('global_umask','');
if( $global_umask != '' )
{
    @umask( $global_umask );
}
 
#Set the locale if it's set
#either in the config, or as a site preference.
$frontendlang = get_site_preference('frontendlang','');
if (isset($config['locale']) && $config['locale'] != '')
{
    $frontendlang = $config['locale'];
}
if ($frontendlang != '')
{
    @setlocale(LC_ALL, $frontendlang);
}
 
$smarty->assign('sitename', get_site_preference('sitename', 'CMSMS Site'));
$smarty->assign('lang',$frontendlang);
$smarty->assign('encoding',get_encoding());
$smarty->assign_by_ref('gCms',$gCms);
 
if ($config['debug'] == true)
{
  $smarty->debugging = true;
  $smarty->error_reporting = 'E_ALL';
}
if (isset($CMS_ADMIN_PAGE) || isset($CMS_STYLESHEET))
{
    include_once(cms_join_path($dirname,$config['admin_dir'],'lang.php'));
 
  #This will only matter on upgrades now. All new stuff (0.13 on) will be UTF-8.
  if (is_file(cms_join_path($dirname,'lib','convert','ConvertCharset.class.php')))
  {
    include(cms_join_path($dirname,'lib','convert','ConvertCharset.class.php'));
    $gCms->variables['convertclass'] =& new ConvertCharset();
  }
}
 
#Load all installed module code
$modload =& $gCms->GetModuleLoader();
$modload->LoadModules(isset($LOAD_ALL_MODULES), !isset($CMS_ADMIN_PAGE));
 
debug_buffer('', 'End of include');
 
function sanitize_get_var(&$value, $key)
{
    $value = eregi_replace('\<\/?script[^\>]*\>', '', $value);
}
 
function load_backwards_compatibility()
{
  $dirname = dirname(__FILE__);
  debug_buffer('loading template functions');
  require_once(cms_join_path($dirname,'lib','classes','class.templateoperations.inc.php'));
  debug_buffer('loading gcb functions');
  require_once(cms_join_path($dirname,'lib','classes','class.globalcontentoperations.inc.php'));
  debug_buffer('loading module class');
  require_once(cms_join_path($dirname,'lib','classes','class.moduleoperations.inc.php'));
  debug_buffer('loading bookmark functions');
  require_once(cms_join_path($dirname,'lib','classes','class.bookmarkoperations.inc.php'));
  debug_buffer('loading content class');
  require_once(cms_join_path($dirname,'lib','classes','class.contentoperations.inc.php'));
  debug_buffer('loading user functions');
  require_once(cms_join_path($dirname,'lib','classes','class.useroperations.inc.php'));
  debug_buffer('loading group functions');
  require_once(cms_join_path($dirname,'lib','classes','class.groupoperations.inc.php'));
  debug_buffer('loading stylesheet functions');
  require_once(cms_join_path($dirname,'lib','classes','class.stylesheetoperations.inc.php'));
  debug_buffer('loading user tags functions');
  require_once(cms_join_path($dirname,'lib','classes','class.usertagoperations.inc.php'));
}
 
# vim:ts=4 sw=4 noet
?>