⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fileinfo.pm

📁 1. 记录每个帖子的访问人情况
💻 PM
字号:
# Copyright 2003-2005 Six Apart.# SCRiPTMAFiA 2005 - THE DiRTY HANDS ON YOUR SCRiPTS## $Id: FileInfo.pm 10197 2005-03-09 00:27:57Z ezra $package MT::FileInfo;use strict;use base qw(MT::Object);__PACKAGE__->install_properties({    columns => [        'id', 'blog_id', 'entry_id', 'url', 'file_path',        'templatemap_id', 'template_id', 'archive_type',        'category_id', 'startdate', 'virtual'    ],    indexes => {        blog_id => 1,        entry_id => 1,        template_id => 1,        templatemap_id => 1,        url => 1,    },    datasource => 'fileinfo',    primary_key => 'id',});=pod=head1 NAMEMT::FileInfo=head1 SYNOPSISA FileInfo gives you information about a certain file orserver-relative URL (it assumes a one-to-one mapping between files andURLs).More precisely A FileInfo maps a file path to a "Specifier" whichtells what kind of file it is and how to rebuild it; also included isthe URL where it is expected to be served.A Specifier is a variant record with the following types and fields:            Index of template_id          | Entry of templatemap_id * entry_id          | DateBased of templatemap_id * date_spec * archive_type          | Category of templatemap_id * category_idA FileInfo is tagged with an archive_type field (from the set{Individual, Daily, Monthly, Weekly, Category, Index}), whichdetermines which of those variants is held in the record.=head1 METHODS=over 4=item set_info_for_url($url, $file_path, $archive_type, $spec)Creates a FileInfo record in the database to indicate that the URLC<$url> serves the file at C<$file_path> and can be rebuilt from theparameters in C<$spec>.The C<$spec> argument is a hash ref with at least one of {TemplateMap,Template} defined, and at least one of the following: {Entry,StartDate, Category}.If $archive_type is 'index' then Template should be given; otherwiseTemplateMap should be given.=back=cut# think: We need a set({a => v, ...}, {b => u, ...}) routine which#    guarantees that subsequently load({a => v, ...}) will return a#    record that matches {b => u}sub set_info_for_url {    my $class = shift;    my ($url, $file_path, $archive_type, $args) = @_;    my $url_map = MT::FileInfo->new();    $url_map->blog_id($args->{Blog});    if ($archive_type eq 'index') {        $url_map->template_id($args->{Template});    } else {        $url_map->templatemap_id($args->{TemplateMap}) if $args->{TemplateMap};        $url_map->template_id($args->{Template}) if $args->{Template};        $args->{Entry} = $args->{Entry}->id if ref $args->{Entry};        $url_map->entry_id($args->{Entry}) if $args->{Entry};        $url_map->startdate($args->{StartDate}) if $args->{StartDate};        $args->{Category} = $args->{Category}->id if ref $args->{Category};        $url_map->category_id($args->{Category}) if $args->{Category};    }    $url_map->archive_type($archive_type);    $url_map->url($url);    $url_map->file_path($file_path);    $url_map->save() || return $class->error($url_map->errstr());    return $url_map;}1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -