[Phpxd-commits] CVS: phpXD.www/classes .htaccess,NONE,1.1 Site.php,NONE,1.1 Sites.php,NONE,1.1 Stati
Status: Beta
Brought to you by:
growbal
|
From: Thomas D. <th...@us...> - 2002-01-26 17:10:47
|
Update of /cvsroot/phpxd/phpXD.www/classes
In directory usw-pr-cvs1:/tmp/cvs-serv21133/classes
Added Files:
.htaccess Site.php Sites.php StaticSite.php
Log Message:
Initial checkin of the phpxd homepage.
--- NEW FILE: .htaccess ---
Deny From All
--- NEW FILE: Site.php ---
<?php
// phpXD-Homepage - EXPERIMENTAL
//
// This Software and all associated files are released unter the
// GNU Public License (GPL), see LICENSE for details.
//
// $Id: Site.php,v 1.1 2002/01/26 17:10:44 thomi Exp $
class Site {
var $site = "";
var $filepath = "";
var $template = "";
var $style = "";
var $xhtml = "";
var $pageTitle;
var $hierarchy;
var $content;
var $navigation;
var $url;
var $urlTitle;
var $sessionID;
var $xhtml;
var $timeStart;
/*
* Renders a site to a string.
* @private
* @return string
*/
function renderToString() {
$page = implode("", file($this->template));
$page = str_replace("\$URL_TITLE\$", $this->urlTitle, $page);
$page = str_replace("\$PAGE_STYLE\$", $this->style, $page);
$page = str_replace("\$PAGE_TITLE\$", $this->pageTitle, $page);
$page = str_replace("\$PAGE_HIERARCHY\$", $this->hierarchy, $page);
$page = str_replace("\$PAGE_CONTENT\$", $this->content, $page);
$page = str_replace("\$PAGE_NAVIGATION\$", $this->navigation, $page);
$page = str_replace("\$URL\$", $this->url, $page);
$page = str_replace("\$SESSION_ID\$", $this->sessionID, $page);
$timeStop = microtime();
list($usecStart, $secStart) = explode(" ", $this->timeStart);
list($usecStop, $secStop) = explode(" ", $timeStop);
$page = str_replace("\$PROCESSING_TIME\$",
sprintf("%.2f", ($secStop + $usecStop -
$secStart - $usecStart)),
$page);
$this->xhtml = $page;
return $this->xhtml;
}
/*
* Renders a site and outputs it.
* @private
* @return void
*/
function render() {
echo $this->renderToString();
}
/*
* Runs the site. This could mean, that the site is created (static sites)
* or handled (dynamic sites).
* @public
* @param $url
* @param $sessionID
* @param $getVars A copy of $HTTP_GET_VARS or $_GET;
* @param $postVars A copy of $HTTP_POST_VARS or $_POST;
* @return string
*/
function run($sessionID, $getVars, $postVars, &$sessionVars) {
}
function makeHierarchy() {
$sites = new Sites();
$subDirs = explode("/", $this->site);
$this->hierarchy = ""; $path = "";
array_pop($subDirs);
if (sizeof($subDirs) > 0) {
foreach ($subDirs as $key => $subDir) {
if (($key != "en") && ($key != "de")) {
if ($this->hierarchy != "") {
$this->hierarchy .= " > ";
}
$title = $sites->getTitle($subDir);
$this->hierarchy .= "<a href=\"".$this->url.$path.$subDir."\">".
$title."</a>";
$path .= $subDir."/";
}
}
}
if ($this->hierarchy != "") {
$this->hierarchy .= " > ";
}
$this->hierarchy .= $this->pageTitle;
}
function &loadNavigation() {
$site = $this->site;
do {
$splitSite = explode("/", $site);
unset($splitSite[count($splitSite) - 1]);
$site = implode("/", $splitSite);
if (file_exists("data/".$site."/navigation.xml")) {
$linksDOM = new phpXD("data/".$site."/navigation.xml");
return $linksDOM->document->documentElement->firstChild;
}
} while ($site != "");
}
function makeNavigation(&$linksDOM) {
$this->navigation = "";
$links =& $linksDOM->getElementsByTagName("li");
for ($i = 0; $i < $links->getLength(); ++$i) {
$link =& $links->item($i);
$firstChild =& $link->firstChild;
while (($firstChild != null) &&
($firstChild->nodeName != "a")) {
$firstChild =& $firstChild->nextSibling;
}
if (($firstChild->nodeType == ELEMENT_NODE) &&
($firstChild->nodeName == "a")) {
$href = $firstChild->getAttribute("href");
$href = str_replace("\$URL\$", "", $href);
$href = str_replace("\$SESSION_ID\$", "", $href);
if ($href == "") {
$href = "index";
}
if ($href == $this->site) {
$class = $firstChild->getAttribute("class");
$firstChild->setAttribute("class", $class." selected");
}
else {
if ((strpos($this->site, $href) === false) ||
!(strpos($this->site, $href) == 0)) {
if (($link->parentNode->parentNode->nodeName == "li") &&
(strpos($href, $this->site) === false)) {
$link->parentNode->removeChild($link);
}
unset($prevChild);
$child =& $firstChild;
while ($child != null) {
if (($child->nodeType == ELEMENT_NODE) &&
($child->nodeName != "a")) {
if ($prevChild != null) {
$prevChild->nextSibling =& $child->nextSibling;
}
}
else {
$prevChild =& $child;
}
$child =& $child->nextSibling;
}
}
}
}
}
$this->XMLToXHTML($linksDOM, $this->navigation);
}
function XMLToXHTML(&$dom, &$output) {
if ($dom->nodeType == CDATA_SECTION_NODE) {
$output .= "<![CDATA[";
$output .= $dom->getData();
$output .= "]]>";
}
if ($dom->nodeType == COMMENT_NODE) {
$output .= "<!--";
$output .= htmlspecialchars($dom->getData());
$output .= "-->";
}
if ($dom->nodeType == ELEMENT_NODE) {
$output .= "<".$dom->tagName;
if (isset($dom->attributes)) {
for ($i = 0; $i < $dom->attributes->getLength(); $i++) {
$elem =& $dom->attributes->item($i);
$output .= " ".$elem->getName()."=\"".$elem->getValue()."\"";
}
}
if ($dom->hasChildNodes()) {
$output .= ">";
$this->XMLToXHTML($dom->firstChild, $output);
$output .= "</".$dom->tagName.">";
}
else {
$output .= " />";
}
}
if ($dom->nodeType == TEXT_NODE) {
$text = str_replace("&", "&", $dom->getData());
$text = str_replace("<", "<", $text);
$output .= str_replace(">", ">", $text);
}
if (isset($dom->nextSibling)) {
$this->XMLToXHTML($dom->nextSibling, $output);
}
}
function destroy(&$dom) {
if ($dom != null) {
if ($dom->hasChildNodes()) {
$this->destroy($dom->firstChild);
}
if ((isset($dom->nextSibling)) &&
($dom->nextSibling != null)) {
$this->destroy($dom->nextSibling);
}
unset($dom);
}
}
}
?>
--- NEW FILE: Sites.php ---
<?php
// phpXD-Homepage - EXPERIMENTAL
//
// This Software and all associated files are released unter the
// GNU Public License (GPL), see LICENSE for details.
//
// $Id: Sites.php,v 1.1 2002/01/26 17:10:44 thomi Exp $
class Sites {
var $sites;
var $titles;
var $styles;
function Sites() {
$this->sites["en/index"] = "StaticSite";
}
// Which site is handled by which class.
function getClass($site) {
if (isset($this->sites[$site])) {
return $this->sites[$site];
}
else {
return "";
}
}
function getTitle($site) {
if (isset($this->titles[$site]) &&
($this->titles[$site] != "")) {
return $this->titles[$site];
}
else {
return ucfirst($site);
}
}
function getStyle($site) {
if (isset($this->styles[$site]) &&
($this->styles[$site] != "")) {
return $this->styles[$site];
}
else {
return "stylesheets/screen.css";
}
}
}
?>
--- NEW FILE: StaticSite.php ---
<?php
// phpXD-Homepage - EXPERIMENTAL
//
// This Software and all associated files are released unter the
// GNU Public License (GPL), see LICENSE for details.
//
// $Id: StaticSite.php,v 1.1 2002/01/26 17:10:44 thomi Exp $
class StaticSite extends Site {
function StaticSite($site, $filepath, $template, $style) {
$this->site = $site;
$this->filepath = $filepath;
$this->template = $template;
$this->style = $style;
}
/*
* Runs the site. This could mean, that the site is created (static sites)
* or handled (dynamic sites).
* @public
* @param $url
* @param $sessionID
* @param $getVars A copy of $HTTP_GET_VARS or $_GET;
* @param $postVars A copy of $HTTP_POST_VARS or $_POST;
* @return string
*/
function run($url, $urlTitle, $sessionID, $getVars,
$postVars, &$sessionVars) {
$this->timeStart = microtime();
$this->url = $url;
$this->urlTitle = $urlTitle;
$this->sessionID = $sessionID;
if (file_exists($this->filepath.$this->site.".xml")) {
$pageDOM = new phpXD($this->filepath.$this->site.".xml");
}
$titleNodes = $pageDOM->document->getElementsByTagName("title");
if ($titleNodes->getLength() > 0) {
$titleNode = $titleNodes->item(0);
$titleNode->normalize();
$this->pageTitle = $titleNode->firstChild->getData();
$this->makeHierarchy();
}
$contentNodes = $pageDOM->document->getElementsByTagName("content");
if ($contentNodes->getLength() > 0) {
$contentNode = $contentNodes->item(0);
$content = "";
$this->XMLToXHTML($contentNode->firstChild, $this->content);
}
$linksNodes = $pageDOM->document->getElementsByTagName("links");
if ($linksNodes->getLength() > 0) {
$linksNode = $linksNodes->item(0);
if ($linksNode->getAttribute("ref") != "") {
$linksDOM = new phpXD("data/".$linksNode->getAttribute("ref"));
$linksNodes2 = $linksDOM->document->getElementsByTagName("links");
if ($linksNodes2->getLength() > 0) {
$temp = $linksNodes2->item(0);
$linksNode2 = $temp->firstChild;
}
}
else {
$linksNode2 = $linksNode->firstChild;
}
}
else {
$linksNode2 = $this->loadNavigation();
}
$this->makeNavigation($linksNode2);
$this->destroy($pageDOM->document->documentElement);
unset($pageDOM);
$this->destroy($linksDOM->document->documentElement);
unset($linksDOM);
}
}
?>
|