/php/lib/Gloo/Controller/Post.php
PHP | 150 lines | 87 code | 37 blank | 26 comment | 12 complexity | 6d0884ff070220154ac1d10bd03c66ee MD5 | raw file
- <?php
- /**
- *
- *
- * @author rajeevj
- */
- class Gloo_Controller_Post implements Gloo_Controller_IController {
- private $token;
- private $pageObj;
- private $name = '__POST_CONTROLLER__';
- function __construct() {
-
- }
- function init($params,$options) {
- //sanity check
- //post controller expects a token parameter
- if (!array_key_exists("token", $params)) {
- trigger_error(":token parameter not found in Request", E_USER_ERROR);
- }
- $this->token = $params["token"];
- $this->pageObj = NULL ;
- }
- function setPageObj($pageObj) {
- $this->pageObj = $pageObj ;
- }
-
- function process() {
-
- $glooWeb = Gloo_Core_Web::getInstance();
- $context = $glooWeb->getContext();
- if(is_null($this->pageObj)){
- $orgId = $context->getOrgId();
- $pageDao = new Gloo_Dao_Page();
- //POST will fetch pageObj on SEO token
- $this->pageObj = $pageDao->getOnSeoKey($orgId, $this->token);
- }
-
- // SEO tweak
- // we do not recognise home page SEO key. This is to ensure that we
- // render home page content only from one URI, i.e. /
- // attempt to access URI /home will return 404
-
- if (empty($this->pageObj) || $this->pageObj['ident_key'] == Gloo_Constants::HOME_KEY) {
- $controller = new Gloo_Controller_Null();
- return $controller->process();
- }
-
- $this->checkPageLock($context);
-
- $glooOrg = $glooWeb->getRequestAttribute(Gloo_Core_Request::GLOO_ORG);
- $title = empty($this->pageObj['title']) ? $this->pageObj['page_name'] :$this->pageObj['title'] ;
- //page specific meta tags override org level
- $metaTags = empty($this->pageObj['meta_tags']) ? $glooOrg['seo_meta'] : $this->pageObj['meta_tags'] ;
-
- $glooWeb->setRequestAttribute(Gloo_Core_Request::PAGE_TITLE, $title);
- $glooWeb->setRequestAttribute(Gloo_Core_Request::PAGE_META_TAGS, $metaTags);
-
- $context->setPageKey($this->token);
- //imp: put modified context back in page
- $glooWeb->setContext($context);
- //load data for blocks
- $glooWeb->loadPageViewData($this->pageObj['org_id'], $this->pageObj['ident_key']);
-
- $layoutDao = new Gloo_Dao_Layout();
- $buffer = $layoutDao->render($glooWeb->getRequestAttribute(Gloo_Core_Request::GLOO_ORG));
-
- return $buffer;
- }
-
- function processCommand($command) {
- $buffer = '';
- if ($command instanceof Gloo_Command_Include) {
- $buffer = $this->processIncludeCommand($command->getAttributes());
- } else {
- trigger_error($this->name . " can not process " . $command->getName(), E_USER_ERROR);
- }
- return $buffer;
- }
- /*
- * command specific content processing. $controller is set inside $web inside index.php
- * after URL routing is done. This callback is used by INCLUDE command via
- * $web->$controller
- *
- */
- private function processIncludeCommand($attribs) {
- if (empty($this->pageObj)) {
- trigger_error('Page object can not be null', E_USER_ERROR);
- exit(1);
- }
-
- $location = new location();
- $file = $location->INC_WIDGET_LIST;
- $blockWidth = $attribs['width'];
- $startIndex = $attribs['index'];
- ob_start();
- include ($file);
- $buffer = ob_get_contents();
- ob_end_clean();
- return $buffer;
- }
- function __toString() {
- return $this->name;
- }
- function checkPageLock($context) {
-
- $pageKey = $this->pageObj['seo_key'];
- $isLocked = intval($this->pageObj['is_locked']) ;
-
- //page locked
- if($isLocked == 1) {
- //password in DB
- $pwdInDB = $this->pageObj['password'];
- //page password typed by user
- $pwdInContext = $context->getLockPassword($pageKey);
- //lock if passwords do not match
- if(strcmp($pwdInContext,$pwdInDB) != 0) {
- //redirect to password input page
- $params = array(
- 'page_key' => Gloo_Util::base64Encrypt($pageKey),
- 'page_uri' => Gloo_Util::base64Encrypt($_SERVER['REQUEST_URI']));
- $location = url::link('/ca/page/keyin.php',$params);
- header('Location: '.$location);
- exit(0);
- }
- }
- }
-
- }
- ?>