core.load_resource_plugin.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * Smarty plugin
  4. * @package Smarty
  5. * @subpackage plugins
  6. */
  7. /**
  8. * load a resource plugin
  9. *
  10. * @param string $type
  11. */
  12. // $type
  13. function smarty_core_load_resource_plugin($params, &$smarty)
  14. {
  15. /*
  16. * Resource plugins are not quite like the other ones, so they are
  17. * handled differently. The first element of plugin info is the array of
  18. * functions provided by the plugin, the second one indicates whether
  19. * all of them exist or not.
  20. */
  21. $_plugin = &$smarty->_plugins['resource'][$params['type']];
  22. if (isset($_plugin)) {
  23. if (!$_plugin[1] && count($_plugin[0])) {
  24. $_plugin[1] = true;
  25. foreach ($_plugin[0] as $_plugin_func) {
  26. if (!is_callable($_plugin_func)) {
  27. $_plugin[1] = false;
  28. break;
  29. }
  30. }
  31. }
  32. if (!$_plugin[1]) {
  33. $smarty->_trigger_fatal_error("[plugin] resource '" . $params['type'] . "' is not implemented", null, null, __FILE__, __LINE__);
  34. }
  35. return;
  36. }
  37. $_plugin_file = $smarty->_get_plugin_filepath('resource', $params['type']);
  38. $_found = ($_plugin_file != false);
  39. if ($_found) { /*
  40. * If the plugin file is found, it -must- provide the properly named
  41. * plugin functions.
  42. */
  43. include_once($_plugin_file);
  44. /*
  45. * Locate functions that we require the plugin to provide.
  46. */
  47. $_resource_ops = array('source', 'timestamp', 'secure', 'trusted');
  48. $_resource_funcs = array();
  49. foreach ($_resource_ops as $_op) {
  50. $_plugin_func = 'smarty_resource_' . $params['type'] . '_' . $_op;
  51. if (!function_exists($_plugin_func)) {
  52. $smarty->_trigger_fatal_error("[plugin] function $_plugin_func() not found in $_plugin_file", null, null, __FILE__, __LINE__);
  53. return;
  54. } else {
  55. $_resource_funcs[] = $_plugin_func;
  56. }
  57. }
  58. $smarty->_plugins['resource'][$params['type']] = array($_resource_funcs, true);
  59. }
  60. }
  61. /* vim: set expandtab: */
  62. ?>