A tumblelog CMS built on AJAX, PHP and MySQL.

plugin.class.php 1.5KB

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