PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/web/nvweb_plugins.php

https://bitbucket.org/navigatecms/navigatecms
PHP | 64 lines | 47 code | 14 blank | 3 comment | 5 complexity | 120d0103c51ab6449599fda09677cc9a MD5 | raw file
Possible License(s): GPL-2.0, MIT, LGPL-2.1, BSD-3-Clause, AGPL-3.0, Apache-2.0
  1. <?php
  2. function nvweb_plugins_load()
  3. {
  4. // load all webget plugins and exclude the DISABLED
  5. global $plugins;
  6. global $DB;
  7. global $website;
  8. $plugin_list = glob(NAVIGATE_PATH.'/plugins/*', GLOB_ONLYDIR);
  9. $plugins = array();
  10. if(is_array($plugin_list))
  11. {
  12. // read the database to find the disabled plugins
  13. $DB->query('SELECT extension, enabled
  14. FROM nv_extensions
  15. WHERE website = '.protect($website->id).'
  16. AND enabled = 0');
  17. $plugins_disabled = $DB->result('extension');
  18. foreach($plugin_list as $plugin_path)
  19. {
  20. $plugin_name = basename($plugin_path);
  21. if(in_array($plugin_name, $plugins_disabled))
  22. continue;
  23. if(file_exists($plugin_path.'/'.$plugin_name.'.php'))
  24. @include_once($plugin_path.'/'.$plugin_name.'.php');
  25. $plugins[] = $plugin_name;
  26. }
  27. }
  28. }
  29. function nvweb_plugins_called_in_template($html)
  30. {
  31. preg_match_all("/(object=)(\"|\')(nvweb)(\"|\')((\s)+)(name=)(\"|\')(\w+)(\"|\')/", $html, $matches);
  32. $plugins_called = array_unique($matches[9]);
  33. sort($plugins_called);
  34. return $plugins_called;
  35. }
  36. // events: before_parse, after_parse
  37. function nvweb_plugins_event($event, $html)
  38. {
  39. global $plugins;
  40. if(!is_array($plugins))
  41. return;
  42. foreach($plugins as $plugin)
  43. {
  44. $fname = 'nvweb_'.$plugin.'_event';
  45. if(function_exists($fname))
  46. $html = $fname($event, $html);
  47. }
  48. return $html;
  49. }
  50. ?>