3 /** This file is part of KCFinder project
5 * @desc This file is included first, before each other
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
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.
22 // ########## Magic3アクセス制御(開始) ##########
23 require_once('../../include/global.php');
25 if (!$gAccessManager->loginedByUser()){ // ログイン中のユーザはアクセスを許可
26 echo 'Access error: access denied.';
28 $gOpeLogManager->writeUserAccess(__METHOD__, 'ファイルブラウザへの不正なアクセスを検出しました。ログインなし', 3001, 'アクセスをブロックしました。');
31 // ########## Magic3アクセス制御(終了) ##########
34 if (substr(PHP_VERSION, 0, strpos(PHP_VERSION, '.')) < 5)
35 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.");
39 if (!function_exists("imagecopyresampled"))
40 die("The GD PHP extension is not available! It's required to run KCFinder.");
44 if (ini_get("safe_mode"))
45 die("The \"safe_mode\" PHP ini setting is turned on! You cannot run KCFinder in safe mode.");
49 if (isset($_GET['cms'])) {
50 switch ($_GET['cms']) {
51 case "drupal": require "integration/drupal.php";
56 // MAGIC AUTOLOAD CLASSES FUNCTION
57 function __autoload($class) {
58 if ($class == "uploader")
59 require "core/uploader.php";
60 elseif ($class == "browser")
61 require "core/browser.php";
62 elseif (file_exists("core/types/$class.php"))
63 require "core/types/$class.php";
64 elseif (file_exists("lib/class_$class.php"))
65 require "lib/class_$class.php";
66 elseif (file_exists("lib/helper_$class.php"))
67 require "lib/helper_$class.php";
71 // json_encode() IMPLEMENTATION IF JSON EXTENSION IS MISSING
72 if (!function_exists("json_encode")) {
74 function kcfinder_json_string_encode($string) {
76 str_replace('/', "\\/",
77 str_replace("\t", "\\t",
78 str_replace("\r", "\\r",
79 str_replace("\n", "\\n",
80 str_replace('"', "\\\"",
81 str_replace("\\", "\\\\",
85 function json_encode($data) {
87 if (is_array($data)) {
91 if (array_keys($data) !== range(0, count($data) - 1)) {
92 foreach ($data as $key => $val)
93 $ret[] = kcfinder_json_string_encode($key) . ':' . json_encode($val);
94 return "{" . implode(",", $ret) . "}";
98 foreach ($data as $val)
99 $ret[] = json_encode($val);
100 return "[" . implode(",", $ret) . "]";
104 } elseif (is_bool($data) || ($data === null))
105 return ($data === null)
107 : ($data ? "true" : "false");
110 elseif (is_float($data))
111 return rtrim(rtrim(number_format($data, 14, ".", ""), "0"), ".");
114 elseif (is_int($data))
118 return kcfinder_json_string_encode($data);
123 // CUSTOM SESSION SAVE HANDLER CLASS EXAMPLE
125 // Uncomment & edit it if the application you want to integrate with, have
126 // its own session save handler. It's not even needed to save instances of
127 // this class in variables. Just add a row:
128 // new SessionSaveHandler();
129 // and your handler will rule the sessions ;-)
132 class SessionSaveHandler {
134 protected $sessionName;
136 public function __construct() {
137 session_set_save_handler(
138 array($this, "open"),
139 array($this, "close"),
140 array($this, "read"),
141 array($this, "write"),
142 array($this, "destroy"),
147 // Open function, this works like a constructor in classes and is
148 // executed when the session is being opened. The open function expects
149 // two parameters, where the first is the save path and the second is the
151 public function open($savePath, $sessionName) {
152 $this->savePath = $savePath;
153 $this->sessionName = $sessionName;
157 // Close function, this works like a destructor in classes and is
158 // executed when the session operation is done.
159 public function close() {
163 // Read function must return string value always to make save handler
164 // work as expected. Return empty string if there is no data to read.
165 // Return values from other handlers are converted to boolean expression.
166 // TRUE for success, FALSE for failure.
167 public function read($id) {
168 $file = $this->savePath . "/sess_$id";
169 return (string) @file_get_contents($file);
172 // Write function that is called when session data is to be saved. This
173 // function expects two parameters: an identifier and the data associated
175 public function write($id, $data) {
176 $file = $this->savePath . "/sess_$id";
177 if (false !== ($fp = @fopen($file, "w"))) {
178 $return = fwrite($fp, $data);
185 // The destroy handler, this is executed when a session is destroyed with
186 // session_destroy() and takes the session id as its only parameter.
187 public function destroy($id) {
188 $file = $this->savePath . "/sess_$id";
189 return @unlink($file);
192 // The garbage collector, this is executed when the session garbage
193 // collector is executed and takes the max session lifetime as its only
195 public function gc($maxlifetime) {
196 foreach (glob($this->savePath . "/sess_*") as $file)
197 if (filemtime($file) + $maxlifetime < time())
203 new SessionSaveHandler();
208 // PUT YOUR ADDITIONAL CODE HERE