function get_thumbnail_file($asset, $blog, $args) { # Parse args $format = '%f-thumb-%wx%h-%i%x'; if (isset($args['format'])) { $format = $args['format']; } # Get parameter $site_path = $blog->site_path(); $site_path = preg_replace('/\\/$/', '', $site_path); $filename = asset_path($asset->asset_file_path, $blog); # Retrieve thumbnail $mt = MT::get_instance(); $path_parts = pathinfo($filename); $cache_path = $mt->config('AssetCacheDir'); $ts = preg_replace('![^0-9]!', '', $asset->asset_created_on); $date_stamp = format_ts('%Y/%m', $ts, $blog); $base_path = $site_path; $archive_path = $blog->archive_path(); if (preg_match('/^%a/', $asset->asset_file_path) && !empty($archive_path)) { $base_path = $blog->archive_path(); $base_path = preg_replace('/\\/$/', '', $base_path); } $cache_dir = $base_path . DIRECTORY_SEPARATOR . $cache_path . DIRECTORY_SEPARATOR . $date_stamp . DIRECTORY_SEPARATOR; $thumb_name = $cache_dir . $format; # generate thumbnail require_once 'thumbnail_lib.php'; $thumb = new Thumbnail($filename); $thumb->id($asset->id); $thumb->format($thumb_name); $thumb->type('auto'); if (isset($args['width'])) { $thumb->width($args['width']); } if (isset($args['height'])) { $thumb->height($args['height']); } if (isset($args['scale'])) { $thumb->scale($args['scale']); } if (isset($args['square'])) { $thumb->square($args['square'] ? true : false); } if (!$thumb->get_thumbnail()) { return ''; } # make url $basename = basename($thumb->dest()); $base_url = $blog->site_url(); $archive_url = $blog->archive_url(); if (preg_match('/^%a/', $asset->asset_file_path) && !empty($archive_url)) { $base_url = $blog->archive_url(); } if (!preg_match('!/$!', $base_url)) { $base_url .= '/'; } if (DIRECTORY_SEPARATOR != '/') { $cache_path = str_replace(DIRECTORY_SEPARATOR, '/', $cache_path); } $thumb_url = $base_url . $cache_path . '/' . $date_stamp . '/' . $basename; return array($thumb_url, $thumb->width(), $thumb->height(), $thumb->dest()); }