]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - scripts/allsites.php
Make attachment fit better in notice: drop text and link
[quix0rs-gnu-social.git] / scripts / allsites.php
1 #!/usr/bin/env php
2 <?php
3 /*
4  * StatusNet - the distributed open-source microblogging tool
5  * Copyright (C) 2009, StatusNet, Inc.
6  *
7  * 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
21 // Abort if called from a web server
22
23 define('INSTALLDIR', dirname(__DIR__));
24 define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
25
26 $shortoptions = 't:w:';
27 $longoptions = array('tagged=', 'not-tagged=');
28
29 $helptext = <<<ENDOFHELP
30 allsites.php - list all sites configured for multi-site use
31 USAGE: allsites.php [OPTIONS]
32
33 -t --tagged=tagname  List only sites with this tag
34 -w --not-tagged=tagname List only sites without this tag
35
36 ENDOFHELP;
37
38 require_once INSTALLDIR.'/scripts/commandline.inc';
39
40 function print_all_sites() {
41
42     $sn = new Status_network();
43
44     if ($sn->find()) {
45         while ($sn->fetch()) {
46             print "$sn->nickname\n";
47         }
48     }
49     return;
50 }
51
52 function print_tagged_sites($tag) {
53
54     $sn = new Status_network();
55
56     $sn->query('select status_network.nickname '.
57                'from status_network join status_network_tag '.
58                'on status_network.site_id = status_network_tag.site_id '.
59                'where status_network_tag.tag = "' . $tag . '"');
60
61     while ($sn->fetch()) {
62         print "$sn->nickname\n";
63     }
64
65     return;
66 }
67
68 function print_untagged_sites($tag) {
69
70     $sn = new Status_network();
71
72     $sn->query('select status_network.nickname '.
73                'from status_network '.
74                'where not exists '.
75                '(select tag from status_network_tag '.
76                'where site_id = status_network.site_id '.
77                'and tag = "'.$tag.'")');
78
79     while ($sn->fetch()) {
80         print "$sn->nickname\n";
81     }
82
83     return;
84 }
85
86 if (have_option('t', 'tagged')) {
87     $tag = get_option_value('t', 'tagged');
88     print_tagged_sites($tag);
89 } else if (have_option('w', 'not-tagged')) {
90     $tag = get_option_value('w', 'not-tagged');
91     print_untagged_sites($tag);
92 } else {
93     print_all_sites();
94 }