/**
* Global Function
*
* @author Avenger
* @version 1.14 $Id 2003-05-30 10:10:08 $
*/
/**
* Popup Prompt box
*
* @access Public
* @param string $txt pop up a popup box $txt the content to be popped
* @return void
*/
function PopBox ($txt) {
echo "";
}
/**
* Illegal Operation warning
*
* @access Public
* @param string $C error message for _alert prompt
* @param string $I _goback returns to which page, and does not return if not specified
* @return void
*/
Function alert ($C _alert, $I _goback= ' main.php ') {
if (!empty ($I _goback)) {
echo "";
} else {
echo "";
}
}
/**
* Generate random string
*
* generates a random string of a specified length and returns it to the user
*
* @access Public
* @param int $len The number of bits generated by the string
* @return String
*/
function Randstr ($len =6) {
$chars = ' abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789-@#~ '; Characters to build the password from
Mt_srand (Double) Microtime () *1000000*getmypid ()); Seed the random number generater (must is done)
$password = ";
while (strlen ($password) < $len)
$password. =substr ($chars, (Mt_rand ()%strlen ($chars)), 1);
return $password;
}
/**
* Determine the selection of the drop-down menu sound
*
* You can determine whether string one and string two are equal. So that equal items are selected in the drop-down menu
*
* @access Public
* @param string $str 1 to compare
* @param string Two $str 2 to compare
* @return string equal to return "selected", otherwise an empty string is returned
*/
function Ckselect ($str 1, $str 2) {
if ($str 1== $str 2) {
Return ' selected ';
}
Return ';
}
/**
* A custom FTP function
*
* @access Private
* @return void
*/
function myftp ($ftp _server, $ftp _port, $ftp _username, $ftp _password, $ftp _path= '/') {
$ftpid = @ftp_connect ($ftp _server, $ftp _port) or Die (' Connect to FTP server error! ');
@ftp_login ($ftpid, $ftp _username, $ftp _password) or Die (' Login ftp error! ');
@ftp_chdir ($ftpid, '/'. $ftp _path) or Die (' chdir error! ');
return $ftpid;
}
/**
* Intercept Chinese part string
*
* Intercept the specified length of the string function, the function can be automatically determined in Chinese and English, there will be no garbled
*
* @access Public
* @param string $str to be processed
* @param int $strlen The length to intercept defaults to 10
* @param string $other If you want to add an ellipsis, the default is to add
* @return String
*/
function Showtitle ($str, $strlen =10, $other =true) {
$j = 0;
for ($i =0; $i < $strlen; $i + +)
if (Ord (substr ($str, $i, 1)) >0xa0) $j + +;
if ($j%2!=0) $strlen + +;
$rstr =substr ($str, 0, $strlen);
if (strlen ($STR) > $strlen && $other) {$rstr. = ' ... ';}
return $rstr;
}
/**
* Make a link
*
* @access Public
* @param the URL to link to the string URL
* @param string Linktext the linked text displayed
* @param string Target frame
* @param string Extras extension parameter
* @return String
*/
function Make_link ($url, $linktext =false, $target =false, $extras =false) {
Return sprintf ("%s",
$url,
($target? ' target= '. $target. ' ' ': '),
($extras? ". $extras:"),
($linktext? $linktext: $url)
);
}
/**
* Format User comments
*
* @access Public
* @param string
* @return void
*/
function Clean_note ($text) {
$text = Htmlspecialchars (Trim ($text));
/* Turn URLs into links */
$text = Preg_replace ("/((Mailto|http|ftp|nntp|news):. +?) (>|\s|\) |\ "|\.\s|$)/", "\1\3", $text);
/* This ' fixing ' code would go away eventually. */
$fixes = Array ('
', '
', '
');
Reset ($fixes);
while (list (, $f) = each ($fixes)) {
$text = Str_replace (Htmlspecialchars ($f), $f, $text);
$text = Str_replace (Htmlspecialchars (Strtoupper ($f)), $f, $text);
}
/*
Tags make things look awfully weird (breaks things out of the
tag). Just convert them to
's
*/
$text = str_replace (array ('
', '
'), '
', $text);
/* Remove
tags to prevent it from showing up in the note */
$text = str_replace (Array ('', ''), ', $text);
/* Preserve linebreaks */
$text = Str_replace ("\ n", "
", $text);
/* This would only be break long lines */
if (function_exists ("WordWrap")) {
$text = WordWrap ($text);
}
Preserve Spacing of user notes
$text = Str_replace ("", "" ", $text);
return $text;
}
/**
* function to get image information
*
* A function to obtain the image information comprehensively
*
* @access Public
* @param string $img picture path
* @return Array
*/
function Getimageinfo ($img) {
$img _info = getimagesize ($img);
Switch ($img _info[2]) {
Case 1:
$imgtype = "GIF";
Break
Case 2:
$imgtype = "JPG";
Break
Case 3:
$imgtype = "PNG";
Break
}
$img _size = ceil (filesize ($img)/1000). " K ";
$new _img_info = Array (
"width" = $img _info[0],
"Height" = $img _info[1],
"Type" = $imgtype,
"Size" = $img _size
);
return $new _img_info;
}
/**
* Calculate Current time
*
* Time to return the current system in microseconds
*
* @access Public
* @return Real
*/
function Getmicrotime () {
$tmp = Explode (' ', Microtime ());
Return (real) $tmp [1]. substr ($tmp [0], 1);
}
/**
* Write file operation
*
* @access Public
* @param bool
* @return void
*/
function Wfile ($file, $content, $mode = ' W ') {
$oldmask = umask (0);
$fp = fopen ($file, $mode);
if (! $fp) return false;
Fwrite ($fp, $content);
Fclose ($FP);
Umask ($oldmask);
return true;
}
/**
* Load Template file
*
* @access Public
* @return void
*/
function Tpl_load ($tplfile, $path = './templates/', $empty = ' remove ') {
Global $TPL;
$path? ": $path = './templates/';
Require_once ' html/template/phplib.php ';
$TPL = new Template_phplib ($path, $empty);
$TPL->setfile (' main ', $tplfile);
}
/**
* Template parsing output
*
* @access Public
* @return void
*/
function Tpl_output () {
Global $TPL;
$tpl->parse (' Output ', ' main ');
$tpl->p (' output ');
}
/**
* Mail Send function
*
* @access Public Private
* @param bool
* @return void
*/
function MailSender ($from, $to, $title, $content) {
$from? $from = ' sender@phpe.net ': ';
$title? $title = ' from exceed PHP ... ': ';
$sig = "
Thank you for using our service. \ n
Exceed PHP (beyond PHP) \ n
$maildate \ n
---------------------------------------------------------------------------------------
\ n
The only way to find the ultimate method is to go beyond it.
Welcome you beyond PHP (http://www.phpe.net) \ n
";
$content. = $sig;
if (@mail ($to, $title, $content, "from: $from \nreply-to: $from")) {
return true;
} else {
return false;
}
}
function Br2none ($STR) {
return Str_replace (Array ('
', '
'), "", $str);
}
/**
* UBB Analysis
*
* @param None
* @access Public
* @return void
*/
function Ubbparse ($txt, $coverhtml =0) {
if ($coverhtml = = 0) $txt = nl2br (New_htmlspecialchars ($txt)); BR and HTML conversions
Convert only BR, do not convert HTML
if ($coverhtml = = 1) {
if (!preg_match ('/<\s* (P|BR) \s*>/is ', $txt) &&!preg_match ('/ /is ', $txt)) {
$txt = Strip_tags ($txt);
$txt = NL2BR ($txt);
} else {
$txt = Str_replace (' }
}
Pre and quote
Error_reporting (E_all);
$txt = Preg_replace ("#\[quote\" (. +?) \[/quote\] #is ","
\1
", $txt);
$txt = Preg_replace ("#\[code\" (. +?) \[/code\] #ise "," ' '. Br2none ('). '
' ", $txt);
Colors Support clamped set
while (Preg_match ("#\[color= ([^\]]+) \] (. +?) \[/color\] #is ", $txt)) {
$txt = Preg_replace ("#\[color= ([^\]]+) \] (. +?) \[/color\] #is "," \2", $txt);
}
Align
$txt = Preg_replace ("#\[center\" (. +?) \[/center\] #is "," \1 ", $txt);
$txt = Preg_replace ("#\[left\" (. +?) \[/left\] #is "," \1 ", $txt);
$txt = Preg_replace ("#\[right\" (. +?) \[/right\] #is "," \1 ", $txt);
Sub & SUP
$txt = Preg_replace ("#\[sup\" (. +?) \[/sup\] #is "," \1 ", $txt);
$txt = Preg_replace ("#\[sub\" (. +?) \[/sub\] #is "," \1 ", $txt);
Email tags
[Email]avenger@php.net[/email] [Email=avenger@php.net]email Me[/email]
$txt = Preg_replace ("#\[email\" (\s+?) \[/email\] #i "," \1 ", $txt);
$txt = Preg_replace ("#\[email\s*=\s*\" \;([\.\w\-]+\@[\.\w\-]+\.[ \.\w\-]+) \s*\ "\;\s*\" (. *?) \[\/email\] #i "," \2 ", $txt);
$txt = Preg_replace ("#\[email\s*=\s* ([\.\w\-]+\@[\.\w\-]+\.[ \w\-]+) \s*\] (. *?) \[\/email\] #i "," \2 ", $txt);
URL tags
[Url]http://www.phpe.net[/url] [Url=http://www.phpe.net]exceed php! [/URL]
$txt = Preg_replace ("#\[url\" (\s+?) \[/url\] #i "," \1 ", $txt);
$txt = Preg_replace ("#\[url\s*=\s*\" \;\s* (\s+?) \s*\ "\;\s*\" (. *?) \[\/url\] #i "," \2 ", $txt);
$txt = Preg_replace ("#\[url\s*=\s* (\s+?) \s*\] (. *?) \[\/url\] #i "," \2 ", $txt);
Start off with the easy stuff
$txt = Preg_replace ("#\[b\" (. +?) \[/b\] #is "," \1", $txt);
$txt = Preg_replace ("#\[i\" (. +?) \[/i\] #is "," \1", $txt);
$txt = Preg_replace ("#\[u\" (. +?) \[/u\] #is "," \1", $txt);
$txt = Preg_replace ("#\[s\" (. +?) \[/s\] #is "," \1", $txt);
Header text
$txt = Preg_replace ("#\[h ([1-6]) \] (. +?) \[/h[1-6]\] #is "," \2 ", $txt);
Images
$txt = Preg_replace ("#\[img\" (. +?) \[/img\] #i "," this.width=500 ' align= ' center ' hspace= ' vspace= ' >
", $txt);
Attach
$txt = Preg_replace ("#\[attach\s*=\s*\" \;\s* (\s+?) \s*\ "\;\s*\" (. *?) \[\/attach\] #i "," Related accessories:\1 ", $txt);
$txt = Preg_replace ("#\[attach\s*=\s* (\s+?) \s*\] (. *?) \[\/attach\] #i "," Related accessories:\1 ", $txt);
Iframe
$txt = Preg_replace ("#\[iframe\" (. +?) \[/iframe\] #i ","
Open the link in a new window ", $txt);
(c) (R) and (tm)
$txt = Preg_replace ("#\ (c\) #i", "©", $txt);
$txt = Preg_replace ("#\ (tm\) #i", "™", $txt);
$txt = Preg_replace ("#\ (r\) #i", "®", $txt);
return $txt;
}
Reformat date
function Format_date ($date) {
if (!preg_match ('/^\d+$/', $date)) $date = Strtotime (Trim ($date));
$sec = Time ()-$date;
Sec 1 day is 86400
if ($sec < 86400) {
Return round ($SEC/3600). ' Hours ago ';
} elseif ($sec < (86400 * 7)) {
Return round ($sec/86400). ' Days ago ';
} elseif ($sec < (86400 * 7 * 4)) {
Return round ($sec/(86400*7)). ' Weeks ago ';
} else {
Return date (' y-m-d ', $date);
}
}
?>