QvitterMuted.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3. · ·
  4. · Get muted profiles for a profile ·
  5. · ·
  6. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7. · ·
  8. · ·
  9. · Q V I T T E R ·
  10. · ·
  11. · https://git.gnu.io/h2p/Qvitter ·
  12. · ·
  13. · ·
  14. · <o) ·
  15. · /_//// ·
  16. · (____/ ·
  17. · (o< ·
  18. · o> \\\\_\ ·
  19. · \\) \____) ·
  20. · ·
  21. · ·
  22. · ·
  23. · Qvitter is free software: you can redistribute it and / or modify it ·
  24. · under the terms of the GNU Affero General Public License as published by ·
  25. · the Free Software Foundation, either version three of the License or (at ·
  26. · your option) any later version. ·
  27. · ·
  28. · Qvitter is distributed in hope that it will be useful but WITHOUT ANY ·
  29. · WARRANTY; without even the implied warranty of MERCHANTABILTY or FITNESS ·
  30. · FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for ·
  31. · more details. ·
  32. · ·
  33. · You should have received a copy of the GNU Affero General Public License ·
  34. · along with Qvitter. If not, see <http://www.gnu.org/licenses/>. ·
  35. · ·
  36. · Contact h@nnesmannerhe.im if you have any questions. ·
  37. · ·
  38. · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */
  39. if (!defined('GNUSOCIAL')) { exit(1); }
  40. class QvitterMuted
  41. {
  42. public static function getMutedProfiles($profile_id, $offset = 0, $limit = PROFILES_PER_PAGE)
  43. {
  44. $ids = self::getMutedIDs($profile_id, $offset, $limit);
  45. if(count($ids) === 0) {
  46. return false;
  47. } else {
  48. $profiles = array();
  49. foreach($ids as $id) {
  50. try {
  51. $profiles[] = Profile::getByID($id);
  52. } catch (Exception $e) {
  53. //
  54. }
  55. }
  56. if(count($profiles) === 0) {
  57. return false;
  58. } else {
  59. return $profiles;
  60. }
  61. }
  62. }
  63. public static function getMutedIDs($profile_id, $offset, $limit)
  64. {
  65. if(!is_numeric($profile_id)) {
  66. return false;
  67. }
  68. $mutes = new Profile_prefs();
  69. $mutes->selectAdd('topic');
  70. $mutes->whereAdd("profile_id = ".$profile_id);
  71. $mutes->whereAdd("namespace = 'qvitter'");
  72. $mutes->whereAdd("data = '1'");
  73. $mutes->whereAdd("topic LIKE 'mute:%'");
  74. $mutes->orderBy('modified DESC');
  75. $mutes->limit($offset, $limit);
  76. if (!$mutes->find()) {
  77. return array();
  78. }
  79. $topics = $mutes->fetchAll('topic');
  80. $ids = array();
  81. foreach($topics as $topic) {
  82. $topic_exploded = explode(':',$topic);
  83. if(is_numeric($topic_exploded[1])) {
  84. $ids[] = $topic_exploded[1];
  85. }
  86. }
  87. return $ids;
  88. }
  89. }