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

📄 functions.php

📁 在综合英文版XOOPS 2.09, 2.091, 2.092 的基础上正式发布XOOPS 2.09中文版 XOOPS 2.09x 版主要是PHP5升级、bug修正和安全补正: 1 全面兼容PHP 5.
💻 PHP
📖 第 1 页 / 共 3 页
字号:
<?php// $Id: functions.php,v 1.1.1.106 2004/12/02 13:40: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: Kazumi Ono (AKA onokazu)                                          //// URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //// Project: The XOOPS Project                                                //// ------------------------------------------------------------------------- //function newbb_attachmentImage($source, $asSource = false){	global $xoopsModuleConfig;	$img_path = XOOPS_ROOT_PATH.'/'.$xoopsModuleConfig['dir_attachments'];	$img_url = XOOPS_URL.'/'.$xoopsModuleConfig['dir_attachments'];	$thumb_path = $img_path.'/thumbs';	$thumb_url = $img_url.'/thumbs';	if(!file_exists($thumb_path.'/'.$source)&&$xoopsModuleConfig['max_img_width']>0)		newbb_createThumbnail($source, $xoopsModuleConfig['max_img_width']);	$thumb = $thumb_path.'/'.$source;	$image = $img_path.'/'.$source;	$thumb_url = $thumb_url.'/'.$source;	$image_url = $img_url.'/'.$source;	if(file_exists($thumb)){		if($asSource) $thumb_url = $thumb;		$attachmentImage  = '<a href="'.$image_url.'" target="newbb_image">';		$attachmentImage .= '<img src="'.$thumb_url.'" alt="'.$source.'" />';		$attachmentImage .= '</a>';	}elseif(file_exists($image)){		if($asSource) $image_url = $image;		$attachmentImage = '<img src="'.$image_url.'" alt="'.$source.'" />';	}else $attachmentImage = '';	return $attachmentImage;}function newbb_createThumbnail($source, $thumb_width){	global $xoopsModuleConfig;	$img_path = XOOPS_ROOT_PATH.'/'.$xoopsModuleConfig['dir_attachments'];	$thumb_path = $img_path.'/thumbs';	$src_file = $img_path.'/'.$source;	$new_file = $thumb_path.'/'.$source;	$imageLibs = newbb_getImageLibs();	if (!filesize($src_file) || !is_readable($src_file)) {		return false;	}	if (!is_dir($thumb_path) || !is_writable($thumb_path)) {		return false;	}	$imginfo = @getimagesize($src_file);	if ( NULL == $imginfo ) {		return false;	}	if($imginfo[0] < $thumb_width) {		return false;	}	$newWidth = (int)(min($imginfo[0],$thumb_width));	$newHeight = (int)($imginfo[1] * $newWidth / $imginfo[0]);	if ($xoopsModuleConfig['image_lib'] == 1 or $xoopsModuleConfig['image_lib'] == 0 )	{		if (preg_match("#[A-Z]:|\\\\#Ai",__FILE__)){			$cur_dir = dirname(__FILE__);			$src_file_im = '"'.$cur_dir.'\\'.strtr($src_file, '/', '\\').'"';			$new_file_im = '"'.$cur_dir.'\\'.strtr($new_file, '/', '\\').'"';		} else {			$src_file_im =   @escapeshellarg($src_file);			$new_file_im =   @escapeshellarg($new_file);		}		$path = empty($xoopsModuleConfig['path_magick'])?"":$xoopsModuleConfig['path_magick']."/";		$magick_command = $path . 'convert -quality 85 -antialias -sample ' . $newWidth . 'x' . $newHeight . ' ' . $src_file_im . ' +profile "*" ' . str_replace('\\', '/', $new_file_im) . '';		@passthru($magick_command);		if (file_exists($new_file)){				return true;		}	}	if ($xoopsModuleConfig['image_lib'] == 2 or $xoopsModuleConfig['image_lib'] == 0 )	{		$path = empty($xoopsModuleConfig['path_netpbm'])?"":$xoopsModuleConfig['path_netpbm']."/";		if (eregi("\.png", $source)){			$cmd = $path . "pngtopnm $src_file | ".$path . "pnmscale -xysize $newWidth $newHeight | ".$path . "pnmtopng > $new_file" ;		}		else if (eregi("\.(jpg|jpeg)", $source)){			$cmd = $path . "jpegtopnm $src_file | ".$path . "pnmscale -xysize $newWidth $newHeight | ".$path . "ppmtojpeg -quality=90 > $new_file" ;		}		else if (eregi("\.gif", $source)){			$cmd = $path . "giftopnm $src_file | ".$path . "pnmscale -xysize $newWidth $newHeight | ppmquant 256 | ".$path . "ppmtogif > $new_file" ;		}		@exec($cmd, $output, $retval);		if (file_exists($new_file)){				return true;		}	}	$type = $imginfo[2];	$supported_types = array();	if (!extension_loaded('gd')) return false;	if (function_exists('imagegif')) $supported_types[] = 1;	if (function_exists('imagejpeg'))$supported_types[] = 2;	if (function_exists('imagepng')) $supported_types[] = 3;    $imageCreateFunction = (function_exists('imagecreatetruecolor'))? "imagecreatetruecolor" : "imagecreate";	if (in_array($type, $supported_types) )	{		switch ($type)		{			case 1 :				if (!function_exists('imagecreatefromgif')) return false;				$im = imagecreatefromgif($src_file);				$new_im = imagecreate($newWidth, $newHeight);				imagecopyresized($new_im, $im, 0, 0, 0, 0, $newWidth, $newHeight, $imginfo[0], $imginfo[1]);				imagegif($new_im, $new_file);				imagedestroy($new_im);				break;			case 2 :				$im = imagecreatefromjpeg($src_file);				$new_im = $imageCreateFunction($newWidth, $newHeight);				imagecopyresized($new_im, $im, 0, 0, 0, 0, $newWidth, $newHeight, $imginfo[0], $imginfo[1]);				imagejpeg($new_im, $new_file, 90);				imagedestroy($new_im);				break;			case 3 :				$im = imagecreatefrompng($src_file);				$new_im = $imageCreateFunction($newWidth, $newHeight);				imagecopyresized($new_im, $im, 0, 0, 0, 0, $newWidth, $newHeight, $imginfo[0], $imginfo[1]);				imagepng($new_im, $new_file);				imagedestroy($new_im);				break;		}	}	if (file_exists($new_file))	return true;	else return false;}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("/&amp;/i", "/&nbsp;/i"), array('&', '&amp;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;}function newbb_html2text($document){	// PHP Manual:: function preg_replace	// $document should contain an HTML document.	// This will remove HTML tags, javascript sections	// and white space. It will also convert some	// common HTML entities to their text equivalent.	$search = array ("'<script[^>]*?>.*?</script>'si",  // Strip out javascript	                 "'<[\/\!]*?[^<>]*?>'si",          // Strip out HTML tags	                 "'([\r\n])[\s]+'",                // Strip out white space	                 "'&(quot|#34);'i",                // Replace HTML entities	                 "'&(amp|#38);'i",	                 "'&(lt|#60);'i",	                 "'&(gt|#62);'i",	                 "'&(nbsp|#160);'i",	                 "'&(iexcl|#161);'i",	                 "'&(cent|#162);'i",	                 "'&(pound|#163);'i",	                 "'&(copy|#169);'i",	                 "'&#(\d+);'e");                    // evaluate as php	$replace = array ("",	                 "",	                 "\\1",	                 "\"",	                 "&",	                 "<",	                 ">",	                 " ",	                 chr(161),	                 chr(162),	                 chr(163),	                 chr(169),	                 "chr(\\1)");	$text = preg_replace($search, $replace, $document);	return $text;}function newbb_setsession($name, $value = ''){	$value = (is_array($value))?implode(",", $value):$value;	$_SESSION['newbb_'.$name] = $value;}function newbb_getsession($name, $isArray = false){	$value = !empty($_SESSION['newbb_'.$name]) ? $_SESSION['newbb_'.$name] : false;	if($isArray) $value = ($value)?explode(",", $value):array();	return $value;}function newbb_setcookie($name, $value = '', $expire = 0){	global $forumCookie;	$value = (is_array($value))?implode(",", $value):$value;	setcookie($forumCookie['prefix'].$name, $value, 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] : false;	if($isArray && !empty($value)) $value = ($value)?explode(",", $value):array();	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];}function newbb_isAdministrator($user=-1, $mid=0){	global $xoopsUser;	static $administrators, $xoopsModule, $newBB_mid;	if($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;	}	if(!isset($administrators)) {		$administrators =& getModuleAdministrators($mid);	}	return in_array($uid,$administrators);}function newbb_isAdmin($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);	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));

⌨️ 快捷键说明

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