本文整理匯總了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();