]> git.mxchange.org Git - friendica.git/blob - src/Module/Diaspora/Fetch.php
Remove deprecated method to find duplicates (issue from 2013)
[friendica.git] / src / Module / Diaspora / Fetch.php
1 <?php
2
3 namespace Friendica\Module\Diaspora;
4
5 use Friendica\BaseModule;
6 use Friendica\Core\Protocol;
7 use Friendica\Core\System;
8 use Friendica\Model\Item;
9 use Friendica\Model\User;
10 use Friendica\Network\HTTPException;
11 use Friendica\Protocol\Diaspora;
12 use Friendica\Util\Strings;
13
14 /**
15  * This module is part of the Diaspora protocol.
16  * It is used for fetching single public posts.
17  */
18 class Fetch extends BaseModule
19 {
20         public static function rawContent()
21         {
22                 $app = self::getApp();
23
24                 // @TODO: Replace with parameter from router
25                 if (($app->argc != 3) || (!in_array($app->argv[1], ["post", "status_message", "reshare"]))) {
26                         throw new HTTPException\NotFoundException();
27                 }
28
29                 // @TODO: Replace with parameter from router
30                 $guid = $app->argv[2];
31
32                 // Fetch the item
33                 $fields = [
34                         'uid', 'title', 'body', 'guid', 'contact-id', 'private', 'created', 'app', 'location', 'coord', 'network',
35                         'event-id', 'resource-id', 'author-link', 'author-avatar', 'author-name', 'plink', 'owner-link', 'attach'
36                 ];
37                 $condition = ['wall' => true, 'private' => false, 'guid' => $guid, 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
38                 $item = Item::selectFirst($fields, $condition);
39                 if (empty($item)) {
40                         $condition = ['guid' => $guid, 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
41                         $item = Item::selectFirst(['author-link'], $condition);
42                         if (empty($item)) {
43                                 $parts = parse_url($item["author-link"]);
44                                 if (empty($parts["scheme"]) || empty($parts["host"])) {
45                                         throw new HTTPException\InternalServerErrorException();
46                                 }
47                                 $host = $parts["scheme"] . "://" . $parts["host"];
48
49                                 if (Strings::normaliseLink($host) != Strings::normaliseLink($app->getBaseURL())) {
50                                         $location = $host . "/fetch/" . $app->argv[1] . "/" . urlencode($guid);
51                                         System::externalRedirect($location, 301);
52                                 }
53                         }
54
55                         throw new HTTPException\NotFoundException();
56                 }
57
58                 // Fetch some data from the author (We could combine both queries - but I think this is more readable)
59                 $user = User::getOwnerDataById($item["uid"]);
60                 if (!$user) {
61                         throw new HTTPException\NotFoundException();
62                 }
63
64                 $status = Diaspora::buildStatus($item, $user);
65                 $xml = Diaspora::buildPostXml($status["type"], $status["message"]);
66
67                 // Send the envelope
68                 header("Content-Type: application/magic-envelope+xml; charset=utf-8");
69                 echo Diaspora::buildMagicEnvelope($xml, $user);
70
71                 exit();
72         }
73 }