~ubuntu-branches/debian/squeeze/movabletype-opensource/squeeze

« back to all changes in this revision

Viewing changes to php/lib/MTUtil.php

  • Committer: Bazaar Package Importer
  • Author(s): Dominic Hargreaves
  • Date: 2008-12-11 20:00:05 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20081211200005-989csado6g2peqwf
Tags: 4.2.3-1
* Urgency medium due to security fixes
* New upstream release: contains XSS security fixes and minor bugfixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
# This program is distributed under the terms of the
4
4
# GNU General Public License, version 2.
5
5
#
6
 
# $Id: MTUtil.php 2651 2008-06-30 02:26:07Z takayama $
 
6
# $Id: MTUtil.php 3128 2008-10-23 20:44:03Z bchoate $
7
7
 
8
8
function start_end_ts($ts) {
9
9
    if ($ts) {
1182
1182
    $expr = preg_replace('/\bNOT\b/i', '!', $expr);
1183
1183
 
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);
1186
1186
 
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;
1301
1301
    $dest;
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')) {
1304
1304
        return '';
1305
1305
    }
1306
1306
    $basename = basename($dest);
1313
1313
}
1314
1314
 
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);
1319
1319
 
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);
1323
1323
 
1324
1324
    return array($thumb_w, $thumb_h);
1325
1325
}
1326
1326
 
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);
1337
1337
 
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);
 
1344
    }
 
1345
 
 
1346
    $cache_dir = $base_path . DIRECTORY_SEPARATOR . $cache_path . DIRECTORY_SEPARATOR . $date_stamp . DIRECTORY_SEPARATOR;
1341
1347
    $thumb_name = $cache_dir . $format;
1342
 
 
 
1348
 
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;
1348
1354
    $dest;
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)) {
1350
1356
        return '';
1351
1357
    }
1352
1358
 
1353
1359
    # make url
1354
1360
    $basename = basename($dest);
1355
 
    $site_url = $blog['blog_site_url'];
1356
 
    if (!preg_match('!/$!', $site_url))
1357
 
        $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))
 
1365
        $base_url .= '/';
1358
1366
 
1359
 
    $thumb_url = $site_url . $cache_path . '/' . $date_stamp . '/' . $basename;
 
1367
    $thumb_url = $base_url . $cache_path . '/' . $date_stamp . '/' . $basename;
1360
1368
 
1361
1369
    return array($thumb_url, $thumb_w, $thumb_h, $thumb_name);
1362
1370
}
1521
1529
        foreach ($f as $filter) {
1522
1530
            if ($filter == '__default__') {
1523
1531
                $filter = 'convert_breaks';
 
1532
            } elseif ($filter == '__sanitize__') {
 
1533
                $filter = 'sanitize';
1524
1534
            }
1525
1535
            if ($filter == 'convert_breaks') {
1526
1536
                $text = html_text_transform($text);