Scripts.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * phpQuery plugin class extending phpQuery object.
  4. * Methods from this class are callable on every phpQuery object.
  5. *
  6. * Class name prefix 'phpQueryObjectPlugin_' must be preserved.
  7. */
  8. abstract class phpQueryObjectPlugin_Scripts {
  9. /**
  10. * Limit binded methods.
  11. *
  12. * null means all public.
  13. * array means only specified ones.
  14. *
  15. * @var array|null
  16. */
  17. public static $phpQueryMethods = null;
  18. public static $config = array();
  19. /**
  20. * Enter description here...
  21. *
  22. * @param phpQueryObject $self
  23. */
  24. public static function script($self, $arg1) {
  25. $params = func_get_args();
  26. $params = array_slice($params, 2);
  27. $return = null;
  28. $config = self::$config;
  29. if (phpQueryPlugin_Scripts::$scriptMethods[$arg1]) {
  30. phpQuery::callbackRun(
  31. phpQueryPlugin_Scripts::$scriptMethods[$arg1],
  32. array($self, $params, &$return, $config)
  33. );
  34. } else if ($arg1 != '__config' && file_exists(dirname(__FILE__)."/Scripts/$arg1.php")) {
  35. phpQuery::debug("Loading script '$arg1'");
  36. require dirname(__FILE__)."/Scripts/$arg1.php";
  37. } else {
  38. phpQuery::debug("Requested script '$arg1' doesn't exist");
  39. }
  40. return $return
  41. ? $return
  42. : $self;
  43. }
  44. }
  45. abstract class phpQueryPlugin_Scripts {
  46. public static $scriptMethods = array();
  47. public static function __initialize() {
  48. if (file_exists(dirname(__FILE__)."/Scripts/__config.php")) {
  49. include dirname(__FILE__)."/Scripts/__config.php";
  50. phpQueryObjectPlugin_Scripts::$config = $config;
  51. }
  52. }
  53. /**
  54. * Extend scripts' namespace with $name related with $callback.
  55. *
  56. * Callback parameter order looks like this:
  57. * - $this
  58. * - $params
  59. * - &$return
  60. * - $config
  61. *
  62. * @param $name
  63. * @param $callback
  64. * @return bool
  65. */
  66. public static function script($name, $callback) {
  67. if (phpQueryPlugin_Scripts::$scriptMethods[$name])
  68. throw new Exception("Script name conflict - '$name'");
  69. phpQueryPlugin_Scripts::$scriptMethods[$name] = $callback;
  70. }
  71. }
  72. ?>