]> git.mxchange.org Git - friendica.git/blob - mod/crepair.php
Some Bugfixes, and variable checks
[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
63         $r = q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `url` = '%s', `request` = '%s', `confirm` = '%s', `notify` = '%s', `poll` = '%s', `attag` = '%s' 
64                 WHERE `id` = %d AND `uid` = %d LIMIT 1",
65                 dbesc($name),
66                 dbesc($nick),
67                 dbesc($url),
68                 dbesc($request),
69                 dbesc($confirm),
70                 dbesc($notify),
71                 dbesc($poll),
72                 dbesc($attag),
73                 intval($contact['id']),
74                 local_user()
75         );
76
77         if($photo) {
78                 logger('mod-crepair: updating photo from ' . $photo);
79                 require_once("Photo.php");
80
81                 $photos = import_profile_photo($photo,local_user(),$contact['id']);
82
83                 $x = q("UPDATE `contact` SET `photo` = '%s',
84                         `thumb` = '%s',
85                         `micro` = '%s',
86                         `name-date` = '%s',
87                         `uri-date` = '%s',
88                         `avatar-date` = '%s'
89                         WHERE `id` = %d LIMIT 1
90                         ",
91                         dbesc($photos[0]),
92                         dbesc($photos[1]),
93                         dbesc($photos[2]),
94                         dbesc(datetime_convert()),
95                         dbesc(datetime_convert()),
96                         dbesc(datetime_convert()),
97                         intval($contact['id'])
98                 );
99         }
100
101         if($r)
102                 info( t('Contact settings applied.') . EOL);
103         else
104                 notice( t('Contact update failed.') . EOL);
105
106
107         return;
108 }
109
110
111
112 function crepair_content(&$a) {
113
114         if(! local_user()) {
115                 notice( t('Permission denied.') . EOL);
116                 return;
117         }
118
119         $cid = (($a->argc > 1) ? intval($a->argv[1]) : 0);
120
121         if($cid) {
122                 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
123                         intval($cid),
124                         intval(local_user())
125                 );
126         }
127
128         if(! count($r)) {
129                 notice( t('Contact not found.') . EOL);
130                 return;
131         }
132
133         $contact = $r[0];
134
135         $msg1 = t('Repair Contact Settings');
136
137         $msg2 = t('<strong>WARNING: This is highly advanced</strong> and if you enter incorrect information your communications with this contact may stop working.');
138         $msg3 = t('Please use your browser \'Back\' button <strong>now</strong> if you are uncertain what to do on this page.');
139
140         $o .= '<h2>' . $msg1 . '</h2>';
141
142         $o .= '<div class="error-message">' . $msg2 . EOL . EOL. $msg3 . '</div>';
143
144         $o .= EOL . '<a href="contacts/' . $cid . '">' . t('Return to contact editor') . '</a>' . EOL;
145
146         $tpl = get_markup_template('crepair.tpl');
147         $o .= replace_macros($tpl, array(
148                 '$label_name' => t('Name'),
149                 '$label_nick' => t('Account Nickname'),
150                 '$label_attag' => t('@Tagname - overrides Name/Nickname'),
151                 '$label_url' => t('Account URL'),
152                 '$label_request' => t('Friend Request URL'),
153                 '$label_confirm' => t('Friend Confirm URL'),
154                 '$label_notify' => t('Notification Endpoint URL'),
155                 '$label_poll' => t('Poll/Feed URL'),
156                 '$label_photo' => t('New photo from this URL'),
157                 '$contact_name' => $contact['name'],
158                 '$contact_nick' => $contact['nick'],
159                 '$contact_id'   => $contact['id'],
160                 '$contact_url'  => $contact['url'],
161                 '$request'      => $contact['request'],
162                 '$confirm'      => $contact['confirm'],
163                 '$notify'       => $contact['notify'],
164                 '$poll'         => $contact['poll'],
165                 '$contact_attag'  => $contact['attag'],
166                 '$lbl_submit'   => t('Submit')
167         ));
168
169         return $o;
170
171 }