Location: PHPKode > scripts > NIKAcore > nikacore/PageNameCollection.php
<?php

// NIKAcore: core classes for PHP websites
// 
// Copyright (C) 2003 NIKA Consulting, Inc.
//
// This file is part of NIKAcore.
// 
// NIKAcore is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 2.1 of the License, or (at your option)
// any later version.
// 
// NIKAcore 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 Lesser General Public License for
// more details.
// 
// You should have received a copy of the GNU Lesser General Public License
// along with NIKAcore; if not, write to the Free Software Foundation, Inc., 59
// Temple Place, Suite 330, Boston, MA  02111-1307  USA
// 
// Contact hide@address.com with comments, questions, or patches.

define('USE_INCLUDE_PATH', 1);
require_once('PageName.php');
require_once('file_exists_in_include_path.php');

class PageNameCollection {

	var $collection = array();

	function populateFromFile($filename) {
		$file_contents = false;
		if (file_exists_in_include_path($filename)) {
			$file_contents = @file($filename, USE_INCLUDE_PATH);
		}
		if ($file_contents === false) {
			$this = $this->newNull();
			return;
		}
		foreach($file_contents as $line) {
			$this->add(PageName::createFromLine($this, $line));
		}
	}

	function createFromFile($filename) {
		$result = new PageNameCollection;
		$result->populateFromFile($filename);
		return $result;
	}

	function isNull() { return false; }

	function newNull() { return new NullPageNameCollection; }

	function add($mapping) {
		if ($mapping->isNull()) return;
		$this->collection[] = $mapping;
	}

	function count() { return count($this->collection); }

	function getPageNameForUrl($url) {
		foreach($this->collection as $element) {
			if (is_object($element) && $element->getUrl() == $url ) { return $element; }
		}
		return PageName::newNull();
	}

	function getRootPageName() {
		return $this->getPageNameForUrl('/');
	}

	function getLongSiteName() {
		$pn = $this->getRootPageName();
		return $pn->getLongName();
	}

	function getSiteName() {
		$pn = $this->getRootPageName();
		return $pn->getShortName();
	}

	function populateWithDefaultData($habitat) {
		$this->populateFromFile($habitat->getUrlmapFilename());
	}

	function getCurrent($habitat) {
		$this->populateWithDefaultData($habitat);
		return $this->getPageNameForUrl($habitat->getRequestUri());
	}

}

class NullPageNameCollection extends PageNameCollection {

	function isNull() { return true; }

	function add($mapping) {}

}

?>
Return current item: NIKAcore