-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModule.php
84 lines (69 loc) · 1.89 KB
/
Module.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
<?php
namespace themroc\humhub\modules\modhelper;
class Module extends \humhub\components\Module
{
protected $mod;
protected $vars;
/**
* @inheritdoc
*/
public function disable ()
{
parent::disable();
}
public function doSort ($mdl, $set, $srch, $tabs)
{
if (is_callable($srch)) {
if (is_array($srch) || is_object($srch))
return $srch($mdl, $tabs); // closures and class methods
if (!is_array($srch)) {
$r= new \ReflectionFunction($srch);
if ($r->isUserDefined()) {
// TODO: Determine if the function was actually defined by our client.
// Otherwise, it should be treated as string
return $srch($mdl, $tabs); // user defined functions
}
}
}
// $srch should be string or array - TODO: test for object?
if (!is_array($srch))
$srch= [$srch];
$fs= [];
foreach ($tabs as $attr) {
$fs[$attr]= '';
foreach ($srch as $s)
$fs[$attr].= $set->get($attr.'/'.$s);
}
asort($fs);
return array_keys($fs);
}
public function saveTab ($mdl, $tab)
{
$mod= $mdl->mod;
$mod['prefix']= empty($tab) ? '' : $tab.'/';
$tabs= $this->getTabs($mod['_']);
if (array_search($tab, $tabs) === false)
$tabs[]= $tab;
if (isset($mod['options']['tab_sort']))
$tabs= $this->doSort($mdl, $mod['settings'], $mod['options']['tab_sort'], $tabs);
$this->setTabs($mod['_'], $tabs);
return;
}
public function getTabs ($mdu)
{
// keep track of new api usage per module
# $this->settings->set('o/fget/'.$mdu->id, time());
if ('' == $tabs= $mdu->settings->get('//tabs'))
if ('' == $tabs= $mdu->settings->get('/frames'))
return [];
return preg_split('!\s*/\s*!', $tabs);
}
public function setTabs ($mdu, $tabs)
{
// keep track of new api usage per module
# $this->settings->set('o/fset/'.$mdu->id, time());
$fr= join('/', $tabs);
$mdu->settings->set('//tabs', $fr);
$mdu->settings->set('/frames', $fr); // deprecated old form
}
}