Revision [13276]
This is an old revision of SmiliesAction made by GiorgosKontopoulos on 2006-02-24 05:45:27.
New image action
This is a general purpose image action but since it was created out of the need to add emoticons or smilies in Wikka I named the page Smilies Action.
This new image action improves:
- simpler syntax (debatable you might say) - don't need to specify parameter names
- smaller code in database
- more readable (older version looks a lot like html code)
- don't need to remember image's extension or folder
- can be configured to add more image directories or image extensions
disadvantages:
- not standard way to pass and handle parameters (does this have any other implications)
- add more if like
Compare the two actions that result to the same thing.
the integrated image action:
the new image action:
Unknown action ""i""
here is the action save it as actions/i.php
<?php
/*
"i" action for icons, emoticons or any image
parameters are passed in the specific order (shown below) seperated by ; (semicolon)
(spaces are trimmed and quotes are not needed)
usage:
{{i src;title;link;class;alt}}
example :
{{i angry; I am angry; AngryPage; angryClass; angry image should display here}}
*/
// ? is there a better way to do this
foreach ($vars as $param => $value) {
list($src,$title,$link,$class,$alt)=explode(";",$value);
}
//icon dirs and extension to check
$iconDirs = array("smilies", "images");
$exts = array("gif","jpg","png");
if ($src == "") exit();
foreach($iconDirs as $idir){
foreach($exts as $ext){
$src2 =$idir."/".$src.".".$ext;
if(file_exists($src2)) break 2;
}
}
$output = "<img";
$output .= " src='".$src2."'";
$title = $this->htmlspecialchars_ent($title);
if (empty($link) && !empty($title)){ //if there is a link the title goes to the link
$output .= " title='".$title."'";
}
if (!empty($class))
$output .= " class='".$this->htmlspecialchars_ent($class)."'";
if (!empty($alt))
$output .= " alt='".$this->htmlspecialchars_ent($alt)."'";
else
$output .= " alt='".$title."'";
$output .= "/>";
if (!empty($link)) {
$output = $this->Link(trim($link), "", $output, 1, 0, $title);
}
$output = $this->ReturnSafeHTML($output);
print($output);
?>
/*
"i" action for icons, emoticons or any image
parameters are passed in the specific order (shown below) seperated by ; (semicolon)
(spaces are trimmed and quotes are not needed)
usage:
{{i src;title;link;class;alt}}
example :
{{i angry; I am angry; AngryPage; angryClass; angry image should display here}}
*/
// ? is there a better way to do this
foreach ($vars as $param => $value) {
list($src,$title,$link,$class,$alt)=explode(";",$value);
}
//icon dirs and extension to check
$iconDirs = array("smilies", "images");
$exts = array("gif","jpg","png");
if ($src == "") exit();
foreach($iconDirs as $idir){
foreach($exts as $ext){
$src2 =$idir."/".$src.".".$ext;
if(file_exists($src2)) break 2;
}
}
$output = "<img";
$output .= " src='".$src2."'";
$title = $this->htmlspecialchars_ent($title);
if (empty($link) && !empty($title)){ //if there is a link the title goes to the link
$output .= " title='".$title."'";
}
if (!empty($class))
$output .= " class='".$this->htmlspecialchars_ent($class)."'";
if (!empty($alt))
$output .= " alt='".$this->htmlspecialchars_ent($alt)."'";
else
$output .= " alt='".$title."'";
$output .= "/>";
if (!empty($link)) {
$output = $this->Link(trim($link), "", $output, 1, 0, $title);
}
$output = $this->ReturnSafeHTML($output);
print($output);
?>
You may also want to add a folder "smilies" and put your favorite smilies named with names easy to remember. In such a case you also need to add an .htaccess file in the "smilies" folder
<IfModule mod_rewrite.c>
RewriteEngine off
</IfModule>
RewriteEngine off
</IfModule>
Found also what seems like a bug in function Link in wikka.php. If the return comes from the last line of Link then no "title" attribute is being inserted. I have not completelly understood the logic of "Link", maybe there is a better way to solve this but anyway here is what worked.
changed:
function Link( ....
...
return $url ? "<a class=\"ext\" href=\"$url\">$text</a>$external_link_tail" : $text;
}
to:
(php)...
return $url ? "<a class=\"ext\" href=\"$url\">$text</a>$external_link_tail" : $text;
}
to:
function Link( ....
...
return $url ? "<a class=\"ext\" title=\"$title\" href=\"$url\">$text</a>$external_link_tail" : $text;
}
%%in wikka.php