PageRenderTime 55ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/Flux/Addon.php

https://github.com/chokoleytdesignoper/fluxcp_choko
PHP | 65 lines | 55 code | 8 blank | 2 comment | 8 complexity | 45bde6a10b20c4069e0e5a72b40c6408 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, BSD-3-Clause
  1. <?php
  2. require_once 'Flux/Config.php';
  3. class Flux_Addon {
  4. public $name;
  5. public $addonDir;
  6. public $configDir;
  7. public $moduleDir;
  8. public $themeDir;
  9. public $addonConfig;
  10. public $accessConfig;
  11. public $messagesConfig;
  12. public function __construct($name, $addonDir = null)
  13. {
  14. $this->name = $name;
  15. $this->addonDir = is_null($addonDir) ? FLUX_ADDON_DIR."/$name" : $addonDir;
  16. $this->configDir = "{$this->addonDir}/config";
  17. $this->moduleDir = "{$this->addonDir}/modules";
  18. $this->themeDir = "{$this->addonDir}/themes/".Flux::config('ThemeName');
  19. $files = array(
  20. 'addonConfig' => "{$this->configDir}/addon.php",
  21. 'accessConfig' => "{$this->configDir}/access.php",
  22. //'messagesConfig' => "{$this->configDir}/messages.php" // Deprecated.
  23. );
  24. foreach ($files as $configName => $filename) {
  25. if (file_exists($filename)) {
  26. $this->{$configName} = Flux::parseConfigFile($filename);
  27. }
  28. if (!($this->{$configName} instanceOf Flux_Config)) {
  29. $tempArr = array();
  30. $this->{$configName} = new Flux_Config($tempArr);
  31. }
  32. }
  33. // Use new language system for messages (also supports addons).
  34. $this->messagesConfig = Flux::parseLanguageConfigFile($name);
  35. }
  36. public function respondsTo($module, $action = null)
  37. {
  38. $path = is_null($action) ? "{$this->moduleDir}/$module" : "{$this->moduleDir}/$module/$action.php";
  39. if ((is_null($action) && is_dir($path)) || file_exists($path)) {
  40. return true;
  41. }
  42. else {
  43. return false;
  44. }
  45. }
  46. public function hasView($module, $action)
  47. {
  48. $path = "{$this->themeDir}/$module/$action.php";
  49. if (file_exists($path)) {
  50. return true;
  51. }
  52. else {
  53. return false;
  54. }
  55. }
  56. }
  57. ?>