Mysidia Adoptables Support Forum

Mysidia Adoptables Support Forum (http://www.mysidiaadoptables.com/forum/index.php)
-   Questions and Supports (http://www.mysidiaadoptables.com/forum/forumdisplay.php?f=18)
-   -   Promo Help Again >.< (Different kinda question) (http://www.mysidiaadoptables.com/forum/showthread.php?t=4692)

parayna 10-11-2014 04:31 PM

Promo Help Again >.< (Different kinda question)
 
Does anyone know how to make it so that when you click on an image of something (just a normal png image) it 'activates' a promo code and gives it to you? (Instead of the promocode link leading you to the promo page where they would have to enter it in manually...)

I want the Adopt page to have talking stuff on it (which is done), a banner saying, 'Adopt a....' (which is done) and then on that page an image of an adoptable and when you click on it it adds it to your account... does anyone know how to do this? Thank you!

~parayna

P.S (Sorry if I was supposed to use my other thread, I wasn't sure... feel free to tell me so I know not to do it again! :pleased: )

P.P.S Also, I am feeling guilty about mooching off of the community so much... so soon (when my site is up and running) I will be releasing some free linearts for you guys to use! They won't be great... but I want to contribute in some way :meow: (the items might be the same as on my site, but the species' won't be. I have unique kind of species on my site so I will be drawing normal animals for the Mysidia community to have. But if I like them enough then I will also use them but just adapt them better for my site XD) I will also include a folder file that will have all of them in and will have GIMP editable files in! (I know that not every one has GIMP so it'll be optional and you could probably just drag the image from the post onto your desktop and colour it in in your chosen program, because it will be transparent)

Hall of Famer 10-13-2014 08:52 AM

It would be possible, and shouldnt be too difficult. Right now I am somewhat busy and cant take code requests beyond bug fixes, but I may have time to look at it for you later this week. If you can wait a bit longer, I will let you know.

parayna 10-14-2014 02:36 PM

OK! Thanks! It's not that urgent, I just wanted to see if it was possible ^_^ (And then implement it into my site if I could :P)

Hall of Famer 10-15-2014 03:23 PM

Of course it can be done. ^^ With proper coding skills, anything is possible with the script. ^^ Its just about how hard and time-consuming it will take. XD

parayna 10-19-2014 10:24 AM

I understand XD I don't have much coding skills but I will be picking things up as people help me so that's most likely how I will learn :P

parayna 11-09-2014 08:12 AM

Hi, have you made any progress with the code? Sorry if it seems like I'm bugging you (trying really hard to word this correctly ¬.¬) but I am thinking of opening to beta testers soon.. but it's fine if you're busy! I mean, you obviously have other stuff to do XD Thank you ^_^

~Parayna

Kyttias 11-09-2014 08:27 AM

I'm also interested in getting adoptables (and items) directly without the user having to go insert a promo code. Unfortunately, I've got a list of other things to do first. ^^; So I look forward to hearing more about this, too.

IntoRain 11-09-2014 09:54 AM

It depends on what you want to do really. Giving an adoptable is a simple db insert. The way to trigger that insert by clicking an image can be done in different ways:

- If the image takes you to a new page (/adopt/code for example), create those files for that page and if needed read the URL to know which adoptable the user is trying to get, check if it exists and if it does give it to the user
- Or with javascript, by making it activate an event on image click, requires the use of ajax though, which mysida isn't very fond of

parayna 11-09-2014 10:30 AM

Um, I'm not really sure to be honest ^_^'' I do know that I want it to be done in the easiest way possible (although I don't mind having to do a few code edits, obviously). The first way you stated seems like it could be better to do.. (but I don't know). Would you be able to reuse the same page whenever you change the monthly adopts? If so, I would like to use that way XD I just need it to be easy enough so that I don't need to create a different page whenever I want to add another adoptable onto the site. That might become tedious. But if it is a simple matter of just changing the codes on one page (say when they click an image, the corresponding adopt is added into the database) and then just change it every time more is released, I don't mind doing that!

But I may need a bit of help... (although I do have an idea on how it can be done.. but I am not confident enough to have a go myself XD)

~Parayna

IntoRain 11-09-2014 10:47 AM

Quote:

Originally Posted by parayna (Post 31475)
Um, I'm not really sure to be honest ^_^'' I do know that I want it to be done in the easiest way possible (although I don't mind having to do a few code edits, obviously). The first way you stated seems like it could be better to do.. (but I don't know). Would you be able to reuse the same page whenever you change the monthly adopts? If so, I would like to use that way XD I just need it to be easy enough so that I don't need to create a different page whenever I want to add another adoptable onto the site. That might become tedious. But if it is a simple matter of just changing the codes on one page (say when they click an image, the corresponding adopt is added into the database) and then just change it every time more is released, I don't mind doing that!

But I may need a bit of help... (although I do have an idea on how it can be done.. but I am not confident enough to have a go myself XD)

~Parayna

With the first one you can create 1 page, for example a "get" page (so 2 files, get.php and getview.php inside the view folder)
So the image would be linked like

<a href="yoursite.com/get/1">image</a>

You'd just need to change the links in this case.
The number after the link would match the IDs in your adoptables table. So when someone visited a get/ID page, you would need to:

1) Cut the link to get the last part (the ID)
2) Check if ID exists
3) Check if ID is actually an adoptable that can be adopted through this way (people WILL try to adopt other adoptables through this link).

You can do a manual check (for example if your monthly adoptables are 1, 2 and 5 you can check if the ID in the link is 1, 2 or 5).

Or you can try to pull the ID from the adoptables table to see if it exists. To check if it is one of your monthly adoptables, you can add an extra column to the table called "active", which would contain "true" if it is currently obtainable or false otherwise. Then with the ID you would check the contents of that column

If it passes the verifications, do a db insert. If not, throw an error


I can try to help you go through each step

NobodysHero 11-09-2014 11:42 AM

Holy cow. Yes, please, IntoRain. This is what I've been looking for since I woke up this morning. LOL! And even a little bit before that. If you could give a step by step for this process (Maybe with some pictures to make a lil fool proof?) That would be amazing! Thanks so much!


____________________________

NobodysHero
MystFell.com
Venture Into The Mist

parayna 11-09-2014 12:10 PM

Oh, would you? :D Thanks! And yeah, this seems like the way I would like to do it ^_^ I do know a little bit about the ID's and stuff from listening to what people have told me and what I have read, but not really enough to do everything myself (like the coding, etc.) XD

~Parayna

IntoRain 11-09-2014 02:44 PM

@NobodysHero
So you own MystFell? Beautiful art! I think I submitted the form put up on VPL, but I'm not sure haha

---------
Alright. This is a very manual version. I didn't do the "active" column version because I'm not sure what you will use this for and that way would be restricting it too much. This way, you can put a linked image in whatever page to make people obtain an adoptable - fun for treasure hunts?

Checking your database for the IDs

Since you will need to get the IDs you want for the adoptable, you will need to go check your database (I haven't checked the admincp to see if they are shown there because mine is currently under changes, sorry).

1) Use phpMyAdmin or similar from your control panel to access your database.
2) Once you are there, choose the database you use for your site (from the left side or by going to "Databases" at the top).
3) Then, choose the table something_adoptables (default is adopts_adoptables)
4) Look at the column id, these will be the numbers you will use. Check the names and images to see if it's the species you want

Image: http://i.imgur.com/ePST02Y.png

Putting the linked image up

Choose which page you want this to appear and link an image to /get/id/ID_NUMBER. This ID_NUMBER should be the same as one of your existing species in the database (see above).

To add it to pages like yoursite.com/adopt, go to inside the view folder and edit the file adoptview.php. Search the index() function and:

PHP Code:

public function index(){    
//you will find something like this in this function:
        
$mysidia Registry::get("mysidia");
        
$document $this->document;        
            
$document->setTitle("News");//I chose a page I have called News
//put this anywhere after the title. Edit the ID to your liking, change the image link, add more images, etc.
            
$document->add(new Comment("<a href='/get/id/1'><img src='http://i.imgur.com/Bjzw7CM.gif'></a>"));
....


You can add more $document->add(new Comment(""));
You can also write HTML code inside the quotation marks " ", so feel free to do things like this:

PHP Code:

$document->add(new Comment("
<b>ADOPT ME:</b>
<br><br>
<a href='/get/id/1'><img src='http://i.imgur.com/Bjzw7CM.gif'></a><br>
<a href='/get/id/7'><img src='another_image.png'></a>
"
)); 

Be careful to use ' ' instead of " " for the links and image links!

Do this: <img src='link.png'>
Not this: <img src="link.png">

The double quotation for the links might interfere with the previous marks and make your page throw errors! Always use the single quotation ones inside Comments("") to avoid mistakes!

Building the GET page!

Alright, clicking the image will take you to your index probably. We have to create the page that will take care of adopting.

Note:
If your link is yoursite.com/get/id/ID_NUMBER then your files need to be get.php and getview.php and both need an index() function and an id() function.
If your link is yoursite.com/capture/get/ID_NUMBER then your files need to be capture.php and captureview.php and both need an index() function and a get() function.
Etc... Just substitute the "get" word and the "id" word used for this explanation

For this example, my link is yoursite.com/get/id/ID_NUMBER
Create a file named get.php with these contents:

PHP Code:

<?php

use Resource\Native\Integer;
use 
Resource\Native\String;

class 
GetController extends AppController{

    private 
$id;
      
    public function 
__construct(){
    
        
parent::__construct("member");
        
$mysidia Registry::get("mysidia");
    
        if(
$mysidia->usergroup->getpermission("canadopt") != "yes"){
            throw new 
NoPermissionException("permission");
        }    
    }
    
    public function 
index(){
           
//don't let people access yoursite.com/get
        
throw new InvalidActionException("global_action");

    }
    
      
//yoursite.com/get/id
    
public function id(){
        
$mysidia Registry::get("mysidia");

        
//get ID_NUMBER
        
$pageURL 'http';
        if (
$_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
        
$pageURL .= "://";
        if (
$_SERVER["SERVER_PORT"] != "80") {
        
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
        } else {
        
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
        }
        
        
$parts Explode('/'$pageURL);
        
$id $parts[count($parts) - 1];
        
        if(!
$id) throw new InvalidIDException("global_id");
        
        
//---------- Edit here
        /* In this part, we check if the ID is actually part of the IDs available to adopt! 
        * If you want adoptable 1 and 7 to be available through get/id/number, you gotta add
        * 1 and 7 to the array
        */ 
        
        
$id_array = [1,7];//add your OK numbers here
        
$count count($id_array);
        
$found false;
        
        for(
$i 0$i $count$i++)
        {
            
//if ID is inside the array, then it's OK
            
if($id == $id_array[$i]){
                
$found true;
                break;
            }
        }
        
        
//the ID wasnt found inside the array, throw error
        
if(!$found)
            throw new 
NoPermissionException("This adoptable is not available through this method.");
        
        
//---------- 

        //after checking:
        
$this->access "member";
            
$this->handleAccess();    
            
        
//get adoptable information
        
$adopt = new Adoptable($id);                    
                        
        
$conditions $adopt->getConditions();
        if(!
$conditions->checkConditions()) throw new NoPermissionException("condition");
        
        
$name $adopt->getType();
            
$alts $adopt->getAltStatus();
           
$code $adopt->getCode();
        
$gender $adopt->getGender();
        
        
//insert into database
            
$mysidia->db->insert("owned_adoptables", array("aid" => NULL"type" => $name"name" => $name"owner" => $mysidia->user->username"currentlevel" => 0"totalclicks" => 0"code" => $code"imageurl" => NULL"usealternates" => $alts"tradestatus" => 'fortrade'"isfrozen" => 'no'"gender" => $gender"offsprings" => 0"lastbred" => 0));
        
        
//get its info
        
$aid $mysidia->db->select("owned_adoptables", array("aid"), "code='{$code}' and owner='{$mysidia->user->username}'")->fetchColumn();
        
$this->setField("aid", new Integer($aid));
            
$this->setField("name", new String($name));            
        
$this->setField("eggImage", new String($adopt->getEggImage()));
        
        
        
    }
    
}
?>

Search where it says "Edit here" in the file above, read the instructions and edit the array how you want it.


Create a file named getview.php inside the view folder with these contents:

PHP Code:

<?php

class GetView extends View{
    
    public function 
index(){
    
        
$mysidia Registry::get("mysidia");
        
$document $this->document;        
            
$document->setTitle("Adopt a pet");
            
       }
       
           public function 
id(){
        
$document $this->document;    
        
$document->setTitle("Adopt a pet");        
        
        
$aid $this->getField("aid")->getValue();
        
$name $this->getField("name")->getValue();
        
$eggImage $this->getField("eggImage")->getValue();
        
        
//display information
        
$image = new Image($eggImage);
        
$image->setLineBreak(TRUE);    
            
$document->setTitle("Catching {$id} ");
        
        
$document->add($image);
        
$document->addLangvar("Congratulations!  You just adopted {$name}.  You can now manage {$name} on the ");
        
$document->add(new Link("myadopts""Myadopts Page."));
        
$document->add(new Comment(""));
        
$document->add(new Link("myadopts/manage/{$aid}""Click Here to Manage {$name}"));
        
$document->add(new Comment(""));
        
$document->add(new Link("myadopts/bbcode/{$aid}""Click Here to get BBCodes/HTML Codes for {$name}"));
        
$document->add(new Comment(""));
        
$document->addLangvar("Be sure and");
        
$document->add(new Link("levelup/{$aid}""feed "));
        
$document->addLangvar("{$name} with clicks so that they grow!");
        
    }

    
}
?>

So now visiting yoursite.com/get/id/1 should add an adoptable to your account (if the number 1 is in your id_array)

I might have forgotten something. If you notice an error, please tell me

parayna 11-09-2014 03:12 PM

Thanks for this! I will have a go (one question, if I wanted to use a custom page for the image, could I do that? So not have them appearing on the adopt.php page... if that makes sense) Also, what adoption restriction would I set (if I had to use the adopt.php page)? Would I make it something like 'promo'? (Because if it is 'always' it appears on there without an image linking it)

Basically, on my site, there is a custom adopt page with a character talking, then a banner beneath it that says, 'Adopt a...' and when you click it, it takes you to a page where you can adopt that species. And I want it where you can click on an image on THAT page and it adds the adoptable to your account.. do I make sense? XD

Thanks!

~Parayna

(For an example, Chicken Smoothie does something very similar to what I would like, if you know it ^_^)

IntoRain 11-09-2014 03:24 PM

Quote:

Originally Posted by parayna (Post 31485)
Thanks for this! I will have a go (one question, if I wanted to use a custom page for the image, could I do that? So not have them appearing on the adopt.php page... if that makes sense)

Yeah, you can put the link /get/id/ID_NUMBER on any page you want


Quote:

Originally Posted by parayna (Post 31485)
Also, what adoption restriction would I set (if I had to use the adopt.php page)? Would I make it something like 'promo'? (Because if it is 'always' it appears on there without an image linking it)

I actually haven't thought about this and I can't test it right now x.x But maybe try with different restrictions? Promo sounds good. If it doesn't work, try removing the line with checkConditions() from get.php


Quote:

Originally Posted by parayna (Post 31485)
Basically, on my site, there is a custom adopt page with a character talking, then a banner beneath it that says, 'Adopt a...' and when you click it, it takes you to a page where you can adopt that species. And I want it where you can click on an image on THAT page and it adds the adoptable to your account.. do I make sense? XD

Thanks!

~Parayna

(For an example, Chicken Smoothie does something very similar to what I would like, if you know it ^_^)

I don't know Chicken Smoothie, sorry but yeah, if you add those pages, you just need the link to /get/id/ID_NUMBER on the adoptable page you want and it should work ^^

parayna 11-09-2014 03:55 PM

Thank you! It worked! :D Now people can adopt them from the page I want!

IntoRain 11-09-2014 04:05 PM

Quote:

Originally Posted by parayna (Post 31493)
Thank you! It worked! :D Now people can adopt them from the page I want!

I'm glad it worked! ^^ if you find any bugs or something, feel free to warn me!


All times are GMT -5. The time now is 01:10 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.