extranet/library/Application/Controller/Plugin/Theme.php
Michael RICOIS cc4592eddd Logger
2017-02-13 14:08:23 +01:00

138 lines
5.5 KiB
PHP

<?php
class Application_Controller_Plugin_Theme extends Zend_Controller_Plugin_Abstract
{
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
if (Zend_Registry::isRegistered('logger')) {
$logger = Zend_Registry::get('logger');
}
$logger->info('PLUGIN THEME - START');
$auth = Zend_Auth::getInstance();
$theme = 'default'; //$theme = 'mobile';
if ( $auth->hasIdentity() ) {
$theme = !empty($auth->getIdentity()->theme) ? $auth->getIdentity()->theme : 'default';
}
$module = $request->getModuleName();
$controller = $request->getControllerName();
$action = $request->getActionName();
//Sauvegarde des paramètres du themes pour gérer les scripts et styles à utiliser
$paramsTheme = new stdClass();
$paramsTheme->name = $theme;
$paramsTheme->pathStyle = '/themes/'.$theme.'/styles';
$paramsTheme->pathScript = '/themes/'.$theme.'/scripts';
$paramsTheme->pathImg = '/themes/'.$theme.'/images';
Zend_Registry::set('theme', $paramsTheme);
//Load bootstrap
$bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
//Get useragent and device informations
$userAgent = $bootstrap->getResource('useragent');
$device = $userAgent->getDevice();
//Module default de l'application
$layoutPath = APPLICATION_PATH . '/layouts/' . $theme;
$helperPath = APPLICATION_PATH . '/layouts/helpers';
$viewPath = APPLICATION_PATH . '/modules/'.$module.'/views/' . $theme;
//Override path for view and layout
$view = $bootstrap->bootstrap('View')->getResource('View');
$view->setBasePath($viewPath);
$view->setHelperPath($helperPath);
$layout = $bootstrap->bootstrap('Layout')->getResource('Layout');
$layout->setLayout('layout');
$layout->setLayoutPath($layoutPath);
// DNS Prefetch
$view->headLink(array('rel'=>'dns-prefetch', 'href'=> '//'.$request->getHttpHost()));
//Load default style and javascript files for the selected theme
switch ( $theme ) {
case 'default':
default:
$view->doctype('HTML5');
$view->headMeta()
->appendHttpEquiv('Content-Type', 'text/html; charset=UTF-8')
->appendHttpEquiv('Content-Language', 'fr-FR');
//Favicon - Touch icon for iOS 2.0+ and Android 2.1+
$view->headLink(array(
'rel' => 'apple-touch-icon-precomposed',
'href' => '/favicon-152.png'
));
//Favicon - targeted to any additional png size
$view->headLink(array(
'rel' => 'icon',
'type' => 'image/png',
'href' => '/favicon-32.png'
));
$view->headLink(array(
'rel' => 'shortcut icon',
'type' => 'image/x-icon',
'href' => '/favicon.ico'
));
$UserLogin = false;
if ( $controller == 'user' && ( $action == 'login' || $action == 'logout' ) ) {
$UserLogin = true;
}
if ( $controller == 'auth' ) {
$UserLogin = true;
}
/**
* ===> Standard Styles
*/
if ( $UserLogin ) {
$view->headLink()
->appendStylesheet('/libs/bootstrap-3.3.7/css/bootstrap.min.css', 'all')
->appendStylesheet('/themes/default/styles/user-login.css', 'all');
} else {
$view->headLink()->appendStylesheet($paramsTheme->pathStyle.'/main.css', 'all');
}
$view->headLink()
->appendStylesheet('/libs/ui-1.12.1/themes/smoothness/jquery-ui.min.css', 'all')
->appendStylesheet('/libs/qtip/jquery.qtip.min.css', 'all')
->appendStylesheet('/libs/font-awesome-4.7.0/css/font-awesome.min.css', 'all');
/**
* ===> Standard Javascript
*/
if ( $UserLogin ) {
$view->headScript()
->appendFile('/libs/html5shiv.min.js', 'text/javascript', array('conditional' => 'lt IE 9'))
->appendFile('/libs/respond.min.js', 'text/javascript', array('conditional' => 'lt IE 9'))
->appendFile('/libs/jquery-1.12.4.min.js', 'text/javascript')
->appendFile('/libs/jquery.placeholder.min.js', 'text/javascript', array('conditional' => 'lt IE 9'))
->appendFile('/libs/bootstrap-3.3.7/js/bootstrap.min.js', 'text/javascript');
} else {
$view->headScript()
->appendFile('/libs/jquery-1.12.4.min.js', 'text/javascript');
}
$view->headScript()
->appendFile('/libs/ui-1.12.1/jquery-ui.min.js', 'text/javascript')
->appendFile('/libs/ui-1.12.1/datepicker-fr.js', 'text/javascript');
if ( ! $UserLogin ) {
$view->headScript()
->appendFile('/libs/qtip/jquery.qtip.min.js', 'text/javascript')
->appendFile($paramsTheme->pathScript.'/script.js', 'text/javascript');
}
break;
}
$logger->info('PLUGIN THEME - STOP');
}
}