-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathReview.php
210 lines (165 loc) · 7.92 KB
/
Review.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
namespace IdnoPlugins\Review {
use Idno\Core\Autosave;
class Review extends \Idno\Common\Entity
{
function getTitle()
{
if (empty($this->title)) return 'Untitled';
return $this->title;
}
function getDescription()
{
if (!empty($this->body)) return $this->body;
return '';
}
function getRating()
{
if (!empty($this->rating)) return (int) $this->rating;
return '';
}
function getProductCategory()
{
if (!empty($this->productCategory)) return $this->productCategory;
return '';
}
function getProductName()
{
if (!empty($this->productName)) return $this->productName;
return '';
}
function getProductLink()
{
if (!empty($this->productLink)) return $this->productLink;
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->getSlug() && ($this->getID())) {
return \Idno\Core\site()->config()->url . 'review/' . $this->getID() . '/' . $this->getPrettyURLTitle();
} else {
return parent::getURL();
}
}
/**
* Review objects have type 'article'
* @return 'article'
*/
function getActivityStreamsObjectType()
{
return 'article';
}
/**
* Review objects show up as h-review in a Microformats stream
* @return string
*/
function getMicroformats2ObjectType() {
return 'h-review';
}
/**
* Retrieve icon
* @return mixed|string
*/
function getIcon()
{
$xpath = new \DOMXPath(@\DOMDocument::loadHTML($this->getDescription()));
$src = $xpath->evaluate("string(//img/@src)");
if (!empty($src)) {
return $src;
}
return parent::getIcon();
}
function getMetadataForFeed()
{
return array(
'type' => 'review',
'rating' => $this->getRating(),
'item' => array(
'name' => $this->getProductName(),
'url' => $this->getProductLink()
)
);
}
function saveDataFromInput()
{
if (empty($this->_id)) {
$new = true;
} else {
$new = false;
}
$body = \Idno\Core\site()->currentPage()->getInput('body');
if (!empty($body)) {
$this->body = $body;
$this->title = \Idno\Core\site()->currentPage()->getInput('title');
$this->rating = \Idno\Core\site()->currentPage()->getInput('rating');
$this->productName = \Idno\Core\site()->currentPage()->getInput('productName');
$this->productCategory = \Idno\Core\site()->currentPage()->getInput('productCategory');
$this->productLink = \Idno\Core\site()->currentPage()->getInput('productLink');
$access = \Idno\Core\site()->currentPage()->getInput('access');
$this->setAccess($access);
if ($time = \Idno\Core\site()->currentPage()->getInput('created')) {
if ($time = strtotime($time)) {
$this->created = $time;
}
}
if ($new) {
if (!empty($_FILES['photo']['tmp_name'])) {
if (\Idno\Entities\File::isImage($_FILES['photo']['tmp_name'])) {
// Extract exif data so we can rotate
if (is_callable('exif_read_data') && $_FILES['photo']['type'] == 'image/jpeg') {
try {
if (function_exists('exif_read_data')) {
if ($exif = exif_read_data($_FILES['photo']['tmp_name'])) {
$this->exif = base64_encode(serialize($exif)); // Yes, this is rough, but exif contains binary data that can not be saved in mongo
}
}
} catch (\Exception $e) {
$exif = false;
}
} else {
$exif = false;
}
if ($photo = \Idno\Entities\File::createFromFile($_FILES['photo']['tmp_name'], $_FILES['photo']['name'], $_FILES['photo']['type'], true, true)) {
$this->attachFile($photo);
// Now get some smaller thumbnails, with the option to override sizes
$sizes = \Idno\Core\site()->events()->dispatch('photo/thumbnail/getsizes', new \Idno\Core\Event(array('sizes' => array('large' => 800, 'medium' => 400, 'small' => 200))));
$eventdata = $sizes->data();
foreach ($eventdata['sizes'] as $label => $size) {
$filename = $_FILES['photo']['name'];
if ($thumbnail = \Idno\Entities\File::createThumbnailFromFile($_FILES['photo']['tmp_name'], "{$filename}_{$label}", $size, false)) {
$varname = "thumbnail_{$label}";
$this->$varname = \Idno\Core\site()->config()->url . 'file/' . $thumbnail;
$varname = "thumbnail_{$label}_id";
$this->$varname = substr($thumbnail, 0, strpos($thumbnail, '/'));
}
}
}
} else {
\Idno\Core\site()->session()->addErrorMessage('This doesn\'t seem to be an image ..');
}
}
}
if ($this->save($new)) {
$autosave = new Autosave();
$autosave->clearContext('review');
\Idno\Core\Webmention::pingMentions($this->getURL(), \Idno\Core\site()->template()->parseURLs($this->getTitle() . ' ' . $this->getDescription()));
return true;
}
} else {
\Idno\Core\site()->session()->addErrorMessage('You can\'t save an empty entry.');
}
return false;
}
function deleteData()
{
\Idno\Core\Webmention::pingMentions($this->getURL(), \Idno\Core\site()->template()->parseURLs($this->getTitle() . ' ' . $this->getDescription()));
}
}
}