PageRenderTime 228ms CodeModel.GetById 221ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/class/textsanitizer/image/image.php

https://gitlab.com/VoyaTrax/vtCMS3
PHP | 99 lines | 70 code | 5 blank | 24 comment | 0 complexity | aebcf548865a5f0fb16cbd906f5a7df9 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: image.php 10328 2012-12-07 00:56:07Z trabis $
22 */
23
24defined('XOOPS_ROOT_PATH') or die('Restricted access');
25
26class MytsImage extends MyTextSanitizerExtension
27{
28    /**
29     * @param MyTextSanitizer $ts
30     * @return bool
31     */
32    public function load(MyTextSanitizer &$ts)
33    {
34        static $jsLoaded;
35
36        $xoops = Xoops::getInstance();
37        $xoops->loadLanguage('misc');
38        $config = $this->loadConfig(dirname(__FILE__));
39        $ts->patterns[] = "/\[img align=(['\"]?)(left|center|right)\\1 width=(['\"]?)([0-9]*)\\3]([^\"\(\)\?\&'<>]*)\[\/img\]/sU";
40        $ts->patterns[] = "/\[img align=(['\"]?)(left|center|right)\\1]([^\"\(\)\?\&'<>]*)\[\/img\]/sU";
41        $ts->patterns[] = "/\[img width=(['\"]?)([0-9]*)\\1]([^\"\(\)\?\&'<>]*)\[\/img\]/sU";
42        $ts->patterns[] = "/\[img]([^\"\(\)\?\&'<>]*)\[\/img\]/sU";
43
44        $ts->patterns[] = "/\[img align=(['\"]?)(left|center|right)\\1 id=(['\"]?)([0-9]*)\\3]([^\"\(\)\?\&'<>]*)\[\/img\]/sU";
45        $ts->patterns[] = "/\[img id=(['\"]?)([0-9]*)\\1]([^\"\(\)\?\&'<>]*)\[\/img\]/sU";
46
47        if (empty($ts->config['allowimage'])) {
48            $ts->replacements[] = '<a href="\\5" rel="external">\\5</a>';
49            $ts->replacements[] = '<a href="\\3" rel="external">\\3</a>';
50            $ts->replacements[] = '<a href="\\3" rel="external">\\3</a>';
51            $ts->replacements[] = '<a href="\\1" rel="external">\\1</a>';
52
53            $ts->replacements[] = '<a href="' . XOOPS_URL . '/image.php?id=\\4" rel="external" title="\\5">\\5</a>';
54            $ts->replacements[] = '<a href="' . XOOPS_URL . '/image.php?id=\\2" rel="external" title="\\3">\\3</a>';
55
56        } else {
57            if (!empty($config['resize']) && empty($config['clickable']) && !empty($config['max_width']) && is_object($xoops->theme())) {
58                if (!$jsLoaded) {
59                    $jsLoaded = true;
60                    $xoops->theme()->addScript('/class/textsanitizer/image/image.js', array(
61                            'type' => 'text/javascript'
62                        ));
63                }
64                $ts->replacements[] = "<img src='\\5' class='\\2' alt='" . _MSC_RESIZED_IMAGE . "' border='0' onload=\"JavaScript:if(this.width>\\4)this.width=\\4\" />";
65                $ts->replacements[] = "<img src='\\3' class='\\2' alt='" . _MSC_RESIZED_IMAGE . "' border='0'" . ($config['resize']
66                    ? "onload=\"javascript:imageResize(this, " . $config['max_width'] . ")\"" : "") . "/>";
67                $ts->replacements[] = "<img src='\\3' alt='" . _MSC_RESIZED_IMAGE . "' border='0' onload=\"JavaScript:if(this.width>\\2)this.width=\\2\" /><br />";
68                $ts->replacements[] = "<img src='\\1' alt='" . _MSC_RESIZED_IMAGE . "' border='0'" . ($config['resize']
69                    ? " onload=\"javascript:imageResize(this, " . $config['max_width'] . ")\"" : "") . "/>";
70
71            } else {
72                if (!empty($config['clickable']) && !empty($config['max_width']) && is_object($xoops->theme())) {
73                    if (!$jsLoaded) {
74                        $jsLoaded = true;
75                        $xoops->theme()->addScript('/class/textsanitizer/image/image.js', array(
76                                'type' => 'text/javascript'
77                            ));
78                    }
79                    $ts->replacements[] = "<a href='javascript:CaricaFoto(\"\\5\");'><img src='\\5' class='\\2' alt='" . _MSC_CLICK_TO_OPEN_IMAGE . "' border='0' onload=\"JavaScript:if(this.width>\\4)this.width=\\4\" /></a>";
80                    $ts->replacements[] = "<a href='javascript:CaricaFoto(\"\\3\");'><img src='\\3' class='\\2' alt='" . _MSC_CLICK_TO_OPEN_IMAGE . "' border='0' " . ($config['resize']
81                        ? "onload=\"javascript:imageResize(this, " . $config['max_width'] . ")\"" : "") . "/></a>";
82                    $ts->replacements[] = "<a href='javascript:CaricaFoto(\"\\3\");'><img src='\\3' alt='" . _MSC_CLICK_TO_OPEN_IMAGE . "' border='0' onload=\"JavaScript:if(this.width>\\2)this.width=\\2\" /></a><br />";
83                    $ts->replacements[] = "<a href='javascript:CaricaFoto(\"\\1\");'><img src='\\1' alt='" . _MSC_CLICK_TO_OPEN_IMAGE . "' border='0' title='" . _MSC_CLICK_TO_OPEN_IMAGE . "'" . ($config['resize']
84                        ? " onload=\"javascript:imageResize(this, " . $config['max_width'] . ")\"" : "") . "/></a>";
85                } else {
86                    $ts->replacements[] = "<img src='\\5' class='\\2' border='0' alt='" . _MSC_ORIGINAL_IMAGE . "' onload=\"JavaScript:if(this.width>\\4) this.width=\\4\" />";
87                    $ts->replacements[] = "<img src='\\3' class='\\2' border='0' alt='" . _MSC_ORIGINAL_IMAGE . "' " . ($config['resize']
88                        ? "onload=\"javascript:imageResize(this, " . $config['max_width'] . ")\"" : "") . "/>";
89                    $ts->replacements[] = "<img src='\\3' border='0' alt='" . _MSC_ORIGINAL_IMAGE . "' onload=\"JavaScript:if(this.width>\\2) this.width=\\2\" />";
90                    $ts->replacements[] = "<img src='\\1' border='0' alt='" . _MSC_ORIGINAL_IMAGE . "' " . ($config['resize']
91                        ? " onload=\"javascript:imageResize(this, " . $config['max_width'] . ")\"" : "") . "/>";
92                }
93            }
94            $ts->replacements[] = '<img src="' . XOOPS_URL . '/image.php?id=\\4" class="\\2" title="\\5" />';
95            $ts->replacements[] = '<img src="' . XOOPS_URL . '/image.php?id=\\2" title="\\3" />';
96        }
97        return true;
98    }
99}