getDetails()->getLanguage()); $tr->setLanguage($language.DEFAULT_ENCODING, $language.DEFAULT_ENCODING); $tr->addDomain('tops', 'i18n'); $tr->useDomain('tops'); $this->translator = $tr; $this->template = new PHPTAL(); $this->template->setTemplateRepository('skins/'.SKIN.'/templates/'); $this->skin_url = 'skins/'.SKIN.'/'; $this->template->setTranslator($this->getTranslator()); } function finalize() { $this->template->tops = $this; //header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 //header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past //header("Content-Type: text/html; charset=UTF-8"); print $this->template->execute(); } function __destruct() { //$this->template->flush(); } function isAnon() { if ( !isset($_SESSION['logged_in'])) { return True; } if ( $_SESSION['logged_in'] ) { return False; } else { return True; } } function getTranslator() { return $this->translator; } function getCurrPage() { return $this->currObj; } function setCurrPage($obj) { $this->currObj = $obj; } /* * 0 - access granted * 1 - no access * */ function checkPermissions($refl, $obj, $mode) { if ( $refl->hasAnnotation('Mode') ) { $anns = $refl->getAllAnnotations('Mode'); foreach($anns as $ann) { if ( $ann->mode == $mode ) { global $user; $this->setModeAnnotation($ann); $hasRoles = $user->hasAnyRole($ann->roles); if ( !$hasRoles ) { // doesn't have valid roles. deny. return 4; } if ( $ann->valid ) { foreach ($ann->valid as $vmeth) { if ( method_exists($obj, $vmeth)) { $bol = call_user_method($vmeth, $obj); if ( $bol ) { // validator must return True on success. deny return 3; } } else { // validator doesn't exist. deny. return 2; } } } } } return 0; } else { $par = $refl->getParentClass(); if ( $par ) { return $this->checkPermissions($par, $obj, $mode); } else { return 0; } } } function showObject($rid, $mode) { global $tdb, $user; if ( is_numeric($rid) || $rid=="new" ) { if ( $rid == "new" ) { if ( !isset($_GET['type']) ) { return 2; } $type = $_GET['type']; } else { $type = $tdb->getResourceTypeByRID($rid); } $typeDesc = $tdb->getType($type); $ddname = dirname(dirname(__FILE__)); require_once($ddname."/plugins/".$typeDesc['pluginID']."/".$typeDesc['typeID'].".php"); $x = new $typeDesc['typeID']($rid); $this->setCurrentDataObject($x); $x->setMode($mode); $x->setTops($this); $x->setDB($tdb); $x->setUser($user); $refl = new ReflectionAnnotatedClass($x); $secCheck = $this->checkPermissions($refl, $x, $mode); if ( $secCheck ) { if ( method_exists($x, "validatorFailed") ) { $postV = $x->validatorFailed(); if ( $postV != NULL ) { return $postV; } } return 1; } $this->template->setTemplateRepository('plugins/tops/templates/'); $this->template->setTemplateRepository('plugins/'.$typeDesc['pluginID'].'/templates/'); $kala = $x->getType()."_".$mode.'.html'; if ( $this->getModeAnnotation() ) { if ( $this->getModeAnnotation()->template ) { $kala = $this->getModeAnnotation()->template; } } $this->template->setTemplate($kala); $this->template->here = $x; $this->template->user = $user; $this->finalize(); /*try { $this->finalize(); } catch (Exception $e) { print "malli jama!"; } */ return 0; } return 1; } function showPage($id, $ovmode=null) { global $user, $tdb; $p = _get_page($id); if ( $p != null ) { _load_file($p['pluginID'], $p['pageID']); $o = new $p['pageID'](); $umode = null; $origMode = null; if ( $ovmode == null) { if ( isset($_GET['mode']) ) { $umode = $_GET['mode'].'Content'; $origMode = $_GET['mode']; } } else { $umode = $ovmode.'Content'; $origMode = $ovmode; } if ( $umode == null) { $umode = 'viewContent'; $origMode = "view"; } $o->setMode($origMode); $o->setTops($this); $o->setDB($tdb); $o->setUser($user); $refl = new ReflectionAnnotatedClass($o); $secCheck = $this->checkPermissions($refl, $o, $origMode); if ( $secCheck ) { return 1; } $this->setCurrPage($o); $this->template->setTemplateRepository('plugins/tops/templates/'); $this->template->setTemplateRepository('plugins/'.$p['pluginID'].'/templates/'); $umodetempl = $id."_".$origMode.".html"; $this->template->setTemplate($umodetempl); $this->template->user = $user; $this->template->pid = $id; $this->template->here = $o; $this->finalize(); return 0; } } public function getCurrentDataObject() { return $this->dataObj; } public function setCurrentDataObject($obj) { $this->dataObj = $obj; } public function getModeAnnotation() { return $this->modeAnnotation; } public function setModeAnnotation($val) { $this->modeAnnotation = $val; } } $tops = new Tops(); if ( $tops->isAnon() ) { $tops->showPage("LoginPage", 'view'); } ?>