<commit_before><?php

/*
 * This filter is intended to switch between regular and mobile
 * version of the site, based on the hostname
 */
class MobileFilter extends sfFilter
{
    public function execute($filterChain)
    {
        $context = $this->getContext();
        if (c2cTools::mobileVersion())
        {
            // change layout for mobile_layout
            $context->getResponse()->setParameter($context->getModuleName().'_'.$context->getActionName().'_layout', 'mobile_layout', 'symfony/action/view');
            $context->getResponse()->addStylesheet('/static/css/mimg.css'); // data uri images that are used only in mobile version
            $context->getResponse()->addStylesheet('/static/css/mobile.css', 'last');
        }
        else
        {
            // TODO the user agent detection can probably be improved...
            // FIXME should we redirect tablets or not? (see also http://android-developers.blogspot.com/2010/12/android-browser-user-agent-issues.html)
            // - Mobile should catch android phones, ipod touch, iphone, ipads (even if we maybe don't want it), windows phone 7 etc
            // - Symbian, Nokia, Blackberry self explainable
            // - SAMSUNG for Bada and other samsung devices
            // - Mini for Opera Mini
            // Maybe we should add more, but it doesn't represent many visits and users can still directly access mobile version of the site

            // we check if the user agent is one from a smartphone. If so, and if there is no cookie preventing redirection,
            // we redirect
            if (preg_match('/(Mobile|Symbian|Nokia|SAMSUNG|BlackBerry|Mini)/i', $_SERVER['HTTP_USER_AGENT'])) {
                // we do not redirect if user has a cookie stating that we shouldn't
                if (!$context->getRequest()->getCookie('nomobile'))
                {
                    // if referer is mobile version, it means that the user deliberatly wanted to have the classic version
                    // we thus do not redirect, and add a cookie to prevent further redirections
                    $mobile_host = sfConfig::get('app_mobile_version_host');
                    if (isset($_SERVER['HTTP_REFERER']) &&
                        !empty($mobile_host) &&
                        preg_match('/'.$mobile_host.'/', $_SERVER['HTTP_REFERER']))
                    {
                        $context->getResponse()->setCookie('nomobile', 1, time() + 60*60*24*30);
                    }
                    else
                    {
                        // redirect to mobile version
                        $context->getController()->redirect('http://'.$mobile_host.$_SERVER['REQUEST_URI']);
                    }
                }
            }

            $context->getResponse()->addStylesheet('/static/css/wimg.css'); // data uri images that are used only in www version
            $context->getResponse()->addStylesheet('/static/css/menu.css');
            $context->getResponse()->addStylesheet('/static/css/print.css', 'print');
        }<commit_msg>match Android for mobile devices: - android tablets do not have the 'Mobile' string in UA - we however want them to be redirected to m.camptocamp.org (better user experience, even if not optimized yet) - except smartphones and tablets, I don't expect many other android devices to connect to c2c, at least for the moment - could / should be updated later<commit_after><?php

/*
 * This filter is intended to switch between regular and mobile
 * version of the site, based on the hostname
 */
class MobileFilter extends sfFilter
{
    public function execute($filterChain)
    {
        $context = $this->getContext();
        if (c2cTools::mobileVersion())
        {
            // change layout for mobile_layout
            $context->getResponse()->setParameter($context->getModuleName().'_'.$context->getActionName().'_layout', 'mobile_layout', 'symfony/action/view');
            $context->getResponse()->addStylesheet('/static/css/mimg.css'); // data uri images that are used only in mobile version
            $context->getResponse()->addStylesheet('/static/css/mobile.css', 'last');
        }
        else
        {
            // TODO the user agent detection can probably be improved...
            // FIXME should we redirect tablets or not? (see also http://android-developers.blogspot.com/2010/12/android-browser-user-agent-issues.html)
            // - Mobile should catch android phones, ipod touch, iphone, ipads (even if we maybe don't want it), windows phone 7 etc
            // - Symbian, Nokia, Blackberry self explainable
            // - SAMSUNG for Bada and other samsung devices
            // - Mini for Opera Mini
            // Maybe we should add more, but it doesn't represent many visits and users can still directly access mobile version of the site

            // we check if the user agent is one from a smartphone. If so, and if there is no cookie preventing redirection,
            // we redirect
            if (preg_match('/(Mobile|Symbian|Nokia|SAMSUNG|BlackBerry|Mini|Android)/i', $_SERVER['HTTP_USER_AGENT'])) {
                // we do not redirect if user has a cookie stating that we shouldn't
                if (!$context->getRequest()->getCookie('nomobile'))
                {
                    // if referer is mobile version, it means that the user deliberatly wanted to have the classic version
                    // we thus do not redirect, and add a cookie to prevent further redirections
                    $mobile_host = sfConfig::get('app_mobile_version_host');
                    if (isset($_SERVER['HTTP_REFERER']) &&
                        !empty($mobile_host) &&
                        preg_match('/'.$mobile_host.'/', $_SERVER['HTTP_REFERER']))
                    {
                        $context->getResponse()->setCookie('nomobile', 1, time() + 60*60*24*30);
                    }
                    else
                    {
                        // redirect to mobile version
                        $context->getController()->redirect('http://'.$mobile_host.$_SERVER['REQUEST_URI']);
                    }
                }
            }

            $context->getResponse()->addStylesheet('/static/css/wimg.css'); // data uri images that are used only in www version
            $context->getResponse()->addStylesheet('/static/css/menu.css');
            $context->getResponse()->addStylesheet('/static/css/print.css', 'print');
        }
{'fraction_non_alphanumeric': 0.11296039451379257, 'fraction_numerical': 0.005393743257820928, 'mean_word_length': 2.0398126463700232, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2387438', 'n_tokens_mistral': 1632, 'n_tokens_neox': 1567, 'n_words': 516}