Simple Machines Community Forum

Customizing SMF => Graphics and Templates => Topic started by: loplo on March 10, 2012, 05:48:40 AM

Title: Adding counter script to footer
Post by: loplo on March 10, 2012, 05:48:40 AM
Hey guys,
I'm trying to add this code to my footer and I can't make it.
<!--/Start async trafic.ro/-->
<script type="text/javascript" id="trfc_trafic_script">
//<![CDATA[
t_rid = 'fly-ra-com';
(function(){ t_js_dw_time=new Date().getTime();
t_js_load_src=((document.location.protocol == 'http:')?'http://storage.':'https://secure.')+'trafic.ro/js/trafic.js?tk='+(Math.pow(10,16)*Math.random())+'&t_rid='+t_rid;
if (document.createElement && document.getElementsByTagName && document.insertBefore) {
t_as_js_en=true;var sn = document.createElement('script');sn.type = 'text/javascript';sn.async = true; sn.src = t_js_load_src;
var psn = document.getElementsByTagName('script')[0];psn.parentNode.insertBefore(sn, psn); } else {
document.write(unescape('%3Cscri' + 'pt type="text/javascript" '+'src="'+t_js_load_src+';"%3E%3C/sc' + 'ript%3E')); }})();
//]]>
</script>
<noscript><p><a href="http://www.trafic.ro/statistici/forum.fly-ra.com"><img alt="forum.fly-ra.com" src="http://log.trafic.ro/cgi-bin/pl.dll?rid=fly-ra-com" /></a> <a href="http://www.trafic.ro/">Web analytics</a></p></noscript>
<!--/End async trafic.ro/-->


I've edited index.template.php, tried to insert he code before </body> or after template_body_below() and I'm getting: syntax error, unexpected T_STRING, expecting ',' or ';'

What to do?
I know there are some mods out there, but I'm not passing the test while installing and I'm afraid to mess around with the code.

Any help appreciated.
Title: Re: Adding counter script to footer
Post by: Aleksi "Lex" Kilpinen on March 10, 2012, 05:53:48 AM
You need to make sure you escape all single quotes in the code. So change all ' to \'
Title: Re: Adding counter script to footer
Post by: loplo on March 10, 2012, 06:02:18 AM
So my code became:
<!--/Start async trafic.ro/-->
<script type="text/javascript" id="trfc_trafic_script">
//<![CDATA[
t_rid = '\fly-ra-com'\;
(function(){ t_js_dw_time=new Date().getTime();
t_js_load_src=((document.location.protocol == '\http:'\)?'\http://storage.'\:'\https://secure.'\)+'\trafic.ro/js/trafic.js?tk='\+(Math.pow(10,16)*Math.random())+'\&t_rid='\+t_rid;
if (document.createElement && document.getElementsByTagName && document.insertBefore) {
t_as_js_en=true;var sn = document.createElement('\script'\);sn.type = '\text/javascript'\;sn.async = true; sn.src = t_js_load_src;
var psn = document.getElementsByTagName('\script'\)[0];psn.parentNode.insertBefore(sn, psn); } else {
document.write(unescape('\%3Cscri'\ + '\pt type="text/javascript" '\+'\src="'\+t_js_load_src+'\;"%3E%3C/sc'\ + '\ript%3E'\)); }})();
//]]>
</script>
<noscript><p><a href="http://www.trafic.ro/statistici/forum.fly-ra.com"><img alt="forum.fly-ra.com" src="http://log.trafic.ro/cgi-bin/pl.dll?rid=fly-ra-com" /></a> <a href="http://www.trafic.ro/">Web analytics</a></p></noscript>
<!--/End async trafic.ro/-->


I've inserted the code before </body> and no joy, still getting the error.
Did I change to much? Did I put the code it in to the wrong place?
Title: Re: Adding counter script to footer
Post by: Aleksi "Lex" Kilpinen on March 10, 2012, 06:04:22 AM
' becomes \' not '\ like you did there ;)
Title: Re: Adding counter script to footer
Post by: loplo on March 10, 2012, 06:16:29 AM
My bad.
It really works! Thanks for helping me out.
Title: Re: Adding counter script to footer
Post by: Aleksi "Lex" Kilpinen on March 10, 2012, 06:18:43 AM
You're welcome :)