3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2010, StatusNet, Inc.
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.
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.
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/>.
20 if (!defined('STATUSNET')) {
25 * Some UI extras for now...
27 * @package LinkPreviewPlugin
28 * @maintainer Brion Vibber <brion@status.net>
30 class LinkPreviewPlugin extends Plugin
32 function onPluginVersion(&$versions)
34 $versions[] = array('name' => 'LinkPreview',
35 'version' => STATUSNET_VERSION,
36 'author' => 'Brion Vibber',
37 'homepage' => 'http://status.net/wiki/Plugin:LinkPreview',
39 _m('UI extensions previewing thumbnails from links.'));
45 * Load JS at runtime if we're logged in.
47 * @param Action $action
48 * @return boolean hook result
50 function onEndShowScripts($action)
52 $user = common_current_user();
53 if ($user && common_config('attachments', 'process_links')) {
54 $action->script($this->path('linkpreview.min.js'));
55 $data = json_encode(array(
56 'api' => common_local_url('oembedproxy'),
57 'width' => common_config('attachments', 'thumbwidth'),
58 'height' => common_config('attachments', 'thumbheight'),
60 $action->inlineScript('$(function() {SN.Init.LinkPreview && SN.Init.LinkPreview('.$data.');})');
68 * Loads our classes if they're requested.
70 * @param string $cls Class requested
72 * @return boolean hook return
74 function onAutoload($cls)
76 $lower = strtolower($cls);
79 case 'oembedproxyaction':
80 require_once dirname(__FILE__) . '/' . $lower . '.php';
88 * Hook for RouterInitialized event.
90 * @param Net_URL_Mapper $m URL mapper
92 * @return boolean hook return
94 function onStartInitializeRouter($m)
96 $m->connect('main/oembed/proxy',
97 array('action' => 'oembedproxy'));