Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· OpenAIAi2 WildChat-4.8M (AI2)

我这段代码是获取dizcuss帖子的一个函数,帮我看看哪里有问题?function recommendposts($page){ global $G;…

  1. User

    我这段代码是获取dizcuss帖子的一个函数,帮我看看哪里有问题?function recommend_posts(page){ global _G; //expectfids=′1000′;//不调用的版块,多个用半角逗号分开//if(!expect_fids='1000';//不调用的版块,多个用半角逗号分开 //if(!_GET['from'] || _GET['from']==''){ // from="t.fid NOT in (expect_fids) and"; //} type = ''; //首页帖子主列表 tnum=35;tnum=35; lasttime = strtotime("-7 month"); begin=(begin=(page-1)tnum;tnum; manylist=array(); orderby=′t.‘dateline‘desc′;orderby='t.`dateline` desc'; sql = "SELECT t.,p.pid,f.name,i.viewperm,i.extra from ".DB::table("forum_thread")." t LEFT JOIN ".DB::table("forum_post")." p on p.tid=t.tid LEFT JOIN "; sql.=DB::table("forumforum")."fonf.fid=t.fidLEFTJOIN".DB::table("forumforumfield")."ioni.fid=t.fidWHEREt.displayorder>=0andt.dateline>sql .= DB::table("forum_forum")." f on f.fid=t.fid LEFT JOIN ".DB::table("forum_forumfield")." i on i.fid=t.fid WHERE t.displayorder>=0 and t.dateline>lasttime and p.first=1 and f.status=1 typegroupbyt.tidORDERBYtype group by t.tid ORDER BY orderby LIMIT begin,begin , tnum"; res=DB::query(res = DB::query(sql);

    $usergroup=user_group($_G['uid']);
    $userextgroupids=explode(",",preg_replace("/\s+/", ",", $usergroup["extgroupids"]));
    $allauthids=array();
    while ($rw=DB::fetch($res)) {
        if ($rw['readperm'] && $rw['readperm']>$usergroup['readaccess']){
            //跳过无权限帖子。
            continue;
        }
        $viewperms = trim($rw["viewperm"]);
        $viewperms_a = explode(",",preg_replace("/\s+/", ",", $viewperms));
        
        if ($usergroup['groupid']=="1" || empty($viewperms_a)){
            //all can view.
        }else if (!in_array($usergroup['groupid'],$viewperms_a) && empty(array_intersect($userextgroupids, $viewperms_a))){
            continue;
        }
    
        $rw['lastposterenc']=urlencode($rw['lastposter']);
        $rw['lastposterid']=DB::result_first("select authorid from ".DB::table("forum_post")." where tid='$rw[tid]' and first=0 ORDER BY pid desc");
        $rw['extra'] = unserialize(stripslashes($rw['extra']));// forumcolor
        //$rw['dateline'] = dgmdate($rw['dateline'], 'u', '9999', getglobal('setting/dateformat')); //$rw['dateline'] = dgmdate($rw['dateline'],'Y-m-d H:i');
        $rw['rushreply'] = getstatus($rw['status'], 3);
    
        if($rw['highlight']) {
            $colorarray = array('', '#EE1B2E', '#EE5023', '#996600', '#3C9D40', '#2897C5', '#2B65B7', '#8F2A90', '#EC1282');
            $string = sprintf('%02d', $rw['highlight']);
            $stylestr = sprintf('%03b', $string[0]);
            $rw['highlight'] = 'style="';
            $rw['highlight'] .= $stylestr[0] ? 'font-weight: bold;' : '';
            $rw['highlight'] .= $stylestr[1] ? 'font-style: italic;' : '';
            $rw['highlight'] .= $stylestr[2] ? 'text-decoration: underline;' : '';
            $rw['highlight'] .= $string[1] ? 'color: '.$colorarray[$string[1]] : '';
            $rw['highlight'] .= '"';
        } else {
            $rw['highlight'] = '';
        }
        $post = C::t('forum_post')->fetch_threadpost_by_tid_invisible($rw['tid']);
        $rw['message'] = trim(messagecutstr($post['message'], 230));
        $table='forum_attachment_'.substr($rw['tid'], -1);
        $getimage = DB::fetch_first("SELECT aid,attachment FROM ".DB::table($table)." WHERE tid='$rw[tid]' AND readperm=0 AND price=0 AND isimage!=0 ORDER BY `dateline` ASC LIMIT 0,1");
        $rw['image'] = getforumimg($getimage['aid'],0,190,105);
        $manylist[]=$rw;
        $allauthids[]=$rw['authorid'];
    }
    loadcache('stamps');
    return $manylist;
    

    }

  2. Assistant

    该段代码中没有明显的语法错误,但是缺少函数调用的前置条件和部分变量定义,需要查看整个代码文件才能确定是否有问题。建议在执行该函数前添加必要的变量定义和函数调用,保证代码的完整性和正确性。