/** * 根据内容或列表页第一个关键词获取内容,不存在关键词随机获取 * * @access public * @param $is_rand:1为随机;$filter:过滤标示(如推荐等);$order_type:排序类型;$pic:是否有图片;$limit:数量 * @return array */ function get_rand_content($key = '', $limit = '0,5', $order_type = 'id', $filter = '', $pic = 'no', $order = 'desc', $lang = '') { $sql_key = ''; $sql_rand = ''; if ($key) { $key_arr = explode(',', $key); $sql_key = " and ("; $key_num = count($key_arr); $sql_or = ''; foreach ($key_arr as $k => $v) { if ($k != $key_num - 1) { $sql_key .= " m.keywords like '%" . $v . "%' or"; } else { $sql_key .= " m.keywords like '%" . $v . "%'"; } if ($k == 2) { break; } } $sql_key .= ")"; } else { $sql_rand = ' rand(),'; } $cate_id = $GLOBALS['cateid']; //获得栏目ID,不存在获取内容页的栏目ID if (empty($cate_id)) { return; } global $category, $channel; $cate_info = get_cate_info($cate_id, $category); //获得栏目信息 $channel_id = $cate_info['cate_channel']; //获得栏目模型ID unset($cate_info); //释放栏目信息,下面将会用到 $channel_info = get_cate_info($channel_id, $channel); //获得栏目模型信息 $content_php = empty($channel_info['content_php']) ? 'show_content.php' : $channel_info['content_php']; $list_php = empty($channel_info['list_php']) ? 'show_list.php' : $channel_info['list_php']; $table = $channel_info['channel_table']; //获得栏目模型表 if (empty($table)) { return; } $child = get_child_id($cate_id); //获得栏目的下级栏目 $cate_id_all = empty($child) ? $cate_id : $cate_id . $child; //组合栏目ID $sql = "select m.*,f.* from " . DB_PRE . "maintb as m left join " . DB_PRE . $table . " as f on f.id = m.id where m.id=f.id and m.verify=0 and m.category in (" . $cate_id_all . ")"; $sql .= empty($filter) ? ' ' : " and m.filter like '%" . $filter . "%'"; $sql .= $sql_key; if ($pic == 'no') { $sql .= ''; } elseif ($pic == 'yes') { $sql .= " and m.tbpic <> ''"; } $sql .= empty($lang) ? " and m.lang='" . $GLOBALS['lang'] . "'" : " and m.lang='" . $lang . "'"; $sql .= in_array($order_type, array('id', 'hits', 'addtime', 'updatetime')) ? " GROUP BY m.id order by" . $sql_rand . " m.top desc, m." . $order_type : " GROUP BY m.id order by" . $sql_rand . " m.top desc, m.id "; $sql .= in_array($order, array('asc', 'desc')) ? ' ' . $order : ' desc'; $sql .= empty($limit) ? ' limit 0,5' : " limit " . $limit; $rel = $GLOBALS['mysql']->fetch_asc($sql); if (!empty($rel)) { $path = CMS_SELF; $i = 1; foreach ($rel as $k => $v) { $rel[$k]['title'] = $v['title']; //标题 if ($rel[$k]['title_color'] || $rel[$k]['title_style'] || $rel[$k]['is_open']) { $font_style = ''; $font_style .= empty($rel[$k]['title_color']) ? '' : 'color:' . $rel[$k]['title_color'] . ';'; if ($rel[$k]['title_style'] == 1) { $font_style .= 'font-weight:bold;'; } elseif ($rel[$k]['title_style'] == 2) { $font_style .= 'font-style:italic;'; } elseif ($rel[$k]['title_style'] == 3) { $font_style .= 'text-decoration:underline;'; } $rel[$k]['style'] = $font_style; $rel[$k]['style_title'] = $rel[$k]['title']; //样式标题 } else { $rel[$k]['style_title'] = $rel[$k]['title']; } $rel[$k]['target'] = $v['is_open'] ? 'target="_blank"' : ''; //新窗口 if ($v['purview']) { $url = $path . 'show_content.php?id=' . $v['id']; } else { $url = !$v['is_html'] && !$GLOBALS['_confing']['web_html'][0] ? $path . $content_php . '?id=' . $v['id'] : $path . $v['url']; } $rel[$k]['url'] = $v['is_url'] ? $v['url_add'] : $url; //链接 $v['tbpic'] = empty($v['tbpic']) ? 'no_pc.gif' : $v['tbpic']; $rel[$k]['thumb_pic'] = CMS_SELF . 'upload/' . $v['tbpic']; //图片 $cate_info = get_cate_info($v['category'], $category); //获取栏目信息 $cate_url = !$v['is_html'] && !$GLOBALS['_confing']['web_html'][0] ? $path . $list_php . '?id=' . $cate_info['id'] : $path . $cate_info['cate_fold_name']; $rel[$k]['cate_url'] = $cate_url; //栏目url $rel[$k]['cate_name'] = $cate_info['cate_name']; //栏目名称 $rel[$k]['cate_pic1'] = CMS_SELF . 'upload/' . $cate_info['cate_pic1']; $rel[$k]['cate_pic2'] = CMS_SELF . 'upload/' . $cate_info['cate_pic2']; $rel[$k]['cate_pic3'] = CMS_SELF . 'upload/' . $cate_info['cate_pic3']; $rel[$k]['cate_content'] = CMS_SELF . 'upload/' . $cate_info['cate_content']; $rel[$k]['autoindex'] = $i; $rel[$k]['first'] = $i == 1 ? 1 : 0; $rel[$k]['last'] = $num == $i ? 1 : 0; $i = $i + 1; } } return $rel; }
//当前语言下的栏目 $_confing = get_confing($lang); //配置信息 $cat_id = $cate_info['id']; //栏目id $cateid = $cat_id; $parent_id = get_cate_last_parent($cat_id); //获取最终顶级栏目 $tpl->template_dir = TP_PATH . $_confing['web_template'] . '/'; $tpl->template_lang = $lang; if ($_confing['is_cache']) { $tpl->template_is_cache = 1; //缓存 $tpl->template_time = $_confing['cache_time'] ? $_confing['cache_time'] : 30; //开启缓存但不存在缓存时间使用30秒 } else { $tpl->template_is_cache = 0; } //开始列表 $child = get_child_id($cat_id); $list_cate = empty($child) ? $cat_id : $cat_id . $child; //所有栏目包含子栏目 $r_count = $GLOBALS['mysql']->fetch_rows("select id from " . DB_PRE . "maintb where category in (" . $list_cate . ")"); //总的数量 $page_size = empty($cate_info['list_num']) ? '20' : $cate_info['list_num']; //显示数目 $page_count = ceil($r_count / $page_size); //总页数 $tpl_rel = explode('.', $cate_info['cate_tpl_list']); $tpl->display($tpl_rel[0]); //载入缓存文件
function get_child_id($id) { $arr = ''; $sql = "select id from " . DB_PRE . "category where cate_hide!=1 and cate_parent=" . intval($id); $child = $GLOBALS['mysql']->fetch_asc($sql); if (empty($child)) { return ''; } else { foreach ($child as $k => $v) { $arr .= "," . $v['id']; $arr .= get_child_id($v['id']); } unset($child); return $arr; } }