<?php
/*
 * content/widget/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-08-23
 */
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.'DaoWidget.class.php');
require_once( dirname(dirname(dirname(__FILE__)))
	.DIRECTORY_SEPARATOR.'Variable.class.php');
class content_widget_setting_Load extends system_login_ModuleBase {
	function content_widget_setting_Load() {
	}
	function execute( & $request ) {
		$widgetFileName			= strtolower(trim(stripslashes($_GET['wfile'])));
		if( strlen(trim($widgetFileName)) == 0 ) {
			$request->addError('HTMLパーツファイル名を指定してください');
		}
		
		if( !$request->isError() ) {
			$variableObject	= new content_Variable($request);
			$widgetObject	= new content_DaoWidget($widgetFileName);
			$widgetObject->load( $request );
			$widgetObject->variableHash	= array();
			// HTML本文からサイト固有値の記述を抜き出す
			foreach( $GLOBALS['SPIDER_USER_AGENT_CLASS_HASH'] as $agent => $agentName ) {
				$body	= $widgetObject->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) ) {
								// キーが存在する場合
								$widgetObject->variableHash[$vaiableKey]	= $variableObject->variableHash[$vaiableKey];
								$widgetObject->variableHash[$vaiableKey]['setup']	= true;
							} else {
								// キーが存在しない場合
								$widgetObject->variableHash[$vaiableKey]	= array(
									'key'		=> $vaiableKey,
									'label'	=> '',
									'value'	=> '',
									'setup'	=> false,
								);
							}
						}
					}
				}
			}
			$request->setAttribute('content.widget.widgetObject',$widgetObject );
		}
	}
}
?>