Forum Replies Created

Viewing 15 replies - 31 through 45 (of 78 total)
  • normadize

    (@normadize)

    I guess that’s for several reasons, one being that the author will then change his code to counter it and then we’re back to square one. The branding can always be hidden, regardless of how Claude changes his code so he may as well himself provide a way to remove it.

    I’llmove away from OneAll in the future and will post my hacks here, but until then you can email me at normadize-at-gmail-com and I’ll be happy to help you.

    normadize

    (@normadize)

    I was looking for proper ways to remove the branding myself. I know already of two hacks that can easily remove this without altering any of the plugin’s code.

    However, I came here to ask Claude Schlesser, the plugin author, who is also the founder of OneAll by the way (*), whether he provides a way to remove the branding. This thread has been informative and I am now also considering moving away from OneAll and this plugin and use a plugin that doesn’t require a 3rd party.

    Anyone care to recommend a good plugin that doesn’t involve a 3rd party?

    Cheers.

    (*) To Claude, if I may: it is rather disappointing seeing you calling someone else names (e.g. “blind”) in a public forum, regardless of the context. As the founder/CEO of a public service, this kind of conduct is unprofessional enough for people to stop using your product even if it’s a good one. Also, you seem to defend the plugin as completely unrelated to OneAll as “external” service, when in fact it’s not. You provide both that “external” service and the plugin together but seemingly wish to be perceived differently here (on this forum, in relation to the plugin) and in relation to OneAll. It’s a bit of a skewed stance, really.

    I agree that some messages about your plugin or addressed to you in this thread were a tad aggressive, and I do understand your perspective, but I have a feeling that your intervention here has not helped you/your case very much. I hope I’m wrong.

    Thread Starter normadize

    (@normadize)

    This bug is still present in the new v3.4

    Thread Starter normadize

    (@normadize)

    I’ve never had issues with Xdebug as far as PHP debuggers go.

    I optimized a few parts of qTranslate functions quite heavily and will post my patches soon.

    In fact, I may even release a very small plugin that patches qTranslate on the fly, which people can just install and use together with qTranslate to make it faster. It’s part of a bigger plugin I am writing.

    Stay tuned.

    Thread Starter normadize

    (@normadize)

    To keep current functionality but with a faster, less-recursive function, replace in qtrans_use() the following:

    global $q_config;
    // return full string if language is not enabled
    if(!qtrans_isEnabled($lang)) return $text;
    if(is_array($text)) {
        // handle arrays recursively
        foreach($text as $key => $t) {
            $text[$key] = qtrans_use($lang,$text[$key],$show_available);
        }
        return $text;
    }
    
    if (is_object($text)||@get_class($text) == '__PHP_Incomplete_Class') {
        foreach(get_object_vars($text) as $key => $t) {
            $text->$key = qtrans_use($lang,$text->$key,$show_available);
        }
        return $text;
    }
    
    // prevent filtering weird data types and save some resources
    if(!is_string($text) || $text == '') {
        return $text;
    }

    with the following

    if (empty($text) || !qtrans_isEnabled($lang))
        return $text;
    
    $re = '/<!--:[a-z]{2}-->/';
    if (is_string($text) && !preg_match($re, $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;
    Thread Starter normadize

    (@normadize)

    Actually, most of the above is not needed. In fact, the second if (is_array() ... is not even reached if $text is an array or object, which is Ok in most cases, see below. You could just as well remove it altogether.

    The qtrans_postsFilter() function is hooked into ‘the_posts’ filter. This function is:

    function qtrans_postsFilter($posts) {
    	if(is_array($posts)) {
    		foreach($posts as $post) {
    			$post->post_content = qtrans_useCurrentLanguageIfNotFoundShowAvailable($post->post_content);
    			$post = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($post);
    		}
    	}
    	return $posts;
    }

    Note how it is passing each object $post in a loop to qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($post) which in turn calls qtrans_use() on each of the object’s properties. Only the title and content (and maybe guid and pinged) properties require translation (none of the other 20+ do) and for those, qTranslate already hooks into ‘the_content’, ‘the_title’ etc filters. This function can be useful if you call get_posts() in your own code.

    You could remove the ‘the_posts’ hook from qtranslate_hooks.php and if you need to call get_posts() in your own code and want the title and content translated, then you can either call qtrans_postsFilter(), which is very inefficient (and you may not want the default behaviour of not showing the default language for the content if the current language is unavailable), of just translate the title and content in a loop — you can have your own function for that.

    Thread Starter normadize

    (@normadize)

    A first (not-complete) optimization for qtrans_use() which calls itself unnecessarily many times is as follows. Replace the lines:

    global $q_config;
    // return full string if language is not enabled
    if(!qtrans_isEnabled($lang)) return $text;
    if(is_array($text)) {
        // handle arrays recursively
        foreach($text as $key => $t) {
            $text[$key] = qtrans_use($lang,$text[$key],$show_available);
        }
        return $text;
    }
    
    if (is_object($text)||@get_class($text) == '__PHP_Incomplete_Class') {
        foreach(get_object_vars($text) as $key => $t) {
            $text->$key = qtrans_use($lang,$text->$key,$show_available);
        }
        return $text;
    }
    
    // prevent filtering weird data types and save some resources
    if(!is_string($text) || $text == '') {
        return $text;
    }

    with

    if (empty($text) || !is_string($text) || !preg_match($re = '/<!--:[a-z]{2}-->/', $text) || !qtrans_isEnabled($lang))
            return $text;
    
    if (is_array($text) || $text instanceof __PHP_Incomplete_Class) {
        foreach ($text as &$t)
            if ($t && is_string($t) && preg_match($re, $t))
                $t = qtrans_use($lang, $t, $show_available);
        return $text;
    }
    
    global $q_config;

    Note the & in the foreach loop.

    Thread Starter normadize

    (@normadize)

    Also, disabling and enabling the plugin is enabling the debug option in my case. It shouldn’t do that I presume.

    Got it … at least in my case.

    Is by any chance the “debug” mode enabled for page cache (or others?) If yes, then that’s it.

    I observed the Ajax JSON return value and, to my horror, I noticed that after the JSON object returned for WPCF7 there was a nasty HTML comment added by W3TC with debug information (I had debug enabled).

    This is actually a (fairly nasty) bug in W3TC. It should not add debug information for application/json content type (actually no other types except html and friends).

    Yes, same issue here as well. Turning on Page Cache in W3TC prevent WPCF7 from working …

    Even when logged in and with the option “don’t cache pages for logged in users” enabled. I also disabled the option “Cache URIs with query string variables” which should do the trick since WPCF7 uses Ajax with a GET query string.

    Any clues?

    Thread Starter normadize

    (@normadize)

    I also optimized qtrans_split() and qtrans_use() myself … but the whole thing needs to be rewritten.

    The plugin author is not replying to anyone anymore. Maybe it’s time to move on.

    Thread Starter normadize

    (@normadize)

    Looking through the code, I’m cringing at the sight of stuff like this:

    elseif(preg_match("#^<!--:-->$#ism", $block, $matches)) {
       $current_language = "";
       continue;
    }

    The above is a clear example of what I was talking about. Not only $matches is not used anywhere, so preg_match() shouldn’t have been asked to create and populate a new array, and not only are the s, m and i modifiers not needed, but the entire if clause could have been replaced with just:

    elseif($block == '<!--:-->'))

    There are too many unnecessary calls to preg_match() and preg_replace(), a lot of them shouldn’t even be case insensitive, or multi-line … strpos(), stripos(), str_replace(), str_ireplace() should be used when possible, or plain comparison like above.

    Also, there are too many for/foreach loops triggering subsequent large number of calls to preg_match/preg_replace. It’s usually better, if possible, to try and call preg_* beforehand on the big string, rather than split the string and then call preg_* a lot of times.

    Thread Starter normadize

    (@normadize)

    You can also make the qtrans_parseURL() function faster, in qtranslate_utils.php. This function is called quite a few times:

    function qtrans_parseURL($url) {
        $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;
    }

    Even though the above could be sped up by using the S PCRE modifier to analyze the regex for future calls, you can replace the entire function with the much faster:

    function qtrans_parseURL($url) {
            $result = parse_url($url) + array(
                    'scheme' => '',
                    'host' => '',
                    'user' => '',
                    'pass' => '',
                    'path' => '',
                    'query' => '',
                    'fragment' => ''
            );
            isset($result['port'])
                    and $result['host'] .= ':'. $result['port'];
            return $result;
    }

    note the + array union operator which basically implements default array values since parse_url() populates those array fields only if a match was found in the url.

    Thread Starter normadize

    (@normadize)

    It’s not actually necessary to seek translations for ALL the options in the wp_options table. Most of them are only used internally and do not require translation so the whole process of seeking a translation can be cut down.

    Many WP installations have a huge wp_options table due to a large number of plugins — it doesn’t matter if they are disabled or not, their options are still there in the table. Most of them ‘forget’ their options in the table even if you uninstall them so if you had previously tried a large number of plugins in the past and uninstalled most of them, your website can get increasingly slow if qTranslate is enabled due to the code below. My wp_options table has 491 rows!

    Commenting out the following block in qtranslate_core.php makes the website a hell of a lot faster for me:

    /*
    if(!defined('WP_ADMIN')) {
    	$alloptions = wp_load_alloptions();
    	foreach($alloptions as $option => $value) {
    		add_filter('option_'.$option, 'qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage',0);
    	}
    }
    */

    With this tweak, the page from the initial post loads in under 1.5 seconds now, down from 5.5 seconds!

    In case you have options that need to be translated, then you can manually hook the qtranslate filter above only for those options, rather than hooking into all options, e.g. I would replace the above code with

    $options = array('options','that','need','translation','here');
    foreach ($options as $opt)
        add_filter('option_'.$option, 'qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage',0);

    And you can add that into your functions.php.

    Thread Starter normadize

    (@normadize)

    I’m going to use this thread to post code optimizations that I do to qTranslate for anyone who is interested.

Viewing 15 replies - 31 through 45 (of 78 total)