sparks wrote:
Cos I wrote that by hand.
I video-chatted with Lightnin just now and he's making sure to whitelist the images!
I can see the examples again!
Offline
hey sparks, would you mind if i used your text renderer in a PHP project I am working on? (you would need to modify it to allow .gif images and to EITHER allow the text renderer itself as an argument OR allow multi-line)
On a completely unrelated note, do you know a good web host for me to use my PHP script? (it must have mysql, too)
Offline
Hey joefarebrother,
You are most welcome to take and remix any of the code for this project. It's completely open-source as the first post states and can be used by anyone. A little credit would be nice but is not necessary if you don't want to.
I use hosting24, which is pretty good, it's not let me down so far (apart from not letting me auto-send many emails). The free version of this is the well-known 000webhost which is also good, but has terrible technical support if something goes wrong!
Offline
Here's how you could allow multi-line plus more image formats:
$strings = explode('|', str_replace('_' , ' ', $_GET['string'])); if(isset($_GET['bgimage']) && (strstr($_GET['bgimage'], ".png") || strstr($_GET['bigimage', ".gif") || strstr($_GET['bgimage'] , '.jpg'))){ // create the background if(strstr($_GET['bgimage'], ".png")) $img = imagecreatefrompng($_GET['bgimage']); else if(strstr($_GET['bigimage'], ".gif")) $img = imagecreatefromgif($_GET['bgimage']); else //jpeg $img = imagecreatefromjpeg($_GET['bgimage']); // All the old code, up to the string positioning and printing // print the string $xpos = 5; if(isset($_GET['xpos'])) $xpos = $_GET['xpos']; $ypos = 20; if(isset($_GET['ypos'])) $ypos = $_GET['ypos']; $font_size = 13; if(isset($_GET['font_size']) $font_size = $_GET['font_size']; for($i = 0; $i < count($strings); ++$i){ $y = $i * imagegetfontheight($font_size) + $ypos; imagettftext($img, $font_size, 0, $xpos, $y, $text_colour, $font, $strings[$i]); } // tell browser about content type header( 'Content-type: image/png' ); // create image imagepng( $img ); } else{ //All the old code, up to setting the width and height // Create image width dependant on width of the strings foreach($strings as $string) $width = max($width, imagefontwidth($font_size) * strlen($string)); //set width to longest string if(isset($_GET['width'])) $width = $_GET['width']; // Set height to that of the font $height = imagefontheight($font_size) * count($strings); if(isset($_GET['height'])) $height = $_GET['height']; // All the old code, up to positioning and printing the strings for($i = 0; $i < count($strings); ++$i){ $string = $strings[$i] // Position of the string horizontally if(isset($_GET['ypos'])) $ypos = $i * imagefontheight($font_size) + $_GET['ypos']; else $ypos = $i * imagefontheight($font_size); // Length of the string if(isset($_GET['limitstring'])) if(strlen($string) > $_GET['limitstring']) $string = substr($string, 0, $_GET['limitstring']); // Loop through the string for($i=0;$i<$len;$i++){ // Position of the character horizontally if(isset($_GET['xpos'])) $xpos = $i * imagefontwidth($font_size) + $_GET['xpos']; else $xpos = $i * imagefontwidth($font_size); // Draw character imagechar($img, $font_size, $xpos, $ypos, $string, $color); // Remove character from string $string = substr($string, 1); } } // Return the image header("Content-Type: image/gif"); imagegif($img); }
This treats the string as an array of strings and draws them individually.
By the way with those webhosts, is it possible to use the blocks.scratchr.org domain?
EDIT: Wait, my above code just gave me an idea! Instead of having &link1=blahblahblah&link2=blahblahblah&link3=blahblahblah... for the random links, you could just have &links=blahblahblah|blahblahblah|blahblahblah... so you could have an INFINITE number of links separated by pipes PLUS it will make the PHP shorter because you only need to collect 1 parameter instead of 10 by using the explode function to separate a string into an array using a separator such as a pipe (|) or some other character. The code will be
$links = explode('|', $_GET['links']);
$chosen_link = $links[array_rand($links)];
Then return the link or image specified by $chosen_link.
A similar thing can allow checking infinite user's online-ness
Last edited by joefarebrother (2012-05-21 14:09:49)
Offline
hello? sparks?
Edit: Whoo! 680th post!
Last edited by joefarebrother (2012-04-27 15:05:11)
Offline
Hey. Hi. Cool! I read this earlier but forgot to reply, sorry! It looks pretty awesome, I'll take a look at it in the next few days when I'm a bit less busy and see about implementing it! Sorry for not replying!
Offline
hey sparks, what happened to my sig? It's meant to say "I play chess at chess.com" on the chess.com logo. It was working fine a few days ago. Your sig's gone too. Has the API stopped working?
Last edited by joefarebrother (2012-04-27 14:23:22)
Offline
I wonder if he is playing around with the API and that's what makes it keep getting messed up. But at least it is being worked on every so often
Last edited by LiquidMetal (2012-04-27 14:51:33)
Offline
It's hosted on scratchr.org. The scratchr.org domain has expired. Renewal is expected, but nothing is guaranteed yet.
Offline
Amos and Andres from the Scratch team have been notified about this now, as well as the site hosts. Most of the moderator and Scratch Team know about it now too, so don't worry, we're getting it back up and running asap!
This is being discussed in about three threads at the moment, and everyone is doing their best to get it renewed, so please keep discussions about this to this thread!
Last edited by sparks (2012-04-28 15:58:21)
Offline
I'd just like to point out how many people this has helped, and how many people use these. Thank you, sparks for these wonderful APIs and the documentation for them. Keep up the good work!
Last edited by XenoK (2012-04-30 22:34:12)
Offline
joefarebrother wrote:
Here's how you could allow multi-line plus more image formats:
Code:
$strings = explode('|', str_replace('_' , ' ', $_GET['string'])); if(isset($_GET['bgimage']) && (strstr($_GET['bgimage'], ".png") || strstr($_GET['bigimage', ".gif") || strstr($_GET['bgimage'] , '.jpg'))){ // create the background if(strstr($_GET['bgimage'], ".png")) $img = imagecreatefrompng($_GET['bgimage']); else if(strstr($_GET['bigimage'], ".gif")) $img = imagecreatefromgif($_GET['bgimage']); else //jpeg $img = imagecreatefromjpeg($_GET['bgimage']); // All the old code, up to the string positioning and printing // print the string $xpos = 5; if(isset($_GET['xpos'])) $xpos = $_GET['xpos']; $ypos = 20; if(isset($_GET['ypos'])) $ypos = $_GET['ypos']; $font_size = 13; if(isset($_GET['font_size']) $font_size = $_GET['font_size']; for($i = 0; $i < count($strings); ++$i){ $y = $i * imagegetfontheight($font_size) + $ypos; imagettftext($img, $font_size, 0, $xpos, $y, $text_colour, $font, $strings[$i]); } // tell browser about content type header( 'Content-type: image/png' ); // create image imagepng( $img ); } else{ //All the old code, up to setting the width and height // Create image width dependant on width of the strings foreach($strings as $string) $width = max($width, imagefontwidth($font_size) * strlen($string)); //set width to longest string if(isset($_GET['width'])) $width = $_GET['width']; // Set height to that of the font $height = imagefontheight($font_size) * count($strings); if(isset($_GET['height'])) $height = $_GET['height']; // All the old code, up to positioning and printing the strings for($i = 0; $i < count($strings); ++$i){ $string = $strings[$i] // Position of the string horizontally if(isset($_GET['ypos'])) $ypos = $i * imagefontheight($font_size) + $_GET['ypos']; else $ypos = $i * imagefontheight($font_size); // Length of the string if(isset($_GET['limitstring'])) if(strlen($string) > $_GET['limitstring']) $string = substr($string, 0, $_GET['limitstring']); // Loop through the string for($i=0;$i<$len;$i++){ // Position of the character horizontally if(isset($_GET['xpos'])) $xpos = $i * imagefontwidth($font_size) + $_GET['xpos']; else $xpos = $i * imagefontwidth($font_size); // Draw character imagechar($img, $font_size, $xpos, $ypos, $string, $color); // Remove character from string $string = substr($string, 1); } } // Return the image header("Content-Type: image/gif"); imagegif($img); }This treats the string as an array of strings and draws them individually.
By the way with those webhosts, is it possible to use the blocks.scratchr.org domain?
EDIT: Wait, my above code just gave me an idea! Instead of having &link1=blahblahblah&link2=blahblahblah&link3=blahblahblah... for the random links, you could just have &links=blahblahblah|blahblahblah|blahblahblah... so you could have an INFINITE number of links separated by pipes PLUS it will make the PHP shorter because you only need to collect 1 parameter instead of 10 by using the explode function to separate a string into an array using a separator such as a pipe (|) or some other character. The code will be
$links = explode('|', $_GET['links']);
$chosen_link = $links[array_rand($links)];
Then return the link or image specified by $chosen_link.
A similar thing can allow checking infinite user's online-ness
Offline
In the project info, there's the type parameter. Is there anything that can be done with it besides for newest? Is there a way you could get the info of a certain project?
Offline
Offline
scimonster wrote:
I'm sure. It's the underscore in the username.
Last edited by SciTecCf (2012-06-28 06:54:10)
Offline
Sci, I think you're right that you should be able to pull some info from any defined project as well as the n'th newest. Adding it to my list of API 2.0 updates!
Yup, its the underscore and there's nothing I can do about it
Offline
You can't URL-encode it to %5?
Offline
awe, the text render-er doesn't work with animated gifs.
Offline
sparks wrote:
Sci, I think you're right that you should be able to pull some info from any defined project as well as the n'th newest. Adding it to my list of API 2.0 updates!
Yup, its the underscore and there's nothing I can do about it
Well, i did it for you.
You might want to give it a test drive before uploading it.
<?php #--------------------------------------------------------------------------FUNCTIONS--------------------------------------------------------------------------------- #the function nth_position() helps locate project information. function nth_position($str, $letter, $n, $offset = 0){ $str_arr = str_split($str); $letter_size = array_count_values(str_split(substr($str, $offset))); if( !isset($letter_size[$letter])){ trigger_error('letter "' . $letter . '" does not exist in ' . $str . ' after ' . $offset . '. position', E_USER_WARNING); return false; } else if($letter_size[$letter] < $n) { trigger_error('letter "' . $letter . '" does not exist ' . $n .' times in ' . $str . ' after ' . $offset . '. position', E_USER_WARNING); return false; } for($i = $offset, $x = 0, $count = (count($str_arr) - $offset); $i < $count, $x != $n; $i++){ if($str_arr[$i] == $letter){ $x++; } } return $i - 1; } #-------------------------------------------------------------------------------CONVERSION--------------------------------------------------------------------------- #This part converts most of the inputs to the API into lowercase in order to decrease human error if(isset($_GET['action'])){ $action = strtolower($_GET['action']); } if(isset($_GET['target'])){ $target = strtolower($_GET['target']); } if(isset($_GET['type'])){ $type = strtolower($_GET['type']); } if(isset($_GET['online'])){ $inOnline = $_GET['online']; } if(isset($_GET['offline'])){ $inOffline = $_GET['offline']; } if(isset($_GET['user'])){ $inUser = $_GET['user']; } if(isset($_GET['user2'])){ $inUser2 = strtolower($_GET['user2']); } if(isset($_GET['user3'])){ $inUser3 = strtolower($_GET['user3']); } if(isset($_GET['user4'])){ $inUser4 = strtolower($_GET['user4']); } if(isset($_GET['return'])){ $inReturn = strtolower($_GET['return']); } #---------------------------------------------------------------IMAGE TO TEXT CUSTOM SETTINGS ---------------------------------------------- $extraText = ''; # these are custom commands that can be set to change the appearance of the custom image, such as text size and colour or background colour. if(isset($_GET['font_size'])){ $extraText = $extraText . '&font_size=' . $_GET['font_size']; } if(isset($_GET['width'])){ $extraText = $extraText . '&width=' . $_GET['width']; } if(isset($_GET['height'])){ $extraText = $extraText . '&height=' . $_GET['height']; } if(isset($_GET['bgr'])){ $extraText = $extraText . '&bgr=' . $_GET['bgr']; #bgr, bgg, bgb, textr, textg and textb are all RGB values, only set them to numbers from 0 to 255. } if(isset($_GET['bgg'])){ $extraText = $extraText . '&bgg=' . $_GET['bgg'];#If you don't set one of the rgb values it will assume it is 0 though if r, b and g aren't set the default colour for the fora is used. } if(isset($_GET['bgb'])){ $extraText = $extraText . '&bgb=' . $_GET['bgb']; } if(isset($_GET['textr'])){ $extraText = $extraText . '&textr=' . $_GET['textr']; } if(isset($_GET['textg'])){ $extraText = $extraText . '&textg=' . $_GET['textg']; } if(isset($_GET['textr'])){ $extraText = $extraText . '&textb=' . $_GET['textb']; } if(isset($_GET['xpos'])){ $extraText = $extraText . '&xpos=' . $_GET['xpos']; } if(isset($_GET['ypos'])){ $extraText = $extraText . '&ypos=' . $_GET['ypos']; } if(isset($_GET['limitstring'])){ $extraText = $extraText . '&limitstring=' . $_GET['limitstring']; } if(isset($_GET['bgimage'])){ $extraText = $extraText . '&bgimage=' . $_GET['bgimage']; } #-------------------------------------------------------------THE API-------------------------------------------------------------------------------------------- if(isset($action)){ #the action attribute tells the API what sort of thing it's going to do, e.g. look at projects or check your online status if($action == 'onlinestatus'){ #target tells this part of the API whether to search in the tbg forum as well as the main one or not. If left blank, only the main fora are searched. if($target == 'tbg'){ #search only the text-based-games forum $page = ltrim(file_get_contents('http://scratch.mit.edu/tbgforums/')); $startpos = strrpos ($page, "Online: </strong></dt>"); $endpos = strlen(ltrim(file_get_contents('http://scratch.mit.edu/tbgforums/'))); $refined = substr($page, $startpos, $endpos); } if($target == 'all'){ #search the main fora as well as the tbg forum $page = ltrim(file_get_contents('http://scratch.mit.edu/tbgforums/')); $startpos = strrpos ($page, "Online: </strong></dt>"); $endpos = strlen(ltrim(file_get_contents('http://scratch.mit.edu/tbgforums/'))); $refined = substr($page, $startpos, $endpos); $page = ltrim(file_get_contents('http://scratch.mit.edu/forums/index.php')); $startpos = strrpos ($page, "Online: </strong></dt>"); $endpos = strlen(ltrim(file_get_contents('http://scratch.mit.edu/forums/index.php'))); $refined = $refined . substr($page, $startpos, $endpos); } if(!isset($target)){ #search only the main fora. $page = ltrim(file_get_contents('http://scratch.mit.edu/forums/index.php')); $startpos = strrpos ($page, "Online: </strong></dt>"); $endpos = strlen(ltrim(file_get_contents('http://scratch.mit.edu/forums/index.php'))); $refined = substr($page, $startpos, $endpos); } #set the default online and offline circle images. If no type value is set, they will appear. $online = 'http://blocks.scratchr.org/online.gif'; $offline = 'http://blocks.scratchr.org/offline.gif'; if(isset($type)){ if($type == 'square'){ #set the images to square indicators $online = 'http://blocks.scratchr.org/onlineSquare.gif'; $offline = 'http://blocks.scratchr.org/offlineSquare.gif'; } if($type == 'text'){ #set the return to the text 'online' or 'offline' $online = 'http://blocks.scratchr.org/onlineText.png'; $offline = 'http://blocks.scratchr.org/offlineText.png'; } if($type == 'customtext'){ #Allow you to choose your own custom online and offline text. $online = 'http://www.blocks.scratchr.org/textrender.php?string=' . $inOnline; $offline = 'http://www.blocks.scratchr.org/textrender.php?string=' . $inOffline; } } if(!isset($type)){ #if type isn't set then you're either going for the default images or your own custom online/offline images. if(isset($inOnline)){ #if the input 'online' is set, display the image linked there when you are online $online = $inOnline; } if(isset($inOffline)){#if the input 'offline' is set, display the image linked there when you are offline $offline = $inOffline; } } $isonline = False; #innocent until proven guilty. The user is assumed to be offline until proof of his presence is found. if(isset($inUser)){ $pos = strrpos($refined, $inUser); if($pos >= '1'){ $isonline = True; #the user's name was found so he is online. } } if(isset($inUser2)){ $pos = strrpos($refined, $inUser2); if($pos >= '1'){ $isonline = True; #users 2 - 4 can also be checked. If they are all offline then isonline will return false, if any one of them are online it will return true. } } if(isset($inUser3)){ $pos = strrpos($refined, $inUser3); if($pos >= '1'){ $isonline = True; } } if(isset($inUser4)){ $pos = strrpos($refined, $inUser4); if($pos >= '1'){ $isonline = True; } } if(!$isonline){ #the return attribute indicates what sort of thing is being sent back to the requester, e.g. an image or an URL. if($inReturn == 'link'){ #the user asked for this link to be given if they are online echo "<meta http-equiv='REFRESH' content='0;url=" . $inOnline . "'>"; #auto-redirect to requested page. } if($inReturn != 'link'){ #the user didn't want a link, rather an image. echo file_get_contents($offline); #the image they specified above is returned to the requestee. header("Content-Type: image/gif"); } } if($isonline){ if($inReturn == 'link'){ echo "<meta http-equiv='REFRESH' content='0;url=" . $inOffline . "'>"; } if($inReturn != 'link'){ echo file_get_contents($online); header("Content-Type: image/gif"); } } } if($action == 'projects'){ #the following API section looks at a user's projects and return information about them. if($type == 'newest' || $type == 'absolute'){ #looking at the n'th newest project, or a specific project $page = ltrim(file_get_contents('http://scratch.mit.edu/api/getprojectsbyusername/' . $inUser)); #this pulls all the project id's belonging to a user into the API. /* $count = '0'; $placeholder = '0'; while ($count < $_GET['num'] - '1'){ #this finds the project id for the n'th newest project. n'th being set by the num parameter. $placeholder = strpos($page, ':', $placeholder + '1'); $count ++; } if($count > 0){ $placeholder++; } */ if($type == 'newest') {$project = explode(':',$page)[$_GET['num']-1];} else{$project = $_GET['num'];} $endplaceholder = strpos($page, ':', $placeholder + 1); if($inReturn == 'image'){ #the user wants a thumbnail of their project returned. #echo "<img src = 'http://scratch.mit.edu/static/projects/" . $inUser . "/" . $project . "_sm.png' />"; < this echoes the image rather than the file. For glitch testing. echo file_get_contents('http://scratch.mit.edu/static/projects/' . $inUser . '/' . $project) . '_sm.png'); header("Content-Type: image/gif"); } if($inReturn == 'link'){ # the user wants a link to their n'th project. $user = $inUser; #$project = substr($page, $placeholder, $endplaceholder - $placeholder); echo "<meta http-equiv='REFRESH' content='0;url=http://scratch.mit.edu/projects/" . $user . "/" . $project . "'>"; #auto-redirect to requested project page. } if($inReturn == 'text'){ #the user wants the name of their n'th project. #$project = substr($page, $placeholder, $endplaceholder - $placeholder); $page = ltrim(file_get_contents('http://scratch.mit.edu/api/getprojectinfobyid/' . $project)); #getinfobyprojectid is a page on the Scratch site that lists everything about a chosen project. $text = strpos($page, ':', 1); $text ++; $text = substr($page, $text, strpos($page, ':', $text + 1) - 7); #each piece of information is seperated by a : (colon) so all this is just filtering through the colons until it reaches the right one. $text = str_replace("%20","_",$text); echo file_get_contents('http://www.blocks.scratchr.org/textrender.php?string=' . $text . $extraText); header("Content-Type: image/gif"); } if($inReturn == 'loves'){ # the user wants the number of loves of their n'th project #$project = substr($page, $placeholder, $endplaceholder - $placeholder); $page = ltrim(file_get_contents('http://scratch.mit.edu/api/getprojectinfobyid/' . $project)); $startlove = nth_position($page, ':', 6) + 1; $page = substr($page, $startlove, strlen($page)); $startlove = nth_position($page, ':', 1) + 1; $page = substr($page, 0, $startlove - 1); echo file_get_contents('http://www.blocks.scratchr.org/textrender.php?string=' . $page . $extraText); header("Content-Type: image/gif"); } if($inReturn == 'faves'){ #the user wants the number of favouriters of their n'th project #$project = substr($page, $placeholder, $endplaceholder - $placeholder); $page = ltrim(file_get_contents('http://scratch.mit.edu/api/getprojectinfobyid/' . $project)); $startlove = nth_position($page, ':', 7) + 1; $page = substr($page, $startlove, strlen($page)); $startlove = nth_position($page, ':', 1) + 1; $page = substr($page, 0, $startlove - 1); echo file_get_contents('http://www.blocks.scratchr.org/textrender.php?string=' . $page . $extraText); header("Content-Type: image/gif"); } if($inReturn == 'comments'){ #the user wants the number of comments of their n'th project #$project = substr($page, $placeholder, $endplaceholder - $placeholder); $page = ltrim(file_get_contents('http://scratch.mit.edu/api/getprojectinfobyid/' . $project)); $startlove = nth_position($page, ':', 12) + 1; $page = substr($page, $startlove, strlen($page)); $startlove = nth_position($page, ':', 1) + 1; $page = substr($page, 0, $startlove - 1); echo file_get_contents('http://www.blocks.scratchr.org/textrender.php?string=' . $page . $extraText); header("Content-Type: image/gif"); } if($inReturn == 'remixes'){ #the user wants the number of remixes of their n'th project #$project = substr($page, $placeholder, $endplaceholder - $placeholder); $page = ltrim(file_get_contents('http://scratch.mit.edu/api/getprojectinfobyid/' . $project)); $startlove = nth_position($page, ':', 8) + 1; $page = substr($page, $startlove, strlen($page)); $startlove = nth_position($page, ':', 1) + 1; $page = substr($page, 0, $startlove - 1); echo file_get_contents('http://www.blocks.scratchr.org/textrender.php?string=' . $page . $extraText); header("Content-Type: image/gif"); } if($inReturn == 'downloads'){ # the user wants the number of downloads of their n'th project #$project = substr($page, $placeholder, $endplaceholder - $placeholder); $page = ltrim(file_get_contents('http://scratch.mit.edu/api/getprojectinfobyid/' . $project)); $startlove = nth_position($page, ':', 13) + 1; $page = substr($page, $startlove, strlen($page)); echo file_get_contents('http://www.blocks.scratchr.org/textrender.php?string=' . $page . $extraText); header("Content-Type: image/gif"); } if($inReturn == 'views'){ # The user wants the number of views for their n'th project #$project = substr($page, $placeholder, $endplaceholder - $placeholder); $page = ltrim(file_get_contents('http://scratch.mit.edu/projects/' . $_GET['user'] . '/' . $project)); $viewStart = strrpos($page, '<!-- ::: Begin viewers, lovers, taggers and favoriters ::: -->') + 71; $viewEnd = strrpos($page, 'views, <a href') - 1; $page = substr($page, $viewStart, $viewEnd - $viewStart); echo file_get_contents('http://www.blocks.scratchr.org/textrender.php?string=' . $page . $extraText); header("Content-Type: image/gif"); } } if($type == 'least'){ #this type will return the project with the least number of.... loves/faves/views etc. $page = 'http://scratch.mit.edu/api/getprojectsbyusername/' . $_GET['user']; $numberOfProjects = substr_count(file_get_contents($page), ':', 0) + 1; $projectcount = 1; if($inReturn == 'views'){ $start = nth_position($page, ':', $count) + 1; $end = nth_position($page, ':', $count + 1) + 1; } } } if($action == 'friends'){ #Thanks to SeptimusHeap for this section if($type == 'newest'){ $page = ltrim(file_get_contents('http://scratch.mit.edu/api/getfriendsbyusername/' . $inUser)); $count = '0'; $placeholder = '0'; while ($count < $_GET['num'] - '1'){ $placeholder = strpos($page, ':', $placeholder + '1'); $count ++; } if($count > 0){ $placeholder++; } $endplaceholder = strpos($page, ':', $placeholder + 1); if($inReturn == 'image'){ #echo "<img src = 'http://scratch.mit.edu/static/icons/buddy/" . substr($page, $placeholder, $endplaceholder - $placeholder) . "_sm.png' />"; < this echoes the image rather than the file. For glitch testing. echo file_get_contents('http://scratch.mit.edu/static/icons/buddy/' . substr($page, $placeholder, $endplaceholder - $placeholder) . '_sm.png'); header("Content-Type: image/gif"); } if($inReturn == 'link'){ $user = $inUser; $userguy = substr($page, $placeholder, $endplaceholder - $placeholder); echo "<meta http-equiv='REFRESH' content='0;url=http://scratch.mit.edu/api/getuser/" . $userguy . "'>"; } } } if($action == 'text'){ echo file_get_contents('http://blocks.scratchr.org/textrender.php?string=' . $_GET['string'] . $extraText); header("Content-Type: image/gif"); } if($action == 'random'){ $numberOfLinks = 0; if(isset($_GET['link1'])){ $numberOfLinks ++; } if(isset($_GET['link2'])){ $numberOfLinks ++; } if(isset($_GET['link3'])){ $numberOfLinks ++; } if(isset($_GET['link4'])){ $numberOfLinks ++; } if(isset($_GET['link5'])){ $numberOfLinks ++; } if(isset($_GET['link6'])){ $numberOfLinks ++; } if(isset($_GET['link7'])){ $numberOfLinks ++; } if(isset($_GET['link8'])){ $numberOfLinks ++; } if(isset($_GET['link9'])){ $numberOfLinks ++; } if(isset($_GET['link10'])){ $numberOfLinks ++; } if($numberOfLinks > 0){ $url = rand(1, $numberOfLinks); if($inReturn == 'image'){ echo file_get_contents($_GET['link' . $url]); header("Content-Type: image/gif"); } if($inReturn == 'link'){ echo "<meta http-equiv='REFRESH' content='0;url=" . $_GET['link' . $url] . "'>"; } } } } if(!isset($action)){ echo "<p>Sorry, you've not set the action parameter, I don't know what to do! For documentation on this API look <a href = 'http://scratch.mit.edu/forums/viewtopic.php?id=69113&p=1'>here</a>"; } ?>
Changes:
Added support for getting a project's info by ID, by using action=projects&type=absolute&num=project ID.
Optimized code for finding ID in nth, so it uses explode(). I'm not sure, but you should be able to do explode()[index], right?
Offline
There is a PHP error!
Your site wrote:
<br />
<b>Warning</b>: letter ":" does not exist in after 0. position in <b>/home/scratchrblocks/blocks.scratchr.org/API.php</b> on line <b>8</b><br />
<br />
<b>Warning</b>: letter ":" does not exist in after 0. position in <b>/home/scratchrblocks/blocks.scratchr.org/API.php</b> on line <b>8</b><br />
Offline
Nice api
Offline