start.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * Provides the ECML service.
  4. *
  5. * @package ECML
  6. */
  7. // be sure to run after other plugins
  8. elgg_register_event_handler('init', 'system', 'ecml_init', 9999);
  9. function ecml_init() {
  10. // get list of views to process for ECML
  11. // entries should be of the form 'view/name' => 'View description'
  12. $default_views = array(
  13. 'output/longtext' => elgg_echo('ecml:view:output_longtext'),
  14. );
  15. $views = elgg_trigger_plugin_hook('get_views', 'ecml', null, $default_views);
  16. foreach ($views as $view => $desc) {
  17. elgg_register_plugin_hook_handler('view', $view, 'ecml_process_view');
  18. }
  19. elgg_register_plugin_hook_handler('unit_test', 'system', 'ecml_unit_test');
  20. if (!class_exists('Elgg_Ecml_Token')) {
  21. spl_autoload_register('_ecml_load_class');
  22. }
  23. }
  24. /**
  25. * Processes a view output for ECML tags
  26. *
  27. * @param string $hook The name of the hook
  28. * @param string $name The name of the view
  29. * @param string $value The value of the view
  30. * @param array $params The parameters for the view
  31. * @return string
  32. */
  33. function ecml_process_view($hook, $name, $value, $params) {
  34. return _ecml_get_processor()->process($value, array(
  35. 'view' => $name,
  36. 'view_params' => $params,
  37. ));
  38. }
  39. function ecml_unit_test($hook, $type, $value, $params) {
  40. // dumb strict errors caused by simpletest!
  41. error_reporting(E_ALL);
  42. $path = dirname(__FILE__) . '/tests';
  43. //error_reporting(E_ALL);
  44. $value[] = "$path/Elgg_Ecml_TokenizerTest.php";
  45. $value[] = "$path/Elgg_Ecml_ProcessorTest.php";
  46. return $value;
  47. }
  48. /**
  49. * @return Elgg_Ecml_Processor
  50. */
  51. function _ecml_get_processor() {
  52. static $proc;
  53. if (null === $proc) {
  54. $proc = new Elgg_Ecml_Processor(new Elgg_Ecml_Tokenizer());
  55. }
  56. return $proc;
  57. }
  58. /**
  59. * @param string $class
  60. */
  61. function _ecml_load_class($class) {
  62. if (0 === strpos($class, 'Elgg_Ecml_')) {
  63. $file = dirname(__FILE__) . '/classes/' . strtr($class, '_\\', '//') . '.php';
  64. is_file($file) && (require $file);
  65. }
  66. }