-
Notifications
You must be signed in to change notification settings - Fork 3
/
Status.php
150 lines (124 loc) · 5.02 KB
/
Status.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
namespace IdnoPlugins\Status {
class Status extends \Idno\Common\Entity
{
/**
* Create an appropriate status class.
* Returns an appropriate new class, either a Status or a Reply, depending on whether it is in reply to something.
* @return Status|Reply
*/
public static function factory()
{
$inreplyto = \Idno\Core\Idno::site()->currentPage()->getInput('inreplyto');
$body = \Idno\Core\Idno::site()->currentPage()->getInput('body');
if (!empty($inreplyto)) {
return new Reply();
}
if ($body[0] == '@') {
return new Reply();
}
return new Status();
}
function getTitle()
{
$title = trim($this->getShortDescription(7));
if (empty($title)) {
$title = \Idno\Core\Idno::site()->language('Status update');
} else if ($title != trim($this->getShortDescription())) $title .= ' ...';
return $title;
}
function getDescription()
{
$body = $this->body;
if (!empty($this->inreplyto)) {
if (is_array($this->inreplyto)) {
foreach ($this->inreplyto as $inreplyto) {
$body = '<a href="' . $inreplyto . '" class="u-in-reply-to"></a>' . $body;
}
} else {
$body = '<a href="' . $this->inreplyto . '" class="u-in-reply-to"></a>' . $body;
}
}
if (!empty($this->syndicatedto)) {
foreach ($this->syndicatedto as $syndicated) {
$body = '<a href="' . $syndicated . '" class="u-in-reply-to"></a>' . $body;
}
}
return $body;
}
/**
* Status objects have type 'note'
* @return 'note'
*/
function getActivityStreamsObjectType()
{
return 'note';
}
function getMetadataForFeed()
{
$meta = array('type' => 'status');
if ($this->inreplyto) {
$meta['in-reply-to'] = $this->inreplyto;
$meta['type'] = 'reply';
}
return $meta;
}
/**
* Saves changes to this object based on user input
* @return true|false
*/
function saveDataFromInput()
{
if (empty($this->_id)) {
$new = true;
} else {
$new = false;
}
$body = \Idno\Core\Idno::site()->currentPage()->getInput('body');
$inreplyto = \Idno\Core\Idno::site()->currentPage()->getInput('inreplyto');
$tags = \Idno\Core\Idno::site()->currentPage()->getInput('tags');
$access = \Idno\Core\Idno::site()->currentPage()->getInput('access');
if ($time = \Idno\Core\Idno::site()->currentPage()->getInput('created')) {
if ($time = strtotime($time)) {
$this->created = $time;
}
}
if (!empty($body) || ('0' === $body)) {
$this->body = $body;
$this->tags = $tags;
// TODO fetch syndicated reply targets asynchronously (or maybe on-demand, when syndicating?)
if (!empty($inreplyto)) {
$this->inreplyto = $inreplyto;
if (is_array($inreplyto)) {
foreach ($inreplyto as $inreplytourl) {
if (!empty($inreplytourl)) {
$this->syndicatedto = \Idno\Core\Webmention::addSyndicatedReplyTargets($inreplytourl, $this->syndicatedto);
}
}
} else {
$this->syndicatedto = \Idno\Core\Webmention::addSyndicatedReplyTargets($inreplyto);
}
}
$this->setAccess($access);
if ($this->publish($new)) {
if ($this->getAccess() == 'PUBLIC') {
\Idno\Core\Idno::site()->queue()->enqueue('default', 'webmention/sendall', [
'source' => $this->getURL(),
'text' => \Idno\Core\Idno::site()->template()->parseURLs($this->getDescription()),
]);
}
return true;
}
} else {
\Idno\Core\Idno::site()->session()->addErrorMessage(\Idno\Core\Idno::site()->language('You can\'t save an empty status update.'));
}
return false;
}
function deleteData()
{
if ($this->getAccess() == 'PUBLIC') {
\Idno\Core\Webmention::pingMentions($this->getURL(), \Idno\Core\Idno::site()->template()->parseURLs($this->getDescription()));
}
}
}
}