newbb_block.php

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

PHP
794
字号
            $topic['topic_subject'] = $subject_array[$arr['topic_subject']];
        } else {
            $topic['topic_subject'] = "";
        }
        $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['topic_time']);
        if (!empty($author_name[$arr['topic_poster']])) {
        	$topic_poster = $author_name[$arr['topic_poster']];
        } 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: title(by default), text
// 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; Only valid for "time"
// options[4] - Display Navigator: 1 (by default), 0 (No)
// options[5] - Title/Text Length : 0 - no limit
// options[6] - SelectedForumIDs: null for all

function b_newbb_post_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 p.post_time>".$time_criteria;
	}
    
    switch ($options[0]) {
	    case "text":
		    if(!empty($newbbConfig['enable_karma']))
				$extra_criteria .= " AND p.post_karma = 0";
		    if(!empty($newbbConfig['allow_require_reply']))
				$extra_criteria .= " AND p.require_reply = 0";	    
        default:
            $order = 'p.post_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 p.forum_id IN (' . implode(',', $allowed_forums) . ')';
    $approve_criteria = ' AND p.approved = 1';

    $query = 'SELECT';
    $query .= '	p.post_id, p.subject, p.post_time, p.icon, p.uid, p.poster_name,';
    if($options[0]=="text"){
    	$query .= '	p.dohtml, p.dosmiley, p.doxcode, p.dobr, pt.post_text,';    
	}
    $query .= '	f.forum_id, f.forum_name, f.allow_subject_prefix'.
    		'	FROM ' . $db->prefix('bb_posts') . ' AS p '.
    		'	LEFT JOIN ' . $db->prefix('bb_forums') . ' AS f ON f.forum_id=p.forum_id';
    if($options[0]=="text"){
    	$query .= '	LEFT JOIN ' . $db->prefix('bb_posts_text') . ' AS pt ON pt.post_id=p.post_id';
	}
    $query .= '	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[0]=="text")?3:$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) {
		//if ($arr['icon'] && is_file(XOOPS_ROOT_PATH . "/images/subject/" . $arr['icon'])) {
		if (!empty($arr['icon'])) {
            $last_post_icon = '<img src="' . XOOPS_URL . '/images/subject/' . htmlspecialchars($arr['icon']) . '" alt="" />';
        } else {
            $last_post_icon = '<img src="' . XOOPS_URL . '/images/subject/icon1.gif" alt="" />';
        }
        //$topic['jump_post'] = "<a href='" . XOOPS_URL . "/modules/newbb/viewtopic.php?post_id=" . $arr['post_id'] ."#forumpost" . $arr['post_id'] . "'>" . $last_post_icon . "</a>";
        $topic['forum_id'] = $arr['forum_id'];
        $topic['forum_name'] = $myts->htmlSpecialChars($arr['forum_name']);
        //$topic['id'] = $arr['topic_id'];

        $title = $myts->htmlSpecialChars($arr['subject']);
        if($options[0]!="text" && !empty($options[5])) {
	        $title = xoops_substr($title, 0, $options[5]);
        }
        $topic['title'] = $title;
        $topic['post_id'] = $arr['post_id'];
        $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;
    	
        if($options[0]=="text"){
	        $post_text = $myts->displayTarea($arr['post_text'],$arr['dohtml'],$arr['dosmiley'],$arr['doxcode'],1,$arr['dobr']);
        	if(!empty($options[5])){
	    		$post_text = xoops_substr(newbb_html2text($post_text), 0, $options[5]);
    		}
        	$topic['post_text'] = $post_text;
        }        
        
        $block['topics'][] = $topic;
        unset($topic);
    }
    $block['indexNav'] = intval($options[4]);
    return $block;
}

// options[0] - Citeria valid: post(by default), topic, 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;
// 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_author_show($options)
{
    global $xoopsConfig;
    global $access_forums;

    $db = &Database::getInstance();
    $myts = &MyTextSanitizer::getInstance();
    $block = array();
    $i = 0;
    $type = "topic";
    $order = "count";
    $extra_criteria = "";
    $time_criteria = null;
	if(!empty($options[2])) {
		$time_criteria = time() - newbb_getSinceTime($options[2]);
		$extra_criteria = " AND topic_time>".$time_criteria;
	}
    switch ($options[0]) {
        case 'topic':
            break;
        case 'digest':
    		$extra_criteria = " AND topic_digest=1";
    		if($time_criteria)
    		$extra_criteria .= " AND digest_time>".$time_criteria;
            break;
        case 'sticky':
    		$extra_criteria .= " AND topic_sticky=1";
            break;
        case 'post':
        default:
        	$type = "post";
    		if($time_criteria)
			$extra_criteria = " AND post_time>".$time_criteria;
            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[5])) {
        $allowedforums = array_filter(array_slice($options, 5), "b_newbb_array_filter"); // get allowed forums
        $allowed_forums = array_intersect($allowedforums, $access_forums);
    }else{
        $allowed_forums = $access_forums;
    }

    if($type=="topic"){
	    $forum_criteria = ' AND forum_id IN (' . implode(',', $allowed_forums) . ')';
	    $approve_criteria = ' AND approved = 1';
	    $query = 'SELECT DISTINCT topic_poster AS author, COUNT(*) AS count
	    			FROM ' . $db->prefix('bb_topics') . '
	    			WHERE topic_poster>0 ' .
	    			$forum_criteria .
	    			$approve_criteria .
	    			$extra_criteria .
	    			' GROUP BY topic_poster ORDER BY ' . $order . ' DESC';
	}else{
	    $forum_criteria = ' AND forum_id IN (' . implode(',', $allowed_forums) . ')';
	    $approve_criteria = ' AND approved = 1';
	    $query = 'SELECT DISTINCT uid AS author, COUNT(*) AS count
	    			FROM ' . $db->prefix('bb_posts') . '
	    			WHERE uid>0 ' .
	    			$forum_criteria .
	    			$approve_criteria .
	    			$extra_criteria .
	    			' GROUP BY uid ORDER BY ' . $order . ' DESC';
	}

    $result = $db->query($query, $options[1], 0);
    if (!$result) {
	    newbb_message("newbb block query error: ".$query);
        return false;
    }
    $author = array();
    while ($row = $db->fetchArray($result)) {
	    $author[$row["author"]]["count"] = $row["count"];
    }
    if (count($author) < 1) return false;
	$author_name = newbb_getUnameFromIds(array_keys($author), $newbbConfig['show_realname']);
	foreach(array_keys($author) as $uid){
		$author[$uid]["name"] = $myts->htmlSpecialChars($author_name[$uid]);
	}
    $block['authors'] =& $author;
    $block['disp_mode'] = $options[3]; // 0 - full view; 1 - lite view;
    $block['indexNav'] = intval($options[4]);
    return $block;
}

function b_newbb_edit($options)
{

⌨️ 快捷键说明

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