forum.php

来自「php 开发的内容管理系统」· PHP 代码 · 共 811 行 · 第 1/3 页

PHP
811
字号
<?php
// $Id: forum.php,v 1.3 2005/10/19 17:20:32 phppp Exp $
//  ------------------------------------------------------------------------ //
//                XOOPS - PHP Content Management System                      //
//                    Copyright (c) 2000 XOOPS.org                           //
//                       <http://www.xoops.org/>                             //
//  ------------------------------------------------------------------------ //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
//  ------------------------------------------------------------------------ //
//  Author: phppp (D.J., infomax@gmail.com)                                  //
//  URL: http://xoopsforge.com, http://xoops.org.cn                          //
//  Project: Article Project                                                 //
//  ------------------------------------------------------------------------ //
 
if (!defined("XOOPS_ROOT_PATH")) {
	exit();
}

defined("NEWBB_FUNCTIONS_INI") || include XOOPS_ROOT_PATH.'/modules/newbb/include/functions.ini.php';
newbb_load_object();

class Forum extends ArtObject {

    function Forum()
    {
	    $this->ArtObject("bb_forums");
        $this->initVar('forum_id', XOBJ_DTYPE_INT);
        $this->initVar('forum_name', XOBJ_DTYPE_TXTBOX);
        $this->initVar('forum_desc', XOBJ_DTYPE_TXTAREA);
        $this->initVar('forum_moderator', XOBJ_DTYPE_ARRAY, serialize(array()));
        $this->initVar('forum_topics', XOBJ_DTYPE_INT);
        $this->initVar('forum_posts', XOBJ_DTYPE_INT);
        $this->initVar('forum_last_post_id', XOBJ_DTYPE_INT);
        $this->initVar('cat_id', XOBJ_DTYPE_INT);
        $this->initVar('forum_type', XOBJ_DTYPE_INT, 0); // 0 - active; 1 - inactive
        $this->initVar('parent_forum', XOBJ_DTYPE_INT);
        $this->initVar('allow_html', XOBJ_DTYPE_INT, 0); // To be added in 3.01: 0 - disabled; 1 - enabled; 2 - checked by default
        $this->initVar('allow_sig', XOBJ_DTYPE_INT, 1);
        $this->initVar('allow_subject_prefix', XOBJ_DTYPE_INT, 1);
        $this->initVar('hot_threshold', XOBJ_DTYPE_INT, 20);
        $this->initVar('allow_polls', XOBJ_DTYPE_INT, 0);
        //$this->initVar('allow_attachments', XOBJ_DTYPE_INT);
        $this->initVar('attach_maxkb', XOBJ_DTYPE_INT, 100);
        $this->initVar('attach_ext', XOBJ_DTYPE_TXTAREA, "zip|jpg|gif");
        $this->initVar('forum_order', XOBJ_DTYPE_INT, 99);
        /*
         * For desc
         *
         */
        $this->initVar("dohtml", XOBJ_DTYPE_INT, 1);
        $this->initVar("dosmiley", XOBJ_DTYPE_INT, 1);
        $this->initVar("doxcode", XOBJ_DTYPE_INT, 1);
        $this->initVar("doimage", XOBJ_DTYPE_INT, 1);
        $this->initVar("dobr", XOBJ_DTYPE_INT, 1);
    }

    // Get moderators in uname or in uid
    function &getModerators($asUname = false)
    {
	    static $_cachedModerators = array();

        $moderators = array_filter($this->getVar('forum_moderator'));
        if(!$asUname) return $moderators;

        $moderators_return = array();
        $moderators_new = array();
        foreach($moderators as $id){
	        if($id ==0) continue;
	        if(isset($_cachedModerators[$id])) $moderators_return[$id] = &$_cachedModerators[$id];
	        else $moderators_new[]=$id;
        }
        if(count($moderators_new)>0){
			include_once XOOPS_ROOT_PATH.'/modules/newbb/include/functions.php';
	        $moderators_new = newbb_getUnameFromIds($moderators_new);
	        foreach($moderators_new as $id => $name){
				$_cachedModerators[$id] = $name;
				$moderators_return[$id] = $name;
			}
        }
        return $moderators_return;
    }

    // deprecated
    function isSubForum()
    {
        return ($this->getVar('parent_forum') > 0);
    }

    function disp_forumModerators($valid_moderators = 0)
    {
    	global $xoopsDB, $xoopsModuleConfig, $myts;

        $ret = "";
        if ($valid_moderators === 0) {
            $valid_moderators = $this->getModerators();
        }
        if (empty($valid_moderators) || !is_array($valid_moderators)) {
            return $ret;
        }
		include_once XOOPS_ROOT_PATH.'/modules/newbb/include/functions.php';
        $moderators = newbb_getUnameFromIds($valid_moderators, !empty($xoopsModuleConfig['show_realname']), true);
		$ret = implode(", ", $moderators);
		return $ret;
    }
}

class NewbbForumHandler extends ArtObjectHandler
{
    function NewbbForumHandler(&$db) {
        $this->ArtObjectHandler($db, 'bb_forums', 'Forum', 'forum_id', 'forum_name');
    }

    function insert(&$forum)
    {
        if(!parent::insert($forum, true)){
	        xoops_error($forum->getErrors());
	        return false;
        }
        
        if ($forum->isNew()) {
        	$this->applyPermissionTemplate($forum);
    	}

        return $forum->getVar('forum_id');
    }

    function delete(&$forum)
    {
        global $xoopsModule;
        // RMV-NOTIFY
        xoops_notification_deletebyitem ($xoopsModule->getVar('mid'), 'forum', $forum->getVar('forum_id'));
        // Get list of all topics in forum, to delete them too
		$topic_handler =& xoops_getmodulehandler('topic', 'newbb');
		$topic_handler->deleteAll(new Criteria("forum_id", $forum->getVar('forum_id')), true, true);
        $this->updateAll("parent_forum", $forum->getVar('parent_forum'), new Criteria("parent_forum", $forum->getVar('forum_id')));
       	$this->deletePermission($forum);
        return parent::delete($forum);
    }

    function &getForums($cat = 0, $permission = "", $tags = null)
    {
	    $_cachedForums=array();
	    $perm_string = (empty($permission))?'all':$permission;
        $forum_handler =& xoops_getmodulehandler('forum', 'newbb');
	    $criteria = new CriteriaCompo(new Criteria("1", 1));
        if (is_numeric($cat) && $cat> 0) {
	        $criteria->add(new Criteria("cat_id", intval($cat)));
        }elseif(is_array($cat) && count($cat) >0){
            $criteria->add(new Criteria("cat_id", "(" . implode(", ", array_map("intval", $cat)).")", "IN"));
        }
        $criteria->setSort("forum_order");
        $criteria->setOrder("ASC");
        $forums =& $forum_handler->getAll($criteria, $tags);
        $_cachedForums[$perm_string]=array();
        foreach(array_keys($forums) as $key){
            if ($permission && !$this->getPermission($forums[$key], $permission, empty($cat))) continue;
            $_cachedForums[$perm_string][$key] =& $forums[$key];
        }
        // TODO: Retrieve subforums
        return $_cachedForums[$perm_string];
    }
    
    function &getForumsByCategory($categoryid = 0, $permission = "", $asObject = true, $tags = null)
    {
	    //$tags = array("parent_forum", "cat_id", "forum_name");
        $forums =& $this->getForums($categoryid, $permission, $tags);
        if($asObject) return $forums;
        
		$forums_array = array();
		$array_cat=array();
		$array_forum=array();
		if(!is_array($forums)) return array();
		foreach (array_keys($forums) as $forumid) {
			$forum =& $forums[$forumid];
		    $forums_array[$forum->getVar('parent_forum')][$forumid] = array(
			    'cid' => $forum->getVar('cat_id'),
			    'title' => $forum->getVar('forum_name')
			);
		}
		if(!isset($forums_array[0])) {
			$ret = array();
			return $ret;
		}
		foreach ($forums_array[0] as $key => $forum) {
		    if (isset($forums_array[$key])) {
		        $forum['sub'] = $forums_array[$key];
		    }
		    $array_forum[$forum['cid']][$key] = $forum;
		}
		ksort($array_forum);
		unset($forums);
		unset($forums_array);
        return $array_forum;
    }

    // Get moderators of multi-forums
    function &getModerators(&$forums, $asUname = false)
    {
        if (empty($forums)) $forums = $this->getForums();
        $moderators = array();
        if (is_array($forums)) {
            foreach ($forums as $forumid => $forum) {
                $moderators = array_merge($moderators, $forum->getModerators($asUname));
            }
        } elseif (is_object($forums)) {
            $moderators =& $forums->getModerators($asUname);
        }
        return $moderators;
    }

    function getAllTopics(&$forum, $startdate, $start, $sortname, $sortorder, $type = '', $excerpt = 0)
    {
        global $xoopsModule, $xoopsConfig, $xoopsModuleConfig, $forumImage, $forumUrl, $myts, $xoopsUser, $viewall_forums;
		include_once XOOPS_ROOT_PATH.'/modules/newbb/include/functions.php';
		
        $UserUid = is_object($xoopsUser) ? $xoopsUser->getVar('uid') : null;

        $topic_lastread = newbb_getcookie('LT', true);

        if (is_object($forum)) {
            $criteria_forum = ' AND t.forum_id = ' . $forum->getVar('forum_id');
            $hot_threshold = $forum->getVar('hot_threshold');
            $allow_subject_prefix = $forum->getVar('allow_subject_prefix');
        } else {
            $hot_threshold = 10;
            $allow_subject_prefix = 0;
            if (is_array($forum) && count($forum) > 0){
                $criteria_forum = ' AND t.forum_id IN (' . implode(',', array_keys($forum)) . ')';
            }elseif(!empty($forum)){
                $criteria_forum = ' AND t.forum_id ='.intval($forum);
            }else{
                $criteria_forum = '';
            }
        }

        $sort = array();
        $criteria_post = ' p.post_time > ' . $startdate;
        $criteria_extra = '';
        $criteria_approve = ' AND t.approved = 1 AND p.approved = 1';
        $post_on = ' p.post_id = t.topic_last_post_id';
        //$post_criteria = '';
        $leftjoin = ' LEFT JOIN ' . $this->db->prefix('bb_posts') . ' p ON p.post_id = t.topic_last_post_id';
        switch ($type) {
            case 'digest':
                $criteria_extra = ' AND t.topic_digest = 1';
                break;
            case 'unreplied':
                $criteria_extra = ' AND t.topic_replies < 1';
                break;
            case 'unread':
				//$time_criterion = max($GLOBALS['last_visit'], $startdate);
                if(empty($xoopsModuleConfig["read_mode"])){
                }elseif($xoopsModuleConfig["read_mode"] ==2){
	        		$leftjoin .= ' LEFT JOIN ' . $this->db->prefix('bb_reads_topic') . ' r ON r.read_item = t.topic_id';

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?