194 lines
6.7 KiB
PHP
194 lines
6.7 KiB
PHP
<?php
|
|
class Application_Controller_Plugin_Theme extends Zend_Controller_Plugin_Abstract
|
|
{
|
|
public function routeShutdown(Zend_Controller_Request_Abstract $request)
|
|
{
|
|
$auth = Zend_Auth::getInstance();
|
|
$theme = 'default';
|
|
if ( $auth->hasIdentity() ) {
|
|
$theme = !empty($auth->getIdentity()->theme) ? $auth->getIdentity()->theme : 'default';
|
|
}
|
|
|
|
//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);
|
|
|
|
//Module default de l'application
|
|
$layoutPath = APPLICATION_PATH . '/views/' . $theme;
|
|
$viewPath = APPLICATION_PATH . '/views/' . $theme;
|
|
|
|
//Load bootstrap
|
|
$bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
|
|
|
|
//Get useragent and device informations
|
|
$userAgent = $bootstrap->getResource('useragent');
|
|
$device = $userAgent->getDevice();
|
|
|
|
//Override path for view and layout
|
|
$view = $bootstrap->bootstrap('View')->getResource('View');
|
|
$view->setBasePath($viewPath);
|
|
$layout = $bootstrap->bootstrap('Layout')->getResource('Layout');
|
|
$layout->setLayout('main');
|
|
$layout->setLayoutPath($layoutPath);
|
|
|
|
//Load default style and javascript files for the selected theme
|
|
switch ( $theme )
|
|
{
|
|
default:
|
|
case 'default':
|
|
|
|
$view->doctype('HTML5');
|
|
|
|
$view->headMeta()
|
|
->appendHttpEquiv('Content-Type', 'text/html; charset=UTF-8')
|
|
->appendHttpEquiv('Content-Language', 'fr-FR');
|
|
|
|
$view->headLink()
|
|
->headLink(array('rel' => 'favicon', 'type' => 'image/png', 'href' => '/favicon.png'));
|
|
$view->headLink()
|
|
->headLink(array('rel' => 'shortcut icon', 'type' => 'image/x-icon', 'href' => '/favicon.ico'));
|
|
|
|
$isIE6 = false;
|
|
if ( $device->getFeature('browser_name')=='Internet Explorer'
|
|
&& $device->getFeature('browser_version')=='6.0' ) {
|
|
$isIE6 = true;
|
|
}
|
|
|
|
//===> Style
|
|
$view->headLink()->appendStylesheet($paramsTheme->pathStyle.'/main.css', 'all');
|
|
if ($isIE6) {
|
|
//Old CSS for IE6
|
|
$view->headLink()
|
|
->appendStylesheet($paramsTheme->pathStyle.'/ie6.css', 'all')
|
|
->appendStylesheet('/libs/ui-1.9.2/themes/smoothness/jquery-ui.css', 'all');
|
|
} else {
|
|
$view->headLink()
|
|
->appendStylesheet('/libs/ui-1.10.3/themes/smoothness/jquery-ui.min.css', 'all');
|
|
}
|
|
$view->headLink()->appendStylesheet('/libs/qtip/jquery.qtip.css', 'all');
|
|
|
|
$view->headScript()
|
|
->appendFile('/libs/jquery/jquery-1.10.1.min.js', 'text/javascript');
|
|
|
|
//===> JavaScript
|
|
if ($isIE6) {
|
|
//Old JQuery version for IE6
|
|
$view->headScript()
|
|
->appendFile('/libs/jquery/jquery.bgiframe.js', 'text/javascript')
|
|
->appendFile('/libs/ui-1.9.2/jquery-ui.min.js', 'text/javascript')
|
|
->appendFile('/libs/ui-1.9.2/jquery-ui-i18n.min.js', 'text/javascript');
|
|
} else {
|
|
$view->headScript()
|
|
->appendFile('/libs/ui-1.10.3/jquery-ui.min.js', 'text/javascript')
|
|
->appendFile('/libs/ui-1.10.3/jquery-ui-i18n.min.js', 'text/javascript');
|
|
}
|
|
$view->headScript()
|
|
->appendFile('/libs/qtip/jquery.qtip.js', 'text/javascript')
|
|
->appendFile($paramsTheme->pathScript.'/script.js', 'text/javascript');
|
|
|
|
/*
|
|
* Specialized Controller - Action javascript
|
|
* controllerName.js || controllerName-actionName.js
|
|
* array(
|
|
* 'controller-action' => array('file.js'=> 'inline|file')
|
|
* )
|
|
*
|
|
*/
|
|
$scripts = array(
|
|
'identite-fiche' => array(
|
|
'identite-fiche.js' => 'inline',
|
|
),
|
|
'identite-fichepc' => array(
|
|
'identite-fiche.js' => 'inline',
|
|
),
|
|
'identite-groupe' => array(
|
|
'identite-groupe.js' => 'inline',
|
|
),
|
|
'identite-liens' => array(
|
|
'identite-liens.js' => 'inline',
|
|
'identite-groupe.js' => 'inline',
|
|
),
|
|
'evaluation-indiscore3' => array(
|
|
'identite-fiche.js' => 'inline',
|
|
),
|
|
);
|
|
|
|
if ( count($scripts)>0 ) {
|
|
$controller = $request->getControllerName();
|
|
$action = $request->getActionName();
|
|
|
|
//Controller
|
|
$key = null;
|
|
if ( array_key_exists($controller, $scripts) ) {
|
|
$key = $controller;
|
|
}
|
|
if ( $key ) {
|
|
$options = $scripts[$key];
|
|
if ( is_array($options) ) {
|
|
foreach ( $options as $file => $type ) {
|
|
switch ( $type ) {
|
|
case 'inline':
|
|
$file = APPLICATION_PATH.'/../public/'.$paramsTheme->pathScript.'/'.$file;
|
|
$contentScript = file_get_contents($file);
|
|
$view->inlineScript()->appendScript($contentScript);
|
|
break;
|
|
case 'file':
|
|
$view->headScript()->appendFile($paramsTheme->pathScript.'/'.$file, 'text/javascript');
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//Controller-Action
|
|
$key = null;
|
|
if ( array_key_exists($controller.'-'.$action, $scripts) ) {
|
|
$key = $controller.'-'.$action;
|
|
}
|
|
if ( $key ) {
|
|
$options = $scripts[$key];
|
|
if ( is_array($options) ) {
|
|
foreach ( $options as $file => $type ) {
|
|
switch ( $type ) {
|
|
case 'inline':
|
|
$file = APPLICATION_PATH.'/../public/'.$paramsTheme->pathScript.'/'.$file;
|
|
$contentScript = file_get_contents($file);
|
|
$view->inlineScript()->appendScript($contentScript);
|
|
break;
|
|
case 'file':
|
|
$view->headScript()->appendFile($paramsTheme->pathScript.'/'.$file, 'text/javascript');
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
break;
|
|
|
|
case 'mobile': //@todo
|
|
|
|
$view->doctype('HTML5');
|
|
|
|
$view->headMeta()
|
|
->appendName('charset', 'utf-8')
|
|
->appendName('viewport', 'width=device-width, initial-scale=1');
|
|
|
|
//Style
|
|
$view->headLink()
|
|
->appendStylesheet('/libs/mobile/1.3.0/jquery.mobile-1.3.0.min.css', 'all');
|
|
|
|
//JavaScript
|
|
$view->headScript()
|
|
->appendFile('/libs/jquery/jquery-1.9.1.min.js', 'text/javascript')
|
|
->appendFile('/libs/mobile/1.3.0/jquery.mobile-1.3.0.min.js', 'text/javascript')
|
|
->appendFile($paramsTheme->pathScript.'/script.js', 'text/javascript');
|
|
|
|
break;
|
|
}
|
|
}
|
|
} |