forked from k0a1a/hotglue2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule_loaders.inc.php-disabled
More file actions
67 lines (52 loc) · 1.78 KB
/
module_loaders.inc.php-disabled
File metadata and controls
67 lines (52 loc) · 1.78 KB
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
<?php
use Smarty\Smarty;
/*
* module_loader.inc.php
* Automatically run PHP scripts for some pages, and pass data to the page
*
* This source code is licensed under the GNU General Public License.
* See the file COPYING for more details.
*/
@require_once('config.inc.php');
require_once('html.inc.php');
require_once('modules.inc.php');
$pages = [];
function loaders_alter_render_early($object) {
global $pages;
// If Smarty is not installed, return
if (!class_exists('Smarty\Smarty')) {
log_msg('debug', 'Smarty is not installed, not converting text');
return $object;
}
$page = explode('.', $object['obj']['name'])[0];
$smarty = new Smarty();
$data = [];
if (!isset($pages[$page])) {
if (file_exists('loaders/' . $page . '.php')) {
include 'loaders/' . $page . '.php';
}
$pages[$page] = $data;
} else {
$data = $pages[$page];
}
$smarty->assign('data', $data);
$object['elem'] = set_text_node($object['elem'], $smarty);
return $object;
}
function set_text_node($elem, $smarty) {
if (is_array($elem) && !isset($elem['val'])) {
// If elem is an array, iterate through it
foreach ($elem as $key => $val) {
$elem[$key] = set_text_node($val, $smarty);
}
} else if (is_array($elem) && isset($elem['val']) && is_array($elem['val'])) {
// If elem is an array with a 'val' key, check if 'val' is a string and set it
foreach ($elem['val'] as $key => $val) {
$elem['val'][$key] = set_text_node($val, $smarty);
}
} else if (isset($elem['val']) && is_string($elem['val'])) {
// If elem is a string, render it with Smarty
$elem['val'] = $smarty->fetch('string:' . $elem['val']);
}
return $elem;
}