Deprecated: Assigning the return value of new by reference is deprecated in /home/bluestat/public_html/source/index.php on line 477
ViewSVN - Blob - ViewGit - Blue Static
<?php
/*=====================================================================*\
|| ################################################################### ||
|| # ViewSVN [#]version[#]
|| # --------------------------------------------------------------- # ||
|| # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
|| # This file may not be reproduced in any way without permission.  # ||
|| # --------------------------------------------------------------- # ||
|| # User License Agreement at http://www.iris-studios.com/license/  # ||
|| ################################################################### ||
\*=====================================================================*/

/**
* Class that manages repositories and can produce lists of
* repositories
*
* @pacakge	ViewSVN
*/

/**
* Repository class that can list repositories and prepare
* them for use
*
* @package	DeskPRO
* @version	$Id$
*/
class Repository
{
	/**
	* Array of valid repositories
	* @var	array
	*/
	var $repositories = array();

	/**
	* Root path to the repository
	* @var string
	*/
	var $path;

	/**
	* Whether or not the path is a container
	* @var	bool
	*/
	var $container;

	/**
	* Constructor: prepare for repository
	*
	* @param	string	Path to repository or container
	* @param	bool	Whether the path is a container
	*/
	function Repository($path, $iscontainer)
	{
		global $viewsvn;

		$this->path = $viewsvn->fetch_sourcepath($path);
		$this->container = (bool)$iscontainer;

		if ($this->container)
		{
			if ($dir = @opendir($this->path))
			{
				while (($file = readdir($dir)) !== false)
				{
					if (is_dir($this->path . $file) AND $file{0} != '.'  AND is_dir($this->path . $file . '/' . 'db'))
					{
						$this->repositories[] = $file;
					}
				}
				closedir($dir);
			}
		}
		else
		{
			if (is_dir($this->path . 'db'))
			{
				$this->repositories[] = $this->path;
			}
		}

		if (count($this->repositories) < 1)
		{
			$viewsvn->trigger->error('no valid repositories');
		}
	}

	/**
	* Returns a list of repositories
	*
	* @access	public
	*
	* @return	array	List of repositories
	*/
	function fetch_list()
	{
		return $this->repositories;
	}

	/**
	* Returns a path to a repository
	*
	* @access	public
	*
	* @param	string	Repository name
	*
	* @return	string	Full path to the repository
	*/
	function fetch_path($repository = '')
	{
		global $viewsvn;

		if (!in_array($repository, $this->fetch_list()))
		{
			$viewsvn->trigger->error('invalid repository name');
		}

		if ($this->container)
		{
			return 'file://' . $this->path . $repository . '/';
		}
		else
		{
			return 'file://' . $this->path . '/';
		}
	}

	/**
	* Verifies a path inside a repository
	*
	* @access	public
	*
	* @param	string	Repository name
	* @param	string	Path
	*
	* @return	bool	Validity
	*/
	function verify($repos, $path)
	{
		global $viewsvn;

		if ($repospath = $this->fetch_path($repos))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}

/*=====================================================================*\
|| ###################################################################
|| # $HeadURL$
|| # $Id$
|| ###################################################################
\*=====================================================================*/
?>