<?php
/**
* @version 0.93
* @category Anahita Plugin
* @package File
* @copyright Copyright (C) 2007 - 2009 rmd Studio Inc. and Peerglobe Technology Inc. All rights reserved.
* @license GNU GPLv2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
* @link http://www.anahitapolis.com
*/
class AnUtilStorageAdapterLocal extends AnUtilStorageAdapterAbstract
{
protected $_root;
protected $_baseURL;
public function __construct($options=array())
{
parent::__construct($options);
$this->_root = $this->getOption('root', JPATH_ROOT);
$base_url = JFactory::getURI()->base();
$application = KFactory::get('lib.joomla.application');
if ( $application->getClientId() != 0 )
$base_url = preg_replace('/\w+\/$/', '', $base_url);
$this->_baseURL = $this->getOption('base_url', $base_url);
}
/**
*
* @return
* @param $path Object
* @param $incpath Object[optional]
* @param $amount Object[optional]
* @param $chunksize Object[optional]
* @param $offset Object[optional]
*/
protected function _read($path)
{
$path = $this->_getFilePath($path);
return file_get_contents($path);
}
/**
*
* @return
* @param $path Object
* @param $buffer Object
* @param $mode Object
*/
protected function _write($path, $data, $public)
{
$path = $this->_getFilePath($path);
$dir = dirname($path);
if ( !file_exists($dir) ) {
mkdir($dir, 0707, true);
}
return file_put_contents($path, (string) $data);
}
protected function _exists($path)
{
$path = $this->_getFilePath($path);
return file_exists($path);
}
protected function _delete($path)
{
$path = $this->_getFilePath($path);
unlink($path);
}
protected function _getUrl($path)
{
return $this->_baseURL.$path;
}
protected function _getFilePath($path)
{
return $this->_root.DS.str_replace('/', DS, $path);
}
//end class
}