filemanager.config.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * CKEditor - The text editor for the Internet - http://ckeditor.com
  4. * Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
  5. *
  6. * == BEGIN LICENSE ==
  7. *
  8. * Licensed under the terms of any of the following licenses of your
  9. * choice:
  10. *
  11. * - GNU General Public License Version 2 or later (the "GPL")
  12. * http://www.gnu.org/licenses/gpl.html
  13. *
  14. * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
  15. * http://www.gnu.org/licenses/lgpl.html
  16. *
  17. * - Mozilla Public License Version 1.1 or later (the "MPL")
  18. * http://www.mozilla.org/MPL/MPL-1.1.html
  19. *
  20. * == END LICENSE ==
  21. *
  22. * @file
  23. * CKEditor Module for Drupal 7.x
  24. *
  25. * This file is required by the CKEeditor module if you want to enable CKFinder,
  26. * an advanced Ajax file browser.
  27. *
  28. */
  29. $GLOBALS['devel_shutdown'] = FALSE;
  30. if (!function_exists('ob_list_handlers') || ob_list_handlers()) {
  31. @ob_end_clean();
  32. }
  33. $ckfinder_user_files_path = '';
  34. $ckfinder_user_files_absolute_path = '';
  35. function CheckAuthentication() {
  36. static $authenticated;
  37. if (!isset($authenticated)) {
  38. if (!empty($_SERVER['SCRIPT_FILENAME'])) {
  39. $drupal_path = dirname(dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME']))));
  40. if (!file_exists($drupal_path . '/includes/bootstrap.inc')) {
  41. $drupal_path = dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME'])));
  42. $depth = 2;
  43. do {
  44. $drupal_path = dirname($drupal_path);
  45. $depth++;
  46. } while (!($bootstrap_file_found = file_exists($drupal_path . '/includes/bootstrap.inc')) && $depth < 10);
  47. }
  48. }
  49. if (!isset($bootstrap_file_found) || !$bootstrap_file_found) {
  50. $drupal_path = '../../../../..';
  51. if (!file_exists($drupal_path . '/includes/bootstrap.inc')) {
  52. $drupal_path = '../..';
  53. do {
  54. $drupal_path .= '/..';
  55. $depth = substr_count($drupal_path, '..');
  56. } while (!($bootstrap_file_found = file_exists($drupal_path . '/includes/bootstrap.inc')) && $depth < 10);
  57. }
  58. }
  59. if (!isset($bootstrap_file_found) || $bootstrap_file_found) {
  60. $current_cwd = getcwd();
  61. chdir($drupal_path);
  62. if (!defined('DRUPAL_ROOT')) {
  63. define('DRUPAL_ROOT', $drupal_path);
  64. }
  65. require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
  66. drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
  67. $authenticated = user_access('allow CKFinder file uploads');
  68. if (isset($_GET['id'], $_SESSION['ckeditor'][$_GET['id']]['UserFilesPath'], $_SESSION['ckeditor'][$_GET['id']]['UserFilesAbsolutePath'])) {
  69. $_SESSION['ckeditor']['UserFilesPath'] = $_SESSION['ckeditor'][$_GET['id']]['UserFilesPath'];
  70. $_SESSION['ckeditor']['UserFilesAbsolutePath'] = $_SESSION['ckeditor'][$_GET['id']]['UserFilesAbsolutePath'];
  71. }
  72. chdir($current_cwd);
  73. }
  74. }
  75. return $authenticated;
  76. }
  77. CheckAuthentication();
  78. if (isset($_SESSION['ckeditor']['UserFilesPath'], $_SESSION['ckeditor']['UserFilesAbsolutePath'])) {
  79. $baseUrl = $_SESSION['ckeditor']['UserFilesPath'];
  80. // To deal with multiple application servers it's better to let CKFinder guess the server path based on the URL,
  81. // because the server side path changes on each request (#2127467).
  82. if (isset($_SERVER['PANTHEON_ENVIRONMENT'])) {
  83. $baseDir = resolveUrl($baseUrl);
  84. }
  85. else {
  86. $baseDir = $_SESSION['ckeditor']['UserFilesAbsolutePath'];
  87. }
  88. }
  89. else {
  90. // Nothing in session? Shouldn't happen... anyway let's try to upload it in the (almost) right place
  91. // Path to user files relative to the document root.
  92. $baseUrl = strtr(base_path(), array(
  93. '/modules/ckeditor/ckfinder/core/connector/php' => '',
  94. )) . variable_get('file_private_path', conf_path() . '/files') . '/';
  95. $baseDir = resolveUrl($baseUrl);
  96. }