<?php
/**
 * 导演模块
 * @author reginx.com
 * $Id$
 */
class dir_mod extends mogvs_mod {

    /**
     * 导演页
     *
     * @param unknown_type $p1
     * @param unknown_type $p2
     */
    public function __call($p1, $p2){
        $str = urldecode(substr($p1, 0, -3));
        // 检测内容编码,确定浏览器类型
        $ie = strtolower(mb_convert_variables('utf-8', 'utf-8,gbk,gb2312,cp936', $str)) != 'utf-8';
        // 浏览器提交中文方式适配
        if($ie){
            $str = mb_convert_encoding($str, 'utf-8', mb_convert_variables('utf-8', 'utf-8,gbk,gb2312,cp936', $str));
        }
        
        $str = filter::text($str);
        
        // 格式验证
        if(!preg_match('/^[\w\_\x{4e00}-\x{9fa5}\·]+$/ui', $str)){
            $this->show404(1 , '参数错误了...');
        }

        $actor = core::getobj('tag_tab')->where("name = '$str'")->get();
        // 不存在
        if(empty($actor)){
            $this->show404(1 , '未找到该记录...');
        }
        $obj = core::getobj('tag_list_tab');
        $obj->where("tagid = {$actor['id']} and ctype = 2 ")->keep();
        $pobj = new page_lib($obj->count(), 'pn', intval($this->get('pn')), 12);
        $obj->clear('fields');
        $obj->fields('vod_tab.id as vid , vod_tab.sname , vod_tab.name ,vod_tab.region , vod_tab.region, vod_tab.cover,vod_tab.cat,vod_tab.actor,vod_tab.desc');
        $obj->leftjoin('vod_tab', 'refid', 'id')->limit($pobj->limit);
        $obj->order('vod_tab.udate ' . ($pobj->rev ? 'asc' : 'desc'));
        $ret['pobj'] = $pobj->toarray();
        $ret['data'] = $pobj->rev ? array_reverse($obj->getall()) : $obj->getall();
        $acts = null;
        // 演员 链接地址转换
        if(isset($this->conf['utype']) && !$this->conf['utype']){
            foreach ((array)$ret['data'] as $k => $v){
                $ret['data'][$k]['sname'] = $v['vid'];
                if(!empty($v['actor'])){
                    $acts .= empty($acts) ? $v['actor'] : (',' . $v['actor']);
                }
            }
            // Query Actors
            if(!empty($acts)){
                $acts   = array_unique(explode(',' , $acts));
                $actstr = join("','" , $acts);
                $actors   = core::getobj('tag_tab')->fields("id,name")->where("name in ('$actstr')")->order("field(name , '$actstr')")->getall();
                foreach ($ret['data'] as $k => $v){
                    $temp = explode(',' , $v['actor']);
                    $ret['data'][$k]['actor'] = array();
                    foreach ($temp as $av){
                        $i = array_search($av , $acts);
                        if($i !== false){
                            $ret['data'][$k]['actor'][] = $actors[$i];
                        }
                    }
                    $temp = array();
                }
                $acts = $actstr = $actors = null;
            }
        }else{
            foreach ((array)$ret['data'] as $k => $v){
                if(!empty($v['actor'])){
                    $ret['data'][$k]['actor'] = explode(',' , $v['actor']);
                }
            }
        }
        $this->assign('list', $ret);
        $this->assign('actor', $actor);
        $this->assign('skey', $actor['name'] . ',' . $actor['name'] . '电影,' . $actor['name'] . '最新电影');
        $this->assign('sdesc', $actor['name'] . '的电影 ,' . $actor['name'] . '导演的电影');
        $this->assign('urhere', array(
            'cur' => "导演 [&nbsp;" . $actor['name'] . "&nbsp;]"
        ));
        $this->assign('regions', api_lib::getregion());
        $this->assign('cats', api_lib::getallcat(2));
        $this->assign('ptitle', $actor['name'] . '_导演的电影 - ' . $actor['name'] . '在线播放');
        $this->display('tag/dir.tpl.html');
    }
}
?>