Created
July 20, 2010 11:34
-
-
Save millken/482847 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?PHP | |
//==================================================== | |
// FileName: cache.inc.php | |
// Summary: update cache to file or database | |
// Author: millken(迷路林肯) | |
// LastModifed:2009-2-15 | |
// copyright (c)2009 millken@gmail.com | |
//==================================================== | |
if(!defined('OK'))exit(__FILE__.'Access Denied'); | |
function updateConfig(){ | |
$array = $GLOBALS['db']->getAll("SELECT * FROM `softini`"); | |
$options = array(); | |
foreach((array)$array as $r) { | |
$options[$r['type']][$r['id']] = $r['name']; | |
} | |
writetofile(ROOT_PATH . 'cache/softini.php','$softini = ' . var_export($options,true)); | |
} | |
function UnicodeHexToDec( $uhStr ) | |
{ | |
$gbStr = ""; | |
$udChar = str_replace('\u','',$uhStr[0]); | |
$udChar = hexdec( $udChar ); | |
$gbStr = "&#".$udChar.";"; | |
return $gbStr; | |
} | |
function decode($str) { | |
$str = str_replace(array('&#',';'),array('',''),$str); | |
$dec = intval($str[0]); | |
if ($dec < 128) { | |
$utf .= chr($dec); | |
} else if ($dec < 2048) { | |
$utf .= chr(192 + (($dec - ($dec % 64)) / 64)); | |
$utf .= chr(128 + ($dec % 64)); | |
} else { | |
$utf .= chr(224 + (($dec - ($dec % 4096)) / 4096)); | |
$utf .= chr(128 + ((($dec % 4096) - ($dec % 64)) / 64)); | |
$utf .= chr(128 + ($dec % 64)); | |
} | |
return $utf; | |
} | |
//更新关键字缓存 | |
function updateWordsCache(){ | |
$content = file_get_contents("http://www.google.cn/rebang/detail?bid=12000003"); | |
$words = $_words = array(); | |
$contents = getstr('queries','linktexts',$content) ; | |
preg_match_all('~\["(.*?)",~',$contents,$words); | |
foreach($words[1] as $w) { | |
if(!strstr($w,"\u")) { | |
$_words[] = $w; | |
}else{ | |
$str = preg_replace_callback("~\\\u\w{4}~i",'UnicodeHexToDec',$w); | |
$str = preg_replace_callback("~&#\d{2,5};~",'decode',$str); | |
$_words[] = $str; | |
} | |
} | |
writetofile(ROOT_PATH . 'cache/searchwords.php','$softwords = ' . var_export($_words,true).";\n"); | |
} | |
//更新GOOGLE sitemap | |
function updateSitemap() { | |
$GLOBALS['db']->query("DELETE FROM `softkeyword` WHERE adddate<left(from_unixtime(unix_timestamp()-86400),10)"); | |
$today = format_time(time(),"Y-m-d"); | |
$str = "<?xml version='1.0' encoding='GBK'?>\n<urlset xmlns='http://www.google.com/schemas/sitemap/0.84'>\n<url><loc>http://www.youcandown.com/</loc><lastmod>{$today}</lastmod><changefreq>daily</changefreq><priority>0.8</priority></url>\n"; | |
$todaysoft = $GLOBALS['db']->getAll("SELECT id FROM `softinfo` WHERE `datetime`>left(from_unixtime(unix_timestamp()-86400*3),10)"); | |
foreach((array)$todaysoft as $t) { | |
$str .="<url><loc>http://www.youcandown.com/soft-{$t['id']}.html</loc><lastmod>{$today}</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>\n"; | |
} | |
$str .="</urlset>"; | |
writetofile(ROOT_PATH . 'todaysoft.xml',$str,'xml'); | |
return true; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment