allsites.php 2.5 KB

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