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.
 
 
 
 
 
 

174 lines
4.2 KiB

  1. <?php
  2. /**
  3. * @file mod/profperm.php
  4. */
  5. use Friendica\App;
  6. use Friendica\Core\Config;
  7. use Friendica\Core\L10n;
  8. use Friendica\Core\Protocol;
  9. use Friendica\Content\Text\HTML;
  10. use Friendica\Database\DBA;
  11. use Friendica\DI;
  12. use Friendica\Model\Profile;
  13. function profperm_init(App $a)
  14. {
  15. if (!local_user()) {
  16. return;
  17. }
  18. $which = $a->user['nickname'];
  19. $profile = $a->argv[1];
  20. Profile::load($a, $which, $profile);
  21. }
  22. function profperm_content(App $a) {
  23. if (!local_user()) {
  24. notice(L10n::t('Permission denied') . EOL);
  25. return;
  26. }
  27. if ($a->argc < 2) {
  28. notice(L10n::t('Invalid profile identifier.') . EOL );
  29. return;
  30. }
  31. $o = '';
  32. // Switch to text mod interface if we have more than 'n' contacts or group members
  33. $switchtotext = DI::pConfig()->get(local_user(),'system','groupedit_image_limit');
  34. if (is_null($switchtotext)) {
  35. $switchtotext = Config::get('system','groupedit_image_limit', 400);
  36. }
  37. if (($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) {
  38. $r = q("SELECT `id` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `self` = 0
  39. AND `network` = '%s' AND `id` = %d AND `uid` = %d LIMIT 1",
  40. DBA::escape(Protocol::DFRN),
  41. intval($a->argv[2]),
  42. intval(local_user())
  43. );
  44. if (DBA::isResult($r)) {
  45. $change = intval($a->argv[2]);
  46. }
  47. }
  48. if (($a->argc > 1) && (intval($a->argv[1]))) {
  49. $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 LIMIT 1",
  50. intval($a->argv[1]),
  51. intval(local_user())
  52. );
  53. if (!DBA::isResult($r)) {
  54. notice(L10n::t('Invalid profile identifier.') . EOL );
  55. return;
  56. }
  57. $profile = $r[0];
  58. $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `profile-id` = %d",
  59. intval(local_user()),
  60. intval($a->argv[1])
  61. );
  62. $ingroup = [];
  63. if (DBA::isResult($r))
  64. foreach($r as $member)
  65. $ingroup[] = $member['id'];
  66. $members = $r;
  67. if (!empty($change)) {
  68. if (in_array($change,$ingroup)) {
  69. q("UPDATE `contact` SET `profile-id` = 0 WHERE `id` = %d AND `uid` = %d",
  70. intval($change),
  71. intval(local_user())
  72. );
  73. }
  74. else {
  75. q("UPDATE `contact` SET `profile-id` = %d WHERE `id` = %d AND `uid` = %d",
  76. intval($a->argv[1]),
  77. intval($change),
  78. intval(local_user())
  79. );
  80. }
  81. $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `profile-id` = %d",
  82. intval(local_user()),
  83. intval($a->argv[1])
  84. );
  85. $members = $r;
  86. $ingroup = [];
  87. if (DBA::isResult($r))
  88. foreach($r as $member)
  89. $ingroup[] = $member['id'];
  90. }
  91. $o .= '<h2>' . L10n::t('Profile Visibility Editor') . '</h2>';
  92. $o .= '<h3>' . L10n::t('Profile') . ' \'' . $profile['profile-name'] . '\'</h3>';
  93. $o .= '<div id="prof-edit-desc">' . L10n::t('Click on a contact to add or remove.') . '</div>';
  94. }
  95. $o .= '<div id="prof-update-wrapper">';
  96. if (!empty($change))
  97. $o = '';
  98. $o .= '<div id="prof-members-title">';
  99. $o .= '<h3>' . L10n::t('Visible To') . '</h3>';
  100. $o .= '</div>';
  101. $o .= '<div id="prof-members">';
  102. $textmode = (($switchtotext && (count($members) > $switchtotext)) ? true : false);
  103. foreach($members as $member) {
  104. if ($member['url']) {
  105. $member['click'] = 'profChangeMember(' . $profile['id'] . ',' . $member['id'] . '); return true;';
  106. $o .= HTML::micropro($member,true,'mpprof', $textmode);
  107. }
  108. }
  109. $o .= '</div><div id="prof-members-end"></div>';
  110. $o .= '<hr id="prof-separator" />';
  111. $o .= '<div id="prof-all-contcts-title">';
  112. $o .= '<h3>' . L10n::t("All Contacts \x28with secure profile access\x29") . '</h3>';
  113. $o .= '</div>';
  114. $o .= '<div id="prof-all-contacts">';
  115. $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 and `pending` = 0 and `self` = 0
  116. AND `network` = '%s' ORDER BY `name` ASC",
  117. intval(local_user()),
  118. DBA::escape(Protocol::DFRN)
  119. );
  120. if (DBA::isResult($r)) {
  121. $textmode = (($switchtotext && (count($r) > $switchtotext)) ? true : false);
  122. foreach($r as $member) {
  123. if (!in_array($member['id'],$ingroup)) {
  124. $member['click'] = 'profChangeMember(' . $profile['id'] . ',' . $member['id'] . '); return true;';
  125. $o .= HTML::micropro($member,true,'mpprof',$textmode);
  126. }
  127. }
  128. }
  129. $o .= '</div><div id="prof-all-contacts-end"></div>';
  130. if (!empty($change)) {
  131. echo $o;
  132. exit();
  133. }
  134. $o .= '</div>';
  135. return $o;
  136. }