<?php



/**

 *      [Discuz!] (C)2001-2099 Comsenz Inc.

 *      This is NOT a freeware, use is subject to license terms

 *

 *      $Id: space_thread.php 28220 2012-02-24 07:52:50Z zhengqingpeng $

 */



    if(!defined('IN_DISCUZ')) {

            exit('Access Denied');

    }





    if(!isset($_GET['uid'])) {

            $_GET['uid'] = isset($_G['uid']) ? $_G['uid'] : 0;

    }



    $space = getuserbyuid($_GET['uid']);



    $minhot = $_G['setting']['feedhotmin']<1?3:$_G['setting']['feedhotmin'];

    $page = empty($_GET['page'])?1:intval($_GET['page']);

    if($page<1) $page=1;

    if(empty($_GET['view'])) $_GET['view'] = 'me';

    $_GET['order'] = empty($_GET['order']) ? 'dateline' : $_GET['order'];

    $allowviewuserthread = $_G['setting']['allowviewuserthread'];

    $perpage = 20;

    $start = ($page-1)*$perpage;

    $list = array();

    $userlist = array();

    $hiddennum = $count = $pricount = 0;

    $multi = '';

    $authorid = 0;

    $replies = $closed = $displayorder = null;

    $dglue = '=';

    $vfid = $_GET['fid'] ? intval($_GET['fid']) : null;

    require_once libfile('function/misc');

    require_once libfile('function/forum');

    loadcache(array('forums'));

    $fids = $comma = '';

    $need_count = true;

    $viewuserthread = false;

    $listcount = 0;

    if($_GET['view'] == 'me') {

            $allowview = true;

            $viewtype = in_array($_GET['type'], array('reply', 'thread', 'postcomment')) ? $_GET['type'] : 'thread';

            if($space['uid'] != $_G['uid'] && in_array($viewtype, array('reply', 'thread'))) {

                    if($allowview) {

                            $viewuserthread = true;

                            $viewfids = str_replace("'", '', $allowviewuserthread);

                            if(!empty($viewfids)) {

                                    $viewfids = explode(',', $viewfids);

                            }

                    }

            }

            if($viewtype == 'thread' && $allowview) {

                    $authorid = $space['uid'];

                    $ordersql = 't.tid DESC';

            } 

    }

    if($searchkey = stripsearchkey($_GET['searchkey'])) {

            $searchkey = dhtmlspecialchars($searchkey);

    }

    loadcache('forums');

    $gids = $fids = $forums = array();

    foreach(C::t('forum_thread')->fetch_all_by_authorid_displayorder($authorid, $displayorder, $dglue, $closed, $searchkey, $start, $perpage, $replies, $vfid) as $tid => $value) {

            if(empty($value['author']) && $value['authorid'] != $_G['uid']) {

                    $hiddennum++;

                    //continue;

            } elseif($viewuserthread && $value['authorid'] != $_G['uid']) {

                    if(($_G['adminid'] != 1 && !empty($viewfids) && !in_array($value['fid'], $viewfids)) || $value['displayorder'] < 0) {

                            $hiddennum++;

                            //continue;

                    }

            } elseif(!isset($_G['cache']['forums'][$value['fid']])) {

                    if(!$_G['setting']['groupstatus']) {

                            $hiddennum++;

                            //continue;

                    } else {

                            $gids[$value['fid']] = $value['tid'];

                    }

            }

            $list[$value['tid']] = procthread($value);

            $forums[$value['fid']] = $list[$value['tid']]['forumname'];

    }

    if(!empty($gids)) {

            $gforumnames = C::t('forum_forum')->fetch_all_name_by_fid(array_keys($gids));

            foreach($gids as $fid => $tid) {

                    $list[$tid]['forumname'] = $gforumnames[$fid]['name'];

                    $forums[$fid] = $gforumnames[$fid]['name'];

            }

    }

    $threads = &$list;

    if($_GET['view'] != 'all') {

            $listcount = count($list)+$hiddennum;

            $multi = simplepage($listcount, $perpage, $page, $theurl);

    }

    require_once libfile('function/forumlist');

    $threadlist = array();

    foreach($threads as $thread) {

        if(isset($_G['mocuz_config']['share_fid']) && $thread['fid'] == $_G['mocuz_config']['share_fid']){

                continue;

        }

        $threadlist[] = array(

            'tid' => $thread['tid'],

            'fid' => $thread['fid'],

            'author' => $thread['author'],

            'authorid' => $thread['authorid'],

            'subject' => odz_format_subject($thread['subject']),

            'dateline' => $thread['dateline'],

            'showtime' => dgmdate($thread['dateline'], 'mu'),

            'views' => $thread['views'],

            'replies' => $thread['replies'],

            'forumname' => strip_tags($thread['forumname']),

            'hasimageattachment' => ($thread['attachment'] == 2 ? 1 : 0), // �Ƿ����ͼƬ����

            'haslock' => $thread['closed'] // �����Ƿ�ر�

        );

    }

    odz_result(array('threadlist'=>$threadlist));

?>