PageRenderTime 33ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Backend/Core/Js/ckfinder/core/connector/php/php5/CommandHandler/Init.php

http://github.com/forkcms/forkcms
PHP | 172 lines | 102 code | 20 blank | 50 comment | 22 complexity | ca9c7f583b296d908b030a4795f25aad MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, MIT, AGPL-3.0, LGPL-2.1, BSD-3-Clause
  1. <?php
  2. /*
  3. * CKFinder
  4. * ========
  5. * http://cksource.com/ckfinder
  6. * Copyright (C) 2007-2014, CKSource - Frederico Knabben. All rights reserved.
  7. *
  8. * The software, this file and its contents are subject to the CKFinder
  9. * License. Please read the license.txt file before using, installing, copying,
  10. * modifying or distribute this file or part of its contents. The contents of
  11. * this file is part of the Source Code of CKFinder.
  12. */
  13. if (!defined('IN_CKFINDER')) exit;
  14. /**
  15. * @package CKFinder
  16. * @subpackage CommandHandlers
  17. * @copyright CKSource - Frederico Knabben
  18. */
  19. /**
  20. * Include base XML command handler
  21. */
  22. require_once CKFINDER_CONNECTOR_LIB_DIR . "/CommandHandler/XmlCommandHandlerBase.php";
  23. /**
  24. * Handle Init command
  25. *
  26. * @package CKFinder
  27. * @subpackage CommandHandlers
  28. * @copyright CKSource - Frederico Knabben
  29. */
  30. class CKFinder_Connector_CommandHandler_Init extends CKFinder_Connector_CommandHandler_XmlCommandHandlerBase
  31. {
  32. /**
  33. * Command name
  34. *
  35. * @access private
  36. * @var string
  37. */
  38. private $command = "Init";
  39. protected function mustCheckRequest()
  40. {
  41. return false;
  42. }
  43. /**
  44. * Must add CurrentFolder node?
  45. *
  46. * @return boolean
  47. * @access protected
  48. */
  49. protected function mustAddCurrentFolderNode()
  50. {
  51. return false;
  52. }
  53. /**
  54. * handle request and build XML
  55. * @access protected
  56. *
  57. */
  58. protected function buildXml()
  59. {
  60. $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
  61. // Create the "ConnectorInfo" node.
  62. $_oConnInfo = new Ckfinder_Connector_Utils_XmlNode("ConnectorInfo");
  63. $this->_connectorNode->addChild($_oConnInfo);
  64. $_oConnInfo->addAttribute("enabled", $_config->getIsEnabled() ? "true" : "false");
  65. if (!$_config->getIsEnabled()) {
  66. $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_CONNECTOR_DISABLED);
  67. }
  68. $_ln = '' ;
  69. $_lc = $_config->getLicenseKey() . ' ' ;
  70. $pos = strpos( CKFINDER_CHARS, $_lc[0] ) % 5;
  71. if ( $pos == 1 || $pos == 4 ) {
  72. $_ln = $_config->getLicenseName() ;
  73. }
  74. $_oConnInfo->addAttribute("s", $_ln);
  75. $_oConnInfo->addAttribute("c", trim( $_lc[11] . $_lc[0] . $_lc [8] . $_lc[12] . $_lc[26] . $_lc[2] . $_lc[3] . $_lc[25] . $_lc[1] ));
  76. $_thumbnailsConfig = $_config->getThumbnailsConfig();
  77. $_thumbnailsEnabled = $_thumbnailsConfig->getIsEnabled() ;
  78. $_oConnInfo->addAttribute("thumbsEnabled", $_thumbnailsEnabled ? "true" : "false");
  79. if ($_thumbnailsEnabled) {
  80. $_oConnInfo->addAttribute("thumbsUrl", $_thumbnailsConfig->getUrl());
  81. $_oConnInfo->addAttribute("thumbsDirectAccess", $_thumbnailsConfig->getDirectAccess() ? "true" : "false" );
  82. $_oConnInfo->addAttribute("thumbsWidth", $_thumbnailsConfig->getMaxWidth());
  83. $_oConnInfo->addAttribute("thumbsHeight", $_thumbnailsConfig->getMaxHeight());
  84. }
  85. $_imagesConfig = $_config->getImagesConfig();
  86. $_oConnInfo->addAttribute("imgWidth", $_imagesConfig->getMaxWidth());
  87. $_oConnInfo->addAttribute("imgHeight", $_imagesConfig->getMaxHeight());
  88. // Create the "ResourceTypes" node.
  89. $_oResourceTypes = new Ckfinder_Connector_Utils_XmlNode("ResourceTypes");
  90. $this->_connectorNode->addChild($_oResourceTypes);
  91. // Create the "PluginsInfo" node.
  92. $_oPluginsInfo = new Ckfinder_Connector_Utils_XmlNode("PluginsInfo");
  93. $this->_connectorNode->addChild($_oPluginsInfo);
  94. // Load the resource types in an array.
  95. $_aTypes = $_config->getDefaultResourceTypes();
  96. if (!sizeof($_aTypes)) {
  97. $_aTypes = $_config->getResourceTypeNames();
  98. }
  99. $_aTypesSize = sizeof($_aTypes);
  100. if ($_aTypesSize) {
  101. $phpMaxSize = 0;
  102. $max_upload = CKFinder_Connector_Utils_Misc::returnBytes(ini_get('upload_max_filesize'));
  103. if ($max_upload) {
  104. $phpMaxSize = $max_upload;
  105. }
  106. $max_post = CKFinder_Connector_Utils_Misc::returnBytes(ini_get('post_max_size'));
  107. if ($max_post) {
  108. $phpMaxSize = $phpMaxSize ? min($phpMaxSize, $max_post) : $max_post;
  109. }
  110. //ini_get('memory_limit') only works if compiled with "--enable-memory-limit"
  111. $memory_limit = CKFinder_Connector_Utils_Misc::returnBytes(@ini_get('memory_limit'));
  112. if ($memory_limit && $memory_limit != -1) {
  113. $phpMaxSize = $phpMaxSize ? min($phpMaxSize, $memory_limit) : $memory_limit;
  114. }
  115. $_oConnInfo->addAttribute("uploadMaxSize", $phpMaxSize);
  116. $_oConnInfo->addAttribute("uploadCheckImages", $_config->checkSizeAfterScaling() ? "false" : "true");
  117. for ($i = 0; $i < $_aTypesSize; $i++)
  118. {
  119. $_resourceTypeName = $_aTypes[$i];
  120. $_acl = $_config->getAccessControlConfig();
  121. $_aclMask = $_acl->getComputedMask($_resourceTypeName, "/");
  122. if ( ($_aclMask & CKFINDER_CONNECTOR_ACL_FOLDER_VIEW) != CKFINDER_CONNECTOR_ACL_FOLDER_VIEW ) {
  123. continue;
  124. }
  125. if (!isset($_GET['type']) || $_GET['type'] === $_resourceTypeName) {
  126. //print $_resourceTypeName;
  127. $_oTypeInfo = $_config->getResourceTypeConfig($_resourceTypeName);
  128. //print_r($_oTypeInfo);
  129. $_oResourceType[$i] = new Ckfinder_Connector_Utils_XmlNode("ResourceType");
  130. $_oResourceTypes->addChild($_oResourceType[$i]);
  131. $_oResourceType[$i]->addAttribute("name", $_resourceTypeName);
  132. $_oResourceType[$i]->addAttribute("url", $_oTypeInfo->getUrl());
  133. $_oResourceType[$i]->addAttribute("allowedExtensions", implode(",", $_oTypeInfo->getAllowedExtensions()));
  134. $_oResourceType[$i]->addAttribute("deniedExtensions", implode(",", $_oTypeInfo->getDeniedExtensions()));
  135. $_oResourceType[$i]->addAttribute("hash", $_oTypeInfo->getHash());
  136. $_oResourceType[$i]->addAttribute("hasChildren", CKFinder_Connector_Utils_FileSystem::hasChildren('/', $_oTypeInfo) ? "true" : "false");
  137. $_oResourceType[$i]->addAttribute("acl", $_aclMask);
  138. $maxSize = $_oTypeInfo->getMaxSize();
  139. if ($phpMaxSize) {
  140. $maxSize = $maxSize ? min($maxSize, $phpMaxSize) : $phpMaxSize;
  141. }
  142. $_oResourceType[$i]->addAttribute("maxSize", $maxSize);
  143. }
  144. }
  145. }
  146. $config = $GLOBALS['config'];
  147. if (!empty($config['Plugins']) && is_array($config['Plugins']) ) {
  148. $_oConnInfo->addAttribute("plugins", implode(",", $config['Plugins']));
  149. }
  150. CKFinder_Connector_Core_Hooks::run('InitCommand', array(&$this->_connectorNode));
  151. }
  152. }