<?php
/*
 * content/page/setting/Load.class.php
 * 
 * CopyRight(C) 2010 Shopformer Development Team. All Right Reserved
 * URL: http://sourceforge.jp/projects/shopformer/
 * 
 * 
 * Mail: m_nakashima@users.sourceforge.jp
 * Auther: Masanori Nakashima
 * Last Update: 2010-06-18
 */
require_once( dirname(dirname(dirname(dirname(__FILE__))))
	.DIRECTORY_SEPARATOR.'system'
	.DIRECTORY_SEPARATOR.'login'
	.DIRECTORY_SEPARATOR.'ModuleBase.class.php');
require_once( dirname(dirname(dirname(__FILE__)))
	.DIRECTORY_SEPARATOR.'DaoPage.class.php');
require_once( dirname(dirname(dirname(__FILE__)))
	.DIRECTORY_SEPARATOR.'Variable.class.php');
class content_page_setting_Load extends system_login_ModuleBase {
	function content_page_setting_Load() {
	}
	function execute( & $request ) {
		$fileUri			= strtolower(trim(stripslashes($_GET['uri'])));
		if( strlen(trim($fileUri)) == 0 ) {
			$request->addError('ファイルURIを指定してください');
		}
		
		if( !$request->isError() ) {
			$variableObject	= new content_Variable($request);
			$pageObject		= new content_DaoPage($fileUri);
			$pageObject->load( $request );
			$pageObject->variableHash	= array();
			// HTML本文からサイト固有値の記述を抜き出す
			foreach( $GLOBALS['SPIDER_USER_AGENT_CLASS_HASH'] as $agent => $agentName ) {
				$body	= $pageObject->getBody( $request, $agent );
				if( preg_match_all( '/\\{value\\:([a-zA-Z](|[0-9a-zA-Z\\.\\_]*[0-9a-zA-Z]))\\}/', $body, $matches, PREG_PATTERN_ORDER ) > 0) {
					if( is_array($matches[1]) ) {
						foreach( $matches[1] as $vaiableKey ) {
							if( $variableObject->existsKey($vaiableKey) ) {
								// キーが存在する場合
								$pageObject->variableHash[$vaiableKey]	= $variableObject->variableHash[$vaiableKey];
								$pageObject->variableHash[$vaiableKey]['setup']	= true;
							} else {
								// キーが存在しない場合
								$pageObject->variableHash[$vaiableKey]	= array(
									'key'		=> $vaiableKey,
									'label'	=> '',
									'value'	=> '',
									'setup'	=> false,
								);
							}
						}
					}
				}
			}
			$request->setAttribute('content.page.pageObject',$pageObject );
		}
	}
}
?>