functions.php
来自「在综合英文版XOOPS 2.09, 2.091, 2.092 的基础上正式发布X」· PHP 代码 · 共 1,088 行 · 第 1/3 页
PHP
1,088 行
$_cachedModerators[$cache_id] = &$forum_handler->getModerators($forum); } return in_array($uid,$_cachedModerators[$cache_id]);}function newbb_isModerator($forum = 0, $user=-1){ global $xoopsUser; static $_cachedModerators; if($user == -1) $user = &$xoopsUser; if(!is_object($user) && intval($user)<1) return false; $uid = (is_object($user))?$user->getVar('uid'):intval($user); $cache_id = (is_object($forum))?$forum->getVar('forum_id'):intval($forum); if(!isset($_cachedModerators[$cache_id])){ $forum_handler =& xoops_getmodulehandler('forum', 'newbb'); if(!is_object($forum)) $forum = $forum_handler->get(intval($forum)); $_cachedModerators[$cache_id] = &$forum_handler->getModerators($forum); } return in_array($uid,$_cachedModerators[$cache_id]);}/** Gets the total number of topics in a form*/function get_total_topics($forum_id=""){ global $xoopsDB; if ( $forum_id ) { $sql = "SELECT COUNT(*) AS total FROM ".$xoopsDB->prefix("bb_topics")." WHERE forum_id = $forum_id"; } else { $sql = "SELECT COUNT(*) AS total FROM ".$xoopsDB->prefix("bb_topics"); } if ( !$result = $xoopsDB->query($sql) ) { return _MD_ERROR; } if ( !$myrow = $xoopsDB->fetchArray($result) ) { return _MD_ERROR; } return $myrow['total'];}/** Returns the total number of posts in the whole system, a forum, or a topic* Also can return the number of users on the system.*/function get_total_posts($id, $type){ global $xoopsDB; switch ( $type ) { case 'users': $sql = "SELECT COUNT(*) AS total FROM ".$xoopsDB->prefix("users")." WHERE (uid > 0) AND ( level >0 )"; break; case 'all': $sql = "SELECT COUNT(*) AS total FROM ".$xoopsDB->prefix("bb_posts"); break; case 'forum': $sql = "SELECT COUNT(*) AS total FROM ".$xoopsDB->prefix("bb_posts")." WHERE forum_id = $id"; break; case 'topic': $sql = "SELECT COUNT(*) AS total FROM ".$xoopsDB->prefix("bb_posts")." WHERE topic_id = $id"; break; // Old, we should never get this. case 'user': exit("Should be using the users.user_posts column for this."); } if ( !$result = $xoopsDB->query($sql) ) { echo "<br />get_total_posts::error :$sql"; return false; } if ( !$myrow = $xoopsDB->fetchArray($result) ) { return 0; } return $myrow['total'];}function get_total_views(){ global $xoopsDB; $total=""; $sql = "SELECT sum(topic_views) FROM ".$xoopsDB->prefix("bb_topics").""; if ( !$result = $xoopsDB->query($sql) ) { return _MD_ERROR; } list ($total) = $xoopsDB->fetchRow($result); return $total;}/** Checks if a topic is locked*/function is_locked($topic){ global $xoopsDB; $ret = false; $sql = "SELECT topic_status FROM ".$xoopsDB->prefix("bb_topics")." WHERE topic_id = $topic"; if ( $r = $xoopsDB->query($sql) ) { if ( $m = $xoopsDB->fetchArray($r) ) { if ( $m['topic_status'] == 1 ) { $ret = true; } } } return $ret;}/** * Checks the groupname. * If found gives the groupname back. */function GetGroupsNames ($uid){ $g=''; $member_handler =& xoops_gethandler('member'); $User= new XoopsUser($uid); $user_groups=$User->getGroups(); $count = count($user_groups); for ($i=0;$i<$count;$i++) { $thisgroup =& $member_handler->getGroup($user_groups[$i]); $g.=$thisgroup->getVar('name')." <br />"; } return ($g);}function make_jumpbox() { $box = '<form name="forum_jumpbox" method="get" action="viewforum.php" onsubmit="if(document.forum_jumpbox.forum.value <1){return false;}">'; $box .= '<select class="select" name="forum" onchange="if(this.options[this.selectedIndex].value >0 ){ forms[\'forum_jumpbox\'].submit();}">'; $box .='<option value="-1">-- '._MD_SELFORUM.' --</option>'; $category_handler =& xoops_getmodulehandler('category', 'newbb'); $forum_handler =& xoops_getmodulehandler('forum', 'newbb'); $categories = $category_handler->getAllCats(0, 'access'); $forums = $forum_handler->getForums(0, 'access'); if(count($categories)>0 && count($forums)>0){ $box_cats=array(); $box_forums=array(); foreach($forums as $forumid=>$forum){ $box_forums[$forum->getVar('cat_id')][$forum->getVar('forum_id')]['title'] = $forum->getVar('forum_name'); } foreach($categories as $category){ if( !isset($box_forums[$category->getVar('cat_id')]) || count( $box_forums[$category->getVar('cat_id')] ) < 1 ) continue; $box .= " <option value='-1'> </option> <option value='-1'>".$category->getVar('cat_title')."</option>"; foreach ($box_forums[$category->getVar('cat_id')] as $forumid=>$forum) { $box .= "<option value='".$forumid."'>-- ".$forum['title']."</option>"; } } } else { $box .= "<option value='-1'>ERROR</option>"; } $box .= "</select> <input type='submit' class='button' value='"._GO."' /></form>"; return $box;}function &newbb_buildrss(){ global $moduleperm_handler, $xoopsDB, $xoopsModuleConfig, $xoopsModule, $xoopsUser, $xoopsConfig, $myts; $moduleperm_handler =& xoops_gethandler('groupperm'); if (!$xoopsModuleConfig['rss_enable'] or !$moduleperm_handler->checkRight('module_read', $xoopsModule->getVar('mid'), XOOPS_GROUP_ANONYMOUS) ) return false; $allow_moderator_html =$xoopsModuleConfig['allow_moderator_html']; $forum_handler =& xoops_getmodulehandler('forum', 'newbb'); $topic_handler =& xoops_getmodulehandler('topic', 'newbb'); $thisUser = $xoopsUser; $xoopsUser = null; $access_forums = $forum_handler->getForums(0,'access'); // get all accessible forums $xoopsUser = $thisUser; $available_forums = array(); foreach($access_forums as $forum){ if($topic_handler->getPermission($forum)) { $available_forums[$forum->getVar('forum_id')] = $forum; } } unset($access_forums); $forum_criteria = ' AND t.forum_id IN ('.implode(',',array_keys($available_forums)).')'; unset($available_forums); $approve_criteria = ' AND t.approved = 1 AND p.approved = 1'; $query='SELECT t.topic_id, t.forum_id, t.topic_title, p.post_id, p.post_time, p.uid, p.poster_name, p.post_karma, p.require_reply, p.dohtml, p.dosmiley, p.doxcode, pt.post_text FROM '.$xoopsDB->prefix('bb_topics').' t, '.$xoopsDB->prefix('bb_posts_text').' pt, '.$xoopsDB->prefix('bb_posts').' p WHERE t.topic_last_post_id=p.post_id '.$forum_criteria. $approve_criteria.' AND pt.post_id=p.post_id ORDER BY p.post_id DESC'; $limit = intval($xoopsModuleConfig['rss_maxitems'] * 1.5); if (!$result = $xoopsDB->query($query,$limit)) { //echo "<br />No result:<br />$query <br />limit:$limit"; return false; } $rows = array(); while ($row = $xoopsDB->fetchArray($result)) { $users[$row['uid']] = 1; $rows[] = $row; } if(count($rows)<1) { return false; } $uids = array_keys($users); if(count($uids)>0){ $member_handler =& xoops_gethandler('member'); $user_criteria = new Criteria('uid', "(".implode(',', $uids).")", 'IN'); $users = $member_handler->getUsers( new Criteria('uid', "(".implode(',', $uids).")", 'IN'), true); }else{ $users = array(); } $xmlrss_handler =& xoops_getmodulehandler('xmlrss', 'newbb'); $rss = $xmlrss_handler->create(); $rss->setVarRss('channel_title', $xoopsConfig['sitename'].' :: '._MD_FORUM); $rss->channel_link = XOOPS_URL.'/'; $rss->setVarRss('channel_desc', $xoopsConfig['slogan'].' :: '.$xoopsModule->getInfo('description')); $rss->channel_lastbuild = formatTimestamp(time(), 'rss'); $rss->channel_webmaster = $xoopsConfig['adminmail']; $rss->channel_editor = $xoopsConfig['adminmail']; $rss->setVarRss('channel_category', $xoopsModule->getVar('name')); $rss->channel_generator = $xoopsModule->getInfo('version'); $rss->channel_language = _LANGCODE; $rss->xml_encoding = empty($xoopsModuleConfig['rss_utf8'])?_CHARSET:'UTF-8'; $rss->image_url = XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname').'/'.$xoopsModule->getInfo('image'); $dimention = getimagesize(XOOPS_ROOT_PATH.'/modules/'.$xoopsModule->getVar('dirname').'/'.$xoopsModule->getInfo('image')); if (empty($dimention[0])) { $width = 88; } else { $width = ($dimention[0] > 144) ? 144 : $dimention[0]; } if (empty($dimention[1])) { $height = 31; } else { $height = ($dimention[1] > 400) ? 400 : $dimention[1]; } $rss->image_width = $width; $rss->image_height = $height; $rss->max_items = $xoopsModuleConfig['rss_maxitems']; $rss->max_item_description = $xoopsModuleConfig['rss_maxdescription']; foreach($rows as $topic){ if( $xoopsModuleConfig['enable_karma'] && $topic['post_karma'] > 0 ) continue; if( $xoopsModuleConfig['allow_require_reply'] && $topic['require_reply']) continue; if($topic['uid'] >0){ if ( isset($users[$topic['uid']]) && (is_object($users[$topic['uid']])) && ($users[$topic['uid']]->isActive()) ){ $topic['uname'] = $users[$topic['uid']]->getVar('uname'); if(newbb_isAdmin(0,$topic['uid']) && $allow_moderator_html){ $topic['topic_title'] = $myts->undoHtmlSpecialChars($topic['topic_title']); $topic['topic_title'] = newbb_html2text($topic['topic_title']); } }else{ $topic['uname'] = $xoopsConfig['anonymous']; } }else{ $topic['uname'] = $topic['poster_name']?$topic['poster_name']:$xoopsConfig['anonymous']; } $description = &$myts->displayTarea($topic['post_text'], $topic['dohtml'], $topic['dosmiley'], $topic['doxcode']); $label = _MD_BY." ".$topic['uname']; $time = formatTimestamp($topic['post_time'], "rss"); $link = XOOPS_URL . "/modules/" . $xoopsModule->dirname() . '/viewtopic.php?topic_id=' . $topic['topic_id'] . '&forum=' . $topic['forum_id']; $title = $topic['topic_title']; if(!$rss->addItem($title, $link, $description, $label, $time)) break; } $rss_feed = &$xmlrss_handler->get($rss); return $rss_feed;}function sync($id, $type){ global $xoopsDB; switch ( $type ) { case 'forum': $sql = "SELECT MAX(post_id) AS last_post FROM ".$xoopsDB->prefix("bb_posts")." WHERE forum_id = $id"; if ( !$result = $xoopsDB->query($sql) ) { exit("Could not get post ID"); } if ( $row = $xoopsDB->fetchArray($result) ) { $last_post = $row['last_post']; } $sql = "SELECT COUNT(*) AS total FROM ".$xoopsDB->prefix("bb_posts")." WHERE forum_id = $id"; if ( !$result = $xoopsDB->query($sql) ) { exit("Could not get post count"); } if ( $row = $xoopsDB->fetchArray($result) ) { $total_posts = $row['total']; } $sql = "SELECT COUNT(*) AS total FROM ".$xoopsDB->prefix("bb_topics")." WHERE forum_id = $id"; if ( !$result = $xoopsDB->query($sql) ) { exit("Could not get topic count"); } if ( $row = $xoopsDB->fetchArray($result) ) { $total_topics = $row['total']; } $sql = sprintf("UPDATE %s SET forum_last_post_id = %u, forum_posts = %u, forum_topics = %u WHERE forum_id = %u", $xoopsDB->prefix("bb_forums"), $last_post, $total_posts, $total_topics, $id); if ( !$result = $xoopsDB->queryF($sql) ) { exit("Could not update forum $id"); } break; case 'topic': $sql = "SELECT max(post_id) AS last_post FROM ".$xoopsDB->prefix("bb_posts")." WHERE topic_id = $id"; if ( !$result = $xoopsDB->query($sql) ) { exit("Could not get post ID"); } if ( $row = $xoopsDB->fetchArray($result) ) { $last_post = $row['last_post']; } if ( $last_post > 0 ) { $sql = "SELECT COUNT(*) AS total FROM ".$xoopsDB->prefix("bb_posts")." WHERE topic_id = $id"; if ( !$result = $xoopsDB->query($sql) ) { exit("Could not get post count"); } if ( $row = $xoopsDB->fetchArray($result) ) { $total_posts = $row['total']; } $total_posts -= 1; $sql = sprintf("UPDATE %s SET topic_replies = %u, topic_last_post_id = %u WHERE topic_id = %u", $xoopsDB->prefix("bb_topics"), $total_posts, $last_post, $id); if ( !$result = $xoopsDB->queryF($sql) ) { exit("Could not update topic $id"); } } break; case 'all forums': $sql = "SELECT forum_id FROM ".$xoopsDB->prefix("bb_forums"); if ( !$result = $xoopsDB->query($sql) ) { exit("Could not get forum IDs"); } while ( $row = $xoopsDB->fetchArray($result) ) { $id = $row['forum_id']; sync($id, "forum"); } break; case 'all topics': $sql = "SELECT topic_id FROM ".$xoopsDB->prefix("bb_topics"); if ( !$result = $xoopsDB->query($sql) ) { exit("Could not get topic ID's"); } while ( $row = $xoopsDB->fetchArray($result) ) { $id = $row['topic_id']; sync($id, "topic"); } break; } return true;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?