data.class.php 5.0 KB

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