Kaeliah
04-02-2011, 01:46 AM
Multiple Alternate Image
By Kaeliah
Modification TOS (http://www.mysidiaadoptables.com/forum/blog.php?cp=3)
I felt very bad for going on hiatus so to make up for it I decided to release this publicly instead of for premium only. Please note that this is a complex script and you should know at least a little PHP before attempting installation. That said, I tried to make it as simply as possible.
Step 1: Open the functions.php, levelup.php & doadopt.php files.
NOTE: Any page that inserts a row into the owned_adoptables table will need an extra '', added after imageurl.
Find the two functions 'getaltstatus' and 'getcurrentimage' in functions.php. They should be one after the other. Replace those two functions with the code below:
function getaltstatus($parentid, $childid, $childlevel) {
// This function determines if we will use alternate images...
$alt = "Cannot find adopt with given parent id.";
// First we need to see if this adoptable type has alternate images enabled...
$query = "SELECT * FROM ".$prefix."adoptables WHERE id='".$parentid."'";
$result = mysql_query($query);
$num = mysql_num_rows($result);
$alternates=@mysql_result($result, $i,"alternates");
// Let's see if the level we are on is the level that requires alternates
if($alternates == "enabled") {
// Alternates for adoptable type are enabled, next check to see if this adopt is already using an alternate.
$query = "SELECT * FROM ".$prefix."owned_adoptables WHERE aid='".$childid."'";
$result = mysql_query($query);
$num = mysql_num_rows($result);
$usealt=@mysql_result($result, $i,"usealternates");
$currentimage=@mysql_result($result, $i,"altimage");
if($usealt == "no"){
// Alternates are not currently being used, next check for alternate image w/ specified entry level.
$query = "SELECT * FROM ".$prefix."alternates WHERE entry='".$childlevel."' AND adoptid='".$parentid."'";
$result = runquery($query);
while($row = mysql_fetch_array($result)){
$method=$row['method'];
$data=$row['data'];
$newurl=$row['alturl'];
// check what kind of method we're using to choose an alternate.
if($method == "random"){
$chance = rand(1, $data);
if($chance == 1){
$alt = $newurl;
}
else{
$alt = "The random finder did not pick 1.";
}
}
else{
$alt = "Not finding method random...";
}
$i++;
}
}
else if($usealt == "yes"){
// This adopt is already using an alternate, so let's get a path.
$query = "SELECT * FROM ".$prefix."alternates WHERE alturl='".$currentimage."' AND adoptid='".$parentid."'";
$result = mysql_query($query);
$path=@mysql_result($result, $i,"path");
$subpath=@mysql_result($result, $i,"subpath");
if($subpath != 0){// check for a subpath.
$query = "SELECT COUNT(*) FROM ".$prefix."alternates WHERE subpath='".$subpath."' AND path='".$path."' AND replacedlevel='".$childlevel."' AND adoptid='".$parentid."'";
$result = mysql_query($query);
$num = mysql_fetch_array($result);
}
else if($path != 0){ // no subpath, so check for a path.
$query = "SELECT COUNT(*) FROM ".$prefix."alternates WHERE path='".$path."' AND replacedlevel='".$childlevel."' AND adoptid='".$parentid."'";
$result = mysql_query($query);
$num = mysql_fetch_array($result);
}
if($num[0] > 1){
// more than 1 path was found, so let's run through subpaths.
$i = 0;
while($i < $num[0]){
$method=@mysql_result($result, $i,"method");
$data=@mysql_result($result, $i,"data");
$newurl=@mysql_result($result, $i,"alturl");
// check what kind of method we're using to choose a subpath.
if($method == "random"){
$chance = rand(1, $data);
if($chance == 1){
$alt = $newurl;
}
else{
$alt = "none";
}
}
else{
$alt = "none";
}
$i++;
}
// In order for paths to work, we HAVE to have a subpath picked. Since a loop until one is picked would be tedius, we'll just randomly pick one.
if($alt == "none"){
$query = "SELECT * FROM ".$prefix."alternates WHERE path='".$path."' AND replacedlevel='".$childlevel."' ORDER BY RAND() LIMIT 1 ";
$result = mysql_query($query);
$newurl=@mysql_result($result, $i,"alturl");
$alt = $alturl;
}
} // end subpaths
else{
// No path was found, so now we just need to pick an alternate.
$query = "SELECT * FROM ".$prefix."alternates WHERE adoptid='".$parentid."' AND replacedlevel = '".$childlevel."'";
$result = mysql_query($query);
$num = mysql_fetch_array($result);
$method=@mysql_result($result, $i,"method");
$data=@mysql_result($result, $i,"data");
$newurl=@mysql_result($result, $i,"alturl");
if($method == "random"){
$chance = rand(1, $data);
if($chance == 1){
$alt = $newurl;
}
else{
$alt = "none";
}
}
else{
$alt = "none";
}
} // End No Subpaths
} // end alternates already enabled.
} // end alternates enabled
else{
$alt = "alternates are reading disabled.";
}
return $alt;
}
function getcurrentimage($aid) {
// This function determines which image we should use for a given adoptable...
$image = "";
// First we select the adoptable from the database and get some basic information...
$query = "SELECT * FROM ".$prefix."owned_adoptables WHERE aid='".$aid."'";
$result = mysql_query($query);
$currentimage=@mysql_result($result, 0,"altimage");
$imageurl=@mysql_result($result, 0,"imageurl");
if($currentimage == ""){
// if the currentimage is blank, we're not using an alternate so grab the primary image.
$image = $imageurl;
}
else{
$image = $currentimage;
}
if($image == ""){
// For some reason, both primary and current images are blank, so let's do one more check.
$currentlevel=@mysql_result($result, 0,"currentlevel");
$type=@mysql_result($result, 0,"type");
if($currentlevel != 0){
$query = "SELECT * FROM ".$prefix."levels WHERE adoptiename = '".$type."' AND thisislevel = '".$currentlevel."'";
$result = mysql_query($query);
$primaryimage=@mysql_result($result, 0,"primaryimage");
mysql_query("UPDATE ".$prefix."owned_adoptables WHERE aid = '".$aid."' SET imageurl = '".$primaryimage."'");
$image = $primaryimage;
}
else{
$query = "SELECT * FROM ".$prefix."adoptables WHERE type = '".$type."'";
$result = mysql_query($query);
$eggimage=@mysql_result($result, 0,"eggimage");
mysql_query("UPDATE ".$prefix."owned_adoptables WHERE aid = '".$aid."' SET imageurl = '".$eggimage."'");
$image = $eggimage;
}
if($image == ""){
// both are definitely blank... show error.
$image = "http://www.".$GLOBALS['domain']."".$GLOBALS['scriptpath']."/templates/icons/delete.gif";
}
}
return $image;
}
Find in levelup.php at about line 140:
$parentid = converttypetoparentid($type); // Get the ID of the parent type adoptable
$altstatus = getaltstatus($parentid, $id, $nextlevel); // Check if we are using alternate images or not...
if($altstatus == "yes"){
// We are enabling alternate images for this adoptable...
$query = "UPDATE ".$prefix."owned_adoptables SET usealternates='yes' WHERE aid='".$id."'";
runquery($query);
}
And replace it with this:
$parentid = converttypetoparentid($type); // Get the ID of the parent type adoptable
$altstatus = getaltstatus($parentid, $id, $nextlevel); // Check if we are using alternate images or not...
if($altstatus != "none"){
// We are enabling alternate images for this adoptable...
$query = "UPDATE ".$prefix."owned_adoptables SET usealternates='yes',altimage='".$altstatus."' WHERE aid='".$id."'";
mysql_query($query);
}
Lastly, open up doadopt.php and any other files that insert rows into the owned_adoptables table.
Find something like this: '$code', '','$alts',
and replace it with this: '$code', '','','$alts',
Step 2: Hard stuff is over, believe it or not. :P Download the 2 files attached to this post. Upload both in your main folder with admin.php and all that good stuff. Run the install.php page ONCE and then DELETE IT.
You're Done! You can check out the additional admin area in site settings -> plugins -> MAI Admin
Okay so I have not been able to beta test this much so please try it out and let me know what errors you get so I can fix 'em quick. I know all the basic functions work though. Also, please read the faq below BEFORE asking questions.
FAQ
Q: I don't understand what all the fields are for?
A: Read the handy dandy instruction thingy that's linked in the MAI Admin.
Q: Is there a way to transfer current alternates?
A: Not as of yet, sorry.
Q: Is this compatible with older versions of MA?
A: Uhm. Probably not. Stick to 1.2.* or higher.
Q: Okay so what do I put for the Alternates stuff when adding an adopt?
A: Enabled alternates as usual and enter random digits to satisfy the checks. The random digits will have no effect on the new alternate system, whether or not alternates are enabled WILL.
Q: Why isn't there an easier way to enable/disable alternates for certain adopts.
A: Good question, I'll think about it for a future update.
That's all folks! Enjoy!
By Kaeliah
Modification TOS (http://www.mysidiaadoptables.com/forum/blog.php?cp=3)
I felt very bad for going on hiatus so to make up for it I decided to release this publicly instead of for premium only. Please note that this is a complex script and you should know at least a little PHP before attempting installation. That said, I tried to make it as simply as possible.
Step 1: Open the functions.php, levelup.php & doadopt.php files.
NOTE: Any page that inserts a row into the owned_adoptables table will need an extra '', added after imageurl.
Find the two functions 'getaltstatus' and 'getcurrentimage' in functions.php. They should be one after the other. Replace those two functions with the code below:
function getaltstatus($parentid, $childid, $childlevel) {
// This function determines if we will use alternate images...
$alt = "Cannot find adopt with given parent id.";
// First we need to see if this adoptable type has alternate images enabled...
$query = "SELECT * FROM ".$prefix."adoptables WHERE id='".$parentid."'";
$result = mysql_query($query);
$num = mysql_num_rows($result);
$alternates=@mysql_result($result, $i,"alternates");
// Let's see if the level we are on is the level that requires alternates
if($alternates == "enabled") {
// Alternates for adoptable type are enabled, next check to see if this adopt is already using an alternate.
$query = "SELECT * FROM ".$prefix."owned_adoptables WHERE aid='".$childid."'";
$result = mysql_query($query);
$num = mysql_num_rows($result);
$usealt=@mysql_result($result, $i,"usealternates");
$currentimage=@mysql_result($result, $i,"altimage");
if($usealt == "no"){
// Alternates are not currently being used, next check for alternate image w/ specified entry level.
$query = "SELECT * FROM ".$prefix."alternates WHERE entry='".$childlevel."' AND adoptid='".$parentid."'";
$result = runquery($query);
while($row = mysql_fetch_array($result)){
$method=$row['method'];
$data=$row['data'];
$newurl=$row['alturl'];
// check what kind of method we're using to choose an alternate.
if($method == "random"){
$chance = rand(1, $data);
if($chance == 1){
$alt = $newurl;
}
else{
$alt = "The random finder did not pick 1.";
}
}
else{
$alt = "Not finding method random...";
}
$i++;
}
}
else if($usealt == "yes"){
// This adopt is already using an alternate, so let's get a path.
$query = "SELECT * FROM ".$prefix."alternates WHERE alturl='".$currentimage."' AND adoptid='".$parentid."'";
$result = mysql_query($query);
$path=@mysql_result($result, $i,"path");
$subpath=@mysql_result($result, $i,"subpath");
if($subpath != 0){// check for a subpath.
$query = "SELECT COUNT(*) FROM ".$prefix."alternates WHERE subpath='".$subpath."' AND path='".$path."' AND replacedlevel='".$childlevel."' AND adoptid='".$parentid."'";
$result = mysql_query($query);
$num = mysql_fetch_array($result);
}
else if($path != 0){ // no subpath, so check for a path.
$query = "SELECT COUNT(*) FROM ".$prefix."alternates WHERE path='".$path."' AND replacedlevel='".$childlevel."' AND adoptid='".$parentid."'";
$result = mysql_query($query);
$num = mysql_fetch_array($result);
}
if($num[0] > 1){
// more than 1 path was found, so let's run through subpaths.
$i = 0;
while($i < $num[0]){
$method=@mysql_result($result, $i,"method");
$data=@mysql_result($result, $i,"data");
$newurl=@mysql_result($result, $i,"alturl");
// check what kind of method we're using to choose a subpath.
if($method == "random"){
$chance = rand(1, $data);
if($chance == 1){
$alt = $newurl;
}
else{
$alt = "none";
}
}
else{
$alt = "none";
}
$i++;
}
// In order for paths to work, we HAVE to have a subpath picked. Since a loop until one is picked would be tedius, we'll just randomly pick one.
if($alt == "none"){
$query = "SELECT * FROM ".$prefix."alternates WHERE path='".$path."' AND replacedlevel='".$childlevel."' ORDER BY RAND() LIMIT 1 ";
$result = mysql_query($query);
$newurl=@mysql_result($result, $i,"alturl");
$alt = $alturl;
}
} // end subpaths
else{
// No path was found, so now we just need to pick an alternate.
$query = "SELECT * FROM ".$prefix."alternates WHERE adoptid='".$parentid."' AND replacedlevel = '".$childlevel."'";
$result = mysql_query($query);
$num = mysql_fetch_array($result);
$method=@mysql_result($result, $i,"method");
$data=@mysql_result($result, $i,"data");
$newurl=@mysql_result($result, $i,"alturl");
if($method == "random"){
$chance = rand(1, $data);
if($chance == 1){
$alt = $newurl;
}
else{
$alt = "none";
}
}
else{
$alt = "none";
}
} // End No Subpaths
} // end alternates already enabled.
} // end alternates enabled
else{
$alt = "alternates are reading disabled.";
}
return $alt;
}
function getcurrentimage($aid) {
// This function determines which image we should use for a given adoptable...
$image = "";
// First we select the adoptable from the database and get some basic information...
$query = "SELECT * FROM ".$prefix."owned_adoptables WHERE aid='".$aid."'";
$result = mysql_query($query);
$currentimage=@mysql_result($result, 0,"altimage");
$imageurl=@mysql_result($result, 0,"imageurl");
if($currentimage == ""){
// if the currentimage is blank, we're not using an alternate so grab the primary image.
$image = $imageurl;
}
else{
$image = $currentimage;
}
if($image == ""){
// For some reason, both primary and current images are blank, so let's do one more check.
$currentlevel=@mysql_result($result, 0,"currentlevel");
$type=@mysql_result($result, 0,"type");
if($currentlevel != 0){
$query = "SELECT * FROM ".$prefix."levels WHERE adoptiename = '".$type."' AND thisislevel = '".$currentlevel."'";
$result = mysql_query($query);
$primaryimage=@mysql_result($result, 0,"primaryimage");
mysql_query("UPDATE ".$prefix."owned_adoptables WHERE aid = '".$aid."' SET imageurl = '".$primaryimage."'");
$image = $primaryimage;
}
else{
$query = "SELECT * FROM ".$prefix."adoptables WHERE type = '".$type."'";
$result = mysql_query($query);
$eggimage=@mysql_result($result, 0,"eggimage");
mysql_query("UPDATE ".$prefix."owned_adoptables WHERE aid = '".$aid."' SET imageurl = '".$eggimage."'");
$image = $eggimage;
}
if($image == ""){
// both are definitely blank... show error.
$image = "http://www.".$GLOBALS['domain']."".$GLOBALS['scriptpath']."/templates/icons/delete.gif";
}
}
return $image;
}
Find in levelup.php at about line 140:
$parentid = converttypetoparentid($type); // Get the ID of the parent type adoptable
$altstatus = getaltstatus($parentid, $id, $nextlevel); // Check if we are using alternate images or not...
if($altstatus == "yes"){
// We are enabling alternate images for this adoptable...
$query = "UPDATE ".$prefix."owned_adoptables SET usealternates='yes' WHERE aid='".$id."'";
runquery($query);
}
And replace it with this:
$parentid = converttypetoparentid($type); // Get the ID of the parent type adoptable
$altstatus = getaltstatus($parentid, $id, $nextlevel); // Check if we are using alternate images or not...
if($altstatus != "none"){
// We are enabling alternate images for this adoptable...
$query = "UPDATE ".$prefix."owned_adoptables SET usealternates='yes',altimage='".$altstatus."' WHERE aid='".$id."'";
mysql_query($query);
}
Lastly, open up doadopt.php and any other files that insert rows into the owned_adoptables table.
Find something like this: '$code', '','$alts',
and replace it with this: '$code', '','','$alts',
Step 2: Hard stuff is over, believe it or not. :P Download the 2 files attached to this post. Upload both in your main folder with admin.php and all that good stuff. Run the install.php page ONCE and then DELETE IT.
You're Done! You can check out the additional admin area in site settings -> plugins -> MAI Admin
Okay so I have not been able to beta test this much so please try it out and let me know what errors you get so I can fix 'em quick. I know all the basic functions work though. Also, please read the faq below BEFORE asking questions.
FAQ
Q: I don't understand what all the fields are for?
A: Read the handy dandy instruction thingy that's linked in the MAI Admin.
Q: Is there a way to transfer current alternates?
A: Not as of yet, sorry.
Q: Is this compatible with older versions of MA?
A: Uhm. Probably not. Stick to 1.2.* or higher.
Q: Okay so what do I put for the Alternates stuff when adding an adopt?
A: Enabled alternates as usual and enter random digits to satisfy the checks. The random digits will have no effect on the new alternate system, whether or not alternates are enabled WILL.
Q: Why isn't there an easier way to enable/disable alternates for certain adopts.
A: Good question, I'll think about it for a future update.
That's all folks! Enjoy!