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.

162 lines
3.9 KiB

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