<?php

/* ========================================================================
 * $Id: Recorder.class.php 2380 2018-11-17 16:28:58Z onez $
 * 
 * Email: www@onez.cn
 * QQ: 6200103
 * HomePage: http://www.onezphp.com
 * ========================================================================
 * Copyright 2016-2017 佳蓝科技.
 * 
 * ======================================================================== */

/* PHP SDK
 * @version 2.0.0
 * @author connect@qq.com
 * @copyright © 2013, Tencent Corporation. All rights reserved.
 */

require_once(CLASS_PATH."ErrorCase.class.php");
class Recorder{
    private static $data;
    private $inc;
    private $error;

    public function __construct(){
      global $G;
        $this->error = new ErrorCase();

        //-------读取配置文件
        /*
        $incFileContents = file(ROOT."comm/inc.php");
        $incFileContents = $incFileContents[1];
        $this->inc = json_decode($incFileContents);
        if(empty($this->inc)){
            $this->error->showError("20001");
        }
        //*/
        $sitetoken=onez()->gp('sitetoken');
        if($sitetoken){
          //if(!empty($G['nodes']['data'])){
            $login_qq_appid=onez($sitetoken)->option('login_qq_appid');
          //}
        }
        if($login_qq_appid){
          $this->inc=array(
            'appid'=>$login_qq_appid,
            'appkey'=>onez($sitetoken)->option('login_qq_appkey'),
            'callback'=>onez('login.qq')->url.'/callback.php',
          );
        }else{
          $this->inc=$G['this']->myoption('login_qq_info');
        }
        $this->inc['scope']='get_user_info,add_share,list_album,add_album,upload_pic,add_topic,add_one_blog,add_weibo,check_page_fans,add_t,add_pic_t,del_t,get_repost_list,get_info,get_other_info,get_fanslist,get_idolist,add_idol,del_idol,get_tenpay_addr';
        $this->inc['scope']='get_user_info';
        $this->inc['errorReport']=1;
        $this->inc['storageType']='file';
        $this->inc=json_decode(json_encode($this->inc));
        

        if(empty($_SESSION['QC_userData'])){
            self::$data = array();
        }else{
            self::$data = $_SESSION['QC_userData'];
        }
    }

    public function write($name,$value){
        self::$data[$name] = $value;
    }

    public function read($name){
        if(empty(self::$data[$name])){
            return null;
        }else{
            return self::$data[$name];
        }
    }

    public function readInc($name){
        if(empty($this->inc->$name)){
            return null;
        }else{
            return $this->inc->$name;
        }
    }

    public function delete($name){
        unset(self::$data[$name]);
    }

    function __destruct(){
        $_SESSION['QC_userData'] = self::$data;
    }
}
