Ejemplo n.º 1
0
 public function set($key, $value, $path = null, $expire = null)
 {
     $filename = $this->_uk86_path($key);
     if (false == uk86_write_file($filename, $value)) {
         return false;
     } else {
         return true;
     }
 }
Ejemplo n.º 2
0
 /**
  * 广告
  *
  * @return array
  */
 public function makeApAllCache()
 {
     if (C('cache_open')) {
         // *kcache() doesnt support iterating on keys
     } else {
         uk86_delCacheFile('adv');
     }
     $model = Model();
     $ap_list = $model->table('adv_position')->where(array('is_use' => 1))->select();
     $adv_list = $model->table('adv')->where(array('adv_end_date' => array('gt', time())))->order('slide_sort, adv_id desc')->select();
     $array = array();
     foreach ((array) $ap_list as $v) {
         foreach ((array) $adv_list as $xv) {
             if ($v['ap_id'] == $xv['ap_id']) {
                 $v['adv_list'][] = $xv;
             }
         }
         // 写入缓存
         $apId = (int) $v['ap_id'];
         if (C('cache_open')) {
             uk86_wkcache("adv/{$apId}", $v);
         } else {
             uk86_write_file(BASE_DATA_PATH . '/cache/adv/' . $apId . '.php', $v);
         }
     }
 }
Ejemplo n.º 3
0
/**
 * 调用推荐位
 *
 * @param unknown_type $rec_id
 * @return string
 */
function uk86_rec_position($rec_id = null)
{
    if (!is_numeric($rec_id)) {
        return null;
    }
    $string = '';
    if (C('cache_open')) {
        $info = uk86_rkcache("rec_position/{$rec_id}", function ($rec_id) {
            $rec_id = substr($rec_id, strlen('rec_position/'));
            return Model('rec_position')->find($rec_id);
        });
    } else {
        $file = BASE_DATA_PATH . '/cache/rec_position/' . $rec_id . '.php';
        if (file_exists($file)) {
            $info = (require $file);
        } else {
            $info = Model('rec_position')->find($rec_id);
            uk86_write_file($file, $info);
        }
    }
    $info['content'] = unserialize($info['content']);
    if ($info['content']['target'] == 2) {
        $target = 'target="_blank"';
    } else {
        $target = '';
    }
    if ($info['pic_type'] == 0) {
        //文字
        foreach ((array) $info['content']['body'] as $v) {
            $href = '';
            if ($v['url'] != '') {
                $href = "href=\"{$v['url']}\"";
            }
            $string .= "<li><a {$target} {$href}>{$v['title']}</a></li>";
        }
        $string = "<ul>{$string}</ul>";
    } else {
        //图片
        $width = $height = '';
        if (is_numeric($info['content']['width'])) {
            $width = "width=\"{$info['content']['width']}\"";
        }
        if (is_numeric($info['content']['height'])) {
            $height = "height=\"{$info['content']['height']}\"";
        }
        if (is_array($info['content']['body'])) {
            if (count($info['content']['body']) > 1) {
                foreach ($info['content']['body'] as $v) {
                    if ($info['pic_type'] == 1) {
                        $v['title'] = UPLOAD_SITE_URL . '/' . $v['title'];
                    }
                    $href = '';
                    if ($v['url'] != '') {
                        $href = "href=\"{$v['url']}\"";
                    }
                    $string .= "<li><a {$target} {$href}><img {$width} {$height} src=\"{$v['title']}\"></a></li>";
                }
                $string = "<ul>{$string}</ul>";
            } else {
                $v = $info['content']['body'][0];
                if ($info['pic_type'] == 1) {
                    $v['title'] = UPLOAD_SITE_URL . '/' . $v['title'];
                }
                $href = '';
                if ($v['url'] != '') {
                    $href = "href=\"{$v['url']}\"";
                }
                $string .= "<a {$target} {$href}><img {$width} {$height} src=\"{$v['title']}\"></a>";
            }
        }
    }
    return $string;
}
Ejemplo n.º 4
0
/**
 * 文件数据读取和保存 字符串、数组
 *
 * @param string $name 文件名称(不含扩展名)
 * @param mixed $value 待写入文件的内容
 * @param string $path 写入cache的目录
 * @param string $ext 文件扩展名
 * @return mixed
 */
function F($name, $value = null, $path = 'cache', $ext = '.php')
{
    if (strtolower(substr($path, 0, 5)) == 'cache') {
        $path = 'data/' . $path;
    }
    static $_cache = array();
    if (isset($_cache[$name . $path])) {
        return $_cache[$name . $path];
    }
    $filename = BASE_ROOT_PATH . '/' . $path . '/' . $name . $ext;
    if (!is_null($value)) {
        $dir = dirname($filename);
        if (!is_dir($dir)) {
            mkdir($dir);
        }
        return uk86_write_file($filename, $value);
    }
    if (is_file($filename)) {
        $_cache[$name . $path] = $value = (include $filename);
    } else {
        $value = false;
    }
    return $value;
}