index.class.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 workspace manager
  12. *
  13. * @package modx
  14. * @subpackage manager.controllers
  15. */
  16. class WorkspacesManagerController extends modManagerController {
  17. public $errors = array();
  18. /**
  19. * The template file for this controller
  20. * @var string $templateFile
  21. */
  22. public $templateFile = 'workspaces/index.tpl';
  23. /**
  24. * The ID of the default Provider
  25. * @var int $providerId
  26. */
  27. public $providerId = 1;
  28. /**
  29. * The name of the default Provider
  30. * @var string $providerName
  31. */
  32. public $providerName = 'modx.com';
  33. /**
  34. * Whether or not cURL is enabled on this server
  35. * @var boolean $curlEnabled
  36. */
  37. public $curlEnabled = true;
  38. /**
  39. * Check for any permissions or requirements to load page
  40. * @return bool
  41. */
  42. public function checkPermissions() {
  43. return $this->modx->hasPermission('workspaces');
  44. }
  45. /**
  46. * Register custom CSS/JS for the page
  47. * @return void
  48. */
  49. public function loadCustomCssJs() {
  50. $mgrUrl = $this->modx->getOption('manager_url',null,MODX_MANAGER_URL);
  51. $this->addJavascript($mgrUrl.'assets/modext/core/modx.view.js');
  52. $this->addJavascript($mgrUrl.'assets/modext/workspace/package.browser.tree.js');
  53. $this->addJavascript($mgrUrl.'assets/modext/workspace/package.browser.panels.js');
  54. $this->addJavascript($mgrUrl.'assets/modext/workspace/combos.js');
  55. $this->addJavascript($mgrUrl.'assets/modext/workspace/package.grid.js');
  56. $this->addJavascript($mgrUrl.'assets/modext/workspace/package.windows.js');
  57. $this->addJavascript($mgrUrl.'assets/modext/workspace/package.panels.js');
  58. $this->addJavascript($mgrUrl.'assets/modext/workspace/package.containers.js');
  59. $this->addJavascript($mgrUrl.'assets/modext/workspace/provider.grid.js');
  60. $this->addJavascript($mgrUrl.'assets/modext/workspace/workspace.panel.js');
  61. $this->addJavascript($mgrUrl.'assets/modext/util/lightbox.js');
  62. $this->addHtml("<script>
  63. Ext.onReady(function() {
  64. MODx.errors = ".$this->modx->toJSON($this->errors).";
  65. MODx.defaultProvider = '".$this->providerId."';MODx.provider = '".$this->providerId."';MODx.providerName = '".$this->providerName."';MODx.curlEnabled = ".(integer)$this->curlEnabled."; Ext.ux.Lightbox.register('a.lightbox');
  66. MODx.add('modx-page-workspace');
  67. });</script>");
  68. $this->addJavascript($mgrUrl.'assets/modext/workspace/index.js');
  69. }
  70. /**
  71. * Custom logic code here for setting placeholders, etc
  72. * @param array $scriptProperties
  73. * @return mixed
  74. */
  75. public function process(array $scriptProperties = array()) {
  76. /* ensure directories for Package Management are created */
  77. /** @var modCacheManager $cacheManager */
  78. $cacheManager = $this->modx->getCacheManager();
  79. $directoryOptions = array(
  80. 'new_folder_permissions' => $this->modx->getOption('new_folder_permissions',null,0775),
  81. );
  82. $errors = array();
  83. /* create assets/ */
  84. $assetsPath = $this->modx->getOption('assets_path',null,MODX_ASSETS_PATH);
  85. if (!is_dir($assetsPath)) {
  86. $cacheManager->writeTree($assetsPath,$directoryOptions);
  87. }
  88. if (!is_dir($assetsPath) || !is_writable($assetsPath)) {
  89. $errors[] = $this->modx->lexicon('dir_err_assets',array('path' => $assetsPath));
  90. }
  91. unset($assetsPath);
  92. /* create assets/components/ */
  93. $assetsCompPath = $this->modx->getOption('assets_path',null,MODX_ASSETS_PATH).'components/';
  94. if (!is_dir($assetsCompPath)) {
  95. $cacheManager->writeTree($assetsCompPath,$directoryOptions);
  96. }
  97. if (!is_dir($assetsCompPath) || !is_writable($assetsCompPath)) {
  98. $errors[] = $this->modx->lexicon('dir_err_assets_comp',array('path' => $assetsCompPath));
  99. }
  100. unset($assetsCompPath);
  101. /* create core/components/ */
  102. $coreCompPath = $this->modx->getOption('core_path',null,MODX_CORE_PATH).'components/';
  103. if (!is_dir($coreCompPath)) {
  104. $cacheManager->writeTree($coreCompPath,$directoryOptions);
  105. }
  106. if (!is_dir($coreCompPath) || !is_writable($coreCompPath)) {
  107. $errors[] = $this->modx->lexicon('dir_err_core_comp',array('path' => $coreCompPath));
  108. }
  109. if (!function_exists('curl_init') || !in_array('curl',get_loaded_extensions())) {
  110. $errors[] = $this->modx->lexicon('curl_not_installed');
  111. $this->curlEnabled = false;
  112. }
  113. if (!empty($errors)) {
  114. $this->errors = $errors;
  115. }
  116. $this->getDefaultProvider();
  117. return true;
  118. }
  119. /**
  120. * Get the default Provider for Package Management
  121. *
  122. * @return modTransportProvider|void
  123. */
  124. public function getDefaultProvider() {
  125. $default = $this->modx->getOption('default_provider');
  126. $c = $this->modx->newQuery('transport.modTransportProvider');
  127. if ($default) {
  128. $c->where(array(
  129. 'id' => $default,
  130. ));
  131. } else {
  132. $c->where(array(
  133. 'name:=' => 'modxcms.com',
  134. 'OR:name:=' => 'modx.com',
  135. ));
  136. }
  137. /** @var modTransportProvider $provider */
  138. $provider = $this->modx->getObject('transport.modTransportProvider',$c);
  139. if ($provider) {
  140. $this->providerId = $provider->get('id');
  141. $this->providerName = $provider->get('name');
  142. } else {
  143. $this->modx->log(modX::LOG_LEVEL_ERROR,'Could not find the main provider for some reason with a name of "modx.com". Did you delete it?');
  144. }
  145. return $provider;
  146. }
  147. /**
  148. * Return the pagetitle
  149. *
  150. * @return string
  151. */
  152. public function getPageTitle() {
  153. return $this->modx->lexicon('package_management');
  154. }
  155. /**
  156. * Return the location of the template file
  157. * @return string
  158. */
  159. public function getTemplateFile() {
  160. return $this->templateFile;
  161. }
  162. /**
  163. * Specify the language topics to load
  164. * @return array
  165. */
  166. public function getLanguageTopics() {
  167. return array('workspace','namespace');
  168. }
  169. /**
  170. * Get the Help URL
  171. * @return string
  172. */
  173. public function getHelpUrl() {
  174. return 'Package+Management';
  175. }
  176. }