PageRenderTime 35ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/php/lib/Gloo/Controller/Post.php

http://webgloo.googlecode.com/
PHP | 150 lines | 87 code | 37 blank | 26 comment | 12 complexity | 6d0884ff070220154ac1d10bd03c66ee MD5 | raw file
  1. <?php
  2. /**
  3. *
  4. *
  5. * @author rajeevj
  6. */
  7. class Gloo_Controller_Post implements Gloo_Controller_IController {
  8. private $token;
  9. private $pageObj;
  10. private $name = '__POST_CONTROLLER__';
  11. function __construct() {
  12. }
  13. function init($params,$options) {
  14. //sanity check
  15. //post controller expects a token parameter
  16. if (!array_key_exists("token", $params)) {
  17. trigger_error(":token parameter not found in Request", E_USER_ERROR);
  18. }
  19. $this->token = $params["token"];
  20. $this->pageObj = NULL ;
  21. }
  22. function setPageObj($pageObj) {
  23. $this->pageObj = $pageObj ;
  24. }
  25. function process() {
  26. $glooWeb = Gloo_Core_Web::getInstance();
  27. $context = $glooWeb->getContext();
  28. if(is_null($this->pageObj)){
  29. $orgId = $context->getOrgId();
  30. $pageDao = new Gloo_Dao_Page();
  31. //POST will fetch pageObj on SEO token
  32. $this->pageObj = $pageDao->getOnSeoKey($orgId, $this->token);
  33. }
  34. // SEO tweak
  35. // we do not recognise home page SEO key. This is to ensure that we
  36. // render home page content only from one URI, i.e. /
  37. // attempt to access URI /home will return 404
  38. if (empty($this->pageObj) || $this->pageObj['ident_key'] == Gloo_Constants::HOME_KEY) {
  39. $controller = new Gloo_Controller_Null();
  40. return $controller->process();
  41. }
  42. $this->checkPageLock($context);
  43. $glooOrg = $glooWeb->getRequestAttribute(Gloo_Core_Request::GLOO_ORG);
  44. $title = empty($this->pageObj['title']) ? $this->pageObj['page_name'] :$this->pageObj['title'] ;
  45. //page specific meta tags override org level
  46. $metaTags = empty($this->pageObj['meta_tags']) ? $glooOrg['seo_meta'] : $this->pageObj['meta_tags'] ;
  47. $glooWeb->setRequestAttribute(Gloo_Core_Request::PAGE_TITLE, $title);
  48. $glooWeb->setRequestAttribute(Gloo_Core_Request::PAGE_META_TAGS, $metaTags);
  49. $context->setPageKey($this->token);
  50. //imp: put modified context back in page
  51. $glooWeb->setContext($context);
  52. //load data for blocks
  53. $glooWeb->loadPageViewData($this->pageObj['org_id'], $this->pageObj['ident_key']);
  54. $layoutDao = new Gloo_Dao_Layout();
  55. $buffer = $layoutDao->render($glooWeb->getRequestAttribute(Gloo_Core_Request::GLOO_ORG));
  56. return $buffer;
  57. }
  58. function processCommand($command) {
  59. $buffer = '';
  60. if ($command instanceof Gloo_Command_Include) {
  61. $buffer = $this->processIncludeCommand($command->getAttributes());
  62. } else {
  63. trigger_error($this->name . " can not process " . $command->getName(), E_USER_ERROR);
  64. }
  65. return $buffer;
  66. }
  67. /*
  68. * command specific content processing. $controller is set inside $web inside index.php
  69. * after URL routing is done. This callback is used by INCLUDE command via
  70. * $web->$controller
  71. *
  72. */
  73. private function processIncludeCommand($attribs) {
  74. if (empty($this->pageObj)) {
  75. trigger_error('Page object can not be null', E_USER_ERROR);
  76. exit(1);
  77. }
  78. $location = new location();
  79. $file = $location->INC_WIDGET_LIST;
  80. $blockWidth = $attribs['width'];
  81. $startIndex = $attribs['index'];
  82. ob_start();
  83. include ($file);
  84. $buffer = ob_get_contents();
  85. ob_end_clean();
  86. return $buffer;
  87. }
  88. function __toString() {
  89. return $this->name;
  90. }
  91. function checkPageLock($context) {
  92. $pageKey = $this->pageObj['seo_key'];
  93. $isLocked = intval($this->pageObj['is_locked']) ;
  94. //page locked
  95. if($isLocked == 1) {
  96. //password in DB
  97. $pwdInDB = $this->pageObj['password'];
  98. //page password typed by user
  99. $pwdInContext = $context->getLockPassword($pageKey);
  100. //lock if passwords do not match
  101. if(strcmp($pwdInContext,$pwdInDB) != 0) {
  102. //redirect to password input page
  103. $params = array(
  104. 'page_key' => Gloo_Util::base64Encrypt($pageKey),
  105. 'page_uri' => Gloo_Util::base64Encrypt($_SERVER['REQUEST_URI']));
  106. $location = url::link('/ca/page/keyin.php',$params);
  107. header('Location: '.$location);
  108. exit(0);
  109. }
  110. }
  111. }
  112. }
  113. ?>