_layout}"; } //-------------------------------------------- // Return this text in plain format to the // browser and stop page execution. //-------------------------------------------- function informationPage($message) { echo $message; exit(); } //-------------------------------------------- // Return some text in plain format. //-------------------------------------------- function informationText($message) { return gettext($message); } function getBreadCrumbs() { $it = &new FAArrayIterator($this->_pages); return $it; } //-------------------------------------------- // Get the path of the referring page from the // session history object. //-------------------------------------------- function popReferer() { $reg = &$this->getRegistry(); $sess = &$reg->get('session'); $history = &$sess->get('referers'); $path = '/'; if($history) { $page = &$history->prevPage(); if($page) { $path = $page->getPath(); } } return $path; } //-------------------------------------------- // Check if "XMLHttpRequest" is in the X-Requested-With // HTTP header. //-------------------------------------------- function checkXHR() { /*$reg = &$this->getRegistry(); $headers = &$reg->get('headers'); if(strtolower($headers->get('X-Requested-With')) != 'xmlhttprequest') { trigger_error("[ERROR] Invalid request method.", E_USER_ERROR); exit(); }*/ } //-------------------------------------------- // Check a given permission and display the perms // required page if the user doesn't meet them. //-------------------------------------------- function checkPerm($object, $perm, &$reg, &$req, &$resp) { $info = &new InformationDisplay($reg, $req, $resp); $user = &$reg->get('user'); if(!$user->canDo($perm, $object)) { $info->display('permsRequired'); } } //-------------------------------------------- // Make sure a user is logged in. //-------------------------------------------- function checkLogin(&$reg, &$req, &$resp) { $user = &$reg->get('user'); $info = &new InformationDisplay($reg, $req, $resp); if(!$user->isMember()) { $info->display("loginRequired"); } } //-------------------------------------------- // Redirect to the page that refered us here. //-------------------------------------------- function popPage() { $this->redirect($this->popReferer(), TRUE); } //-------------------------------------------- // Redirect to another page based on a given path. //-------------------------------------------- function redirect($path, $full = FALSE) { $reg = &$this->getRegistry(); if (!$full) { //$path = 'http://' . $this->getHost() . dirname($_SERVER['SCRIPT_NAME']) .'/'. $reg->get('k4_base_url') . $path; $path = k4_url($path); } // TODO:{[figure out a better way to get/set the base url[redirect[k4PageController} header("Location: $path"); exit(); } //-------------------------------------------- // Get the current host. E.g.: "onelobby.com"/index.php function getHost() { return get_host(); } //-------------------------------------------- // Set the page title for a action. //-------------------------------------------- function setPage($title) { $resp = &$this->getResponse(); $resp->assign('page_title', $title); $reg = &$this->getRegistry(); $reg->set('page_title', $title); } //-------------------------------------------- // Import an included PEAR package. //-------------------------------------------- function getPearPackage($name) { $file = K4_BASE_DIR .'/../pear/'. $name .'/'. $name .'.php';; if(file_exists($file) && is_readable($file)) { require_once $file; } else { trigger_error("[ERROR] PEAR Package does not exist."); } } //-------------------------------------------- // Check if a record is cacheable, and if the // cache system is turned on, cache it. //-------------------------------------------- function cacheAble(&$record) { if($record->cacheAble()) { if(K4_BUILD_CACHE) { //-------------------------------------------- // Figure out where we should cache this object. //-------------------------------------------- $class_name = strtolower(get_class($record)); $dir_name = K4_CACHE_DIR .'/'. $class_name; if(!file_exists($dir_name)) { mkdir($dir_name, 0777); @chmod($dir_name, 0777); } //-------------------------------------------- // Whoops! The cache dir isn't writable. //-------------------------------------------- if(!is_writable($dir_name)) { trigger_error("[ERROR] Cache directory $class_name is not writable.", E_USER_ERROR); } $record->cacheObject($dir_name .'/'. $record->getId() .'.php'); exit(); } } } } ?>