<?php
/**
 * Copyright (C) LJCMS All rights reserved.
 * <E-Mail：aspcms@qq.com>
 * Url http://www.liangjing.org
 *     http://www.8CMS.com
 * Update 2016.03.19
 */

class XOption extends X{
	
    public static function get($optionname){

        $need_unserialize = array(
            'active_plugins', 'site_base', 'upload_config', 
            'index_style', 'main_style', 'order_config', 'site_rewrite', 'wap_config','site_base_en',
        );
        
      
            if (!empty($optionname)){
                    
            $cache = parent::import('cache', 'lib');
            $data = $cache->readCache('options');
           
         
            unset($cache);
            
            
            if (!empty($data)) { 
      
                if (in_array($optionname, $need_unserialize)){
                   
                    parent::loadUtil('handle');
         
                    return XHandle::dounSerialize($data[$optionname]);
                }
                else {
                   
                    return $data[$optionname];
                }
            }
            else {
                
                return array();
            }
		}
	}
	
       public static function get1($optionname){

                $sql = "SELECT * FROM ".DB_PREFIX."options WHERE optionname='$optionname'";
                $data= parent::$obj->fetch_first($sql);
                parent::loadUtil('handle');
                $arr=XHandle::dounSerialize($data['optionvalue']);
                $arr['tjcode']=$data['tjcode'];
                return $arr;
	}
        public static function get2($optionname){
                $sql = "SELECT * FROM ".DB_PREFIX."options WHERE optionname='$optionname'";
                $data= parent::$obj->fetch_first($sql);
                $code=$data['optionvalue'];
               $url="https://www.8cms.cn/api.php?a=is_code&code=$code";
                             $curl = curl_init(); // 启动一个CURL会话
                            curl_setopt($curl, CURLOPT_URL, $url);
                            curl_setopt($curl, CURLOPT_HEADER, 0);
                            curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
                            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
                            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, true);  // 从证书中检查SSL加密算法是否存在
                            $tmpInfo = curl_exec($curl);     //返回api的json对象
                           //关闭URL请求
                            curl_close($curl);
                            $res1= json_decode($tmpInfo,TRUE);    
                           return $res1['slay'];
	}
    
	public static function updateOption($name, $value){
            
		parent::$obj->update(DB_PREFIX."options", array('optionvalue'=>$value), "optionname='{$name}'");
        
        $cache = parent::import('cache', 'lib');
        $cache->updateCache('options');
        unset($cache);
	}
        	public static function updateOption1($name, $value ,$tjcode){
            
		parent::$obj->update(DB_PREFIX."options", array('optionvalue'=>$value, "tjcode"=>$tjcode), "optionname='{$name}'");
        
        $cache = parent::import('cache', 'lib');
        $cache->updateCache('options');
        unset($cache);
	}
           private function curl_get($url){
          //初始化

    }
     
}
?>
