forked from NextDom/nextdom-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.php
executable file
·140 lines (124 loc) · 4.87 KB
/
core.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
<?php
/* This file is part of Jeedom.
*
* Jeedom is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Jeedom is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Jeedom. If not, see <http://www.gnu.org/licenses/>.
*/
/* This file is part of NextDom Software.
*
* NextDom is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NextDom Software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NextDom Software. If not, see <http://www.gnu.org/licenses/>.
*/
namespace {
use NextDom\Exceptions\CoreException;
use NextDom\Managers\ConfigManager;
define('NEXTDOM_ROOT', realpath(__DIR__ . '/..'));
if (file_exists(NEXTDOM_ROOT . '/core/config/common.config.php')) {
require_once NEXTDOM_ROOT . '/core/config/common.config.php';
}
/**
* Before autoload force plugin autoload last
*/
$ENABLED_PLUGINS = null;
spl_autoload_register('nextdomPluginAutoload', true, true);
if (file_exists(NEXTDOM_ROOT . '/core/config/common.config.php')) {
require_once NEXTDOM_ROOT . '/core/config/common.config.php';
}
global $CONFIG;
define('NEXTDOM_DATA', $CONFIG["paths"]["lib"]);
define('NEXTDOM_LOG', $CONFIG["paths"]["log"]);
define('NEXTDOM_TMP', $CONFIG["paths"]["tmp"]);
require_once NEXTDOM_ROOT . '/vendor/autoload.php';
require_once NEXTDOM_ROOT . '/src/Helpers/DBHelper.php';
require_once NEXTDOM_ROOT . '/src/Managers/ConfigManager.php';
require_once NEXTDOM_DATA . '/config/nextdom.config.php';
require_once NEXTDOM_DATA . '/config/compatibility.config.php';
// Developer mode : Register global error and exception handlers
if (('cli' !== php_sapi_name()) &&
('1' == ConfigManager::getDefaultConfiguration()['core']['developer::mode']) &&
('1' == ConfigManager::getDefaultConfiguration()['core']['developer::errorhandler']) &&
('1' == ConfigManager::getDefaultConfiguration()['core']['developer::exceptionhandler'])) {
Symfony\Component\Debug\ErrorHandler::register();
Symfony\Component\Debug\ExceptionHandler::register();
}
/**
* Include files from plugins
*
* @param string $className Name of the class
*
* @throws Exception
*/
function nextdomPluginAutoload($className)
{
global $ENABLED_PLUGINS;
if ($ENABLED_PLUGINS === null) {
$ENABLED_PLUGINS = array_keys(ConfigManager::getEnabledPlugins());
}
if (!empty($ENABLED_PLUGINS)) {
$purgedClassName = str_replace(['Real', 'Cmd'], '', $className);
$activePlugin = in_array($purgedClassName, $ENABLED_PLUGINS);
if (!$activePlugin) {
$purgedClassName = explode('_', $purgedClassName)[0];
$activePlugin = in_array($purgedClassName, $ENABLED_PLUGINS);
}
if ($activePlugin) {
$pluginFile = NEXTDOM_ROOT . '/plugins/' . $purgedClassName . '/core/class/' . $purgedClassName . '.class.php';
if (file_exists($pluginFile)) {
require_once($pluginFile);
} else {
throw new CoreException('File ' . $pluginFile . ' for plugin ' . $purgedClassName . ' not found.');
}
}
}
}
/**
* Translate a string (global function)
*
* @param string $content
* @param string $name
* @param bool $backslah
* @return string
* @throws \Exception
*/
function __(string $content, string $name = '', bool $backslah = false): string
{
return \NextDom\__($content, $name, $backslah);
}
}
// Declare global functions
namespace NextDom {
use NextDom\Helpers\TranslateHelper;
/**
* Translate a string
*
* @param string $content
* @param string $name
* @param bool $backslah
* @return string
* @throws \Exception
*/
function __(string $content, string $name = '', bool $backslah = false): string
{
return TranslateHelper::sentence($content, $name, $backslah);
}
}