<?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\login\public_class;
use temmoku\db;
use \plugin\login\init;
class cache{
	public static function run($data=''){
		
		self::setting_cache();
		//更多登陆
		self::more_login_list_cache();
		self::import_hook_sql();
	}
	
	//核心缓存
	public static function setting_cache(){
		$data=db::select('*')->from(init::$table."set")->query();
		$list=[];
		foreach((array)$data AS $key=>$row){
			$list[$row['u_key']]=$row['u_value'];
		}
		$array=['login'=>$list];
		createconf($array,'setting',init::$dir,true);
	}
	
	public static function more_login_list_cache(){
		$data=db::select('*')->from(init::$table.'list')->where("is_open=1")->query();
		$list=[];
		foreach($data AS $row){
			if($row['is_son']){
				$loginurl= $row['loginurl'] ? WEBURL."/login/index/vendor/name/$row[initial_name]/".$row['loginurl'] :WEBURL."/login/index/vendor/name/$row[initial_name]/c/index/m/index";
			}else{
				$loginurl=WEBURL.$row['loginurl'];
			}
			$thumb=$row['thumb'] ? get_img_url($row['thumb']) : "";
			
			$list[$row['initial_name']]=[
				'thumb'=>$thumb,
				'is_son'=>$row['is_son'],
				'is_open_window'=>$row['is_open_window'],
				'loginurl'=>$loginurl,
				'name'=>$row['name'],
				'match_field'=>$row['match_field'],
				'setting'=>$row['setting']
			];
		}
		$array=['more_login_list'=>$list];
		createconf($array,'more_login_list',init::$dir,true);
	}
	private static function import_hook_sql(){
		$array=[
			'login_post_begin'=>'登陆插件登陆前',
			'login_post_end'=>'登陆插件登陆后',
			'login_reg_begin'=>'登陆插件注册前',
			'login_reg_end'=>'登陆插件注册后',
			'login_out'=>'登陆插件退出时'
		];
		foreach($array AS $name=>$content){
			$row=db::select('id')->from(jab."hook")->where("name like '$name'")->row();
			if(!$row){
				db::insert(jab."hook")->cols(['name'=>$name,'content'=>$content,'state'=>1])->query();
			}
		}
	}
}
?>