OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / scripts / kcfinder-2.51 / core / autoload.php
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 // ########## Magic3アクセス制御(開始) ##########
23 require_once('../../include/global.php');
24
25 if (!$gAccessManager->loginedByUser()){         // ログイン中のユーザはアクセスを許可
26         echo 'Access error: access denied.';
27
28         $gOpeLogManager->writeUserAccess(__METHOD__, 'ファイルブラウザへの不正なアクセスを検出しました。ログインなし', 3001, 'アクセスをブロックしました。');
29         exit(0);
30 }
31 // ########## Magic3アクセス制御(終了) ##########
32
33 // PHP VERSION CHECK
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.");
36
37
38 // GD EXTENSION CHECK
39 if (!function_exists("imagecopyresampled"))
40     die("The GD PHP extension is not available! It's required to run KCFinder.");
41
42
43 // SAFE MODE CHECK
44 if (ini_get("safe_mode"))
45     die("The \"safe_mode\" PHP ini setting is turned on! You cannot run KCFinder in safe mode.");
46
47
48 // CMS INTEGRATION
49 if (isset($_GET['cms'])) {
50     switch ($_GET['cms']) {
51         case "drupal": require "integration/drupal.php";
52     }
53 }
54
55
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";
68 }
69
70
71 // json_encode() IMPLEMENTATION IF JSON EXTENSION IS MISSING
72 if (!function_exists("json_encode")) {
73
74     function kcfinder_json_string_encode($string) {
75         return '"' .
76             str_replace('/', "\\/",
77             str_replace("\t", "\\t",
78             str_replace("\r", "\\r",
79             str_replace("\n", "\\n",
80             str_replace('"', "\\\"",
81             str_replace("\\", "\\\\",
82         $string)))))) . '"';
83     }
84
85     function json_encode($data) {
86
87         if (is_array($data)) {
88             $ret = array();
89
90             // OBJECT
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) . "}";
95
96             // ARRAY
97             } else {
98                 foreach ($data as $val)
99                     $ret[] = json_encode($val);
100                 return "[" . implode(",", $ret) . "]";
101             }
102
103         // BOOLEAN OR NULL
104         } elseif (is_bool($data) || ($data === null))
105             return ($data === null)
106                 ? "null"
107                 : ($data ? "true" : "false");
108
109         // FLOAT
110         elseif (is_float($data))
111             return rtrim(rtrim(number_format($data, 14, ".", ""), "0"), ".");
112
113         // INTEGER
114         elseif (is_int($data))
115             return $data;
116
117         // STRING
118         return kcfinder_json_string_encode($data);
119     }
120 }
121
122
123 // CUSTOM SESSION SAVE HANDLER CLASS EXAMPLE
124 //
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 ;-)
130
131 /*
132 class SessionSaveHandler {
133     protected $savePath;
134     protected $sessionName;
135
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"),
143             array($this, "gc")
144         );
145     }
146
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
150     // session name.
151     public function open($savePath, $sessionName) {
152         $this->savePath = $savePath;
153         $this->sessionName = $sessionName;
154         return true;
155     }
156
157     // Close function, this works like a destructor in classes and is
158     // executed when the session operation is done.
159     public function close() {
160         return true;
161     }
162
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);
170     }
171
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
174     // with it.
175     public function write($id, $data) {
176         $file = $this->savePath . "/sess_$id";
177         if (false !== ($fp = @fopen($file, "w"))) {
178             $return = fwrite($fp, $data);
179             fclose($fp);
180             return $return;
181         } else
182             return false;
183     }
184
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);
190     }
191
192     // The garbage collector, this is executed when the session garbage
193     // collector is executed and takes the max session lifetime as its only
194     // parameter.
195     public function gc($maxlifetime) {
196         foreach (glob($this->savePath . "/sess_*") as $file)
197             if (filemtime($file) + $maxlifetime < time())
198                 @unlink($file);
199         return true;
200     }
201 }
202
203 new SessionSaveHandler();
204
205 */
206
207
208 // PUT YOUR ADDITIONAL CODE HERE
209
210 ?>