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