functions-formatting.php

来自「php 开发的内容管理系统」· PHP 代码 · 共 1,037 行 · 第 1/3 页

PHP
1,037
字号
	'&#145;' => '&#8216;',	'&#146;' => '&#8217;',	'&#147;' => '&#8220;',	'&#148;' => '&#8221;',	'&#149;' => '&#8226;',	'&#150;' => '&#8211;',	'&#151;' => '&#8212;',	'&#152;' => '&#732;',	'&#153;' => '&#8482;',	'&#154;' => '&#353;',	'&#155;' => '&#8250;',	'&#156;' => '&#339;',	'&#157;' => '',	'&#158;' => '',	'&#159;' => '&#376;'	);	// Remove metadata tags	$content = preg_replace('/<title>(.+?)<\/title>/','',$content);	$content = preg_replace('/<category>(.+?)<\/category>/','',$content);	// Converts lone & characters into &#38; (a.k.a. &amp;)	$content = preg_replace('/&([^#])(?![a-z1-4]{1,8};)/i', '&#038;$1', $content);	// Fix Word pasting	$content = strtr($content, $wp_htmltranswinuni);	// Just a little XHTML help	$content = str_replace('<br>', '<br />', $content);	$content = str_replace('<hr>', '<hr />', $content);	return $content;}function funky_javascript_fix($text) {	// Fixes for browsers' javascript bugs	global $is_macIE, $is_winIE;		if ( $is_winIE || $is_macIE )		$text =  preg_replace("/\%u([0-9A-F]{4,4})/e",  "'&#'.base_convert('\\1',16,10).';'", $text);		return $text;}/* balanceTags  Balances Tags of string using a modified stack.  @param text      Text to be balanced @return          Returns balanced text @author          Leonard Lin (leonard@acm.org) @version         v1.1 @date            November 4, 2001 @license         GPL v2.0 @notes            @changelog        ---  Modified by Scott Reilly (coffee2code) 02 Aug 2004             1.2  ***TODO*** Make better - change loop condition to $text             1.1  Fixed handling of append/stack pop order of end text                  Added Cleaning Hooks             1.0  First Version*/function balanceTags($text, $is_comment = 0) {		if ( get_option('use_balanceTags') == 0)		return $text;	$tagstack = array(); $stacksize = 0; $tagqueue = ''; $newtext = '';	# WP bug fix for comments - in case you REALLY meant to type '< !--'	$text = str_replace('< !--', '<    !--', $text);	# WP bug fix for LOVE <3 (and other situations with '<' before a number)	$text = preg_replace('#<([0-9]{1})#', '&lt;$1', $text);	while (preg_match("/<(\/?\w*)\s*([^>]*)>/",$text,$regex)) {		$newtext .= $tagqueue;		$i = strpos($text,$regex[0]);		$l = strlen($regex[0]);		// clear the shifter		$tagqueue = '';		// Pop or Push		if ($regex[1][0] == "/") { // End Tag			$tag = strtolower(substr($regex[1],1));			// if too many closing tags			if($stacksize <= 0) { 				$tag = '';				//or close to be safe $tag = '/' . $tag;			}			// if stacktop value = tag close value then pop			else if ($tagstack[$stacksize - 1] == $tag) { // found closing tag				$tag = '</' . $tag . '>'; // Close Tag				// Pop				array_pop ($tagstack);				$stacksize--;			} else { // closing tag not at top, search for it				for ($j=$stacksize-1;$j>=0;$j--) {					if ($tagstack[$j] == $tag) {					// add tag to tagqueue						for ($k=$stacksize-1;$k>=$j;$k--){							$tagqueue .= '</' . array_pop ($tagstack) . '>';							$stacksize--;						}						break;					}				}				$tag = '';			}		} else { // Begin Tag			$tag = strtolower($regex[1]);			// Tag Cleaning			// If self-closing or '', don't do anything.			if((substr($regex[2],-1) == '/') || ($tag == '')) {			}			// ElseIf it's a known single-entity tag but it doesn't close itself, do so			elseif ($tag == 'br' || $tag == 'img' || $tag == 'hr' || $tag == 'input') {				$regex[2] .= '/';			} else {	// Push the tag onto the stack				// If the top of the stack is the same as the tag we want to push, close previous tag				if (($stacksize > 0) && ($tag != 'div') && ($tagstack[$stacksize - 1] == $tag)) {					$tagqueue = '</' . array_pop ($tagstack) . '>';					$stacksize--;				}				$stacksize = array_push ($tagstack, $tag);			}			// Attributes			$attributes = $regex[2];			if($attributes) {				$attributes = ' '.$attributes;			}			$tag = '<'.$tag.$attributes.'>';			//If already queuing a close tag, then put this tag on, too			if ($tagqueue) {				$tagqueue .= $tag;				$tag = '';			}		}		$newtext .= substr($text,0,$i) . $tag;		$text = substr($text,$i+$l);	}  	// Clear Tag Queue	$newtext .= $tagqueue;	// Add Remaining text	$newtext .= $text;	// Empty Stack	while($x = array_pop($tagstack)) {		$newtext .= '</' . $x . '>'; // Add remaining tags to close	}	// WP fix for the bug with HTML comments	$newtext = str_replace("< !--","<!--",$newtext);	$newtext = str_replace("<    !--","< !--",$newtext);	return $newtext;}function force_balance_tags($text) {	return balanceTags($text, 0, true);}function format_to_edit($content, $richedit = false) {	$content = apply_filters('format_to_edit', $content);	if (! $richedit )		$content = htmlspecialchars($content);	return $content;}function format_to_post($content) {	global $wpdb;	$content = apply_filters('format_to_post', $content);	return $content;}function zeroise($number,$threshold) { // function to add leading zeros when necessary	return sprintf('%0'.$threshold.'s', $number);}function backslashit($string) {	$string = preg_replace('/^([0-9])/', '\\\\\\\\\1', $string);	$string = preg_replace('/([a-z])/i', '\\\\\1', $string);	return $string;}function trailingslashit($string) {    if ( '/' != substr($string, -1)) {        $string .= '/';    }    return $string;}function addslashes_gpc($gpc) {	global $wpdb;	if (get_magic_quotes_gpc()) {		$gpc = stripslashes($gpc);	}	return $wpdb->escape($gpc);}function stripslashes_deep($value){   $value = is_array($value) ?               array_map('stripslashes_deep', $value) :               stripslashes($value);   return $value;}function antispambot($emailaddy, $mailto=0) {	$emailNOSPAMaddy = '';	srand ((float) microtime() * 1000000);	for ($i = 0; $i < strlen($emailaddy); $i = $i + 1) {		$j = floor(rand(0, 1+$mailto));		if ($j==0) {			$emailNOSPAMaddy .= '&#'.ord(substr($emailaddy,$i,1)).';';		} elseif ($j==1) {			$emailNOSPAMaddy .= substr($emailaddy,$i,1);		} elseif ($j==2) {			$emailNOSPAMaddy .= '%'.zeroise(dechex(ord(substr($emailaddy, $i, 1))), 2);		}	}	$emailNOSPAMaddy = str_replace('@','&#64;',$emailNOSPAMaddy);	return $emailNOSPAMaddy;}function make_clickable($ret) {	$ret = ' ' . $ret;	$ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "$1<a href='$2' rel='nofollow'>$2</a>", $ret);	$ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "$1<a href='http://$2' rel='nofollow'>$2</a>", $ret);	$ret = preg_replace("#(\s)([a-z0-9\-_.]+)@([^,< \n\r]+)#i", "$1<a href=\"mailto:$2@$3\">$2@$3</a>", $ret);	$ret = substr($ret, 1);	$ret = trim($ret);	return $ret;}function wp_rel_nofollow( $text ) {	$text = preg_replace('|<a (.+?)>|i', '<a $1 rel="nofollow">', $text);	return $text;}function convert_smilies($text) {	global $wp_smiliessearch, $wp_smiliesreplace;    $output = '';	if (get_settings('use_smilies')) {		// HTML loop taken from texturize function, could possible be consolidated		$textarr = preg_split("/(<.*>)/U", $text, -1, PREG_SPLIT_DELIM_CAPTURE); // capture the tags as well as in between		$stop = count($textarr);// loop stuff		for ($i = 0; $i < $stop; $i++) {			$content = $textarr[$i];			if ((strlen($content) > 0) && ('<' != $content{0})) { // If it's not a tag				$content = str_replace($wp_smiliessearch, $wp_smiliesreplace, $content);			}			$output .= $content;		}	} else {		// return default text.		$output = $text;	}	return $output;}function is_email($user_email) {	$chars = "/^([a-z0-9+_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,6}\$/i";	if(strstr($user_email, '@') && strstr($user_email, '.')) {		if (preg_match($chars, $user_email)) {			return true;		} else {			return false;		}	} else {		return false;	}}// used by wp-mail to handle charsets in email subjectsfunction wp_iso_descrambler($string) {  /* this may only work with iso-8859-1, I'm afraid */  if (!preg_match('#\=\?(.+)\?Q\?(.+)\?\=#i', $string, $matches)) {    return $string;  } else {    $subject = str_replace('_', ' ', $matches[2]);    $subject = preg_replace('#\=([0-9a-f]{2})#ei', "chr(hexdec(strtolower('$1')))", $subject);    return $subject;  }}// give it a date, it will give you the same date as GMTfunction get_gmt_from_date($string) {  // note: this only substracts $time_difference from the given date  preg_match('#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $string, $matches);  $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);  $string_gmt = gmdate('Y-m-d H:i:s', $string_time - get_settings('gmt_offset') * 3600);  return $string_gmt;}// give it a GMT date, it will give you the same date with $time_difference addedfunction get_date_from_gmt($string) {  // note: this only adds $time_difference to the given date  preg_match('#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $string, $matches);  $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);  $string_localtime = gmdate('Y-m-d H:i:s', $string_time + get_settings('gmt_offset')*3600);  return $string_localtime;}// computes an offset in seconds from an iso8601 timezonefunction iso8601_timezone_to_offset($timezone) {  // $timezone is either 'Z' or '[+|-]hhmm'  if ($timezone == 'Z') {    $offset = 0;  } else {    $sign    = (substr($timezone, 0, 1) == '+') ? 1 : -1;    $hours   = intval(substr($timezone, 1, 2));    $minutes = intval(substr($timezone, 3, 4)) / 60;    $offset  = $sign * 3600 * ($hours + $minutes);  }  return $offset;}// converts an iso8601 date to MySQL DateTime format used by post_date[_gmt]function iso8601_to_datetime($date_string, $timezone = USER) {  if ($timezone == GMT) {    preg_match('#([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(Z|[\+|\-][0-9]{2,4}){0,1}#', $date_string, $date_bits);    if (!empty($date_bits[7])) { // we have a timezone, so let's compute an offset      $offset = iso8601_timezone_to_offset($date_bits[7]);    } else { // we don't have a timezone, so we assume user local timezone (not server's!)      $offset = 3600 * get_settings('gmt_offset');    }    $timestamp = gmmktime($date_bits[4], $date_bits[5], $date_bits[6], $date_bits[2], $date_bits[3], $date_bits[1]);    $timestamp -= $offset;    return gmdate('Y-m-d H:i:s', $timestamp);  } elseif ($timezone == USER) {    return preg_replace('#([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(Z|[\+|\-][0-9]{2,4}){0,1}#', '$1-$2-$3 $4:$5:$6', $date_string);  }

⌨️ 快捷键说明

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