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