]> git.mxchange.org Git - friendica.git/blob - mod/repair_ostatus.php
old boot.functions replaced in /mod
[friendica.git] / mod / repair_ostatus.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 use Friendica\App;
23 use Friendica\Core\Protocol;
24 use Friendica\Core\Session;
25 use Friendica\Database\DBA;
26 use Friendica\DI;
27 use Friendica\Model\Contact;
28
29 function repair_ostatus_content(App $a) {
30
31         if (!Session::getLocalUser()) {
32                 DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.'));
33                 DI::baseUrl()->redirect('ostatus_repair');
34                 // NOTREACHED
35         }
36
37         $o = '<h2>' . DI::l10n()->t('Resubscribing to OStatus contacts') . '</h2>';
38
39         $uid = Session::getLocalUser();
40
41         $counter = intval($_REQUEST['counter'] ?? 0);
42
43         $condition = ['uid' => $uid, 'network' => Protocol::OSTATUS, 'rel' => [Contact::FRIEND, Contact::SHARING]];
44         $total = DBA::count('contact', $condition);
45
46         if (!$total) {
47                 return ($o . DI::l10n()->t('Error'));
48         }
49
50         $contact = Contact::selectToArray(['url'], $condition, ['order' => ['url'], 'limit' => [$counter++, 1]]);
51         if (!DBA::isResult($contact)) {
52                 $o .= DI::l10n()->t('Done');
53                 return $o;
54         }
55
56         $o .= '<p>' . $counter . '/' . $total . ': ' . $contact[0]['url'] . '</p>';
57
58         $o .= '<p>' . DI::l10n()->t('Keep this window open until done.') . '</p>';
59
60         Contact::createFromProbeForUser($a->getLoggedInUserId(), $contact[0]['url']);
61
62         DI::page()['htmlhead'] = '<meta http-equiv="refresh" content="1; URL=' . DI::baseUrl() . '/repair_ostatus?counter=' . $counter . '">';
63
64         return $o;
65 }