GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

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
commit  325c55c6309b98c3e310d2a5a812d50d95ba1db7
tree    c5849f4ed8ccd949819a093c31dc33f7b666adfa
cmsmadesimple-2-0 / include.php
100644 228 lines (194 sloc) 6.676 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
<?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');
 
$log =& LoggerManager::getLogger('include.php');
$log->debug('Starting include.php');
 
/**
* 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);
 
#Setup session with different id and start it
@session_name("CMSSESSID");
@ini_set('url_rewriter.tags', '');
@ini_set('session.use_trans_sid', 0);
#if(!@session_id()) {
if(!@session_id() && (isset($_REQUEST[session_name()]) || isset($CMS_ADMIN_PAGE))) {
  #Trans SID sucks also...
  @ini_set('url_rewriter.tags', '');
  @ini_set('session.use_trans_sid', 0);
  @session_start();
}
 
require_once(dirname(__FILE__)."/lib/misc.functions.php");
 
#Make a new CMS object
require_once(dirname(__FILE__)."/lib/classes/class.global.inc.php");
$gCms = new CmsObject();
 
#Setup hash for storing all modules
$gCms->cmsmodules = array();
$gCms->userplugins = array();
$gCms->cmsplugins = array();
$gCms->siteprefs = array();
 
#Load the config file (or defaults if it doesn't exist)
require_once(dirname(__FILE__)."/version.php");
require_once(dirname(__FILE__)."/lib/config.functions.php");
 
#make a local reference
#if (cms_config_check_old_config()) {
#  cms_config_upgrade();
#}
$config = cms_config_load(true);
 
#Hack for changed directory and no way to upgrade config.php
$config['previews_path'] = str_replace('smarty/cms', 'tmp', $config['previews_path']);
 
#Attach to global object
$gCms->config = &$config;
 
#Set the locale if it's set
if (isset($config['locale']))
{
  @setlocale(LC_ALL, $config['locale']);
}
 
#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"];
}
 
#Setup db connection
include_once(dirname(__FILE__)."/lib/adodb/adodb.inc.php");
 
$sql_execs = 0;
 
$sql_queries = "";
 
function count_sql_execs($db, $sql, $inputarray)
{
  global $gCms;
  global $sql_execs;
  global $sql_queries;
  if (!is_array($inputarray)) $sql_execs++;
  else if (is_array(reset($inputarray))) $sql_execs += sizeof($inputarray);
  else $sql_execs++;
  if ($gCms->config["debug"] == true)
  {
    #$sql_queries .= "<p>$sql</p>\n";
  }
}
 
if (!isset($DONT_LOAD_DB)) {
  #global $ADODB_COUNTRECS;
  #$ADODB_COUNTRECS = false;
  $db = &ADONewConnection($config['dbms'], 'pear:date');
  if (isset($config['persistent_db_conn']) && $config['persistent_db_conn'] == true)
  {
    $db->PConnect($config["db_hostname"],$config["db_username"],$config["db_password"],$config["db_name"]);
  }
  else
  {
    $db->Connect($config["db_hostname"],$config["db_username"],$config["db_password"],$config["db_name"]);
  }
  if (!$db) die("Connection failed");
  $db->SetFetchMode(ADODB_FETCH_ASSOC);
  $db->fnExecute = 'count_sql_execs';
  if ($gCms->config['debug'] == true)
  {
    #$db->debug = true;
  }
  $gCms->db = &$db;
}
 
require_once(dirname(__FILE__).'/lib/smarty/Smarty.class.php');
#require_once(dirname(__FILE__)."/lib/db.functions.php");
require_once(dirname(__FILE__)."/lib/page.functions.php");
require_once(dirname(__FILE__)."/lib/content.functions.php");
#require_once(dirname(__FILE__)."/lib/module.functions.php");
require_once(dirname(__FILE__)."/lib/classes/class.pageinfo.inc.php");
require_once(dirname(__FILE__)."/lib/classes/class.content.inc.php");
require_once(dirname(__FILE__)."/lib/classes/class.module.inc.php");
require_once(dirname(__FILE__)."/lib/classes/class.group.inc.php");
require_once(dirname(__FILE__)."/lib/classes/class.user.inc.php");
require_once(dirname(__FILE__)."/lib/classes/class.bookmark.inc.php");
require_once(dirname(__FILE__).'/lib/classes/class.htmlblob.inc.php');
require_once(dirname(__FILE__).'/lib/classes/class.template.inc.php');
require_once(dirname(__FILE__).'/lib/classes/class.stylesheet.inc.php');
require_once(dirname(__FILE__)."/lib/translation.functions.php");
#require_once(dirname(__FILE__)."/lib/xajax/xajax.inc.php");
 
#Load content types
$dir = dirname(__FILE__)."/lib/contenttypes";
$ls = dir($dir);
while (($file = $ls->read()) != "")
{
  if (!is_dir("$dir/$file") && (strpos($file, ".") === false || strpos($file, ".") != 0))
  {
    if (substr($file,strlen($file)-4,4) == ".php")
    {
      include_once("$dir/$file");
    }
  }
}
 
if (!defined('SMARTY_DIR')) {
  define('SMARTY_DIR', dirname(__FILE__).'/lib/smarty/');
}
 
#Setup global smarty object
$smarty = new Smarty_CMS($config);
$gCms->smarty = &$smarty;
 
#Stupid magic quotes...
if(get_magic_quotes_gpc())
{
  strip_slashes($_GET);
  strip_slashes($_POST);
  strip_slashes($_REQUEST);
  strip_slashes($_COOKIE);
  strip_slashes($_SESSIONS);
}
 
#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;
}
 
#Load all site preferences
load_site_preferences();
 
if (isset($CMS_ADMIN_PAGE))
{
  include_once(dirname(__FILE__)."/".$config['admin_dir']."/lang.php");
 
  require_once(dirname(__FILE__).'/lib/convert/ConvertCharset.class.php');
  $gCms->variables['convertclass'] = new ConvertCharset();
 
}
 
#Load all installed module code
if (isset($LOAD_ALL_MODULES))
{
  ModuleOperations::LoadModules(true);
}
else
{
  ModuleOperations::LoadModules(false);
}
 
$log->debug('Leaving include.php');
 
# vim:ts=4 sw=4 noet
?>