PageRenderTime 12ms CodeModel.GetById 2ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/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
  7 This program is distributed in the hope that it will be useful,
  8 but WITHOUT ANY WARRANTY; without even the implied warranty of
  9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 10*/
 11
 12/**
 13 * TextSanitizer extension
 14 *
 15 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
 16 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
 17 * @package         class
 18 * @subpackage      textsanitizer
 19 * @since           2.3.0
 20 * @author          Taiwen Jiang <phppp@users.sourceforge.net>
 21 * @version         $Id: flash.php 8271 2011-11-11 19:46:00Z trabis $
 22 */
 23
 24defined('XOOPS_ROOT_PATH') or die('Restricted access');
 25
 26class MytsFlash extends MyTextSanitizerExtension
 27{
 28    /**
 29     * @param int $textarea_id
 30     * @return array
 31     */
 32    public function encode($textarea_id)
 33    {
 34        $config = parent::loadConfig(dirname(__FILE__));
 35        $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;";
 36        $javascript = <<<EOF
 37            function xoopsCodeFlash(id, enterFlashPhrase, enterFlashHeightPhrase, enterFlashWidthPhrase, enableDimensionDetect)
 38            {
 39                var selection = xoopsGetSelect(id);
 40                if (selection.length > 0) {
 41                    var text = selection;
 42                } else {
 43                    var text = prompt(enterFlashPhrase, "");
 44                }
 45                var domobj = xoopsGetElementById(id);
 46                if ( text.length > 0 ) {
 47                    var text2 = enableDimensionDetect ? "" : prompt(enterFlashWidthPhrase, "");
 48                    var text3 = enableDimensionDetect ? "" : prompt(enterFlashHeightPhrase, "");
 49                    var result = "[flash="+text2+","+text3+"]" + text + "[/flash]";
 50                    xoopsInsertText(domobj, result);
 51                }
 52                domobj.focus();
 53            }
 54EOF;
 55
 56        return array(
 57            $code, $javascript
 58        );
 59    }
 60
 61    /**
 62     * @param MyTextSanitizer $ts
 63     * @return bool
 64     */
 65    public function load(MyTextSanitizer &$ts)
 66    {
 67        $ts->patterns[] = "/\[(swf|flash)=(['\"]?)([^\"']*),([^\"']*)\\2]([^\"]*)\[\/\\1\]/esU";
 68        $ts->replacements[] = __CLASS__ . "::decode( '\\5', '\\3', '\\4' )";
 69
 70        return true;
 71    }
 72
 73    /**
 74     * @param string $url
 75     * @param int $width
 76     * @param int $height
 77     * @return string
 78     */
 79    public function decode($url, $width, $height)
 80    {
 81        $config = parent::loadConfig(dirname(__FILE__));
 82        if ((empty($width) || empty($height)) && !empty($config['detect_dimension'])) {
 83            if (!$dimension = @getimagesize($url)) {
 84                return "<a href='{$url}' rel='external' title=''>{$url}</a>";
 85            }
 86            if (!empty($width)) {
 87                $height = $dimension[1] * $width / $dimension[0];
 88            } else {
 89                if (!empty($height)) {
 90                    $width = $dimension[0] * $height / $dimension[1];
 91                } else {
 92                    list ($width, $height) = array(
 93                        $dimension[0], $dimension[1]
 94                    );
 95                }
 96            }
 97        }
 98
 99        $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'>";
100        $rp .= "<param name='movie' value='{$url}'>";
101        $rp .= "<param name='QUALITY' value='high'>";
102        $rp .= "<PARAM NAME='bgcolor' VALUE='#FFFFFF'>";
103        $rp .= "<param name='wmode' value='transparent'>";
104        $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>";
105        $rp .= "</object>";
106        return $rp;
107    }
108}