📄 functions.php
字号:
<?php
// $Id: functions.php 1282 2008-01-29 04:26:44Z phppp $
// ------------------------------------------------------------------------ //
// 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 //
// ------------------------------------------------------------------------ //
// ################## Various functions from here ################
function xoops_header($closehead=true)
{
global $xoopsConfig, $xoopsTheme, $xoopsConfigMetaFooter;
$myts =& MyTextSanitizer::getInstance();
if (!headers_sent()) {
header('Content-Type:text/html; charset='._CHARSET);
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header('Cache-Control: no-store, no-cache, max-age=1, s-maxage=1, must-revalidate, post-check=0, pre-check=0');
header("Pragma: no-cache");
}
echo "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>";
echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'._LANGCODE.'" lang="'._LANGCODE.'">
<head>
<meta http-equiv="content-type" content="text/html; charset='._CHARSET.'" />
<meta http-equiv="content-language" content="'._LANGCODE.'" />
<meta name="robots" content="'.htmlspecialchars($xoopsConfigMetaFooter['meta_robots']).'" />
<meta name="keywords" content="'.htmlspecialchars($xoopsConfigMetaFooter['meta_keywords']).'" />
<meta name="description" content="'.htmlspecialchars($xoopsConfigMetaFooter['meta_desc']).'" />
<meta name="rating" content="'.htmlspecialchars($xoopsConfigMetaFooter['meta_rating']).'" />
<meta name="author" content="'.htmlspecialchars($xoopsConfigMetaFooter['meta_author']).'" />
<meta name="copyright" content="'.htmlspecialchars($xoopsConfigMetaFooter['meta_copyright']).'" />
<meta name="generator" content="XOOPS" />
<title>'.htmlspecialchars($xoopsConfig['sitename']).'</title>
<script type="text/javascript" src="'.XOOPS_URL.'/include/xoops.js"></script>
';
$themecss = getcss($xoopsConfig['theme_set']);
echo '<link rel="stylesheet" type="text/css" media="all" href="'.XOOPS_URL.'/xoops.css" />';
if ($themecss) {
echo '<link rel="stylesheet" type="text/css" media="all" href="'.$themecss.'" />';
//echo '<style type="text/css" media="all"><!-- @import url('.$themecss.'); --></style>';
}
if ($closehead) {
echo '</head><body>';
}
}
function xoops_footer()
{
echo '</body></html>';
ob_end_flush();
}
function xoops_error($msg, $title='')
{
echo '
<div class="errorMsg">';
if ($title != '') {
echo '<h4>'.$title.'</h4>';
}
if (is_array($msg)) {
foreach ($msg as $m) {
echo $m.'<br />';
}
} else {
echo $msg;
}
echo '</div>';
}
function xoops_result($msg, $title='')
{
echo '
<div class="resultMsg">';
if ($title != '') {
echo '<h4>'.$title.'</h4>';
}
if (is_array($msg)) {
foreach ($msg as $m) {
echo $m.'<br />';
}
} else {
echo $msg;
}
echo '</div>';
}
function xoops_confirm($hiddens, $action, $msg, $submit='', $addtoken = true)
{
$submit = ($submit != '') ? trim($submit) : _SUBMIT;
echo '
<div class="confirmMsg">
<h4>'.$msg.'</h4>
<form method="post" action="'.$action.'">
';
foreach ($hiddens as $name => $value) {
if (is_array($value)) {
foreach ($value as $caption => $newvalue) {
echo '<input type="radio" name="'.$name.'" value="'.htmlspecialchars($newvalue).'" /> '.$caption;
}
echo '<br />';
} else {
echo '<input type="hidden" name="'.$name.'" value="'.htmlspecialchars($value).'" />';
}
}
if ($addtoken != false) {
echo $GLOBALS['xoopsSecurity']->getTokenHTML();
}
echo '
<input type="submit" name="confirm_submit" value="'.$submit.'" /> <input type="button" name="confirm_back" value="'._CANCEL.'" onclick="javascript:history.go(-1);" />
</form>
</div>
';
}
/**
* Deprecated, use {@link XoopsSecurity} class instead
**/
function xoops_refcheck($docheck=1)
{
return $GLOBALS['xoopsSecurity']->checkReferer($docheck);
}
function xoops_getUserTimestamp($time, $timeoffset="")
{
global $xoopsConfig, $xoopsUser;
if ($timeoffset == '') {
if ($xoopsUser) {
$timeoffset = $xoopsUser->getVar("timezone_offset");
} else {
$timeoffset = $xoopsConfig['default_TZ'];
}
}
$usertimestamp = intval($time) + (floatval($timeoffset) - $xoopsConfig['server_TZ'])*3600;
return $usertimestamp;
}
/*
* Function to display formatted times in user timezone
*/
function formatTimestamp($time, $format="l", $timeoffset="")
{
global $xoopsConfig, $xoopsUser;
$usertimestamp = xoops_getUserTimestamp($time, $timeoffset);
switch (strtolower($format)) {
case 's':
$datestring = _SHORTDATESTRING;
break;
case 'm':
$datestring = _MEDIUMDATESTRING;
break;
case 'mysql':
$datestring = "Y-m-d H:i:s";
break;
case 'rss':
$datestring = "r";
break;
case 'l':
$datestring = _DATESTRING;
break;
default:
if ($format != '') {
$datestring = $format;
} else {
$datestring = _DATESTRING;
}
break;
}
return ucfirst(date($datestring, $usertimestamp));
}
/*
* Function to calculate server timestamp from user entered time (timestamp)
*/
function userTimeToServerTime($timestamp, $userTZ=null)
{
global $xoopsConfig;
if (!isset($userTZ)) {
$userTZ = $xoopsConfig['default_TZ'];
}
$timestamp = $timestamp - (($userTZ - $xoopsConfig['server_TZ']) * 3600);
return $timestamp;
}
function xoops_makepass() {
$makepass = '';
$syllables = array("er","in","tia","wol","fe","pre","vet","jo","nes","al","len","son","cha","ir","ler","bo","ok","tio","nar","sim","ple","bla","ten","toe","cho","co","lat","spe","ak","er","po","co","lor","pen","cil","li","ght","wh","at","the","he","ck","is","mam","bo","no","fi","ve","any","way","pol","iti","cs","ra","dio","sou","rce","sea","rch","pa","per","com","bo","sp","eak","st","fi","rst","gr","oup","boy","ea","gle","tr","ail","bi","ble","brb","pri","dee","kay","en","be","se");
srand((double)microtime()*1000000);
for ($count = 1; $count <= 4; $count++) {
if (rand()%10 == 1) {
$makepass .= sprintf("%0.0f",(rand()%50)+1);
} else {
$makepass .= sprintf("%s",$syllables[rand()%62]);
}
}
return $makepass;
}
/*
* Functions to display dhtml loading image box
*/
function OpenWaitBox()
{
echo "<div id='waitDiv' style='position:absolute;left:40%;top:50%;visibility:hidden;text-align: center;'>
<table cellpadding='6' border='2' class='bg2'>
<tr>
<td align='center'><b><big>" ._FETCHING."</big></b><br /><img src='".XOOPS_URL."/images/await.gif' alt='' /><br />" ._PLEASEWAIT."</td>
</tr>
</table>
</div>
<script type='text/javascript'>
<!--//
var DHTML = (document.getElementById || document.all || document.layers);
function ap_getObj(name) {
if (document.getElementById) {
return document.getElementById(name).style;
} else if (document.all) {
return document.all[name].style;
} else if (document.layers) {
return document.layers[name];
}
}
function ap_showWaitMessage(div,flag) {
if (!DHTML) {
return;
}
var x = ap_getObj(div);
x.visibility = (flag) ? 'visible' : 'hidden';
if (!document.getElementById) {
if (document.layers) {
x.left=280/2;
}
}
return true;
}
ap_showWaitMessage('waitDiv', 1);
//-->
</script>";
}
function CloseWaitBox()
{
echo "<script type='text/javascript'>
<!--//
ap_showWaitMessage('waitDiv', 0);
//-->
</script>
";
}
function checkEmail($email,$antispam = false)
{
if (!$email || !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i",$email)){
return false;
}
if ($antispam) {
$email = str_replace("@", " at ", $email);
$email = str_replace(".", " dot ", $email);
}
return $email;
}
function formatURL($url)
{
$url = trim($url);
if ($url != '') {
if ((!preg_match("/^http[s]*:\/\//i", $url)) && (!preg_match("/^ftp*:\/\//i", $url)) && (!preg_match("/^ed2k*:\/\//i", $url)) ) {
$url = 'http://'.$url;
}
}
return $url;
}
/*
* Function to display banners in all pages
*/
function showbanner()
{
echo xoops_getbanner();
}
/*
* Function to get banner html tags for use in templates
*/
function xoops_getbanner()
{
global $xoopsConfig;
$db =& Database::getInstance();
$bresult = $db->query("SELECT COUNT(*) FROM ".$db->prefix("banner"));
list ($numrows) = $db->fetchRow($bresult);
if ( $numrows > 1 ) {
$numrows = $numrows-1;
mt_srand((double)microtime()*1000000);
$bannum = mt_rand(0, $numrows);
} else {
$bannum = 0;
}
if ( $numrows > 0 ) {
$bresult = $db->query("SELECT * FROM ".$db->prefix("banner"), 1, $bannum);
list ($bid, $cid, $imptotal, $impmade, $clicks, $imageurl, $clickurl, $date, $htmlbanner, $htmlcode) = $db->fetchRow($bresult);
if ($xoopsConfig['my_ip'] == xoops_getenv('REMOTE_ADDR')) {
// EMPTY
} else {
$db->queryF(sprintf("UPDATE %s SET impmade = impmade+1 WHERE bid = %u", $db->prefix("banner"), $bid));
}
/* Check if this impression is the last one and print the banner */
if ( $imptotal == $impmade ) {
$newid = $db->genId($db->prefix("bannerfinish")."_bid_seq");
$sql = sprintf("INSERT INTO %s (bid, cid, impressions, clicks, datestart, dateend) VALUES (%u, %u, %u, %u, %u, %u)", $db->prefix("bannerfinish"), $newid, $cid, $impmade, $clicks, $date, time());
$db->queryF($sql);
$db->queryF(sprintf("DELETE FROM %s WHERE bid = %u", $db->prefix("banner"), $bid));
}
if ($htmlbanner){
$bannerobject = $htmlcode;
}else{
$bannerobject = '<div><a href="'.XOOPS_URL.'/banners.php?op=click&bid='.$bid.'" target="_blank">';
if (stristr($imageurl, '.swf')) {
$bannerobject = $bannerobject
.'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="468" height="60">'
.'<param name="movie" value="'.$imageurl.'"></param>'
.'<param name="quality" value="high"></param>'
.'<embed src="'.$imageurl.'" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="468" height="60">'
.'</embed>'
.'</object>';
} else {
$bannerobject = $bannerobject.'<img src="'.$imageurl.'" alt="" />';
}
$bannerobject = $bannerobject.'</a></div>';
}
return $bannerobject;
}
}
/*
* Function to redirect a user to certain pages
*/
function redirect_header($url, $time = 3, $message = '', $addredirect = true, $allowExternalLink = false)
{
global $xoopsConfig, $xoopsLogger, $xoopsUserIsAdmin;
if ( preg_match( "/[\\0-\\31]|about:|script:/i", $url) ) {
if (!preg_match('/^\b(java)?script:([\s]*)history\.go\(-[0-9]*\)([\s]*[;]*[\s]*)$/si', $url) ) {
$url = XOOPS_URL;
}
}
if ( !$allowExternalLink && $pos = strpos( $url, '://' ) ) {
$xoopsLocation = substr( XOOPS_URL, strpos( XOOPS_URL, '://' ) + 3 );
if (strcasecmp(substr($url, $pos + 3, strlen($xoopsLocation)), $xoopsLocation)) {
$url = XOOPS_URL;
}
}
if (defined('XOOPS_CPFUNC_LOADED')) {
$theme = 'default';
} else {
$theme = $xoopsConfig['theme_set'];
}
require_once XOOPS_ROOT_PATH . '/class/template.php';
require_once XOOPS_ROOT_PATH . '/class/theme.php';
$xoopsThemeFactory =& new xos_opal_ThemeFactory();
$xoopsThemeFactory->allowedThemes = $xoopsConfig['theme_set_allowed'];
$xoopsThemeFactory->defaultTheme = $theme;
$xoTheme =& $xoopsThemeFactory->createInstance(array("plugins" => array()));
$xoopsTpl =& $xoTheme->template;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -