1 | <?php |
||
42 | class AdminDelegationPlugin extends Plugin { |
||
43 | |||
44 | public function __construct($id) { |
||
45 | parent::__construct($id); |
||
46 | $this->_addHook('cssfile', 'cssFile', false); |
||
47 | $this->_addHook('site_admin_option_hook', 'site_admin_option_hook', false); |
||
48 | $this->_addHook('widget_instance', 'widget_instance', false); |
||
49 | $this->_addHook('widgets', 'widgets', false); |
||
50 | } |
||
51 | |||
52 | public function getPluginInfo() { |
||
53 | if (!is_a($this->pluginInfo, 'AdminDelegationPluginInfo')) { |
||
54 | include_once 'AdminDelegationPluginInfo.class.php'; |
||
55 | $this->pluginInfo = new AdminDelegationPluginInfo($this); |
||
56 | } |
||
57 | return $this->pluginInfo; |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Check if current user is allowed to use given widget |
||
62 | * |
||
63 | * @param String $widget |
||
64 | * |
||
65 | * @return Boolean |
||
66 | */ |
||
67 | protected function _userCanViewWidget($widget) { |
||
68 | $um = UserManager::instance(); |
||
69 | $user = $um->getCurrentUser(); |
||
70 | if ($user) { |
||
71 | $service = AdminDelegation_Service::getServiceFromWidget($widget); |
||
72 | if ($service) { |
||
|
|||
73 | $usm = new AdminDelegation_UserServiceManager(); |
||
74 | return $usm->isUserGrantedForService($user, $service); |
||
75 | } |
||
76 | } |
||
77 | return false; |
||
78 | } |
||
79 | |||
80 | public function cssFile($params) { |
||
81 | // Only show the stylesheet if we're actually in the Docman pages. |
||
82 | // This stops styles inadvertently clashing with the main site. |
||
83 | if (strpos($_SERVER['REQUEST_URI'], $this->getPluginPath()) === 0 || |
||
84 | strpos($_SERVER['REQUEST_URI'], '/widgets/') === 0 |
||
85 | ) { |
||
86 | echo '<link rel="stylesheet" type="text/css" href="'.$this->getThemePath().'/css/style.css" />'."\n"; |
||
87 | } |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * Hook: admin link to plugin |
||
92 | * |
||
93 | * @param Array $params |
||
94 | */ |
||
95 | public function site_admin_option_hook($params) { |
||
98 | |||
99 | /** |
||
100 | * Hook: event raised when widget are instanciated |
||
101 | * |
||
102 | * @param Array $params |
||
103 | */ |
||
104 | public function widget_instance($params) { |
||
105 | if ($params['widget'] == 'admindelegation' && $this->_userCanViewWidget('admindelegation')) { |
||
106 | include_once 'AdminDelegation_UserWidget.class.php'; |
||
107 | $params['instance'] = new AdminDelegation_UserWidget($this); |
||
108 | } |
||
109 | if ($params['widget'] == 'admindelegation_projects' && $this->_userCanViewWidget('admindelegation_projects')) { |
||
110 | include_once 'AdminDelegation_ShowProjectWidget.class.php'; |
||
111 | $params['instance'] = new AdminDelegation_ShowProjectWidget($this); |
||
112 | } |
||
113 | |||
114 | } |
||
115 | |||
116 | /** |
||
117 | * Hook: event raised when user lists all available widget |
||
118 | * |
||
119 | * @param Array $params |
||
120 | */ |
||
121 | public function widgets($params) { |
||
134 | } |
||
135 | |||
136 | ?> |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
integer
values, zero is a special case, in particular the following results might be unexpected: