本文整理汇总了PHP中c2cTools::mobileRegexp方法的典型用法代码示例。如果您正苦于以下问题:PHP c2cTools::mobileRegexp方法的具体用法?PHP c2cTools::mobileRegexp怎么用?PHP c2cTools::mobileRegexp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类c2cTools
的用法示例。
在下文中一共展示了c2cTools::mobileRegexp方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
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: executeSwitchformfactor
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());
}
示例3:
<?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();