]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/SphinxSearch/SphinxSearchPlugin.php
[TRANSLATION] Update license and copyright notice in translation files
[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     const PLUGIN_VERSION = '2.0.0';
57
58     /**
59      * Automatically load any classes used
60      *
61      * @param string $cls the class
62      * @return boolean hook return
63      */
64     function onAutoload($cls)
65     {
66         switch ($cls) {
67         case 'SphinxSearch':
68             include_once INSTALLDIR . '/plugins/SphinxSearch/' .
69               strtolower($cls) . '.php';
70             return false;
71         }
72
73         return parent::onAutoload($cls);
74     }
75
76     /**
77      * Create sphinx search engine object for the given table type.
78      *
79      * @param Memcached_DataObject $target
80      * @param string $table
81      * @param out &$search_engine SearchEngine object on output if successful
82      * @ return boolean hook return
83      */
84     function onGetSearchEngine(Memcached_DataObject $target, $table, &$search_engine)
85     {
86         if (common_config('sphinx', 'enabled')) {
87             if (!class_exists('SphinxClient')) {
88                 // TRANS: Server exception.
89                 throw new ServerException(_m('Sphinx PHP extension must be installed.'));
90             }
91             $engine = new SphinxSearch($target, $table);
92             if ($engine->is_connected()) {
93                 $search_engine = $engine;
94                 return false;
95             }
96         }
97         // Sphinx disabled or disconnected
98         return true;
99     }
100
101     /**
102      * Provide plugin version information.
103      *
104      * This data is used when showing the version page.
105      *
106      * @param array &$versions array of version data arrays; see EVENTS.txt
107      *
108      * @return boolean hook value
109      */
110     function onPluginVersion(array &$versions)
111     {
112         $url = 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/SphinxSearch';
113
114         $versions[] = array('name' => 'SphinxSearch',
115             'version' => self::PLUGIN_VERSION,
116             'author' => 'Brion Vibber',
117             'homepage' => $url,
118             'rawdescription' =>
119             // TRANS: Plugin description.
120             _m('Plugin for Sphinx search backend.'));
121
122         return true;
123     }
124 }