📄 functions.php
字号:
$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]);
}
function newbb_checkSubjectPrefixPermission($forum = 0, $user=-1)
{
global $xoopsUser, $xoopsModuleConfig;
if($xoopsModuleConfig['subject_prefix_level']<1){
return false;
}
if($xoopsModuleConfig['subject_prefix_level']==1){
return true;
}
if(is_numeric($user) && $user == -1) $user =& $xoopsUser;
if(!is_object($user) && intval($user)<1) return false;
$uid = (is_object($user))?$user->getVar('uid'):intval($user);
if($xoopsModuleConfig['subject_prefix_level']==2){
return true;
}
if($xoopsModuleConfig['subject_prefix_level']==3){
if(newbb_isAdmin($forum, $user)) return true;
else return false;
}
if($xoopsModuleConfig['subject_prefix_level']==4){
if(newbb_isAdministrator($user)) return true;
}
return false;
}
/*
* Gets the total number of topics in a form
*/
function get_total_topics($forum_id="")
{
$topic_handler =& xoops_getmodulehandler('topic', 'newbb');
$criteria =& new CriteriaCompo(new Criteria("approved", 0, ">"));
if ( $forum_id ) {
$criteria->add(new Criteria("forum_id", intval($forum_id)));
}
return $topic_handler->getCount($criteria);
}
/*
* 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 = 0, $type = "all")
{
$post_handler =& xoops_getmodulehandler('post', 'newbb');
$criteria =& new CriteriaCompo(new Criteria("approved", 0, ">"));
switch ( $type ) {
case 'forum':
if($id>0) $criteria->add(new Criteria("forum_id", intval($id)));
break;
case 'topic':
if($id>0) $criteria->add(new Criteria("topic_id", intval($id)));
break;
case 'all':
default:
break;
}
return $post_handler->getCount($criteria);
}
function get_total_views()
{
global $xoopsDB;
$sql = "SELECT sum(topic_views) FROM ".$xoopsDB->prefix("bb_topics")."";
if ( !$result = $xoopsDB->query($sql) ) {
return null;
}
list ($total) = $xoopsDB->fetchRow($result);
return $total;
}
function newbb_forumSelectBox($value = null, $permission = "access", $delimitor_category = true)
{
$category_handler =& xoops_getmodulehandler('category', 'newbb');
$forum_handler =& xoops_getmodulehandler('forum', 'newbb');
$categories = $category_handler->getAllCats($permission, true);
$forums = $forum_handler->getForumsByCategory(array_keys($categories), $permission, false);
if(!defined("_MD_SELFORUM")) {
if ( !( $ret = @include_once( XOOPS_ROOT_PATH."/modules/newbb/language/".$GLOBALS['xoopsConfig']['language']."/main.php" ) ) ) {
include_once( XOOPS_ROOT_PATH."/modules/newbb/language/english/main.php" );
}
}
$value = is_array($value)?$value:array($value);
$box ='<option value="-1">-- '._MD_SELFORUM.' --</option>';
if(count($categories)>0 && count($forums)>0){
foreach(array_keys($forums) as $key){
if($delimitor_category) {
$box .= "<option value='-1'> </option>";
}
$box .= "<option value='-1'>[".$categories[$key]->getVar('cat_title')."]</option>";
foreach ($forums[$key] as $f=>$forum) {
$box .= "<option value='".$f."' ".( (in_array($f, $value))?" selected":"" ).">-- ".$forum['title']."</option>";
if( !isset($forum["sub"]) || count($forum["sub"]) ==0 ) continue;
foreach (array_keys($forum["sub"]) as $s) {
$box .= "<option value='".$s."' ".( (in_array($s, $value))?" selected":"" ).">---- ".$forum["sub"][$s]['title']."</option>";
}
}
}
} else {
$box .= "<option value='-1'>"._MD_NOFORUMINDB."</option>";
}
unset($forums, $categories);
return $box;
}
function newbb_make_jumpbox($forum_id = 0)
{
$box = '<form name="forum_jumpbox" method="get" action="viewforum.php" onsubmit="javascript: if(document.forum_jumpbox.forum.value < 1){return false;}">';
$box .= '<select class="select" name="forum" onchange="javascript: if(this.options[this.selectedIndex].value >0 ){ document.forms.forum_jumpbox.submit();}">';
$box .= newbb_forumSelectBox($forum_id);
$box .= "</select> <input type='submit' class='button' value='"._GO."' /></form>";
unset($forums, $categories);
return $box;
}
function newbb_isIE5()
{
static $user_agent_is_IE5;
if(isset($user_agent_is_IE5)) return $user_agent_is_IE5;;
$msie='/msie\s(5\.[5-9]|[6-9]\.[0-9]*).*(win)/i';
if( !isset($_SERVER['HTTP_USER_AGENT']) ||
!preg_match($msie,$_SERVER['HTTP_USER_AGENT']) ||
preg_match('/opera/i',$_SERVER['HTTP_USER_AGENT'])){
$user_agent_is_IE5 = false;
}else{
$user_agent_is_IE5 = true;
}
return $user_agent_is_IE5;
}
function newbb_displayImage($image, $alt = "", $width = 0, $height =0, $style ="margin: 0px;", $sizeMeth='scale')
{
global $xoopsModuleConfig, $forumImage;
static $image_type;
$user_agent_is_IE5 = newbb_isIE5();
if(!isset($image_type)) $image_type = ($xoopsModuleConfig['image_type'] == 'auto')?(($user_agent_is_IE5)?'gif':'png'):$xoopsModuleConfig['image_type'];
$image .= '.'.$image_type;
$imageuri=preg_replace("/^".preg_quote(XOOPS_URL,"/")."/",XOOPS_ROOT_PATH,$image);
if(!preg_match("/^".preg_quote(XOOPS_ROOT_PATH,"/")."/",$imageuri)){
$imageuri = XOOPS_ROOT_PATH."/".$image;
}
if(file_exists($imageuri)){
$size=@getimagesize($imageuri);
if(is_array($size)){
$width=$size[0];
$height=$size[1];
}
}else{
$image=$forumImage['blank'].'.gif';
}
$width .='px';
$height .='px';
$img_style = "width: $width; height:$height; $style";
$image_url = "<img src=\"".$image."\" style=\"".$img_style."\" alt=\"".$alt."\" align=\"middle\" />";
return $image_url;
}
/**
* newbb_updaterating()
*
* @param $sel_id
* @return updates rating data in itemtable for a given item
**/
function newbb_updaterating($sel_id)
{
global $xoopsDB;
$query = "select rating FROM " . $xoopsDB -> prefix('bb_votedata') . " WHERE topic_id = " . $sel_id . "";
$voteresult = $xoopsDB -> query($query);
$votesDB = $xoopsDB -> getRowsNum($voteresult);
$totalrating = 0;
while (list($rating) = $xoopsDB -> fetchRow($voteresult))
{
$totalrating += $rating;
}
$finalrating = $totalrating / $votesDB;
$finalrating = number_format($finalrating, 4);
$sql = sprintf("UPDATE %s SET rating = %u, votes = %u WHERE topic_id = %u", $xoopsDB -> prefix('bb_topics'), $finalrating, $votesDB, $sel_id);
$xoopsDB -> queryF($sql);
}
function newbb_sinceSelectBox($selected = 100)
{
global $xoopsModuleConfig;
$select_array = explode(',',$xoopsModuleConfig['since_options']);
$select_array = array_map('trim',$select_array);
$forum_selection_since = '<select name="since">';
foreach ($select_array as $since) {
$forum_selection_since .= '<option value="'.$since.'"'.(($selected == $since) ? ' selected="selected"' : '').'>';
if($since>0){
$forum_selection_since .= sprintf(_MD_FROMLASTDAYS, $since);
}else{
$forum_selection_since .= sprintf(_MD_FROMLASTHOURS, abs($since));
}
$forum_selection_since .= '</option>';
}
$forum_selection_since .= '<option value="365"'.(($selected == 365) ? ' selected="selected"' : '').'>'._MD_THELASTYEAR.'</option>';
$forum_selection_since .= '<option value="0"'.(($selected == 0) ? ' selected="selected"' : '').'>'._MD_BEGINNING.'</option>';
$forum_selection_since .= '</select>';
return $forum_selection_since;
}
function newbb_getSinceTime($since = 100)
{
if($since==1000) return 0;
if($since>0) return intval($since) * 24 * 3600;
else return intval(abs($since)) * 3600;
}
function newbb_welcome( $user = -1 )
{
global $xoopsModuleConfig, $xoopsUser;
if(empty($xoopsModuleConfig["welcome_forum"])) return null;
if(is_numeric($user) && $user == -1) $user =& $xoopsUser;
if(!is_object($user) || $user->getVar('posts')){
return false;
}
$forum_handler =& xoops_getmodulehandler('forum', 'newbb');
$forum =& $forum_handler->get($xoopsModuleConfig["welcome_forum"]);
if (!$forum_handler->getPermission($forum)){
unset($forum);
return false;
}
unset($forum);
include_once dirname(__FILE__)."/functions.welcome.php";
return newbb_welcome_create($user, $xoopsModuleConfig["welcome_forum"]);
}
function newbb_synchronization($type = "")
{
switch($type){
case "rate":
case "report":
case "post":
case "topic":
case "forum":
case "category":
case "moderate":
case "read":
$type = array($type);
$clean = $type;
break;
default:
$type = null;
$clean = array("category", "forum", "topic", "post", "report", "rate", "moderate", "readtopic", "readforum");
break;
}
foreach($clean as $item){
$handler =& xoops_getmodulehandler($item, "newbb");
$handler->cleanOrphan();
unset($handler);
}
$newbbConfig = newbb_load_config();
if(empty($type) || in_array("post", $type)):
$post_handler =& xoops_getmodulehandler("post", "newbb");
$expires = isset($newbbConfig["pending_expire"])?intval($newbbConfig["pending_expire"]):7;
$post_handler->cleanExpires($expires*24*3600);
endif;
if(empty($type) || in_array("topic", $type)):
$topic_handler =& xoops_getmodulehandler("topic", "newbb");
$expires = isset($newbbConfig["pending_expire"])?intval($newbbConfig["pending_expire"]):7;
$topic_handler->cleanExpires($expires*24*3600);
$topic_handler->synchronization();
endif;
if(empty($type) || in_array("forum", $type)):
$forum_handler =& xoops_getmodulehandler("forum", "newbb");
$forum_handler->synchronization();
endif;
if(empty($type) || in_array("moderate", $type)):
$moderate_handler =& xoops_getmodulehandler("moderate", "newbb");
$moderate_handler->clearGarbage();
endif;
if(empty($type) || in_array("read", $type)):
$read_handler =& xoops_getmodulehandler("readforum", "newbb");
$read_handler->clearGarbage();
$read_handler->synchronization();
$read_handler =& xoops_getmodulehandler("readtopic", "newbb");
$read_handler->clearGarbage();
$read_handler->synchronization();
endif;
return true;
}
function newbb_setRead($type, $item_id, $post_id, $uid = null)
{
$read_handler =& xoops_getmodulehandler("read".$type, "newbb");
return $read_handler->setRead($item_id, $post_id, $uid);
}
function newbb_getRead($type, $item_id, $uid = null)
{
$read_handler =& xoops_getmodulehandler("read".$type, "newbb");
return $read_handler->getRead($item_id, $uid);
}
function newbb_setRead_forum($status = 0, $uid = null)
{
$read_handler =& xoops_getmodulehandler("readforum", "newbb");
return $read_handler->setRead_items($status, $uid);
}
function newbb_setRead_topic($status = 0, $forum_id = 0, $uid = null)
{
$read_handler =& xoops_getmodulehandler("readtopic", "newbb");
return $read_handler->setRead_items($status, $forum_id, $uid);
}
function newbb_isRead($type, &$items, $uid = null)
{
$read_handler =& xoops_getmodulehandler("read".$type, "newbb");
return $read_handler->isRead_items($items, $uid);
}
endif;
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -