Could you, um, put a few comments telling what is what in the source?
My PHP is rusty (AKA haven't coded for months
)
Offline
Won't work. Is it IP?
Last edited by owetre18 (2011-07-18 18:40:40)
Offline
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: </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)
Offline
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=
Offline
sparks wrote:
That's the plan
![]()
Cool. Could I draft a script?
Offline
<?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)
Offline
This is pretty cool!
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?
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
Offline
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)
Offline
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
Offline
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
Offline
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![]()
You drink coffe 0.o
Offline
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
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
Last edited by sparks (2011-07-19 06:16:15)
Offline
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
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
![]()
O.o English, please?
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
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
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
![]()
Lol. Though scimonster didn't understand that, I did... Is there something wrong with me?!? (I'm 14, BTW)
Offline
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
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
![]()
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.
Offline
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
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
![]()
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.
![]()
Neither have I...
Offline
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.
![]()
Neither have I...
Now that I read through it slowly I get it. ;P
Offline
Sorry, I've been studying psychology for two years now
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:
[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)
Offline
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
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
![]()
Good idea.
I just tried with someone else's page, and it was on a different line. D:
Offline