view.class.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /*
  3. * This file is part of MODX Revolution.
  4. *
  5. * Copyright (c) MODX, LLC. All Rights Reserved.
  6. *
  7. * For complete copyright and license information, see the COPYRIGHT and LICENSE
  8. * files found in the top-level directory of this distribution.
  9. */
  10. /**
  11. * Loads the view context preview page.
  12. *
  13. * @package modx
  14. * @subpackage manager.controllers
  15. */
  16. class ContextViewManagerController extends modManagerController {
  17. public $contextKey = '';
  18. /**
  19. * Check for any permissions or requirements to load page
  20. * @return bool
  21. */
  22. public function checkPermissions() {
  23. return $this->modx->hasPermission('view_context');
  24. }
  25. /**
  26. * Register custom CSS/JS for the page
  27. * @return void
  28. */
  29. public function loadCustomCssJs() {
  30. $this->addHtml("<script>
  31. Ext.onReady(function() {
  32. MODx.load({
  33. xtype: 'page-context-view'
  34. ,key: MODx.request.key
  35. });
  36. });</script>");
  37. }
  38. /**
  39. * Custom logic code here for setting placeholders, etc
  40. * @param array $scriptProperties
  41. * @return mixed
  42. */
  43. public function process(array $scriptProperties = array()) {
  44. /* get context by key */
  45. $context= $this->modx->getObjectGraph('modContext', '{"ContextSettings":{}}', $scriptProperties['key']);
  46. if ($context == null) {
  47. return $this->failure($this->modx->lexicon('context_with_key_not_found',array('key' => $scriptProperties['key'])));
  48. }
  49. if (!$context->checkPolicy('view')) return $this->failure($this->modx->lexicon('permission_denied'));
  50. /* prepare context data for display */
  51. if (!$context->prepare()) {
  52. return $this->failure($this->modx->lexicon('context_err_load_data'), $context->toArray());
  53. }
  54. /* assign context and display */
  55. $placeholders = array();
  56. $placeholders['context'] = $context;
  57. $placeholders['_ctx'] = $context->get('key');
  58. $this->contextKey = $context->get('key');
  59. return $this->modx->smarty->fetch('context/view.tpl');
  60. }
  61. /**
  62. * Return the pagetitle
  63. *
  64. * @return string
  65. */
  66. public function getPageTitle() {
  67. return $this->modx->lexicon('context').': '.$this->contextKey;
  68. }
  69. /**
  70. * Return the location of the template file
  71. * @return string
  72. */
  73. public function getTemplateFile() {
  74. return 'context/view.tpl';
  75. }
  76. /**
  77. * Specify the language topics to load
  78. * @return array
  79. */
  80. public function getLanguageTopics() {
  81. return array('context');
  82. }
  83. /**
  84. * Get the Help URL
  85. * @return string
  86. */
  87. public function getHelpUrl() {
  88. return 'Contexts';
  89. }
  90. }