a short sketch about linux syntex lines.

源代码在线查看: uccode.class.php

软件大小: 7892 K
上传用户: balefu123
关键词: sketch syntex short about
下载地址: 免注册下载 普通下载 VIP

相关代码

								
				/*
					[UCenter] (C)2001-2009 Comsenz Inc.
					This is NOT a freeware, use is subject to license terms
				
					$Id: uccode.class.php 753 2008-11-14 06:48:25Z cnteacher $
				*/
				
				class uccode {
					var $uccodes;
				
					function uccode() {
						$this->uccode = array(
							'pcodecount' => -1,
							'codecount' => 0,
							'codehtml' => ''
						);
					}
				
					function codedisp($code) {
						$this->uccode['pcodecount']++;
						$code = str_replace('\\"', '"', preg_replace("/^[\n\r]*(.+?)[\n\r]*$/is", "\\1", $code));
						$this->uccode['codehtml'][$this->uccode['pcodecount']] = $this->tpl_codedisp($code);
						$this->uccode['codecount']++;
						return "[\tUCENTER_CODE_".$this->uccode[pcodecount]."\t]";
					}
				
					function complie($message) {
						$message = htmlspecialchars($message);
						if(strpos($message, '[/code]') !== FALSE) {
							$message = preg_replace("/\s*\[code\](.+?)\[\/code\]\s*/ies", "\$this->codedisp('\\1')", $message);
						}
						if(strpos($message, '[/url]') !== FALSE) {
							$message = preg_replace("/\[url(=((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|ed2k|thunder|synacast){1}:\/\/|www\.)([^\[\"']+?))?\](.+?)\[\/url\]/ies", "\$this->parseurl('\\1', '\\5')", $message);
						}
						if(strpos($message, '[/email]') !== FALSE) {
							$message = preg_replace("/\[email(=([a-z0-9\-_.+]+)@([a-z0-9\-_]+[.][a-z0-9\-_.]+))?\](.+?)\[\/email\]/ies", "\$this->parseemail('\\1', '\\4')", $message);
						}
						$message = str_replace(array(
							'[/color]', '[/size]', '[/font]', '[/align]', '[b]', '[/b]',
							'[i]', '[/i]', '[u]', '[/u]', '[list]', '[list=1]', '[list=a]',
							'[list=A]', '[*]', '[/list]', '[indent]', '[/indent]', '[/float]'
						), array(
							'', '', '', '', '', '', '',
							'', '', '', '', '', '',
							'', '', '', '', '', ''
						), preg_replace(array(
							"/\[color=([#\w]+?)\]/i",
							"/\[size=(\d+?)\]/i",
							"/\[size=(\d+(\.\d+)?(px|pt|in|cm|mm|pc|em|ex|%)+?)\]/i",
							"/\[font=([^\[\							"/\[align=(left|center|right)\]/i",
							"/\[float=(left|right)\]/i"
						), array(
							"",
							"",
							"",
							"",
							"",
							""
						), $message));
						if(strpos($message, '[/quote]') !== FALSE) {
							$message = preg_replace("/\s*\[quote\][\n\r]*(.+?)[\n\r]*\[\/quote\]\s*/is", $this->tpl_quote(), $message);
						}
						if(strpos($message, '[/img]') !== FALSE) {
							$message = preg_replace(array(
								"/\[img\]\s*([^\[\								"/\[img=(\d{1,4})[x|\,](\d{1,4})\]\s*([^\[\							), array(
								"\$this->bbcodeurl('\\1', '')",
								"\$this->bbcodeurl('\\3', '')"
							), $message);
						}
						for($i = 0; $i uccode['pcodecount']; $i++) {
							$message = str_replace("[\tUCENTER_CODE_$i\t]", $this->uccode['codehtml'][$i], $message);
						}
						return nl2br(str_replace(array("\t", '   ', '  '), array('        ', '   ', '  '), $message));
					}
				
					function parseurl($url, $text) {
						if(!$url && preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|ed2k|thunder|synacast){1}:\/\/|www\.)[^\[\"']+/i", trim($text), $matches)) {
							$url = $matches[0];
							$length = 65;
							if(strlen($url) > $length) {
								$text = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, - intval($length * 0.3));
							}
							return ''.$text.'';
						} else {
							$url = substr($url, 1);
							if(substr(strtolower($url), 0, 4) == 'www.') {
								$url = 'http://'.$url;
							}
							return ''.$text.'';
						}
					}
				
					function parseemail($email, $text) {
						if(!$email && preg_match("/\s*([a-z0-9\-_.+]+)@([a-z0-9\-_]+[.][a-z0-9\-_.]+)\s*/i", $text, $matches)) {
							$email = trim($matches[0]);
							return ''.$email.'';
						} else {
							return ''.$text.'';
						}
					}
				
					function bbcodeurl($url, $tags) {
						if(!preg_match("//s", $url)) {
							if(!in_array(strtolower(substr($url, 0, 6)), array('http:/', 'https:', 'ftp://', 'rtsp:/', 'mms://'))) {
								$url = 'http://'.$url;
							}
							return str_replace(array('submit', 'logging.php'), array('', ''), sprintf($tags, $url, addslashes($url)));
						} else {
							return ' '.$url;
						}
					}
				
					function tpl_codedisp($code) {
						return ''.$code.'';
					}
				
					function tpl_quote() {
						return '\\1';
					}
				}
				
				/*
				
				Usage:
				$str = 				1
				2
				3
				EOF;
				require_once 'lib/uccode.class.php';
				$this->uccode = new uccode();
				echo $this->uccode->complie($str);
				
				*/
				
				?>			

相关资源