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