Location: PHPKode > projects > Aukyla Document Management System > adms2/plugins/URINamespaces/ADMS_History_URINamespace.php
<?php
/*
     ADMS_History_URINamespace.php, giving access to documents in the history
     Copyright (C) 2004 Arend van Beelen, Auton Rijnsburg

     This program is free software; you can redistribute it and/or modify it
     under the terms of the GNU General Public License as published by the Free
     Software Foundation; either version 2 of the License, or (at your option)
     any later version.

     This program is distributed in the hope that it will be useful, but WITHOUT
     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
     FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
     more details.

     You should have received a copy of the GNU General Public License along
     with this program; if not, write to the Free Software Foundation, Inc.,
     59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

     For any questions, comments or whatever, you may mail me at: hide@address.com
*/

require_once('Locale.php');
require_once('String.php');
require_once('URI.php');

require_once('ADMS/History.php');

class ADMS_History_URINamespace extends LocalURINamespace
{
	public function __construct()
	{
		Locale::init('apps/ADMS');
	}

	public function stream_open($path, $mode, $options = 0, &$opened_path = '')
	{
		return false;
	}

	public function stream_close()
	{
		return false;
	}

	public function stream_read($count)
	{
		return false;
	}

	public function stream_write($data)
	{
		return false;
	}

	public function stream_eof()
	{
		return true;
	}

	public function stream_tell()
	{
		return false;
	}

	public function stream_seek($offset, $whence)
	{
		return false;
	}

	public function stream_flush()
	{
		return false;
	}

	public function stream_stat()
	{
		return false;
	}

	public function unlink($path)
	{
		return false;
	}

	public function rename($pathFrom, $pathTo)
	{
		return false;
	}

	public function mkdir($path, $mode, $options)
	{
		return false;
	}

	public function rmdir($path, $options = 0)
	{
		return false;
	}

	public function dir_opendir($path, $options)
	{
		$parsedPath = $this->parseUrl($path);

		if($parsedPath['created'] == true)
		{
			$this->entries = ADMS_History::createdSince($parsedPath['time'], $parsedPath['maxEntries']);
		}
		else
		{
			$this->entries = ADMS_History::modifiedSince($parsedPath['time'], $parsedPath['maxEntries']);
		}

		$this->dirPosition = 0;

		return true;
	}

	public function url_stat($path, $flags)
	{
		return array('dev'     =>  0,
		             'ino'     =>  0,
		             'mode'    =>  0040000,
		             'nlink'   =>  0,
		             'uid'     =>  0,
		             'gid'     =>  0,
		             'rdev'    => -1,
		             'size'    =>  0,
		             'atime'   =>  0,
		             'mtime'   =>  0,
		             'ctime'   =>  0,
		             'blksize' => -1,
		             'blocks'  =>  0);
	}

	public function dir_readdir()
	{
		$position = $this->dirPosition++;

		return (isset($this->entries[$position]) ? $this->entries[$position]->document : false);
	}

	public function dir_rewinddir()
	{
		$this->dirPosition = 0;

		return true;
	}

	public function dir_closedir()
	{
		return true;
	}

	public function uniquePath($path, $suggestion)
	{
		return false;
	}

	public function permissions($path)
	{
		return PERMISSION_READ;
	}

	public function permissionsArray($path)
	{
		return array('other' => PERMISSION_READ);
	}

	public function setPermissionsArray($path, $permissions)
	{
		return false;
	}

	public function metaData($path, $key)
	{
		switch($key)
		{
			case 'name':
				$parsedPath = $this->parseUrl($path);
				$date = date('l dS of F Y', $parsedPath['time']);
				if($parsedPath['created'] == true)
				{
					return i18n("Documents created since %1.", $date);
				}
				else
				{
					return i18n("Documents modified since %1.", $date);
				}

			case 'mime-type':
				return 'inode/directory';

			default:
				return '';
		}
	}

	public function setMetaData($path, $key, $value)
	{
		return false;
	}

	private function parseUrl($url)
	{
		$result = array('created' => true,
		                'time' => time() - 86400,
		                'maxEntries' => 20);

		$url = String::substringAfter($url, 'ADMS_History://');

		if(String::substringBefore($url, '/') == 'modifiedSince')
		{
			$result['created'] = false;
		}

		$url = String::substringAfter($url, '/');

		if($url != '')
		{
			$result['time'] = (int) String::substringBefore($url, '/');
		}

		$url = String::substringAfter($url, '/');

		if($url != '')
		{
			$result['maxEntries'] = (int) $url;
		}

		return $result;
	}

	private $entries;
	private $dirPosition;
}

?>
Return current item: Aukyla Document Management System