]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/SphinxSearch/SphinxSearchPlugin.php
plugins onAutoload now only overloads if necessary (extlibs etc.)
[quix0rs-gnu-social.git] / plugins / SphinxSearch / SphinxSearchPlugin.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * PHP version 5
6  *
7  * LICENCE: This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  *
20  * @category  Plugin
21  * @package   StatusNet
22  * @author    Brion Vibber <brion@status.net>
23  * @copyright 2009 Control Yourself, Inc.
24  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
25  * @link      http://laconi.ca/
26  */
27
28 if (!defined('STATUSNET')) {
29     exit(1);
30 }
31
32 // Set defaults if not already set in the config array...
33 global $config;
34 $sphinxDefaults =
35     array('enabled' => true,
36           'server' => 'localhost',
37           'port' => 3312);
38 foreach($sphinxDefaults as $key => $val) {
39     if (!isset($config['sphinx'][$key])) {
40         $config['sphinx'][$key] = $val;
41     }
42 }
43
44 /**
45  * Plugin for Sphinx search backend.
46  *
47  * @category Plugin
48  * @package  StatusNet
49  * @author   Brion Vibber <brion@status.net>
50  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
51  * @link     http://laconi.ca/
52  * @link     http://twitter.com/
53  */
54 class SphinxSearchPlugin extends Plugin
55 {
56     /**
57      * Automatically load any classes used
58      *
59      * @param string $cls the class
60      * @return boolean hook return
61      */
62     function onAutoload($cls)
63     {
64         switch ($cls) {
65         case 'SphinxSearch':
66             include_once INSTALLDIR . '/plugins/SphinxSearch/' .
67               strtolower($cls) . '.php';
68             return false;
69         }
70
71         return parent::onAutoload($cls);
72     }
73
74     /**
75      * Create sphinx search engine object for the given table type.
76      *
77      * @param Memcached_DataObject $target
78      * @param string $table
79      * @param out &$search_engine SearchEngine object on output if successful
80      * @ return boolean hook return
81      */
82     function onGetSearchEngine(Memcached_DataObject $target, $table, &$search_engine)
83     {
84         if (common_config('sphinx', 'enabled')) {
85             if (!class_exists('SphinxClient')) {
86                 // TRANS: Server exception.
87                 throw new ServerException(_m('Sphinx PHP extension must be installed.'));
88             }
89             $engine = new SphinxSearch($target, $table);
90             if ($engine->is_connected()) {
91                 $search_engine = $engine;
92                 return false;
93             }
94         }
95         // Sphinx disabled or disconnected
96         return true;
97     }
98
99     /**
100      * Provide plugin version information.
101      *
102      * This data is used when showing the version page.
103      *
104      * @param array &$versions array of version data arrays; see EVENTS.txt
105      *
106      * @return boolean hook value
107      */
108     function onPluginVersion(&$versions)
109     {
110         $url = 'http://status.net/wiki/Plugin:SphinxSearch';
111
112         $versions[] = array('name' => 'SphinxSearch',
113             'version' => STATUSNET_VERSION,
114             'author' => 'Brion Vibber',
115             'homepage' => $url,
116             'rawdescription' =>
117             // TRANS: Plugin description.
118             _m('Plugin for Sphinx search backend.'));
119
120         return true;
121     }
122 }