]> git.mxchange.org Git - friendica.git/blob - mod/crepair.php
better handling of remote urls - especially FB opengraph
[friendica.git] / mod / crepair.php
1 <?php
2
3 function crepair_post(&$a) {
4         if(! local_user())
5                 return;
6
7         $cid = (($a->argc > 1) ? intval($a->argv[1]) : 0);
8
9         if($cid) {
10                 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
11                         intval($cid),
12                         intval(local_user())
13                 );
14         }
15
16         if(! count($r))
17                 return;
18
19         $contact = $r[0];
20
21         $nick    = ((x($_POST,'nick')) ? $_POST['nick'] : '');
22         $url     = ((x($_POST,'url')) ? $_POST['url'] : '');
23         $request = ((x($_POST,'request')) ? $_POST['request'] : '');
24         $confirm = ((x($_POST,'confirm')) ? $_POST['confirm'] : '');
25         $notify  = ((x($_POST,'notify')) ? $_POST['notify'] : '');
26         $poll    = ((x($_POST,'poll')) ? $_POST['poll'] : '');
27         $attag   = ((x($_POST,'attag')) ? $_POST['attag'] : '');
28         $photo   = ((x($_POST,'photo')) ? $_POST['photo'] : '');
29
30         $r = q("UPDATE `contact` SET `nick` = '%s', `url` = '%s', `request` = '%s', `confirm` = '%s', `notify` = '%s', `poll` = '%s', `attag` = '%s' 
31                 WHERE `id` = %d AND `uid` = %d LIMIT 1",
32                 dbesc($nick),
33                 dbesc($url),
34                 dbesc($request),
35                 dbesc($confirm),
36                 dbesc($notify),
37                 dbesc($poll),
38                 dbesc($attag),
39                 intval($contact['id']),
40                 local_user()
41         );
42
43         if($photo) {
44                 logger('mod-crepair: updating photo from ' . $photo);
45                 require_once("Photo.php");
46
47                 $photos = import_profile_photo($photo,local_user(),$contact['id']);
48
49                 $x = q("UPDATE `contact` SET `photo` = '%s',
50                         `thumb` = '%s',
51                         `micro` = '%s',
52                         `name-date` = '%s',
53                         `uri-date` = '%s',
54                         `avatar-date` = '%s'
55                         WHERE `id` = %d LIMIT 1
56                         ",
57                         dbesc($photos[0]),
58                         dbesc($photos[1]),
59                         dbesc($photos[2]),
60                         dbesc(datetime_convert()),
61                         dbesc(datetime_convert()),
62                         dbesc(datetime_convert()),
63                         intval($contact['id'])
64                 );
65         }
66
67         if($r)
68                 info( t('Contact settings applied.') . EOL);
69         else
70                 notice( t('Contact update failed.') . EOL);
71
72
73         return;
74 }
75
76
77
78 function crepair_content(&$a) {
79
80         if(! local_user()) {
81                 notice( t('Permission denied.') . EOL);
82                 return;
83         }
84
85         $cid = (($a->argc > 1) ? intval($a->argv[1]) : 0);
86
87         if($cid) {
88                 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
89                         intval($cid),
90                         intval(local_user())
91                 );
92         }
93
94         if(! count($r)) {
95                 notice( t('Contact not found.') . EOL);
96                 return;
97         }
98
99         $contact = $r[0];
100
101         $msg1 = t('Repair Contact Settings');
102
103         $msg2 = t('<strong>WARNING: This is highly advanced</strong> and if you enter incorrect information your communications with this contact will stop working.');
104         $msg3 = t('Please use your browser \'Back\' button <strong>now</strong> if you are uncertain what to do on this page.');
105
106         $o .= '<h2>' . $msg1 . '</h2>';
107
108         $o .= '<div class="error-message">' . $msg2 . EOL . EOL. $msg3 . '</div>';
109
110         $tpl = get_markup_template('crepair.tpl');
111         $o .= replace_macros($tpl, array(
112                 '$label_name' => t('Name'),
113                 '$label_nick' => t('Account Nickname'),
114                 '$label_attag' => t('@Tagname - overrides Name/Nickname'),
115                 '$label_url' => t('Account URL'),
116                 '$label_request' => t('Friend Request URL'),
117                 '$label_confirm' => t('Friend Confirm URL'),
118                 '$label_notify' => t('Notification Endpoint URL'),
119                 '$label_poll' => t('Poll/Feed URL'),
120                 '$label_photo' => t('New photo from this URL'),
121                 '$contact_name' => $contact['name'],
122                 '$contact_nick' => $contact['nick'],
123                 '$contact_id'   => $contact['id'],
124                 '$contact_url'  => $contact['url'],
125                 '$request'      => $contact['request'],
126                 '$confirm'      => $contact['confirm'],
127                 '$notify'       => $contact['notify'],
128                 '$poll'         => $contact['poll'],
129                 '$contact_attag'  => $contact['attag'],
130                 '$lbl_submit'   => t('Submit')
131         ));
132
133         return $o;
134
135 }