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.

180 lines
5.3 KiB

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