예제 #1
0
 /**
  * Do all the API work, fetch the data, parse it and return it for the renderer
  */
 function handle($match, $state, $pos, &$handler)
 {
     // check type and remove markup
     if (substr($match, 2, 8) == 'wishlist') {
         $match = substr($match, 11, -2);
         $type = 'wishlist';
     } elseif (substr($match, 2, 10) == 'amazonlist') {
         $match = substr($match, 13, -2);
         $type = 'amazonlist';
     } else {
         $match = substr($match, 9, -2);
         $type = 'product';
     }
     list($ctry, $asin) = explode(':', $match, 2);
     // default parameters...
     $params = array('type' => $type, 'imgw' => $this->getConf('imgw'), 'imgh' => $this->getConf('imgh'), 'maxlen' => $this->getConf('maxlen'), 'price' => $this->getConf('showprice'), 'purchased' => $this->getConf('showpurchased'), 'sort' => $this->getConf('sort'));
     // ...can be overridden
     list($asin, $more) = explode(' ', $asin, 2);
     if (preg_match('/(\\d+)x(\\d+)/i', $more, $match)) {
         $params['imgw'] = $match[1];
         $params['imgh'] = $match[2];
     }
     if (preg_match('/=(\\d+)/', $more, $match)) {
         $params['maxlen'] = $match[1];
     }
     if (preg_match('/noprice/i', $more, $match)) {
         $params['price'] = false;
     } elseif (preg_match('/(show)?price/i', $more, $match)) {
         $params['price'] = true;
     }
     if (preg_match('/nopurchased/i', $more, $match)) {
         $params['purchased'] = false;
     } elseif (preg_match('/(show)?purchased/i', $more, $match)) {
         $params['purchased'] = true;
     }
     if (preg_match('/sortprice/i', $more, $match)) {
         $params['sort'] = 'Price';
     } elseif (preg_match('/sortpriority/i', $more, $match)) {
         $params['sort'] = 'Priority';
     } elseif (preg_match('/sortadded/i', $more, $match)) {
         $params['sort'] = 'DateAdded';
     }
     // no country given?
     if (empty($asin)) {
         $asin = $ctry;
         $ctry = 'us';
     }
     // correct country given?
     if (!preg_match('/^(us|uk|jp|de|fr|ca)$/', $ctry)) {
         $ctry = 'us';
     }
     // get partner id
     $partner = $this->getConf('partner_' . $ctry);
     // correct domains
     if ($ctry == 'us') {
         $ctry = 'com';
     }
     if ($ctry == 'uk') {
         $ctry = 'co.uk';
     }
     // basic API parameters
     $opts = array();
     $opts['Service'] = 'AWSECommerceService';
     $opts['AWSAccessKeyId'] = AMAZON_APIKEY;
     $opts['AssociateTag'] = $partner;
     if ($type == 'product') {
         // parameters for querying a single product
         $opts['Operation'] = 'ItemLookup';
         $opts['ResponseGroup'] = 'Medium,OfferSummary';
         if (strlen($asin) < 13) {
             $opts['IdType'] = 'ASIN';
             $opts['ItemId'] = $asin;
         } else {
             $opts['SearchIndex'] = 'Books';
             $opts['IdType'] = 'ISBN';
             $opts['ItemId'] = $asin;
         }
     } else {
         // parameters to query a wishlist
         $opts['Operation'] = 'ListLookup';
         $opts['ResponseGroup'] = 'ListItems,Medium,OfferSummary';
         $opts['ListId'] = $asin;
         $opts['Sort'] = $params['sort'];
         $opts['IsIncludeUniversal'] = 'True';
         $opts['IsOmitPurchasedItems'] = $params['purchased'] ? 'False' : 'True';
         if ($type == 'wishlist') {
             $opts['ListType'] = 'WishList';
         } else {
             $opts['ListType'] = 'Listmania';
         }
     }
     // support paged results
     $result = array();
     $pages = 1;
     for ($page = 1; $page <= $pages; $page++) {
         $opts['ProductPage'] = $page;
         // fetch it
         $http = new DokuHTTPClient();
         $url = $this->_signedRequestURI($ctry, $opts, $this->getConf('publickey'), $this->getConf('privatekey'));
         $xml = $http->get($url);
         if (empty($xml)) {
             if ($http->error) {
                 return $http->error;
             }
             if ($http->status == 403) {
                 return 'Signature check failed, did you set your Access Keys in config?';
             }
             return 'unkown error';
         }
         // parse it
         require_once dirname(__FILE__) . '/XMLParser.php';
         $xmlp = new XMLParser($xml);
         $data = $xmlp->getTree();
         //dbg($data);
         // check for errors and return the item(s)
         if ($type == 'product') {
             // error?
             if ($data['ITEMLOOKUPRESPONSE'][0]['ITEMS'][0]['REQUEST'][0]['ERRORS']) {
                 return $data['ITEMLOOKUPRESPONSE'][0]['ITEMS'][0]['REQUEST'][0]['ERRORS'][0]['ERROR'][0]['MESSAGE'][0]['VALUE'];
             }
             // return item
             $result = array_merge($result, (array) $data['ITEMLOOKUPRESPONSE'][0]['ITEMS'][0]['ITEM']);
         } else {
             // error?
             if ($data['LISTLOOKUPRESPONSE'][0]['LISTS'][0]['REQUEST'][0]['ERRORS']) {
                 return $data['LISTLOOKUPRESPONSE'][0]['LISTS'][0]['REQUEST'][0]['ERRORS'][0]['ERROR'][0]['MESSAGE'][0]['VALUE'];
             }
             // multiple pages?
             $pages = (int) $data['LISTLOOKUPRESPONSE'][0]['LISTS'][0]['LIST'][0]['TOTALPAGES'][0]['VALUE'];
             // return items
             $result = array_merge($result, (array) $data['LISTLOOKUPRESPONSE'][0]['LISTS'][0]['LIST'][0]['LISTITEM']);
         }
     }
     return array($result, $params);
 }
예제 #2
0
 /**
  * Get Xml Array.
  * If xml file has been compiled (has .cmp), load the cmp file as array;
  * otherwise, compile the .xml to .cmp first new 2.2.3, .cmp files
  * will be created in app/cache/metadata_cmp directory. replace '/' with '_'
  * for example, /module/demo/BOEvent.xml has cmp file as _module_demo_BOEvent.xml
  *
  * @param string $xmlFile
  * @return array
  * */
 public static function &getXmlArray($xmlFile)
 {
     if (isset(self::$_xmlArrayList[$xmlFile])) {
         return self::$_xmlArrayList[$xmlFile];
     }
     $objXmlFileName = $xmlFile;
     //echo "getXmlArray($xmlFile)\n";
     //$objCmpFileName = dirname($objXmlFileName) . "/__cmp/" . basename($objXmlFileName, "xml") . ".cmp";
     //$_crc32 = sprintf('%08X', crc32(dirname($objXmlFileName)));
     $_crc32 = strtoupper(md5(dirname($objXmlFileName)));
     $objCmpFileName = CACHE_METADATA_PATH . '/' . $_crc32 . '_' . basename($objXmlFileName, "xml") . "cmp";
     $xmlArr = null;
     //$cacheKey = substr($objXmlFileName, strlen(META_PATH)+1);
     $cacheKey = $objXmlFileName;
     $findInCache = false;
     if (file_exists($objCmpFileName) && filemtime($objCmpFileName) > filemtime($objXmlFileName)) {
         // search in cache first
         if (!$xmlArr && extension_loaded('apc')) {
             if (($xmlArr = apc_fetch($cacheKey)) != null) {
                 $findInCache = true;
             }
         }
         if (!$xmlArr) {
             $content_array = file($objCmpFileName);
             $xmlArr = unserialize(implode("", $content_array));
         }
     } else {
         if (extension_loaded('ionCube Loader')) {
             include_once OPENBIZ_BIN . "util/xmltoarray.php";
         } else {
             include_once OPENBIZ_BIN . "util/xmltoarray.src.php";
         }
         $parser = new XMLParser($objXmlFileName, 'file', 1);
         $xmlArr = $parser->getTree();
         // simple validate the xml array
         $root_keys = array_keys($xmlArr);
         $root_key = $root_keys[0];
         if (!$root_key || $root_key == "") {
             trigger_error("Metadata file parsing error for file {$objXmlFileName}. Please double check your metadata xml file again.", E_USER_ERROR);
         }
         $xmlArrStr = serialize($xmlArr);
         if (!file_exists(dirname($objCmpFileName))) {
             mkdir(dirname($objCmpFileName));
         }
         $cmp_file = fopen($objCmpFileName, 'w') or die("can't open cmp file to write");
         fwrite($cmp_file, $xmlArrStr) or die("can't write to the cmp file");
         fclose($cmp_file);
     }
     // save to cache to avoid file processing overhead
     if (!$findInCache && extension_loaded('apc')) {
         apc_store($cacheKey, $xmlArr);
     }
     self::$_xmlArrayList[$xmlFile] = $xmlArr;
     return $xmlArr;
 }
예제 #3
0
 /**
  * Erzeugt die Kartendarstellung aus einer XML Datei
  *
  * @param string $file XML Datei
  * @return bool
  */
 function xmlMap($file)
 {
     $parser = new XMLParser($file, 'file', 1);
     $tree = $parser->getTree();
     $lat = $tree[MAP][STARTLAT][VALUE];
     $lng = $tree[MAP][STARTLONG][VALUE];
     $width = $tree[MAP][WIDTH][VALUE];
     $height = $tree[MAP][HEIGHT][VALUE];
     $min_zoom = $tree[MAP][MINZOOM][VALUE];
     $typ = $tree[MAP][MAPTYPE][VALUE];
     $zoom = $tree[MAP][STARTZOOM][VALUE];
     if (!$min_zoom) {
         $min_zoom = 1;
     }
     $max_zoom = $tree[MAP][MAXZOOM][VALUE];
     if (!$max_zoom) {
         $max_zoom = 17;
     }
     $navcontrol = $tree[MAP][NAVCONTROL][VALUE];
     $width = $width . "px";
     $height = $height . "px";
     if ($typ == "normal") {
         $typstr = "G_NORMAL_MAP";
     } elseif ($typ == "satellit") {
         $typstr = "G_SATELLITE_MAP";
     } elseif ($typ == "hybrid") {
         $typstr = "G_HYBRID_MAP";
     }
     if ($navcontrol == "large") {
         $controlstr = "GLargeMapControl()";
     } elseif ($navcontrol == "small") {
         $controlstr = "GSmallMapControl()";
     }
     echo "\n\t\t<script type=\"text/javascript\">\n\n\t\tvar map = new GMap2(document.getElementById(\"gmapper_map\"));\n\n\t\tmap.addControl(new {$controlstr});\n\n\t\tmap.addControl(new GMapTypeControl());\n\n\t\tmap.enableDoubleClickZoom();\n\n\t\tmap.enableContinuousZoom();\n\n\t\tvar mt = map.getMapTypes();\n\n\t\t      for (var i=0; i<mt.length; i++) {\n\t\t        mt[i].getMinimumResolution = function() {return {$min_zoom};}\n\t\t        mt[i].getMaximumResolution = function() {return {$max_zoom};}\n\t\t      }\n\t\tmap.addControl(new GMapTypeControl());\n\n\t\tmap.setCenter(new GLatLng( {$lat},{$lng}),{$zoom});\n\n\n\t\tmap.setMapType({$typstr});\n\n\t\t</script>";
     return true;
 }