]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/LinkPreview/LinkPreviewPlugin.php
Merge branch '1.0.x' into profile-fixups
[quix0rs-gnu-social.git] / plugins / LinkPreview / LinkPreviewPlugin.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2010, StatusNet, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('STATUSNET')) {
21     exit(1);
22 }
23
24 /**
25  * Some UI extras for now...
26  *
27  * @package LinkPreviewPlugin
28  * @maintainer Brion Vibber <brion@status.net>
29  */
30 class LinkPreviewPlugin extends Plugin
31 {
32     function onPluginVersion(&$versions)
33     {
34         $versions[] = array('name' => 'LinkPreview',
35                             'version' => STATUSNET_VERSION,
36                             'author' => 'Brion Vibber',
37                             'homepage' => 'http://status.net/wiki/Plugin:LinkPreview',
38                             'rawdescription' =>
39                             _m('UI extensions previewing thumbnails from links.'));
40
41         return true;
42     }
43
44     /**
45      * Load JS at runtime if we're logged in.
46      *
47      * @param Action $action
48      * @return boolean hook result
49      */
50     function onEndShowScripts($action)
51     {
52         $user = common_current_user();
53         if ($user && common_config('attachments', 'process_links')) {
54             if (common_config('site', 'minify')) {
55                 $js = 'linkpreview.min.js';
56             } else {
57                 $js = 'linkpreview.js';
58             }
59             $action->script($this->path($js));
60             $data = json_encode(array(
61                 'api' => common_local_url('oembedproxy'),
62                 'width' => common_config('attachments', 'thumbwidth'),
63                 'height' => common_config('attachments', 'thumbheight'),
64             ));
65             $action->inlineScript('$(function() {SN.Init.LinkPreview && SN.Init.LinkPreview('.$data.');})');
66         }
67         return true;
68     }
69
70     /**
71      * Autoloader
72      *
73      * Loads our classes if they're requested.
74      *
75      * @param string $cls Class requested
76      *
77      * @return boolean hook return
78      */
79     function onAutoload($cls)
80     {
81         $lower = strtolower($cls);
82         switch ($lower)
83         {
84         case 'oembedproxyaction':
85             require_once dirname(__FILE__) . '/' . $lower . '.php';
86             return false;
87         default:
88             return true;
89         }
90     }
91
92     /**
93      * Hook for RouterInitialized event.
94      *
95      * @param Net_URL_Mapper $m URL mapper
96      *
97      * @return boolean hook return
98      */
99     function onStartInitializeRouter($m)
100     {
101         $m->connect('main/oembed/proxy',
102                 array('action' => 'oembedproxy'));
103
104         return true;
105     }
106 }