Skip to content

Instantly share code, notes, and snippets.

@bazooka07
Last active June 25, 2018 14:35
Show Gist options
  • Save bazooka07/5d1821030f37a0d430dd6b561a10e508 to your computer and use it in GitHub Desktop.
Save bazooka07/5d1821030f37a0d430dd6b561a10e508 to your computer and use it in GitHub Desktop.
<?php
/* --------- plxShow::artThumbnail() ---------- */
public function artThumbnail($format='<a href="#img_url"><img class="art_thumbnail" src="#img_thumb_url" alt="#img_alt" title="#img_title" /></a>', $echo=true) {
$filename = trim($this->plxMotor->plxRecord_arts->f('thumbnail'));
if(!empty($filename)) {
$img_url = $this->plxMotor->urlRewrite($filename);
$img_thumb = plxUtils::thumbName($filename);
$replaces = array(
'#img_url' => $img_url,
'#img_thumb_url'=> (file_exists(PLX_ROOT.$img_thumb)) ? $this->plxMotor->urlRewrite($img_thumb) : $img_url,
'#img_title' => plxUtils::strCheck($this->plxMotor->plxRecord_arts->f('thumbnail_title')),
'#img_alt' => $this->plxMotor->plxRecord_arts->f('thumbnail_alt')
);
if($echo)
echo str_replace(array_keys($replaces), array_values($replaces), $format);
else
return str_replace(array_keys($replaces), array_values($replaces), $format);
} elseif(!$echo) {
return false;
}
}
?>
<?php
/* -------- plxUtils::thumbName($filename) -------- */
public static function thumbName($filename) {
if(preg_match('/^(.*\.)(jpe?g|png|gif)$/iD', $filename, $matches)) {
return $matches[1].'tb.'.$matches[2];
} else {
return $filename;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment