PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/third_party/kcfinder/core/autoload.php

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