|
@@ -68,7 +68,12 @@ function api_set_encoding_html(&$string, $encoding)
|
|
|
}
|
|
|
} else {
|
|
|
$count = 1;
|
|
|
- $string = str_ireplace('</head>', '<meta http-equiv="Content-Type" content="text/html; charset='.$encoding.'"/></head>', $string, $count);
|
|
|
+ $string = str_ireplace(
|
|
|
+ '</head>',
|
|
|
+ '<meta http-equiv="Content-Type" content="text/html; charset='.$encoding.'"/></head>',
|
|
|
+ $string,
|
|
|
+ $count
|
|
|
+ );
|
|
|
}
|
|
|
$string = api_convert_encoding($string, $encoding, $old_encoding);
|
|
|
}
|
|
@@ -76,9 +81,10 @@ function api_set_encoding_html(&$string, $encoding)
|
|
|
/**
|
|
|
* Returns the title of a html document.
|
|
|
* @param string $string The contents of the input document.
|
|
|
- * @param string $output_encoding The encoding of the retrieved title. If the value is not set, the system encoding is assumend.
|
|
|
- * @param string $input_encoding The encoding of the input document. If the value is not set, it is detected.
|
|
|
- * @return string The retrieved title, html-entities and extra-whitespace between the words are cleaned.
|
|
|
+ * @param string $output_encoding The encoding of the retrieved title.
|
|
|
+ * If the value is not set, the system encoding is assumed.
|
|
|
+ * @param string $input_encoding The encoding of the input document. If the value is not set, it is detected.
|
|
|
+ * @return string The retrieved title, html-entities and extra-whitespace between the words are cleaned.
|
|
|
*/
|
|
|
function api_get_title_html(&$string, $output_encoding = null, $input_encoding = null)
|
|
|
{
|
|
@@ -89,7 +95,17 @@ function api_get_title_html(&$string, $output_encoding = null, $input_encoding =
|
|
|
if (empty($input_encoding)) {
|
|
|
$input_encoding = api_detect_encoding_html($string);
|
|
|
}
|
|
|
- return trim(@preg_replace('/\s+/', ' ', api_html_entity_decode(api_convert_encoding($matches[1], $output_encoding, $input_encoding), ENT_QUOTES, $output_encoding)));
|
|
|
+ return trim(
|
|
|
+ @preg_replace(
|
|
|
+ '/\s+/',
|
|
|
+ ' ',
|
|
|
+ api_html_entity_decode(
|
|
|
+ api_convert_encoding($matches[1], $output_encoding, $input_encoding),
|
|
|
+ ENT_QUOTES,
|
|
|
+ $output_encoding
|
|
|
+ )
|
|
|
+ )
|
|
|
+ );
|
|
|
}
|
|
|
return '';
|
|
|
}
|
|
@@ -105,7 +121,8 @@ define('_PCRE_XML_ENCODING', '/<\?xml.*encoding=[\'"](.*?)[\'"].*\?>/m');
|
|
|
/**
|
|
|
* Detects encoding of xml-formatted text.
|
|
|
* @param string $string The input xml-formatted text.
|
|
|
- * @param string $default_encoding This is the default encoding to be returned if there is no way the xml-text's encoding to be detected. If it not spesified, the system encoding is assumed then.
|
|
|
+ * @param string $default_encoding This is the default encoding to be returned
|
|
|
+ * if there is no way the xml-text's encoding to be detected. If it not spesified, the system encoding is assumed then.
|
|
|
* @return string Returns the detected encoding.
|
|
|
* @todo The second parameter is to be eliminated. See api_detect_encoding_html().
|
|
|
*/
|
|
@@ -125,10 +142,12 @@ function api_detect_encoding_xml($string, $default_encoding = null)
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * Converts character encoding of a xml-formatted text. If inside the text the encoding is declared, it is modified accordingly.
|
|
|
+ * Converts character encoding of a xml-formatted text.
|
|
|
+ * If inside the text the encoding is declared, it is modified accordingly.
|
|
|
* @param string $string The text being converted.
|
|
|
* @param string $to_encoding The encoding that text is being converted to.
|
|
|
- * @param string $from_encoding (optional) The encoding that text is being converted from. If it is omited, it is tried to be detected then.
|
|
|
+ * @param string $from_encoding (optional) The encoding that text is being converted from.
|
|
|
+ * If it is omited, it is tried to be detected then.
|
|
|
* @return string Returns the converted xml-text.
|
|
|
*/
|
|
|
function api_convert_encoding_xml($string, $to_encoding, $from_encoding = null)
|
|
@@ -137,9 +156,11 @@ function api_convert_encoding_xml($string, $to_encoding, $from_encoding = null)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Converts character encoding of a xml-formatted text into UTF-8. If inside the text the encoding is declared, it is set to UTF-8.
|
|
|
+ * Converts character encoding of a xml-formatted text into UTF-8.
|
|
|
+ * If inside the text the encoding is declared, it is set to UTF-8.
|
|
|
* @param string $string The text being converted.
|
|
|
- * @param string $from_encoding (optional) The encoding that text is being converted from. If it is omited, it is tried to be detected then.
|
|
|
+ * @param string $from_encoding (optional) The encoding that text is being converted from.
|
|
|
+ * If it is omited, it is tried to be detected then.
|
|
|
* @return string Returns the converted xml-text.
|
|
|
*/
|
|
|
function api_utf8_encode_xml($string, $from_encoding = null)
|
|
@@ -148,9 +169,11 @@ function api_utf8_encode_xml($string, $from_encoding = null)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Converts character encoding of a xml-formatted text from UTF-8 into a specified encoding. If inside the text the encoding is declared, it is modified accordingly.
|
|
|
+ * Converts character encoding of a xml-formatted text from UTF-8 into a specified encoding.
|
|
|
+ * If inside the text the encoding is declared, it is modified accordingly.
|
|
|
* @param string $string The text being converted.
|
|
|
- * @param string $to_encoding (optional) The encoding that text is being converted to. If it is omited, the platform character set is assumed.
|
|
|
+ * @param string $to_encoding (optional) The encoding that text is being converted to.
|
|
|
+ * If it is omitted, the platform character set is assumed.
|
|
|
* @return string Returns the converted xml-text.
|
|
|
*/
|
|
|
function api_utf8_decode_xml($string, $to_encoding = 'UTF-8')
|
|
@@ -159,10 +182,12 @@ function api_utf8_decode_xml($string, $to_encoding = 'UTF-8')
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Converts character encoding of a xml-formatted text. If inside the text the encoding is declared, it is modified accordingly.
|
|
|
+ * Converts character encoding of a xml-formatted text.
|
|
|
+ * If inside the text the encoding is declared, it is modified accordingly.
|
|
|
* @param string $string The text being converted.
|
|
|
* @param string $to_encoding The encoding that text is being converted to.
|
|
|
- * @param string $from_encoding (optional) The encoding that text is being converted from. If the value is empty, it is tried to be detected then.
|
|
|
+ * @param string $from_encoding (optional) The encoding that text is being converted from.
|
|
|
+ * If the value is empty, it is tried to be detected then.
|
|
|
* @return string Returns the converted xml-text.
|
|
|
*/
|
|
|
function _api_convert_encoding_xml(&$string, $to_encoding, $from_encoding)
|
|
@@ -172,11 +197,16 @@ function _api_convert_encoding_xml(&$string, $to_encoding, $from_encoding)
|
|
|
}
|
|
|
$to_encoding = api_refine_encoding_id($to_encoding);
|
|
|
if (!preg_match('/<\?xml.*\?>/m', $string, $matches)) {
|
|
|
- return api_convert_encoding('<?xml version="1.0" encoding="'.$to_encoding.'"?>'."\n".$string, $to_encoding, $from_encoding);
|
|
|
+ return api_convert_encoding(
|
|
|
+ '<?xml version="1.0" encoding="'.$to_encoding.'"?>'."\n".$string,
|
|
|
+ $to_encoding,
|
|
|
+ $from_encoding
|
|
|
+ );
|
|
|
}
|
|
|
if (!preg_match(_PCRE_XML_ENCODING, $string)) {
|
|
|
if (strpos($matches[0], 'standalone') !== false) {
|
|
|
- // The encoding option should precede the standalone option, othewise DOMDocument fails to load the document.
|
|
|
+ // The encoding option should precede the standalone option,
|
|
|
+ // othewise DOMDocument fails to load the document.
|
|
|
$replace = str_replace('standalone', ' encoding="'.$to_encoding.'" standalone', $matches[0]);
|
|
|
} else {
|
|
|
$replace = str_replace('?>', ' encoding="'.$to_encoding.'"?>', $matches[0]);
|
|
@@ -265,7 +295,8 @@ function api_camel_case_to_underscore($string)
|
|
|
* Converts a string with underscores into camel case.
|
|
|
* Works correctly with ASCII strings only, implementation for human-language strings is not necessary.
|
|
|
* @param string $string The input string (ASCII)
|
|
|
- * @param bool $capitalise_first_char (optional) If true (default), the function capitalises the first char in the result string.
|
|
|
+ * @param bool $capitalise_first_char (optional)
|
|
|
+ * If true (default), the function capitalises the first char in the result string.
|
|
|
* @return string The converted result string
|
|
|
*/
|
|
|
function api_underscore_to_camel_case($string, $capitalise_first_char = true)
|
|
@@ -287,9 +318,11 @@ function _api_camelize($match)
|
|
|
*
|
|
|
* @author Brouckaert Olivier
|
|
|
* @param string $text The text to truncate.
|
|
|
- * @param integer $length The approximate desired length. The length of the suffix below is to be added to have the total length of the result string.
|
|
|
- * @param string $suffix A suffix to be added as a replacement.
|
|
|
- * @param string $encoding (optional) The encoding to be used. If it is omitted, the platform character set will be used by default.
|
|
|
+ * @param integer $length The approximate desired length. The length of the suffix below is to be added to
|
|
|
+ * have the total length of the result string.
|
|
|
+ * @param string $suffix A suffix to be added as a replacement.
|
|
|
+ * @param string $encoding (optional) The encoding to be used. If it is omitted,
|
|
|
+ * the platform character set will be used by default.
|
|
|
* @param boolean $middle If this parameter is true, truncation is done in the middle of the string.
|
|
|
* @return string Truncated string, decorated with the given suffix (replacement).
|
|
|
*/
|
|
@@ -303,7 +336,23 @@ function api_trunc_str($text, $length = 30, $suffix = '...', $middle = false, $e
|
|
|
return $text;
|
|
|
}
|
|
|
if ($middle) {
|
|
|
- return rtrim(api_substr($text, 0, round($length / 2), $encoding)).$suffix.ltrim(api_substr($text, - round($length / 2), $text_length, $encoding));
|
|
|
+ return rtrim(
|
|
|
+ api_substr(
|
|
|
+ $text,
|
|
|
+ 0,
|
|
|
+ round($length / 2),
|
|
|
+ $encoding
|
|
|
+ )
|
|
|
+ ).
|
|
|
+ $suffix.
|
|
|
+ ltrim(
|
|
|
+ api_substr(
|
|
|
+ $text,
|
|
|
+ -round($length / 2),
|
|
|
+ $text_length,
|
|
|
+ $encoding
|
|
|
+ )
|
|
|
+ );
|
|
|
}
|
|
|
return rtrim(api_substr($text, 0, $length, $encoding)).$suffix;
|
|
|
}
|
|
@@ -364,7 +413,8 @@ function _make_url_clickable_cb($matches)
|
|
|
$url = $matches[2];
|
|
|
|
|
|
if (')' == $matches[3] && strpos($url, '(')) {
|
|
|
- // If the trailing character is a closing parethesis, and the URL has an opening parenthesis in it, add the closing parenthesis to the URL.
|
|
|
+ // If the trailing character is a closing parethesis, and the URL has an opening
|
|
|
+ // parenthesis in it, add the closing parenthesis to the URL.
|
|
|
// Then we can let the parenthesis balancer do its thing below.
|
|
|
$url .= $matches[3];
|
|
|
$suffix = '';
|
|
@@ -399,7 +449,8 @@ function _make_url_clickable_cb($matches)
|
|
|
*
|
|
|
* @param string $url The URL to be cleaned.
|
|
|
* @param array $protocols Optional. An array of acceptable protocols.
|
|
|
- * Defaults to 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'svn' if not set.
|
|
|
+ * Defaults to 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher',
|
|
|
+ * 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'svn' if not set.
|
|
|
* @param string $_context Private. Use esc_url_raw() for database usage.
|
|
|
* @return string The cleaned $url after the 'clean_url' filter is applied.
|
|
|
*/
|
|
@@ -464,7 +515,8 @@ function esc_url($url, $protocols = null, $_context = 'display')
|
|
|
* @since wordpress 2.8.1
|
|
|
* @access private
|
|
|
*
|
|
|
- * @param string|array $search The value being searched for, otherwise known as the needle. An array may be used to designate multiple needles.
|
|
|
+ * @param string|array $search The value being searched for, otherwise known as the needle.
|
|
|
+ * An array may be used to designate multiple needles.
|
|
|
* @param string $subject The string being searched and replaced on, otherwise known as the haystack.
|
|
|
* @return string The string with the replaced svalues.
|
|
|
*/
|
|
@@ -542,7 +594,8 @@ function _make_email_clickable_cb($matches)
|
|
|
function make_clickable($text)
|
|
|
{
|
|
|
$r = '';
|
|
|
- $textarr = preg_split('/(<[^<>]+>)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE); // split out HTML tags
|
|
|
+ // split out HTML tags
|
|
|
+ $textarr = preg_split('/(<[^<>]+>)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
|
|
|
$nested_code_pre = 0; // Keep track of how many levels link is nested inside <pre> or <code>
|
|
|
foreach ($textarr as $piece) {
|
|
|
if (preg_match('|^<code[\s>]|i', $piece) || preg_match('|^<pre[\s>]|i', $piece)) {
|
|
@@ -551,7 +604,10 @@ function make_clickable($text)
|
|
|
$nested_code_pre--;
|
|
|
}
|
|
|
|
|
|
- if ($nested_code_pre || empty($piece) || ($piece[0] === '<' && !preg_match('|^<\s*[\w]{1,20}+://|', $piece))) {
|
|
|
+ if ($nested_code_pre ||
|
|
|
+ empty($piece) ||
|
|
|
+ ($piece[0] === '<' && !preg_match('|^<\s*[\w]{1,20}+://|', $piece))
|
|
|
+ ) {
|
|
|
$r .= $piece;
|
|
|
continue;
|
|
|
}
|
|
@@ -559,7 +615,8 @@ function make_clickable($text)
|
|
|
// Long strings might contain expensive edge cases ...
|
|
|
if (10000 < strlen($piece)) {
|
|
|
// ... break it up
|
|
|
- foreach (_split_str_by_whitespace($piece, 2100) as $chunk) { // 2100: Extra room for scheme and leading and trailing paretheses
|
|
|
+ foreach (_split_str_by_whitespace($piece, 2100) as $chunk) {
|
|
|
+ // 2100: Extra room for scheme and leading and trailing paretheses
|
|
|
if (2101 < strlen($chunk)) {
|
|
|
$r .= $chunk; // Too big, no whitespace: bail.
|
|
|
} else {
|
|
@@ -585,8 +642,16 @@ function make_clickable($text)
|
|
|
// Tell PCRE to spend more time optimizing since, when used on a page load, it will probably be used several times.
|
|
|
|
|
|
$ret = preg_replace_callback($url_clickable, '_make_url_clickable_cb', $ret);
|
|
|
- $ret = preg_replace_callback('#([\s>])((www|ftp)\.[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]+)#is', '_make_web_ftp_clickable_cb', $ret);
|
|
|
- $ret = preg_replace_callback('#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i', '_make_email_clickable_cb', $ret);
|
|
|
+ $ret = preg_replace_callback(
|
|
|
+ '#([\s>])((www|ftp)\.[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]+)#is',
|
|
|
+ '_make_web_ftp_clickable_cb',
|
|
|
+ $ret
|
|
|
+ );
|
|
|
+ $ret = preg_replace_callback(
|
|
|
+ '#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i',
|
|
|
+ '_make_email_clickable_cb',
|
|
|
+ $ret
|
|
|
+ );
|
|
|
|
|
|
$ret = substr($ret, 1, -1); // Remove our whitespace padding.
|
|
|
$r .= $ret;
|
|
@@ -606,7 +671,8 @@ function make_clickable($text)
|
|
|
*
|
|
|
* Joining the returned chunks with empty delimiters reconstructs the input string losslessly.
|
|
|
*
|
|
|
- * Input string must have no null characters (or eventual transformations on output chunks must not care about null characters)
|
|
|
+ * Input string must have no null characters (or eventual transformations on output chunks
|
|
|
+ * must not care about null characters)
|
|
|
*
|
|
|
* <code>
|
|
|
* _split_str_by_whitespace( "1234 67890 1234 67890a cd 1234 890 123456789 1234567890a 45678 1 3 5 7 90 ", 10 ) ==
|
|
@@ -752,7 +818,7 @@ function get_week_from_day($date)
|
|
|
/**
|
|
|
* This function splits the string into words and then joins them back together again one by one.
|
|
|
* Example: "Test example of a long string"
|
|
|
- * substrwords(5) = Test ... *
|
|
|
+ * substrwords(5) = Test ... *
|
|
|
* @param string
|
|
|
* @param int the max number of character
|
|
|
* @param string how the string will be end
|
|
@@ -820,35 +886,6 @@ function format_file_size($file_size)
|
|
|
return $file_size;
|
|
|
}
|
|
|
|
|
|
-function return_datetime_from_array($array)
|
|
|
-{
|
|
|
- $year = '0000';
|
|
|
- $month = $day = $hours = $minutes = $seconds = '00';
|
|
|
- if (isset($array['Y']) && (isset($array['F']) || isset($array['M'])) && isset($array['d']) && isset($array['H']) && isset($array['i'])) {
|
|
|
- $year = $array['Y'];
|
|
|
- $month = isset($array['F']) ? $array['F'] : $array['M'];
|
|
|
- if (intval($month) < 10) {
|
|
|
- $month = '0'.$month;
|
|
|
- }
|
|
|
- $day = $array['d'];
|
|
|
- if (intval($day) < 10) {
|
|
|
- $day = '0'.$day;
|
|
|
- }
|
|
|
- $hours = $array['H'];
|
|
|
- if (intval($hours) < 10) {
|
|
|
- $hours = '0'.$hours;
|
|
|
- }
|
|
|
- $minutes = $array['i'];
|
|
|
- if (intval($minutes) < 10) {
|
|
|
- $minutes = '0'.$minutes;
|
|
|
- }
|
|
|
- }
|
|
|
- if (checkdate($month, $day, $year)) {
|
|
|
- $datetime = $year.'-'.$month.'-'.$day.' '.$hours.':'.$minutes.':'.$seconds;
|
|
|
- }
|
|
|
- return $datetime;
|
|
|
-}
|
|
|
-
|
|
|
/**
|
|
|
* Converts an string CLEANYO[admin][amann,acostea]
|
|
|
* into an array:
|