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.24 (9 years 2 months 2 days 7 hours 27 minutes 23 seconds ago) by djmaze
Changed : +8 -2 lines
Comment: Added a debug trace for the session data


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


Code Credits - Privacy Policy