예제 #1
0
 function _html_check_img_src($match)
 {
     static $showHostReg = NULL;
     static $directHostReg = NULL;
     if (is_null($showHostReg)) {
         $showHostReg = '#(?!)#';
         if ($this->Config_showImgHosts) {
             $showHostReg = $this->_getHostsRegex($this->Config_showImgHosts);
         }
     }
     if (is_null($directHostReg)) {
         $directHostReg = '#(?!)#';
         if ($this->Config_directImgHosts) {
             $directHostReg = $this->_getHostsRegex($this->Config_directImgHosts);
         }
     }
     $type = strtolower($match[2]);
     if (!$this->vars['ua']['allowInputImage'] && $type === 'input') {
         return str_replace('image', 'submit', $match[1] . $match[5]) . (isset($match[6]) ? $match[6] : '');
     }
     // Doesn't process. ("_ktai_direct" found)
     if (strpos($match[1], ' _ktai_direct') !== false) {
         $match[0] = preg_replace('/ _ktai_direct[^ \\/>]*/', '', $match[0]);
         return $match[0];
     }
     $url = $match[4];
     // Url rewrite
     $rewiteUrl = false;
     if (!empty($this->Config_urlImgRewrites['regex']) && !empty($this->Config_urlImgRewrites['tostr'])) {
         $rewiteUrl = $url = preg_replace($this->Config_urlImgRewrites['regex'], $this->Config_urlImgRewrites['tostr'], $url);
     }
     // Save original URL
     $src = $url;
     $parsed_url = parse_url($url);
     if ($this->Config_directImgHosts !== 'all' && empty($parsed_url['host']) || $parsed_url['host'] === $this->parsed_base['host'] && $parsed_url['scheme'] === $this->parsed_base['scheme'] || preg_match($showHostReg, $parsed_url['host']) && !preg_match($directHostReg, $parsed_url['host'])) {
         $png = $this->vars['ua']['allowPNG'] ? '&p' : '';
         if (empty($parsed_url['host'])) {
             $url = $this->getRealUrl($url);
         }
         // Size tag
         $reps = array();
         $width = $height = '';
         if (preg_match('/(width=[\'"]?)(\\d+)/i', $match[1] . $match[5], $arg)) {
             $w_org = $arg[0];
             $w_tag = $arg[1];
             $width = $arg[2];
         }
         if (preg_match('/(height=[\'"]?)(\\d+)/i', $match[1] . $match[5], $arg)) {
             $h_org = $arg[0];
             $h_tag = $arg[1];
             $height = $arg[2];
         }
         $_size = '';
         $url = str_replace('&', '&', $url);
         $twice = !defined('K_TAI_RENDER_IMG_NO_TWICE') && isset($this->vars['ua']['width']) && $this->Config_imageTwiceDisplayWidth && $this->vars['ua']['width'] >= $this->Config_imageTwiceDisplayWidth;
         if ($width && $height) {
             $zoom = min($this->Config_pictSizeMax / $width, $this->Config_pictSizeMax / $height);
             if ($zoom < 1) {
                 $_w = round($width * $zoom);
                 $reps['from'][] = $w_org;
                 $reps['to'][] = $w_tag . ($twice ? $_w * 2 : $_w);
                 $_h = round($height * $zoom);
                 $reps['from'][] = $h_org;
                 $reps['to'][] = $h_tag . ($twice ? $_h * 2 : $_h);
             } else {
                 if ($twice) {
                     $reps['from'][] = $w_org;
                     $reps['to'][] = $w_tag . intval($width * 2);
                     $reps['from'][] = $h_org;
                     $reps['to'][] = $h_tag . intval($height * 2);
                 }
             }
         } else {
             if ($width) {
                 if ($this->Config_pictSizeMax < $width) {
                     $reps['from'][] = $w_org;
                     $reps['to'][] = $w_tag . ($twice ? $this->Config_pictSizeMax * 2 : $this->Config_pictSizeMax);
                 } else {
                     if ($twice) {
                         $reps['from'][] = $w_org;
                         $reps['to'][] = $w_tag . intval($width * 2);
                     }
                 }
             } else {
                 if ($height) {
                     if ($this->Config_pictSizeMax < $height) {
                         $reps['from'][] = $h_org;
                         $reps['to'][] = $h_tag . ($twice ? $this->Config_pictSizeMax * 2 : $this->Config_pictSizeMax);
                     } else {
                         if ($twice) {
                             $reps['from'][] = $h_org;
                             $reps['to'][] = $h_tag . intval($height * 2);
                         }
                     }
                 } else {
                     if ($twice) {
                         if ($imagesize = HypCommonFunc::get_imagesize4ktai($url, $this->Config_pictSizeMax, $this->vars['ua']['allowPNG'])) {
                             list($_w, $_h) = explode('x', $imagesize);
                             $_w = intval($_w * 2);
                             $_h = intval($_h * 2);
                             $_size = ' width="' . $_w . '" height="' . $_h . '"';
                         }
                     }
                 }
             }
         }
         if (HypCommonFunc::get_imagefilesize4ktai($url, $this->Config_pictSizeMax, $this->vars['ua']['allowPNG']) !== 0) {
             $src = $this->Config_hypCommonURL . '/gate.php?way=imgconv&amp;m=i4k&amp;s=' . $this->Config_pictSizeMax . $png . '&amp;u=' . rawurlencode($url);
         }
         $ret = $match[1] . $_size . ' src="' . $src . '"' . $match[5];
         if (isset($reps['from'])) {
             $ret = str_replace($reps['from'], $reps['to'], $ret);
         }
         return $ret . (isset($match[6]) ? $match[6] : '');
     } else {
         if ($type === 'input') {
             return str_replace('image', 'submit', $match[1] . $match[5]) . (isset($match[6]) ? $match[6] : '');
         } else {
             if (empty($parsed_url['host']) || preg_match($directHostReg, $parsed_url['host'])) {
                 if ($rewiteUrl && $rewiteUrl !== $match[4]) {
                     $match[0] = str_replace($match[4], $rewiteUrl, $match[0]);
                 }
                 return $match[0];
             } else {
                 if (!isset($match[6])) {
                     return "" . ' href="' . $url . '">[PIC]</a>';
                 } else {
                     return htmlspecialchars($parsed_url['host']) . $match[6];
                 }
             }
         }
     }
 }