function.popup.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * Smarty plugin
  4. * @package Smarty
  5. * @subpackage PluginsFunction
  6. */
  7. /**
  8. * Smarty {popup} function plugin
  9. *
  10. * Type: function<br>
  11. * Name: popup<br>
  12. * Purpose: make text pop up in windows via overlib
  13. * @link http://smarty.php.net/manual/en/language.function.popup.php {popup}
  14. * (Smarty online manual)
  15. * @author Monte Ohrt <monte at ohrt dot com>
  16. * @param array $params parameters
  17. * @param object $smarty Smarty object
  18. * @param object $template template object
  19. * @return string
  20. */
  21. function smarty_function_popup($params, $smarty, $template)
  22. {
  23. $append = '';
  24. foreach ($params as $_key=>$_value) {
  25. switch ($_key) {
  26. case 'text':
  27. case 'trigger':
  28. case 'function':
  29. case 'inarray':
  30. $$_key = (string)$_value;
  31. if ($_key == 'function' || $_key == 'inarray')
  32. $append .= ',' . strtoupper($_key) . ",'$_value'";
  33. break;
  34. case 'caption':
  35. case 'closetext':
  36. case 'status':
  37. $append .= ',' . strtoupper($_key) . ",'" . str_replace("'","\'",$_value) . "'";
  38. break;
  39. case 'fgcolor':
  40. case 'bgcolor':
  41. case 'textcolor':
  42. case 'capcolor':
  43. case 'closecolor':
  44. case 'textfont':
  45. case 'captionfont':
  46. case 'closefont':
  47. case 'fgbackground':
  48. case 'bgbackground':
  49. case 'caparray':
  50. case 'capicon':
  51. case 'background':
  52. case 'frame':
  53. $append .= ',' . strtoupper($_key) . ",'$_value'";
  54. break;
  55. case 'textsize':
  56. case 'captionsize':
  57. case 'closesize':
  58. case 'width':
  59. case 'height':
  60. case 'border':
  61. case 'offsetx':
  62. case 'offsety':
  63. case 'snapx':
  64. case 'snapy':
  65. case 'fixx':
  66. case 'fixy':
  67. case 'padx':
  68. case 'pady':
  69. case 'timeout':
  70. case 'delay':
  71. $append .= ',' . strtoupper($_key) . ",$_value";
  72. break;
  73. case 'sticky':
  74. case 'left':
  75. case 'right':
  76. case 'center':
  77. case 'above':
  78. case 'below':
  79. case 'noclose':
  80. case 'autostatus':
  81. case 'autostatuscap':
  82. case 'fullhtml':
  83. case 'hauto':
  84. case 'vauto':
  85. case 'mouseoff':
  86. case 'followmouse':
  87. case 'closeclick':
  88. case 'wrap':
  89. if ($_value) $append .= ',' . strtoupper($_key);
  90. break;
  91. default:
  92. trigger_error("[popup] unknown parameter $_key", E_USER_WARNING);
  93. }
  94. }
  95. if (empty($text) && !isset($inarray) && empty($function)) {
  96. trigger_error("overlib: attribute 'text' or 'inarray' or 'function' required",E_USER_WARNING);
  97. return false;
  98. }
  99. if (empty($trigger)) { $trigger = "onmouseover"; }
  100. $retval = $trigger . '="return overlib(\''.preg_replace(array("!'!",'!"!',"![\r\n]!"),array("\'","\'",'\r'),$text).'\'';
  101. $retval .= $append . ');"';
  102. if ($trigger == 'onmouseover')
  103. $retval .= ' onmouseout="nd();"';
  104. return $retval;
  105. }
  106. ?>