-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathloader.php
202 lines (163 loc) · 6.62 KB
/
loader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<?php
// $Id: loader.php 1041 2012-09-09 06:23:26Z i.bitcero $
// --------------------------------------------------------------
// Red México Common Utilities
// A framework for Red México Modules
// Author: Eduardo Cortés <i.bitcero@gmail.com>
// Email: i.bitcero@gmail.com
// License: GPL 2.0
// --------------------------------------------------------------
/**
* rmcommon constants
*/
if (!defined('RMCPATH')) {
define('RMCPATH', XOOPS_ROOT_PATH . '/modules/rmcommon');
}
if (!defined('RMCURL')) {
define('RMCURL', XOOPS_URL . '/modules/rmcommon');
}
define('ABSURL', XOOPS_URL);
define('ABSPATH', XOOPS_ROOT_PATH);
define('RMCVERSION', '2.3.7.5');
/**
* Welcome Screen
*/
if (isset($_COOKIE['rmcwelcome'])) {
$domain = preg_replace("/http:\/\/|https:\/\//", '', XOOPS_URL);
setcookie('rmcwelcome', 1, time() - 3600, '/', $domain);
header('location: ' . RMCURL . '/about.php');
die();
}
/**
* Messages Levels
*/
define('RMMSG_INFO', 0);
define('RMMSG_WARN', 1);
define('RMMSG_SUCCESS', 2);
define('RMMSG_SAVED', 3);
define('RMMSG_ERROR', 4);
define('RMMSG_DANGER', 4);
define('RMMSG_OTHER', 5);
// Render output
require RMCPATH . '/include/render-output.php';
// Legacy Autoloader
require RMCPATH . '/include/legacy-autoloader.php';
// Logger and Database
require_once XOOPS_ROOT_PATH . '/class/logger/xoopslogger.php';
require_once XOOPS_ROOT_PATH . '/class/database/databasefactory.php';
$dbF = new XoopsDatabaseFactory();
$db = $dbF->getDatabaseConnection();
$GLOBALS['rmFunctions'] = new RMFunctions();
global $rmFunctions;
/**
* New object to manage Common Utilities configurations
*/
global $cuSettings;
$GLOBALS['cuSettings'] = (object)$rmFunctions->settings->cu_settings();
/**
* Do not use $rmc_config, use $cuSettings instead
* @Todo: Delete references to $rmc_config
* @deprecated
*/
$GLOBALS['rmc_config'] = (array)$cuSettings;
global $rmc_config;
// PSR-4 implementation
require __DIR__ . '/class/Psr4ClassLoader.php';
$loader = new \Common\Core\Psr4ClassLoader();
$loader->register();
// Basic namespaces from Common Utilities
$loader->addNamespace('Common\Core', RMCPATH . '/class');
$loader->addNamespace('Common\API', RMCPATH . '/api');
$loader->addNamespace('Common\API\Editors', RMCPATH . '/api/editors');
$loader->addNamespace('Common\Core\Helpers', RMCPATH . '/class/helpers');
$loader->addNamespace('Common\\Admin\\Theme\\' . ucfirst($cuSettings->theme), RMCPATH . '/themes/' . $cuSettings->theme . '/class');
//$loader->addNamespace('Common\Plugin', XOOPS_ROOT_PATH . '/modules/rmcommon/plugins');
$loader->addNamespace('Common\Widgets', XOOPS_ROOT_PATH . '/modules/rmcommon/widgets');
// Base classes
$GLOBALS['rmEvents'] = RMEvents::get();
$GLOBALS['rmTpl'] = RMTemplate::getInstance();
$GLOBALS['rmCodes'] = RMCustomCode::get();
global $rmEvents, $rmTpl, $rmCodes;
// Custom Codes
require RMCPATH . '/include/custom-codes.php';
$cuSettings->lang = $rmEvents->run_event('rmcommon.set.language', $cuSettings->lang);
// Load plugins
$file = XOOPS_CACHE_PATH . '/plgs.cnf';
$plugins = [];
$GLOBALS['installed_plugins'] = [];
if (file_exists($file)) {
$plugins = json_decode(file_get_contents($file), true);
}
if (empty($plugins) || !is_array($plugins)) {
$result = $db->query('SELECT dir FROM ' . $db->prefix('mod_rmcommon_plugins') . ' WHERE status=1');
while (false !== ($row = $db->fetchArray($result))) {
$GLOBALS['installed_plugins'][$row['dir']] = true;
$plugins[] = $row['dir'];
$rmEvents->load_extra_preloads(RMCPATH . '/plugins/' . $row['dir'], preg_replace('/[^A-Za-z0-9]/', '', $row['dir']) . 'Plugin');
}
file_put_contents($file, json_encode($plugins));
} else {
foreach ($plugins as $p) {
$GLOBALS['installed_plugins'][$p] = true;
$rmEvents->load_extra_preloads(RMCPATH . '/plugins/' . $p, ucfirst(preg_replace('/[^A-Za-z0-9]/', '', $p)) . 'Plugin');
}
}
// Load GUI theme events
$rmEvents->load_extra_preloads(RMCPATH . '/themes/' . $cuSettings->theme, ucfirst($cuSettings->theme));
// Load theme Events
list($theme) = $db->fetchRow($db->query('select conf_value from ' . $db->prefix('config') . " where conf_name = 'theme_set' and conf_modid = 0;"));
RMEvents::get()->load_extra_preloads(XOOPS_THEME_PATH . '/' . $theme, ucfirst($theme) . 'Theme');
/**
* Modules and other elements can use this event to add their own namespaces
* The module most return the $loader object again to prevent errors
*/
$loader = RMEvents::get()->trigger('rmcommon.psr4loader', $loader);
unset($plugins);
unset($file);
$GLOBALS['installed_plugins'] = $rmEvents->run_event('rmcommon.plugins.loaded', $GLOBALS['installed_plugins']);
require_once __DIR__ . '/api/l10n.php';
// Load rmcommon language
load_mod_locale('rmcommon');
if (isset($xoopsModule) && is_object($xoopsModule) && 'rmcommon' != $xoopsModule->dirname()) {
load_mod_locale($xoopsModule->dirname());
}
if (!$cuSettings) {
_e('Sorry, Red Mexico Common Utilities has not been installed yet!');
die();
}
$rmEvents->run_event('rmcommon.base.loaded');
$rmTpl->add_head_script('var xoUrl = "' . XOOPS_URL . '";');
if ($cuSettings->updates && isset($xoopsOption['pagetype']) && 'admin' == $xoopsOption['pagetype']) {
$interval = $cuSettings->updatesinterval <= 0 ? 7 : $cuSettings->updatesinterval;
if (file_exists(XOOPS_CACHE_PATH . '/updates.chk')) {
$updates = unserialize(base64_decode(file_get_contents(XOOPS_CACHE_PATH . '/updates.chk'), true));
} else {
$updates = ['date' => 0, 'total' => 0, 'updates' => []];
}
RMTemplate::getInstance()->add_script('updates.js', 'rmcommon', ['footer' => 1]);
if ($updates['date'] < (time() - ($cuSettings->updatesinterval * 86400))) {
$rmTpl->add_inline_script('(function(){rmCheckUpdates();})();', 1);
define('RMC_CHECK_UPDATES', 1);
} else {
$rmTpl->add_inline_script('$(document).ready(function(){rmCallNotifier(' . $updates['total'] . ');});', 1);
}
}
/**
* Add ajax controller script
*/
if (defined('XOOPS_CPFUNC_LOADED') || (isset($xoopsOption) && array_key_exists('pagetype', $xoopsOption) && 'admin' == $xoopsOption['pagetype'])) {
$rmTpl->add_script('cu-handler.js', 'rmcommon', ['footer' => 1, 'id' => 'cuhandler']);
$rmTpl->add_script('jquery.validate.min.js', 'rmcommon', ['footer' => 1]);
}
// Services Manager
$cuServices = Common\Core\Helpers\Services::getInstance();
$GLOBALS['cuServices'] = $cuServices;
// Icons manager
$cuIcons = Common\Core\Helpers\Icons::getInstance();
$GLOBALS['cuIcons'] = $cuIcons;
// Common handler
global $common;
$common = Common\Core\Helpers\Common::getInstance();
// Rewrite for JS
RMSettings::write_rewrite_js();
require_once RMCPATH . '/include/tpl_functions.php';