I am aware that there is an API called BukGet but how do I use this in PHP? Can someone please post the code they have used to implement this to their website? Keir
Check out their github. There are a few examples. I've implemented it using .NET, and it works really nice. @SteveMcGrath what do you want that PHP script to do?
So would that work on a website? I am trying to get the download link (done) and below it, it would say Version and then get the from BukkitDev and CB Version and get that from BukkitDev too. Thanks Keir
So like this: Download Current Version Supported CB version The flow of my implementation is like this: Request to API --> Get result --> Result to own class --> get data from class That self-made class contains the plugin information, and a list of the Versions. The versions are also a custom class This structure allows you to easily expand or add functionality later on. However, if you need that information only from you plugin, you could just use strpos($haystack,$needle), mb_substr($haystack,$startpos) and explode($haystack,$startpos) to get the correct parts out of the result.
Yeah exactly like that, I am rubbish at PHP so is there any chance you could post the code to use? Keir
There a quite a few, would you be able to make this configurable? But if this isn't possible could you use locked-chest-commands I am presuming it wouldn't be too hard to change this? Simply URL change right? Thanks for all your help Keir
Here's your 50-line solution: example: http://automation.bertware.net/plugin.php?plugin=UselessTNT as you can see, you insert the plugin name using the "plugin" parameter I made it using functions, so it's quite modular. You'll probably be able to onderstand how the functions are working, so you could change them to get other values as well PHP: <?php$plugin_name = $_GET['plugin']; //Get plugin name from URL$plugin_name = strtolower($plugin_name); //to lower for valid URL$base = "http://bukget.org/api/plugin/"; // Base path for bukget API plugin search$url=$base . $plugin_name;$content = file_get_contents($base . $plugin_name); //Get contentecho Getname($content); //get plugin nameecho "<br>";echo GetVersion($content); //get plugin versionecho "<br>";echo GetLink($content);//get plugin DL linkecho "<br>";echo GetCB($content); //get compatible CB version function Getname($cont) {//example: "name": "locked-chest-surprise",$start = strpos($cont,'"plugin_name": "');$cont = mb_substr($cont,$start+16); //+16, because strpos get start of string, we need the end$split = explode('"',$cont); //get first element of this array, to get the value$cont = $split[0];return $cont;}function GetVersion($cont) {//example: "name": "UselessTNT ver.2.8",$versions_start = strpos($cont,'"md5":'); //make sure it detects the version name, not hte plugin name. so remove first part of result$cont = mb_substr($cont,$versions_start);$start = strpos($cont,'"name": "');$cont = mb_substr($cont,$start+9,$versions_start);$split = explode('"',$cont);$cont = $split[0];return $cont;}function GetLink($cont) {//example: "dl_link": "http://dev.bukkit.org/media/files/562/989/UselessTNT.jar",$start = strpos($cont,'"dl_link": "');$cont = mb_substr($cont,$start+12);$split = explode('"',$cont);$cont = $split[0];return $cont;}function GetCB($cont) {//example: "game_builds": [ "CB 1.0.1-R1" ], //spaces in this comment might be incorrect$start = strpos($cont,'"CB ');$cont = mb_substr($cont,$start+1);$split = explode('"',$cont);$cont = $split[0];return $cont;} ?>
Wow!!!! Thanks for this, I cant try it just now but I will when I'm back at my pc. Do you mind if I post this on my blog? All credit will be given to you plus a link to this topic. Thanks Keir
Hint: use this line: PHP: echo '<a href="' . GetLink($content) . '"><img src="http://mag.racked.eu/mcimage/i327/' . GetName($content) . '/' . GetVersion($content) . '/mca.png"</a>'; to generate an image + hyperlink as shown at: http://automation.bertware.net/plugin.php?plugin=UselessTNT
Wow! You are completely awesome! Does the URL have to have the ?plugin=UselessTNT bit or can I have it without that. Keir
you should ALWAYS add the plugin parameter, but of course you can change the plugin. it can be anything, like ?plugin=[PLUGIN_NAME] example: http://automation.bertware.net/plugin.php?plugin=worldguard
Ok it's just that now my URL will look like this keir-nellyer.co.uk/main-projects/generalcommands?plugin=generalcommands Also I don't think the Plugin bit in the URL would work with WordPress too well. Keir
that ?plugin part should work in wordpress. However, if you want to use this for only one plugin: replace PHP: $plugin_name = $_GET['plugin']; with PHP: $plugin_name = "generalcommands"; or you could also use this code (Default value, but can be overwritten using ?plugin) PHP: $plugin_name = $_GET['plugin']; //get name from urlif ($plugin_name =""){ //if no name provided$plugin_name = "generalcommands"; // set default} I tried your link but it doesn't work, as wordpress thinks its a wordpress page. I am currently using this method: subdomain, with 2 directory's: -site (wordpress site) -tools (php scripts and such stuff) maybe you could add such a 'tools' directory even in your wordpress main directory. then I am using this code: HTML: <html><object data="URL HERE" width="300" height="125"><embed src="URL HERE" width="300" height="125"> </embed>Error</object></html> you can change the width and height. This is a code snippet I found on the internet, but it works nicely with wordpress.
@Bertware Thanks soooo much for your help! I found the time today to add this to my wordpress site and it works! I had to use a plugin to get PHP working and modify a little bit of the code to make it work with wordpress and it is amazing. This will help loads of plugin developers who have a website and use BukkitDev. Keir
Hey, thanks for this! I never knew such an API existed for BukkitDev. Trying out your script, one thing I've noticed is that the plugin version format varies with different plugins, it seems to simply grab the title of the uploaded file. Is there any way to strip this down to a simple, numerical number? Also, how would you go about displaying the information for multiple plugins on one page? Thanks!
the PHP script should contain the functions. you need to get the API result to a variable, in this example i use the $content variable PHP: $plugin_name = "plugin name"; //enter name, or enter code to retrieve from URL. Must be lowercase!$base = "http://bukget.org/api/plugin/"; // Base path for bukget API plugin search$url=$base . $plugin_name;$content = file_get_contents($base . $plugin_name); //Get content then you can use the functions to retrieve the information, as the 2 examples below are showing PHP: echo Getname($content); //get plugin nameecho "<br>";echo GetVersion($content); //get plugin versionecho "<br>";echo GetLink($content);//get plugin DL linkecho "<br>";echo GetCB($content); //get compatible CB version PHP: echo '<a href="' . GetLink($content) . '"><img src="http://mag.racked.eu/mcimage/i327/' . GetName($content) . '/' . GetVersion($content) . '/mca.png"</a>';
Yeah, I got that part.. but I need to display multiple of those per page. E.g. if I supplied the link: http://yousite.com/whatever.php?plugin=mcmmo&plugin2=vanish Because the current script only allows for one plugin name (in your example the $plugin_name variable) but I need it to handle multiple plugin names.
You can. But I need the script to then process *both* of those variables and return the necessary information for both of them on the same page.
I would just embed the script on every page you need it, for every plug-in you want to show, and provide the plugin name in the URL.