]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/LinkPreview/LinkPreviewPlugin.php
[TRANSLATION] Update license and copyright notice in translation files
[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     const PLUGIN_VERSION = '2.0.0';
33
34     function onPluginVersion(array &$versions)
35     {
36         $versions[] = array('name' => 'LinkPreview',
37                             'version' => self::PLUGIN_VERSION,
38                             'author' => 'Brion Vibber',
39                             'homepage' => 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/LinkPreview',
40                             'rawdescription' =>
41                             // TRANS: Plugin description.
42                             _m('UI extension for previewing thumbnails from links.'));
43
44         return true;
45     }
46
47     /**
48      * Load JS at runtime if we're logged in.
49      *
50      * @param Action $action
51      * @return boolean hook result
52      */
53     function onEndShowScripts($action)
54     {
55         $user = common_current_user();
56         if ($user && common_config('attachments', 'process_links')) {
57             $action->script($this->path('js/linkpreview.js'));
58             $data = json_encode(array(
59                 'api' => common_local_url('oembedproxy'),
60                 'width' => common_config('attachments', 'thumbwidth'),
61                 'height' => common_config('attachments', 'thumbheight'),
62             ));
63             $action->inlineScript('$(function() {SN.Init.LinkPreview && SN.Init.LinkPreview('.$data.');})');
64         }
65         return true;
66     }
67
68     /**
69      * Hook for RouterInitialized event.
70      *
71      * @param URLMapper $m URL mapper
72      *
73      * @return boolean hook return
74      */
75     public function onStartInitializeRouter(URLMapper $m)
76     {
77         $m->connect('main/oembed/proxy',
78                 array('action' => 'oembedproxy'));
79
80         return true;
81     }
82 }