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.

173 lines
5.2 KiB

  1. <?php
  2. /**
  3. * @file mod/crepair.php
  4. */
  5. use Friendica\App;
  6. use Friendica\Core\Config;
  7. use Friendica\Core\L10n;
  8. use Friendica\Core\Logger;
  9. use Friendica\Core\Protocol;
  10. use Friendica\Core\Renderer;
  11. use Friendica\Database\DBA;
  12. use Friendica\DI;
  13. use Friendica\Model;
  14. use Friendica\Module;
  15. use Friendica\Util\Strings;
  16. function crepair_init(App $a)
  17. {
  18. if (!local_user()) {
  19. return;
  20. }
  21. }
  22. function crepair_post(App $a)
  23. {
  24. if (!local_user()) {
  25. return;
  26. }
  27. $cid = (($a->argc > 1) ? intval($a->argv[1]) : 0);
  28. $contact = null;
  29. if ($cid) {
  30. $contact = DBA::selectFirst('contact', [], ['id' => $cid, 'uid' => local_user()]);
  31. }
  32. if (!DBA::isResult($contact)) {
  33. return;
  34. }
  35. $name = ($_POST['name'] ?? '') ?: $contact['name'];
  36. $nick = $_POST['nick'] ?? '';
  37. $url = $_POST['url'] ?? '';
  38. $alias = $_POST['alias'] ?? '';
  39. $request = $_POST['request'] ?? '';
  40. $confirm = $_POST['confirm'] ?? '';
  41. $notify = $_POST['notify'] ?? '';
  42. $poll = $_POST['poll'] ?? '';
  43. $attag = $_POST['attag'] ?? '';
  44. $photo = $_POST['photo'] ?? '';
  45. $remote_self = $_POST['remote_self'] ?? false;
  46. $nurl = Strings::normaliseLink($url);
  47. $r = DBA::update(
  48. 'contact',
  49. [
  50. 'name' => $name,
  51. 'nick' => $nick,
  52. 'url' => $url,
  53. 'nurl' => $nurl,
  54. 'alias' => $alias,
  55. 'request' => $request,
  56. 'confirm' => $confirm,
  57. 'notify' => $notify,
  58. 'poll' => $poll,
  59. 'attag' => $attag,
  60. 'remote_self' => $remote_self,
  61. ],
  62. ['id' => $contact['id'], 'uid' => local_user()]
  63. );
  64. if ($photo) {
  65. Logger::log('mod-crepair: updating photo from ' . $photo);
  66. Model\Contact::updateAvatar($photo, local_user(), $contact['id']);
  67. }
  68. if ($r) {
  69. info(L10n::t('Contact settings applied.') . EOL);
  70. } else {
  71. notice(L10n::t('Contact update failed.') . EOL);
  72. }
  73. return;
  74. }
  75. function crepair_content(App $a)
  76. {
  77. if (!local_user()) {
  78. notice(L10n::t('Permission denied.') . EOL);
  79. return;
  80. }
  81. $cid = (($a->argc > 1) ? intval($a->argv[1]) : 0);
  82. $contact = null;
  83. if ($cid) {
  84. $contact = DBA::selectFirst('contact', [], ['id' => $cid, 'uid' => local_user()]);
  85. }
  86. if (!DBA::isResult($contact)) {
  87. notice(L10n::t('Contact not found.') . EOL);
  88. return;
  89. }
  90. if (empty(DI::page()['aside'])) {
  91. DI::page()['aside'] = '';
  92. }
  93. if (DBA::isResult($contact)) {
  94. $a->data['contact'] = $contact;
  95. Model\Profile::load($a, "", 0, Model\Contact::getDetailsByURL($contact["url"]));
  96. }
  97. $warning = L10n::t('<strong>WARNING: This is highly advanced</strong> and if you enter incorrect information your communications with this contact may stop working.');
  98. $info = L10n::t('Please use your browser \'Back\' button <strong>now</strong> if you are uncertain what to do on this page.');
  99. $returnaddr = "contact/$cid";
  100. $allow_remote_self = Config::get('system', 'allow_users_remote_self');
  101. // Disable remote self for everything except feeds.
  102. // There is an issue when you repeat an item from maybe twitter and you got comments from friendica and twitter
  103. // Problem is, you couldn't reply to both networks.
  104. if (!in_array($contact['network'], [Protocol::FEED, Protocol::DFRN, Protocol::DIASPORA, Protocol::TWITTER])) {
  105. $allow_remote_self = false;
  106. }
  107. if ($contact['network'] == Protocol::FEED) {
  108. $remote_self_options = ['0' => L10n::t('No mirroring'), '1' => L10n::t('Mirror as forwarded posting'), '2' => L10n::t('Mirror as my own posting')];
  109. } else {
  110. $remote_self_options = ['0' => L10n::t('No mirroring'), '2' => L10n::t('Mirror as my own posting')];
  111. }
  112. $update_profile = in_array($contact['network'], Protocol::FEDERATED);
  113. $tab_str = Module\Contact::getTabsHTML($a, $contact, 6);
  114. $tpl = Renderer::getMarkupTemplate('crepair.tpl');
  115. $o = Renderer::replaceMacros($tpl, [
  116. '$tab_str' => $tab_str,
  117. '$warning' => $warning,
  118. '$info' => $info,
  119. '$returnaddr' => $returnaddr,
  120. '$return' => L10n::t('Return to contact editor'),
  121. '$update_profile' => $update_profile,
  122. '$udprofilenow' => L10n::t('Refetch contact data'),
  123. '$contact_id' => $contact['id'],
  124. '$lbl_submit' => L10n::t('Submit'),
  125. '$label_remote_self' => L10n::t('Remote Self'),
  126. '$allow_remote_self' => $allow_remote_self,
  127. '$remote_self' => ['remote_self',
  128. L10n::t('Mirror postings from this contact'),
  129. $contact['remote_self'],
  130. L10n::t('Mark this contact as remote_self, this will cause friendica to repost new entries from this contact.'),
  131. $remote_self_options
  132. ],
  133. '$name' => ['name', L10n::t('Name') , $contact['name']],
  134. '$nick' => ['nick', L10n::t('Account Nickname'), $contact['nick']],
  135. '$attag' => ['attag', L10n::t('@Tagname - overrides Name/Nickname'), $contact['attag']],
  136. '$url' => ['url', L10n::t('Account URL'), $contact['url']],
  137. '$alias' => ['alias', L10n::t('Account URL Alias'), $contact['alias']],
  138. '$request' => ['request', L10n::t('Friend Request URL'), $contact['request']],
  139. 'confirm' => ['confirm', L10n::t('Friend Confirm URL'), $contact['confirm']],
  140. 'notify' => ['notify', L10n::t('Notification Endpoint URL'), $contact['notify']],
  141. 'poll' => ['poll', L10n::t('Poll/Feed URL'), $contact['poll']],
  142. 'photo' => ['photo', L10n::t('New photo from this URL'), ''],
  143. ]);
  144. return $o;
  145. }