Stack2RSS 1.0
A simple web application that creates an RSS feed given an API route.
|
00001 <?php 00002 00003 /// \file item_converter.php Contains the conversion class for item objects. 00004 00005 // This class derives from Converter 00006 require_once 'converter.php'; 00007 00008 /// Provides conversion for item objects 00009 /** 00010 * <i>Note: unfortunately, the API uses 'item' for two different objects returned: <kbd>/sites</kbd> and <kbd>/users/{ID}/associated</kbd>.</i> 00011 * 00012 * Because of this, this class is slightly more complicated than it needs to be. 00013 */ 00014 class ItemConverter extends Converter 00015 { 00016 /// Determines if this item is a site or associated user 00017 /** 00018 * \param[in] $json_item the JSON data for the item 00019 * \return TRUE or FALSE depending on whether this item represents a site or not 00020 */ 00021 private function IsSite($json_item) 00022 { 00023 return isset($json_item['main_site']); 00024 } 00025 00026 protected function GetTitle($json_item) 00027 { 00028 if($this->IsSite($json_item)) 00029 return $json_item['main_site']['name']; 00030 else 00031 return $json_item['site_name']; 00032 } 00033 00034 protected function GetDescription($json_item) 00035 { 00036 if($this->IsSite($json_item)) 00037 return $json_item['main_site']['description']; 00038 else 00039 return '<i>No data.</i>'; 00040 } 00041 00042 protected function GetLink($json_item) 00043 { 00044 if($this->IsSite($json_item)) 00045 return "http://{$json_item['main_site']['site_url']}/"; 00046 else 00047 return "http://stackexchange.com/users/{$json_item['association_id']}?tab=accounts"; 00048 } 00049 00050 protected function GetDate($json_item) 00051 { 00052 if($this->IsSite($json_item)) 00053 return date(DATE_RSS, $json_item['creation_date']); 00054 else 00055 return date(DATE_RSS, $json_item['user_creation_date']); 00056 } 00057 } 00058 00059 ?>