Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: Jeremy Blackman on July 09, 2013, 05:12:27 PM

Title: Problem with image rotation script executing
Post by: Jeremy Blackman on July 09, 2013, 05:12:27 PM
Our site (xixax.com) has two image rotation scripts in the header. They have been working fine forever, but they studdenly stopped working right. When viewed on the forum, they get "stuck" on one image. However, the scripts are intact and work fine when viewed separately:

xixax.com/header_words/
xixax.com/header_caps/

Everyone seems to be having the same problem. The pair of images you get stuck with is random.

Could this be related to a hacking attempt? (We have not changed any files ourselves recently.) I haven't found anything obvious. Can someone give me a better idea of where to look in the FTP?
Title: Re: Problem with image rotation script executing
Post by: TheListener on July 09, 2013, 07:53:32 PM
Were the scripts manually added or used within an installed mod?
Title: Re: Problem with image rotation script executing
Post by: Jeremy Blackman on July 09, 2013, 08:08:22 PM
They were manually added years ago. The person who did that work is no longer an administrator or member, so that's about the extent of my knowledge on how it was done.
Title: Re: Problem with image rotation script executing
Post by: Colin on July 09, 2013, 09:54:56 PM
It is working just fine. The reason the images are not rotating when you click to another page on your forum is because your browser is caching the images. In other words your browser is downloading the image to your computer and saving so it doesn't have to pull another copy online when you load a webpage that uses it again.

There are a few techniques around it. One is to us meta tags to control the browser cache. Unfortunately this is not a very reliable way as it can sometimes be ignored


header("Pragma-directive: no-cache");
    header("Cache-directive: no-cache");
    header("Cache-control: no-cache");
    header("Pragma: no-cache");
    header("Expires: 0");


Another way is adding a random get parameter to the img src URL. It won't affect the php image chooser, but it will make the browser think it is a different image so the browser won't pull from the cached record.
Title: Re: Problem with image rotation script executing
Post by: TheListener on July 09, 2013, 09:57:38 PM
http://custom.simplemachines.org/mods/index.php?mod=2847

Hows this Colin?
Title: Re: Problem with image rotation script executing
Post by: Colin on July 09, 2013, 10:01:09 PM
Nice find, Mr. Fossil. That would work, but it doesn't look like it allows you to select multiple random header images to be displayed at the same time. If you do use this method, though, it would eliminate the need to even use your PHP rotator script.
Title: Re: Problem with image rotation script executing
Post by: TheListener on July 09, 2013, 10:04:10 PM
Quoteselect multiple random header images

Maybe if the images were made into one using gimp or similar?
Title: Re: Problem with image rotation script executing
Post by: Colin on July 09, 2013, 10:05:37 PM
Well if it was one image it would have to have a transparent center, or the same color of the theme header background, and span the width of the entire header. That would be quite a large image and would take some unnecessary time to download. I can't say I would recommend that, but it sure is a valid thought.
Title: Re: Problem with image rotation script executing
Post by: Jeremy Blackman on July 09, 2013, 11:25:11 PM
Interesting. I thought it might be a cache thing, but it suddenly started happening for everyone at exactly the same time. Why on earth would something like this suddenly surface after years of working? Could it possibly be Go Daddy causing a problem? (We switched to them 4 or 5 months ago.)

I located the file where the script is executed... themes/default/index.template.php

I don't see any malicious code, and the script appears to be intact. Here is the script:

<script language="JavaScript"><!--
var now1 = new Date();
if (document.images) {
  document.images.myImageName1.src = 'http://xixax.com/header_caps/index.php?' + now1.getTime();
}
//--></script><script language="JavaScript"><!--
var now2 = new Date();
if (document.images) {
  document.images.myImageName2.src = 'http://xixax.com/header_words/index.php?' + now2.getTime();
}
//--></script>
<img src="http://xixax.com/images/rightheadtopbot.gif" ALIGN="right" />
<img src="http://xixax.com/header_words/index.php" name="myImageName2" ALIGN="right" />
<img src="http://xixax.com/header_caps/index.php" name="myImageName1" ALIGN="right" />
Title: Re: Problem with image rotation script executing
Post by: Colin on July 10, 2013, 02:01:26 AM
Aha! Who ever wrote the javascript was smart enough to implement the second method I mentioned, but via the clientside, javascript.

The reason why this is not working is because the javascript is being executed prior to the <img> tags being loaded. If you upload your index.template.php I will fix it and upload the correct version.
Title: Re: Problem with image rotation script executing
Post by: Jeremy Blackman on July 10, 2013, 09:56:44 AM
Excellent! Here it is...
Title: Re: Problem with image rotation script executing
Post by: Jeremy Blackman on July 17, 2013, 07:16:46 PM
Is anyone able to help with that script? Any help would be greatly appreciated!
Title: Re: Problem with image rotation script executing
Post by: Colin on July 17, 2013, 07:58:54 PM
Woops. Sorry. I totally forgot about this. I am making the change now.
Title: Re: Problem with image rotation script executing
Post by: Colin on July 17, 2013, 08:01:13 PM
Try this

Title: Re: Problem with image rotation script executing
Post by: Jeremy Blackman on July 17, 2013, 11:08:27 PM
I got this error:


Template Parse Error!

There was a problem loading the /Themes/default/index.template.php template or language file. Please check the syntax and try again - remember, single quotes (') often have to be escaped with a slash (\). To see more specific error information from PHP, try accessing the file directly.

You may want to try to refresh this page or use the default theme.

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in .../Themes/default/index.template.php on line 666

657: implode('', $buttons), '
658: </ul>
659: </div>';
660: }
661: echo '
662:
663: <script language="JavaScript"><!--
664: var now1 = new Date();
665: if (document.images) {
666:   document.images.myImageName1.src = 'http://xixax.com/header_caps/index.php?' + now1.getTime();
667: }
668: //--></script><script language="JavaScript"><!--
669: var now2 = new Date();
670: if (document.images) {
Title: Re: Problem with image rotation script executing
Post by: Kindred on July 18, 2013, 01:24:01 AM
Unescaped single quotes in that javascript  are causing the echo statement to prematurely abort.
Title: Re: Problem with image rotation script executing
Post by: Colin on July 18, 2013, 02:27:16 AM
Woops I didn't catch those nasty little single quotes. Give this one a try
Title: Re: Problem with image rotation script executing
Post by: Jeremy Blackman on July 18, 2013, 10:06:00 AM
Hmm. Unfortunately that didn't fix the script, and it created a little gap between each image and made text larger. Screenshot attached.
Title: Re: Problem with image rotation script executing
Post by: Jeremy Blackman on August 13, 2013, 07:35:53 PM
Can anyone help with this?
Title: Re: Problem with image rotation script executing
Post by: Jeremy Blackman on August 21, 2013, 05:52:21 PM
Someone completely rewrote the rotation script that's in index.template.php, and that fixed it.