Edit File by line
/home/barbar84/public_h.../wp-inclu.../SimplePi...
File: Misc.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* SimplePie
[2] Fix | Delete
*
[3] Fix | Delete
* A PHP-Based RSS and Atom Feed Framework.
[4] Fix | Delete
* Takes the hard work out of managing a complete RSS/Atom solution.
[5] Fix | Delete
*
[6] Fix | Delete
* Copyright (c) 2004-2016, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
[7] Fix | Delete
* All rights reserved.
[8] Fix | Delete
*
[9] Fix | Delete
* Redistribution and use in source and binary forms, with or without modification, are
[10] Fix | Delete
* permitted provided that the following conditions are met:
[11] Fix | Delete
*
[12] Fix | Delete
* * Redistributions of source code must retain the above copyright notice, this list of
[13] Fix | Delete
* conditions and the following disclaimer.
[14] Fix | Delete
*
[15] Fix | Delete
* * Redistributions in binary form must reproduce the above copyright notice, this list
[16] Fix | Delete
* of conditions and the following disclaimer in the documentation and/or other materials
[17] Fix | Delete
* provided with the distribution.
[18] Fix | Delete
*
[19] Fix | Delete
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
[20] Fix | Delete
* to endorse or promote products derived from this software without specific prior
[21] Fix | Delete
* written permission.
[22] Fix | Delete
*
[23] Fix | Delete
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
[24] Fix | Delete
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
[25] Fix | Delete
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
[26] Fix | Delete
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
[27] Fix | Delete
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
[28] Fix | Delete
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
[29] Fix | Delete
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
[30] Fix | Delete
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
[31] Fix | Delete
* POSSIBILITY OF SUCH DAMAGE.
[32] Fix | Delete
*
[33] Fix | Delete
* @package SimplePie
[34] Fix | Delete
* @copyright 2004-2016 Ryan Parman, Sam Sneddon, Ryan McCue
[35] Fix | Delete
* @author Ryan Parman
[36] Fix | Delete
* @author Sam Sneddon
[37] Fix | Delete
* @author Ryan McCue
[38] Fix | Delete
* @link http://simplepie.org/ SimplePie
[39] Fix | Delete
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
[40] Fix | Delete
*/
[41] Fix | Delete
[42] Fix | Delete
/**
[43] Fix | Delete
* Miscellanous utilities
[44] Fix | Delete
*
[45] Fix | Delete
* @package SimplePie
[46] Fix | Delete
*/
[47] Fix | Delete
class SimplePie_Misc
[48] Fix | Delete
{
[49] Fix | Delete
public static function time_hms($seconds)
[50] Fix | Delete
{
[51] Fix | Delete
$time = '';
[52] Fix | Delete
[53] Fix | Delete
$hours = floor($seconds / 3600);
[54] Fix | Delete
$remainder = $seconds % 3600;
[55] Fix | Delete
if ($hours > 0)
[56] Fix | Delete
{
[57] Fix | Delete
$time .= $hours.':';
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
$minutes = floor($remainder / 60);
[61] Fix | Delete
$seconds = $remainder % 60;
[62] Fix | Delete
if ($minutes < 10 && $hours > 0)
[63] Fix | Delete
{
[64] Fix | Delete
$minutes = '0' . $minutes;
[65] Fix | Delete
}
[66] Fix | Delete
if ($seconds < 10)
[67] Fix | Delete
{
[68] Fix | Delete
$seconds = '0' . $seconds;
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
$time .= $minutes.':';
[72] Fix | Delete
$time .= $seconds;
[73] Fix | Delete
[74] Fix | Delete
return $time;
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
public static function absolutize_url($relative, $base)
[78] Fix | Delete
{
[79] Fix | Delete
$iri = SimplePie_IRI::absolutize(new SimplePie_IRI($base), $relative);
[80] Fix | Delete
if ($iri === false)
[81] Fix | Delete
{
[82] Fix | Delete
return false;
[83] Fix | Delete
}
[84] Fix | Delete
return $iri->get_uri();
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
/**
[88] Fix | Delete
* Get a HTML/XML element from a HTML string
[89] Fix | Delete
*
[90] Fix | Delete
* @deprecated Use DOMDocument instead (parsing HTML with regex is bad!)
[91] Fix | Delete
* @param string $realname Element name (including namespace prefix if applicable)
[92] Fix | Delete
* @param string $string HTML document
[93] Fix | Delete
* @return array
[94] Fix | Delete
*/
[95] Fix | Delete
public static function get_element($realname, $string)
[96] Fix | Delete
{
[97] Fix | Delete
$return = array();
[98] Fix | Delete
$name = preg_quote($realname, '/');
[99] Fix | Delete
if (preg_match_all("/<($name)" . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . "(>(.*)<\/$name>|(\/)?>)/siU", $string, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE))
[100] Fix | Delete
{
[101] Fix | Delete
for ($i = 0, $total_matches = count($matches); $i < $total_matches; $i++)
[102] Fix | Delete
{
[103] Fix | Delete
$return[$i]['tag'] = $realname;
[104] Fix | Delete
$return[$i]['full'] = $matches[$i][0][0];
[105] Fix | Delete
$return[$i]['offset'] = $matches[$i][0][1];
[106] Fix | Delete
if (strlen($matches[$i][3][0]) <= 2)
[107] Fix | Delete
{
[108] Fix | Delete
$return[$i]['self_closing'] = true;
[109] Fix | Delete
}
[110] Fix | Delete
else
[111] Fix | Delete
{
[112] Fix | Delete
$return[$i]['self_closing'] = false;
[113] Fix | Delete
$return[$i]['content'] = $matches[$i][4][0];
[114] Fix | Delete
}
[115] Fix | Delete
$return[$i]['attribs'] = array();
[116] Fix | Delete
if (isset($matches[$i][2][0]) && preg_match_all('/[\x09\x0A\x0B\x0C\x0D\x20]+([^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3D\x3E]*)(?:[\x09\x0A\x0B\x0C\x0D\x20]*=[\x09\x0A\x0B\x0C\x0D\x20]*(?:"([^"]*)"|\'([^\']*)\'|([^\x09\x0A\x0B\x0C\x0D\x20\x22\x27\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x3E]*)?))?/', ' ' . $matches[$i][2][0] . ' ', $attribs, PREG_SET_ORDER))
[117] Fix | Delete
{
[118] Fix | Delete
for ($j = 0, $total_attribs = count($attribs); $j < $total_attribs; $j++)
[119] Fix | Delete
{
[120] Fix | Delete
if (count($attribs[$j]) === 2)
[121] Fix | Delete
{
[122] Fix | Delete
$attribs[$j][2] = $attribs[$j][1];
[123] Fix | Delete
}
[124] Fix | Delete
$return[$i]['attribs'][strtolower($attribs[$j][1])]['data'] = SimplePie_Misc::entities_decode(end($attribs[$j]));
[125] Fix | Delete
}
[126] Fix | Delete
}
[127] Fix | Delete
}
[128] Fix | Delete
}
[129] Fix | Delete
return $return;
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
public static function element_implode($element)
[133] Fix | Delete
{
[134] Fix | Delete
$full = "<$element[tag]";
[135] Fix | Delete
foreach ($element['attribs'] as $key => $value)
[136] Fix | Delete
{
[137] Fix | Delete
$key = strtolower($key);
[138] Fix | Delete
$full .= " $key=\"" . htmlspecialchars($value['data'], ENT_COMPAT, 'UTF-8') . '"';
[139] Fix | Delete
}
[140] Fix | Delete
if ($element['self_closing'])
[141] Fix | Delete
{
[142] Fix | Delete
$full .= ' />';
[143] Fix | Delete
}
[144] Fix | Delete
else
[145] Fix | Delete
{
[146] Fix | Delete
$full .= ">$element[content]</$element[tag]>";
[147] Fix | Delete
}
[148] Fix | Delete
return $full;
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
public static function error($message, $level, $file, $line)
[152] Fix | Delete
{
[153] Fix | Delete
if ((ini_get('error_reporting') & $level) > 0)
[154] Fix | Delete
{
[155] Fix | Delete
switch ($level)
[156] Fix | Delete
{
[157] Fix | Delete
case E_USER_ERROR:
[158] Fix | Delete
$note = 'PHP Error';
[159] Fix | Delete
break;
[160] Fix | Delete
case E_USER_WARNING:
[161] Fix | Delete
$note = 'PHP Warning';
[162] Fix | Delete
break;
[163] Fix | Delete
case E_USER_NOTICE:
[164] Fix | Delete
$note = 'PHP Notice';
[165] Fix | Delete
break;
[166] Fix | Delete
default:
[167] Fix | Delete
$note = 'Unknown Error';
[168] Fix | Delete
break;
[169] Fix | Delete
}
[170] Fix | Delete
[171] Fix | Delete
$log_error = true;
[172] Fix | Delete
if (!function_exists('error_log'))
[173] Fix | Delete
{
[174] Fix | Delete
$log_error = false;
[175] Fix | Delete
}
[176] Fix | Delete
[177] Fix | Delete
$log_file = @ini_get('error_log');
[178] Fix | Delete
if (!empty($log_file) && ('syslog' !== $log_file) && !@is_writable($log_file))
[179] Fix | Delete
{
[180] Fix | Delete
$log_error = false;
[181] Fix | Delete
}
[182] Fix | Delete
[183] Fix | Delete
if ($log_error)
[184] Fix | Delete
{
[185] Fix | Delete
@error_log("$note: $message in $file on line $line", 0);
[186] Fix | Delete
}
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
return $message;
[190] Fix | Delete
}
[191] Fix | Delete
[192] Fix | Delete
public static function fix_protocol($url, $http = 1)
[193] Fix | Delete
{
[194] Fix | Delete
$url = SimplePie_Misc::normalize_url($url);
[195] Fix | Delete
$parsed = SimplePie_Misc::parse_url($url);
[196] Fix | Delete
if ($parsed['scheme'] !== '' && $parsed['scheme'] !== 'http' && $parsed['scheme'] !== 'https')
[197] Fix | Delete
{
[198] Fix | Delete
return SimplePie_Misc::fix_protocol(SimplePie_Misc::compress_parse_url('http', $parsed['authority'], $parsed['path'], $parsed['query'], $parsed['fragment']), $http);
[199] Fix | Delete
}
[200] Fix | Delete
[201] Fix | Delete
if ($parsed['scheme'] === '' && $parsed['authority'] === '' && !file_exists($url))
[202] Fix | Delete
{
[203] Fix | Delete
return SimplePie_Misc::fix_protocol(SimplePie_Misc::compress_parse_url('http', $parsed['path'], '', $parsed['query'], $parsed['fragment']), $http);
[204] Fix | Delete
}
[205] Fix | Delete
[206] Fix | Delete
if ($http === 2 && $parsed['scheme'] !== '')
[207] Fix | Delete
{
[208] Fix | Delete
return "feed:$url";
[209] Fix | Delete
}
[210] Fix | Delete
elseif ($http === 3 && strtolower($parsed['scheme']) === 'http')
[211] Fix | Delete
{
[212] Fix | Delete
return substr_replace($url, 'podcast', 0, 4);
[213] Fix | Delete
}
[214] Fix | Delete
elseif ($http === 4 && strtolower($parsed['scheme']) === 'http')
[215] Fix | Delete
{
[216] Fix | Delete
return substr_replace($url, 'itpc', 0, 4);
[217] Fix | Delete
}
[218] Fix | Delete
[219] Fix | Delete
return $url;
[220] Fix | Delete
}
[221] Fix | Delete
[222] Fix | Delete
public static function array_merge_recursive($array1, $array2)
[223] Fix | Delete
{
[224] Fix | Delete
foreach ($array2 as $key => $value)
[225] Fix | Delete
{
[226] Fix | Delete
if (is_array($value))
[227] Fix | Delete
{
[228] Fix | Delete
$array1[$key] = SimplePie_Misc::array_merge_recursive($array1[$key], $value);
[229] Fix | Delete
}
[230] Fix | Delete
else
[231] Fix | Delete
{
[232] Fix | Delete
$array1[$key] = $value;
[233] Fix | Delete
}
[234] Fix | Delete
}
[235] Fix | Delete
[236] Fix | Delete
return $array1;
[237] Fix | Delete
}
[238] Fix | Delete
[239] Fix | Delete
public static function parse_url($url)
[240] Fix | Delete
{
[241] Fix | Delete
$iri = new SimplePie_IRI($url);
[242] Fix | Delete
return array(
[243] Fix | Delete
'scheme' => (string) $iri->scheme,
[244] Fix | Delete
'authority' => (string) $iri->authority,
[245] Fix | Delete
'path' => (string) $iri->path,
[246] Fix | Delete
'query' => (string) $iri->query,
[247] Fix | Delete
'fragment' => (string) $iri->fragment
[248] Fix | Delete
);
[249] Fix | Delete
}
[250] Fix | Delete
[251] Fix | Delete
public static function compress_parse_url($scheme = '', $authority = '', $path = '', $query = '', $fragment = '')
[252] Fix | Delete
{
[253] Fix | Delete
$iri = new SimplePie_IRI('');
[254] Fix | Delete
$iri->scheme = $scheme;
[255] Fix | Delete
$iri->authority = $authority;
[256] Fix | Delete
$iri->path = $path;
[257] Fix | Delete
$iri->query = $query;
[258] Fix | Delete
$iri->fragment = $fragment;
[259] Fix | Delete
return $iri->get_uri();
[260] Fix | Delete
}
[261] Fix | Delete
[262] Fix | Delete
public static function normalize_url($url)
[263] Fix | Delete
{
[264] Fix | Delete
$iri = new SimplePie_IRI($url);
[265] Fix | Delete
return $iri->get_uri();
[266] Fix | Delete
}
[267] Fix | Delete
[268] Fix | Delete
public static function percent_encoding_normalization($match)
[269] Fix | Delete
{
[270] Fix | Delete
$integer = hexdec($match[1]);
[271] Fix | Delete
if ($integer >= 0x41 && $integer <= 0x5A || $integer >= 0x61 && $integer <= 0x7A || $integer >= 0x30 && $integer <= 0x39 || $integer === 0x2D || $integer === 0x2E || $integer === 0x5F || $integer === 0x7E)
[272] Fix | Delete
{
[273] Fix | Delete
return chr($integer);
[274] Fix | Delete
}
[275] Fix | Delete
[276] Fix | Delete
return strtoupper($match[0]);
[277] Fix | Delete
}
[278] Fix | Delete
[279] Fix | Delete
/**
[280] Fix | Delete
* Converts a Windows-1252 encoded string to a UTF-8 encoded string
[281] Fix | Delete
*
[282] Fix | Delete
* @static
[283] Fix | Delete
* @param string $string Windows-1252 encoded string
[284] Fix | Delete
* @return string UTF-8 encoded string
[285] Fix | Delete
*/
[286] Fix | Delete
public static function windows_1252_to_utf8($string)
[287] Fix | Delete
{
[288] Fix | Delete
static $convert_table = array("\x80" => "\xE2\x82\xAC", "\x81" => "\xEF\xBF\xBD", "\x82" => "\xE2\x80\x9A", "\x83" => "\xC6\x92", "\x84" => "\xE2\x80\x9E", "\x85" => "\xE2\x80\xA6", "\x86" => "\xE2\x80\xA0", "\x87" => "\xE2\x80\xA1", "\x88" => "\xCB\x86", "\x89" => "\xE2\x80\xB0", "\x8A" => "\xC5\xA0", "\x8B" => "\xE2\x80\xB9", "\x8C" => "\xC5\x92", "\x8D" => "\xEF\xBF\xBD", "\x8E" => "\xC5\xBD", "\x8F" => "\xEF\xBF\xBD", "\x90" => "\xEF\xBF\xBD", "\x91" => "\xE2\x80\x98", "\x92" => "\xE2\x80\x99", "\x93" => "\xE2\x80\x9C", "\x94" => "\xE2\x80\x9D", "\x95" => "\xE2\x80\xA2", "\x96" => "\xE2\x80\x93", "\x97" => "\xE2\x80\x94", "\x98" => "\xCB\x9C", "\x99" => "\xE2\x84\xA2", "\x9A" => "\xC5\xA1", "\x9B" => "\xE2\x80\xBA", "\x9C" => "\xC5\x93", "\x9D" => "\xEF\xBF\xBD", "\x9E" => "\xC5\xBE", "\x9F" => "\xC5\xB8", "\xA0" => "\xC2\xA0", "\xA1" => "\xC2\xA1", "\xA2" => "\xC2\xA2", "\xA3" => "\xC2\xA3", "\xA4" => "\xC2\xA4", "\xA5" => "\xC2\xA5", "\xA6" => "\xC2\xA6", "\xA7" => "\xC2\xA7", "\xA8" => "\xC2\xA8", "\xA9" => "\xC2\xA9", "\xAA" => "\xC2\xAA", "\xAB" => "\xC2\xAB", "\xAC" => "\xC2\xAC", "\xAD" => "\xC2\xAD", "\xAE" => "\xC2\xAE", "\xAF" => "\xC2\xAF", "\xB0" => "\xC2\xB0", "\xB1" => "\xC2\xB1", "\xB2" => "\xC2\xB2", "\xB3" => "\xC2\xB3", "\xB4" => "\xC2\xB4", "\xB5" => "\xC2\xB5", "\xB6" => "\xC2\xB6", "\xB7" => "\xC2\xB7", "\xB8" => "\xC2\xB8", "\xB9" => "\xC2\xB9", "\xBA" => "\xC2\xBA", "\xBB" => "\xC2\xBB", "\xBC" => "\xC2\xBC", "\xBD" => "\xC2\xBD", "\xBE" => "\xC2\xBE", "\xBF" => "\xC2\xBF", "\xC0" => "\xC3\x80", "\xC1" => "\xC3\x81", "\xC2" => "\xC3\x82", "\xC3" => "\xC3\x83", "\xC4" => "\xC3\x84", "\xC5" => "\xC3\x85", "\xC6" => "\xC3\x86", "\xC7" => "\xC3\x87", "\xC8" => "\xC3\x88", "\xC9" => "\xC3\x89", "\xCA" => "\xC3\x8A", "\xCB" => "\xC3\x8B", "\xCC" => "\xC3\x8C", "\xCD" => "\xC3\x8D", "\xCE" => "\xC3\x8E", "\xCF" => "\xC3\x8F", "\xD0" => "\xC3\x90", "\xD1" => "\xC3\x91", "\xD2" => "\xC3\x92", "\xD3" => "\xC3\x93", "\xD4" => "\xC3\x94", "\xD5" => "\xC3\x95", "\xD6" => "\xC3\x96", "\xD7" => "\xC3\x97", "\xD8" => "\xC3\x98", "\xD9" => "\xC3\x99", "\xDA" => "\xC3\x9A", "\xDB" => "\xC3\x9B", "\xDC" => "\xC3\x9C", "\xDD" => "\xC3\x9D", "\xDE" => "\xC3\x9E", "\xDF" => "\xC3\x9F", "\xE0" => "\xC3\xA0", "\xE1" => "\xC3\xA1", "\xE2" => "\xC3\xA2", "\xE3" => "\xC3\xA3", "\xE4" => "\xC3\xA4", "\xE5" => "\xC3\xA5", "\xE6" => "\xC3\xA6", "\xE7" => "\xC3\xA7", "\xE8" => "\xC3\xA8", "\xE9" => "\xC3\xA9", "\xEA" => "\xC3\xAA", "\xEB" => "\xC3\xAB", "\xEC" => "\xC3\xAC", "\xED" => "\xC3\xAD", "\xEE" => "\xC3\xAE", "\xEF" => "\xC3\xAF", "\xF0" => "\xC3\xB0", "\xF1" => "\xC3\xB1", "\xF2" => "\xC3\xB2", "\xF3" => "\xC3\xB3", "\xF4" => "\xC3\xB4", "\xF5" => "\xC3\xB5", "\xF6" => "\xC3\xB6", "\xF7" => "\xC3\xB7", "\xF8" => "\xC3\xB8", "\xF9" => "\xC3\xB9", "\xFA" => "\xC3\xBA", "\xFB" => "\xC3\xBB", "\xFC" => "\xC3\xBC", "\xFD" => "\xC3\xBD", "\xFE" => "\xC3\xBE", "\xFF" => "\xC3\xBF");
[289] Fix | Delete
[290] Fix | Delete
return strtr($string, $convert_table);
[291] Fix | Delete
}
[292] Fix | Delete
[293] Fix | Delete
/**
[294] Fix | Delete
* Change a string from one encoding to another
[295] Fix | Delete
*
[296] Fix | Delete
* @param string $data Raw data in $input encoding
[297] Fix | Delete
* @param string $input Encoding of $data
[298] Fix | Delete
* @param string $output Encoding you want
[299] Fix | Delete
* @return string|boolean False if we can't convert it
[300] Fix | Delete
*/
[301] Fix | Delete
public static function change_encoding($data, $input, $output)
[302] Fix | Delete
{
[303] Fix | Delete
$input = SimplePie_Misc::encoding($input);
[304] Fix | Delete
$output = SimplePie_Misc::encoding($output);
[305] Fix | Delete
[306] Fix | Delete
// We fail to fail on non US-ASCII bytes
[307] Fix | Delete
if ($input === 'US-ASCII')
[308] Fix | Delete
{
[309] Fix | Delete
static $non_ascii_octects = '';
[310] Fix | Delete
if (!$non_ascii_octects)
[311] Fix | Delete
{
[312] Fix | Delete
for ($i = 0x80; $i <= 0xFF; $i++)
[313] Fix | Delete
{
[314] Fix | Delete
$non_ascii_octects .= chr($i);
[315] Fix | Delete
}
[316] Fix | Delete
}
[317] Fix | Delete
$data = substr($data, 0, strcspn($data, $non_ascii_octects));
[318] Fix | Delete
}
[319] Fix | Delete
[320] Fix | Delete
// This is first, as behaviour of this is completely predictable
[321] Fix | Delete
if ($input === 'windows-1252' && $output === 'UTF-8')
[322] Fix | Delete
{
[323] Fix | Delete
return SimplePie_Misc::windows_1252_to_utf8($data);
[324] Fix | Delete
}
[325] Fix | Delete
// This is second, as behaviour of this varies only with PHP version (the middle part of this expression checks the encoding is supported).
[326] Fix | Delete
elseif (function_exists('mb_convert_encoding') && ($return = SimplePie_Misc::change_encoding_mbstring($data, $input, $output)))
[327] Fix | Delete
{
[328] Fix | Delete
return $return;
[329] Fix | Delete
}
[330] Fix | Delete
// This is third, as behaviour of this varies with OS userland and PHP version
[331] Fix | Delete
elseif (function_exists('iconv') && ($return = SimplePie_Misc::change_encoding_iconv($data, $input, $output)))
[332] Fix | Delete
{
[333] Fix | Delete
return $return;
[334] Fix | Delete
}
[335] Fix | Delete
// This is last, as behaviour of this varies with OS userland and PHP version
[336] Fix | Delete
elseif (class_exists('\UConverter') && ($return = SimplePie_Misc::change_encoding_uconverter($data, $input, $output)))
[337] Fix | Delete
{
[338] Fix | Delete
return $return;
[339] Fix | Delete
}
[340] Fix | Delete
[341] Fix | Delete
// If we can't do anything, just fail
[342] Fix | Delete
return false;
[343] Fix | Delete
}
[344] Fix | Delete
[345] Fix | Delete
protected static function change_encoding_mbstring($data, $input, $output)
[346] Fix | Delete
{
[347] Fix | Delete
if ($input === 'windows-949')
[348] Fix | Delete
{
[349] Fix | Delete
$input = 'EUC-KR';
[350] Fix | Delete
}
[351] Fix | Delete
if ($output === 'windows-949')
[352] Fix | Delete
{
[353] Fix | Delete
$output = 'EUC-KR';
[354] Fix | Delete
}
[355] Fix | Delete
if ($input === 'Windows-31J')
[356] Fix | Delete
{
[357] Fix | Delete
$input = 'SJIS';
[358] Fix | Delete
}
[359] Fix | Delete
if ($output === 'Windows-31J')
[360] Fix | Delete
{
[361] Fix | Delete
$output = 'SJIS';
[362] Fix | Delete
}
[363] Fix | Delete
[364] Fix | Delete
// Check that the encoding is supported
[365] Fix | Delete
if (!in_array($input, mb_list_encodings()))
[366] Fix | Delete
{
[367] Fix | Delete
return false;
[368] Fix | Delete
}
[369] Fix | Delete
[370] Fix | Delete
if (@mb_convert_encoding("\x80", 'UTF-16BE', $input) === "\x00\x80")
[371] Fix | Delete
{
[372] Fix | Delete
return false;
[373] Fix | Delete
}
[374] Fix | Delete
[375] Fix | Delete
// Let's do some conversion
[376] Fix | Delete
if ($return = @mb_convert_encoding($data, $output, $input))
[377] Fix | Delete
{
[378] Fix | Delete
return $return;
[379] Fix | Delete
}
[380] Fix | Delete
[381] Fix | Delete
return false;
[382] Fix | Delete
}
[383] Fix | Delete
[384] Fix | Delete
protected static function change_encoding_iconv($data, $input, $output)
[385] Fix | Delete
{
[386] Fix | Delete
return @iconv($input, $output, $data);
[387] Fix | Delete
}
[388] Fix | Delete
[389] Fix | Delete
/**
[390] Fix | Delete
* @param string $data
[391] Fix | Delete
* @param string $input
[392] Fix | Delete
* @param string $output
[393] Fix | Delete
* @return string|false
[394] Fix | Delete
*/
[395] Fix | Delete
protected static function change_encoding_uconverter($data, $input, $output)
[396] Fix | Delete
{
[397] Fix | Delete
return @\UConverter::transcode($data, $output, $input);
[398] Fix | Delete
}
[399] Fix | Delete
[400] Fix | Delete
/**
[401] Fix | Delete
* Normalize an encoding name
[402] Fix | Delete
*
[403] Fix | Delete
* This is automatically generated by create.php
[404] Fix | Delete
*
[405] Fix | Delete
* To generate it, run `php create.php` on the command line, and copy the
[406] Fix | Delete
* output to replace this function.
[407] Fix | Delete
*
[408] Fix | Delete
* @param string $charset Character set to standardise
[409] Fix | Delete
* @return string Standardised name
[410] Fix | Delete
*/
[411] Fix | Delete
public static function encoding($charset)
[412] Fix | Delete
{
[413] Fix | Delete
// Normalization from UTS #22
[414] Fix | Delete
switch (strtolower(preg_replace('/(?:[^a-zA-Z0-9]+|([^0-9])0+)/', '\1', $charset)))
[415] Fix | Delete
{
[416] Fix | Delete
case 'adobestandardencoding':
[417] Fix | Delete
case 'csadobestandardencoding':
[418] Fix | Delete
return 'Adobe-Standard-Encoding';
[419] Fix | Delete
[420] Fix | Delete
case 'adobesymbolencoding':
[421] Fix | Delete
case 'cshppsmath':
[422] Fix | Delete
return 'Adobe-Symbol-Encoding';
[423] Fix | Delete
[424] Fix | Delete
case 'ami1251':
[425] Fix | Delete
case 'amiga1251':
[426] Fix | Delete
return 'Amiga-1251';
[427] Fix | Delete
[428] Fix | Delete
case 'ansix31101983':
[429] Fix | Delete
case 'csat5001983':
[430] Fix | Delete
case 'csiso99naplps':
[431] Fix | Delete
case 'isoir99':
[432] Fix | Delete
case 'naplps':
[433] Fix | Delete
return 'ANSI_X3.110-1983';
[434] Fix | Delete
[435] Fix | Delete
case 'arabic7':
[436] Fix | Delete
case 'asmo449':
[437] Fix | Delete
case 'csiso89asmo449':
[438] Fix | Delete
case 'iso9036':
[439] Fix | Delete
case 'isoir89':
[440] Fix | Delete
return 'ASMO_449';
[441] Fix | Delete
[442] Fix | Delete
case 'big5':
[443] Fix | Delete
case 'csbig5':
[444] Fix | Delete
return 'Big5';
[445] Fix | Delete
[446] Fix | Delete
case 'big5hkscs':
[447] Fix | Delete
return 'Big5-HKSCS';
[448] Fix | Delete
[449] Fix | Delete
case 'bocu1':
[450] Fix | Delete
case 'csbocu1':
[451] Fix | Delete
return 'BOCU-1';
[452] Fix | Delete
[453] Fix | Delete
case 'brf':
[454] Fix | Delete
case 'csbrf':
[455] Fix | Delete
return 'BRF';
[456] Fix | Delete
[457] Fix | Delete
case 'bs4730':
[458] Fix | Delete
case 'csiso4unitedkingdom':
[459] Fix | Delete
case 'gb':
[460] Fix | Delete
case 'iso646gb':
[461] Fix | Delete
case 'isoir4':
[462] Fix | Delete
case 'uk':
[463] Fix | Delete
return 'BS_4730';
[464] Fix | Delete
[465] Fix | Delete
case 'bsviewdata':
[466] Fix | Delete
case 'csiso47bsviewdata':
[467] Fix | Delete
case 'isoir47':
[468] Fix | Delete
return 'BS_viewdata';
[469] Fix | Delete
[470] Fix | Delete
case 'cesu8':
[471] Fix | Delete
case 'cscesu8':
[472] Fix | Delete
return 'CESU-8';
[473] Fix | Delete
[474] Fix | Delete
case 'ca':
[475] Fix | Delete
case 'csa71':
[476] Fix | Delete
case 'csaz243419851':
[477] Fix | Delete
case 'csiso121canadian1':
[478] Fix | Delete
case 'iso646ca':
[479] Fix | Delete
case 'isoir121':
[480] Fix | Delete
return 'CSA_Z243.4-1985-1';
[481] Fix | Delete
[482] Fix | Delete
case 'csa72':
[483] Fix | Delete
case 'csaz243419852':
[484] Fix | Delete
case 'csiso122canadian2':
[485] Fix | Delete
case 'iso646ca2':
[486] Fix | Delete
case 'isoir122':
[487] Fix | Delete
return 'CSA_Z243.4-1985-2';
[488] Fix | Delete
[489] Fix | Delete
case 'csaz24341985gr':
[490] Fix | Delete
case 'csiso123csaz24341985gr':
[491] Fix | Delete
case 'isoir123':
[492] Fix | Delete
return 'CSA_Z243.4-1985-gr';
[493] Fix | Delete
[494] Fix | Delete
case 'csiso139csn369103':
[495] Fix | Delete
case 'csn369103':
[496] Fix | Delete
case 'isoir139':
[497] Fix | Delete
return 'CSN_369103';
[498] Fix | Delete
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function