Пример #1
0
 function mark_sql()
 {
     global $MAC, $MAC_CACHE;
     $labelRule = buildregx("([a-z0-9]+)=([\\x{4e00}-\\x{9fa5}|a-zA-Z0-9|,|\$|.|+|-]+)", "") . "u";
     preg_match_all($labelRule, $this->markpar, $matches);
     $this->L = array();
     $lp = array();
     for ($j = 0; $j < count($matches[0]); $j++) {
         $parname = $matches[1][$j];
         $parval = $matches[2][$j];
         $lp[$parname] = $parval;
     }
     if (empty($lp['table'])) {
         $lp['table'] = 'vod';
     }
     if (empty($lp['type'])) {
         $lp['type'] = 'all';
     }
     if ($lp['order'] != 'asc' && $lp['order'] != 'desc') {
         $lp['order'] = 'asc';
     }
     unset($matches);
     if (!isNum($lp['start'])) {
         $lp['start'] = 0;
     } else {
         $lp['start'] = intval($lp['start']);
     }
     if ($lp['start'] > 0) {
         $lp['start']--;
     }
     if (!isNum($lp['num'])) {
         $lp['num'] = 12;
     } else {
         $lp['limit'] = 'true';
         $lp['num'] = intval($lp['num']);
     }
     if (!empty($lp['label'])) {
         $this->P['label'] = $lp['label'];
     }
     if (!empty($lp["pagesize"])) {
         $auto = '';
         $lp['num'] = intval($lp['pagesize']);
     } else {
         $auto = 'false';
     }
     $order = ' ORDER BY ';
     $limit = ' limit 0,' . ($lp['num'] + $lp['start']);
     //echo $limit . "<br>";
     switch ($this->markname) {
         case 'link':
             $tb = 'link';
             $col = '`l_id`, `l_name`, `l_url`, `l_logo`, `l_type`, `l_sort`';
             if ($lp['limit'] == '') {
                 $limit = '';
             }
             switch ($lp['by']) {
                 case 'id':
                     $order .= ' l_id ';
                     break;
                 default:
                     $order .= ' l_sort ';
                     break;
             }
             $order .= $lp['order'];
             if ($lp['type'] == 'all') {
             } else {
                 $where .= $lp['type'] == 'pic' ? ' AND l_type=1 ' : " AND l_type=0 ";
             }
             break;
         case 'gbook':
             $tb = 'gbook';
             $col = '`g_id`, `g_vid`, `g_hide`, `g_name`, `g_content`, `g_reply`, `g_ip`, `g_time`, `g_replytime`';
             switch ($lp['by']) {
                 case 'id':
                     $order .= ' g_id ';
                     break;
                 default:
                     $order .= ' g_time ';
                     break;
             }
             $order .= $lp['order'];
             $where .= ' AND g_hide=0 ';
             if (!empty($this->P['wd'])) {
                 $where .= ' AND instr(g_name,\'' . $this->P['wd'] . '\')>0 ';
             }
             $this->P['pageflag'] = '';
             $this->P['pagetype'] = 'gbook';
             $limitstart = $lp['num'] * ($this->P['pg'] - 1);
             $limit = ' limit ' . $limitstart . ',' . ($lp['num'] + $lp['start']);
             break;
         case 'comment':
             $tb = 'comment';
             $col = '`c_id`, `c_vid`, `c_hide`, `c_name`, `c_content`, `c_ip`, `c_time`, `c_type`';
             switch ($lp['by']) {
                 case 'id':
                     $order .= ' c_id ';
                     break;
                 default:
                     $order .= ' c_time ';
                     break;
             }
             $order .= $lp['order'];
             $where .= ' AND c_hide=0 ';
             if (!empty($lp['type'])) {
                 if ($lp['type'] != 'all') {
                     $where .= ' AND c_type in (' . $lp['type'] . ') ';
                 }
             }
             if ($lp['vid'] == 'current') {
                 if ($this->C["siteaid"] == 16) {
                     $where .= ' AND c_type=16 and c_vid=' . $this->D['d_id'];
                 } elseif ($this->C["siteaid"] == 26) {
                     $where .= ' AND c_type=26 and c_vid=' . $this->D['a_id'];
                 }
             }
             $this->P['pageflag'] = '';
             $this->P['pagetype'] = 'comment';
             $limitstart = $lp['num'] * ($this->P['pg'] - 1);
             $limit = ' limit ' . $limitstart . ',' . ($lp['num'] + $lp['start']);
             break;
         case 'matrix':
         case 'menu':
             $tb = $lp['table'] . '_type';
             $col = ' `t_id`, `t_name`, `t_enname`,  `t_pid`, `t_sort`, `t_hide`, `t_tpl`, `t_key`, `t_des` ';
             if ($lp['limit'] == '') {
                 $limit = '';
             }
             switch ($lp['by']) {
                 case 'id':
                     $order .= ' t_id ';
                     break;
                 default:
                     $order .= ' t_sort ';
                     break;
             }
             $order .= $lp['order'];
             $where .= ' AND t_hide=0 ';
             if ($lp['type'] == 'tag') {
                 return;
             } elseif ($lp['type'] == 'all') {
             } elseif ($lp['type'] == 'parent') {
                 $where .= ' AND t_pid =0 ';
             } elseif ($lp['type'] == 'child') {
                 $where .= ' AND t_pid >0 ';
             } elseif ($lp['type'] == 'auto') {
                 if (!is_array($this->T)) {
                     $where .= " AND t_pid >0 ";
                 } else {
                     $this->P["auto"] = true;
                     if ($this->T['t_pid'] == 0) {
                         $where .= " AND t_pid = " . $this->T["t_id"];
                     } else {
                         $where .= " AND t_pid = " . $this->T["t_pid"];
                     }
                 }
             } elseif (!empty($lp['type'])) {
                 $where .= ' AND t_id IN(' . $lp['type'] . ') ';
             }
             if ($lp['parent'] == 'all') {
                 $where .= ' AND t_pid =0 ';
             } elseif ($lp['parent'] != '') {
                 $where .= ' AND t_pid IN(' . $lp['parent'] . ') ';
             }
             if ($lp['table'] == 'vod') {
                 $col .= ',`t_tpl_vod`, `t_tpl_play`, `t_tpl_down` ';
                 if ($GLOBALS['MAC']['user']['status'] == 1) {
                     $where .= getTypeByPopedomFilter('menu');
                 }
             } else {
                 $col .= ',`t_tpl_art`';
             }
             break;
         case 'topic':
             $tb = $lp['table'] . '_topic';
             $col = '`t_id`, `t_name`, `t_enname`,`t_sort`, `t_level`, `t_pic`,`t_key` ,`t_des`,`t_title`,`t_content`,`t_hits`,`t_dayhits`,`t_weekhits`,`t_monthhits`,`t_up`,`t_down`,`t_score`,`t_scoreall`,`t_scorenum`,`t_addtime`,`t_time` ';
             switch ($lp['by']) {
                 case "id":
                     $order .= " t_id ";
                     break;
                 case "hits":
                     $order .= " t_hits ";
                     break;
                 case "dayhits":
                     $order .= " t_dayhits ";
                     break;
                 case "weekhits":
                     $order .= "  t_weekhits ";
                     break;
                 case "monthhits":
                     $order .= " t_monthhits ";
                     break;
                 case "addtime":
                     $order .= " t_addtime ";
                     break;
                 case "level":
                     $order .= " t_level ";
                     break;
                 case "up":
                     $order .= " t_up ";
                     break;
                 case "down":
                     $order .= " t_down ";
                     break;
                 default:
                     $order .= " t_time ";
                     break;
             }
             $order .= $lp['order'];
             $where .= ' AND t_hide=0 ';
             if (!empty($lp['id']) && $lp['id'] != "all") {
                 $where = $where . ' AND t_id IN(' . $lp['id'] . ') ';
             }
             if ($auto == '') {
                 $this->P['pageflag'] = $lp['table'];
                 $this->P['pagetype'] = 'topicindex';
                 $limitstart = $lp['num'] * ($this->P['pg'] - 1);
                 $limit = ' limit ' . $limitstart . ',' . ($lp['num'] + $lp['start']);
             }
             break;
         case 'class':
             $tb = 'vod_class';
             $col = ' `c_id`, `c_name`, `c_pid`, `c_sort`, `c_hide` ';
             if ($lp['limit'] == '') {
                 $limit = '';
             }
             switch ($lp['by']) {
                 case 'id':
                     $order .= ' c_id ';
                     break;
                 default:
                     $order .= ' c_sort ';
                     break;
             }
             $order .= $lp['order'];
             $where .= ' AND c_hide=0 ';
             if ($lp['type'] == 'auto') {
                 if (is_array($this->T)) {
                     $this->P["auto"] = true;
                     if ($this->T['t_pid'] == 0) {
                         $where .= " AND c_pid = " . $this->T["t_id"];
                     } else {
                         $where .= " AND c_pid = " . $this->T["t_pid"];
                     }
                 }
             } elseif ($lp['type'] != '' && $lp['type'] != 'all') {
                 $where .= ' AND c_pid IN(' . $lp['type'] . ') ';
             }
             if (!empty($lp['id'])) {
                 $where .= ' AND c_id IN(' . $lp['id'] . ') ';
             }
             break;
         case 'vod':
             $tb = 'vod';
             $col = '`d_id`, `d_name`, `d_subname`, `d_enname`, `d_letter`, `d_color`, `d_pic`, `d_picthumb`, `d_picslide`, `d_starring`, `d_directed`, `d_tag`, `d_remarks`, `d_area`, `d_lang`, `d_year`, `d_type`, `d_class`, `d_hide`, `d_lock`, `d_state`, `d_level`, `d_usergroup`, `d_stint`, `d_stintdown`, `d_hits`, `d_dayhits`, `d_weekhits`, `d_monthhits`, `d_duration`, `d_up`, `d_down`, `d_score`,`d_scoreall`, `d_scorenum`, `d_addtime`, `d_time`, `d_hitstime`, `d_maketime`, `d_playfrom`, `d_playserver`, `d_playnote`,`d_downfrom`, `d_downserver`, `d_downnote` ';
             if (strpos($this->markdes, ':content') > 0) {
                 $col .= ', `d_content`';
             }
             if (!empty($this->P["order"])) {
                 $lp['order'] = $this->P["order"];
                 $this->P["auto"] = true;
             }
             if (!empty($this->P["by"])) {
                 $lp['by'] = $this->P["by"];
                 $this->P["auto"] = true;
             }
             if (!empty($lp['pagesize'])) {
                 if (!empty($this->P["area"])) {
                     $lp['area'] = $this->P["area"];
                     $this->P["auto"] = true;
                 }
                 if (!empty($this->P["year"])) {
                     $lp['year'] = $this->P["year"];
                     $this->P["auto"] = true;
                 }
                 if (!empty($this->P["lang"])) {
                     $lp['lang'] = $this->P["lang"];
                     $this->P["auto"] = true;
                 }
                 if (!empty($this->P["letter"])) {
                     $lp['letter'] = $this->P["letter"];
                     $this->P["auto"] = true;
                 }
                 if (!empty($this->P["class"])) {
                     $lp['class'] = $this->P["class"];
                     $this->P["auto"] = true;
                 }
                 if (!empty($this->P["wd"])) {
                     $lp['wd'] = $this->P["wd"];
                     $this->P["auto"] = true;
                 }
                 if (!empty($this->P["pinyin"])) {
                     $lp['enname'] = $this->P["pinyin"];
                     $this->P["auto"] = true;
                 }
                 if (!empty($this->P["tag"])) {
                     $lp['tag'] = $this->P["tag"];
                     $this->P["auto"] = true;
                 }
                 if (!empty($this->P["starring"])) {
                     $lp['starring'] = $this->P["starring"];
                     $this->P["auto"] = true;
                 }
                 if (!empty($this->P["directed"])) {
                     $lp['directed'] = $this->P["directed"];
                     $this->P["auto"] = true;
                 }
                 if (!empty($this->P["typeid"])) {
                     $lp['type'] = $this->P["typeid"];
                     $this->P["auto"] = true;
                 }
                 if (!empty($this->P["classid"])) {
                     $lp['class'] = $this->P["classid"];
                     $this->P["auto"] = true;
                 }
                 if (!empty($this->P["ids"])) {
                     $lp['ids'] = $this->P["ids"];
                 }
             }
             switch ($lp['by']) {
                 case "id":
                     $order .= " d_id ";
                     break;
                 case "hits":
                     $order .= " d_hits ";
                     break;
                 case "dayhits":
                     $order .= " d_dayhits ";
                     break;
                 case "weekhits":
                     $order .= "  d_weekhits ";
                     break;
                 case "monthhits":
                     $order .= " d_monthhits ";
                     break;
                 case "addtime":
                     $order .= " d_addtime ";
                     break;
                 case "level":
                     $order .= " d_level ";
                     break;
                 case "up":
                     $order .= " d_up ";
                     break;
                 case "down":
                     $order .= " d_down ";
                     break;
                 case "score":
                     $order .= " d_score ";
                     break;
                 case "scoreall":
                     $order .= " d_scoreall ";
                     break;
                 case "scorenum":
                     $order .= " d_scorenum ";
                     break;
                 case "rnd":
                     $datacount = $this->getDataCount('vod', 'all');
                     $maxi = $datacount - $lp['num'];
                     if ($maxi < 0) {
                         $maxi = 0;
                     }
                     $randi = @mt_rand(0, $maxi);
                     if ($randi < 0) {
                         $randi = 0;
                     }
                     $where .= ' AND d_id >=' . $randi;
                     $order .= " d_time ";
                     $lp['order'] = 'asc';
                     break;
                 default:
                     $order .= " d_time ";
                     break;
             }
             switch ($lp['order']) {
                 case "desc":
                     break;
                 default:
                     $lp['order'] = 'asc';
                     break;
             }
             $order .= $lp['order'];
             $where .= ' AND d_hide=0 AND d_type>0 ';
             if ($lp['state'] == 'series') {
                 $where .= ' and d_state > 0';
             } elseif (isNum($lp['state'])) {
                 $where .= ' and d_state = ' . $lp['state'];
             }
             if (!empty($lp['level'])) {
                 if ($lp['level'] != 'all') {
                     $where .= ' and d_level in(' . $lp['level'] . ')';
                 } else {
                     $where .= ' and d_level >0';
                 }
             }
             if (!empty($lp['year'])) {
                 $where .= ' and d_year=' . $lp['year'] . '';
             }
             if (!empty($lp['letter'])) {
                 $where .= ' and d_letter=\'' . $lp['letter'] . '\'';
             }
             if (!empty($lp['day'])) {
                 $symbol = '';
                 if (strpos(',' . $lp['day'], '+')) {
                     $symbol = '+';
                 } elseif (strpos(',' . $lp['day'], '-') == false) {
                     $symbol = '-';
                 }
                 $todaydate = date('Y-m-d');
                 $tommdate = date('Y-m-d', strtotime($symbol . $lp['day'] . ' day'));
                 $tommunix = strtotime($tommdate);
                 $todayunix = $tommunix + 86400;
                 $where .= ' AND ( d_time>' . $tommunix . ' AND d_time<' . $todayunix . ') ';
             }
             if (!empty($lp['days'])) {
                 $symbol = '-';
                 if (strpos(',' . $lp['days'], '+')) {
                     $symbol = '+';
                 }
                 $todaydate = date('Y-m-d');
                 $tommdate = date('Y-m-d', strtotime($symbol . $lp['days'] . ' day'));
                 $todayunix = strtotime($todaydate);
                 $tommunix = strtotime($tommdate);
                 $where .= ' AND d_time>' . $tommunix;
             }
             if (!empty($lp['area'])) {
                 $where .= ' and d_area=\'' . $lp['area'] . '\'';
             }
             if (!empty($lp['lang'])) {
                 $where .= ' and d_lang=\'' . $lp['lang'] . '\'';
             }
             if ($auto == '') {
                 $this->P['pageflag'] = 'vod';
                 $limitstart = $lp['num'] * ($this->P['pg'] - 1);
                 $limit = ' limit ' . $limitstart . ',' . ($lp['num'] + $lp['start']);
                 if ($this->P['vodtypeid'] != -1) {
                     $typearr = $MAC_CACHE['vodtype'][$this->P['vodtypeid']];
                     $expand = '';
                     $where .= ' AND ( d_type IN (' . $typearr['childids'] . ') ' . $expand . ' )';
                     $this->P['pagetype'] = 'type';
                     if ($GLOBALS['method'] != 'type') {
                         $this->P['pagetype'] = 'list';
                     }
                     $this->P['maxpage'] = $lp['maxpage'];
                 } elseif ($this->P['vodtopicid'] != -1) {
                     $where .= ' AND d_id IN(select r_b from {pre}vod_relation where r_type=2 and r_a=' . $this->P['vodtopicid'] . ')';
                     $this->P['pagetype'] = 'topic';
                 } elseif (!empty($lp['label'])) {
                     $this->P['pageflag'] = $lp['label'];
                     $this->P['pagetype'] = 'label';
                 } else {
                     //$where = $this->P['where'];
                     if (!empty($this->P['des'])) {
                         $this->P['pagetype'] = 'search';
                     }
                 }
             } else {
                 if (!empty($lp['type'])) {
                     if ($lp['type'] != 'all') {
                         if ($lp['type'] == 'current' && $this->P['vodtypeid'] > -1) {
                             $typearr = $MAC_CACHE['vodtype'][$this->P['vodtypeid']];
                             $where .= ' and d_type in (' . $typearr['childids'] . ')';
                         } else {
                             if (strpos($lp['type'], ',') > 0) {
                                 $where .= ' and d_type in (' . $lp['type'] . ')';
                             } else {
                                 $typearr = $MAC_CACHE['vodtype'][$lp['type']];
                                 if (is_array($typearr)) {
                                     $where .= ' and d_type in (' . $typearr['childids'] . ')';
                                 }
                             }
                         }
                     }
                 }
                 if (!empty($lp['topic'])) {
                     if ($lp['topic'] != 'all') {
                         if ($lp['topic'] == 'current' && $this->P['vodtopicid'] > -1) {
                             $where .= ' AND d_id IN(select r_b from {pre}vod_relation where r_type=2 and r_a=' . $this->P['vodtopicid'] . ')';
                             ' and d_topic in (' . $this->P['vodtopicid'] . ')';
                         } else {
                             $where .= ' AND d_id IN(select r_b from {pre}vod_relation where r_type=2 and r_a in (' . $lp['topic'] . '))';
                         }
                     }
                 }
             }
             if (!empty($lp['id'])) {
                 $where .= ' AND d_id IN(' . $lp['id'] . ') ';
             }
             if (!empty($lp['ids'])) {
                 $where .= ' AND d_id IN(' . $lp['ids'] . ') ';
             }
             if ($GLOBALS['MAC']['view']['vodtype'] != 2 && $GLOBALS['MAC']['user']['status'] == 1) {
                 $where .= getTypeByPopedomFilter('vod');
             }
             if (!empty($lp['class'])) {
                 $where .= ' AND instr(d_class,\',' . $lp['class'] . ',\')>0  ';
             }
             if (!empty($lp['enname'])) {
                 $where .= ' AND instr(d_enname,\'' . $lp['enname'] . '\')>0  ';
             }
             if (!empty($lp['starring'])) {
                 $where .= ' AND instr(d_starring,\'' . $lp['starring'] . '\')>0  ';
             }
             if (!empty($lp['directed'])) {
                 $where .= ' AND instr(d_directed,\'' . $lp['directed'] . '\')>0  ';
             }
             if (!empty($lp['tag'])) {
                 $where .= ' AND instr(d_tag,\'' . $lp['tag'] . '\')>0  ';
             }
             if (!empty($lp['wd'])) {
                 $where .= ' AND ( instr(d_name,\'' . $lp['wd'] . '\')>0 or instr(d_starring,\'' . $lp['wd'] . '\')>0 ) ';
             }
             if (!empty($lp['similar']) && is_array($this->P['similar'])) {
                 switch ($lp['similar']) {
                     case "name":
                         $cola = 'name';
                         break;
                     case "tag":
                         $cola = 'tag';
                         break;
                     case "directed":
                         $cola = 'directed';
                         break;
                     default:
                         $cola = 'starring';
                         break;
                 }
                 $vala = $this->P['similar'][$cola];
                 $vala = str_replace(array(",", "'"), array(" ", "''"), $vala);
                 $tmp = explode(" ", $vala);
                 $tmp = array_filter($tmp);
                 $rc = false;
                 $where2 = "";
                 if (count($tmp) > 0) {
                     foreach ($tmp as $tt) {
                         if ($rc) {
                             $where2 .= " or ";
                         }
                         $where2 .= " d_{$cola} like '%" . $tt . "%' ";
                         $rc = true;
                     }
                     if ($rc) {
                         $where .= " AND (" . $where2 . ") and d_id <> " . intval($this->D['d_id']) . " ";
                     }
                 }
                 unset($tmp);
             }
             break;
         case 'art':
             $tb = 'art';
             $col = '`a_id`, `a_name`, `a_subname`, `a_enname`, `a_letter`, `a_color`, `a_from`, `a_author`, `a_tag`, `a_pic`, `a_type`, `a_level`, `a_hide`, `a_lock`, `a_hits`, `a_dayhits`, `a_weekhits`, `a_monthhits`, `a_addtime`, `a_time`, `a_hitstime`, `a_maketime`';
             if (strpos($this->markdes, ':content') > 0) {
                 $col .= ', `a_content`';
             }
             if (!empty($this->P["order"])) {
                 $lp['order'] = $this->P["order"];
                 $this->P["auto"] = true;
             }
             if (!empty($this->P["by"])) {
                 $lp['by'] = $this->P["by"];
                 $this->P["auto"] = true;
             }
             if (!empty($lp['pagesize'])) {
                 if (!empty($this->P["letter"])) {
                     $lp['letter'] = $this->P["letter"];
                     $this->P["auto"] = true;
                 }
                 if (!empty($this->P["wd"])) {
                     $lp['wd'] = $this->P["wd"];
                     $this->P["auto"] = true;
                 }
                 if (!empty($this->P["pinyin"])) {
                     $lp['enname'] = $this->P["pinyin"];
                     $this->P["auto"] = true;
                 }
                 if (!empty($this->P["tag"])) {
                     $lp['tag'] = $this->P["tag"];
                     $this->P["auto"] = true;
                 }
                 if (!empty($this->P["typeid"])) {
                     $lp['type'] = $this->P["typeid"];
                     $this->P["auto"] = true;
                 }
                 if (!empty($this->P["ids"])) {
                     $lp['ids'] = $this->P["ids"];
                 }
             }
             switch ($lp['by']) {
                 case 'id':
                     $order .= ' a_id ';
                     break;
                 case 'level':
                     $order .= ' a_level ';
                     break;
                 case 'hits':
                     $order .= ' a_hits ';
                     break;
                 case 'dayhits':
                     $order .= ' a_dayhits ';
                     break;
                 case 'weekhits':
                     $order .= ' a_weekhits ';
                     break;
                 case 'monthhits':
                     $order .= ' a_monthhits ';
                     break;
                 case 'addtime':
                     $order .= ' a_addtime ';
                     break;
                 case 'level':
                     $order .= ' a_level ';
                     break;
                 case 'up':
                     $order .= ' a_up ';
                     break;
                 case 'down':
                     $order .= ' a_down ';
                     break;
                 case 'rnd':
                     $datacount = $this->getDataCount('art', 'all');
                     $maxi = $datacount - $lp['num'];
                     if ($maxi < 0) {
                         $maxi = 0;
                     }
                     $randi = @mt_rand(0, $maxi);
                     if ($randi < 0) {
                         $randi = 0;
                     }
                     $where .= ' AND a_id >=' . $randi;
                     $order .= ' a_time ';
                     $lp['order'] = 'asc';
                     break;
                 default:
                     $order .= ' a_time ';
                     break;
             }
             switch ($lp['order']) {
                 case "desc":
                     break;
                 default:
                     $lp['order'] = 'asc';
                     break;
             }
             $order .= $lp['order'];
             $where .= ' AND a_hide=0 AND a_type>0 ';
             if (!empty($lp['level'])) {
                 if ($lp['level'] != 'all') {
                     $where .= ' and a_level in(' . $lp['level'] . ')';
                 } else {
                     $where .= ' and a_level >0';
                 }
             }
             if (!empty($lp['letter'])) {
                 $where .= ' and a_letter=\'' . $lp['letter'] . '\'';
             }
             if (!empty($lp['day'])) {
                 $symbol = '';
                 if (strpos(',' . $lp['day'], '+')) {
                     $symbol = '+';
                 } elseif (strpos(',' . $lp['day'], '-') == false) {
                     $symbol = '-';
                 }
                 $todaydate = date('Y-m-d');
                 $tommdate = date('Y-m-d', strtotime($symbol . $lp['day'] . ' day'));
                 $tommunix = strtotime($tommdate);
                 $todayunix = $tommunix + 86400;
                 $where .= ' AND ( a_time>' . $tommunix . ' AND a_time<' . $todayunix . ') ';
             }
             if (!empty($lp['days'])) {
                 $symbol = '-';
                 if (strpos(',' . $lp['days'], '+')) {
                     $symbol = '+';
                 }
                 $todaydate = date('Y-m-d');
                 $tommdate = date('Y-m-d', strtotime($symbol . $lp['days'] . ' day'));
                 $todayunix = strtotime($todaydate);
                 $tommunix = strtotime($tommdate);
                 $where .= ' AND a_time>' . $tommunix;
             }
             if ($auto == '') {
                 $this->P['pageflag'] = 'art';
                 $limitstart = $lp['num'] * ($this->P['pg'] - 1);
                 $limit = ' limit ' . $limitstart . ',' . ($lp['num'] + $lp['start']);
                 if ($this->P['arttypeid'] != -1) {
                     $typearr = $MAC_CACHE['arttype'][$this->P['arttypeid']];
                     $where .= ' AND a_type IN (' . $typearr['childids'] . ')';
                     $this->P['pagetype'] = 'type';
                     if ($GLOBALS['method'] != 'type') {
                         $this->P['pagetype'] = 'list';
                     }
                     $this->P['maxpage'] = $lp['maxpage'];
                 } elseif ($this->P['arttopicid'] != -1) {
                     $where .= ' AND a_id IN(select r_b from {pre}art_relation where r_type=2 and r_a=' . $this->P['arttopicid'] . ')';
                     $this->P['pagetype'] = 'topic';
                 } else {
                     //$where = $this->P['where'];
                     if (!empty($this->P['des'])) {
                         $this->P['pagetype'] = 'search';
                     }
                 }
             } else {
                 if (!empty($lp['type'])) {
                     if ($lp['type'] != 'all') {
                         if ($lp['type'] == 'current' && $this->P['arttypeid'] > -1) {
                             $typearr = $MAC_CACHE['arttype'][$this->P['arttypeid']];
                             $where .= ' and a_type in (' . $typearr['childids'] . ')';
                         } else {
                             if (strpos($lp['type'], ',') > 0) {
                                 $where .= ' and a_type in (' . $lp['type'] . ')';
                             } else {
                                 $typearr = $MAC_CACHE['arttype'][$lp['type']];
                                 if (is_array($typearr)) {
                                     $where .= ' and a_type in (' . $typearr['childids'] . ')';
                                 }
                             }
                         }
                     }
                 }
                 if (!empty($lp['topic'])) {
                     if ($lp['topic'] != 'all') {
                         if ($lp['topic'] == 'current' && $this->P['arttopicid'] > -1) {
                             $where .= ' AND a_id IN(select r_b from {pre}art_relation where r_type=2 and r_a=' . $this->P['arttopicid'] . ')';
                         } else {
                             $where .= ' AND a_id IN(select r_b from {pre}art_relation where r_type=2 and r_a in(' . $lp['topic'] . '))';
                         }
                     }
                 }
             }
             if (!empty($lp['id'])) {
                 $where .= ' AND a_id IN(' . $lp['id'] . ') ';
             }
             if (!empty($lp['ids'])) {
                 $where .= ' AND a_id IN(' . $lp['ids'] . ') ';
             }
             if (!empty($lp['enname'])) {
                 $where .= ' AND instr(a_enname,\'' . $lp['enname'] . '\')>0  ';
             }
             if (!empty($lp['tag'])) {
                 $where .= ' AND instr(a_tag,\'' . $lp['tag'] . '\')>0  ';
             }
             if (!empty($lp['similar']) && is_array($this->P['similar'])) {
                 switch ($lp['similar']) {
                     case "name":
                         $cola = 'name';
                         break;
                     default:
                         $cola = 'tag';
                         break;
                 }
                 $vala = $this->P['similar'][$cola];
                 $vala = str_replace(array(",", "'"), array(" ", "''"), $vala);
                 $tmp = explode(" ", $vala);
                 $tmp = array_filter($tmp);
                 $rc = false;
                 $where2 = "";
                 if (count($tmp) > 0) {
                     foreach ($tmp as $tt) {
                         if ($rc) {
                             $where2 .= " or ";
                         }
                         $where2 .= " a_{$cola} like '%" . $tt . "%' ";
                         $rc = true;
                     }
                     if ($rc) {
                         $where .= " AND (" . $where2 . ") and a_id <> " . intval($this->D['a_id']) . " ";
                     }
                 }
                 unset($tmp);
             }
             break;
     }
     $this->L = $lp;
     unset($lp);
     $this->sql = 'SELECT ' . $col . ' FROM {pre}' . $tb . ' WHERE 1=1 ' . $where . $order . $limit;
     $this->sql1 = 'SELECT count(*) FROM {pre}' . $tb . ' WHERE 1=1 ' . $where;
     if ($this->markname == 'vod') {
         //echo $this->sql .'<br>';
         //exit;
     }
 }
Пример #2
0
 function vodpagelist()
 {
     global $db, $mac, $cache;
     if (indexOf($this->html, "[pagelist:content")) {
         $field_des = "d_content";
     } else {
         $field_des = "0";
     }
     $labelRule = buildregx("{joyplus:vodpagelist([\\s\\S]*?)}([\\s\\S]*?){/joyplus:vodpagelist}", "");
     preg_match_all($labelRule, $this->html, $matches1);
     if (isN($this->page)) {
         $this->page = $mac["page"];
     }
     for ($i = 0; $i < count($matches1[0]); $i++) {
         $markpar = $matches1[1][$i];
         $this->markdes = $matches1[2][$i];
         $this->markval = $matches1[0][$i];
         $labelRule = buildregx("([a-z0-9]+)=([\\x{4e00}-\\x{9fa5}|a-z0-9|,|\$|.]+)", "") . "u";
         preg_match_all($labelRule, $markpar, $matches2);
         $this->getParam($matches2);
         $sql = "SELECT d_id,d_name,d_subname,d_enname,d_type,d_letter,d_state,d_color,d_pic,d_starring,d_directed,d_area,";
         $sql = $sql . "d_year,d_language,d_level,d_stint,d_hits,d_dayhits,d_weekhits,d_monthhits,d_topic," . $field_des . ",";
         $sql = $sql . "d_remarks,d_good,d_bad,d_score,d_scorecount,d_addtime,d_time,d_playfrom  FROM {pre}vod ";
         if (!isNum($this->par_num)) {
             $this->par_num = 12;
         } else {
             $this->par_num = intval($this->par_num);
         }
         if (!isN($mac["order"])) {
             $this->par_order = $mac["order"];
             $mac["listorder"] = true;
         }
         if (!isN($mac["by"])) {
             $this->par_by = $mac["by"];
             $mac["listorder"] = true;
         }
         if (!isN($mac["area"])) {
             $this->par_area = $mac["area"];
             $mac["listorder"] = true;
         }
         if (!isN($mac["year"])) {
             $this->par_year = $mac["year"];
             $mac["listorder"] = true;
         }
         if ($this->par_state == "series") {
             $where = $where . " and d_state > 0";
         } else {
             if (isNum($this->par_state)) {
                 $where = $where . " and d_state = " . $this->par_state;
             }
         }
         if (!isN($this->par_level)) {
             if ($this->par_level != "all") {
                 $where = $where . " AND d_level in(" . $this->par_level . ")";
             } else {
                 $where = $where . " AND d_level >0";
             }
         }
         if (!isN($this->par_topic)) {
             if ($this->par_topic != "all") {
                 $sql = $sql . " ,{pre}vod_topic_items as items WHERE d_hide=0 and items.vod_id=d_id";
                 if ($this->par_topic == "current" && $mac["vodtopicid"] > -1) {
                     $where = $where . " and items.topic_id in (" . $mac["vodtopicid"] . ")";
                 } else {
                     $where = $where . " and items.topic_id in (" . $this->par_topic . ")";
                 }
             } else {
                 //$sql=$sql."  WHERE d_hide=0 ";
             }
         } else {
             //$sql=$sql."  WHERE d_hide=0 ";
         }
         if (!isN($this->par_area)) {
             $where = $where . " and d_area ='" . $this->par_area . "'";
         }
         if (!isN($this->par_lang)) {
             $where = $where . " and d_language ='" . $this->par_lang . "'";
         }
         if (!isN($this->par_letter)) {
             $where = $where . " and d_letter ='" . $this->par_letter . "'";
         }
         if (!isN($this->par_year)) {
             $where = $where . " and d_year ='" . $this->par_year . "'";
         }
         if (isNum($this->par_day)) {
             $where = $where . " and datediff(now(), d_time) <" . $this->par_day;
         }
         $where = $where . " AND d_type>0 ";
         if ($mac["vodtypeid"] != -1) {
             $this->page_id = $mac["vodtypeid"];
             //                $where = $where . " AND d_type IN (" . $this->page_typearr["childids"] . ")";
             $this->page_type = "vodtype";
             if ($this->page_typearr['t_pid'] === '0') {
                 $where = $where . " AND d_type IN (" . $this->page_typearr["childids"] . ")";
             } else {
                 $where = $where . " AND (d_type = " . $this->page_typearr['t_pid'] . " and d_type_name like '%" . replaceStr($this->page_typearr['t_name'], '片', '') . "%')";
             }
         } else {
             if ($mac["vodtopicid"] != -1) {
                 if (strpos($where, "items.topic_id") === false) {
                     $sql = $sql . " ,{pre}vod_topic_items as items WHERE d_hide=0 and items.vod_id=d_id";
                 }
                 $this->page_id = $mac["vodtopicid"];
                 $where = $where . " AND items.topic_id IN(" . $mac["vodtopicid"] . ")";
                 $this->page_type = "vodtopic";
             } else {
                 if (!isN($mac["ids"])) {
                     $where = $where . " AND d_id IN( " . $mac["ids"] . " )";
                     $this->page_type = "vodsearch";
                 } else {
                     if (!isN($this->par_label)) {
                         $this->page_type = "label";
                     } else {
                         $where = $mac["where"];
                         if (!isN($mac["des"])) {
                             $this->page_type = "vodsearch";
                             $this->par_type = "";
                         }
                     }
                 }
             }
         }
         if ($mac["vodtypeid"] == -1 && !isN($this->par_type)) {
             if ($this->par_type != "all") {
                 if (strpos($this->par_type, ",") > 0) {
                     $where = $where . " and d_type in (" . $this->par_type . ")";
                 } else {
                     $typearr = getValueByArray($cache[0], "t_id", intval($this->par_type));
                     if (is_array($typearr)) {
                         $where = $where . " and d_type in (" . $typearr["childids"] . ")";
                     }
                 }
             }
         }
         if (app_user == 1) {
             $where = $where . getTypeByPopedomFilter("vod");
         }
         if (!isN($this->par_starring)) {
             $where = $where . " AND d_starring LIKE '%" . $this->par_starring . "%' ";
         }
         switch ($this->par_order) {
             case "desc":
                 $this->par_order = "desc";
                 break;
             default:
                 $this->par_order = "asc";
                 break;
         }
         switch ($this->par_by) {
             case "id":
                 $orderstr = " ORDER BY d_id " . $this->par_order;
                 break;
             case "hits":
                 $orderstr = " ORDER BY d_hits " . $this->par_order;
                 break;
             case "dayhits":
                 $orderstr = " ORDER BY d_dayhits " . $this->par_order;
                 break;
             case "weekhits":
                 $orderstr = " ORDER BY d_weekhits " . $this->par_order;
                 break;
             case "monthhits":
                 $orderstr = " ORDER BY d_monthhits " . $this->par_order;
                 break;
             case "addtime":
                 $orderstr = " ORDER BY d_addtime " . $this->par_order;
                 break;
             case "level":
                 $orderstr = " ORDER BY d_level " . $this->par_order;
                 break;
             case "good":
                 $orderstr = " ORDER BY d_good " . $this->par_order;
                 break;
             case "bad":
                 $orderstr = " ORDER BY d_bad " . $this->par_order;
                 break;
             case "score":
                 $orderstr = " ORDER BY d_score " . $this->par_order;
                 break;
             case "scorecount":
                 $orderstr = " ORDER BY d_scorecount " . $this->par_order;
                 break;
             default:
                 $orderstr = " ORDER BY d_time " . $this->par_order;
                 break;
         }
         $topstr = " limit " . $this->par_num * ($this->page - 1) . "," . $this->par_num;
         $this->page_size = $this->par_num;
         $this->page_count = 0;
         $this->data_count = 0;
         //            var_dump($sql . $where . $orderstr . $topstr);
         if (strpos($where, "items.topic_id") !== false) {
             $rscount = $db->getOne("SELECT COUNT(d_id) FROM {pre}vod ,{pre}vod_topic_items as items WHERE d_hide=0 and items.vod_id=d_id " . $where);
         } else {
             $rscount = $db->getOne("SELECT COUNT(d_id) FROM {pre}vod  WHERE d_hide=0 " . $where);
         }
         if (strpos($where, "d_hide") === false && strpos($sql, "d_hide") === false) {
             $where = "   WHERE d_hide=0 " . $where;
         }
         //  var_dump($sql . $where . $orderstr . $topstr);
         if ($rscount == 0) {
             $this->html = replaceStr($this->html, $this->markval, "<font style='font-size:13px'><div align='center'>没有相关记录!</div></font>");
             return;
         }
         $pagecount = ceil($rscount / $this->par_num);
         $rs = $db->query($sql . $where . $orderstr . $topstr);
         if (!$rs) {
             $rscount = 0;
             $pagecount = 0;
             $this->html = replaceStr($this->html, $this->markval, "vodpagelist标签出错");
             return;
         }
         $this->page_count = $pagecount;
         $this->data_count = $rscount;
         $labelRule = buildregx("\\[pagelist:\\s*([0-9a-zA-Z]+)([\\s]*[len|style]*)[=]??([\\da-zA-Z\\-\\\\/\\:\\s]*)\\]", "");
         preg_match_all($labelRule, $this->markdes, $matches2);
         $num = 0;
         while ($row = $db->fetch_array($rs)) {
             $num = $num + 1;
             $marktemp = $this->markdes;
             for ($j = 0; $j < count($matches2[0]); $j++) {
                 $marktemp = $this->parse("vod", $marktemp, $matches2[0][$j], $matches2[1][$j], $matches2[3][$j], $row, $num);
             }
             $markhtml = $markhtml . $marktemp;
         }
         unset($rs);
         unset($matches2);
         $this->html = replaceStr($this->html, $this->markval, $markhtml);
     }
     unset($matches1);
 }