I-Topic: Self Updating Images In Posts And Sigs
This API allows Scratch users to show images that change according to events and conditions in their forum posts and signatures. This includes showing whether the user is online or not and displaying their newest project(s).
___________________________________________________________________________________
Examples of using the API:
I am currently and my newest project is called . Click on the thumbnail to view it:
___________________________________________________________________________________
This API is open source! Look at post #2 for the most recent php code!
___________________________________________________________________________________
Create your custom link/image using the creator linked and documented here by comp500 or make it yourself using the uses list below.
Uses list. Click one to be taken to the documentation page.
Online/offline indicator
- Online offline circle/square
- Online offline custom images
- Online offline custom URLs
Newest project thumbnail(s)/link(s)/info
- Thumbnail image
- Link
- Name
- Number of love-it's
- Number of views
- Number of comments
- Number of favouriters
- Number of remixers
- Number of downloads
newest friend user image(s)
- Newest friend user icon image(s)
- Newest friend mystuff page link(s)
Random
- Random Images
- Random Links
Customise any text return to match your sig
___________________________________________________________________________________
Thanks to MathWizz for help getting the images to display on the fora!
Last edited by sparks (2012-09-05 14:32:39)
Offline
The current php code for this API
V 1.1
~searching the TBG as well as main forum added; not sure if it works.
~up to four users can be checked for "online-ness" at once, if any are online the image returned will be the online one.
1.2
~ Thanks to SeptimusHeap the API can now display your newest friends' Scratch user images and also link to their mystuff page.
1.3
~Newest project action can now report the project name as well as the link and thumbnail!
~ added case-sensitivity to all attributes save for link 1-10, online, offline and string.
~added project love-it, faves, comments, remixes and download return.
~annotated code to make it easier to read and break-down.
1.4
~Added complete image-to-text return control for all current image settings
1.4.1
~Added header type as image for non-link returns.
1.4.2
~Added project views to project info API.
<?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'){ #looking at the n'th newest 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++; } $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 . "/" . 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/projects/' . $inUser . '/' . substr($page, $placeholder, $endplaceholder - $placeholder) . '_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 witth 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>"; } ?>
___________________________________________________________________________________
Generator
The current source code for comp500's generator can be downloaded here.
___________________________________________________________________________________
Text renderer
V 1.1
~Added "_" to " "(space) converter.
V 1.2
~ Added complete text image control for current settings.
V2.0
~ Added background-image options (thanks to LS97 for the help there)
<?PHP //parser in spaces $count = 1; $string = str_replace("_"," ",$_GET['string']); if(isset($_GET['bgimage']) && strstr($_GET['bgimage'], ".png")){ #thanks to LS97 for making most of the bgimage attribute! // create the background $img = imagecreatefrompng($_GET['bgimage']); //chooses the text color if(isset($_GET['textr']) | isset($_GET['textg']) | isset($_GET['textb'])){ $red = (int)$_GET['textr']; $green = (int)$_GET['textg']; $blue = (int)$_GET['textb']; $text_colour = imagecolorallocate($img, $red, $blue, $green); } else{ $text_colour = imagecolorallocate($img, 0, 0, 0); } // get the font $font = realpath('Trebuchet_MS.ttf'); // print the string $xpos = 5; if(isset($_GET['xpos'])){ $xpos = $_GET['xpos']; } $ypos = 20; if(isset($_GET['ypos'])){ $ypos = $_GET['ypos']; } imagettftext($img, 13, 0, $xpos, $ypos, $text_colour, $font, $string); // tell browser about content type header( 'Content-type: image/png' ); // create image imagepng( $img ); } if(!isset($_GET['bgimage'])){ // Set font size $font_size = 2; if(isset($_GET['font_size'])){ $font_size = $_GET['font_size']; } $font = '/fonts/Trebuchet_MS.ttf'; if(isset($_GET['font'])){ $font = $_GET['font']; } // Create image width dependant on width of the string $width = imagefontwidth($font_size)*strlen($string); if(isset($_GET['width'])){ $width = $_GET['width']; } // Set height to that of the font $height = imagefontheight($font_size); if(isset($_GET['height'])){ $height = $_GET['height']; } // Create the image pallette $img = imagecreate($width,$height); if(isset($_GET['bgr']) | isset($_GET['bgg']) | isset($_GET['bgb'])){ $red = (int)$_GET['bgr']; $blue = (int)$_GET['bgg']; $green = (int)$_GET['bgb']; $bg = imagecolorallocate($img, $red, $blue, $green); } else{ $bg = imagecolorallocate($img, 222, 223, 223); } // Font color if(isset($_GET['textr']) | isset($_GET['textg']) | isset($_GET['textb'])){ $red = (int)$_GET['textr']; $green = (int)$_GET['textg']; $blue = (int)$_GET['textb']; $color = imagecolorallocate($img, $red, $blue, $green); } else{ $color = imagecolorallocate($img, 0, 0, 0); } // Length of the string if(isset($_GET['limitstring'])){ if(strlen($string) > $_GET['limitstring']){ $string= substr($string, 0, $_GET['limitstring']); } } $len = strlen($string); // Y-coordinate of character, X changes, Y is static $ypos = 0; if(isset($_GET['ypos'])){ $ypos = $_GET['ypos']; } // 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); } // Remove image imagedestroy($img); ?>
Last edited by sparks (2011-11-24 06:53:43)
Offline
^ home
Online/offline indicator
action value:
onlineStatus
parameters:
user, [type, online, offline]
___________________________________________________________________________________
Standard image
For this type you need only give the Scratcher name. This will either show a or a . For example: I am currently .
type value:
none
[img]http://blocks.scratchr.org/API.php?user=USERNAMEHERE&action=onlineStatus[/img]
___________________________________________________________________________________
Square image
This requires the Scratcher name and the type value "square". This will either show a or a . For example: I am currently .
type value:
square
[img]http://blocks.scratchr.org/API.php?user=USERNAMEHERE&action=onlineStatus&type=square[/img]
___________________________________________________________________________________
text return
This requires the Scratcher name and the type value "text". It returns an image of the words "online" or "offline". For example, I am currently .
type value:
text
[img]http://blocks.scratchr.org/API.php?user=USERNAMEHERE&action=onlineStatus&type=text[/img]
___________________________________________________________________________________
Any image return
This API attribute is excellent for changing signatures! It requires the Scratcher name and the parameters online and offline. So any two images can be grabbed from anywhere online such as and . In application it shows that I am currently .
type value:
none
other parameters:
online, offline
[img]http://blocks.scratchr.org/API.php?user=USERNAMEHERE&action=onlineStatus&online=URLTOIMAGEBEINGSHOWNFORONLINE&offline=URLTOIMAGEBEINGSHOWNFOROFFLINE[/img]
Note~ if you leave either online or offline out of the URL the normal image will appear in its place.
Any link return
if you want to link to one URL when you are online and another when you are offline you simply have to add "return=link" to the above api and place them within a link tag.
[url]http://blocks.scratchr.org/API.php?user=USERNAMEHERE&action=onlineStatus&return=link&online=ONLINELINKURL&offline=OFFLINELINKURL[/url]
___________________________________________________________________________________
Show if one of up to four users are online
To do this, simply add one parameter per scratch username. if any of them are online, the image returned will be the online image. If you want to search for, for example, only two users, simply don't add user3 and user4 to the URL.
parameters:
user, [user2, user3, user4]
[img]http://blocks.scratchr.org/API.php?action=onlineStatus&user=USERNAME1HERE&user2=USERNAME2HERE&user3=USERNAME3HERE&user4=USERNAME4HERE[/img]
___________________________________________________________________________________
Searching the text-based games forum
This uses the parameter "target". It can be added to any online/offline search you are using. If you don't set "target" and leave it out, the API will search the Scratch forums only. If you set it to "tbg" it will search for online users on the text-based games forum only. If you set it to "all" it will search through both the main fora and the text-based games forum.
parameters:
target
example:
[img]http://www.blocks.scratchr.org/API.php?action=onlineStatus&user=USERNAMEHERE&target=all[/img]
Last edited by sparks (2011-07-28 05:11:41)
Offline
^ home
Project links, thumbs and info
Project thumnails
This API lets you show your newest projects in your sig! When you add a new project it will appear as num=1 automatically and all the other project images will slide back! For example, my newest project has this thumbnail:
action value:
projects
type value:
newest
return value:
image
parameters:
user, num
[img]http://blocks.scratchr.org/API.php?user=USERNAMEHERE&action=projects&type=newest&return=image&num=NUMBER[/img]
setting num to 1 will return your newest project, setting it to 2 will return your second newest and so on.
___________________________________________________________________________________
Project links
This API lets you link to your n'th newest projects in your signature! For example, my newest project has this link: My newest project
action value:
projects
type value:
newest
return value:
link
parameters:
user, num
[url]http://blocks.scratchr.org/API.php?user=USERNAMEHERE&action=projects&type=newest&return=link&num=NUMBER[/url]
setting num to 1 will return your newest project, setting it to 2 will return your second newest and so on.
________________________________________________________________________________
if you want to create a thumbnail to go with the link to your newest project, the parameters and method are exactly the same for the link version but you put it into [ url] tags and return=link is replaced with return=image.
For example:
[url=http://blocks.scratchr.org/API.php?user=USERNAMEHERE&action=projects&type=newest&return=link&num=1][img]http://blocks.scratchr.org/API.php?user=USERNAMEHERE&action=projects&type=newest&return=image&num=1[/img][/url]
___________________________________________________________________________________
Project info
This API returns info about your num'th project as an image of the name. For example, my newest project, has love-it's and favouriters, comments, downloads, views and remixes!
action value:
projects
type value:
newest
return value:
text, loves, faves, comments, remixes, downloads, views
parameters:
user, num, return
[img]http://blocks.scratchr.org/API.php?user=USERNAMEHERE&action=projects&type=newest&return=RETURNVALUE&num=NUMBER[/img]
There are several return values for this action:
text -return the project name
loves - return the number of love-it's
faves - return the number of favouriters
comments - return the number of comments
remixes - return the number of remixes
downloads - return the number of downloads
views - return the number of views
Last edited by sparks (2011-11-24 06:51:54)
Offline
^ home
Random
Random images
This API randomly selects one of up to ten images to display with every page refresh. This works very well for sigs where a user wants a random message or picture shown. For example, this image will randomly change whenever you refresh the page:
Action value:
random
Return value:
image
Parameters:
link1 [link2 link3 link4 link5 link6 link7 link8 link9 link10]
[img]http://www.blocks.scratchr.org/API.php?action=random&return=image&link1=IMAGELINK1&link2=IMAGELINK2[/img]
___________________________________________________________________________________
Random links
This API attribute will link randomly to one of up to ten pages. You can follow the link more than once without refreshing the page and you will still be taken randomly to a different page each time. for example, this link will either take you to the google homepage or the Scratch homepage.
Action value:
random
Return value:
link
Parameters:
link1 [link2 link3 link4 link5 link6 link7 link8 link9 link10]
[url=http://www.blocks.scratchr.org/API.php?action=random&return=link&link1=LINK1URL&link2=LINK2URL]LINKTEXT/IMAGE[/url]
Last edited by sparks (2011-07-22 07:09:16)
Offline
^ home
Friend thumbnails and links
Friend thumbs
This API attribute allows you to display the user images for your n'th friend(s). For example, my newest friend has this image as their user image:
Action value:
friends
Type value:
newest
return value:
image
parameters:
user, num
[img]http://www.blocks.scratchr.org/API.php?action=friends&type=newest&user=USERNAMEHERE&return=image&num=NUMBER[/img]
___________________________________________________________________________________
Friend links
This API attribute allows you to link to the mystuff page of your n'th friend(s). For example, my newest friend's mystuff page can be seen here.
Action value:
friends
Type value:
newest
return value:
link
parameters:
user, num
[url=http://www.blocks.scratchr.org/API.php?action=friends&type=newest&user=USERNAMEHERE&return=link&num=NUMBER]LINK TEXT OR IMAGE HERE[/url]
___________________________________________________________________________________
to create a dynamic image of their user picture to go with the link, use the code below which applies the two API's.
For example:
Thanks to SeptimusHeap for helping with this section of the API!
Last edited by sparks (2011-07-21 18:55:56)
Offline
Customising text returns
The API text return allows changing information about projects and people to be displayed as an image
The standard return above is designed to fit in with the rest of the fora as unobtrusive. However, should you wish to make a text return fit your signature colour scheme at all the grey background and black text simply won't do. This post lists all the additional attributes you can apply to both the text and the background of a text return.
Each attribute is simply added to the URL with an & between each one. For example &width=30&height=30. NEVER use spaces or the image won't show!.
Background attributes
Background size
parameters:
height, width
Notes: Both height and width are set in pixels and may only be whole numbers (integers). If only width is set the height will still snap to that of the font size and visa versa if width is set, not height.
(colour slightly changed for clarification).
[img]http://www.blocks.scratchr.org/API.php?action=text&string=example&height=60&width=100[/img]
Background colour
parameters:
bgr, bgg, bgb
Notes: The background colour can be set using red, green and blue component values. Each can be set to a number from 0 to 255. bgr is red, bgg is green and bgb is blue. A good colour picker that shows you the RGB values of a colour can be found here.
If bgr, bgg and bgb are all unset, the background will revert to the standard forum grey (R=222 G=223 B=223). If you are setting one or two of the three values to 0 you can just leave them unset. So rather than sending &bgr=0&bgg=0&bgb=0 to get black you can just send &bgr=0 as the other two are assumed to be 0 too. In the same way, red can be sent as just &bgr=255.
(R:255 G:255 B:0)
[img]http://www.blocks.scratchr.org/API.php?action=text&string=example&bgr=255&bgg=255[/img
Background image
parameters:
bgimage
Notes: The background image can be set to an online image. Please note, it can take PNG, GIF, JPEG and BMP but does not always work with PNG and BMP. If a background image is set, the background size and colour attributes will do nothing.
(http://www.clker.com/cliparts/Z/W/N/F/6/p/light-blue-square-th.png)
[img]http://www.blocks.scratchr.org/API.php?action=text&string=example&bgimage=LINKTOIMAGE[/img]
Text control and position
These attributes allow you to control the positioning of text.
parameters:
xpos, ypos, font_size, limitstring
Notes: xpos and ypos indicate how far from the top-left corner the text should be drawn (in pixels). The value must be a whole number (integer) for both attributes. They do not both have to be set together, one can be set by itself. When not set they revert to the default value of 0.
(bg colour and size slightly changed for clarification). (x:20 y:30)
[img]http://www.blocks.scratchr.org/API.php?action=text&string=example&xpos=20&ypos=30[/img]
font_size controls the font size. The default size is 2.
(font_size=5)
[img]http://www.blocks.scratchr.org/API.php?action=text&string=example&font_size=5[/img]
limitstring is an attribute that cuts return text short if it's longer than the specified number of characters.
(limited to 5 characters or less)
[img]http://www.blocks.scratchr.org/API.php?action=text&string=example&limitstring=5[/img]
Text colour
The text colour can be controlled using the same rgb system described above to control background colour.
parameters:
textr, textg, textb
(R:10 G:100 B:200)
[img]http://www.blocks.scratchr.org/API.php?action=text&string=example&textr=10&textg=100&textb=200[/img]
Last edited by sparks (2011-07-29 11:17:50)
Offline
Looks like sparks is being awesome again
My newest project:
(using sparks' code)
Last edited by RUMCHEERYPOOPOO (2011-07-19 12:31:28)
Offline
Offline
Is there anything smaller than _sm? Icon sized would be handy for sigs...
EDIT: finished re-documenting online/offline part of the API. projects images and links next!
Last edited by sparks (2011-07-19 12:57:22)
Offline
You should capitalize the title.
News on the other APIs?
Offline
RUMCHEERYPOOPOO wrote:
Looks like sparks is being awesome again
Yep.
Post these on the wiki: dazman wanted dynamically updating projects on his page.
Offline
Wow! That's really impressive! I can imagine this would be very useful, whether you want to use it here on the forum, or even on your own website perhaps. Kudos to you!
Offline
Thanks, Lucario, it started out a just being a way to show which Scratchers on a collab thread were online, but once I added the "link your own online and offline image" people started using it for their sigs I'm just developing it some more now so we'll see where it goes!
Offline
sparks wrote:
Thanks, Lucario, it started out a just being a way to show which Scratchers on a collab thread were online, but once I added the "link your own online and offline image" people started using it for their sigs I'm just developing it some more now so we'll see where it goes!
Ooh! What now? Newest favorite? Newest friend?
Offline
Possibly! It's all possible, do you think newest friend will be helpful? What I really need is to work out how to get the page to make a text image, then text such as project names etc will work too!
Offline
Cool.
Offline
Great stuff, sparks! Thanks for sharing this wonderfullness
Offline
Paddle2See wrote:
Great stuff, sparks! Thanks for sharing this wonderfullness
Thanks, Paddle2See, I'm glad you like it! (especially because I was just a little bit worried that after the Scratch team spent so much time disallowing php or changing.... stuff in posts they wouldn't like this (technically the API is no more dangerous than any other image tag though))
Offline
Well done Sparks! You don't know how much I'll want to see the code of this.
Offline