1: | <?php
|
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: |
|
19: | defined('XOOPS_ROOT_PATH') || exit('Restricted access');
|
20: | global $xoopsConfig;
|
21: | include_once $GLOBALS['xoops']->path('language/' . $xoopsConfig['language'] . '/misc.php');
|
22: |
|
23: | |
24: | |
25: |
|
26: | class MytsImage extends MyTextSanitizerExtension
|
27: | {
|
28: | |
29: | |
30: | |
31: | |
32: |
|
33: | public function load(MyTextSanitizer $myts)
|
34: | {
|
35: | static $jsLoaded;
|
36: |
|
37: | $config = parent::loadConfig(__DIR__);
|
38: | $myts->patterns[] = "/\[img align=(['\"]?)(left|center|right)\\1 width=(['\"]?)(\d*)\\3]([^\"\(\)\?\&'<>]*)\[\/img\]/sU";
|
39: | $myts->patterns[] = "/\[img align=(['\"]?)(left|center|right)\\1]([^\"\(\)\?\&'<>]*)\[\/img\]/sU";
|
40: | $myts->patterns[] = "/\[img width=(['\"]?)(\d*)\\1]([^\"\(\)\?\&'<>]*)\[\/img\]/sU";
|
41: | $myts->patterns[] = "/\[img]([^\"\(\)\?\&'<>]*)\[\/img\]/sU";
|
42: |
|
43: | $myts->patterns[] = "/\[img align=(['\"]?)(left|center|right)\\1 id=(['\"]?)(\d*)\\3]([^\"\(\)\?\&'<>]*)\[\/img\]/sU";
|
44: | $myts->patterns[] = "/\[img id=(['\"]?)(\d*)\\1]([^\"\(\)\?\&'<>]*)\[\/img\]/sU";
|
45: |
|
46: | if (empty($myts->config['allowimage'])) {
|
47: | $myts->replacements[] = '<a href="\\5" rel="external">\\5</a>';
|
48: | $myts->replacements[] = '<a href="\\3" rel="external">\\3</a>';
|
49: | $myts->replacements[] = '<a href="\\3" rel="external">\\3</a>';
|
50: | $myts->replacements[] = '<a href="\\1" rel="external">\\1</a>';
|
51: |
|
52: | $myts->replacements[] = '<a href="' . XOOPS_URL . '/image.php?id=\\4" rel="external" title="\\5">\\5</a>';
|
53: | $myts->replacements[] = '<a href="' . XOOPS_URL . '/image.php?id=\\2" rel="external" title="\\3">\\3</a>';
|
54: | } else {
|
55: | if (!empty($config['resize']) && empty($config['clickable']) && !empty($config['max_width']) && !empty($GLOBALS['xoTheme'])) {
|
56: | if (!$jsLoaded) {
|
57: | $jsLoaded = true;
|
58: | $GLOBALS['xoTheme']->addScript('/class/textsanitizer/image/image.js', array(
|
59: | 'type' => 'text/javascript'));
|
60: | }
|
61: | $myts->replacements[] = "<img src='\\5' class='\\2' alt='" . _MSC_RESIZED_IMAGE . "' border='0' onload=\"JavaScript:if(this.width>\\4)this.width=\\4\" />";
|
62: | $myts->replacements[] = "<img src='\\3' class='\\2' alt='" . _MSC_RESIZED_IMAGE . "' border='0'" . ($config['resize'] ? "onload=\"javascript:resizeImage(this, " . $config['max_width'] . ")\"" : '') . '/>';
|
63: | $myts->replacements[] = "<img src='\\3' alt='" . _MSC_RESIZED_IMAGE . "' border='0' onload=\"if(this.width>\\2)this.width=\\2\" /><br>";
|
64: | $myts->replacements[] = "<img src='\\1' alt='" . _MSC_RESIZED_IMAGE . "' border='0'" . ($config['resize'] ? " onload=\"javascript:resizeImage(this, " . $config['max_width'] . ")\"" : '') . '/>';
|
65: | } elseif (!empty($config['clickable']) && !empty($config['max_width']) && !empty($GLOBALS['xoTheme'])) {
|
66: | if (!$jsLoaded) {
|
67: | $jsLoaded = true;
|
68: | $GLOBALS['xoTheme']->addScript('/class/textsanitizer/image/image.js', array(
|
69: | 'type' => 'text/javascript'));
|
70: | }
|
71: | $myts->replacements[] = "<a href='javascript:loadImage(\"\\5\");'><img src='\\5' class='\\2' alt='" . _MSC_CLICK_TO_OPEN_IMAGE . "' border='0' onload=\"if(this.width>\\4)this.width=\\4\" /></a>";
|
72: | $myts->replacements[] = "<a href='javascript:loadImage(\"\\3\");'><img src='\\3' class='\\2' alt='" . _MSC_CLICK_TO_OPEN_IMAGE . "' border='0' " . ($config['resize'] ? "onload=\"javascript:resizeImage(this, " . $config['max_width'] . ")\"" : '') . '/></a>';
|
73: | $myts->replacements[] = "<a href='javascript:loadImage(\"\\3\");'><img src='\\3' alt='" . _MSC_CLICK_TO_OPEN_IMAGE . "' border='0' onload=\"if(this.width>\\2)this.width=\\2\" /></a><br>";
|
74: | $myts->replacements[] = "<a href='javascript:loadImage(\"\\1\");'><img src='\\1' alt='" . _MSC_CLICK_TO_OPEN_IMAGE . "' border='0' title='" . _MSC_CLICK_TO_OPEN_IMAGE . "'" . ($config['resize'] ? " onload=\"javascript:resizeImage(this, " . $config['max_width'] . ")\"" : '') . '/></a>';
|
75: | } else {
|
76: | $myts->replacements[] = "<img src='\\5' class='\\2' border='0' alt='" . _MSC_ORIGINAL_IMAGE . "' onload=\"JavaScript:if(this.width>\\4) this.width=\\4\" />";
|
77: | $myts->replacements[] = "<img src='\\3' class='\\2' border='0' alt='" . _MSC_ORIGINAL_IMAGE . "' " . ($config['resize'] ? "onload=\"javascript:resizeImage(this, " . $config['max_width'] . ")\"" : '') . '/>';
|
78: | $myts->replacements[] = "<img src='\\3' border='0' alt='" . _MSC_ORIGINAL_IMAGE . "' onload=\"JavaScript:if(this.width>\\2) this.width=\\2\" />";
|
79: | $myts->replacements[] = "<img src='\\1' border='0' alt='" . _MSC_ORIGINAL_IMAGE . "' " . ($config['resize'] ? " onload=\"javascript:resizeImage(this, " . $config['max_width'] . ")\"" : '') . '/>';
|
80: | }
|
81: | $myts->replacements[] = '<img src="' . XOOPS_URL . '/image.php?id=\\4" class="\\2" title="\\5" />';
|
82: | $myts->replacements[] = '<img src="' . XOOPS_URL . '/image.php?id=\\2" title="\\3" />';
|
83: | }
|
84: |
|
85: | return true;
|
86: | }
|
87: | }
|
88: | |