Merge pull request #9701 from MrPetovan/bug/9636-frio-mobile-intros-buttons
[friendica.git/.git] / mod / repair_ostatus.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
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']);
41
42         $r = q("SELECT COUNT(*) AS `total` FROM `contact` WHERE
43         `uid` = %d AND `network` = '%s' AND `rel` IN (%d, %d)",
44                 intval($uid),
45                 DBA::escape(Protocol::OSTATUS),
46                 intval(Contact::FRIEND),
47                 intval(Contact::SHARING));
48
49         if (!DBA::isResult($r)) {
50                 return ($o . DI::l10n()->t("Error"));
51         }
52
53         $total = $r[0]["total"];
54
55         $r = q("SELECT `url` FROM `contact` WHERE
56                 `uid` = %d AND `network` = '%s' AND `rel` IN (%d, %d)
57                 ORDER BY `url`
58                 LIMIT %d, 1",
59                 intval($uid),
60                 DBA::escape(Protocol::OSTATUS),
61                 intval(Contact::FRIEND),
62                 intval(Contact::SHARING), $counter++);
63
64         if (!DBA::isResult($r)) {
65                 $o .= DI::l10n()->t("Done");
66                 return $o;
67         }
68
69         $o .= "<p>".$counter."/".$total.": ".$r[0]["url"]."</p>";
70
71         $o .= "<p>".DI::l10n()->t("Keep this window open until done.")."</p>";
72
73         Contact::createFromProbe($a->user, $r[0]["url"], true);
74
75         DI::page()['htmlhead'] = '<meta http-equiv="refresh" content="1; URL=' . DI::baseUrl() . '/repair_ostatus?counter='.$counter.'">';
76
77         return $o;
78 }