分析photo gallery plugin学习插件的编写

| 暂无评论 | 暂无引用通告

-->

插件功能:显示特定条件的图片,同时还能以对有时间格式的图片名进行排序

插件主页

http://brandon.fuller.name/archives/hacks/mtphotogallery/#download 

下载插件 

解压得到文件PhotoGallery.pl,然后将其移到$MTDIR/plugins下,


可用的标签有

MTPhotoGallery

添加容器标签:

MT::Template::Context->add_container_tag( PhotoGallery => \&hdlr_PhotoGallery );
 

容器标签,根椐传给的图像文件列表处理图片,默认情况下处理站点中的所有图片 
debug=”0|1”
是否为试调模式
silent=”0|1”
设置插件无声退出
path=”dir
设定查找图片的目录,默认情况下插件搜索整个站点的目录

代码中获得文件列表

        opendir( THISDIR, $photodir ) || die "Cannot open directory $photodir: $1";
        @allfiles = grep( !/^\.\.?$/, readdir( THISDIR ) ); #用于去掉.及..
        closedir( THISDIR );

recursive=”0|1”
是否递归搜索子目录

代码:

                        if ( $recursive eq '1' )
                        {
                                $res .= &makeFileList( \@$usefiles, $ctx, $builder, $tokens, File::Spec->catfile( $photodir, $f ), "$photovdir/$f", "$exclude", $recursive, $ext, $debug );
                        }

 

count=”n
显示图片的数目限制;这里设了一个计数器

    foreach $f ( @sortedfiles )
    {
        last if ( $count-- == 0 );

sort_order=”ascend|descend|random”
排序方式
exclude=”expression

需要排除的文件

代码

       if ( defined( $args->{exclude} ) )
        {
                $exclude = build_expr( $ctx, $args->{exclude} );
        }
        else
        {
                $exclude = '';
        }
以下用于文件的踢除

@allfiles = grep( !/^.*$exclude.*$/, @allfiles ); 

 

extension=”expression
此参数可以匹欲显示图片的扩展名,不同的格式之间用竖线隔开,如:"jpg|bmp|png"扩展名前不用加点号。

用竖线隔开那是因为:

        elsif ( $f =~ /^(.+)\.($ext)$/ )
        {
            push( @$usefiles, "$photovdir/$f" );
        }

MTPhotoGalleryImageDate

从图片名中分析所得的日期信息

  • format=”%B %e, %Y”
    Use the standard Movable Type date formatting commands described in the User Manual.

MTPhotoGalleryImageDateExists

A container tag that conditionally generates its contents based on the existence of a value in MTPhotoGalleryImageDate.

 

  • state=”0|1”
    If 1, then tag shows output when value exists. If 0, then tag shows output when value does not exist.

MTPhotoGalleryImageLink

添加标签: MT::Template::Context->add_tag( PhotoGalleryImageLink => \&hdlr_PhotoGalleryImageLink );

The full URL of this image.

MTPhotoGalleryImageFileName

不带路径的图片名

MTPhotoGalleryImagePath

相对于站点根目录的路径名不包含图片文件名如果需要图片文件名可以使用标签 MTPhotoGalleryImageFileName连接。

MTPhotoGalleryImageTitle

从文件名从分析出的图片标题,但前题是文件名是按照指定的格式.

MTPhotoGalleryImageTitleExists

A container tag that conditionally generates its contents based on the existence of a value in MTPhotoGalleryImageTitle.

 

  • state=”0|1”
    If 1, then tag shows output when value exists. If 0, then tag shows output when value does not exist.


效果如:图片册 太难看了,呵呵,慢慢改

举例将图片显示到模板中:

此处我们用到了MTGrid(用于分栏显示等)用于 MTEmbedImage(用于创建缩略图)两个插件

 <MTGrid num_columns="3">

   <MTPhotoGallery path="image" exclude="-THUMB">    图片相对于站点根目录的路径,去除文件名中包含-THUMB的图片
<MTGridCell>
            <MTGridIfLeftColumn><tr></MTGridIfLeftColumn>

              <td>
            <MTEmbedImage basename="[MTPhotoGalleryImagePath]/[MTPhotoGalleryImageFileName]" width="150" thumbsuffix="-THUMB">
    被选中的图片被生成缩略图,下面是显示图片

              <a href="<MTPhotoGalleryImageLink>">
                  <img src="<MTEmbedImageThumbFilename>"
                     width="<MTEmbedImageThumbWidth>"
                     height="<MTEmbedImageThumbHeight>"/>
               </a>
            </MTEmbedImage>
         </td>
       <MTGridIfRightColumn></tr></MTGridIfRightColumn>
     </MTGridCell>
   </MTPhotoGallery>
<MTGridTrailingCells>
         <MTGridIfLeftColumn></tr></MTGridIfLeftColumn>
         <td>&nbsp;</td>
         <MTGridIfRightColumn></tr></MTGridIfRightColumn>
      </MTGridTrailingCells>
   </MTGrid>

 

暂无引用通告

发送引用通告网址: http://supersun.info/mt/mt-tb.cgi/539
如果您想引用这篇日记到您的Blog,请复制上面的链接,放置到您发表文章时的相应界面中。

发表评论

最新资源

  • IMG_1437.JPG
  • line.png
  • bar.png
  • perl_calander.jpg

关于此日记

此日记由 supersun 发表于 2007年3月29日 10:13

此Blog上的上一篇日记IceSword120

此Blog上的下一篇日记模块:File::Spec

首页归档页可以看到最新的日记和所有日记。