2012-03-23 10:55:01 +00:00
|
|
|
<?php
|
|
|
|
class Application_Controller_Plugin_Theme extends Zend_Controller_Plugin_Abstract
|
|
|
|
{
|
2012-04-18 12:13:45 +00:00
|
|
|
public function routeShutdown(Zend_Controller_Request_Abstract $request)
|
2012-03-23 10:55:01 +00:00
|
|
|
{
|
|
|
|
$auth = Zend_Auth::getInstance();
|
|
|
|
$theme = 'default';
|
|
|
|
if ( $auth->hasIdentity() ) {
|
2013-05-14 09:32:08 +00:00
|
|
|
$theme = !empty($auth->getIdentity()->theme) ? $auth->getIdentity()->theme : 'default';
|
2012-03-23 10:55:01 +00:00
|
|
|
}
|
2013-01-16 15:32:46 +00:00
|
|
|
|
2013-11-13 14:10:30 +00:00
|
|
|
$controller = $request->getControllerName();
|
|
|
|
$action = $request->getActionName();
|
|
|
|
|
2012-11-19 13:43:23 +00:00
|
|
|
//Sauvegarde des paramètres du themes pour gérer les scripts et styles à utiliser
|
2012-03-25 16:51:13 +00:00
|
|
|
$paramsTheme = new stdClass();
|
|
|
|
$paramsTheme->name = $theme;
|
|
|
|
$paramsTheme->pathStyle = '/themes/'.$theme.'/styles';
|
|
|
|
$paramsTheme->pathScript = '/themes/'.$theme.'/scripts';
|
2012-11-19 13:43:23 +00:00
|
|
|
$paramsTheme->pathImg = '/themes/'.$theme.'/images';
|
2012-03-25 16:51:13 +00:00
|
|
|
Zend_Registry::set('theme', $paramsTheme);
|
2013-01-16 15:32:46 +00:00
|
|
|
|
2012-03-27 15:16:46 +00:00
|
|
|
//Module default de l'application
|
|
|
|
$layoutPath = APPLICATION_PATH . '/views/' . $theme;
|
|
|
|
$viewPath = APPLICATION_PATH . '/views/' . $theme;
|
2013-01-16 15:32:46 +00:00
|
|
|
|
2013-05-14 09:32:08 +00:00
|
|
|
//Load bootstrap
|
2012-11-19 13:43:23 +00:00
|
|
|
$bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
|
2013-05-14 09:32:08 +00:00
|
|
|
|
|
|
|
//Get useragent and device informations
|
|
|
|
$userAgent = $bootstrap->getResource('useragent');
|
|
|
|
$device = $userAgent->getDevice();
|
|
|
|
|
|
|
|
//Override path for view and layout
|
2012-03-23 10:55:01 +00:00
|
|
|
$view = $bootstrap->bootstrap('View')->getResource('View');
|
2012-11-19 13:43:23 +00:00
|
|
|
$view->setBasePath($viewPath);
|
2012-03-23 10:55:01 +00:00
|
|
|
$layout = $bootstrap->bootstrap('Layout')->getResource('Layout');
|
|
|
|
$layout->setLayout('main');
|
2012-11-19 13:43:23 +00:00
|
|
|
$layout->setLayoutPath($layoutPath);
|
2013-01-16 15:32:46 +00:00
|
|
|
|
2012-11-19 13:43:23 +00:00
|
|
|
//Load default style and javascript files for the selected theme
|
2012-03-23 10:55:01 +00:00
|
|
|
switch ( $theme )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case 'default':
|
2013-01-16 15:32:46 +00:00
|
|
|
|
2012-11-19 13:43:23 +00:00
|
|
|
$view->doctype('HTML5');
|
2013-01-16 15:32:46 +00:00
|
|
|
|
2012-03-25 16:51:13 +00:00
|
|
|
$view->headMeta()
|
|
|
|
->appendHttpEquiv('Content-Type', 'text/html; charset=UTF-8')
|
2012-11-19 13:43:23 +00:00
|
|
|
->appendHttpEquiv('Content-Language', 'fr-FR');
|
2013-01-16 15:32:46 +00:00
|
|
|
|
2012-03-25 16:51:13 +00:00
|
|
|
$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'));
|
2013-01-16 15:32:46 +00:00
|
|
|
|
2013-11-13 14:10:30 +00:00
|
|
|
/**
|
|
|
|
* Detect IE
|
|
|
|
*/
|
2013-02-12 16:07:13 +00:00
|
|
|
$isIE6 = false;
|
|
|
|
if ( $device->getFeature('browser_name')=='Internet Explorer'
|
|
|
|
&& $device->getFeature('browser_version')=='6.0' ) {
|
|
|
|
$isIE6 = true;
|
|
|
|
}
|
|
|
|
|
2013-11-13 14:10:30 +00:00
|
|
|
/**
|
|
|
|
* ===> Standard Styles
|
|
|
|
*/
|
2013-02-12 16:07:13 +00:00
|
|
|
$view->headLink()->appendStylesheet($paramsTheme->pathStyle.'/main.css', 'all');
|
|
|
|
if ($isIE6) {
|
|
|
|
//Old CSS for IE6
|
|
|
|
$view->headLink()
|
|
|
|
->appendStylesheet($paramsTheme->pathStyle.'/ie6.css', 'all')
|
2013-03-15 16:24:04 +00:00
|
|
|
->appendStylesheet('/libs/ui-1.9.2/themes/smoothness/jquery-ui.css', 'all');
|
2013-02-12 16:07:13 +00:00
|
|
|
} else {
|
|
|
|
$view->headLink()
|
2014-02-13 14:41:39 +00:00
|
|
|
->appendStylesheet('/libs/ui-1.10.4/themes/smoothness/jquery-ui.min.css', 'all');
|
2013-02-12 16:07:13 +00:00
|
|
|
}
|
|
|
|
$view->headLink()->appendStylesheet('/libs/qtip/jquery.qtip.css', 'all');
|
2013-02-05 08:43:06 +00:00
|
|
|
|
|
|
|
|
2013-11-13 14:10:30 +00:00
|
|
|
/**
|
|
|
|
* ===> Standard Javascript
|
|
|
|
*/
|
|
|
|
$view->headScript()
|
2014-02-13 14:41:39 +00:00
|
|
|
->appendFile('/libs/jquery/jquery-1.11.0.min.js', 'text/javascript');
|
2013-11-13 14:10:30 +00:00
|
|
|
|
2013-02-12 16:07:13 +00:00
|
|
|
if ($isIE6) {
|
|
|
|
//Old JQuery version for IE6
|
|
|
|
$view->headScript()
|
2013-02-18 11:11:51 +00:00
|
|
|
->appendFile('/libs/jquery/jquery.bgiframe.js', 'text/javascript')
|
2013-03-15 16:24:04 +00:00
|
|
|
->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');
|
2013-02-12 16:07:13 +00:00
|
|
|
} else {
|
|
|
|
$view->headScript()
|
2014-02-13 14:41:39 +00:00
|
|
|
->appendFile('/libs/ui-1.10.4/jquery-ui.min.js', 'text/javascript')
|
|
|
|
->appendFile('/libs/ui-1.10.4/jquery-ui-i18n.min.js', 'text/javascript');
|
2013-02-12 16:07:13 +00:00
|
|
|
}
|
|
|
|
$view->headScript()
|
2012-03-23 10:55:01 +00:00
|
|
|
->appendFile('/libs/qtip/jquery.qtip.js', 'text/javascript')
|
2013-01-17 14:27:04 +00:00
|
|
|
->appendFile($paramsTheme->pathScript.'/script.js', 'text/javascript');
|
2013-01-16 15:32:46 +00:00
|
|
|
|
2013-11-13 14:10:30 +00:00
|
|
|
/**
|
|
|
|
* ===> Specific Style and Script by Controller/Action
|
2012-12-06 16:38:43 +00:00
|
|
|
* Specialized Controller - Action javascript
|
|
|
|
* controllerName.js || controllerName-actionName.js
|
|
|
|
* array(
|
2013-11-13 14:10:30 +00:00
|
|
|
* 'controller-action' => array('file.js'=> 'inline|file')
|
2012-12-06 16:38:43 +00:00
|
|
|
* )
|
|
|
|
*/
|
|
|
|
$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(
|
2012-12-07 08:18:18 +00:00
|
|
|
'identite-groupe.js' => 'inline',
|
2012-12-06 16:38:43 +00:00
|
|
|
),
|
2013-02-01 10:49:47 +00:00
|
|
|
'evaluation-indiscore3' => array(
|
|
|
|
'identite-fiche.js' => 'inline',
|
|
|
|
),
|
2012-12-06 16:38:43 +00:00
|
|
|
);
|
2013-01-16 15:32:46 +00:00
|
|
|
|
2012-12-06 16:38:43 +00:00
|
|
|
if ( count($scripts)>0 ) {
|
|
|
|
//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':
|
2013-11-13 14:10:30 +00:00
|
|
|
$view->inlineScript()->appendFile($paramsTheme->pathScript.'/'.$file);
|
2012-12-06 16:38:43 +00:00
|
|
|
break;
|
|
|
|
case 'file':
|
|
|
|
$view->headScript()->appendFile($paramsTheme->pathScript.'/'.$file, 'text/javascript');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-16 15:32:46 +00:00
|
|
|
|
2012-12-06 16:38:43 +00:00
|
|
|
//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':
|
2013-11-13 14:10:30 +00:00
|
|
|
$view->inlineScript()->appendFile($paramsTheme->pathScript.'/'.$file);
|
2012-12-06 16:38:43 +00:00
|
|
|
break;
|
|
|
|
case 'file':
|
|
|
|
$view->headScript()->appendFile($paramsTheme->pathScript.'/'.$file, 'text/javascript');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-16 15:32:46 +00:00
|
|
|
|
2012-03-23 10:55:01 +00:00
|
|
|
break;
|
2013-01-16 15:32:46 +00:00
|
|
|
|
2013-02-18 11:11:51 +00:00
|
|
|
case 'mobile': //@todo
|
2012-03-25 16:51:13 +00:00
|
|
|
|
|
|
|
$view->doctype('HTML5');
|
2013-01-16 15:32:46 +00:00
|
|
|
|
2012-03-25 16:51:13 +00:00
|
|
|
$view->headMeta()
|
|
|
|
->appendName('charset', 'utf-8')
|
|
|
|
->appendName('viewport', 'width=device-width, initial-scale=1');
|
2013-01-16 15:32:46 +00:00
|
|
|
|
2012-03-25 16:51:13 +00:00
|
|
|
//Style
|
|
|
|
$view->headLink()
|
2014-02-13 14:41:39 +00:00
|
|
|
->appendStylesheet('/libs/mobile/1.4.0/jquery.mobile-1.4.0.min.css', 'all');
|
2013-01-16 15:32:46 +00:00
|
|
|
|
2012-03-25 16:51:13 +00:00
|
|
|
//JavaScript
|
2013-03-15 16:39:05 +00:00
|
|
|
$view->headScript()
|
2014-02-13 14:41:39 +00:00
|
|
|
->appendFile('/libs/jquery/jquery-1.11.0.min.js', 'text/javascript')
|
|
|
|
->appendFile('/libs/mobile/1.4.0/jquery.mobile-1.4.0.min.js', 'text/javascript')
|
2013-03-15 16:39:05 +00:00
|
|
|
->appendFile($paramsTheme->pathScript.'/script.js', 'text/javascript');
|
2013-01-16 15:32:46 +00:00
|
|
|
|
2012-03-23 10:55:01 +00:00
|
|
|
break;
|
2012-11-19 13:43:23 +00:00
|
|
|
}
|
2012-03-23 10:55:01 +00:00
|
|
|
}
|
|
|
|
}
|