function amazon($id)
 {
     if (is_null($this->isn)) {
         return false;
     }
     require_once ROOT_DIR . '/sys/Amazon.php';
     require_once 'XML/Unserializer.php';
     $params = array('ResponseGroup' => 'Images', 'ItemId' => $this->isn);
     $request = new AWS_Request($id, 'ItemLookup', $params);
     $result = $request->sendRequest();
     if (!PEAR_Singleton::isError($result)) {
         $unxml = new XML_Unserializer();
         $unxml->unserialize($result);
         $data = $unxml->getUnserializedData();
         if (PEAR_Singleton::isError($data)) {
             return false;
         }
         if (isset($data['Items']['Item']) && !$data['Items']['Item']['ASIN']) {
             $data['Items']['Item'] = $data['Items']['Item'][0];
         }
         if (isset($data['Items']['Item'])) {
             // Where in the XML can we find the URL we need?
             switch ($this->size) {
                 case 'small':
                     $imageIndex = 'SmallImage';
                     break;
                 case 'medium':
                     $imageIndex = 'MediumImage';
                     break;
                 case 'large':
                     $imageIndex = 'LargeImage';
                     break;
                 default:
                     $imageIndex = false;
                     break;
             }
             // Does a URL exist?
             if ($imageIndex && isset($data['Items']['Item'][$imageIndex]['URL'])) {
                 $imageUrl = $data['Items']['Item'][$imageIndex]['URL'];
                 return $this->processImageURL($imageUrl, false);
             }
         }
     }
     return false;
 }
示例#2
0
 /**
  * Get the name of an Amazon customer.
  *
  * @param string $id         Amazon access key
  * @param string $customerId Amazon customer to look up
  *
  * @return  string           Customer name, if available.
  * @access  private
  */
 private function _getAmazonCustomer($id, $customerId)
 {
     // Spare ourselves an API call if no ID is available:
     if (empty($customerId)) {
         return 'Anonymous';
     }
     // Send request:
     $params = array('ResponseGroup' => 'CustomerInfo', 'CustomerId' => $customerId);
     $request = new AWS_Request($id, 'CustomerContentLookup', $params);
     $response = $request->sendRequest();
     // Parse response:
     if (!PEAR::isError($response)) {
         $data = @simplexml_load_string($response);
         if ($data) {
             if (isset($data->Customers->Customer->Name)) {
                 return (string) $data->Customers->Customer->Name;
             } elseif (isset($data->Customers->Customer->Nickname)) {
                 return (string) $data->Customers->Customer->Nickname;
             } else {
                 return 'Anonymous';
             }
         } else {
             return new PEAR_Error('Could not parse Amazon response.');
         }
     } else {
         return $response;
     }
 }
示例#3
0
/**
 * Retrieve an Amazon cover.
 *
 * @param string $id Amazon Web Services client ID.
 *
 * @return bool      True if image displayed, false otherwise.
 */
function amazon($id)
{
    include_once 'sys/Amazon.php';
    $params = array('ResponseGroup' => 'Images', 'ItemId' => $_GET['isn']);
    $request = new AWS_Request($id, 'ItemLookup', $params);
    $result = $request->sendRequest();
    if (!PEAR::isError($result)) {
        $data = @simplexml_load_string($result);
        if (!$data) {
            return false;
        }
        if (isset($data->Items->Item[0])) {
            // Where in the XML can we find the URL we need?
            switch ($_GET['size']) {
                case 'small':
                    $imageIndex = 'SmallImage';
                    break;
                case 'medium':
                    $imageIndex = 'MediumImage';
                    break;
                case 'large':
                    $imageIndex = 'LargeImage';
                    break;
                default:
                    $imageIndex = false;
                    break;
            }
            // Does a URL exist?
            if ($imageIndex && isset($data->Items->Item[0]->{$imageIndex}->URL)) {
                $imageUrl = (string) $data->Items->Item[0]->{$imageIndex}->URL;
                return processImageURL($imageUrl, false);
            }
        }
    }
    return false;
}
示例#4
0
 private function getAmazonCustomer($id, $customerId)
 {
     $params = array('ResponseGroup' => 'CustomerInfo', 'CustomerId' => $customerId);
     $request = new AWS_Request($id, 'CustomerContentLookup', $params);
     $response = $request->sendRequest();
     $result = null;
     if (!PEAR_Singleton::isError($response)) {
         $unxml = new XML_Unserializer();
         $result = $unxml->unserialize($response);
         if (!PEAR_Singleton::isError($result)) {
             $data = $unxml->getUnserializedData();
             if (isset($data['Customers']['Customer']['Name'])) {
                 return $data['Customers']['Customer']['Name'];
             } elseif (isset($data['Customers']['Customer']['Nickname'])) {
                 return $data['Customers']['Customer']['Nickname'];
             } else {
                 return 'Anonymous';
             }
         } else {
             return $result;
         }
     } else {
         return $result;
     }
 }