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 : 1.15 (9 years 7 months 1 weeks 4 minutes ago) by djmaze
Changed : +3 -3 lines
Comment: Fixed nukeurl processing


# 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 1.1 of the GNU General Public License Version 2
10 djmaze 1.1  
11 djmaze 1.1 Last modification notes:
12 djmaze 1.1  
13 djmaze 1.15 $Id: cmsinit.inc,v 1.14 2004/09/10 13:48:38 alexm Exp $
14 djmaze 1.1  
15 djmaze 1.1 *************************************************************/
16 djmaze 1.1 set_magic_quotes_runtime(0); // Disable magic_quotes_runtime
17 djmaze 1.1  
18 djmaze 1.1 // Disable DOS Attacks
19 djmaze 1.1 if (($_SERVER['HTTP_USER_AGENT'] == '' || $_SERVER['HTTP_USER_AGENT'] == '-') && !defined('XMLFEED')) {
20 djmaze 1.1 exit;
21 djmaze 1.1 }
22 djmaze 1.1  
23 djmaze 1.1 // Compress output if server/php config allows
24 djmaze 1.1 $do_gzip_compress = false;
25 djmaze 1.1 $do_zlib_compress = false;
26 djmaze 1.1 $phpver = explode('.', phpversion());
27 djmaze 1.1 $phpver = "$phpver[0]$phpver[1]";
28 djmaze 1.1  
29 djmaze 1.1 if (extension_loaded('zlib')) {
30 djmaze 1.1 if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && eregi('gzip', $_SERVER['HTTP_ACCEPT_ENCODING'])) {
31 djmaze 1.1 if ($phpver >= 43) { // PHP 4.2.x seems to give memleak
32 djmaze 1.1 ob_start('ob_gzhandler');
33 djmaze 1.1 }
34 djmaze 1.1 else if ($phpver > 40) {
35 djmaze 1.1 $do_gzip_compress = true;
36 djmaze 1.1 ob_start();
37 djmaze 1.1 ob_implicit_flush(0);
38 djmaze 1.1 header('Content-Encoding: gzip');
39 djmaze 1.1 }
40 djmaze 1.1 } else {
41 djmaze 1.1 // Some stupid firewalls don't send the HTTP_ACCEPT_ENCODING
42 djmaze 1.1 // So we still compress in memory for fast page generations
43 djmaze 1.1 // But it will take longer for the visitor to see the page.
44 djmaze 1.1 $do_zlib_compress = true;
45 djmaze 1.1 ob_start();
46 djmaze 1.1 ob_implicit_flush(0);
47 djmaze 1.1 }
48 djmaze 1.1 }
49 djmaze 1.1  
50 djmaze 1.1 if ($phpver >= 41) {
51 djmaze 1.1 $PHP_SELF = $_SERVER['PHP_SELF'];
52 djmaze 1.1 }
53 djmaze 1.1 // Import GET/POST/Cookie variables into the global scope
54 djmaze 1.1 //if (!ini_get("register_globals")) {
55 djmaze 1.1 $r_globals = intval(ini_get('register_globals'));
56 djmaze 1.1 if ($r_globals == 0) {
57 djmaze 1.1 import_request_variables('GPC');
58 djmaze 1.1 }
59 djmaze 1.1 error_reporting(E_ALL);
60 djmaze 1.1 // unset any vars set from globals
61 djmaze 1.1 $phpEx = 'php';
62 djmaze 1.7 $modheader = $adminmenuitems = $adminmail = '';
63 djmaze 1.1 $showblocks = 1;
64 djmaze 1.1 // useless vars but still here to prevent "notice" messages
65 djmaze 1.1 $user = $admin = $cookie = '';
66 djmaze 1.1  
67 djmaze 1.1 if (!isset($file)) $file = NULL;
68 djmaze 1.1 if (!isset($name)) $name = NULL;
69 djmaze 1.1  
70 djmaze 1.1 list($usec, $sec) = explode(' ', microtime());
71 djmaze 1.1 $start_time = ($usec + $sec);
72 djmaze 1.1 if (!defined('CPG_NUKE')) define('CPG_NUKE', true);
73 djmaze 1.1  
74 trevor 1.8 // stops the page creation and shows an error page
75 djmaze 1.1 function nuke_error($message, $title='ERROR', $redirect='') {
76 djmaze 1.1 cpg_error($message, $title, $redirect);
77 djmaze 1.1 }
78 djmaze 1.1 function cpg_error($message, $title='ERROR', $redirect='') {
79 djmaze 1.1 global $userinfo, $SESS;
80 djmaze 1.1 if ($redirect) { header('Refresh: 3; url='.$redirect); }
81 djmaze 1.1 if (defined('THEME_USES_TPL')) {
82 djmaze 1.1 global $pagetitle, $showblocks, $home;
83 djmaze 1.1 $home = $showblocks = 0;
84 djmaze 1.1 $pagetitle = $title;
85 djmaze 1.1 require_once('header.php');
86 djmaze 1.1 OpenTable();
87 djmaze 1.1 echo '<center>'.$message.'<br /><br />'._GOBACK.'</center>';
88 djmaze 1.1 CloseTable();
89 djmaze 1.1 require_once('footer.php');
90 djmaze 1.1 } else {
91 djmaze 1.1 require_once('includes/cpg_page.php');
92 djmaze 1.1 $errorpage = cpg_header($title);
93 djmaze 1.1 $errorpage .= "<center>$message</center>";
94 djmaze 1.1 $errorpage .= cpg_footer();
95 djmaze 1.1 if (isset($SESS)) $SESS->write_close();
96 djmaze 1.1 die($errorpage);
97 djmaze 1.1 }
98 djmaze 1.1 }
99 djmaze 1.1  
100 djmaze 1.1 // include database connection, sql abstraction layer and globally used functions
101 djmaze 1.1 require_once('config.php');
102 djmaze 1.1 if (!CPG_DEBUG && !defined('INSTALL')) { error_reporting(E_ALL ^ E_NOTICE); }
103 djmaze 1.1 require_once('db/db.php');
104 djmaze 1.1 require_once('includes/classes/session.php');
105 djmaze 1.1 require_once('includes/functions/display.php');
106 djmaze 1.1 require_once('includes/functions/linking.php');
107 djmaze 1.1 require_once('includes/classes/template.php');
108 djmaze 1.1 require_once('includes/classes/cpg_member.php');
109 djmaze 1.1 if (defined('INSTALL')) return;
110 djmaze 1.1  
111 djmaze 1.1 if ($file != 'posting' && $name != 'Forums') {
112 djmaze 1.1 foreach ($_POST as $secvalue) {
113 djmaze 1.1 if (eregi("<[^>]*script *\"?[^>]*>", $secvalue)) {
114 trevor 1.13 cpg_error('<strong>The characters that you tried to include in your html request are forbidden...</strong>', 'Security Error');
115 djmaze 1.1 }
116 djmaze 1.1 }
117 djmaze 1.1 }
118 djmaze 1.1  
119 djmaze 1.4 if (!load_cfg('MAIN_CFG')) {
120 djmaze 1.1 if (!($result = $db->sql_query('SELECT * FROM '.$prefix.'_config_custom', true))) {
121 djmaze 1.1 url_redirect('install.php');
122 djmaze 1.1 }
123 djmaze 1.1 while ($row = $db->sql_fetchrow($result)) {
124 djmaze 1.1 $MAIN_CFG[$row['cfg_name']][$row['cfg_field']] = $row['cfg_value'];
125 djmaze 1.1 }
126 djmaze 1.1 save_cfg('MAIN_CFG');
127 djmaze 1.1 $db->sql_freeresult($result);
128 djmaze 1.4 }
129 djmaze 1.5 if (!extension_loaded('gd')) { $MAIN_CFG['global']['gfx_chk'] = 0; }
130 djmaze 1.15 if (substr($MAIN_CFG['global']['nukeurl'], -1) == '/') { $MAIN_CFG['global']['nukeurl'] = substr($MAIN_CFG['global']['nukeurl'], 0, -1); }
131 djmaze 1.5 if (substr($MAIN_CFG['server']['path'], -1) != '/') $MAIN_CFG['server']['path'] .= '/';
132 djmaze 1.5 if ($MAIN_CFG['server']['path'][0] != '/') $MAIN_CFG['server']['path'] = '/'.$MAIN_CFG['server']['path'];
133 djmaze 1.5  
134 djmaze 1.1 if ($phpver >= 43) { // version_compare()
135 djmaze 1.1 extract($MAIN_CFG['global'], EXTR_OVERWRITE | EXTR_REFS);
136 djmaze 1.1 } else {
137 djmaze 1.1 extract($MAIN_CFG['global'], EXTR_OVERWRITE);
138 djmaze 1.1 }
139 djmaze 1.1  
140 djmaze 1.1 if (defined('XMLFEED')) return; // no need to load everything if it's a feed
141 djmaze 1.1  
142 djmaze 1.6 global $CPG_SESS;
143 djmaze 1.6 $SESS =& new cpg_session();
144 djmaze 1.1 if (isset($_GET['name']) && ($_GET['name'] == 'gfx' || (isset($_GET['op']) && $_GET['name'] == 'Your_Account' && $_GET['op'] == 'gfx')) && isset($random_num)) {
145 djmaze 1.1 require('includes/gfxchk.php');
146 djmaze 1.1 }
147 djmaze 1.1 //$SESS = new cpg_session($dbonly, $name, $time);
148 djmaze 1.1 //register_shutdown_function(array(&$SESS, "write_close"));
149 djmaze 1.1 $CLASS['member'] =& new cpg_member($MAIN_CFG['cookie']['member']);
150 djmaze 1.1 $userinfo =& $CLASS['member']->members[$CLASS['member']->user_id];
151 djmaze 1.1 $nukeuser =& $CLASS['member']->cookie;
152 djmaze 1.1 if ($CLASS['member']->loadadmin($MAIN_CFG['cookie']['admin'])) {
153 djmaze 1.1 foreach($CLASS['member']->admin as $var => $val) {
154 djmaze 1.4 if (ereg('radmin',$var)) { $$var =& $val; }
155 djmaze 1.1 }
156 djmaze 1.1 }
157 djmaze 1.1 if (($MAIN_CFG['global']['maintenance']==1) && !is_admin() && !defined('ADMIN_PAGES') && !defined('INSTALL')) {
158 trevor 1.12 cpg_error('<strong>'.$MAIN_CFG['global']['maintenance_text'].'</strong>', 'Maintenance');
159 djmaze 1.1 }
160 djmaze 1.1 $SESS->init_info();
161 djmaze 1.1 /************************************************************************************/
162 djmaze 1.3 /* Include language to detect languages from browser setting and user preferences */
163 djmaze 1.1 /* Join the nuke language initiative (NLI) http://cpgnuke.com */
164 djmaze 1.1 /************************************************************************************/
165 djmaze 1.1 require_once('includes/functions/language.php');
166 djmaze 1.1  
167 djmaze 1.1 // Load cache handler
168 djmaze 1.1 if (isset($MAIN_CFG['cache']['handler'])) {
169 djmaze 1.1 // mmcache.php
170 djmaze 1.1 }
171 djmaze 1.1  
172 djmaze 1.3 /************************************************************************************/
173 djmaze 1.7 /* Load the theme template system and check if the current theme uses the system */
174 djmaze 1.7 /************************************************************************************/
175 djmaze 1.7 $ThemeSel = get_theme();
176 djmaze 1.7 define('THEME_USES_TPL', file_exists('themes/'.$ThemeSel.'/template/header.html'));
177 djmaze 1.7 // Load template handler
178 djmaze 1.7 $cpgtpl =& new cpg_template();
179 djmaze 1.7 $cpgtpl->set_template(); // dynamic language
180 djmaze 1.7 //$cpgtpl->set_template(true); // static language
181 djmaze 1.7 //$cpgtpl->cachepath = '';
182 djmaze 1.7 if (THEME_USES_TPL) { $template =& $cpgtpl; }
183 djmaze 1.7  
184 djmaze 1.7 header('Content-Type: text/html; charset='._CHARSET);
185 djmaze 1.7 header('Content-language: ' . get_langcode($currentlang, 1));
186 djmaze 1.7 // standard privacy header change to yours
187 djmaze 1.7 header('P3P: CP="CAO DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM PRE"');
188 djmaze 1.7 //header("P3P: CP=\"ALL DSP COR NID CURa OUR STP PUR\"");
189 djmaze 1.7 // Notify server time
190 djmaze 1.7 header('Date: '.date('D, d M Y H:i:s', gmtime()).' GMT');
191 djmaze 1.7  
192 djmaze 1.7 ini_set('sendmail_from', $adminmail);
193 djmaze 1.7  
194 djmaze 1.7 /************************************************************************************/
195 djmaze 1.3 /* Check if the <form> POST is comming from this server */
196 djmaze 1.3 /************************************************************************************/
197 djmaze 1.3 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
198 djmaze 1.9 // if (isset($_SERVER['HTTP_REFERER'])) {
199 djmaze 1.3 if (!isset($CPG_SESS['user']['uri']) || empty($CPG_SESS['user']['uri'])) {
200 djmaze 1.3 // if (!ereg("(http://$_SERVER[HTTP_HOST])", $_SERVER['HTTP_REFERER']) && !ereg("(https://$_SERVER[HTTP_HOST])", $_SERVER['HTTP_REFERER'])&& !ereg("(http://www.$_SERVER[HTTP_HOST])", $_SERVER['HTTP_REFERER'])) {
201 djmaze 1.3 $errorpage = '<html><body><center><h1>ERROR</h1>';
202 djmaze 1.3 $the_error = "Someone with IP $_SERVER[REMOTE_ADDR]<br />\n"
203 djmaze 1.3 ."tried to send information thru a POST from the following url: $_SERVER[HTTP_REFERER]<br />\n<br />\n"
204 djmaze 1.3 ."The website he tried it on is: $_SERVER[HTTP_HOST]<br />\n"
205 djmaze 1.3 ."And to the following page: $_SERVER[REQUEST_URI]<br />";
206 djmaze 1.3 $the_error = $errorpage . '<form><textarea rows="8" cols="60">' . htmlspecialchars($the_error) . '</textarea></form></body></html>';
207 djmaze 1.3 if (is_admin()) {
208 djmaze 1.3 die($the_error);
209 djmaze 1.7 } else if (isset($adminmail) && $adminmail != '') {
210 djmaze 1.3 $subject = "POST Error on $sitename";
211 djmaze 1.3 if(!send_mail($mailer_message,$the_error, 1, $subject)) {
212 djmaze 1.3 echo $mailer_message;
213 djmaze 1.3 }
214 djmaze 1.3 }
215 djmaze 1.3 die('Posting from another server not allowed!');
216 djmaze 1.3 }
217 djmaze 1.9 // }
218 djmaze 1.3 /* problems when using some firewalls and proxy servers
219 djmaze 1.3 else {
220 djmaze 1.3 die("Warning you didn't send the HTTP_REFERER header to this website.
221 djmaze 1.3 This can be caused due to your browser, using a proxy server or firewall.
222 djmaze 1.3 Please change browser or turn off the use of a proxy or turn off the \"Deny servers to trace web browsing\" in your firewall
223 djmaze 1.3 and you shouldn't have problems when sending a POST on this website.");
224 djmaze 1.3 }*/
225 djmaze 1.3 }
226 djmaze 1.3  
227 djmaze 1.1 // Function which removes \015\012 which causes linebreaks in SMTP email
228 djmaze 1.1 function removecrlf($str) {
229 djmaze 1.1 return strtr($str, "\015\012", ' ');
230 djmaze 1.1 }
231 djmaze 1.1 /***********************************************************************************
232 djmaze 1.1  
233 djmaze 1.1 bool send_mail(&$mailer_message, $message, $html=0, $subject="", $to="", $to_name="", $from="",$from_name="" )
234 djmaze 1.1  
235 djmaze 1.1 Sends a email thru PHP or SMTP using plain text or html formatted
236 djmaze 1.1 $mailer_message: returns info about the send mail or the error message
237 djmaze 1.1 $message : the message that you want to send
238 djmaze 1.1 $html : send message as html or text 1 = html, 0 = text(default)
239 djmaze 1.1 $subject : the subject of the message, default = _FEEDBACK
240 djmaze 1.1 $to : emailaddress of person to send to, default = admin mailaddress
241 djmaze 1.1 $to_name : name of person to send to, default = sitename
242 djmaze 1.1 $from : emailaddress of person who sends the message, default = admin mailaddress
243 djmaze 1.1 $from_name: name of person who sends the message, default = sitename
244 djmaze 1.1  
245 djmaze 1.1 ************************************************************************************/
246 djmaze 1.1 function send_mail(&$mailer_message, $message, $html=0, $subject='', $to='', $to_name='', $from='', $from_name='') {
247 alexm 1.14 global $MAIN_CFG, $module_name;
248 alexm 1.14  
249 djmaze 1.1 if ($module_name != 'Contact' && function_exists('get_lang')) {
250 djmaze 1.1 get_lang('Contact');
251 djmaze 1.1 }
252 djmaze 1.7 if ($to == '') $to = $MAIN_CFG['global']['adminmail'];
253 djmaze 1.1 require_once('includes/classes/phpmailer.php');
254 djmaze 1.1 $mail = new PHPMailer();
255 djmaze 1.1 $mail->SetLanguage();
256 djmaze 1.1 if ($MAIN_CFG['email']['smtp_on']) {
257 djmaze 1.1 $mail->IsSMTP(); // set mailer to use SMTP
258 djmaze 1.1 $mail->Host = $MAIN_CFG['email']['smtphost'];
259 djmaze 1.1 if ($MAIN_CFG['email']['smtp_auth']) {
260 djmaze 1.1 $mail->SMTPAuth = true; // turn on SMTP authentication
261 djmaze 1.1 $mail->Username = $MAIN_CFG['email']['smtp_uname']; // SMTP username
262 djmaze 1.1 $mail->Password = $MAIN_CFG['email']['smtp_pass']; // SMTP password
263 djmaze 1.1 }
264 djmaze 1.1 } else {
265 djmaze 1.1 $mail->IsMail();
266 djmaze 1.1 }
267 djmaze 1.7 $mail->From = ($from!='') ? removecrlf($from) : $MAIN_CFG['global']['adminmail'];
268 djmaze 1.7 $mail->FromName = ($from_name!='') ? removecrlf($from_name) : $MAIN_CFG['global']['sitename'];
269 djmaze 1.1 if ($to_name != ''){
270 djmaze 1.1 $mail->AddAddress(removecrlf($to), removecrlf($to_name));
271 djmaze 1.1 } else {
272 djmaze 1.1 $mail->AddAddress(removecrlf($to));
273 djmaze 1.1 }
274 djmaze 1.1 $mail->Priority = 3;
275 djmaze 1.1 $mail->Encoding = '8bit';
276 djmaze 1.1 $mail->CharSet = _CHARSET;
277 djmaze 1.1 $mail->Subject = ($subject!='') ? removecrlf($subject) : _FEEDBACK;
278 djmaze 1.1 if ($MAIN_CFG['email']['allow_html_email'] && $html) {
279 djmaze 1.1 require_once('includes/nbbcode.php');
280 djmaze 1.1 $message = decode_bbcode($message);
281 djmaze 1.1 $mail->IsHTML(true);
282 djmaze 1.1 $mail->AltBody = strip_tags($message);
283 djmaze 1.1 $mail->Body = $message;
284 djmaze 1.1 } else {
285 djmaze 1.1 $mail->Body = strip_tags($message);
286 djmaze 1.1 }
287 djmaze 1.1 $mailer_message ='';
288 djmaze 1.1 if (!$mail->Send()) {
289 djmaze 1.1 $mailer_message .= 'Message could not be sent.<p>';
290 djmaze 1.1 $mailer_message .= 'Mailer Error: ' . $mail->ErrorInfo;
291 djmaze 1.1 return false;
292 djmaze 1.1 } else {
293 djmaze 1.1 $mailer_message .= '<p align="center">'._SUCCESS_MESSAGE_SENT.'<br />';
294 djmaze 1.1 $mailer_message .= "<code>$message</code><br />";
295 djmaze 1.1 $mailer_message .= '<p align="center">'._MAHALO.'</center></p>';
296 djmaze 1.1 return true;
297 djmaze 1.1 }
298 djmaze 1.1 //return $mailer_message;
299 djmaze 1.1 }
300 djmaze 1.1  
301 djmaze 1.1 /***********************************************************************************
302 djmaze 1.1 Returns if the emailaddress is valid or not
303 djmaze 1.1 ************************************************************************************/
304 djmaze 1.1 function is_email(&$email) {
305 djmaze 1.10 global $DeniedEmailDomains;
306 djmaze 1.1 if (strlen($email) < 5) return 0;
307 djmaze 1.1 $email = strtolower($email);
308 djmaze 1.1 if (!ereg('^[_\.\+0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,6}$',$email)) {
309 djmaze 1.1 return -1;
310 djmaze 1.1 }
311 djmaze 1.1 $email = explode('@', $email);
312 djmaze 1.10 $DeniedEmailDomains[] = 'mydomain.com';
313 djmaze 1.10 $domains = implode('|', $DeniedEmailDomains);
314 djmaze 1.10 if (eregi("($domains)", $email[1])) {
315 djmaze 1.1 return -2;
316 djmaze 1.1 }
317 djmaze 1.1 $email = implode('@', $email);
318 djmaze 1.1 return 1;
319 djmaze 1.1 }
320 djmaze 1.1  
321 djmaze 1.1 /***********************************************************************************
322 djmaze 1.1 Returns admin name if the user is an administrator, otherwise false
323 djmaze 1.1 ************************************************************************************/
324 djmaze 1.1 function is_admin() {
325 djmaze 1.1 global $CLASS;
326 djmaze 1.1 return is_object($CLASS['member']) ? $CLASS['member']->admin_id : false;
327 djmaze 1.1 }
328 djmaze 1.1 function can_admin($module='') {
329 djmaze 1.7 global $CLASS;
330 djmaze 1.7 $adminfo =& $CLASS['member']->admin;
331 djmaze 1.1 return is_array($adminfo) ? ($adminfo['radminsuper'] || (isset($adminfo['radmin'.$module]) ? $adminfo['radmin'.$module] : false)) : false;
332 djmaze 1.1 }
333 djmaze 1.1 /***********************************************************************************
334 djmaze 1.1 Returns member ID if the user is an registered member, otherwise false
335 djmaze 1.1 ************************************************************************************/
336 djmaze 1.1 function is_user() {
337 djmaze 1.1 global $CLASS;
338 djmaze 1.1 return ($CLASS['member']->user_id > 1) ? $CLASS['member']->user_id : false;
339 djmaze 1.1 }
340 djmaze 1.1 function is_group() {
341 djmaze 1.1 // Function does not exist; here for compatibility with PHP-Nuke 7 modules
342 djmaze 1.1 }
343 djmaze 1.1 function update_points() {
344 djmaze 1.1 // Function does not exist; here for compatibility with PHP-Nuke 7 modules
345 djmaze 1.1 }
346 djmaze 1.1 /***********************************************************************************
347 djmaze 1.1 Useless unless you don't want to convert PHP-Nuke modules
348 djmaze 1.1 NOT RECOMENDED to use, the global $nukeuser already contains all the info
349 djmaze 1.1 ************************************************************************************/
350 djmaze 1.1 function cookiedecode() {
351 djmaze 1.1 global $nukeuser;
352 djmaze 1.1 return $nukeuser;
353 djmaze 1.1 }
354 djmaze 1.1 /***********************************************************************************
355 djmaze 1.1 Useless unless you don't want to convert PHP-Nuke modules
356 djmaze 1.1 NOT RECOMENDED to use, the global $userinfo already contains all the info
357 djmaze 1.1 ************************************************************************************/
358 djmaze 1.1 function getusrinfo() {
359 djmaze 1.1 global $userinfo;
360 djmaze 1.1 return $userinfo;
361 djmaze 1.1 }
362 djmaze 1.1 /***********************************************************************************
363 djmaze 1.1 See includes/classes/cpg_member -> getmemdata() for details
364 djmaze 1.1 ************************************************************************************/
365 djmaze 1.1 function getusrdata($user, $data='*') {
366 djmaze 1.1 global $CLASS;
367 djmaze 1.1 return $CLASS['member']->getmemdata($user, $data);
368 djmaze 1.1 }
369 djmaze 1.1 /***********************************************************************************
370 djmaze 1.1  
371 djmaze 1.1 bool is_active($module)
372 djmaze 1.1  
373 djmaze 1.1 Checks if the module with 'modulename' is active
374 djmaze 1.1 $module: the name of the module which you wanna check; example: 'Your_Account'
375 djmaze 1.1  
376 djmaze 1.1 ************************************************************************************/
377 djmaze 1.1 function is_active($module) {
378 djmaze 1.1 global $prefix, $db;
379 djmaze 1.1 static $save; // Added by steven111
380 djmaze 1.1 if (is_array($save)) {
381 djmaze 1.1 if (isset($save[$module])) return ($save[$module]);
382 djmaze 1.1 return 0;
383 djmaze 1.1 }
384 djmaze 1.1 $result = $db->sql_query('SELECT title FROM '.$prefix.'_modules WHERE active=1');
385 djmaze 1.1 while ($row = $db->sql_fetchrow($result)) {
386 djmaze 1.1 $save[$row[0]] = 1;
387 djmaze 1.1 }
388 djmaze 1.1 $db->sql_freeresult($result);
389 djmaze 1.1 if (isset($save[$module])) return ($save[$module]);
390 djmaze 1.1 return 0;
391 djmaze 1.1 }
392 djmaze 1.1 /***********************************************************************************
393 djmaze 1.1  
394 djmaze 1.1 string Fix_Quotes(&$str, $nohtml=0)
395 djmaze 1.1  
396 djmaze 1.1 Adds slashes to string and strips PHP+HTML for SQL insertion and hack prevention
397 djmaze 1.1 $str : the string to modify
398 djmaze 1.1 $nohtml: strip PHP+HTML tags, 0 = no, 1 = yes, default = 0
399 djmaze 1.1  
400 djmaze 1.1 ************************************************************************************/
401 djmaze 1.1 function Fix_Quotes(&$str, $nohtml=false, $spchar=false) {
402 djmaze 1.1 global $db;
403 djmaze 1.1 $str = $db->sql_escape_string(trim($str));
404 djmaze 1.1 if ($nohtml) { $str = strip_tags($str); }
405 djmaze 1.1 if ($spchar) { $str = htmlspecialchars($str,ENT_NOQUOTES,'UTF-8'); }
406 djmaze 1.1 return $str;
407 djmaze 1.1 }
408 djmaze 1.1  
409 djmaze 1.1 /***********************************************************************************
410 djmaze 1.1  
411 djmaze 1.1 string FixQuotes ($what = "")
412 djmaze 1.1  
413 djmaze 1.1 Old PHP-Nuke function to stay compatible, use the advanced Fix_Quotes instead
414 djmaze 1.1  
415 djmaze 1.1 ************************************************************************************/
416 djmaze 1.1 function FixQuotes($what = "") {
417 djmaze 1.1 $what = ereg_replace("'","''",$what);
418 djmaze 1.1 while (eregi("\\\\'", $what)) {
419 djmaze 1.1 $what = ereg_replace("\\\\'","'",$what);
420 djmaze 1.1 }
421 djmaze 1.1 return $what;
422 djmaze 1.1 }
423 djmaze 1.1  
424 djmaze 1.1 /*********************************************************/
425 djmaze 1.1 /* text filterering */
426 djmaze 1.1 /*********************************************************/
427 djmaze 1.1  
428 djmaze 1.1 function check_words(&$Message) {
429 djmaze 1.1 global $CensorList, $CensorReplace, $CensorMode;
430 djmaze 1.1 if ($CensorMode != 0) {
431 djmaze 1.1 if (is_array($CensorList)) {
432 djmaze 1.1 if ($CensorMode == 1) {
433 djmaze 1.1 for ($i = 0; $i < count($CensorList); $i++) {
434 djmaze 1.1 $Message = eregi_replace("$CensorList[$i]([^a-zA-Z0-9])","$CensorReplace\\1",$Message);
435 djmaze 1.1 }
436 djmaze 1.1 } elseif ($CensorMode == 2) {
437 djmaze 1.1 for ($i = 0; $i < count($CensorList); $i++) {
438 djmaze 1.1 $Message = eregi_replace("(^|[^[:alnum:]])$CensorList[$i]","\\1$CensorReplace",$Message);
439 djmaze 1.1 }
440 djmaze 1.1 } elseif ($CensorMode == 3) {
441 djmaze 1.1 for ($i = 0; $i < count($CensorList); $i++) {
442 djmaze 1.1 $Message = eregi_replace($CensorList[$i],$CensorReplace,$Message);
443 djmaze 1.1 }
444 djmaze 1.1 }
445 djmaze 1.1 }
446 djmaze 1.1 }
447 djmaze 1.1 return $Message;
448 djmaze 1.1 }
449 djmaze 1.1  
450 djmaze 1.1 function delQuotes($string){
451 djmaze 1.1 /* no recursive function to add quote to an HTML tag if needed */
452 djmaze 1.1 /* and delete duplicate spaces between attribs. */
453 djmaze 1.1 $tmp = ""; # string buffer
454 djmaze 1.1 $result = ""; # result string
455 djmaze 1.1 $i = 0;
456 djmaze 1.1 $attrib = -1; # Are us in an HTML attrib ? -1: no attrib 0: name of the attrib 1: value of the atrib
457 djmaze 1.1 $quote = 0; # Is a string quote delimited opened ? 0=no, 1=yes
458 djmaze 1.1 $len = strlen($string);
459 djmaze 1.1 while ($i < $len) {
460 djmaze 1.1 switch($string[$i]) { # What car is it in the buffer ?
461 djmaze 1.1 case '"': #" # a quote.
462 djmaze 1.1 if ($quote == 0) {
463 djmaze 1.1 $quote = 1;
464 djmaze 1.1 } else {
465 djmaze 1.1 $quote = 0;
466 djmaze 1.1 if (($attrib > 0) && ($tmp != '')) { $result .= "=\"$tmp\""; }
467 djmaze 1.1 $tmp = '';
468 djmaze 1.1 $attrib = -1;
469 djmaze 1.1 }
470 djmaze 1.1 break;
471 djmaze 1.1 case '=': # an equal - attrib delimiter
472 djmaze 1.1 if ($quote == 0) { # Is it found in a string ?
473 djmaze 1.1 $attrib = 1;
474 djmaze 1.1 if ($tmp != '') $result.=" $tmp";
475 djmaze 1.1 $tmp = '';
476 djmaze 1.1 } else $tmp .= '=';
477 djmaze 1.1 break;
478 djmaze 1.1 case ' ': # a blank ?
479 djmaze 1.1 if ($attrib > 0) { # add it to the string, if one opened.
480 djmaze 1.1 $tmp .= $string[$i];
481 djmaze 1.1 }
482 djmaze 1.1 break;
483 djmaze 1.1 default: # Other
484 djmaze 1.1 if ($attrib < 0) # If we weren't in an attrib, set attrib to 0
485 djmaze 1.1 $attrib = 0;
486 djmaze 1.1 $tmp .= $string[$i];
487 djmaze 1.1 break;
488 djmaze 1.1 }
489 djmaze 1.1 $i++;
490 djmaze 1.1 }
491 djmaze 1.1 if (($quote != 0) && ($tmp != '')) {
492 djmaze 1.1 if ($attrib == 1) $result .= '=';
493 djmaze 1.1 /* If it is the value of an atrib, add the '=' */
494 djmaze 1.1 $result .= "\"$tmp\""; /* Add quote if needed (the reason of the function ;-) */
495 djmaze 1.1 }
496 djmaze 1.1 return $result;
497 djmaze 1.1 }
498 djmaze 1.1  
499 djmaze 1.1 function convert_html($message, $tohtml=0) {
500 djmaze 1.1 if ($tohtml) {
501 djmaze 1.1 $html_entities_match = array('#&gt;#', '#&lt;#', '#&quot;#', '#&amp;#');
502 djmaze 1.1 $html_entities_replace = array('>', '<', '"', '&');
503 djmaze 1.1 } else {
504 djmaze 1.1 $html_entities_match = array('#&(?!\(\#[0-9]+)#', '#<#', '#>#', '#"#');
505 djmaze 1.1 $html_entities_replace = array('&amp;', '&lt;', '&gt;', '&quot;');
506 djmaze 1.1 }
507 djmaze 1.1 return preg_replace($html_entities_match, $html_entities_replace, $message);
508 djmaze 1.1 }
509 djmaze 1.1  
510 djmaze 1.1 function check_html($str, $strip="") {
511 djmaze 1.1 /* The core of this code has been lifted from phpslash */
512 djmaze 1.1 /* which is licenced under the GPL. */
513 djmaze 1.1 global $AllowableHTML;
514 djmaze 1.1 if ($strip == 'nohtml') { $HTML=array(''); }
515 djmaze 1.1 else { $HTML = $AllowableHTML; }
516 djmaze 1.1 $str = stripslashes($str);
517 djmaze 1.1 $str = eregi_replace('<[[:space:]]*([^>]*)[[:space:]]*>','<\\1>', $str);
518 djmaze 1.1 // Delete all spaces from html tags .
519 djmaze 1.1 $str = eregi_replace('<a[^>]*href[[:space:]]*=[[:space:]]*"?[[:space:]]*([^" >]*)[[:space:]]*"?[^>]*>','<a href="\\1">', $str);
520 djmaze 1.1 // Delete all attribs from Anchor, except an href, double quoted.
521 djmaze 1.1 $str = eregi_replace('<[[:space:]]* img[[:space:]]*([^>]*)[[:space:]]*>', '', $str);
522 djmaze 1.1 // Delete all img tags
523 djmaze 1.1 $str = eregi_replace('<a[^>]*href[[:space:]]*=[[:space:]]*"?javascript[[:punct:]]*"?[^>]*>', '', $str);
524 djmaze 1.1 // Delete javascript code from a href tags -- Zhen-Xjell @ http://nukecops.com
525 djmaze 1.1 $tmp = "";
526 djmaze 1.1 while (ereg('<(/?[[:alpha:]]*)[[:space:]]*([^>]*)>',$str,$reg)) {
527 djmaze 1.1 $i = strpos($str,$reg[0]);
528 djmaze 1.1 $l = strlen($reg[0]);
529 djmaze 1.1 if ($reg[1][0] == '/') $tag = strtolower(substr($reg[1],1));
530 djmaze 1.1 else $tag = strtolower($reg[1]);
531 djmaze 1.1 if ($a = $HTML[$tag]) {
532 djmaze 1.1 if ($reg[1][0] == '/') $tag = "</$tag>";
533 djmaze 1.1 elseif ($a == 1 || $reg[2] == '') $tag = "<$tag>";
534 djmaze 1.1 else {
535 djmaze 1.1 # Place here the double quote fix function.
536 djmaze 1.1 $attrb_list=delQuotes($reg[2]);
537 djmaze 1.1 // A VER
538 djmaze 1.1 $attrb_list = ereg_replace('&','&amp;',$attrb_list);
539 djmaze 1.1 $tag = "<$tag" . $attrb_list . ">";
540 djmaze 1.1 }
541 djmaze 1.1 } # Attribs in tag allowed
542 djmaze 1.1 else $tag = '';
543 djmaze 1.1 $tmp .= substr($str,0,$i) . $tag;
544 djmaze 1.1 $str = substr($str,$i+$l);
545 djmaze 1.1 }
546 djmaze 1.1 $str = $tmp . $str;
547 djmaze 1.1 $str = addslashes($str);
548 djmaze 1.1 return $str;
549 djmaze 1.1 // exit;
550 djmaze 1.1 /* Squash PHP tags unconditionally */
551 djmaze 1.1 // $str = ereg_replace("<\?","",$str);
552 djmaze 1.1 // return $str;
553 djmaze 1.1 }
554 djmaze 1.1  
555 djmaze 1.1 function filter_text($Message, $strip="") {
556 djmaze 1.1 check_words($Message);
557 djmaze 1.1 $Message = check_html($Message, $strip);
558 djmaze 1.1 return $Message;
559 djmaze 1.1 }
560 djmaze 1.1  
561 djmaze 1.1 /*********************************************************/
562 djmaze 1.1 /* Time formatting */
563 djmaze 1.1 /*********************************************************/
564 djmaze 1.1  
565 djmaze 1.1 function gmtime() {
566 djmaze 1.1 static $time;
567 djmaze 1.1 if (!$time) { $time = (time() - date('Z')); }
568 djmaze 1.1 return $time;
569 djmaze 1.1 }
570 djmaze 1.1 function formatTimestamp($time) {
571 djmaze 1.1 return formatDateTime($time, _DATESTRING);
572 djmaze 1.1 }
573 djmaze 1.1 function formatDateTime($time, $format) {
574 djmaze 1.1 global $locale, $userinfo;
575 djmaze 1.1 // setlocale(LC_TIME, $locale);
576 djmaze 1.1 if (!is_numeric($time)) {
577 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);
578 djmaze 1.1 $time = mktime($datetime[4],$datetime[5],$datetime[6],$datetime[2],$datetime[3],$datetime[1]);
579 djmaze 1.1 }
580 djmaze 1.1 if (is_user() && intval($userinfo['user_timezone']) != 0) {
581 djmaze 1.1 $time = $time+(3600*intval($userinfo['user_timezone']));
582 djmaze 1.1 }
583 djmaze 1.1 return utf8_encode(ucfirst(strftime($format, $time)));
584 djmaze 1.1 }
585 djmaze 1.1  
586 djmaze 1.1 function formatAidHeader($aid) {
587 djmaze 1.1 echo $aid;
588 djmaze 1.1 }
589 djmaze 1.1  
590 djmaze 1.1 function get_author($aid) {
591 djmaze 1.1 return $aid;
592 djmaze 1.1 }
593 djmaze 1.1  
594 djmaze 1.1 function encode_ip($dotquad_ip) {
595 djmaze 1.1 $ip_sep = explode('.', $dotquad_ip);
596 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]) : '';
597 djmaze 1.1 }
598 djmaze 1.1 function decode_ip($int_ip) {
599 djmaze 1.1 $hexipbang = explode('.', chunk_split($int_ip, 2, '.'));
600 djmaze 1.1 return hexdec($hexipbang[0]). '.' . hexdec($hexipbang[1]) . '.' . hexdec($hexipbang[2]) . '.' . hexdec($hexipbang[3]);
601 djmaze 1.1 }
602 djmaze 1.1  
603 djmaze 1.1 function save_cfg($name) {
604 djmaze 1.1 $cache_dir = 'cache';
605 djmaze 1.1 $filename = $cache_dir."/config_$name.php";
606 djmaze 1.1 if (is_dir($cache_dir) && is_writable($cache_dir)) {
607 djmaze 1.1 if ($fp = @fopen($filename, 'wb')) {
608 djmaze 1.1 @flock($fp, LOCK_EX);
609 djmaze 1.1 $data = "<?php\nif (!defined('CPG_NUKE')) { header('Location: index.php'); exit; }\n";
610 djmaze 1.1 global $$name;
611 djmaze 1.1 $config =& $$name;
612 djmaze 1.1 if (is_array($config)) {
613 djmaze 1.1 @reset($config);
614 djmaze 1.1 while (list($key, $value) = @each($config) ) {
615 djmaze 1.1 if (is_array($value)) {
616 djmaze 1.1 while (list($subkey, $subvalue) = @each($value) ) {
617 djmaze 1.1 $data .= '$'.$name.'[\''.$key.'\'][\''.$subkey.'\'] = \''.ereg_replace('\'', '\\\'', trim($subvalue))."';\n";
618 djmaze 1.1 }
619 djmaze 1.1 } else {
620 djmaze 1.1 $data .= '$'.$name.'[\''.$key.'\'] = \''.trim($value).'\';'."\n";
621 djmaze 1.1 }
622 djmaze 1.1 }
623 djmaze 1.1 }
624 djmaze 1.1 @fwrite ($fp, $data.'?>');
625 djmaze 1.1 @flock($fp, LOCK_UN);
626 djmaze 1.1 @fclose($fp);
627 djmaze 1.1 @umask(0);
628 djmaze 1.1 }
629 djmaze 1.1 }
630 djmaze 1.1 }
631 djmaze 1.1 function load_cfg($name) {
632 djmaze 1.1 global $$name;
633 djmaze 1.1 if (file_exists("cache/config_$name.php")) {
634 djmaze 1.1 include("cache/config_$name.php");
635 djmaze 1.1 return true;
636 djmaze 1.1 } else {
637 djmaze 1.1 return false;
638 djmaze 1.1 }
639 djmaze 1.1 }
640 djmaze 1.1 function delete_cfg($name) {
641 djmaze 1.1 $cache_dir = 'cache';
642 djmaze 1.1 $filename = $cache_dir."/config_$name.php";
643 djmaze 1.1 if (is_dir($cache_dir) && is_writable($cache_dir)) {
644 djmaze 1.1 if (file_exists($filename)) {
645 djmaze 1.1 @unlink($filename);
646 djmaze 1.1 }
647 djmaze 1.1 }
648 djmaze 1.15 }


Code Credits - Privacy Policy