]> git.mxchange.org Git - friendica.git/blob - mod/repair_ostatus.php
RU translations THX Alexander An
[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\Database\DBA;
25 use Friendica\DI;
26 use Friendica\Model\Contact;
27
28 function repair_ostatus_content(App $a) {
29
30         if (!local_user()) {
31                 notice(DI::l10n()->t('Permission denied.'));
32                 DI::baseUrl()->redirect('ostatus_repair');
33                 // NOTREACHED
34         }
35
36         $o = '<h2>' . DI::l10n()->t('Resubscribing to OStatus contacts') . '</h2>';
37
38         $uid = local_user();
39
40         $counter = intval($_REQUEST['counter'] ?? 0);
41
42         $condition = ['uid' => $uid, 'network' => Protocol::OSTATUS, 'rel' => [Contact::FRIEND, Contact::SHARING]];
43         $total = DBA::count('contact', $condition);
44
45         if (!$total) {
46                 return ($o . DI::l10n()->t('Error'));
47         }
48
49         $contact = Contact::selectToArray(['url'], $condition, ['order' => ['url'], 'limit' => [$counter++, 1]]);
50         if (!DBA::isResult($contact)) {
51                 $o .= DI::l10n()->t('Done');
52                 return $o;
53         }
54
55         $o .= '<p>' . $counter . '/' . $total . ': ' . $contact[0]['url'] . '</p>';
56
57         $o .= '<p>' . DI::l10n()->t('Keep this window open until done.') . '</p>';
58
59         Contact::createFromProbeForUser($a->getLoggedInUserId(), $contact[0]['url']);
60
61         DI::page()['htmlhead'] = '<meta http-equiv="refresh" content="1; URL=' . DI::baseUrl() . '/repair_ostatus?counter=' . $counter . '">';
62
63         return $o;
64 }