Permalink
Browse files

started by randomecho.com

  • Loading branch information...
0 parents commit a57b367e1e56d40094200198640265cf30e10fe5 @randomecho committed Jan 14, 2012
Showing with 340 additions and 0 deletions.
  1. +25 −0 LICENSE
  2. +37 −0 README.md
  3. +96 −0 classes/controller/petfinder.php
  4. +20 −0 config/petfinder.php
  5. +46 −0 messages/petfinder.php
  6. +43 −0 views/petfinder_multi.php
  7. +9 −0 views/petfinder_none.php
  8. +64 −0 views/petfinder_single.php
25 LICENSE
@@ -0,0 +1,25 @@
+Copyright (c) 2012 Soon Van - randomecho.com
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of the original author nor the names of contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,37 @@
+# Petfinder via Kohana
+
+Petfinder is an online, searchable database of animals who need homes.
+This module allows an animal shelter to display their pets listed on
+the Petfinder database through their own website (built on Kohana 3.2).
+
+Initially developed for use at http://kentuckyanimalrescue.org/
+
+## URL path
+
+The following is the default path used to list the current pets posted by the shelter:
+
+ http://example.com/petfinder
+
+This can be configured to whatever else you would like as the bootstrap file will pick up
+the URL path from the config file.
+
+Individual pet listings, with extra information and details, will be found at the default
+sample URL:
+
+ http://example.com/petfinder/details/21249157-petname
+
+
+### bootstrap.php
+
+ Route::set('petfinder', Kohana::$config->load('petfinder.url_route').'(/<action>(/<id>))')
+ ->defaults(array(
+ 'controller' => 'petfinder',
+ 'action' => 'index',
+ ));
+
+
+## API key
+
+For a developer API key, go to http://www.petfinder.com/developers/api-key
+
+
@@ -0,0 +1,96 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+/**
+ * Petfinder listing and display
+ *
+ * @package Petfinder via Kohana
+ * @category Core
+ * @author Soon Van - randomecho.com
+ * @copyright 2012 Soon Van
+ * @license http://www.opensource.org/licenses/BSD-3-Clause
+ */
+
+class Controller_Petfinder extends Controller_TemplateIndex {
+
+ /**
+ * Request the list of adoptable pets from Petfinder via their RESTful API.
+ * If a list is available, render the collection of pets found.
+ * Otherwise show the view saying there are none available.
+ *
+ */
+ public function action_index()
+ {
+ $adoptable = simplexml_load_file(Kohana::$config->load('petfinder.api_url').
+ Kohana::$config->load('petfinder.get_shelterpets').
+ '?key='.Kohana::$config->load('petfinder.api_key').
+ '&id='.Kohana::$config->load('petfinder.shelter_id'));
+
+ if($adoptable->header->status->code == 100 && count((array)$adoptable->pets) > 0)
+ {
+ $shelter_pets = (array)$adoptable->pets;
+
+ $shelter_pets['legend'] = Kohana::$config->load('petfinder.legend');
+ $shelter_pets['url_details'] = Kohana::$config->load('petfinder.url_route').'/details/';
+
+ $this->template->content = View::factory('petfinder_multi', $shelter_pets);
+ }
+ else
+ {
+ $info['url_main'] = Kohana::$config->load('petfinder.url_route');
+ $info['error_message'] = Kohana::message('petfinder', 'error.none');
+ $info['error_heading'] = Kohana::message('petfinder', 'error.none_heading');
+
+ $this->template->content = View::factory('petfinder_none', $info);
+ }
+
+ }
+
+ /**
+ * Display the details of an individual pet as requested from the list
+ * Reject showing if it doesn't contain the pet name in URL and bounce back to main list
+ * If the URL is correct, but pet ID is invalid, display the error message view
+ *
+ */
+ public function action_details()
+ {
+ $id_pet = $this->request->param('id');
+
+ // reject as invalid if not parsed by the site with nice url featuring pet name
+ if(!stristr($id_pet, '-'))
+ Request::current()->redirect($this->template->baseurl.Kohana::$config->load('petfinder.url_route'));
+
+ $url_pet = explode('-', $id_pet);
+ $id_pet = (int)$url_pet[0];
+
+ $pet_details = simplexml_load_file(Kohana::$config->load('petfinder.api_url').
+ Kohana::$config->load('petfinder.get_pet').
+ '?key='.Kohana::$config->load('petfinder.api_key').
+ '&id='.$id_pet);
+
+ if($pet_details->header->status->code == 100)
+ {
+ $shelter_pets['pet'] = $pet_details->pet;
+ $shelter_pets['status_heading'] = Kohana::message('petfinder', 'status_heading.'.$pet_details->pet->status);
+ $shelter_pets['legend_sex'] = Kohana::message('petfinder', 'legend_sex.'.$pet_details->pet->sex);
+
+ foreach($pet_details->pet->options->option as $option)
+ {
+ $shelter_pets['options'][] = Kohana::message('petfinder', 'legend_options.'.$option);
+ }
+
+ $shelter_pets['url_main'] = Kohana::$config->load('petfinder.url_route');
+
+ $this->template->content = View::factory('petfinder_single', $shelter_pets);
+ }
+ else
+ {
+ $info['url_main'] = Kohana::$config->load('petfinder.url_route');
+ $info['error_message'] = Kohana::message('petfinder', 'error.invalid');
+ $info['error_heading'] = Kohana::message('petfinder', 'error.invalid_heading');
+
+ $this->template->content = View::factory('petfinder_none', $info);
+ }
+
+ }
+
+}
@@ -0,0 +1,20 @@
+<?php defined('SYSPATH') OR die('No direct access allowed.');
+
+return array(
+ 'api_key' => 'YOUR_API_KEY',
+ 'api_secret' => 'YOUR_API_SECRET',
+ 'shelter_id' => 'YOUR_SHELTER_ID',
+
+ 'api_url' => 'http://api.petfinder.com/',
+ 'url_route' => 'petfinder',
+
+ 'get_token' => 'auth.getToken',
+ 'get_breeds' => 'breed.list',
+ 'get_pet' => 'pet.get',
+ 'get_random' => 'pet.getRandom',
+ 'find_pet' => 'pet.find',
+ 'find_shelter' => 'shelter.find',
+ 'get_shelter' => 'shelter.get',
+ 'get_shelterpets' => 'shelter.getPets',
+ 'get_shelterbreeds' => 'shelter.listByBreed',
+);
@@ -0,0 +1,46 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+return array(
+ 'status' => array(
+ 'A' => 'Adoptable',
+ 'H' => 'On hold',
+ 'P' => 'Pending adoption',
+ 'X' => 'Adopted',
+ ),
+
+ 'status_heading' => array(
+ 'A' => ', one of our adoptable pets',
+ 'H' => 'is currently on hold',
+ 'P' => 'is pending adoption',
+ 'X' => ', one of our adopted pets',
+ ),
+
+ 'legend_sex' => array(
+ 'M' => 'Male',
+ 'F' => 'Female',
+ ),
+
+ 'legend_size' => array(
+ 'S' => 'Small',
+ 'M' => 'Medium',
+ 'L' => 'Large',
+ 'XL' => 'Extra large',
+ ),
+
+ 'legend_options' => array(
+ 'altered' => 'Spayed/Neutered',
+ 'hasShots' => 'current on vaccinations',
+ 'housebroken' => 'house broken',
+ 'noCats' => 'prefers home with no cats',
+ 'noDogs' => 'prefers home with no dogs',
+ 'noKids' => 'prefers home with no children',
+ 'specialNeeds' => 'Requires special care',
+ ),
+
+ 'error' => array(
+ 'none' => 'Our shelter currently has no adoptable pets. Please check back soon.',
+ 'none_heading' => 'No pets at this time',
+ 'invalid' => 'Invalid pet ID.',
+ 'invalid_heading' => 'No pet found.',
+ ),
+);
@@ -0,0 +1,43 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+$output = '';
+
+$output .= '<h1>Our list of adoptable pets</h1>';
+
+$count_pets = count($pet);
+
+for($i = 0; $i < $count_pets; $i++)
+{
+ $current_pet = $pet[$i];
+
+ $output .= '<div class="petinfo">';
+ $output .= HTML::anchor($url_details.$current_pet->id.'-'.URL::title($current_pet->name), '<h3>'.$current_pet->name.'</h3>');
+
+ $output .= '<div class="petfinderThumb">';
+ $thumbnail = $current_pet->media->photos->photo[1];
+ $output .= HTML::anchor($url_details.$current_pet->id.'-'.URL::title($current_pet->name), HTML::image($thumbnail));
+ $output .= '</div>';
+
+ $output .= '<div class="petfinderStats petfinderSnippet">';
+ $output .= '<dl class="petfinderBio">';
+ $output .= '<dt class="petfinderBioLabel">Age</dt><dd class="petfinderBioData">'.$current_pet->age.'</dd>';
+ $output .= '<dt class="petfinderBioLabel">Sex</dt><dd class="petfinderBioData">x'.$current_pet->sex.'</dd>';
+
+ $output .= '<dt class="petfinderBioLabel">Breed</dt><dd class="petfinderBioData">';
+
+ if($current_pet->mix == 'yes')
+ $output .= 'Mix of ';
+
+ foreach($current_pet->breeds->breed as $pet_breed)
+ {
+ $output .= $pet_breed.', ';
+ }
+
+ $output .= '</dd>';
+ $output .= '</dl>';
+
+ $output .= '</div>';
+ $output .= '</div>';
+}
+
+echo $output;
@@ -0,0 +1,9 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+$output = '';
+
+$output .= '<h1>'.$error_heading.'</h1>';
+$output .= '<p>'.$error_message.'</p>';
+
+echo $output;
+
@@ -0,0 +1,64 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+$output = '';
+
+$current_pet = $pet;
+
+$output .= '<div class="petinfo">';
+$output .= '<h1>'.$current_pet->name.$status_heading.'</h1>';
+
+$thumbnail = $current_pet->media->photos->photo[0];
+$output .= HTML::image($thumbnail, array('title' => $current_pet->name));
+
+$output .= '<div class="petfinderStats">';
+
+$output .= '<div class="petfinderInfo">';
+$output .= $current_pet->description;
+$output .= '</div>';
+
+$output .= '<dl class="petfinderBio">';
+$output .= '<dt class="petfinderBioLabel">Petfinder ID</dt><dd class="petfinderBioData">'.$current_pet->id.'</dd>';
+$output .= '<dt class="petfinderBioLabel">Age</dt><dd class="petfinderBioData">'.$current_pet->age.'</dd>';
+
+$output .= '<dt class="petfinderBioLabel">Sex</dt><dd class="petfinderBioData">'.$legend_sex.'</dd>';
+
+$output .= '<dt class="petfinderBioLabel">Breed</dt><dd class="petfinderBioData">';
+
+if($current_pet->mix == 'yes')
+ $output .= 'Mix of ';
+
+foreach($current_pet->breeds->breed as $pet_breed)
+{
+ $output .= $pet_breed.', ';
+}
+
+$output .= '</dd>';
+
+if(isset($options))
+{
+ $output .= '<dt class="petfinderBioLabel">Details</dt><dd class="petfinderBioData">';
+ foreach($options as $pet_data)
+ {
+ $output .= $pet_data.', ';
+ }
+ $output .= '</dd>';
+}
+
+if($current_pet->status == 'A')
+{
+ $output .= '<dt class="petfinderBioLabel">Contact</dt>';
+
+ $name_contact = ($current_pet->contact->name != '') ? $current_pet->contact->name : 'Contact us';
+
+ if($current_pet->contact->email != '')
+ $output .= '<dd class="petfinderBioData">'.HTML::mailto($current_pet->contact->email.'?subject=Petfinder: '.$current_pet->name, $name_contact).'</dd>';
+ else
+ $output .= '<dd class="petfinderBioData">'.HTML::anchor('http://www.petfinder.com/petdetail/'.$current_pet->id, 'See contact details on Petfinder').'</dd>';
+}
+
+$output .= '</dl>';
+$output .= '</div>';
+$output .= '</div>';
+$output .= '<p>'.HTML::anchor($url_main, 'Back to main list of pets').'</p>';
+
+echo $output;

0 comments on commit a57b367

Please sign in to comment.