Changeset 1340

Show
Ignore:
Timestamp:
01/28/08 06:52:30 (17 months ago)
Author:
takayama
Message:

Fixed BugId:66594
* Generate user-pic when user-pic was not found

Location:
branches/release-29
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • branches/release-29/lib/MT/App/CMS.pm

    r1339 r1340  
    1592315923    ## TODO: should this be layered into _upload_file somehow, so we don't 
    1592415924    ## save the asset twice? 
     15925    my $user_id = $app->param('user_id'); 
     15926 
    1592515927    $asset->tags('@userpic'); 
     15928    $asset->created_by($user_id); 
    1592615929    $asset->save; 
    15927  
    15928     my $user_id = $app->param('user_id'); 
    1592915930 
    1593015931    $app->forward( 'asset_userpic', { asset => $asset, user_id => $user_id } ); 
  • branches/release-29/lib/MT/Auth/OpenID.pm

    r1174 r1340  
    9898        if ( my $userpic = $class->get_userpicasset($vident) ) { 
    9999            $userpic->tags('@userpic'); 
     100            $userpic->created_by($cmntr->id); 
    100101            $userpic->save; 
    101102            if (my $userpic = $cmntr->userpic) { 
  • branches/release-29/php/lib/MTUtil.php

    r1174 r1340  
    12711271 
    12721272function userpic_url($asset, $blog, $author) { 
    1273     $url = $asset['asset_url']; 
    1274     $static_path = static_path($blog['blog_site_url']); 
    1275     $static_path = preg_replace('/\/$/', '', $static_path); 
    1276     $static_path .= '/support'; 
    1277  
    12781273    global $mt; 
    1279     $cache_path = $mt->config('AssetCacheDir'); 
    1280     $image_path = $cache_path . '/' . 'userpics'; 
    1281  
    12821274    $format = $mt->translate('userpic-[_1]-%wx%h%x', array($author['author_id'])); 
    12831275    $max_dim = $mt->config('UserpicThumbnailSize'); 
     
    12911283    $filename = preg_replace($patterns, $replacement, $format); 
    12921284 
     1285    # generate thumbnail 
     1286    $src_file = asset_path($asset['asset_file_path'], $blog); 
     1287 
     1288    $cache_path = $mt->config('AssetCacheDir'); 
     1289    $image_path = $cache_path . DIRECTORY_SEPARATOR . 'userpics'; 
     1290    $static_file_path = static_file_path().'support'; 
     1291    make_thumbnail_file($src_file, $static_file_path.DIRECTORY_SEPARATOR.$image_path.DIRECTORY_SEPARATOR.$filename, $max_dim, $max_dim, 0, 'png'); 
     1292 
     1293    $static_path = $mt->config('StaticWebPath'); 
     1294    $static_path = preg_replace('/\/$/', '', $static_path); 
     1295    $static_path .= '/support'; 
    12931296    $url = sprintf("%s/%s/%s", $static_path, $image_path, $filename); 
    12941297 
     
    12961299} 
    12971300 
    1298 function get_thumbnail_file($asset, $blog, $width = 0, $height = 0, $scale = 0, $format = '%f-thumb-%wx%h%x') { 
    1299     # Get parameter 
    1300     $site_path = $blog['blog_site_path']; 
    1301     $site_path = preg_replace('/\/$/', '', $site_path); 
    1302     $filename = asset_path($asset['asset_file_path'], $blog); 
    1303  
     1301function make_thumbnail_file($src, $dest, $width, $height, $scale = 0, $dest_type = 'auto') { 
    13041302    # Get source image information 
    1305     list($src_w, $src_h, $src_type, $src_attr) = getimagesize($filename); 
     1303    list($src_w, $src_h, $src_type, $src_attr) = getimagesize($src); 
    13061304 
    13071305    # Load source image 
     
    13101308    switch($src_type) { 
    13111309    case 1: #GIF 
    1312         $src_img = @imagecreatefromgif($filename); 
     1310        $src_img = @imagecreatefromgif($src); 
    13131311        break; 
    13141312    case 2: #JPEG 
    1315         $src_img = @imagecreatefromjpeg($filename); 
     1313        $src_img = @imagecreatefromjpeg($src); 
    13161314        break; 
    13171315    case 3: #PNG 
    1318         $src_img = @imagecreatefrompng($filename); 
     1316        $src_img = @imagecreatefrompng($src); 
    13191317        break; 
    13201318    default: #Unsupported format 
     
    13291327    $thumb_w = $src_w; 
    13301328    $thumb_h = $src_h; 
    1331  
    1332     $name_w = 'auto'; $name_h = 'auto'; 
    1333     if ($width > 0) 
    1334         $name_w = $width; 
    1335     if ($height > 0) 
    1336         $name_h = $height; 
    13371329 
    13381330    if ($scale > 0) { 
     
    13461338        $thumb_h = (int)($thumb_h * $pct); 
    13471339    } 
     1340 
     1341    # Generate 
     1342    if(!file_exists($dest)) { 
     1343        $dir_name = dirname($dest); 
     1344        if (!file_exists($dir_name)) { 
     1345          mkdir($dir_name, 0777, true); 
     1346        } 
     1347        if (!is_writable($dir_name)) { 
     1348            imagedestroy($src_img); 
     1349            return ''; 
     1350        } 
     1351 
     1352        # Create thumbnail 
     1353        $dst_img = imagecreatetruecolor ( $thumb_w, $thumb_h ); 
     1354        $result = imagecopyresampled ( $dst_img, $src_img, 0, 0, 0, 0, 
     1355                    $thumb_w, $thumb_h, $src_w, $src_h); 
     1356 
     1357        $output = $src_type; 
     1358        if ($dest_type != 'auto') { 
     1359            $output = strtolower($dest_type) == 'gif' ? 1 
     1360              : strtolower($dest_type) == 'jpeg' ? 2 
     1361              : strtolower($dest_type) == 'png' ? 3 
     1362              : $src_type; 
     1363        } 
     1364        switch($output) { 
     1365            case 1: #GIF 
     1366            imagegif($dst_img, $dest); 
     1367            break; 
     1368        case 2: #JPEG 
     1369            imagejpeg($dst_img, $dest); 
     1370            break; 
     1371        case 3: #PNG 
     1372            imagepng($dst_img, $dest); 
     1373            break; 
     1374        } 
     1375        imagedestroy($dst_img); 
     1376    } 
     1377 
     1378    imagedestroy($src_img); 
     1379 
     1380    return array($thumb_w, $thumb_h); 
     1381} 
     1382 
     1383function get_thumbnail_file($asset, $blog, $width = 0, $height = 0, $scale = 0, $format = '%f-thumb-%wx%h%x') { 
     1384    # Get parameter 
     1385    $site_path = $blog['blog_site_path']; 
     1386    $site_path = preg_replace('/\/$/', '', $site_path); 
     1387    $filename = asset_path($asset['asset_file_path'], $blog); 
     1388    $name_w = 'auto'; $name_h = 'auto'; 
     1389    if ($width > 0) 
     1390        $name_w = $width; 
     1391    if ($height > 0) 
     1392        $name_h = $height; 
    13481393 
    13491394    # Generate thumbnail file name 
     
    13721417    $cache_dir = $site_path . DIRECTORY_SEPARATOR . $cache_path . DIRECTORY_SEPARATOR . $date_stamp . DIRECTORY_SEPARATOR; 
    13731418    $thumb_name = $cache_dir . $thumb_filename; 
    1374     if(!file_exists($thumb_name)) { 
    1375         if (!file_exists($cache_dir)) { 
    1376           mkdir($cache_dir, 0777, true); 
    1377         } 
    1378         if (!is_writable($cache_dir)) 
    1379             return ''; 
    1380         # Create thumbnail 
    1381         $dst_img = imagecreatetruecolor ( $thumb_w, $thumb_h ); 
    1382         $result = imagecopyresampled ( $dst_img, $src_img, 0, 0, 0, 0, 
    1383                     $thumb_w, $thumb_h, $src_w, $src_h); 
    1384  
    1385         switch($src_type) { 
    1386             case 1: #GIF 
    1387             imagegif($dst_img, $thumb_name); 
    1388             break; 
    1389         case 2: #JPEG 
    1390             imagejpeg($dst_img, $thumb_name); 
    1391             break; 
    1392         case 3: #PNG 
    1393             imagepng($dst_img, $thumb_name); 
    1394             break; 
    1395         } 
    1396         imagedestroy($dst_img); 
    1397     } 
    1398  
    1399     imagedestroy($src_img); 
     1419  
     1420    # generate thumbnail 
     1421    list ($thumb_w, $thumb_h) = make_thumbnail_file($filename, $thumb_name, $width, $height); 
    14001422 
    14011423    # make url