]> git.mxchange.org Git - friendica.git/blob - mod/crepair.php
Remote self is now working for diaspora contacts as well.
[friendica.git] / mod / crepair.php
1 <?php
2
3 function crepair_init(&$a) {
4         if(! local_user())
5                 return;
6
7         $contact_id = 0;
8
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(! count($r)) {
16                         $contact_id = 0;
17                 }
18         }
19
20         if(! x($a->page,'aside'))
21                 $a->page['aside'] = '';
22
23         if($contact_id) {
24                         $a->data['contact'] = $r[0];
25                         $o .= '<div class="vcard">';
26                         $o .= '<div class="fn">' . $a->data['contact']['name'] . '</div>';
27                         $o .= '<div id="profile-photo-wrapper"><img class="photo" style="width: 175px; height: 175px;" src="' . $a->data['contact']['photo'] . '" alt="' . $a->data['contact']['name'] . '" /></div>';
28                         $o .= '</div>';
29                         $a->page['aside'] .= $o;
30
31         }
32 }
33
34
35 function crepair_post(&$a) {
36         if(! local_user())
37                 return;
38
39         $cid = (($a->argc > 1) ? intval($a->argv[1]) : 0);
40
41         if($cid) {
42                 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
43                         intval($cid),
44                         intval(local_user())
45                 );
46         }
47
48         if(! count($r))
49                 return;
50
51         $contact = $r[0];
52
53         $name    = ((x($_POST,'name')) ? $_POST['name'] : $contact['name']);
54         $nick    = ((x($_POST,'nick')) ? $_POST['nick'] : '');
55         $url     = ((x($_POST,'url')) ? $_POST['url'] : '');
56         $request = ((x($_POST,'request')) ? $_POST['request'] : '');
57         $confirm = ((x($_POST,'confirm')) ? $_POST['confirm'] : '');
58         $notify  = ((x($_POST,'notify')) ? $_POST['notify'] : '');
59         $poll    = ((x($_POST,'poll')) ? $_POST['poll'] : '');
60         $attag   = ((x($_POST,'attag')) ? $_POST['attag'] : '');
61         $photo   = ((x($_POST,'photo')) ? $_POST['photo'] : '');
62         $remote_self = ((x($_POST,'remote_self')) ? $_POST['remote_self'] : false);
63         $nurl    = normalise_link($url);
64
65         $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
66                 WHERE `id` = %d AND `uid` = %d",
67                 dbesc($name),
68                 dbesc($nick),
69                 dbesc($url),
70                 dbesc($nurl),
71                 dbesc($request),
72                 dbesc($confirm),
73                 dbesc($notify),
74                 dbesc($poll),
75                 dbesc($attag),
76                 intval($remote_self),
77                 intval($contact['id']),
78                 local_user()
79         );
80
81         if($photo) {
82                 logger('mod-crepair: updating photo from ' . $photo);
83                 require_once("include/Photo.php");
84
85                 $photos = import_profile_photo($photo,local_user(),$contact['id']);
86
87                 $x = q("UPDATE `contact` SET `photo` = '%s',
88                         `thumb` = '%s',
89                         `micro` = '%s',
90                         `name-date` = '%s',
91                         `uri-date` = '%s',
92                         `avatar-date` = '%s'
93                         WHERE `id` = %d
94                         ",
95                         dbesc($photos[0]),
96                         dbesc($photos[1]),
97                         dbesc($photos[2]),
98                         dbesc(datetime_convert()),
99                         dbesc(datetime_convert()),
100                         dbesc(datetime_convert()),
101                         intval($contact['id'])
102                 );
103         }
104
105         if($r)
106                 info( t('Contact settings applied.') . EOL);
107         else
108                 notice( t('Contact update failed.') . EOL);
109
110
111         return;
112 }
113
114
115
116 function crepair_content(&$a) {
117
118         if(! local_user()) {
119                 notice( t('Permission denied.') . EOL);
120                 return;
121         }
122
123         $cid = (($a->argc > 1) ? intval($a->argv[1]) : 0);
124
125         if($cid) {
126                 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
127                         intval($cid),
128                         intval(local_user())
129                 );
130         }
131
132         if(! count($r)) {
133                 notice( t('Contact not found.') . EOL);
134                 return;
135         }
136
137         $contact = $r[0];
138
139         $msg1 = t('Repair Contact Settings');
140
141         $msg2 = t('<strong>WARNING: This is highly advanced</strong> and if you enter incorrect information your communications with this contact may stop working.');
142         $msg3 = t('Please use your browser \'Back\' button <strong>now</strong> if you are uncertain what to do on this page.');
143
144         $o .= '<h2>' . $msg1 . '</h2>';
145
146         $o .= '<div class="error-message">' . $msg2 . EOL . EOL. $msg3 . '</div>';
147
148         $o .= EOL . '<a href="contacts/' . $cid . '">' . t('Return to contact editor') . '</a>' . EOL;
149
150         $allow_remote_self = get_config('system','allow_users_remote_self');
151
152         // Disable remote self for everything except feeds.
153         // There is an issue when you repeat an item from maybe twitter and you got comments from friendica and twitter
154         // Problem is, you couldn't reply to both networks.
155         if (!in_array($contact['network'], array(NETWORK_FEED, NETWORK_DFRN, NETWORK_DIASPORA)))
156                 $allow_remote_self = false;
157
158         if ($contact['network'] == NETWORK_FEED)
159                 $remote_self_options = array('0'=>t('No mirroring'), '1'=>t('Mirror as forwarded posting'), '2'=>t('Mirror as my own posting'));
160         else
161                 $remote_self_options = array('0'=>t('No mirroring'), '2'=>t('Mirror as my own posting'));
162
163         $tpl = get_markup_template('crepair.tpl');
164         $o .= replace_macros($tpl, array(
165                 '$label_name' => t('Name'),
166                 '$label_nick' => t('Account Nickname'),
167                 '$label_attag' => t('@Tagname - overrides Name/Nickname'),
168                 '$label_url' => t('Account URL'),
169                 '$label_request' => t('Friend Request URL'),
170                 '$label_confirm' => t('Friend Confirm URL'),
171                 '$label_notify' => t('Notification Endpoint URL'),
172                 '$label_poll' => t('Poll/Feed URL'),
173                 '$label_photo' => t('New photo from this URL'),
174                 '$label_remote_self' => t('Remote Self'),
175                 '$allow_remote_self' => $allow_remote_self,
176                 '$remote_self' => array('remote_self', t('Mirror postings from this contact'), $contact['remote_self'], t('Mark this contact as remote_self, this will cause friendica to repost new entries from this contact.'), $remote_self_options),
177                 '$contact_name' => $contact['name'],
178                 '$contact_nick' => $contact['nick'],
179                 '$contact_id'   => $contact['id'],
180                 '$contact_url'  => $contact['url'],
181                 '$request'      => $contact['request'],
182                 '$confirm'      => $contact['confirm'],
183                 '$notify'       => $contact['notify'],
184                 '$poll'         => $contact['poll'],
185                 '$contact_attag'  => $contact['attag'],
186                 '$lbl_submit'   => t('Submit')
187             ));
188
189         return $o;
190
191 }