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