File: prepend.php

package info (click to toggle)
dotclear 2.6.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 8,420 kB
  • sloc: php: 54,270; sql: 1,290; sh: 213; xml: 173; makefile: 158
file content (311 lines) | stat: -rw-r--r-- 11,607 bytes parent folder | download
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<?php
# -- BEGIN LICENSE BLOCK ---------------------------------------
#
# This file is part of Dotclear 2.
#
# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
# Licensed under the GPL version 2.0 license.
# See LICENSE file or
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK -----------------------------------------

/* ------------------------------------------------------------------------------------------- */
#  ClearBricks, DotClear classes auto-loader
if (@is_dir('/usr/lib/clearbricks')) {
	define('CLEARBRICKS_PATH','/usr/lib/clearbricks');
} elseif (is_dir(dirname(__FILE__).'/libs/clearbricks')) {
	define('CLEARBRICKS_PATH',dirname(__FILE__).'/libs/clearbricks');
} elseif (isset($_SERVER['CLEARBRICKS_PATH']) && is_dir($_SERVER['CLEARBRICKS_PATH'])) {
	define('CLEARBRICKS_PATH',$_SERVER['CLEARBRICKS_PATH']);
}

if (!defined('CLEARBRICKS_PATH') || !is_dir(CLEARBRICKS_PATH)) {
	exit('No clearbricks path defined');
}

require CLEARBRICKS_PATH.'/_common.php';
$__autoload['dcCore']				= dirname(__FILE__).'/core/class.dc.core.php';
$__autoload['dcAuth']				= dirname(__FILE__).'/core/class.dc.auth.php';
$__autoload['dcBlog']				= dirname(__FILE__).'/core/class.dc.blog.php';
$__autoload['dcCategories']			= dirname(__FILE__).'/core/class.dc.categories.php';
$__autoload['dcError']				= dirname(__FILE__).'/core/class.dc.error.php';
$__autoload['dcMeta']				= dirname(__FILE__).'/core/class.dc.meta.php';
$__autoload['dcMedia']				= dirname(__FILE__).'/core/class.dc.media.php';
$__autoload['dcPostMedia']				= dirname(__FILE__).'/core/class.dc.postmedia.php';
$__autoload['dcModules']				= dirname(__FILE__).'/core/class.dc.modules.php';
$__autoload['dcPlugins']				= dirname(__FILE__).'/core/class.dc.plugins.php';
$__autoload['dcThemes']				= dirname(__FILE__).'/core/class.dc.themes.php';
$__autoload['dcRestServer']			= dirname(__FILE__).'/core/class.dc.rest.php';
$__autoload['dcNamespace']			= dirname(__FILE__).'/core/class.dc.namespace.php';
$__autoload['dcSettings']			= dirname(__FILE__).'/core/class.dc.settings.php';
$__autoload['dcTrackback']			= dirname(__FILE__).'/core/class.dc.trackback.php';
$__autoload['dcUpdate']				= dirname(__FILE__).'/core/class.dc.update.php';
$__autoload['dcUtils']				= dirname(__FILE__).'/core/class.dc.utils.php';
$__autoload['dcXmlRpc']				= dirname(__FILE__).'/core/class.dc.xmlrpc.php';
$__autoload['dcLog']				= dirname(__FILE__).'/core/class.dc.log.php';
$__autoload['dcWorkspace']			= dirname(__FILE__).'/core/class.dc.workspace.php';
$__autoload['dcPrefs']				= dirname(__FILE__).'/core/class.dc.prefs.php';
$__autoload['dcStore']			= dirname(__FILE__).'/core/class.dc.store.php';
$__autoload['dcStoreReader']		= dirname(__FILE__).'/core/class.dc.store.reader.php';
$__autoload['dcStoreParser']		= dirname(__FILE__).'/core/class.dc.store.parser.php';
$__autoload['dcFavorites']			= dirname(__FILE__).'/admin/class.dc.favorites.php';

$__autoload['rsExtPost']				= dirname(__FILE__).'/core/class.dc.rs.extensions.php';
$__autoload['rsExtComment']			= dirname(__FILE__).'/core/class.dc.rs.extensions.php';
$__autoload['rsExtDates']			= dirname(__FILE__).'/core/class.dc.rs.extensions.php';
$__autoload['rsExtUser']				= dirname(__FILE__).'/core/class.dc.rs.extensions.php';

$__autoload['dcMenu']				= dirname(__FILE__).'/admin/class.dc.menu.php';
$__autoload['dcPage']				= dirname(__FILE__).'/admin/lib.dc.page.php';
$__autoload['adminGenericList']		= dirname(__FILE__).'/admin/lib.pager.php';
$__autoload['adminPostList']			= dirname(__FILE__).'/admin/lib.pager.php';
$__autoload['adminPostMiniList']		= dirname(__FILE__).'/admin/lib.pager.php';
$__autoload['adminCommentList']		= dirname(__FILE__).'/admin/lib.pager.php';
$__autoload['adminUserList']			= dirname(__FILE__).'/admin/lib.pager.php';
$__autoload['dcPager']		= dirname(__FILE__).'/admin/lib.pager.php';
$__autoload['dcAdminCombos']			= dirname(__FILE__).'/admin/lib.admincombos.php';
$__autoload['adminModulesList']			= dirname(__FILE__).'/admin/lib.moduleslist.php';
$__autoload['adminThemesList']			= dirname(__FILE__).'/admin/lib.moduleslist.php';

$__autoload['dcTemplate']			= dirname(__FILE__).'/public/class.dc.template.php';
$__autoload['context']				= dirname(__FILE__).'/public/lib.tpl.context.php';
$__autoload['dcUrlHandlers']			= dirname(__FILE__).'/public/lib.urlhandlers.php';
$__autoload['dcPostsActionsPage']			= dirname(__FILE__).'/admin/actions/class.dcactionposts.php';
$__autoload['dcCommentsActionsPage']			= dirname(__FILE__).'/admin/actions/class.dcactioncomments.php';
$__autoload['dcActionsPage']			= dirname(__FILE__).'/admin/actions/class.dcaction.php';

# Clearbricks extensions
html::$absolute_regs[] = '/(<param\s+name="movie"\s+value=")(.*?)(")/msu';
html::$absolute_regs[] = '/(<param\s+name="FlashVars"\s+value=".*?(?:mp3|flv)=)(.*?)(&|")/msu';
/* ------------------------------------------------------------------------------------------- */


mb_internal_encoding('UTF-8');

# Setting timezone
dt::setTZ('UTC');

# CLI_MODE, boolean constant that tell if we are in CLI mode
define('CLI_MODE',PHP_SAPI == 'cli');

# Disallow every special wrapper
if (function_exists('stream_wrapper_unregister'))
{
	foreach (array('http','https','ftp','ftps','ssh2.shell','ssh2.exec',
	'ssh2.tunnel','ssh2.sftp','ssh2.scp','ogg','expect') as $p) {
		@stream_wrapper_unregister($p);
	}
}

if (isset($_SERVER['DC_RC_PATH'])) {
	define('DC_RC_PATH',$_SERVER['DC_RC_PATH']);
} elseif (isset($_SERVER['REDIRECT_DC_RC_PATH'])) {
	define('DC_RC_PATH',$_SERVER['REDIRECT_DC_RC_PATH']);
} else {
	define('DC_RC_PATH',dirname(__FILE__).'/config.php');
}

if (!is_file(DC_RC_PATH))
{
	if (strpos($_SERVER['SCRIPT_FILENAME'],'/admin') === false) {
		$path = 'admin/install/wizard.php';
	} else {
		$path = strpos($_SERVER['PHP_SELF'],'/install') === false ? 'install/wizard.php' : 'wizard.php';
	}
	http::redirect($path);
}

require DC_RC_PATH;

/*== DC_DEBUG ==
if (!defined('DC_DEBUG')) {
	define('DC_DEBUG',true);
}
if (DC_DEBUG) {
	ini_set('display_errors',true);
	error_reporting(E_ALL | E_STRICT);
}
//*/

if (!defined('DC_DEBUG')) {
	define('DC_DEBUG',false);
}

# Constants
define('DC_ROOT',path::real(dirname(__FILE__).'/..'));
define('DC_VERSION','2.6.4');
define('DC_DIGESTS',dirname(__FILE__).'/digests');
define('DC_L10N_ROOT',dirname(__FILE__).'/../locales');
define('DC_L10N_UPDATE_URL','http://services.dotclear.net/dc2.l10n/?version=%s');
define('DC_DISTRIB_PLUGINS','aboutConfig,akismet,antispam,attachments,blogroll,blowupConfig,dclegacy,fairTrackbacks,importExport,maintenance,pages,pings,simpleMenu,tags,themeEditor,userPref,widgets');
define('DC_DISTRIB_THEMES','blueSilence,blowupConfig,customCSS,default,ductile');

if (!defined('DC_VENDOR_NAME')) {
	define('DC_VENDOR_NAME','Dotclear');
}

if (!defined('DC_XMLRPC_URL')) {
	define('DC_XMLRPC_URL','%1$sxmlrpc/%2$s');
}

if (!defined('DC_ADMIN_SSL')) {
	define('DC_ADMIN_SSL',false);
}

if (defined('DC_FORCE_SCHEME_443') && DC_FORCE_SCHEME_443) {
	http::$https_scheme_on_443 = true;
}

if (!defined('DC_DBPERSIST')) {
	define('DC_DBPERSIST',false);
}

if (!defined('DC_UPDATE_URL')) {
	define('DC_UPDATE_URL','http://download.dotclear.org/versions.xml');
}

if (!defined('DC_UPDATE_VERSION')) {
	define('DC_UPDATE_VERSION','stable');
}

if (!defined('DC_ALLOW_MULTI_MODULES')) {
	define('DC_ALLOW_MULTI_MODULES',false);
}

l10n::init();

try {
	$core = new dcCore(DC_DBDRIVER,DC_DBHOST,DC_DBNAME,DC_DBUSER,DC_DBPASSWORD,DC_DBPREFIX,DC_DBPERSIST);
} catch (Exception $e) {
	init_prepend_l10n();
	if (!defined('DC_CONTEXT_ADMIN')) {
		__error(__('Site temporarily unavailable'),
			__('<p>We apologize for this temporary unavailability.<br />'.
			'Thank you for your understanding.</p>'),
			20);
	} else {
		__error(__('Unable to connect to database')
			,$e->getCode() == 0 ?
			sprintf(__('<p>This either means that the username and password information in '.
			'your <strong>config.php</strong> file is incorrect or we can\'t contact '.
			'the database server at "<em>%s</em>". This could mean your '.
			'host\'s database server is down.</p> '.
			'<ul><li>Are you sure you have the correct username and password?</li>'.
			'<li>Are you sure that you have typed the correct hostname?</li>'.
			'<li>Are you sure that the database server is running?</li></ul>'.
			'<p>If you\'re unsure what these terms mean you should probably contact '.
			'your host. If you still need help you can always visit the '.
			'<a href="http://forum.dotclear.net/">Dotclear Support Forums</a>.</p>').
			(DC_DEBUG ?
				__('The following error was encountered while trying to read the database:').'</p><ul><li>'.$e->getMessage().'</li></ul>' :	'')
			,(DC_DBHOST != '' ? DC_DBHOST : 'localhost')
			)
			: ''
			,20);
	}
}

# If we have some __top_behaviors, we load them
if (isset($__top_behaviors) && is_array($__top_behaviors))
{
	foreach ($__top_behaviors as $b) {
		$core->addBehavior($b[0],$b[1]);
	}
	unset($b);
}

http::trimRequest();
try {
	http::unsetGlobals();
} catch (Exception $e) {
	header('Content-Type: text/plain');
	echo $e->getMessage();
	exit;
}

$core->url->registerDefault(array('dcUrlHandlers','home'));
$core->url->registerError(array('dcUrlHandlers','default404'));
$core->url->register('lang','','^([a-zA-Z]{2}(?:-[a-z]{2})?(?:/page/[0-9]+)?)$',array('dcUrlHandlers','lang'));
$core->url->register('post','post','^post/(.+)$',array('dcUrlHandlers','post'));
$core->url->register('preview','preview','^preview/(.+)$',array('dcUrlHandlers','preview'));
$core->url->register('category','category','^category/(.+)$',array('dcUrlHandlers','category'));
$core->url->register('archive','archive','^archive(/.+)?$',array('dcUrlHandlers','archive'));

$core->url->register('feed','feed','^feed/(.+)$',array('dcUrlHandlers','feed'));
$core->url->register('trackback','trackback','^trackback/(.+)$',array('dcUrlHandlers','trackback'));
$core->url->register('rsd','rsd','^rsd$',array('dcUrlHandlers','rsd'));
$core->url->register('xmlrpc','xmlrpc','^xmlrpc/(.+)$',array('dcUrlHandlers','xmlrpc'));

$core->setPostType('post','post.php?id=%d',$core->url->getURLFor('post','%s'),'Posts');

# Store upload_max_filesize in bytes
$u_max_size = files::str2bytes(ini_get('upload_max_filesize'));
$p_max_size = files::str2bytes(ini_get('post_max_size'));
if ($p_max_size < $u_max_size) {
	$u_max_size = $p_max_size;
}
define('DC_MAX_UPLOAD_SIZE',$u_max_size);
unset($u_max_size); unset($p_max_size);

# Shutdown
register_shutdown_function('__shutdown');

function __shutdown()
{
	global $__shutdown;
	if (is_array($__shutdown)) {
		foreach ($__shutdown as $f) {
			if (is_callable($f)) {
				call_user_func($f);
			}
		}
	}
	# Explicitly close session before DB connection
	try {
		if (session_id()) {
			session_write_close();
		}
	} catch (Exception $e) {}
	$GLOBALS['core']->con->close();
}

function __error($summary,$message,$code=0)
{
	# Error codes
	# 10 : no config file
	# 20 : database issue
	# 30 : blog is not defined
	# 40 : template files creation
	# 50 : no default theme
	# 60 : template processing error
	# 70 : blog is offline

	if (CLI_MODE)
	{
		trigger_error($summary,E_USER_ERROR);
		exit(1);
	}
	else
	{
		if (defined('DC_ERRORFILE') && is_file(DC_ERRORFILE)) {
			include DC_ERRORFILE;
		} else {
			include dirname(__FILE__).'/core_error.php';
		}
		exit;
	}
}

function init_prepend_l10n()
{
	# Loading locales for detected language
	$dlang = http::getAcceptLanguages();
	foreach($dlang as $l)
	{
		if ($l == 'en' || l10n::set(dirname(__FILE__).'/../locales/'.$l.'/main') !== false) {
			l10n::lang($l);
			break;
		}
	}
}