$val) { $key = is_string($key) ? '\''.addcslashes($key, '\'\\').'\'' : $key; $val = !is_array($val) && (!preg_match("/^\-?[1-9]\d*$/", $val) || strlen($val) > 12) ? '\''.addcslashes($val, '\'\\').'\'' : $val; if(is_array($val)) { $evaluate .= "$comma$key => ".nmarrayeval($val, $level + 1); } else { $evaluate .= "$comma$key => $val"; } $comma = ",\n$space"; } } $evaluate .= "\n$space)"; return $evaluate; } function nmwritetocache($script, $cachenames, $cachedata = '', $prefix = '',$cachedir= 'nm_cache' ) { global $authkey, $timestamp, $cache_flag; if(is_array($cachenames) && !$cachedata) { foreach($cachenames as $name) { $cachedata .= nmgetcachearray($name, $script); } } $dir = DISCUZ_ROOT.'./forumdata/'.$cachedir.'/'; if(!is_dir($dir)) { @mkdir($dir, 0777); } if($fp = @fopen("$dir$prefix$script.php", 'wb')) { fwrite($fp, ""); fclose($fp); } else { dexit('Can not write to cache files, please check directory ./forumdata/ and ./forumdata/cache/ .'); } } function updatenmcache($cachename = '') { global $db, $bbname, $tablepre, $maxbdays, $geo_md5,$cache_flag; $cachescript = array ( 'geo_topics_latest_'.$geo_md5 => array('geo_newthread_'.$geo_md5), 'geo_topics_hot_'.$geo_md5 => array('geo_hot_'.$geo_md5), 'geo_now_'.$geo_md5 => array('geo_now_'.$geo_md5), ); foreach($cachescript as $script => $cachenames) { if(!$cachename || (!is_array($cachename) && in_array($cachename, $cachenames)) || (is_array($cachename) && array_intersect($cachename, $cachenames))) { nmwritetocache($script, $cachenames); } } } function nmgetcachearray($cachename, $script = '') { global $db, $timestamp, $tablepre, $timeoffset, $maxbdays, $smcols, $smrows,$geo_md5,$geos_all_children_sql; //$disallow = "f.fid!='72'and f.fid!='73'and f.fid!='76'and f.fid!='49'and f.fid!='67'and f.fid!='74'and f.fid!='77'and f.fid!='46' and f.fid!='6'and f.fid!='25'and f.fid!='51'and f.fid!='26'and f.fid!='64'"; $cols = '*'; $conditions = ''; switch($cachename) { case 'geo_newthread_'.$geo_md5: $table = 'members m, cdb_threads t'; $cols = 'm.uid, t.subject, t.authorid,t.author,t.tid, t.lastpost, mf.uid, mf.avatar'; $conditions = "LEFT JOIN {$tablepre}forums f ON f.fid=t.fid LEFT JOIN {$tablepre}memberfields mf ON mf.uid=t.authorid WHERE m.uid = t.authorid AND m.uid IN (SELECT uid FROM {$tablepre}members WHERE usr_geo IN ({$geos_all_children_sql})) ORDER BY t.lastpost DESC LIMIT 25"; break; case 'geo_hot_'.$geo_md5: $now = getdate(time()); $start = mktime(0, 0, 0, $now['mon'], 1, $now['year']); $table = 'threads t'; $cols = 't.subject, t.authorid,t.author,t.tid,t.authorid,t.dateline,t.lastpost,t.views,t.replies'; $conditions = "LEFT JOIN {$tablepre}forums f ON f.fid=t.fid WHERE t.authorid IN (SELECT uid FROM {$tablepre}members WHERE usr_geo IN ({$geos_all_children_sql})) AND t.dateline > {$start} ORDER BY t.views DESC,t.replies DESC LIMIT 10"; break; case 'geo_now_'.$geo_md5: $table = 'plugin_now n'; $cols = 'n.vid,n.dateline,n.author,n.authorid,n.content,n.background,mf.avatar'; $conditions = "LEFT JOIN {$tablepre}memberfields mf ON mf.uid=n.authorid WHERE n.authorid IN (SELECT uid FROM {$tablepre}members WHERE usr_geo IN ({$geos_all_children_sql})) ORDER BY dateline DESC LIMIT 10"; break; } $data = array(); if(!in_array($cachename, array('advs', 'supe_updateusers', 'supe_updateitems', 'supe_updatecircles'))) { $query = $db->query("SELECT $cols FROM {$tablepre}$table $conditions"); if (mysql_num_rows($query) > 0) { $cache_flag = true; } else { $cache_flag = false; } } switch($cachename) { //S:nowhere case 'geo_now_'.$geo_md5: while ($message = $db->fetch_array($query)) { $message['content'] = dhtmlspecialchars($message['content']); $message['avatar'] = avRESIZE($message['avatar'],'s'); if ($message['background']=='1') { $message['background'] = 'mobile'; } else if ($message['background']=='2') { $message['background'] = 'im'; } else { $message['background'] = 'web'; } $data[] = $message; } $expiration_name="now"; $expiration= 1200 + time(); break; //E:nowhere //S:geo_topic_latest_cache case 'geo_newthread_'.$geo_md5: while($topthread = $db->fetch_array($query)) { $topthread['uid'] = $topthread['uid']; $topthread['author'] = $topthread['author'] ? $topthread['author'] : 'ÓοÍ'; $topthread['avatar'] = avRESIZE($topthread['avatar'],'s'); $data[] = $topthread; } $expiration_name="thread"; $expiration= 1200 + time(); break; case 'geo_hot_'.$geo_md5: while($topthread = $db->fetch_array($query)) { $topthread['uid'] = $topthread['uid']; $topthread['author'] = $topthread['author'] ? $topthread['author'] : 'ÓοÍ'; $topthread['avatar'] = avRESIZE($topthread['avatar'],'s'); $data[] = $topthread; } $expiration_name="hot"; $expiration= 3600 + time(); break; //E:geo_topic_latest_cache default: while($datarow = $db->fetch_array($query)) { $data[] = $datarow; } } return "\$_DCACHE['$cachename'] = ".nmarrayeval($data).";\n\n\$".$expiration_name."_expiration = '".$expiration."';\n"; } function nmgetcachevars($data, $type = 'VAR') { $evaluate = ''; foreach($data as $key => $val) { if(is_array($val)) { $evaluate .= "\$$key = ".nmarrayeval($val).";\n"; } else { $val = addcslashes($val, '\'\\'); $evaluate .= $type == 'VAR' ? "\$$key = '$val';\n" : "define('".strtoupper($key)."', '$val');\n"; } } return $evaluate; } ?>