Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
4.4 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. <?php
  2. function community_init(&$a) {
  3. if(! local_user()) {
  4. unset($_SESSION['theme']);
  5. unset($_SESSION['mobile-theme']);
  6. }
  7. }
  8. function community_content(&$a, $update = 0) {
  9. $o = '';
  10. if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
  11. notice( t('Public access denied.') . EOL);
  12. return;
  13. }
  14. if(get_config('system','no_community_page')) {
  15. notice( t('Not available.') . EOL);
  16. return;
  17. }
  18. require_once("include/bbcode.php");
  19. require_once('include/security.php');
  20. require_once('include/conversation.php');
  21. $o .= '<h3>' . t('Community') . '</h3>';
  22. if(! $update) {
  23. nav_set_selected('community');
  24. }
  25. if(x($a->data,'search'))
  26. $search = notags(trim($a->data['search']));
  27. else
  28. $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
  29. // Here is the way permissions work in this module...
  30. // Only public posts can be shown
  31. // OR your own posts if you are a logged in member
  32. if(get_config('system', 'old_pager')) {
  33. $r = q("SELECT COUNT(distinct(`item`.`uri`)) AS `total`
  34. FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
  35. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  36. INNER JOIN `user` ON `user`.`uid` = `item`.`uid` AND `user`.`hidewall` = 0
  37. WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
  38. AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
  39. AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
  40. AND `item`.`private` = 0 AND `item`.`wall` = 1"
  41. );
  42. if(count($r))
  43. $a->set_pager_total($r[0]['total']);
  44. if(! $r[0]['total']) {
  45. info( t('No results.') . EOL);
  46. return $o;
  47. }
  48. }
  49. $r = community_getitems($a->pager['start'], $a->pager['itemspage']);
  50. if(! count($r)) {
  51. info( t('No results.') . EOL);
  52. return $o;
  53. }
  54. $maxpostperauthor = get_config('system','max_author_posts_community_page');
  55. if ($maxpostperauthor != 0) {
  56. $count = 1;
  57. $previousauthor = "";
  58. $numposts = 0;
  59. $s = array();
  60. do {
  61. foreach ($r AS $row=>$item) {
  62. if ($previousauthor == $item["author-link"])
  63. ++$numposts;
  64. else
  65. $numposts = 0;
  66. $previousauthor = $item["author-link"];
  67. if (($numposts < $maxpostperauthor) AND (sizeof($s) < $a->pager['itemspage']))
  68. $s[] = $item;
  69. }
  70. if ((sizeof($s) < $a->pager['itemspage']))
  71. $r = community_getitems($a->pager['start'] + ($count * $a->pager['itemspage']), $a->pager['itemspage']);
  72. } while ((sizeof($s) < $a->pager['itemspage']) AND (++$count < 50) AND (sizeof($r) > 0));
  73. } else
  74. $s = $r;
  75. // we behave the same in message lists as the search module
  76. $o .= conversation($a,$s,'community',$update);
  77. if(!get_config('system', 'old_pager')) {
  78. $o .= alt_pager($a,count($r));
  79. } else {
  80. $o .= paginate($a);
  81. }
  82. return $o;
  83. }
  84. function community_getitems($start, $itemspage) {
  85. // Work in progress
  86. if (get_config('system', 'global_community'))
  87. return(community_getpublicitems($start, $itemspage));
  88. $r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
  89. `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`,
  90. `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
  91. `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`,
  92. `user`.`nickname`, `user`.`hidewall`
  93. FROM `thread` FORCE INDEX (`wall_private_received`)
  94. INNER JOIN `user` ON `user`.`uid` = `thread`.`uid` AND `user`.`hidewall` = 0
  95. INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
  96. AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
  97. AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
  98. INNER JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
  99. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `contact`.`self`
  100. WHERE `thread`.`visible` = 1 AND `thread`.`deleted` = 0 and `thread`.`moderated` = 0
  101. AND `thread`.`private` = 0 AND `thread`.`wall` = 1
  102. ORDER BY `thread`.`received` DESC LIMIT %d, %d ",
  103. intval($start),
  104. intval($itemspage)
  105. );
  106. return($r);
  107. }
  108. function community_getpublicitems($start, $itemspage) {
  109. $r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
  110. `author-name` AS `name`, `owner-avatar` AS `photo`,
  111. `owner-link` AS `url`, `owner-avatar` AS `thumb`
  112. FROM `item` WHERE `item`.`uid` = 0
  113. AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
  114. AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
  115. ORDER BY `item`.`received` DESC LIMIT %d, %d",
  116. intval($start),
  117. intval($itemspage)
  118. );
  119. return($r);
  120. }