allsites.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. // Abort if called from a web server
  21. define('INSTALLDIR', dirname(__DIR__));
  22. define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
  23. $shortoptions = 't:w:';
  24. $longoptions = array('tagged=', 'not-tagged=');
  25. $helptext = <<<ENDOFHELP
  26. allsites.php - list all sites configured for multi-site use
  27. USAGE: allsites.php [OPTIONS]
  28. -t --tagged=tagname List only sites with this tag
  29. -w --not-tagged=tagname List only sites without this tag
  30. ENDOFHELP;
  31. require_once INSTALLDIR.'/scripts/commandline.inc';
  32. function print_all_sites() {
  33. $sn = new Status_network();
  34. if ($sn->find()) {
  35. while ($sn->fetch()) {
  36. print "$sn->nickname\n";
  37. }
  38. }
  39. return;
  40. }
  41. function print_tagged_sites($tag) {
  42. $sn = new Status_network();
  43. $sn->query('select status_network.nickname '.
  44. 'from status_network join status_network_tag '.
  45. 'on status_network.site_id = status_network_tag.site_id '.
  46. 'where status_network_tag.tag = "' . $tag . '"');
  47. while ($sn->fetch()) {
  48. print "$sn->nickname\n";
  49. }
  50. return;
  51. }
  52. function print_untagged_sites($tag) {
  53. $sn = new Status_network();
  54. $sn->query('select status_network.nickname '.
  55. 'from status_network '.
  56. 'where not exists '.
  57. '(select tag from status_network_tag '.
  58. 'where site_id = status_network.site_id '.
  59. 'and tag = "'.$tag.'")');
  60. while ($sn->fetch()) {
  61. print "$sn->nickname\n";
  62. }
  63. return;
  64. }
  65. if (have_option('t', 'tagged')) {
  66. $tag = get_option_value('t', 'tagged');
  67. print_tagged_sites($tag);
  68. } else if (have_option('w', 'not-tagged')) {
  69. $tag = get_option_value('w', 'not-tagged');
  70. print_untagged_sites($tag);
  71. } else {
  72. print_all_sites();
  73. }