]> dev.renevier.net Git - syj.git/blob - application/controllers/helpers/SyjMedias.php
cache js, css and png files
[syj.git] / application / controllers / helpers / SyjMedias.php
1 <?php
2 /*  This file is part of Syj, Copyright (c) 2010-2011 Arnaud Renevier,
3     and is published under the AGPL license. */
4
5 class Syj_Controller_Action_Helper_SyjMedias extends Zend_Controller_Action_Helper_Abstract
6 {
7     protected $_config;
8
9     public function init() {
10         $this->_config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/medias.ini', APPLICATION_ENV);
11     }
12
13     public function addScripts($action) {
14         $view = $this->getActionController()->view;
15         if (APPLICATION_ENV == "production") {
16             $view->headScript()->appendFile('js/' . $action . '.js' . '?' . Syj_Version::VERSION);
17             return;
18         }
19         $scripts = explode(',', $this->_config->get('scripts')->get($action));
20         foreach ($scripts as $name) {
21             $view->headScript()->appendFile('js/' . trim($name) . '.js');
22         }
23     }
24
25     public function addStyleSheets($action) {
26         $view = $this->getActionController()->view;
27         if (APPLICATION_ENV == "production") {
28             $suffix = '?' . Syj_Version::VERSION;
29         } else {
30             $suffix = '';
31         }
32
33         $sheets = explode(',', $this->_config->get('css')->get($action));
34         foreach ($sheets as $sheet) {
35             $arr = explode(':', $sheet);
36             $arr = array_map('trim', $arr);
37             $href = 'css/' . $arr[0] . '.css' . $suffix;
38             $medias = array_slice($arr, 1);
39             if (!$medias) {
40                 $medias = "all";
41             }
42             $view->headLink()->appendStylesheet($href, $medias);
43         }
44     }
45 }