<?php
/*
 +----------------------------------------------------------------------
 | TEMMOKUMVC [ NO BEST, ONLY BETTER ]
 +----------------------------------------------------------------------
 | Copyright (c) 2018~2019 https://www.temmoku.cn All rights reserved.
 +----------------------------------------------------------------------
 | Author: 张宗强 Email:webmaster@temmoku.cn QQ:158726877 516669373 TEL:17895221001 微信:temmokumvc
 +---------------------------------------------------------------------- 
*/
namespace plugin\friend_link\public_class;
use temmoku\db;
use plugin\friend_link\init;
class cache{
	
	public static function run($data=''){
		self::setting_cache();
		//友情链接
		self::friend_cache();
	}
	
	
	//核心缓存
	public static function setting_cache(){
		
		$data=db::select('*')->from(init::$table."set")->query();
		$datadb=[];
		foreach($data AS $key=>$rs){
			$datadb[$rs['u_key']]=$rs['u_value'];
		}
		$array=['setting'=>$datadb];
		createconf($array,'setting',init::$dir,true);
	}
	
	//友情链接
	public static function friend_cache(){
		$data=db::select('*')->from(init::$table."friend")->WHERE('state=1')->orderByDESC(['reorder'])->query();
		
		$list=[];
		foreach((array)$data AS $key=>$row){
			$row['thumb'] ? $thumb =get_img_url($row['thumb']) :$thumb='';
			$list[$row['cid']][]=[
				'title'=>$row['title'],
				'is_w'=>$row['is_w'],
				'link'=>$row['link'],
				'thumb'=>$thumb
			];
		}
		$array=['friend_list'=>$list];
		createconf($array,'friend_cache');
	}
}
?>