|
1
|
|
|
<?php |
|
2
|
|
|
/* Copyright (C) NAVER <http://www.navercorp.com> */ |
|
3
|
|
|
/** |
|
4
|
|
|
* documentItem class |
|
5
|
|
|
* document object |
|
6
|
|
|
* |
|
7
|
|
|
* @author NAVER ([email protected]) |
|
8
|
|
|
* @package /modules/document |
|
9
|
|
|
* @version 0.1 |
|
10
|
|
|
*/ |
|
11
|
|
|
class documentItem extends BaseObject |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* Document number |
|
15
|
|
|
* @var int |
|
16
|
|
|
*/ |
|
17
|
|
|
var $document_srl = 0; |
|
18
|
|
|
/** |
|
19
|
|
|
* Language code |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
var $lang_code = null; |
|
23
|
|
|
/** |
|
24
|
|
|
* Grant cache |
|
25
|
|
|
* @var bool |
|
26
|
|
|
*/ |
|
27
|
|
|
var $grant_cache = null; |
|
28
|
|
|
/** |
|
29
|
|
|
* Status of allow trackback |
|
30
|
|
|
* @var bool |
|
31
|
|
|
*/ |
|
32
|
|
|
var $allow_trackback_status = null; |
|
33
|
|
|
/** |
|
34
|
|
|
* column list |
|
35
|
|
|
* @var array |
|
36
|
|
|
*/ |
|
37
|
|
|
var $columnList = array(); |
|
38
|
|
|
/** |
|
39
|
|
|
* allow script access list |
|
40
|
|
|
* @var array |
|
41
|
|
|
*/ |
|
42
|
|
|
var $allowscriptaccessList = array(); |
|
43
|
|
|
/** |
|
44
|
|
|
* allow script access key |
|
45
|
|
|
* @var int |
|
46
|
|
|
*/ |
|
47
|
|
|
var $allowscriptaccessKey = 0; |
|
48
|
|
|
/** |
|
49
|
|
|
* upload file list |
|
50
|
|
|
* @var array |
|
51
|
|
|
*/ |
|
52
|
|
|
var $uploadedFiles = array(); |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Constructor |
|
56
|
|
|
* @param int $document_srl |
|
57
|
|
|
* @param bool $load_extra_vars |
|
58
|
|
|
* @param array columnList |
|
59
|
|
|
* @return void |
|
60
|
|
|
*/ |
|
61
|
|
|
function documentItem($document_srl = 0, $load_extra_vars = true, $columnList = array()) |
|
|
|
|
|
|
62
|
|
|
{ |
|
63
|
|
|
$this->document_srl = $document_srl; |
|
64
|
|
|
$this->columnList = $columnList; |
|
65
|
|
|
|
|
66
|
|
|
$this->_loadFromDB($load_extra_vars); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
function setDocument($document_srl, $load_extra_vars = true) |
|
70
|
|
|
{ |
|
71
|
|
|
$this->document_srl = $document_srl; |
|
72
|
|
|
$this->_loadFromDB($load_extra_vars); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Get data from database, and set the value to documentItem object |
|
77
|
|
|
* @param bool $load_extra_vars |
|
78
|
|
|
* @return void |
|
79
|
|
|
*/ |
|
80
|
|
|
function _loadFromDB($load_extra_vars = true) |
|
81
|
|
|
{ |
|
82
|
|
|
if(!$this->document_srl) return; |
|
83
|
|
|
|
|
84
|
|
|
$document_item = false; |
|
85
|
|
|
$cache_put = false; |
|
|
|
|
|
|
86
|
|
|
$columnList = array(); |
|
87
|
|
|
$this->columnList = array(); |
|
88
|
|
|
|
|
89
|
|
|
// cache controll |
|
90
|
|
|
$oCacheHandler = CacheHandler::getInstance('object'); |
|
91
|
|
|
if($oCacheHandler->isSupport()) |
|
92
|
|
|
{ |
|
93
|
|
|
$cache_key = 'document_item:' . getNumberingPath($this->document_srl) . $this->document_srl; |
|
94
|
|
|
$document_item = $oCacheHandler->get($cache_key); |
|
95
|
|
|
if($document_item !== false) |
|
96
|
|
|
{ |
|
97
|
|
|
$columnList = array('readed_count', 'voted_count', 'blamed_count', 'comment_count', 'trackback_count'); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
$args = new stdClass(); |
|
102
|
|
|
$args->document_srl = $this->document_srl; |
|
103
|
|
|
$output = executeQuery('document.getDocument', $args, $columnList); |
|
104
|
|
|
|
|
105
|
|
|
if($document_item === false) |
|
106
|
|
|
{ |
|
107
|
|
|
$document_item = $output->data; |
|
108
|
|
|
|
|
109
|
|
|
//insert in cache |
|
110
|
|
|
if($document_item && $oCacheHandler->isSupport()) |
|
111
|
|
|
{ |
|
112
|
|
|
$oCacheHandler->put($cache_key, $document_item); |
|
|
|
|
|
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
else |
|
116
|
|
|
{ |
|
117
|
|
|
$document_item->readed_count = $output->data->readed_count; |
|
118
|
|
|
$document_item->voted_count = $output->data->voted_count; |
|
119
|
|
|
$document_item->blamed_count = $output->data->blamed_count; |
|
120
|
|
|
$document_item->comment_count = $output->data->comment_count; |
|
121
|
|
|
$document_item->trackback_count = $output->data->trackback_count; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
$this->setAttribute($document_item, $load_extra_vars); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
function setAttribute($attribute, $load_extra_vars=true) |
|
128
|
|
|
{ |
|
129
|
|
|
if(!$attribute->document_srl) |
|
130
|
|
|
{ |
|
131
|
|
|
$this->document_srl = null; |
|
132
|
|
|
return; |
|
133
|
|
|
} |
|
134
|
|
|
$this->document_srl = $attribute->document_srl; |
|
135
|
|
|
$this->lang_code = $attribute->lang_code; |
|
136
|
|
|
$this->adds($attribute); |
|
137
|
|
|
|
|
138
|
|
|
// Tags |
|
139
|
|
|
if($this->get('tags')) |
|
140
|
|
|
{ |
|
141
|
|
|
$tag_list = explode(',', $this->get('tags')); |
|
142
|
|
|
$tag_list = array_map('trim', $tag_list); |
|
143
|
|
|
$this->add('tag_list', $tag_list); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
$oDocumentModel = getModel('document'); |
|
147
|
|
|
if($load_extra_vars) |
|
148
|
|
|
{ |
|
149
|
|
|
$GLOBALS['XE_DOCUMENT_LIST'][$attribute->document_srl] = $this; |
|
150
|
|
|
$oDocumentModel->setToAllDocumentExtraVars(); |
|
151
|
|
|
} |
|
152
|
|
|
$GLOBALS['XE_DOCUMENT_LIST'][$this->document_srl] = $this; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
function isExists() |
|
156
|
|
|
{ |
|
157
|
|
|
return $this->document_srl ? true : false; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
function isGranted() |
|
161
|
|
|
{ |
|
162
|
|
|
if($_SESSION['own_document'][$this->document_srl]) return $this->grant_cache = true; |
|
163
|
|
|
|
|
164
|
|
|
if($this->grant_cache !== null) |
|
165
|
|
|
{ |
|
166
|
|
|
return $this->grant_cache; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
if(!Context::get('is_logged')) return $this->grant_cache = false; |
|
170
|
|
|
|
|
171
|
|
|
$logged_info = Context::get('logged_info'); |
|
172
|
|
|
if($logged_info->is_admin == 'Y') return $this->grant_cache = true; |
|
173
|
|
|
|
|
174
|
|
|
$oModuleModel = getModel('module'); |
|
175
|
|
|
$grant = $oModuleModel->getGrant($oModuleModel->getModuleInfoByModuleSrl($this->get('module_srl')), $logged_info); |
|
176
|
|
|
if($grant->manager) return $this->grant_cache = true; |
|
177
|
|
|
|
|
178
|
|
View Code Duplication |
if($this->get('member_srl') && ($this->get('member_srl') == $logged_info->member_srl || $this->get('member_srl')*-1 == $logged_info->member_srl)) return $this->grant_cache = true; |
|
179
|
|
|
|
|
180
|
|
|
return $this->grant_cache = false; |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
function setGrant() |
|
184
|
|
|
{ |
|
185
|
|
|
$_SESSION['own_document'][$this->document_srl] = true; |
|
186
|
|
|
$this->grant_cache = true; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
function isAccessible() |
|
190
|
|
|
{ |
|
191
|
|
|
return $_SESSION['accessible'][$this->document_srl]==true?true:false; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
function allowComment() |
|
195
|
|
|
{ |
|
196
|
|
|
// init write, document is not exists. so allow comment status is true |
|
197
|
|
|
if(!$this->isExists()) return true; |
|
198
|
|
|
|
|
199
|
|
|
return $this->get('comment_status') == 'ALLOW' ? true : false; |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
function allowTrackback() |
|
203
|
|
|
{ |
|
204
|
|
|
static $allow_trackback_status = null; |
|
205
|
|
|
if(is_null($allow_trackback_status)) |
|
206
|
|
|
{ |
|
207
|
|
|
|
|
208
|
|
|
// Check the tarckback module exist |
|
209
|
|
|
if(!getClass('trackback')) |
|
210
|
|
|
{ |
|
211
|
|
|
$allow_trackback_status = false; |
|
212
|
|
|
} |
|
213
|
|
|
else |
|
214
|
|
|
{ |
|
215
|
|
|
// If the trackback module is configured to be disabled, do not allow. Otherwise, check the setting of each module. |
|
216
|
|
|
$oModuleModel = getModel('module'); |
|
217
|
|
|
$trackback_config = $oModuleModel->getModuleConfig('trackback'); |
|
218
|
|
|
|
|
219
|
|
|
if(!$trackback_config) |
|
220
|
|
|
{ |
|
221
|
|
|
$trackback_config = new stdClass(); |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
if(!isset($trackback_config->enable_trackback)) $trackback_config->enable_trackback = 'Y'; |
|
225
|
|
|
if($trackback_config->enable_trackback != 'Y') $allow_trackback_status = false; |
|
226
|
|
|
else |
|
227
|
|
|
{ |
|
228
|
|
|
$module_srl = $this->get('module_srl'); |
|
229
|
|
|
// Check settings of each module |
|
230
|
|
|
$module_config = $oModuleModel->getModulePartConfig('trackback', $module_srl); |
|
231
|
|
|
if($module_config->enable_trackback == 'N') $allow_trackback_status = false; |
|
232
|
|
|
else if($this->get('allow_trackback')=='Y' || !$this->isExists()) $allow_trackback_status = true; |
|
233
|
|
|
} |
|
234
|
|
|
} |
|
235
|
|
|
} |
|
236
|
|
|
return $allow_trackback_status; |
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
function isLocked() |
|
240
|
|
|
{ |
|
241
|
|
|
if(!$this->isExists()) return false; |
|
242
|
|
|
|
|
243
|
|
|
return $this->get('comment_status') == 'ALLOW' ? false : true; |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
function isEditable() |
|
247
|
|
|
{ |
|
248
|
|
|
if($this->isGranted() || !$this->get('member_srl')) return true; |
|
249
|
|
|
return false; |
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
function isSecret() |
|
253
|
|
|
{ |
|
254
|
|
|
$oDocumentModel = getModel('document'); |
|
255
|
|
|
return $this->get('status') == $oDocumentModel->getConfigStatus('secret') ? true : false; |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
function isNotice() |
|
259
|
|
|
{ |
|
260
|
|
|
return $this->get('is_notice') == 'Y' ? true : false; |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
function useNotify() |
|
264
|
|
|
{ |
|
265
|
|
|
return $this->get('notify_message')=='Y' ? true : false; |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
function doCart() |
|
269
|
|
|
{ |
|
270
|
|
|
if(!$this->document_srl) return false; |
|
271
|
|
|
if($this->isCarted()) $this->removeCart(); |
|
272
|
|
|
else $this->addCart(); |
|
273
|
|
|
} |
|
274
|
|
|
|
|
275
|
|
|
function addCart() |
|
276
|
|
|
{ |
|
277
|
|
|
$_SESSION['document_management'][$this->document_srl] = true; |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
function removeCart() |
|
281
|
|
|
{ |
|
282
|
|
|
unset($_SESSION['document_management'][$this->document_srl]); |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
function isCarted() |
|
286
|
|
|
{ |
|
287
|
|
|
return $_SESSION['document_management'][$this->document_srl]; |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
/** |
|
291
|
|
|
* Send notify message to document owner |
|
292
|
|
|
* @param string $type |
|
293
|
|
|
* @param string $content |
|
294
|
|
|
* @return void |
|
295
|
|
|
*/ |
|
296
|
|
|
function notify($type, $content) |
|
297
|
|
|
{ |
|
298
|
|
|
if(!$this->document_srl) return; |
|
299
|
|
|
// return if it is not useNotify |
|
300
|
|
|
if(!$this->useNotify()) return; |
|
301
|
|
|
// Pass if an author is not a logged-in user |
|
302
|
|
|
if(!$this->get('member_srl')) return; |
|
303
|
|
|
// Return if the currently logged-in user is an author |
|
304
|
|
|
$logged_info = Context::get('logged_info'); |
|
305
|
|
|
if($logged_info->member_srl == $this->get('member_srl')) return; |
|
306
|
|
|
// List variables |
|
307
|
|
|
if($type) $title = "[".$type."] "; |
|
308
|
|
|
$title .= cut_str(strip_tags($content), 10, '...'); |
|
|
|
|
|
|
309
|
|
|
$content = sprintf('%s<br /><br />from : <a href="%s" target="_blank">%s</a>',$content, getFullUrl('','document_srl',$this->document_srl), getFullUrl('','document_srl',$this->document_srl)); |
|
310
|
|
|
$receiver_srl = $this->get('member_srl'); |
|
311
|
|
|
$sender_member_srl = $logged_info->member_srl; |
|
312
|
|
|
// Send a message |
|
313
|
|
|
$oCommunicationController = getController('communication'); |
|
314
|
|
|
$oCommunicationController->sendMessage($sender_member_srl, $receiver_srl, $title, $content, false); |
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
|
|
function getLangCode() |
|
318
|
|
|
{ |
|
319
|
|
|
return $this->get('lang_code'); |
|
320
|
|
|
} |
|
321
|
|
|
|
|
322
|
|
View Code Duplication |
function getIpAddress() |
|
|
|
|
|
|
323
|
|
|
{ |
|
324
|
|
|
if($this->isGranted()) |
|
325
|
|
|
{ |
|
326
|
|
|
return $this->get('ipaddress'); |
|
327
|
|
|
} |
|
328
|
|
|
|
|
329
|
|
|
return '*' . strstr($this->get('ipaddress'), '.'); |
|
330
|
|
|
} |
|
331
|
|
|
|
|
332
|
|
|
function isExistsHomepage() |
|
333
|
|
|
{ |
|
334
|
|
|
if(trim($this->get('homepage'))) return true; |
|
335
|
|
|
return false; |
|
336
|
|
|
} |
|
337
|
|
|
|
|
338
|
|
|
function getHomepageUrl() |
|
339
|
|
|
{ |
|
340
|
|
|
$url = trim($this->get('homepage')); |
|
341
|
|
|
if(!$url) return; |
|
342
|
|
|
|
|
343
|
|
View Code Duplication |
if(strncasecmp('http://', $url, 7) !== 0 && strncasecmp('https://', $url, 8) !== 0) $url = 'http://' . $url; |
|
344
|
|
|
|
|
345
|
|
|
return $url; |
|
346
|
|
|
} |
|
347
|
|
|
|
|
348
|
|
|
function getMemberSrl() |
|
349
|
|
|
{ |
|
350
|
|
|
return $this->get('member_srl'); |
|
351
|
|
|
} |
|
352
|
|
|
|
|
353
|
|
|
function getUserID() |
|
354
|
|
|
{ |
|
355
|
|
|
return htmlspecialchars($this->get('user_id'), ENT_COMPAT | ENT_HTML401, 'UTF-8', false); |
|
356
|
|
|
} |
|
357
|
|
|
|
|
358
|
|
|
function getUserName() |
|
359
|
|
|
{ |
|
360
|
|
|
return htmlspecialchars($this->get('user_name'), ENT_COMPAT | ENT_HTML401, 'UTF-8', false); |
|
361
|
|
|
} |
|
362
|
|
|
|
|
363
|
|
|
function getNickName() |
|
364
|
|
|
{ |
|
365
|
|
|
return htmlspecialchars($this->get('nick_name'), ENT_COMPAT | ENT_HTML401, 'UTF-8', false); |
|
366
|
|
|
} |
|
367
|
|
|
|
|
368
|
|
|
function getLastUpdater() |
|
369
|
|
|
{ |
|
370
|
|
|
return htmlspecialchars($this->get('last_updater'), ENT_COMPAT | ENT_HTML401, 'UTF-8', false); |
|
371
|
|
|
} |
|
372
|
|
|
|
|
373
|
|
|
function getTitleText($cut_size = 0, $tail='...') |
|
374
|
|
|
{ |
|
375
|
|
|
if(!$this->document_srl) return; |
|
376
|
|
|
|
|
377
|
|
|
if($cut_size) $title = cut_str($this->get('title'), $cut_size, $tail); |
|
378
|
|
|
else $title = $this->get('title'); |
|
379
|
|
|
|
|
380
|
|
|
return $title; |
|
381
|
|
|
} |
|
382
|
|
|
|
|
383
|
|
|
function getTitle($cut_size = 0, $tail='...') |
|
384
|
|
|
{ |
|
385
|
|
|
if(!$this->document_srl) return; |
|
386
|
|
|
|
|
387
|
|
|
$title = $this->getTitleText($cut_size, $tail); |
|
388
|
|
|
|
|
389
|
|
|
$attrs = array(); |
|
390
|
|
|
$this->add('title_color', trim($this->get('title_color'))); |
|
391
|
|
|
if($this->get('title_bold')=='Y') $attrs[] = "font-weight:bold;"; |
|
392
|
|
View Code Duplication |
if($this->get('title_color') && $this->get('title_color') != 'N') $attrs[] = "color:#".$this->get('title_color'); |
|
393
|
|
|
|
|
394
|
|
|
if(count($attrs)) return sprintf("<span style=\"%s\">%s</span>", implode(';',$attrs), htmlspecialchars($title, ENT_COMPAT | ENT_HTML401, 'UTF-8', false)); |
|
395
|
|
|
else return htmlspecialchars($title, ENT_COMPAT | ENT_HTML401, 'UTF-8', false); |
|
396
|
|
|
} |
|
397
|
|
|
|
|
398
|
|
|
function getContentText($strlen = 0) |
|
399
|
|
|
{ |
|
400
|
|
|
if(!$this->document_srl) return; |
|
401
|
|
|
|
|
402
|
|
|
if($this->isSecret() && !$this->isGranted() && !$this->isAccessible()) return Context::getLang('msg_is_secret'); |
|
403
|
|
|
|
|
404
|
|
|
$result = $this->_checkAccessibleFromStatus(); |
|
405
|
|
|
if($result) $_SESSION['accessible'][$this->document_srl] = true; |
|
406
|
|
|
|
|
407
|
|
|
$content = $this->get('content'); |
|
408
|
|
|
$content = preg_replace_callback('/<(object|param|embed)[^>]*/is', array($this, '_checkAllowScriptAccess'), $content); |
|
409
|
|
|
$content = preg_replace_callback('/<object[^>]*>/is', array($this, '_addAllowScriptAccess'), $content); |
|
410
|
|
|
|
|
411
|
|
|
if($strlen) return cut_str(strip_tags($content),$strlen,'...'); |
|
412
|
|
|
|
|
413
|
|
|
return htmlspecialchars($content); |
|
414
|
|
|
} |
|
415
|
|
|
|
|
416
|
|
View Code Duplication |
function _addAllowScriptAccess($m) |
|
|
|
|
|
|
417
|
|
|
{ |
|
418
|
|
|
if($this->allowscriptaccessList[$this->allowscriptaccessKey] == 1) |
|
419
|
|
|
{ |
|
420
|
|
|
$m[0] = $m[0].'<param name="allowscriptaccess" value="never"></param>'; |
|
421
|
|
|
} |
|
422
|
|
|
$this->allowscriptaccessKey++; |
|
423
|
|
|
return $m[0]; |
|
424
|
|
|
} |
|
425
|
|
|
|
|
426
|
|
View Code Duplication |
function _checkAllowScriptAccess($m) |
|
|
|
|
|
|
427
|
|
|
{ |
|
428
|
|
|
if($m[1] == 'object') |
|
429
|
|
|
{ |
|
430
|
|
|
$this->allowscriptaccessList[] = 1; |
|
431
|
|
|
} |
|
432
|
|
|
|
|
433
|
|
|
if($m[1] == 'param') |
|
434
|
|
|
{ |
|
435
|
|
|
if(stripos($m[0], 'allowscriptaccess')) |
|
436
|
|
|
{ |
|
437
|
|
|
$m[0] = '<param name="allowscriptaccess" value="never"'; |
|
438
|
|
|
if(substr($m[0], -1) == '/') |
|
439
|
|
|
{ |
|
440
|
|
|
$m[0] .= '/'; |
|
441
|
|
|
} |
|
442
|
|
|
$this->allowscriptaccessList[count($this->allowscriptaccessList)-1]--; |
|
443
|
|
|
} |
|
444
|
|
|
} |
|
445
|
|
|
else if($m[1] == 'embed') |
|
446
|
|
|
{ |
|
447
|
|
|
if(stripos($m[0], 'allowscriptaccess')) |
|
448
|
|
|
{ |
|
449
|
|
|
$m[0] = preg_replace('/always|samedomain/i', 'never', $m[0]); |
|
450
|
|
|
} |
|
451
|
|
|
else |
|
452
|
|
|
{ |
|
453
|
|
|
$m[0] = preg_replace('/\<embed/i', '<embed allowscriptaccess="never"', $m[0]); |
|
454
|
|
|
} |
|
455
|
|
|
} |
|
456
|
|
|
return $m[0]; |
|
457
|
|
|
} |
|
458
|
|
|
|
|
459
|
|
|
function getContent($add_popup_menu = true, $add_content_info = true, $resource_realpath = false, $add_xe_content_class = true, $stripEmbedTagException = false) |
|
460
|
|
|
{ |
|
461
|
|
|
if(!$this->document_srl) return; |
|
462
|
|
|
|
|
463
|
|
|
if($this->isSecret() && !$this->isGranted() && !$this->isAccessible()) return Context::getLang('msg_is_secret'); |
|
464
|
|
|
|
|
465
|
|
|
$result = $this->_checkAccessibleFromStatus(); |
|
466
|
|
|
if($result) $_SESSION['accessible'][$this->document_srl] = true; |
|
467
|
|
|
|
|
468
|
|
|
$content = $this->get('content'); |
|
469
|
|
|
if(!$stripEmbedTagException) stripEmbedTagForAdmin($content, $this->get('member_srl')); |
|
470
|
|
|
|
|
471
|
|
|
// Define a link if using a rewrite module |
|
472
|
|
|
$oContext = &Context::getInstance(); |
|
473
|
|
|
if($oContext->allow_rewrite) |
|
474
|
|
|
{ |
|
475
|
|
|
$content = preg_replace('/<a([ \t]+)href=("|\')\.\/\?/i',"<a href=\\2". Context::getRequestUri() ."?", $content); |
|
476
|
|
|
} |
|
477
|
|
|
// To display a pop-up menu |
|
478
|
|
|
if($add_popup_menu) |
|
479
|
|
|
{ |
|
480
|
|
|
$content = sprintf( |
|
481
|
|
|
'%s<div class="document_popup_menu"><a href="#popup_menu_area" class="document_%d" onclick="return false">%s</a></div>', |
|
482
|
|
|
$content, |
|
483
|
|
|
$this->document_srl, Context::getLang('cmd_document_do') |
|
484
|
|
|
); |
|
485
|
|
|
} |
|
486
|
|
|
// If additional content information is set |
|
487
|
|
View Code Duplication |
if($add_content_info) |
|
488
|
|
|
{ |
|
489
|
|
|
$memberSrl = $this->get('member_srl'); |
|
490
|
|
|
if($memberSrl < 0) |
|
491
|
|
|
{ |
|
492
|
|
|
$memberSrl = 0; |
|
493
|
|
|
} |
|
494
|
|
|
$content = sprintf( |
|
495
|
|
|
'<!--BeforeDocument(%d,%d)--><div class="document_%d_%d xe_content">%s</div><!--AfterDocument(%d,%d)-->', |
|
496
|
|
|
$this->document_srl, $memberSrl, |
|
497
|
|
|
$this->document_srl, $memberSrl, |
|
498
|
|
|
$content, |
|
499
|
|
|
$this->document_srl, $memberSrl, |
|
500
|
|
|
$this->document_srl, $memberSrl |
|
501
|
|
|
); |
|
502
|
|
|
// Add xe_content class although accessing content is not required |
|
503
|
|
|
} |
|
504
|
|
|
else |
|
505
|
|
|
{ |
|
506
|
|
|
if($add_xe_content_class) $content = sprintf('<div class="xe_content">%s</div>', $content); |
|
507
|
|
|
} |
|
508
|
|
|
// Change the image path to a valid absolute path if resource_realpath is true |
|
509
|
|
|
if($resource_realpath) |
|
510
|
|
|
{ |
|
511
|
|
|
$content = preg_replace_callback('/<img([^>]+)>/i',array($this,'replaceResourceRealPath'), $content); |
|
512
|
|
|
} |
|
513
|
|
|
|
|
514
|
|
|
return $content; |
|
515
|
|
|
} |
|
516
|
|
|
|
|
517
|
|
|
/** |
|
518
|
|
|
* Return transformed content by Editor codes |
|
519
|
|
|
* @param bool $add_popup_menu |
|
520
|
|
|
* @param bool $add_content_info |
|
521
|
|
|
* @param bool $resource_realpath |
|
522
|
|
|
* @param bool $add_xe_content_class |
|
523
|
|
|
* @return string |
|
524
|
|
|
*/ |
|
525
|
|
|
function getTransContent($add_popup_menu = true, $add_content_info = true, $resource_realpath = false, $add_xe_content_class = true) |
|
526
|
|
|
{ |
|
527
|
|
|
$oEditorController = getController('editor'); |
|
528
|
|
|
|
|
529
|
|
|
$content = $this->getContent($add_popup_menu, $add_content_info, $resource_realpath, $add_xe_content_class); |
|
530
|
|
|
$content = $oEditorController->transComponent($content); |
|
531
|
|
|
|
|
532
|
|
|
return $content; |
|
533
|
|
|
} |
|
534
|
|
|
|
|
535
|
|
View Code Duplication |
function getSummary($str_size = 50, $tail = '...') |
|
|
|
|
|
|
536
|
|
|
{ |
|
537
|
|
|
$content = $this->getContent(FALSE, FALSE); |
|
538
|
|
|
|
|
539
|
|
|
$content = nl2br($content); |
|
540
|
|
|
|
|
541
|
|
|
// For a newlink, inert a whitespace |
|
542
|
|
|
$content = preg_replace('!(<br[\s]*/{0,1}>[\s]*)+!is', ' ', $content); |
|
543
|
|
|
|
|
544
|
|
|
// Replace tags such as </p> , </div> , </li> and others to a whitespace |
|
545
|
|
|
$content = str_replace(array('</p>', '</div>', '</li>', '-->'), ' ', $content); |
|
546
|
|
|
|
|
547
|
|
|
// Remove Tags |
|
548
|
|
|
$content = preg_replace('!<([^>]*?)>!is', '', $content); |
|
549
|
|
|
|
|
550
|
|
|
// Replace < , >, " |
|
551
|
|
|
$content = str_replace(array('<', '>', '"', ' '), array('<', '>', '"', ' '), $content); |
|
552
|
|
|
|
|
553
|
|
|
// Delete a series of whitespaces |
|
554
|
|
|
$content = preg_replace('/ ( +)/is', ' ', $content); |
|
555
|
|
|
|
|
556
|
|
|
// Truncate string |
|
557
|
|
|
$content = trim(cut_str($content, $str_size, $tail)); |
|
558
|
|
|
|
|
559
|
|
|
// Replace back < , <, " |
|
560
|
|
|
$content = str_replace(array('<', '>', '"'),array('<', '>', '"'), $content); |
|
561
|
|
|
|
|
562
|
|
|
return $content; |
|
563
|
|
|
} |
|
564
|
|
|
|
|
565
|
|
|
function getRegdate($format = 'Y.m.d H:i:s') |
|
566
|
|
|
{ |
|
567
|
|
|
return zdate($this->get('regdate'), $format); |
|
568
|
|
|
} |
|
569
|
|
|
|
|
570
|
|
View Code Duplication |
function getRegdateTime() |
|
|
|
|
|
|
571
|
|
|
{ |
|
572
|
|
|
$regdate = $this->get('regdate'); |
|
573
|
|
|
$year = substr($regdate,0,4); |
|
574
|
|
|
$month = substr($regdate,4,2); |
|
575
|
|
|
$day = substr($regdate,6,2); |
|
576
|
|
|
$hour = substr($regdate,8,2); |
|
577
|
|
|
$min = substr($regdate,10,2); |
|
578
|
|
|
$sec = substr($regdate,12,2); |
|
579
|
|
|
return mktime($hour,$min,$sec,$month,$day,$year); |
|
580
|
|
|
} |
|
581
|
|
|
|
|
582
|
|
|
function getRegdateGM() |
|
583
|
|
|
{ |
|
584
|
|
|
return $this->getRegdate('D, d M Y H:i:s').' '.$GLOBALS['_time_zone']; |
|
585
|
|
|
} |
|
586
|
|
|
|
|
587
|
|
|
function getRegdateDT() |
|
588
|
|
|
{ |
|
589
|
|
|
return $this->getRegdate('Y-m-d').'T'.$this->getRegdate('H:i:s').substr($GLOBALS['_time_zone'],0,3).':'.substr($GLOBALS['_time_zone'],3,2); |
|
590
|
|
|
} |
|
591
|
|
|
|
|
592
|
|
|
function getUpdate($format = 'Y.m.d H:i:s') |
|
593
|
|
|
{ |
|
594
|
|
|
return zdate($this->get('last_update'), $format); |
|
595
|
|
|
} |
|
596
|
|
|
|
|
597
|
|
View Code Duplication |
function getUpdateTime() |
|
|
|
|
|
|
598
|
|
|
{ |
|
599
|
|
|
$year = substr($this->get('last_update'),0,4); |
|
600
|
|
|
$month = substr($this->get('last_update'),4,2); |
|
601
|
|
|
$day = substr($this->get('last_update'),6,2); |
|
602
|
|
|
$hour = substr($this->get('last_update'),8,2); |
|
603
|
|
|
$min = substr($this->get('last_update'),10,2); |
|
604
|
|
|
$sec = substr($this->get('last_update'),12,2); |
|
605
|
|
|
return mktime($hour,$min,$sec,$month,$day,$year); |
|
606
|
|
|
} |
|
607
|
|
|
|
|
608
|
|
|
function getUpdateGM() |
|
609
|
|
|
{ |
|
610
|
|
|
return gmdate("D, d M Y H:i:s", $this->getUpdateTime()); |
|
611
|
|
|
} |
|
612
|
|
|
|
|
613
|
|
|
function getUpdateDT() |
|
614
|
|
|
{ |
|
615
|
|
|
return $this->getUpdate('Y-m-d').'T'.$this->getUpdate('H:i:s').substr($GLOBALS['_time_zone'],0,3).':'.substr($GLOBALS['_time_zone'],3,2); |
|
616
|
|
|
} |
|
617
|
|
|
|
|
618
|
|
|
function getPermanentUrl() |
|
619
|
|
|
{ |
|
620
|
|
|
return getFullUrl('','mid', $this->getDocumentMid('document_srl'), 'document_srl', $this->get('document_srl')); |
|
|
|
|
|
|
621
|
|
|
} |
|
622
|
|
|
|
|
623
|
|
|
function getTrackbackUrl() |
|
624
|
|
|
{ |
|
625
|
|
|
if(!$this->document_srl) return; |
|
626
|
|
|
|
|
627
|
|
|
// Generate a key to prevent spams |
|
628
|
|
|
$oTrackbackModel = getModel('trackback'); |
|
629
|
|
|
if($oTrackbackModel) return $oTrackbackModel->getTrackbackUrl($this->document_srl, $this->getDocumentMid()); |
|
|
|
|
|
|
630
|
|
|
} |
|
631
|
|
|
|
|
632
|
|
|
/** |
|
633
|
|
|
* Update readed count |
|
634
|
|
|
* @return void |
|
635
|
|
|
*/ |
|
636
|
|
|
function updateReadedCount() |
|
637
|
|
|
{ |
|
638
|
|
|
$oDocumentController = getController('document'); |
|
639
|
|
|
if($oDocumentController->updateReadedCount($this)) |
|
640
|
|
|
{ |
|
641
|
|
|
$readed_count = $this->get('readed_count'); |
|
642
|
|
|
$this->add('readed_count', $readed_count+1); |
|
643
|
|
|
} |
|
644
|
|
|
} |
|
645
|
|
|
|
|
646
|
|
|
function isExtraVarsExists() |
|
647
|
|
|
{ |
|
648
|
|
|
if(!$this->get('module_srl')) return false; |
|
649
|
|
|
$oDocumentModel = getModel('document'); |
|
650
|
|
|
$extra_keys = $oDocumentModel->getExtraKeys($this->get('module_srl')); |
|
651
|
|
|
return count($extra_keys)?true:false; |
|
652
|
|
|
} |
|
653
|
|
|
|
|
654
|
|
|
function getExtraVars() |
|
655
|
|
|
{ |
|
656
|
|
|
if(!$this->get('module_srl') || !$this->document_srl) return null; |
|
657
|
|
|
|
|
658
|
|
|
$oDocumentModel = getModel('document'); |
|
659
|
|
|
return $oDocumentModel->getExtraVars($this->get('module_srl'), $this->document_srl); |
|
660
|
|
|
} |
|
661
|
|
|
|
|
662
|
|
View Code Duplication |
function getExtraValue($idx) |
|
|
|
|
|
|
663
|
|
|
{ |
|
664
|
|
|
$extra_vars = $this->getExtraVars(); |
|
665
|
|
|
if(is_array($extra_vars) && array_key_exists($idx,$extra_vars)) |
|
666
|
|
|
{ |
|
667
|
|
|
return $extra_vars[$idx]->getValue(); |
|
668
|
|
|
} |
|
669
|
|
|
else |
|
670
|
|
|
{ |
|
671
|
|
|
return ''; |
|
672
|
|
|
} |
|
673
|
|
|
} |
|
674
|
|
|
|
|
675
|
|
View Code Duplication |
function getExtraValueHTML($idx) |
|
|
|
|
|
|
676
|
|
|
{ |
|
677
|
|
|
$extra_vars = $this->getExtraVars(); |
|
678
|
|
|
if(is_array($extra_vars) && array_key_exists($idx,$extra_vars)) |
|
679
|
|
|
{ |
|
680
|
|
|
return $extra_vars[$idx]->getValueHTML(); |
|
681
|
|
|
} |
|
682
|
|
|
else |
|
683
|
|
|
{ |
|
684
|
|
|
return ''; |
|
685
|
|
|
} |
|
686
|
|
|
} |
|
687
|
|
|
|
|
688
|
|
View Code Duplication |
function getExtraEidValue($eid) |
|
|
|
|
|
|
689
|
|
|
{ |
|
690
|
|
|
$extra_vars = $this->getExtraVars(); |
|
691
|
|
|
|
|
692
|
|
|
if($extra_vars) |
|
693
|
|
|
{ |
|
694
|
|
|
// Handle extra variable(eid) |
|
695
|
|
|
foreach($extra_vars as $idx => $key) |
|
696
|
|
|
{ |
|
697
|
|
|
$extra_eid[$key->eid] = $key; |
|
|
|
|
|
|
698
|
|
|
} |
|
699
|
|
|
} |
|
700
|
|
|
|
|
701
|
|
|
if(is_array($extra_eid) && array_key_exists($eid,$extra_eid)) |
|
702
|
|
|
{ |
|
703
|
|
|
return $extra_eid[$eid]->getValue(); |
|
|
|
|
|
|
704
|
|
|
} |
|
705
|
|
|
else |
|
706
|
|
|
{ |
|
707
|
|
|
return ''; |
|
708
|
|
|
} |
|
709
|
|
|
} |
|
710
|
|
|
|
|
711
|
|
View Code Duplication |
function getExtraEidValueHTML($eid) |
|
|
|
|
|
|
712
|
|
|
{ |
|
713
|
|
|
$extra_vars = $this->getExtraVars(); |
|
714
|
|
|
// Handle extra variable(eid) |
|
715
|
|
|
foreach($extra_vars as $idx => $key) |
|
716
|
|
|
{ |
|
717
|
|
|
$extra_eid[$key->eid] = $key; |
|
|
|
|
|
|
718
|
|
|
} |
|
719
|
|
|
|
|
720
|
|
|
if(is_array($extra_eid) && array_key_exists($eid,$extra_eid)) |
|
721
|
|
|
{ |
|
722
|
|
|
return $extra_eid[$eid]->getValueHTML(); |
|
|
|
|
|
|
723
|
|
|
} |
|
724
|
|
|
else |
|
725
|
|
|
{ |
|
726
|
|
|
return ''; |
|
727
|
|
|
} |
|
728
|
|
|
} |
|
729
|
|
|
|
|
730
|
|
|
function getExtraVarsValue($key) |
|
731
|
|
|
{ |
|
732
|
|
|
$extra_vals = unserialize($this->get('extra_vars')); |
|
733
|
|
|
$val = $extra_vals->$key; |
|
734
|
|
|
return $val; |
|
735
|
|
|
} |
|
736
|
|
|
|
|
737
|
|
|
function getCommentCount() |
|
738
|
|
|
{ |
|
739
|
|
|
return $this->get('comment_count'); |
|
740
|
|
|
} |
|
741
|
|
|
|
|
742
|
|
|
function getComments() |
|
743
|
|
|
{ |
|
744
|
|
|
if(!$this->getCommentCount()) return; |
|
745
|
|
|
if(!$this->isGranted() && $this->isSecret()) return; |
|
746
|
|
|
// cpage is a number of comment pages |
|
747
|
|
|
$cpageStr = sprintf('%d_cpage', $this->document_srl); |
|
748
|
|
|
$cpage = Context::get($cpageStr); |
|
749
|
|
|
|
|
750
|
|
|
if(!$cpage) |
|
751
|
|
|
{ |
|
752
|
|
|
$cpage = Context::get('cpage'); |
|
753
|
|
|
} |
|
754
|
|
|
|
|
755
|
|
|
// Get a list of comments |
|
756
|
|
|
$oCommentModel = getModel('comment'); |
|
757
|
|
|
$output = $oCommentModel->getCommentList($this->document_srl, $cpage, $is_admin); |
|
|
|
|
|
|
758
|
|
|
if(!$output->toBool() || !count($output->data)) return; |
|
759
|
|
|
// Create commentItem object from a comment list |
|
760
|
|
|
// If admin priviledge is granted on parent posts, you can read its child posts. |
|
761
|
|
|
$accessible = array(); |
|
762
|
|
|
$comment_list = array(); |
|
763
|
|
|
foreach($output->data as $key => $val) |
|
764
|
|
|
{ |
|
765
|
|
|
$oCommentItem = new commentItem(); |
|
766
|
|
|
$oCommentItem->setAttribute($val); |
|
767
|
|
|
// If permission is granted to the post, you can access it temporarily |
|
768
|
|
|
if($oCommentItem->isGranted()) $accessible[$val->comment_srl] = true; |
|
769
|
|
|
// If the comment is set to private and it belongs child post, it is allowable to read the comment for who has a admin privilege on its parent post |
|
770
|
|
|
if($val->parent_srl>0 && $val->is_secret == 'Y' && !$oCommentItem->isAccessible() && $accessible[$val->parent_srl]===true) |
|
771
|
|
|
{ |
|
772
|
|
|
$oCommentItem->setAccessible(); |
|
773
|
|
|
} |
|
774
|
|
|
$comment_list[$val->comment_srl] = $oCommentItem; |
|
775
|
|
|
} |
|
776
|
|
|
// Variable setting to be displayed on the skin |
|
777
|
|
|
Context::set($cpageStr, $output->page_navigation->cur_page); |
|
778
|
|
|
Context::set('cpage', $output->page_navigation->cur_page); |
|
779
|
|
|
if($output->total_page>1) $this->comment_page_navigation = $output->page_navigation; |
|
|
|
|
|
|
780
|
|
|
|
|
781
|
|
|
return $comment_list; |
|
782
|
|
|
} |
|
783
|
|
|
|
|
784
|
|
|
function getTrackbackCount() |
|
785
|
|
|
{ |
|
786
|
|
|
return $this->get('trackback_count'); |
|
787
|
|
|
} |
|
788
|
|
|
|
|
789
|
|
|
function getTrackbacks() |
|
790
|
|
|
{ |
|
791
|
|
|
if(!$this->document_srl) return; |
|
792
|
|
|
|
|
793
|
|
|
if(!$this->allowTrackback() || !$this->get('trackback_count')) return; |
|
|
|
|
|
|
794
|
|
|
|
|
795
|
|
|
$oTrackbackModel = getModel('trackback'); |
|
796
|
|
|
return $oTrackbackModel->getTrackbackList($this->document_srl, $is_admin); |
|
|
|
|
|
|
797
|
|
|
} |
|
798
|
|
|
|
|
799
|
|
|
function thumbnailExists($width = 80, $height = 0, $type = '') |
|
800
|
|
|
{ |
|
801
|
|
|
if(!$this->document_srl) return false; |
|
802
|
|
|
if(!$this->getThumbnail($width, $height, $type)) return false; |
|
803
|
|
|
return true; |
|
804
|
|
|
} |
|
805
|
|
|
|
|
806
|
|
|
function getThumbnail($width = 80, $height = 0, $thumbnail_type = '') |
|
807
|
|
|
{ |
|
808
|
|
|
// Return false if the document doesn't exist |
|
809
|
|
|
if(!$this->document_srl) return; |
|
810
|
|
|
|
|
811
|
|
|
if($this->isSecret() && !$this->isGranted()) |
|
812
|
|
|
{ |
|
813
|
|
|
return; |
|
814
|
|
|
} |
|
815
|
|
|
|
|
816
|
|
|
// If not specify its height, create a square |
|
817
|
|
|
if(!$height) $height = $width; |
|
818
|
|
|
|
|
819
|
|
|
// Return false if neither attachement nor image files in the document |
|
820
|
|
|
$content = $this->get('content'); |
|
821
|
|
View Code Duplication |
if(!$this->get('uploaded_count')) |
|
822
|
|
|
{ |
|
823
|
|
|
if(!$content) |
|
824
|
|
|
{ |
|
825
|
|
|
$args = new stdClass(); |
|
826
|
|
|
$args->document_srl = $this->document_srl; |
|
827
|
|
|
$output = executeQuery('document.getDocument', $args, array('content')); |
|
828
|
|
|
if($output->toBool() && $output->data) |
|
829
|
|
|
{ |
|
830
|
|
|
$content = $output->data->content; |
|
831
|
|
|
$this->add('content', $content); |
|
832
|
|
|
} |
|
833
|
|
|
} |
|
834
|
|
|
|
|
835
|
|
|
if(!preg_match("!<img!is", $content)) return; |
|
836
|
|
|
} |
|
837
|
|
|
// Get thumbnai_type information from document module's configuration |
|
838
|
|
|
if(!in_array($thumbnail_type, array('crop','ratio'))) |
|
839
|
|
|
{ |
|
840
|
|
|
$config = $GLOBALS['__document_config__']; |
|
841
|
|
|
if(!$config) |
|
842
|
|
|
{ |
|
843
|
|
|
$oDocumentModel = getModel('document'); |
|
844
|
|
|
$config = $oDocumentModel->getDocumentConfig(); |
|
845
|
|
|
$GLOBALS['__document_config__'] = $config; |
|
846
|
|
|
} |
|
847
|
|
|
$thumbnail_type = $config->thumbnail_type; |
|
848
|
|
|
} |
|
849
|
|
|
|
|
850
|
|
|
// Define thumbnail information |
|
851
|
|
|
$thumbnail_path = sprintf('files/thumbnails/%s',getNumberingPath($this->document_srl, 3)); |
|
852
|
|
|
$thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type); |
|
853
|
|
|
$thumbnail_lockfile = sprintf('%s%dx%d.%s.lock', $thumbnail_path, $width, $height, $thumbnail_type); |
|
854
|
|
|
$thumbnail_url = Context::getRequestUri().$thumbnail_file; |
|
855
|
|
|
|
|
856
|
|
|
// Return false if thumbnail file exists and its size is 0. Otherwise, return its path |
|
857
|
|
View Code Duplication |
if(file_exists($thumbnail_file) || file_exists($thumbnail_lockfile)) |
|
858
|
|
|
{ |
|
859
|
|
|
if(filesize($thumbnail_file) < 1) |
|
860
|
|
|
{ |
|
861
|
|
|
return FALSE; |
|
862
|
|
|
} |
|
863
|
|
|
else |
|
864
|
|
|
{ |
|
865
|
|
|
return $thumbnail_url; |
|
866
|
|
|
} |
|
867
|
|
|
} |
|
868
|
|
|
|
|
869
|
|
|
// Create lockfile to prevent race condition |
|
870
|
|
|
FileHandler::writeFile($thumbnail_lockfile, '', 'w'); |
|
871
|
|
|
|
|
872
|
|
|
// Target File |
|
873
|
|
|
$source_file = null; |
|
874
|
|
|
$is_tmp_file = false; |
|
|
|
|
|
|
875
|
|
|
|
|
876
|
|
|
// Find an iamge file among attached files if exists |
|
877
|
|
View Code Duplication |
if($this->hasUploadedFiles()) |
|
878
|
|
|
{ |
|
879
|
|
|
$file_list = $this->getUploadedFiles(); |
|
880
|
|
|
|
|
881
|
|
|
$first_image = null; |
|
882
|
|
|
foreach($file_list as $file) |
|
883
|
|
|
{ |
|
884
|
|
|
if($file->direct_download !== 'Y') continue; |
|
885
|
|
|
|
|
886
|
|
|
if($file->cover_image === 'Y' && file_exists($file->uploaded_filename)) |
|
887
|
|
|
{ |
|
888
|
|
|
$source_file = $file->uploaded_filename; |
|
889
|
|
|
break; |
|
890
|
|
|
} |
|
891
|
|
|
|
|
892
|
|
|
if($first_image) continue; |
|
893
|
|
|
|
|
894
|
|
|
if(preg_match("/\.(jpe?g|png|gif|bmp)$/i", $file->source_filename)) |
|
895
|
|
|
{ |
|
896
|
|
|
if(file_exists($file->uploaded_filename)) |
|
897
|
|
|
{ |
|
898
|
|
|
$first_image = $file->uploaded_filename; |
|
899
|
|
|
} |
|
900
|
|
|
} |
|
901
|
|
|
} |
|
902
|
|
|
|
|
903
|
|
|
if(!$source_file && $first_image) |
|
904
|
|
|
{ |
|
905
|
|
|
$source_file = $first_image; |
|
906
|
|
|
} |
|
907
|
|
|
} |
|
908
|
|
|
// If not exists, file an image file from the content |
|
909
|
|
|
$is_tmp_file = false; |
|
910
|
|
View Code Duplication |
if(!$source_file) |
|
911
|
|
|
{ |
|
912
|
|
|
$random = new Password(); |
|
913
|
|
|
|
|
914
|
|
|
preg_match_all("!<img[^>]*src=(?:\"|\')([^\"\']*?)(?:\"|\')!is", $content, $matches, PREG_SET_ORDER); |
|
915
|
|
|
|
|
916
|
|
|
foreach($matches as $target_image) |
|
|
|
|
|
|
917
|
|
|
{ |
|
918
|
|
|
$target_src = trim($target_image[1]); |
|
919
|
|
|
if(preg_match('/\/(common|modules|widgets|addons|layouts|m\.layouts)\//i', $target_src)) continue; |
|
920
|
|
|
|
|
921
|
|
|
if(!preg_match('/^(http|https):\/\//i',$target_src)) |
|
922
|
|
|
{ |
|
923
|
|
|
$target_src = Context::getRequestUri().$target_src; |
|
924
|
|
|
} |
|
925
|
|
|
|
|
926
|
|
|
$target_src = htmlspecialchars_decode($target_src); |
|
927
|
|
|
|
|
928
|
|
|
$tmp_file = _XE_PATH_ . 'files/cache/tmp/' . $random->createSecureSalt(32, 'hex'); |
|
929
|
|
|
FileHandler::getRemoteFile($target_src, $tmp_file); |
|
930
|
|
|
if(!file_exists($tmp_file)) continue; |
|
931
|
|
|
|
|
932
|
|
|
$imageinfo = getimagesize($tmp_file); |
|
933
|
|
|
list($_w, $_h) = $imageinfo; |
|
934
|
|
|
if($imageinfo === false || ($_w < ($width * 0.3) && $_h < ($height * 0.3))) { |
|
935
|
|
|
FileHandler::removeFile($tmp_file); |
|
936
|
|
|
continue; |
|
937
|
|
|
} |
|
938
|
|
|
|
|
939
|
|
|
$source_file = $tmp_file; |
|
940
|
|
|
$is_tmp_file = true; |
|
941
|
|
|
break; |
|
942
|
|
|
} |
|
943
|
|
|
} |
|
944
|
|
|
|
|
945
|
|
|
if($source_file) |
|
946
|
|
|
{ |
|
947
|
|
|
$output_file = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, 'jpg', $thumbnail_type); |
|
948
|
|
|
} |
|
949
|
|
|
|
|
950
|
|
|
// Remove source file if it was temporary |
|
951
|
|
|
if($is_tmp_file) |
|
952
|
|
|
{ |
|
953
|
|
|
FileHandler::removeFile($source_file); |
|
954
|
|
|
} |
|
955
|
|
|
|
|
956
|
|
|
// Remove lockfile |
|
957
|
|
|
FileHandler::removeFile($thumbnail_lockfile); |
|
958
|
|
|
|
|
959
|
|
|
// Return the thumbnail path if it was successfully generated |
|
960
|
|
|
if($output_file) |
|
|
|
|
|
|
961
|
|
|
{ |
|
962
|
|
|
return $thumbnail_url; |
|
963
|
|
|
} |
|
964
|
|
|
// Create an empty file if thumbnail generation failed |
|
965
|
|
|
else |
|
966
|
|
|
{ |
|
967
|
|
|
FileHandler::writeFile($thumbnail_file, '','w'); |
|
968
|
|
|
} |
|
969
|
|
|
|
|
970
|
|
|
return; |
|
971
|
|
|
} |
|
972
|
|
|
|
|
973
|
|
|
/** |
|
974
|
|
|
* Functions to display icons for new post, latest update, secret(private) post, image/video/attachment |
|
975
|
|
|
* Determine new post and latest update by $time_interval |
|
976
|
|
|
* @param int $time_interval |
|
977
|
|
|
* @return array |
|
978
|
|
|
*/ |
|
979
|
|
|
function getExtraImages($time_interval = 43200) |
|
980
|
|
|
{ |
|
981
|
|
|
if(!$this->document_srl) return; |
|
982
|
|
|
// variables for icon list |
|
983
|
|
|
$buffs = array(); |
|
984
|
|
|
|
|
985
|
|
|
$check_files = false; |
|
|
|
|
|
|
986
|
|
|
|
|
987
|
|
|
// Check if secret post is |
|
988
|
|
|
if($this->isSecret()) $buffs[] = "secret"; |
|
989
|
|
|
|
|
990
|
|
|
// Set the latest time |
|
991
|
|
|
$time_check = date("YmdHis", $_SERVER['REQUEST_TIME']-$time_interval); |
|
992
|
|
|
|
|
993
|
|
|
// Check new post |
|
994
|
|
|
if($this->get('regdate')>$time_check) $buffs[] = "new"; |
|
995
|
|
|
else if($this->get('last_update')>$time_check) $buffs[] = "update"; |
|
996
|
|
|
|
|
997
|
|
|
/* |
|
998
|
|
|
$content = $this->get('content'); |
|
999
|
|
|
|
|
1000
|
|
|
// Check image files |
|
1001
|
|
|
preg_match_all('!<img([^>]*?)>!is', $content, $matches); |
|
1002
|
|
|
$cnt = count($matches[0]); |
|
1003
|
|
|
for($i=0;$i<$cnt;$i++) { |
|
1004
|
|
|
if(preg_match('/editor_component=/',$matches[0][$i])&&!preg_match('/image_(gallery|link)/i',$matches[0][$i])) continue; |
|
1005
|
|
|
$buffs[] = "image"; |
|
1006
|
|
|
$check_files = true; |
|
1007
|
|
|
break; |
|
1008
|
|
|
} |
|
1009
|
|
|
|
|
1010
|
|
|
// Check video files |
|
1011
|
|
|
if(preg_match('!<embed([^>]*?)>!is', $content) || preg_match('/editor_component=("|\')*multimedia_link/i', $content) ) { |
|
1012
|
|
|
$buffs[] = "movie"; |
|
1013
|
|
|
$check_files = true; |
|
1014
|
|
|
} |
|
1015
|
|
|
*/ |
|
1016
|
|
|
|
|
1017
|
|
|
// Check the attachment |
|
1018
|
|
|
if($this->hasUploadedFiles()) $buffs[] = "file"; |
|
1019
|
|
|
|
|
1020
|
|
|
return $buffs; |
|
1021
|
|
|
} |
|
1022
|
|
|
|
|
1023
|
|
|
function getStatus() |
|
1024
|
|
|
{ |
|
1025
|
|
|
if(!$this->get('status')) return $this->getDefaultStatus(); |
|
|
|
|
|
|
1026
|
|
|
return $this->get('status'); |
|
1027
|
|
|
} |
|
1028
|
|
|
|
|
1029
|
|
|
/** |
|
1030
|
|
|
* Return the value obtained from getExtraImages with image tag |
|
1031
|
|
|
* @param int $time_check |
|
1032
|
|
|
* @return string |
|
1033
|
|
|
*/ |
|
1034
|
|
|
function printExtraImages($time_check = 43200) |
|
1035
|
|
|
{ |
|
1036
|
|
|
if(!$this->document_srl) return; |
|
1037
|
|
|
|
|
1038
|
|
|
$oDocumentModel = getModel('document'); |
|
1039
|
|
|
$documentConfig = $oDocumentModel->getDocumentConfig(); |
|
1040
|
|
|
if(Mobile::isFromMobilePhone()) |
|
1041
|
|
|
{ |
|
1042
|
|
|
$iconSkin = $documentConfig->micons; |
|
1043
|
|
|
} |
|
1044
|
|
|
else |
|
1045
|
|
|
{ |
|
1046
|
|
|
$iconSkin = $documentConfig->icons; |
|
1047
|
|
|
} |
|
1048
|
|
|
$path = sprintf('%s%s',getUrl(), "modules/document/tpl/icons/$iconSkin/"); |
|
1049
|
|
|
|
|
1050
|
|
|
$buffs = $this->getExtraImages($time_check); |
|
1051
|
|
|
if(!count($buffs)) return; |
|
1052
|
|
|
|
|
1053
|
|
|
$buff = array(); |
|
1054
|
|
|
foreach($buffs as $key => $val) |
|
|
|
|
|
|
1055
|
|
|
{ |
|
1056
|
|
|
$buff[] = sprintf('<img src="%s%s.gif" alt="%s" title="%s" style="margin-right:2px;" />', $path, $val, $val, $val); |
|
1057
|
|
|
} |
|
1058
|
|
|
return implode('', $buff); |
|
1059
|
|
|
} |
|
1060
|
|
|
|
|
1061
|
|
View Code Duplication |
function hasUploadedFiles() |
|
|
|
|
|
|
1062
|
|
|
{ |
|
1063
|
|
|
if(!$this->document_srl) return; |
|
1064
|
|
|
|
|
1065
|
|
|
if($this->isSecret() && !$this->isGranted()) return false; |
|
1066
|
|
|
return $this->get('uploaded_count')? true : false; |
|
1067
|
|
|
} |
|
1068
|
|
|
|
|
1069
|
|
|
function getUploadedFiles($sortIndex = 'file_srl') |
|
1070
|
|
|
{ |
|
1071
|
|
|
if(!$this->document_srl) return; |
|
1072
|
|
|
|
|
1073
|
|
|
if($this->isSecret() && !$this->isGranted()) return; |
|
1074
|
|
|
if(!$this->get('uploaded_count')) return; |
|
1075
|
|
|
|
|
1076
|
|
|
if(!$this->uploadedFiles[$sortIndex]) |
|
1077
|
|
|
{ |
|
1078
|
|
|
$oFileModel = getModel('file'); |
|
1079
|
|
|
$this->uploadedFiles[$sortIndex] = $oFileModel->getFiles($this->document_srl, array(), $sortIndex, true); |
|
1080
|
|
|
} |
|
1081
|
|
|
|
|
1082
|
|
|
return $this->uploadedFiles[$sortIndex]; |
|
1083
|
|
|
} |
|
1084
|
|
|
|
|
1085
|
|
|
/** |
|
1086
|
|
|
* Return Editor html |
|
1087
|
|
|
* @return string |
|
1088
|
|
|
*/ |
|
1089
|
|
View Code Duplication |
function getEditor() |
|
|
|
|
|
|
1090
|
|
|
{ |
|
1091
|
|
|
$module_srl = $this->get('module_srl'); |
|
1092
|
|
|
if(!$module_srl) $module_srl = Context::get('module_srl'); |
|
1093
|
|
|
|
|
1094
|
|
|
$oEditorModel = getModel('editor'); |
|
1095
|
|
|
return $oEditorModel->getModuleEditor('document', $module_srl, $this->document_srl, 'document_srl', 'content'); |
|
1096
|
|
|
} |
|
1097
|
|
|
|
|
1098
|
|
|
/** |
|
1099
|
|
|
* Check whether to have a permission to write comment |
|
1100
|
|
|
* Authority to write a comment and to write a document is separated |
|
1101
|
|
|
* @return bool |
|
1102
|
|
|
*/ |
|
1103
|
|
|
function isEnableComment() |
|
1104
|
|
|
{ |
|
1105
|
|
|
// Return false if not authorized, if a secret document, if the document is set not to allow any comment |
|
1106
|
|
|
if (!$this->allowComment()) return false; |
|
1107
|
|
|
if(!$this->isGranted() && $this->isSecret()) return false; |
|
1108
|
|
|
|
|
1109
|
|
|
return true; |
|
1110
|
|
|
} |
|
1111
|
|
|
|
|
1112
|
|
|
/** |
|
1113
|
|
|
* Return comment editor's html |
|
1114
|
|
|
* @return string |
|
1115
|
|
|
*/ |
|
1116
|
|
|
function getCommentEditor() |
|
1117
|
|
|
{ |
|
1118
|
|
|
if(!$this->isEnableComment()) return; |
|
1119
|
|
|
|
|
1120
|
|
|
$oEditorModel = getModel('editor'); |
|
1121
|
|
|
return $oEditorModel->getModuleEditor('comment', $this->get('module_srl'), $comment_srl, 'comment_srl', 'content'); |
|
|
|
|
|
|
1122
|
|
|
} |
|
1123
|
|
|
|
|
1124
|
|
|
/** |
|
1125
|
|
|
* Return author's profile image |
|
1126
|
|
|
* @return string |
|
1127
|
|
|
*/ |
|
1128
|
|
View Code Duplication |
function getProfileImage() |
|
|
|
|
|
|
1129
|
|
|
{ |
|
1130
|
|
|
if(!$this->isExists() || !$this->get('member_srl')) return; |
|
1131
|
|
|
$oMemberModel = getModel('member'); |
|
1132
|
|
|
$profile_info = $oMemberModel->getProfileImage($this->get('member_srl')); |
|
1133
|
|
|
if(!$profile_info) return; |
|
1134
|
|
|
|
|
1135
|
|
|
return $profile_info->src; |
|
1136
|
|
|
} |
|
1137
|
|
|
|
|
1138
|
|
|
/** |
|
1139
|
|
|
* Return author's signiture |
|
1140
|
|
|
* @return string |
|
1141
|
|
|
*/ |
|
1142
|
|
View Code Duplication |
function getSignature() |
|
|
|
|
|
|
1143
|
|
|
{ |
|
1144
|
|
|
// Pass if a document doesn't exist |
|
1145
|
|
|
if(!$this->isExists() || !$this->get('member_srl')) return; |
|
1146
|
|
|
// Get signature information |
|
1147
|
|
|
$oMemberModel = getModel('member'); |
|
1148
|
|
|
$signature = $oMemberModel->getSignature($this->get('member_srl')); |
|
1149
|
|
|
// Check if a maximum height of signiture is set in the member module |
|
1150
|
|
|
if(!isset($GLOBALS['__member_signature_max_height'])) |
|
1151
|
|
|
{ |
|
1152
|
|
|
$oModuleModel = getModel('module'); |
|
1153
|
|
|
$member_config = $oModuleModel->getModuleConfig('member'); |
|
1154
|
|
|
$GLOBALS['__member_signature_max_height'] = $member_config->signature_max_height; |
|
1155
|
|
|
} |
|
1156
|
|
|
if($signature) |
|
1157
|
|
|
{ |
|
1158
|
|
|
$max_signature_height = $GLOBALS['__member_signature_max_height']; |
|
1159
|
|
|
if($max_signature_height) $signature = sprintf('<div style="max-height:%dpx;overflow:auto;overflow-x:hidden;height:expression(this.scrollHeight > %d ? \'%dpx\': \'auto\')">%s</div>', $max_signature_height, $max_signature_height, $max_signature_height, $signature); |
|
1160
|
|
|
} |
|
1161
|
|
|
|
|
1162
|
|
|
return $signature; |
|
1163
|
|
|
} |
|
1164
|
|
|
|
|
1165
|
|
|
/** |
|
1166
|
|
|
* Change an image path in the content to absolute path |
|
1167
|
|
|
* @param array $matches |
|
1168
|
|
|
* @return mixed |
|
1169
|
|
|
*/ |
|
1170
|
|
|
function replaceResourceRealPath($matches) |
|
1171
|
|
|
{ |
|
1172
|
|
|
return preg_replace('/src=(["\']?)files/i','src=$1'.Context::getRequestUri().'files', $matches[0]); |
|
1173
|
|
|
} |
|
1174
|
|
|
|
|
1175
|
|
|
/** |
|
1176
|
|
|
* Check accessible by document status |
|
1177
|
|
|
* @param array $matches |
|
|
|
|
|
|
1178
|
|
|
* @return mixed |
|
1179
|
|
|
*/ |
|
1180
|
|
|
function _checkAccessibleFromStatus() |
|
1181
|
|
|
{ |
|
1182
|
|
|
$logged_info = Context::get('logged_info'); |
|
1183
|
|
|
if($logged_info->is_admin == 'Y') return true; |
|
1184
|
|
|
|
|
1185
|
|
|
$status = $this->get('status'); |
|
1186
|
|
|
if(empty($status)) return false; |
|
1187
|
|
|
|
|
1188
|
|
|
$oDocumentModel = getModel('document'); |
|
1189
|
|
|
$configStatusList = $oDocumentModel->getStatusList(); |
|
1190
|
|
|
|
|
1191
|
|
|
if($status == $configStatusList['public'] || $status == $configStatusList['publish']) |
|
1192
|
|
|
return true; |
|
1193
|
|
|
else if($status == $configStatusList['private'] || $status == $configStatusList['secret']) |
|
1194
|
|
|
{ |
|
1195
|
|
|
if($this->get('member_srl') == $logged_info->member_srl) |
|
1196
|
|
|
return true; |
|
1197
|
|
|
} |
|
1198
|
|
|
return false; |
|
1199
|
|
|
} |
|
1200
|
|
|
|
|
1201
|
|
|
function getTranslationLangCodes() |
|
1202
|
|
|
{ |
|
1203
|
|
|
$obj = new stdClass; |
|
1204
|
|
|
$obj->document_srl = $this->document_srl; |
|
1205
|
|
|
// -2 is an index for content. We are interested if content has other translations. |
|
1206
|
|
|
$obj->var_idx = -2; |
|
1207
|
|
|
$output = executeQueryArray('document.getDocumentTranslationLangCodes', $obj); |
|
1208
|
|
|
|
|
1209
|
|
|
if (!$output->data) |
|
1210
|
|
|
{ |
|
1211
|
|
|
$output->data = array(); |
|
1212
|
|
|
} |
|
1213
|
|
|
// add original page's lang code as well |
|
1214
|
|
|
$origLangCode = new stdClass; |
|
1215
|
|
|
$origLangCode->lang_code = $this->getLangCode(); |
|
1216
|
|
|
$output->data[] = $origLangCode; |
|
1217
|
|
|
|
|
1218
|
|
|
return $output->data; |
|
1219
|
|
|
} |
|
1220
|
|
|
|
|
1221
|
|
|
|
|
1222
|
|
|
/** |
|
1223
|
|
|
* Returns the document's mid in order to construct SEO friendly URLs |
|
1224
|
|
|
* @return string |
|
1225
|
|
|
*/ |
|
1226
|
|
|
function getDocumentMid() |
|
1227
|
|
|
{ |
|
1228
|
|
|
$model = getModel('module'); |
|
1229
|
|
|
$module = $model->getModuleInfoByModuleSrl($this->get('module_srl')); |
|
1230
|
|
|
return $module->mid; |
|
1231
|
|
|
} |
|
1232
|
|
|
|
|
1233
|
|
|
/** |
|
1234
|
|
|
* Returns the document's type (document/page/wiki/board/etc) |
|
1235
|
|
|
* @return string |
|
1236
|
|
|
*/ |
|
1237
|
|
|
function getDocumentType() |
|
1238
|
|
|
{ |
|
1239
|
|
|
$model = getModel('module'); |
|
1240
|
|
|
$module = $model->getModuleInfoByModuleSrl($this->get('module_srl')); |
|
1241
|
|
|
return $module->module; |
|
1242
|
|
|
} |
|
1243
|
|
|
|
|
1244
|
|
|
/** |
|
1245
|
|
|
* Returns the document's alias |
|
1246
|
|
|
* @return string |
|
1247
|
|
|
*/ |
|
1248
|
|
|
function getDocumentAlias() |
|
1249
|
|
|
{ |
|
1250
|
|
|
$oDocumentModel = getModel('document'); |
|
1251
|
|
|
return $oDocumentModel->getAlias($this->document_srl); |
|
1252
|
|
|
} |
|
1253
|
|
|
|
|
1254
|
|
|
/** |
|
1255
|
|
|
* Returns the document's actual title (browser_title) |
|
1256
|
|
|
* @return string |
|
1257
|
|
|
*/ |
|
1258
|
|
|
function getModuleName() |
|
1259
|
|
|
{ |
|
1260
|
|
|
$model = getModel('module'); |
|
1261
|
|
|
$module = $model->getModuleInfoByModuleSrl($this->get('module_srl')); |
|
1262
|
|
|
return $module->browser_title; |
|
1263
|
|
|
} |
|
1264
|
|
|
|
|
1265
|
|
|
function getBrowserTitle() |
|
1266
|
|
|
{ |
|
1267
|
|
|
return $this->getModuleName(); |
|
1268
|
|
|
} |
|
1269
|
|
|
} |
|
1270
|
|
|
/* End of file document.item.php */ |
|
1271
|
|
|
/* Location: ./modules/document/document.item.php */ |
|
1272
|
|
|
|