public function index() { global_run(); init_app_page(); $GLOBALS['tmpl']->assign("no_nav", true); //无分类下拉 $id = intval($_REQUEST['id']); require_once APP_ROOT_PATH . 'system/model/topic.php'; $topic = get_topic_item($id); if ($id > 0 && !empty($topic)) { // } else { app_redirect(url("index")); } if ($topic['group_id'] > 0) { $GLOBALS['tmpl']->assign('topic_group', get_topic_group($topic['group_id'])); } $title = $topic['forum_title']; $content = decode_topic($topic['content']); $is_fav = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "topic where (fav_id = " . $id . " or (origin_id = " . $id . " and fav_id <> 0)) and user_id = " . intval($GLOBALS['user_info']['id'])); $GLOBALS['tmpl']->assign("topic", $topic); $GLOBALS['tmpl']->assign("title", $title); $GLOBALS['tmpl']->assign("content", $content); $GLOBALS['tmpl']->assign("is_fav", $is_fav); $GLOBALS['tmpl']->assign("page_title", $title); $GLOBALS['tmpl']->assign("page_keyword", $title . ","); $GLOBALS['tmpl']->assign("page_description", $title . ","); $GLOBALS['tmpl']->assign('user_auth', get_user_auth()); $GLOBALS['tmpl']->display("topic_index.html"); }
/** * 加载相应的类型消息 * @param unknown_type $msg 数据集(即数据库中的对应消息行) * * 返回:array("id"=>"当前消息ID",title="标题",is_read=>"是否已读","icon"=>"相关数据的图片(可为空)","content"=>"内容","create_time"=>"时间","link"=>"(可为空)相关数据的跳转链接"); */ public function load_msg($msg) { if (!$msg['data']) { require_once APP_ROOT_PATH . "system/model/topic.php"; $data = get_topic_item($msg['data_id']); $msg['data'] = serialize($data); $GLOBALS['db']->autoExecute(DB_PREFIX . "msg_box", $msg, "UPDATE", "id=" . $msg['id'], "SILENT"); } $data = unserialize($msg['data']); //图标,取分享的第一张 if ($data['id'] != $data['origin_id'] && $data['origin']) { $msg['title'] = $data['origin']['forum_title']; $msg['icon'] = $data['origin']['images'][0]['o_path']; $msg['link'] = $data['origin']['url']; } else { $msg['title'] = $data['forum_title']; $msg['icon'] = $data['images'][0]['o_path']; $msg['link'] = $data['url']; } if ($msg['title'] == "") { $msg['title'] = "会员分享"; } $msg['short_title'] = msubstr($msg['title']); return $msg; }
public function load($param) { $key = $this->build_key(__CLASS__, $param); $GLOBALS['fcache']->set_dir(APP_ROOT_PATH . "public/runtime/data/" . __CLASS__ . "/"); $recommend_topic = $GLOBALS['fcache']->get($key); if ($recommend_topic === false) { $recommend_topic = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "topic where is_recommend = 1 order by create_time desc limit 3"); foreach ($recommend_topic as $k => $item) { $recommend_topic[$k] = get_topic_item($item); } $GLOBALS['fcache']->set_dir(APP_ROOT_PATH . "public/runtime/data/" . __CLASS__ . "/"); $GLOBALS['fcache']->set($key, $recommend_topic); } return $recommend_topic; }
public function load($param) { $key = $this->build_key(__CLASS__, $param); $GLOBALS['fcache']->set_dir(APP_ROOT_PATH . "public/runtime/data/" . __CLASS__ . "/"); $result = $GLOBALS['fcache']->get($key); if ($result === false) { $result['image'] = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "topic where group_id <> 0 and is_effect = 1 and is_delete = 0 and is_recommend = 1 and has_image = 1 order by create_time desc limit 4"); $ids = array(0); foreach ($result['image'] as $k => $v) { $result['image'][$k] = get_topic_item($v); $result['image'][$k]['group_info'] = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "topic_group where id = " . $v['group_id']); $ids[] = $v['id']; } $result['list'] = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "topic where group_id <> 0 and is_effect = 1 and is_delete = 0 and is_recommend = 1 and id not in(" . implode(",", $ids) . ") order by create_time desc limit 8"); foreach ($result['list'] as $k => $v) { $result['list'][$k] = get_topic_item($v); $result['list'][$k]['group_info'] = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "topic_group where id = " . $v['group_id']); } $GLOBALS['fcache']->set_dir(APP_ROOT_PATH . "public/runtime/data/" . __CLASS__ . "/"); $GLOBALS['fcache']->set($key, $result); } return $result; }
public function index() { $GLOBALS['tmpl']->caching = true; $GLOBALS['tmpl']->cache_lifetime = 600; //缓存10分钟 $cache_id = md5(MODULE_NAME . ACTION_NAME . $GLOBALS['deal_city']['id']); if (!$GLOBALS['tmpl']->is_cached('daren_index.html', $cache_id)) { $title = $GLOBALS['lang']['DAREN_SHOW']; $site_nav[] = array('name' => $GLOBALS['lang']['HOME_PAGE'], 'url' => APP_ROOT . "/"); $site_nav[] = array('name' => $title, 'url' => url("shop", "daren")); $GLOBALS['tmpl']->assign("site_nav", $site_nav); $GLOBALS['tmpl']->assign("page_title", $title); $GLOBALS['tmpl']->assign("page_keyword", $title . ","); $GLOBALS['tmpl']->assign("page_description", $title . ","); $user_id = intval($GLOBALS['user_info']['id']); //输出所有达人推荐 $rnd_daren_list = get_rand_user(42, 1); $GLOBALS['tmpl']->assign("rnd_daren_list", $rnd_daren_list); $daren_list = get_rand_user(8, 1); foreach ($daren_list as $kk => $vv) { $focus_uid = intval($vv['id']); $focus_data = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user_focus where focus_user_id = " . $user_id . " and focused_user_id = " . $focus_uid); if ($focus_data) { $daren_list[$kk]['focused'] = 1; } } $GLOBALS['tmpl']->assign("daren_list", $daren_list); $topic_list = $GLOBALS['db']->getAll("select t.* from " . DB_PREFIX . "topic as t where t.is_effect = 1 and t.is_delete = 0 and t.is_recommend = 1 order by t.create_time desc limit 6"); foreach ($topic_list as $kk => $vv) { $vv['content'] = msubstr($vv['content'], 0, 30); $topic_list[$kk] = get_topic_item($vv); $topic_user_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where id = " . $vv['user_id'] . " and is_effect =1 and is_delete = 0"); $focus_uid = intval($topic_user_info['id']); $focus_data = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user_focus where focus_user_id = " . $user_id . " and focused_user_id = " . $focus_uid); if ($focus_data) { $topic_user_info['focused'] = 1; } $topic_list[$kk]['user_info'] = $topic_user_info; } $GLOBALS['tmpl']->assign("topic_list", $topic_list); $cate_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "topic_tag_cate where showin_web = 1 order by sort desc limit 7"); foreach ($cate_list as $k => $v) { //获取分类下的推荐分享 $cate_list[$k]['topic_list'] = $GLOBALS['db']->getAll("select t.* from " . DB_PREFIX . "topic as t left join " . DB_PREFIX . "topic_cate_link as l on l.topic_id = t.id where l.cate_id = " . $v['id'] . " and t.is_effect = 1 and t.is_delete = 0 and t.is_recommend = 1 order by t.create_time desc limit 4"); foreach ($cate_list[$k]['topic_list'] as $kk => $vv) { $vv['content'] = msubstr($vv['content'], 0, 30); $cate_list[$k]['topic_list'][$kk] = get_topic_item($vv); $topic_user_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where id = " . $vv['user_id'] . " and is_effect =1 and is_delete = 0"); $focus_uid = intval($topic_user_info['id']); $focus_data = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user_focus where focus_user_id = " . $user_id . " and focused_user_id = " . $focus_uid); if ($focus_data) { $topic_user_info['focused'] = 1; } $cate_list[$k]['topic_list'][$kk]['user_info'] = $topic_user_info; } $cate_list[$k]['daren_list'] = $GLOBALS['db']->getAllCached("select u.* from " . DB_PREFIX . "user as u left join " . DB_PREFIX . "user_cate_link as l on l.user_id = u.id where l.cate_id = " . $v['id'] . " and u.is_effect = 1 and u.is_delete = 0 and u.is_daren = 1 order by rand() limit 8"); foreach ($cate_list[$k]['daren_list'] as $kk => $vv) { $focus_uid = intval($vv['id']); $focus_data = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user_focus where focus_user_id = " . $user_id . " and focused_user_id = " . $focus_uid); if ($focus_data) { $cate_list[$k]['daren_list'][$kk]['focused'] = 1; } } } $GLOBALS['tmpl']->assign("cate_list", $cate_list); $daren_html = decode_topic($GLOBALS['tmpl']->fetch("inc/daren_show_item.html")); $GLOBALS['tmpl']->assign("daren_html", $daren_html); } $GLOBALS['tmpl']->display("daren_index.html", $cache_id); }
function get_topic_list($limit, $condition = '', $orderby = 'create_time desc', $keywords_array = array()) { if ($orderby == '') { $orderby = 'create_time desc'; } if ($condition != '') { $condition = " and " . $condition; } $list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "topic where is_effect = 1 and is_delete = 0 " . $condition . " order by " . $orderby . " limit " . $limit); $total = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "topic where is_effect = 1 and is_delete = 0 " . $condition); foreach ($list as $k => $v) { $list[$k] = get_topic_item($v, $keywords_array); if (msubstr(preg_replace("/<[^>]+>/i", "", $list[$k]['content']), 0, 50) != preg_replace("/<[^>]+>/i", "", $list[$k]['content'])) { $list[$k]['short_content'] = msubstr(preg_replace("/<[^>]+>/i", "", $list[$k]['content']), 0, 50); } else { $list[$k]['short_content'] = preg_replace("/<br[^>]+>/i", "", $list[$k]['content']); } if ($list[$k]['origin']) { if (msubstr(preg_replace("/<[^>]+>/i", "", $list[$k]['origin']['content']), 0, 50) != preg_replace("/<[^>]+>/i", "", $list[$k]['origin']['content'])) { $list[$k]['origin']['short_content'] = msubstr(preg_replace("/<[^>]+>/i", "", $list[$k]['origin']['content']), 0, 50); } else { $list[$k]['origin']['short_content'] = preg_replace("/<br[^>]+>/i", "", $list[$k]['origin']['content']); } } } return array('list' => $list, 'total' => $total); }
public function search() { //获取可以相关的用户 $user_list = get_rand_user(4); $user_id = intval($GLOBALS['user_info']['id']); $ids = array(0); foreach ($user_list as $k => $v) { $ids[] = $v['id']; } $focus_data = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "user_focus where focus_user_id = " . $user_id . " and focused_user_id in (" . implode(",", $ids) . ")"); foreach ($user_list as $k => $v) { foreach ($focus_data as $kk => $vv) { if ($vv['focused_user_id'] == $v['id']) { $user_list[$k]['focused'] = 1; break; } } if ($v['city_id'] != 0 && $v['city_id'] == $GLOBALS['deal_city']['id']) { $user_list[$k]['same_city'] = 1; } else { $user_list[$k]['same_city'] = 0; } } $GLOBALS['tmpl']->assign("user_list", $user_list); convert_req($_REQUEST); $type = intval($_REQUEST['type']); $filter = intval($_REQUEST['filter']); $keyword = addslashes(htmlspecialchars(trim($_REQUEST['keyword']))); $GLOBALS['tmpl']->assign("keyword", $keyword); $GLOBALS['tmpl']->assign("type", $type); $GLOBALS['tmpl']->assign("filter", $filter); $url_param = array("type" => $type, "filter" => $filter, "keyword" => $keyword); if ($type == 0) { unset($url_param['type']); } if ($filter == 0) { unset($url_param['filter']); } if (intval($_REQUEST['is_redirect']) == 1) { if ($type > 0) { app_redirect(url("shop", "topic#search", $url_param)); } else { app_redirect(url("shop", "topic#search", $url_param)); } } $type_navs = array(array("type" => 0, "name" => $GLOBALS['lang']['TOPIC_TYPE_ALL']), array("type" => 1, "name" => $GLOBALS['lang']['TOPIC_TYPE_DEAL']), array("type" => 2, "name" => $GLOBALS['lang']['TOPIC_TYPE_STORE']), array("type" => 3, "name" => $GLOBALS['lang']['TOPIC_TYPE_RECOMMEND'])); foreach ($type_navs as $k => $v) { $tmp_url_param = $url_param; if ($v['type'] != 0) { $tmp_url_param['type'] = $v['type']; } else { unset($tmp_url_param['type']); } $type_navs[$k]['url'] = url("shop", "topic#search", $tmp_url_param); if ($v['type'] == $type) { $type_navs[$k]['act'] = true; } } $filter_navs = array(array("filter" => 0, "name" => $GLOBALS['lang']['TOPIC_FILTER_ALL']), array("filter" => 1, "name" => $GLOBALS['lang']['TOPIC_FILTER_MYFOCUS']), array("filter" => 2, "name" => $GLOBALS['lang']['TOPIC_FILTER_DAREN']), array("filter" => 3, "name" => $GLOBALS['lang']['TOPIC_FILTER_MERCHANT'])); foreach ($filter_navs as $k => $v) { $tmp_url_param = $url_param; if ($v['filter'] != 0) { $tmp_url_param['filter'] = $v['filter']; } else { unset($tmp_url_param['filter']); } $filter_navs[$k]['url'] = url("shop", "topic#search", $tmp_url_param); if ($v['filter'] == $filter) { $filter_navs[$k]['act'] = true; } } $condition = " 1=1 "; if ($type == 0) { //所有分享 $condition .= ""; $search_title = $GLOBALS['lang']['TOPIC_TYPE_ALL']; } elseif ($type == 1) { $condition .= " and (t.type='tuancomment' or t.type='shopcomment' or t.type='youhuicomment' ) "; $search_title = $GLOBALS['lang']['TOPIC_TYPE_DEAL']; } elseif ($type == 2) { $condition .= " and t.type='slocationcomment' "; $search_title = $GLOBALS['lang']['TOPIC_TYPE_STORE']; } elseif ($type == 3) { $condition .= " and t.title like '" . $keyword . "' "; $search_title = $GLOBALS['lang']['TOPIC_TYPE_RECOMMEND']; } if ($filter == 0) { //全部 //$search_title.= " - ".$GLOBALS['lang']['TOPIC_FILTER_ALL']; } elseif ($filter == 1) { $search_title .= " - " . $GLOBALS['lang']['TOPIC_FILTER_MYFOCUS']; $condition .= " and uf.focus_user_id = " . intval($GLOBALS['user_info']['id']); } elseif ($filter == 2) { $search_title .= " - " . $GLOBALS['lang']['TOPIC_FILTER_DAREN']; $condition .= " and u.is_daren = 1 "; } elseif ($filter == 3) { $search_title .= " - " . $GLOBALS['lang']['TOPIC_FILTER_MERCHANT']; $condition .= " and u.is_merchant = 1 "; } if ($keyword) { $search_title .= " - " . $keyword; $kws_div = div_str($keyword); foreach ($kws_div as $k => $item) { $kw[$k] = str_to_unicode_string($item); } $ukeyword = implode(" ", $kw); $condition .= " and match(t.keyword_match) against('" . $ukeyword . "' IN BOOLEAN MODE) "; } $GLOBALS['tmpl']->assign("kws_div", $kws_div); $GLOBALS['tmpl']->assign("page_title", $search_title); $GLOBALS['tmpl']->assign("page_keyword", $search_title . ","); $GLOBALS['tmpl']->assign("page_description", $search_title . ","); //分页 $page = intval($_REQUEST['p']); if ($page == 0) { $page = 1; } $limit = ($page - 1) * app_conf("PAGE_SIZE") . "," . app_conf("PAGE_SIZE"); // $result = get_topic_list($limit,$condition,"",$kws_div); $orderby = 't.create_time desc'; $condition = " and " . $condition; $list = $GLOBALS['db']->getAll("select t.* from " . DB_PREFIX . "topic as t left join " . DB_PREFIX . "user as u on t.user_id = u.id left join " . DB_PREFIX . "user_focus as uf on uf.focused_user_id = t.user_id where t.is_effect = 1 and t.is_delete = 0 " . $condition . " group by t.id order by " . $orderby . " limit " . $limit); $total = $GLOBALS['db']->getOne("select count(distinct(t.id)) from " . DB_PREFIX . "topic as t left join " . DB_PREFIX . "user as u on t.user_id = u.id left join " . DB_PREFIX . "user_focus as uf on uf.focused_user_id = t.user_id where t.is_effect = 1 and t.is_delete = 0 " . $condition); foreach ($list as $k => $v) { $list[$k] = get_topic_item($v, $kws_div); if (msubstr(preg_replace("/<[^>]+>/i", "", $list[$k]['content']), 0, 50) != preg_replace("/<[^>]+>/i", "", $list[$k]['content'])) { $list[$k]['short_content'] = msubstr(preg_replace("/<[^>]+>/i", "", $list[$k]['content']), 0, 50); } else { $list[$k]['short_content'] = preg_replace("/<br[^>]+>/i", "", $list[$k]['content']); } if ($list[$k]['origin']) { if (msubstr(preg_replace("/<[^>]+>/i", "", $list[$k]['origin']['content']), 0, 50) != preg_replace("/<[^>]+>/i", "", $list[$k]['origin']['content'])) { $list[$k]['origin']['short_content'] = msubstr(preg_replace("/<[^>]+>/i", "", $list[$k]['origin']['content']), 0, 50); } else { $list[$k]['origin']['short_content'] = preg_replace("/<br[^>]+>/i", "", $list[$k]['origin']['content']); } } } $result = array('list' => $list, 'total' => $total); if ($result['total'] > 0) { if (check_ipop_limit(get_client_ip(), "topic_search", 10, $keyword)) { $GLOBALS['db']->query("update " . DB_PREFIX . "topic_tag set count = count + 1 where name = '" . $keyword . "'"); } } //$result['list'] = div_to_col($result['list']); $GLOBALS['tmpl']->assign("topic_list", $result['list']); $page = new Page($result['total'], app_conf("PAGE_SIZE")); //初始化分页对象 $p = $page->show(); $GLOBALS['tmpl']->assign('pages', $p); $GLOBALS['tmpl']->assign('user_auth', get_user_auth()); $list_html = load_topic_list(); //$list_html = decode_topic_without_img($GLOBALS['tmpl']->fetch("inc/topic_col_list.html")); $GLOBALS['tmpl']->assign("list_html", $list_html); $GLOBALS['tmpl']->assign("type_navs", $type_navs); $GLOBALS['tmpl']->assign("filter_navs", $filter_navs); $res = load_dynamic_cache("topic_search_hot"); if ($res === false) { $res['hot_tag_list'] = $GLOBALS['db']->getAll("select name,color from " . DB_PREFIX . "topic_tag where is_recommend = 1 order by sort desc, count desc limit 10"); $res['hot_title_list'] = $GLOBALS['db']->getAll("select name,color from " . DB_PREFIX . "topic_title where is_recommend = 1 order by sort desc,count desc limit 10"); set_dynamic_cache("topic_search_hot", $res); } //输出搜索热词 $GLOBALS['tmpl']->assign("hot_tag_list", $res['hot_tag_list']); $GLOBALS['tmpl']->assign("hot_title_list", $res['hot_title_list']); //输出推荐分享 $recommend_topic = load_auto_cache("recommend_uc_topic"); $GLOBALS['tmpl']->assign("recommend_topic", $recommend_topic); $GLOBALS['tmpl']->display("topic_search.html"); }
public function load_topic() { $GLOBALS['tmpl']->assign('user_auth', get_user_auth()); $cid = intval($_REQUEST['cid']); $tag = addslashes(htmlspecialchars(trim($_REQUEST['tag']))); $page = intval($_REQUEST['page']); if ($page == 0) { $page = 1; } $step = intval($_REQUEST['step']); $step_size = intval($_REQUEST['step_size']); $limit = ($page - 1) * PAGE_SIZE + ($step - 1) * SECTOR . "," . SECTOR; if ($step == 0 || $step > $step_size) { //超出 $result['doms'] = array(); $result['step'] = 0; $result['status'] = 0; $result['info'] = 'end'; ajax_return($result); } if ($cid > 0) { $cate_name = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "topic_tag_cate where id = " . $cid); if ($cate_name) { $unicode_cate_name = str_to_unicode_string($cate_name); $condition .= " and match(cate_match) against('" . $unicode_cate_name . "' IN BOOLEAN MODE) "; } } if ($tag != "") { $unicode_tag = str_to_unicode_string($tag); $condition .= " and match(keyword_match) against('" . $unicode_tag . "' IN BOOLEAN MODE) "; } $sql = "select * from " . DB_PREFIX . "topic where is_effect = 1 and is_delete = 0 and fav_id = 0 and relay_id = 0 and type in ('share','sharetuan','sharegoods','sharefyouhui','sharebyouhui','shareevent') " . $condition . " order by create_time desc limit " . $limit; $result_list = $GLOBALS['db']->getAll($sql); if ($result_list) { $result['doms'] = array(); foreach ($result_list as $k => $v) { $topic = get_topic_item($v); if (msubstr(preg_replace("/<[^>]+>/i", "", $topic['content']), 0, 50) != preg_replace("/<[^>]+>/i", "", $topic['content'])) { $topic['short_content'] = msubstr(preg_replace("/<[^>]+>/i", "", $topic['content']), 0, 50); } else { $topic['short_content'] = preg_replace("/<br[^>]+>/i", "", $topic['content']); } if ($topic['origin']) { if (msubstr(preg_replace("/<[^>]+>/i", "", $topic['origin']['content']), 0, 50) != preg_replace("/<[^>]+>/i", "", $topic['origin']['content'])) { $topic['origin']['short_content'] = msubstr(preg_replace("/<[^>]+>/i", "", $topic['origin']['content']), 0, 50); } else { $topic['origin']['short_content'] = preg_replace("/<br[^>]+>/i", "", $topic['origin']['content']); } } $GLOBALS['tmpl']->assign("message_item", $topic); $result['doms'][] = decode_topic_without_img($GLOBALS['tmpl']->fetch("inc/discover_item.html")); } if ($step == 0 || $step >= $step_size) { //超出 $result['step'] = 0; $result['status'] = 0; $result['info'] = 'end'; ajax_return($result); } else { $result['status'] = 1; $result['step'] = $step + 1; $result['info'] = 'next'; ajax_return($result); } } else { $result['doms'] = array(); $result['step'] = 0; $result['status'] = 0; $result['info'] = 'end'; // $result['sql'] = $sql; ajax_return($result); } }