PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/js/tiny_mce/plugins/kcfinder/core/autoload.php

https://gitlab.com/ilya.webcity/anna
PHP | 196 lines | 57 code | 26 blank | 113 comment | 12 complexity | a3852493edfaa4803d95ddcb5cccbfad MD5 | raw file
  1. <?php
  2. /** This file is part of KCFinder project
  3. *
  4. * @desc This file is included first, before each other
  5. * @package KCFinder
  6. * @version 2.52-dev
  7. * @author Pavel Tzonkov <pavelc@users.sourceforge.net>
  8. * @copyright 2010, 2011 KCFinder Project
  9. * @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2
  10. * @license http://www.opensource.org/licenses/lgpl-2.1.php LGPLv2
  11. * @link http://kcfinder.sunhater.com
  12. *
  13. * This file is the place you can put any code (at the end of the file),
  14. * which will be executed before any other. Suitable for:
  15. * 1. Set PHP ini settings using ini_set()
  16. * 2. Custom session save handler with session_set_save_handler()
  17. * 3. Any custom integration code. If you use any global variables
  18. * here, they can be accessed in config.php via $GLOBALS array.
  19. * It's recommended to use constants instead.
  20. */
  21. // PHP VERSION CHECK
  22. if (substr(PHP_VERSION, 0, strpos(PHP_VERSION, '.')) < 5)
  23. die("You are using PHP " . PHP_VERSION . " when KCFinder require at least version 5! Some systems has an option to change the active PHP version. Please refer to your hosting provider or upgrade your PHP distribution.");
  24. // SAFE MODE CHECK
  25. if (ini_get("safe_mode"))
  26. die("The \"safe_mode\" PHP ini setting is turned on! You cannot run KCFinder in safe mode.");
  27. // CMS INTEGRATION
  28. if (isset($_GET['cms'])) {
  29. switch ($_GET['cms']) {
  30. case "drupal": require "integration/drupal.php";
  31. }
  32. }
  33. // MAGIC AUTOLOAD CLASSES FUNCTION
  34. function __autoload($class) {
  35. if ($class == "uploader")
  36. require "core/uploader.php";
  37. elseif ($class == "browser")
  38. require "core/browser.php";
  39. elseif (file_exists("core/types/$class.php"))
  40. require "core/types/$class.php";
  41. elseif (file_exists("lib/class_$class.php"))
  42. require "lib/class_$class.php";
  43. elseif (file_exists("lib/helper_$class.php"))
  44. require "lib/helper_$class.php";
  45. }
  46. // json_encode() IMPLEMENTATION IF JSON EXTENSION IS MISSING
  47. if (!function_exists("json_encode")) {
  48. function kcfinder_json_string_encode($string) {
  49. return '"' .
  50. str_replace('/', "\\/",
  51. str_replace("\t", "\\t",
  52. str_replace("\r", "\\r",
  53. str_replace("\n", "\\n",
  54. str_replace('"', "\\\"",
  55. str_replace("\\", "\\\\",
  56. $string)))))) . '"';
  57. }
  58. function json_encode($data) {
  59. if (is_array($data)) {
  60. $ret = array();
  61. // OBJECT
  62. if (array_keys($data) !== range(0, count($data) - 1)) {
  63. foreach ($data as $key => $val)
  64. $ret[] = kcfinder_json_string_encode($key) . ':' . json_encode($val);
  65. return "{" . implode(",", $ret) . "}";
  66. // ARRAY
  67. } else {
  68. foreach ($data as $val)
  69. $ret[] = json_encode($val);
  70. return "[" . implode(",", $ret) . "]";
  71. }
  72. // BOOLEAN OR NULL
  73. } elseif (is_bool($data) || ($data === null))
  74. return ($data === null)
  75. ? "null"
  76. : ($data ? "true" : "false");
  77. // FLOAT
  78. elseif (is_float($data))
  79. return rtrim(rtrim(number_format($data, 14, ".", ""), "0"), ".");
  80. // INTEGER
  81. elseif (is_int($data))
  82. return $data;
  83. // STRING
  84. return kcfinder_json_string_encode($data);
  85. }
  86. }
  87. // CUSTOM SESSION SAVE HANDLER CLASS EXAMPLE
  88. //
  89. // Uncomment & edit it if the application you want to integrate with, have
  90. // its own session save handler. It's not even needed to save instances of
  91. // this class in variables. Just add a row:
  92. // new SessionSaveHandler();
  93. // and your handler will rule the sessions ;-)
  94. /*
  95. class SessionSaveHandler {
  96. protected $savePath;
  97. protected $sessionName;
  98. public function __construct() {
  99. session_set_save_handler(
  100. array($this, "open"),
  101. array($this, "close"),
  102. array($this, "read"),
  103. array($this, "write"),
  104. array($this, "destroy"),
  105. array($this, "gc")
  106. );
  107. }
  108. // Open function, this works like a constructor in classes and is
  109. // executed when the session is being opened. The open function expects
  110. // two parameters, where the first is the save path and the second is the
  111. // session name.
  112. public function open($savePath, $sessionName) {
  113. $this->savePath = $savePath;
  114. $this->sessionName = $sessionName;
  115. return true;
  116. }
  117. // Close function, this works like a destructor in classes and is
  118. // executed when the session operation is done.
  119. public function close() {
  120. return true;
  121. }
  122. // Read function must return string value always to make save handler
  123. // work as expected. Return empty string if there is no data to read.
  124. // Return values from other handlers are converted to boolean expression.
  125. // TRUE for success, FALSE for failure.
  126. public function read($id) {
  127. $file = $this->savePath . "/sess_$id";
  128. return (string) @file_get_contents($file);
  129. }
  130. // Write function that is called when session data is to be saved. This
  131. // function expects two parameters: an identifier and the data associated
  132. // with it.
  133. public function write($id, $data) {
  134. $file = $this->savePath . "/sess_$id";
  135. if (false !== ($fp = @fopen($file, "w"))) {
  136. $return = fwrite($fp, $data);
  137. fclose($fp);
  138. return $return;
  139. } else
  140. return false;
  141. }
  142. // The destroy handler, this is executed when a session is destroyed with
  143. // session_destroy() and takes the session id as its only parameter.
  144. public function destroy($id) {
  145. $file = $this->savePath . "/sess_$id";
  146. return @unlink($file);
  147. }
  148. // The garbage collector, this is executed when the session garbage
  149. // collector is executed and takes the max session lifetime as its only
  150. // parameter.
  151. public function gc($maxlifetime) {
  152. foreach (glob($this->savePath . "/sess_*") as $file)
  153. if (filemtime($file) + $maxlifetime < time())
  154. @unlink($file);
  155. return true;
  156. }
  157. }
  158. new SessionSaveHandler();
  159. */
  160. // PUT YOUR ADDITIONAL CODE HERE
  161. ?>