Dotclear


Ignore:
Timestamp:
12/18/09 01:47:08 (13 years ago)
Author:
JcDenis
Message:

efiMetadatas 0.2:

  • Added generic class to get readable meta
File:
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/efiMetadatas/_widgets.php

    r1918 r1989  
    6868          if ($w->category != 'null' && $w->category != '' && $w->category != $_ctx->posts->cat_id) return; 
    6969 
    70           # Path and url 
    71           $p_url = $core->blog->settings->public_url; 
    72           $p_site = preg_replace('#^(.+?//.+?)/(.*)$#','$1',$core->blog->url); 
    73           $p_root = $core->blog->public_path; 
     70          # Content lookup 
     71          $text = $_ctx->posts->post_excerpt_xhtml.$_ctx->posts->post_content_xhtml; 
    7472 
    75           # Image pattern 
    76           $pattern = '(?:'.preg_quote($p_site,'/').')?'.preg_quote($p_url,'/'); 
    77           $pattern = sprintf('/<img.+?src="%s(.*?\.(?:jpg|gif|png))"[^>]+/msu',$pattern); 
    78  
    79           # Content lookup 
    80           $subject = $_ctx->posts->post_excerpt_xhtml.$_ctx->posts->post_content_xhtml; 
     73          # Find source image 
     74          $img = efiMetadatas::imgSource($core,$text,$w->thumbsize); 
    8175 
    8276          # No image 
    83           if (!preg_match_all($pattern,$subject,$m)) return; 
    84  
    85           $src = false; 
    86           $size = $w->thumbsize; 
    87           $alt = $metas = $thumb = ''; 
    88           $allowed_ext = array('.jpg','.JPG','.png','.PNG','.gif','.GIF'); 
    89  
    90           # Loop through images 
    91           foreach ($m[1] as $i => $img) 
    92           { 
    93                $src = false; 
    94                $info = path::info($img); 
    95                $base = $info['base']; 
    96                $ext = $info['extension']; 
    97  
    98                # Not original 
    99                if (preg_match('/^\.(.+)_(sq|t|s|m)$/',$base,$mbase)) 
    100                { 
    101                     $base = $mbase[1]; 
    102                } 
    103  
    104                # Full path 
    105                $f = $p_root.'/'.$info['dirname'].'/'.$base; 
    106  
    107                # Find extension 
    108                foreach($allowed_ext as $end) 
    109                { 
    110                     if (file_exists($f.$end)) 
    111                     { 
    112                          $src = $f.$end; 
    113                          break; 
    114                     } 
    115                } 
    116  
    117                # No file 
    118                if (!$src) continue; 
    119  
    120                # Find thumbnail 
    121                if (!empty($size)) 
    122                { 
    123                     $t = $p_root.'/'.$info['dirname'].'/.'.$base.'_'.$size.'.jpg'; 
    124                     if (file_exists($t)) 
    125                     { 
    126                          $thb = $p_url.(dirname($img) != '/' ? dirname($img) : '').'/.'.$base.'_'.$size.'.jpg'; 
    127                     } 
    128                } 
    129  
    130                # Find image description 
    131                if (preg_match('/alt="([^"]+)"/',$m[0][$i],$malt)) 
    132                { 
    133                     $alt = $malt[1]; 
    134                } 
    135                break; 
    136           } 
    137  
    138           # No image 
    139           if (!$src || !file_exists($src)) return; 
    140  
    141           # Image info         
    142           $metas_array = imageMeta::readMeta($src); 
     77          if (!$img['source']) return; 
    14378 
    14479          # List metas 
    145           foreach($metas_array as $k => $v) 
     80          $metas = efiMetadatas::imgMeta($core,$img['source']); 
     81 
     82          $content = ''; 
     83          foreach($metas as $k => $v) 
    14684          { 
    147                if (!$w->showmeta && !$v) continue; 
    148                $metas .= '<li><strong>'.__($k.':').'</strong><br />'.$v.'</li>'; 
     85               // keep empty meta if wanted 
     86               if (!$w->showmeta && empty($v[1])) continue; 
     87               $content .= '<li class="efi-'.$k.'"><strong>'.$v[0].':</strong><br />'.$v[1].'</li>'; 
    14988          } 
    15089 
    15190          # No meta 
    152           if (empty($metas)) return; 
    153  
     91          if (empty($content)) return; 
    15492 
    15593          # thumbnail 
    156           if (!empty($thb)) 
     94          if ($img['thumb']) 
    15795          { 
    15896               $thumb =  
    15997               '<div class="img-box">'.                 
    16098               '<div class="img-thumbnail">'. 
    161                '<img alt="'.$alt.'" src="'.$thb.'" />'. 
     99               '<img alt="'.$img['title'].'" src="'.$img['thumb'].'" />'. 
    162100               '</div>'. 
    163101               "</div>\n"; 
     
    168106          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). 
    169107          $thumb. 
    170           '<ul>'.$metas.'</ul>'. 
     108          '<ul>'.$content.'</ul>'. 
    171109          '</div>'; 
    172110     } 
Note: See TracChangeset for help on using the changeset viewer.

Sites map