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