[Frameworkspider-svn] spider-commit [107] RewriteDocumentRootタグの修正。

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2010年 6月 22日 (火) 11:09:58 JST


Revision: 107
          http://sourceforge.jp/projects/frameworkspider/svn/view?view=rev&revision=107
Author:   m_nakashima
Date:     2010-06-22 11:09:58 +0900 (Tue, 22 Jun 2010)

Log Message:
-----------
RewriteDocumentRootタグの修正。
同じ名称のフォルダが階層内にあった場合にリンク変換が正しく行われない問題の修正をおこないました。

Modified Paths:
--------------
    current/README.txt
    current/spider/lib/spider/tags/RewriteDocumentRoot.class.php
    current/spider/lib/util/HttpRequest.class.php
    current/spider/spider_main.inc.php

Removed Paths:
-------------
    current/spider/lib/util/GetHTTPResponse.class.php


-------------- next part --------------
Modified: current/README.txt
===================================================================
--- current/README.txt	2010-06-03 07:18:21 UTC (rev 106)
+++ current/README.txt	2010-06-22 02:09:58 UTC (rev 107)
@@ -3,6 +3,8 @@
 **
 ** このファイルにはコミットごとに変更点とファイル名を記述します。
 **
+-- 2010-06-22
+1) RewriteDocumentRootタグの修正。同じ名称のフォルダが階層内にあった場合にリンク変換が正しく行われない問題の修正をおこないました。
 -- 2010-06-03
 1) setタグクラスの修正をおこないました。第二引数全体が''で囲まれていた場合、文字列判断はPHPプログラム
    と同等の記述で動作するようになりました。

Modified: current/spider/lib/spider/tags/RewriteDocumentRoot.class.php
===================================================================
--- current/spider/lib/spider/tags/RewriteDocumentRoot.class.php	2010-06-03 07:18:21 UTC (rev 106)
+++ current/spider/lib/spider/tags/RewriteDocumentRoot.class.php	2010-06-22 02:09:58 UTC (rev 107)
@@ -16,7 +16,8 @@
  * @author Multimedia Digital Contents Systems.Co.,Ltd. m.nakashima <m_nakas****@md-sy*****>
  * @since PHP 4.3
  */
-require_once(dirname(__FILE__).DIRECTORY_SEPARATOR."TagBase.class.php");
+require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'TagBase.class.php');
+require_once(dirname(dirname(dirname(__FILE__))).DIRECTORY_SEPARATOR.'util'.DIRECTORY_SEPARATOR.'CharUtility.class.php');
 class spider_tags_RewriteDocumentRoot extends spider_tags_TagBase {
 
 	/**
@@ -39,9 +40,10 @@
 			// 明示的に否定していないなら暗黙的に書き換える
 			$result_strings = preg_replace( '/\\{rewrite\\-document\\-root\\:[^\\}]*?\\}/'
 				, "", $result_strings );
-			$replace_uri	= APPLICATION_BASE_URI;
-			if( preg_match('/\\/$/', APPLICATION_BASE_URI) > 0 ) {
-				$replace_uri	= preg_replace('/\\/$/','',$replace_uri);
+			$regxUri	= str_replace('\\','\\\\',util_CharUtility::escapeRegxStr(APPLICATION_BASE_URI));
+			$replaceUri	= APPLICATION_BASE_URI;
+			if( preg_match('/\\/$/', $replaceUri) > 0 ) {
+				$replaceUri	= preg_replace('/\\/$/','',$replaceUri);
 			}
 			// src書き換え
 			$process_code = 'if( preg_match_all( \'/[sS][rR][cC]\\\\=([\\\'"])(\\/([^\\\'"\\/][^\\\'"]*|))([\\\'"])/\'';
@@ -50,8 +52,8 @@
 			$process_code .= ', PREG_PATTERN_ORDER ) > 0 ) { ';
 			$process_code .= 'foreach ( $output_array as $output ) { ';
 			$process_code .= 'foreach ( $output as $target ) { ';
-			$process_code .= 'if( preg_match(\'/\'.str_replace("/","\\/",\''.$replace_uri.'\').\'/\', $target ) == 0 ) { '."\n";
-			$process_code .= '$repstr = preg_replace(\'/[sS][rR][cC]\\\\=([\\\'"])(\\/[^\\\'"]*)([\\\'"])/\',\'src=${1}'.$replace_uri.'${2}${3}\',$target); '."\n";
+			$process_code .= 'if( preg_match(\'/^\'.\''.$regxUri.'\'.\'/\', $target ) == 0 ) { '."\n";
+			$process_code .= '$repstr = preg_replace(\'/[sS][rR][cC]\\\\=([\\\'"])(\\/[^\\\'"]*)([\\\'"])/\',\'src=${1}'.$replaceUri.'${2}${3}\',$target); '."\n";
 			$process_code .= '$outstr = str_replace( $target, $repstr, $outstr );'."\n";
 			$process_code .= ' }'."\n";
 			$process_code .= '}}}';
@@ -63,8 +65,8 @@
 			$process_code .= ', PREG_PATTERN_ORDER ) > 0 ) { ';
 			$process_code .= 'foreach ( $output_array as $output ) { ';
 			$process_code .= 'foreach ( $output as $target ) { ';
-			$process_code .= 'if( preg_match(\'/\'.str_replace("/","\\/",\''.$replace_uri.'\').\'/\', $target ) == 0 ) { '."\n";
-			$process_code .= '$repstr = preg_replace(\'/[hH][rR][eE][fF]\\\\=([\\\'"])(\\/[^\\\'"]*)([\\\'"])/\',\'href=${1}'.$replace_uri.'${2}${3}\',$target); '."\n";
+			$process_code .= 'if( preg_match(\'/^\'.\''.$regxUri.'\'.\'/\', $target ) == 0 ) { '."\n";
+			$process_code .= '$repstr = preg_replace(\'/[hH][rR][eE][fF]\\\\=([\\\'"])(\\/[^\\\'"]*)([\\\'"])/\',\'href=${1}'.$replaceUri.'${2}${3}\',$target); '."\n";
 			$process_code .= '$outstr = str_replace( $target, $repstr, $outstr );'."\n";
 			$process_code .= ' }'."\n";
 			$process_code .= '}}}';
@@ -76,8 +78,8 @@
 			$process_code .= ', PREG_PATTERN_ORDER ) > 0 ) { ';
 			$process_code .= 'foreach ( $output_array as $output ) { ';
 			$process_code .= 'foreach ( $output as $target ) { ';
-			$process_code .= 'if( preg_match(\'/\'.str_replace("/","\\/",\''.$replace_uri.'\').\'/\', $target ) == 0 ) { '."\n";
-			$process_code .= '$repstr = preg_replace(\'/[aA][cC][tT][iI][oO][nN]\\\\=([\\\'"])(\\/[^\\\'"]*)([\\\'"])/\',\'action=${1}'.$replace_uri.'${2}${3}\',$target); '."\n";
+			$process_code .= 'if( preg_match(\'/^\'.\''.$regxUri.'\'.\'/\', $target ) == 0 ) { '."\n";
+			$process_code .= '$repstr = preg_replace(\'/[aA][cC][tT][iI][oO][nN]\\\\=([\\\'"])(\\/[^\\\'"]*)([\\\'"])/\',\'action=${1}'.$replaceUri.'${2}${3}\',$target); '."\n";
 			$process_code .= '$outstr = str_replace( $target, $repstr, $outstr );'."\n";
 			$process_code .= ' }'."\n";
 			$process_code .= '}}}';
@@ -89,8 +91,8 @@
 			$process_code .= ', PREG_PATTERN_ORDER ) > 0 ) { ';
 			$process_code .= 'foreach ( $output_array as $output ) { ';
 			$process_code .= 'foreach ( $output as $target ) { ';
-			$process_code .= 'if( preg_match(\'/\'.str_replace("/","\\/",\''.$replace_uri.'\').\'/\', $target ) == 0 ) { '."\n";
-			$process_code .= '$repstr = preg_replace(\'/window\\\\.open\\\\(([\\\'"])(\\/[^\\\'"]*)([\\\'"])/\',\'window.open(${1}'.$replace_uri.'${2}${3}\',$target); '."\n";
+			$process_code .= 'if( preg_match(\'/^\'.\''.$regxUri.'\'.\'/\', $target ) == 0 ) { '."\n";
+			$process_code .= '$repstr = preg_replace(\'/window\\\\.open\\\\(([\\\'"])(\\/[^\\\'"]*)([\\\'"])/\',\'window.open(${1}'.$replaceUri.'${2}${3}\',$target); '."\n";
 			$process_code .= '$outstr = str_replace( $target, $repstr, $outstr );'."\n";
 			$process_code .= ' }'."\n";
 			$process_code .= '}}}';
@@ -102,8 +104,8 @@
 			$process_code .= ', PREG_PATTERN_ORDER ) > 0 ) { ';
 			$process_code .= 'foreach ( $output_array as $output ) { ';
 			$process_code .= 'foreach ( $output as $target ) { ';
-			$process_code .= 'if( preg_match(\'/\'.str_replace("/","\\/",\''.$replace_uri.'\').\'/\', $target ) == 0 ) { '."\n";
-			$process_code .= '$repstr = preg_replace(\'/url\\\\(([\\\'"])(\\/[^\\\'"]*)([\\\'"])/\',\'url(${1}'.$replace_uri.'${2}${3}\',$target); '."\n";
+			$process_code .= 'if( preg_match(\'/^\'.\''.$regxUri.'\'.\'/\', $target ) == 0 ) { '."\n";
+			$process_code .= '$repstr = preg_replace(\'/url\\\\(([\\\'"])(\\/[^\\\'"]*)([\\\'"])/\',\'url(${1}'.$replaceUri.'${2}${3}\',$target); '."\n";
 			$process_code .= '$outstr = str_replace( $target, $repstr, $outstr );'."\n";
 			$process_code .= ' }'."\n";
 			$process_code .= '}}}';

Deleted: current/spider/lib/util/GetHTTPResponse.class.php
===================================================================
--- current/spider/lib/util/GetHTTPResponse.class.php	2010-06-03 07:18:21 UTC (rev 106)
+++ current/spider/lib/util/GetHTTPResponse.class.php	2010-06-22 02:09:58 UTC (rev 107)
@@ -1,208 +0,0 @@
-<?php
-/**
- * ユーティリティ:HTTPリクエストを送信してレスポンスを取得するユーティリティオブジェクト
- * 
- * @package util ユーティリティパッケージ
- * @version 1.0.0
- * @copyright Copyright &copy; 2008, Multimedia Digital Contents Systems.Co.,Ltd.<info****@md-sy*****> http://www.md-systems.net/
- * @author Multimedia Digital Contents Systems.Co.,Ltd. m.nakashima <m_nakas****@md-sy*****>
- * @since PHP 4.3
- * @deprecated
- */
-class util_GetHTTPResponse {
-	var $protocol			= "";
-	var $status_code		= "";
-	var $status_string		= "";
-	var $response_headers	= array();
-	var $response_body		= null;
-	function util_GetHTTPResponse(){
-	}
-	function get($url,$header_params=array()){
-		list( $pr, $blank, $domain )	= explode('/',$url );
-		$uri	= substr($url,strpos($url,$domain));
-		$uri	= str_replace($domain,"",$uri);
-		if( strlen($uri) == 0 ) {
-			$uri	= '/';
-		}
-		if( preg_match('/^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}/',gethostbyname($domain)) == 0 ) {
-			return false;
-		}
-		return $this->get_response($domain,$uri,$header_params);
-	}
-	function get_response($host,$uri,$header_params=array()){
-		$request = "GET {$uri} HTTP/1.1\r\n"
-			."Accept: */*\r\n"
-			."Host: {$host}\r\n"
-		;
-		foreach( $header_params as $key => $value ) {
-			if( strlen(trim($key)) > 0 && strlen(trim($value)) > 0 ) {
-				$request	.= $key . ": " . $value . "\r\n";
-			}
-		}
-		$request	.= "Connection: close\r\n\r\n";
-		if( $fp = @fsockopen( gethostbyname($host), 80, $rv->en, $rv->es, 20 ) ){
-			if( socket_set_timeout( $fp, 30 ) ) {
-				fwrite( $fp, $request );
-				$response	= '';
-				while (!feof($fp)) {
-					$response .= fgets($fp, 128);
-				}
-				// responseの解析
-				$header_string	= '';
-				$response_body	= null;
-
-				// レスポンスヘッダ文字列を取得
-				$header_string		= substr( $response, 0, strpos($response,"\r\n\r\n"));
-				$headerpear_array	= explode("\r\n",$header_string);
-				// レスポンスステータスを確認
-				$status_str			= array_shift($headerpear_array);
-				list($this->protocol,$this->status_code,$this->status_string)
-					= explode(" ",$status_str);
-				// その他のヘッダを取得
-				foreach($headerpear_array as $line){
-					if( strlen($line) > 0 ) {
-						$headers	= explode(":",$line);
-						if( count($headers) > 0 ) {
-							$key	= array_shift($headers);
-							$val	= implode(':',$headers);
-							$this->response_headers[trim($key)] = trim($val);
-						}
-					}
-				}
-				// レスポンスボディの取得
-				if( $this->response_headers['Transfer-Encoding'] == 'chunked' ) {
-					$header_hex_string		= bin2hex($header_string."\r\n\r\n");
-					$separator_hex_string	= bin2hex("\r\n");
-					$body_start_pos			= strlen($header_hex_string);
-					$body_hex_string		= bin2hex($response);
-					$body_hex_string		= substr($body_hex_string,$body_start_pos);
-					$body_chunk_array		= explode($separator_hex_string,$body_hex_string);
-					// 0,2,4,..偶数はチャンクサイズなので削除してつなげ直す
-					$i	= 0;
-					$body_hex_string		= '';
-					foreach( $body_chunk_array as $val ) {
-						if( $i%2 != 0 ) { $body_hex_string	.= $val; }
-						$i++;
-					}
-					$this->response_body	= pack("H*",$body_hex_string);
-				} else {
-					$lines					= explode("\r\n\r\n",$response);
-					$header_string			= array_shift($lines);
-					$response_body			= implode("\r\n\r\n",$lines);
-					$this->response_body	= $response_body;
-					$headerpear_array		= explode("\r\n",$header_string);
-					$status_str				= array_shift($headerpear_array);
-					list($this->protocol,$this->status_code,$this->status_string)
-						= explode(" ",$status_str);
-				}
-				return true;
-			}
-			return false;
-		} else {
-			return false;
-		}
-	}
-	function post($url,$header_params=array(),$requestBody){
-		list( $pr, $blank, $domain )	= explode('/',$url );
-		$uri	= substr($url,strpos($url,$domain));
-		$uri	= str_replace($domain,"",$uri);
-		if( strlen($uri) == 0 ) {
-			$uri	= '/';
-		}
-		if( preg_match('/^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}/',gethostbyname($domain)) == 0 ) {
-			return false;
-		}
-		return $this->post_response($domain,$uri,$header_params,$requestBody);
-	}
-	function post_response($host,$uri,$header_params=array(),$requestBody){
-		$request = "POST {$uri} HTTP/1.1\r\n"
-			."Accept: */*\r\n"
-			."Host: {$host}\r\n"
-		;
-		foreach( $header_params as $key => $value ) {
-			if( strlen(trim($key)) > 0 && strlen(trim($value)) > 0 ) {
-				$request	.= $key . ": " . $value . "\r\n";
-			}
-		}
-		$request	.= "Connection: close\r\n\r\n";
-		$request	.= "Content-Type: application/x-www-form-urlencoded;charset=UTF-8\r\n";
-		$request	.= "Content-Length: ".strlen($requestBody)."\r\n\r\n";
-		$request	.= $requestBody;
-		if( $fp = @fsockopen( $host, 80, $rv->en, $rv->es, 20 ) ){
-			if( socket_set_timeout( $fp, 30 ) ) {
-				fwrite( $fp, $request );
-				$response	= '';
-				while (!feof($fp)) {
-					$response .= fgets($fp, 128);
-				}
-				// responseの解析
-				$header_string	= '';
-				$response_body	= null;
-
-				// レスポンスヘッダ文字列を取得
-				$header_string		= substr( $response, 0, strpos($response,"\r\n\r\n"));
-				$headerpear_array	= explode("\r\n",$header_string);
-				// レスポンスステータスを確認
-				$status_str			= array_shift($headerpear_array);
-				list($this->protocol,$this->status_code,$this->status_string)
-					= explode(" ",$status_str);
-				// その他のヘッダを取得
-				foreach($headerpear_array as $line){
-					if( strlen($line) > 0 ) {
-						$headers	= explode(":",$line);
-						if( count($headers) > 0 ) {
-							$key	= array_shift($headers);
-							$val	= implode(':',$headers);
-							$this->response_headers[trim($key)] = trim($val);
-						}
-					}
-				}
-				// レスポンスボディの取得
-				if( $this->response_headers['Transfer-Encoding'] == 'chunked' ) {
-					$header_hex_string		= bin2hex($header_string."\r\n\r\n");
-					$separator_hex_string	= bin2hex("\r\n");
-					$body_start_pos			= strlen($header_hex_string);
-					$body_hex_string		= bin2hex($response);
-					$body_hex_string		= substr($body_hex_string,$body_start_pos);
-					$body_chunk_array		= explode($separator_hex_string,$body_hex_string);
-					// 0,2,4,..偶数はチャンクサイズなので削除してつなげ直す
-					$i	= 0;
-					$body_hex_string		= '';
-					foreach( $body_chunk_array as $val ) {
-						if( $i%2 != 0 ) { $body_hex_string	.= $val; }
-						$i++;
-					}
-					$this->response_body	= pack("H*",$body_hex_string);
-				} else {
-					$lines					= explode("\r\n\r\n",$response);
-					$header_string			= array_shift($lines);
-					$response_body			= implode("\r\n\r\n",$lines);
-					$this->response_body	= $response_body;
-					$headerpear_array		= explode("\r\n",$header_string);
-					$status_str				= array_shift($headerpear_array);
-					list($this->protocol,$this->status_code,$this->status_string)
-						= explode(" ",$status_str);
-				}
-				return true;
-			}
-			return false;
-		} else {
-			return false;
-		}
-	}
-}
-//$obj = new util_GetHTTPResponse();
-//if( $obj->get('http://www.md-systems.net/') ){
-////	foreach( $obj->response_headers as $key => $value ) {
-////		header($key.': '.$value);
-////	}
-////	print $obj->response_body;
-////
-//	header('Content-type: text/plain;charset=UTF-8');
-//print_r($obj);
-//} else {
-//	header('Content-type: text/plain;charset=UTF-8');
-//	echo "通信に失敗";
-//}
-//
-?>
\ No newline at end of file

Modified: current/spider/lib/util/HttpRequest.class.php
===================================================================
--- current/spider/lib/util/HttpRequest.class.php	2010-06-03 07:18:21 UTC (rev 106)
+++ current/spider/lib/util/HttpRequest.class.php	2010-06-22 02:09:58 UTC (rev 107)
@@ -109,7 +109,7 @@
 		// リクエスト文字列作成
 		$requestStrings	= $this->_createRequestStrings( $contents );
 		// ソケット通信
-		if( $socket = @fsockopen( $connectTarget, $this->requestPort, $this->errorNumber, $this->errorMessage, $timeout ) ){
+		if( $socket = @fsockopen( $address, $this->requestPort, $this->errorNumber, $this->errorMessage, $timeout ) ){
 			if( @socket_set_timeout( $socket, $timeout ) ) {
 				// リクエスト送信
 				fwrite( $socket, $requestStrings );
@@ -148,9 +148,13 @@
 				$requestStrings	.= $key . ": " . $value . "\r\n";
 			}
 		}
-		$requestStrings	.= "Connection: close\r\n\r\n";
+		$requestStrings	.= "Connection: close\r\n";
 		if( strlen($contents) > 0 ) {
+			$requestStrings	.= "Content-Type: application/x-www-form-urlencoded\r\n";
+			$requestStrings	.= "Content-Length: ".strlen($contents)."\r\n\r\n";
 			$requestStrings	.= $contents."\r\n\r\n";
+		} else {
+			$requestStrings	.= "\r\n";
 		}
 		return $requestStrings;
 	}

Modified: current/spider/spider_main.inc.php
===================================================================
--- current/spider/spider_main.inc.php	2010-06-03 07:18:21 UTC (rev 106)
+++ current/spider/spider_main.inc.php	2010-06-22 02:09:58 UTC (rev 107)
@@ -3,7 +3,7 @@
  * framework-spider: Webページ利用用共通メイン実行ファイル
  */
 // Framework Version
-define( 'SPIDER_VERSION', '1.0.01' );
+define( 'SPIDER_VERSION', '1.0.04' );
 
 /* 設定ファイルの読み込み	*/
 require_once( dirname(__FILE__).DIRECTORY_SEPARATOR.'define.inc.php' );



Frameworkspider-svn メーリングリストの案内
Back to archive index