3
3
# This program is distributed under the terms of the
4
4
# GNU General Public License, version 2.
6
# $Id: MTUtil.php 2651 2008-06-30 02:26:07Z takayama $
6
# $Id: MTUtil.php 3128 2008-10-23 20:44:03Z bchoate $
8
8
function start_end_ts($ts) {
1182
1182
$expr = preg_replace('/\bNOT\b/i', '!', $expr);
1184
1184
# The following is no more readable in PHP than it is in Perl
1185
$expr = preg_replace_callback('/( |#\d+|&&|\|\||!|\(|\))|([^#0-9&|!()]+)/', 'create_expr_exception', $expr);
1185
$expr = preg_replace_callback('/( |\#\d+|&&|\|\||!|\(|\))|([^#&|!()]+)/', 'create_expr_exception', $expr);
1187
1187
# Syntax check on 'tag' argument
1188
1188
# Strip out all the valid stuff. if anything is left, we have
1300
1300
$thumb_h = $max_dim;
1302
1302
$thumb_name = $static_file_path.DIRECTORY_SEPARATOR.$image_path.DIRECTORY_SEPARATOR.$format;
1303
if (!$thumb->get_thumbnail($dest, $thumb_w, $thumb_h, $scale, $thumb_name, 'png')) {
1303
if (!$thumb->get_thumbnail($dest, $thumb_w, $thumb_h, $asset['asset_id'], $scale, $thumb_name, 'png')) {
1306
1306
$basename = basename($dest);
1315
1315
# for compatibility...
1316
function make_thumbnail_file($src, $dest, $width, $height, $scale = 0, $dest_type = 'auto') {
1316
function make_thumbnail_file($src, $dest, $width, $height, $scale = 0, $dest_type = 'auto', $id = 0) {
1317
1317
require_once('thumbnail_lib.php');
1318
1318
$thumb = new Thumbnail($src);
1320
1320
$thumb_w = $width;
1321
1321
$thumb_h = $height;
1322
$thumb->get_thumbnail($dest, $thumb_w, $thumb_h, $scale, null, $dest_type);
1322
$thumb->get_thumbnail($dest, $thumb_w, $thumb_h, $id, $scale, null, $dest_type);
1324
1324
return array($thumb_w, $thumb_h);
1327
function get_thumbnail_file($asset, $blog, $width = 0, $height = 0, $scale = 0, $format = '%f-thumb-%wx%h%x') {
1327
function get_thumbnail_file($asset, $blog, $width = 0, $height = 0, $scale = 0, $format = '%f-thumb-%wx%h-%i%x') {
1328
1328
# Get parameter
1329
1329
$site_path = $blog['blog_site_path'];
1330
1330
$site_path = preg_replace('/\/$/', '', $site_path);
1338
1338
$ts = preg_replace('![^0-9]!', '', $asset['asset_created_on']);
1339
1339
$date_stamp = format_ts('%Y/%m', $ts, $blog);
1340
$cache_dir = $site_path . DIRECTORY_SEPARATOR . $cache_path . DIRECTORY_SEPARATOR . $date_stamp . DIRECTORY_SEPARATOR;
1340
$base_path = $site_path;
1341
if (preg_match('/^%a/', $asset['asset_file_path']) && !empty($blog['blog_archive_path'])) {
1342
$base_path = $blog['blog_archive_path'];
1343
$base_path = preg_replace('/\/$/', '', $base_path);
1346
$cache_dir = $base_path . DIRECTORY_SEPARATOR . $cache_path . DIRECTORY_SEPARATOR . $date_stamp . DIRECTORY_SEPARATOR;
1341
1347
$thumb_name = $cache_dir . $format;
1343
1349
# generate thumbnail
1344
1350
require_once('thumbnail_lib.php');
1345
1351
$thumb = new Thumbnail($filename);
1346
1352
$thumb_w = $width;
1347
1353
$thumb_h = $height;
1349
if (!$thumb->get_thumbnail($dest, $thumb_w, $thumb_h, $scale, $thumb_name)) {
1355
if (!$thumb->get_thumbnail($dest, $thumb_w, $thumb_h, $asset['asset_id'], $scale, $thumb_name)) {
1354
1360
$basename = basename($dest);
1355
$site_url = $blog['blog_site_url'];
1356
if (!preg_match('!/$!', $site_url))
1361
$base_url = $blog['blog_site_url'];
1362
if (preg_match('/^%a/', $asset['asset_file_path']) && !empty($blog['blog_archive_url']))
1363
$base_url = $blog['blog_archive_url'];
1364
if (!preg_match('!/$!', $base_url))
1359
$thumb_url = $site_url . $cache_path . '/' . $date_stamp . '/' . $basename;
1367
$thumb_url = $base_url . $cache_path . '/' . $date_stamp . '/' . $basename;
1361
1369
return array($thumb_url, $thumb_w, $thumb_h, $thumb_name);
1521
1529
foreach ($f as $filter) {
1522
1530
if ($filter == '__default__') {
1523
1531
$filter = 'convert_breaks';
1532
} elseif ($filter == '__sanitize__') {
1533
$filter = 'sanitize';
1525
1535
if ($filter == 'convert_breaks') {
1526
1536
$text = html_text_transform($text);