2012-03-23 10:55:01 +00:00
|
|
|
<?php
|
|
|
|
class Application_Controller_Plugin_Theme extends Zend_Controller_Plugin_Abstract
|
|
|
|
{
|
2014-04-24 10:46:36 +00:00
|
|
|
public function preDispatch(Zend_Controller_Request_Abstract $request)
|
2012-03-23 10:55:01 +00:00
|
|
|
{
|
2016-04-07 15:48:55 +00:00
|
|
|
Zend_Registry::get('firebug')->info('PLUGIN THEME - START');
|
|
|
|
|
|
|
|
$auth = Zend_Auth::getInstance();
|
2014-04-24 10:46:36 +00:00
|
|
|
$theme = 'default'; //$theme = 'mobile';
|
2012-03-23 10:55:01 +00:00
|
|
|
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
|
|
|
|
2015-10-05 15:38:02 +00:00
|
|
|
$module = $request->getModuleName();
|
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
|
|
|
|
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();
|
|
|
|
|
2015-10-05 15:38:02 +00:00
|
|
|
//Module default de l'application
|
|
|
|
$layoutPath = APPLICATION_PATH . '/layouts/' . $theme;
|
|
|
|
$helperPath = APPLICATION_PATH . '/layouts/helpers';
|
2016-03-03 10:02:03 +00:00
|
|
|
$viewPath = APPLICATION_PATH . '/modules/'.$module.'/views/default';
|
2015-10-05 15:38:02 +00:00
|
|
|
|
2013-05-14 09:32:08 +00:00
|
|
|
//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);
|
2015-10-06 10:15:01 +00:00
|
|
|
$view->setHelperPath($helperPath);
|
2012-03-23 10:55:01 +00:00
|
|
|
$layout = $bootstrap->bootstrap('Layout')->getResource('Layout');
|
2014-03-14 10:42:09 +00:00
|
|
|
$layout->setLayout('layout');
|
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
|
2015-10-05 15:38:02 +00:00
|
|
|
switch ( $theme ) {
|
2014-08-12 20:19:45 +00:00
|
|
|
case 'default':
|
2016-03-03 10:02:03 +00:00
|
|
|
case 'default2016':
|
2014-08-12 20:19:45 +00:00
|
|
|
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
|
|
|
|
2014-03-14 10:42:09 +00:00
|
|
|
//Favicon - Touch icon for iOS 2.0+ and Android 2.1+
|
|
|
|
$view->headLink()->headLink(array(
|
|
|
|
'rel' => 'apple-touch-icon-precomposed',
|
|
|
|
'href' => '/favicon-152.png'
|
|
|
|
));
|
|
|
|
//Favicon - targeted to any additional png size
|
|
|
|
$view->headLink()->headLink(array(
|
|
|
|
'rel' => 'icon',
|
|
|
|
'type' => 'image/png',
|
|
|
|
'href' => '/favicon-32.png'
|
|
|
|
));
|
|
|
|
$view->headLink()->headLink(array(
|
|
|
|
'rel' => 'shortcut icon',
|
|
|
|
'type' => 'image/x-icon',
|
|
|
|
'href' => '/favicon.ico')
|
|
|
|
);
|
2013-01-16 15:32:46 +00:00
|
|
|
|
2014-04-24 10:46:36 +00:00
|
|
|
$UserLogin = false;
|
2016-04-29 17:33:19 +02:00
|
|
|
if ( $module == 'auth' ) {
|
2014-12-09 11:28:12 +00:00
|
|
|
$UserLogin = true;
|
|
|
|
}
|
|
|
|
|
2013-11-13 14:10:30 +00:00
|
|
|
/**
|
|
|
|
* ===> Standard Styles
|
|
|
|
*/
|
2016-02-29 10:01:00 +00:00
|
|
|
$view->headLink()
|
|
|
|
->appendStylesheet('/libs/bootstrap-3.3.6/css/bootstrap.min.css', 'all')
|
|
|
|
->appendStylesheet('/libs/ui-1.11.4/themes/smoothness/jquery-ui.min.css', 'all')
|
|
|
|
->appendStylesheet('/libs/qtip/jquery.qtip.min.css', 'all')
|
|
|
|
->appendStylesheet('/libs/font-awesome-4.5.0/css/font-awesome.min.css', 'all');
|
2014-04-24 10:46:36 +00:00
|
|
|
if ( $UserLogin ) {
|
2016-02-29 10:01:00 +00:00
|
|
|
$view->headLink()->appendStylesheet('/themes/default/styles/user-login.css', 'all');
|
2013-02-12 16:07:13 +00:00
|
|
|
} else {
|
2014-09-25 07:44:55 +00:00
|
|
|
$view->headLink()->appendStylesheet($paramsTheme->pathStyle.'/main.css', 'all');
|
2013-02-12 16:07:13 +00:00
|
|
|
}
|
2013-02-05 08:43:06 +00:00
|
|
|
|
2013-11-13 14:10:30 +00:00
|
|
|
/**
|
|
|
|
* ===> Standard Javascript
|
|
|
|
*/
|
2016-02-29 10:01:00 +00:00
|
|
|
$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'))
|
2016-04-20 15:39:27 +02:00
|
|
|
->appendFile('/libs/jquery/jquery-1.12.3.min.js', 'text/javascript')
|
2016-02-29 14:37:59 +00:00
|
|
|
->appendFile('/libs/bootstrap-3.3.6/js/bootstrap.min.js', 'text/javascript');
|
2016-02-29 10:01:00 +00:00
|
|
|
|
|
|
|
if ( $UserLogin ) {
|
|
|
|
$view->headScript()
|
|
|
|
->appendFile('/libs/jquery/jquery.placeholder.min.js', 'text/javascript', array('conditional' => 'lt IE 9'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$view->headScript()
|
|
|
|
->appendFile('/libs/ui-1.11.4/jquery-ui.min.js', 'text/javascript')
|
|
|
|
->appendFile('/libs/ui-1.11.4/i18n/datepicker-fr.js', 'text/javascript');
|
|
|
|
|
2014-04-24 10:46:36 +00:00
|
|
|
|
|
|
|
if ( ! $UserLogin ) {
|
|
|
|
$view->headScript()
|
2014-12-12 13:14:36 +00:00
|
|
|
->appendFile('/libs/qtip/jquery.qtip.min.js', 'text/javascript')
|
2014-04-24 10:46:36 +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;
|
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
|
|
|
|
2014-04-24 10:46:36 +00:00
|
|
|
$view->doctype('HTML5');
|
|
|
|
|
|
|
|
$view->headMeta()
|
|
|
|
->appendHttpEquiv('Content-Type', 'text/html; charset=UTF-8')
|
|
|
|
->appendHttpEquiv('Content-Language', 'fr-FR')
|
|
|
|
->appendName('viewport', 'width=device-width, initial-scale=1');
|
|
|
|
|
|
|
|
//Favicon - Touch icon for iOS 2.0+ and Android 2.1+
|
|
|
|
$view->headLink()->headLink(array(
|
|
|
|
'rel' => 'apple-touch-icon-precomposed',
|
|
|
|
'href' => '/favicon-152.png'
|
|
|
|
));
|
|
|
|
//Favicon - targeted to any additional png size
|
|
|
|
$view->headLink()->headLink(array(
|
|
|
|
'rel' => 'icon',
|
|
|
|
'type' => 'image/png',
|
|
|
|
'href' => '/favicon-32.png'
|
|
|
|
));
|
|
|
|
$view->headLink()->headLink(array(
|
|
|
|
'rel' => 'shortcut icon',
|
|
|
|
'type' => 'image/x-icon',
|
|
|
|
'href' => '/favicon.ico')
|
|
|
|
);
|
2013-01-16 15:32:46 +00:00
|
|
|
|
2012-03-25 16:51:13 +00:00
|
|
|
//Style
|
|
|
|
$view->headLink()
|
2014-04-24 10:46:36 +00:00
|
|
|
->appendStylesheet('/libs/mobile/1.4.2/jquery.mobile-1.4.2.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-04-24 10:46:36 +00:00
|
|
|
->appendFile('/libs/jquery/jquery-2.1.0.min.js', 'text/javascript')
|
|
|
|
->appendFile('/libs/mobile/1.4.2/jquery.mobile-1.4.2.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
|
|
|
}
|
2016-04-07 15:48:55 +00:00
|
|
|
|
|
|
|
Zend_Registry::get('firebug')->info('PLUGIN THEME - STOP');
|
2012-03-23 10:55:01 +00:00
|
|
|
}
|
|
|
|
}
|