# Plugin for TWiki Collaboration Platform, http://TWiki.org/ # # Copyright (C) 2004-2005 Aurelio A. Heckert, aurium@gmail.com # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details, published at # http://www.gnu.org/copyleft/gpl.html # # ========================= # # This is an empty TWiki plugin. Use it as a template # for your own plugins; see TWiki.TWikiPlugins for details. # # Each plugin is a package that may contain these functions: VERSION: # # initPlugin ( $topic, $web, $user, $installWeb ) 1.000 # initializeUserHandler ( $loginName, $url, $pathInfo ) 1.010 # registrationHandler ( $web, $wikiName, $loginName ) 1.010 # commonTagsHandler ( $text, $topic, $web ) 1.000 # startRenderingHandler ( $text, $web ) 1.000 # outsidePREHandler ( $text ) 1.000 # insidePREHandler ( $text ) 1.000 # endRenderingHandler ( $text ) 1.000 # beforeEditHandler ( $text, $topic, $web ) 1.010 # afterEditHandler ( $text, $topic, $web ) 1.010 # beforeSaveHandler ( $text, $topic, $web ) 1.010 # writeHeaderHandler ( $query ) 1.010 Use only in one Plugin # redirectCgiQueryHandler ( $query, $url ) 1.010 Use only in one Plugin # getSessionValueHandler ( $key ) 1.010 Use only in one Plugin # setSessionValueHandler ( $key, $value ) 1.010 Use only in one Plugin # # initPlugin is required, all other are optional. # For increased performance, all handlers except initPlugin are # disabled. To enable a handler remove the leading DISABLE_ from # the function name. Remove disabled handlers you do not need. # # NOTE: To interact with TWiki use the official TWiki functions # in the TWiki::Func module. Do not reference any functions or # variables elsewhere in TWiki!! # ========================= package TWiki::Plugins::LinkOptionsPlugin; # change the package name and $pluginName!!! # ========================= use vars qw( $web $topic $user $installWeb $VERSION $RELEASE $pluginName $debug ); # This should always be $Rev: 11207 $ so that TWiki can determine the checked-in # status of the plugin. It is used by the build automation tools, so # you should leave it alone. $VERSION = '$Rev: 11207 $'; # This is a free-form string you can use to "name" your own plugin version. # It is *not* used by the build automation tools, but is reported as part # of the version number in PLUGINDESCRIPTIONS. $RELEASE = 'Dakar'; $pluginName = 'LinkOptionsPlugin'; # Name of this Plugin $numLastWinWithoutName = 0; # ========================= sub initPlugin { ( $topic, $web, $user, $installWeb ) = @_; # check for Plugins.pm versions if( $TWiki::Plugins::VERSION < 1 ) { TWiki::Func::writeWarning( "Version mismatch between $pluginName and Plugins.pm" ); return 0; } # Get plugin debug flag $debug = TWiki::Func::getPreferencesFlag( "\U$pluginName\E_DEBUG" ); # Plugin correctly initialized TWiki::Func::writeDebug( "- TWiki::Plugins::${pluginName}::initPlugin( $web.$topic ) is OK" ) if $debug; return 1; } # ========================= sub commonTagsHandler { ### my ( $text, $topic, $web ) = @_; # do not uncomment, use $_[0], $_[1]... instead TWiki::Func::writeDebug( "- ${pluginName}::commonTagsHandler( $_[2].$_[1] )" ) if $debug; # This is the place to define customized tags and variables # Called by sub handleCommonTags, after %INCLUDE:"..."% # do custom extension rule, like for example: $_[0] =~ s/\[\[([^]\n]+)\]\[([^]\n]+)\]\[([^]]+)\]\]/&handleLinkOptions($1, $2, $3)/ge; } # ========================= @preDefOptions = ( 'newwin', 'name', 'title', 'class', 'id', 'skin' ); @winOptions = ( 'directories', 'location', 'menubar', 'resizable', 'scrollbars', 'status', 'titlebar', 'toolbar' ); sub handleLinkOptions { my ( $link, $text, $options ) = @_; my %extraOpts = (); my $style = ''; my $extraAtt = ''; my @sepOpt; my $html = TWiki::Func::renderText("[[$link][$text]]"); $options =~ s/win([^:|]+):([^|]+)(\||$)/$1=:$2$3/g; my @options = split(/\|/, $options); foreach $option (@options){ @sepOpt = split(/:/, $option); if ( in_array(lc($sepOpt[0]), @preDefOptions) || in_array(lc($sepOpt[0]), @winOptions) ){ $extraOpts{lc($sepOpt[0])} = $sepOpt[1]; } else{ $style .= "$option; "; } } if ( $extraOpts{'skin'} ){ if ( $html =~ m/^]*href="[^"]*\?[^"]*skin=.+/ ){ $html =~ s/^]*href="[^"]*\?[^"]*skin=)[^&"]*(.+)/]*href="[^"]*\?.+/ ){ $html =~ s/^]*href="[^"]*\?)(.+)/]*href="[^"]*)"(.+)/]*)target="[^"]*"([^>]*)>(.+)/$3/; #" $html =~ s/^]*title=.+/ ){ $html =~ s/^]*)title="[^"]*"([^>]*)>(.+)/$3/; #" } else { $html =~ s/^]*)>(.+)/$2/; } } if ( $extraOpts{'class'} ){ if ( $html =~ m/^]*title=.+/ ){ $html =~ s/^]*)class="[^"]*"([^>]*)>(.+)/$3/; #" } else { $html =~ s/^]*)>(.+)/$2/; } } if ( $extraOpts{'id'} ){ if ( $html =~ m/^]*id=.+/ ){ $html =~ s/^]*)id="[^"]*"([^>]*)>(.+)/$3/; #" } else { $html =~ s/^]*)>(.+)/$2/; } } $html =~ s/