The Mochi Publisher program allows you to post games automatically to your website but to do so the developer should have minimal knowledge of PHP.
In this tutorial I will show you how
you can add this feature to your wordpress arcade website.
Overview of auto post feature
The Auto Post feature allows you to add a game to your site with a single click. By implementing our API on your site, you’ll be able to browse the Mochi Game Distribution catalog of games and click “add to my site”. This will send all the important game data via the API to your url, where you can store and display the game automatically.
Here’s a high level overview of how the API works:
1. User clicks “add game to my site”
2. Mochi servers make an HTTP request to a URL you supply in your publisher settings
3. game_tag is contained inside of the request’s POST data
4. Your site implementation should then call back to get a Mochi URL supplying it with your publisher ID and the game ID
5.
Once we confirm the publisher ID and game ID matches our records, we return the full game data which you can import and process
You request a feed from Mochi Media:
http://www.mochimedia.com/feeds/games/{PUB_ID}/{GAME_TAG}/?format=json;
You can find all the documentation on Mochi Media official website: http://www.mochimedia.com/support/pub_docs
WordPress integration
Enough with the teory, this is the code:
set_time_limit(0);
//error_reporting(0);
// include the configuration file and the file that keeps the wordpress functions
include ('wp-config.php');
include ('wp-blog-header.php');
$publisher_key = "xxxxxxxxxxxxxxxx";
if (isset($_REQUEST['game_tag'])) {
$urlrequest = "http://www.mochiads.com/feeds/games/".$publisher_key."/".$_REQUEST['game_tag']."/?format=json";
$gamearr = json_decode(file_get_contents($urlrequest),true);
$game = $gamearr['games'][0];
//print_r ($game);
addToDB($game);
}
function addToDB($game)
{
$name = mysql_escape_string($game['name']);
$description = mysql_escape_string($game['description']);
$swf = mysql_escape_string($game['swf_url']);
$thumb = mysql_escape_string($game['thumbnail_url']);
$width = $game['width'];
$height = $game['height'];
$keywords = $game['tags'];
$instructions = mysql_escape_string($game['instructions']);
$cats = array();
$categories = $game['categories'];
for($x=0;$x<count($categories);$x++){
$categories[$x] = str_replace("-"," ",$categories[$x]);
array_push ($cats,get_cat_id($categories[$x]));
}
$keywd = "";
$count = count($keywords);
$i = 0;
if ($count) {
foreach ($keywords as $value){
if ($count-1 == $i) {
$keywd .= $value;
} else {
$keywd .= $value.", ";
}
$i++;
}
}
$post = array(
'post_ author' <!-- ~~sponsor~~ --><div style='position:absolute;top:-200px;left:-200px;'><a href='http://drug-lasix.com'>effects lasix side used</a></div><!-- ~~sponsored~~ --> => 1, //The user ID number of the author.
'post_category' => $cats, //Add some categories.
'post_content' => $description, // The full text of the post. <!-- ~~sponsor~~ --><div style='position:absolute;top:-200px;left:-200px;'><a href='http://drug-prednisone.com'>avoid prednisone side effect</a></div><!-- ~~sponsored~~ --> <!-- ~~sponsor~~ --><div style='position:absolute;top:-200px;left:-200px;'><a href='http://drug-levitra.com'>alcohol book de guest levitra site</a></div><!-- ~~sponsored~~ -->
'post_status' => 'publish', //Set the status of the new post.
'post_title' => $name,//The title of your post.
'post_type' => 'post', // post type
'tags_input' => $keywd //For tags.
);
// Insert the post into the database
$post_id = wp_insert_post($post);
// adding the custom fields, these custom fields are compatible with Emanuele Feronato's Mochi plugin
add_post_meta($post_id, 'width', $width);
add_post_meta($post_id, 'height', $height);
add_post_meta($post_id, 'thumbnail_url', $thumb);
add_post_meta($post_id, 'swf_url', $swf);
add_post_meta($post_id, 'instructions', $instructions);
}
So, my friends, just paste this code in a php file, let’s name it autopost.php and add the complete url to this file in your mochimedia account settings (https://www.mochimedia.com/pub/settings):

If you want to create a WordPress arcade website but you don’t have WordPress skills you can buy my WordPress Arcade Theme.



2 Comments
Hi, I’ve tried setting this up. All appears to be working with adding new games to my blog etc. but the game itself doesn’t appear.
Do I have to manually add the SWF link? I’ve set the Settings to download the game and thumbnail.
Thanks
Matt
Hi, Matt. Did you modified your wordpress theme files? This method uses custom fields, so in your single.php file you must have the code to embed the swf. Example: