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

#51 2011-07-18 18:24:52

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

Re: My new online/offline API for the fora

Hey that's handy!


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

Offline

 

#52 2011-07-18 18:28:36

SeptimusHeap
Scratcher
Registered: 2010-02-01
Posts: 1000+

Re: My new online/offline API for the fora

Could you, um, put a few comments telling what is what in the source?

My PHP is rusty (AKA haven't coded for months  tongue )


http://i46.tinypic.com/dw7zft.png

Offline

 

#53 2011-07-18 18:37:48

owetre18
Scratcher
Registered: 2009-07-01
Posts: 1000+

Re: My new online/offline API for the fora

http://blocks.scratchr.org/libstatus.php?user=owetre18

Won't work. Is it IP?

Last edited by owetre18 (2011-07-18 18:40:40)

Offline

 

#54 2011-07-18 18:49:53

Barf_Bag
Scratcher
Registered: 2011-07-10
Posts: 100+

Re: My new online/offline API for the fora

This is a cool idea.


http://i56.tinypic.com/33tiavp.png

Offline

 

#55 2011-07-18 19:18:19

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

Re: My new online/offline API for the fora

SeptimusHeap wrote:

Could you, um, put a few comments telling what is what in the source?

My PHP is rusty (AKA haven't coded for months :P)

will do :)

<?php
$page = ltrim(file_get_contents('http://scratch.mit.edu/forums/index.php'));
This reads the entire forum index page to the variable $page.
$startpos = strrpos ($page, "Online:&nbsp;</strong></dt>");
strrpos is basically setting $startpos to the number of characters into the page the text "Online:..." is found at.
$endpos = strlen(ltrim(file_get_contents('http://scratch.mit.edu/forums/index.php')));
strlen gets the number of characters in $page
$refined = substr($page, $startpos, $endpos);
substr is the same as (letters ()-() of []) in Scratch
$online = 'http://blocks.scratchr.org/online.gif';
$offline = 'http://blocks.scratchr.org/offline.gif';
sets the default images for online and offline
if(isset($_GET['type'])){
    if($_GET['type'] == 'square'){
        $online = 'http://blocks.scratchr.org/onlineSquare.gif';
        $offline = 'http://blocks.scratchr.org/offlineSquare.gif';
    }
    if($_GET['type'] == 'text'){
        $online = 'http://blocks.scratchr.org/onlineText.gif';
        $offline = 'http://blocks.scratchr.org/offlineText.gif';
    }
}
if(!isset($_GET['type'])){
    if(isset($_GET['online'])){
        $online = $_GET['online'];
    }
        if(isset($_GET['offline'])){
        $offline = $_GET['offline'];
    }
}
all that basically changes the online/offline images if other parameters are set.
if(isset($_GET['user'])){
    $pos = strrpos($refined, $_GET['user']);
    if(strlen($pos < '1')){
        echo file_get_contents($offline);
file_get_contents() is echoing the final image that is reported back to the fora.
    }
    if(strlen($pos >= '1')){
        echo file_get_contents($online);
    }
}
?>

Last edited by sparks (2011-07-18 19:21:05)


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

Offline

 

#56 2011-07-18 19:29:12

SeptimusHeap
Scratcher
Registered: 2010-02-01
Posts: 1000+

Re: My new online/offline API for the fora

How about using strrpos to find <img src="/static/projects which is the start of the first image link, then making the end pos strrpos " title=


http://i46.tinypic.com/dw7zft.png

Offline

 

#57 2011-07-18 19:34:34

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

Re: My new online/offline API for the fora

That's the plan  smile


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

Offline

 

#58 2011-07-18 19:36:22

SeptimusHeap
Scratcher
Registered: 2010-02-01
Posts: 1000+

Re: My new online/offline API for the fora

sparks wrote:

That's the plan  smile

Cool. Could I draft a script?


http://i46.tinypic.com/dw7zft.png

Offline

 

#59 2011-07-18 19:40:01

SeptimusHeap
Scratcher
Registered: 2010-02-01
Posts: 1000+

Re: My new online/offline API for the fora

<?php
$page = ltrim(file_get_contents(http://scratch.mit.edu/users/SeptimusHeap'));
$startpos = strrpos ($page, "<img src="/static/projects")+10;
$endpos = strrpos ($page, "title=")+10;
...


I'll do more later.

Last edited by SeptimusHeap (2011-07-18 19:40:29)


http://i46.tinypic.com/dw7zft.png

Offline

 

#60 2011-07-18 21:53:56

cpumaster930
Scratcher
Registered: 2009-02-23
Posts: 100+

Re: My new online/offline API for the fora

This is pretty cool!  big_smile

Here's a suggestion: could you provide several links and images and have the image pick one at random to display?  Example: provide images of and links to five of your projects, and every time someone refreshes the page, your signature displays (at random) one of those five projects?  smile
This would be useful if you have a large number of projects and want to mix up your signature without having to do it randomly  wink


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

Offline

 

#61 2011-07-19 02:38:17

meowmeow55
Scratcher
Registered: 2008-12-24
Posts: 1000+

Re: My new online/offline API for the fora

PHP can output a proper image, why can't you make it do that here?

@cpumaster: That might make the URL a little crazy, but it probably could be done (using a "random" argument to the script that contains URLs separated by semicolons, for example).

BTW, the API is getting really popular, sparks! I'm seeing it in a lot of people's sigs now!

Last edited by meowmeow55 (2011-07-19 02:46:38)


Yawn.

Offline

 

#62 2011-07-19 03:11:50

ssss
Scratcher
Registered: 2007-07-29
Posts: 1000+

Re: My new online/offline API for the fora

meowmeow55 wrote:

PHP can output a proper image, why can't you make it do that here?

@cpumaster: That might make the URL a little crazy, but it probably could be done (using a "random" argument to the script that contains URLs separated by semicolons, for example).

BTW, the API is getting really popular, sparks! I'm seeing it in a lot of people's sigs now!

LIKE MINE  big_smile


Hey.  It's me SSSS, back from the dead!  smile

Offline

 

#63 2011-07-19 04:01:33

urhungry
Scratcher
Registered: 2009-07-03
Posts: 1000+

Re: My new online/offline API for the fora

Seriously awesome job. Very nice work, going in my signature as soon as possible.

Offline

 

#64 2011-07-19 06:04:01

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

Re: My new online/offline API for the fora

Thanks guys, it's great to see this being used everywhere!

I think random project displaying is totally possible, let me get newest project displaying working first though! I really like the thought that your sig could either show your three newest projects, or a random project. You wouldn't need to even give the entire URL for each project, it could just be the project id.

Getting the API to create a link is going to be hard because although php redirect works really well, it does not like variables in it's redirect in my experience, so the redirect may be a little slow.

As I type I'm thinking, how does  one get the API to create a random project thumbnail AND THEN create that link too?

I've just woken up so let me get some coffee and I'll get started on some of these updates  big_smile


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

Offline

 

#65 2011-07-19 06:08:02

ssss
Scratcher
Registered: 2007-07-29
Posts: 1000+

Re: My new online/offline API for the fora

sparks wrote:

Thanks guys, it's great to see this being used everywhere!

I think random project displaying is totally possible, let me get newest project displaying working first though! I really like the thought that your sig could either show your three newest projects, or a random project. You wouldn't need to even give the entire URL for each project, it could just be the project id.

Getting the API to create a link is going to be hard because although php redirect works really well, it does not like variables in it's redirect in my experience, so the redirect may be a little slow.

As I type I'm thinking, how does  one get the API to create a random project thumbnail AND THEN create that link too?

I've just woken up so let me get some coffee and I'll get started on some of these updates  big_smile

You drink coffe 0.o  tongue


Hey.  It's me SSSS, back from the dead!  smile

Offline

 

#66 2011-07-19 06:15:05

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

Re: My new online/offline API for the fora

Coffee helps me concentrate and also makes me slightly sleepy - it has the opposite effect on me to most people. This is because my Hypothalamus (part of the brain) secretes less of a neurotransmitter called dopamine that is responsible for concentration and calmness. Caffeine, as a stimulant, basically gives my hypothalamus a kick up the backside and encourages it to produce more dopamine  big_smile  It's also tasty and delicious! (I'm 18 by the way, so it's not so odd.) I was in Switzerland last year and asked for a coffee and the lady thought I was joking... I don't think many young people drink it  tongue

Last edited by sparks (2011-07-19 06:16:15)


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

Offline

 

#67 2011-07-19 06:24:48

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: My new online/offline API for the fora

sparks wrote:

Coffee helps me concentrate and also makes me slightly sleepy - it has the opposite effect on me to most people. This is because my Hypothalamus (part of the brain) secretes less of a neurotransmitter called dopamine that is responsible for concentration and calmness. Caffeine, as a stimulant, basically gives my hypothalamus a kick up the backside and encourages it to produce more dopamine  big_smile  It's also tasty and delicious! (I'm 18 by the way, so it's not so odd.) I was in Switzerland last year and asked for a coffee and the lady thought I was joking... I don't think many young people drink it  tongue

O.o English, please?  tongue
I know how old you are.

You want this thing in the [img] tags to create a link?! I don't think it's possible.

Offline

 

#68 2011-07-19 06:27:50

ssss
Scratcher
Registered: 2007-07-29
Posts: 1000+

Re: My new online/offline API for the fora

sparks wrote:

Coffee helps me concentrate and also makes me slightly sleepy - it has the opposite effect on me to most people. This is because my Hypothalamus (part of the brain) secretes less of a neurotransmitter called dopamine that is responsible for concentration and calmness. Caffeine, as a stimulant, basically gives my hypothalamus a kick up the backside and encourages it to produce more dopamine  big_smile  It's also tasty and delicious! (I'm 18 by the way, so it's not so odd.) I was in Switzerland last year and asked for a coffee and the lady thought I was joking... I don't think many young people drink it  tongue

Lol.  Though scimonster didn't understand that, I did...  Is there something wrong with me?!? (I'm 14, BTW)


Hey.  It's me SSSS, back from the dead!  smile

Offline

 

#69 2011-07-19 06:29:21

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: My new online/offline API for the fora

ssss wrote:

sparks wrote:

Coffee helps me concentrate and also makes me slightly sleepy - it has the opposite effect on me to most people. This is because my Hypothalamus (part of the brain) secretes less of a neurotransmitter called dopamine that is responsible for concentration and calmness. Caffeine, as a stimulant, basically gives my hypothalamus a kick up the backside and encourages it to produce more dopamine  big_smile  It's also tasty and delicious! (I'm 18 by the way, so it's not so odd.) I was in Switzerland last year and asked for a coffee and the lady thought I was joking... I don't think many young people drink it  tongue

Lol.  Though scimonster didn't understand that, I did...  Is there something wrong with me?!? (I'm 14, BTW)

I just haven't reviewed parts of the brain recently.  tongue

Offline

 

#70 2011-07-19 06:30:32

ssss
Scratcher
Registered: 2007-07-29
Posts: 1000+

Re: My new online/offline API for the fora

scimonster wrote:

ssss wrote:

sparks wrote:

Coffee helps me concentrate and also makes me slightly sleepy - it has the opposite effect on me to most people. This is because my Hypothalamus (part of the brain) secretes less of a neurotransmitter called dopamine that is responsible for concentration and calmness. Caffeine, as a stimulant, basically gives my hypothalamus a kick up the backside and encourages it to produce more dopamine  big_smile  It's also tasty and delicious! (I'm 18 by the way, so it's not so odd.) I was in Switzerland last year and asked for a coffee and the lady thought I was joking... I don't think many young people drink it  tongue

Lol.  Though scimonster didn't understand that, I did...  Is there something wrong with me?!? (I'm 14, BTW)

I just haven't reviewed parts of the brain recently.  tongue

Neither have I...


Hey.  It's me SSSS, back from the dead!  smile

Offline

 

#71 2011-07-19 06:32:15

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: My new online/offline API for the fora

ssss wrote:

scimonster wrote:

ssss wrote:


Lol.  Though scimonster didn't understand that, I did...  Is there something wrong with me?!? (I'm 14, BTW)

I just haven't reviewed parts of the brain recently.  tongue

Neither have I...

Now that I read through it slowly I get it. ;P

Offline

 

#72 2011-07-19 06:35:33

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

Re: My new online/offline API for the fora

Sorry, I've been studying psychology for two years now  tongue

I don't want the image tag to create a link, I'm going to get the API to act as a redirect link. Say I wanted a link to my newest project, which always links to my newest project, you could use something like this:

Code:

[url=http://blocks.scratchr.org/libstatus.php?user=sparks&projectlink=1]my newest project[/url]

Now this does not currently work, but if you clicked that link, it would take you to the API page and then that page would find the link to your newest project and automatically redirect you to that without you having to click on anything.

I'm also putting the API on a new page, as libstatus does not really reflect anything properly. I'll keep the current API page up but any of the new features will be on the new page, sorry about that. I'm also making the parameters clearer.

Last edited by sparks (2011-07-19 06:36:41)


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

Offline

 

#73 2011-07-19 06:47:02

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: My new online/offline API for the fora

So you want to read line 273, from the 3rd slash, to the next double quote.
That gives the ID of the 1st project.
10 lines after is the next.

EDIT: It reads as if you're logged out, right?

Last edited by scimonster (2011-07-19 06:47:46)

Offline

 

#74 2011-07-19 06:48:10

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

Re: My new online/offline API for the fora

Because things like the number of lines of the Scratcher's location and whether they are logged in or not affects the lines below I'm using the strrpos command to find it, but yes  smile


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

Offline

 

#75 2011-07-19 06:50:43

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: My new online/offline API for the fora

sparks wrote:

Because things like the number of lines of the Scratcher's location and whether they are logged in or not affects the lines below I'm using the strrpos command to find it, but yes  smile

Good idea.
I just tried with someone else's page, and it was on a different line. D:

Offline

 

Board footer