allsites.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/usr/bin/env php
  2. <?php
  3. // This file is part of GNU social - https://www.gnu.org/software/social
  4. //
  5. // GNU social is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU Affero General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // GNU social is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU Affero General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License
  16. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  17. /**
  18. * @package GNUsocial
  19. * @author Evan Prodromou <evan@status.net>
  20. * @copyright 2009, StatusNet, Inc.
  21. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  22. */
  23. // Abort if called from a web server
  24. define('INSTALLDIR', dirname(__DIR__));
  25. define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
  26. $shortoptions = 't:w:';
  27. $longoptions = array('tagged=', 'not-tagged=');
  28. $helptext = <<<ENDOFHELP
  29. allsites.php - list all sites configured for multi-site use
  30. USAGE: allsites.php [OPTIONS]
  31. -t --tagged=tagname List only sites with this tag
  32. -w --not-tagged=tagname List only sites without this tag
  33. ENDOFHELP;
  34. require_once INSTALLDIR.'/scripts/commandline.inc';
  35. function print_all_sites()
  36. {
  37. $sn = new Status_network();
  38. if ($sn->find()) {
  39. while ($sn->fetch()) {
  40. print "$sn->nickname\n";
  41. }
  42. }
  43. return;
  44. }
  45. function print_tagged_sites($tag)
  46. {
  47. $sn = new Status_network();
  48. $sn->query(
  49. 'SELECT status_network.nickname '.
  50. 'FROM status_network INNER JOIN status_network_tag '.
  51. 'ON status_network.site_id = status_network_tag.site_id '.
  52. "WHERE status_network_tag.tag = '" . $sn->escape($tag) . "'"
  53. );
  54. while ($sn->fetch()) {
  55. print "$sn->nickname\n";
  56. }
  57. return;
  58. }
  59. function print_untagged_sites($tag)
  60. {
  61. $sn = new Status_network();
  62. $sn->query(
  63. 'SELECT status_network.nickname '.
  64. 'FROM status_network '.
  65. 'WHERE NOT EXISTS '.
  66. '(SELECT tag FROM status_network_tag '.
  67. 'WHERE site_id = status_network.site_id '.
  68. "AND tag = '" . $sn->escape($tag) . "')"
  69. );
  70. while ($sn->fetch()) {
  71. print "$sn->nickname\n";
  72. }
  73. return;
  74. }
  75. if (have_option('t', 'tagged')) {
  76. $tag = get_option_value('t', 'tagged');
  77. print_tagged_sites($tag);
  78. } elseif (have_option('w', 'not-tagged')) {
  79. $tag = get_option_value('w', 'not-tagged');
  80. print_untagged_sites($tag);
  81. } else {
  82. print_all_sites();
  83. }