PageRenderTime 56ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/resources/kcfinder/core/autoload.php

https://github.com/LosYear/FluentCMS
PHP | 202 lines | 93 code | 9 blank | 100 comment | 2 complexity | dfd5d0dadab728b832c2db1a21e81d3a 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.51
  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. // GD EXTENSION CHECK
  25. if (!function_exists("imagecopyresampled"))
  26. die("The GD PHP extension is not available! It's required to run KCFinder.");
  27. // SAFE MODE CHECK
  28. if (ini_get("safe_mode"))
  29. die("The \"safe_mode\" PHP ini setting is turned on! You cannot run KCFinder in safe mode.");
  30. // CMS INTEGRATION
  31. if (isset($_GET['cms'])) {
  32. switch ($_GET['cms']) {
  33. case "drupal": require "integration/drupal.php"; break;
  34. case "yii": require "integration/yii.php"; break;
  35. }
  36. }
  37. // MAGIC AUTOLOAD CLASSES FUNCTION
  38. function __autoload($class) {
  39. if ($class == "uploader")
  40. require "core/uploader.php";
  41. elseif ($class == "browser")
  42. require "core/browser.php";
  43. elseif (file_exists("core/types/$class.php"))
  44. require "core/types/$class.php";
  45. elseif (file_exists("lib/class_$class.php"))
  46. require "lib/class_$class.php";
  47. elseif (file_exists("lib/helper_$class.php"))
  48. require "lib/helper_$class.php";
  49. }
  50. // json_encode() IMPLEMENTATION IF JSON EXTENSION IS MISSING
  51. if (!function_exists("json_encode")) {
  52. function kcfinder_json_string_encode($string) {
  53. return '"' .
  54. str_replace('/', "\\/",
  55. str_replace("\t", "\\t",
  56. str_replace("\r", "\\r",
  57. str_replace("\n", "\\n",
  58. str_replace('"', "\\\"",
  59. str_replace("\\", "\\\\",
  60. $string)))))) . '"';
  61. }
  62. function json_encode($data) {
  63. if (is_array($data)) {
  64. $ret = array();
  65. // OBJECT
  66. if (array_keys($data) !== range(0, count($data) - 1)) {
  67. foreach ($data as $key => $val)
  68. $ret[] = kcfinder_json_string_encode($key) . ':' . json_encode($val);
  69. return "{" . implode(",", $ret) . "}";
  70. // ARRAY
  71. } else {
  72. foreach ($data as $val)
  73. $ret[] = json_encode($val);
  74. return "[" . implode(",", $ret) . "]";
  75. }
  76. // BOOLEAN OR NULL
  77. } elseif (is_bool($data) || ($data === null))
  78. return ($data === null)
  79. ? "null"
  80. : ($data ? "true" : "false");
  81. // FLOAT
  82. elseif (is_float($data))
  83. return rtrim(rtrim(number_format($data, 14, ".", ""), "0"), ".");
  84. // INTEGER
  85. elseif (is_int($data))
  86. return $data;
  87. // STRING
  88. return kcfinder_json_string_encode($data);
  89. }
  90. }
  91. // CUSTOM SESSION SAVE HANDLER CLASS EXAMPLE
  92. //
  93. // Uncomment & edit it if the application you want to integrate with, have
  94. // its own session save handler. It's not even needed to save instances of
  95. // this class in variables. Just add a row:
  96. // new SessionSaveHandler();
  97. // and your handler will rule the sessions ;-)
  98. /*
  99. class SessionSaveHandler {
  100. protected $savePath;
  101. protected $sessionName;
  102. public function __construct() {
  103. session_set_save_handler(
  104. array($this, "open"),
  105. array($this, "close"),
  106. array($this, "read"),
  107. array($this, "write"),
  108. array($this, "destroy"),
  109. array($this, "gc")
  110. );
  111. }
  112. // Open function, this works like a constructor in classes and is
  113. // executed when the session is being opened. The open function expects
  114. // two parameters, where the first is the save path and the second is the
  115. // session name.
  116. public function open($savePath, $sessionName) {
  117. $this->savePath = $savePath;
  118. $this->sessionName = $sessionName;
  119. return true;
  120. }
  121. // Close function, this works like a destructor in classes and is
  122. // executed when the session operation is done.
  123. public function close() {
  124. return true;
  125. }
  126. // Read function must return string value always to make save handler
  127. // work as expected. Return empty string if there is no data to read.
  128. // Return values from other handlers are converted to boolean expression.
  129. // TRUE for success, FALSE for failure.
  130. public function read($id) {
  131. $file = $this->savePath . "/sess_$id";
  132. return (string) @file_get_contents($file);
  133. }
  134. // Write function that is called when session data is to be saved. This
  135. // function expects two parameters: an identifier and the data associated
  136. // with it.
  137. public function write($id, $data) {
  138. $file = $this->savePath . "/sess_$id";
  139. if (false !== ($fp = @fopen($file, "w"))) {
  140. $return = fwrite($fp, $data);
  141. fclose($fp);
  142. return $return;
  143. } else
  144. return false;
  145. }
  146. // The destroy handler, this is executed when a session is destroyed with
  147. // session_destroy() and takes the session id as its only parameter.
  148. public function destroy($id) {
  149. $file = $this->savePath . "/sess_$id";
  150. return @unlink($file);
  151. }
  152. // The garbage collector, this is executed when the session garbage
  153. // collector is executed and takes the max session lifetime as its only
  154. // parameter.
  155. public function gc($maxlifetime) {
  156. foreach (glob($this->savePath . "/sess_*") as $file)
  157. if (filemtime($file) + $maxlifetime < time())
  158. @unlink($file);
  159. return true;
  160. }
  161. }
  162. new SessionSaveHandler();
  163. */
  164. // PUT YOUR ADDITIONAL CODE HERE
  165. ?>