Skip to content

Instantly share code, notes, and snippets.

@dennyhalim
Created September 14, 2009 11:04
Show Gist options
  • Save dennyhalim/186601 to your computer and use it in GitHub Desktop.
Save dennyhalim/186601 to your computer and use it in GitHub Desktop.
<?php
/*created by Luke Pauline, aka Randomator. Made in Rochdale near Manchester in Lancashire in England.
visit me at http://www.random-flash.co.uk or http://www.dolphinweb.co.uk
for help and advice contact me via mochiads by the forums or by pm best to do it through forums since most of the people there
know more about php and how this works than I do
copyright © 2009 legitimate software*/
//enter database info here
$host = ""; //what is your mysql host?
$base = ""; //what is your database called?
$user = ""; //what is your database username?
$pass = ""; //what is your database password?
$pubID = ""; //what is your mochi ads publisher ID?
$site = ""; //what is your domain name?
$swfFol = "games"; //what is the folder in which your games are stored?
$imgFol = "games/images"; //what is the folder in which your images are stored?
$maxW = "675";
$published = "1"; //would you like the games to be pulished as soon as the script is finished?
//this is the part you will have to customise
//one way to do it is to set the category references
//if you had only five categories action, driving, shooting, sports and misc/other you could set the category refences for both fighting and action as the category reference for action then all fighting games would also be put into action etc
//set categories preferences
//this is how the script decides which category to put the game in because mochi passes you multiple categories
//I tend to put action and adventure low because most of games on Mochi are classed as action
//and I put those that are blacklisted at the top
$prefer[]=array();
$prefer["Driving"] = "1";
$prefer["Shooting"] = "2";
$prefer["Sports"] = "3";
$prefer["Fighting"] = "4";
$prefer["Board Game"] = "5";
$prefer["Puzzles"] = "6";
$prefer["Casino"] = "7";
$prefer["Adventure"] = "8";
$prefer["Action"] = "9";
$prefer["Dress Up"] = "10";
$prefer["Pimp my / Customize"] = "11";
$prefer["Other"] = "12";
//set category references
//to find out this open up the cat table in phpmyadmin and look at the numbers next to each of the categories
$catRef[]=array();
$catRef['Action']="2";
$catRef['Adventure']="3";
$catRef['Board Game']="4";
$catRef['Casino'] = "5";
$catRef['Driving']="6";
$catRef['Fighting']="7";
$catRef['Puzzles']="8";
$catRef['Shooting']="9";
$catRef['Sports']="10";
$catRef['Other']="11";
$catRef["Dress Up"] = "12";
$catRef["Pimp my / Customize"] = "13";
//set blacklist (1 for allowed 0 for disallowed)
$catAl[]=array();
$catAl['Action']="1";
$catAl['Adventure']="1";
$catAl['Board Game']="1";
$catAl['Casino']="1";
$catAl['Driving']="1";
$catAl['Dress Up']="1";
$catAl['Fighting']="1";
$catAl['Puzzles']="1";
$catAl['Pimp my / Customize']="1";
$catAl['Shooting']="1";
$catAl['Sports']="1";
$catAl['Other']="1";
//connect to database
$con = mysql_connect($host,$user,$pass);
if(!$con){
die("Could not connect to database: ".mysql_error());
}
mysql_select_db($base,$con);
//recover the variable game_tag
$game_tag=$_REQUEST['game_tag'];
//retrieve and decode json feed
$mFeed = "http://www.mochiads.com/feeds/games/".$pubID."/".$game_tag."/?format=json";
$games = json_decode(file_get_contents($mFeed),true);
//separating out json feed
$game = $games["games"][0];
$name = $game["name"];
$desc = mysql_real_escape_string($game["description"]);
$swf = $game["swf_url"];
$height = $game["height"];
$width = $game["width"];
if($width>$maxW){
$height *= (100/$width*$maxW)/100;
$width = $maxW;
}
$img = $game["thumbnail_url"];
$slug = $game["slug"];
$mC=13;
foreach($game["categories"] as $key => $val){
if($prefer[$val]<$mC){
$mC=$prefer[$val];
$cate=$catRef[$val];
$chat=$val;
}
}
echo $cate;
if(!empty($mFeed)){
if($catAl[$chat]==1){
//begin copying files
//retrieve swf file
$cha = curl_init();
curl_setopt($cha, CURLOPT_URL, $swf);
//copy swf into your folder
$fha = fopen($swfFol."/".$slug.".swf", 'w');
curl_setopt($cha, CURLOPT_FILE, $fha);
curl_exec($cha);
curl_close($cha);
fclose($fha);
$swf = $site."/".$swfFol."/".$slug.".swf";
//retrieve thumbnail
$chb = curl_init();
curl_setopt($chb, CURLOPT_URL, $img);
//copy thumbnail into your folder
$fhb = fopen($imgFol."/".$slug."_thumb.gif", 'w');
curl_setopt($chb, CURLOPT_FILE, $fhb);
curl_exec($chb);
curl_close($chb);
fclose($fhb);
$img = $site."/".$imgFol."/".$slug."_thumb.gif";
//add game to database
$sql = "INSERT INTO `ava_games` (`id`, `name`, `description`, `url`, `catergory_id`, `hits`, `published`, `user_submit`, `width`, `height`, `image`, `import`, `filetype`) VALUES (NULL, '$name', '$desc', '$swf', '$cate', '0', '1', '0', '$width', '$height', '$img', '0', '1')";
mysql_query($sql) or die(mysql_error);
}
}
//close connection
mysql_close($con);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment