Changeset 104
- Timestamp:
- 07/07/05 01:58:04 (3 years ago)
- Files:
-
- tagwire/trunk/README.txt (modified) (3 diffs)
- tagwire/trunk/tagwire.pl (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
tagwire/trunk/README.txt
r100 r104 151 151 --------------------- 152 152 153 A container tag for listing tags for a entry. It can only be used in153 A container tag for listing tags for an entry. It can only be used in 154 154 "entry context" which means "the inside of MTEntries" or Individual 155 155 Archives. … … 189 189 </MTEntries> 190 190 191 ----------------------- 192 MTRelatedTags Container 193 ----------------------- 194 195 A container tag for listing tags *related* to the current tag. The 196 relationship between tags is defined by how many common *entries* 197 includes them. This container can only be used in "tag context" which 198 means the inside of MTTags or MTEntryTags. 199 200 * Option(s): 201 202 glue="glue" 203 204 Separates each of the tags with a string specified by "glue". 205 This is useful when you wish to separate the tag names with a 206 comma, for example. 207 208 sort_by="tag|tag-case|count" 209 210 Chooses sorting method for tags. "tag" means case-insensitive 211 alphabetical sort, "tag-case" means case-sensitive alphabetical 212 sort, "count" means sort by tag's count. Default setting is "tag". 213 214 sort_order="ascend|descend" 215 216 Chooses sorting order. The default sort_order is "ascend". 217 218 lastn="N" 219 220 Shows only last N tags. By default, all tags are displayed. 221 222 case_sensitive="0|1" 223 224 Chooses whether the plugin treats tags as the case-sensitive 225 manner or not. The default is case_sensitive="1". 226 227 * Available tags in this container: 228 229 <$MTTag$> 230 Shows a tag. 231 232 <$MTTagCount$> 233 Shows the appearance count of a tag. 234 235 * Example: 236 237 To list tags of the entries and their related tags, and to link all of them to Technorati: 238 239 <MTEntries lastn="10"> 240 <h2><$MTEntryTitle$></h2> 241 242 <ul> 243 <MTEntryTags> 244 <li><a href="http://www.technorati.com/tag/<$MTTag encode_url="1"$>" 245 rel="TAG" title="TAG:<$MTTag$>"><$MTTag$></a> 246 <ul> 247 <MTRelatedTags> 248 <li><a href="http://www.technorati.com/tag/<$MTTag encode_url="1"$>" 249 rel="TAG" title="TAG:<$MTTag$>"><$MTTag$></a></li> 250 </MTRelatedTags> 251 </ul> 252 </li> 253 </MTEntryTags> 254 </ul> 255 256 <$MTEntryBody$> 257 </MTEntries> 258 191 259 --------------------------- 192 260 MTEntriesWithTags Container … … 282 350 </MTEntries> 283 351 352 ----------------------- 353 MTXSearchTags Container 354 ----------------------- 355 356 A container tag for listing the query string of MT-XSearch as tags. 357 It can only be used in "MT-XSearch" Template. 358 359 * Option(s): 360 361 glue="glue" 362 363 Separates each of the tags with a string specified by "glue". 364 This is useful when you wish to separate the tag names with a 365 comma, for example. 366 367 * Available tags in this container: 368 369 <$MTTag$> 370 Shows a tag. 371 372 <$MTTagCount$> 373 Shows the appearance count of a tag. 374 375 * Example: 376 377 To list tags given by the query string of MT-XSearch and their related tags, and to link them to Technorati: 378 379 <MTXSearchTags> 380 <h2><$MTTag$></h2> 381 382 <ul> 383 <MTRelatedTags> 384 <li><a href="http://www.technorati.com/tag/<$MTTag encode_url="1"$>" 385 rel="TAG" title="TAG:<$MTTag$>"><$MTTag$></a></li> 386 </MTRelatedTags> 387 </ul> 388 </MTXSearchTags> 389 284 390 --------------------- 285 391 encode_urlplus Filter tagwire/trunk/tagwire.pl
r102 r104 28 28 author_name => 'Hirotaka Ogawa', 29 29 author_link => 'http://profile.typekey.com/ogawa/', 30 version => '0.2 3'30 version => '0.24' 31 31 }); 32 32 MT->add_plugin($plugin); … … 90 90 MT::Template::Context->add_container_tag('Tags' => \&tags); 91 91 MT::Template::Context->add_container_tag('EntryTags' => \&entry_tags); 92 MT::Template::Context->add_container_tag('RelatedTags' => \&related_tags); 92 93 MT::Template::Context->add_tag('Tag' => \&tag); 93 94 MT::Template::Context->add_tag('TagCount' => \&tag_count); … … 287 288 push @res, $out; 288 289 } 290 my $glue = $args->{glue} || ''; 291 join $glue, @res; 292 } 293 294 sub related_tags { 295 my ($ctx, $args, $cond) = @_; 296 my $tag = $ctx->stash('Tagwire::tag') or return ''; 297 my $tag_count = $ctx->stash('Tagwire::tag_count'); 298 299 my $sort_by = $args->{sort_by} || 'tag'; 300 # sort_order (ascend/descend, default = ascend) 301 my $sort_order = $args->{sort_order} || 'ascend'; 302 # lastn (default = 0, no cutoff) 303 my $lastn = $args->{lastn} || 0; 304 # case_sensitive (0/1, default = 1) 305 my $case_sensitive = defined $args->{case_sensitive} ? 306 $args->{case_sensitive} : 1; 307 308 my $blog_id = $ctx->stash('blog_id'); 309 my %tags = (); 310 311 my $data = get_pd_indexes($blog_id) || get_db_indexes($blog_id) 312 or return ''; 313 my %tindex = %{$data->{tindex}}; 314 my %eindex = %{$data->{eindex}}; 315 if ($case_sensitive) { 316 foreach my $eid (@{$tindex{$tag}}) { 317 foreach my $mtag (@{$eindex{$eid}->{tags}}) { 318 $tags{$mtag} = exists $tags{$mtag} ? $tags{$mtag} + 1 : 1; 319 } 320 } 321 delete $tags{$tag}; 322 } else { 323 $tag = lc $tag; 324 foreach my $nctag (grep { lc $_ eq $tag } keys %tindex) { 325 foreach my $eid (@{$tindex{$nctag}}) { 326 foreach $_ (@{$eindex{$eid}->{tags}}) { 327 my $mtag = lc $_; 328 $tags{$mtag} = exists $tags{$mtag} ? $tags{$mtag} + 1 : 1; 329 } 330 } 331 } 332 delete $tags{$tag}; 333 } 334 my @list; 335 if ($sort_by eq 'tag' || $sort_by eq 'keyword' ) { 336 @list = $sort_order eq 'ascend' ? 337 sort { lc $a cmp lc $b } keys %tags : 338 sort { lc $b cmp lc $a } keys %tags; 339 } elsif ($sort_by eq 'tag-case' || $sort_by eq 'keyword-case') { 340 @list = $sort_order eq 'ascend' ? 341 sort keys %tags : 342 sort reverse keys %tags; 343 } else { 344 @list = $sort_order eq 'ascend' ? 345 sort { $tags{$a} <=> $tags{$b} } keys %tags : 346 sort { $tags{$b} <=> $tags{$a} } keys %tags; 347 } 348 349 my @res; 350 my $builder = $ctx->stash('builder'); 351 my $tokens = $ctx->stash('tokens'); 352 my $i = 0; 353 foreach (@list) { 354 last if $lastn && $i >= $lastn; 355 $ctx->stash('Tagwire::tag', $case_sensitive ? $_ : ucfirst $_); 356 $ctx->stash('Tagwire::tag_count', $tags{$_}); 357 defined(my $out = $builder->build($ctx, $tokens)) 358 or return $ctx->error($ctx->errstr); 359 push @res, $out; 360 $i++; 361 } 362 $ctx->stash('Tagwire::tag', $tag); 363 $ctx->stash('Tagwire::tag_count', $tag_count); 364 289 365 my $glue = $args->{glue} || ''; 290 366 join $glue, @res; … … 352 428 my $count = scalar @patterns; 353 429 my @eids = grep { $match{$_} == $count } keys %match or return; 354 @eids = sort { $eindex{$b}->{created_on} <=> $eindex{$a}->{created_on} } @eids;355 430 @eids = $sort_order eq 'descend' ? 356 431 sort { $eindex{$b}->{created_on} <=> $eindex{$a}->{created_on} } @eids : … … 477 552 }; 478 553 554 MT::Template::Context->add_container_tag('XSearchTags' => \&xsearch_tags); 555 sub xsearch_tags { 556 my ($ctx, $args, $cond) = @_; 557 my $r = MT::Request->instance; 558 return '' unless defined $r->cache('Tagwire::xsearch_tags'); 559 my @tags = @{$r->cache('Tagwire::xsearch_tags')}; 560 my @res; 561 my $builder = $ctx->stash('builder'); 562 my $tokens = $ctx->stash('tokens'); 563 foreach (@tags) { 564 $ctx->stash('Tagwire::tag', $_); 565 defined(my $out = $builder->build($ctx, $tokens)) 566 or return $ctx->error($ctx->errstr); 567 push @res, $out; 568 } 569 my $glue = $args->{glue} || ''; 570 join $glue, @res; 571 } 572 479 573 sub xsearch_on_stash { 480 574 $_[0]->stash('entry', $_[1]); … … 497 591 or return \@results; 498 592 593 my $r = MT::Request->instance; 594 $r->cache('Tagwire::xsearch_tags', \@patterns); 595 499 596 my $data = get_pd_indexes($blog_id) || get_db_indexes($blog_id) 500 597 or return \@results;
