Combu Server  3.1.1
PHP API Documentation
AddonModule.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Combu;
4 
11 {
12  public $Id = 0;
13  public $Name = "";
14  public $Version = "1.0";
15  public $OnUserCreate = NULL;
16  public $OnUserUpdate = NULL;
17  public $OnUserDelete = NULL;
18  public $OnUserCustomDataOutput = NULL;
19  public $OnUserProcessOutput = NULL;
20  public $OnUserLogout = NULL;
21 
22  private $Folder = "";
23  private $Properties = array();
24  private $AdminMenu = array();
25  private $BlockedUpdateUserCustomData = array();
26 
27  public function __construct($folder) {
28  $this->Folder = $folder;
29  if (substr($this->Folder, -1) != "/") {
30  $this->Folder .= "/";
31  }
32  }
33 
38  public static function LoadAddons() {
39  $addons = array();
40  $handle = NULL;
41  if (file_exists(ADDONS_FOLDER)) {
42  $handle = opendir(ADDONS_FOLDER);
43  }
44  while ($handle && false !== ($entry = readdir($handle))) {
45  // Skip files
46  if (!is_dir(ADDONS_FOLDER . "/" . $entry)) {
47  continue;
48  }
49  // Skip back/current directories
50  if ($entry == "." || $entry == "..") {
51  continue;
52  }
53  // Try to load the add-on in this directory
54  $addon = self::LoadAddon(ADDONS_FOLDER . "/" . $entry);
55  if ($addon) {
56  $addon->Id = count($addons) + 1;
57  $addons[] = $addon;
58  }
59  }
60  return $addons;
61  }
62 
68  private static function LoadAddon($folder) {
69  // Is there a loader file in this folder?
70  $addon_file = $folder . "/addon.php";
71  $disabled_file = $folder . "/.disabled";
72  if (file_exists($addon_file) && !file_exists($disabled_file)) {
73  try {
74  // Create a new AddonModule for this entry
75  $addon = new self($folder);
76  // Run the add-on loader
77  include_once $addon_file;
78  return $addon;
79  } catch (Exception $ex) {
80  // Loading this add-on failed, log the exception
81  AppLog::Error("Error trying to load add-on " . basename($folder) . ": " . $ex->getMessage());
82  }
83  }
84  return NULL;
85  }
86 
93  public static function GetAddon($addonName) {
94  global $Addons;
95  foreach ($Addons as $addon) {
96  if ($addon->Name == $addonName)
97  return $addon;
98  }
99  return NULL;
100  }
101 
106  public function GetFolder() {
107  return $this->Folder;
108  }
109 
115  public function GetFile($fileRelativePath) {
116  if (substr($fileRelativePath, 0, 1) == "/")
117  $fileRelativePath = substr($fileRelativePath, 1);
118  return $this->Folder . $fileRelativePath;
119  }
120 
126  public function GetMenuLink($menu) {
127  return URL_ROOT . "admin/addon-load.php?addon=" . urlencode($this->Name) . "&menu=" . $menu;
128  }
129 
134  public function GetTooltip() {
135  return $this->Name . " " . $this->Version;
136  }
137 
142  public function GetProperties () {
143  return $this->Properties;
144  }
145 
151  public function GetProperty($name) {
152  if (array_key_exists($name, $this->Properties))
153  return $this->Properties[$name];
154  return NULL;
155  }
156 
162  public function SetProperty($name, $value) {
163  $this->Properties[$name] = $value;
164  }
165 
171  public function AddAdminMenu($displayText, $url) {
172  if ($displayText && $url)
173  $this->AdminMenu[] = array( "Display" => $displayText, "Url" => $url );
174  }
175 
180  public function GetAdminMenu() {
181  return $this->AdminMenu;
182  }
183 
188  public function BlockUpdateUserCustomData($dataKey) {
189  if (!array_key_exists($dataKey, $this->BlockedUpdateUserCustomData))
190  $this->BlockedUpdateUserCustomData[] = $dataKey;
191  }
192 
199  public static function IsBlockedUpdateUserCustomData($dataKey) {
200  global $Addons;
201  foreach ($Addons as $addon) {
202  if (in_array($dataKey, $addon->BlockedUpdateUserCustomData))
203  return TRUE;
204  }
205  return FALSE;
206  }
207 
215  public static function ProcessOutputUserCustomData($user, &$customData) {
216  global $Addons;
217  foreach ($Addons as $addon) {
218  if ($addon->OnUserCustomDataOutput)
219  eval ($addon->OnUserCustomDataOutput . "(\$user, \$customData);");
220  }
221  }
222 
230  public static function ProcessOutputUser(&$userData) {
231  global $Addons;
232  foreach ($Addons as $addon) {
233  if ($addon->OnUserProcessOutput)
234  eval ($addon->OnUserProcessOutput . "(\$userData);");
235  }
236  }
237 
243  public static function NotifyUserCreate($user) {
244  global $Addons;
245  foreach ($Addons as $addon) {
246  if ($addon->OnUserCreate)
247  eval ($addon->OnUserCreate . "(\$user);");
248  }
249  }
250 
256  public static function NotifyUserUpdate($user) {
257  global $Addons;
258  foreach ($Addons as $addon) {
259  if ($addon->OnUserUpdate)
260  eval ($addon->OnUserUpdate . "(\$user);");
261  }
262  }
263 
269  public static function NotifyUserDelete($user) {
270  global $Addons;
271  foreach ($Addons as $addon) {
272  if ($addon->OnUserDelete)
273  eval ($addon->OnUserDelete . "(\$user);");
274  }
275  }
276 
282  public static function NotifyUserLogout($user) {
283  global $Addons;
284  foreach ($Addons as $addon) {
285  if ($addon->OnUserLogout)
286  eval ($addon->OnUserLogout . "(\$user);");
287  }
288  }
289 }
SetProperty($name, $value)
__construct($folder)
Definition: AddonModule.php:27
AddAdminMenu($displayText, $url)
static NotifyUserLogout($user)
static LoadAddons()
Definition: AddonModule.php:38
static ProcessOutputUserCustomData($user, &$customData)
static IsBlockedUpdateUserCustomData($dataKey)
static NotifyUserUpdate($user)
Definition: Account.php:3
BlockUpdateUserCustomData($dataKey)
static NotifyUserDelete($user)
static NotifyUserCreate($user)
GetFile($fileRelativePath)
static ProcessOutputUser(&$userData)
static GetAddon($addonName)
Definition: AddonModule.php:93