5 Description: Minifies resources (Javascript and CSS)
7 Author: Craig Andrews <candrews@integralblue.com>
8 Author URI: http://candrews.integralblue.com/
12 * StatusNet - the distributed open-source microblogging tool
13 * Copyright (C) 2009, StatusNet, Inc.
15 * This program is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Affero General Public License as published by
17 * the Free Software Foundation, either version 3 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU Affero General Public License for more details.
25 * You should have received a copy of the GNU Affero General Public License
26 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 * @package MinifyPlugin
31 * @maintainer Craig Andrews <candrews@integralblue.com>
34 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
36 class MinifyPlugin extends Plugin
40 * Add Minification related paths to the router table
42 * Hook for RouterInitialized event.
44 * @return boolean hook return
47 function onStartInitializeRouter($m)
49 $m->connect('main/min',
50 array('action' => 'minify'));
54 function onAutoload($cls)
59 require_once(INSTALLDIR.'/plugins/Minify/' . strtolower(mb_substr($cls, 0, -6)) . '.php');
66 function onLoginAction($action, &$login)
78 function onStartScriptElement($action,&$src,&$type) {
79 $url = parse_url($src);
80 if( empty($url->scheme) && empty($url->host) && empty($url->query) && empty($url->fragment))
82 $src = $this->minifyUrl($src);
86 function onStartCssLinkElement($action,&$src,&$theme,&$media) {
87 $allowThemeMinification =
88 is_null(common_config('theme', 'dir'))
89 && is_null(common_config('theme', 'path'))
90 && is_null(common_config('theme', 'server'));
91 $url = parse_url($src);
92 if( empty($url->scheme) && empty($url->host) && empty($url->query) && empty($url->fragment))
95 $theme = common_config('site', 'theme');
97 if($allowThemeMinification && file_exists(INSTALLDIR.'/local/theme/'.$theme.'/'.$src)) {
98 $src = $this->minifyUrl('local/theme/'.$theme.'/'.$src);
99 } else if($allowThemeMinification && file_exists(INSTALLDIR.'/theme/'.$theme.'/'.$src)) {
100 $src = $this->minifyUrl('theme/'.$theme.'/'.$src);
101 }else if(file_exists(INSTALLDIR.'/'.$src)){
102 $src = $this->minifyUrl($src);
107 function minifyUrl($src) {
108 return common_local_url('minify',null,array('f' => $src ,v => STATUSNET_VERSION));