Dragonfly CMS logo Server sponsored and hosted by
DedicatedNOW
CVS logo  
.:: Home :: Dev. Resources :: Forums ::.
Dragonfly CMS CVS Repository
 Location: / cvs / html / includes / cmsinit.inc
This is a web interface to the Dragonfly CMS CVS tree. You can browse the file hierarchy by picking directories. If you pick a file, you will see the revision history for that file.
Selecting a revision number will show that revision of the file. There are links at each revision to display diffs, annotate and download.
Note: Info about CVS and our commits can be found at our CVS Info Forum
File name: html/includes/cmsinit.inc
Revision : 9.142.2.15 (2 years 5 months 2 weeks 6 days 18 hours 16 minutes 23 seconds ago) by nanocaiordo
Changed : +3 -3 lines
Comment: 9.3.1.0 project closed.


# Author Rev Line
1 djmaze 1.1 <?php
2 djmaze 1.1 /*********************************************
3 djmaze 9.16 CPG Dragonfly™ CMS
4 djmaze 1.1 ********************************************
5 nanocaio 9.118 Copyright © 2004 - 2007 by CPG-Nuke Dev Team
6 djmaze 9.58 http://dragonflycms.org
7 djmaze 1.1  
8 djmaze 9.16 Dragonfly is released under the terms and conditions
9 djmaze 8.10 of the GNU GPL version 2 or any later version
10 djmaze 1.1  
11 djmaze 9.17 $Source: /cvs/html/includes/cmsinit.inc,v $
12 nanocaio 9.142.2.15 $Revision: 9.142.2.14 $
13 nanocaio 9.138 $Author: nanocaiordo $
14 nanocaio 9.142.2.15 $Date: 2011/10/18 12:21:40 $
15 djmaze 9.16 **********************************************/
16 djmaze 9.64 # Disable DOS Attacks and any other strange behavior
17 akamu 9.66 if (((empty($_SERVER['HTTP_USER_AGENT']) || $_SERVER['HTTP_USER_AGENT'] == '-') && !defined('XMLFEED')) || defined('CORE_PATH')) { exit; }
18 akamu 9.66  
19 nanocaio 9.142.2.10 if (!defined('E_STRICT')) { define('E_STRICT', 2048); }
20 nanocaio 9.142.2.10 if (!defined('E_RECOVERABLE_ERROR')) { define('E_RECOVERABLE_ERROR', 4096); }
21 nanocaio 9.142.2.10 if (!defined('E_DEPRECATED')) { define('E_DEPRECATED', 8192); }
22 nanocaio 9.142.2.10 if (!defined('E_USER_DEPRECATED')) { define('E_USER_DEPRECATED', 16384); }
23 nanocaio 9.142.2.12 error_reporting(E_ALL ^ E_DEPRECATED);
24 nanocaio 9.142.2.5  
25 djmaze 9.78 #
26 djmaze 9.78 # Create constants
27 djmaze 9.78 #
28 djmaze 9.78 define('START_TIME', get_microtime());
29 nanocaio 9.142.2.15 define('CPG_NUKE', '9.3.1.0');
30 djmaze 9.82 define('GZIPSUPPORT', extension_loaded('zlib'));
31 djmaze 9.90 define('WINDOWS', (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN'));
32 djmaze 9.82 # Are we allowed to modify php.ini on the fly ?
33 djmaze 9.82 define('CAN_MOD_INI', !ereg('ini_set', ini_get('disable_functions')));
34 djmaze 9.99 define('MAGICQUOTES', get_magic_quotes_gpc()||ini_get('magic_quotes_sybase'));
35 djmaze 9.82 # http://bugs.php.net/bug.php?id=31849
36 djmaze 9.136 if (WINDOWS || !function_exists('posix_getpwuid')) {
37 djmaze 9.87 define('_DRAGONLY_OWNER', 'N/A');
38 djmaze 9.87 define('_PROCESS_UID', '0');
39 djmaze 9.87 define('_PROCESS_OWNER', 'nobody');
40 djmaze 9.87 } else {
41 djmaze 9.87 define('_DRAGONLY_OWNER', get_current_user());
42 djmaze 9.87 define('_PROCESS_UID', posix_geteuid());
43 djmaze 9.87 $processUser = posix_getpwuid(_PROCESS_UID);
44 djmaze 9.87 define('_PROCESS_OWNER', $processUser['name']);
45 djmaze 9.87 }
46 akamu 9.66  
47 djmaze 9.78 # Store the path of our (shared) core files
48 djmaze 9.78 $root_path = dirname(__FILE__);
49 djmaze 9.90 if (WINDOWS) { $root_path = str_replace('\\', '/', $root_path); }
50 djmaze 9.78 define('CORE_PATH', ((strlen($root_path) > 2) ? $root_path : './includes').'/');
51 djmaze 9.78 if (!defined('BASEDIR')) { define('BASEDIR', dirname(CORE_PATH).'/'); }
52 djmaze 9.78  
53 djmaze 9.78 $phpver = explode('.', phpversion());
54 djmaze 9.136 $phpver = "{$phpver[0]}{$phpver[1]}";
55 djmaze 9.78 define('PHPVERS', $phpver);
56 nanocaio 9.118 unset($root_path, $phpver);
57 nanocaio 9.118  
58 nanocaio 9.118 #
59 nanocaio 9.118 # Change behaviour for specific PHP versions
60 nanocaio 9.118 #
61 djmaze 9.130 if (PHPVERS >= '51') { date_default_timezone_set(date_default_timezone_get()); }
62 djmaze 9.130 //if (PHPVERS < '50') { require_once(CORE_PATH.'functions/php5.php'); }
63 djmaze 9.78  
64 nanocaio 9.142.2.3 # IE8 google.com/search?q=X-Content-Type-Options
65 nanocaio 9.142.2.3 header('X-Content-Type-Options: nosniff');
66 nanocaio 9.142.2.3  
67 djmaze 9.78 #
68 djmaze 9.78 # Set default settings
69 djmaze 9.78 #
70 djmaze 9.78  
71 djmaze 9.84 header('X-Powered-By: Dragonfly CMS using PHP engine');
72 djmaze 9.100  
73 djmaze 9.100 # http://bugs.php.net/bug.php?id=15693
74 djmaze 9.100 if ($_SERVER['REQUEST_METHOD'] == 'HEAD') { exit; }
75 djmaze 9.100  
76 djmaze 9.78 set_magic_quotes_runtime(0); # Disable magic_quotes_runtime
77 djmaze 9.78 umask(0);
78 djmaze 9.78  
79 djmaze 9.78 if (CAN_MOD_INI) {
80 djmaze 9.78 ini_set('magic_quotes_sybase', 0);
81 djmaze 9.78 // ini_set('include_path', ini_get('include_path').';'.CORE_PATH);
82 djmaze 9.79 ini_set('zlib.output_compression', 0);
83 djmaze 8.15 }
84 djmaze 9.78  
85 djmaze 9.64 # Compress output if server/php config allows
86 djmaze 9.80 if (ini_get('output_buffering')) {
87 djmaze 9.80 ob_end_clean();
88 djmaze 9.130 // header('Content-Encoding: none');
89 phoenix 9.124 header('Content-Encoding: ');
90 djmaze 9.80 }
91 djmaze 9.80 if (!defined('INSTALL')) {
92 nanocaio 9.142.2.10 if (GZIPSUPPORT && !ini_get('zlib.output_compression') && isset($_SERVER['HTTP_ACCEPT_ENCODING']) && false !== strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) {
93 djmaze 9.130 if (PHPVERS >= 43) { # PHP 4.2.x seems to give memleak
94 djmaze 9.130 ob_start('ob_gzhandler');
95 djmaze 9.130 } else {
96 djmaze 9.130 define('GZIP_COMPRESS', true);
97 djmaze 9.130 ob_start();
98 djmaze 9.130 ob_implicit_flush(0);
99 djmaze 9.130 header('Content-Encoding: gzip');
100 djmaze 9.130 }
101 djmaze 9.16 } else {
102 djmaze 9.64 # Some stupid firewalls don't send the HTTP_ACCEPT_ENCODING
103 djmaze 9.64 # So we still compress in memory for fast page generations
104 djmaze 9.64 # But it will take longer for the visitor to see the page.
105 djmaze 9.16 ob_start();
106 djmaze 9.16 ob_implicit_flush(0);
107 djmaze 9.16 }
108 djmaze 1.1 }
109 djmaze 9.80 if (!defined('GZIP_COMPRESS')) { define('GZIP_COMPRESS', false); }
110 djmaze 1.1  
111 djmaze 9.80 #
112 djmaze 9.80 # Check input variables
113 djmaze 9.80 #
114 djmaze 9.80  
115 djmaze 9.80 # Destroy GET/POST/Cookie variables from the global scope since IIS can't
116 djmaze 9.80 # turn off register_globals as Apache can thru .ht*
117 djmaze 9.80 if (intval(ini_get('register_globals')) != 0) {
118 djmaze 9.80 foreach ($_REQUEST AS $key => $val) { if (isset($$key)) unset($$key); }
119 djmaze 9.80 }
120 djmaze 9.99 if (is_array($_POST)) { array_walk($_POST, 'Prepare_INPUT'); }
121 djmaze 9.99 if (is_array($_GET)) { array_walk($_GET, 'Prepare_INPUT'); }
122 djmaze 9.80  
123 djmaze 9.83 if (!file_exists(CORE_PATH.'config.php')) {
124 djmaze 9.83 if (!defined('INSTALL')) { cpg_error('You must install Dragonfly first before you can use it'); }
125 djmaze 9.83 } else {
126 djmaze 9.83 require_once(CORE_PATH.'classes/cpg_debugger.php'); # we define our own error handler
127 djmaze 9.83 require_once(CORE_PATH.'config.php');
128 djmaze 9.83 }
129 nanocaio 9.131 require_once(CORE_PATH.'classes/methods.php');
130 djmaze 9.54 require_once(CORE_PATH.'db/db.php');
131 djmaze 9.54 require_once(CORE_PATH.'classes/cpg_cache.php');
132 djmaze 9.84 require_once(CORE_PATH.'functions/linking.php');
133 djmaze 9.84  
134 djmaze 9.84 if (defined('INSTALL')) return;
135 djmaze 9.84  
136 djmaze 9.54 require_once(CORE_PATH.'classes/time.php');
137 djmaze 9.84 if (!defined('XMLFEED')) {
138 djmaze 9.54 require_once(CORE_PATH.'functions/display.php');
139 djmaze 9.54 require_once(CORE_PATH.'classes/cpg_member.php');
140 djmaze 9.76 require_once(CORE_PATH.'classes/multibyte.php');
141 djmaze 9.54 require_once(CORE_PATH.'classes/session.php');
142 djmaze 9.54 require_once(CORE_PATH.'classes/template.php');
143 djmaze 9.16 }
144 djmaze 1.1  
145 nanocaio 9.142.2.9 function df_shutdown() {
146 nanocaio 9.142.2.9 global $SESS, $db;
147 nanocaio 9.142.2.9 if (is_object($SESS)) { $SESS->write_close; }
148 nanocaio 9.142.2.9 if (is_object($db)) { $db->sql_close(); }
149 nanocaio 9.142.2.9 }
150 nanocaio 9.142.2.9 register_shutdown_function('df_shutdown');
151 nanocaio 9.142.2.9  
152 djmaze 8.30 if (!Cache::array_load('MAIN_CFG')) {
153 djmaze 9.16 $result = $db->sql_query('SELECT * FROM '.$prefix.'_config_custom', true);
154 djmaze 9.16 if (!$result) { url_redirect('install.php'); }
155 djmaze 9.16 while ($row = $db->sql_fetchrow($result)) {
156 djmaze 9.16 $MAIN_CFG[$row['cfg_name']][$row['cfg_field']] = $row['cfg_value'];
157 djmaze 9.16 }
158 djmaze 9.16 Cache::array_save('MAIN_CFG');
159 djmaze 9.16 $db->sql_freeresult($result);
160 djmaze 1.4 }
161 djmaze 9.50 if (version_compare($MAIN_CFG['global']['Version_Num'], CPG_NUKE, '<')) {
162 trevor 9.60 cpg_error('<strong>We are currently upgrading our website.<br />Please be patient; we should be back shortly.</strong>', 'Maintenance');
163 djmaze 9.50 }
164 djmaze 8.35 $cpgdebugger->error_level = $MAIN_CFG['debug']['error_level'];
165 akamu 9.37 if (CAN_MOD_INI) ini_set('sendmail_from', $MAIN_CFG['global']['adminmail']);
166 djmaze 9.45 if (CPG_DEBUG) { trigger_error('sendmail_from: '.ini_get('sendmail_from'),E_USER_NOTICE); }
167 nanocaio 9.142.2.14 if (eregi('^(localhost|127.0.0.1|192.168|10\.|172.(1[6-9]|2[0-9]|3[0-1])\.)', $_SERVER['HTTP_HOST'])) { $MAIN_CFG['cookie']['domain'] = NULL; }
168 djmaze 8.23 else if ($MAIN_CFG['cookie']['server']) {
169 djmaze 9.77 $MAIN_CFG['cookie']['domain'] = $MAIN_CFG['server']['domain'] = str_replace('www.', '', $_SERVER['SERVER_NAME']);
170 djmaze 8.23 }
171 djmaze 9.52 $MAIN_CFG['global']['nukeurl'] = 'http://'.$MAIN_CFG['server']['domain'].substr($MAIN_CFG['server']['path'], 0, -1);
172 djmaze 9.77 $MAIN_CFG['server']['domain'] = preg_replace('#[a-z]+://#i', '', $MAIN_CFG['server']['domain']);
173 djmaze 1.48  
174 djmaze 9.52 if (!extension_loaded('gd')) { $MAIN_CFG['global']['sec_code'] = 0; }
175 djmaze 9.52 if ($MAIN_CFG['global']['admingraphic'] < 1) $MAIN_CFG['global']['admingraphic'] = 3;
176 djmaze 1.49 if (empty($MAIN_CFG['cookie']['member'])) $MAIN_CFG['cookie']['member'] = 'member';
177 djmaze 1.49 if (empty($MAIN_CFG['cookie']['admin'])) $MAIN_CFG['cookie']['admin'] = 'admin';
178 djmaze 1.52 $BASEHREF = ($_SERVER['SERVER_PORT'] != 443 ? 'http' : 'https') . '://';
179 djmaze 1.52 $BASEHREF .= (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $MAIN_CFG['server']['domain']);
180 djmaze 1.52 $BASEHREF .= $MAIN_CFG['server']['path'];
181 djmaze 9.130 extract($MAIN_CFG['global'], ((PHPVERS >= 43) ? EXTR_OVERWRITE | EXTR_REFS : EXTR_OVERWRITE));
182 djmaze 1.1  
183 djmaze 9.64 if (defined('XMLFEED')) return; # no need to load everything if it's a feed
184 djmaze 1.1  
185 djmaze 9.21 /******************************************************************************
186 djmaze 9.21 Set default metatags
187 djmaze 9.21 *******************************************************************************/
188 djmaze 9.21 $METATAGS['description'] = $slogan;
189 djmaze 9.21 $METATAGS['keywords'] = '';
190 djmaze 9.21 $METATAGS['resource-type'] = 'document';
191 djmaze 9.21 $METATAGS['distribution'] = 'global';
192 djmaze 9.21 $METATAGS['author'] = $sitename;
193 djmaze 9.21 $METATAGS['copyright'] = 'Copyright (c) '.date('Y').' by '.$sitename;
194 djmaze 9.21 $METATAGS['robots'] = 'index, follow';
195 djmaze 9.21 $METATAGS['rating'] = 'general';
196 djmaze 9.58 $METATAGS['generator'] = 'CPG Dragonfly CMS: Copyright (c) 2003-'.date('Y').' by CPG-Nuke Development Team, http://dragonflycms.org';
197 djmaze 9.21 //$METATAGS['revisit-after'] = '1 days';
198 djmaze 9.21 $METATAGS['MSSmartTagsPreventParsing'] = 'true';
199 djmaze 9.21  
200 djmaze 9.21 /******************************************************************************
201 djmaze 9.21 Start the session
202 djmaze 9.21 *******************************************************************************/
203 djmaze 9.80 $CPG_SESS = array();
204 nanocaio 9.142.2.12 $SESS = new cpg_session();
205 djmaze 9.21  
206 nanocaio 9.101 /******************************************************************************
207 nanocaio 9.142.2.6 Are we requesting the security code ?
208 nanocaio 9.142.2.6 *******************************************************************************/
209 nanocaio 9.142.2.6 if (isset($_GET['name']) && ($_GET['name'] == 'gfx' || (isset($_GET['op']) && $_GET['name'] == 'Your_Account' && $_GET['op'] == 'gfx'))) {
210 nanocaio 9.142.2.6 require(BASEDIR.'includes/gfxchk.php');
211 nanocaio 9.142.2.6 }
212 nanocaio 9.142.2.6 /******************************************************************************
213 nanocaio 9.101 Include language to detect languages from browser setting and user preferences
214 nanocaio 9.125 Join our language initiative (NLI) http://dragonflycms.org
215 nanocaio 9.101 *******************************************************************************/
216 nanocaio 9.142.2.6 define('_JS_ALERT', '<script type="text/javascript">alert("%s");</script>');
217 nanocaio 9.101 require_once(CORE_PATH.'functions/language.php');
218 djmaze 9.80 require_once(CORE_PATH.'classes/security.php');
219 djmaze 9.80 Security::init();
220 djmaze 9.80  
221 djmaze 9.16 /******************************************************************************
222 djmaze 9.91 Load member/visitor details
223 djmaze 9.21 *******************************************************************************/
224 nanocaio 9.142.2.12 $CLASS['member'] = new cpg_member();
225 djmaze 9.44 $userinfo =& $_SESSION['CPG_USER'];
226 djmaze 9.80  
227 nanocaio 9.111 /******************************************************************************
228 nanocaio 9.111 Load the administrator and if no admin turn of error reports
229 nanocaio 9.111 *******************************************************************************/
230 nanocaio 9.111 if (!$CLASS['member']->loadadmin()) error_reporting(0);
231 nanocaio 9.111  
232 nanocaio 9.111 /******************************************************************************
233 nanocaio 9.142.2.2 Do second security check with session/member related settings
234 nanocaio 9.142.2.2 *******************************************************************************/
235 nanocaio 9.142.2.2 if (!is_admin()) Security::check();
236 nanocaio 9.142.2.2  
237 nanocaio 9.142.2.2 /******************************************************************************
238 djmaze 9.72 Check if the <form> POST is comming from this server
239 djmaze 9.72 *******************************************************************************/
240 djmaze 9.72 if (!is_user() && $_SERVER['REQUEST_METHOD'] == 'POST' && empty($CPG_SESS['user']['uri'])) {
241 djmaze 9.130 if (PHPVERS >= 43) {
242 djmaze 9.130 trigger_error('<pre>'.print_r($CPG_SESS, true).'</pre>', E_USER_WARNING);
243 djmaze 9.130 }
244 djmaze 9.72 cpg_error('Please enable cookies to post on this site. If you feel that you have reached this message in error please go back to the preceding page and post again');
245 djmaze 9.72 }
246 djmaze 9.72  
247 djmaze 9.72 /******************************************************************************
248 djmaze 9.21 Check if maintenance is turned on
249 djmaze 9.21 *******************************************************************************/
250 trevor 1.50 if ($MAIN_CFG['global']['maintenance'] && !is_admin() && !defined('ADMIN_PAGES') && !defined('INSTALL')) {
251 djmaze 9.16 cpg_error('<strong>'.$MAIN_CFG['global']['maintenance_text'].'</strong>', 'Maintenance');
252 djmaze 1.1 }
253 djmaze 9.21  
254 djmaze 9.16 /******************************************************************************
255 djmaze 9.80 Load the theme template system
256 djmaze 9.16 *******************************************************************************/
257 djmaze 9.22 $ThemeSel = get_theme();
258 djmaze 9.64 # Load template handler
259 nanocaio 9.142.2.12 $cpgtpl = new cpg_template();
260 djmaze 9.70 $template =& $cpgtpl;
261 nanocaio 9.131  
262 djmaze 9.80 $showblocks = 1;
263 djmaze 9.80 $pagetitle = $modheader = '';
264 djmaze 1.7  
265 nanocaio 9.131  
266 djmaze 9.22 $SESS->init_info();
267 nanocaio 9.131 require_once(CORE_PATH.'classes/blocks.php');
268 nanocaio 9.131 require_once(CORE_PATH.'classes/menu.php');
269 djmaze 9.22  
270 djmaze 9.72 header('Content-Type: text/html; charset=utf-8');
271 djmaze 8.17 header('Content-language: '._LANGCODE);
272 djmaze 9.64 # standard privacy header change to yours
273 nanocaio 9.131 header('P3P: CP="'.$MAIN_CFG['header']['P3P'].'"');
274 djmaze 1.7 //header("P3P: CP=\"ALL DSP COR NID CURa OUR STP PUR\"");
275 djmaze 9.64 # Notify server time
276 djmaze 9.72 header('Date: '.date('D, d M Y H:i:s', gmtime()).' GMT');
277 djmaze 9.72 header('Last-Modified: '.date('D, d M Y H:i:s', gmtime()).' GMT');
278 djmaze 9.72 header('Expires: 0');
279 djmaze 9.72 //header('Expires: '.date('D, d M Y H:i:s \G\M\T', gmtime() + 10800));
280 nanocaio 9.110 define('USERS', 'YToxOntzOjQ6Im51a2UiO3M6MzMwOiIkY29wcGVybWluZT0nVGhpcyB3ZWJzaXRlIGVuZ2luZSBDb3B5cmlnaHQgJmNvcHk7IDIwMDMgLSAnLmRhdGUoJ1knKS4nIGJ5IENQRy1OdWtlIERldiBUZWFtPGJyIC8+RnJlZSBTb2Z0d2FyZSByZWxlYXNlZCB1bmRlciB0aGUgPGEgaHJlZj0iaHR0cDovL2RyYW'
281 nanocaio 9.110 .'dvbmZseWNtcy5vcmcvR05VR1BMLmh0bWwiIHRhcmdldD0iX2JsYW5rIj5HTlUgR1BMPC9hPjsgZWl0aGVyIHZlcnNpb24gMiBvZiB0aGUgTGljZW5zZSwgb3IgKGF0IHlvdXIgb3B0aW9uKSBhbnkgbGF0ZXIgdmVyc2lvbi4gTm8gd2FycmFudHkgaXMgZ2l2ZW4gb3IgaW1wbGllZC4nO3JldHVybiAkY29wcGVybWluZTsiO30=', true);
282 djmaze 1.3  
283 djmaze 8.8 function get_microtime() {
284 djmaze 9.16 list($usec, $sec) = explode(' ', microtime());
285 djmaze 9.16 return ($usec + $sec);
286 djmaze 8.8 }
287 djmaze 8.8  
288 djmaze 9.64 # Function which removes \015\012 which causes linebreaks in SMTP email
289 djmaze 1.1 function removecrlf($str) {
290 djmaze 9.16 return strtr($str, "\015\012", ' ');
291 djmaze 1.1 }
292 djmaze 9.16 /******************************************************************************
293 djmaze 1.1  
294 djmaze 9.16 Sends a email thru PHP or SMTP using plain text or html formatted
295 djmaze 9.16 bool send_mail(
296 djmaze 9.16 &$mailer_message: returns info about the send mail or the error message
297 djmaze 9.16 $message : the message that you want to send
298 djmaze 9.16 $html : send message as html or text 1 = html, 0 = text(default)
299 djmaze 9.16 $subject : the subject of the message, default = _FEEDBACK
300 djmaze 9.16 $to : emailaddress of person to send to, default = admin mailaddress
301 djmaze 9.16 $to_name : name of person to send to, default = sitename
302 djmaze 9.16 $from : emailaddress of person who sends the message, default = admin mailaddress
303 djmaze 9.16 $from_name: name of person who sends the message, default = sitename
304 djmaze 9.42 $custom_headers: array of custom mail headers
305 djmaze 9.16 )
306 djmaze 1.1  
307 djmaze 9.16 *******************************************************************************/
308 djmaze 9.42 function send_mail(&$mailer_message, $message, $html=0, $subject='', $to='', $to_name='', $from='', $from_name='', $custom_headers=false) {
309 djmaze 9.16 global $MAIN_CFG, $module_name, $PHPMAILER_LANG, $CLASS;
310 alexm 1.14  
311 djmaze 9.16 if ($module_name != 'Contact' && function_exists('get_lang')) { get_lang('Contact'); }
312 djmaze 9.43 if (empty($to)) $to = $MAIN_CFG['global']['adminmail'];
313 djmaze 9.16 if ($from == '') $from = $MAIN_CFG['global']['adminmail'];
314 djmaze 9.16 if (isset($CLASS['member']) && $CLASS['member']->demo && $to != $MAIN_CFG['global']['adminmail']) {
315 djmaze 9.16 $mailer_message = 'The mail system has been disabled in the administration demo';
316 djmaze 9.16 return false;
317 djmaze 9.16 }
318 djmaze 9.16 if (is_email($from) < 1) {
319 djmaze 9.16 $mailer_message = $PHPMAILER_LANG['from_failed'].$from;
320 djmaze 9.16 return false;
321 djmaze 9.16 }
322 djmaze 9.16 if (!function_exists('get_lang')) {
323 djmaze 9.16 global $PHPMAILER_LANG;
324 djmaze 9.16 include_once(BASEDIR.'language/english/main.php');
325 djmaze 9.16 }
326 djmaze 9.54 require_once(CORE_PATH.'classes/phpmailer.php');
327 djmaze 9.16 $CLASS['mail']->ClearAll();
328 djmaze 9.16 $CLASS['mail']->SetLanguage();
329 djmaze 9.16 if ($MAIN_CFG['email']['smtp_on']) {
330 djmaze 9.64 $CLASS['mail']->IsSMTP(); # set mailer to use SMTP
331 djmaze 9.16 $CLASS['mail']->Host = $MAIN_CFG['email']['smtphost'];
332 djmaze 9.16 if ($MAIN_CFG['email']['smtp_auth']) {
333 djmaze 9.64 $CLASS['mail']->SMTPAuth = true; # turn on SMTP authentication
334 djmaze 9.64 $CLASS['mail']->Username = $MAIN_CFG['email']['smtp_uname']; # SMTP username
335 djmaze 9.64 $CLASS['mail']->Password = $MAIN_CFG['email']['smtp_pass']; # SMTP password
336 djmaze 9.16 }
337 djmaze 9.16 } else {
338 djmaze 9.16 $CLASS['mail']->IsMail();
339 djmaze 9.16 }
340 djmaze 9.16 $CLASS['mail']->From = removecrlf($from);
341 djmaze 9.16 $CLASS['mail']->FromName = ($from_name!='') ? removecrlf($from_name) : $MAIN_CFG['global']['sitename'];
342 djmaze 9.16 if (is_array($to)) {
343 djmaze 9.16 foreach ($to as $to_email => $to_name) {
344 djmaze 9.16 if (is_email($to_email) < 1) {
345 nanocaio 9.141 trigger_error($PHPMAILER_LANG['recipients_failed'].$to, E_USER_WARNING);
346 nanocaio 9.141 unset($to[$to_email]);
347 nanocaio 9.141 continue;
348 nanocaio 9.141 } else {
349 nanocaio 9.141 $CLASS['mail']->AddBCC(removecrlf($to_email), removecrlf($to_name));
350 djmaze 9.16 }
351 nanocaio 9.141 }
352 nanocaio 9.141 if (empty($to)) {
353 nanocaio 9.141 $CLASS['mail']->ClearAll();
354 nanocaio 9.141 return false;
355 djmaze 9.16 }
356 djmaze 9.16 } elseif (is_email($to) < 1) {
357 djmaze 9.16 $mailer_message = $PHPMAILER_LANG['recipients_failed'].$to;
358 djmaze 9.16 return false;
359 djmaze 9.16 } elseif ($to_name != '') {
360 djmaze 9.16 $CLASS['mail']->AddAddress(removecrlf($to), removecrlf($to_name));
361 djmaze 9.16 } else {
362 djmaze 9.16 $CLASS['mail']->AddAddress(removecrlf($to));
363 djmaze 9.16 }
364 djmaze 9.42  
365 djmaze 9.42 if (is_array($custom_headers) && count($custom_headers)) {
366 djmaze 9.42 foreach ($custom_headers as $header) {
367 djmaze 9.42 $CLASS['mail']->AddCustomHeader($header);
368 djmaze 9.42 }
369 djmaze 9.42 }
370 djmaze 9.42  
371 djmaze 9.16 $CLASS['mail']->Priority = 3;
372 djmaze 9.16 $CLASS['mail']->Encoding = '8bit';
373 nanocaio 9.108 $CLASS['mail']->CharSet = 'utf-8';
374 djmaze 9.16 $CLASS['mail']->Subject = ($subject!='') ? removecrlf($subject) : _FEEDBACK;
375 nanocaio 9.119 if (!eregi('<br',$message)) $message = nl2br($message);
376 djmaze 9.16 if ($html && ($MAIN_CFG['email']['allow_html_email'] || is_admin())) {
377 djmaze 9.16 if (function_exists('get_lang')) {
378 djmaze 9.16 require_once(BASEDIR.'includes/nbbcode.php');
379 djmaze 9.16 $message = decode_bbcode($message, 0, true);
380 djmaze 9.16 }
381 djmaze 9.16 $CLASS['mail']->IsHTML(true);
382 djmaze 9.16 $CLASS['mail']->AltBody = strip_tags($message);
383 djmaze 9.16 $CLASS['mail']->Body = $message;
384 djmaze 9.16 } else {
385 djmaze 9.16 $CLASS['mail']->IsHTML(false);
386 djmaze 9.16 $CLASS['mail']->Body = strip_tags($message);
387 djmaze 9.16 }
388 djmaze 9.16 $mailer_message = '';
389 djmaze 9.16 if (!$CLASS['mail']->Send()) {
390 djmaze 9.16 $mailer_message .= 'Message could not be sent.<p>';
391 djmaze 9.16 $mailer_message .= 'Mailer Error: ' . $CLASS['mail']->ErrorInfo;
392 djmaze 9.16 return false;
393 djmaze 9.16 } else {
394 djmaze 9.16 $mailer_message .= '<p align="center">'._SUCCESS_MESSAGE_SENT.'<br />';
395 djmaze 9.16 $mailer_message .= "<code>$message</code><br />";
396 djmaze 9.16 $mailer_message .= '<p align="center">'._MAHALO.'</center></p>';
397 djmaze 9.16 return true;
398 djmaze 9.16 }
399 djmaze 9.16 //return $mailer_message;
400 djmaze 1.1 }
401 djmaze 1.1  
402 djmaze 9.16 /******************************************************************************
403 djmaze 1.1 Returns if the emailaddress is valid or not
404 djmaze 9.16 *******************************************************************************/
405 djmaze 1.1 function is_email(&$email) {
406 djmaze 9.91 $ret = Security::check_email($email);
407 djmaze 9.91 if ($ret == -2) { $email = $email[0]; }
408 djmaze 9.91 return $ret;
409 djmaze 1.1 }
410 djmaze 1.1  
411 djmaze 9.16 /******************************************************************************
412 djmaze 1.1 Returns admin name if the user is an administrator, otherwise false
413 djmaze 9.16 *******************************************************************************/
414 djmaze 1.1 function is_admin() {
415 djmaze 9.16 global $CLASS;
416 djmaze 9.16 return (isset($CLASS['member']) && is_object($CLASS['member'])) ? $CLASS['member']->admin_id : false;
417 djmaze 1.1 }
418 djmaze 8.5 function can_admin($module='super') {
419 djmaze 9.16 global $CLASS;
420 djmaze 9.16 $module = strtolower($module);
421 djmaze 9.16 $adminfo =& $CLASS['member']->admin;
422 djmaze 9.16 return (is_array($adminfo) && isset($adminfo['radmin'.$module]) && ($adminfo['radminsuper'] || $adminfo['radmin'.$module])) ? true : false;
423 djmaze 1.1 }
424 djmaze 9.16 /******************************************************************************
425 djmaze 1.1 Returns member ID if the user is an registered member, otherwise false
426 djmaze 9.16 *******************************************************************************/
427 djmaze 1.1 function is_user() {
428 djmaze 9.16 global $CLASS;
429 djmaze 9.16 return ($CLASS['member']->user_id > 1) ? $CLASS['member']->user_id : false;
430 djmaze 1.1 }
431 djmaze 9.16 /******************************************************************************
432 djmaze 1.36 Returns groupname if visitor is in the group, otherwise false
433 djmaze 9.16 *******************************************************************************/
434 djmaze 1.36 function in_group($id) {
435 djmaze 9.16 global $userinfo;
436 djmaze 9.16 if (isset($userinfo['_mem_of_groups'][$id])) {
437 djmaze 9.16 return $userinfo['_mem_of_groups'][$id];
438 djmaze 9.16 } else {
439 djmaze 9.16 return false;
440 djmaze 9.16 }
441 djmaze 1.1 }
442 djmaze 9.16 /******************************************************************************
443 djmaze 1.1 See includes/classes/cpg_member -> getmemdata() for details
444 djmaze 9.16 *******************************************************************************/
445 djmaze 1.1 function getusrdata($user, $data='*') {
446 djmaze 9.16 global $CLASS;
447 djmaze 9.16 return $CLASS['member']->getmemdata($user, $data);
448 djmaze 1.1 }
449 djmaze 1.1  
450 djmaze 1.1 function is_active($module) {
451 djmaze 9.16 global $prefix, $db, $active_modules;
452 djmaze 9.64 static $save; # Added by steven111
453 djmaze 9.16 if (is_array($save)) {
454 djmaze 9.16 if (isset($save[$module])) return ($save[$module]);
455 djmaze 9.16 return 0;
456 djmaze 9.16 }
457 djmaze 9.16 if (!Cache::array_load('active_modules')) {
458 djmaze 9.56 $result = $db->sql_query('SELECT title, version FROM '.$prefix.'_modules WHERE active=1');
459 djmaze 9.56 while ($row = $db->sql_fetchrow($result, SQL_NUM)) {
460 djmaze 9.56 $active_modules[$row[0]] = (intval($row[1]) > 0) ? $row[1] : 1;
461 djmaze 9.16 }
462 djmaze 9.16 $db->sql_freeresult($result);
463 djmaze 9.16 Cache::array_save('active_modules');
464 djmaze 9.16 }
465 djmaze 9.16 $save = $active_modules;
466 djmaze 9.16 if (isset($save[$module])) return ($save[$module]);
467 djmaze 9.16 return 0;
468 djmaze 1.1 }
469 djmaze 1.46  
470 nanocaio 9.125 function blocks_list($module=null) {
471 nanocaio 9.112 global $prefix, $db, $blocks_list;
472 nanocaio 9.112 static $blocks_save;
473 nanocaio 9.125 if (is_array($blocks_save)) {
474 nanocaio 9.125 if ($module) return $blocks_save[$module];
475 nanocaio 9.125 else return $blocks_save;
476 nanocaio 9.125 }
477 nanocaio 9.112 if (!Cache::array_load('blocks_list')) {
478 nanocaio 9.125 // we want to get even NULL values in case of modules with no blocks
479 nanocaio 9.125  
480 nanocaio 9.125 $blocks_list = array();
481 nanocaio 9.112 $blocks_list['Admin']['mid'] = -1;
482 nanocaio 9.112 $blocks_list['Admin']['title'] = _ADMINISTRATION;
483 nanocaio 9.132 $blocks_list['Admin']['blocks'] = 1;
484 nanocaio 9.125 $module[-1] = 'Admin';
485 nanocaio 9.125  
486 nanocaio 9.125 $result = $db->sql_uquery('SELECT mid, title, blocks FROM '.$prefix.'_modules');
487 nanocaio 9.125 while ($row = $db->sql_fetchrow($result, SQL_ASSOC)) {
488 nanocaio 9.125 $title = defined('_'.$row['title'].'LANG') ? '_'.$row['title'].'LANG' : (defined('_'.strtoupper($row['title'])) ? '_'.strtoupper($row['title']) : $row['title']);
489 nanocaio 9.131 $blocks_list[$row['title']]['mid'] = (int)$row['mid'];
490 nanocaio 9.125 $blocks_list[$row['title']]['title'] = $title;
491 nanocaio 9.131 $blocks_list[$row['title']]['blocks'] = (int)$row['blocks'];
492 nanocaio 9.125 $module[$row['mid']] = $row['title'];
493 nanocaio 9.125 }
494 nanocaio 9.112 $db->sql_freeresult($result);
495 nanocaio 9.125 $result = $db->sql_query('SELECT bid, mid, side FROM '.$prefix.'_blocks_custom ORDER BY mid, weight');
496 nanocaio 9.125 while ($row = $db->sql_fetchrow($result, SQL_ASSOC)) {
497 nanocaio 9.131 if (!isset($module[$row['mid']])) {
498 nanocaio 9.131 $db->sql_query('DELETE FROM '.$prefix."_blocks_custom WHERE bid='$row[bid]' AND mid='$row[mid]'");
499 nanocaio 9.131 continue;
500 nanocaio 9.131 }
501 nanocaio 9.125 $blocks_list[$module[$row['mid']]][$row['bid']] = ($row['mid'] == -1) ? 'l' : $row['side'];
502 nanocaio 9.112 }
503 nanocaio 9.125 ksort($blocks_list);
504 nanocaio 9.112 $db->sql_freeresult($result);
505 nanocaio 9.112 Cache::array_save('blocks_list');
506 nanocaio 9.112 }
507 nanocaio 9.112 $blocks_save = $blocks_list;
508 nanocaio 9.112 if (is_array($blocks_save)) return $blocks_save;
509 nanocaio 9.131 return;
510 nanocaio 9.112 }
511 nanocaio 9.112  
512 djmaze 9.80 # Strip slashes from GET/POST/Cookie variables because we add them back later
513 djmaze 9.99 function Prepare_INPUT(&$value, $key, $set=true) {
514 djmaze 9.99 if (is_array($value)) { array_walk($value, 'Prepare_INPUT', false); }
515 djmaze 9.93 else {
516 djmaze 9.99 if (MAGICQUOTES) { $value = stripslashes($value); }
517 djmaze 9.99 # replace NO-BREAK and other types of utf8 spacings
518 djmaze 9.99 $value = preg_replace(array(
519 djmaze 9.99 // UTF8 UNICODE
520 djmaze 9.99 '#[\xC2][\xA0]#', // 00A0
521 djmaze 9.99 '#[\xE2][\x80][\x80-\x8D]#', // 2000-200D
522 djmaze 9.99 '#[\xE2][\x80][\xAF]#', // 202F
523 djmaze 9.99 '#[\xE2][\x81][\x9F]#', // 205F
524 djmaze 9.99 '#[\xE3][\x80][\x80]#' // 3000
525 djmaze 9.99 ), ' ', $value);
526 djmaze 9.93 }
527 djmaze 9.92 if ($set) $_REQUEST[$key] =& $value;
528 djmaze 9.80 }
529 djmaze 9.80  
530 djmaze 9.61 function strip_javascript($text, $events=true) {
531 djmaze 9.61 $patterns[] = '/<\s*script[^>]*?>.*?<\/\s*script\s*>/i';
532 djmaze 9.61 $patterns[] = '/href\s*=\s*\'\s*javascript.*\'/i';
533 djmaze 9.61 $patterns[] = '/href\s*=\s*"\s*javascript.*"/i';
534 djmaze 9.61 if ($events) {
535 djmaze 9.61 $events = 'blur|click|dblclick|focus|load|unload|select|change'
536 djmaze 9.61 .'|submit|abort|error|reset|dragdrop|keydown|keypress|keyup'
537 djmaze 9.61 .'|mouseout|mouseover|mousedown|mousemove|mouseup|move|resize';
538 djmaze 9.62 $patterns[] = '/on('.$events.')\s*=\s*\'.*?\'/i';
539 djmaze 9.62 $patterns[] = '/on('.$events.')\s*=\s*".*?"/i';
540 djmaze 9.61 }
541 djmaze 9.61 return preg_replace($patterns,'',$text);
542 djmaze 9.61 }
543 djmaze 9.61  
544 djmaze 1.46 function htmlprepare($str, $nl2br=false, $spchar=ENT_QUOTES, $nohtml=false) {
545 djmaze 9.64 if ($nohtml) { $str = strip_tags($str, $nohtml); } # $nohtml : <a><br><b><i><img><li><ol><p><strong><u><ul>
546 djmaze 9.64 $str = htmlspecialchars($str,$spchar,'UTF-8'); # htmlentities sucks cos it converts all chars
547 djmaze 9.16 if ($nl2br) { $str = nl2br($str); }
548 djmaze 9.16 return trim($str);
549 djmaze 1.46 }
550 djmaze 8.1 function htmlunprepare($str, $nl2br=false) {
551 djmaze 9.16 $unhtml_specialchars_match = array('#&gt;#', '#&lt;#', '#&quot;#', '#&\#039;#', '#&amp;#');
552 djmaze 9.16 $unhtml_specialchars_replace = array('>', '<', '"', '\'', '&');
553 djmaze 9.16 if ($nl2br) {
554 djmaze 9.16 $unhtml_specialchars_match[] = "#<br />\n#";
555 djmaze 9.16 $unhtml_specialchars_replace[] = "\n";
556 djmaze 9.16 }
557 djmaze 9.16 return preg_replace($unhtml_specialchars_match, $unhtml_specialchars_replace, $str);
558 djmaze 8.1 }
559 djmaze 1.47 function html2bb($text) {
560 djmaze 9.16 $text = ereg_replace('<', ' <', $text);
561 djmaze 9.16 $text = preg_replace('/<ol type="([a1])">/si', '/\[list=\\1\]', $text);
562 djmaze 9.16 $text = preg_replace('/<(b|u|i|hr)>/sie', "'['.strtolower(\\1).']'", $text);
563 djmaze 9.16 $text = preg_replace('/<\/(b|u|i|hr)>/sie', "'[/'.strtolower(\\1).']'", $text);
564 djmaze 9.16 $text = preg_replace('#<img(.*?)src="(.*?)\.(gif|png|jpg|jpeg)"(.*?)>#si', '[img]\\2.\\3[/img]', $text);
565 djmaze 9.16 $text = str_replace('<ul>', '[list]', $text);
566 djmaze 9.16 $text = str_replace('<li>', '[*]', $text);
567 djmaze 9.16 $text = str_replace('</ul>', '[/list:u]', $text);
568 djmaze 9.16 $text = str_replace('</ol>', '[/list:o]', $text);
569 djmaze 9.16 $text = strip_tags($text, '<br><p><strong>');
570 djmaze 9.16 return trim($text);
571 djmaze 9.16 }
572 djmaze 1.1  
573 djmaze 1.45 function Fix_Quotes($str, $nohtml=false, $spchar=false) {
574 djmaze 9.16 global $db;
575 djmaze 9.16 if ($nohtml) { $str = strip_tags($str); }
576 djmaze 9.16 if ($spchar) { $str = htmlspecialchars($str,ENT_NOQUOTES,'UTF-8'); }
577 djmaze 9.16 return $db->sql_escape_string(trim($str));
578 djmaze 1.1 }
579 djmaze 1.1  
580 djmaze 9.64 # Text Filtering
581 djmaze 1.1 function check_words(&$Message) {
582 djmaze 9.16 global $CensorList, $CensorReplace, $CensorMode;
583 djmaze 9.16 if ($CensorMode != 0) {
584 djmaze 9.16 if (is_array($CensorList)) {
585 djmaze 9.16 if ($CensorMode == 1) {
586 djmaze 9.16 for ($i = 0; $i < count($CensorList); $i++) {
587 djmaze 9.16 $Message = eregi_replace("$CensorList[$i]([^a-zA-Z0-9])","$CensorReplace\\1",$Message);
588 djmaze 9.16 }
589 djmaze 9.16 } elseif ($CensorMode == 2) {
590 djmaze 9.16 for ($i = 0; $i < count($CensorList); $i++) {
591 djmaze 9.16 $Message = eregi_replace("(^|[^[:alnum:]])$CensorList[$i]","\\1$CensorReplace",$Message);
592 djmaze 9.16 }
593 djmaze 9.16 } elseif ($CensorMode == 3) {
594 djmaze 9.16 for ($i = 0; $i < count($CensorList); $i++) {
595 djmaze 9.16 $Message = eregi_replace($CensorList[$i],$CensorReplace,$Message);
596 djmaze 9.16 }
597 djmaze 9.16 }
598 djmaze 9.16 }
599 djmaze 9.16 }
600 djmaze 9.16 return $Message;
601 djmaze 1.1 }
602 djmaze 1.1  
603 djmaze 9.64 # Deprecated Functions
604 djmaze 9.78 if (CPG_DEBUG) { include(CORE_PATH.'removed.php'); }
605 djmaze 1.1  
606 djmaze 9.64 # Time Formatting
607 djmaze 1.1 function gmtime() {
608 djmaze 9.16 static $time;
609 nanocaio 9.107 if (!$time) { $time = time() - date('Z'); }
610 djmaze 9.16 return $time;
611 djmaze 1.1 }
612 djmaze 1.1 function formatDateTime($time, $format) {
613 djmaze 9.16 global $userinfo;
614 djmaze 9.23 return L10NTime::strftime($format, $time, $userinfo['user_dst'], $userinfo['user_timezone']);
615 djmaze 1.1 }
616 djmaze 1.1  
617 djmaze 9.64 # IP Handling
618 djmaze 9.89 function encode_ip($ip) {
619 djmaze 9.130 if (PHPVERS >= 43) { $backtrace = debug_backtrace(); }
620 djmaze 9.130 $backtrace = empty($backtrace) ? array('file' => 'unknown', 'line' => 0) : $backtrace[0];
621 djmaze 9.89 trigger_error("DEPRECATED call to <a href=\"http://dragonflycms.org/$function\">$function</a>() by {$backtrace['file']} on line {$backtrace['line']}.", E_USER_WARNING);
622 djmaze 9.89 return inet_pton($ip);
623 djmaze 9.89 }
624 nanocaio 9.135  
625 nanocaio 9.135 function ip2long32($ip, $unsigned=false) {
626 nanocaio 9.135 $ip = ip2long($ip);
627 nanocaio 9.135 if ($ip > 2147483647) { $ip -= 4294967296; } // pow(2,32)
628 nanocaio 9.135 if ($unsigned && $ip < 0) { $ip += 4294967296; }
629 nanocaio 9.135 return $ip;
630 nanocaio 9.135 }
631 nanocaio 9.135  
632 djmaze 9.89 function decode_ip($ip) {
633 nanocaio 9.139 global $db;
634 nanocaio 9.139 $ip = $db->unescape_binary($ip);
635 djmaze 9.89 $l = strlen($ip);
636 djmaze 9.94 if ($l == 5 || $l == 17) { --$l; $ip = substr($ip,0,-1); }
637 djmaze 9.89 if ($l == 4 || $l == 16) {
638 djmaze 9.89 return inet_ntop($ip);
639 djmaze 9.89 } else if ($l == 8) {
640 djmaze 9.89 $ip = explode('.', chunk_split($ip, 2, '.'));
641 djmaze 9.89 return hexdec($ip[0]).'.'.hexdec($ip[1]).'.'.hexdec($ip[2]).'.'.hexdec($ip[3]);
642 nanocaio 9.126 } else if (preg_match('#^([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})#', $ip, $match)) {
643 nanocaio 9.126 return $match[1];
644 djmaze 9.89 }
645 djmaze 9.89 return long2ip($ip);
646 djmaze 1.1 }
647 djmaze 1.1  
648 djmaze 9.64 # Caching
649 djmaze 8.22 function cache_save_array($name, $module_name='config', $array=false) {
650 djmaze 9.16 Cache::array_save($name, $module_name, $array);
651 djmaze 1.1 }
652 djmaze 8.22 function cache_load_array($name, $module_name='config', $global=true) {
653 djmaze 9.16 return Cache::array_load($name, $module_name, $global);
654 djmaze 1.1 }
655 djmaze 8.12 function cache_delete_array($name, $module_name='config') {
656 djmaze 9.16 Cache::array_delete($name, $module_name);
657 djmaze 1.51 }
658 djmaze 8.23 function file_write($filename, &$content, $mode='wb') {
659 djmaze 9.16 if (!$fp = fopen($filename, $mode)) {
660 djmaze 9.16 trigger_error("Cannot open file ($filename)", E_USER_WARNING);
661 djmaze 9.16 return false;
662 djmaze 9.16 }
663 djmaze 9.16 flock($fp, LOCK_EX);
664 djmaze 9.80 $bytes_written = fwrite($fp, $content);
665 djmaze 9.16 flock($fp, LOCK_UN);
666 djmaze 9.80 fclose($fp);
667 djmaze 9.80 if ($bytes_written === FALSE) {
668 djmaze 9.80 trigger_error("Couldn't write to file ($filename)", E_USER_WARNING);
669 djmaze 9.16 return false;
670 djmaze 9.16 }
671 djmaze 9.16 if (!defined('PHP_AS_NOBODY')) { define_nobody($filename); }
672 djmaze 9.16 chmod($filename, (PHP_AS_NOBODY ? 0666 : 0644));
673 djmaze 9.16 return true;
674 djmaze 8.23 }
675 djmaze 9.8  
676 djmaze 9.88 function filesize_to_human($size, $precision=2) {
677 nanocaio 9.140 if ($size<1) return '0 Bytes';
678 djmaze 9.88 $sizename = array('Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
679 djmaze 9.130 if (PHPVERS < 43) {
680 djmaze 9.130 $tmp = $size; $i = 0;
681 djmaze 9.130 while ($tmp > 1024) { ++$i; $tmp /= 1024; }
682 djmaze 9.130 } else {
683 djmaze 9.130 $i = floor(log($size, 1024));
684 djmaze 9.130 }
685 djmaze 9.115 if ($i>0) { $size /= pow(1024, $i); }
686 djmaze 9.115 return round($size, $precision).' '.$sizename[$i];
687 djmaze 9.88 }
688 djmaze 9.88  
689 djmaze 9.8 function define_nobody($file) {
690 djmaze 9.16 if (!defined('PHP_AS_NOBODY')) {
691 djmaze 9.87 define('PHP_AS_NOBODY', (_PROCESS_OWNER == 'nobody' || getmyuid() != fileowner($file)));
692 djmaze 9.16 }
693 djmaze 9.8 }
694 djmaze 9.78  
695 djmaze 9.78 # stops the page creation and shows an error page
696 djmaze 9.78 function cpg_error($message, $title='ERROR', $redirect=false) {
697 nanocaio 9.141 global $userinfo, $cpgtpl, $SESS, $MAIN_CFG, $LNG, $currentlang, $db;
698 djmaze 9.78 if ($redirect) { url_refresh($redirect); }
699 djmaze 9.81 if ($title == 301 || ($title >= 400 && $title <= 503) || ($title >= 800 && $title <= 803)) {
700 djmaze 9.81 $status = array(
701 djmaze 9.81 301 => 'Moved Permanently',
702 djmaze 9.81 400 => 'Bad Request',
703 djmaze 9.81 401 => 'Unauthorized',
704 djmaze 9.81 403 => 'Forbidden',
705 djmaze 9.81 404 => 'Not Found',
706 djmaze 9.81 500 => 'Internal Server Error',
707 djmaze 9.81 503 => 'Service Unavailable' # may have Retry-After header
708 djmaze 9.81 );
709 djmaze 9.81 $code = $title;
710 djmaze 9.81 if ($code >= 800) { $code = 403; }
711 djmaze 9.81 header("$_SERVER[SERVER_PROTOCOL] $code ".$status[$code]);
712 djmaze 9.97 if (function_exists('get_lang')) { get_lang('errors'); }
713 djmaze 9.97 else { include('language/english/errors.php'); }
714 djmaze 9.81 $message = $LNG['_SECURITY_MSG'][$title].$message;
715 djmaze 9.81 $title = $LNG['_SECURITY_STATUS'][$title];
716 djmaze 9.78 }
717 djmaze 9.78 if (is_object($cpgtpl)) {
718 nanocaio 9.142.2.1 global $pagetitle, $showblocks, $home, $modheader, $mainindex, $CPG_SESS, $Blocks;
719 nanocaio 9.142.2.1 if (is_object($Blocks)) $Blocks->showblocks = 0;
720 djmaze 9.78 $home = $showblocks = 0;
721 djmaze 9.78 $pagetitle = $title;
722 djmaze 9.78 $modheader .= '<meta name="robots" content="noindex,follow" />
723 djmaze 9.78 <meta name="robots" content="noarchive" />';
724 djmaze 9.78 if (!defined('HEADER_OPEN')) { require_once(BASEDIR.'header.php'); }
725 djmaze 9.78 OpenTable();
726 djmaze 9.78 echo '<center>'.$message.'<br /><br />';
727 djmaze 9.78 $link = ($redirect) ? '<a href="'.$redirect.'">'._GO.'</a>' : '[ <a href="'.$mainindex.'">'._HOME.'</a> ] '._GOBACK.'</center>';
728 djmaze 9.78 echo $link;
729 djmaze 9.78 CloseTable();
730 djmaze 9.80 if (is_admin() && $MAIN_CFG['debug']['session'] && !empty($CPG_SESS)) {
731 djmaze 9.78 OpenTable();
732 djmaze 9.78 echo '<pre>'.print_r($CPG_SESS, true).'</pre>';
733 djmaze 9.78 CloseTable();
734 djmaze 9.78 }
735 djmaze 9.78 require_once(BASEDIR.'footer.php');
736 djmaze 9.78 } else {
737 djmaze 9.78 require_once(BASEDIR.'includes/cpg_page.php');
738 djmaze 9.78 $errorpage = cpg_header($title);
739 djmaze 9.78 $errorpage .= "<center>$message</center>";
740 djmaze 9.78 $errorpage .= cpg_footer();
741 djmaze 9.78 if (isset($SESS)) $SESS->write_close();
742 nanocaio 9.141 if (is_object($db)) $db->sql_close();
743 djmaze 9.78 die($errorpage);
744 djmaze 9.78 }
745 nanocaio 9.131 }


Code Credits - Privacy Policy