This is the Mochi Importer modified by me to cater for better file management. This imports all the featured games only, otherwise you can add by keyword.
How to use:
- Upload into your wp-content/plugins/ folder
- Activate via Plugins on the left
- Click on MochiAds on the left bottom to cascade the options
- Click on each link from the top one by one if its the first time otherwise, simply click on FEED GAMES to get newer games that have been featured by Mochi Ad.
- Enjoy.
<?php /* Plugin Name: Mochi Plugin URI: http://wordpress.org/# Description: Turns your blog into a MochiAds portal. Author: Most wanted games. Version: 1.0 Thanks to Emanuele Feronato!! Revision History: Better Manage Game Files Functions */ add_action('admin_menu', 'mt_add_pages'); function mt_add_pages() { add_menu_page('MochiAds', 'MochiAds', 8, __FILE__, 'mt_toplevel_page'); add_submenu_page(__FILE__, 'Mochi Table', 'Mochi Table', 8, 'mochi-table', 'mochi_table'); add_submenu_page(__FILE__, 'Mochi Directory', 'Mochi Directory', 8, 'mochi-directory', 'mochi_directory'); add_submenu_page(__FILE__, 'Categories', 'Categories', 8, 'mochi-create-categories', 'mochi_create_categories'); add_submenu_page(__FILE__, 'Feed Games', 'Feed Games', 8, 'mochi-feed-games', 'mochi_feed_games'); add_submenu_page(__FILE__, 'Add Games to Blog', 'Add games to blog', 8, 'mochi-add-games', 'mochi_add_games'); add_submenu_page(__FILE__, 'Manage Game Files', 'Manage Game Files', 8, 'manage-game-files', 'manage_game_files'); add_submenu_page(__FILE__, 'Add Games on Keyword', 'Add Games on Keyword', 8, 'add-games-on-keyword', 'add_games_on_keyword'); } function mt_toplevel_page() { echo "<h2>MochiAds Import Plugin</h2>"; echo "<p>Thanks to Feronato for the original idea. It has been updated with more functionalities on game file management. Terms of use is the usual. It is your own sole responsibility of using this for anything. Mostwanted and the author are not responsibile in anyway.</p>"; echo "<p>For more information, contributions, updates and so on visit <a href = \"http://www.mostwanted.com.au\">www.mostwanted.com.au</a></p>"; } function add_games_on_keyword() { global $wpdb; $list = ""; $inserted = 0; $offset = 0; if (!isset($_POST["keyword"])) { echo "<h2>Find Games on Keyword</h2>"; echo 'Offset at: '.$offset; echo '<form name="keywordinput" action="?page=add-games-on-keyword" method="post">Keyword: <input type="text" name="keyword" /><br/>Offset: <input type="text" name="offset" value="0"/><br/><input type="submit" value="Find from offset 0" /></form>'; return; } else { $offset = $_POST["offset"]; } echo "<h2>Result on Keyword '".$_POST["keyword"]."'</h2>"; $mochi_url = "http://www.mochiads.com/feeds/games/74420952224d4b62/all?format=json&limit=500&offset=".$offset; //$_POST["keyword"] $feed = file_get_contents($mochi_url); $games_array = json_decode($feed,true); $number_of_games = count($games_array[games]); $offset += $number_of_games; for($x=0;$x<$number_of_games;$x++){ $insert = ""; $game_title = ""; $values = ""; foreach($games_array[games][$x] as $varname => $varvalue) { $$varname = $varvalue; if($varname=="controls"){ $app =""; for($y=0;$y<count($controls);$y++){ $app.= implode("=",$controls[$y]); if($y<count($controls)-1){ $app.= ";"; } } $controls = $app; } if ($varname=="name") { $game_title = str_replace("'", "\\'", $$varname); } if($varname=="tags"){ $tags = implode(",",$tags); } if($varname=="categories"){ $categories = implode(",",$categories); } $insert.= "$varname,"; $values.= "'".str_replace("'","\\'",$$varname)."',"; } if(strpos($game_title, $_POST["keyword"])) { $id = $wpdb->get_var("SELECT uuid FROM ".$wpdb->prefix."mochi WHERE uuid = '$uuid'"); if(!$id){ $query = "insert into ".$wpdb->prefix."mochi (".$insert."status)values(".$values."'new')"; $list .= "<li>".$name."</li>"; $wpdb->query($query); $inserted++; } } } if($inserted){ echo "<p>$inserted new games found on keyword '".$_POST["keyword"]."'</p>"; echo "<ol>$list</ol>"; }else{ echo "No NEWER games found at the moment containing the keyword '".$_POST["keyword"]."'..."; } echo '<br/><br/>Try a different keyword.'; echo 'Offset at: '.$offset; echo '<form name="keywordinput" action="?page=add-games-on-keyword" method="post">Keyword: <input type="text" name="keyword" value="'.$_POST["keyword"].'"/><br/>Offset: <input type="text" name="offset" value="'.$offset.'"/><br/><input type="submit" value="Find From Offset" /></form>'; } function manage_game_files(){ global $wpdb; echo "<h2>Manage Game Files</h2>"; if($_GET[toggle]){ $query = "select id,swf_url,blog_url from ".$wpdb->prefix."mochi where id = $_GET[toggle]"; $game = $wpdb->get_row($query,ARRAY_A); if($game[blog_url]){ $unlink = unlink($game[blog_url]); if($unlink){ echo "<p>".$game[blog_url]." successfully removed</p>"; $query = "update ".$wpdb->prefix."mochi set blog_url = \"\" where id = $game[id]"; $wpdb->query($query); } else{ echo "<p>".$game[blog_url]." not removed</p>"; } } else{ $parts = explode("/",$game[swf_url]); $filename = WP_PLUGIN_DIR."/mochi/mochigames/".$parts[count($parts)-1]; $copy = copy($game[swf_url],$filename); if($copy){ echo "<p>".$game[swf_url]." successfully copied to ".$filename."</p>"; $query = "update ".$wpdb->prefix."mochi set blog_url = \"$filename\" where id = $game[id]"; $wpdb->query($query); } else{ echo "<p>".$game[swf_url]." not copied</p>"; } } } if($_GET[activate]){ $query = "select id,swf_url,blog_url from ".$wpdb->prefix."mochi where blog_url = '' order by id desc limit 0,$_GET[activate]"; $games = $wpdb->get_results($query,ARRAY_A); echo "<p><strong>Progress</strong> ["; $success = 0; $failed = 0; foreach($games as $game){ $parts = explode("/",$game[swf_url]); $filename = WP_PLUGIN_DIR."/mochi/mochigames/".$parts[count($parts)-1]; $copy = copy($game[swf_url],$filename); if($copy) { $success++; echo "."; $query = "update ".$wpdb->prefix."mochi set blog_url = \"$filename\" where id = $game[id]"; $wpdb->query($query); } else { $failed++; //echo "<p>".$game[swf_url]." not copied</p>"; } } echo "] ".$success."/".$failed." (success/fail)</p>"; } if($_GET[activated] == 1){ $query = "select id,name,swf_url,blog_url from ".$wpdb->prefix."mochi where blog_url != '' order by id desc limit 0,100"; } else if ($_GET[activated] == 0){ $query = "select id,name,swf_url,blog_url from ".$wpdb->prefix."mochi where blog_url = '' order by id desc limit 0,100"; } $games = $wpdb->get_results($query,ARRAY_A); echo "<strong>Automation Activate</strong> -> <a href = \"?page=manage-game-files&activate=50\">50</a> | <a href = \"?page=manage-game-files&activate=100\">100</a> | <a href = \"?page=manage-game-files&activate=200\">200</a>"; echo "<hr/>"; echo "<ol>"; echo "<li><strong>Activated</strong> -> <a href = \"?page=manage-game-files&activated=1\">FILTER</a> | "; echo "<strong>Deactivated</strong> -> <a href = \"?page=manage-game-files&activated=0\">FILTER</a></li>"; echo "<strong>Select Count</strong> -> ".count($games)."</li>"; echo "<hr/>"; if($games) { foreach($games as $game){ if($game[blog_url]){ $game[swf_url]=$game[blog_url]; } echo "<li><strong>".$game[name]."</strong> -> <a href = \"?page=manage-game-files&toggle=$game[id]\">".$game[swf_url]."</a></li>"; } } else { echo "<li><strong>none</strong></li>"; } echo "</ol>"; } function mochi_directory(){ echo "<h2>Mochi Directory</h2>"; $dirname = WP_PLUGIN_DIR."/mochi/mochigames"; if (!file_exists($dirname)){ $creation = mkdir($dirname, 0777); if($creation){ echo "<p>Mochi Directory successfully created at $dirname</p>"; } else{ echo "<p>Mochi Directory not created - try again</p>"; } } else{ echo "<p>Mochi Directory already created at $dirname</p>"; } } function mochi_add_games(){ global $wpdb; echo "<h2>Add Games to blog</h2>"; echo "<ol>"; $inserted = false; for($i=1;$i<=100;$i++){ $row = $wpdb->get_row("select * from ".$wpdb->prefix."mochi where `status`= 'new' order by `popularity` asc limit 0, 100"); if($row){ $inserted = true; $cat_id = array(); foreach($row as $varname => $varvalue) { $$varname = $varvalue; } echo "<li><strong>$name</strong><ul><li>Categories: $categories</li>"; $categs = explode(",",$categories); for($x=0;$x<count($categs);$x++){ $categs[$x] = str_replace("-"," ",$categs[$x]); array_push ($cat_id,get_cat_id($categs[$x])); } if($leaderboard_enabled){ array_push ($cat_id,get_cat_id("High Scores")); echo "<li>Leaderboard enabled</li>"; } echo "</ul>"; $post = array(); $post['post_title'] = $name; $post['post_status'] = 'publish'; $post['post_author'] = 2; $post['post_type'] = 'post'; $post['post_category'] = $cat_id; $post['post_date'] = $feed_approval_created; $post['tags_input'] = $tags.','.$author; $post['post_content'] = '<img class="aligncenter size-full" title="'.$name.'" src="'.$thumbnail_url.'" alt="'.$name.'" />'.$description; $post_id = wp_insert_post($post); add_post_meta($post_id, 'description', $description); add_post_meta($post_id, 'height', $height); add_post_meta($post_id, 'instructions', $instructions); add_post_meta($post_id, 'author', $author); add_post_meta($post_id, 'swf_url', $swf_url); $site_swf_url = "/wp/wp-content/plugins/mochi/mochigames".substr($swf_url, strrpos($swf_url, '/')); add_post_meta($post_id, 'site_swf_url', $site_swf_url); add_post_meta($post_id, 'thumbnail_url', $thumbnail_url); add_post_meta($post_id, 'zip_url', $zip_url); add_post_meta($post_id, 'popularity', $popularity); add_post_meta($post_id, 'width', $width); $query = "update ".$wpdb->prefix."mochi set status = 'published' where id = $id"; $list .= "<li>".$name."</li>"; $wpdb->query($query); echo "</li>"; } } if(!$inserted){ echo "<li>No new games to add</li>"; } echo "</ol>"; } function mochi_feed_games(){ global $wpdb; $list = ""; $inserted = 0; echo "<h2>New Games</h2>"; $mochi_url = "http://www.mochiads.com/feeds/games/74420952224d4b62/featured_games/all?format=json"; $feed = file_get_contents($mochi_url); $games_array = json_decode($feed,true); $number_of_games = count($games_array[games]); for($x=0;$x<$number_of_games;$x++){ $insert = ""; $values = ""; foreach($games_array[games][$x] as $varname => $varvalue) { $$varname = $varvalue; if($varname=="controls"){ $app =""; for($y=0;$y<count($controls);$y++){ $app.= implode("=",$controls[$y]); if($y<count($controls)-1){ $app.= ";"; } } $controls = $app; } if($varname=="tags"){ $tags = implode(",",$tags); } if($varname=="categories"){ $categories = implode(",",$categories); } $insert.= "$varname,"; $values.= "'".str_replace("'","\\'",$$varname)."',"; } $id = $wpdb->get_var("SELECT uuid FROM ".$wpdb->prefix."mochi WHERE uuid = '$uuid'"); if(!$id){ $query = "insert into ".$wpdb->prefix."mochi (".$insert."status)values(".$values."'new')"; $list .= "<li>".$name."</li>"; $wpdb->query($query); $inserted++; } } if($inserted){ echo "<p>$inserted new games found</p>"; echo "<ol>$list</ol>"; } else{ echo "No new games at the moment..."; } } function mochi_create_categories() { echo "<h2>Categories</h2>"; echo "<ul>"; $categories = array("Action","Adventure","Board Game","Casino","Dress Up","Driving","Fighting","High Scores","Other","Customize","Puzzles","Shooting","Sports"); $nicenames = array("action","adventure","board_game","casino","dress_up","driving","fighting","leaderboard_enabled","other","customize","puzzles","shooting","sports"); for($x=0;$x<count($categories);$x++){ $new_category = array("cat_name" => $categories[$x],"category_description" => "Flash $categories[$x] Games"); $cat_id = wp_insert_category($new_category); if(!$cat_id){ return(new IXR_Error(500, __("Sorry, the new category failed."))); } else{ echo "<li><strong>$categories[$x]</strong> category successfully created with id = <strong>$cat_id</strong></li>"; } } echo "</ul>"; } function mochi_table() { global $wpdb; echo "<h2>Mysql table</h2>"; $table_name = $wpdb->prefix . "mochi"; $query = "CREATE TABLE `$table_name` ( `id` int(11) NOT NULL auto_increment, `rating` text collate utf8_unicode_ci NOT NULL, `updated` text collate utf8_unicode_ci NOT NULL, `popularity` text collate utf8_unicode_ci NOT NULL, `description` text collate utf8_unicode_ci NOT NULL, `key_mappings` text collate utf8_unicode_ci NOT NULL, `height` text collate utf8_unicode_ci NOT NULL, `controls` text collate utf8_unicode_ci NOT NULL, `game_url` text collate utf8_unicode_ci NOT NULL, `tags` text collate utf8_unicode_ci NOT NULL, `slug` text collate utf8_unicode_ci NOT NULL, `categories` text collate utf8_unicode_ci NOT NULL, `instructions` text collate utf8_unicode_ci NOT NULL, `uuid` text collate utf8_unicode_ci NOT NULL, `author` text collate utf8_unicode_ci NOT NULL, `control_scheme` text collate utf8_unicode_ci NOT NULL, `author_link` text collate utf8_unicode_ci NOT NULL, `feed_approval_created` text collate utf8_unicode_ci NOT NULL, `name` text collate utf8_unicode_ci NOT NULL, `swf_url` text collate utf8_unicode_ci NOT NULL, `recommended` text collate utf8_unicode_ci NOT NULL, `thumbnail_url` text collate utf8_unicode_ci NOT NULL, `created` text collate utf8_unicode_ci NOT NULL, `game_tag` text collate utf8_unicode_ci NOT NULL, `leaderboard_enabled` text collate utf8_unicode_ci NOT NULL, `zip_url` text collate utf8_unicode_ci NOT NULL, `width` text collate utf8_unicode_ci NOT NULL, `status` text collate utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($query); $query = "ALTER TABLE `$table_name` ADD `swf_file_size` TEXT NOT NULL AFTER `key_mappings`;"; $wpdb->query($query); $query = "ALTER TABLE `$table_name` ADD `recommendation` TEXT NOT NULL AFTER `controls`;"; $wpdb->query($query); $query = "ALTER TABLE `$table_name` ADD `blog_url` TEXT NOT NULL AFTER `game_url`;"; $wpdb->query($query); $query = "ALTER TABLE `$table_name` ADD `resolution` TEXT NOT NULL AFTER `width`;"; $wpdb->query($query); echo "Table <strong>".$wpdb->prefix."mochi</strong> successfully created and updated (working at 05-15-2009)"; } ?>