public static function getContext() { if (self::$context === null) { self::$context = new self(); } return self::$context; }
public function login($redirectTo) { $roles = func_get_args(); array_shift($roles); $this->authenticate($roles[0]); if (($c = count($roles)) > 1) { for ($i = 1; $i < $c; $i++) { $this->addRole($roles[$i]); } } if ($response = Sabel_Context::getResponse()) { $backUri = null; if ($request = Sabel_Context::getRequest()) { $backUri = $request->getValueWithMethod("back_uri"); } if ($backUri === null) { $response->getRedirector()->to($redirectTo); } else { l("ACL: back to the page before authentication.", SBL_LOG_DEBUG); $response->getRedirector()->uri($backUri); } } $this->remove("login_uri"); $this->remove("back_uri"); }
protected function routing($config) { $request = new Sabel_Request_Object("index/index"); $config->configure(); $candidate = $config->getValidCandidate($request->getUri()); Sabel_Context::getContext()->setCandidate($candidate); }
protected function setUri($uri) { $bus = Sabel_Context::getContext()->getBus(); if (is_object($bus) && ($request = $bus->get("request"))) { $request->setUri($uri); } $_SERVER["REQUEST_URI"] = $uri; }
/** * HTTP Redirect to another location with uri. * * @param string $uriParameter * @param array $parameters * * @return void */ public function to($uriParameter, $parameters = array()) { $context = Sabel_Context::getContext(); $uri = $context->getCandidate()->uri($uriParameter); if ($this->parameters = $parameters) { $uri .= "?" . http_build_query($this->parameters, "", "&"); } return $this->uri($uri); }
function linkto($file) { if ($bus = Sabel_Context::getContext()->getBus()) { if ($bus->get("NO_VIRTUAL_HOST")) { return dirname($_SERVER["SCRIPT_NAME"]) . "/" . $file; } } return "/" . $file; }
public function testCreateDevelopmentCandidate() { $bus = $this->bus; $bus->set("request", new Sabel_Request_Object("devel/main/index/db")); $processor = new Processor_Router("router"); $processor->execute($bus); $candidate = Sabel_Context::getContext()->getCandidate(); $this->assertTrue($candidate instanceof Sabel_Map_Candidate); $this->assertEquals("devel", $candidate->getName()); $this->assertEquals("db", $bus->get("request")->fetchParameterValue("param")); }
public function partial($name, $assign = array()) { $bus = Sabel_Context::getContext()->getBus(); $view = $bus->get("view"); if (($template = $view->getValidLocation($name)) !== null) { $responses = array_merge($bus->get("response")->getResponses(), $assign); $contents = $template->getContents(); return $this->rendering($contents, $responses, $template->getPath()); } else { throw new Sabel_Exception_Runtime("template is not found."); } }
protected function getRequestUri() { if (class_exists("Sabel_Context", false)) { $bus = Sabel_Context::getContext()->getBus(); if (is_object($bus) && ($request = $bus->get("request"))) { return "/" . $request->getUri(); } } if (isset($_SERVER["REQUEST_URI"])) { return "/" . normalize_uri($_SERVER["REQUEST_URI"]); } else { return "/"; } }
public function execute(Sabel_Bus $bus) { $request = $bus->get("request"); $config = $bus->getConfig("map"); $config->configure(); if ($candidate = $config->getValidCandidate($request->getUri())) { $request->setParameterValues(array_map("urldecode", $candidate->getUriParameters())); $destination = $candidate->getDestination(); l("DESTINATION: " . $destination); $bus->set("destination", $destination); Sabel_Context::getContext()->setCandidate($candidate); } else { $message = __METHOD__ . "() didn't match to any routing configuration."; throw new Sabel_Exception_Runtime($message); } }
public function afterAction($bus) { $response = $bus->get("response"); $response->setResponses(array_merge($response->getResponses(), $bus->get("controller")->getAttributes())); if ($response->getStatus()->isServerError()) { $exception = Sabel_Context::getContext()->getException(); if (!is_object($exception)) { return; } $eol = (ENVIRONMENT & DEVELOPMENT) > 0 ? "<br />" : PHP_EOL; $msg = get_class($exception) . ": " . $exception->getMessage() . $eol . "At: " . date("r") . $eol . $eol . Sabel_Exception_Printer::printTrace($exception, $eol, true); if ((ENVIRONMENT & PRODUCTION) > 0) { } else { $response->setResponse("exception_message", $msg); } l(PHP_EOL . str_replace("<br />", PHP_EOL, $msg), SBL_LOG_ERR); } }
public function execute($bus) { $response = $bus->get("response"); $status = $response->getStatus(); $controller = $bus->get("controller"); if ($response->isFailure() || $response->isRedirected()) { return; } $action = $bus->get("destination")->getAction(); $controller->setAction($action); if ($isAjax = $bus->get("AJAX_REQUEST")) { $controller->setAttribute("ajax", new AjaxResult()); } $controller->setAttribute("submenu", new Views_Submenu()); try { $controller->initialize(); if ($response->isSuccess() && !$response->isRedirected()) { $controller->execute(); } $controller->finalize(); if ($isAjax && $response->isFailure()) { $status->setCode(Sabel_Response::OK); $controller->ajax->code = $status->getCode(); } } catch (Exception_UserNotFound $unf) { if ($isAjax) { $controller->ajax->code = Sabel_Response::NOT_FOUND; } else { $status->setCode(Sabel_Response::NOT_FOUND); } Sabel_Context::getContext()->setException($e); } catch (Exception $e) { if ($isAjax) { $controller->ajax->code = Sabel_Response::INTERNAL_SERVER_ERROR; } else { $status->setCode(Sabel_Response::INTERNAL_SERVER_ERROR); } Sabel_Context::getContext()->setException($e); } if ($controller->getAttribute("layout") === false) { $bus->set("NO_LAYOUT", true); } }
public function execute(Sabel_Bus $bus) { $response = $bus->get("response"); $controller = $bus->get("controller"); if ($response->isFailure() || $response->isRedirected()) { return; } $action = $bus->get("destination")->getAction(); $controller->setAction($action); try { $controller->initialize(); if ($response->isSuccess() && !$response->isRedirected()) { $controller->execute(); } $controller->finalize(); } catch (Exception $e) { $response->getStatus()->setCode(Sabel_Response::INTERNAL_SERVER_ERROR); Sabel_Context::getContext()->setException($e); } if ($controller->getAttribute("layout") === false) { $bus->set("NO_LAYOUT", true); } }
/** * create uri */ function uri($param, $secure = false, $absolute = false) { $context = Sabel_Context::getContext(); $prefix = get_uri_prefix($secure, $absolute); return $prefix . "/" . $context->getCandidate()->uri($param); }
/** * create uri */ function uri($uri, $secure = false, $absolute = false) { $context = Sabel_Context::getContext(); return get_uri_prefix($secure, $absolute) . "/" . $context->getCandidate()->uri($uri); }
public function __construct() { $this->processorList = new Sabel_Util_HashList(); Sabel_Context::getContext()->setBus($this); }
/** * HTTP Redirect to another location with uri. * * @param string $uri * @param array $parameters * @param string $flagment * * @return string */ public function to($uri, $parameters = array(), $flagment = "") { $context = Sabel_Context::getContext(); return $this->uri($context->getCandidate()->uri($uri), $parameters, $flagment); }
public function build($limit, array $getValues = array()) { $page = 1; $pageKey = $this->attributes["pageKey"]; if (isset($getValues[$pageKey])) { $page = $getValues[$pageKey]; if (!is_numeric($page) || $page < 1) { $page = 1; } } $model = $this->model; $attributes =& $this->attributes; $uriQuery = array(); foreach ($getValues as $key => $val) { if ($key === $pageKey) { unset($getValues[$key]); } elseif (is_array($val)) { foreach ($val as $k => $v) { $uriQuery[] = urlencode("{$key}[{$k}]") . "=" . urlencode($v); } } else { $uriQuery[] = urlencode($key) . "=" . urlencode($val); } } $attributes["uriQuery"] = implode("&", $uriQuery); $count = $this->isJoin ? $model->getCount(null, false) : $model->getCount(); $attributes["count"] = $count; $attributes["limit"] = $limit; $attributes["page"] = $page; $pager = new Sabel_View_Pager($count, $limit); $pager->setPageNumber($page); $attributes["viewer"] = new Sabel_View_PageViewer($pager); if ($count === 0) { $attributes["offset"] = 0; $attributes["results"] = array(); } else { $offset = $pager->getSqlOffset(); $this->_setOrderBy($getValues); $model->setLimit($limit); $model->setOffset($offset); $attributes["offset"] = $offset; $attributes["results"] = $model->{$this->method}(); if ($this->uri === null && ($request = Sabel_Context::getRequest())) { $attributes["uri"] = get_uri_prefix() . "/" . $request->getUri(); } } return $this; }
//require ("Sabel" . DIRECTORY_SEPARATOR . "Sabel.php"); require RUN_BASE . DIRECTORY_SEPARATOR . "Sabel" . DIRECTORY_SEPARATOR . "Sabel.php"; require RUN_BASE . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "INIT.php"; require RUN_BASE . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "environment.php"; if (!defined("ENVIRONMENT")) { echo "SABEL FATAL ERROR: must define ENVIRONMENT in config/environment.php"; exit; } if ((ENVIRONMENT & PRODUCTION) > 0) { Sabel::init(); $out = Sabel_Bus::create()->run(new Config_Bus()); Sabel::shutdown(); } else { $out = Sabel_Bus::create()->run(new Config_Bus()); } if (Sabel_Context::getContext()->getBus()->get("AJAX_REQUEST")) { echo $out; exit; } $root =& XCube_Root::getSingleton(); $target =& $root->mContext->mModule->getRenderTarget(); $target->setResult($out); $target->setAttribute('legacy_buffertype', null); $theme =& $root->mController->_mStrategy->getMainThemeObject(); $renderSystem =& $root->getRenderSystem($theme->get('render_system')); $renderSystem->_commonPrepareRender(); if (isset($GLOBALS['xoopsUserIsAdmin'])) { $renderSystem->mXoopsTpl->assign('xoops_isadmin', $GLOBALS['xoopsUserIsAdmin']); } $renderSystem->mXoopsTpl->assign('xoops_block_header', ''); $renderSystem->mXoopsTpl->assign('xoops_module_header', '');
public function __construct() { $this->imanage = Sabel_Context::getContext()->getBus()->get("imanage"); }
protected function getBus() { return Sabel_Context::getContext()->getBus(); }