Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modification of qtrans_parseURL and qtrans_use written by normadize to i... #7

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 12 additions & 19 deletions qtranslate_core.php
Original file line number Diff line number Diff line change
Expand Up @@ -1066,29 +1066,22 @@ function qtranxf_enableLanguage($lang) {

if (!function_exists('qtranxf_use')){
function qtranxf_use($lang, $text, $show_available=false) {
global $q_config;
// return full string if language is not enabled
if(!qtranxf_isEnabled($lang)) return $text;
if(is_array($text)) {
// handle arrays recursively
foreach($text as $key => $t) {
$text[$key] = qtranxf_use($lang,$text[$key],$show_available);
}
return $text;
}
if (empty($text) || !qtrans_isEnabled($lang))
return $text;

if(is_object($text)||@get_class($text) == '__PHP_Incomplete_Class') {
foreach(get_object_vars($text) as $key => $t) {
$text->$key = qtranxf_use($lang,$text->$key,$show_available);
}
return $text;
}
$re = '/<!--:[a-z]{2}-->|\[:[a-z]{2}\]/';
if (is_string($text) && !preg_match($re, $text))
return $text;

// prevent filtering weird data types and save some resources
if(!is_string($text) || $text == '') {
return $text;
if (is_array($text) || is_object($text)) {
foreach ($text as &$t)
if ($t && ((is_string($t) && preg_match($re, $t)) || is_array($t) || is_object($t)))
$t = qtrans_use($lang, $t, $show_available);
return $text;
}

global $q_config;

// get content
$content = qtranxf_split($text);
// find available languages
Expand Down
34 changes: 12 additions & 22 deletions qtranslate_utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,18 @@ function qtranxf_dbg_echo($msg,$var=null){
}// */

function qtranxf_parseURL($url) {
/*
if(function_exists('parse_url')){
$result = parse_url($url);
if(!isset($result['path'])) $result['path']='';
if(!isset($result['host'])) $result['host']='';
if(isset($result['port'])) $result['host'].=':'.$result['port'];
}else{
*/
$r = '!(?:(\w+)://)?(?:(\w+)\:(\w+)@)?([^/:]+)?';
$r .= '(?:\:(\d*))?([^#?]+)?(?:\?([^#]+))?(?:#(.+$))?!i';
preg_match ( $r, $url, $out );
$result = @array(
"scheme" => $out[1],
"host" => $out[4].(($out[5]=='')?'':':'.$out[5]),
"user" => $out[2],
"pass" => $out[3],
"path" => $out[6],
"query" => $out[7],
"fragment" => $out[8]
);
// }
return $result;
$result = parse_url($url) + array(
'scheme' => '',
'host' => '',
'user' => '',
'pass' => '',
'path' => '',
'query' => '',
'fragment' => ''
);
isset($result['port'])
and $result['host'] .= ':'. $result['port'];
return $result;
}

function qtranxf_stripSlashesIfNecessary($str) {
Expand Down