<?php
/*
 * content/page/html/Save.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_html_Save extends system_login_ModuleBase {
	function content_page_html_Save() {
		array_push($this->require_module_array,'content.page.setting.Load');
	}
	function execute( & $request ) {
		if( !$request->isError() ) {
			$agent			= strtolower(trim(stripslashes($_POST['agent'])));
			$bodyStrings	= stripslashes($_POST['body_strings']);
			$bodyStrings	= str_replace("\\","\\\\",$bodyStrings);
			$pageObject		= $request->getAttribute('content.page.pageObject' );
			$isExistAgent	= false;
			foreach( $GLOBALS['SPIDER_USER_AGENT_CLASS_HASH'] as $agentType => $agentName ) {
				if( $agentType == $agent ) {
					$isExistAgent	= true;
					break;
				}
			}
			if( !$isExistAgent ) {
				$agent			= 'default';
			}
			// 本文ファイルを保存
			$pageObject->saveBody( $request, $agent, $bodyStrings );
			if( !$request->isError() ) {
				// エラーがないならビルド
				$pageObject->rebuild( $request, $agent );
			}
			$request->setAttribute('content.page.html.agent',$agent);
			$request->setAttribute('content.page.html.body', $bodyStrings );
		}
	}
}
?>