]> git.mxchange.org Git - friendica.git/blob - mod/subthread.php
Merge pull request #5634 from astifter/photo_view_page_icons
[friendica.git] / mod / subthread.php
1 <?php
2 /**
3  * @file mod/subthread.php
4  */
5 use Friendica\App;
6 use Friendica\Core\Addon;
7 use Friendica\Core\L10n;
8 use Friendica\Core\System;
9 use Friendica\Database\DBA;
10 use Friendica\Model\Item;
11
12 require_once 'include/security.php';
13 require_once 'include/items.php';
14
15 function subthread_content(App $a) {
16
17         if (!local_user() && !remote_user()) {
18                 return;
19         }
20
21         $activity = ACTIVITY_FOLLOW;
22
23         $item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0);
24
25         $condition = ["`parent` = ? OR `parent-uri` = ? AND `parent` = `id`", $item_id, $item_id];
26         $item = Item::selectFirst([], $condition);
27
28         if (empty($item_id) || !DBA::isResult($item)) {
29                 logger('subthread: no item ' . $item_id);
30                 return;
31         }
32
33         $owner_uid = $item['uid'];
34
35         if (!can_write_wall($owner_uid)) {
36                 return;
37         }
38
39         $remote_owner = null;
40
41         if (!$item['wall']) {
42                 // The top level post may have been written by somebody on another system
43                 $contact = DBA::selectFirst('contact', [], ['id' => $item['contact-id'], 'uid' => $item['uid']]);
44                 if (!DBA::isResult($contact)) {
45                         return;
46                 }
47                 if (!$contact['self']) {
48                         $remote_owner = $contact;
49                 }
50         }
51
52         $owner = null;
53         // this represents the post owner on this system.
54
55         $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
56                 WHERE `contact`.`self` = 1 AND `contact`.`uid` = %d LIMIT 1",
57                 intval($owner_uid)
58         );
59
60         if (DBA::isResult($r)) {
61                 $owner = $r[0];
62         }
63
64         if (!$owner) {
65                 logger('like: no owner');
66                 return;
67         }
68
69         if (!$remote_owner) {
70                 $remote_owner = $owner;
71         }
72
73         $contact = null;
74         // This represents the person posting
75
76         if (local_user() && (local_user() == $owner_uid)) {
77                 $contact = $owner;
78         } else {
79                 $contact = DBA::selectFirst('contact', [], ['id' => $_SESSION['visitor_id'], 'uid' => $owner_uid]);
80                 if (!DBA::isResult($contact)) {
81                         return;
82                 }
83         }
84
85         $uri = Item::newURI($owner_uid);
86
87         $post_type = (($item['resource-id']) ? L10n::t('photo') : L10n::t('status'));
88         $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE );
89         $link = xmlify('<link rel="alternate" type="text/html" href="' . System::baseUrl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n") ;
90         $body = $item['body'];
91
92         $obj = <<< EOT
93
94         <object>
95                 <type>$objtype</type>
96                 <local>1</local>
97                 <id>{$item['uri']}</id>
98                 <link>$link</link>
99                 <title></title>
100                 <content>$body</content>
101         </object>
102 EOT;
103         $bodyverb = L10n::t('%1$s is following %2$s\'s %3$s');
104
105         if (!isset($bodyverb)) {
106                 return;
107         }
108
109         $arr = [];
110
111         $arr['guid'] = System::createGUID(32);
112         $arr['uri'] = $uri;
113         $arr['uid'] = $owner_uid;
114         $arr['contact-id'] = $contact['id'];
115         $arr['wall'] = $item['wall'];
116         $arr['origin'] = 1;
117         $arr['gravity'] = GRAVITY_ACTIVITY;
118         $arr['parent'] = $item['id'];
119         $arr['parent-uri'] = $item['uri'];
120         $arr['thr-parent'] = $item['uri'];
121         $arr['owner-name'] = $remote_owner['name'];
122         $arr['owner-link'] = $remote_owner['url'];
123         $arr['owner-avatar'] = $remote_owner['thumb'];
124         $arr['author-name'] = $contact['name'];
125         $arr['author-link'] = $contact['url'];
126         $arr['author-avatar'] = $contact['thumb'];
127
128         $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
129         $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
130         $plink = '[url=' . System::baseUrl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . ']' . $post_type . '[/url]';
131         $arr['body'] =  sprintf( $bodyverb, $ulink, $alink, $plink );
132
133         $arr['verb'] = $activity;
134         $arr['object-type'] = $objtype;
135         $arr['object'] = $obj;
136         $arr['allow_cid'] = $item['allow_cid'];
137         $arr['allow_gid'] = $item['allow_gid'];
138         $arr['deny_cid'] = $item['deny_cid'];
139         $arr['deny_gid'] = $item['deny_gid'];
140         $arr['visible'] = 1;
141         $arr['unseen'] = 1;
142
143         $post_id = Item::insert($arr);
144
145         if (!$item['visible']) {
146                 Item::update(['visible' => true], ['id' => $item['id']]);
147         }
148
149         $arr['id'] = $post_id;
150
151         Addon::callHooks('post_local_end', $arr);
152
153         killme();
154
155 }