newbb_block.php

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

PHP
794
字号
<?php
// $Id: newbb_block.php,v 1.1.1.2 2005/10/19 16:23:31 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();
}
require_once(XOOPS_ROOT_PATH.'/modules/newbb/include/functions.php');
if(defined('NEWBB_BLOCK_DEFINED')) return;
define('NEWBB_BLOCK_DEFINED',true);

function b_newbb_array_filter($var){
	return $var > 0;
}

// options[0] - Citeria valid: time(by default)
// options[1] - NumberToDisplay: any positive integer
// options[2] - TimeDuration: negative for hours, positive for days, for instance, -5 for 5 hours and 5 for 5 days
// options[3] - DisplayMode: 0-full view;1-compact view;2-lite view
// options[4] - Display Navigator: 1 (by default), 0 (No)
// options[5] - Title Length : 0 - no limit
// options[6] - SelectedForumIDs: null for all

function b_newbb_show($options)
{
    global $xoopsConfig;
    global $access_forums;

    $db =& Database::getInstance();
    $myts =& MyTextSanitizer::getInstance();
    $block = array();
    $i = 0;
    $order = "";
    $extra_criteria = "";
	if(!empty($options[2])) {
		$time_criteria = time() - newbb_getSinceTime($options[2]);
		$extra_criteria = " AND p.post_time>".$time_criteria;
	}
    $time_criteria = null;
    switch ($options[0]) {
        case 'time':
        default:
            $order = 'p.post_time';
    		$extra_criteria .= " AND p.approved=1";
            break;
    }
    $newbbConfig = getConfigForBlock();
    			
    if(!isset($access_forums)){
	    $forum_handler =& xoops_getmodulehandler('forum', 'newbb');
    	if(!$access_obj =& $forum_handler->getForums(0, 'access', array('forum_id', 'cat_id', 'forum_type')) ){
	    	return null;
    	}
    	$access_forums = array_keys( $access_obj ); // get all accessible forums
    	unset($access_obj );
	}
    if (!empty($options[6])) {
        $allowedforums = array_filter(array_slice($options, 6), "b_newbb_array_filter"); // get allowed forums
        $allowed_forums = array_intersect($allowedforums, $access_forums);
    }else{
        $allowed_forums = $access_forums;
    }

    $forum_criteria = ' AND t.forum_id IN (' . implode(',', $allowed_forums) . ')';
    $approve_criteria = ' AND t.approved = 1';

    $query = 'SELECT'.
    		'	DISTINCT t.topic_id, t.topic_replies, t.forum_id, t.topic_title, t.topic_views, t.topic_subject,'.
    		'	f.forum_name, f.allow_subject_prefix,'.
    		'	p.post_id, p.post_time, p.icon, p.uid, p.poster_name'.
    		'	FROM ' . $db->prefix('bb_posts') . ' AS p '.
    		'	LEFT JOIN ' . $db->prefix('bb_topics') . ' AS t ON t.topic_last_post_id=p.post_id'.
    		'	LEFT JOIN ' . $db->prefix('bb_forums') . ' AS f ON f.forum_id=t.forum_id'.
    		'	WHERE 1=1 ' .
    			$forum_criteria .
    			$approve_criteria .
    			$extra_criteria .
    			' ORDER BY ' . $order . ' DESC';

    $result = $db->query($query, $options[1], 0);
    if (!$result) {
	    newbb_message("newbb block query error: ".$query);
        return false;
    }
    $block['disp_mode'] = $options[3]; // 0 - full view; 1 - compact view; 2 - lite view;
    $rows = array();
    $author = array();
    while ($row = $db->fetchArray($result)) {
        $rows[] = $row;
        $author[$row["uid"]] = 1;
    }
    if (count($rows) < 1) return false;
	$author_name = newbb_getUnameFromIds(array_keys($author), $newbbConfig['show_realname'], true);

    foreach ($rows as $arr) {
        $topic_page_jump = '';
        if ($arr['allow_subject_prefix']) {
            $subjectpres = explode(',', $newbbConfig['subject_prefix']);
            if (count($subjectpres) > 1) {
                foreach($subjectpres as $subjectpre) {
                    $subject_array[] = $subjectpre;
                }
               	$subject_array[0] = null;
            }
            $topic['topic_subject'] = $subject_array[$arr['topic_subject']];
        } else {
            $topic['topic_subject'] = "";
        }
        $topic['post_id'] = $arr['post_id'];
        $topic['forum_id'] = $arr['forum_id'];
        $topic['forum_name'] = $myts->htmlSpecialChars($arr['forum_name']);
        $topic['id'] = $arr['topic_id'];

        $title = $myts->htmlSpecialChars($arr['topic_title']);
        if(!empty($options[5])){
        	$title = xoops_substr($title, 0, $options[5]);
    	}
        $topic['title'] = $title;
        $topic['replies'] = $arr['topic_replies'];
        $topic['views'] = $arr['topic_views'];
        $topic['time'] = newbb_formatTimestamp($arr['post_time']);
        if (!empty($author_name[$arr['uid']])) {
        	$topic_poster = $author_name[$arr['uid']];
        } else {
            $topic_poster = $myts->htmlSpecialChars( ($arr['poster_name'])?$arr['poster_name']:$GLOBALS["xoopsConfig"]["anonymous"] );
        }
        $topic['topic_poster'] = $topic_poster;
        $topic['topic_page_jump'] = $topic_page_jump;
        $block['topics'][] = $topic;
        unset($topic);
    }
    $block['indexNav'] = intval($options[4]);

    return $block;
}

// options[0] - Citeria valid: time(by default), views, replies, digest, sticky
// options[1] - NumberToDisplay: any positive integer
// options[2] - TimeDuration: negative for hours, positive for days, for instance, -5 for 5 hours and 5 for 5 days
// options[3] - DisplayMode: 0-full view;1-compact view;2-lite view
// options[4] - Display Navigator: 1 (by default), 0 (No)
// options[5] - Title Length : 0 - no limit
// options[6] - SelectedForumIDs: null for all

function b_newbb_topic_show($options)
{
    global $xoopsConfig;
    global $access_forums;

    $db = &Database::getInstance();
    $myts = &MyTextSanitizer::getInstance();
    $block = array();
    $i = 0;
    $order = "";
    $extra_criteria = "";
    $time_criteria = null;
	if(!empty($options[2])) {
		$time_criteria = time() - newbb_getSinceTime($options[2]);
		$extra_criteria = " AND t.topic_time>".$time_criteria;
	}
    switch ($options[0]) {
        case 'views':
            $order = 't.topic_views';
            break;
        case 'replies':
            $order = 't.topic_replies';
            break;
        case 'digest':
            $order = 't.digest_time';
    		$extra_criteria = " AND t.topic_digest=1";
    		if($time_criteria)
    		$extra_criteria .= " AND t.digest_time>".$time_criteria;
            break;
        case 'sticky':
            $order = 't.topic_time';
    		$extra_criteria .= " AND t.topic_sticky=1";
            break;
        case 'time':
        default:
            $order = 't.topic_time';
            break;
    }
	$newbbConfig = getConfigForBlock();

    if(!isset($access_forums)){
	    $forum_handler =& xoops_getmodulehandler('forum', 'newbb');
    	if(!$access_obj =& $forum_handler->getForums(0, 'access', array('forum_id', 'cat_id', 'forum_type')) ){
	    	return null;
    	}
    	$access_forums = array_keys( $access_obj ); // get all accessible forums
    	unset($access_obj );
	}

    if (!empty($options[6])) {
        $allowedforums = array_filter(array_slice($options, 6), "b_newbb_array_filter"); // get allowed forums
        $allowed_forums = array_intersect($allowedforums, $access_forums);
    }else{
        $allowed_forums = $access_forums;
    }

    $forum_criteria = ' AND t.forum_id IN (' . implode(',', $allowed_forums) . ')';
    $approve_criteria = ' AND t.approved = 1';

    $query = 'SELECT'.
    		'	t.topic_id, t.topic_replies, t.forum_id, t.topic_title, t.topic_views, t.topic_subject, t.topic_time, t.topic_poster, t.poster_name,'.
    		'	f.forum_name, f.allow_subject_prefix'.
    		'	FROM ' . $db->prefix('bb_topics') . ' AS t '.
    		'	LEFT JOIN ' . $db->prefix('bb_forums') . ' AS f ON f.forum_id=t.forum_id'.
    		'	WHERE 1=1 ' .
    			$forum_criteria .
    			$approve_criteria .
    			$extra_criteria .
    			' ORDER BY ' . $order . ' DESC';

    $result = $db->query($query, $options[1], 0);
    if (!$result) {
	    newbb_message("newbb block query error: ".$query);
        return false;
    }
    $block['disp_mode'] = $options[3]; // 0 - full view; 1 - compact view; 2 - lite view;
    $rows = array();
    $author = array();
    while ($row = $db->fetchArray($result)) {
        $rows[] = $row;
        $author[$row["topic_poster"]] = 1;
    }
    if (count($rows) < 1) return false;
	$author_name = newbb_getUnameFromIds(array_keys($author), $newbbConfig['show_realname'], true);

    foreach ($rows as $arr) {
        $topic_page_jump = '';
        if ($arr['allow_subject_prefix']) {
            $subjectpres = explode(',', $newbbConfig['subject_prefix']);
            if (count($subjectpres) > 1) {
                foreach($subjectpres as $subjectpre) {
                    $subject_array[] = $subjectpre;
                }
               	$subject_array[0] = null;
            }

⌨️ 快捷键说明

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