view.class.php 2.5 KB

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