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