public function execute($filterChain)
 {
     $context = $this->getContext();
     $user = $context->getUser();
     if ($this->isFirstCall() && !$user->hasAttribute('form_factor')) {
         // if you make changes here, be sure also to check web/forums/include/common.php
         // and check varnish vcl file
         $cookie = $context->getRequest()->getCookie('form_factor');
         if ($cookie === 'mobile' || $cookie === null && c2cTools::mobileRegexp()) {
             $user->setAttribute('form_factor', 'mobile');
         } else {
             $user->setAttribute('form_factor', 'desktop');
         }
     }
     if ($user->getAttribute('form_factor', 'desktop') === 'mobile') {
         // change layout for mobile_layout
         $context->getResponse()->setParameter($context->getModuleName() . '_' . $context->getActionName() . '_layout', 'mobile_layout', 'symfony/action/view');
         $context->getResponse()->addStylesheet('/static/css/mobile.css', 'last');
     } else {
         $context->getResponse()->addStylesheet('/static/css/default.css');
         $context->getResponse()->addStylesheet('/static/css/menu.css');
         $context->getResponse()->addStylesheet('/static/css/print.css', 'print');
     }
     // execute next filter
     $filterChain->execute();
 }
示例#2
0
 public function executeSwitchformfactor()
 {
     $user = $this->getUser();
     if ($user->getAttribute('form_factor', 'desktop') === 'mobile') {
         $user->setAttribute('form_factor', 'desktop');
         if (!c2cTools::mobileRegexp()) {
             // delete form_factor cookie (not needed)
             $this->getResponse()->setCookie('form_factor', null, -1);
         } else {
             // set cookie so that we are sure to prevent redirection on next sessions
             $this->getResponse()->setCookie('form_factor', 'desktop', time() + 60 * 60 * 24 * 30);
         }
     } else {
         $user->setAttribute('form_factor', 'mobile');
         if (c2cTools::mobileRegexp()) {
             // delete form_factor cookie (not needed)
             $this->getResponse()->setCookie('form_factor', null, -1);
         } else {
             // set cookie so that we are sure to set form factor correctly on next sessions
             $this->getResponse()->setCookie('form_factor', 'mobile', time() + 60 * 60 * 24 * 30);
         }
     }
     // redirect to referer
     return $this->redirect($this->getRequest()->getReferer());
 }
<?php

// this is the same process that occurs in FormFactorFilter for symfony
// adapted for the forums
if (!$sf_user->hasAttribute('form_factor')) {
    // if you make changes here, be sure also to check varnish and FormFactorFilter
    $cookie = $request->getCookie('form_factor');
    if ($cookie === 'mobile' || $cookie === null && c2cTools::mobileRegexp()) {
        $sf_user->setAttribute('form_factor', 'mobile');
    } else {
        $sf_user->setAttribute('form_factor', 'desktop');
    }
}
$mobile_version = c2cTools::mobileVersion();