📄 functions.php
字号:
<?php
// $Id: functions.php,v 1.3 2005/10/19 17:20:33 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("NEWBB_FUNCTIONS")):
define("NEWBB_FUNCTIONS", true);
include_once dirname(__FILE__)."/functions.ini.php";
function &newbb_getUnameFromIds( $userid, $usereal = 0, $linked = false )
{
$users = mod_getUnameFromIds( $userid, $usereal, $linked);
return $users;
}
function newbb_getUnameFromId( $userid, $usereal = 0, $linked = false)
{
return mod_getUnameFromId( $userid, $usereal, $linked);
}
function newbb_is_dir($dir){
$openBasedir = ini_get('open_basedir');
if (empty($openBasedir)) {
return @is_dir($dir);
}
return in_array($dir, explode(':', $openBasedir));
}
/*
* Sorry, we have to use the stupid solution unless there is an option in MyTextSanitizer:: htmlspecialchars();
*/
function newbb_htmlSpecialChars($text)
{
return preg_replace(array("/&/i", "/ /i"), array('&', '&nbsp;'), htmlspecialchars($text));
}
function &newbb_displayTarea(&$text, $html = 0, $smiley = 1, $xcode = 1, $image = 1, $br = 1)
{
global $myts;
if ($html != 1) {
// html not allowed
$text = newbb_htmlSpecialChars($text);
}
$text = $myts->codePreConv($text, $xcode); // Ryuji_edit(2003-11-18)
$text = $myts->makeClickable($text);
if ($smiley != 0) {
// process smiley
$text = $myts->smiley($text);
}
if ($xcode != 0) {
// decode xcode
if ($image != 0) {
// image allowed
$text = $myts->xoopsCodeDecode($text);
} else {
// image not allowed
$text = $myts->xoopsCodeDecode($text, 0);
}
}
if ($br != 0) {
$text = $myts->nl2Br($text);
}
$text = $myts->codeConv($text, $xcode, $image); // Ryuji_edit(2003-11-18)
return $text;
}
/*
* Filter out possible malicious text
* kses project at SF could be a good solution to check
*
* package: Article
*
* @param string $text text to filter
* @param bool $force flag indicating to force filtering
* @return string filtered text
*/
function &newbb_textFilter($text, $force = false)
{
global $xoopsUser, $xoopsConfig;
if(empty($force) && is_object($xoopsUser) && $xoopsUser->isAdmin()){
return $text;
}
// For future applications
$tags=empty($xoopsConfig["filter_tags"])?array():explode(",", $xoopsConfig["filter_tags"]);
$tags = array_map("trim", $tags);
// Set embedded tags
$tags[] = "SCRIPT";
$tags[] = "VBSCRIPT";
$tags[] = "JAVASCRIPT";
foreach($tags as $tag){
$search[] = "/<".$tag."[^>]*?>.*?<\/".$tag.">/si";
$replace[] = " [!".strtoupper($tag)." FILTERED!] ";
}
// Set iframe tag
$search[]= "/<IFRAME[^>\/]*SRC=(['\"])?([^>\/]*)(\\1)[^>\/]*?\/>/si";
$replace[]=" [!IFRAME FILTERED!] \\2 ";
$search[]= "/<IFRAME[^>]*?>([^<]*)<\/IFRAME>/si";
$replace[]=" [!IFRAME FILTERED!] \\1 ";
// action
$text = preg_replace($search, $replace, $text);
return $text;
}
function newbb_html2text($document)
{
$text = strip_tags($document);
return $text;
}
/*
* Currently the newbb session/cookie handlers are limited to:
* -- one dimension
* -- "," and "|" are preserved
*
*/
function newbb_setsession($name, $string = '')
{
if(is_array($string)) {
$value = array();
foreach ($string as $key => $val){
$value[]=$key."|".$val;
}
$string = implode(",", $value);
}
$_SESSION['newbb_'.$name] = $string;
}
function newbb_getsession($name, $isArray = false)
{
$value = !empty($_SESSION['newbb_'.$name]) ? $_SESSION['newbb_'.$name] : false;
if($isArray) {
$_value = ($value)?explode(",", $value):array();
$value = array();
if(count($_value)>0) foreach($_value as $string){
$key = substr($string, 0, strpos($string,"|"));
$val = substr($string, (strpos($string,"|")+1));
$value[$key] = $val;
}
unset($_value);
}
return $value;
}
function newbb_setcookie($name, $string = '', $expire = 0)
{
global $forumCookie;
if(is_array($string)) {
$value = array();
foreach ($string as $key => $val){
$value[]=$key."|".$val;
}
$string = implode(",", $value);
}
setcookie($forumCookie['prefix'].$name, $string, intval($expire), $forumCookie['path'], $forumCookie['domain'], $forumCookie['secure']);
}
function newbb_getcookie($name, $isArray = false)
{
global $forumCookie;
$value = !empty($_COOKIE[$forumCookie['prefix'].$name]) ? $_COOKIE[$forumCookie['prefix'].$name] : null;
if($isArray) {
$_value = ($value)?explode(",", $value):array();
$value = array();
if(count($_value)>0) foreach($_value as $string){
$sep = strpos($string,"|");
if($sep===false){
$value[]=$string;
}else{
$key = substr($string, 0, $sep);
$val = substr($string, ($sep+1));
$value[$key] = $val;
}
}
unset($_value);
}
return $value;
}
function newbb_checkTimelimit($action_last, $action_tag, $inMinute = true)
{
global $xoopsModuleConfig;
if(!isset($xoopsModuleConfig[$action_tag]) or $xoopsModuleConfig[$action_tag]==0) return true;
$timelimit = ($inMinute)?$xoopsModuleConfig[$action_tag]*60:$xoopsModuleConfig[$action_tag];
return ($action_last > time()-$timelimit)?true:false;
}
function &getModuleAdministrators($mid=0)
{
static $module_administrators=array();
if(isset($module_administrators[$mid])) return $module_administrators[$mid];
$moduleperm_handler =& xoops_gethandler('groupperm');
$groupsIds = $moduleperm_handler->getGroupIds('module_admin', $mid);
$administrators = array();
$member_handler =& xoops_gethandler('member');
foreach($groupsIds as $groupid){
$userIds = $member_handler->getUsersByGroup($groupid);
foreach($userIds as $userid){
$administrators[$userid] = 1;
}
}
$module_administrators[$mid] =array_keys($administrators);
unset($administrators);
return $module_administrators[$mid];
}
/* use hardcoded DB query to save queries */
function newbb_isModuleAdministrator($uid = 0, $mid = 0)
{
global $xoopsDB;
static $module_administrators=array();
if(isset($module_administrators[$mid][$uid])) return $module_administrators[$mid][$uid];
$sql = "SELECT COUNT(l.groupid) FROM ".$xoopsDB->prefix('groups_users_link')." AS l".
" LEFT JOIN ".$xoopsDB->prefix('group_permission')." AS p ON p.gperm_groupid=l.groupid".
" WHERE l.uid=".intval($uid).
" AND p.gperm_modid = '1' AND p.gperm_name = 'module_admin' AND p.gperm_itemid = '".intval($mid)."'";
if(!$result = $xoopsDB->query($sql)){
$module_administrators[$mid][$uid] = null;
}else{
list($count) = $xoopsDB->fetchRow($result);
$module_administrators[$mid][$uid] = intval($count);
}
return $module_administrators[$mid][$uid];
}
/* use hardcoded DB query to save queries */
function newbb_isModuleAdministrators($uid = array(), $mid = 0)
{
global $xoopsDB;
$module_administrators=array();
if(empty($uid)) return $module_administrators;
$sql = "SELECT COUNT(l.groupid) AS count, l.uid FROM ".$xoopsDB->prefix('groups_users_link')." AS l".
" LEFT JOIN ".$xoopsDB->prefix('group_permission')." AS p ON p.gperm_groupid=l.groupid".
" WHERE l.uid IN (".implode(", ", array_map("intval", $uid)).")".
" AND p.gperm_modid = '1' AND p.gperm_name = 'module_admin' AND p.gperm_itemid = '".intval($mid)."'".
" GROUP BY l.uid";
if($result = $xoopsDB->query($sql)){
while($myrow = $xoopsDB->fetchArray($result)){
$module_administrators[$myrow["uid"]] = intval($myrow["count"]);
}
}
return $module_administrators;
}
function newbb_isAdministrator($user=-1, $mid=0)
{
global $xoopsUser, $xoopsModule;
static $administrators, $newBB_mid;
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(!$mid){
if (!isset($newBB_mid)) {
if(is_object($xoopsModule)&& 'newbb' == $xoopsModule->dirname()){
$newBB_mid = $xoopsModule->getVar('mid');
}else{
$modhandler =& xoops_gethandler('module');
$newBB =& $modhandler->getByDirname('newbb');
$newBB_mid = $newBB->getVar('mid');
unset($newBB);
}
}
$mid = $newBB_mid;
}
return newbb_isModuleAdministrator($uid, $mid);
}
function newbb_isAdmin($forum = 0, $user=-1)
{
global $xoopsUser;
static $_cachedModerators;
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(newbb_isAdministrator($uid)) return true;
$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_isModerator($forum = 0, $user=-1)
{
global $xoopsUser;
static $_cachedModerators;
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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -