<?php

namespace H5\Src;

use Dever;
use Main\Lib\Core;

class View extends Core
{
    # 根据类型，获取详情的html页面
    public function get()
    {
        $type = Dever::input('type');
        $id = Dever::input('id');
        $signature = Dever::input('signature');
        $data = array();
        $template = false;
        switch($type) {
            case 1:
                $data = Dever::load('main/view')->article();
                $template = 'article';
                break;
            case 2:
                $data = Dever::load('main/view')->vod();
                $template = 'video';
                break;
            case 3:
                $data = Dever::load('main/view')->live();
                $template = 'live';
                break;
            case 4:
                Dever::alert('错误的数据');
                # 这个有点特殊
                $info = Dever::db('journal/content')->one($id);
                if (!$info) {
                    Dever::alert('错误的数据');
                }
                $data = Dever::load('main/journal')->readContent($info);
                break;
            case 6:
                $data = Dever::load('main/view')->feature();
                $template = 'feature';
                break;
        }

        if ($data && $template) {
            if (isset($data['info']['content_array'])) {
                $data['content'] = $data['info']['content_array'];
            } elseif (isset($data['info']['content'])) {
                $data['content'][] = array
                (
                    'type' => 1,
                    'content' => $data['info']['content']
                );
            }

            # 应用宝地址
            $data['app'] = 'http://t.cn/ELf3Waq';
            $data['type'] = $type;

            if (isset($data['relation'][3])) {
                unset($data['relation'][3]);
            }

            if (isset($data['comment'])) {
                $comment = $data['comment'];
                $data['comment'] = array();
                foreach ($comment as $k => $v) {
                    if ($k <= 2) {
                        $data['comment'][$k] = $v;
                    }
                }
            }

            if (isset($data['info']['function'])) {
                $data['info']['function'] = explode(',', $data['info']['function']);
            }

            return Dever::render($template, $data);
        } else {
            Dever::alert('错误的数据');
        }
    }
}