]> git.mxchange.org Git - friendica.git/blob - mod/repair_ostatus.php
Merge pull request #6977 from annando/fix-reshare
[friendica.git] / mod / repair_ostatus.php
1 <?php
2 /**
3  * @file mod/repair_ostatus.php
4  */
5
6 use Friendica\App;
7 use Friendica\Core\L10n;
8 use Friendica\Core\Protocol;
9 use Friendica\Core\System;
10 use Friendica\Database\DBA;
11 use Friendica\Model\Contact;
12
13 function repair_ostatus_content(App $a) {
14
15         if (! local_user()) {
16                 notice(L10n::t('Permission denied.') . EOL);
17                 $a->internalRedirect('ostatus_repair');
18                 // NOTREACHED
19         }
20
21         $o = "<h2>".L10n::t("Resubscribing to OStatus contacts")."</h2>";
22
23         $uid = local_user();
24
25         $a = \get_app();
26
27         $counter = intval($_REQUEST['counter']);
28
29         $r = q("SELECT COUNT(*) AS `total` FROM `contact` WHERE
30         `uid` = %d AND `network` = '%s' AND `rel` IN (%d, %d)",
31                 intval($uid),
32                 DBA::escape(Protocol::OSTATUS),
33                 intval(Contact::FRIEND),
34                 intval(Contact::SHARING));
35
36         if (!DBA::isResult($r)) {
37                 return ($o . L10n::t("Error"));
38         }
39
40         $total = $r[0]["total"];
41
42         $r = q("SELECT `url` FROM `contact` WHERE
43                 `uid` = %d AND `network` = '%s' AND `rel` IN (%d, %d)
44                 ORDER BY `url`
45                 LIMIT %d, 1",
46                 intval($uid),
47                 DBA::escape(Protocol::OSTATUS),
48                 intval(Contact::FRIEND),
49                 intval(Contact::SHARING), $counter++);
50
51         if (!DBA::isResult($r)) {
52                 $o .= L10n::t("Done");
53                 return $o;
54         }
55
56         $o .= "<p>".$counter."/".$total.": ".$r[0]["url"]."</p>";
57
58         $o .= "<p>".L10n::t("Keep this window open until done.")."</p>";
59
60         Contact::createFromProbe($uid, $r[0]["url"], true);
61
62         $a->page['htmlhead'] = '<meta http-equiv="refresh" content="1; URL='.System::baseUrl().'/repair_ostatus?counter='.$counter.'">';
63
64         return $o;
65 }