⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 forum.php

📁 在综合英文版XOOPS 2.09, 2.091, 2.092 的基础上正式发布XOOPS 2.09中文版 XOOPS 2.09x 版主要是PHP5升级、bug修正和安全补正: 1 全面兼容PHP 5.
💻 PHP
📖 第 1 页 / 共 3 页
字号:
        $topics = array();
        while ($myrow = $this->db->fetchArray($result)) {
            // ------------------------------------------------------
            /* Necessary and sufficient conditions for an unread topic:
            	1. the last_post_time must be later than the last_vist;
            	2. the last_post_time must be later than the topic_lastread;
            */
            $is_unread = false;
            $lastread = empty($topic_lastread[$myrow['topic_id']])? 0 : $topic_lastread[$myrow['topic_id']];
            if(max($GLOBALS['last_visit'], $lastread) < $myrow['last_post_time']) $is_unread = true;
            // ------------------------------------------------------

            // ------------------------------------------------------
            // topic_icon: priority: sticky -> digest -> regular

            // ------------------------------------------------------
            // type: if 'unread' topics
            if ('unread' == $type) {
	            if(!$is_unread) continue;
            }

            // ------------------------------------------------------
            // topic_icon: priority: sticky -> digest -> regular
            if ($myrow['icon'] && is_file(XOOPS_ROOT_PATH . '/images/subject/' . $myrow['icon'])) {
                $topic_icon = '<img src="' . XOOPS_URL . '/images/subject/' . $myrow['icon'] . '" alt="" />';
                $stick = 1;
            } else {
                $topic_icon = '<img src="' . XOOPS_URL . '/images/icons/no_posticon.gif" alt="" />';
                $stick = 1;
            }
            if ($myrow['topic_sticky']) {
                $topic_icon = newbb_displayImage($forumImage['folder_sticky'], _MD_TOPICSTICKY);
                $stick = 0;
                $sticky++;
            }
            if ($myrow['topic_haspoll']) {
                $topic_icon = newbb_displayImage($forumImage['poll'], _MD_TOPICHASPOLL);
            }
            if ($myrow['topic_haspoll'] && $myrow['topic_sticky']) {
                $topic_icon = newbb_displayImage($forumImage['folder_sticky'], _MD_TOPICSTICKY) . '<br />' . newbb_displayImage($forumImage['poll'], _MD_TOPICHASPOLL);
                $stick = 0;
                $sticky++;
            }
            // ------------------------------------------------------
            // topic_folder: priority: newhot -> hot/new -> regular
            if ($myrow['topic_status'] == 1) {
                $topic_folder = $forumImage['locked_topic'];
            } else {
                if ($myrow['topic_digest']) $topic_folder = $forumImage['folder_digest'];
                elseif ($myrow['topic_replies'] >= $hot_threshold) {
	                if($is_unread){
                        $topic_folder = $forumImage['hot_newposts_topic'];
                    } else {
                        $topic_folder = $forumImage['hot_folder_topic'];
                    }
                } else {
	                if($is_unread){
                        $topic_folder = $forumImage['newposts_topic'];
                    } else {
                        $topic_folder = $forumImage['folder_topic'];
                    }
                }
            }
            // ------------------------------------------------------
            // rating_img
            $rating = number_format($myrow['rating'] / 2, 0);
            if ($rating < 1) {
                $rating_img = newbb_displayImage($forumImage['blank']);
            } else {
                $rating_img = newbb_displayImage($forumImage['rate' . $rating]);
            }
            // ------------------------------------------------------
            // topic_page_jump
            if ($myrow['icon']) {
            	$last_post_icon = '<img src="' . XOOPS_URL . '/images/subject/' . $myrow['icon'] . '" alt="" />';
        	} else {
            	$last_post_icon = '<img src="' . XOOPS_URL . '/images/subject/icon1.gif" alt="" />';
        	}
            $topic_page_jump = '';
            $topic_page_jump_icon = '';
            $totalpages = ceil(($myrow['topic_replies'] + 1) / $xoopsModuleConfig['posts_per_page']);
            if ($totalpages > 1) {
                $topic_page_jump .= '&nbsp;&nbsp;&nbsp;<img src="' . XOOPS_URL . '/images/icons/posticon.gif" alt="" /> ';
                $append = false;
                for ($i = 1; $i <= $totalpages; $i++) {
                    if ($i > 3 && $i < $totalpages) {
	                    if(!$append){
                        	$topic_page_jump .= "...";
                        	$append = true;
                    	}
                    } else {
                        $topic_page_jump .= '[<a href="viewtopic.php?topic_id=' . $myrow['topic_id'] . '&amp;start=' . (($i - 1) * $xoopsModuleConfig['posts_per_page']) . '">' . $i . '</a>]';
                        $topic_page_jump_icon = "<a href='" . XOOPS_URL . "/modules/newbb/viewtopic.php?topic_id=" . $myrow['topic_id'] . "&amp;start=" . (($i - 1) * $xoopsModuleConfig['posts_per_page']) . "#forumpost" . $myrow['post_id'] . "'>" . newbb_displayImage($forumImage['docicon']) . "</a>";
                    }
                }
            }
            else {
            	$topic_page_jump_icon = "<a href='" . XOOPS_URL . "/modules/newbb/viewtopic.php?topic_id=" . $myrow['topic_id'] . "#forumpost" . $myrow['post_id'] . "'>" . newbb_displayImage($forumImage['docicon']) . "</a>";
        	}
        	// ------------------------------------------------------
            // topic_poster
            if ($myrow['topic_poster'] != 0 && $myrow['uname']) {
                if ($xoopsModuleConfig['show_realname'] && $myrow['name']) {
                    $topic_poster = '<a href="' . XOOPS_URL . '/userinfo.php?uid=' . $myrow['topic_poster'] . '">' . $myrow['name'] . '</a>';
                } else {
                    $topic_poster = '<a href="' . XOOPS_URL . '/userinfo.php?uid=' . $myrow['topic_poster'] . '">' . $myrow['uname'] . '</a>';
                }
            } else {
                $topic_poster = $myrow['poster_name']?$myts->htmlSpecialChars($myrow['poster_name']):$xoopsConfig['anonymous'];
            }
            // ------------------------------------------------------
            // topic_last_poster
            if ($xoopsModuleConfig['show_realname'] && $myrow['last_post_name']) {
                $topic_last_poster = $myts->htmlSpecialChars($myrow['last_post_name']);
            } elseif($myrow['last_poster']) {
                $topic_last_poster = $myts->htmlSpecialChars($myrow['last_poster']);
            } elseif ($myrow['last_poster_name']){
                $topic_last_poster = $myts->htmlSpecialChars($myrow['last_poster_name']);
        	}else{
                $topic_last_poster = $xoopsConfig['anonymous'];
            }
            // ------------------------------------------------------
            // => topic array
            if (is_object($viewall_forums[$myrow['forum_id']]))
                $forum_link = '<a href="' . XOOPS_URL . '/modules/newbb/viewforum.php?forum=' . $myrow['forum_id'] . '">' . $myts->htmlSpecialChars($viewall_forums[$myrow['forum_id']]->getVar('forum_name')) . '</a>';
            else $forum_link = '';

            if (newbb_isAdmin($forum,$myrow['topic_poster']) && $xoopsModuleConfig['allow_moderator_html'])
                $topic_title = $myrow['topic_title'];
            else
                $topic_title = $myts->htmlSpecialChars($myrow['topic_title']);
            if ($myrow['topic_digest']) $topic_title = "<span class='digest'>" . $topic_title . "</span>";

            $subjectpres = explode(',', $xoopsModuleConfig['subject_prefix']);
            if (count($subjectpres) > 1) {
                foreach($subjectpres as $subjectpre) {
                    $subject_array[] = $subjectpre;
                }
            }

            $topics[$myrow['topic_id']] = array('topic_icon' => $topic_icon,
                'topic_folder' => newbb_displayImage($topic_folder),
                'topic_title' => $topic_title,
                'allow_prefix' => $allow_subject_prefix,
                'topic_subject' => $subject_array[$myrow['topic_subject']],
                'topic_link' => 'viewtopic.php?topic_id=' . $myrow['topic_id'] . '&amp;forum=' . $myrow['forum_id'],
                'rating_img' => $rating_img,
                'topic_page_jump' => $topic_page_jump,
                'topic_page_jump_icon' => $topic_page_jump_icon,
                'topic_replies' => $myrow['topic_replies'],
                'topic_poster' => $topic_poster,
                'topic_views' => $myrow['topic_views'],
                'topic_last_posttime' => formatTimestamp($myrow['last_post_time']),
                'topic_last_poster' => $topic_last_poster,
                'topic_forum_link' => $forum_link,
                'stick' => $stick
                );
            }

            if (is_array($topics) && count($topics) > 0) {
                $result2 = $this->db->query("SELECT attachment,topic_id FROM " . $this->db->prefix("bb_posts") . " WHERE topic_id IN (" . implode(',', array_keys($topics)) . ")");
                if ($result2) {
                    while ($arr2 = $this->db->fetchArray($result2)) {
                        if ($arr2['attachment']) $topics[$arr2['topic_id']]['attachment'] = '&nbsp;' . newbb_displayImage($forumImage['clip'], _MD_TOPICSHASATT);
                        unset($arr2);
                    }
                }
            }
            return array($topics, $sticky);
        }

        function getTopicCount($forum, $startdate, $type)
        {
            global $viewall_forums;

            switch ($type) {
                case 'digest':
                    $post_time = ' p.post_time > ' . $startdate;
                    $extra_criteria = ' AND topic_digest = 1';
                    break;
                case 'unreplied':
                    $post_time = ' p.post_time > ' . $startdate;
                    $extra_criteria = ' AND topic_replies < 1';
                    break;
	            case 'all':
	                $post_time = ' p.post_time > ' . $startdate;
	                $extra_criteria = '';
	                break;
                default:
                    $post_time = ' (p.post_time > ' . $startdate . ' OR t.topic_sticky=1)';
                    $extra_criteria = '';
                    break;
            }
            if (is_object($forum)) $forum_criteria = ' AND t.forum_id = ' . $forum->getVar('forum_id');
            else {
                if (is_array($viewall_forums) && count($viewall_forums) > 0)
                    $forum_criteria = ' AND t.forum_id IN (' . implode(',', array_keys($viewall_forums)) . ')';
                else
                    $forum_criteria = '';
            }

            $approve_criteria = ' AND t.approved = 1'; // any others?

            $sql = 'SELECT COUNT(*) as count FROM ' . $this->db->prefix("bb_topics") . ' t LEFT JOIN ' . $this->db->prefix('bb_posts') . ' p ON p.post_id = t.topic_last_post_id WHERE ';
            $sql .= $post_time . $forum_criteria . $extra_criteria . $approve_criteria;
            if (!$result = $this->db->query($sql)) {
                redirect_header('index.php', 2, "<br />NewbbForumHandler::getTopicCount "._MD_ERROROCCURED."<br />".$sql);
                exit();
            }
            $myrow = $this->db->fetchArray($result);
            return $myrow['count'];
        }

	    // get permission
	    // parameter: $type: 'moderate', 'access', 'post', 'addpoll'
	    // $gperm_names = "'global_forum_access', 'forum_can_post', 'forum_can_addpoll'";
        function getPermission($forum, $type = "access")
        {
            global $xoopsUser, $xoopsModule;
            static $_cachedPerms;

            if (newbb_isAdministrator()) return true;
            if (is_int($forum)) $forum = $this->get($forum);
            if ($forum->getVar('forum_type')) return false;// if forum inactive, all has no access except admin


            $category_handler = &xoops_getmodulehandler('category', 'newbb');
            $categoryPerm = &$category_handler->getPermission($forum->getVar('cat_id'));
        	if (!$categoryPerm) return false;

            $type = strtolower($type);
            if ("moderate" == $type) {
                $permission = (newbb_isModerator($forum))?1:0;
            } else {
                 if(in_array($type, array('post', 'addpoll'))) {
	               	$perm_type = 'topic';
	                $perm_item = 'forum_can_' . $type;
                }
                else {
	               	$perm_type = 'forum';
	                $perm_item = 'global_forum_access';
                }
	    			if (!isset($_cachedPerms[$perm_type])) {
						$getpermission = &xoops_getmodulehandler('permission', 'newbb');
						$_cachedPerms[$perm_type] = $getpermission->getPermissions($perm_type);
	    			}
                	$permission = (isset($_cachedPerms[$perm_type][$forum->getVar('forum_id')][$perm_item])) ? 1 : 0;
            }
            return $permission;
        }
    }

?>

⌨️ 快捷键说明

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