westdc-core/Westdc/Helpers/Layout.php

107 lines
2.6 KiB
PHP
Raw Normal View History

<?php
namespace Westdc\Helpers;
use \Zend\Authentication\AuthenticationService;
use \Zend\Authentication\Storage\Session as SessionStorage;
use View as view;
class Layout
{
2015-01-09 15:33:25 +00:00
function __construct()
{
2015-01-09 15:33:25 +00:00
}
//设置网页标题
public function setLayoutTitle($e)
{
$matches = $e->getRouteMatch();
if(empty($matches))
{
return;
}
2015-01-09 15:33:25 +00:00
// $action = $matches->getParam('action');
// $controller = $matches->getParam('controller');
$viewHelperManager = $e->getApplication()->getServiceManager()->get('viewHelperManager');
$headTitleHelper = $viewHelperManager->get('headTitle');
// Setting a separator string for segments
$headTitleHelper->setSeparator(' - ');
2015-01-09 15:33:25 +00:00
return;
}
//导航条按钮激活
public function setPageNav($e)
{
$matches = $e->getRouteMatch();
$action = $matches->getParam('action');
$controller = $matches->getParam('controller');
$viewHelperManager = $e->getApplication()->getServiceManager()->get('viewHelperManager');
$inlineScriptHelper = $viewHelperManager->get('inlineScript');
$inlineScriptHelper ->captureStart();
2015-02-06 14:15:28 +00:00
echo "$('#Nav-".$this->getControllerNavName($controller)."-".$action."').addClass('active');";
$inlineScriptHelper ->captureEnd();
}
public function getControllerNavName($invokename)
{
2015-02-06 14:15:28 +00:00
$controller_spell = explode("\\",$invokename);
return strtolower(end($controller_spell));
}
//添加用户Ajax脚本
public function setMemberScript($e)
{
$viewHelperManager = $e->getApplication()->getServiceManager()->get('viewHelperManager');
$inlineScriptHelper = $viewHelperManager->get('inlineScript');
$inlineScriptHelper->prependFile('/js/member.js');
}
//移动设备识别
public function mobileDetect($e)
{
if(!isset($_COOKIE['deviceType']) || empty($_COOKIE['deviceType']))
{
$detect = new MobileDetect;
$deviceType = ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'phone') : 'computer');
setcookie("deviceType", $deviceType, time()+86400,"/");
if(!isset($_SESSION['deviceType']) || empty($_SESSION['deviceType']))
{
$_SESSION['deviceType'] = $deviceType;
}
}else{
if(!isset($_SESSION['deviceType']) || empty($_SESSION['deviceType']))
{
$_SESSION['deviceType'] = $_COOKIE['deviceType'];
}
}
}
//重置session支持flash上传
public function resetSession($e)
{
$session_name = session_name();
//echo session_id();
if (isset($_POST[$session_name])) {
if(view::checkOs() !== 'windows')
{
session_destroy();
session_id($_POST[$session_name]);
session_start();
}else{
session_id($_POST[$session_name]);
}
}
}
}