Previous Thread
Next Thread
Print Thread
Hop To
#128530 04/29/2006 3:52 PM
Joined: Apr 2006
Posts: 116
F
member
member
F Offline
Joined: Apr 2006
Posts: 116
Is possible.

First you need to collect 800 graemlins and rename them so that the graemlin name matches filename, for example graemlin for :happydance: should be happydance.gif (all lower case)

upload them to the images/graemlins directory

then you need to index them all and put 'em in the javascript array.

First make subdirectory jscripts in ubbthreads directory

Here is the perl script to automate it:
Code
#!/usr/bin/perl

$path_to_tas = "/yourfullscriptpath/ubbthreads/images/graemlins/";

print "Content-type: text/html\n\n";
open FS, "ls $path_to_tas|";
@all_ = <FS>;
close FS;

@relevant_ = sort {lc($a) cmp lc($b)}(grep (/\.gif$/i, @all_));

open SF, ">/yourfullscriptpath/ubbthreads/jscripts/graemlins_array.js";
print SF "dl=new Array();\n";

$g_counter=0;

foreach $smile_ (@relevant_){
chomp ($smile_);
$sname = $smile_;
$sname =~ s/\.gif//;

print SF "dl[$g_counter]='$sname';\n";
$g_counter++;
}

close SF;

print "Done!";
exit;

This will create graemlins_array.js file in jscripts directory and fill it something like:

dl=new Array();
dl[0]='aak';
dl[1]='abduction';
dl[2]='admin';
dl[3]='afro';
dl[4]='agent';
dl[5]='agree';
dl[6]='airbaloon';
.....


make another file in the same directory and call it graemlins_select.js. The content of this file:

Code
gpath='/ubbthreads/images/graemlins/';
current='';
d='';



skip = new Array();

for(f=0;f<document.replier.instant.length;f++){skip[document.replier.instant[f].src.split('.gif')[0].split(gpath)[1]]='omit';}


grandom=dl[Math.round(Math.random()*dl.length)];

d+='<table cellpadding="0" cellspacing="0"><tr><td><br /><br /><br /><select class="formboxes" name="egselect" onchange="ShowSmiley(this.options[this.selectedIndex].value);">\n';
d+='<option selected value="'+grandom+'"> Extra Graemlins\n';

for(i=0;i<dl.length;i++){
     if (skip[dl[i]] == 'omit') {d+='';}
     else {d+='<option value="'+dl[i]+'"> :'+dl[i]+':\n';}
}

d+='</select>  ► <br /><br /><br />\n';
d+='</td><td><img id="egimg" src="'+gpath+grandom+'.gif" style="cursor:pointer; cursor:hand;" onclick="AddIt(current)" alt=":'+grandom+':" title=":'+grandom+':" /></td></tr></table>\n';


document.write(d);

function ShowSmiley(i){

document.getElementById('egimg').src=gpath+i+'.gif';
document.getElementById('egimg').alt=':'+i+':';
document.getElementById('egimg').title=':'+i+':';
current=i;
}

function AddIt(sm){
insertAtCaret(document.replier.Body, ' :'+sm+':');
document.replier.Body.focus();
}

Now you need to call these scripts from ubbt_instant_ubbcode.tmpl template:

add
Code
<script type="text/javascript" src="http://yoursite/ubbthreads/jscripts/graemlins_array.js"></script>
<script type="text/javascript" src="http://yoursite/ubbthreads/jscripts/graemlins_select.js"></script>
after

$graemlinlist

Now a little modification needs to be done to the ubbt_inc.php

replace
Code
$graemlinlist .= <<<EOF
				<a href="javascript:void(0)" onclick="insertAtCaret(document.replier.Body, ' $code'); document.replier.Body.focus();"><img  src="{$config['images']}/graemlins/$image" border="0" alt="$altcode" title="$altcode" /></a>   
EOF;
with
Code
$graemlinlist .= <<<EOF
				<a href="javascript:void(0)" onclick="insertAtCaret(document.replier.Body, ' $code'); document.replier.Body.focus();"><img name="instant" src="{$config['images']}/graemlins/$image" border="0" alt="$altcode" title="$altcode" /></a>   
EOF;


add

Code
$Body = preg_replace('/<img.*?src="\/ubbthreads\/images\/graemlins\/(\w+)\.gif" \/>/', ':$1:', $Body);

AFTER

Code
$Body = str_replace("<img src=\"{$config['images']}/graemlins/$image\" alt=\"\" />","$string",$Body);


then add

Code
                         	if (preg_match_all ("/:(\w+):/i",$Body,$matches,PREG_PATTERN_ORDER)){
                                     $m_length = count($matches[1]);
                                     for ($m=0;$m<$m_length;$m++){
                                          $file_to_check = $matches[1][$m];
                                        if (!file_exists("/usr/home/web/users/a0004302/html/snew/ubbthreads/images/graemlins/".$matches[1][$m].".gif")){
                                          $Body = str_replace(":".$matches[1][$m].":","[".$matches[1][$m]."]",$Body);
                                        } else {
                                          $Body = str_replace(":".$matches[1][$m].":","<img border=\"0\" alt=\"[".$matches[1][$m]."]\" title=\"".$matches[1][$m]."\" src=\"/ubbthreads/images/graemlins/".$matches[1][$m].".gif\" />",$Body);
                                        }                                     
                                     }                                
                                 }	


AFTER

Code
else {
				@eval("\$string = $code;");
				$string = preg_quote($string,'/');
				$Body = preg_replace("/(:|\[)$string(:|\])/i","<img src=\"{$config['images']}/graemlins/$image\" alt=\"\" />",$Body);
			}
		}



I think this is it.

What it does is it loads all the graemlins you have in the <select>element less the instant graemlins displayed and shows the clickable image when you select a graemlin from the list.

Any of the extra graemlins could be used as normal ones

:extragraemlin:

ubbt_inc modication is for converting ubb code to html code and back.

The last bit: IF YOU DO NOT FULLY UNDERSTAND HOW THE ABOVE MODIFICATION WORKS DO NOT TRY IT!!!

Last edited by fatalpapercut; 04/29/2006 3:55 PM.
#128531 04/29/2006 4:09 PM
Joined: Dec 2003
Posts: 1,798
Likes: 2
Pooh-Bah
Pooh-Bah
Joined: Dec 2003
Posts: 1,798
Likes: 2
looks like a nice modification <img src="https://www.ubbcentral.com/boards/images/graemlins/smile.gif" alt="" />


- Allen
- ThreadsDev | PraiseCafe
#128532 04/30/2006 10:08 PM
Joined: Apr 2006
Posts: 116
F
member
member
F Offline
Joined: Apr 2006
Posts: 116
Slightly improved graemlins_select.js

Code

gpath='/ubbthreads/images/graemlins/';
d='';


skip = new Array();

for(f=0;f&lt;document.replier.instant.length;f++){skip[document.replier.instant[f].src.split('.gif')[0].split(gpath)[1]]='omit';}


grandom=dl[Math.round(Math.random()*dl.length)];
if (skip[grandom] == 'omit'){grandom = 'wave';}
current=grandom;

d+='&lt;table cellpadding="0" cellspacing="0"&gt;&lt;tr&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;select class="formboxes" name="egselect" onchange="ShowSmiley(this.options[this.selectedIndex].value);"&gt;\n';
d+='&lt;option selected value="'+grandom+'"&gt; Extra Graemlins\n';

for(i=0;i&lt;dl.length;i++){
     if (skip[dl[i]] == 'omit') {d+='';}
     else {d+='&lt;option value="'+dl[i]+'"&gt; :'+dl[i]+':\n';}
}

d+='&lt;/select&gt; &amp;nbsp;&lt;b&gt;&amp;gt;&amp;gt;&lt;/b&gt;&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;\n';

d+='&lt;/td&gt;&lt;td&gt;&lt;img id="egimg" src="'+gpath+grandom+'.gif" style="cursor:pointer; cursor:hand;" onclick="AddIt(current)" alt=":'+grandom+':" title=":'+grandom+':" /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;\n';


document.write(d);

document.replier.egselect.options[0].selected = "true";

function ShowSmiley(i){

document.getElementById('egimg').src=gpath+i+'.gif';
document.getElementById('egimg').alt=':'+i+':';
document.getElementById('egimg').title=':'+i+':';
current=i;
}

function AddIt(sm){
insertAtCaret(document.replier.Body, ' :'+sm+':');
document.replier.Body.focus();
}


Link Copied to Clipboard
ShoutChat
Comment Guidelines: Do post respectful and insightful comments. Don't flame, hate, spam.
Recent Topics
PHP 8 bug in membermanage.tmpl
by phoenix011235 - 09/08/2026 7:47 PM
Are any of these legitmate?
by Baldeagle - 09/06/2026 1:37 PM
After server reboot
by Morgan - 09/02/2026 8:27 AM
8.0.1 Patch Changelog Discussion
by isaac - 11/26/2025 1:34 PM
Who's Online Now
1 members (Rick Gardner), 283 guests, and 175 robots.
Key: Admin, Global Mod, Mod
Random Gallery Image
Latest Gallery Images
Ride safe!
Ride safe!
by Morgan, December 7
Los Angeles
Los Angeles
by isaac, August 6
3D Creations
3D Creations
by JAISP, December 30
Artistic structures
Artistic structures
by isaac, August 29
Powered by UBB.threads™ PHP Forum Software 8.1.0
(Snapshot build 20260527)