<commit_before># This program is distributed under the terms of
# The MIT License (MIT)
#
# Copyright (c) 2014 Six Apart, Ltd.
#
# $Id$

package MT::App::Viewer;

use strict;
use base qw( MT::App );

use MT::Entry;
use MT::Template;
use MT::Template::Context;
use MT::Promise qw(delay);

sub init {
    my $app = shift;
    $app->SUPER::init(@_) or return;
    $app->{default_mode} = 'main';
    $app->add_methods( 'main' => \&view, );
    return $app;
}

my %view_handlers = (
    'index'      => \&_view_index,
    'individual' => \&_view_entry,
    'page'       => \&_view_entry,
    'category'   => \&_view_category,
    'author'     => \&_view_author,
    '*'          => \&_view_date_archive,
);

sub view {
    my $app = shift;

    my $R = MT::Request->instance;
    $R->stash( 'live_view', 1 );

    ## Process the path info.
    my $uri = $app->param('uri') || $ENV{REQUEST_URI};
    my $blog_id = $app->param('blog_id')
        or return $app->errtrans("Invalid request.");

    ## Check ExcludeBlogs and IncludeBlogs to see if this blog is
    ## private or not.
    my $cfg = $app->config;
    if ( my $inc_blogs = $cfg->IncludeBlogs ) {
        return $app->errtrans('Invalid request')
            unless grep { $_ == $blog_id } split ',', $inc_blogs;
    }
    if ( my $exc_blogs = $cfg->ExcludeBlogs ) {
        return $app->errtrans('Invalid request')
            if grep { $_ == $blog_id } split ',', $exc_blogs;
    }<commit_msg>"blog_id" パラメータが無くても動作するよう修正。<commit_after># This program is distributed under the terms of
# The MIT License (MIT)
#
# Copyright (c) 2014 Six Apart, Ltd.
#
# $Id$

package MT::App::Viewer;

use strict;
use base qw( MT::App );

use MT::Entry;
use MT::Template;
use MT::Template::Context;
use MT::Promise qw(delay);

sub init {
    my $app = shift;
    $app->SUPER::init(@_) or return;
    $app->{default_mode} = 'main';
    $app->add_methods( 'main' => \&view, );
    return $app;
}

my %view_handlers = (
    'index'      => \&_view_index,
    'individual' => \&_view_entry,
    'page'       => \&_view_entry,
    'category'   => \&_view_category,
    'author'     => \&_view_author,
    '*'          => \&_view_date_archive,
);

sub view {
    my $app = shift;

    my $R = MT::Request->instance;
    $R->stash( 'live_view', 1 );

    ## Process the path info.
    my $uri = $app->param('uri') || $ENV{REQUEST_URI};
    my $blog_id = $app->param('blog_id');

    my $cfg = $app->config;
    if ( !$blog_id ) {
        my $idx = $cfg->IndexBasename || 'index';

        my @url_terms = ( { url => $uri } );
        if ( $uri !~ m!\Q/$idx(?:\.[^\.\/]+)?\E$! ) {
            $uri .= '/' unless $uri =~ m!/$!;
            push @url_terms,
                (
                '-or', { url => "${uri}${idx}" },
                '-or', { url => { like => "${uri}${idx}.%" } }
                );
        }

        # Load fileinfo by URL
        require MT::Template;
        require MT::PublishOption;
        my $fi = MT->model('fileinfo')->load(
            \@url_terms,
            {   join => [
                    'MT::Template',
                    undef,
                    {   type => { not => 'backup' },
                        build_type =>
                            { not => MT::PublishOption->DISABLED() },
                        id => \' = fileinfo_template_id',
                    }
                ],
            }

        ) or return $app->errtrans("Invalid request.");

        $blog_id = $fi->blog_id;
    }

    ## Check ExcludeBlogs and IncludeBlogs to see if this blog is
    ## private or not.
    if ( my $inc_blogs = $cfg->IncludeBlogs ) {
        return $app->errtrans('Invalid request')
            unless grep { $_ == $blog_id } split ',', $inc_blogs;
    }
    if ( my $exc_blogs = $cfg->ExcludeBlogs ) {
        return $app->errtrans('Invalid request')
            if grep { $_ == $blog_id } split ',', $exc_blogs;
    }
{'fraction_non_alphanumeric': 0.17838809034907596, 'fraction_numerical': 0.002566735112936345, 'mean_word_length': 2.0326848249027236, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 58, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7375434', 'n_tokens_mistral': 1375, 'n_tokens_neox': 1316, 'n_words': 314}