andre88uk
10-25-2004, 07:01 PM
hiya guys...and gals.
I am coding a forum (not doing bad) but want to make code so that if a user typed something like:
/wink yes please
it would print [br]
<img src="$images/emoticons/wink.gif> yes please
but obviously with the image instead of the code.
i also want to display the images(i can figurew that out) and make it so that when they are writing the post they click the images and it inserts the correct code into the message body.
Cheers in advance,
Andre88uk
kevin
10-25-2004, 09:12 PM
the first part is simple substitution, but I suggest you use something besides the forward slash, use [wink] or :wink: something like that, I'll post an example with []
$string =~ s/\[wink\]/<img src="$images\/emoticons\/wink\.gif">/gi;
you have to escape [] with backslashes (\[wink\]) because they are character class delimiters and will be treated as such if not escaped.
the i option forces the regexp to be noncase sensitive ([wink] and [WINK] would be the same) and the g option forces the regexp to substitue all occurrences of the pattern within the same string.
The second half of your question is a javascript question (clicking and inserting into message).
andre88uk
10-26-2004, 05:50 AM
okay so how do i get the code into the script i already have.
it is sumat like <input type="text" size="30" maxvalue="100" value="~ &killhtml($post=>param='message') qq~ />
kevin
10-26-2004, 02:02 PM
Originally posted by andre88uk
okay so how do i get the code into the script i already have.
it is sumat like <input type="text" size="30" maxvalue="100" value="~ &killhtml($post=>param='message') qq~ />
well, make it a sub routine and pass the arguements to the sub routine. First get your input from the form, then pass it to a sub routine:
my $message = &killhtml($post=>param('message'));
sub killhtml {
my $message = shift;
$message =~ s/\[wink\]/<img src="$images\/emoticons\/wink\.gif">/gi;
return $message;
}
exactly how you do it is up to you. Probably easiest to use a hash of some sort that stores the name of the smiley and its html converted equivalent as the value of the hash:
%smilies = (
'[wink]' => '<img src="$images\/emoticons\/wink\.gif">',
'[sad]' => '<img src="$images\/emoticons\/sad\.gif">',
etc
etc
etc
);
kevin
10-26-2004, 04:17 PM
I dug out some code I wrote a while back for a webhosting type script. One part of the script would list files in a folder and display the appropriate icon, just like most apache directory tree lists do. In the head scetion of the script there is a hash that has the icon associated with the file type:
local %filetypes = (
'zip' => 'archive',
'tar' => 'archive',
'gz' => 'archive',
'ace' => 'archive',
'rar' => 'archive',
'cab' => 'archive',
'bin' => 'archive',
'htm' => 'html',
'html' => 'html',
'shtm' => 'html',
'shtml' => 'html',
'xml' => 'html',
'gif' => 'image',
'jpg' => 'image',
'jpeg' => 'image',
'png' => 'image',
'art' => 'image',
'bmp' => 'image',
'mpeg' => 'movie',
'mpg' => 'movie',
'mov' => 'movie',
'avi' => 'movie',
'wmv' => 'movie',
'asf' => 'movie',
'mid' => 'sound',
'wav' => 'sound',
'ra' => 'sound',
'ram' => 'sound',
'mp3' => 'sound',
'm3u' => 'sound',
'txt' => 'text'
);
now in the script while the directory list is generated it calls the sub routine to associate the icon with the file type:
&get_icons if $functions{'use_icons'} == 1;
sub get_icons {
@ext=split(/\./,$file_name);#get the file extension
$ext = lc(pop(@ext));#in case there is more than one dot in the filename we want the very last one
$ft = $filetypes{$ext} || 'unknown';#see if it exists, if not assign it a default icon
# now plug in the html
$file_icon = qq~<img src="$config{'root_url'}/images/$ft.gif" width="16" height="18" alt="$ft file" title="$ft file" vspace="0" align="middle">~;
}
Something like this would work well for a smiley replacement although it would not be as dynamic as say this forum, since you can add smilies on the fly withoiut having to edit any script variables. But you could do that with your forum, it would just take more effort to figure out how.
There are so many good forum scripts already coded, why are you doing this? Is it for fun and learning?
vBulletin® v3.6.7, Copyright ©2000-2010, Jelsoft Enterprises Ltd.