]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Minify/MinifyPlugin.php
Added minify plugin
[quix0rs-gnu-social.git] / plugins / Minify / MinifyPlugin.php
1 <?php
2 /*
3 StatusNet Plugin: 0.9
4 Plugin Name: Minify
5 Description: Minifies resources (Javascript and CSS)
6 Version: 0.1
7 Author: Craig Andrews <candrews@integralblue.com>
8 Author URI: http://candrews.integralblue.com/
9 */
10
11 /*
12  * StatusNet - the distributed open-source microblogging tool
13  * Copyright (C) 2009, StatusNet, Inc.
14  *
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.
19  *
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.
24  *
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/>.
27  */
28
29 /**
30  * @package MinifyPlugin
31  * @maintainer Craig Andrews <candrews@integralblue.com>
32  */
33
34 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
35
36 class MinifyPlugin extends Plugin
37 {
38
39     /**
40      * Add Minification related paths to the router table
41      *
42      * Hook for RouterInitialized event.
43      *
44      * @return boolean hook return
45      */
46
47     function onStartInitializeRouter($m)
48     {
49         $m->connect('main/min',
50                     array('action' => 'minify'));
51         return true;
52     }
53
54     function onAutoload($cls)
55     {
56         switch ($cls)
57         {
58          case 'MinifyAction':
59             require_once(INSTALLDIR.'/plugins/Minify/' . strtolower(mb_substr($cls, 0, -6)) . '.php');
60             return false;
61          default:
62             return true;
63         }
64     }
65
66     function onLoginAction($action, &$login)
67     {
68         switch ($action)
69         {
70          case 'minify':
71             $login = true;
72             return false;
73          default:
74             return true;
75         }
76     }
77
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))
81         {
82             $src = common_path('main/min?f='.$src.'&v=' . STATUSNET_VERSION);
83         }
84     }
85
86     function onStartCssLinkElement($action,&$src,&$theme,&$media) {
87         $url = parse_url($src);
88         if( empty($url->scheme) && empty($url->host) && empty($url->query) && empty($url->fragment))
89         {
90             if(file_exists(Theme::file($src,$theme))){
91                 //src is a relative path, so we can do minification
92                 if(isset($theme)) {
93                     $src = common_path('main/min?f=theme/'.$theme.'/'.$src.'&v=' . STATUSNET_VERSION);
94                 } else {
95                     $src = common_path('main/min?f=theme/default/'.$src.'&v=' . STATUSNET_VERSION);
96                 }
97             }
98         }
99     }
100 }
101