Exemplo n.º 1
0
 /**
  * Validate Tag Search Options
  *
  * @param array $options
  */
 protected function _validateTagSearch($options)
 {
     $valid_options = array('api_key', 'method', 'user_id', 'per_page', 'page', 'extras', 'min_upload_date', 'min_taken_date', 'max_upload_date', 'max_taken_date', 'tag_mode', 'tags');
     if (!is_array($options)) {
         return;
     }
     $this->_compareOptions($options, $valid_options);
     $filter = new Zend_InputFilter($options, false);
     if (!$filter->isBetween('per_page', 1, 500, true)) {
         throw new Zend_Service_Exception($options['per_page'] . ' is not valid for the "per_page" option');
     }
     if (!$filter->isInt('page')) {
         throw new Zend_Service_Exception($options['page'] . ' is not valid for the "page" option');
     }
     // validate extras, which are delivered in csv format
     if ($options['extras']) {
         $extras = explode(',', $options['extras']);
         $valid_extras = array('license', 'date_upload', 'date_taken', 'owner_name', 'icon_server');
         foreach ($extras as $extra) {
             /**
              * @todo The following does not do anything [yet], so it is commented out.
              */
             //in_array(trim($extra), $valid_extras);
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Validate Web Search Options
  *
  * @param array $options
  */
 protected function _validateWebSearch($options)
 {
     $valid_options = array('appid', 'query', 'results', 'start', 'language', 'type', 'format', 'adult_ok', 'similar_ok', 'country', 'site', 'subscription', 'license');
     if (!is_array($options)) {
         return;
     }
     $this->_compareOptions($options, $valid_options);
     $filter = new Zend_InputFilter($options, false);
     if (isset($options['results'])) {
         if (!$filter->isBetween('results', 1, 20, true)) {
             throw new Zend_Service_Exception($options['results'] . ' is not valid for the "results" option.');
         }
     }
     if (isset($options['start'])) {
         if (!$filter->isBetween('start', 1, 1000, true)) {
             throw new Zend_Service_Exception($options['start'] . ' is not valid for the "start" option.');
         }
     }
     $this->_validateLanguage($options['language']);
     $this->_validateInArray('query type', $options['type'], array('all', 'any', 'phrase'));
     $this->_validateInArray('format', $options['format'], array('any', 'html', 'msword', 'pdf', 'ppt', 'rss', 'txt', 'xls'));
     $this->_validateInArray('license', $options['license'], array('any', 'cc_any', 'cc_commercial', 'cc_modifiable'));
 }
Exemplo n.º 3
0
 /**
  * Validate options for an ItemLookup
  *
  * @param array $options Options array to be used for the query
  * @throws Zend_Service_Exception
  * @return void
  */
 protected function _validateItemLookup($options = array())
 {
     if (!is_array($options)) {
         throw new Zend_Service_Exception('Options must be specified as an array');
     }
     /**
      * @todo use input filter for this?
      */
     // Validate keys in the $options array
     $this->_compareOptions($options, array('ItemId', 'IdType', 'SearchIndex', 'MerchantId', 'Condition', 'DeliveryMethod', 'ISPUPostalCode', 'OfferPage', 'ReviewPage', 'VariationPage', 'ResponseGroup', 'Service', 'SubscriptionId', 'Operation'));
     // Validate SearchIndex (required)
     if (empty($options['SearchIndex'])) {
         throw new Zend_Service_Exception('Query requires a SearchIndex');
     } else {
         $this->_validateInArray('SearchIndex', $options['SearchIndex'], array_keys(self::$_searchSort));
     }
     // Validate ResponseGroup (required)
     if (empty($options['ResponseGroup'])) {
         throw new Zend_Service_Exception('Query requires a ResponseGroup');
     } else {
         $responseGroup = split(',', $options['ResponseGroup']);
         foreach ($responseGroup as $r) {
             if (!in_array($r, array('Request', 'Small', 'Medium', 'Large'))) {
                 throw new Zend_Service_Exception('This wrapper only supports Request, Small, Medium and Large ' . 'ResponseGroups');
             }
         }
     }
     // Validate Sort (optional)
     if (isset($options['Sort'])) {
         $this->_validateInArray('Sort', $options['Sort'], array_values(self::$_searchSort[$SearchIndex]));
     }
     // Validate City (optional)
     if (isset($options['City'])) {
         $this->_validateInArray('City', $options['City'], array('Boston', 'Chicago', 'New York', 'San Francisco', 'Seattle', 'Washington, D.C.'));
     }
     $filter = new Zend_InputFilter($options, false);
     if (isset($options['ItemPage'])) {
         if (!$filter->isBetween('ItemPage', 0, 2500, true)) {
             throw new Zend_Service_Exception($options['ItemPage'] . ' is not a valid value for the "ItemPage" option.');
         }
     }
 }
<?php

/**
 * Query Yahoo! Web, Image and News searches
 */
require_once 'Zend/Service/Yahoo.php';
if (isset($_POST) && strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
    $filter = new Zend_InputFilter($_POST);
    $keywords = $filter->getAlnum('search_term');
} else {
    $keywords = '';
}
?>
<!DOCTYPE html public "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <style type="text/css">
        html, body {
            margin: 0px;
            padding: 0px;
            font-family: Tahoma, Verdana, sans-serif;
            font-size: 10px;
        }

        h1 {
            margin-top: 0px;
            background-color: darkblue;
            color: white;
            font-size: 16px;
        }