PageRenderTime 27ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/storecommander/ead6f6fce09/SC/lib/js/ckeditor/kcfinder/integration/drupal.php

https://gitlab.com/ptisky/API_prestashop
PHP | 134 lines | 70 code | 23 blank | 41 comment | 21 complexity | fad6f2e9506c688dcf24572dde4b6ce4 MD5 | raw file
  1. <?php
  2. /**
  3. * Store Commander
  4. *
  5. * @category administration
  6. * @author Store Commander - support@storecommander.com
  7. * @version 2015-09-15
  8. * @uses Prestashop modules
  9. * @since 2009
  10. * @copyright Copyright &copy; 2009-2015, Store Commander
  11. * @license commercial
  12. * All rights reserved! Copying, duplication strictly prohibited
  13. *
  14. * *****************************************
  15. * * STORE COMMANDER *
  16. * * http://www.StoreCommander.com *
  17. * * V 2015-09-15 *
  18. * *****************************************
  19. *
  20. * Compatibility: PS version: 1.1 to 1.6.1
  21. *
  22. **/
  23. /** This file is part of KCFinder project
  24. *
  25. * @desc CMS integration code: Drupal
  26. * @package KCFinder
  27. * @version 3.12
  28. * @author Dany Alejandro Cabrera <otello2040@gmail.com>
  29. * @copyright 2010-2014 KCFinder Project
  30. * @license http://opensource.org/licenses/GPL-3.0 GPLv3
  31. * @license http://opensource.org/licenses/LGPL-3.0 LGPLv3
  32. * @link http://kcfinder.sunhater.com
  33. */
  34. // gets a valid drupal_path
  35. function get_drupal_path() {
  36. if (!empty($_SERVER['SCRIPT_FILENAME'])) {
  37. $drupal_path = dirname(dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME']))));
  38. if (!file_exists($drupal_path . '/includes/bootstrap.inc')) {
  39. $drupal_path = dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME'])));
  40. $depth = 2;
  41. do {
  42. $drupal_path = dirname($drupal_path);
  43. $depth++;
  44. } while (!($bootstrap_file_found = file_exists($drupal_path . '/includes/bootstrap.inc')) && $depth < 10);
  45. }
  46. }
  47. if (!isset($bootstrap_file_found) || !$bootstrap_file_found) {
  48. $drupal_path = '../../../../..';
  49. if (!file_exists($drupal_path . '/includes/bootstrap.inc')) {
  50. $drupal_path = '../..';
  51. do {
  52. $drupal_path .= '/..';
  53. $depth = substr_count($drupal_path, '..');
  54. } while (!($bootstrap_file_found = file_exists($drupal_path . '/includes/bootstrap.inc')) && $depth < 10);
  55. }
  56. }
  57. return $drupal_path;
  58. }
  59. function CheckAuthentication($drupal_path) {
  60. static $authenticated;
  61. if (!isset($authenticated)) {
  62. if (!isset($bootstrap_file_found) || $bootstrap_file_found) {
  63. $current_cwd = getcwd();
  64. if (!defined('DRUPAL_ROOT')){
  65. define('DRUPAL_ROOT', $drupal_path);
  66. }
  67. // Simulate being in the drupal root folder so we can share the session
  68. chdir(DRUPAL_ROOT);
  69. global $base_url;
  70. $base_root = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http';
  71. $base_url = $base_root .= '://'. preg_replace('/[^a-z0-9-:._]/i', '', $_SERVER['HTTP_HOST']);
  72. if ($dir = trim(dirname($_SERVER['SCRIPT_NAME']), '\,/')) {
  73. $base_path = "/$dir";
  74. $base_url .= $base_path;
  75. }
  76. // correct base_url so it points to Drupal root
  77. $pos = strpos($base_url, '/sites/');
  78. $base_url = substr($base_url, 0, $pos); // drupal root absolute url
  79. // If we aren't in a Drupal installation, or if Drupal path hasn't been properly found, die
  80. if(!file_exists(DRUPAL_ROOT . '/includes/bootstrap.inc')) {
  81. die("The CMS integration service for -drupal- requires KCFinder to be properly placed inside your Drupal installation.");
  82. }
  83. // bootstrap
  84. require_once(DRUPAL_ROOT . '/includes/bootstrap.inc');
  85. drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
  86. // if user has access permission...
  87. if (user_access('access kcfinder')) {
  88. if (!isset($_SESSION['KCFINDER'])) {
  89. $_SESSION['KCFINDER'] = array();
  90. $_SESSION['KCFINDER']['disabled'] = false;
  91. }
  92. // User has permission, so make sure KCFinder is not disabled!
  93. if(!isset($_SESSION['KCFINDER']['disabled'])) {
  94. $_SESSION['KCFINDER']['disabled'] = false;
  95. }
  96. global $user;
  97. $_SESSION['KCFINDER']['uploadURL'] = strtr(variable_get('kcfinder_upload_url', 'sites/default/files/kcfinder'), array('%u' => $user->uid, '%n' => $user->name));
  98. $_SESSION['KCFINDER']['uploadDir'] = strtr(variable_get('kcfinder_upload_dir', ''), array('%u' => $user->uid, '%n' => $user->name));
  99. $_SESSION['KCFINDER']['theme'] = variable_get('kcfinder_theme', 'oxygen');
  100. //echo '<br />uploadURL: ' . $_SESSION['KCFINDER']['uploadURL']<br />;
  101. //echo '<br />uploadDir: ' . $_SESSION['KCFINDER']['uploadDir']<br />;
  102. chdir($current_cwd);
  103. return true;
  104. }
  105. chdir($current_cwd);
  106. return false;
  107. }
  108. }
  109. }
  110. CheckAuthentication(get_drupal_path());
  111. ?>