[Frameworkspider-svn] spider-commit [73]

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2009年 6月 13日 (土) 15:48:45 JST


Revision: 73
          http://svn.sourceforge.jp/view?root=frameworkspider&view=rev&rev=73
Author:   m_nakashima
Date:     2009-06-13 15:48:45 +0900 (Sat, 13 Jun 2009)

Log Message:
-----------


Modified Paths:
--------------
    current/DATA/lib/spider/HttpOutput.class.php
    current/DATA/lib/spider/HttpRequest.class.php
    current/DATA/lib/util/CharUtility.class.php
    current/DATA/lib/util/Mail.class.php
    current/DATA/lib/util/ValidateFunctions.class.php
    current/DATA/lib/util/mail/SendMail.class.php

Added Paths:
-----------
    current/DATA/lib/util/Date.class.php


-------------- next part --------------
Modified: current/DATA/lib/spider/HttpOutput.class.php
===================================================================
--- current/DATA/lib/spider/HttpOutput.class.php	2009-05-09 03:42:30 UTC (rev 72)
+++ current/DATA/lib/spider/HttpOutput.class.php	2009-06-13 06:48:45 UTC (rev 73)
@@ -35,6 +35,7 @@
 		
 		// ユーザーエージェント分類をリクエストにセット
 		$request->setAttribute('spider.access_agent_class',$build_information_object->agent_class);
+		$request->agentClass	= $build_information_object->agent_class;
 		
 		// ビルドファイルパスを取得
 		$build_file_path	= $build_information_object->getAgentPageBuildFilePath();

Modified: current/DATA/lib/spider/HttpRequest.class.php
===================================================================
--- current/DATA/lib/spider/HttpRequest.class.php	2009-05-09 03:42:30 UTC (rev 72)
+++ current/DATA/lib/spider/HttpRequest.class.php	2009-06-13 06:48:45 UTC (rev 73)
@@ -30,7 +30,8 @@
 	var $redirect_url		= null;
 	/** Attribute Prefix	*/
 	var $attribute_prefix	= null;
-
+	/** Access User Agent Class	*/
+	var $agentClass			= null;
 	/**
 	 * コンストラクタ
 	 */
@@ -155,7 +156,12 @@
 		} else {
 			$key	= $scope.'/'.$key;
 		}
-		$_SESSION[$key]	= serialize( $value );
+		$spiderSession	= new spider_Session();
+		if( isset($_SESSION) && isset($_SESSION['spider_session_object']) ) {
+			$spiderSession	= unserialize($_SESSION['spider_session_object']);
+		}
+		$spiderSession->setValue($key,$value);
+		$_SESSION['spider_session_object']	= serialize($spiderSession);
 	}
 	/**
 	 * セッション変数を取得します
@@ -163,20 +169,23 @@
 	 */
 	function getSession( $key ) {
 		$this->optimizeSession();
+		$spiderSession	= new spider_Session();
+		if( isset($_SESSION) && isset($_SESSION['spider_session_object']) ) {
+			$spiderSession	= unserialize($_SESSION['spider_session_object']);
+		}
 		$value			= null;
 		$current_scope	= dirname( $_SERVER['PHP_SELF'] );
 		while( strlen($current_scope) > 1 ) {
 			$target_key		= $current_scope.'/'.$key;
-			if( isset( $_SESSION ) && isset($_SESSION[$target_key]) ) {
-				return unserialize($_SESSION[$target_key]);
+			if( false !== $spiderSession->getValue($target_key) ) {
+				return $spiderSession->getValue($target_key);
 			}
 			$current_scope	= dirname( $current_scope );
 		}
 		$target_key	= $this->_getGlobalSessionKey( $key );
-		if( isset( $_SESSION ) && isset($_SESSION[$target_key]) ) {
-			return unserialize($_SESSION[$target_key]);
+		if( false !== $spiderSession->getValue($target_key) ) {
+			return $spiderSession->getValue($target_key);
 		}
-		
 		return null;
 	}
 	/**
@@ -185,16 +194,21 @@
 	 */
 	function existsSession( $key ) {
 		$this->optimizeSession();
+		$spiderSession	= new spider_Session();
+		if( isset($_SESSION) && isset($_SESSION['spider_session_object']) ) {
+			$spiderSession	= unserialize($_SESSION['spider_session_object']);
+		}
+		$value			= null;
 		$current_scope	= dirname( $_SERVER['PHP_SELF'] );
 		while( strlen($current_scope) > 1 ) {
 			$target_key		= $current_scope.'/'.$key;
-			if( isset( $_SESSION ) && isset($_SESSION[$target_key]) ) {
+			if( false !== $spiderSession->getValue($target_key) ) {
 				return true;
 			}
 			$current_scope	= dirname( $current_scope );
 		}
 		$target_key	= $this->_getGlobalSessionKey( $key );
-		if( isset( $_SESSION ) && isset($_SESSION[$target_key]) ) {
+		if( false !== $spiderSession->getValue($target_key) ) {
 			return true;
 		}
 		return false;
@@ -204,6 +218,10 @@
 	 */
 	function removeSession( $key, $scope=SPIDER_SESSION_SCOPE_AUTO ) {
 		$this->optimizeSession();
+		$spiderSession	= new spider_Session();
+		if( isset($_SESSION) && isset($_SESSION['spider_session_object']) ) {
+			$spiderSession	= unserialize($_SESSION['spider_session_object']);
+		}
 		if( $scope == SPIDER_SESSION_SCOPE_AUTO ) {
 			$scope	= dirname($_SERVER['PHP_SELF']);
 		}
@@ -212,22 +230,26 @@
 		} else {
 			$key	= $scope.'/'.$key;
 		}
-		if(isset($_SESSION[$key])) {
-			unset($_SESSION[$key]);
-		}
+		$spiderSession->removeValue($key);
+		$_SESSION['spider_session_object']	= serialize($spiderSession);
 	}
 	/**
 	 * セッション登録済み情報を最適化します
 	 */
 	function optimizeSession() {
 		if( isset( $_SESSION ) && is_array( $_SESSION ) ) {
+			$spiderSession	= new spider_Session();
+			if( isset($_SESSION) && isset($_SESSION['spider_session_object']) ) {
+				$spiderSession	= unserialize($_SESSION['spider_session_object']);
+			}
 			$current_scope	= dirname( $_SERVER['PHP_SELF'] );
 			foreach( $_SESSION as $key => $value ) {
 				if( strlen($key) > 0 && preg_match('/^spider\\_GLOBAL\\./',$key) == 0
 					&& preg_match('/^'.util_CharUtility::escape_regx_str($current_scope).'/',$key) == 0 ) {
-					unset( $_SESSION[$key] );	
+					$spiderSession->removeValue($key);
 				}
 			}
+			$_SESSION['spider_session_object']	= serialize($spiderSession);
 		}
 	}
 	/**
@@ -484,4 +506,27 @@
 		}
 	}
 }
+/**
+ * spider_HttpRequestクラスオブジェクトを経由したセッション保存用の
+ * 情報コンテナクラス
+ */
+class spider_Session {
+	var $valueHash	= array();
+	function spider_Session(){
+		$this->valueHash	= array();
+	}
+	function setValue($key,$value) {
+		$this->valueHash[$key]	= $value;
+	}
+	function getValue($key) {
+		if( isset($this->valueHash[$key]) ) {
+			return $this->valueHash[$key];
+		} else {
+			return false;
+		}
+	}
+	function removeValue($key) {
+		unset($this->valueHash[$key]);
+	}
+}
 ?>

Modified: current/DATA/lib/util/CharUtility.class.php
===================================================================
--- current/DATA/lib/util/CharUtility.class.php	2009-05-09 03:42:30 UTC (rev 72)
+++ current/DATA/lib/util/CharUtility.class.php	2009-06-13 06:48:45 UTC (rev 73)
@@ -116,6 +116,125 @@
 		return $ret_str;
 	}
 	/**
+	 * 指定長のランダムアルファベットを生成して返します
+	 */
+	function createRundomAlphabet( $length, $type=0 ) {
+		$start	= 65;
+		$end	= 90;
+		if( 1==$type ) {
+			$start	= 97;
+			$end	= 122;
+		}
+		return util_CharUtility::createRundomAscii( $length, $start, $end );
+	}
+	/**
+	 * 指定範囲のASCII文字列からランダム文字列を生成します
+	 */
+	function createRundomAscii( $length=8, $start=33, $end=126 ) {
+		$string	= '';
+		for( $i=0; $i<$length; $i++ ) {
+			$num	= rand( $start, $end );
+			$string	.= pack('C*',$num);
+		}
+		return $string;
+	}
+	/**
+	 * 文字列を数字部分とアルファベット部分ごとの要素に分けて配列で戻します。
+	 */
+	function explodeAN( $string, $alphSep=0 ) {
+		$elm		= '';
+		$elmArray	= array();
+		$prevChar	= '';
+		for( $pos=0; $pos<strlen($string); $pos++ ) {
+			$char		= substr($string,$pos,1);
+			if( strlen($prevChar) > 0 ) {
+				if( preg_match('/[0-9]/',$prevChar) >0 ) {
+					if( preg_match('/[0-9]/',$char) >0 ) {
+						$elm	.= $char;
+					} else {
+						array_push( $elmArray, $elm );
+						$elm	= $char;
+					}
+				} else {
+					if( preg_match('/[0-9]/',$char) >0 ) {
+						array_push( $elmArray, $elm );
+						$elm	= $char;
+					} else {
+						if( $alphSep == 0 ) {
+							$elm	.= $char;
+						} else {
+							if( strlen($elm) >= $alphSep ) {
+								array_push( $elmArray, $elm );
+								$elm	= $char;
+							} else {
+								$elm	.= $char;
+							}
+						}
+					}
+				}
+			} else {
+				$elm	.= $char;
+			}
+			$prevChar	= $char;
+		}
+		if( strlen($elm) > 0 ) {
+			array_push( $elmArray, $elm );
+		}
+		return $elmArray;
+	}
+	/**
+	 * CSVデータラインを配列にして返します
+	 */
+	function csv2Array( $strings ) {
+		$strings		= str_replace("\r\n","\n",$strings);
+		$strings		= str_replace("\r","\n",$strings);
+		$columns		= explode(',',$strings);
+		$regist_columns	= array();
+		$column_value	= '';
+		// カラム値を""と,の関係維持して正確に分割する
+		foreach( $columns as $val ) {
+			if( strlen($column_value) > 0 ) {
+				$column_value	.= ','.$val;
+			} else {
+				$column_value	.= $val;
+			}
+			$quote_count	= substr_count( $column_value, '"' );
+			if( $quote_count % 2 != 0 ) {
+				// クォータ数が偶数でない場合はカラムデータが完結していないので次の行へ
+			} else {
+				// 完結している場合はカラムとして処理
+				if( preg_match('/^"/',$column_value) > 0 && preg_match( '/"$/', $column_value ) > 0 ) {
+					$column_value	= preg_replace('/^"/','',$column_value );
+					$column_value	= preg_replace('/"$/','',$column_value );
+					$column_value	= preg_replace('/""/','"',$column_value );
+				}
+				$column_value			= mb_convert_kana($column_value,'KVas');
+				array_push( $regist_columns, $column_value );
+				$column_value	= '';
+			}
+		}
+		return $regist_columns;
+	}
+	/**
+	 * CSVデータラインを指定定義のハッシュにして返します
+	 */
+	function csv2Hash( $orderDefinitionHash, $strings ) {
+		$dataArray	= util_CharUtility::csv2Array( $strings );
+		$returnHash	= array();
+		if( isset($orderDefinitionHash[0]) ) {
+			// キー0番目が格納されているならキーが順序の処理
+			foreach( $orderDefinitionHash as $num => $keyName ) {
+				$returnHash[$keyName]	= trim($dataArray[$num]);
+			}
+		} else {
+			// キーが数値でないなら値が順序の処理
+			foreach( $orderDefinitionHash as $keyName => $order ) {
+				$returnHash[$keyName]	= trim($dataArray[$order-1]);
+			}
+		}
+		return $returnHash;
+	}
+	/**
 	 * 正規表現で利用する為の文字パターン用にエスケープします。
 	 */
 	function escape_regx_str($str){

Added: current/DATA/lib/util/Date.class.php
===================================================================
--- current/DATA/lib/util/Date.class.php	                        (rev 0)
+++ current/DATA/lib/util/Date.class.php	2009-06-13 06:48:45 UTC (rev 73)
@@ -0,0 +1,57 @@
+<?php
+class util_Date {
+	/**
+	 * 指定年月の日数を取得します
+	 * @param $year 年
+	 * @param $month 月
+	 * @return 月の日数,年月の指定が正しくない場合はfalse
+	 */
+	function getMonthMaxDay( $year, $month ) {
+		if( !is_numeric( $year ) || preg_match('/^[0-9]{1,4}$/',$year) == 0 ) {
+			return false;
+		} else if( !is_numeric( $month ) || preg_match('/^((|0)[1-9]|1[0-2])$/',$month) == 0 ) {
+			return false;
+		}
+		if ( ( $month == 4 || $month == 6 || $month == 9 || $month == 11 ) ) {
+			return 30;
+		} else if( 2 != $month ) {
+			return 31;
+		} else {
+			if ( ( $year % 400 ) == 0 ) {
+				return 29;
+			} else if ( ( $year % 100 ) == 0 ) {
+				return 28;
+			} else if ( ( $year % 4 ) == 0 ) {
+				return 29;
+			}
+		}
+	}
+	/**
+	 * 指定年月の日付ををキー、値を曜日とするハッシュを取得します
+	 * @param $year 年
+	 * @param $month 月
+	 * @param $isHash 日付以下をハッシュにするかのフラグ
+	 * @return array 指定年月の日付ををキー、値を曜日とするハッシュ
+	 */
+	function getMonthCalendarHash( $year, $month, $isHash=false, $is2d=false ) {
+		if( $maxDays = util_Date::getMonthMaxDay( $year, $month ) ) {
+			$calendarHash	= array();
+			for ( $day=1; $day<=$maxDays; $day++ ) {
+				$wday	= jddayofweek( cal_to_jd( CAL_GREGORIAN, $month, $day, $year ), 0 );
+				$vday	= $day;
+				if( $is2d ) {
+					$vday	= sprintf('%02d',$day);
+				}
+				if( $isHash ) {
+					$calendarHash[$vday]	= array('wday'=>$wday);
+				} else {
+					$calendarHash[$vday]	= $wday;
+				}
+			}
+			return $calendarHash;
+		} else {
+			return false;
+		}
+	}
+}
+?>
\ No newline at end of file

Modified: current/DATA/lib/util/Mail.class.php
===================================================================
--- current/DATA/lib/util/Mail.class.php	2009-05-09 03:42:30 UTC (rev 72)
+++ current/DATA/lib/util/Mail.class.php	2009-06-13 06:48:45 UTC (rev 73)
@@ -1052,6 +1052,26 @@
 			}
 		}
 	}
+	/**
+	 * 件名の特定置き換えワードを設定した文字列を返す。
+	 */
+	function getReplacedTextSubject( $convert_encoding=true ) {
+		$subject = $this->subject;
+		foreach( $this->replace_words as $key => $val ) {
+			$subject	= str_replace( "{".$key."}", $val, $subject );
+		}
+		return $subject;
+	}
+	/**
+	 * 本文の特定置き換えワードを設定した文字列を返す。
+	 */
+	function getReplacedTextBody( $convert_encoding=true ) {
+		$text_body = $this->text_body;
+		foreach( $this->replace_words as $key => $val ) {
+			$text_body	= str_replace( "{".$key."}", $val, $text_body );
+		}
+		return $text_body;
+	}
 }
 // 本クラスで利用するグローバル変数定義
 /** 文字コード変換ルール	*/

Modified: current/DATA/lib/util/ValidateFunctions.class.php
===================================================================
--- current/DATA/lib/util/ValidateFunctions.class.php	2009-05-09 03:42:30 UTC (rev 72)
+++ current/DATA/lib/util/ValidateFunctions.class.php	2009-06-13 06:48:45 UTC (rev 73)
@@ -27,7 +27,7 @@
 					|| !preg_match("/^[0-9]+$/", $month ) 
 					|| !preg_match("/^[0-9]+$/", $day ) ){
 			return false;
-		} else if ( ( $year < 1900 || $year > 2050 ) 
+		} else if ( ( $year < 1900 || $year > 2037 ) 
 					|| ( $month < 1 || $month > 12 ) 
 					|| ( $day < 1 || $day > 31 ) ) {
 			return false;
@@ -58,10 +58,88 @@
 	 * @return boolean 有効であればtrue、無効であればfalse
 	 */
 	function isAvailableDateFormat( $date_string ) {
-		list( $year, $month, $day )	= explode('-',$date_string);
-		return isAvailableDate( $year, $month, $day );
+		$elements	= explode('-',$date_string);
+		if( count($elements) == 3 ) {
+			$year	= array_shift($elements);
+			$month	= array_shift($elements);
+			$day	= array_shift($elements);
+			return ValidateFunctions::isAvailableDate( $year, $month, $day );
+		} else {
+			return false;
+		}
 	}
 	/**
+	 * 渡された時分秒が有効な時間であるか検査します。
+	 * 有効であればtrue、無効であればfalseを返します。
+	 * @param $hour 時
+	 * @param $min 分
+	 * @param $sec 秒
+	 * @return boolean 有効であればtrue、無効であればfalse
+	 */
+	function isAvailableTime( $hour, $min, $sec, $permit_decimal_sec=false ) {
+		if( preg_match('/^[0-9]{1,2}$/',$hour) == 0 ) {
+			return false;
+		} else if( $hour < 0 || $hour > 23 ) {
+			return false;
+		}
+		if( preg_match('/^[0-9]{1,2}$/',$min) == 0 ) {
+			return false;
+		} 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;
+			}
+		} else {
+			if( preg_match('/^[0-9]{1,2}$/',$sec) == 0 ) {
+				return false;
+			} else if( $sec < 0 || $sec >= 60 ) {
+				return false;
+			}
+		}
+		return true;
+	}
+	/**
+	 * 渡された時分秒フォーマットが有効な時間であるか検査します。
+	 * 有効であればtrue、無効であればfalseを返します。
+	 * @param $time_string 日付フォーマット文字列
+	 * @return boolean 有効であればtrue、無効であればfalse
+	 */
+	function isAvailableTimeFormat( $time_string ) {
+		$elements	= explode(':',$time_string);
+		if( count($elements) == 3 ) {
+			$hour	= array_shift($elements);
+			$min	= array_shift($elements);
+			$sec	= array_shift($elements);
+			return ValidateFunctions::isAvailableTime( $hour, $min, $sec );
+		} else {
+			return false;
+		}
+	}
+	/**
+	 * 渡された文字列が日時フォーマットとして有効化検査します
+	 * 有効であればtrue、無効であればfalseを返します。
+	 * @param $datetime_string 日時フォーマット文字列
+	 * @return boolean 有効であればtrue、無効であればfalse
+	 */
+	function isAvailableDatetimeFormat( $datetime_string ) {
+		$elements	= explode(' ',$datetime_string);
+		if( count($elements) == 2 ) {
+			$date_string	= array_shift($elements);
+			$time_string	= array_shift($elements);
+			if( ValidateFunctions::isAvailableDateFormat($date_string) ) {
+				return ValidateFunctions::isAvailableTimeFormat($time_string);
+			} else {
+				return false;
+			}
+		} else {
+			return false;
+		}
+	}
+	/**
 	 * 電話番号の書式チェックを行います
 	 */
 	function validateTelephoneNumber( &$request, $telephone_area_code, $telephone_city_code, $telephone_code, $item_name ) {
@@ -73,11 +151,13 @@
 			$telephone_city_code 	= ""; 
 			$telephone_code			= "";
 			$telephone_number		= "";
-		} elseif ( $telephone_len > 0 ) {
+		} else if ( $telephone_len > 0 ) {
 			if ( strlen( $telephone_area_code) == 0 
 					|| strlen( $telephone_city_code) == 0 
 					|| strlen( $telephone_code) == 0 ) {
 				$request->addError($item_name.'は市外局番・市内局番・局番を全て半角数字で入力してください。');
+			} else if( $telephone_len > 14 ) {
+				$request->addError($item_name.'の数字は合計14文字以下で入力してください。');
 			} else {
 				$telephone_number	= $telephone_area_code
 										. "-" . $telephone_city_code

Modified: current/DATA/lib/util/mail/SendMail.class.php
===================================================================
--- current/DATA/lib/util/mail/SendMail.class.php	2009-05-09 03:42:30 UTC (rev 72)
+++ current/DATA/lib/util/mail/SendMail.class.php	2009-06-13 06:48:45 UTC (rev 73)
@@ -55,7 +55,7 @@
 		}
 		$sendmail_path	= trim($this->options['sendmail_path']);
 		// コマンド文字列
-		$command	= $sendmail_path.' -t -f'.$envelope_from.' '. $to;
+		$command	= $sendmail_path.' -f'.$envelope_from.' '. $to;
 		// sendmailへパイプオープン
 		$mp = popen($command, "w");
 		if( $mp ) {



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