Completed
Push — legacy0716 ( 3b711e )
by Richard
09:56
created

XoopsLoad::loadCore()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 27
Code Lines 17

Duplication

Lines 8
Ratio 29.63 %

Code Coverage

Tests 14
CRAP Score 6.0702

Importance

Changes 0
Metric Value
cc 6
eloc 17
nc 5
nop 1
dl 8
loc 27
ccs 14
cts 16
cp 0.875
crap 6.0702
rs 8.439
c 0
b 0
f 0
1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
12
/**
13
 * Xoops Autoload class
14
 *
15
 * @category  XoopsLoad
16
 * @package   Xoops\Core
17
 * @author    Taiwen Jiang <[email protected]>
18
 * @copyright 2011-2015 XOOPS Project (http://xoops.org)
19
 * @license   GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
20
 * @link      http://xoops.org
21
 * @since     2.3.0
22
 */
23
class XoopsLoad
24
{
25
    /**
26
     * holds classes name and classes paths
27
     *
28
     * @var array
29
     */
30
    protected static $map = array();
31
32
    /**
33
     * Allow modules/preloads/etc to add their own maps
34
     * Use XoopsLoad::addMap(array('classname', 'path/to/class');
35
     *
36
     * @param array $map class map array
37
     *
38
     * @return array
39
     */
40 11
    public static function addMap(array $map)
41
    {
42 11
        XoopsLoad::$map = array_merge(XoopsLoad::$map, $map);
43
44 11
        return XoopsLoad::$map;
45
    }
46
47
    /**
48
     * getMap - return class map
49
     *
50
     * @return array
51
     */
52 2
    public static function getMap()
53
    {
54 2
        return XoopsLoad::$map;
55
    }
56
57
    /**
58
     * load - load file based on type
59
     *
60
     * @param string $name class name
61
     * @param string $type type core, framework, class, module
62
     *
63
     * @return bool
64
     */
65 70
    public static function load($name, $type = "core")
66
    {
67 70
        static $loaded;
68
69 70
        $lname = strtolower($name);
70
71 70
        $type = empty($type) ? 'core' : $type;
72 70
        if (isset($loaded[$type][$lname])) {
73 1
            return $loaded[$type][$lname];
74
        }
75
76 70
        if (class_exists($lname, false)) {
77
            $loaded[$type][$lname] = true;
78
79
            return true;
80
        }
81
        switch ($type) {
82 70
            case 'framework':
83
                $isloaded = self::loadFramework($lname);
84
                break;
85 70
            case 'class':
86 70
            case 'core':
87 70
                $type = 'core';
88 70
                if ($isloaded = self::loadClass($name)) {
89
                    break;
90
                }
91 70
                $isloaded = self::loadCore($lname);
92 70
                break;
93
            default:
94
                $isloaded = self::loadModule($lname, $type);
95
                break;
96
        }
97 70
        $loaded[$type][$lname] = $isloaded;
98
99 70
        return $loaded[$type][$lname];
100
    }
101
102
    /**
103
     * Load core class
104
     *
105
     * @param string $name class name
106
     *
107
     * @return bool|string
108
     */
109 70
    private static function loadCore($name)
110
    {
111 70
        $map = XoopsLoad::$map; //addMap(XoopsLoad::loadCoreConfig());
112 70
        if (isset($map[$name])) {
113
            //attempt loading from map
114 66
            require $map[$name];
115 66
            if (class_exists($name) && method_exists($name, '__autoload')) {
116
                call_user_func(array($name, '__autoload'));
117
            }
118
119 66
            return true;
120 4
        } elseif (self::fileExists($file = \XoopsBaseConfig::get('root-path') . '/class/' . $name . '.php')) {
121
            //attempt loading from file
122 1
            include_once $file;
123 1
            $class = 'Xoops' . ucfirst($name);
124 1 View Code Duplication
            if (class_exists($class)) {
125
                return $class;
126
            } else {
127 1
                trigger_error(
128 1
                    'Class ' . $name . ' not found in file ' . __FILE__ . 'at line ' . __LINE__,
129 1
                    E_USER_WARNING
130
                );
131
            }
132
        }
133
134 4
        return false;
135
    }
136
137
    /**
138
     * Load Framework class
139
     *
140
     * @param string $name framework class name
141
     *
142
     * @return false|string
143
     */
144
    private static function loadFramework($name)
145
    {
146 View Code Duplication
        if (!self::fileExists($file = \XoopsBaseConfig::get('root-path') . '/Frameworks/' . $name . '/xoops' . $name . '.php')) {
147
            /*
148
            trigger_error(
149
                'File ' . str_replace(\XoopsBaseConfig::get('root-path'), '', $file)
150
                . ' not found in file ' . __FILE__ . ' at line ' . __LINE__,
151
                E_USER_WARNING
152
            );
153
            */
154
            return false;
155
        }
156
        include_once $file;
157
        $class = 'Xoops' . ucfirst($name);
158
        if (class_exists($class, false)) {
159
            return $class;
160
        }
161
162
        return false;
163
    }
164
165
    /**
166
     * Load module class
167
     *
168
     * @param string      $name    class name
169
     * @param string|null $dirname module dirname
170
     *
171
     * @return bool
172
     */
173
    private static function loadModule($name, $dirname = null)
174
    {
175
        if (empty($dirname)) {
176
            return false;
177
        }
178
        if (self::fileExists($file = \XoopsBaseConfig::get('root-path') . '/modules/' . $dirname . '/class/' . $name . '.php')) {
179
            include_once $file;
180
            if (class_exists(ucfirst($dirname) . ucfirst($name))) {
181
                return true;
182
            }
183
        }
184
185
        return false;
186
    }
187
188
    /**
189
     * XoopsLoad::loadCoreConfig()
190
     *
191
     * @static
192
     * @return array
193
     */
194 1
    public static function loadCoreConfig()
195
    {
196 1
        $xoops_root_path = \XoopsBaseConfig::get('root-path');
197
        return array(
198 1
            'bloggerapi' => $xoops_root_path . '/class/xml/rpc/bloggerapi.php',
199 1
            'criteria' => $xoops_root_path . '/class/criteria.php',
200 1
            'criteriacompo' => $xoops_root_path . '/class/criteria.php',
201 1
            'criteriaelement' => $xoops_root_path . '/class/criteria.php',
202 1
            'formdhtmltextarea' => $xoops_root_path . '/class/xoopseditor/dhtmltextarea/dhtmltextarea.php',
203 1
            'formtextarea' => $xoops_root_path . '/class/xoopseditor/textarea/textarea.php',
204 1
            'htmlawed' => $xoops_root_path . '/class/vendor/htmLawed.php',
205 1
            'metaweblogapi' => $xoops_root_path . '/class/xml/rpc/metaweblogapi.php',
206 1
            'movabletypeapi' => $xoops_root_path . '/class/xml/rpc/movabletypeapi.php',
207 1
            'mytextsanitizer' => $xoops_root_path . '/class/module.textsanitizer.php',
208
            //'mytextsanitizerextension' => $xoops_root_path . '/class/module.textsanitizer.php',
209
            //'phpmailer' => $xoops_root_path . '/class/mail/phpmailer/class.phpmailer.php',
210 1
            'rssauthorhandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
211 1
            'rsscategoryhandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
212 1
            'rsscommentshandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
213 1
            'rsscopyrighthandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
214 1
            'rssdescriptionhandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
215 1
            'rssdocshandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
216 1
            'rssgeneratorhandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
217 1
            'rssguidhandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
218 1
            'rssheighthandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
219 1
            'rssimagehandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
220 1
            'rssitemhandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
221 1
            'rsslanguagehandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
222 1
            'rsslastbuilddatehandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
223 1
            'rsslinkhandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
224 1
            'rssmanagingeditorhandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
225 1
            'rssnamehandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
226 1
            'rsspubdatehandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
227 1
            'rsssourcehandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
228 1
            'rsstextinputhandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
229 1
            'rsstitlehandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
230 1
            'rssttlhandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
231 1
            'rssurlhandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
232 1
            'rsswebmasterhandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
233 1
            'rsswidthhandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
234 1
            'saxparser' => $xoops_root_path . '/class/xml/saxparser.php',
235
            //'smarty' => $xoops_root_path . '/smarty/Smarty.class.php',
236 1
            'snoopy' => $xoops_root_path . '/class/vendor/snoopy.php',
237 1
            'sqlutility' => $xoops_root_path . '/class/database/sqlutility.php',
238 1
            'tar' => $xoops_root_path . '/class/class.tar.php',
239 1
            'xmltaghandler' => $xoops_root_path . '/class/xml/xmltaghandler.php',
240 1
            'xoopsadminthemefactory' => $xoops_root_path . '/class/theme.php',
241 1
            'xoopsapi' => $xoops_root_path . '/class/xml/rpc/xoopsapi.php',
242
            //'xoopsauth' => $xoops_root_path . '/class/auth/auth.php',
243
            //'xoopsauthfactory' => $xoops_root_path . '/class/auth/authfactory.php',
244
            //'xoopsauthads' => $xoops_root_path . '/class/auth/auth_ads.php',
245
            //'xoopsauthldap' => $xoops_root_path . '/class/auth/auth_ldap.php',
246
            //'xoopsauthprovisionning' => $xoops_root_path . '/class/auth/auth_provisionning.php',
247
            //'xoopsauthxoops' => $xoops_root_path . '/class/auth/auth_xoops.php',
248
            //'xoopsavatar' => $xoops_root_path . '/kernel/avatar.php',
249
            //'xoopsavatarhandler' => $xoops_root_path . '/kernel/avatar.php',
250
            //'xoopsavataruserlink' => $xoops_root_path . '/kernel/avataruserlink.php',
251
            //'xoopsavataruserlinkhandler' => $xoops_root_path . '/kernel/avataruserlink.php',
252
            //'xoopsblock' => $xoops_root_path . '/kernel/block.php',
253
            //'xoopsblockform' => $xoops_root_path . '/class/xoopsform/blockform.php',
254
            //'xoopsblockhandler' => $xoops_root_path . '/kernel/block.php',
255
            //'xoopsblockmodulelink' => $xoops_root_path . '/kernel/blockmodulelink.php',
256
            //'xoopsblockmodulelinkhandler' => $xoops_root_path . '/kernel/blockmodulelink.php',
257
            //'xoopscalendar' => $xoops_root_path . '/class/calendar/xoopscalendar.php',
258 1
            'xoopscaptcha' => $xoops_root_path . '/class/captcha/xoopscaptcha.php',
259 1
            'xoopscaptchamethod' => $xoops_root_path . '/class/captcha/xoopscaptchamethod.php',
260 1
            'xoopscaptchaimage' => $xoops_root_path . '/class/captcha/image.php',
261 1
            'xoopscaptcharecaptcha' => $xoops_root_path . '/class/captcha/recaptcha.php',
262 1
            'xoopscaptchatext' => $xoops_root_path . '/class/captcha/text.php',
263 1
            'xoopscaptchaimagehandler' => $xoops_root_path . '/class/captcha/image/scripts/imageclass.php',
264
            //'xoopscomment' => $xoops_root_path . '/kernel/comment.php',
265
            //'xoopscommenthandler' => $xoops_root_path . '/kernel/comment.php',
266
            //'xoopscommentrenderer' => $xoops_root_path . '/class/commentrenderer.php',
267
            //'xoopsconfigcategory' => $xoops_root_path . '/kernel/configcategory.php',
268
            //'xoopsconfigcategoryhandler' => $xoops_root_path . '/kernel/configcategory.php',
269
            //'xoopsconfighandler' => $xoops_root_path . '/kernel/config.php',
270
            //'xoopsconfigitem' => $xoops_root_path . '/kernel/configitem.php',
271
            //'xoopsconfigitemhandler' => $xoops_root_path . '/kernel/configitem.php',
272
            //'xoopsconfigoption' => $xoops_root_path . '/kernel/configoption.php',
273
            //'xoopsconfigoptionhandler' => $xoops_root_path . '/kernel/configoption.php',
274 1
            'xoopsdatabase' => $xoops_root_path . '/class/database/database.php',
275
            //'xoopsconnection' => $xoops_root_path . '/class/database/connection.php',
276
            //'xoopsquerybuilder' => $xoops_root_path . '/class/database/querybuilder.php',
277 1
            'xoopsdatabasefactory' => $xoops_root_path . '/class/database/databasefactory.php',
278 1
            'xoopsdatabasemanager' => $xoops_root_path . '/class/database/manager.php',
279 1
            'xoopsdownloader' => $xoops_root_path . '/class/downloader.php',
280 1
            'xoopsmysqldatabase' => $xoops_root_path . '/class/database/mysqldatabase.php',
281 1
            'xoopsmysqldatabaseproxy' => $xoops_root_path . '/class/database/mysqldatabaseproxy.php',
282 1
            'xoopsmysqldatabasesafe' => $xoops_root_path . '/class/database/mysqldatabasesafe.php',
283
            //'xoopsgroup' => $xoops_root_path . '/kernel/group.php',
284
            //'xoopsgrouphandler' => $xoops_root_path . '/kernel/group.php',
285
            //'xoopsgroupperm' => $xoops_root_path . '/kernel/groupperm.php',
286
            //'xoopsgrouppermhandler' => $xoops_root_path . '/kernel/groupperm.php',
287
            //'xoopsimage' => $xoops_root_path . '/kernel/image.php',
288
            //'xoopsimagecategory' => $xoops_root_path . '/kernel/imagecategory.php',
289
            //'xoopsimagecategoryhandler' => $xoops_root_path . '/kernel/imagecategory.php',
290
            //'xoopsimagehandler' => $xoops_root_path . '/kernel/image.php',
291
            //'xoopsimageset' => $xoops_root_path . '/kernel/imageset.php',
292
            //'xoopsimagesethandler' => $xoops_root_path . '/kernel/imageset.php',
293
            //'xoopsimagesetimg' => $xoops_root_path . '/kernel/imagesetimg.php',
294
            //'xoopsimagesetimghandler' => $xoops_root_path . '/kernel/imagesetimg.php',
295 1
            'xoopslists' => $xoops_root_path . '/class/xoopslists.php',
296
            //'xoopslocal' => $xoops_root_path . '/include/xoopslocal.php',
297 1
            'xoopslocalabstract' => $xoops_root_path . '/class/xoopslocal.php',
298 1
            'xoopslogger' => $xoops_root_path . '/class/logger/xoopslogger.php',
299 1
            'xoopseditor' => $xoops_root_path . '/class/xoopseditor/xoopseditor.php',
300 1
            'xoopseditorhandler' => $xoops_root_path . '/class/xoopseditor/xoopseditor.php',
301 1
            'xoopsfile' => $xoops_root_path . '/class/file/xoopsfile.php',
302 1
            'xoopsfilehandler' => $xoops_root_path . '/class/file/file.php',
303 1
            'xoopsfilterinput' => $xoops_root_path . '/class/xoopsfilterinput.php',
304 1
            'xoopsfolderhandler' => $xoops_root_path . '/class/file/folder.php',
305 1
            'xoopsform' => $xoops_root_path . '/class/xoopsform/form.php',
306 1
            'xoopsformbutton' => $xoops_root_path . '/class/xoopsform/formbutton.php',
307 1
            'xoopsformbuttontray' => $xoops_root_path . '/class/xoopsform/formbuttontray.php',
308
            //'xoopsformcalendar' => $xoops_root_path . '/class/xoopsform/formcalendar.php',
309 1
            'xoopsformcaptcha' => $xoops_root_path . '/class/xoopsform/formcaptcha.php',
310 1
            'xoopsformcheckbox' => $xoops_root_path . '/class/xoopsform/formcheckbox.php',
311 1
            'xoopsformcolorpicker' => $xoops_root_path . '/class/xoopsform/formcolorpicker.php',
312
            //'xoopsformcontainer' => $xoops_root_path . '/class/xoopsform/formcontainer.php',
313 1
            'xoopsformdatetime' => $xoops_root_path . '/class/xoopsform/formdatetime.php',
314 1
            'xoopsformdhtmltextarea' => $xoops_root_path . '/class/xoopsform/formdhtmltextarea.php',
315 1
            'xoopsformeditor' => $xoops_root_path . '/class/xoopsform/formeditor.php',
316 1
            'xoopsformelement' => $xoops_root_path . '/class/xoopsform/formelement.php',
317 1
            'xoopsformelementtray' => $xoops_root_path . '/class/xoopsform/formelementtray.php',
318 1
            'xoopsformfile' => $xoops_root_path . '/class/xoopsform/formfile.php',
319 1
            'xoopsformhidden' => $xoops_root_path . '/class/xoopsform/formhidden.php',
320 1
            'xoopsformhiddentoken' => $xoops_root_path . '/class/xoopsform/formhiddentoken.php',
321 1
            'xoopsformlabel' => $xoops_root_path . '/class/xoopsform/formlabel.php',
322 1
            'xoopsformloader' => $xoops_root_path . '/class/xoopsformloader.php',
323 1
            'xoopsformpassword' => $xoops_root_path . '/class/xoopsform/formpassword.php',
324 1
            'xoopsformradio' => $xoops_root_path . '/class/xoopsform/formradio.php',
325 1
            'xoopsformradioyn' => $xoops_root_path . '/class/xoopsform/formradioyn.php',
326
            //'xoopsformraw' => $xoops_root_path . '/class/xoopsform/formraw.php',
327 1
            'xoopsformselect' => $xoops_root_path . '/class/xoopsform/formselect.php',
328 1
            'xoopsformselectcheckgroup' => $xoops_root_path . '/class/xoopsform/formselectcheckgroup.php',
329 1
            'xoopsformselectcountry' => $xoops_root_path . '/class/xoopsform/formselectcountry.php',
330 1
            'xoopsformselecteditor' => $xoops_root_path . '/class/xoopsform/formselecteditor.php',
331 1
            'xoopsformselectgroup' => $xoops_root_path . '/class/xoopsform/formselectgroup.php',
332 1
            'xoopsformselectlang' => $xoops_root_path . '/class/xoopsform/formselectlang.php',
333
            //'xoopsformselectlocale' => $xoops_root_path . '/class/xoopsform/formselectlocale.php',
334 1
            'xoopsformselectmatchoption' => $xoops_root_path . '/class/xoopsform/formselectmatchoption.php',
335 1
            'xoopsformselecttheme' => $xoops_root_path . '/class/xoopsform/formselecttheme.php',
336 1
            'xoopsformselecttimezone' => $xoops_root_path . '/class/xoopsform/formselecttimezone.php',
337 1
            'xoopsformselectuser' => $xoops_root_path . '/class/xoopsform/formselectuser.php',
338
            //'xoopsformtab' => $xoops_root_path . '/class/xoopsform/formtab.php',
339
            //'xoopsformtabtray' => $xoops_root_path . '/class/xoopsform/formtabtray.php',
340 1
            'xoopsformtext' => $xoops_root_path . '/class/xoopsform/formtext.php',
341 1
            'xoopsformtextarea' => $xoops_root_path . '/class/xoopsform/formtextarea.php',
342 1
            'xoopsformtextdateselect' => $xoops_root_path . '/class/xoopsform/formtextdateselect.php',
343
            //'xoopsformmail' => $xoops_root_path . '/class/xoopsform/formmail.php',
344
            //'xoopsformurl' => $xoops_root_path . '/class/xoopsform/formurl.php',
345 1
            'xoopsgroupformcheckbox' => $xoops_root_path . '/class/xoopsform/grouppermform.php',
346 1
            'xoopsgrouppermform' => $xoops_root_path . '/class/xoopsform/grouppermform.php',
347
            //'xoopsguestuser' => $xoops_root_path . '/kernel/user.php',
348 1
            'xoopsmailer' => $xoops_root_path . '/class/xoopsmailer.php',
349 1
            'xoopsmediauploader' => $xoops_root_path . '/class/uploader.php',
350
            //'xoopsmemberhandler' => $xoops_root_path . '/kernel/member.php',
351
            //'xoopsmembership' => $xoops_root_path . '/kernel/membership.php',
352
            //'xoopsmembershiphandler' => $xoops_root_path . '/kernel/membership.php',
353
            //'xoopsmodelfactory' => $xoops_root_path . '/class/model/xoopsmodel.php',
354
            //'xoopsmoduleadmin' => $xoops_root_path . '/class/moduleadmin.php',
355
            //'xoopsmodule' => $xoops_root_path . '/kernel/module.php',
356
            //'xoopsmodulehandler' => $xoops_root_path . '/kernel/module.php',
357 1
            'xoopsmultimailer' => $xoops_root_path . '/class/xoopsmultimailer.php',
358
            //'xoopsnotification' => $xoops_root_path . '/kernel/notification.php',
359
            //'xoopsnotificationhandler' => $xoops_root_path . '/kernel/notification.php',
360 1
            'xoopsobject' => $xoops_root_path . '/kernel/object.php',
361 1
            'xoopsobjecthandler' => $xoops_root_path . '/kernel/object.php',
362 1
            'xoopsobjecttree' => $xoops_root_path . '/class/tree.php',
363
            //'xoopsonline' => $xoops_root_path . '/kernel/online.php',
364
            //'xoopsonlinehandler' => $xoops_root_path . '/kernel/online.php',
365 1
            'xoopspagenav' => $xoops_root_path . '/class/pagenav.php',
366 1
            'xoopspersistableobjecthandler' => $xoops_root_path . '/kernel/object.php',
367 1
            'xoopspreload' => $xoops_root_path . '/class/preload.php',
368 1
            'xoopspreloaditem' => $xoops_root_path . '/class/preload.php',
369
            //'xoopsprivmessage' => $xoops_root_path . '/kernel/privmessage.php',
370
            //'xoopsprivmessagehandler' => $xoops_root_path . '/kernel/privmessage.php',
371
            //'xoopsranks' => $xoops_root_path . '/kernel/ranks.php',
372
            //'xoopsrankshandler' => $xoops_root_path . '/kernel/ranks.php',
373
            // 'xoopsregistry' => $xoops_root_path . '/class/registry.php',
374 1
            'xoopsrequest' => $xoops_root_path . '/class/xoopsrequest.php',
375
            // 'xoopssecurity' => $xoops_root_path . '/class/xoopssecurity.php',
376
            // 'xoopssessionhandler' => $xoops_root_path . '/kernel/session.php',
377 1
            'xoopssimpleform' => $xoops_root_path . '/class/xoopsform/simpleform.php',
378 1
            'xoopstableform' => $xoops_root_path . '/class/xoopsform/tableform.php',
379 1
            'xoopstardownloader' => $xoops_root_path . '/class/tardownloader.php',
380 1
            'xoopstheme' => $xoops_root_path . '/class/theme.php',
381 1
            'xoopsthemeblocksplugin' => $xoops_root_path . '/class/theme_blocks.php',
382 1
            'xoopsthemefactory' => $xoops_root_path . '/class/theme.php',
383 1
            'xoopsthemeform' => $xoops_root_path . '/class/xoopsform/themeform.php',
384 1
            'xoopsthemeplugin' => $xoops_root_path . '/class/theme.php',
385 1
            'xoopsthemesetparser' => $xoops_root_path . '/class/xml/themesetparser.php',
386
            //'xoopstpl' => $xoops_root_path . '/class/template.php',
387
            //'xoopstplfile' => $xoops_root_path . '/kernel/tplfile.php',
388
            //'xoopstplfilehandler' => $xoops_root_path . '/kernel/tplfile.php',
389
            //'xoopstplset' => $xoops_root_path . '/kernel/tplset.php',
390
            //'xoopstplsethandler' => $xoops_root_path . '/kernel/tplset.php',
391
            //'xoopsuser' => $xoops_root_path . '/kernel/user.php',
392
            //'xoopsuserhandler' => $xoops_root_path . '/kernel/user.php',
393 1
            'xoopsuserutility' => $xoops_root_path . '/class/userutility.php',
394 1
            'xoopsutility' => $xoops_root_path . '/class/utility/xoopsutility.php',
395 1
            'xoopsxmlrpcapi' => $xoops_root_path . '/class/xml/rpc/xmlrpcapi.php',
396 1
            'xoopsxmlrpcarray' => $xoops_root_path . '/class/xml/rpc/xmlrpctag.php',
397 1
            'xoopsxmlrpcbase64'=> $xoops_root_path . '/class/xml/rpc/xmlrpctag.php',
398 1
            'xoopsxmlrpcboolean' => $xoops_root_path . '/class/xml/rpc/xmlrpctag.php',
399 1
            'xoopsxmlrpcdatetime' => $xoops_root_path . '/class/xml/rpc/xmlrpctag.php',
400 1
            'xoopsxmlrpcdocument' => $xoops_root_path . '/class/xml/rpc/xmlrpctag.php',
401 1
            'xoopsxmlrpcdouble' => $xoops_root_path . '/class/xml/rpc/xmlrpctag.php',
402 1
            'xoopsxmlrpcfault' => $xoops_root_path . '/class/xml/rpc/xmlrpctag.php',
403 1
            'xoopsxmlrpcint' => $xoops_root_path . '/class/xml/rpc/xmlrpctag.php',
404 1
            'xoopsxmlrpcparser' => $xoops_root_path . '/class/xml/rpc/xmlrpcparser.php',
405 1
            'xoopsxmlrpcrequest' => $xoops_root_path . '/class/xml/rpc/xmlrpctag.php',
406 1
            'xoopsxmlrpcresponse' => $xoops_root_path . '/class/xml/rpc/xmlrpctag.php',
407 1
            'xoopsxmlrpcstring' => $xoops_root_path . '/class/xml/rpc/xmlrpctag.php',
408 1
            'xoopsxmlrpcstruct' => $xoops_root_path . '/class/xml/rpc/xmlrpctag.php',
409 1
            'xoopsxmlrpctag' => $xoops_root_path . '/class/xml/rpc/xmlrpctag.php',
410 1
            'xoopsxmlrss2parser' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
411 1
            'xoopszipdownloader' => $xoops_root_path . '/class/zipdownloader.php',
412 1
            'zipfile' => $xoops_root_path . '/class/class.zipfile.php',
413
        );
414
    }
415
416
    /**
417
     * XoopsLoad::loadConfig()
418
     *
419
     * @param string $data array of configs or dirname of module
420
     *
421
     * @return array|bool
422
     */
423
    public static function loadConfig($data = null)
424
    {
425
        $xoops = Xoops::getInstance();
426
        $configs = array();
427
        if (is_array($data)) {
428
            $configs = $data;
429
        } else {
430
            if (!empty($data)) {
431
                $dirname = $data;
432
            } elseif ($xoops->isModule()) {
433
                $dirname = $xoops->module->getVar('dirname', 'n');
434
            } else {
435
                return false;
436
            }
437 View Code Duplication
            if (self::fileExists($file = \XoopsBaseConfig::get('root-path') . '/modules/' . $dirname . '/include/autoload.php')) {
438
                if (!$configs = include $file) {
439
                    return false;
440
                }
441
            }
442
        }
443
444
        return array_merge(XoopsLoad::loadCoreConfig(), $configs);
445
    }
446
447
    /**
448
     * loadFile
449
     *
450
     * @param string $file file to load
451
     * @param bool   $once true to use include_once, false for include
452
     *
453
     * @return bool
454
     */
455 74
    public static function loadFile($file, $once = true)
456
    {
457 74
        self::securityCheck($file);
458 74
        if (self::fileExists($file)) {
459 4
            if ($once) {
460 4
                include_once $file;
461
            } else {
462
                include $file;
463
            }
464
465 4
            return true;
466
        }
467
468 72
        return false;
469
    }
470
471
    /**
472
     * loadClass
473
     *
474
     * @param string $class class to load
475
     *
476
     * @return bool
477
     */
478 70
    public static function loadClass($class)
479
    {
480 70
        if (class_exists($class, false) || interface_exists($class, false)) {
481
            return true;
482
        }
483
484 70
        $file = str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php';
485 70
        if (!self::loadFile(\XoopsBaseConfig::get('lib-path') . DIRECTORY_SEPARATOR . $file)) {
486 70
            return false;
487
        }
488
489
        if (!class_exists($class, false) && !interface_exists($class, false)) {
490
            return false;
491
        }
492
493
        if (method_exists($class, '__autoload')) {
494
            call_user_func(array($class, '__autoload'));
495
        }
496
497
        return true;
498
    }
499
500
    /**
501
     * Use this method instead of XoopsLoad::fileExists for increasing performance
502
     *
503
     * @param string $file file name
504
     *
505
     * @return mixed
506
     */
507 133
    public static function fileExists($file)
508
    {
509 133
        static $included = array();
510 133
        if (!isset($included[$file])) {
511 85
            $included[$file] = file_exists($file);
512
        }
513
514 133
        return $included[$file];
515
    }
516
517
    /**
518
     * Ensure that filename does not contain exploits
519
     *
520
     * @param string $filename file name
521
     *
522
     * @return void
523
     */
524 74
    protected static function securityCheck($filename)
525
    {
526
        /**
527
         * Security check
528
         */
529 74
        if (preg_match('/[^a-z0-9\\/\\\\_.:-]/i', $filename)) {
530
            exit('Security check: Illegal character in filename');
531
        }
532 74
    }
533
534
    /**
535
     * startAutoloader enable the autoloader
536
     *
537
     * @param string $path path of the library directory where composer managed
538
     *                     vendor directory can be found.
539
     * @return void
540
     */
541
    public static function startAutoloader($path)
542
    {
543
        static $libPath = null;
544
545
        if ($libPath === null) {
546
            $loaderPath = $path . '/vendor/autoload.php';
547
            if (self::fileExists($loaderPath)) {
548
                $libPath = $path;
549
                include $loaderPath;
550
            }
551
            XoopsLoad::addMap(XoopsLoad::loadCoreConfig());
552
            spl_autoload_register(array('XoopsLoad', 'load'));
553
        }
554
    }
555
}
556