A tumblelog CMS built on AJAX, PHP and MySQL.

plugin.class.php 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. if (!defined('entry') || !entry) {
  3. die('Not a valid page');
  4. }
  5. /* ===========================
  6. Sorbet CMS - A PHP based tumblelog CMS forked from Gelato CMS
  7. Sorbet CMS is a free software licensed under the GPL 3.0
  8. =========================== */
  9. ?>
  10. <?php
  11. class plugin
  12. {
  13. public $actions = array();
  14. public $exists = array();
  15. public function call($name)
  16. {
  17. if (!$this->exists($name)) {
  18. return false;
  19. }
  20. $index = 0;
  21. foreach ($GLOBALS['plugins::$instances'] as $plugin) {
  22. if (array_key_exists($index, $this->actions[$name])) {
  23. $action = $this->actions[$name][$index][1];
  24. if (is_callable(array($plugin, $action))) {
  25. $plugin->$action();
  26. $index++;
  27. }
  28. }
  29. }
  30. }
  31. public function exists($name)
  32. {
  33. if (isset($this->exists[$name])) {
  34. return $this->exists[$name];
  35. }
  36. foreach ($GLOBALS['plugins::$instances'] as $plugin) {
  37. if (array_key_exists($name, $this->actions)) {
  38. if (is_callable(array($plugin, $this->actions[$name][0][1]))) {
  39. return $this->exists[$name] = true;
  40. }
  41. }
  42. }
  43. return $this->exists[$name] = false;
  44. }
  45. //I really hate you PHP4's OOP implementation
  46. public function &instance()
  47. {
  48. static $instance;
  49. if (!isset($instance)) {
  50. $instance = new plugin();
  51. }
  52. return $instance;
  53. }
  54. }
  55. ?>