XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
comment.item.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
3 
12 class commentItem extends BaseObject
13 {
14 
19  var $comment_srl = 0;
20 
25  var $columnList = array();
26 
33  function __construct($comment_srl = 0, $columnList = array())
34  {
35  $this->comment_srl = $comment_srl;
36  $this->columnList = $columnList;
37  $this->_loadFromDB();
38  }
39 
41  {
42  $this->comment_srl = $comment_srl;
43  $this->_loadFromDB();
44  }
45 
50  function _loadFromDB()
51  {
52  if(!$this->comment_srl)
53  {
54  return;
55  }
56 
57  $args = new stdClass();
58  $args->comment_srl = $this->comment_srl;
59  $output = executeQuery('comment.getComment', $args, $this->columnList);
60 
61  $this->setAttribute($output->data);
62  }
63 
68  function setAttribute($attribute)
69  {
70  if(!$attribute->comment_srl)
71  {
72  $this->comment_srl = NULL;
73  return;
74  }
75 
76  $this->comment_srl = $attribute->comment_srl;
77  $this->adds($attribute);
78 
79  // define vars on the object for backward compatibility of skins
80  if(count($attribute))
81  {
82  foreach($attribute as $key => $val)
83  {
84  $this->{$key} = $val;
85  }
86  }
87  }
88 
89  function isExists()
90  {
91  return $this->comment_srl ? TRUE : FALSE;
92  }
93 
94  function isGranted()
95  {
96  if($_SESSION['own_comment'][$this->comment_srl])
97  {
98  return TRUE;
99  }
100 
101  if(!Context::get('is_logged'))
102  {
103  return FALSE;
104  }
105 
106  $logged_info = Context::get('logged_info');
107  if($logged_info->is_admin == 'Y')
108  {
109  return TRUE;
110  }
111 
112  $grant = Context::get('grant');
113  if($grant->manager)
114  {
115  return TRUE;
116  }
117 
118  if($this->get('member_srl') && ($this->get('member_srl') == $logged_info->member_srl || $this->get('member_srl') * -1 == $logged_info->member_srl))
119  {
120  return TRUE;
121  }
122 
123  return FALSE;
124  }
125 
126  function setGrant()
127  {
128  $_SESSION['own_comment'][$this->comment_srl] = TRUE;
129  $this->is_granted = TRUE;
130  }
131 
132  function setAccessible()
133  {
134  $_SESSION['accessibled_comment'][$this->comment_srl] = TRUE;
135  }
136 
137  function isEditable()
138  {
139  if($this->isGranted() || !$this->get('member_srl'))
140  {
141  return TRUE;
142  }
143  return FALSE;
144  }
145 
146  function isSecret()
147  {
148  return $this->get('is_secret') == 'Y' ? TRUE : FALSE;
149  }
150 
151  function isAccessible()
152  {
153  if($_SESSION['accessibled_comment'][$this->comment_srl])
154  {
155  return TRUE;
156  }
157 
158  if($this->isGranted() || !$this->isSecret())
159  {
160  $this->setAccessible();
161  return TRUE;
162  }
163 
164  $oDocumentModel = getModel('document');
165  $oDocument = $oDocumentModel->getDocument($this->get('document_srl'));
166  if($oDocument->isGranted())
167  {
168  $this->setAccessible();
169  return TRUE;
170  }
171 
172  return FALSE;
173  }
174 
175  function useNotify()
176  {
177  return $this->get('notify_message') == 'Y' ? TRUE : FALSE;
178  }
179 
184  function notify($type, $content)
185  {
186  // return if not useNotify
187  if(!$this->useNotify())
188  {
189  return;
190  }
191 
192  // pass if the author is not logged-in user
193  if(!$this->get('member_srl'))
194  {
195  return;
196  }
197 
198  // return if the currently logged-in user is an author of the comment.
199  $logged_info = Context::get('logged_info');
200  if($logged_info->member_srl == $this->get('member_srl'))
201  {
202  return;
203  }
204 
205  // get where the comment belongs to
206  $oDocumentModel = getModel('document');
207  $oDocument = $oDocumentModel->getDocument($this->get('document_srl'));
208 
209  // Variables
210  if($type)
211  {
212  $title = "[" . $type . "] ";
213  }
214 
215  $title .= cut_str(strip_tags($content), 30, '...');
216  $content = sprintf('%s<br /><br />from : <a href="%s#comment_%s" target="_blank">%s</a>', $content, getFullUrl('', 'document_srl', $this->get('document_srl')), $this->get('comment_srl'), getFullUrl('', 'document_srl', $this->get('document_srl')));
217  $receiver_srl = $this->get('member_srl');
218  $sender_member_srl = $logged_info->member_srl;
219 
220  // send a message
221  $oCommunicationController = getController('communication');
222  $oCommunicationController->sendMessage($sender_member_srl, $receiver_srl, $title, $content, FALSE);
223  }
224 
225  function getIpAddress()
226  {
227  if($this->isGranted())
228  {
229  return $this->get('ipaddress');
230  }
231 
232  return '*' . strstr($this->get('ipaddress'), '.');
233  }
234 
235  function isExistsHomepage()
236  {
237  if(trim($this->get('homepage')))
238  {
239  return TRUE;
240  }
241 
242  return FALSE;
243  }
244 
245  function getHomepageUrl()
246  {
247  $url = trim($this->get('homepage'));
248  if(!$url)
249  {
250  return;
251  }
252 
253  if(strncasecmp('http://', $url, 7) !== 0)
254  {
255  $url = "http://" . $url;
256  }
257 
258  return htmlspecialchars($url, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
259  }
260 
261  function getMemberSrl()
262  {
263  return $this->get('member_srl');
264  }
265 
266  function getUserID()
267  {
268  return htmlspecialchars($this->get('user_id'), ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
269  }
270 
271  function getUserName()
272  {
273  return htmlspecialchars($this->get('user_name'), ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
274  }
275 
276  function getNickName()
277  {
278  return htmlspecialchars($this->get('nick_name'), ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
279  }
280 
285  function getContentText($strlen = 0)
286  {
287  if($this->isSecret() && !$this->isAccessible())
288  {
289  return Context::getLang('msg_is_secret');
290  }
291 
292  $content = $this->get('content');
293 
294  if($strlen)
295  {
296  return cut_str(strip_tags($content), $strlen, '...');
297  }
298 
299  return htmlspecialchars($content, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
300  }
301 
306  function getContent($add_popup_menu = TRUE, $add_content_info = TRUE, $add_xe_content_class = TRUE)
307  {
308  if($this->isSecret() && !$this->isAccessible())
309  {
310  return Context::getLang('msg_is_secret');
311  }
312 
313  $content = $this->get('content');
314  stripEmbedTagForAdmin($content, $this->get('member_srl'));
315 
316  // when displaying the comment on the pop-up menu
317  if($add_popup_menu && Context::get('is_logged'))
318  {
319  $content = sprintf(
320  '%s<div class="comment_popup_menu"><a href="#popup_menu_area" class="comment_%d" onclick="return false">%s</a></div>', $content, $this->comment_srl, Context::getLang('cmd_comment_do')
321  );
322  }
323 
324  // if additional information which can access contents is set
325  if($add_content_info)
326  {
327  $memberSrl = $this->get('member_srl');
328  if($memberSrl < 0)
329  {
330  $memberSrl = 0;
331  }
332  $content = sprintf(
333  '<!--BeforeComment(%d,%d)--><div class="comment_%d_%d xe_content">%s</div><!--AfterComment(%d,%d)-->', $this->comment_srl, $memberSrl, $this->comment_srl, $memberSrl, $content, $this->comment_srl, $memberSrl
334  );
335  // xe_content class name should be specified although content access is not necessary.
336  }
337  else
338  {
339  if($add_xe_content_class)
340  {
341  $content = sprintf('<div class="xe_content">%s</div>', $content);
342  }
343  }
344 
345  return $content;
346  }
347 
352  function getSummary($str_size = 50, $tail = '...')
353  {
354  $content = $this->getContent(FALSE, FALSE);
355 
356  // for newline, insert a blank.
357  $content = preg_replace('!(<br[\s]*/{0,1}>[\s]*)+!is', ' ', $content);
358 
359  // replace tags such as </p> , </div> , </li> by blanks.
360  $content = str_replace(array('</p>', '</div>', '</li>', '-->'), ' ', $content);
361 
362  // Remove tags
363  $content = preg_replace('!<([^>]*?)>!is', '', $content);
364 
365  // replace < , >, "
366  $content = str_replace(array('&lt;', '&gt;', '&quot;', '&nbsp;'), array('<', '>', '"', ' '), $content);
367 
368  // delete a series of blanks
369  $content = preg_replace('/ ( +)/is', ' ', $content);
370 
371  // truncate strings
372  $content = trim(cut_str($content, $str_size, $tail));
373 
374  // restore >, <, , "\
375  $content = str_replace(array('<', '>', '"'), array('&lt;', '&gt;', '&quot;'), $content);
376 
377  return $content;
378  }
379 
380  function getRegdate($format = 'Y.m.d H:i:s')
381  {
382  return zdate($this->get('regdate'), $format);
383  }
384 
385  function getRegdateTime()
386  {
387  $regdate = $this->get('regdate');
388  $year = substr($regdate, 0, 4);
389  $month = substr($regdate, 4, 2);
390  $day = substr($regdate, 6, 2);
391  $hour = substr($regdate, 8, 2);
392  $min = substr($regdate, 10, 2);
393  $sec = substr($regdate, 12, 2);
394  return mktime($hour, $min, $sec, $month, $day, $year);
395  }
396 
397  function getRegdateGM()
398  {
399  return $this->getRegdate('D, d M Y H:i:s') . ' ' . $GLOBALS['_time_zone'];
400  }
401 
402  function getUpdate($format = 'Y.m.d H:i:s')
403  {
404  return zdate($this->get('last_update'), $format);
405  }
406 
407  function getPermanentUrl()
408  {
409  return getFullUrl('', 'mid', $this->getCommentMid(), 'document_srl', $this->get('document_srl')) . '#comment_' . $this->get('comment_srl');
410  }
411 
412  function getUpdateTime()
413  {
414  $year = substr($this->get('last_update'), 0, 4);
415  $month = substr($this->get('last_update'), 4, 2);
416  $day = substr($this->get('last_update'), 6, 2);
417  $hour = substr($this->get('last_update'), 8, 2);
418  $min = substr($this->get('last_update'), 10, 2);
419  $sec = substr($this->get('last_update'), 12, 2);
420  return mktime($hour, $min, $sec, $month, $day, $year);
421  }
422 
423  function getUpdateGM()
424  {
425  return gmdate("D, d M Y H:i:s", $this->getUpdateTime());
426  }
427 
428  function hasUploadedFiles()
429  {
430  if(($this->isSecret() && !$this->isAccessible()) && !$this->isGranted())
431  {
432  return FALSE;
433  }
434  return $this->get('uploaded_count') ? TRUE : FALSE;
435  }
436 
437  function getUploadedFiles()
438  {
439  if(($this->isSecret() && !$this->isAccessible()) && !$this->isGranted())
440  {
441  return;
442  }
443 
444  if(!$this->get('uploaded_count'))
445  {
446  return;
447  }
448 
449  $oFileModel = getModel('file');
450  $file_list = $oFileModel->getFiles($this->comment_srl, array(), 'file_srl', TRUE);
451  return $file_list;
452  }
453 
458  function getEditor()
459  {
460  $module_srl = $this->get('module_srl');
461  if(!$module_srl)
462  {
463  $module_srl = Context::get('module_srl');
464  }
465  $oEditorModel = getModel('editor');
466  return $oEditorModel->getModuleEditor('comment', $module_srl, $this->comment_srl, 'comment_srl', 'content');
467  }
468 
473  function getProfileImage()
474  {
475  if(!$this->isExists() || !$this->get('member_srl'))
476  {
477  return;
478  }
479  $oMemberModel = getModel('member');
480  $profile_info = $oMemberModel->getProfileImage($this->get('member_srl'));
481  if(!$profile_info)
482  {
483  return;
484  }
485 
486  return $profile_info->src;
487  }
488 
493  function getSignature()
494  {
495  // pass if the posting not exists.
496  if(!$this->isExists() || !$this->get('member_srl'))
497  {
498  return;
499  }
500 
501  // get the signiture information
502  $oMemberModel = getModel('member');
503  $signature = $oMemberModel->getSignature($this->get('member_srl'));
504 
505  // check if max height of the signiture is specified on the member module
506  if(!isset($GLOBALS['__member_signature_max_height']))
507  {
508  $oModuleModel = getModel('module');
509  $member_config = $oModuleModel->getModuleConfig('member');
510  $GLOBALS['__member_signature_max_height'] = $member_config->signature_max_height;
511  }
512 
513  $max_signature_height = $GLOBALS['__member_signature_max_height'];
514 
515  if($max_signature_height)
516  {
517  $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);
518  }
519 
520  return $signature;
521  }
522 
523  function thumbnailExists($width = 80, $height = 0, $type = '')
524  {
525  if(!$this->comment_srl)
526  {
527  return FALSE;
528  }
529 
530  if(!$this->getThumbnail($width, $height, $type))
531  {
532  return FALSE;
533  }
534 
535  return TRUE;
536  }
537 
538  function getThumbnail($width = 80, $height = 0, $thumbnail_type = '')
539  {
540  // return false if no doc exists
541  if(!$this->comment_srl)
542  {
543  return;
544  }
545 
546  if($this->isSecret() && !$this->isGranted())
547  {
548  return;
549  }
550 
551  // If signiture height setting is omitted, create a square
552  if(!$height)
553  {
554  $height = $width;
555  }
556 
557  $content = $this->get('content');
558  if(!$this->hasUploadedFiles())
559  {
560  if(!$content)
561  {
562  $args = new stdClass();
563  $args->comment_srl = $this->comment_srl;
564  $output = executeQuery('document.getComment', $args, array('content'));
565  if($output->toBool() && $output->data)
566  {
567  $content = $output->data->content;
568  $this->add('content', $content);
569  }
570  }
571 
572  if(!preg_match("!<img!is", $content)) return;
573  }
574 
575  // get thumbail generation info on the doc module configuration.
576  if(!in_array($thumbnail_type, array('crop', 'ratio')))
577  {
578  $thumbnail_type = 'crop';
579  }
580 
581  // Define thumbnail information
582  $thumbnail_path = sprintf('files/thumbnails/%s', getNumberingPath($this->comment_srl, 3));
583  $thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type);
584  $thumbnail_lockfile = sprintf('%s%dx%d.%s.lock', $thumbnail_path, $width, $height, $thumbnail_type);
585  $thumbnail_url = Context::getRequestUri() . $thumbnail_file;
586 
587  // return false if a size of existing thumbnail file is 0. otherwise return the file path
588  if(file_exists($thumbnail_file) || file_exists($thumbnail_lockfile))
589  {
590  if(filesize($thumbnail_file) < 1)
591  {
592  return FALSE;
593  }
594  else
595  {
596  return $thumbnail_url . '?' . date('YmdHis', filemtime($thumbnail_file));
597  }
598  }
599 
600  // Create lockfile to prevent race condition
601  FileHandler::writeFile($thumbnail_lockfile, '', 'w');
602 
603  // Target file
604  $source_file = NULL;
605  $is_tmp_file = FALSE;
606 
607  // find an image file among attached files
608  if($this->hasUploadedFiles())
609  {
610  $file_list = $this->getUploadedFiles();
611 
612  $first_image = null;
613  foreach($file_list as $file)
614  {
615  if($file->direct_download !== 'Y') continue;
616 
617  if($file->cover_image === 'Y' && file_exists($file->uploaded_filename))
618  {
619  $source_file = $file->uploaded_filename;
620  break;
621  }
622 
623  if($first_image) continue;
624 
625  if(preg_match("/\.(jpe?g|png|gif|bmp)$/i", $file->source_filename))
626  {
627  if(file_exists($file->uploaded_filename))
628  {
629  $first_image = $file->uploaded_filename;
630  }
631  }
632  }
633 
634  if(!$source_file && $first_image)
635  {
636  $source_file = $first_image;
637  }
638  }
639 
640  // get an image file from the doc content if no file attached.
641  $is_tmp_file = false;
642  if(!$source_file)
643  {
644  $random = new Password();
645 
646  preg_match_all("!<img[^>]*src=(?:\"|\')([^\"\']*?)(?:\"|\')!is", $content, $matches, PREG_SET_ORDER);
647 
648  foreach($matches as $target_image)
649  {
650  $target_src = trim($target_image[1]);
651  if(preg_match('/\/(common|modules|widgets|addons|layouts|m\.layouts)\//i', $target_src)) continue;
652 
653  if(!preg_match('/^(http|https):\/\//i',$target_src))
654  {
655  $target_src = Context::getRequestUri().$target_src;
656  }
657 
658  $target_src = htmlspecialchars_decode($target_src);
659 
660  $tmp_file = _XE_PATH_ . 'files/cache/tmp/' . $random->createSecureSalt(32, 'hex');
661  FileHandler::getRemoteFile($target_src, $tmp_file);
662  if(!file_exists($tmp_file)) continue;
663 
664  $imageinfo = getimagesize($tmp_file);
665  list($_w, $_h) = $imageinfo;
666  if($imageinfo === false || ($_w < ($width * 0.3) && $_h < ($height * 0.3))) {
667  FileHandler::removeFile($tmp_file);
668  continue;
669  }
670 
671  $source_file = $tmp_file;
672  $is_tmp_file = true;
673  break;
674  }
675  }
676 
677  $output = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, 'jpg', $thumbnail_type);
678 
679  // Remove source file if it was temporary
680  if($is_tmp_file)
681  {
682  FileHandler::removeFile($source_file);
683  }
684 
685  // Remove lockfile
686  FileHandler::removeFile($thumbnail_lockfile);
687 
688  // Create an empty file if thumbnail generation failed
689  if(!$output)
690  {
691  FileHandler::writeFile($thumbnail_file, '','w');
692  }
693 
694  return $thumbnail_url . '?' . date('YmdHis', filemtime($thumbnail_file));
695  }
696 
697  function isCarted()
698  {
699  return $_SESSION['comment_management'][$this->comment_srl];
700  }
701 
706  function getCommentMid()
707  {
708  $model = getModel('module');
709  $module = $model->getModuleInfoByModuleSrl($this->get('module_srl'));
710  return $module->mid;
711  }
712 
713 }
714 /* End of file comment.item.php */
715 /* Location: ./modules/comment/comment.item.php */
$oModuleModel
Definition: ko.install.php:236
getController($module_name)
Definition: func.inc.php:90
getNumberingPath($no, $size=3)
Definition: func.inc.php:1081
zdate($str, $format= 'Y-m-d H:i:s', $conversion=TRUE)
Definition: func.inc.php:692
removeFile($filename)
stripEmbedTagForAdmin(&$content, $writer_member_srl)
Definition: func.inc.php:1568
if(file_exists(_XE_PATH_. 'config/config.user.inc.php')) if(!defined('__DEBUG__')) if(!defined('__DEBUG_OUTPUT__')) if(!defined('__DEBUG_PROTECT__')) if(!defined('__DEBUG_PROTECT_IP__')) if(!defined('__DEBUG_DB_OUTPUT__')) if(!defined('__LOG_SLOW_QUERY__')) if(!defined('__LOG_SLOW_TRIGGER__')) if(!defined('__LOG_SLOW_ADDON__')) if(!defined('__LOG_SLOW_WIDGET__')) if(!defined('__DEBUG_QUERY__')) if(!defined('__OB_GZHANDLER_ENABLE__')) if(!defined('__ENABLE_PHPUNIT_TEST__')) if(!defined('__PROXY_SERVER__')) if(!defined('__ERROR_LOG__')) if(!defined('__DISABLE_DEFAULT_CSS__')) if(!defined('__AUTO_OPCACHE_INVALIDATE__')) if((__DEBUG_OUTPUT__==2)&&version_compare(PHP_VERSION, '6.0.0')===-1) if(version_compare(PHP_VERSION, '5.3.0') >=0) $GLOBALS['__xe_autoload_file_map']
Definition: config.inc.php:324
$output
Definition: ko.install.php:193
add($key, $val)
writeFile($filename, $buff, $mode="w")
getRegdate($format= 'Y.m.d H:i:s')
__construct($comment_srl=0, $columnList=array())
setAttribute($attribute)
getSummary($str_size=50, $tail= '...')
$args
Definition: ko.install.php:185
getRemoteFile($url, $target_filename, $body=null, $timeout=3, $method= 'GET', $content_type=null, $headers=array(), $cookies=array(), $post_data=array(), $request_config=array())
notify($type, $content)
getContentText($strlen=0)
$oDocumentModel
Definition: ko.install.php:259
thumbnailExists($width=80, $height=0, $type= '')
setComment($comment_srl)
getLang($code)
const _XE_PATH_
Definition: config.inc.php:49
getContent($add_popup_menu=TRUE, $add_content_info=TRUE, $add_xe_content_class=TRUE)
createImageFile($source_file, $target_file, $resize_width=0, $resize_height=0, $target_type= '', $thumbnail_type= 'crop', $thumbnail_transparent=FALSE)
getRequestUri($ssl_mode=FOLLOW_REQUEST_SSL, $domain=null)
getModel($module_name)
Definition: func.inc.php:145
$module_srl
Definition: ko.install.php:254
cut_str($string, $cut_size=0, $tail= '...')
Definition: func.inc.php:508
getUpdate($format= 'Y.m.d H:i:s')
executeQuery($query_id, $args=NULL, $arg_columns=NULL)
Definition: func.inc.php:203
getFullUrl()
Definition: func.inc.php:361
getThumbnail($width=80, $height=0, $thumbnail_type= '')