<?php
class String {
	var $likes = '[^<\"\']*';
	var $links = '([^\'\"<]*)';
	var $titles = '(.*?)';
	var $bodys = '(.*)';
	var $author = '([^<]*)';
	var $source = '([^<]*)';
	var $pubtime = '([^<]*)';
	var $link_pages = '(.*)';
	var $link_nexts = '([^<]*)';
	var $pages;

	var $preg_likes = '\[变数\]';
	var $preg_links = '\[连接\]';
	var $preg_titles = '\[标题\]';
	var $preg_bodys = '\[内容\]';
	var $preg_author = '\[作者\]';
	var $preg_source = '\[来源\]';
	var $preg_pubtime = '\[时间\]';
	var $preg_link_pages = '\[分页区域\]';
	var $preg_link_nexts = '\[上下页\]';
	// 替换连接和标题
	function pregLinks($linktitle) {
		$linktitle = preg_quote($linktitle, "/"); //给 . \\ + * ? [ ^ ] $ ( ) { } = ! < > | : 添加 \
		$linktitle = preg_replace("/\s+/", '\s+', $linktitle); //给空加上 \s
		 
		// $linktitle  = addcslashes($linktitle,"\'\"\/");
		$linktitle = str_replace($this -> preg_links, $this -> links, $linktitle);
		$linktitle = str_replace($this -> preg_titles, $this -> titles, $linktitle);
		$linktitle = str_replace($this -> preg_likes, $this -> likes, $linktitle);

		$linktitle = str_replace('"', '\"', $linktitle);

		return $linktitle;
	} 
	function pregPage($link_pages) {
		$link_pages = preg_quote($link_pages, "/"); //给 . \\ + * ? [ ^ ] $ ( ) { } = ! < > | : 添加 \
		$link_pages = preg_replace("/\s+/", '\s+', $link_pages); //给空加上 \s
		 
		// $link_pages  = addcslashes($link_pages,"\'\"\/");
		$link_pages = str_replace($this -> preg_link_pages, $this -> link_pages, $link_pages);
		$link_pages = str_replace($this -> preg_likes, $this -> likes, $link_pages);

		$link_pages = str_replace('"', '\"', $link_pages);

		return $link_pages;
	} 
	function pregNexts($link_nexts) {
		$link_nexts = preg_quote($link_nexts, "/"); //给 . \\ + * ? [ ^ ] $ ( ) { } = ! < > | : 添加 \
		$link_nexts = preg_replace("/\s+/", '\s+', $link_nexts); //给空加上 \s 
		// $link_nexts  = addcslashes($link_nexts,"\'\"\/");
		$link_nexts = str_replace($this -> preg_link_nexts, $this -> link_nexts, $link_nexts);
		$link_nexts = str_replace($this -> preg_likes, $this -> likes, $link_nexts);

		$link_nexts = str_replace('"', '\"', $link_nexts);

		return $link_nexts;
	} 
	function pregBody($body) {
		$body = preg_quote($body, "/"); //给 . \\ + * ? [ ^ ] $ ( ) { } = ! < > | : 添加 \
		$body = preg_replace("/\s+/", '\s+', $body); //给空加上 \s 
		// $body  = addcslashes($body,"\'\"\/");
		$body = str_replace($this -> preg_bodys, $this -> bodys, $body);
		$body = str_replace($this -> preg_likes, $this -> likes, $body);

		$body = str_replace('"', '\"', $body);

		return $body;
	} 
	function pregAuthor($author) {
		$author = preg_quote($author, "/"); //给 . \\ + * ? [ ^ ] $ ( ) { } = ! < > | : 添加 \
		$author = preg_replace("/\s+/", '\s+', $author); //给空加上 \s 
		// $author  = addcslashes($author,"\'\"\/");
		$author = str_replace($this -> preg_author, $this -> author, $author);
		$author = str_replace($this -> preg_likes, $this -> likes, $author);

		$author = str_replace('"', '\"', $author);

		return $author;
	} 
	function pregSource($source) {
		$source = preg_quote($source, "/"); //给 . \\ + * ? [ ^ ] $ ( ) { } = ! < > | : 添加 \
		$source = preg_replace("/\s+/", '\s+', $source); //给空加上 \s
		$source = str_replace($this -> preg_source, $this -> source, $source);
		$source = str_replace($this -> preg_likes, $this -> likes, $source);
		$source = str_replace('"', '\"', $source);
		return $source;
	} 
	function pregPubtime($pubtime) {
		$pubtime = preg_quote($pubtime, "/"); //给 . \\ + * ? [ ^ ] $ ( ) { } = ! < > | : 添加 \
		$pubtime = preg_replace("/\s+/", '\s+', $pubtime); //给空加上 \s
		$pubtime = str_replace($this -> preg_pubtime, $this -> source, $pubtime);
		$pubtime = str_replace($this -> preg_likes, $this -> likes, $pubtime);
		$pubtime = str_replace('"', '\"', $pubtime);
		return $pubtime;
	} 
	function getUrl($onurl) {
		preg_match ('/((http:\/\/[^\/]+).*\/)[^\/]*/i', $onurl, $this -> outurl);
		$this -> outurl[2] .= '/';
		return $this -> outurl;
	} 
	function gethttp($url) {
		if (!preg_match ('/http:\/\//i', $url, $out)) {
			if (preg_match ('/^(\.{2})?\/(.+)/i', $url, $out)) { // 带有目录的网址 加+网址
					$url = $this -> outurl[2] . $out[2]; //有目录的 或有/的
			} else {
				preg_match ('/^(\.{1}\/)?(.+)/i', $url, $out); //将.去掉
				$url = $this -> outurl[1] . $out[2]; //无目录的网址 加上网址+目录
			} 
		} else {
			$url = $url; //有HTTP的 不需要任何操作
		} 
		return $url;
	} 
	function pregCont($cont, $adds = 0) {
		$pattern = "/(<[^<]*(href|src|value|dynsrc)=['\"\s]*)((\.{2})?\/)([^:<'\"]+\.[^:<'\"]+)(['\"\s]+[^<]*>)/is";
		$pattern2 = "/(<[^<]*(href|src|value|dynsrc)=['\"\s]*)(\.\/)?([^:<'\"]+\.[^:<'\"]+)(['\"\s]+[^<]*>)/is";
		$replacement = "\${1}" . $this -> outurl[2] . "${3}\${5}\$6";
		$replacement2 = "\${1}" . $this -> outurl[1] . "\${4}\$5";
		$cont = preg_replace($pattern, $replacement, $cont);
		$cont = preg_replace($pattern2, $replacement2, $cont);

		if ($adds == 0) {
			$cont = addslashes($cont);
		} 

		return $cont;
	} 
	// 处理cookie
	function getCookie($cookie) {
		$cookie = explode("\n*\n", $cookie);

		for ($i = 0; $i < count($cookie); $i++) {
			$cookie_s = preg_split ("/[\s]+/", $cookie[$i]);
			if ($cookie_s[0] != "" and $cookie_s[1] != "") {
				$cookies .= $cookie_s[0] . '=' . $cookie_s[1] . '; ';
			} 
		} 
		return $cookies;
	} 

	function fileFsock($url, $cookie) {
		return $this -> getCookie($cookie); 
	} 
} 

?>