<?php

namespace Main\Src;

use Dever;
use Main\Lib\Core;

class Content extends Core
{
    public function test_combine()
    {
        return Dever::load('passport/lib/base')->combine(4, '321313');
    }

    public function test_redis()
    {
        # 测试缓存
        $redis = new \Redis;

        $expire = 3600;

        $key = 'test_';

        $redis->connect('192.168.0.220', '6379');

        for($i=0; $i<= 100;$i++) {
            $redis->set($key . $i, 'key_' . $i . '_value_' . rand(0,10000), $expire);
        }

        for($i=0; $i<= 100;$i++) {
            $data[] = $redis->get($key . $i);
        }

        echo 'ok';die;
    }

    public function test_memcache()
    {
        # 测试缓存
        $cache = new \Memcached;

        $expire = 3600;

        $key = 'test_';

        $cache->addServer('192.168.0.220', '11211', 100);

        for($i=0; $i<= 100;$i++) {
            $cache->set($key . $i, 'key_' . $i . '_value_' . rand(0,10000), $expire);
        }

        for($i=0; $i<= 100;$i++) {
            $data[] = $cache->get($key . $i);
        }

        echo 'ok';die;
    }

    # 开屏广告
    public function ad()
    {
        $this->data['push_screen_ad'] = Dever::load('push/lib/data')->get('app_screen_ad', 'APP开屏广告', 1);

        return $this->data;
    }
    
    # 首页精选
    public function home()
    {
        //MWY2M2MtZThRSG1iR2NHTjV6SjlHUDZvSHNlVURQVkRiT1dtREQxVVA4SThSOEc5bFhnUW43UExo
        //echo Dever::login(96046);die;
        //1 NDY3MmVlOGVsdUxxa2pzNHczckR2TEl1NGFmVmVTd2ItWWhDcDB1T04wdXBDaUpDMl9rRmU4VHM=
        //2 ZTdjNjBHUTY4QUpoZk16QVlZRlg0d3locDFRcll5a3FQcWhFdEo1M1QzaFhmNGhrUlAyTTdGVWc= 
        //9 ZTBiZWN5dW9ublpnSzR2dmlXUUc5MWJJQWk5d3pFQmx0TEp6a0VJVkU4NG5HVTYtcjhFNTdfdnc=
        # 栏目
        //$this->data['push_menu'] = Dever::load('push/lib/data')->get('menu', '头部导航');

        # 小程序去掉视频栏目
        $cate = array();
        //$cate['id_no'] = 2;
        $this->data['menu'] = Dever::db('content/cate')->getAll($cate);

        if ($this->app) {
            # 焦点图
            $this->data['push_focus'] = Dever::load('push/lib/data')->get('app_focus', 'APP精选焦点图');

            # 广告
            $this->data['push_ad'] = Dever::load('push/lib/data')->get('app_ad', 'APP精选广告位');

            # 广告弹窗
            $this->data['push_open_ad'] = Dever::load('push/lib/data')->get('app_open_ad', 'APP精选弹窗广告位');
        } else {
            # 焦点图
            $this->data['push_focus'] = Dever::load('push/lib/data')->get('focus', '精选焦点图');

            # 广告
            $this->data['push_ad'] = Dever::load('push/lib/data')->get('ad', '精选广告位');

            # 广告弹窗
            $this->data['push_open_ad'] = Dever::load('push/lib/data')->get('open_ad', '精选弹窗广告位');
        }
        
        # 开屏广告
        $this->data['push_screen_ad'] = Dever::load('push/lib/data')->get('app_screen_ad', 'APP开屏广告', 1);

        # 推荐位
        $this->data['push_link'] = Dever::load('push/lib/data')->get('link', '精选分类');

        # 精选推荐
        $this->data['push_up'] = Dever::load('push/lib/data')->get('up', '精选推荐');

        $this->news();

        return $this->data;
    }

    # 精选推荐更多
    public function up()
    {
    	$this->data['push_up'] = Dever::load('push/lib/data')->get('up', '精选推荐', 10, true);

    	return $this->data;
    }

    # 下拉更多
    public function news()
    {
    	# 直接从已审核的列表中读取
    	$this->data['news'] = array();

        $cate = Dever::input('menu');
        $where = array();
        if ($cate > 0) {
            $where['cate_id'] = $cate;
        }

        $type = Dever::input('type');
        if ($type > 0) {
            $where['type'] = $type;
        }

        if (checkVersion()->video == 2) {
            $where['type_no'] = 2;
        }

    	$data = Dever::db('audit/data')->getAll($where);
        if ($data) {
            foreach ($data as $k => $v) {
                $data[$k] = $this->content($v);
            }
            $this->data['news'] = $data;
        } else {
            $this->data['news'] = array();
        }

        return $this->data;
    }
}