Ripcurl
|
| Posted: 04/22/2003, 7:02 PM |
|
Working on a blog section for a website (ie shoutbox) and i've got everything working right, but need help on trying to fine tune a function.
I need to fine tune a piece of js so that it works correctly. Many people are familiar with forums and their clickable smilies, and I've got the jist of it down, but need help in making it come out correctly
My current JS is this:
<script language="javascript">
<!--
function writeImgTag(code)
{
var cache = document.blog_add.shout.value;
this.code = code;
document.blog_add.shout.value = cache + " <img src='smilies/" + code + ".gif'> ";
document.blog_add.shout.focus();
}
//-->
</script>
<a name="smilies"></a>
<a href="#smilies" onClick="writeImgTag('bluebigeek')" ><img src="smilies/bluebigeek.gif" border=0></a>
So per this code, in the Shout "textbox" it will fill in <img src='smilies/bluebigeek.gif'> and one can write their message in the textbox.
Now, how can i change it so that instead of writing out the entire <img src> tag, it will use normal smilie codes (ie :) or ;) or ;P ) and put that in the shoutbox, then as its added to the DB replace these smiley codes with their corresponding <img src> tags. Would that be on the "before insert" event?
Working with PHP + Templates and CC 2.0.5 .
This is the only piece of code that I need, and I think it would be useful for others to use.
|
|
|
 |
RonB
|
| Posted: 04/23/2003, 4:47 AM |
|
Hi,
I think you'll have to use a beforeinsert event and use the str_replace function php offers combined with an if/else construction:
let's say the user oput this in the textbox:
have a nice day 
=>
global $record;
$record->textbox->setvalue(str_replace(" ","<img src='smilies/bluebigeek.gif'> ",$record->textbox->Value));
would result in : have a nice day <img src='smilies/bluebigeek.gif'>
Now copy the code and replce the with the next text and the <img src='smilies/bluebigeek.gif'> with the next <img src> tag until you've civered all the possibilities.
Ron
|
|
|
 |
RipCurl
|
| Posted: 04/23/2003, 12:43 PM |
|
Thanks for the code,
Now. to add salt to the wound.
Since Im only allowing 255 characters to be posted total, right now, I have the coding putting in the whole <img src=" '' "> tag into the db, so of course instead of inserting the entire image source tag, is it possible to just store the " ;) " equivalent and when the grid is displayed show the corresponding smilie?
Ie
user put in
Have a nice day :)
Insert into DB will be
Have a nice day :)
But when the grid shows the message it should show
Have a nice day <img src="smilie.gif"> (showing the actual smilie)
A mod of your script should work on th Before show event maybe?
And I have 240 smilies, so how would i start up a str_replace array?
|
|
|
 |
RipCurl
|
| Posted: 04/23/2003, 2:05 PM |
|
Okay, this is rough but, I have a function like this:
function textsmilies($text) {
$emoticon = array(
":)" => "<img src='smilies/smile.gif' alt='' align='absmiddle'>",
" " => "<img src='smilies/sad.gif' alt='' align='absmiddle'>",
";)" => "<img src='smilies/smilewinkgrin.gif' alt='' align='absmiddle'>",
":|" => "<img src='smilies/none.gif' alt='' align='absmiddle'>",
" " => "<img src='smilies/smile.gif' alt='' align='absmiddle'>",
" " => "<img src='smilies/sad.gif' alt='' align='absmiddle'>",
" " => "<img src='smilies/smilewinkgrin.gif' alt='' align='absmiddle'>",
" " => "<img src='smilies/none.gif' alt='' align='absmiddle'>",
":0" => "<img src='smilies/bigeek.gif' alt='' align='absmiddle'>",
"B)" => "<img src='smilies/cool.gif' alt='' align='absmiddle'>",
":D" => "<img src='smilies/biggrin.gif' alt='' align='absmiddle'>",
":P" => "<img src='smilies/bigrazz.gif' alt='' align='absmiddle'>",
":B" => "<img src='smilies/bigrazz.gif' alt='' align='absmiddle'>",
"B-)" => "<img src='smilies/cool.gif' alt='' align='absmiddle'>",
" " => "<img src='smilies/biggrin.gif' alt='' align='absmiddle'>",
" " => "<img src='smilies/bigrazz.gif' alt='' align='absmiddle'>",
":O" => "<img src='smilies/bigeek.gif' alt='' align='absmiddle'>",
"b)" => "<img src='smilies/cool.gif' alt='' align='absmiddle'>",
":d" => "<img src='smilies/biggrin.gif' alt='' align='absmiddle'>",
":p" => "<img src='smilies/bigrazz.gif' alt='' align='absmiddle'>",
":b" => "<img src='smilies/bigrazz.gif' alt='' align='absmiddle'>",
"b-)" => "<img src='smilies/cool.gif' alt='' align='absmiddle'>",
":-d" => "<img src='smilies/biggrin.gif' alt='' align='absmiddle'>",
":-p" => "<img src='smilies/bigrazz.gif' alt='' align='absmiddle'>",
":-b" => "<img src='smilies/bigrazz.gif' alt='' align='absmiddle'>",
":o" => "<img src='smilies/bigeek.gif' alt='' align='absmiddle'>",
"o_O" => "<img src='smilies/bigeek.gif' alt='' align='absmiddle'>",
"O_o" => "<img src='smilies/bigeek.gif' alt='' align='absmiddle'>",
"o_o" => "<img src='smilies/bigeek.gif' alt='' align='absmiddle'>",
"O_O" => "<img src='smilies/bigeek.gif' alt='' align='absmiddle'>",
":cool:" => "<img src='smilies/cool.gif' alt='' align='absmiddle'>",
);
foreach ($emoticon as $code => $image) {
$text = str_replace($code, $image, $text);
}
return $text;
}
Question is:
Would I put the function that i have above in the "Global Functions" of the Modules and in the Before Show event place th "foreach" section for that grid?
|
|
|
 |
RipCurl
|
| Posted: 04/23/2003, 2:19 PM |
|
Woohoo!! got it to work!
Just place the function in the open events of the page.
In the grid's before show event, used the function on that particular field:
$fldshout = textimages($fldshout);
And that did the trick!
If anyone wants a basic blog for php + templates for CC, post and I'll try to supply the code for it.
|
|
|
 |
ripcurl
|
| Posted: 04/23/2003, 2:28 PM |
|
Oops meant
$fldshout= textsmilies($fldshout);
|
|
|
 |
|