Beispiel #1
0
    public function all()
    {
        global $_FANWE;
        $is_best = false;
        $is_all = true;
        $_FANWE['nav_title'] = lang('common', 'daren');
        $count = FDB::resultFirst('SELECT COUNT(uid) FROM ' . FDB::table('user_daren') . ' WHERE status = 1');
        $pager = buildPage('daren/all', array(), $count, $_FANWE['page'], 18);
        $col = 3;
        $index = 0;
        $list = array();
        $today_time = getTodayTime();
        $sql = 'SELECT ud.*,u.user_name,u.server_code,uc.fans,uc.goods,uc.shares,
			up.reside_province,up.reside_city,up.introduce 
			FROM ' . FDB::table('user_daren') . ' AS ud 
			INNER JOIN ' . FDB::table('user') . ' AS u ON u.uid = ud.uid 
			INNER JOIN ' . FDB::table('user_count') . ' AS uc ON uc.uid = u.uid 
			INNER JOIN ' . FDB::table('user_profile') . ' AS up ON up.uid = ud.uid 
			WHERE ud.status = 1 
			ORDER BY ud.day_time DESC,ud.id DESC LIMIT ' . $pager['limit'];
        $res = FDB::query($sql);
        while ($data = FDB::fetch($res)) {
            $data['today_best'] = false;
            $data['url'] = FU('u/index', array('uid' => $data['uid']));
            $province = $_FANWE['cache']['citys']['all'][$data['reside_province']]['name'];
            $city = $_FANWE['cache']['citys']['all'][$data['reside_city']]['name'];
            $data['city'] = $province . ' ' . $city;
            $list[$index % $col][] = $data;
            $index++;
        }
        include template('page/daren');
        display();
    }
    public function run()
    {
        global $_FANWE;
        $root = array();
        $root['return'] = 0;
        $uid = (int) $_FANWE['requestData']['uid'];
        $cid = (int) $_FANWE['requestData']['cid'];
        $album_title = trim($_FANWE['requestData']['title']);
        $data = array('title' => $album_title, 'cid' => $cid);
        $vservice = FS('Validate');
        $validate = array(array('title', 'required', lang('album', 'name_require')), array('title', 'max_length', lang('album', 'name_max'), 60), array('cid', 'min', lang('album', 'cid_min'), 1));
        if (!$vservice->validation($validate, $data)) {
            $root['info'] = $vservice->getError();
            m_display($root);
        }
        $check_result = FS('Share')->checkWord($album_title, 'title');
        if ($check_result['error_code'] == 1) {
            $root['info'] = $check_result['error_msg'];
            m_display($root);
        }
        if ($uid > 0) {
            if (!FS('User')->getUserExists($uid)) {
                $uid = 0;
            }
        }
        if ($cid == 0) {
            $uid == 0;
        }
        if ($uid == 0) {
            $root['info'] = "请先登录";
            m_display($root);
        }
        $share_data = array();
        $share_data['uid'] = $uid;
        $share_data['type'] = 'album';
        $share_data['content'] = $album_title;
        $share = FS('Share')->submit($share_data, false, true, true);
        if ($share['status']) {
            $data = array();
            $data['title'] = htmlspecialchars($album_title);
            $data['album_title_match'] = segmentToUnicode(clearSymbol($album_title));
            $data['uid'] = $uid;
            $data['cid'] = $cid;
            $data['share_id'] = $share['share_id'];
            $data['create_day'] = getTodayTime();
            $data['create_time'] = TIME_UTC;
            $data['show_type'] = 2;
            $aid = FDB::insert('album', $data, true);
            FDB::query('UPDATE ' . FDB::table('share') . ' SET rec_id = ' . $aid . ' 
				WHERE share_id = ' . $share['share_id']);
            FDB::query("update " . FDB::table("user_count") . " set albums = albums + 1 where uid = " . $uid);
            $root['aid'] = $aid;
            $root['album_name'] = $album_title;
            $root['return'] = 1;
        }
        m_display($root);
    }
    public function run()
    {
        global $_FANWE;
        $root = array();
        $root['return'] = 1;
        $is_hot = (int) $_FANWE['requestData']['is_hot'];
        $is_new = (int) $_FANWE['requestData']['is_new'];
        $page = (int) $_FANWE['requestData']['page'];
        $page = max(1, $page);
        $today_time = getTodayTime();
        $field = '';
        $whrer = '';
        $book_photo_goods = (int) $_FANWE['setting']['book_photo_goods'];
        if ($book_photo_goods == 0) {
            $whrer = " WHERE share_data IN ('goods','photo','goods_photo')";
        } elseif ($book_photo_goods == 1) {
            $whrer = " WHERE share_data IN ('photo','goods_photo')";
        } elseif ($book_photo_goods == 2) {
            $whrer = " WHERE share_data IN ('goods','goods_photo')";
        }
        if ($is_hot == 1) {
            $day7_time = $today_time - 604800;
            $field = ",(create_time > {$day7_time}) AS time_sort ";
            $sort = " ORDER BY time_sort DESC,collect_count DESC";
        }
        if ($is_new == 1) {
            $sort = " ORDER BY share_id DESC";
        }
        $sql_count = "SELECT COUNT(DISTINCT share_id) FROM " . FDB::table("share");
        $total = FDB::resultFirst($sql_count);
        $page_size = PAGE_SIZE;
        $max_page = 100;
        if ($total > $max_page * $page_size) {
            $total = $max_page * $page_size;
        }
        if ($page > $max_page) {
            $page = $max_page;
        }
        $page_total = ceil($total / $page_size);
        $limit = ($page - 1) * $page_size . "," . $page_size;
        $sql = 'SELECT DISTINCT(share_id),cache_data ' . $field . '
					FROM ' . FDB::table('share') . $whrer . $sort . ' LIMIT ' . $limit;
        $res = FDB::query($sql);
        $share_list = array();
        while ($item = FDB::fetch($res)) {
            $cache_data = fStripslashes(unserialize($item['cache_data']));
            $img = current($cache_data['imgs']['all']);
            $data = array();
            $data['share_id'] = $item['share_id'];
            $data['img'] = getImgName($img['img'], 100, 999, 0, true);
            $data['height'] = $img['height'] * (100 / $img['width']);
            $share_list[] = $data;
        }
        $root['item'] = $share_list;
        $root['page'] = array("page" => $page, "page_total" => $page_total);
        m_display($root);
    }
    public function run()
    {
        global $_FANWE;
        $root = array();
        $root['return'] = 1;
        $key = 'm/sharecate';
        $cache_list = getCache($key);
        if ($cache_list !== NULL || TIME_UTC - $cache_list['cache_time'] > 600) {
            $cate_list = array();
            $min_time = $this->getQuarterMinTime();
            $max_time = getTodayTime();
            FanweService::instance()->cache->loadCache('albums');
            $album_cate = $_FANWE['cache']['albums']['category'];
            foreach ($album_cate as $k => $v) {
                $cate = array();
                $cate['cate_id'] = $v['id'];
                $cate['cate_name'] = $v['name'];
                $cate['short_name'] = $v['name'];
                $cate['cate_code'] = $v['cate_code'];
                $cate['cate_icon'] = FS("Image")->getImageUrl($v['img'], 2);
                $cate['desc'] = $v['desc'];
                $cate['create_time'] = $v['create_time'];
                //获取本季分享数量
                $share_count_sql = 'select count(DISTINCT s.share_id) from ' . FDB::table("share") . ' as s 
					INNER JOIN ' . FDB::table("album_share") . ' as al on s.share_id = al.share_id where al.cid = ' . $v['id'] . " and s.day_time >= {$min_time} AND s.day_time <= {$max_time} ";
                $cate['share_count'] = FDB::resultFirst($share_count_sql);
                $cate['img_tags'] = array();
                $img_size = 320;
                $sql = 'select s.share_id,al.title,sp.img from ' . FDB::table("share") . ' as s
					INNER JOIN ' . FDB::table("album_share") . ' as als ON s.share_id = als.share_id 
					INNER JOIN ' . FDB::table("album") . ' as al ON als.album_id = al.id
					INNER JOIN ' . FDB::table("share_photo") . " as sp ON s.share_id = sp.share_id \r\n\t\t\t\t\tWHERE s.day_time >= {$min_time} AND s.day_time <= {$max_time} AND als.cid = " . $v['id'] . " GROUP BY s.share_id ORDER BY s.share_id desc limit 5";
                $res = FDB::query($sql);
                while ($data = FDB::fetch($res)) {
                    $img_data = array();
                    $img_data['share_id'] = $data['share_id'];
                    $img_data['tag_name'] = $data['title'];
                    $img_data['is_tag'] = 0;
                    $img_data['img'] = FS("Image")->getImageUrl(getImgName($data['img'], $img_size, $img_size, 1, true), 2);
                    $img_data['url_tag'] = urlencode($data['title']);
                    $cate['img_tags'][] = $img_data;
                    $img_size = 160;
                }
                $cate['txt_tags'] = array();
                $cate_list[] = $cate;
            }
            $cache_list = array();
            $cache_list['cate_list'] = $cate_list;
            $cache_list['cache_time'] = TIME_UTC;
            setCache($key, $cache_list);
        } else {
            $cate_list = $cache_list['cate_list'];
        }
        $root['item'] = $cate_list;
        m_display($root);
    }
    private function getList()
    {
        global $_FANWE;
        $_FANWE['user_click_share_id'] = (int) $_FANWE['request']['sid'];
        unset($_FANWE['request']['sid']);
        $cache_file = getTplCache('page/book/book_index', $_FANWE['request'], 2);
        if (getCacheIsUpdate($cache_file, BOOK_CACHE_PAGE_TIME)) {
            $category = urldecode($_FANWE['request']['cate']);
            $is_root = false;
            $page_args = array();
            if (isset($_FANWE['cache']['goods_category']['cate_code'][$category])) {
                $page_args['cate'] = $_FANWE['request']['cate'];
                $cate_id = $_FANWE['cache']['goods_category']['cate_code'][$category];
                $goods_cate_code = $category;
            } else {
                $is_root = true;
                $cate_id = $_FANWE['cache']['goods_category']['root'];
            }
            $sort = $_FANWE['request']['sort'];
            $sort = !empty($sort) ? $sort : "pop";
            $category_data = $_FANWE['cache']['goods_category']['all'][$cate_id];
            $category_tags = array();
            $_FANWE['nav_title'] = $category_data['cate_name'];
            if (!empty($category_data['seo_keywords'])) {
                $_FANWE['seo_keywords'] = $category_data['seo_keywords'];
                $_FANWE['setting']['site_keywords'] = '';
            }
            if (!empty($category_data['seo_desc'])) {
                $_FANWE['seo_description'] = $category_data['seo_desc'];
                $_FANWE['setting']['site_description'] = '';
            }
            $child_ids = array();
            if (isset($category_data['child'])) {
                $child_ids = $category_data['child'];
                if (!$is_root) {
                    $tagurlpara['cate'] = urlencode($category_data['cate_code']);
                }
                foreach ($category_data['child'] as $child_id) {
                    $child_cate = $_FANWE['cache']['goods_category']['all'][$child_id];
                    $tag_key = 'goods_category_tags_' . $child_id;
                    FanweService::instance()->cache->loadCache($tag_key);
                    foreach ($_FANWE['cache'][$tag_key] as $k => $tag) {
                        $tagurlpara['tag'] = urlencode($tag['tag_name']);
                        $tag['url'] = FU("book/" . ACTION_NAME, $tagurlpara);
                        $child_cate['tags'][] = $tag;
                        if ($k > 16) {
                            break;
                        }
                    }
                    $category_tags[] = $child_cate;
                }
            }
            $hot_tags = array();
            if (!$is_root) {
                $child_ids[] = $cate_id;
                require fimport("function/share");
                $hot_tags = getHotTags($child_ids, $category, 10);
            }
            $condition = " WHERE s.share_data IN ('goods','photo','goods_photo')";
            if (!$is_root) {
                $cids = array();
                FS('Share')->getChildCids($cate_id, $cids);
                $condition .= " AND sc.cate_id IN (" . implode(',', $cids) . ")";
            }
            $title = $category_data['short_name'];
            $is_match = false;
            $tag = urldecode($_FANWE['request']['kw']);
            if (!empty($tag)) {
                $_FANWE['nav_title'] = $tag . ' - ' . $_FANWE['nav_title'];
                $title = htmlspecialchars($tag);
                $is_match = true;
                //$match_key = FS('Words')->segment($tag,10);
                //$match_key = tagToUnicode($match_key,'+');
                $match_key = segmentToUnicode($tag, '+');
                $condition .= " AND match(sm.content_match) against('" . $match_key . "' IN BOOLEAN MODE) ";
                $page_args['tag'] = urlencode($tag);
            }
            //输出排序URL
            $sort_page_args = $page_args;
            $sort_page_args['sort'] = 'hot7';
            $hot7_url['url'] = FU('book/' . ACTION_NAME, $sort_page_args);
            if ($sort == 'hot7') {
                $hot7_url['act'] = 1;
            }
            $sort_page_args['sort'] = 'hot30';
            $hot30_url['url'] = FU('book/' . ACTION_NAME, $sort_page_args);
            if ($sort == 'hot30') {
                $hot30_url['act'] = 1;
            }
            $sort_page_args['sort'] = 'new';
            $new_url['url'] = FU('book/' . ACTION_NAME, $sort_page_args);
            if ($sort == 'new') {
                $new_url['act'] = 1;
            }
            $sort_page_args['sort'] = 'pop';
            $pop_url['url'] = FU('book/' . ACTION_NAME, $sort_page_args);
            if ($sort == 'pop') {
                $pop_url['act'] = 1;
            }
            if (!empty($_FANWE['request']['sort'])) {
                $page_args['sort'] = $sort;
            } else {
                $page_args['sort'] = 'pop';
            }
            $today_time = getTodayTime();
            switch ($sort) {
                //7天最热 点击次数
                case 'hot7':
                    $day7_time = $today_time - 604800;
                    $field = ",(s.create_time > {$day7_time}) AS time_sort ";
                    $sort = " ORDER BY time_sort DESC,s.click_count DESC";
                    break;
                    //30天最热 点击次数
                //30天最热 点击次数
                case 'hot30':
                    $day30_time = $today_time - 2592000;
                    $field = ",(s.create_time > {$day30_time}) AS time_sort ";
                    $sort = " ORDER BY time_sort DESC,s.click_count DESC";
                    break;
                    //最新
                //最新
                case 'new':
                    $field = '';
                    $sort = " ORDER BY s.share_id DESC";
                    break;
                    //潮流  喜欢人数
                //潮流  喜欢人数
                case 'pop':
                default:
                    $day7_time = $today_time - 604800;
                    $field = ",(s.create_time > {$day7_time}) AS time_sort ";
                    $sort = " ORDER BY time_sort DESC,s.collect_count DESC";
                    break;
            }
            $sql = 'SELECT DISTINCT(s.share_id),s.uid,s.content,s.collect_count,s.comment_count,s.create_time,s.cache_data ' . $field . '
					FROM ' . FDB::table('share') . ' AS s ';
            if (!$is_root) {
                $sql .= 'INNER JOIN ' . FDB::table('share_category') . ' AS sc ON s.share_id = sc.share_id ';
            }
            if ($is_match) {
                $sql .= 'INNER JOIN ' . FDB::table('share_match') . ' AS sm ON sm.share_id = s.share_id ';
            }
            $sql .= $condition . $sort;
            $sql_count = 'SELECT COUNT(DISTINCT s.share_id)
				FROM ' . FDB::table('share') . ' AS s ';
            if (!$is_root) {
                $sql_count .= 'INNER JOIN ' . FDB::table('share_category') . ' AS sc ON s.share_id = sc.share_id ';
            }
            if ($is_match) {
                $sql_count .= 'INNER JOIN ' . FDB::table('share_match') . ' AS sm ON sm.share_id = s.share_id ';
            }
            $sql_count .= $condition;
            $page_size = 50;
            $max_page = 100;
            $count = FDB::resultFirst($sql_count);
            if ($count > $max_page * $page_size) {
                $count = $max_page * $page_size;
            }
            if ($_FANWE['page'] > $max_page) {
                $_FANWE['page'] = $max_page;
            }
            $pager = buildPage('book/' . $action, $page_args, $count, $_FANWE['page'], $page_size, '', 3);
            $share_datas = array();
            $sql = $sql . ' LIMIT ' . $pager['limit'];
            $share_list = FDB::fetchAll($sql);
            $share_list = FS('Share')->getShareDetailList($share_list, false, false, false, true, 2);
            $col = 4;
            $index = 0;
            $share_display = array();
            foreach ($share_list as $share) {
                $mod = $index % $col;
                $share_display['col' . $mod][] = $share;
                $index++;
            }
            include template('page/book/book_index');
            display($cache_file);
            exit;
        } else {
            include $cache_file;
            display();
        }
    }
    public function save()
    {
        global $_FANWE;
        if ($_FANWE['uid'] == 0) {
            fHeader("location: " . FU('user/login'));
        }
        $id = (int) $_FANWE['request']['id'];
        if ($id > 0) {
            $album = FS("Album")->getAlbumById($id);
            if (empty($album) || $album['uid'] != $_FANWE['uid']) {
                fHeader("location: " . FU('album'));
            }
        }
        $data = array('title' => trim($_FANWE['request']['title']), 'content' => trim($_FANWE['request']['content']), 'cid' => (int) $_FANWE['request']['cid'], 'show_type' => (int) $_FANWE['request']['show_type'], 'tags' => trim($_FANWE['request']['tags']));
        $vservice = FS('Validate');
        $validate = array(array('title', 'required', lang('album', 'name_require')), array('title', 'max_length', lang('album', 'name_max'), 60), array('content', 'max_length', lang('album', 'content_max'), 1000), array('cid', 'min', lang('album', 'cid_min'), 1), array('show_type', 'min', lang('album', 'show_type_min'), 1));
        if (!$vservice->validation($validate, $data)) {
            exit($vservice->getError());
        }
        if (!isset($_FANWE['cache']['albums']['category'][$data['cid']])) {
            exit;
        }
        if (!checkIpOperation("add_share", SHARE_INTERVAL_TIME)) {
            showError('提交失败', lang('share', 'interval_tips'), -1);
        }
        $check_result = FS('Share')->checkWord($_FANWE['request']['title'], 'title');
        if ($check_result['error_code'] == 1) {
            showError('提交失败', $check_result['error_msg'], -1);
        }
        $check_result = FS('Share')->checkWord($_FANWE['request']['content'], 'content');
        if ($check_result['error_code'] == 1) {
            showError('提交失败', $check_result['error_msg'], -1);
        }
        $check_result = FS('Share')->checkWord($_FANWE['request']['tags'], 'tag');
        if ($check_result['error_code'] == 1) {
            showError('提交失败', $check_result['error_msg'], -1);
        }
        $tags = str_replace('***', '', $_FANWE['request']['tags']);
        $tags = str_replace(' ', ' ', $tags);
        $tags = explode(' ', $tags);
        $tags = array_unique($tags);
        if (count($tags) > $_FANWE['cache']['albums']['setting']['album_tag_count']) {
            exit;
        }
        if ($id > 0) {
            $data['title'] = htmlspecialchars($_FANWE['request']['title']);
            $data['content'] = htmlspecialchars($_FANWE['request']['content']);
            $data['tags'] = implode(' ', $tags);
            FDB::update('album', $data, 'id = ' . $id);
            FS('Share')->updateShare($album['share_id'], $data['title'], $data['content']);
            FS("Album")->saveTags($id, $tags);
            if ($data['cid'] != $album['cid']) {
                FDB::query('UPDATE ' . FDB::table("album_share") . ' SET cid = ' . $data['cid'] . ' WHERE album_id = ' . $id);
            }
            $url = FU('album/show', array('id' => $id));
            fHeader('location: ' . $url);
            exit;
        }
        $_FANWE['request']['uid'] = $_FANWE['uid'];
        $_FANWE['request']['type'] = 'album';
        $share = FS('Share')->submit($_FANWE['request']);
        if ($share['status']) {
            $data['title'] = htmlspecialchars($_FANWE['request']['title']);
            $data['content'] = htmlspecialchars($_FANWE['request']['content']);
            $data['tags'] = implode(' ', $tags);
            $data['uid'] = $_FANWE['uid'];
            $data['share_id'] = $share['share_id'];
            $data['create_day'] = getTodayTime();
            $data['create_time'] = TIME_UTC;
            $aid = FDB::insert('album', $data, true);
            FS("Album")->saveTags($aid, $tags);
            FDB::query('UPDATE ' . FDB::table('share') . ' SET rec_id = ' . $aid . ' 
				WHERE share_id = ' . $share['share_id']);
            FDB::query("update " . FDB::table("user_count") . " set albums = albums + 1 where uid = " . $_FANWE['uid']);
            FS('Medal')->runAuto($_FANWE['uid'], 'albums');
            $url = FU('album/show', array('id' => $aid));
            fHeader('location: ' . $url);
        } else {
            showError('提交失败', '添加数据失败', -1);
        }
    }
/**
 *  当前模板用到的相关函数
*/
function getHotCate()
{
    global $_FANWE;
    $args = array();
    FanweService::instance()->cache->loadCache('albums');
    $category_id = urldecode($_FANWE['request']['hot']);
    $tag = $_FANWE['request']['tag'];
    $sort = $_FANWE['request']['sort'];
    $link_url = $_FANWE['site_url'] . "services/service.php?m=index&a=share&width=190&p=2";
    $json_url = $_FANWE['site_url'] . "services/service.php?m=index&a=share&width=190";
    //判断排序
    if ($sort) {
        if ($sort == 'hot') {
            $link_url .= "&sort=collect_count";
            $json_url .= "&sort=collect_count";
        }
    }
    //判断分类
    if ($category_id) {
        $args['category_id'] = $category_id;
        $link_url .= "&cate=" . $category_id;
        $json_url .= "&cate=" . $category_id;
    }
    if ($tag) {
        $link_url .= "&tag=" . $tag;
        $json_url .= "&tag=" . $tag;
    }
    $is_cate = false;
    $today_time = getTodayTime();
    $day7_time = $today_time - 604800;
    $img_width = 190;
    $cate_id = $category_id;
    $sort_field = $_FANWE['request']['sort'];
    $page_num = intval($_FANWE['setting']['share_index_page']) ? intval($_FANWE['setting']['share_index_page']) : 30;
    $is_cate = false;
    if ($cate_id) {
        $is_cate = true;
    }
    if ($is_cate) {
        $condition .= " AND als.cid = " . $cate_id;
        $join_sql = ' LEFT JOIN ' . FDB::table('album_share') . ' AS als ON als.share_id = s.share_id ';
    }
    $audit_index = intval($_FANWE['setting']['audit_index']);
    if ($audit_index) {
        $condition .= " AND s.status =1 ";
    }
    $page = intval($_REQUEST['p']);
    $field = ",(s.create_time > {$day7_time}) AS time_sort ";
    $sort = " ";
    if ($sort_field == 'hot') {
        $sort = "  ORDER BY s.collect_count DESC ";
    } else {
        $sort = "  ORDER BY s.share_id DESC ";
    }
    $sql = 'SELECT DISTINCT(s.share_id),s.uid,s.content,s.collect_count,s.comment_count,s.create_time,s.cache_data ,s.parent_id ' . $field . '
					FROM ' . FDB::table('share') . ' AS s  ' . $join_sql . ' where s.share_data <> ' . " 'default' " . $condition . $sort . ' LIMIT ' . $page_num;
    $is_next = 1;
    $share_list = FDB::fetchAll($sql);
    $scale = 1;
    if ($share_list) {
        $share_list = FS('Share')->getShareDetailList($share_list, false, false, false, true, 2);
        $list = array();
        $current_user = array();
        $current_user['u_url'] = FU('u/index', array('uid' => $_FANWE['uid']));
        $current_user['avt'] = avatar($_FANWE['uid'], 's', $is_src = 1);
        $i = 0;
        foreach ($share_list as $k => $v) {
            $list[$i] = $v;
            $img = FDB::fetchFirst("select img,img_height,img_width,is_animate,video from " . FDB::table("share_photo") . " where share_id = " . $v['share_id'] . " and img <> '' ");
            if ($img['is_animate'] == 1) {
                $img_url = $img['img'];
            } else {
                $img_url = getImgName($img['img'], $img_width, 999, 2, true);
            }
            $is_video = 0;
            if (!empty($img['video'])) {
                $is_video = 1;
                $vedio_url = $img['video'];
            }
            $list[$i]['is_video'] = $is_video;
            $list[$i]['video'] = $vedio_url;
            //$img_url = getImgName($img['img'],$img_width,999,2,true);
            $list[$i]['share_img'] = $img_url;
            $list[$i]['height'] = $img['img_height'] * ($img_width / $img['img_width']);
            /*获取play图标的位置*/
            $list[$i]['video_style_top'] = ($list[$i]['height'] - 33) / 2;
            $list[$i]['video_style_right'] = (254 - 33) / 2;
            $list[$i]['height'] = round($list[$i]['height'] / $scale);
            $list[$i]['is_animate'] = $img['is_animate'];
            $list[$i]['width'] = $img_width;
            $list[$i]['avt'] = avatar($v['uid'], 's', $is_src = 1);
            $parent_id = FDB::resultFirst("select parent_id from " . FDB::table("share") . " where share_id = " . $v['share_id']);
            if ($parent_id == 0) {
                $list[$i]['isOriginal'] = 1;
            } else {
                $list[$i]['isOriginal'] = 0;
            }
            $list[$i]['likeStatus'] = FS('Share')->getIsCollectByUid($v['share_id'], $_FANWE['uid']) ? 1 : 0;
            $list[$i]['isMe'] = $v['uid'] == $_FANWE['uid'] ? 1 : 0;
            $list[$i]['is_relay'] = $v['is_relay'];
            //分享评论
            $share_comments = FS('Share')->getShareCommentList($v['share_id'], '0,2');
            if ($share_comments) {
                $share_comments_data = array();
                $idxj = 0;
                foreach ($share_comments as $vv) {
                    $share_comments_data[$idxj]['comment_id'] = $vv['comment_id'];
                    $share_comments_data[$idxj]['parent_id'] = $vv['parent_id'];
                    $share_comments_data[$idxj]['user_url'] = FU('u/album', array('uid' => $vv['user']['uid']));
                    $share_comments_data[$idxj]['user_name'] = $vv['user']['user_name'];
                    $share_comments_data[$idxj]['avt'] = avatar($vv['uid'], 's', $is_src = 1);
                    $share_comments_data[$idxj]['comment'] = cutStr($vv['content'], 20);
                    $idxj++;
                }
                $list[$i]['comments'] = $share_comments_data;
            }
            $list[$i]['share_url'] = FU('note/index', array('sid' => $v['share_id']));
            $list[$i]['u_url'] = FU('u/album', array('uid' => $v['uid']));
            $list[$i]['relay_count'] = FDB::resultFirst("select relay_count from " . FDB::table("share") . " where share_id = " . $v['share_id']);
            $album_sql = "select a.id,a.title from  " . FDB::table('album_share') . " as ah left join " . FDB::table('album') . " as a on ah.album_id = a.id where ah.share_id = " . $v['share_id'];
            $album = FDB::fetchFirst($album_sql);
            if ($album) {
                $list[$i]['album_title'] = $album['title'];
                $list[$i]['is_album'] = 1;
                $list[$i]['album_url'] = FU("album/show", array('id' => $album['id']));
            } else {
                $list[$i]['album_title'] = "";
                $list[$i]['is_album'] = 0;
                $list[$i]['album_url'] = "";
            }
            $list[$i]['user_name'] = FDB::resultFirst("select user_name from " . FDB::table('user') . " where uid =" . $v['uid']);
            $i++;
        }
        $args['list'] = $list;
    }
    $args['current_user'] = $current_user;
    $args['link_url'] = $link_url;
    $args['json_url'] = $json_url;
    return tplFetch('inc/index/index_cate', $args);
}
    exit;
}
$check_result = FS('Share')->checkWord($_FANWE['request']['title'], 'title');
if ($check_result['error_code'] == 1) {
    $result['msg'] = $check_result['error_msg'];
    outputJson($result);
}
$_FANWE['request']['uid'] = $_FANWE['uid'];
$_FANWE['request']['type'] = 'album';
$_FANWE['request']['content'] = $_FANWE['request']['title'];
$share = FS('Share')->submit($_FANWE['request'], false, true, true);
if ($share['status']) {
    $data['title'] = htmlspecialchars($_FANWE['request']['title']);
    $data['album_title_match'] = segmentToUnicode(clearSymbol($data['title']));
    $data['uid'] = $_FANWE['uid'];
    $data['share_id'] = $share['share_id'];
    $data['create_day'] = getTodayTime();
    $data['create_time'] = TIME_UTC;
    $data['show_type'] = 2;
    $aid = FDB::insert('album', $data, true);
    FDB::query('UPDATE ' . FDB::table('share') . ' SET rec_id = ' . $aid . ' 
		WHERE share_id = ' . $share['share_id']);
    FDB::query("update " . FDB::table("user_count") . " set albums = albums + 1 where uid = " . $_FANWE['uid']);
    $result['url'] = FU("album/show", array('id' => $aid));
    $result['aid'] = $aid;
    $result['title'] = $data['title'];
    $result['status'] = 1;
} else {
    $result['msg'] = '添加数据失败';
}
outputJson($result);
 public function updateUserScore($uid, $model, $action, $msg = '', $rec_id = 0, $score = 0, $is_log = true)
 {
     global $_FANWE;
     $model = strtolower($model);
     $action = strtolower($action);
     $handle = $model . "_" . $action . "_score";
     if ($handle != "jifen_exchange_score" && $score == 0) {
         $score = (int) $_FANWE['setting'][$handle];
     }
     if (abs($score) > 0) {
         if ($rec_id == 0) {
             $rec_id = $uid;
         }
         $setting_max_score = (int) $_FANWE['setting']['today_max_score'];
         $today_score = 0;
         if ($score > 0 && $setting_max_score > 0) {
             $today_score = UserService::getUserTodayScore($uid);
             if ($today_score > $setting_max_score) {
                 $score = 0;
                 $msg .= ' (超过每天最多积分' . $setting_max_score . '限定)';
             }
         }
         $is_update = true;
         $is_update = FDB::query("UPDATE " . FDB::table('user') . " SET credits = credits + " . intval($score) . " WHERE uid = {$uid}", 'UNBUFFERED');
         if ($is_update !== false) {
             if ($is_log) {
                 $log['uid'] = $uid;
                 $log['score'] = $score;
                 $log['create_time'] = TIME_UTC;
                 $log['create_day'] = getTodayTime();
                 $log['content'] = lang('user', $handle);
                 if (!empty($msg)) {
                     $log['content'] .= ' ' . $msg;
                 }
                 $log['rec_id'] = $rec_id;
                 $log['rec_module'] = $model;
                 $log['rec_action'] = $action;
                 FDB::insert('user_score_log', $log);
             }
             if ($score > 0 && $setting_max_score > 0) {
                 UserService::updateUserTodayScore($uid, $score);
             }
             if ($score < 0) {
                 FDB::query("UPDATE " . FDB::table('user') . " SET credits = 0 WHERE uid = {$uid} AND credits < 0");
             }
         } else {
             return false;
         }
     }
     return true;
 }
    /**  
     * 获取达人列表
     * @return array
     */
    public function getDarens($limit = '0,15')
    {
        $key = str_replace(',', '_', $limit);
        $list = getCache('daren/index/list_' . $key);
        if ($list === NULL) {
            $today_time = getTodayTime() + 86400;
            $sql = 'SELECT ud.uid,ud.reason,u.user_name 
				FROM ' . FDB::table('user_daren') . ' AS ud 
				INNER JOIN ' . FDB::table('user') . ' AS u ON u.uid = ud.uid  
				WHERE ud.status = 1 AND ud.day_time < ' . $today_time . '
				ORDER BY ud.id DESC LIMIT ' . $limit;
            $list = FDB::fetchAll($sql);
            setCache('daren/index/list_' . $key, $list);
        }
        return $list;
    }
 /**
  * 添加一条统计信息
  * @param array $data
  * @return
  */
 public function insert($data)
 {
     $data['uid'] = (int) $data['uid'];
     $data['num'] = (int) $data['num'];
     $data['last_time'] = (int) $data['lastday'];
     $data['type'] = StatisticsService::getTypeByKey($data['type']);
     if (!$data['last_time']) {
         $data['last_time'] = getTodayTime();
     }
     if (!$data['uid'] || !$data['type']) {
         return false;
     }
     FDB::insert('user_statistics', $data);
     return true;
 }
<?php

global $_FANWE;
$is_cate = false;
$today_time = getTodayTime();
$day7_time = $today_time - 604800;
$img_width = $_FANWE['request']['width'];
$cate_id = urldecode($_FANWE['request']['cate']);
$sort_field = $_FANWE['request']['sort'];
$page_num = intval($_FANWE['setting']['share_index_page']) ? intval($_FANWE['setting']['share_index_page']) : 30;
$is_cate = false;
if ($cate_id) {
    $is_cate = true;
}
if ($is_cate) {
    $condition .= " AND als.cid = " . $cate_id;
    $join_sql = ' LEFT JOIN ' . FDB::table('album_share') . ' AS als ON als.share_id = s.share_id ';
}
$audit_index = intval($_FANWE['setting']['audit_index']);
if ($audit_index) {
    $condition .= " AND s.status =1 ";
}
$page = intval($_REQUEST['p']);
$limit = ($page - 1) * $page_num . "," . $page_num;
$next_limit = $page * $page_num . "," . "1";
$field = ",(s.create_time > {$day7_time}) AS time_sort ";
$sort = " ";
if ($sort_field == 'collect_count') {
    $sort = "  ORDER BY s.collect_count DESC ";
} else {
    $sort = "  ORDER BY s.share_id DESC ";
Beispiel #13
0
    public function save()
    {
        global $_FANWE;
        if ($_FANWE['uid'] == 0) {
            fHeader("location: " . FU('user/login'));
        }
        if ($_FANWE['setting']['second_status'] == 0) {
            fHeader("location: " . FU('index'));
        }
        if (!isset($_FANWE['request']['pics']) || !is_array($_FANWE['request']['pics']) || count($_FANWE['request']['pics']) == 0) {
            exit;
        }
        $data = array('name' => trim($_FANWE['request']['title']), 'content' => trim($_FANWE['request']['content']), 'sid' => (int) $_FANWE['request']['sid'], 'num' => (int) $_FANWE['request']['num'], 'price' => (double) $_FANWE['request']['price'], 'transport_fee' => (double) $_FANWE['request']['fare'], 'valid_time' => (int) $_FANWE['request']['valid_time']);
        $vservice = FS('Validate');
        $validate = array(array('name', 'required', lang('second', 'name_require')), array('name', 'max_length', lang('second', 'name_max'), 40), array('content', 'required', lang('second', 'content_require')), array('content', 'max_length', lang('second', 'content_max'), 1000), array('sid', 'min', lang('second', 'sid_min'), 1), array('num', 'range', lang('second', 'num_range'), 1, 3), array('price', 'min', lang('second', 'price_min'), 0.01), array('transport_fee', 'min', lang('second', 'fee_min'), 0), array('valid_time', 'range', lang('second', 'valid_time_range'), 2, 30));
        if (!$vservice->validation($validate, $data)) {
            exit;
        }
        if (!isset($_FANWE['cache']['seconds'][$data['sid']])) {
            exit;
        }
        if (!checkIpOperation("add_share", SHARE_INTERVAL_TIME)) {
            showError('提交失败', lang('share', 'interval_tips'), -1);
        }
        $check_result = FS('Share')->checkWord($_FANWE['request']['content'], 'content');
        if ($check_result['error_code'] == 1) {
            showError('提交失败', $check_result['error_msg'], -1);
        }
        $check_result = FS('Share')->checkWord($_FANWE['request']['title'], 'title');
        if ($check_result['error_code'] == 1) {
            showError('提交失败', $check_result['error_msg'], -1);
        }
        $_FANWE['request']['uid'] = $_FANWE['uid'];
        $_FANWE['request']['type'] = 'ershou';
        $share = FS('Share')->submit($_FANWE['request']);
        if ($share['status']) {
            $data['name'] = htmlspecialchars($_FANWE['request']['title']);
            $data['content'] = htmlspecialchars($_FANWE['request']['content']);
            $data['uid'] = $_FANWE['uid'];
            $data['share_id'] = $share['share_id'];
            $data['city_id'] = $_FANWE['user']['reside_province'];
            $data['valid_time'] = getTodayTime() + 86400 * $data['valid_time'];
            $data['create_time'] = TIME_UTC;
            $data['status'] = 0;
            $gid = FDB::insert('second_goods', $data, true);
            $sign = md5($gid . $_FANWE['setting']['second_taobao_sign']);
            FDB::query('UPDATE ' . FDB::table('second_goods') . ' SET sign = \'' . $sign . '\' WHERE gid = ' . $gid);
            FDB::query('UPDATE ' . FDB::table('share') . ' SET rec_id = ' . $gid . ' 
				WHERE share_id = ' . $share['share_id']);
            FDB::query("update " . FDB::table("user_count") . " set seconds = seconds + 1 where uid = " . $_FANWE['uid']);
            FS('Medal')->runAuto($_FANWE['uid'], 'seconds');
            $url = "http://communityweb.alipay.com/dispatch.htm?type=exGuarantee&forumId=" . $_FANWE['setting']['second_taobao_forumid'] . "&exId=" . $gid . "&userIP=" . $_FANWE['client_ip'] . "&userIPSign=" . md5($_FANWE['client_ip'] . $_FANWE['setting']['second_taobao_sign']);
            fHeader('location: ' . $url);
        } else {
            showError('提交失败', '添加数据失败', -1);
        }
    }
Beispiel #14
0
 /**
  * 给一个用户颁发勋章
  * type{0:系统自动颁发,1:用户申请,2:管理员颁发}
  * @param int $uid
  * @param int $mid
  * @param bool $is_apply 是否是申请勋章
  * @param array $medal 勋章信息(可选)
  * @
  * @return bool
  */
 public function awardMedal($uid, $mid, $is_apply = false, $medal = array(), $desc = '')
 {
     if (MedalService::getAwardByUidAndMid($uid, $mid)) {
         return array(false, '勋章已存在');
     }
     $medal = $medal ? $medal : MedalService::get($mid);
     if (!$medal) {
         return array(false, '勋章不存在');
     }
     $data = array('uid' => $uid, 'mid' => $mid, 'create_time' => TIME_UTC);
     if ($medal['give_type'] == 1 && $medal['expiration']) {
         $today_time = getTodayTime();
         $data['deadline'] = $today_time + $medal['expiration'] * 86400;
     }
     $data['type'] = $medal['give_type'] == 1 ? $is_apply ? 1 : 2 : 0;
     $result = FDB::insert('user_medal', $data, true);
     if ($result) {
         MedalService::sendAwardNotice($uid, $medal, $data['type'], $desc);
     }
     return array($result);
 }
    public function index()
    {
        global $_FANWE;
        FanweService::instance()->cache->loadCache('style_category');
        $sort = $_FANWE['request']['sort'];
        $sort = !empty($sort) ? $sort : "pop";
        $category_data = $_FANWE['cache']['style_category']['all'][3];
        $category_tags = array();
        $_FANWE['nav_title'] = $category_data['cate_name'];
        $child_ids = array();
        if (isset($category_data['child'])) {
            $child_ids = $category_data['child'];
            foreach ($category_data['child'] as $child_id) {
                $child_cate = $_FANWE['cache']['style_category']['all'][$child_id];
                $tag_key = 'style_category_tags_' . $child_id;
                FanweService::instance()->cache->loadCache($tag_key);
                foreach ($_FANWE['cache'][$tag_key] as $k => $tag) {
                    $tagurlpara['tag'] = urlencode($tag['tag_name']);
                    $tag['url'] = FU("style/" . ACTION_NAME, $tagurlpara);
                    $child_cate['tags'][] = $tag;
                }
                $category_tags[] = $child_cate;
            }
        }
        $condition = " WHERE sp.type = 'dapei' AND s.is_best = 1";
        $title = $category_data['short_name'];
        $is_match = false;
        $tag = urldecode($_FANWE['request']['tag']);
        if (!empty($tag)) {
            $_FANWE['nav_title'] = $tag . ' - ' . $_FANWE['nav_title'];
            $title = htmlspecialchars($tag);
            $is_match = true;
            $match_key = segmentToUnicode($tag, '+');
            $condition .= " AND match(sm.content_match) against('" . $match_key . "' IN BOOLEAN MODE) ";
            $page_args['tag'] = urlencode($tag);
        }
        //输出排序URL
        $sort_page_args = $page_args;
        $sort_page_args['sort'] = 'hot7';
        $hot7_url['url'] = FU('style/' . ACTION_NAME, $sort_page_args);
        if ($sort == 'hot7') {
            $hot7_url['act'] = 1;
        }
        $sort_page_args['sort'] = 'hot30';
        $hot30_url['url'] = FU('style/' . ACTION_NAME, $sort_page_args);
        if ($sort == 'hot30') {
            $hot30_url['act'] = 1;
        }
        $sort_page_args['sort'] = 'new';
        $new_url['url'] = FU('style/' . ACTION_NAME, $sort_page_args);
        if ($sort == 'new') {
            $new_url['act'] = 1;
        }
        $sort_page_args['sort'] = 'pop';
        $pop_url['url'] = FU('style/' . ACTION_NAME, $sort_page_args);
        if ($sort == 'pop') {
            $pop_url['act'] = 1;
        }
        if (!empty($_FANWE['request']['sort'])) {
            $page_args['sort'] = $sort;
        } else {
            $page_args['sort'] = 'pop';
        }
        $today_time = getTodayTime();
        $field = '';
        switch ($sort) {
            //7天最热 点击次数
            case 'hot7':
                $day7_time = $today_time - 604800;
                $field = ",(s.create_time > {$day7_time}) AS time_sort ";
                $sort = " ORDER BY time_sort DESC,s.click_count DESC";
                break;
                //30天最热 点击次数
            //30天最热 点击次数
            case 'hot30':
                $day30_time = $today_time - 2592000;
                $field = ",(s.create_time > {$day30_time}) AS time_sort ";
                $sort = " ORDER BY time_sort DESC,s.click_count DESC";
                break;
                //最新
            //最新
            case 'new':
                $field = '';
                $sort = " ORDER BY s.share_id DESC";
                break;
                //潮流  喜欢人数
            //潮流  喜欢人数
            case 'pop':
            default:
                $day7_time = $today_time - 604800;
                $field = ",(s.create_time > {$day7_time}) AS time_sort ";
                $sort = " ORDER BY time_sort DESC,s.collect_count DESC";
                break;
        }
        $sql = 'SELECT s.* ' . $field . '
				FROM ' . FDB::table('share_photo') . ' AS sp 
				INNER JOIN  ' . FDB::table('share') . ' AS s ON s.share_id = sp.share_id ';
        if ($is_match) {
            $sql .= 'INNER JOIN ' . FDB::table('share_match') . ' AS sm ON sm.share_id = s.share_id ';
        }
        $sql .= $condition . ' GROUP BY s.share_id ' . $sort;
        $sql_count = 'SELECT COUNT(DISTINCT s.share_id)
			FROM ' . FDB::table('share_photo') . ' AS sp 
				INNER JOIN  ' . FDB::table('share') . ' AS s ON s.share_id = sp.share_id ';
        if ($is_match) {
            $sql_count .= 'INNER JOIN ' . FDB::table('share_match') . ' AS sm ON sm.share_id = s.share_id ';
        }
        $sql_count .= $condition;
        $page_size = 20;
        $max_page = 100;
        $count = FDB::resultFirst($sql_count);
        if ($count > $max_page * $page_size) {
            $count = $max_page * $page_size;
        }
        if ($_FANWE['page'] > $max_page) {
            $_FANWE['page'] = $max_page;
        }
        $pager = buildPage('style/' . ACTION_NAME, $page_args, $count, $_FANWE['page'], $page_size, '', 3);
        $share_datas = array();
        $sql = $sql . ' LIMIT ' . $pager['limit'];
        $share_list = FDB::fetchAll($sql);
        $share_list = FS('Share')->getShareDetailList($share_list, true, true, true, true);
        //本周最热时尚搭配
        $day7_time = $today_time - 604800;
        $sql = 'SELECT s.* ,(s.create_time > ' . $day7_time . ') AS time_sort 
			FROM ' . FDB::table('share_photo') . ' AS sp 
			INNER JOIN ' . FDB::table('share') . ' AS s ON s.share_id = sp.share_id 
			WHERE sp.type = \'dapei\' AND s.is_best = 1 
			GROUP BY s.share_id 
			ORDER BY time_sort DESC,s.click_count DESC 
			LIMIT 0,5';
        $share_week_hots = FDB::fetchAll($sql);
        $share_week_hots = FS('Share')->getShareDetailList($share_week_hots, true, true, true, true);
        include template('page/style/style_index');
        display();
    }
        $data['rel_goods'][] = array('name' => addslashes(htmlspecialchars($rec_obj['name'])), 'url' => $rec_obj['url'], 'taoke_url' => $rec_obj['taoke_url'], 'price' => $rec_obj['price'], 'sort' => 1, 'shop_id' => $rec_obj['shop_id'], 'goods_key' => $rec_obj['goods_key'], 'img' => $rec_obj['img'], 'base_id' => $rec_id, 'base_share' => $rec_share_id);
        $data['share_tag'] = FS('Words')->segment($rec_obj['name'], 5);
        break;
}
$data['pub_out_check'] = (int) $_FANWE['request']['pub_out_check'];
$share = FS("Share")->save($data);
if ($share['status']) {
    $bln = FDB::query("INSERT INTO " . FDB::table('share_rec') . "(share_id,rec_count) VALUES('{$rec_share_id}',1)", 'SILENT');
    if (!$bln) {
        FDB::query("UPDATE " . FDB::table('share_rec') . " SET rec_count = rec_count + 1 WHERE share_id = {$rec_share_id}");
    }
    $album_rec = array();
    $album_rec['album_id'] = $aid;
    $album_rec['ashare_id'] = $share['share_id'];
    $album_rec['share_id'] = $rec_share_id;
    $album_rec['rec_id'] = $rec_id;
    $album_rec['type'] = $rec_type;
    FDB::insert('album_rec', $album_rec);
    $album_share = array();
    $album_share['album_id'] = $aid;
    $album_share['share_id'] = $share['share_id'];
    $album_share['cid'] = $album['cid'];
    $album_share['create_day'] = getTodayTime();
    FDB::insert("album_share", $album_share);
    FS('Album')->updateAlbumByShare($aid, $share['share_id']);
    FS('Album')->updateAlbum($aid);
    $result['status'] = 1;
} else {
    $result['status'] = 0;
}
outputJson($result);
    public function run()
    {
        global $_FANWE;
        $root = array();
        $root['return'] = 1;
        $is_hot = (int) $_FANWE['requestData']['is_hot'];
        $is_new = (int) $_FANWE['requestData']['is_new'];
        $cid = (int) $_FANWE['requestData']['cid'];
        $tag = trim($_FANWE['requestData']['tag']);
        $is_spare_flow = (int) $_FANWE['requestData']['is_spare_flow'];
        $page = (int) $_FANWE['requestData']['page'];
        $page = max(1, $page);
        $img_width = 200;
        $max_height = 400;
        $scale = 2;
        if ($is_spare_flow == 1) {
            $img_width = 100;
            $scale = 1;
        }
        $today_time = getTodayTime();
        $field = '';
        $whrer = '';
        $joins = '';
        $book_photo_goods = (int) $_FANWE['setting']['book_photo_goods'];
        if ($book_photo_goods == 0) {
            $whrer = " WHERE s.share_data IN ('goods','photo','goods_photo')";
        } elseif ($book_photo_goods == 1) {
            $whrer = " WHERE s.share_data IN ('photo','goods_photo')";
        } elseif ($book_photo_goods == 2) {
            $whrer = " WHERE s.share_data IN ('goods','goods_photo')";
        }
        if ($cid > 0 && isset($_FANWE['cache']['goods_category']['all'][$cid])) {
            if ($_FANWE['cache']['goods_category']['all'][$cid]['is_root'] == 0) {
                $is_cate = true;
                $whrer .= " AND sc.cid = " . $cid;
                $joins .= ' INNER JOIN ' . FDB::table('album_share') . ' AS sc ON s.share_id = sc.share_id ';
            } else {
                $cid = 0;
            }
        } else {
            $cid = 0;
        }
        if (!empty($tag)) {
            $is_match = true;
            $match_key = segmentToUnicode($tag, '+');
            $whrer .= " AND match(s.share_content_match) against('" . $match_key . "' IN BOOLEAN MODE) ";
        }
        $joins .= ' INNER JOIN ' . FDB::table('share_photo') . ' as sp ON sp.share_id = s.share_id ';
        if ($is_hot == 1) {
            $day7_time = $today_time - 604800;
            $field = ",(s.create_time > {$day7_time}) AS time_sort ";
            $sort = " ORDER BY time_sort DESC,s.collect_count DESC";
        }
        if ($is_new == 1) {
            $sort = " ORDER BY s.share_id DESC";
        }
        $args = md5($is_hot . '/' . $is_new . '/' . $cid . '/t' . $tag . '/' . $is_spare_flow . '/' . $page);
        $key = 'm/sharelist/' . substr($args, 0, 2) . '/' . substr($args, 2, 2) . '/' . $args;
        $cache_list = getCache($key);
        if ($cache_list === NULL || TIME_UTC - $cache_list['cache_time'] > 600) {
            $sql_count = "SELECT COUNT(DISTINCT s.share_id) FROM " . FDB::table("share") . ' AS s' . $joins . $whrer;
            $total = FDB::resultFirst($sql_count);
            $page_size = 20;
            //PAGE_SIZE;
            $max_page = 100;
            if ($total > $max_page * $page_size) {
                $total = $max_page * $page_size;
            }
            if ($page > $max_page) {
                $page = $max_page;
            }
            $page_total = max(ceil($total / $page_size), 1);
            if ($page > $page_total) {
                $page = $page_total;
            }
            $limit = ($page - 1) * $page_size . "," . $page_size;
            $sql = 'SELECT DISTINCT(s.share_id),sp.img_width,sp.img_height,sp.img ' . $field . '
						FROM ' . FDB::table('share') . ' AS s' . $joins . $whrer . $sort . ' LIMIT ' . $limit;
            $res = FDB::query($sql);
            $share_list = array();
            while ($item = FDB::fetch($res)) {
                $cache_data = fStripslashes(unserialize($item['cache_data']));
                $img = current($cache_data['imgs']['all']);
                $data = array();
                $data['share_id'] = $item['share_id'];
                $data['img'] = FS("Image")->getImageUrl(getImgName($item['img'], $img_width, $max_height, 2, true), 2);
                $data['height'] = $item['img_height'] * ($img_width / $item['img_width']);
                $data['height'] = $data['height'] > $max_height ? $max_height : $data['height'];
                $data['height'] = round($data['height'] / $scale);
                $share_list[] = $data;
            }
            $cache_list = array();
            $cache_list['page_total'] = $page_total;
            $cache_list['share_list'] = $share_list;
            $cache_list['cache_time'] = TIME_UTC;
            setCache($key, $cache_list);
        } else {
            $page_total = $cache_list['page_total'];
            $share_list = $cache_list['share_list'];
        }
        $root['tag'] = $tag;
        $root['cid'] = $cid;
        $root['item'] = $share_list;
        $root['page'] = array("page" => $page, "page_total" => $page_total);
        if ($page == 1) {
            FanweService::instance()->cache->loadCache('madv');
            $advs = $_FANWE['cache']['madv']['sharelist'];
            if ($advs) {
                foreach ($advs as $adv) {
                    $adv['img'] = FS("Image")->getImageUrl($adv['img'], 2);
                    if ($adv['type'] == 1) {
                        $tag_count = count($adv['data']['tags']);
                        unset($adv['data']);
                        $adv['data']['count'] = $tag_count;
                    } elseif ($adv['type'] != 2 && $adv['type'] != 8) {
                        unset($adv['data']);
                    }
                    unset($adv['sort'], $adv['status'], $adv['page']);
                    $root['advs'][] = $adv;
                }
            }
        }
        m_display($root);
    }
Beispiel #18
0
    /**
     * 获取首页显示的分享分类最近7天最热标签的分享
     * @return array
     */
    public function getIndexCateTagShares($num = 30)
    {
        global $_FANWE;
        $day7_time = getTodayTime() - 604800;
        $cate_list =& ShareService::getIndexShareCateHotTags($num);
        if (!empty($cate_list['share_list'])) {
            $list = array();
            $share_datas = array();
            $sql = 'SELECT * FROM ' . FDB::table('share') . ' 
				WHERE share_id IN (' . implode(',', $cate_list['share_list']) . ')';
            $list = FDB::fetchAll($sql);
            $list = ShareService::getShareDetailList($list);
            foreach ($list as $data) {
                $cate_list['shares'][$data['share_id']]['share'] = $data;
            }
        }
        foreach ($cate_list['shares'] as $share) {
            $cate_id = $share['cate_id'];
            unset($share['cate_id']);
            $uid = $share['share']['uid'];
            if (!isset($cate_list[$cate_id]['user'][$uid])) {
                $cate_list[$cate_id]['user'][$uid] = $share['share']['user_name'];
            }
            $cate_list[$cate_id]['shares'][] = $share;
        }
        unset($cate_list['shares']);
        unset($cate_list['share_list']);
        return $cate_list;
    }