data.class.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. require_once dirname(__FILE__).'/resource.class.php';
  11. /**
  12. * Loads the resource data page
  13. *
  14. * @package modx
  15. * @subpackage manager.controllers
  16. */
  17. class ResourceDataManagerController extends ResourceManagerController {
  18. /** @var modResource $resource */
  19. public $resource;
  20. /** @var string $previewUrl */
  21. public $previewUrl;
  22. /**
  23. * Check for any permissions or requirements to load page
  24. * @return bool
  25. */
  26. public function checkPermissions() {
  27. return $this->modx->hasPermission('view_document');
  28. }
  29. /**
  30. * Register custom CSS/JS for the page
  31. * @return void
  32. */
  33. public function loadCustomCssJs() {
  34. $mgrUrl = $this->modx->getOption('manager_url',null,MODX_MANAGER_URL);
  35. $this->addJavascript($mgrUrl.'assets/modext/widgets/system/modx.grid.manager.log.js');
  36. $this->addJavascript($mgrUrl.'assets/modext/widgets/resource/modx.panel.resource.data.js');
  37. $this->addJavascript($mgrUrl.'assets/modext/sections/resource/data.js');
  38. $this->addHtml('
  39. <script type="text/javascript">
  40. // <![CDATA[
  41. Ext.onReady(function() {
  42. MODx.ctx = "'.$this->resource->get('context_key').'";
  43. MODx.load({
  44. xtype: "modx-page-resource-data"
  45. ,record: {
  46. id: "'.$this->resource->get('id').'"
  47. ,context_key: "'.$this->resource->get('context_key').'"
  48. ,class_key: "'.$this->resource->get('class_key').'"
  49. ,pagetitle: "'.$this->resource->get('pagetitle').'"
  50. ,preview_url: "'.$this->previewUrl.'"
  51. }
  52. ,canEdit: "'.($this->modx->hasPermission('edit_document') ? 1 : 0).'"
  53. });
  54. });
  55. // ]]>
  56. </script>');
  57. }
  58. /**
  59. * Custom logic code here for setting placeholders, etc
  60. * @param array $scriptProperties
  61. * @return mixed
  62. */
  63. public function process(array $scriptProperties = array()) {
  64. $placeholders = array();
  65. if (empty($scriptProperties['id']) || strlen($scriptProperties['id']) !== strlen((integer)$scriptProperties['id'])) {
  66. return $this->failure($this->modx->lexicon('resource_err_nf'));
  67. }
  68. $this->resource = $this->modx->getObject('modResource', array('id' => $scriptProperties['id']));
  69. if ($this->resource == null) return $this->failure(sprintf($this->modx->lexicon('resource_with_id_not_found'), $scriptProperties['id']));
  70. if (!$this->resource->checkPolicy('view')) return $this->failure($this->modx->lexicon('access_denied'));
  71. $this->resource->getOne('CreatedBy');
  72. $this->resource->getOne('EditedBy');
  73. $this->resource->getOne('Template');
  74. $server_offset_time= intval($this->modx->getOption('server_offset_time',null,0));
  75. $this->resource->set('createdon_adjusted',strftime('%c', $this->resource->get('createdon') + $server_offset_time));
  76. $this->resource->set('editedon_adjusted',strftime('%c', $this->resource->get('editedon') + $server_offset_time));
  77. $this->resource->_contextKey= $this->resource->get('context_key');
  78. $buffer = $this->modx->cacheManager->get($this->resource->getCacheKey(), array(
  79. xPDO::OPT_CACHE_KEY => $this->modx->getOption('cache_resource_key', null, 'resource'),
  80. xPDO::OPT_CACHE_HANDLER => $this->modx->getOption('cache_resource_handler', null, $this->modx->getOption(xPDO::OPT_CACHE_HANDLER)),
  81. xPDO::OPT_CACHE_FORMAT => (integer) $this->modx->getOption('cache_resource_format', null, $this->modx->getOption(xPDO::OPT_CACHE_FORMAT, null, xPDOCacheManager::CACHE_PHP)),
  82. ));
  83. if ($buffer) {
  84. $placeholders['buffer'] = htmlspecialchars($buffer['resource']['_content']);
  85. }
  86. /* assign resource to smarty */
  87. $placeholders['resource'] = $this->resource;
  88. /* make preview url */
  89. $this->getPreviewUrl();
  90. $placeholders['_ctx'] = $this->resource->get('context_key');
  91. return $placeholders;
  92. }
  93. /**
  94. * @return string
  95. */
  96. public function getPreviewUrl() {
  97. $this->previewUrl = $this->modx->makeUrl($this->resource->get('id'),$this->resource->get('context_key'));
  98. return $this->previewUrl;
  99. }
  100. /**
  101. * Return the pagetitle
  102. *
  103. * @return string
  104. */
  105. public function getPageTitle() {
  106. if ($this->resource) {
  107. return $this->resource->get('pagetitle');
  108. }
  109. }
  110. /**
  111. * Return the location of the template file
  112. * @return string
  113. */
  114. public function getTemplateFile() {
  115. return '';
  116. }
  117. /**
  118. * Specify the language topics to load
  119. * @return array
  120. */
  121. public function getLanguageTopics() {
  122. return array('resource');
  123. }
  124. /**
  125. * Get the Help URL
  126. * @return string
  127. */
  128. public function getHelpUrl() {
  129. return 'Resources';
  130. }
  131. public function firePreRenderEvents() {
  132. return;
  133. }
  134. public function fireOnRenderEvent() {
  135. return;
  136. }
  137. public function fireOnTVFormRender() {
  138. return;
  139. }
  140. public function loadRichTextEditor() {
  141. }
  142. }