Location: PHPKode > projects > Aukyla Document Management System > adms2/plugins/URINamespaces/ADMS_Search_URINamespace.php
<?php
/*
     ADMS_Search_URINamespace.php, giving access to the search functions
     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('Search.php');
require_once('String.php');
require_once('URI.php');

class ADMS_Search_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)
	{
		$query = String::substringAfter($path, 'ADMS_Search://');
		if($query === self::$lastQuery)
		{
			$this->results = self::$lastResults;
		}
		else
		{
			$search = Search::instance();
			$search->setInterfaces(array('ADMS'));
			$this->results = $search->doSearch($query);
			self::$lastQuery = $query;
			self::$lastResults = $this->results;
		}

		$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->results['ADMS'][$position]) ? $this->results['ADMS'][$position]->uri : 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)
	{
		$query = String::substringAfter($path, 'ADMS_Search://');

		switch($key)
		{
			case 'name':
				return i18n("Search results for %1.", $query);

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

			case 'ADMS-scores':
				if($query === self::$lastQuery)
				{
					$results = self::$lastResults;
				}
				else
				{
					$search = Search::instance();
					$search->setInterfaces(array('ADMS'));
					$results = $search->doSearch($query);
				}

				$value = '';
				foreach($results['ADMS'] as $result)
				{
					$value .= "{$result->score}\n";
				}
				return $value;

			default:
				return '';
		}
	}

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

	private static $lastQuery = '';
	private static $lastResults = array();
	private $results = array();
	private $dirPosition = 0;
}

?>
Return current item: Aukyla Document Management System