[Frameworkspider-svn] spider-commit [83] リバースプロキシ経由でアクセスした場合にテンプレート内の自動URI書き換えが正しく行えないのでリバースプロキシ経由の場合に特別設定を行えるように機能を追加しました。

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2009年 10月 7日 (水) 18:23:27 JST


Revision: 83
          http://sourceforge.jp/projects/frameworkspider/svn/view?view=rev&revision=83
Author:   m_nakashima
Date:     2009-10-07 18:23:27 +0900 (Wed, 07 Oct 2009)

Log Message:
-----------
リバースプロキシ経由でアクセスした場合にテンプレート内の自動URI書き換えが正しく行えないのでリバースプロキシ経由の場合に特別設定を行えるように機能を追加しました。
spider/define.inc.phpで設定を追加できます。

Modified Paths:
--------------
    current/WWW_PUBLIC/spider.inc.php
    current/spider/define.inc.php
    current/spider/lib/spider/BuildInformation.class.php
    current/spider/lib/spider/Builder.class.php
    current/spider/lib/spider/HttpRequest.class.php
    current/spider/lib/spider/functions.inc.php
    current/spider/lib/spider/module/AutoEncode.class.php
    current/spider/lib/spider/module/AutoFormat.class.php
    current/spider/lib/spider/tags/Charset.class.php
    current/spider/lib/spider/tags/UseSession.class.php
    current/spider/lib/util/ValidateFunctions.class.php
    current/spider/spider_command.inc.php
    current/spider/spider_main.inc.php
    current/spider/unique_setting.inc.php


-------------- next part --------------
Modified: current/WWW_PUBLIC/spider.inc.php
===================================================================
--- current/WWW_PUBLIC/spider.inc.php	2009-09-15 09:53:36 UTC (rev 82)
+++ current/WWW_PUBLIC/spider.inc.php	2009-10-07 09:23:27 UTC (rev 83)
@@ -20,7 +20,13 @@
 	header( 'Content-type: text/plain;charset=UTF-8' );
 	die( 'You can\'t access this file direct!' );
 }
-
+/*
+ * application base path
+ */
+define( 'APPLICATION_BASE_PATH', dirname(__FILE__ ) );
+/*
+ * If spider folder is not defined, search spider folder.
+ */
 if( !isset( $DIR_PATH_SPIDER_DATA ) || strlen( trim( $DIR_PATH_SPIDER_DATA ) ) == 0 ) {
 	$DIR_PATH_SPIDER_DATA	= null;
 	$targetDir				= dirname(__FILE__);
@@ -60,41 +66,73 @@
 } else {
 	define ( 'DIR_PATH_SPIDER_DATA',	$DIR_PATH_SPIDER_DATA );
 }
-$request_protocol		= $_SERVER['SERVER_PROTOCOL'];
-$request_port			= $_SERVER['SERVER_PORT'];
-$request_server_name	= $_SERVER['SERVER_NAME'];
+/*
+ * If spider folder is found, require define.inc.php
+ */
+$spiderDefinePath	= DIR_PATH_SPIDER_DATA.DIRECTORY_SEPARATOR.'define.inc.php';
+if( defined('DIR_PATH_SPIDER_DATA') && is_dir(DIR_PATH_SPIDER_DATA) && file_exists($spiderDefinePath) ) { 
+	require_once( $spiderDefinePath );
+} else {
+		header( 'Content-type: text/plain;charset=UTF-8' );
+		die( 'Spider DATA Folder is invalid!' );
+}
+/*
+ * folder & uri
+ */
 $request_uri			= $_SERVER['REQUEST_URI'];
 $document_root			= $_SERVER['DOCUMENT_ROOT'];
-$is_ssl					= false;
-if( isset($_SERVER['HTTPS']) && preg_match('/[oO][fF][fF]/', $_SERVER['HTTPS'] ) == 0 ) {
-	$is_ssl				= true;
-}
-// ユーザーディレクトリをドキュメントルートにする
+
+/* formart user document root */
 if( preg_match('/^\\/\\~[0-9a-zA-Z\\_]+\\//',$request_uri) > 0 ) {
 	$user_request_uri	= preg_replace('/^\\/\\~[^\\/]+\\//','/',$_SERVER['PHP_SELF'] );
 	$document_root		= str_replace( '/',DIRECTORY_SEPARATOR, dirname($script_filename) );
 	$document_root		= str_replace( str_replace( '/',DIRECTORY_SEPARATOR, dirname($user_request_uri) ), '', $document_root );
 }
-$spider_base_uri	= null;
-if( isset($SPIDER_DEFINE_BASE_URI) && strlen($SPIDER_DEFINE_BASE_URI) > 0 ) {
-	$spider_base_uri		= $SPIDER_DEFINE_BASE_URI;
-} else {
-	$spider_inc_path		= str_replace( DIRECTORY_SEPARATOR, '/', __FILE__ );
-	$spider_base_uri		= dirname(str_replace( $document_root, '', $spider_inc_path ));
-	if( preg_match('/^\\/\\~[0-9a-zA-Z\\_]+\\//',$request_uri) > 0 ) {
-		// ユーザーディレクトリの場合リクエストURIの一つ目の要素をくっつける
-		$dirname_array		= explode('/',$request_uri);
-		$spider_base_uri	= '/'.$dirname_array[1].$spider_base_uri;
+/*
+ * if not defined, create application base uri.
+ */
+if( defined('APPLICATION_PROXY_REV_HOST') && strlen(APPLICATION_PROXY_REV_HOST) > 0
+	&& ( APPLICATION_PROXY_REV_HOST == $_SERVER['HTTP_X_FORWARDED_HOST']
+		|| APPLICATION_PROXY_REV_HOST == $_SERVER['HTTP_X_FORWARDED_SERVER'] ) ) {
+	// リバースプロキシホスト名が設置されていてそこからのアクセスの場合
+	define( 'APPLICATION_BASE_URL', APPLICATION_PROXY_REV_BASE_URL );
+	define( 'APPLICATION_NML_URL', APPLICATION_PROXY_REV_NML_URL );
+	define( 'APPLICATION_SSL_URL', APPLICATION_PROXY_REV_SSL_URL );
+	define( 'APPLICATION_BASE_URI', APPLICATION_PROXY_REV_BASE_URI );
+} else if( !defined('APPLICATION_BASE_URI') ) {
+	$app_base_uri	= null;
+	if( isset($SPIDER_DEFINE_BASE_URI) && strlen($SPIDER_DEFINE_BASE_URI) > 0 ) {
+		$app_base_uri		= $SPIDER_DEFINE_BASE_URI;
+	} else {
+		$spider_inc_path		= str_replace( DIRECTORY_SEPARATOR, '/', __FILE__ );
+		$app_base_uri		= dirname(str_replace( $document_root, '', $spider_inc_path ));
+		if( preg_match('/^\\/\\~[0-9a-zA-Z\\_]+\\//',$request_uri) > 0 ) {
+			// if user dir, unshift first folder
+			$dirname_array		= explode('/',$request_uri);
+			$app_base_uri	= '/'.$dirname_array[1].$app_base_uri;
+		}
+		if( preg_match('/^\\./',$app_base_uri) > 0 ) {
+			// if first char is '.', remove.
+			$app_base_uri	= preg_replace('/^\\./','',$app_base_uri);
+		}
 	}
-	if( preg_match('/^\\./',$spider_base_uri) > 0 ) {
-		// リクエストURIが.から始まる場合は除去する
-		$spider_base_uri	= preg_replace('/^\\./','',$spider_base_uri);
+	if( !preg_match('/\\/$/', $app_base_uri ) ) {
+		$app_base_uri	.= '/';
 	}
+	if ( !preg_match( '/\\/$/', $app_base_uri ) ) {
+		$app_base_uri .= '/';
+	}
+	define( 'APPLICATION_BASE_URI',  $app_base_uri );
+	unset($app_base_uri);
 }
-if( !preg_match('/\\/$/', $spider_base_uri ) ) {
-	$spider_base_uri	.= '/';
+
+$request_protocol		= $_SERVER['SERVER_PROTOCOL'];
+$request_port			= $_SERVER['SERVER_PORT'];
+$request_server_name	= $_SERVER['SERVER_NAME'];
+$is_ssl					= false;
+if( isset($_SERVER['HTTPS']) && preg_match('/[oO][fF][fF]/', $_SERVER['HTTPS'] ) == 0 ) {
+	$is_ssl				= true;
 }
-
 $prtcl = 'http://';
 if( $is_ssl ) {
 	$prtcl = 'https://';
@@ -103,23 +141,22 @@
 if ( $request_port != 80 && $request_port != 443 ) {
 	$target_port	= ':' . $request_port;
 }
-$app_base_url	= $prtcl . $request_server_name . $target_port . $spider_base_uri;
-$app_nomal_url	= 'http://' . $request_server_name . $target_port . $spider_base_uri;
-$app_ssl_url	= 'https://' . $request_server_name . $target_port . $spider_base_uri;
+if( !defined('APPLICATION_BASE_URL') ) {
+	$app_base_url	= $prtcl . $request_server_name . $target_port . APPLICATION_BASE_URI;
+	define( 'APPLICATION_BASE_URL', $app_base_url );
+}
+if( !defined('APPLICATION_NML_URL') ) {
+	$app_nomal_url	= 'http://' . $request_server_name . $target_port . APPLICATION_BASE_URI;
+	define( 'APPLICATION_NML_URL', $app_nomal_url );
+}
+if( !defined('APPLICATION_SSL_URL') ) {
+	$app_ssl_url	= 'https://' . $request_server_name . $target_port . APPLICATION_BASE_URI;
+	define( 'APPLICATION_SSL_URL', $app_ssl_url );
+}
 
-define( 'APPLICATION_BASE_URL', $app_base_url );
-define( 'APPLICATION_NML_URL', $app_nomal_url );
-define( 'APPLICATION_SSL_URL', $app_ssl_url );
-$app_base_uri = $spider_base_uri;
-if ( !preg_match( '/\\/$/', $app_base_uri ) ) {
-	$app_base_uri .= '/';
-}
-define( 'APPLICATION_BASE_URI',  $app_base_uri );
-define( 'APPLICATION_BASE_PATH', dirname(__FILE__ ) );
 unset($app_base_url);
 unset($app_nomal_url);
 unset($app_ssl_url);
-unset($spider_base_uri);
 require_once( DIR_PATH_SPIDER_DATA . DIRECTORY_SEPARATOR . 'spider_main.inc.php' );
 
 ?>

Modified: current/spider/define.inc.php
===================================================================
--- current/spider/define.inc.php	2009-09-15 09:53:36 UTC (rev 82)
+++ current/spider/define.inc.php	2009-10-07 09:23:27 UTC (rev 83)
@@ -7,6 +7,25 @@
 define( 'SPIDER_USE_SPIDER_SESSION_ID',	false );
 
 /*
+ * アプリケーション設置位置設定
+ * 自動判別で正しく動作しない場合や自動判別しない場合に設定
+ */
+//define( 'APPLICATION_BASE_URL', '' );
+//define( 'APPLICATION_NML_URL', '' );
+//define( 'APPLICATION_SSL_URL', '' );
+//define( 'APPLICATION_BASE_URI', '' );
+
+/*
+ * リバースプロキシサーバーなど経由してアクセスする場合の強制位置設定
+ * ホスト名を設定した場合以下5項目は全て正しく記述する必要があります
+ */
+define( 'APPLICATION_PROXY_REV_HOST', '' );
+define( 'APPLICATION_PROXY_REV_BASE_URL', '' );
+define( 'APPLICATION_PROXY_REV_NML_URL', '' );
+define( 'APPLICATION_PROXY_REV_SSL_URL', '' );
+define( 'APPLICATION_PROXY_REV_BASE_URI', '' );
+
+/*
  * ユーザーエージェント分岐定義
  */
 // 分岐タイプ定義 分類ID=>分類名称
@@ -33,7 +52,16 @@
 	'/^DoCoMo\\/2/'						=> 'docomo2',
 	'/^DoCoMo\\/1/'						=> 'docomo',
 );
-
+// ユーザーエージェントごとに出力文字セットを指定する場合
+$GLOBALS['SPIDER_USER_AGENT_CLASS_OUTPUT_CHARSET']	= array(
+	'docomo'	=> 'SJIS-win',
+	'docomo2'	=> 'SJIS-win',
+	'au'		=> 'SJIS-win',
+	'softbank'	=> 'SJIS-win',
+	'mobile'	=> 'UTF-8',
+	'iphone3'	=> 'UTF-8',
+	'default'	=> 'UTF-8',
+);
 /*
  * 拡張設定
  */
@@ -47,7 +75,7 @@
 // テンプレート配置ディレクトリ名
 define ( 'DIR_NAME_TEMPLATES',		'templates' );
 // ウィジェットディレクトリ名
-define ( 'DIR_NAME_WIDGET',			'widgets' );
+define ( 'DIR_NAME_WIDGETS',			'widgets' );
 // データ保存ディレクトリ名
 define ( 'DIR_NAME_DATA',				'data' );
 // ワークディレクトリ名
@@ -72,7 +100,7 @@
 // テンプレートディレクトリパス
 define( 'DIR_PATH_TEMPLATES', DIR_PATH_SPIDER_DATA.DIRECTORY_SEPARATOR.DIR_NAME_TEMPLATES );
 // ウィジェットディレクトリパス
-define( 'DIR_PATH_WIDGETS',DIR_PATH_SPIDER_DATA.DIRECTORY_SEPARATOR.DIR_NAME_WIDGET);
+define( 'DIR_PATH_WIDGETS',DIR_PATH_SPIDER_DATA.DIRECTORY_SEPARATOR.DIR_NAME_WIDGETS);
 // データ保存ディレクトリ
 define( 'DIR_PATH_DATA', DIR_PATH_SPIDER_DATA . DIRECTORY_SEPARATOR . DIR_NAME_DATA );
 // ワークディレクトリパス

Modified: current/spider/lib/spider/BuildInformation.class.php
===================================================================
--- current/spider/lib/spider/BuildInformation.class.php	2009-09-15 09:53:36 UTC (rev 82)
+++ current/spider/lib/spider/BuildInformation.class.php	2009-10-07 09:23:27 UTC (rev 83)
@@ -104,6 +104,7 @@
 		}
 		$bin_file_path	= DIR_PATH_BIN
 			.DIRECTORY_SEPARATOR.$virtual_root
+			.DIRECTORY_SEPARATOR.str_replace('/','',str_replace(DIRECTORY_SEPARATOR,'',APPLICATION_BASE_URI))
 			.DIRECTORY_SEPARATOR.$this->getAgentPageUri();
 		if( !is_dir( dirname($bin_file_path) ) ) {
 			// 上位ディレクトリがないならディレクトリ階層を作成する

Modified: current/spider/lib/spider/Builder.class.php
===================================================================
--- current/spider/lib/spider/Builder.class.php	2009-09-15 09:53:36 UTC (rev 82)
+++ current/spider/lib/spider/Builder.class.php	2009-10-07 09:23:27 UTC (rev 83)
@@ -1,4 +1,9 @@
 <?php
+$GLOBALS['DEF_SPIDER_CHARSET_REPLACE_ENCODINGS']	= array(
+	'SJIS-win'	=> 'Shift_JIS',
+	'SJIS'		=> 'Shift_JIS',
+	
+);
 /**
  * 実行ファイルを作成します。
  * 
@@ -265,12 +270,34 @@
 		}
 
 		// 最終的にできた表示文字列をフラッシュする
-		$string .= "ob_start('".$build_information_object->output_handler."');\n";
-		$string .= "ob_implicit_flush( false );\n";
-		$string .= "mb_language('".$build_information_object->output_language."');\n";
+		$outputReplaceCode = $build_information_object->output_charset;
+		if( isset($GLOBALS['DEF_SPIDER_CHARSET_REPLACE_ENCODINGS'][$outputReplaceCode]) ) {
+			// 変換文字が定義されているなら変換文字を使う(SJIS等の場合Shift_JISにするなどの為)
+			$outputReplaceCode = $GLOBALS['DEF_SPIDER_CHARSET_REPLACE_ENCODINGS'][$outputReplaceCode];
+		}
+		$string .= 'if(\'UTF-8\'!=\''.$build_information_object->output_charset.'\'){'."\n";
+		$string .= '$needContentType = false;'."\n";
+		$string .= '$sentContentType = false;'."\n";
+		$string .= 'if( preg_match(\'/^4/\',phpversion()) > 0 || preg_match(\'/^3/\',phpversion()) > 0 ) {'."\n";
+		$string .= 'if( headers_sent() ) {'."\n";
+		$string .= '$sentContentType = true;'."\n";
+		$string .= '}'."\n";
+		$string .= '} else {'."\n";
+		$string .= '$headers = headers_list();'."\n";
+		$string .= 'foreach( $headers as $hk => $hv ) {'."\n";
+		$string .= 'if(preg_match(\'/^[cC][oO][nN][tT][eE][nN][tT]\\\\-[tT][yY][pP][eE]/\',$hv) > 0 ) {'."\n";
+		$string .= '$sentContentType = true;'."\n";
+		$string .= 'if(preg_match(\'/[uU][tT][fF]\\\\-8/\',$hv) > 0 ) {'."\n";
+		$string .= '$needContentType = true;'."\n";
+		$string .= '}'."\n";
+		$string .= '}'."\n";
+		$string .= '}'."\n";
+		$string .= '}'."\n";
+		$string .= 'if(!$sentContentType || $needContentType ){ header(\'Content-Type: text/html;charset='.$outputReplaceCode.';\'); }'."\n";
+		$string .= 'echo mb_convert_encoding($outstr,\''.$build_information_object->output_charset.'\',\'UTF-8\');'."\n";
+		$string .= '} else {'."\n";
 		$string .= 'echo $outstr;'."\n";
-		$string .= "mb_http_output('".$build_information_object->output_charset."');\n\n";
-		$string .= 'ob_flush();'."\n";
+		$string .= '}'."\n";
 		$string .= "}\n";
 
 		// 表示後実行コードを記述

Modified: current/spider/lib/spider/HttpRequest.class.php
===================================================================
--- current/spider/lib/spider/HttpRequest.class.php	2009-09-15 09:53:36 UTC (rev 82)
+++ current/spider/lib/spider/HttpRequest.class.php	2009-10-07 09:23:27 UTC (rev 83)
@@ -138,7 +138,21 @@
 	 * リダイレクト先を設定します
 	 */
 	function redirectTo($url) {
-		$this->redirect_url	= $url;
+		if( preg_match('/^\\//',$url) > 0 ) {
+			// リダイレクトURLがドキュメントルートからのパスで記載されている場合
+			if( defined('APPLICATION_PROXY_REV_HOST') && strlen(APPLICATION_PROXY_REV_HOST) > 0
+				&& ( APPLICATION_PROXY_REV_HOST == $_SERVER['HTTP_X_FORWARDED_HOST']
+					|| APPLICATION_PROXY_REV_HOST == $_SERVER['HTTP_X_FORWARDED_SERVER'] ) ) {
+				// リバースプロキシホスト名が設置されていてそこからのアクセスの場合
+				$url	= preg_replace('/\\/$/','',APPLICATION_PROXY_REV_BASE_URI).$url;
+			} else {
+				// リバースプロキシ経由でない場合
+				$this->redirect_url	= $url;
+			}
+		} else {
+			// 相対パスかプロトコルからの完全URLの場合
+			$this->redirect_url	= $url;
+		}
 	}
 	/**
 	 * セッション変数を設定します

Modified: current/spider/lib/spider/functions.inc.php
===================================================================
--- current/spider/lib/spider/functions.inc.php	2009-09-15 09:53:36 UTC (rev 82)
+++ current/spider/lib/spider/functions.inc.php	2009-10-07 09:23:27 UTC (rev 83)
@@ -268,6 +268,34 @@
 	}
 }
 /**
+ * 文字列長を比較して$aと$bが同じ場合は0を、$aが$bより長い場合は1を、$aが$bより短い場合は-1を返します。
+ */
+function spiderCmp( $a, $b ) {
+	$alen	= strlen($a);
+	$blen	= strlen($b);
+	if( $alen == $blen ) {
+		return 0;
+	} else if( $alen > $blen ) {
+		return 1;
+	} else {
+		return -1;
+	}
+}
+/**
+ * 文字列長を比較して$aと$bが同じ場合は0を、$aが$bより長い場合は-1を、$aが$bより短い場合は1を返します。
+ */
+function spiderCmpR( $a, $b ) {
+	$alen	= strlen($a);
+	$blen	= strlen($b);
+	if( $alen == $blen ) {
+		return 0;
+	} else if( $alen > $blen ) {
+		return -1;
+	} else {
+		return 1;
+	}
+}
+/**
  * CSVデータラインを配列にして返します
  */
 function convert_csv_columns( $strings ) {

Modified: current/spider/lib/spider/module/AutoEncode.class.php
===================================================================
--- current/spider/lib/spider/module/AutoEncode.class.php	2009-09-15 09:53:36 UTC (rev 82)
+++ current/spider/lib/spider/module/AutoEncode.class.php	2009-10-07 09:23:27 UTC (rev 83)
@@ -15,31 +15,33 @@
 	function spider_module_AutoEncode() {
 	}
 	function execute( & $request ) {
-		$strings		= implode('',$_POST).implode('',$_GET);
-		$input_charset	= mb_detect_encoding($strings,'auto');
-		if( $input_charset != 'UTF-8' ) {
+		$vars			= $_POST;
+		$strings		= print_r($vars,true);
+		$vars			= $_GET;
+		$strings		.= print_r($vars,true);
+		$vars			= null;
+		$inputCharset	= mb_detect_encoding($strings,'auto');
+		if( $inputCharset != 'UTF-8' ) {
 			// POSTパラメータ
-			foreach( $_POST as $key => $val ) {
-				if ( is_array($val) ) {
-					if( preg_match('/^[aA][sS][cC][iI][iI]$/',mb_detect_encoding($val,'auto')) == 0 ) {
-						$_POST[$key]	= mb_convert_variables('UTF-8',$input_charset,$val);
-					}
-				} else {
-					if( preg_match('/^[aA][sS][cC][iI][iI]$/',mb_detect_encoding($val,'auto')) == 0 ) {
-						$_POST[$key]	= mb_convert_encoding($val,'UTF-8',$input_charset);
-					}
-				}
-			}
+			$this->encodeHash( $_POST,'UTF-8', $inputCharset );
 			// GETパラメータ
-			foreach( $_GET as $key => $val ) {
-				if ( is_array($val) ) {
-					if( preg_match('/^[aA][sS][cC][iI][iI]$/',mb_detect_encoding($val,'auto')) == 0 ) {
-						$_GET[$key]	= mb_convert_variables('UTF-8',$input_charset,$val);
-					}
+			$this->encodeHash( $_GET,'UTF-8', $inputCharset );
+		}
+	}
+	/**
+	 * 多次元配列を指定文字セットにエンコードします
+	 */
+	function encodeHash( & $hash,$toChar='UTF-8', $fromChar ) {
+		if( is_array($hash) ) {
+			foreach( $hash as $key => $val ) {
+				$encKey	= mb_convert_encoding( $key, $toChar, $fromChar );
+				if( is_array($val) ) {
+					$this->encodeHash( $hash[$key],$toChar,$fromChar );
+					$hash[$encKey]	= $hash[$key];
 				} else {
-					if( preg_match('/^[aA][sS][cC][iI][iI]$/',mb_detect_encoding($val,'auto')) == 0 ) {
-						$_GET[$key]	= mb_convert_encoding($val,'UTF-8',$input_charset);
-					}
+					$val			= mb_convert_encoding( $val, $toChar, $fromChar );
+					$hash[$key]		= $val;
+					$hash[$encKey]	= $val;
 				}
 			}
 		}

Modified: current/spider/lib/spider/module/AutoFormat.class.php
===================================================================
--- current/spider/lib/spider/module/AutoFormat.class.php	2009-09-15 09:53:36 UTC (rev 82)
+++ current/spider/lib/spider/module/AutoFormat.class.php	2009-10-07 09:23:27 UTC (rev 83)
@@ -20,38 +20,20 @@
 	}
 	function execute( & $request ) {
 		// POSTパラメータ
-		foreach( $_POST as $key => $val ) {
-			if ( is_array($val) ) {
-				// パラメータが配列の場合、各値を変換する
-				$value_array = array();
-				foreach( $val as $value ) {
-					$value	= mb_convert_kana($value,'KVas');
-					array_push($value_array,$value);
-				}
-				$_POST[$key]	= $value_array;
-			} else {
-				if ( strlen(trim($val))>0 ) {
-					$_POST[$key]	= mb_convert_kana($val,'KVas');
-				} else {
-					$_POST[$key]	= '';
-				}
-			}
-		}
+		$this->convertKana( $_POST,'KVas','UTF-8' );
 		// GETパラメータ
-		foreach( $_GET as $key => $val ) {
-			if ( is_array($val) ) {
-				// パラメータが配列の場合、各値を変換する
-				$value_array = array();
-				foreach( $val as $value ) {
-					$value	= mb_convert_kana($value,'KVas');
-					array_push($value_array,$value);
-				}
-				$_GET[$key]	= $value_array;
-			} else {
-				if ( strlen(trim($val))>0 ) {
-					$_GET[$key]	= mb_convert_kana($val,'KVas');
+		$this->convertKana( $_GET,'KVas','UTF-8' );
+	}
+	/**
+	 * 多次元配列の値をフォーマットにエンコードします
+	 */
+	function convertKana( & $hash, $format='KVas', $toChar='UTF-8') {
+		if( is_array($hash) ) {
+			foreach( $hash as $key => $val ) {
+				if( is_array($val) ) {
+					$this->convertKana( $hash[$key] );
 				} else {
-					$_GET[$key]	= '';
+					$hash[$key]	= mb_convert_kana($val,$format,$toChar);
 				}
 			}
 		}

Modified: current/spider/lib/spider/tags/Charset.class.php
===================================================================
--- current/spider/lib/spider/tags/Charset.class.php	2009-09-15 09:53:36 UTC (rev 82)
+++ current/spider/lib/spider/tags/Charset.class.php	2009-10-07 09:23:27 UTC (rev 83)
@@ -37,39 +37,45 @@
 	 */
 	function convert( &$result_strings, &$build_information ){
 		// charsetタグ内文字列
-		$charset_strings	= '';
+		$charsetStrings	= '';
 		if ( preg_match_all( '/\\{charset\\:[^\\}]*?\\}/'
 				, $result_strings
 				, $output_array
 				, PREG_PATTERN_ORDER ) > 0 ) {
+			// charsetタグが明示的に指定されている場合、最後に書かれたものを適用
 			foreach ( $output_array as $output ) {
 				foreach ( $output as $target ) {
-					$charset_strings	= preg_replace( '/\\{charset\\:/','', $target );
-					$charset_strings	= preg_replace( '/\\}/','', $charset_strings );
+					$charsetStrings	= preg_replace( '/\\{charset\\:/','', $target );
+					$charsetStrings	= preg_replace( '/\\}/','', $charsetStrings );
 					// 空行にならないよう前後が改行も削除
 					$result_strings 	= str_replace( "\n".$target."\n", "", $result_strings );
 					$result_strings 	= str_replace( $target, "", $result_strings );
-					$charset_strings	= trim($charset_strings);
+					$charsetStrings	= trim($charsetStrings);
 				}
 			}
 		} else {
-			if ( $build_information->agent_class == 'default' ){
-				$charset_strings	= 'UTF-8';
+			// charsetタグがない場合はユーザーエージェント指定の文字コードがあるなら適用
+			if( isset($GLOBALS['SPIDER_USER_AGENT_CLASS_OUTPUT_CHARSET'])
+				&& isset($GLOBALS['SPIDER_USER_AGENT_CLASS_OUTPUT_CHARSET'][$build_information->agent_class])
+				&& strlen($GLOBALS['SPIDER_USER_AGENT_CLASS_OUTPUT_CHARSET'][$build_information->agent_class]) > 0 ) {
+				// 対象ユーザーエージェント分類の文字コードが指定されているなら適用
+				$charsetStrings	= $GLOBALS['SPIDER_USER_AGENT_CLASS_OUTPUT_CHARSET'][$build_information->agent_class];
 			} else {
-				$charset_strings	= 'SJIS-win';
+				// 定義がないなら常にUTF-8で出力する
+				$charsetStrings	= 'UTF-8';
 			}
 		}
 
-		$charset_array	= explode( " ", $charset_strings );
+		$charsetArray	= explode( ' ', $charsetStrings );
 		// 最初の項は必ず文字コード
-		$charset			= trim(array_shift($charset_array));
+		$outputCharset			= trim(array_shift($charsetArray));
 		$convert_kana		= '';
 		$internal_charset	= 'UTF-8';
 		$output_handler		= 'mb_output_handler';
 		$detect_order		= 'UTF-8,EUC-JP,SJIS,SJIS-win,JIS,UTF-7';
 		$language			= 'japanese';
 		// 残りの項の解析
-		foreach( $charset_array as $str ) {
+		foreach( $charsetArray as $str ) {
 			if( strlen(trim($str)) > 0 ) {
 				list( $key, $val )	= explode('=',trim($str));
 				$key	= trim($key);
@@ -90,28 +96,33 @@
 				}
 			}
 		}
-		// 互換の為creatorにも設定
-		$build_information->output_charset		= $charset;
+		// 互換の為buil_informationにも設定
+		$build_information->output_charset		= $outputCharset;
 		$build_information->convert_kana		= $convert_kana;
 		$build_information->output_handler		= $output_handler;
 		$build_information->internal_charset	= $internal_charset;
 		$build_information->detect_order		= $detect_order;
 		$build_information->output_language		= $language;
 
-		// 出力文字コード変換
-		$out_code = "UTF-8";
-		if ( 'SJIS' == $charset
-			|| 'SJIS-win' == $charset ) {
-			$out_code = 'Shift_JIS';
-		} else if ( 'EUC-JP' == $charset ) {
-			$out_code = 'EUC-JP';
+		// 出力HTML内の文字コード指定変換
+		$htmlReplaceCode = $outputCharset;
+		if( isset($GLOBALS['DEF_SPIDER_CHARSET_REPLACE_ENCODINGS'][$outputCharset]) ) {
+			// 変換文字が定義されているなら変換文字を使う(SJIS等の場合Shift_JISにするなどの為)
+			$htmlReplaceCode = $GLOBALS['DEF_SPIDER_CHARSET_REPLACE_ENCODINGS'][$outputCharset];
 		}
-		$result_strings = str_replace(
-			"content=\"text/html; charset=UTF-8\""
-			, 'content="text/html; charset=' . $out_code . '"'
-			, $result_strings );
+		// メタタグのcharsetを変更
+		$result_strings	= preg_replace(
+			'/(<[mM][eE][tT][aA][^>]*\\s[cC][oO][nN][tT][eE][nN][tT]\\=[\'"][^\'"]*[cC][hH][aA][rR][sS][eE][tT]\\=)([^\'"\\;]+)([^\'"]*[\'"][^>]*>)/',
+			'$1'.$htmlReplaceCode.'$3',
+			$result_strings
+		);
+		// XML宣言もあれば変更
+		$result_strings	= preg_replace(
+			'/(<\\?xml[^>]*\\s[eE][nN][cC][oO][dD][iI][nN][gG]\\=[\'"])([^\'"]*)([^\'"]*[\'"][^>]*>)/',
+			'$1'.$htmlReplaceCode.'$3',
+			$result_strings
+		);
 
-
 		// 前処理の文字コードフラッシュコードを追加
 		$process_code = "ob_start('".$output_handler."');\n";
 		$process_code .= "ob_implicit_flush( false );\n";
@@ -120,7 +131,9 @@
 		$process_code .= "mb_internal_encoding('".$internal_charset."');\n";
 		// 2009-07-01 DoCoMo XHTML対応 暫定 PHPheaderでセットしたContent-Typeの文字セットでob_get_cleanの取得文字コードを勝手に操作する為UTF-8で指定...
 		if( preg_match('/\\<\\!DOCTYPE\\shtml\\sPUBLIC\\s\\"\\-\\/\\/i\\-mode group/',$result_strings) > 0 ) {
-			$process_code .= '$request->setResponseHeader(\'Content-Type\',\'application/xhtml+xml;charset=UTF-8\');'."\n";
+			$process_code .= 'if(preg_match(\'/^DoCoMo/\',$_SERVER[\'HTTP_USER_AGENT\']) > 0 ) {'."\n";
+			$process_code .= '$request->setResponseHeader(\'Content-Type\',\'application/xhtml+xml;charset='.$htmlReplaceCode.'\');'."\n";
+			$process_code .= '}'."\n";
 		}
 		
 		if( !isset($build_information->preview_process_hash)
@@ -147,16 +160,8 @@
 			array_push( $build_information->convert_view_process_hash[$this->priority], $process_code );
 		} else if ( 'docomo' == $build_information->agent_class || 'docomo2' == $build_information->agent_class || 'softbank' == $build_information->agent_class || 'au' == $build_information->agent_class ) {
 			$process_code = '$outstr = mb_convert_kana( $outstr, "kna" );'."\n";
-			if( 'docomo2' == $build_information->agent_class ) {
-				// ユーザーエージェントがdocomo2でボディがxml宣言で始まっているならヘッダー追加
-				$process_code .= 'if( preg_match(\'/\\\\<\\\\?xml/\',$outstr) > 0 ){ '
-					. 'header(\'Content-Type: application/xhtml+xml;charset=Shift_JIS\'); echo "\n";'."\n"
-					. ' }'."\n"
-				;
-			}
 			array_push( $build_information->convert_view_process_hash[$this->priority], $process_code );
 		}
-		
 	}
 }
 ?>
\ No newline at end of file

Modified: current/spider/lib/spider/tags/UseSession.class.php
===================================================================
--- current/spider/lib/spider/tags/UseSession.class.php	2009-09-15 09:53:36 UTC (rev 82)
+++ current/spider/lib/spider/tags/UseSession.class.php	2009-10-07 09:23:27 UTC (rev 83)
@@ -41,6 +41,9 @@
 				. "die( '".$GLOBALS['spider.messages']['spider.tags.usesession.cantstart']."' );\n}\n"
 				. "}else{\n"
 				. "session_start();\n}"
+				. "\n"
+				. '$GLOBALS[\'request_object\']->setAttribute( \'spider.session_name\', session_name(), SPIDER_SESSION_SCOPE_GLOBAL );'. "\n"
+				. '$GLOBALS[\'request_object\']->setAttribute( \'spider.session_id\', session_id(), SPIDER_SESSION_SCOPE_GLOBAL );'. "\n"
 			;
 			if( !isset($build_information->preview_process_hash)
 				|| !is_array($build_information->preview_process_hash) ){

Modified: current/spider/lib/util/ValidateFunctions.class.php
===================================================================
--- current/spider/lib/util/ValidateFunctions.class.php	2009-09-15 09:53:36 UTC (rev 82)
+++ current/spider/lib/util/ValidateFunctions.class.php	2009-10-07 09:23:27 UTC (rev 83)
@@ -87,18 +87,20 @@
 		} else if( $min < 0 || $min > 59 ) {
 			return false;
 		}
-		if( $permit_decimal_sec ) {
-			if( preg_match('/^[0-9]{1,2}(|\\.[0-9]+)$/',$sec) == 0 ) {
-				return false;
-			} else if( $sec < 0 || $sec >= 60 ) {
-				return false;
+		if( !is_null($sec) && strlen($sec) > 0 ) {
+			if( $permit_decimal_sec ) {
+				if( preg_match('/^[0-9]{1,2}(|\\.[0-9]+)$/',$sec) == 0 ) {
+					return false;
+				} else if( $sec < 0 || $sec >= 60 ) {
+					return false;
+				}
+			} else {
+				if( preg_match('/^[0-9]{1,2}$/',$sec) == 0 ) {
+					return false;
+				} else if( $sec < 0 || $sec >= 60 ) {
+					return false;
+				}
 			}
-		} else {
-			if( preg_match('/^[0-9]{1,2}$/',$sec) == 0 ) {
-				return false;
-			} else if( $sec < 0 || $sec >= 60 ) {
-				return false;
-			}
 		}
 		return true;
 	}
@@ -110,7 +112,7 @@
 	 */
 	function isAvailableTimeFormat( $time_string ) {
 		$elements	= explode(':',$time_string);
-		if( count($elements) == 3 ) {
+		if( count($elements) == 2 || count($elements) == 3 ) {
 			$hour	= array_shift($elements);
 			$min	= array_shift($elements);
 			$sec	= array_shift($elements);

Modified: current/spider/spider_command.inc.php
===================================================================
--- current/spider/spider_command.inc.php	2009-09-15 09:53:36 UTC (rev 82)
+++ current/spider/spider_command.inc.php	2009-10-07 09:23:27 UTC (rev 83)
@@ -19,8 +19,8 @@
 
 /* グローバル関数ファイル	*/
 require_once( DIR_PATH_LIB
-	. DIRECTORY_SEPARATOR . "spider" 
-	. DIRECTORY_SEPARATOR . "functions.inc.php" );
+	.DIRECTORY_SEPARATOR.'spider' 
+	.DIRECTORY_SEPARATOR.'functions.inc.php' );
 
 /* パーミッションの確認	*/
 $errors	= spider_is_avairable_permittion();
@@ -33,11 +33,24 @@
 	die;
 }
 
+// 出力クラス
 require_once( DIR_PATH_LIB
-	. DIRECTORY_SEPARATOR . "spider"
-	. DIRECTORY_SEPARATOR . "HttpRequest.class.php" );
+	.DIRECTORY_SEPARATOR.'spider' 
+	.DIRECTORY_SEPARATOR.'HttpOutput.class.php' );
+$GLOBALS['output']		= new spider_HttpOutput();
+// リクエストクラス
+require_once( DIR_PATH_LIB
+	.DIRECTORY_SEPARATOR.'spider'
+	.DIRECTORY_SEPARATOR.'HttpRequest.class.php' );
 $GLOBALS['request']	= new spider_HttpRequest();
+/* コントローラークラス	*/
+require_once( DIR_PATH_LIB
+	.DIRECTORY_SEPARATOR.'spider' 
+	.DIRECTORY_SEPARATOR.'Controller.class.php' );
+$GLOBALS['controller']	= new spider_Controller( $GLOBALS['request'], $GLOBALS['output'] );
 
+
+// 出力文字コードの確認
 mb_language('japanese');
 mb_internal_encoding('UTF-8');
 ob_start('mb_output_handler');
@@ -48,6 +61,23 @@
 } else if( preg_match('/[uU][tT][fF]\\-8/', $_ENV['LANG'] ) > 0 ) {
 	mb_http_output('UTF-8');
 }
+// phpのインストール種別を確認
+$is_cli		= false;
+if( preg_match('/[cC][lL][iI]/',php_sapi_name()) > 0 ) {
+	$is_cli	= true;
+} else if( preg_match('/[hH][aA][nN][dD][lL][eE][rR]/',php_sapi_name()) > 0 ) {
+	header('Content-Type: text/plain; charset=UTF-8;');
+	echo "Core Error!!\n";
+	echo "this process called by php spi version.\n";
+	echo "please call on commandline.\n";
+	exit(0);
+} else {
+	echo "Core Error!!\n";
+	echo "this process called by php unknown version.\n";
+	echo "please call on commandline.\n";
+	exit(0);
+}
+
 ob_implicit_flush( true );
 if ( file_exists( dirname( __FILE__ ).DIRECTORY_SEPARATOR.'unique_setting.inc.php' ) ) {
 	include_once( dirname( __FILE__ ).DIRECTORY_SEPARATOR.'unique_setting.inc.php' );

Modified: current/spider/spider_main.inc.php
===================================================================
--- current/spider/spider_main.inc.php	2009-09-15 09:53:36 UTC (rev 82)
+++ current/spider/spider_main.inc.php	2009-10-07 09:23:27 UTC (rev 83)
@@ -17,35 +17,36 @@
 }
 
 // アクションファイルパスの取得
-$action_file_path = $_SERVER["SCRIPT_FILENAME"];
-if ( str_replace( "\\", "/", __FILE__ )
-	== str_replace( "\\", "/", $action_file_path ) ) {
+$action_file_path = $_SERVER['SCRIPT_FILENAME'];
+if ( str_replace( '\\', '/', __FILE__ )
+	== str_replace( '\\', '/', $action_file_path ) ) {
 	// 本ファイル直接呼出しなら実行中止
 	header( 'Content-type: text/plain;charset=UTF-8' );
-	die( "Core Error : コントロールファイルです。" );
+	die( 'Core Error : コントロールファイルです。' );
 }
 
 /* リクエストコンテナオブジェクト	*/
 require_once( DIR_PATH_LIB
-	. DIRECTORY_SEPARATOR . "spider"
-	. DIRECTORY_SEPARATOR . "HttpRequest.class.php" );
-$GLOBALS['request_object']	= new spider_HttpRequest();
+	.DIRECTORY_SEPARATOR.'spider'
+	.DIRECTORY_SEPARATOR.'HttpRequest.class.php' );
+$GLOBALS['request']			= new spider_HttpRequest();
+$GLOBALS['request_object']	= & $GLOBALS['request'];
 
 /* 出力クラス	*/
 require_once( DIR_PATH_LIB
-	. DIRECTORY_SEPARATOR . "spider" 
-	. DIRECTORY_SEPARATOR . "HttpOutput.class.php" );
+	.DIRECTORY_SEPARATOR.'spider' 
+	.DIRECTORY_SEPARATOR.'HttpOutput.class.php' );
 $GLOBALS['output_object']		= new spider_HttpOutput();
 
 /* コントローラークラス	*/
 require_once( DIR_PATH_LIB
-	. DIRECTORY_SEPARATOR . "spider" 
-	. DIRECTORY_SEPARATOR . "Controller.class.php" );
+	.DIRECTORY_SEPARATOR.'spider' 
+	.DIRECTORY_SEPARATOR.'Controller.class.php' );
 
 /* グローバル関数ファイル	*/
 require_once( DIR_PATH_LIB
-	. DIRECTORY_SEPARATOR . "spider" 
-	. DIRECTORY_SEPARATOR . "functions.inc.php" );
+	.DIRECTORY_SEPARATOR.'spider' 
+	.DIRECTORY_SEPARATOR.'functions.inc.php' );
 
 /* パーミッションの確認	*/
 $errors	= spider_is_avairable_permittion();
@@ -59,30 +60,35 @@
 }
 
 // POSTとGETとCOOKIEの値をオブジェクトに設定する
+$GLOBALS['request_object']->setAttribute( 'postparams', $_POST );
 foreach( $_POST as $key => $value ) {
 	$GLOBALS['request_object']->setAttribute( 'post.'.$key, $value );
 }
+$GLOBALS['request_object']->setAttribute( 'getparams', $_GET );
 foreach( $_GET as $key => $value ) {
 	$GLOBALS['request_object']->setAttribute( 'get.'.$key, $value );
 }
 foreach( $_COOKIE as $key => $value ) {
 	$GLOBALS['request_object']->setAttribute( 'cookie.'.$key, $value );
 }
-// sessionのnameとidをリクエストに登録する
-$GLOBALS['request_object']->setAttribute( 'spider.session_name', session_name() );
-$GLOBALS['request_object']->setAttribute( 'spider.session_id', session_id() );
+// session_idが正しく取れないのでUseSessionタグ内に移動
+//// sessionのnameとidをリクエストに登録する
+//$GLOBALS['request_object']->setAttribute( 'spider.session_name', session_name(), SPIDER_SESSION_SCOPE_GLOBAL );
+//$GLOBALS['request_object']->setAttribute( 'spider.session_id', session_id(), SPIDER_SESSION_SCOPE_GLOBAL );
 
 // spiderの固定値をリクエスト属性に設定する
 $base_url = APPLICATION_BASE_URL;
-$GLOBALS['request_object']->setAttribute( 'spider.base_url', $base_url );
+$GLOBALS['request_object']->setAttribute( 'spider.base_url', $base_url, SPIDER_SESSION_SCOPE_GLOBAL );
 $nomal_url = APPLICATION_NML_URL;
-$GLOBALS['request_object']->setAttribute( 'spider.nomal_url', $nomal_url );
+$GLOBALS['request_object']->setAttribute( 'spider.nomal_url', $nomal_url, SPIDER_SESSION_SCOPE_GLOBAL );
 $ssl_url = APPLICATION_SSL_URL;
-$GLOBALS['request_object']->setAttribute( 'spider.ssl_url', $ssl_url );
+$GLOBALS['request_object']->setAttribute( 'spider.ssl_url', $ssl_url, SPIDER_SESSION_SCOPE_GLOBAL );
 $base_uri = APPLICATION_BASE_URI;
-$GLOBALS['request_object']->setAttribute( 'spider.base_uri', $base_uri );
+$GLOBALS['request_object']->setAttribute( 'spider.base_uri', $base_uri, SPIDER_SESSION_SCOPE_GLOBAL );
 $base_path = APPLICATION_BASE_PATH;
-$GLOBALS['request_object']->setAttribute( 'spider.base_path', $base_path );
+$GLOBALS['request_object']->setAttribute( 'spider.base_path', $base_path, SPIDER_SESSION_SCOPE_GLOBAL );
+$access_uri	= preg_replace('/^'.str_replace('.','\\.',str_replace('/','\\/',$base_uri)).'/','/',$_SERVER['REQUEST_URI']);
+$GLOBALS['request_object']->setAttribute( 'spider.access_uri', $access_uri, SPIDER_SESSION_SCOPE_GLOBAL );
 
 // コントローラー
 $GLOBALS['controller']	= new spider_Controller( $GLOBALS['request_object'], $GLOBALS['output_object'] );

Modified: current/spider/unique_setting.inc.php
===================================================================
--- current/spider/unique_setting.inc.php	2009-09-15 09:53:36 UTC (rev 82)
+++ current/spider/unique_setting.inc.php	2009-10-07 09:23:27 UTC (rev 83)
@@ -13,6 +13,20 @@
  */
 $GLOBALS['SPIDER_PREVIOUS_SCRIPT_FILE_PATH_ARRAY']	= array();
 
+// PHP内部文字セット(基本的に変更しないこと)
+define ( 'CHARSET_INTERNAL', 	'UTF-8' );
+
+/** 地域ハッシュ	*/
+$GLOBALS['AREA_HASH']			= array(
+	1	=> '北海道・東北',
+	2	=> '関東',
+	3	=> '甲信越・北陸',
+	4	=> '東海',
+	5	=> '関西',
+	6	=> '中国',
+	7	=> '四国',
+	8	=> '九州',
+);
 /** 都道府県ハッシュ	*/
 $GLOBALS['PREFECTURE_HASH']	= array(
 	1=>'北海道',
@@ -64,6 +78,64 @@
 	47=>'沖縄県',
 	51=>'海外',
 );
+/** 都道府県エリアハッシュ	*/
+$GLOBALS['PREFECTURE_AREA_HASH']	= array(
+	1=>1,
+	2=>1,
+	3=>1,
+	4=>1,
+	5=>1,
+	6=>1,
+	7=>1,
+	8=>2,
+	9=>2,
+	10=>2,
+	11=>2,
+	12=>2,
+	13=>2,
+	14=>2,
+	15=>3,
+	16=>3,
+	17=>3,
+	18=>3,
+	19=>3,
+	20=>3,
+	21=>4,
+	22=>4,
+	23=>4,
+	24=>4,
+	25=>5,
+	26=>5,
+	27=>5,
+	28=>5,
+	29=>5,
+	30=>5,
+	31=>6,
+	32=>6,
+	33=>6,
+	34=>6,
+	35=>6,
+	36=>7,
+	37=>7,
+	38=>7,
+	39=>7,
+	40=>8,
+	41=>8,
+	42=>8,
+	43=>8,
+	44=>8,
+	45=>8,
+	46=>8,
+	47=>8,
+);
+/** エリア都道府県ハッシュ	*/
+$GLOBALS['AREA_PREFECTURE_HASH']	= array();
+foreach( $GLOBALS['PREFECTURE_AREA_HASH'] as $key => $value ) {
+	if( !is_array($GLOBALS['AREA_PREFECTURE_HASH'][$value])) {
+		$GLOBALS['AREA_PREFECTURE_HASH'][$value]	= array();
+	}
+	array_push($GLOBALS['AREA_PREFECTURE_HASH'][$value],$key);
+}
 /** 携帯メールアドレスドメイン名	*/
 $GLOBALS['MOBILE_MAIL_DOMAIN_ARRAY'] = array(
 	'docomo.ne.jp'



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