Location: PHPKode > scripts > NIKAcore > nikacore/PageName.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.

class PageName {
	
	function PageName(&$collection, $url, $long_name, $short_name = false) {
		$this->collection =& $collection;
		$this->url = $url;
		$this->long_name = $long_name;
		$this->short_name = ($short_name ? $short_name : $long_name);
	}

	function newNull() { return new NullPageName; }
	
	function isNull() { return false; }

	function splitNames($names) {
		$names_array = explode('|', $names);
		$long_name = $names_array[0];
		$short_name = isset($names_array[1]) ? $names_array[1] : false;
		return array($long_name, $short_name);
	}
	
	function stripComment($line) {
		list($result) = explode('#', $line);
		return $result;
	}

	function createFromLine(&$collection, $line) {
		$line = PageName::stripComment($line);
		if (! chop($line)) return PageName::newNull();
		list($url, $names) = explode('=', $line); 
		list($long_name, $short_name) = PageName::splitNames($names);
		return new PageName($collection, trim($url), trim($long_name), trim($short_name));
	}

	function getUrl() { return $this->url; }

	function getLongName() { return $this->long_name; }

	function getShortName() { return $this->short_name; }

	function isRoot() { return $this->getUrl() == '/'; }

	function pageTitle() {
		if ($this->isRoot()) {
			return $this->collection->getLongSiteName();
		} else {
			return $this->collection->getSiteName(). ': '.
				$this->getShortName();
		}
	}

	function htmlTag($tag, $contents) {
		return "<$tag>$contents</$tag>\n";
	}

	function htmlPageTitleTag() {
		return $this->htmlTag('title', $this->pageTitle());
	}

	function htmlH1HeadlineTag() {
		if ($this->isRoot()) return '';
		return $this->htmlTag('h1', $this->getLongName());
	}

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

}

class NullPageName extends PageName {

	function NullPageName() {}

	function isNull() { return true; }

	function getUrl() { return null; }
	function getLongName() { return null; }
	function getShortName() { return null; }
	function htmlPageTitleTag() { return '<title></title>'; }
}

?>
Return current item: NIKAcore