<?php
/*
 * content/Delete.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(__FILE__))
	.DIRECTORY_SEPARATOR.'system'
	.DIRECTORY_SEPARATOR.'login'
	.DIRECTORY_SEPARATOR.'ModuleBase.class.php');
require_once( dirname(dirname(__FILE__))
	.DIRECTORY_SEPARATOR.'system'
	.DIRECTORY_SEPARATOR.'DataFileWriter.class.php');
class content_Delete extends system_login_ModuleBase {
	function content_Delete() {
	}
	function execute( & $request ) {
		$targetType		= strtolower(trim(stripslashes($_POST['target_type'])));
		$fileUri		= strtolower(trim(stripslashes($_POST['target_uri'])));
		$agentType		= strtolower(trim(stripslashes($_POST['agent_type'])));
		if( DIR_NAME_TEMPLATES != $targetType && DIR_NAME_PAGES != $targetType && DIR_NAME_WIDGETS != $targetType ) {
			$targetType	= 'public';
		}
		if( !array_key_exists($agentType,$GLOBALS['SPIDER_USER_AGENT_CLASS_HASH']) ) {
			$agentType	= 'default';
		}

		if( strlen($fileUri) <= 1 ) {
			$request->addError('削除するファイルを指定してください。');
		} else if( !system_DataFileWriter::isExists( $request, $fileUri, $targetType ) ) {
			$request->addError('指定されたファイルは存在しません。');
		}
		
		if( !$request->isError() ) {
			if( 'public' == $targetType ) {
				// 公開フォルダ内ファイルなら
				$currentBody	= system_DataFileWriter::delete( $request, $fileUri, 'public' );
			} else {
				// 公開フォルダ以外のファイルなら
				$currentBody	= system_DataFileWriter::delete( $request, '/'.$agentType.$fileUri, 'public' );
			}
		}
	}
}
?>