AutocompletePlugin.php 2.66 KB
Newer Older
Craig Andrews's avatar
Craig Andrews committed
1 2
<?php
/**
Evan Prodromou's avatar
Evan Prodromou committed
3
 * StatusNet, the distributed open-source microblogging tool
Craig Andrews's avatar
Craig Andrews committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * Plugin to enable nickname completion in the enter status box
 *
 * PHP version 5
 *
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @category  Plugin
Evan Prodromou's avatar
Evan Prodromou committed
23
 * @package   StatusNet
Craig Andrews's avatar
Craig Andrews committed
24
 * @author    Craig Andrews <candrews@integralblue.com>
25 26
 * @copyright 2010 Free Software Foundation http://fsf.org
 * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
Craig Andrews's avatar
Craig Andrews committed
27
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
Evan Prodromou's avatar
Evan Prodromou committed
28
 * @link      http://status.net/
Craig Andrews's avatar
Craig Andrews committed
29 30
 */

31
if (!defined('STATUSNET') && !defined('LACONICA')) {
Craig Andrews's avatar
Craig Andrews committed
32 33 34 35 36 37 38 39 40 41 42
    exit(1);
}

class AutocompletePlugin extends Plugin
{
    function __construct()
    {
        parent::__construct();
    }

    function onEndShowScripts($action){
43
        if (common_logged_in()) {
44 45
            $action->element('span', array('id' => 'autocomplete-api',
                                           'data-url' => common_local_url('autocomplete')));
46 47
            $action->script($this->path('jquery-autocomplete/jquery.autocomplete.pack.js'));
            $action->script($this->path('Autocomplete.js'));
48
        }
Craig Andrews's avatar
Craig Andrews committed
49 50
    }

Evan Prodromou's avatar
Evan Prodromou committed
51
    function onEndShowStatusNetStyles($action)
Craig Andrews's avatar
Craig Andrews committed
52
    {
53
        if (common_logged_in()) {
54
            $action->cssLink($this->path('jquery-autocomplete/jquery.autocomplete.css'));
55
        }
Craig Andrews's avatar
Craig Andrews committed
56 57
    }

58 59 60
    function onRouterInitialized($m)
    {
        if (common_logged_in()) {
61
            $m->connect('main/autocomplete/suggest', array('action'=>'autocomplete'));
62 63 64
        }
    }

65 66 67 68 69 70 71
    function onPluginVersion(&$versions)
    {
        $versions[] = array('name' => 'Autocomplete',
                            'version' => STATUSNET_VERSION,
                            'author' => 'Craig Andrews',
                            'homepage' => 'http://status.net/wiki/Plugin:Autocomplete',
                            'rawdescription' =>
72
                            // TRANS: Plugin description.
73
                            _m('The autocomplete plugin adds autocompletion for @ replies.'));
74 75
        return true;
    }
Craig Andrews's avatar
Craig Andrews committed
76
}