<?php
/**
* @author moufer<moufer@163.com>
* @copyright www.modoer.com
* @version $Id fun_common.php 3 2008-08-24 10:34 $
*/
!defined('IN_MUDDER') && exit('Access Denied');

/*
function mylinks_Cache($refurbish = false) {
    global $timestamp, $db, $dbpre, $_plugins;

    $cache = new Cache_Base($timestamp);
    $cachefile = MUDDER_CACHEDIR.'cache_plugins_mylinks.php';
    if(!$refurbish && $cache->Check_Cachefile($cachefile, -1)) {
        return $cache->Get_CacheArray($cachefile);
    }

    $result = array();
    $config = $_plugins['mylinks']['config'];
    foreach($config as $key => $val) {
        if(substr($key, 0, 4) != 'num_') continue;
        $val = intval($val);
        if($val <= 0) continue;
        $newkey = substr($key,4,strlen($key));
        $where = array("ischeck=1");
        $where[] = $newkey == 'logo' ? "logo!=''" : "logo=''";
        $result[$newkey] = $db->get_all("SELECT * FROM {$dbpre}mylinks WHERE ".implode(" AND ",$where)." ORDER BY displayorder LIMIT $val");
    }

    $cachedata = "<?php\r\n return ".$cache->ArrayEval($result).";\r\n?>";
    $cache->Write_Cache('cache_plugins_mylinks.php', MUDDER_CACHEDIR, $cachedata);
    return $result;
}
*/
// 将链接写入缓存
function write_cache_links($return = false) {
    global $db, $dbpre;

    $MOD = $result = array();
    $MOD = read_cache(MUDDER_ROOT.'data/cachefiles/cache_'.MOD_FLAG.'_config.php');
    foreach($MOD as $key => $val) {
        if(substr($key, 0, 4) != 'num_') continue;
        $val = intval($val);
        if($val <= 0) continue;
        $newkey = substr($key, 4, strlen($key));
        $where = array("ischeck=1");
        $where[] = $newkey == 'logo' ? "logo!=''" : "logo=''";
        $result[$newkey] = $db->get_all("SELECT * FROM {$dbpre}mylinks WHERE ".implode(" AND ",$where)." ORDER BY displayorder LIMIT $val");
    }
    write_cache('links', arrayeval($result), '', 'return');
    if($return) return $result;
}

// 读取链接缓存
function read_cache_links() {
    global $db, $dbpre;

    $cachefile = MUDDER_ROOT.'./data/cachefiles/cache_links.php';
    if(check_cache($cachefile)) {
        return read_cache($cachefile);
    }
    return write_cache_links(true);
}
?>