gzuncompress
|
Server IP : 172.19.0.3 / Your IP : 216.73.216.178 Web Server : Apache/2.4 System : Linux 880f91b28fd7 5.15.0-117-generic #127~20.04.1-Ubuntu SMP Thu Jul 11 15:36:12 UTC 2024 x86_64 User : tomlinde ( 155017) PHP Version : 5.6.40 Disable Function : dl, syslog, opcache_get_status MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0700) : /home/webpages/lima-city/tomlinde/html/gallery_rongriijen/internals/classes/ |
| [ Home ] | [ C0mmand ] | [ Upload File ] | [ Lock Shell ] | [ Logout ] |
|---|
<?php
class Page extends DOMDocument {
public $xpath;
function __construct(){
parent::__construct();
//lazy language setting..
$lang = strtolower(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2))."_".strtoupper(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2));
//$this->setLanguage($lang);
$this->xpath = new DOMXPath($this);//addTagToPath needs the xpath
$this->addTagToPath("/", "page");
$this->addTagToPath("/page", "messages");
}
public function setLanguage($lang) {
//these things are needed for gettext
putenv('LC_ALL='.$lang);
setlocale(LC_ALL, $lang);
bindtextdomain("page", "./l10n");
textdomain("page");
}
public function setXSL($path) {
$xslt = $this->createProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="'.$path.'"');
$this->insertBefore($xslt, $this->xpath->evaluate("/page")->item(0));
}
public function writeGlobalTags(){
if($this->isLoggedIn()){
$this->addTagToPath("/page", "login");
$this->addTagToPath("/page/login", "isLoggedIn", $this->isLoggedIn());
$this->addTagToPath("/page/login", "nick", $_SESSION['nick']);
}
}
public function isLoggedIn(){
if(array_key_exists('login', $_SESSION))
return $_SESSION['login'];
else
return false;
}
public function logout(){
$newPageObject = $this->redirectPage("home");
if(array_key_exists('login', $_SESSION)){
//$_SESSION['login'] = false;
unset($_SESSION['login']);
unset($_SESSION['nick']);
$newPageObject->addMessage("confirmation", _("Logout complete."));
}
return $newPageObject;
}
public function addTagToPath($path, $tagname, $content = NULL, $attr = NULL, $aValue = NULL){
$element = $this->prepareTag($tagname, $content, $attr, $aValue);
$this->addSubTreeToPath($path, $element);
}
public function prepareTag( $tagname, $content = NULL, $attr = NULL, $aValue = NULL){
if($content != NULL){
$element = $this->createElement($tagname);
$txt = $this->createTextNode($content);
$element->appendChild($txt);
} else
$element = $this->createElement($tagname);
if($attr != NULL){
$ntxt = $this->createTextNode($aValue);
$nattr = $this->createAttribute($attr);
$nattr->appendChild($ntxt);
$element->appendChild($nattr);
}
return $element;
}
public function addSubTreeToPath($path, $subtree){
$this->xpath->evaluate($path)->item(0)->appendChild($subtree);
}
public function addMessage($type, $message){
switch($type){
case "confirmation":
case "notice":
case "warning":
case "error":
$this->addTagToPath("/page/messages", $type, $message); break;
default: throw new Exception("Provided message type '".$type."'doesn't exist!");
}
}
public function redirectPage($pageCode){
//TODO: add a parameter to allow coming back, for example after login
include("pages/".strtolower($pageCode).".inc.php");
$pageObject->addTagToPath("/page", "pagecode", strtolower($pageCode));
return $pageObject;
}
}
?>