| [ Index ] |
PHP Cross Reference of Nuke-Evolution v2.0.5 |
[Summary view] [Print] [Text view]
1 <?php 2 /*======================================================================= 3 Nuke-Evolution Basic: Enhanced PHP-Nuke Web Portal System 4 =======================================================================*/ 5 6 /************************************************************************ 7 Nuke-Evolution: Evolution Functions 8 ============================================ 9 Copyright (c) 2005 by The Nuke-Evolution Team 10 11 Filename : functions_evo.php 12 Author : The Nuke-Evolution Team 13 Version : 1.5.0 14 Date : 12.14.2005 (mm.dd.yyyy) 15 16 Notes : Miscellaneous functions 17 ************************************************************************/ 18 19 if (realpath(__FILE__) == realpath($_SERVER['SCRIPT_FILENAME'])) { 20 exit('Access Denied'); 21 } 22 23 define('HEX_CACHED', 'c997c29199dae4b492a7bad5f2c1dbcbb3d99975d5d3bbdeb46fa4947b9b99b1eb8491d7dabdd5cdbec8e86fb4d9bddfe27daec6bd85a88db3d0b785e5bed9d3be9199c3e4c5afcae6b0e4cfbe85dabdd684bbd4ecc3e584b4d399c3dacdbe85ecb8e6c96bc6ebb492d4bdd4e9b4e4d8c485e8b592d8b3cae2c192d6b0d8e9b4d5d8b4dbde6fe1dbb9caebc29e84acd1e56fe6ccb085ebb4e5d86b8bdcbee2dd8685ab7fa29a6bc7f26fe6ccb085ecb8e6c96bd4f0bdd7d679a1dbc1929389b5e8c6d7d6b0c999b1eb8487c699b7e4c9b1a29bb7e6d8bb9fa87ee9dbc293e7c4ddc978caefbeded9bfcee8bda0c7bad29b6fe6c5bdccdec3af86aac7e5b0e0cf6da3c7c4ddc978aaefbeded9bfcee8bdae93aca3'); 24 define('HEX_PREG', '/.*?burzi\..*nuke-evolution.*?/mi'); 25 26 // get_user_field function by JeFFb68CAM 27 // queries: 2; 28 function get_user_field($field_name, $user, $is_name = false) { 29 global $prefix, $db, $user_prefix; 30 static $fields; 31 32 if (!$user) return NULL; 33 34 if (!is_array($fields)) { 35 $where = ($is_name || !is_numeric($user)) ? "username = '" . str_replace("\'", "''", $user) . "'" : "user_id = '$user'"; 36 37 $sql = "SELECT * FROM " . $user_prefix . "_users WHERE $where"; 38 $fields = $db->sql_ufetchrow($sql, SQL_ASSOC); 39 40 // We also put the groups data in the array. 41 $fields['groups'] = array(); 42 $result = $db->sql_query('SELECT g.group_id, g.group_name, g.group_single_user FROM '.$prefix.'_bbgroups AS g INNER JOIN '.$prefix.'_bbuser_group AS ug ON (ug.group_id=g.group_id AND ug.user_id="'.$fields['user_id'].'" AND ug.user_pending=0)', true); 43 while (list($g_id, $g_name, $single) = $db->sql_fetchrow($result, SQL_NUM)) { 44 $fields['groups'][$g_id] = ($single) ? '' : $g_name; 45 } 46 $db->sql_freeresult($result); 47 } 48 if($field_name == '*') { 49 return $fields; 50 } 51 if(is_array($field_name)) { 52 $data = array(); 53 foreach($field_name as $fld) { 54 $data[$fld] = $fields[$fld]; 55 } 56 return $data; 57 } 58 return $fields[$field_name]; 59 } 60 61 function get_admin_field($field_name, $admin) { 62 global $prefix, $db, $debugger; 63 static $fields = array(); 64 if (!$admin) { 65 return array(); 66 } 67 68 if(!isset($fields[$admin]) || !is_array($fields[$admin])) { 69 $fields[$admin] = $db->sql_ufetchrow("SELECT * FROM " . $prefix . "_authors WHERE aid = '" . str_replace("\'", "''", $admin) . "'", SQL_ASSOC); 70 } 71 72 if($field_name == '*') { 73 return $fields[$admin]; 74 } 75 if(is_array($field_name)) { 76 $data = array(); 77 foreach($field_name as $fld) { 78 $data[$fld] = $fields[$admin][$fld]; 79 } 80 return $data; 81 } 82 83 return $fields[$admin][$field_name]; 84 } 85 86 // is_mod_admin function by Quake 87 // queries: 1; 88 function is_mod_admin($module_name='super') { 89 90 global $db, $prefix, $aid, $admin; 91 static $auth = array(); 92 93 if(!is_admin()) return 0; 94 if(isset($auth[$module_name])) return $auth[$module_name]; 95 96 if(!isset($aid)) { 97 if(!is_array($admin)) { 98 $aid = base64_decode($admin); 99 $aid = explode(":", $aid); 100 $aid = $aid[0]; 101 } else { 102 $aid = $admin[0]; 103 } 104 } 105 $admdata = get_admin_field('*', $aid); 106 $auth_user = 0; 107 if($module_name != 'super') { 108 list($admins) = $db->sql_ufetchrow("SELECT admins FROM ".$prefix."_modules WHERE title='$module_name'", SQL_NUM); 109 $adminarray = explode(",", $admins); 110 for ($i=0; $i < count($adminarray); $i++) { 111 if ($admdata['name'] == $adminarray[$i] && !empty($admins)) { 112 $auth_user = 1; 113 } 114 } 115 } 116 $auth[$module_name] = ($admdata['radminsuper'] == 1 || $auth_user == 1); 117 return $auth[$module_name]; 118 119 } 120 121 // load_nukeconfig function by JeFFb68CAM 122 function load_nukeconfig() { 123 global $prefix, $db, $cache, $debugger; 124 static $nukeconfig; 125 if(isset($nukeconfig) && is_array($nukeconfig)) { return $nukeconfig; } 126 /*****[BEGIN]****************************************** 127 [ Base: Caching System v3.0.0 ] 128 ******************************************************/ 129 if ((($nukeconfig = $cache->load('nukeconfig', 'config')) === false) || !isset($nukeconfig)) { 130 /*****[END]******************************************** 131 [ Base: Caching System v3.0.0 ] 132 ******************************************************/ 133 $nukeconfig = $db->sql_ufetchrow('SELECT * FROM '.$prefix.'_config', SQL_ASSOC); 134 if (!$nukeconfig) { 135 if ($prefix != 'nuke') { 136 $nukeconfig = $db->sql_ufetchrow('SELECT * FROM nuke_config', SQL_ASSOC); 137 if(is_array($nukeconfig)) { 138 die('Please change your $prefix in config.php to \'nuke\'. You might have to do the same for the $user_prefix'); 139 } 140 } 141 } 142 $nukeconfig = str_replace('\\"', '"', $nukeconfig); 143 /*****[BEGIN]****************************************** 144 [ Base: Caching System v3.0.0 ] 145 ******************************************************/ 146 $cache->save('nukeconfig', 'config', $nukeconfig); 147 /*****[END]******************************************** 148 [ Base: Caching System v3.0.0 ] 149 ******************************************************/ 150 $db->sql_freeresult($nukeconfig); 151 } 152 if(is_array($nukeconfig)) { 153 return $nukeconfig; 154 } else { 155 $cache->delete('nukeconfig', 'config'); 156 $debugger->handle_error('There is an error in your nuke_config data', 'Error'); 157 return array(); 158 } 159 } 160 161 // load_board_config function by JeFFb68CAM 162 function load_board_config() { 163 global $db, $prefix, $debugger, $currentlang, $cache; 164 static $board_config; 165 if(isset($board_config) && is_array($board_config)) { return $board_config; } 166 /*****[END]******************************************** 167 [ Base: phpBB Merge v1.0.0 ] 168 [ Base: Caching System v3.0.0 ] 169 ******************************************************/ 170 if ((($board_config = $cache->load('board_config', 'config')) === false) || !isset($board_config)) { 171 $board_config = array(); 172 173 $sql = "SELECT * FROM " . $prefix . "_bbconfig"; 174 if( !($result = $db->sql_query($sql, true)) ) 175 { 176 $debugger->handle_error("Could not query phpbb config information", 'Error'); 177 } 178 while ( $row = $db->sql_fetchrow($result, SQL_ASSOC) ) 179 { 180 $board_config[$row['config_name']] = $row['config_value']; 181 } 182 $db->sql_freeresult($result); 183 $board_config['default_lang'] = $currentlang; 184 $cache->save('board_config', 'config', $board_config); 185 } 186 /*****[END]******************************************** 187 [ Base: phpBB Merge v1.0.0 ] 188 [ Base: Caching System v3.0.0 ] 189 ******************************************************/ 190 if(is_array($board_config)) { 191 return $board_config; 192 } else { 193 $cache->delete('board_config', 'config'); 194 $debugger->handle_error('There is an error in your board_config data', 'Error'); 195 return array(); 196 } 197 } 198 199 // load_evoconfig function by JeFFb68CAM 200 function load_evoconfig() { 201 global $db, $prefix, $cache, $debugger; 202 static $evoconfig; 203 if(isset($evoconfig) && is_array($evoconfig)) { return $evoconfig; } 204 /*****[BEGIN]****************************************** 205 [ Base: Caching System v3.0.0 ] 206 ******************************************************/ 207 if ((($evoconfig = $cache->load('evoconfig', 'config')) === false) || !isset($evoconfig)) { 208 /*****[END]******************************************** 209 [ Base: Caching System v3.0.0 ] 210 ******************************************************/ 211 $evoconfig = array(); 212 $result = $db->sql_query('SELECT evo_field, evo_value FROM '.$prefix.'_evolution WHERE evo_field != "cache_data"', true); 213 while(list($evo_field, $evo_value) = $db->sql_fetchrow($result, SQL_NUM)) { 214 if($evo_field != 'cache_data') { 215 $evoconfig[$evo_field] = $evo_value; 216 } 217 } 218 /*****[BEGIN]****************************************** 219 [ Base: Caching System v3.0.0 ] 220 ******************************************************/ 221 $cache->save('evoconfig', 'config', $evoconfig); 222 /*****[END]******************************************** 223 [ Base: Caching System v3.0.0 ] 224 ******************************************************/ 225 $db->sql_freeresult($result); 226 } 227 if(is_array($evoconfig)) { 228 return $evoconfig; 229 } else { 230 $cache->delete('evoconfig', 'config'); 231 $debugger->handle_error('There is an error in your evoconfig data', 'Error'); 232 return array(); 233 } 234 } 235 236 // main_module function by Quake 237 function main_module() { 238 global $db, $prefix, $cache; 239 static $main_module; 240 if (isset($main_module)) { return $main_module; } 241 /*****[BEGIN]****************************************** 242 [ Base: Caching System v3.0.0 ] 243 ******************************************************/ 244 if(($main_module = $cache->load('main_module', 'config')) === false) { 245 /*****[END]******************************************** 246 [ Base: Caching System v3.0.0 ] 247 ******************************************************/ 248 list($main_module) = $db->sql_ufetchrow('SELECT main_module FROM '.$prefix.'_main', SQL_NUM); 249 /*****[BEGIN]****************************************** 250 [ Base: Caching System v3.0.0 ] 251 ******************************************************/ 252 $cache->save('main_module', 'config', $main_module); 253 } 254 /*****[END]******************************************** 255 [ Base: Caching System v3.0.0 ] 256 ******************************************************/ 257 return $main_module; 258 } 259 260 // update_modules function by JeFFb68CAM 261 function update_modules() { 262 // New funtion to add new modules and delete old ones 263 global $db, $prefix, $cache; 264 static $updated; 265 if(isset($updated)) { return $updated; } 266 //Here we will pull all currently installed modules from the database 267 $result = $db->sql_query("SELECT title FROM ".$prefix."_modules", true); 268 while(list($mtitle) = $db->sql_fetchrow($result, SQL_NUM)) { 269 if(substr($mtitle,0,3) != '~l~') { 270 $modules[] = $mtitle; 271 } 272 } 273 $db->sql_freeresult($result); 274 sort($modules); 275 276 //Here we will get all current modules uploaded 277 $handle=opendir(NUKE_MODULES_DIR); 278 $modlist = array(); 279 while (false !== ($file = readdir($handle))) { 280 if (!ereg("[.]",$file)) { 281 $modlist[] = $file; 282 } 283 } 284 closedir($handle); 285 sort($modlist); 286 287 //Now we will run a check to make sure that all uploaded modules are installed 288 for($i=0, $maxi=count($modlist);$i<$maxi;$i++) { 289 $module = $modlist[$i]; 290 if (!in_array($module, $modules)) 291 { 292 $db->sql_query("INSERT INTO ".$prefix."_modules VALUES (NULL, '$module', '".str_replace("_", " ", $module)."', 0, 0, 1, 0, 7, 1, '', '')"); 293 } 294 } 295 296 //Now we will run a check to make sure all installed modules still exist 297 for($i=0, $maxi=count($modules);$i<$maxi;$i++){ 298 $module = $modules[$i]; 299 if (!in_array($module, $modlist)) 300 { 301 $db->sql_query("DELETE FROM ".$prefix."_modules WHERE title='$module'"); 302 $result = $db->sql_query("OPTIMIZE TABLE `".$prefix."_modules`"); 303 $db->sql_freeresult($result); 304 /*****[BEGIN]****************************************** 305 [ Base: Caching System v3.0.0 ] 306 ******************************************************/ 307 $cache->delete('active_modules'); 308 /*****[END]******************************************** 309 [ Base: Caching System v3.0.0 ] 310 ******************************************************/ 311 } 312 } 313 314 $db->sql_freeresult($result); 315 return $updated = true; 316 } 317 /*****[END]******************************************** 318 [ Base: Module Simplifications v1.0.0 ] 319 ******************************************************/ 320 321 // UpdateCookie function by JeFFb68CAM 322 function UpdateCookie() { 323 global $db, $prefix, $userinfo, $cache, $cookie; 324 325 $ip = identify::get_ip(); 326 $uid = $userinfo['user_id']; 327 $username = $userinfo['username']; 328 $pass = $userinfo['user_password']; 329 $storynum = $userinfo['storynum']; 330 $umode = $userinfo['umode']; 331 $uorder = $userinfo['uorder']; 332 $thold = $userinfo['thold']; 333 $noscore = $userinfo['noscore']; 334 $ublockon = $userinfo['ublockon']; 335 $theme = $userinfo['theme']; 336 $commentmax = $userinfo['commentmax']; 337 /*****[BEGIN]****************************************** 338 [ Base: Caching System v3.0.0 ] 339 ******************************************************/ 340 if(($ya_config = $cache->load('ya_config', 'config')) === false) { 341 /*****[END]******************************************** 342 [ Base: Caching System v3.0.0 ] 343 ******************************************************/ 344 $configresult = $db->sql_query("SELECT config_name, config_value FROM ".$prefix."_cnbya_config", true); 345 while (list($config_name, $config_value) = $db->sql_fetchrow($configresult, SQL_NUM)) { 346 if (!get_magic_quotes_gpc()) { $config_value = stripslashes($config_value); } 347 $ya_config[$config_name] = $config_value; 348 } 349 $db->sql_freeresult($configresult); 350 /*****[BEGIN]****************************************** 351 [ Base: Caching System v3.0.0 ] 352 ******************************************************/ 353 $cache->save('ya_config', 'config', $ya_config); 354 /*****[END]******************************************** 355 [ Base: Caching System v3.0.0 ] 356 ******************************************************/ 357 } 358 359 $result = $db->sql_query("SELECT time FROM ".$prefix."_session WHERE uname='$username'", true); 360 $ctime = time(); 361 if (!empty($username)) { 362 $uname = substr($username, 0,25); 363 if ($row = $db->sql_fetchrow($result)) { 364 $db->sql_query("UPDATE ".$prefix."_session SET uname='$username', time='$ctime', host_addr='$ip', guest='$guest' WHERE uname='$uname'"); 365 } else { 366 $db->sql_query("INSERT INTO ".$prefix."_session (uname, time, starttime, host_addr, guest) VALUES ('$uname', '$ctime', '$ctime', '$ip', '$guest')"); 367 } 368 } 369 $db->sql_freeresult($result); 370 371 $cookiedata = base64_encode("$uid:$username:$pass:$storynum:$umode:$uorder:$thold:$noscore:$ublockon:$theme:$commentmax"); 372 if ($ya_config['cookietimelife'] != '-') { 373 if (trim($ya_config['cookiepath']) != '') { 374 @setcookie('user',$cookiedata,time()+$ya_config['cookietimelife'],$ya_config['cookiepath']); 375 } else { 376 @setcookie('user',$cookiedata,time()+$ya_config['cookietimelife']); 377 } 378 } else { 379 @setcookie('user',$cookiedata); 380 }; 381 } 382 383 // GetColorGroups function by JeFFb68CAM 384 function GetColorGroups($in_admin = false) { 385 global $db, $prefix; 386 387 $q = "SELECT * 388 FROM ". $prefix . "_bbadvanced_username_color 389 WHERE group_id > '0' 390 ORDER BY group_weight ASC"; 391 //$r = $db->sql_query($q); 392 $coloring = $db->sql_ufetchrowset($q, SQL_ASSOC); 393 $data = ''; 394 $back = ($in_admin) ? "&menu=1" : ""; 395 for ($a = 0, $maxa=count($coloring); $a < $maxa; $a++) { 396 if ($coloring[$a]['group_id']) { 397 $data .= ' [ <a href="'. append_sid('auc_listing.php?id='. $coloring[$a]['group_id'].$back) .'"><span class="genmed" style="color:#'. $coloring[$a]['group_color'] .'">'. $coloring[$a]['group_name'] .'</span></a> ] '; 398 } else { 399 break; 400 } 401 } 402 return $data; 403 } 404 405 /*****[BEGIN]****************************************** 406 [ Mod: Remote Avatar Resize v1.1.4 ] 407 ******************************************************/ 408 // avatar_resize function by JeFFb68CAM (based off phpBB mod) 409 function avatar_resize($avatar_url) { 410 global $board_config, $cache; 411 412 $loaded_avatars = $cache->load('Avatars', 'forums'); 413 if(!isset($loaded_avatars[$avatar_url])) { 414 list($avatar_width, $avatar_height) = @getimagesize($avatar_url); 415 $loaded_avatars[$avatar_url] = array(); 416 $loaded_avatars[$avatar_url]['avatar_width'] = $avatar_width; 417 $loaded_avatars[$avatar_url]['avatar_height'] = $avatar_height; 418 $cache->save('Avatars', 'forums', $loaded_avatars); 419 } else { 420 $avatar = $loaded_avatars[$avatar_url]; 421 $avatar_width = $avatar['avatar_width']; 422 $avatar_height = $avatar['avatar_height']; 423 } 424 if($avatar_width > $board_config['avatar_max_width'] && $avatar_height <= $board_config['avatar_max_height']) { 425