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.67 (8 years 6 months 3 weeks 3 days 5 hours 52 minutes 10 seconds ago) by djmaze
Changed : +5 -7 lines
Comment: Proper cookie domain on localhost install and upgraded version number for release


# Author Rev Line
1 djmaze 1.1 <?php
2 djmaze 1.1 /*********************************************
3 djmaze 9.16 CPG Dragonfly™ CMS
4 djmaze 1.1 ********************************************
5 djmaze 9.16 Copyright © 2004 - 2005 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 djmaze 9.67 $Revision: 9.66 $
13 djmaze 9.67 $Author: akamu $
14 djmaze 9.67 $Date: 2005/09/29 21:42:16 $
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 djmaze 9.67 define('CPG_NUKE', '9.0.7.0');
20 akamu 9.66  
21 djmaze 8.8 $start_time = get_microtime();
22 djmaze 9.64 set_magic_quotes_runtime(0); # Disable magic_quotes_runtime
23 djmaze 8.23 umask(0);
24 djmaze 1.22  
25 djmaze 9.64 # Are we allowed to modify php.ini on the fly ?
26 djmaze 8.35 define('CAN_MOD_INI', !ereg('ini_set', ini_get('disable_functions')));
27 djmaze 8.35  
28 djmaze 9.64 # http://bugs.php.net/bug.php?id=31849
29 djmaze 9.10 if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
30 djmaze 9.16 define('_DRAGONLY_OWNER', 'N/A');
31 djmaze 9.10 } else {
32 djmaze 9.16 define('_DRAGONLY_OWNER', get_current_user());
33 djmaze 9.10 }
34 djmaze 9.10  
35 djmaze 9.64 # Destroy GET/POST/Cookie variables from the global scope since IIS can't
36 djmaze 9.64 # turn off register_globals as Apache can thru .ht*
37 djmaze 8.39 if (intval(ini_get('register_globals')) != 0) {
38 djmaze 9.54 foreach ($_REQUEST AS $key => $val) { if (isset($$key)) unset($$key); }
39 djmaze 1.37 }
40 djmaze 9.64 # Strip slashes from GET/POST/Cookie variables because we add them back on SQL
41 djmaze 8.2 function StripAllSlashes(&$value, $key) {
42 djmaze 9.16 if (is_array($value)) array_walk($value, 'StripAllSlashes');
43 djmaze 9.16 else $value = stripslashes($value);
44 djmaze 9.16 $_REQUEST[$key] =& $value;
45 djmaze 8.2 }
46 djmaze 1.41 if (get_magic_quotes_gpc() || ini_get('magic_quotes_sybase')) {
47 djmaze 9.40 if (is_array($_GET)) { array_walk($_GET, 'StripAllSlashes'); }
48 djmaze 9.16 if (is_array($_POST)) { array_walk($_POST, 'StripAllSlashes'); }
49 djmaze 9.16 if (is_array($_COOKIE)) { array_walk($_COOKIE, 'StripAllSlashes'); }
50 djmaze 1.41 }
51 djmaze 1.37  
52 djmaze 9.64 # Store the path of our (shared) core files
53 djmaze 9.54 $root_path = dirname(__FILE__);
54 djmaze 9.54 if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
55 djmaze 9.64 $root_path = str_replace('\\', '/', $root_path);
56 djmaze 8.15 }
57 djmaze 9.55 define('CORE_PATH', ((strlen($root_path) > 2) ? $root_path : 'includes').'/');
58 djmaze 9.54 unset($root_path);
59 djmaze 9.54 if (!defined('BASEDIR')) { define('BASEDIR', dirname(CORE_PATH).'/'); }
60 djmaze 9.56 //if (CAN_MOD_INI) ini_set('include_path', ini_get('include_path').';'.CORE_PATH);
61 djmaze 1.22 $phpver = explode('.', phpversion());
62 djmaze 1.22 $phpver = "$phpver[0]$phpver[1]";
63 djmaze 8.27 define('PHPVERS', $phpver);
64 djmaze 1.1  
65 djmaze 9.64 # we define our own error handler
66 djmaze 9.54 require_once(CORE_PATH.'classes/cpg_debugger.php');
67 djmaze 8.19  
68 djmaze 8.35 ini_set('magic_quotes_sybase', 0);
69 djmaze 8.35  
70 djmaze 9.64 # Compress output if server/php config allows
71 trevor 9.35 $do_gzip_compress = $do_zlib_compress = false;
72 djmaze 8.31 define('GZIPSUPPORT', extension_loaded('zlib'));
73 djmaze 9.64 if (GZIPSUPPORT && !defined('INSTALL')) {
74 djmaze 9.16 if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && eregi('gzip', $_SERVER['HTTP_ACCEPT_ENCODING'])) {
75 djmaze 9.64 if (PHPVERS >= 43) { # PHP 4.2.x seems to give memleak
76 djmaze 9.16 ob_start('ob_gzhandler');
77 djmaze 9.16 } else {
78 djmaze 9.16 $do_gzip_compress = true;
79 djmaze 9.16 ob_start();
80 djmaze 9.16 ob_implicit_flush(0);
81 djmaze 9.16 header('Content-Encoding: gzip');
82 djmaze 9.16 }
83 djmaze 9.16 } else {
84 djmaze 9.64 # Some stupid firewalls don't send the HTTP_ACCEPT_ENCODING
85 djmaze 9.64 # So we still compress in memory for fast page generations
86 djmaze 9.64 # But it will take longer for the visitor to see the page.
87 djmaze 9.16 $do_zlib_compress = true;
88 djmaze 9.16 ob_start();
89 djmaze 9.16 ob_implicit_flush(0);
90 djmaze 9.16 }
91 djmaze 1.1 }
92 djmaze 1.1  
93 djmaze 8.37 if (PHPVERS >= 41) { $PHP_SELF = $_SERVER['PHP_SELF']; }
94 djmaze 1.37  
95 djmaze 1.1 $showblocks = 1;
96 djmaze 9.32 $CPG_SESS = array();
97 trevor 9.34 $pagetitle = $modheader = $user = $admin = $cookie = '';
98 trevor 8.29 if (!isset($file)) $file = null;
99 trevor 8.29 if (!isset($name)) $name = null;
100 djmaze 1.1  
101 djmaze 9.64 # stops the page creation and shows an error page
102 trevor 8.29 function nuke_error($message, $title='ERROR', $redirect='') {
103 trevor 9.36 trigger_error('The function nuke_error() is deprecated in Dragonfly. Please change your call to cpg_error()', E_USER_WARNING);
104 djmaze 9.16 cpg_error($message, $title, $redirect);
105 trevor 8.29 }
106 djmaze 9.2 function cpg_error($message, $title='ERROR', $redirect=false) {
107 trevor 9.30 global $userinfo, $SESS, $MAIN_CFG;
108 djmaze 9.56 if ($redirect) { url_refresh($redirect); }
109 djmaze 9.16 if ($title == 301) {
110 djmaze 9.16 $title = 'Moved';
111 djmaze 9.16 header('HTTP/1.0 301 Moved Permanently');
112 djmaze 9.16 } elseif ($title == 401) {
113 djmaze 9.16 $title = (defined('_ACCESSDENIED') ? _ACCESSDENIED : 'Access Denied');
114 djmaze 9.16 header('HTTP/1.0 401 Unauthorized');
115 djmaze 9.16 } elseif ($title == 404) {
116 djmaze 9.16 $title = 'Not found';
117 djmaze 9.16 header('HTTP/1.0 404 Not Found');
118 djmaze 9.16 }
119 djmaze 9.16 if (defined('THEME_USES_TPL') || defined('HEADER_OPEN')) {
120 djmaze 9.16 global $pagetitle, $showblocks, $home, $modheader, $mainindex;
121 djmaze 9.16 $home = $showblocks = 0;
122 djmaze 9.16 $pagetitle = $title;
123 djmaze 9.16 $modheader .= '<meta name="robots" content="noindex,follow" />
124 djmaze 9.16 <meta name="robots" content="noarchive" />';
125 djmaze 9.16 if (!defined('HEADER_OPEN')) { require_once(BASEDIR.'header.php'); }
126 djmaze 9.16 OpenTable();
127 djmaze 9.16 echo '<center>'.$message.'<br /><br />';
128 djmaze 9.16 $link = ($redirect) ? '<a href="'.$redirect.'">'._GO.'</a>' : '[ <a href="'.$mainindex.'">'._HOME.'</a> ] '._GOBACK.'</center>';
129 djmaze 9.16 echo $link;
130 djmaze 9.16 CloseTable();
131 trevor 9.30 if (is_admin() && $MAIN_CFG['debug']['session']) {
132 djmaze 9.24 global $CPG_SESS;
133 djmaze 9.24 OpenTable();
134 djmaze 9.24 echo '<pre>'.print_r($CPG_SESS, true).'</pre>';
135 djmaze 9.24 CloseTable();
136 djmaze 9.24 }
137 djmaze 9.16 require_once(BASEDIR.'footer.php');
138 djmaze 9.16 } else {
139 djmaze 9.16 require_once(BASEDIR.'includes/cpg_page.php');
140 djmaze 9.16 $errorpage = cpg_header($title);
141 djmaze 9.16 $errorpage .= "<center>$message</center>";
142 djmaze 9.16 $errorpage .= cpg_footer();
143 djmaze 9.16 if (isset($SESS)) $SESS->write_close();
144 djmaze 9.16 die($errorpage);
145 djmaze 9.16 }
146 djmaze 1.1 }
147 djmaze 1.1  
148 djmaze 8.18 if (file_exists('config.php')) {
149 djmaze 9.16 require_once('config.php');
150 djmaze 8.18 } else {
151 djmaze 9.16 require_once(BASEDIR.'config.php');
152 djmaze 8.18 }
153 djmaze 9.54 require_once(CORE_PATH.'db/db.php');
154 djmaze 9.54 require_once(CORE_PATH.'classes/cpg_cache.php');
155 djmaze 9.54 require_once(CORE_PATH.'classes/time.php');
156 djmaze 9.54 require_once(CORE_PATH.'functions/linking.php');
157 djmaze 9.16 if (!defined('XMLFEED') && !defined('INSTALL')) {
158 djmaze 9.54 require_once(CORE_PATH.'functions/display.php');
159 djmaze 9.54 require_once(CORE_PATH.'classes/cpg_member.php');
160 djmaze 9.54 require_once(CORE_PATH.'classes/session.php');
161 djmaze 9.54 require_once(CORE_PATH.'classes/template.php');
162 djmaze 9.16 }
163 djmaze 9.9 header('X-Powered-By: Dragonfly CMS using PHP engine');
164 djmaze 1.1 if (defined('INSTALL')) return;
165 djmaze 1.1  
166 djmaze 8.30 if (!Cache::array_load('MAIN_CFG')) {
167 djmaze 9.16 $result = $db->sql_query('SELECT * FROM '.$prefix.'_config_custom', true);
168 djmaze 9.16 if (!$result) { url_redirect('install.php'); }
169 djmaze 9.16 while ($row = $db->sql_fetchrow($result)) {
170 djmaze 9.16 $MAIN_CFG[$row['cfg_name']][$row['cfg_field']] = $row['cfg_value'];
171 djmaze 9.16 }
172 djmaze 9.16 Cache::array_save('MAIN_CFG');
173 djmaze 9.16 $db->sql_freeresult($result);
174 djmaze 1.4 }
175 djmaze 9.1 if (!defined('PHP_AS_NOBODY')) { define('PHP_AS_NOBODY', true); }
176 djmaze 9.50 if (version_compare($MAIN_CFG['global']['Version_Num'], CPG_NUKE, '<')) {
177 trevor 9.60 cpg_error('<strong>We are currently upgrading our website.<br />Please be patient; we should be back shortly.</strong>', 'Maintenance');
178 djmaze 9.50 }
179 djmaze 8.35 $cpgdebugger->error_level = $MAIN_CFG['debug']['error_level'];
180 akamu 9.37 if (CAN_MOD_INI) ini_set('sendmail_from', $MAIN_CFG['global']['adminmail']);
181 djmaze 9.45 if (CPG_DEBUG) { trigger_error('sendmail_from: '.ini_get('sendmail_from'),E_USER_NOTICE); }
182 djmaze 9.67 if (eregi('^localhost|127.0.0.1|192.|10.|172.', $_SERVER['HTTP_HOST'])) $MAIN_CFG['cookie']['domain'] = NULL;
183 djmaze 8.23 else if ($MAIN_CFG['cookie']['server']) {
184 djmaze 9.16 $MAIN_CFG['cookie']['domain'] = $MAIN_CFG['server']['domain'] = ereg_replace('www.', '', $_SERVER['SERVER_NAME']);
185 djmaze 8.23 }
186 djmaze 9.52 $MAIN_CFG['global']['nukeurl'] = 'http://'.$MAIN_CFG['server']['domain'].substr($MAIN_CFG['server']['path'], 0, -1);
187 djmaze 1.48  
188 djmaze 9.52 if (!extension_loaded('gd')) { $MAIN_CFG['global']['sec_code'] = 0; }
189 djmaze 9.52 if ($MAIN_CFG['global']['admingraphic'] < 1) $MAIN_CFG['global']['admingraphic'] = 3;
190 djmaze 1.49 if (empty($MAIN_CFG['cookie']['member'])) $MAIN_CFG['cookie']['member'] = 'member';
191 djmaze 1.49 if (empty($MAIN_CFG['cookie']['admin'])) $MAIN_CFG['cookie']['admin'] = 'admin';
192 djmaze 1.52 $BASEHREF = ($_SERVER['SERVER_PORT'] != 443 ? 'http' : 'https') . '://';
193 djmaze 1.52 $BASEHREF .= (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $MAIN_CFG['server']['domain']);
194 djmaze 1.52 $BASEHREF .= $MAIN_CFG['server']['path'];
195 djmaze 8.37 extract($MAIN_CFG['global'], ((PHPVERS >= 43) ? EXTR_OVERWRITE | EXTR_REFS : EXTR_OVERWRITE));
196 djmaze 1.1  
197 djmaze 9.64 if (defined('XMLFEED')) return; # no need to load everything if it's a feed
198 djmaze 1.1  
199 djmaze 9.52 if ($sec_code == 7 || $sec_code < 3) $gfx_chk = $sec_code;
200 djmaze 9.52 elseif ($sec_code == 6) $gfx_chk = 4;
201 djmaze 9.52 elseif ($sec_code == 5) $gfx_chk = 6;
202 djmaze 9.52 elseif ($sec_code == 4) $gfx_chk = 3;
203 djmaze 9.52 elseif ($sec_code == 3) $gfx_chk = 5;
204 djmaze 9.52 $MAIN_CFG['global']['gfx_chk'] = $gfx_chk;
205 djmaze 9.21 /******************************************************************************
206 djmaze 9.21 Set default metatags
207 djmaze 9.21 *******************************************************************************/
208 djmaze 9.21 $METATAGS['description'] = $slogan;
209 djmaze 9.21 $METATAGS['keywords'] = '';
210 djmaze 9.21 $METATAGS['resource-type'] = 'document';
211 djmaze 9.21 $METATAGS['distribution'] = 'global';
212 djmaze 9.21 $METATAGS['author'] = $sitename;
213 djmaze 9.21 $METATAGS['copyright'] = 'Copyright (c) '.date('Y').' by '.$sitename;
214 djmaze 9.21 $METATAGS['robots'] = 'index, follow';
215 djmaze 9.21 $METATAGS['rating'] = 'general';
216 djmaze 9.58 $METATAGS['generator'] = 'CPG Dragonfly CMS: Copyright (c) 2003-'.date('Y').' by CPG-Nuke Development Team, http://dragonflycms.org';
217 djmaze 9.21 //$METATAGS['revisit-after'] = '1 days';
218 djmaze 9.21 $METATAGS['MSSmartTagsPreventParsing'] = 'true';
219 djmaze 9.21  
220 djmaze 9.21 /******************************************************************************
221 djmaze 9.21 Start the session
222 djmaze 9.21 *******************************************************************************/
223 djmaze 1.6 $SESS =& new cpg_session();
224 djmaze 9.21  
225 djmaze 9.16 /******************************************************************************
226 djmaze 9.16 Check if the <form> POST is comming from this server
227 djmaze 9.16 *******************************************************************************/
228 djmaze 9.65 if ($_SERVER['REQUEST_METHOD'] == 'POST' && empty($CPG_SESS['user']['uri'])) {
229 djmaze 9.65 if (PHPVERS >= 43) {
230 djmaze 9.65 trigger_error('<pre>'.print_r($CPG_SESS, true).'</pre>', E_USER_WARNING);
231 djmaze 9.16 }
232 djmaze 9.65 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');
233 djmaze 8.37 }
234 djmaze 9.21  
235 djmaze 9.21 /******************************************************************************
236 djmaze 9.21 Load member/visitor details and ban him if he is listed in the banlist
237 djmaze 9.21 *******************************************************************************/
238 djmaze 1.18 $CLASS['member'] =& new cpg_member();
239 djmaze 9.44 $userinfo =& $_SESSION['CPG_USER'];
240 djmaze 9.44 //$userinfo =& $CLASS['member']->members[$CLASS['member']->user_id];
241 djmaze 9.20 if (!isset($CPG_SESS['banned'])) {
242 djmaze 9.20 $CPG_SESS['banned'] = false;
243 djmaze 9.20 preg_match('/(..)(..)(..)(..)/', $userinfo['user_ip'], $ip_parts);
244 djmaze 9.20 $sql = "SELECT ban_ip, ban_userid, ban_email FROM " . $prefix.'_bbbanlist' . "
245 djmaze 9.20 WHERE ban_ip IN ('".$ip_parts[1].$ip_parts[2].$ip_parts[3].$ip_parts[4]."', '".$ip_parts[1].$ip_parts[2].$ip_parts[3]."ff', '".$ip_parts[1].$ip_parts[2]."ffff', '".$ip_parts[1]."ffffff')";
246 djmaze 9.20 if (is_user()) {
247 djmaze 9.20 $sql .= " OR ban_userid = ".is_user();
248 djmaze 9.20 // $sql .= " OR ban_email LIKE '".str_replace("\'", "''", $userinfo['user_email'])."'
249 djmaze 9.20 // OR ban_email LIKE '".substr(str_replace("\'", "''", $userinfo['user_email']), strpos(str_replace("\'", "''", $userinfo['user_email']), "@"))."'";
250 djmaze 9.20 }
251 djmaze 9.20 if ($ban_info = $db->sql_ufetchrow($sql, SQL_ASSOC)) {
252 djmaze 9.20 $CPG_SESS['banned'] = ($ban_info['ban_ip'] || $ban_info['ban_userid']); // || $ban_info['ban_email']
253 djmaze 9.20 }
254 djmaze 9.20 }
255 trevor 9.36 if ($CPG_SESS['banned']) { cpg_error('You have been banned from this site'); }
256 djmaze 9.21  
257 djmaze 9.21 /******************************************************************************
258 djmaze 9.22 Are we requesting the security code ?
259 djmaze 9.21 *******************************************************************************/
260 djmaze 9.22 if (isset($_GET['name']) && ($_GET['name'] == 'gfx' || (isset($_GET['op']) && $_GET['name'] == 'Your_Account' && $_GET['op'] == 'gfx'))) {
261 djmaze 9.22 require(BASEDIR.'includes/gfxchk.php');
262 djmaze 1.1 }
263 djmaze 9.21  
264 djmaze 9.21 /******************************************************************************
265 djmaze 9.22 Load the administrator and if no admin turn of error reports
266 djmaze 9.21 *******************************************************************************/
267 djmaze 9.22 if (!$CLASS['member']->loadadmin()) {
268 djmaze 9.22 error_reporting(0);
269 djmaze 9.21 }
270 djmaze 9.21  
271 djmaze 9.21 /******************************************************************************
272 djmaze 9.21 Check if maintenance is turned on
273 djmaze 9.21 *******************************************************************************/
274 trevor 1.50 if ($MAIN_CFG['global']['maintenance'] && !is_admin() && !defined('ADMIN_PAGES') && !defined('INSTALL')) {
275 djmaze 9.16 cpg_error('<strong>'.$MAIN_CFG['global']['maintenance_text'].'</strong>', 'Maintenance');
276 djmaze 1.1 }
277 djmaze 9.21  
278 djmaze 9.16 /******************************************************************************
279 djmaze 9.22 Load the theme template system and check if the current theme uses the system
280 djmaze 9.16 *******************************************************************************/
281 djmaze 9.22 $ThemeSel = get_theme();
282 djmaze 9.22 define('THEME_USES_TPL', file_exists('themes/'.$ThemeSel.'/template/header.html'));
283 djmaze 9.64 # Load template handler
284 djmaze 1.7 $cpgtpl =& new cpg_template();
285 djmaze 9.64 $cpgtpl->set_template(); # dynamic language
286 djmaze 9.64 //$cpgtpl->set_template(true); # static language
287 djmaze 1.7 //$cpgtpl->cachepath = '';
288 djmaze 1.7 if (THEME_USES_TPL) { $template =& $cpgtpl; }
289 djmaze 1.7  
290 djmaze 9.22 $SESS->init_info();
291 djmaze 9.22  
292 djmaze 9.22 /******************************************************************************
293 djmaze 9.22 Include language to detect languages from browser setting and user preferences
294 djmaze 9.22 Join the nuke language initiative (NLI) http://cpgnuke.com
295 djmaze 9.22 *******************************************************************************/
296 djmaze 9.54 require_once(CORE_PATH.'functions/language.php');
297 djmaze 9.22  
298 djmaze 1.7 header('Content-Type: text/html; charset='._CHARSET);
299 djmaze 8.17 header('Content-language: '._LANGCODE);
300 djmaze 9.64 # standard privacy header change to yours
301 djmaze 1.7 header('P3P: CP="CAO DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM PRE"');
302 djmaze 1.7 //header("P3P: CP=\"ALL DSP COR NID CURa OUR STP PUR\"");
303 djmaze 9.64 # Notify server time
304 djmaze 8.21 header('Date: '.date('D, d M Y H:i:s \G\M\T', gmtime()));
305 djmaze 9.65 header('Last-Modified: '.date('D, d M Y H:i:s \G\M\T', gmtime()));
306 djmaze 9.65 header('Expires: '.date('D, d M Y H:i:s \G\M\T', gmtime() + 10800));
307 djmaze 8.28 define('USERS', 'YToxOntzOjQ6Im51a2UiO3M6MzE5OiIkY29wcGVybWluZT0iVGhpcyB3ZWJzaXRlIGVuZ2luZSBDb3B5cmlnaHQgJmNvcHk7IDIwMDMgLSAiLmRhdGUoJ1knKS4iIGJ5IENQRy1OdWtlIERldiBUZWFtPGJyIC8+RnJlZSBTb2Z0d2FyZSByZWxlYXNlZCB1bmRlciB0aGUgPGEgaHJlZj1cImh0dHA6L'
308 djmaze 8.28 .'y93d3cuZHJhZ29uZmx5Y21zLmNvbS9HTlVHUEwuaHRtbFwiIHRhcmdldD1cIl9ibGFua1wiPkdOVSBHUEw8L2E+OyBlaXRoZXIgdmVyc2lvbiAyIG9mIHRoZSBMaWNlbnNlLCBvciAoYXQgeW91ciBvcHRpb24pIGFueSBsYXRlciB2ZXJzaW9uLiBObyB3YXJyYW50eSBpcyBnaXZlbiBvciBpbXBsaWVkLiI7Ijt9', true);
309 djmaze 1.3  
310 djmaze 8.8 function get_microtime() {
311 djmaze 9.16 list($usec, $sec) = explode(' ', microtime());
312 djmaze 9.16 return ($usec + $sec);
313 djmaze 8.8 }
314 djmaze 8.8  
315 djmaze 9.64 # Function which removes \015\012 which causes linebreaks in SMTP email
316 djmaze 1.1 function removecrlf($str) {
317 djmaze 9.16 return strtr($str, "\015\012", ' ');
318 djmaze 1.1 }
319 djmaze 9.16 /******************************************************************************
320 djmaze 1.1  
321 djmaze 9.16 Sends a email thru PHP or SMTP using plain text or html formatted
322 djmaze 9.16 bool send_mail(
323 djmaze 9.16 &$mailer_message: returns info about the send mail or the error message
324 djmaze 9.16 $message : the message that you want to send
325 djmaze 9.16 $html : send message as html or text 1 = html, 0 = text(default)
326 djmaze 9.16 $subject : the subject of the message, default = _FEEDBACK
327 djmaze 9.16 $to : emailaddress of person to send to, default = admin mailaddress
328 djmaze 9.16 $to_name : name of person to send to, default = sitename
329 djmaze 9.16 $from : emailaddress of person who sends the message, default = admin mailaddress
330 djmaze 9.16 $from_name: name of person who sends the message, default = sitename
331 djmaze 9.42 $custom_headers: array of custom mail headers
332 djmaze 9.16 )
333 djmaze 1.1  
334 djmaze 9.16 *******************************************************************************/
335 djmaze 9.42 function send_mail(&$mailer_message, $message, $html=0, $subject='', $to='', $to_name='', $from='', $from_name='', $custom_headers=false) {
336 djmaze 9.16 global $MAIN_CFG, $module_name, $PHPMAILER_LANG, $CLASS;
337 alexm 1.14  
338 djmaze 9.16 if ($module_name != 'Contact' && function_exists('get_lang')) { get_lang('Contact'); }
339 djmaze 9.43 if (empty($to)) $to = $MAIN_CFG['global']['adminmail'];
340 djmaze 9.16 if ($from == '') $from = $MAIN_CFG['global']['adminmail'];
341 djmaze 9.16 if (isset($CLASS['member']) && $CLASS['member']->demo && $to != $MAIN_CFG['global']['adminmail']) {
342 djmaze 9.16 $mailer_message = 'The mail system has been disabled in the administration demo';
343 djmaze 9.16 return false;
344 djmaze 9.16 }
345 djmaze 9.16 if (is_email($from) < 1) {
346 djmaze 9.16 $mailer_message = $PHPMAILER_LANG['from_failed'].$from;
347 djmaze 9.16 return false;
348 djmaze 9.16 }
349 djmaze 9.16 if (!function_exists('get_lang')) {
350 djmaze 9.16 global $PHPMAILER_LANG;
351 djmaze 9.16 include_once(BASEDIR.'language/english/main.php');
352 djmaze 9.16 }
353 djmaze 9.54 require_once(CORE_PATH.'classes/phpmailer.php');
354 djmaze 9.16 $CLASS['mail']->ClearAll();
355 djmaze 9.16 $CLASS['mail']->SetLanguage();
356 djmaze 9.16 if ($MAIN_CFG['email']['smtp_on']) {
357 djmaze 9.64 $CLASS['mail']->IsSMTP(); # set mailer to use SMTP
358 djmaze 9.16 $CLASS['mail']->Host = $MAIN_CFG['email']['smtphost'];
359 djmaze 9.16 if ($MAIN_CFG['email']['smtp_auth']) {
360 djmaze 9.64 $CLASS['mail']->SMTPAuth = true; # turn on SMTP authentication
361 djmaze 9.64 $CLASS['mail']->Username = $MAIN_CFG['email']['smtp_uname']; # SMTP username
362 djmaze 9.64 $CLASS['mail']->Password = $MAIN_CFG['email']['smtp_pass']; # SMTP password
363 djmaze 9.16 }
364 djmaze 9.16 } else {
365 djmaze 9.16 $CLASS['mail']->IsMail();
366 djmaze 9.16 }
367 djmaze 9.16 $CLASS['mail']->From = removecrlf($from);
368 djmaze 9.16 $CLASS['mail']->FromName = ($from_name!='') ? removecrlf($from_name) : $MAIN_CFG['global']['sitename'];
369 djmaze 9.16 if (is_array($to)) {
370 djmaze 9.16 foreach ($to as $to_email => $to_name) {
371 djmaze 9.16 if (is_email($to_email) < 1) {
372 djmaze 9.16 $mailer_message = $PHPMAILER_LANG['recipients_failed'].$to;
373 djmaze 9.16 return false;
374 djmaze 9.16 }
375 djmaze 9.16 $CLASS['mail']->AddBCC(removecrlf($to_email), removecrlf($to_name));
376 djmaze 9.16 }
377 djmaze 9.16 } elseif (is_email($to) < 1) {
378 djmaze 9.16 $mailer_message = $PHPMAILER_LANG['recipients_failed'].$to;
379 djmaze 9.16 return false;
380 djmaze 9.16 } elseif ($to_name != '') {
381 djmaze 9.16 $CLASS['mail']->AddAddress(removecrlf($to), removecrlf($to_name));
382 djmaze 9.16 } else {
383 djmaze 9.16 $CLASS['mail']->AddAddress(removecrlf($to));
384 djmaze 9.16 }
385 djmaze 9.42  
386 djmaze 9.42 if (is_array($custom_headers) && count($custom_headers)) {
387 djmaze 9.42 foreach ($custom_headers as $header) {
388 djmaze 9.42 $CLASS['mail']->AddCustomHeader($header);
389 djmaze 9.42 }
390 djmaze 9.42 }
391 djmaze 9.42  
392 djmaze 9.16 $CLASS['mail']->Priority = 3;
393 djmaze 9.16 $CLASS['mail']->Encoding = '8bit';
394 djmaze 9.16 $CLASS['mail']->CharSet = _CHARSET;
395 djmaze 9.16 $CLASS['mail']->Subject = ($subject!='') ? removecrlf($subject) : _FEEDBACK;
396 djmaze 9.16 if ($html && ($MAIN_CFG['email']['allow_html_email'] || is_admin())) {
397 djmaze 9.16 if (function_exists('get_lang')) {
398 djmaze 9.16 require_once(BASEDIR.'includes/nbbcode.php');
399 djmaze 9.16 $message = decode_bbcode($message, 0, true);
400 djmaze 9.16 }
401 djmaze 9.16 $CLASS['mail']->IsHTML(true);
402 djmaze 9.16 $CLASS['mail']->AltBody = strip_tags($message);
403 djmaze 9.16 $CLASS['mail']->Body = $message;
404 djmaze 9.16 } else {
405 djmaze 9.16 $CLASS['mail']->IsHTML(false);
406 djmaze 9.16 $CLASS['mail']->Body = strip_tags($message);
407 djmaze 9.16 }
408 djmaze 9.16 $mailer_message = '';
409 djmaze 9.16 if (!$CLASS['mail']->Send()) {
410 djmaze 9.16 $mailer_message .= 'Message could not be sent.<p>';
411 djmaze 9.16 $mailer_message .= 'Mailer Error: ' . $CLASS['mail']->ErrorInfo;
412 djmaze 9.16 return false;
413 djmaze 9.16 } else {
414 djmaze 9.16 $mailer_message .= '<p align="center">'._SUCCESS_MESSAGE_SENT.'<br />';
415 djmaze 9.16 $mailer_message .= "<code>$message</code><br />";
416 djmaze 9.16 $mailer_message .= '<p align="center">'._MAHALO.'</center></p>';
417 djmaze 9.16 return true;
418 djmaze 9.16 }
419 djmaze 9.16 //return $mailer_message;
420 djmaze 1.1 }
421 djmaze 1.1  
422 djmaze 9.16 /******************************************************************************
423 djmaze 1.1 Returns if the emailaddress is valid or not
424 djmaze 9.16 *******************************************************************************/
425 djmaze 1.1 function is_email(&$email) {
426 djmaze 9.16 global $DeniedEmailDomains;
427 djmaze 9.48 static $domains;
428 djmaze 9.16 if (strlen($email) < 5) return 0;
429 djmaze 9.16 $email = strtolower($email);
430 djmaze 9.16 if (!ereg('^[_\.\+0-9a-z-]+@[0-9a-z-]{2,63}\.+[a-z]{2,6}$',$email) &&
431 akamu 9.46 !ereg('^[_\.\+0-9a-z-]+@[_0-9a-z\-]{2,25}\.+[_0-9a-z\-]{2,63}\.+[a-z]{2,6}$',$email) &&
432 akamu 9.46 !ereg('^[_\.\+0-9a-z-]+@[_0-9a-z\-]{2,25}\.+[_0-9a-z\-]{2,63}\.+[a-z]{2,6}\.+[a-z]{2,6}$',$email)) {
433 djmaze 9.16 // "#\[email\]([a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)\[/email\]#si"
434 djmaze 9.16 return -1;
435 djmaze 9.16 }
436 djmaze 9.49 if (empty($domains)) {
437 djmaze 9.48 $DeniedEmailDomains[] = 'mydomain.com';
438 djmaze 9.48 $domains = implode('|', $DeniedEmailDomains);
439 djmaze 9.48 }
440 djmaze 9.16 $email = explode('@', $email);
441 djmaze 9.48 if (eregi("($domains)", $email[1])) { return -2; }
442 djmaze 9.16 $email = implode('@', $email);
443 djmaze 9.16 return 1;
444 djmaze 1.1 }
445 djmaze 1.1  
446 djmaze 9.16 /******************************************************************************
447 djmaze 1.1 Returns admin name if the user is an administrator, otherwise false
448 djmaze 9.16 *******************************************************************************/
449 djmaze 1.1 function is_admin() {
450 djmaze 9.16 global $CLASS;
451 djmaze 9.16 return (isset($CLASS['member']) && is_object($CLASS['member'])) ? $CLASS['member']->admin_id : false;
452 djmaze 1.1 }
453 djmaze 8.5 function can_admin($module='super') {
454 djmaze 9.16 global $CLASS;
455 djmaze 9.16 $module = strtolower($module);
456 djmaze 9.16 $adminfo =& $CLASS['member']->admin;
457 djmaze 9.16 return (is_array($adminfo) && isset($adminfo['radmin'.$module]) && ($adminfo['radminsuper'] || $adminfo['radmin'.$module])) ? true : false;
458 djmaze 1.1 }
459 djmaze 9.16 /******************************************************************************
460 djmaze 1.1 Returns member ID if the user is an registered member, otherwise false
461 djmaze 9.16 *******************************************************************************/
462 djmaze 1.1 function is_user() {
463 djmaze 9.16 global $CLASS;
464 djmaze 9.16 return ($CLASS['member']->user_id > 1) ? $CLASS['member']->user_id : false;
465 djmaze 1.1 }
466 djmaze 9.16 /******************************************************************************
467 djmaze 1.36 Returns groupname if visitor is in the group, otherwise false
468 djmaze 9.16 *******************************************************************************/
469 djmaze 1.36 function in_group($id) {
470 djmaze 9.16 global $userinfo;
471 djmaze 9.16 if (isset($userinfo['_mem_of_groups'][$id])) {
472 djmaze 9.16 return $userinfo['_mem_of_groups'][$id];
473 djmaze 9.16 } else {
474 djmaze 9.16 return false;
475 djmaze 9.16 }
476 djmaze 1.1 }
477 djmaze 9.16 /******************************************************************************
478 djmaze 1.1 See includes/classes/cpg_member -> getmemdata() for details
479 djmaze 9.16 *******************************************************************************/
480 djmaze 1.1 function getusrdata($user, $data='*') {
481 djmaze 9.16 global $CLASS;
482 djmaze 9.16 return $CLASS['member']->getmemdata($user, $data);
483 djmaze 1.1 }
484 djmaze 1.1  
485 djmaze 1.1 function is_active($module) {
486 djmaze 9.16 global $prefix, $db, $active_modules;
487 djmaze 9.64 static $save; # Added by steven111
488 djmaze 9.16 if (is_array($save)) {
489 djmaze 9.16 if (isset($save[$module])) return ($save[$module]);
490 djmaze 9.16 return 0;
491 djmaze 9.16 }
492 djmaze 9.16 if (!Cache::array_load('active_modules')) {
493 djmaze 9.56 $result = $db->sql_query('SELECT title, version FROM '.$prefix.'_modules WHERE active=1');
494 djmaze 9.56 while ($row = $db->sql_fetchrow($result, SQL_NUM)) {
495 djmaze 9.56 $active_modules[$row[0]] = (intval($row[1]) > 0) ? $row[1] : 1;
496 djmaze 9.16 }
497 djmaze 9.16 $db->sql_freeresult($result);
498 djmaze 9.16 Cache::array_save('active_modules');
499 djmaze 9.16 }
500 djmaze 9.16 $save = $active_modules;
501 djmaze 9.16 if (isset($save[$module])) return ($save[$module]);
502 djmaze 9.16 return 0;
503 djmaze 1.1 }
504 djmaze 1.46  
505 djmaze 9.61 function strip_javascript($text, $events=true) {
506 djmaze 9.61 $patterns[] = '/<\s*script[^>]*?>.*?<\/\s*script\s*>/i';
507 djmaze 9.61 $patterns[] = '/href\s*=\s*\'\s*javascript.*\'/i';
508 djmaze 9.61 $patterns[] = '/href\s*=\s*"\s*javascript.*"/i';
509 djmaze 9.61 if ($events) {
510 djmaze 9.61 $events = 'blur|click|dblclick|focus|load|unload|select|change'
511 djmaze 9.61 .'|submit|abort|error|reset|dragdrop|keydown|keypress|keyup'
512 djmaze 9.61 .'|mouseout|mouseover|mousedown|mousemove|mouseup|move|resize';
513 djmaze 9.62 $patterns[] = '/on('.$events.')\s*=\s*\'.*?\'/i';
514 djmaze 9.62 $patterns[] = '/on('.$events.')\s*=\s*".*?"/i';
515 djmaze 9.61 }
516 djmaze 9.61 return preg_replace($patterns,'',$text);
517 djmaze 9.61 }
518 djmaze 9.61  
519 djmaze 1.46 function htmlprepare($str, $nl2br=false, $spchar=ENT_QUOTES, $nohtml=false) {
520 djmaze 9.64 if ($nohtml) { $str = strip_tags($str, $nohtml); } # $nohtml : <a><br><b><i><img><li><ol><p><strong><u><ul>
521 djmaze 9.64 $str = htmlspecialchars($str,$spchar,'UTF-8'); # htmlentities sucks cos it converts all chars
522 djmaze 9.16 if ($nl2br) { $str = nl2br($str); }
523 djmaze 9.16 return trim($str);
524 djmaze 1.46 }
525 djmaze 8.1 function htmlunprepare($str, $nl2br=false) {
526 djmaze 9.16 $unhtml_specialchars_match = array('#&gt;#', '#&lt;#', '#&quot;#', '#&\#039;#', '#&amp;#');
527 djmaze 9.16 $unhtml_specialchars_replace = array('>', '<', '"', '\'', '&');
528 djmaze 9.16 if ($nl2br) {
529 djmaze 9.16 $unhtml_specialchars_match[] = "#<br />\n#";
530 djmaze 9.16 $unhtml_specialchars_replace[] = "\n";
531 djmaze 9.16 }
532 djmaze 9.16 return preg_replace($unhtml_specialchars_match, $unhtml_specialchars_replace, $str);
533 djmaze 8.1 }
534 djmaze 1.47 function html2bb($text) {
535 djmaze 9.16 $text = ereg_replace('<', ' <', $text);
536 djmaze 9.16 $text = preg_replace('/<ol type="([a1])">/si', '/\[list=\\1\]', $text);
537 djmaze 9.16 $text = preg_replace('/<(b|u|i|hr)>/sie', "'['.strtolower(\\1).']'", $text);
538 djmaze 9.16 $text = preg_replace('/<\/(b|u|i|hr)>/sie', "'[/'.strtolower(\\1).']'", $text);
539 djmaze 9.16 $text = preg_replace('#<img(.*?)src="(.*?)\.(gif|png|jpg|jpeg)"(.*?)>#si', '[img]\\2.\\3[/img]', $text);
540 djmaze 9.16 $text = str_replace('<ul>', '[list]', $text);
541 djmaze 9.16 $text = str_replace('<li>', '[*]', $text);
542 djmaze 9.16 $text = str_replace('</ul>', '[/list:u]', $text);
543 djmaze 9.16 $text = str_replace('</ol>', '[/list:o]', $text);
544 djmaze 9.16 $text = strip_tags($text, '<br><p><strong>');
545 djmaze 9.16 return trim($text);
546 djmaze 9.16 }
547 djmaze 1.1  
548 djmaze 1.45 function Fix_Quotes($str, $nohtml=false, $spchar=false) {
549 djmaze 9.16 global $db;
550 djmaze 9.16 if ($nohtml) { $str = strip_tags($str); }
551 djmaze 9.16 if ($spchar) { $str = htmlspecialchars($str,ENT_NOQUOTES,'UTF-8'); }
552 djmaze 9.16 return $db->sql_escape_string(trim($str));
553 djmaze 1.1 }
554 djmaze 1.1  
555 djmaze 9.64 # Text Filtering
556 djmaze 1.1 function check_words(&$Message) {
557 djmaze 9.16 global $CensorList, $CensorReplace, $CensorMode;
558 djmaze 9.16 if ($CensorMode != 0) {
559 djmaze 9.16 if (is_array($CensorList)) {
560 djmaze 9.16 if ($CensorMode == 1) {
561 djmaze 9.16 for ($i = 0; $i < count($CensorList); $i++) {
562 djmaze 9.16 $Message = eregi_replace("$CensorList[$i]([^a-zA-Z0-9])","$CensorReplace\\1",$Message);
563 djmaze 9.16 }
564 djmaze 9.16 } elseif ($CensorMode == 2) {
565 djmaze 9.16 for ($i = 0; $i < count($CensorList); $i++) {
566 djmaze 9.16 $Message = eregi_replace("(^|[^[:alnum:]])$CensorList[$i]","\\1$CensorReplace",$Message);
567 djmaze 9.16 }
568 djmaze 9.16 } elseif ($CensorMode == 3) {
569 djmaze 9.16 for ($i = 0; $i < count($CensorList); $i++) {
570 djmaze 9.16 $Message = eregi_replace($CensorList[$i],$CensorReplace,$Message);
571 djmaze 9.16 }
572 djmaze 9.16 }
573 djmaze 9.16 }
574 djmaze 9.16 }
575 djmaze 9.16 return $Message;
576 djmaze 1.1 }
577 djmaze 1.1  
578 djmaze 9.64 # Deprecated Functions
579 djmaze 1.36 function cookiedecode() {
580 trevor 9.36 trigger_error('The function cookiedecode() is deprecated in Dragonfly. Please use the global array $userinfo', E_USER_WARNING);
581 djmaze 9.53 return false;
582 djmaze 1.36 }
583 djmaze 1.36 function getusrinfo() {
584 trevor 9.36 trigger_error('The function getusrinfo() is deprecated in Dragonfly. Please use the global array $userinfo', E_USER_WARNING);
585 djmaze 9.16 global $userinfo;
586 djmaze 9.16 return $userinfo;
587 djmaze 1.36 }
588 trevor 8.29 function FixQuotes($what='') {
589 trevor 9.36 trigger_error('The function FixQuotes() is deprecated in Dragonfly. Please change your call to Fix_Quotes()', E_USER_WARNING);
590 djmaze 9.16 $what = ereg_replace("'","''",$what);
591 djmaze 9.16 while (eregi("\\\\'", $what)) {
592 djmaze 9.16 $what = ereg_replace("\\\\'","'",$what);
593 djmaze 9.16 }
594 djmaze 9.16 return $what;
595 djmaze 1.1 }
596 djmaze 1.36 function formatTimestamp($time) {
597 trevor 9.36 trigger_error('The function formatTimestamp() is deprecated in Dragonfly. Please change your call to formatDateTime()', E_USER_WARNING);
598 djmaze 9.16 return formatDateTime($time, _DATESTRING);
599 djmaze 1.1 }
600 djmaze 1.36 function check_html($str, $strip='') {
601 trevor 9.36 trigger_error('The function check_html() is deprecated in Dragonfly. Please change your call to Fix_Quotes()', E_USER_WARNING);
602 djmaze 9.16 return Fix_Quotes($str, empty($strip));
603 djmaze 1.1 }
604 trevor 8.29 function filter_text($Message, $strip='') {
605 trevor 9.36 trigger_error('The function filter_text() is deprecated in Dragonfly. Please change your call to check_words()', E_USER_WARNING);
606 djmaze 9.16 return check_words($Message);
607 djmaze 1.36 }
608 trevor 8.29 function delQuotes($string) {
609 trevor 9.36 trigger_error('The function delQuotes() has been removed from Dragonfly', E_USER_WARNING);
610 djmaze 9.16 return $string;
611 djmaze 1.36 }
612 djmaze 1.36 function is_group() {
613 djmaze 9.16 trigger_error('The function is_group() has been removed from Dragonfly', E_USER_NOTICE);
614 djmaze 1.36 }
615 djmaze 1.36 function update_points() {
616 djmaze 9.16 trigger_error('The function update_points() has been removed from Dragonfly', E_USER_NOTICE);
617 djmaze 1.36 }
618 djmaze 1.36 function formatAidHeader($aid) {
619 djmaze 9.16 trigger_error('The function formatAidHeader() has been removed from Dragonfly', E_USER_NOTICE);
620 djmaze 9.16 echo $aid;
621 djmaze 1.36 }
622 djmaze 1.36 function get_author($aid) {
623 djmaze 9.16 trigger_error('The function get_author() has been removed from Dragonfly', E_USER_NOTICE);
624 djmaze 9.16 return $aid;
625 djmaze 1.1 }
626 djmaze 1.1  
627 djmaze 9.64 # Time Formatting
628 djmaze 1.1 function gmtime() {
629 djmaze 9.16 static $time;
630 djmaze 9.16 if (!$time) { $time = (time() - date('Z')); }
631 djmaze 9.16 return $time;
632 djmaze 1.1 }
633 djmaze 1.1 function formatDateTime($time, $format) {
634 djmaze 9.16 global $userinfo;
635 djmaze 9.23 return L10NTime::strftime($format, $time, $userinfo['user_dst'], $userinfo['user_timezone']);
636 djmaze 1.1 }
637 djmaze 1.1  
638 djmaze 9.64 # IP Handling
639 djmaze 1.1 function encode_ip($dotquad_ip) {
640 djmaze 9.16 $ip_sep = explode('.', $dotquad_ip);
641 djmaze 9.16 return (count($ip_sep) == 4) ? sprintf('%02x%02x%02x%02x', $ip_sep[0], $ip_sep[1], $ip_sep[2], $ip_sep[3]) : '';
642 djmaze 1.1 }
643 djmaze 1.1 function decode_ip($int_ip) {
644 djmaze 9.16 $hexipbang = explode('.', chunk_split($int_ip, 2, '.'));
645 djmaze 9.16 return hexdec($hexipbang[0]). '.' . hexdec($hexipbang[1]) . '.' . hexdec($hexipbang[2]) . '.' . hexdec($hexipbang[3]);
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.16 if (fwrite($fp, $content) === FALSE) {
665 djmaze 9.16 flock($fp, LOCK_UN);
666 djmaze 9.16 trigger_error("Cannot write to file ($filename)", E_USER_WARNING);
667 djmaze 9.16 return false;
668 djmaze 9.16 }
669 djmaze 9.16 flock($fp, LOCK_UN);
670 djmaze 9.16 if (!fclose($fp)) {
671 djmaze 9.16 trigger_error("Cannot close file ($filename)", E_USER_WARNING);
672 djmaze 9.16 return false;
673 djmaze 9.16 }
674 djmaze 9.16 if (!defined('PHP_AS_NOBODY')) { define_nobody($filename); }
675 djmaze 9.16 chmod($filename, (PHP_AS_NOBODY ? 0666 : 0644));
676 djmaze 9.16 return true;
677 djmaze 8.23 }
678 djmaze 9.8  
679 djmaze 9.8 function define_nobody($file) {
680 djmaze 9.64 # http://bugs.php.net/bug.php?id=31849
681 djmaze 9.16 if (!defined('PHP_AS_NOBODY')) {
682 djmaze 9.16 define('PHP_AS_NOBODY', (getmyuid() != fileowner($file) || _DRAGONLY_OWNER == 'nobody'));
683 djmaze 9.16 }
684 djmaze 9.8 }


Code Credits - Privacy Policy