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