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