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