/class/textsanitizer/flash/flash.php

https://gitlab.com/VoyaTrax/vtCMS3 · PHP · 108 lines · 66 code · 8 blank · 34 comment · 11 complexity · 2c0e14673360a7810842e8349a01cfbe MD5 · raw file

  1. <?php
  2. /*
  3. You may not change or alter any portion of this comment or credits
  4. of supporting developers from this source code or any supporting source code
  5. which is considered copyrighted (c) material of the original comment or credit authors.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. */
  10. /**
  11. * TextSanitizer extension
  12. *
  13. * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/
  14. * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
  15. * @package class
  16. * @subpackage textsanitizer
  17. * @since 2.3.0
  18. * @author Taiwen Jiang <phppp@users.sourceforge.net>
  19. * @version $Id: flash.php 8271 2011-11-11 19:46:00Z trabis $
  20. */
  21. defined('XOOPS_ROOT_PATH') or die('Restricted access');
  22. class MytsFlash extends MyTextSanitizerExtension
  23. {
  24. /**
  25. * @param int $textarea_id
  26. * @return array
  27. */
  28. public function encode($textarea_id)
  29. {
  30. $config = parent::loadConfig(dirname(__FILE__));
  31. $code = "<img src='{$this->image_path}/swf.gif' alt='" . _XOOPS_FORM_ALTFLASH . "' onclick='xoopsCodeFlash(\"{$textarea_id}\",\"" . htmlspecialchars(_XOOPS_FORM_ENTERFLASHURL, ENT_QUOTES) . "\",\"" . htmlspecialchars(_XOOPS_FORM_ALT_ENTERHEIGHT, ENT_QUOTES) . "\",\"" . htmlspecialchars(_XOOPS_FORM_ALT_ENTERWIDTH, ENT_QUOTES) . "\", \"" . $config['detect_dimension'] . "\");' onmouseover='style.cursor=\"hand\"'/>&nbsp;";
  32. $javascript = <<<EOF
  33. function xoopsCodeFlash(id, enterFlashPhrase, enterFlashHeightPhrase, enterFlashWidthPhrase, enableDimensionDetect)
  34. {
  35. var selection = xoopsGetSelect(id);
  36. if (selection.length > 0) {
  37. var text = selection;
  38. } else {
  39. var text = prompt(enterFlashPhrase, "");
  40. }
  41. var domobj = xoopsGetElementById(id);
  42. if ( text.length > 0 ) {
  43. var text2 = enableDimensionDetect ? "" : prompt(enterFlashWidthPhrase, "");
  44. var text3 = enableDimensionDetect ? "" : prompt(enterFlashHeightPhrase, "");
  45. var result = "[flash="+text2+","+text3+"]" + text + "[/flash]";
  46. xoopsInsertText(domobj, result);
  47. }
  48. domobj.focus();
  49. }
  50. EOF;
  51. return array(
  52. $code, $javascript
  53. );
  54. }
  55. /**
  56. * @param MyTextSanitizer $ts
  57. * @return bool
  58. */
  59. public function load(MyTextSanitizer &$ts)
  60. {
  61. $ts->patterns[] = "/\[(swf|flash)=(['\"]?)([^\"']*),([^\"']*)\\2]([^\"]*)\[\/\\1\]/esU";
  62. $ts->replacements[] = __CLASS__ . "::decode( '\\5', '\\3', '\\4' )";
  63. return true;
  64. }
  65. /**
  66. * @param string $url
  67. * @param int $width
  68. * @param int $height
  69. * @return string
  70. */
  71. public function decode($url, $width, $height)
  72. {
  73. $config = parent::loadConfig(dirname(__FILE__));
  74. if ((empty($width) || empty($height)) && !empty($config['detect_dimension'])) {
  75. if (!$dimension = @getimagesize($url)) {
  76. return "<a href='{$url}' rel='external' title=''>{$url}</a>";
  77. }
  78. if (!empty($width)) {
  79. $height = $dimension[1] * $width / $dimension[0];
  80. } else {
  81. if (!empty($height)) {
  82. $width = $dimension[0] * $height / $dimension[1];
  83. } else {
  84. list ($width, $height) = array(
  85. $dimension[0], $dimension[1]
  86. );
  87. }
  88. }
  89. }
  90. $rp = "<object width='{$width}' height='{$height}' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0'>";
  91. $rp .= "<param name='movie' value='{$url}'>";
  92. $rp .= "<param name='QUALITY' value='high'>";
  93. $rp .= "<PARAM NAME='bgcolor' VALUE='#FFFFFF'>";
  94. $rp .= "<param name='wmode' value='transparent'>";
  95. $rp .= "<embed src='{$url}' width='{$width}' height='{$height}' quality='high' bgcolor='#FFFFFF' wmode='transparent' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash'></embed>";
  96. $rp .= "</object>";
  97. return $rp;
  98. }
  99. }