Changeset 1333
- Timestamp:
- 01/23/08 08:06:50 (7 months ago)
- Files:
-
- branches/release-29/build/mt-dists/default.mk (modified) (1 diff)
- branches/release-29/lib/MT/Author.pm (modified) (2 diffs)
- branches/release-29/lib/MT/Core.pm (modified) (1 diff)
- branches/release-29/lib/MT/Template/ContextHandlers.pm (modified) (3 diffs)
- branches/release-29/lib/MT/Upgrade.pm (modified) (1 diff)
- branches/release-29/lib/MT/Util.pm (modified) (1 diff)
- branches/release-29/lib/MT/WeblogPublisher.pm (modified) (1 diff)
- branches/release-29/php/lib/block.mtarchivelist.php (modified) (1 diff)
- branches/release-29/php/lib/block.mtauthornext.php (modified) (2 diffs)
- branches/release-29/php/lib/block.mtauthorprevious.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/release-29/build/mt-dists/default.mk
r1194 r1333 2 2 3 3 PRODUCT_VERSION = 4.1 4 SCHEMA_VERSION = 4.003 64 SCHEMA_VERSION = 4.0037 5 5 API_VERSION = 4.1 6 6 branches/release-29/lib/MT/Author.pm
r1174 r1333 36 36 'auth_type' => 'string(255)', 37 37 'userpic_asset_id' => 'integer', 38 'basename' => 'string(255)', 38 39 }, 39 40 defaults => { … … 210 211 my $auth = shift; 211 212 212 if ((!$auth->id) && ($auth->type == AUTHOR)) { 213 # New author, undefined API password. Generate one. 214 if (!defined $auth->api_password) { 215 my @pool = ('a'..'z', 0..9); 216 my $pass = ''; 217 for (1..8) { $pass .= $pool[ rand @pool ] } 218 $auth->api_password($pass); 213 if ($auth->type == AUTHOR) { 214 if (!$auth->id) { 215 # New author, undefined API password. Generate one. 216 if (!defined $auth->api_password) { 217 my @pool = ('a'..'z', 0..9); 218 my $pass = ''; 219 for (1..8) { $pass .= $pool[ rand @pool ] } 220 $auth->api_password($pass); 221 } 219 222 } 223 # Generate basename 224 my $basename = MT::Util::make_unique_author_basename($auth); 225 $auth->basename($basename); 220 226 } 221 227 branches/release-29/lib/MT/Core.pm
r1242 r1333 496 496 'UserpicMaxUpload' => { default => 0 }, 497 497 'UserpicThumbnailSize' => { default => 100 }, 498 499 # Basename settings 500 'AuthorBansenameLimit' => { default => 30 }, 498 501 }, 499 502 upgrade_functions => \&load_upgrade_fns, branches/release-29/lib/MT/Template/ContextHandlers.pm
r1308 r1333 285 285 AuthorNext => \&_hdlr_author_prev_next, 286 286 AuthorPrevious => \&_hdlr_author_prev_next, 287 AuthorBasename => \&_hdlr_author_basename, 287 288 288 289 BlogID => \&_hdlr_blog_id, … … 2366 2367 } 2367 2368 my %f = ( 2368 'a' => "<MTAuthor DisplayName $dir>",2369 '-a' => "<MTAuthor DisplayName dirify='-'>",2370 '_a' => "<MTAuthor DisplayName dirify='_'>",2369 'a' => "<MTAuthorBasename $dir>", 2370 '-a' => "<MTAuthorBasename dirify='-'>", 2371 '_a' => "<MTAuthorBasename dirify='_'>", 2371 2372 'b' => "<MTEntryBasename $sep>", 2372 2373 '-b' => "<MTEntryBasename separator='-'>", … … 3150 3151 local $ctx->{__stash}{asset} = $asset; 3151 3152 $builder->build($ctx, $tok, { %$cond }); 3153 } 3154 3155 sub _hdlr_author_basename { 3156 my $author = $_[0]->stash('author') 3157 or return $_[0]->_no_author_error('MTAuthorBasename'); 3158 my $name = $author->basename; 3159 $name = MT::Util::make_unique_author_basename($author) if !$name; 3160 return $name; 3152 3161 } 3153 3162 branches/release-29/lib/MT/Upgrade.pm
r1256 r1333 776 776 $blog->page_layout($layout); 777 777 $blog->save; 778 }, 779 }, 780 }, 781 'core_set_author_basename' => { 782 version_limit => 4.0037, 783 priority => 3.2, 784 updater => { 785 type => 'author', 786 label => 'Assigning author basename...', 787 condition => sub { 788 $_[0]->type == 1; 789 }, 790 code => sub { 791 my ($author) = @_; 792 my $basename = MT::Util::make_unique_author_basename($author); 793 $author->basename($basename); 794 $author->save; 778 795 }, 779 796 }, branches/release-29/lib/MT/Util.pm
r1233 r1333 910 910 } 911 911 912 sub make_unique_author_basename { 913 my ($author) = @_; 914 my $name = MT::Util::dirify($author->nickname); 915 return "author" . $author->id if $name !~ /\w/; 916 917 my $limit = MT->instance->config('AuthorBasenameLimit'); 918 $limit = 15 if $limit < 15; $limit = 250 if $limit > 250; 919 my $base = substr($name, 0, $limit); 920 $base =~ s/_+$//; 921 my $i = 1; 922 my $base_copy = $base; 923 924 my $author_class = ref $author; 925 while ($author_class->count({ basename => $base })) { 926 $base = $base_copy . '_' . $i++; 927 } 928 $base; 929 } 930 912 931 sub archive_file_for { 913 932 MT->instance->publisher->archive_file_for(@_); branches/release-29/lib/MT/WeblogPublisher.pm
r1254 r1333 2898 2898 return "" unless $this_author; 2899 2899 2900 my $name = dirify( $this_author->nickname );2901 $name = "author" . $this_author->id if $name !~ /\w/;2902 2900 if ( !$file_tmpl ) { 2903 $file = sprintf( "%s/index", $ name );2901 $file = sprintf( "%s/index", $this_author->basename ); 2904 2902 } 2905 2903 $file; branches/release-29/php/lib/block.mtarchivelist.php
r1308 r1333 2 2 require_once "archive_lib.php"; 3 3 function smarty_block_mtarchivelist($args, $content, &$ctx, &$repeat) { 4 $localvars = array('current_archive_type', 'current_timestamp', 'current_timestamp_end', 'entries', 'archive_count', '_archive_list_num', '_archive_list_results','entry','ArchiveListHeader', 'ArchiveListFooter', 'inside_archive_list', 'category' );4 $localvars = array('current_archive_type', 'current_timestamp', 'current_timestamp_end', 'entries', 'archive_count', '_archive_list_num', '_archive_list_results','entry','ArchiveListHeader', 'ArchiveListFooter', 'inside_archive_list', 'category', 'author'); 5 5 global $_archivers; 6 6 7 if (!isset($content)) { 7 8 require_once("archive_lib.php"); branches/release-29/php/lib/block.mtauthornext.php
r1174 r1333 9 9 static $_next_cache = array(); 10 10 if (!isset($content)) { 11 $ctx->localize(array('author', 'conditional', 'else_content')); 11 $next_author = null; 12 $ctx->localize(array('author')); 12 13 $author = $ctx->stash('author'); 13 14 if ($author) { … … 25 26 'need_entry' => 1); 26 27 list($next_author) = $ctx->mt->db->fetch_authors($args); 27 if ($next_author) $_next_cache[$author_id] = $next_author; 28 if ($next_author) { 29 $_next_cache[$author_id] = $next_author; 30 $ctx->stash('author', $next_author); 31 } else 32 $repeat = false; 28 33 } 29 $ctx->stash('author', $next_author); 34 } else { 35 $repeat = false; 30 36 } 31 $ctx->stash('conditional', isset($next_author));32 $ctx->stash('else_content', null);33 37 } else { 34 if (!$ctx->stash('conditional')) { 35 $content = $ctx->stash('else_content'); 36 } 37 $ctx->restore(array('author', 'conditional', 'else_content')); 38 $ctx->restore(array('author')); 38 39 } 39 40 return $content; branches/release-29/php/lib/block.mtauthorprevious.php
r1174 r1333 9 9 static $_prev_cache = array(); 10 10 if (!isset($content)) { 11 $ctx->localize(array('author', 'conditional', 'else_content')); 11 $prev_author = null; 12 $ctx->localize(array('author')); 12 13 $author = $ctx->stash('author'); 13 14 if ($author) { … … 25 26 'need_entry' => 1); 26 27 list($prev_author) = $ctx->mt->db->fetch_authors($args); 27 if ($prev_author) $_prev_cache[$author_id] = $prev_author; 28 if ($prev_author) { 29 $_prev_cache[$author_id] = $prev_author; 30 $ctx->stash('author', $prev_author); 31 } else 32 $repeat = false; 28 33 } 29 $ctx->stash('author', $prev_author);30 34 } 31 $ctx->stash('conditional', isset($prev_author));32 $ctx->stash('else_content', null);33 35 } else { 34 if (!$ctx->stash('conditional')) { 35 $content = $ctx->stash('else_content'); 36 } 37 $ctx->restore(array('author', 'conditional', 'else_content')); 36 $ctx->restore(array('author')); 38 37 } 39 38 return $content;
