This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-03-22 17:04:07

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Check for antidote code in your signatures!

I was experimenting with new PHP code when I came across a function that allowed me to neatly check whether the page you are currently viewing contains unparsed antidote code.

For those who are unaware of the whole thing, the Scratch Team has taken down images a while ago, so a user-contributed plugin called Antidote was introduced (developed by rookwood101 with some contribution from my part) to counter the loss of images.

However, only users who have antidote installed are able to see any images posted on the forums. Those without the plugin will see ugly [img] tags in text. Therefore I have come up with code to check the page for antidote code, and appropriately recommend the user to install Antidote to view the images and videos.

I would suggest that anyone who uses the img tags often should put this simple code into your signature, so that people are aware that they need to download antidote to view your posts. The beauty of this is that if the page contains no images, it displays a smaller and more peaceful reminder to download antidote anyway  tongue

Use this code in your signatures:

[url=http://scratch.mit.edu/forums/viewtopic.php?id=85229][img]http://modshare.tk/misc/antidote.php?antidoteexists=false[/img][/url]

Furthermore, if you wish to have a bigger image in your signature, please use the parameter "big" in the URL. For example, add &big=both at the end.

For those of you who have antidote you can see what the result is:
http://modshare.tk/misc/antidote.php?antidoteexists=false

Of course, depending on the page, the image will vary. Have fun using it!

Last edited by LS97 (2012-03-27 12:40:38)

Offline

 

#2 2012-03-22 17:17:02

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: Check for antidote code in your signatures!

Can you open-source this? It looks interesting.


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#3 2012-03-22 17:23:40

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Check for antidote code in your signatures!

bobbybee wrote:

Can you open-source this? It looks interesting.

Sure! I'll do it tomorrow when I'm on my other computer.
Meanwhile, if it helps, I mainly used the REFERER superglobal to check out the page the user was on, and then simply looked for traces of unparsed BBCode  wink  It's relatively short code.

Offline

 

#4 2012-03-22 17:48:59

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: Check for antidote code in your signatures!

I see...
Wait, how would it detect anti-dote if they're are no images?


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#5 2012-03-22 18:08:36

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Check for antidote code in your signatures!

bobbybee wrote:

I see...
Wait, how would it detect anti-dote if they're are no images?

It doesn't detect antidote, it detects whether the page needs antidote or not. To detect the actual antidote I would have to use JS too (which I cannot, from a PHP image).

Offline

 

#6 2012-03-22 18:38:53

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: Check for antidote code in your signatures!

LS97 wrote:

bobbybee wrote:

I see...
Wait, how would it detect anti-dote if they're are no images?

It doesn't detect antidote, it detects whether the page needs antidote or not. To detect the actual antidote I would have to use JS too (which I cannot, from a PHP image).

Makes sense, I suppose.


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#7 2012-03-22 19:51:52

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Check for antidote code in your signatures!

That is pretty neat! I would love to have a look at the code for it and I think this is a pretty neat usage of dynamic signatures! I might add it to my API thread as a link at some point  smile

How does antidote change page HTML? Perhaps antidote could be detected by checking for [img ] tags? If there are no [img ] tags it would mean either there are no images, or antidote is installed and has replaced all the tags with <img> tags?


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#8 2012-03-22 19:57:26

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: Check for antidote code in your signatures!

sparks wrote:

That is pretty neat! I would love to have a look at the code for it and I think this is a pretty neat usage of dynamic signatures! I might add it to my API thread as a link at some point  smile

How does antidote change page HTML? Perhaps antidote could be detected by checking for [img ] tags? If there are no [img ] tags it would mean either there are no images, or antidote is installed and has replaced all the tags with <img> tags?

Maybe it could load the page and detect [img] tags. If there is, check if there is [img] tags in the page. That way it would actually know.


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#9 2012-03-23 07:42:42

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Check for antidote code in your signatures!

sparks,

The problem/aspect I came across during the testing is that the image, being a PHP one, cannot check the contents of the page the user is on. That would mean a big security hole for any browser! Therefore I had to get the page server-side only to check if the original contained BBCode -- not whether it had been parsed.

Javascript is essential to check the user's side, and unfortunately JS cannot be injected through images. I had been thinking about linking to a page that contained img tags, so that the user could check whether their browser effectively supported Antidote, but of course antidote only parses the code if it's on the scratch forums.

I hope that makes sense, because it doesn't to me  tongue

Offline

 

#10 2012-03-23 07:50:34

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Check for antidote code in your signatures!

As promised yesterday, here's the source code!

Code:

<?php
// Check if page contains antidote
$ref = $_SERVER['HTTP_REFERER'];
if(strstr($ref, 'scratch.mit.edu/forums/viewtopic.php')) {
    // Check for unconverted [img], youtube, and project tags
    $page = file_get_contents($ref);
    if(strstr($page, '[img]') || strstr($page, '[youtube]') || strstr($page, '[scratch=flash]')) {
        // There is unparsed antidote on the page!
        $filename = '2';
    } else {
        // Either the page has no antidote or the code has been parsed already
        $filename = '3';
    }
} else {
    // View this image on a scratch site!
    $filename = '1';
}

// start making image
$img = imagecreatefrompng('anti' . $filename . '.png');
//alert browser about content
header('Content-type: image/png');
//create image
imagepng($img);
?>

The $filename bit just determines which image to display. Then the code later displays the appropriate one!

Offline

 

#11 2012-03-23 07:55:39

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Check for antidote code in your signatures!

Haha, antidote has converted most of that code to images  tongue  I'd better quote it to read.

How about making an antidote update so that antidote also checks for img tags on a page on your server? That might then be readable.

That is surprisingly simple to code! It takes brains to work out it can be done though, well done!

Last edited by sparks (2012-03-23 07:58:26)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#12 2012-03-23 08:04:24

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Check for antidote code in your signatures!

?

I'm using Antidote but the image still pops up...


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#13 2012-03-23 08:26:36

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Check for antidote code in your signatures!

Hardmath123 wrote:

?

I'm using Antidote but the image still pops up...

Yes, as I explained it the post to sparks, the image can only check whether there is BBCode, not whether the code has been parsed or not!

Offline

 

#14 2012-03-23 08:32:47

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Check for antidote code in your signatures!

sparks wrote:

Haha, antidote has converted most of that code to images  tongue  I'd better quote it to read.

How about making an antidote update so that antidote also checks for img tags on a page on your server? That might then be readable.

That is surprisingly simple to code! It takes brains to work out it can be done though, well done!

That's weird -- I have antidote installed, but the code looks fine to me. Do you have the latest fixed version? I tried talking to rookwood about this, but his Skype habits aren't exactly top-etiquette...

I tried to avoid antidote updating since so many people will not have the latest version. Of course, that could be seen as a plus, because those with older versions would still be prompted to install! Additionally, the new version could automatically remove my "missing plugin" images. Unfortunately I will have to talk to rookwood about that.

And yes, this is my favourite kind of coding. Not too difficult code-wise, easy to debug, but that requires thinking!  smile

Offline

 

#15 2012-03-23 08:37:19

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Check for antidote code in your signatures!

Ah, you see I didn't know that there was an antidote update! I shall go download it  tongue

What you need is a way to detect the version  tongue  Does the firefox addon system allow for AJAX? You could use that to send the version number to a php file that checks to see if a newer version is avaliable and display a message with an update link?

By the way, if you're more of a PHPer like me, you might like this little function I built for Javascript to simulate PHP's file_get_contents():

Code:

function file_get_contents(url){
    if(window.XMLHttpRequest){
        request = new XMLHttpRequest();
    }
    else if(window.ActiveXObject){
        request = new ActiveXObject("Microsoft.XMLHTTP");
    }
    request.open("GET", url, false);
    request.send(null);
    return request.responseText;
}

It just lets me use AJAX in a method I'm more familiar with  tongue

EDIT: Updated, that's better  tongue

Last edited by sparks (2012-03-23 08:38:39)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#16 2012-03-23 08:48:27

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Check for antidote code in your signatures!

sparks wrote:

Ah, you see I didn't know that there was an antidote update! I shall go download it  tongue

What you need is a way to detect the version  tongue  Does the firefox addon system allow for AJAX? You could use that to send the version number to a php file that checks to see if a newer version is avaliable and display a message with an update link?

By the way, if you're more of a PHPer like me, you might like this little function I built for Javascript to simulate PHP's file_get_contents():

Code:

function file_get_contents(url){
    if(window.XMLHttpRequest){
        request = new XMLHttpRequest();
    }
    else if(window.ActiveXObject){
        request = new ActiveXObject("Microsoft.XMLHTTP");
    }
    request.open("GET", url, false);
    request.send(null);
    return request.responseText;
}

It just lets me use AJAX in a method I'm more familiar with  tongue

EDIT: Updated, that's better  tongue

Nice function  big_smile
I do believe Firefox is just about as permissive as Chrome in its addons. It would probably be simpler, however, to actually inject the version into the JS using PHP beforehand, and then the javascript would simply have to run an equality test!

Offline

 

#17 2012-03-23 15:47:02

lallaway12
Scratcher
Registered: 2012-01-04
Posts: 500+

Re: Check for antidote code in your signatures!

cool make it say

img uploading...

anidite finding imgs


http://i49.tinypic.com/2re4ied.png

Offline

 

#18 2012-03-23 17:32:34

Servine
Scratcher
Registered: 2011-03-19
Posts: 1000+

Re: Check for antidote code in your signatures!

I gave antidote the name antidote  big_smile

Yup, me! Well, rookwood basically did all the work, but I gave it the name  big_smile


http://bluetetrarpg.x10.mx/usercard/?name=Servine

Offline

 

#19 2012-03-23 18:03:08

rookwood101
Scratcher
Registered: 2011-07-29
Posts: 500+

Re: Check for antidote code in your signatures!

sparks wrote:

Ah, you see I didn't know that there was an antidote update! I shall go download it  tongue

What you need is a way to detect the version  tongue  Does the firefox addon system allow for AJAX? You could use that to send the version number to a php file that checks to see if a newer version is avaliable and display a message with an update link?

By the way, if you're more of a PHPer like me, you might like this little function I built for Javascript to simulate PHP's file_get_contents():

Code:

function file_get_contents(url){
    if(window.XMLHttpRequest){
        request = new XMLHttpRequest();
    }
    else if(window.ActiveXObject){
        request = new ActiveXObject("Microsoft.XMLHTTP");
    }
    request.open("GET", url, false);
    request.send(null);
    return request.responseText;
}

It just lets me use AJAX in a method I'm more familiar with  tongue

EDIT: Updated, that's better  tongue

Wouldn't it be better to do:

Code:

function file_get_contents(url){
    if(window.XMLHttpRequest){
        request = new XMLHttpRequest();
    }
    else if(window.ActiveXObject){
        request = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else {
        return false;
    }
    request.open("GET", url, false);
    request.send(null);
    return request.responseText;
}

That way if neither method exists (I have no idea when that would be true, but hey  smile  ) it still works and doesn't error - or at least it errors nicely.

I suppose that through my use of compiled languages as opposed to interpreted languages, I have learned that error handling is of great importance  smile  - otherwise it just crashes.

Last edited by rookwood101 (2012-03-23 18:04:21)


http://i.imgur.com/zeIZW.png

Offline

 

#20 2012-03-23 20:35:41

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Check for antidote code in your signatures!

Thanks! I barely understand AJAX's connection code, hence my function, so this improvement is very useful, thanks!

Will it return a specific message if the client cannot use AJAX?


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#21 2012-03-24 03:55:02

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Check for antidote code in your signatures!

rookwood101 wrote:

sparks wrote:

Ah, you see I didn't know that there was an antidote update! I shall go download it  tongue

What you need is a way to detect the version  tongue  Does the firefox addon system allow for AJAX? You could use that to send the version number to a php file that checks to see if a newer version is avaliable and display a message with an update link?

By the way, if you're more of a PHPer like me, you might like this little function I built for Javascript to simulate PHP's file_get_contents():

Code:

function file_get_contents(url){
    if(window.XMLHttpRequest){
        request = new XMLHttpRequest();
    }
    else if(window.ActiveXObject){
        request = new ActiveXObject("Microsoft.XMLHTTP");
    }
    request.open("GET", url, false);
    request.send(null);
    return request.responseText;
}

It just lets me use AJAX in a method I'm more familiar with  tongue

EDIT: Updated, that's better  tongue

Wouldn't it be better to do:

Code:

function file_get_contents(url){
    if(window.XMLHttpRequest){
        request = new XMLHttpRequest();
    }
    else if(window.ActiveXObject){
        request = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else {
        return false;
    }
    request.open("GET", url, false);
    request.send(null);
    return request.responseText;
}

That way if neither method exists (I have no idea when that would be true, but hey  smile  ) it still works and doesn't error - or at least it errors nicely.

I suppose that through my use of compiled languages as opposed to interpreted languages, I have learned that error handling is of great importance  smile  - otherwise it just crashes.

Wait, hold on: this only works with local files, right? (I mean files on the same server) I thought this was a JS safety feature...  hmm

Last edited by Hardmath123 (2012-03-24 03:55:18)


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#22 2012-03-24 10:53:49

lallaway12
Scratcher
Registered: 2012-01-04
Posts: 500+

Re: Check for antidote code in your signatures!

Cool


http://i49.tinypic.com/2re4ied.png

Offline

 

#23 2012-03-24 15:07:16

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Check for antidote code in your signatures!

Hardmath123 wrote:

Wait, hold on: this only works with local files, right? (I mean files on the same server) I thought this was a JS safety feature...  hmm

That's right. Unless the other server has expressedly allowed connection from the local server, in which case a connection can be made.


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#24 2012-03-24 22:33:28

GP1
Scratcher
Registered: 2009-07-06
Posts: 1000+

Re: Check for antidote code in your signatures!

This is cool!


I am currently http://blocks.scratchr.org/API.php?user=GP1&amp;action=onlineStatus&amp;type=imagehttp://blocks.scratchr.org/API.php?user=GP1&amp;action=onlineStatus&amp;type=text and I finally got over 1000 posts.

Offline

 

#25 2012-03-25 03:44:27

rookwood101
Scratcher
Registered: 2011-07-29
Posts: 500+

Re: Check for antidote code in your signatures!

Squawkers13 wrote:

the image dissapeared

indeed.


http://i.imgur.com/zeIZW.png

Offline

 

Board footer