/pimcore/modules/extensionmanager/controllers/DownloadController.php

https://github.com/timglabisch/pimcore · PHP · 196 lines · 134 code · 44 blank · 18 comment · 22 complexity · 652ef7090f6f66c3e7ecb5fbe94674e3 MD5 · raw file

  1. <?php
  2. /**
  3. * Pimcore
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://www.pimcore.org/license
  11. *
  12. * @copyright Copyright (c) 2009-2013 pimcore GmbH (http://www.pimcore.org)
  13. * @license http://www.pimcore.org/license New BSD License
  14. */
  15. class Extensionmanager_DownloadController extends Pimcore_Controller_Action_Admin {
  16. public function init () {
  17. parent::init();
  18. $this->checkPermission("plugins");
  19. }
  20. public function getExtensionsAction () {
  21. // plugins
  22. $pluginConfigs = Pimcore_ExtensionManager::getPluginConfigs();
  23. // get remote repo state of plugins
  24. $remoteConfig = array();
  25. foreach ($pluginConfigs as $config) {
  26. $remoteConfig["extensions"][] = array(
  27. "id" => $config["plugin"]["pluginName"],
  28. "type" => "plugin"
  29. );
  30. }
  31. $brickConfigs = Pimcore_ExtensionManager::getBrickConfigs();
  32. // get repo state of bricks
  33. foreach ($brickConfigs as $id => $config) {
  34. $remoteConfig["extensions"][] = array(
  35. "id" => $id,
  36. "type" => "brick"
  37. );
  38. }
  39. $remoteConfig["token"] = Pimcore_Liveconnect::getToken();
  40. $rawData = Pimcore_Tool::getHttpData("http://extensions.pimcore.org/download/getExtensions.php", null, array("data" => base64_encode(Pimcore_Tool_Serialize::serialize($remoteConfig))));
  41. if(!$rawData) {
  42. header('HTTP/1.1 403 Forbidden');
  43. exit;
  44. }
  45. echo $rawData;
  46. exit;
  47. }
  48. public function getDownloadInformationAction () {
  49. $id = $this->getParam("id");
  50. $type = $this->getParam("type");
  51. $remoteConfig = array(
  52. "token" => Pimcore_Liveconnect::getToken(),
  53. "id" => $id,
  54. "type" => $type
  55. );
  56. $rawData = Pimcore_Tool::getHttpData("http://extensions.pimcore.org/download/getDownloadInformation.php", null, array("data" => base64_encode(Pimcore_Tool_Serialize::serialize($remoteConfig))));
  57. if(!$rawData) {
  58. header('HTTP/1.1 403 Forbidden');
  59. exit;
  60. }
  61. $steps[] = array(
  62. "action" => "empty-extension-dir",
  63. "params" => array(
  64. "id" => $id,
  65. "type" => $type
  66. )
  67. );
  68. $data = Zend_Json::decode($rawData);
  69. foreach ($data["files"] as $file) {
  70. $steps[] = array(
  71. "action" => "download-file",
  72. "params" => array(
  73. "id" => $id,
  74. "type" => $type,
  75. "path" => $file["path"],
  76. "revision" => $file["revision"]
  77. )
  78. );
  79. }
  80. $this->_helper->json(array("steps" => $steps));
  81. }
  82. public function downloadFileAction () {
  83. $id = $this->getParam("id");
  84. $type = $this->getParam("type");
  85. $path = $this->getParam("path");
  86. $revision = $this->getParam("revision");
  87. $remoteConfig = $this->getAllParams();
  88. $remoteConfig["token"] = Pimcore_Liveconnect::getToken();
  89. $rawData = Pimcore_Tool::getHttpData("http://extensions.pimcore.org/download/downloadFile.php?data=" . base64_encode(Pimcore_Tool_Serialize::serialize($remoteConfig)));
  90. if(!$rawData) {
  91. header('HTTP/1.1 403 Forbidden');
  92. exit;
  93. }
  94. $file = Zend_Json::decode($rawData);
  95. if($type == "plugin") {
  96. $parentPath = PIMCORE_PLUGINS_PATH;
  97. } else if ($type == "brick") {
  98. $parentPath = PIMCORE_WEBSITE_VAR . "/areas";
  99. }
  100. if(!is_dir($parentPath)) {
  101. mkdir($parentPath, 0755, true);
  102. }
  103. $fileDestPath = $parentPath . $path;
  104. if(!is_dir(dirname($fileDestPath))) {
  105. mkdir(dirname($fileDestPath), 0755, true);
  106. }
  107. file_put_contents($fileDestPath, base64_decode($file["content"]));
  108. chmod($fileDestPath, 0766);
  109. // write revision information
  110. $revisionFile = $parentPath . "/" . $id . "/.pimcore_extension_revision";
  111. file_put_contents($revisionFile, $revision);
  112. chmod($revisionFile, 0766);
  113. $this->_helper->json(array("success" => true));
  114. }
  115. public function deleteAction () {
  116. $id = $this->getParam("id");
  117. $type = $this->getParam("type");
  118. $path = $this->getParam("path");
  119. $revision = $this->getParam("revision");
  120. if($type == "plugin") {
  121. $parentPath = PIMCORE_PLUGINS_PATH;
  122. } else if ($type == "brick") {
  123. $parentPath = PIMCORE_WEBSITE_VAR . "/areas";
  124. }
  125. if(!is_dir($parentPath)) {
  126. mkdir($parentPath, 0755, true);
  127. }
  128. $fileDestPath = $parentPath . $path;
  129. if(!is_dir(dirname($fileDestPath))) {
  130. mkdir(dirname($fileDestPath), 0755, true);
  131. }
  132. @unlink($fileDestPath);
  133. // write revision information
  134. $revisionFile = $parentPath . "/" . $id . "/.pimcore_extension_revision";
  135. file_put_contents($revisionFile, $revision);
  136. chmod($revisionFile, 0766);
  137. $this->_helper->json(array("success" => true));
  138. }
  139. public function emptyExtensionDirAction () {
  140. $id = $this->getParam("id");
  141. $type = $this->getParam("type");
  142. if($type == "plugin") {
  143. $extensionPath = PIMCORE_PLUGINS_PATH . "/" . $id;
  144. } else if ($type = "brick") {
  145. $extensionPath = PIMCORE_WEBSITE_VAR . "/areas/" . $id;
  146. }
  147. if(is_dir($extensionPath)) {
  148. recursiveDelete($extensionPath,true);
  149. }
  150. $this->_helper->json(array("success" => true));
  151. }
  152. }