setHistory(); $tr = new PHPTAL_GetTextTranslator(); $ud = $user->getDetails(); $this->userlanguage = $ud->getLanguage(); $this->assisted = $ud->getAssisted(); $this->animated = $ud->getAnimated(); $language = constant('LOCALE_'.$this->getUserLanguage()); $tr->setLanguage($language.DEFAULT_ENCODING, $language.DEFAULT_ENCODING); $tr->addDomain('krihvel', 'i18n'); $tr->useDomain('krihvel'); $this->translator = $tr; $ddname = dirname(dirname(__FILE__)); require_once($ddname."/skins/".SKIN."/template.php"); $this->template = new Template($this); } function finalize() { $licence = new PHPTAL(); $licence->setTemplateRepository('skins/'.SKIN.'/templates/'); $licence->setTemplate("licences.html"); $licence->setTranslator($this->getTranslator()); $this->out("footer", $licence->execute(), true); $this->template->finalize(); } function __destruct() { $this->template->flush(); } function out($section, $message, $replace=false) { $this->template->out($section, $message, $replace); } function isAnon() { if ( !isset($_SESSION['logged_in'])) { return True; } if ( $_SESSION['logged_in'] ) { return False; } else { return True; } } function getAnimated() { if ($this->animated) { return "_animated"; } return ""; } function getAssisted() { if ($this->assisted) { return "assisted_"; } return ""; } function getSeason() { $month = date('n'); if (in_array($month, array(1,2,12))) { return "_winter"; } return "_spring"; } function getTranslator() { return $this->translator; } function getUserLanguage() { return $this->userlanguage; } function getUserLanguageSuffix() { $suffix = $this->getUserLanguage(); if ($suffix) { return "_".$suffix; } return false; } function getCurrPage() { return $this->currObj; } function setCurrPage($obj) { $this->currObj = $obj; } function getHistory() { if (!isset($_SESSION['krihvel_history'])) { $_SESSION['krihvel_history'] = array(false); } if (!isset($_SESSION['krihvel_history_page'])) { $last = array_slice($_SESSION['krihvel_history'], -1, 1); return $last[0]; } else if ($_SESSION['krihvel_history_page'] >=0 && $_SESSION['krihvel_history_page'] < count($_SESSION['krihvel_history'])) { return $_SESSION['krihvel_history'][$_SESSION['krihvel_history_page']]; } return "?".$_SERVER['QUERY_STRING']; } function setHistory() { if (!$this->isAnon()) { if (!isset($_SESSION['krihvel_history'])){ $_SESSION['krihvel_history'] = array(false); } if (!isset($_SESSION['krihvel_history_page'])){ $_SESSION['krihvel_history_page'] = count($_SESSION['krihvel_history']); } if (isset($_GET['back'])) { if ($_SESSION['krihvel_history_page']>0) { $_SESSION['krihvel_history_page']--; } } else { if (count($_SESSION['krihvel_history'])>10) { array_shift($_SESSION['krihvel_history']); } if ($_SESSION['krihvel_history_page']<9) { $_SESSION['krihvel_history_page']++; } $_SESSION['krihvel_history'] []= "?".$_SERVER['QUERY_STRING']; } } } /* * 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_func(array($obj, $vmeth)); 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 $kdb, $user; if ( is_numeric($rid) || $rid=="new" ) { if ( $rid == "new" ) { if ( !isset($_GET['type']) ) { return 2; } $type = $_GET['type']; } else { $type = $kdb->getResourceTypeByRID($rid); } $typeDesc = $kdb->getType($type); //_load_file($typeDesc['pluginid'], $typeDesc['file']); $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->setKrihvel($this); $x->setDB($kdb); $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; } $template = new PHPTAL(); //$template->setTemplateRepository('plugins/'.$x->getType().'/templates/'); $template->setTemplateRepository('plugins/'.$typeDesc['pluginID'].'/templates/'); $this->out("debug", "Adding template repo: ".'plugins/'.$typeDesc['pluginID'].'/templates/'); $template->setTemplateRepository('skins/'.SKIN.'/templates/'); $kala = $x->getType()."_".$mode.'.html'; if ( $this->getModeAnnotation() ) { if ( $this->getModeAnnotation()->template ) { $kala = $this->getModeAnnotation()->template; } } $template->setTemplate($kala); $this->out("debug", "Trying template: ".$kala); $template->here = $x; $template->user = $user; $template->krihvel = $this; $template->setTranslator($this->getTranslator()); $templ = "Lehe näitamisel tekkis viga, sest sa tahtsid häkkida - ära palun häki!"; try { $templ = $template->execute(); } catch (Exception $e) { if ( DEV_MODE ){ print $e; } } if (!$user->hasRole('anonymous')) { if ($x->getType() == "link") { $elem = "
"; $this->out("leftmenu", $elem); } $elem = " "; $this->out("leftmenu", $elem); } $this->out("helplink", $x->getType(), true); $this->out("popup", $templ); $x->addJS(); $x->addCSS(); return 0; } return 1; } function showPage($id, $ovmode=null) { global $user, $kdb; $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->setKrihvel($this); $o->setDB($kdb); $o->setUser($user); $refl = new ReflectionAnnotatedClass($o); $secCheck = $this->checkPermissions($refl, $o, $origMode); if ( $secCheck ) { return 1; } $this->setCurrPage($o); $template = new PHPTAL(); $template->setTemplateRepository('plugins/'.$p['pluginID'].'/templates/'); $template->setTemplateRepository('skins/'.SKIN.'/templates/'); //$template->setTemplateRepository('help/'); $umodetempl = $id."_".$origMode.".html"; if ( in_array($id, array("MyFolder", "Folder")) && $user->getDetails()->getTablesView() ) { $umodetempl = "Folder_table.html"; } //$umodetempl = $id."_".$origMode.".html"; $template->setTemplate($umodetempl); $template->user = $user; $template->krihvel = $this; $template->pid = $id; $this->out("helplink", $id, true); $template->here = $o; $template->setTranslator($this->getTranslator()); try { $this->out("debug", "Trying template: ".$umodetempl); $templ = $template->execute(); if ( method_exists($o, "getOutput") ) { $this->out($o->getOutput(), $templ); } else { $this->out("popup", $templ); } if ( method_exists($o, "addJS") ) { $o->addJS(); } if ( method_exists($o, "addCSS") ) { $o->addCSS(); } } catch (Exception $e) { if (DEV_MODE) { print $e; } if ( method_exists($o, $umode) ) { call_user_func(array($o, $umode)); } } } else { if (DEV_MODE) { print $id; } //die('error 51'); } } 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; } } $krihvel = new Krihvel(); $krihvel->finalize(); ?>