-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathComic.php
113 lines (90 loc) · 3.59 KB
/
Comic.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
<?php
namespace IdnoPlugins\Comic {
class Comic extends \Idno\Common\Entity
{
function getTitle()
{
if (empty($this->title)) return \Idno\Core\Idno::site()->language()->_('Untitled');
return $this->title;
}
function getDescription()
{
if (!empty($this->body)) return $this->body;
return '';
}
function getURL()
{
// If we have a URL override, use it
if (!empty($this->url)) {
return $this->url;
}
if (!empty($this->canonical)) {
return $this->canonical;
}
if (($this->getID())) {
return \Idno\Core\Idno::site()->config()->url . 'comic/' . $this->getID() . '/' . $this->getPrettyURLTitle();
} else {
return parent::getURL();
}
}
/**
* Entry objects have type 'article'
* @return 'article'
*/
function getActivityStreamsObjectType()
{
return 'article';
}
function saveDataFromInput()
{
if (empty($this->_id)) {
$new = true;
} else {
$new = false;
}
if ($new) {
if (!\Idno\Core\Idno::site()->triggerEvent("file/upload", [], true)) {
return false;
}
}
$body = \Idno\Core\Idno::site()->currentPage()->getInput('body');
if (!empty($_FILES['comic']['tmp_name']) || !empty($this->_id)) {
$this->body = $body;
$this->title = \Idno\Core\Idno::site()->currentPage()->getInput('title');
$this->description = \Idno\Core\Idno::site()->currentPage()->getInput('description');
if ($time = \Idno\Core\Idno::site()->currentPage()->getInput('created')) {
if ($time = strtotime($time)) {
$this->created = $time;
}
}
if (!empty($_FILES['comic']['tmp_name'])) {
if (\Idno\Entities\File::isImage($_FILES['comic']['tmp_name'])) {
if ($size = getimagesize($_FILES['comic']['tmp_name'])) {
$this->width = $size[0];
$this->height = $size[1];
}
if ($comic = \Idno\Entities\File::createFromFile($_FILES['comic']['tmp_name'], $_FILES['comic']['name'], $_FILES['comic']['type'], true)) {
$this->attachFile($comic);
}
}
}
$this->setAccess(\Idno\Core\Idno::site()->currentPage()->getInput('access', 'PUBLIC'));
if ($this->publish($new)) {
if ($this->getAccess() == 'PUBLIC') {
\Idno\Core\Webmention::pingMentions($this->getURL(), \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 comic.'));
}
return false;
}
function deleteData()
{
if ($this->getAccess() == 'PUBLIC') {
\Idno\Core\Webmention::pingMentions($this->getURL(), \Idno\Core\Idno::site()->template()->parseURLs($this->getDescription()));
}
}
}
}