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.

187 lines
5.3 KiB

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