function escape($str) { // Unescape already-escaped chars (<, >, &, ...) in RSS body before htmlspecialchars() $str = strtr($str, array_flip(get_html_translation_table(ENT_COMPAT))); // Escape $str = htmlspecialchars($str, ENT_COMPAT, HypCommonFunc::get_htmlspecialchars_encoding($this->encoding)); //echo $str; // Unescape $str = str_replace('&', '&', $str); // Encoding conversion //$this->func->encode_numericentity($str, $this->cont['SOURCE_ENCODING'], $this->encoding); $str = mb_convert_encoding($str, 'UTF-8', $this->encoding); return trim($str); }
function init() { $this->xml = ''; $this->compactArray = array(); $this->html = ''; $this->searchKey = ''; $this->newestTime = 0; $this->error = ''; $this->batchCount = 0; $this->batchKeys = array(); $this->htmlsp_encoding = HypCommonFunc::get_htmlspecialchars_encoding($this->encoding); if (!$this->cacheDir) { $this->cacheDir = (defined(XOOPS_TRUST_PATH) ? XOOPS_TRUST_PATH : dirname(dirname(dirname(dirname(__FILE__))))) . '/cache/'; } }
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&m=i4k&s=' . $this->Config_pictSizeMax . $png . '&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'], ENT_COMPAT, HypCommonFunc::get_htmlspecialchars_encoding($this->inputEncode)) . $match[6]; } } } } }
public static function get_search_words($words, $special = false, $enc = 'EUC-JP') { $retval = array(); //if (defined('XOOPS_USE_MULTIBYTES') && XOOPS_USE_MULTIBYTES && (!function_exists('mb_strlen') || !function_exists('mb_substr'))) return $retval; // Perlメモ - 正しくパターンマッチさせる // http://www.din.or.jp/~ohzaki/perl.htm#JP_Match $eucpre = $eucpost = ''; $enc = strtoupper($enc); $is_utf8 = false; if ($enc === 'EUC-JP' || $enc === 'EUCJP-WIN') { $eucpre = '(?<!\\x8F)'; // # JIS X 0208 が 0文字以上続いて # ASCII, SS2, SS3 または終端 $eucpost = '(?=(?:[\\xA1-\\xFE][\\xA1-\\xFE])*(?:[\\x00-\\x7F\\x8E\\x8F]|\\z))'; } else { if ($enc === 'UTF-8') { $is_utf8 = true; } } // $special : htmlspecialchars()を通すか $quote_func = create_function('$str', $special ? 'return preg_quote($str,"/");' : 'return preg_quote(htmlspecialchars($str, ENT_COMPAT, \'' . HypCommonFunc::get_htmlspecialchars_encoding($enc) . '\'),"/");'); // LANG=='ja'で、mb_convert_kanaが使える場合はmb_convert_kanaを使用 $convert_kana_exists = function_exists('mb_convert_kana'); $convert_kana = create_function('$str,$option,$enc', $convert_kana_exists ? 'return mb_convert_kana($str,$option,$enc);' : 'return $str;'); $mb_strlen = create_function('$str,$enc', function_exists('mb_strlen') ? 'return mb_strlen($str,$enc);' : 'return strlen($str);'); $mb_substr = create_function('$str,$start,$len,$enc', function_exists('mb_substr') ? 'return mb_substr($str,$start,$len,$enc);' : 'return substr($str,$start,$len);'); foreach ($words as $word) { // 英数字は半角,カタカナは全角,ひらがなはカタカナに $word_zk = $convert_kana($word, 'aKCV', $enc); $chars = array(); for ($pos = 0; $pos < $mb_strlen($word_zk, $enc); $pos++) { $char = $mb_substr($word_zk, $pos, 1, $enc); $arr = array($quote_func($char)); if (strlen($char) == 1) { $arr[] = $quote_func($char); // 英文字 if ($convert_kana_exists) { $arr[] = $quote_func($convert_kana(strtoupper($char), "A", $enc)); // 全角大文字 $arr[] = $quote_func($convert_kana(strtolower($char), "A", $enc)); // 全角小文字 } } else { $arr[] = $quote_func($convert_kana($char, "c", $enc)); // ひらがな $arr[] = $quote_func($convert_kana($char, "k", $enc)); // 半角カタカナ } if ($is_utf8) { $chars[] = '[' . join('', array_unique($arr)) . ']'; } else { $chars[] = '(?:' . join('|', array_unique($arr)) . ')'; } } $retval[$word] = $eucpre . join('', $chars) . $eucpost; } return $retval; }