--- /Data/Projects_Arthur/TWiki Subversion/twiki/lib/TWiki/Render.pm 2005-04-29 23:15:18.000000000 +0200 +++ /Data/Projects_Arthur/TWiki Subversion/TWiki patches/MyRender.pm 2005-04-30 13:43:21.000000000 +0200 @@ -724,11 +724,14 @@ ---++ ObjectMethod filenameToIcon ( $fileName ) -> $html -Produce an image tailored to the type of the file, guessed from -its extension. - -used in TWiki::handleIcon +Fetches an image file from an image directory, mapped from _filetypes.txt (on basis of the file extension). Calls _getSkinIconTopicPath to get the attachment topic path from preference variable ICONTOPIC. +Prerequisites: + - ICONTOPIC must be defined, as Web.TopicName or as TopicName (then %WEB%.TopicName is used) + - The file _filetypes.txts hould be in the same directory as the image attachments + +used in: Attach::_expandAttrs + =cut sub filenameToIcon { @@ -737,10 +740,11 @@ my @bits = ( split( /\./, $fileName ) ); my $fileExt = lc $bits[$#bits]; - - my $iconDir = $TWiki::cfg{PubDir}.'/icn'; - my $iconUrl = $TWiki::cfg{PubUrlPath}.'/icn'; + + my $iconUrl = $TWiki::cfg{PubUrlPath}.'/'.$this->_getSkinIconTopicPath(); + my $iconDir = $TWiki::cfg{PubDir}.'/'.$this->_getSkinIconTopicPath(); my $store = $this->{session}->{store}; + # The file _filetypes.txt should be in the same directory as the image attachments my $iconList = $store->readFile( $iconDir.'/_filetypes.txt' ); foreach( split( /\n/, $iconList ) ) { @bits = ( split( / / ) ); @@ -750,13 +754,60 @@ alt => '', border => 0 } ); } } - return CGI::img( { src => "$iconUrl/else.gif", + return CGI::img( { src => "$iconUrl/_else.gif", width => 16, height => 16, align => 'top', alt => '', border => 0 } ); } =pod +---++ ObjectMethod getDocGraphic ( $fileName ) -> $html + +Fetches an image file from a topic attachment directory. Calls _getSkinIconTopicPath to get the attachment topic path from preference variable ICONTOPIC. + +Prerequisites: + - ICONTOPIC must be defined, as Web.TopicName or as TopicName (then %WEB%.TopicName is used) + +used in: TWiki::_ICON + +=cut + +sub getDocGraphic { + my( $this, $fileName ) = @_; + ASSERT(ref($this) eq 'TWiki::Render') if DEBUG; + + my $iconUrl = $TWiki::cfg{PubUrlPath}.'/'.$this->_getSkinIconTopicPath(); + return CGI::img( { src => $iconUrl.'/'.$fileName.'.gif', + align => 'top', alt => '', border => 0 } ); +} + +=pod + +---++ ObjectMethod _getSkinIconTopicPath ( ) -> $skinIconTopicPath + +Reads the variable ICONTOPIC from the preferences, and returns a relative file path (url) to this topic. Web.TopicName becomes Web/TopicName; TopicName becomes %WEB%.TopicName. + +=cut + +sub _getSkinIconTopicPath { + my( $this ) = @_; + my $session = $this->{session}; + my $prefs = $session->{prefs}; + my $web = $session->{webName}; + my $skinIconTopicPath = $prefs->getPreferencesValue('ICONTOPIC'); + # Remove whitespace at end + $skinIconTopicPath =~ s/\s*$//s; + # If there is no dot in $skinIconTopicPath, no web has been specified; use the local web + if ( index( $skinIconTopicPath, '.' ) == -1 ) { + $skinIconTopicPath = $web.'.'.$skinIconTopicPath; + } + # Replace dot in Web.TopicName with slash to get the path: Web/TopicName + $skinIconTopicPath =~ s/\./\//; + return $skinIconTopicPath; +} + +=pod + ---++ ObjectMethod renderFormField ( %params, $topic, $web ) -> $html Returns the fully rendered expansion of a %FORMFIELD{}% tag.