Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Adoptables Database Layout:
- -Languages
- --ID
- --Abbreviation
- --Name
- -Species
- --ID
- --Base Value
- -EvolutionNodes
- --ID
- --Species.ID #<- old species
- --Species.ID #<- new species
- --Level
- --Items.ID
- --Gender
- -Evolutions #Keep track of evolutions?
- --Adoptables.ID
- --EvolutionNodes.ID
- --Time/Date of evolution.
- -Items
- --ID
- --Base Value
- --Item_Types.ID# Potion, click packages, etc.
- --Strength #Potion = 200, Hyperpotion=1000 or whatever.
- -Species Names
- --Species.ID
- --Languages.ID
- --Name
- -Users
- --ID
- #Do some fancy-schmancy stuff that links to the vBulletin database.
- -Adoptables
- --ID
- --Users.ID
- --Species.ID
- --Date Adopted
- --Name
- --EXP Points #number of clicks.
- --Level
- --Gender
- ** BTW, all of this belongs in a folder /api
- ** or have a sub-domain. "api.adopt.thepokemonboard.net/<REST_PATH>"
- */
- ?>
- ========================================================
- -------------Rest.php-----------------------------------
- ========================================================
- <?php
- function RestAPI($mapped_functions){
- if(array_key_exists($mapped_functions,$_SERVER['REQUEST_METHOD']))
- $mapped_functions[$_SERVER['REQUEST_METHOD']]();
- throw new Exception("Unsupported REQUEST.Method encountered.");
- }
- ?>
- ========================================================
- ========================================================
- --------------DB_Connect.php----------------------------
- ========================================================
- <?php
- function Connect($db_name){
- $con = mysql_connect("localhost","user","password");
- if(!$con)
- throw new Exception('Could not connect: ' . mysql_error())
- mysql_select_db($db_name,$con);
- return $con;
- }
- ?>
- ========================================================
- ========================================================
- --------------user.php----------------------------------
- ========================================================
- <?php
- include("rest.php");
- include("db_connect.php");
- function GetUser()
- {
- $con = Connect("vBulletin");
- //Obtain user information here.
- $user = array('id'=>5);
- if($user==null)
- throw new Exception("No user logged in.");
- mysql_close($con);
- return json_encode($user);
- }
- function Users()
- {
- try {
- echo RestAPI(array("GET"=>display_adoptable,"POST"=>new_adoptable));
- } catch(Exception $e) {
- die($e->getMessage());
- }
- }
- ?>
- ========================================================
- ========================================================
- --------------Adoptables.php----------------------------
- ========================================================
- <?php
- include("rest.php");
- include("db_connect.php");
- include("user.php");.
- $adopt_db_name="Adoptables";
- function NewAdoptable(){
- $user=json_decode(GetUser())['id'];
- $con = Connect($adopt_db_name);
- $adopt_name=isset($_POST['name'])?$_POST['name']:null;
- $adopt_species=$_POST['species'];
- if($adopt_species=="")
- throw new Exception("A species is required.");
- }
- function GetAdoptable(){
- $con = Connect($adopt_db_name);
- $lang = isset($_GET['lang'])?$_GET['lang']:'0';
- $query =
- 'Select
- adopt.id as \'ID\',
- adopt.user_id as \'userID\',
- (select species_names.name from species_names where species_names.species_id==adopt.id AND species_names.language_id=='.$lang.') as \'species\'
- coalesce(
- adopt.name,
- (select species_names.name from species_names where species_names.species_id==adopt.id AND species_names.language_id=='.$lang.')
- ) as \'name\',
- adopt.gender as \'gender\',
- adopt.level as \'level\',
- adopt.exp*20 as \'clicks\',
- adopt.created as \'creation\'
- from adoptables as adopt
- ';
- if(isset($_GET['id'])){
- $query = $query . "\n where adopt.id==$_GET['id'] limit 0,1";
- }
- $num_results = 0;
- $query_result = mysql_query($query);
- $return = array();
- while($row = mysql_fetch_array($query_result))
- {
- $num_results+=1;
- array_push($return,array(
- 'id' => $row['ID'],
- 'user' => $row['userID'],
- 'species' => $row['species'],
- 'name' => $row['name'],
- 'gender' => $row['gender'],
- 'exp' => $row['clicks'],
- 'created' => $row['created']
- ));
- }
- if($num_results>0)
- return json_encode($return);
- else
- throw new Exception("Couldn't find any adoptables".((isset($_GET['id']))?('by the ID of '.$_GET['id']):"").".");
- }
- function Adoptable(){
- try {
- echo RestAPI(array("GET"=>"GetAdoptable","POST"=>"NewAdoptable"));
- } catch(Exception $e) {
- die($e->getMessage());
- }
- }
- ?>
- ========================================================
Advertisement
Add Comment
Please, Sign In to add comment