Skip to content

Commit

Permalink
[#642 state:resolved] Added new config directives, `SupportDirectoryU…
Browse files Browse the repository at this point in the history
…RL` and `SupportDirectoryPath` which can be accessed through MT base class accessor methods, `support_directory_url()` and `support_directory_path()` and the template tag `mt:SupportDirectoryURL`
  • Loading branch information
jayallen committed Dec 5, 2010
1 parent cf60cfe commit cd0db37
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 0 deletions.
32 changes: 32 additions & 0 deletions lib/MT.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2330,6 +2330,26 @@ sub static_file_path {
return;
} ## end sub static_file_path

sub support_directory_url {
my $app = shift;
my $url = $app->config('SupportDirectoryURL')
|| MT::Util::caturl( $app->static_path, 'support' );
$url .= '/' unless substr( $url, -1, 1 ) eq '/';
return $url;
}

sub support_directory_path {
my $app = shift;
my $path = $app->config('SupportDirectoryPath')
|| File::Spec->catdir( $app->static_file_path, 'support');

$path = File::Spec->catdir( $app->path, $path )
unless File::Spec->file_name_is_absolute( $path );

$path .= '/' unless substr( $path, -1, 1 ) eq '/';
return $path;
}

sub template_paths {
my $mt = shift;
my @paths;
Expand Down Expand Up @@ -4342,6 +4362,18 @@ Returns the application's static web path.
Returns the application's static file path.
=head2 $app->support_directory_url()
Returns the URL to the static support directory. This can be set in the
mt-config.cgi with the SupportDirectoryURL directive. This method will always
return a value ending in a /
=head2 $app->support_directory_path()
Returns the file path to the static support directory. This can
be set in the mt-config.cgi with the SupportDirectoryPath directive. This method will always
return a value ending in a /
=head2 MT::core_upload_file_to_sync
A MT callback handler routine that forwards to the L<upload_file_to_sync>
Expand Down
2 changes: 2 additions & 0 deletions lib/MT/Core.pm
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ BEGIN {
'AssetAutoDirifyDelimiter' => { default => '-' },
'SearchTemplatePath' =>
{ default => 'search_templates', path => 1, },
'SupportDirectoryPath' => { default => '' },
'SupportDirectoryURL' => { default => '' },
'ObjectDriver' => undef,
'ObjectCacheLimit' => { default => 1000 },
'ObjectCacheDisabled' => undef,
Expand Down
17 changes: 17 additions & 0 deletions lib/MT/Template/ContextHandlers.pm
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ sub core_tags {
CGIHost => \&_hdlr_cgi_host,
StaticWebPath => \&_hdlr_static_path,
StaticFilePath => \&_hdlr_static_file_path,
SupportDirectoryURL => \&_hdlr_support_directory_url,
AdminScript => \&_hdlr_admin_script,
CommentScript => \&_hdlr_comment_script,
TrackbackScript => \&_hdlr_trackback_script,
Expand Down Expand Up @@ -6608,6 +6609,22 @@ sub _hdlr_static_path {

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

=head2 SupportDirectoryURL

The value of the C<SupportDirectoryURL> configuration setting. This value is
guaranteed to end with a "/" character.

=for tags configuration

=cut

sub _hdlr_support_directory_url {
my ($ctx) = @_;
return MT->instance->support_directory_url;
}

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

=head2 _get_script_location

An internal wrapper method around all of the "FooScript" config directives which supports two optional arguments:
Expand Down
16 changes: 16 additions & 0 deletions php/lib/MTUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,22 @@ function static_file_path() {
return $path;
}

function support_directory_url() {
global $mt;
$url = $mt->config('SupportDirectoryURL');
if ( ! $url) $url = static_path('') . 'support';
if ( ! preg_match('!/$!', $url) ) $url .= '/';
return $url;
}

function support_directory_path() {
global $mt;
$path = $mt->config('SupportDirectoryPath');
if ( ! $path ) $path = static_file_path() . 'support';
if ( ! preg_match('!/$!', $path) ) $path .= '/';
return $path;
}

function asset_path($path, $blog) {
$site_path = $blog['blog_site_path'];
$site_path = preg_replace('/\/$/', '', $site_path);
Expand Down
13 changes: 13 additions & 0 deletions php/lib/function.mtsupportdirectoryurl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
# Movable Type (r) Open Source (C) 2001-2010 Six Apart, Ltd.
# This program is distributed under the terms of the
# GNU General Public License, version 2.
#
# $Id: function.mtsupportdirectoryurl.php 5225 2010-01-27 07:14:14Z takayama $

function smarty_function_mtsupportdirectoryurl($args, &$ctx) {
require_once "MTUtil.php";
$url = support_directory_url();
return $url;
}
?>
54 changes: 54 additions & 0 deletions t/30-support-files.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/perl

use strict;
use warnings;
BEGIN {
use lib qw( lib extlib t/lib );
$ENV{MT_CONFIG} = 'sqlite-test.cfg';
$ENV{MT_APP} = 'MT::App::CMS';
}

use Test::More tests => 7;
use MT;
use MT::Test qw( :app :db );
use MT::Builder;
use MT::Template::Context;

my $app = MT::App::CMS->instance();
my $cfg = $app->config;

diag('Now testing default SupportDirectoryPath and SupportDirectoryURL');

is( $cfg->get('SupportDirectoryPath'), '',
'Default SupportDirectoryPath config'); #1

is( $cfg->get('SupportDirectoryURL'), '',
'Default SupportDirectoryURL config' ); #2

is( $app->support_directory_path(),
File::Spec->catdir( $app->static_file_path, 'support').'/',
'Default $app->support_directory_path()' ); #3

is( $app->support_directory_url(),
File::Spec->catdir($app->static_path, 'support').'/',
'Default $app->support_directory_url()' ); #4

diag('Now setting SupportDirectoryPath and SupportDirectoryURL');

$cfg->set('SupportDirectoryPath', '/PATH/TO/SOME/SUPPORT' );
$cfg->set('SupportDirectoryURL', 'http://example.com/PATH/TO/SOME/SUPPORT' );

is( $app->support_directory_path(),
'/PATH/TO/SOME/SUPPORT/',
'Updated $app->support_directory_path()' ); #5

is( $app->support_directory_url(),
'http://example.com/PATH/TO/SOME/SUPPORT/',
'Updated $app->support_directory_path()' ); #6

my $builder = MT::Builder->new;
my $ctx = MT::Template::Context->new;
my $tokens = $builder->compile( $ctx, '<$mt:SupportDirectoryURL$>' ); #7
is( $builder->build( $ctx, $tokens ),
$app->support_directory_url(),
'<$mt:SupportDirectoryURL$>' ); #7

0 comments on commit cd0db37

Please sign in to comment.