Provide triggers document.getThumbnail (before) and comment.getThumbnail (before)

This commit is contained in:
Kijin Sung 2020-10-01 17:22:06 +09:00
parent f5ff91491b
commit 16d3209bbd
2 changed files with 31 additions and 2 deletions

View file

@ -666,6 +666,7 @@ class commentItem extends BaseObject
$thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type);
$thumbnail_lockfile = sprintf('%s%dx%d.%s.lock', $thumbnail_path, $width, $height, $thumbnail_type);
$thumbnail_url = Context::getRequestUri() . $thumbnail_file;
$thumbnail_file = RX_BASEDIR . $thumbnail_file;
// return false if a size of existing thumbnail file is 0. otherwise return the file path
if(file_exists($thumbnail_file) || file_exists($thumbnail_lockfile))
@ -680,6 +681,20 @@ class commentItem extends BaseObject
}
}
// Call trigger for custom thumbnails.
$trigger_obj = (object)[
'document_srl' => $this->document_srl, 'comment_srl' => $this->comment_srl,
'width' => $width, 'height' => $height,
'image_type' => 'jpg', 'type' => $thumbnail_type, 'quality' => $config->thumbnail_quality,
'filename' => $thumbnail_file, 'url' => $thumbnail_url,
];
$output = ModuleHandler::triggerCall('comment.getThumbnail', 'before', $trigger_obj);
clearstatcache(true, $thumbnail_file);
if (file_exists($thumbnail_file) && filesize($thumbnail_file) > 0)
{
return $thumbnail_url . '?' . date('YmdHis', filemtime($thumbnail_file));
}
// return false if neigher attached file nor image;
if(!$this->get('uploaded_count') && !preg_match("!<img!is", $this->get('content')))
{
@ -778,7 +793,7 @@ class commentItem extends BaseObject
if($source_file)
{
$output = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, 'jpg', $thumbnail_type, $config->thumbnail_quality);
$output = FileHandler::createImageFile($source_file, $thumbnail_file, $trigger_obj->width, $trigger_obj->height, $trigger_obj->image_type, $trigger_obj->type, $trigger_obj->quality);
}
// Remove source file if it was temporary

View file

@ -1084,6 +1084,7 @@ class documentItem extends BaseObject
$thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type);
$thumbnail_lockfile = sprintf('%s%dx%d.%s.lock', $thumbnail_path, $width, $height, $thumbnail_type);
$thumbnail_url = Context::getRequestUri().$thumbnail_file;
$thumbnail_file = RX_BASEDIR . $thumbnail_file;
// Return false if thumbnail file exists and its size is 0. Otherwise, return its path
if(file_exists($thumbnail_file) || file_exists($thumbnail_lockfile))
@ -1098,6 +1099,19 @@ class documentItem extends BaseObject
}
}
// Call trigger for custom thumbnails.
$trigger_obj = (object)[
'document_srl' => $this->document_srl, 'width' => $width, 'height' => $height,
'image_type' => 'jpg', 'type' => $thumbnail_type, 'quality' => $config->thumbnail_quality,
'filename' => $thumbnail_file, 'url' => $thumbnail_url,
];
$output = ModuleHandler::triggerCall('document.getThumbnail', 'before', $trigger_obj);
clearstatcache(true, $thumbnail_file);
if (file_exists($thumbnail_file) && filesize($thumbnail_file) > 0)
{
return $thumbnail_url . '?' . date('YmdHis', filemtime($thumbnail_file));
}
// Get content if it does not exist.
if($this->get('content'))
{
@ -1210,7 +1224,7 @@ class documentItem extends BaseObject
if($source_file)
{
$output_file = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, 'jpg', $thumbnail_type, $config->thumbnail_quality);
$output_file = FileHandler::createImageFile($source_file, $thumbnail_file, $trigger_obj->width, $trigger_obj->height, $trigger_obj->image_type, $trigger_obj->type, $trigger_obj->quality);
}
// Remove source file if it was temporary