A tumblelog CMS built on AJAX, PHP and MySQL.

plugin.class.php 1.9KB

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