Skip to content

Commit

Permalink
Implement mt-cdsearch.cgi. MTC-11858
Browse files Browse the repository at this point in the history
  • Loading branch information
masiuchi committed Mar 22, 2018
1 parent b001e68 commit cd0de86
Show file tree
Hide file tree
Showing 9 changed files with 1,210 additions and 135 deletions.
211 changes: 118 additions & 93 deletions lib/MT/App/Search.pm

Large diffs are not rendered by default.

681 changes: 681 additions & 0 deletions lib/MT/App/Search/ContentData.pm

Large diffs are not rendered by default.

125 changes: 88 additions & 37 deletions lib/MT/Core.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1776,6 +1776,9 @@ BEGIN {
path => 1,
type => 'ARRAY',
},
'SearchContentDataTemplatePath' => {
default => sub { $_[0]->SearchTemplatePath }
},
'ThemesDirectory' => {
default => 'themes',
path => 1,
Expand Down Expand Up @@ -1876,35 +1879,45 @@ BEGIN {
default => 'mt-search.cgi',
handler => \&SearchScript,
},
'FreeTextSearchScript' => { default => 'mt-ftsearch.cgi', },
'XMLRPCScript' => { default => 'mt-xmlrpc.cgi', },
'AtomScript' => { default => 'mt-atom.cgi', },
'UpgradeScript' => { default => 'mt-upgrade.cgi', },
'CheckScript' => { default => 'mt-check.cgi', },
'DataAPIScript' => { default => 'mt-data-api.cgi', },
'PublishCharset' => { default => 'utf-8', },
'SafeMode' => { default => 1, },
'AllowFileInclude' => { default => 0, },
'GlobalSanitizeSpec' => {
'FreeTextSearchScript' => { default => 'mt-ftsearch.cgi', },
'ContentDataSearchScript' => { default => 'mt-cdsearch.cgi' },
'XMLRPCScript' => { default => 'mt-xmlrpc.cgi', },
'AtomScript' => { default => 'mt-atom.cgi', },
'UpgradeScript' => { default => 'mt-upgrade.cgi', },
'CheckScript' => { default => 'mt-check.cgi', },
'DataAPIScript' => { default => 'mt-data-api.cgi', },
'PublishCharset' => { default => 'utf-8', },
'SafeMode' => { default => 1, },
'AllowFileInclude' => { default => 0, },
'GlobalSanitizeSpec' => {
default =>
'a href,b,i,br/,p,strong,em,ul,ol,li,blockquote,pre',
},
'GenerateTrackBackRSS' => { default => 0, },
'DBIRaiseError' => { default => 0, },
'SearchAlwaysAllowTemplateID' => { default => 0, },
'PreviewInNewWindow' => { default => 1, },
'BasenameCheckCompat' => { default => 0, },
'GenerateTrackBackRSS' => { default => 0, },
'DBIRaiseError' => { default => 0, },
'SearchAlwaysAllowTemplateID' => { default => 0, },
'SearchContentDataAlwaysAllowTemplateId' => {
default => sub { $_[0]->SearchAlwaysAllowTemplateId }
},
'PreviewInNewWindow' => { default => 1, },
'BasenameCheckCompat' => { default => 0, },

## Search settings, copied from Jay's mt-search and integrated
## into default config.
'NoOverride' => { default => '', },
'RegexSearch' => { default => 0, },
'CaseSearch' => { default => 0, },
'ResultDisplay' => { default => 'descend', },
'ExcerptWords' => { default => 40, },
'SearchElement' => { default => 'entries', },
'ExcludeBlogs' => undef,
'IncludeBlogs' => undef,
'NoOverride' => { default => '', },
'RegexSearch' => { default => 0, },
'CaseSearch' => { default => 0, },
'ResultDisplay' => { default => 'descend', },
'ExcerptWords' => { default => 40, },
'SearchElement' => { default => 'entries', },
'ExcludeBlogs' => undef,
'ContentDataExcludeBlogs' => {
default => sub { $_[0]->ExcludeBlogs }
},
'IncludeBlogs' => undef,
'ContentDataIncludeBlogs' => {
default => sub { $_[0]->IncludeBlogs }
},
'DefaultTemplate' => { default => 'default.tmpl', },
'Type' => { default => 'straight', },
'MaxResults' => { default => '20', },
Expand All @@ -1914,14 +1927,32 @@ BEGIN {
type => 'ARRAY',
default => 'feed results_feed.tmpl',
},
'SearchSortBy' => undef,
'SearchSortOrder' => { default => 'ascend', },
'SearchNoOverride' => { default => 'SearchMaxResults', },
'SearchResultDisplay' => { alias => 'ResultDisplay', },
'SearchExcerptWords' => { alias => 'ExcerptWords', },
'SearchDefaultTemplate' => { alias => 'DefaultTemplate', },
'SearchMaxResults' => { alias => 'MaxResults', },
'SearchAltTemplate' => { alias => 'AltTemplate' },
'SearchSortBy' => undef,
'SearchContentDataSortBy' => {
default => sub { $_[0]->SearchSortBy }
},
'SearchSortOrder' => { default => 'ascend', },
'SearchNoOverride' => { default => 'SearchMaxResults', },
'SearchContentDataNoOverride' => {
default => sub { $_[0]->SearchNoOverride }
},
'SearchResultDisplay' => { alias => 'ResultDisplay', },
'SearchContentDataResultDisplay' => {
default => sub { $_[0]->SearchResultDisplay }
},
'SearchExcerptWords' => { alias => 'ExcerptWords', },
'SearchDefaultTemplate' => { alias => 'DefaultTemplate', },
'SearchContentDataDefaultTemplate' =>
{ default => 'content_data_default.tmpl' },
'SearchMaxResults' => { alias => 'MaxResults', },
'SearchContentDataMaxResults' => {
default => sub { $_[0]->SearchMaxResults }
},
'SearchAltTemplate' => { alias => 'AltTemplate' },
'SearchContentDataAltTemplate' => {
type => 'ARRAY',
default => 'feed content_data_results_feed.tmpl',
},
'SearchPrivateTags' => { default => 0 },
'DeepCopyRecursiveLimit' => { default => 2 },
'BulkLoadMetaObjectsLimit' => { default => 100 },
Expand All @@ -1931,12 +1962,22 @@ BEGIN {
'SignOnPublicKey' => { default => '', },
'ThrottleSeconds' => { default => 20, },
'SearchCacheTTL' => { default => 20, },
'SearchThrottleSeconds' => { default => 5 },
'SearchThrottleIPWhitelist' => undef,
'CMSSearchLimit' => { default => 125 },
'OneHourMaxPings' => { default => 10, },
'OneDayMaxPings' => { default => 50, },
'SupportURL' => {
'SearchContentDataCacheTTL' => {
default => sub { $_[0]->SearchCacheTTL }
},
'SearchThrottleSeconds' => { default => 5 },
'SearchContentDataThrottleSeconds' => {
default => sub { $_[0]->SearchThrottleSeconds }
},
'SearchThrottleIPWhitelist' => undef,
'SearchContentDataIPWhitelist' => {
default => sub { $_[0]->SearchThrottleIPWhitelist }
},
'SearchContentTypes' => undef,
'CMSSearchLimit' => { default => 125 },
'OneHourMaxPings' => { default => 10, },
'OneDayMaxPings' => { default => 50, },
'SupportURL' => {
default => 'http://www.sixapart.com/movabletype/support/',
},
'NewsURL' =>
Expand Down Expand Up @@ -2200,6 +2241,16 @@ BEGIN {
methods => sub { MT->app->core_methods() },
default => sub { MT->app->core_parameters() },
},
'cd_search' => {
handler => 'MT::App::Search::ContentData',
script => sub { MT->config->ContentDataSearchScript },
tags => sub {
require MT::Template::Context::Search;
return MT::Template::Context::Search->load_core_tags();
},
methods => sub { MT->app->core_methods() },
default => sub { MT->app->core_parameters() },
},
'cms' => {
handler => 'MT::App::CMS',
script => sub { MT->config->AdminScript },
Expand Down
30 changes: 29 additions & 1 deletion lib/MT/Template/Context/Search.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ sub load_core_tags {
SearchString => \&_hdlr_search_string,
SearchResultCount => \&_hdlr_result_count,
MaxResults => \&_hdlr_max_results,
SearchContentTypes => \&_hdlr_search_content_types,
SearchIncludeBlogs => \&_hdlr_include_blogs,
SearchTemplateID => \&_hdlr_template_id,
SearchTemplateBlogID => \&_hdlr_template_blog_id,
Expand Down Expand Up @@ -336,6 +337,8 @@ sub _hdlr_results {
if $this_object->can('blog');
local $ctx->{__stash}{blog_id} = $this_object->blog->id
if $this_object->can('blog') && $this_object->blog;
local $ctx->{__stash}{content_type} = $this_object->content_type
if $this_object->isa('MT::ContentData');
my $ts;
if ( $this_object->isa('MT::Entry') ) {
$ts = $this_object->authored_on;
Expand Down Expand Up @@ -415,12 +418,33 @@ sub _hdlr_results {
$output;
}

###########################################################################

=head2 SearchContentTypes
Used in the search result template to pass the SearchContentTypes parameters
through from the search form keeping the context of any followup search
the same as the initial search.
B<Example:>
<input type="hidden" name="SearchContentTypes" value="<$mt:SearchContenTypes$>" />
=for tags search
=cut

sub _hdlr_search_content_types {
my $ret = $_[0]->stash('search_content_types');
defined $ret ? $ret : '';
}

sub context_script {
my ( $ctx, $args, $cond ) = @_;

my $search_string = decode_html( $ctx->stash('search_string') );
my $cgipath = $ctx->invoke_handler( 'cgipath', $args );
my $script = $ctx->{config}->SearchScript;
my $script = $ctx->invoke_handler( 'searchscript', $args );
my $link = $cgipath . $script . '?search=' . encode_url($search_string);
if ( my $mode = $ctx->stash('mode') ) {
$mode = encode_url($mode);
Expand Down Expand Up @@ -462,6 +486,10 @@ sub context_script {
if ( my $format = $ctx->stash('format') ) {
$link .= '&format=' . encode_url($format);
}

my $content_field = $ctx->stash('search_content_field');
$link .= '&content_field=' . encode_url($content_field) if $content_field;

$link;
}

Expand Down
10 changes: 7 additions & 3 deletions lib/MT/Template/ContextHandlers.pm
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,7 @@ sub core_tags {
SearchMaxResults =>
'$Core::MT::Template::Tags::Search::_hdlr_search_max_results',
SearchIncludeBlogs => sub {''},
SearchContentTypes => sub {''},
SearchTemplateID => sub {0},
SearchTemplateBlogID => sub {0},

Expand Down Expand Up @@ -5590,16 +5591,19 @@ sub _hdlr_trackback_script {

=head2 SearchScript
Returns the value of the C<SearchScript> configuration setting. The
default for this setting if unassigned is "mt-search.cgi".
Returns the value of the C<SearchScript> or C<ContentDataSearchScript>
configuration setting. The default for this setting if unassigned is
"mt-search.cgi" or "mt-cdsearch.cgi".
=for tags configuration
=cut

sub _hdlr_search_script {
my ($ctx) = @_;
return $ctx->{config}->SearchScript;
return MT->instance->isa('MT::App::Search::ContentData')
? $ctx->{config}->ContentDataSearchScript
: $ctx->{config}->SearchScript;
}

###########################################################################
Expand Down
12 changes: 12 additions & 0 deletions mt-cdsearch.cgi
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/perl -w

# Movable Type (r) (C) 2001-2018 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 MT::Bootstrap App => 'MT::App::Search::ContentData';

Loading

0 comments on commit cd0de86

Please sign in to comment.