forked from FreePBX/superfecta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsources.php
73 lines (57 loc) · 2.88 KB
/
sources.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
<?php
define("UPDATE_SERVER", "https://raw.github.com/tm1000/Caller-ID-Superfecta/v3.x/sources/");
define("ROOT_PATH", dirname(__FILE__) . '/');
//fix in the future
$version = preg_replace('/(alpha|beta)/i', '.0.', $module_info['module']['version']);
preg_match('/^(\d\.(:?\d*)\.(:?\d*))/i', $version, $matches);
$major_version = $matches[1];
//Get the enabled sources from this scheme
$sql = "SELECT value FROM superfectaconfig WHERE source='$scheme' AND field='sources'";
$enabled_sources = explode(',', $db->getOne($sql));
//get a list of the files that are on this local server
$tpl_sources = array();
$i = 0;
foreach (glob(ROOT_PATH . "sources/source-*.module") as $filename) {
if (file_exists($filename)) {
$source_desc = '';
$source_param = array();
require_once($filename);
preg_match('/source-(.*)\.module/i', $filename, $matches);
$this_source_name = $matches[1];
$this_source_class = new $this_source_name();
if ($major_version >= $this_source_class->version_requirement) {
$j = !in_array($this_source_name, $enabled_sources) ? ($j = $i + 200) : ($j = $i);
if (in_array($this_source_name, $enabled_sources)) {
$j = array_search($this_source_name, $enabled_sources);
} else {
$j = $i + 200;
}
$tpl_sources[$j]['showup'] = FALSE;
$tpl_sources[$j]['showdown'] = FALSE;
$tpl_sources[$j]['showupdate'] = FALSE;
$tpl_sources[$j]['pretty_source_name'] = str_replace("_", " ", $this_source_name);
$tpl_sources[$j]['source_name'] = $this_source_name;
$tpl_sources[$j]['enabled'] = in_array($this_source_name, $enabled_sources) ? TRUE : FALSE;
$tpl_sources[$j]['status'] = in_array($this_source_name, $enabled_sources) ? 'enabled' : 'disabled';
$tpl_sources[$j]['description'] = isset($this_source_class->description) ? preg_replace('/(<a>|<\/a>)/i', '', $this_source_class->description) : 'N/A';
$tpl_sources[$j]['show_link'] = isset($this_source_class->source_param) ? TRUE : FALSE;
//Simplify please
if (in_array($this_source_name, $enabled_sources)) {
if ($enabled_sources[0] != $this_source_name) {
$tpl_sources[$j]['showup'] = TRUE;
}
$c = count($enabled_sources) - 1;
if ($enabled_sources[$c] != $this_source_name) {
$tpl_sources[$j]['showdown'] = TRUE;
}
}
$i++;
}
unset($this_source_class);
}
}
ksort($tpl_sources);
$supertpl->assign("scheme", $scheme);
$supertpl->assign("sources", $tpl_sources);
$supertpl->assign("web_path", 'http://' . $_SERVER['SERVER_NAME'] . '/admin/modules/superfecta/tpl/js/jquery.form.js');
echo $supertpl->draw('sources');