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.1 (9 years 2 months 3 weeks 6 days 3 hours 54 minutes 21 seconds ago) by djmaze
Changed : +3 -2 lines
Comment: New filehandler class for properly handling uploaded images
Fixed avatar control to check animation on uploaded avatars


# Author Rev Line
1 djmaze 1.1 <?php
2 djmaze 1.1 /*********************************************
3 djmaze 1.1 CPG-NUKE: Advanced Content Management System
4 djmaze 1.1 ********************************************
5 djmaze 1.1 Copyright (c) 2004 by CPG-Nuke Dev Team
6 djmaze 1.1 http://www.cpgnuke.com
7 djmaze 1.1  
8 djmaze 1.1 CPG-Nuke 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 1.17 $Source: /cvs/html/includes/cmsinit.inc,v $
12 djmaze 9.1 $Revision: 9.0 $
13 djmaze 8.36 $Author: djmaze $
14 djmaze 9.1 $Date: 2005/01/12 03:32:35 $
15 djmaze 1.1  
16 djmaze 8.6 ***********************************************************************/
17 djmaze 1.22 // Disable DOS Attacks
18 djmaze 1.22 if (($_SERVER['HTTP_USER_AGENT'] == '' || $_SERVER['HTTP_USER_AGENT'] == '-') && !defined('XMLFEED')) {
19 djmaze 1.22 exit;
20 djmaze 1.22 }
21 djmaze 8.40 define('CPG_NUKE', '9.0.0 RC1');
22 djmaze 8.8 $start_time = get_microtime();
23 djmaze 1.48 set_magic_quotes_runtime(0); // Disable magic_quotes_runtime
24 djmaze 8.23 umask(0);
25 djmaze 1.22  
26 djmaze 8.35 define('CAN_MOD_INI', !ereg('ini_set', ini_get('disable_functions')));
27 djmaze 8.35  
28 djmaze 8.39 // Remove GET/POST/Cookie variables from the global scope
29 djmaze 8.39 if (intval(ini_get('register_globals')) != 0) {
30 djmaze 1.37 // since IIS can't turn off register_globals as Apache thru .ht* we destroy them here
31 djmaze 1.37 foreach ($_REQUEST AS $key => $val) {
32 djmaze 1.37 if (isset($$key)) unset($$key);
33 djmaze 8.39 // $_REQUEST[$key] = $val;
34 djmaze 1.37 }
35 djmaze 1.37 }
36 djmaze 8.2 function StripAllSlashes(&$value, $key) {
37 djmaze 8.2 if (is_array($value)) array_walk($value, 'StripAllSlashes');
38 djmaze 8.2 else $value = stripslashes($value);
39 djmaze 8.2 $_REQUEST[$key] =& $value;
40 djmaze 8.2 }
41 djmaze 1.41 if (get_magic_quotes_gpc() || ini_get('magic_quotes_sybase')) {
42 djmaze 8.2 if (is_array($_GET) ) { array_walk($_GET, 'StripAllSlashes'); }
43 djmaze 8.2 if (is_array($_POST)) { array_walk($_POST, 'StripAllSlashes'); }
44 djmaze 8.2 if (is_array($_COOKIE)) { array_walk($_COOKIE, 'StripAllSlashes'); }
45 djmaze 1.41 }
46 djmaze 1.37  
47 djmaze 8.15 if (!defined('BASEDIR')) {
48 djmaze 8.15 $root_path = dirname(dirname(__FILE__));
49 djmaze 8.15 if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
50 djmaze 8.15 $root_path = str_replace('\\', '/', $root_path); //Damn' windows
51 djmaze 8.15 }
52 djmaze 8.15 if (strlen($root_path) > 2) define('BASEDIR', $root_path.'/');
53 djmaze 8.15 else define('BASEDIR', '');
54 djmaze 8.15 }
55 djmaze 8.35 //if (CAN_MOD_INI) ini_set('include_path', BASEDIR);
56 djmaze 1.22 $phpver = explode('.', phpversion());
57 djmaze 1.22 $phpver = "$phpver[0]$phpver[1]";
58 djmaze 8.27 define('PHPVERS', $phpver);
59 djmaze 1.1  
60 trevor 8.29 // we define our own error handler
61 djmaze 8.19 require_once(BASEDIR.'includes/classes/cpg_debugger.php');
62 djmaze 8.19  
63 djmaze 8.35 ini_set('magic_quotes_sybase', 0);
64 djmaze 8.35  
65 djmaze 1.1 // Compress output if server/php config allows
66 djmaze 1.1 $do_gzip_compress = false;
67 djmaze 1.1 $do_zlib_compress = false;
68 djmaze 8.31 define('GZIPSUPPORT', extension_loaded('zlib'));
69 djmaze 8.31 if (GZIPSUPPORT) {
70 djmaze 1.1 if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && eregi('gzip', $_SERVER['HTTP_ACCEPT_ENCODING'])) {
71 djmaze 8.37 if (PHPVERS >= 43) { // PHP 4.2.x seems to give memleak
72 djmaze 1.1 ob_start('ob_gzhandler');
73 djmaze 1.30 } else {
74 djmaze 1.1 $do_gzip_compress = true;
75 djmaze 1.1 ob_start();
76 djmaze 1.1 ob_implicit_flush(0);
77 djmaze 1.1 header('Content-Encoding: gzip');
78 djmaze 1.1 }
79 djmaze 1.1 } else {
80 djmaze 1.1 // Some stupid firewalls don't send the HTTP_ACCEPT_ENCODING
81 djmaze 1.1 // So we still compress in memory for fast page generations
82 djmaze 1.1 // But it will take longer for the visitor to see the page.
83 djmaze 1.1 $do_zlib_compress = true;
84 djmaze 1.1 ob_start();
85 djmaze 1.1 ob_implicit_flush(0);
86 djmaze 1.1 }
87 djmaze 1.1 }
88 djmaze 1.1  
89 djmaze 8.37 if (PHPVERS >= 41) { $PHP_SELF = $_SERVER['PHP_SELF']; }
90 djmaze 1.37  
91 djmaze 1.1 // unset any vars set from globals
92 djmaze 1.19 $pagetitle = $modheader = $adminmenuitems = $adminmail = '';
93 djmaze 1.1 $showblocks = 1;
94 djmaze 1.1 // useless vars but still here to prevent "notice" messages
95 djmaze 1.1 $user = $admin = $cookie = '';
96 djmaze 1.1  
97 trevor 8.29 if (!isset($file)) $file = null;
98 trevor 8.29 if (!isset($name)) $name = null;
99 djmaze 1.1  
100 trevor 1.8 // stops the page creation and shows an error page
101 trevor 8.29 function nuke_error($message, $title='ERROR', $redirect='') {
102 trevor 8.29 trigger_error('Please replace your call to nuke_error() with cpg_error()', E_USER_WARNING);
103 trevor 8.29 cpg_error($message, $title, $redirect);
104 trevor 8.29 }
105 djmaze 1.1 function cpg_error($message, $title='ERROR', $redirect='') {
106 djmaze 1.1 global $userinfo, $SESS;
107 djmaze 1.1 if ($redirect) { header('Refresh: 3; url='.$redirect); }
108 djmaze 1.44 if (defined('THEME_USES_TPL') || defined('HEADER_OPEN')) {
109 trevor 8.34 global $pagetitle, $showblocks, $home, $modheader, $mainindex;
110 djmaze 1.1 $home = $showblocks = 0;
111 djmaze 1.1 $pagetitle = $title;
112 akamu 8.33 $modheader .= '<meta name="robots" content="noindex,follow" />
113 akamu 8.33 <meta name="robots" content="noarchive" />';
114 djmaze 8.15 require_once(BASEDIR.'header.php');
115 djmaze 1.1 OpenTable();
116 akamu 1.28 echo '<center>'.$message.'<br /><br />';
117 trevor 8.34 $link = ($redirect!='') ? '<a href="'.$redirect.'">'._GO.'</a>' : '[ <a href="'.$mainindex.'">'._HOME.'</a> ] '._GOBACK.'</center>';
118 akamu 8.33 echo $link;
119 djmaze 1.1 CloseTable();
120 djmaze 8.23 require_once(BASEDIR.'footer.php');
121 djmaze 1.1 } else {
122 djmaze 8.15 require_once(BASEDIR.'includes/cpg_page.php');
123 djmaze 1.1 $errorpage = cpg_header($title);
124 djmaze 1.1 $errorpage .= "<center>$message</center>";
125 djmaze 1.1 $errorpage .= cpg_footer();
126 djmaze 1.1 if (isset($SESS)) $SESS->write_close();
127 djmaze 1.1 die($errorpage);
128 djmaze 1.1 }
129 djmaze 1.1 }
130 djmaze 1.1  
131 djmaze 8.18 if (file_exists('config.php')) {
132 djmaze 8.18 require_once('config.php');
133 djmaze 8.18 } else {
134 djmaze 8.18 require_once(BASEDIR.'config.php');
135 djmaze 8.18 }
136 djmaze 8.15 require_once(BASEDIR.'includes/db/db.php');
137 djmaze 8.28 require_once(BASEDIR.'includes/classes/cpg_cache.php');
138 djmaze 8.15 require_once(BASEDIR.'includes/classes/session.php');
139 djmaze 8.15 require_once(BASEDIR.'includes/functions/display.php');
140 djmaze 8.15 require_once(BASEDIR.'includes/functions/linking.php');
141 djmaze 8.15 require_once(BASEDIR.'includes/classes/template.php');
142 djmaze 8.15 require_once(BASEDIR.'includes/classes/cpg_member.php');
143 djmaze 1.1 if (defined('INSTALL')) return;
144 djmaze 1.1  
145 djmaze 8.30 if (!Cache::array_load('MAIN_CFG')) {
146 djmaze 1.49 $result = $db->sql_query('SELECT * FROM '.$prefix.'_config_custom', true);
147 djmaze 8.39 if (!$result) { url_redirect('install.php'); }
148 djmaze 1.1 while ($row = $db->sql_fetchrow($result)) {
149 djmaze 1.1 $MAIN_CFG[$row['cfg_name']][$row['cfg_field']] = $row['cfg_value'];
150 djmaze 1.1 }
151 djmaze 8.30 Cache::array_save('MAIN_CFG');
152 djmaze 1.1 $db->sql_freeresult($result);
153 djmaze 1.4 }
154 djmaze 9.1 if (!defined('PHP_AS_NOBODY')) { define('PHP_AS_NOBODY', true); }
155 djmaze 8.40 if (version_compare($MAIN_CFG['global']['Version_Num'], CPG_NUKE, '<')) { url_redirect('install.php'); }
156 djmaze 8.35 $cpgdebugger->error_level = $MAIN_CFG['debug']['error_level'];
157 djmaze 8.37 if (CAN_MOD_INI) ini_set('sendmail_from', $adminmail);
158 djmaze 8.32 if (eregi('localhost|127.0.0.1', $_SERVER['HTTP_HOST'])) $MAIN_CFG['cookie']['domain'] = '';
159 djmaze 8.23 else if ($MAIN_CFG['cookie']['server']) {
160 djmaze 8.23 $MAIN_CFG['cookie']['domain'] = $MAIN_CFG['server']['domain'] = ereg_replace('www.', '', $_SERVER['SERVER_NAME']);
161 djmaze 8.23 }
162 djmaze 1.48  
163 djmaze 1.34 if (!extension_loaded('gd')) { $MAIN_CFG['global']['gfx_chk'] = 0; }
164 djmaze 1.34 $MAIN_CFG['global']['nukeurl'] = 'http://'.$MAIN_CFG['server']['domain'].substr($MAIN_CFG['server']['path'], 0, -1);
165 djmaze 1.49 if (empty($MAIN_CFG['cookie']['member'])) $MAIN_CFG['cookie']['member'] = 'member';
166 djmaze 1.49 if (empty($MAIN_CFG['cookie']['admin'])) $MAIN_CFG['cookie']['admin'] = 'admin';
167 djmaze 1.52 $BASEHREF = ($_SERVER['SERVER_PORT'] != 443 ? 'http' : 'https') . '://';
168 djmaze 1.52 $BASEHREF .= (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $MAIN_CFG['server']['domain']);
169 djmaze 1.52 $BASEHREF .= $MAIN_CFG['server']['path'];
170 djmaze 8.37 extract($MAIN_CFG['global'], ((PHPVERS >= 43) ? EXTR_OVERWRITE | EXTR_REFS : EXTR_OVERWRITE));
171 djmaze 1.1  
172 djmaze 1.1 if (defined('XMLFEED')) return; // no need to load everything if it's a feed
173 djmaze 1.1  
174 djmaze 1.6 global $CPG_SESS;
175 djmaze 1.6 $SESS =& new cpg_session();
176 djmaze 8.37 //register_shutdown_function(array(&$SESS, "write_close"));
177 djmaze 1.25 if (isset($_GET['name']) && ($_GET['name'] == 'gfx' || (isset($_GET['op']) && $_GET['name'] == 'Your_Account' && $_GET['op'] == 'gfx'))) {
178 djmaze 8.15 require(BASEDIR.'includes/gfxchk.php');
179 djmaze 1.1 }
180 djmaze 8.37 /************************************************************************************/
181 djmaze 8.37 /* Check if the <form> POST is comming from this server */
182 djmaze 8.37 /************************************************************************************/
183 djmaze 8.37 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
184 djmaze 8.37 if (!isset($CPG_SESS['user']['uri']) || empty($CPG_SESS['user']['uri'])) {
185 djmaze 8.37 if (PHPVERS >= 43) {
186 djmaze 8.37 trigger_error('<pre>'.print_r($CPG_SESS, true).'</pre>', E_USER_WARNING);
187 djmaze 8.37 }
188 djmaze 8.37 cpg_error('Please enable cookies to post on this site. If you feel that you have reached this message in error please refresh the preceding page once and post again');
189 djmaze 8.37 }
190 djmaze 8.37 }
191 djmaze 1.18 $CLASS['member'] =& new cpg_member();
192 djmaze 1.1 $userinfo =& $CLASS['member']->members[$CLASS['member']->user_id];
193 djmaze 1.1 $nukeuser =& $CLASS['member']->cookie;
194 djmaze 1.18 if ($CLASS['member']->loadadmin()) {
195 djmaze 1.1 foreach($CLASS['member']->admin as $var => $val) {
196 djmaze 1.4 if (ereg('radmin',$var)) { $$var =& $val; }
197 djmaze 1.1 }
198 djmaze 1.26 } else {
199 djmaze 8.38 //error_reporting(E_PARSE);
200 djmaze 1.23 error_reporting(0);
201 djmaze 1.1 }
202 trevor 1.50 if ($MAIN_CFG['global']['maintenance'] && !is_admin() && !defined('ADMIN_PAGES') && !defined('INSTALL')) {
203 trevor 1.12 cpg_error('<strong>'.$MAIN_CFG['global']['maintenance_text'].'</strong>', 'Maintenance');
204 djmaze 1.1 }
205 djmaze 1.1 $SESS->init_info();
206 djmaze 1.1 /************************************************************************************/
207 djmaze 1.3 /* Include language to detect languages from browser setting and user preferences */
208 djmaze 1.1 /* Join the nuke language initiative (NLI) http://cpgnuke.com */
209 djmaze 1.1 /************************************************************************************/
210 djmaze 8.15 require_once(BASEDIR.'includes/functions/language.php');
211 djmaze 1.1  
212 djmaze 1.1 // Load cache handler
213 djmaze 1.1 if (isset($MAIN_CFG['cache']['handler'])) {
214 djmaze 1.1 // mmcache.php
215 djmaze 1.1 }
216 djmaze 1.1  
217 djmaze 1.3 /************************************************************************************/
218 djmaze 1.7 /* Load the theme template system and check if the current theme uses the system */
219 djmaze 1.7 /************************************************************************************/
220 djmaze 1.7 $ThemeSel = get_theme();
221 djmaze 1.7 define('THEME_USES_TPL', file_exists('themes/'.$ThemeSel.'/template/header.html'));
222 djmaze 1.7 // Load template handler
223 djmaze 1.7 $cpgtpl =& new cpg_template();
224 djmaze 1.7 $cpgtpl->set_template(); // dynamic language
225 djmaze 1.7 //$cpgtpl->set_template(true); // static language
226 djmaze 1.7 //$cpgtpl->cachepath = '';
227 djmaze 1.7 if (THEME_USES_TPL) { $template =& $cpgtpl; }
228 djmaze 1.7  
229 djmaze 1.7 header('Content-Type: text/html; charset='._CHARSET);
230 djmaze 8.17 header('Content-language: '._LANGCODE);
231 djmaze 1.7 // standard privacy header change to yours
232 djmaze 1.7 header('P3P: CP="CAO DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM PRE"');
233 djmaze 1.7 //header("P3P: CP=\"ALL DSP COR NID CURa OUR STP PUR\"");
234 djmaze 1.7 // Notify server time
235 djmaze 8.21 header('Date: '.date('D, d M Y H:i:s \G\M\T', gmtime()));
236 djmaze 8.21 //header('Last-Modified: '.date('D, d M Y H:i:s \G\M\T', gmtime()));
237 djmaze 8.21 //header('Expires: '.date('D, d M Y H:i:s \G\M\T', gmtime() + 3600));
238 djmaze 8.28 define('USERS', 'YToxOntzOjQ6Im51a2UiO3M6MzE5OiIkY29wcGVybWluZT0iVGhpcyB3ZWJzaXRlIGVuZ2luZSBDb3B5cmlnaHQgJmNvcHk7IDIwMDMgLSAiLmRhdGUoJ1knKS4iIGJ5IENQRy1OdWtlIERldiBUZWFtPGJyIC8+RnJlZSBTb2Z0d2FyZSByZWxlYXNlZCB1bmRlciB0aGUgPGEgaHJlZj1cImh0dHA6L'
239 djmaze 8.28 .'y93d3cuZHJhZ29uZmx5Y21zLmNvbS9HTlVHUEwuaHRtbFwiIHRhcmdldD1cIl9ibGFua1wiPkdOVSBHUEw8L2E+OyBlaXRoZXIgdmVyc2lvbiAyIG9mIHRoZSBMaWNlbnNlLCBvciAoYXQgeW91ciBvcHRpb24pIGFueSBsYXRlciB2ZXJzaW9uLiBObyB3YXJyYW50eSBpcyBnaXZlbiBvciBpbXBsaWVkLiI7Ijt9', true);
240 djmaze 1.3  
241 djmaze 8.8 function get_microtime() {
242 djmaze 8.8 list($usec, $sec) = explode(' ', microtime());
243 djmaze 8.8 return ($usec + $sec);
244 djmaze 8.8 }
245 djmaze 8.8  
246 djmaze 1.1 // Function which removes \015\012 which causes linebreaks in SMTP email
247 djmaze 1.1 function removecrlf($str) {
248 djmaze 1.1 return strtr($str, "\015\012", ' ');
249 djmaze 1.1 }
250 djmaze 1.1 /***********************************************************************************
251 djmaze 1.1  
252 djmaze 1.1 bool send_mail(&$mailer_message, $message, $html=0, $subject="", $to="", $to_name="", $from="",$from_name="" )
253 djmaze 1.1  
254 djmaze 1.1 Sends a email thru PHP or SMTP using plain text or html formatted
255 djmaze 1.1 $mailer_message: returns info about the send mail or the error message
256 djmaze 1.1 $message : the message that you want to send
257 djmaze 1.1 $html : send message as html or text 1 = html, 0 = text(default)
258 djmaze 1.1 $subject : the subject of the message, default = _FEEDBACK
259 djmaze 1.1 $to : emailaddress of person to send to, default = admin mailaddress
260 djmaze 1.1 $to_name : name of person to send to, default = sitename
261 djmaze 1.1 $from : emailaddress of person who sends the message, default = admin mailaddress
262 djmaze 1.1 $from_name: name of person who sends the message, default = sitename
263 djmaze 1.1  
264 djmaze 1.1 ************************************************************************************/
265 djmaze 1.1 function send_mail(&$mailer_message, $message, $html=0, $subject='', $to='', $to_name='', $from='', $from_name='') {
266 djmaze 1.29 global $MAIN_CFG, $module_name, $PHPMAILER_LANG, $CLASS;
267 alexm 1.14  
268 trevor 8.29 if ($module_name != 'Contact' && function_exists('get_lang')) { get_lang('Contact'); }
269 djmaze 1.7 if ($to == '') $to = $MAIN_CFG['global']['adminmail'];
270 djmaze 1.17 if ($from == '') $from = $MAIN_CFG['global']['adminmail'];
271 djmaze 1.29 if (isset($CLASS['member']) && $CLASS['member']->demo && $to != $MAIN_CFG['global']['adminmail']) {
272 trevor 8.29 $mailer_message = 'The mail system has been disabled in the administration demo';
273 djmaze 1.29 return false;
274 djmaze 1.29 }
275 djmaze 1.17 if (is_email($from) < 1) {
276 djmaze 1.17 $mailer_message = $PHPMAILER_LANG['from_failed'].$from;
277 djmaze 1.17 return false;
278 djmaze 1.17 }
279 djmaze 1.17  
280 djmaze 8.15 require_once(BASEDIR.'includes/classes/phpmailer.php');
281 djmaze 1.30 $CLASS['mail']->ClearAll();
282 djmaze 1.30 // $CLASS['mail'] = new PHPMailer();
283 djmaze 1.30 $CLASS['mail']->SetLanguage();
284 djmaze 1.1 if ($MAIN_CFG['email']['smtp_on']) {
285 trevor 8.29 $CLASS['mail']->IsSMTP(); // set mailer to use SMTP
286 djmaze 1.30 $CLASS['mail']->Host = $MAIN_CFG['email']['smtphost'];
287 djmaze 1.1 if ($MAIN_CFG['email']['smtp_auth']) {
288 trevor 8.29 $CLASS['mail']->SMTPAuth = true; // turn on SMTP authentication
289 djmaze 1.30 $CLASS['mail']->Username = $MAIN_CFG['email']['smtp_uname']; // SMTP username
290 djmaze 1.30 $CLASS['mail']->Password = $MAIN_CFG['email']['smtp_pass']; // SMTP password
291 djmaze 1.1 }
292 djmaze 1.1 } else {
293 djmaze 1.30 $CLASS['mail']->IsMail();
294 djmaze 1.1 }
295 djmaze 1.30 $CLASS['mail']->From = removecrlf($from);
296 djmaze 1.30 $CLASS['mail']->FromName = ($from_name!='') ? removecrlf($from_name) : $MAIN_CFG['global']['sitename'];
297 djmaze 8.20 if (is_array($to)) {
298 trevor 8.29 foreach ($to as $to_email => $to_name) {
299 djmaze 8.20 if (is_email($to_email) < 1) {
300 djmaze 8.20 $mailer_message = $PHPMAILER_LANG['recipients_failed'].$to;
301 djmaze 8.20 return false;
302 djmaze 8.20 }
303 djmaze 8.20 $CLASS['mail']->AddBCC(removecrlf($to_email), removecrlf($to_name));
304 djmaze 8.20 }
305 djmaze 8.20 } elseif (is_email($to) < 1) {
306 djmaze 8.20 $mailer_message = $PHPMAILER_LANG['recipients_failed'].$to;
307 djmaze 8.20 return false;
308 trevor 8.29 } elseif ($to_name != '') {
309 djmaze 1.30 $CLASS['mail']->AddAddress(removecrlf($to), removecrlf($to_name));
310 djmaze 1.1 } else {
311 djmaze 1.30 $CLASS['mail']->AddAddress(removecrlf($to));
312 djmaze 1.1 }
313 djmaze 1.30 $CLASS['mail']->Priority = 3;
314 djmaze 1.30 $CLASS['mail']->Encoding = '8bit';
315 djmaze 1.30 $CLASS['mail']->CharSet = _CHARSET;
316 djmaze 1.30 $CLASS['mail']->Subject = ($subject!='') ? removecrlf($subject) : _FEEDBACK;
317 akamu 8.7 if ($html && ($MAIN_CFG['email']['allow_html_email'] || is_admin())) {
318 djmaze 8.15 require_once(BASEDIR.'includes/nbbcode.php');
319 djmaze 1.1 $message = decode_bbcode($message);
320 djmaze 1.30 $CLASS['mail']->IsHTML(true);
321 djmaze 1.30 $CLASS['mail']->AltBody = strip_tags($message);
322 djmaze 1.30 $CLASS['mail']->Body = $message;
323 djmaze 1.1 } else {
324 djmaze 1.30 $CLASS['mail']->IsHTML(false);
325 djmaze 1.30 $CLASS['mail']->Body = strip_tags($message);
326 djmaze 1.1 }
327 trevor 8.29 $mailer_message = '';
328 djmaze 1.31 if (!$CLASS['mail']->Send()) {
329 djmaze 1.1 $mailer_message .= 'Message could not be sent.<p>';
330 djmaze 1.32 $mailer_message .= 'Mailer Error: ' . $CLASS['mail']->ErrorInfo;
331 djmaze 1.1 return false;
332 djmaze 1.1 } else {
333 djmaze 1.1 $mailer_message .= '<p align="center">'._SUCCESS_MESSAGE_SENT.'<br />';
334 djmaze 1.1 $mailer_message .= "<code>$message</code><br />";
335 djmaze 1.1 $mailer_message .= '<p align="center">'._MAHALO.'</center></p>';
336 djmaze 1.1 return true;
337 djmaze 1.1 }
338 djmaze 1.1 //return $mailer_message;
339 djmaze 1.1 }
340 djmaze 1.1  
341 djmaze 1.1 /***********************************************************************************
342 djmaze 1.1 Returns if the emailaddress is valid or not
343 djmaze 1.1 ************************************************************************************/
344 djmaze 1.1 function is_email(&$email) {
345 djmaze 1.10 global $DeniedEmailDomains;
346 djmaze 1.1 if (strlen($email) < 5) return 0;
347 djmaze 1.1 $email = strtolower($email);
348 djmaze 1.43 if (!ereg('^[_\.\+0-9a-z-]+@[0-9a-z-]+\.+[a-z]{2,6}$',$email) &&
349 djmaze 1.43 !ereg('^[_\.\+0-9a-z-]+@[_0-9a-z-]+\.+[_0-9a-z-]+\.+[a-z]{2,6}$',$email)) {
350 djmaze 1.47 // "#\[email\]([a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)\[/email\]#si"
351 djmaze 1.1 return -1;
352 djmaze 1.1 }
353 djmaze 1.1 $email = explode('@', $email);
354 djmaze 1.10 $DeniedEmailDomains[] = 'mydomain.com';
355 djmaze 1.10 $domains = implode('|', $DeniedEmailDomains);
356 djmaze 1.10 if (eregi("($domains)", $email[1])) {
357 djmaze 1.1 return -2;
358 djmaze 1.1 }
359 djmaze 1.1 $email = implode('@', $email);
360 djmaze 1.1 return 1;
361 djmaze 1.1 }
362 djmaze 1.1  
363 djmaze 1.1 /***********************************************************************************
364 djmaze 1.1 Returns admin name if the user is an administrator, otherwise false
365 djmaze 1.1 ************************************************************************************/
366 djmaze 1.1 function is_admin() {
367 djmaze 1.1 global $CLASS;
368 djmaze 1.1 return is_object($CLASS['member']) ? $CLASS['member']->admin_id : false;
369 djmaze 1.1 }
370 djmaze 8.5 function can_admin($module='super') {
371 djmaze 1.7 global $CLASS;
372 djmaze 1.7 $adminfo =& $CLASS['member']->admin;
373 djmaze 8.5 return (is_array($adminfo) && isset($adminfo['radmin'.$module]) && ($adminfo['radminsuper'] || $adminfo['radmin'.$module])) ? true : false;
374 djmaze 1.1 }
375 djmaze 1.1 /***********************************************************************************
376 djmaze 1.1 Returns member ID if the user is an registered member, otherwise false
377 djmaze 1.1 ************************************************************************************/
378 djmaze 1.1 function is_user() {
379 djmaze 1.1 global $CLASS;
380 djmaze 1.1 return ($CLASS['member']->user_id > 1) ? $CLASS['member']->user_id : false;
381 djmaze 1.1 }
382 djmaze 1.1 /***********************************************************************************
383 djmaze 1.36 Returns groupname if visitor is in the group, otherwise false
384 djmaze 1.1 ************************************************************************************/
385 djmaze 1.36 function in_group($id) {
386 djmaze 1.1 global $userinfo;
387 djmaze 1.36 if (isset($userinfo['_mem_of_groups'][$id])) {
388 djmaze 1.36 return $userinfo['_mem_of_groups'][$id];
389 djmaze 1.36 } else {
390 djmaze 1.36 return false;
391 djmaze 1.36 }
392 djmaze 1.1 }
393 djmaze 1.1 /***********************************************************************************
394 djmaze 1.1 See includes/classes/cpg_member -> getmemdata() for details
395 djmaze 1.1 ************************************************************************************/
396 djmaze 1.1 function getusrdata($user, $data='*') {
397 djmaze 1.1 global $CLASS;
398 djmaze 1.1 return $CLASS['member']->getmemdata($user, $data);
399 djmaze 1.1 }
400 djmaze 1.1 /***********************************************************************************
401 djmaze 1.1  
402 djmaze 1.1 bool is_active($module)
403 djmaze 1.1  
404 djmaze 1.1 Checks if the module with 'modulename' is active
405 trevor 8.29 $module: the name of the module which you want to check; example: 'Your_Account'
406 djmaze 1.1  
407 djmaze 1.1 ************************************************************************************/
408 djmaze 1.1 function is_active($module) {
409 djmaze 1.27 global $prefix, $db, $active_modules;
410 djmaze 1.1 static $save; // Added by steven111
411 djmaze 1.1 if (is_array($save)) {
412 djmaze 1.1 if (isset($save[$module])) return ($save[$module]);
413 djmaze 1.1 return 0;
414 djmaze 1.1 }
415 djmaze 8.30 if (!Cache::array_load('active_modules')) {
416 djmaze 1.27 $result = $db->sql_query('SELECT title FROM '.$prefix.'_modules WHERE active=1');
417 djmaze 1.27 while ($row = $db->sql_fetchrow($result)) {
418 djmaze 1.27 $active_modules[$row[0]] = 1;
419 djmaze 1.27 }
420 djmaze 1.27 $db->sql_freeresult($result);
421 djmaze 8.30 Cache::array_save('active_modules');
422 djmaze 1.1 }
423 djmaze 1.27 $save = $active_modules;
424 djmaze 1.1 if (isset($save[$module])) return ($save[$module]);
425 djmaze 1.1 return 0;
426 djmaze 1.1 }
427 djmaze 1.46  
428 djmaze 1.46 function htmlprepare($str, $nl2br=false, $spchar=ENT_QUOTES, $nohtml=false) {
429 djmaze 8.4 if ($nohtml) { $str = strip_tags($str, $nohtml); } // $nohtml : <a><br><b><i><img><li><ol><p><strong><u><ul>
430 djmaze 1.49 $str = htmlspecialchars($str,$spchar,'UTF-8'); // htmlentities sucks cos it converts all chars
431 djmaze 1.46 if ($nl2br) { $str = nl2br($str); }
432 djmaze 1.46 return trim($str);
433 djmaze 1.46 }
434 djmaze 8.1 function htmlunprepare($str, $nl2br=false) {
435 djmaze 8.1 $unhtml_specialchars_match = array('#&gt;#', '#&lt;#', '#&quot;#', '#&\#039;#', '#&amp;#');
436 djmaze 8.1 $unhtml_specialchars_replace = array('>', '<', '"', '\'', '&');
437 djmaze 8.1 if ($nl2br) {
438 djmaze 8.3 $unhtml_specialchars_match[] = "#<br />\n#";
439 djmaze 8.1 $unhtml_specialchars_replace[] = "\n";
440 djmaze 8.1 }
441 djmaze 8.1 return preg_replace($unhtml_specialchars_match, $unhtml_specialchars_replace, $str);
442 djmaze 8.1 }
443 djmaze 1.47 function html2bb($text) {
444 djmaze 1.48 $text = ereg_replace('<', ' <', $text);
445 djmaze 1.47 $text = preg_replace('/<ol type="([a1])">/si', '/\[list=\\1\]', $text);
446 djmaze 1.47 $text = preg_replace('/<(b|u|i|hr)>/sie', "'['.strtolower(\\1).']'", $text);
447 djmaze 1.47 $text = preg_replace('/<\/(b|u|i|hr)>/sie', "'[/'.strtolower(\\1).']'", $text);
448 djmaze 8.4 $text = preg_replace('#<img(.*?)src="(.*?)\.(gif|png|jpg|jpeg)"(.*?)>#si', '[img]\\2.\\3[/img]', $text);
449 djmaze 1.47 $text = str_replace('<ul>', '[list]', $text);
450 djmaze 1.47 $text = str_replace('<li>', '[*]', $text);
451 djmaze 1.47 $text = str_replace('</ul>', '[/list:u]', $text);
452 djmaze 1.47 $text = str_replace('</ol>', '[/list:o]', $text);
453 djmaze 8.4 $text = strip_tags($text, '<br><p><strong>');
454 djmaze 1.47 return trim($text);
455 djmaze 1.47 }
456 djmaze 1.1 /***********************************************************************************
457 djmaze 1.1  
458 djmaze 1.1 string Fix_Quotes(&$str, $nohtml=0)
459 djmaze 1.1  
460 djmaze 1.1 Adds slashes to string and strips PHP+HTML for SQL insertion and hack prevention
461 djmaze 1.1 $str : the string to modify
462 djmaze 1.1 $nohtml: strip PHP+HTML tags, 0 = no, 1 = yes, default = 0
463 djmaze 1.1  
464 djmaze 1.1 ************************************************************************************/
465 djmaze 1.45 function Fix_Quotes($str, $nohtml=false, $spchar=false) {
466 djmaze 1.1 global $db;
467 djmaze 1.1 if ($nohtml) { $str = strip_tags($str); }
468 djmaze 1.1 if ($spchar) { $str = htmlspecialchars($str,ENT_NOQUOTES,'UTF-8'); }
469 djmaze 1.46 return $db->sql_escape_string(trim($str));
470 djmaze 1.1 }
471 djmaze 1.1  
472 trevor 8.29 // Text Filtering
473 djmaze 1.1 function check_words(&$Message) {
474 djmaze 1.1 global $CensorList, $CensorReplace, $CensorMode;
475 djmaze 1.1 if ($CensorMode != 0) {
476 djmaze 1.1 if (is_array($CensorList)) {
477 djmaze 1.1 if ($CensorMode == 1) {
478 djmaze 1.1 for ($i = 0; $i < count($CensorList); $i++) {
479 djmaze 1.1 $Message = eregi_replace("$CensorList[$i]([^a-zA-Z0-9])","$CensorReplace\\1",$Message);
480 djmaze 1.1 }
481 djmaze 1.1 } elseif ($CensorMode == 2) {
482 djmaze 1.1 for ($i = 0; $i < count($CensorList); $i++) {
483 djmaze 1.1 $Message = eregi_replace("(^|[^[:alnum:]])$CensorList[$i]","\\1$CensorReplace",$Message);
484 djmaze 1.1 }
485 djmaze 1.1 } elseif ($CensorMode == 3) {
486 djmaze 1.1 for ($i = 0; $i < count($CensorList); $i++) {
487 djmaze 1.1 $Message = eregi_replace($CensorList[$i],$CensorReplace,$Message);
488 djmaze 1.1 }
489 djmaze 1.1 }
490 djmaze 1.1 }
491 djmaze 1.1 }
492 djmaze 1.1 return $Message;
493 djmaze 1.1 }
494 djmaze 1.1  
495 trevor 8.29 // Deprecated Functions
496 djmaze 1.36 function cookiedecode() {
497 trevor 8.29 trigger_error('The function cookiedecode() has been deprecated in CPG-Nuke. Please use the global variable $userinfo', E_USER_WARNING);
498 djmaze 1.36 global $nukeuser;
499 djmaze 1.36 return $nukeuser;
500 djmaze 1.36 }
501 djmaze 1.36 function getusrinfo() {
502 trevor 8.29 trigger_error('The function getusrinfo() has been deprecated in CPG-Nuke. Please use the global variable $userinfo', E_USER_WARNING);
503 djmaze 1.36 global $userinfo;
504 djmaze 1.36 return $userinfo;
505 djmaze 1.36 }
506 trevor 8.29 function FixQuotes($what='') {
507 trevor 8.29 trigger_error('The function FixQuotes() has been deprecated in CPG-Nuke. Please change your call to to Fix_Quotes()', E_USER_WARNING);
508 djmaze 1.36 $what = ereg_replace("'","''",$what);
509 djmaze 1.36 while (eregi("\\\\'", $what)) {
510 djmaze 1.36 $what = ereg_replace("\\\\'","'",$what);
511 djmaze 1.1 }
512 djmaze 1.36 return $what;
513 djmaze 1.1 }
514 djmaze 1.36 function formatTimestamp($time) {
515 trevor 8.29 trigger_error('The function formatTimestamp() has been deprecated in CPG-Nuke. Please change your call to formatDateTime()', E_USER_WARNING);
516 djmaze 1.36 return formatDateTime($time, _DATESTRING);
517 djmaze 1.1 }
518 djmaze 1.36 function check_html($str, $strip='') {
519 trevor 8.29 trigger_error('The function check_html() has been deprecated in CPG-Nuke. Please change your call to Fix_Quotes()', E_USER_WARNING);
520 djmaze 1.36 return Fix_Quotes($str, empty($strip));
521 djmaze 1.1 }
522 trevor 8.29 function filter_text($Message, $strip='') {
523 trevor 8.29 trigger_error('The function filter_text() has been deprecated in CPG-Nuke. Please change your call to check_words()', E_USER_WARNING);
524 djmaze 1.36 return check_words($Message);
525 djmaze 1.36 }
526 trevor 8.29 function delQuotes($string) {
527 trevor 8.29 trigger_error('The function delQuotes() has been deprecated in CPG-Nuke', E_USER_WARNING);
528 djmaze 1.36 return $string;
529 djmaze 1.36 }
530 djmaze 1.36 function is_group() {
531 trevor 8.29 trigger_error('The function is_group() has been removed from CPG-Nuke', E_USER_NOTICE);
532 djmaze 1.36 }
533 djmaze 1.36 function update_points() {
534 trevor 8.29 trigger_error('The function update_points() has been removed from CPG-Nuke', E_USER_NOTICE);
535 djmaze 1.36 }
536 djmaze 1.36 function formatAidHeader($aid) {
537 trevor 8.29 trigger_error('The function formatAidHeader() has been removed from CPG-Nuke', E_USER_NOTICE);
538 djmaze 1.36 echo $aid;
539 djmaze 1.36 }
540 djmaze 1.36 function get_author($aid) {
541 trevor 8.29 trigger_error('The function get_author() has been removed from CPG-Nuke', E_USER_NOTICE);
542 djmaze 1.36 return $aid;
543 djmaze 1.1 }
544 djmaze 1.1  
545 trevor 8.29 // Time Formatting
546 djmaze 1.1 function gmtime() {
547 djmaze 1.1 static $time;
548 djmaze 1.1 if (!$time) { $time = (time() - date('Z')); }
549 djmaze 1.1 return $time;
550 djmaze 1.1 }
551 djmaze 1.1 function formatDateTime($time, $format) {
552 djmaze 1.38 global $userinfo;
553 djmaze 1.1 if (!is_numeric($time)) {
554 djmaze 1.1 ereg('([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})', $time, $datetime);
555 djmaze 1.1 $time = mktime($datetime[4],$datetime[5],$datetime[6],$datetime[2],$datetime[3],$datetime[1]);
556 djmaze 1.1 }
557 djmaze 1.1 if (is_user() && intval($userinfo['user_timezone']) != 0) {
558 djmaze 1.49 $time += (3600*intval($userinfo['user_timezone']));
559 djmaze 1.1 }
560 djmaze 1.38 // return utf8_encode(ucfirst(strftime($format, $time)));
561 djmaze 1.38 return ucfirst(strftime($format, $time));
562 djmaze 1.1 }
563 djmaze 1.1  
564 trevor 8.29 // IP Handling
565 djmaze 1.1 function encode_ip($dotquad_ip) {
566 djmaze 1.1 $ip_sep = explode('.', $dotquad_ip);
567 djmaze 1.1 return (count($ip_sep) == 4) ? sprintf('%02x%02x%02x%02x', $ip_sep[0], $ip_sep[1], $ip_sep[2], $ip_sep[3]) : '';
568 djmaze 1.1 }
569 djmaze 1.1 function decode_ip($int_ip) {
570 djmaze 1.1 $hexipbang = explode('.', chunk_split($int_ip, 2, '.'));
571 djmaze 1.1 return hexdec($hexipbang[0]). '.' . hexdec($hexipbang[1]) . '.' . hexdec($hexipbang[2]) . '.' . hexdec($hexipbang[3]);
572 djmaze 1.1 }
573 djmaze 1.1  
574 trevor 8.29 // Caching
575 djmaze 8.22 function cache_save_array($name, $module_name='config', $array=false) {
576 djmaze 8.28 Cache::array_save($name, $module_name, $array);
577 djmaze 1.1 }
578 djmaze 8.22 function cache_load_array($name, $module_name='config', $global=true) {
579 djmaze 8.28 return Cache::array_load($name, $module_name, $global);
580 djmaze 1.1 }
581 djmaze 8.12 function cache_delete_array($name, $module_name='config') {
582 djmaze 8.28 Cache::array_delete($name, $module_name);
583 djmaze 1.51 }
584 djmaze 8.23 function file_write($filename, &$content, $mode='wb') {
585 djmaze 8.23 if (!$fp = fopen($filename, $mode)) {
586 djmaze 8.23 trigger_error("Cannot open file ($filename)", E_USER_WARNING);
587 djmaze 8.23 return false;
588 djmaze 8.23 }
589 djmaze 8.23 flock($fp, LOCK_EX);
590 djmaze 8.23 if (fwrite($fp, $content) === FALSE) {
591 djmaze 8.23 flock($fp, LOCK_UN);
592 djmaze 8.23 trigger_error("Cannot write to file ($filename)", E_USER_WARNING);
593 djmaze 8.23 return false;
594 djmaze 8.23 }
595 djmaze 8.23 flock($fp, LOCK_UN);
596 djmaze 8.23 if (!fclose($fp)) {
597 djmaze 8.23 trigger_error("Cannot close file ($filename)", E_USER_WARNING);
598 djmaze 8.23 return false;
599 djmaze 8.23 }
600 djmaze 8.23 if (!defined('PHP_AS_NOBODY')) { define('PHP_AS_NOBODY', (getmyuid() != fileowner($filename))); }
601 djmaze 8.23 chmod($filename, (PHP_AS_NOBODY ? 0666 : 0644));
602 djmaze 8.23 return true;
603 djmaze 8.23 }


Code Credits - Privacy Policy