/
Like.php
73 lines (61 loc) · 2.46 KB
/
Like.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
<?php
namespace IdnoPlugins\Reactions {
use Idno\Core\Idno;
use Idno\Core\Webmention;
class Like extends \Idno\Common\Entity {
function getTitle()
{
$result = 'Liked ';
if (!empty($this->description)) {
$result .= $this->description;
}
return $result;
}
function getActivityStreamsObjectType()
{
return 'like';
}
function saveDataFromInput()
{
$page = Idno::site()->currentPage();
if (empty($this->_id)) {
$new = true;
} else {
$new = false;
}
$this->likeof = $page->getInput('like-of');
if ($this->likeof) {
foreach ((array) $this->likeof as $likeofurl) {
$this->syndicatedto = Webmention::addSyndicatedReplyTargets($likeofurl, $this->syndicatedto);
}
}
$this->description = $page->getInput('description');
if (empty($this->description)) {
$result = \IdnoPlugins\Reactions\Pages\Fetch::fetch($this->likeof);
if (!empty($result['description'])) {
$this->description = $result['description'];
}
}
$this->setAccess($page->getInput('access'));
Idno::site()->logging()->log("saving like. new: $new");
if ($this->publish($new)) {
Idno::site()->logging()->log("sending webmentions from {$this->getURL()} to {$this->likeof}");
Webmention::sendWebmentionPayload($this->getURL(), $this->likeof);
}
return true;
}
function save()
{
// generate our own meaningful, unique(ish) slug
if (!$this->getSlug() && !$this->_id
&& $this->getTitle() && $this->likeof) {
$this->setSlugResilient($this->getTitle() . '-' . substr(md5($this->likeof), 0, 10));
}
return parent::save();
}
public function getEditURL()
{
return \Idno\Core\Idno::site()->config()->getDisplayURL() . 'indielike/edit/' . $this->getID();
}
}
}