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