]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/SphinxSearch/scripts/sphinx-utils.php
Introduced common_location_shared() to check if location sharing is always,
[quix0rs-gnu-social.git] / plugins / SphinxSearch / scripts / sphinx-utils.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2009, 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 function sphinx_use_network()
21 {
22     return have_option('network');
23 }
24
25 function sphinx_base()
26 {
27     if (have_option('base')) {
28         return get_option_value('base');
29     } else {
30         return "/usr/local/sphinx";
31     }
32 }
33
34 function sphinx_iterate_sites($callback)
35 {
36     if (sphinx_use_network()) {
37         // @fixme this should use, like, some kind of config
38         Status_network::setupDB('localhost', 'statusnet', 'statuspass', 'statusnet');
39         $sn = new Status_network();
40         if (!$sn->find()) {
41             die("Confused... no sites in status_network table or lookup failed.\n");
42         }
43         while ($sn->fetch()) {
44             $callback($sn);
45         }
46     } else {
47         if (preg_match('!^(mysqli?|pgsql)://(.*?):(.*?)@(.*?)/(.*?)$!',
48                 common_config('db', 'database'), $matches)) {
49             list(/*all*/, $dbtype, $dbuser, $dbpass, $dbhost, $dbname) = $matches;
50             $sn = (object)array(
51                 'sitename' => common_config('site', 'name'),
52                 'dbhost' => $dbhost,
53                 'dbuser' => $dbuser,
54                 'dbpass' => $dbpass,
55                 'dbname' => $dbname);
56             $callback($sn);
57         } else {
58             print "Unrecognized database configuration string in config.php\n";
59             exit(1);
60         }
61     }
62 }