function.popup.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * Smarty plugin
  4. * @package Smarty
  5. * @subpackage plugins
  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. * @param array
  16. * @param Smarty
  17. * @return string
  18. */
  19. function smarty_function_popup($params, &$smarty)
  20. {
  21. $append = '';
  22. foreach ($params as $_key=>$_value) {
  23. switch ($_key) {
  24. case 'text':
  25. case 'trigger':
  26. $$_key = (string)$_value;
  27. break;
  28. case 'caption':
  29. case 'closetext':
  30. case 'status':
  31. $append .= ',' . strtoupper($_key) . ",'" . str_replace("'","\'",$_value) . "'";
  32. break;
  33. case 'fgcolor':
  34. case 'bgcolor':
  35. case 'textcolor':
  36. case 'capcolor':
  37. case 'closecolor':
  38. case 'textfont':
  39. case 'captionfont':
  40. case 'closefont':
  41. case 'fgbackground':
  42. case 'bgbackground':
  43. case 'inarray':
  44. case 'caparray':
  45. case 'capicon':
  46. case 'background':
  47. case 'frame':
  48. case 'function':
  49. $append .= ',' . strtoupper($_key) . ",'$_value'";
  50. break;
  51. case 'textsize':
  52. case 'captionsize':
  53. case 'closesize':
  54. case 'width':
  55. case 'height':
  56. case 'border':
  57. case 'offsetx':
  58. case 'offsety':
  59. case 'snapx':
  60. case 'snapy':
  61. case 'fixx':
  62. case 'fixy':
  63. case 'padx':
  64. case 'pady':
  65. case 'timeout':
  66. case 'delay':
  67. $append .= ',' . strtoupper($_key) . ",$_value";
  68. break;
  69. case 'sticky':
  70. case 'left':
  71. case 'right':
  72. case 'center':
  73. case 'above':
  74. case 'below':
  75. case 'noclose':
  76. case 'autostatus':
  77. case 'autostatuscap':
  78. case 'fullhtml':
  79. case 'hauto':
  80. case 'vauto':
  81. if ($_value) $append .= ',' . strtoupper($_key);
  82. break;
  83. default:
  84. $smarty->trigger_error("[popup] unknown parameter $_key", E_USER_WARNING);
  85. }
  86. }
  87. if (empty($text) && !isset($inarray) && empty($function)) {
  88. $smarty->trigger_error("overlib: attribute 'text' or 'inarray' or 'function' required");
  89. return false;
  90. }
  91. if (empty($trigger)) { $trigger = "onmouseover"; }
  92. $retval = $trigger . '="return overlib(\''.preg_replace(array("!'!","![\r\n]!"),array("\'",'\r'),$text).'\'';
  93. $retval .= $append . ');" onmouseout="nd();"';
  94. return $retval;
  95. }
  96. /* vim: set expandtab: */
  97. ?>