mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-06 10:11:38 +09:00
Optimize thumbnail check logic
This commit is contained in:
parent
4102c4bda2
commit
9d0e808514
2 changed files with 30 additions and 36 deletions
|
|
@ -635,17 +635,13 @@ class commentItem extends BaseObject
|
|||
function getThumbnail($width = 80, $height = 0, $thumbnail_type = '')
|
||||
{
|
||||
// return false if no doc exists
|
||||
if(!$this->comment_srl)
|
||||
if(!$this->comment_srl || !$this->isAccessible())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Get thumbnail type information from document module's configuration
|
||||
$config = $GLOBALS['__document_config__'];
|
||||
if(!$config)
|
||||
{
|
||||
$config = $GLOBALS['__document_config__'] = DocumentModel::getDocumentConfig();
|
||||
}
|
||||
$config = DocumentModel::getDocumentConfig();
|
||||
if ($config->thumbnail_target === 'none' || $config->thumbnail_type === 'none')
|
||||
{
|
||||
return;
|
||||
|
|
@ -659,23 +655,12 @@ class commentItem extends BaseObject
|
|||
$config->thumbnail_quality = 75;
|
||||
}
|
||||
|
||||
if(!$this->isAccessible())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// If signiture height setting is omitted, create a square
|
||||
if(!$height)
|
||||
{
|
||||
$height = $width;
|
||||
}
|
||||
|
||||
// return false if neigher attached file nor image;
|
||||
if(!$this->hasUploadedFiles() && !preg_match("!<img!is", $this->get('content')))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Define thumbnail information
|
||||
$thumbnail_path = sprintf('files/thumbnails/%s', getNumberingPath($this->comment_srl, 3));
|
||||
$thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type);
|
||||
|
|
@ -695,6 +680,12 @@ class commentItem extends BaseObject
|
|||
}
|
||||
}
|
||||
|
||||
// return false if neigher attached file nor image;
|
||||
if(!$this->get('uploaded_count') && !preg_match("!<img!is", $this->get('content')))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Create lockfile to prevent race condition
|
||||
FileHandler::writeFile($thumbnail_lockfile, '', 'w');
|
||||
|
||||
|
|
|
|||
|
|
@ -1053,7 +1053,10 @@ class documentItem extends BaseObject
|
|||
function getThumbnail($width = 80, $height = 0, $thumbnail_type = '')
|
||||
{
|
||||
// Return false if the document doesn't exist
|
||||
if(!$this->document_srl) return;
|
||||
if(!$this->document_srl || !$this->isAccessible())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Get thumbnail type information from document module's configuration
|
||||
$config = DocumentModel::getDocumentConfig();
|
||||
|
|
@ -1070,28 +1073,12 @@ class documentItem extends BaseObject
|
|||
$config->thumbnail_quality = 75;
|
||||
}
|
||||
|
||||
if(!$this->isAccessible())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// If not specify its height, create a square
|
||||
if(!$height) $height = $width;
|
||||
if($this->get('content'))
|
||||
if(!$height)
|
||||
{
|
||||
$content = $this->get('content');
|
||||
}
|
||||
elseif($config->thumbnail_target !== 'attachment')
|
||||
{
|
||||
$args = new stdClass();
|
||||
$args->document_srl = $this->document_srl;
|
||||
$output = executeQuery('document.getDocument', $args);
|
||||
$content = $output->data->content;
|
||||
$height = $width;
|
||||
}
|
||||
|
||||
// Return false if neither attachement nor image files in the document
|
||||
if(!$this->get('uploaded_count') && !preg_match("!<img!is", $content)) return;
|
||||
|
||||
// Define thumbnail information
|
||||
$thumbnail_path = sprintf('files/thumbnails/%s',getNumberingPath($this->document_srl, 3));
|
||||
$thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type);
|
||||
|
|
@ -1110,6 +1097,22 @@ class documentItem extends BaseObject
|
|||
return $thumbnail_url . '?' . date('YmdHis', filemtime($thumbnail_file));
|
||||
}
|
||||
}
|
||||
|
||||
// Get content if it does not exist.
|
||||
if($this->get('content'))
|
||||
{
|
||||
$content = $this->get('content');
|
||||
}
|
||||
elseif($config->thumbnail_target !== 'attachment')
|
||||
{
|
||||
$args = new stdClass();
|
||||
$args->document_srl = $this->document_srl;
|
||||
$output = executeQuery('document.getDocument', $args);
|
||||
$content = $output->data->content;
|
||||
}
|
||||
|
||||
// Return false if neither attachement nor image files in the document
|
||||
if(!$this->get('uploaded_count') && !preg_match("!<img!is", $content)) return;
|
||||
|
||||
// Create lockfile to prevent race condition
|
||||
FileHandler::writeFile($thumbnail_lockfile, '', 'w');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue