Last active
June 11, 2018 04:41
-
-
Save hideki-a/fe4a061424c3d02bc3026633272dac20 to your computer and use it in GitHub Desktop.
記事番号から記事を表示
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="ja"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>記事番号から記事を表示</title> | |
</head> | |
<body> | |
<h1>記事番号から記事を表示</h1> | |
<form action="/mt/mt-linkentry.cgi" method="get"> | |
<label for="code">記事番号</label>: <input type="text" name="code" id="code"> <input type="submit" value="表示する"> | |
<br>例)<code>201605-001</code> | |
</form> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package MT::App::LinkEntry; | |
use strict; | |
use base qw( MT::App ); | |
use MT::Entry; | |
# See Also: http://www.ark-web.jp/sandbox/wiki/306.html | |
@MT::App::LinkEntry = qw( MT::App ); | |
sub init { | |
my $app = shift; | |
$app->SUPER::init(@_) or return; | |
$app->add_methods( DispEntryByCode => \&_DispEntryByCode ); | |
$app->mode('DispEntryByCode'); | |
$app; | |
} | |
sub _DispEntryByCode { | |
my $app = shift; | |
my $class = MT->model('entry'); | |
my $code = $app->param( 'code' ); | |
my $col = 'entry_link_code'; | |
my $type = MT::Meta->metadata_by_name($class, 'field.' . $col); | |
my @entries = MT::Entry->load( | |
{ | |
blog_id => 1, | |
status => MT::Entry::RELEASE() | |
}, | |
{ | |
join => [ | |
$class->meta_pkg, | |
undef, | |
{ | |
'entry_id' => \'= entry_id', | |
type => 'field.' . $col, | |
$type->{type} => $code | |
} | |
] | |
} | |
); | |
# TODO: 結果が1記事か確認する | |
my $location; | |
for my $entry ( @entries ) { | |
$location = $entry->permalink; | |
} | |
$app->set_header( 'Location' => $location ); | |
$app->send_http_header(); | |
return 'OK'; | |
} | |
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
# Movable Type (r) (C) 2001-2016 Six Apart, Ltd. All Rights Reserved. | |
# This code cannot be redistributed without permission from www.sixapart.com. | |
# For more information, consult your Movable Type license. | |
# | |
# $Id$ | |
use strict; | |
use lib $ENV{MT_HOME} ? "$ENV{MT_HOME}/lib" : 'lib'; | |
use lib $ENV{MT_HOME} ? "$ENV{MT_HOME}/plugins/LinkEntry/lib" : 'plugins/LinkEntry/lib'; | |
use MT::Bootstrap App => 'MT::App::LinkEntry'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment