function lhg_amazon_price_to_float($price, $my_region)
{
    $price = trim($price);
    # check if this is a affilinet price
    # EUR formatting is different than from Amazon, i.e. "XX.XX EUR" instead of "EUR XX,XX"
    if (preg_match("/[0-9].[0-9][0-9] EUR/", $price, $match) == 1) {
        #error_log("Found".$match[0]);
        # make amazon like string
        $price = str_replace(",", "", $price);
        $price = str_replace(".", ",", $price);
        $price = str_replace("EUR", "", $price);
    }
    # check if this is a zanox price
    # EUR formatting is different than from Amazon, i.e. "XX.XX" instead of "EUR XX,XX"
    if (preg_match("/EUR/", $price, $match) == 0 && preg_match("/[0-9].[0-9][0-9]\$/", $price, $match) == 1) {
        #error_log("Found".$match[0]);
        # make amazon like string
        $price = str_replace(",", "", $price);
        $price = str_replace(".", ",", $price);
    }
    global $region;
    if ($my_region == "") {
        $my_region = $region;
    }
    #print "OP(reg: $region): $price<br>";
    //$currency_region = lhg_get_currency_region ( $price );
    $price = lhg_remove_amazon_currency_symbol($price, $my_region);
    # thousand separator needs to be removed
    if (strpos($price, ".") > strpos($price, ",")) {
        $price = str_replace(",", "", $price);
    }
    //broken pound symbol sometimes in co.uk prices
    if (!is_numeric(substr($price, 0, 1))) {
        $price = substr($price, 1);
    }
    // EUR values e.g. 1.345,03 or 32,43
    if ($my_region == "de" or $my_region == "fr" or $my_region == "es" or $my_region == "nl" or $my_region == "it") {
        # looks like amazon (EUR) price
        //
        //switch to US format
        //if ($region == "co.jp") $price = str_replace(",","",$price);
        //if ($region == "cn")    $price = str_replace(",","",$price);
        if ($my_region == "de" or $my_region == "es" or $my_region == "fr" or $my_region == "it" or $my_region == "nl") {
            $price = str_replace(".", "", $price);
        }
        if ($my_region == "de" or $my_region == "es" or $my_region == "fr" or $my_region == "it" or $my_region == "nl") {
            $price = str_replace(",", ".", $price);
        }
        //remove thousand separator
        #$price = floatval ( str_replace(",","",$price) );
    }
    #print "P2F (reg: $region): $price<br>";
    return $price;
}
function getSingleAmazonProduct($asin = '', $extratext = '', $extrabutton = 0)
{
    global $public_key, $private_key, $aws_partner_id, $aws_partner_locale, $amazonhiddenmsg, $amazonerrormsg, $apippopennewwindow, $apippnewwindowhtml;
    global $appip_text_lgimage;
    global $appip_text_listprice;
    global $appip_text_newfrom;
    global $appip_text_usedfrom;
    global $appip_text_instock;
    global $appip_text_outofstock;
    global $appip_text_author;
    global $appip_text_starring;
    global $appip_text_director;
    global $appip_text_reldate;
    global $appip_text_preorder;
    global $appip_text_releasedon;
    global $appip_text_notavalarea;
    global $buyamzonbutton;
    global $addestrabuybutton;
    global $encodemode;
    global $post;
    global $amazonRun;
    //text strings
    global $lang;
    global $txt_compat;
    global $txt_Compat;
    global $txt_with;
    global $txt_rating;
    global $txt_ratings;
    global $txt_price;
    global $txt_out_of_stock;
    global $txt_button;
    global $txt_button_width;
    global $siteurl;
    global $txt_pricetrend;
    global $txt_A_preis;
    global $txt_currency;
    global $txt_shipping;
    global $txt_on_stock;
    global $txt_updated;
    global $txt_buy_from;
    global $txt_search_at;
    global $txt_preorder;
    global $txt_not_avail_at;
    global $txt_never_avail;
    $region = get_region();
    $aws_partner_id = get_id();
    $aws_partner_locale = $region;
    //print "PL: $aws_partner_locale";
    //$apippOpenNewWindow = get_post_meta($post->ID,'amazon-product-newwindow',true);
    //if($apippOpenNewWindow!='3'){$apippnewwindowhtml=' target="amazonwin" ';}
    #print "A0: $asin<br>";
    $asinlist = get_post_meta($post->ID, 'amazon-product-asin-list', true);
    #print "CSV: ".str_getcsv($asin.",".$asinlist, ",");
    $data = str_getcsv($asin . "," . $asinlist, ",");
    #var_dump($data);
    #
    # check if DB entries for asins already exist -> create if necessary
    #
    $i = 0;
    while ($i < count($data)) {
        $asin_tmp = $data[$i];
        #print " A: $asin";
        if ($asin_tmp != "") {
            lhg_amazon_create_db_entry($region, $post->ID, $asin_tmp);
        }
        $i++;
    }
    //print "<br>Data0: $data[0] <br>";
    //print "Data1: $data[1] <br>";
    #print "Af: $asin<br>";
    if ($asin != '') {
        #print "count: ".count($data);
        #$i=0;
        #while ( $i< count($data) ){
        # one loop is enough. SQL request looks at all ASINs
        //print "I: $i <br>";
        global $amazonRun;
        $amazonRun = 0;
        // reset loop counter for new asin list element
        $asin = $data[$i];
        // $asin; //valid ASIN
        $ASIN = $asin;
        //valid ASIN
        //print "ASIN: $asin";
        $errors = '';
        #$appip_responsegroup 	= "ItemAttributes,Images,Offers,Reviews";
        #$appip_operation 		= "ItemLookup";
        #$appip_idtype	 		= "ASIN";
        #if ($region != "nl")
        #$pxml = aws_signed_request($aws_partner_locale, array("Operation"=>$appip_operation,"ItemId"=>$ASIN,"ResponseGroup" => $appip_responsegroup,"IdType"=>$appip_idtype,"AssociateTag"=>$aws_partner_id ), $public_key, $private_key);
        //print "<br>PXML: ";var_dump($pxml);
        #if(!is_array($pxml)){
        #	$pxml2=$pxml;
        #	$pxml = array();
        #	$pxml["itemlookuperrorresponse"]["error"]["code"]["message"] = $pxml2;
        #}
        #if(isset($pxml["itemlookuperrorresponse"]["error"]["code"])){
        #	$errors = $pxml["itemlookuperrorresponse"]["error"]["code"]["message"];
        #}
        //print "<br>Article found, checking";
        //Call 1
        $amazonRun += 1;
        //count loops to prevent multiple requests (will be reset for ASIN lists)
        //echo "<hr>Call 1<br>RUN: $amazonRun<br>";
        //if ($run == 2) break;
        #$result = FormatASINResult($pxml,$post->ID);
        $newPrice = lhg_db_get_lowest_amazon_price($post->ID, $region);
        #print "<br>New Price: $newPrice - $asin, $region";
        #if ($newPrice != "" and $newPrice != 0) break;
        #$i++;
        #}
        if ($lang != "de") {
            if ($newPrice == 0) {
                $newPrice = "out of stock";
            }
        }
        if ($lang == "de") {
            if ($newPrice == 0) {
                $newPrice = "nicht lieferbar";
            }
        }
        if ($errors == 'exceeded') {
            #	$hiddenerrors = "<"."!-- HIDDEN AMAZON PRODUCT IN A POST ERROR: Requests Exceeded -->";
            #	$errors = 'Requests Exceeded';
            #	if($extratext!=''){return $hiddenerrors.$extratext;}
            #	return $hiddenerrors;
            #}elseif($errors=='no signature match'){
            #        //echo "HERE A!";
            #	$hiddenerrors = "<"."!-- HIDDEN AMAZON PRODUCT IN A POST ERROR: Signature does not match AWS Signature. Check AWS Keys and Signature method. -->";
            #	$errors = 'Signature does not match';
            #	if($extratext!=''){return $hiddenerrors.$extratext;}
            #	return $hiddenerrors;
            //}elseif($errors=='not valid'){
            //        //echo "HERE B!";
            //	$hiddenerrors = "<"."!-- HIDDEN AMAZON PRODUCT IN A POST ERROR: Item Not Valid. Possibly not available in your locale or you did not enter a correct ASIN. -->";
            //	$errors = 'Not a valid item';
            //	if($extratext!=''){return $hiddenerrors.$extratext;}
            //	return $hiddenerrors;
            //}elseif($errors!=''){
            //	$hiddenerrors = "<"."!-- HIDDEN AMAZON PRODUCT IN A POST ERROR: ". $errors ."-->";
            //	if($extratext!=''){return $hiddenerrors.$extratext;}
            //	return $hiddenerrors;
        } else {
            //global $run;
            //$run += 1;
            //Call 2
            //echo "<hr>Call 2<br>";
            //$result = FormatASINResult($pxml,$post->ID);
            //print_r ($result);
            //echo "<br>WHAT: ".$result['URL'];
            //$returnval  = '	<br /><div class="amazon-box">';
            //$returnval = '                               ';
            //$returnval  .= ' 	 			<div class="amazon-box">';
            //<table cellpadding="0"class="amazon-product-table">'."\n";
            //$returnval .= '		<tr>'."\n";
            //$returnval .= '			<td valign="top">'."\n";
            $returnval .= '				<div class="amazon-image-wrapper">' . "\n";
            //$returnval .= '					<a href="' . $result["URL"] . '" '. $apippnewwindowhtml .'>' . awsImageGrabber($result['MediumImage'],'amazon-image') . '</a><br />'."\n";
            global $txt_cpl_noimage;
            // = "Kein Bild verf&uuml;gbar";
            #
            # ToDo: URL should be stored in DB and not fetched each time
            #
            #$amazon_image = awsImageGrabber($result['MediumImage'],'amazon-image');
            $attr = array('alt' => trim(strip_tags(translate_title(get_the_title($PID)))), 'title' => trim(strip_tags(translate_title(get_the_title($PID)))));
            $amazon_image = get_the_post_thumbnail($artid, array(130, 130), $attr);
            if (strpos($amazon_image, 'src=""')) {
                $amazon_image = '<img src="/wp-uploads/2013/03/noimage130.jpg" alt="' . $txt_cpl_noimage . '" title="' . $txt_cpl_noimage . '">';
            }
            if ($amazon_image == "") {
                $amazon_image = '<img src="/wp-uploads/2013/03/noimage130.jpg" alt="' . $txt_cpl_noimage . '" title="' . $txt_cpl_noimage . '">';
            }
            $returnval .= '					' . $amazon_image . '' . "\n";
            //$returnval .= '					'. awsImageGrabber($result['MediumImage'],'amazon-image') . ''."\n";
            //if($result['LargeImage']!=''){
            //$returnval .= '				<a target="amazon-image" href="javascript: void(0)" onclick="artwindow=window.open(\'' .$result['LargeImage'] .'\',\'art\',\'directories=no, location=no, menubar=no, resizable=no, scrollbars=no, status=no, toolbar=no, width=400,height=525\');artwindow.focus();return false;"><span class="amazon-tiny">'.$appip_text_lgimage.'</span></a>'."\n";
            //$returnval .= '					<a rel="appiplightbox" href="'.$result['LargeImage'] .'"><span class="amazon-tiny">'.$appip_text_lgimage.'</span></a>'."\n";
            //$returnval .= '					<span class="amazon-tiny">'.$appip_text_lgimage.'</span>'."\n";
            //}
            $returnval .= '				</div>' . "\n";
            $returnval .= '
<div class="amazon-buying">' . "\n";
            //$returnval .= '					<h2 class="amazon-asin-title"><a href="' . $result["URL"] . '" '. $apippnewwindowhtml .'><span class="asin-title">'.$result["Title"].'</span></a></h2>'."\n";
            //$returnval .= '					<h2 class="amazon-asin-title"><a href="' . $result["URL"] . '" '. $apippnewwindowhtml .'><span class="asin-title">'.$result["Title"].'</span></a></h2>'."\n";
            #if(isset($result["Author"])){
            #$returnval .= '					<span class="amazon-author">'.$appip_text_author.' '.$result["Author"].'</span><br />'."\n";
            #}
            #if(isset($result["Director"])){
            #$returnval .= '					<span class="amazon-director-label">'.$appip_text_director.': </span><span class="amazon-director">'.$result["Director"].'</span><br />'."\n";
            #}
            #if(isset($result["Actors"])){
            #$returnval .= '					<span class="amazon-starring-label">'.$appip_text_starring.': </span><span class="amazon-starring">'.$result["Actors"].'</span><br />'."\n";
            #}
            //if(isset($result["Rating"])){
            //$returnval .= '					<span class="amazon-rating-label">Rating: </span><span class="amazon-rating">'.$result["Rating"].'</span><br />'."\n";
            //}
            ob_start();
            if (function_exists('the_ratings')) {
                $returnval .= the_ratings();
            }
            $out1 = ob_get_contents();
            ob_end_clean();
            //get the correct! rating
            $post_id = $post->ID;
            global $wpdb;
            global $lhg_price_db;
            if ($lang != "de") {
                $ratings = $lhg_price_db->get_results("SELECT * FROM  `lhgtransverse_posts` WHERE postid_com = {$post_id}");
            }
            if ($lang == "de") {
                $ratings = $lhg_price_db->get_results("SELECT * FROM  `lhgtransverse_posts` WHERE postid_de = {$post_id}");
            }
            #$get_rates = $wpdb->get_results("SELECT rating_rating FROM $wpdb->ratings WHERE rating_postid = $post_id");
            $rating_total = 0;
            $rating_total = $ratings[0]->post_ratings_users_com + $ratings[0]->post_ratings_users_de;
            $rating = $ratings[0]->post_ratings_score_com + $ratings[0]->post_ratings_score_de;
            #foreach($get_rates as $get_rate){
            #        $rating += $get_rate->rating_rating;
            #        //print_r($get_rate);
            #        $rating_total++;
            #}
            //$returnval .= '<div class="hreview-aggregate">';
            //$returnval .= '<span class="item">';
            //$returnval .= '<span class="fn"><span class="value-title" title="'.get_the_title().'"/></span>';
            //$returnval .= '<span class="photo"><span class="value-title" title="'.wp_get_attachment_url( get_post_thumbnail_id($post->ID) ).'"/></span>';
            //$returnval .= '</span>';
            //$returnval .= '<span class="rating"><span class="value-title" title="'.($rating/$rating_total).'"/></span>';
            //$returnval .= '<span class="reviewer"><span class="value-title" title="linux-hardware-guide.de"/></span>';
            //$returnval .= '<span class="dtreviewed"><span class="value-title" title="'.get_the_date().'"/></span>';
            //$returnval .= '<span class="votes"><span class="value-title" title="'.$rating_total.'"/></span>';
            //$returnval .= '<span class="count"><span class="value-title" title="'.get_comments_number().'"/></span>';
            //$tooltip= 'Bewertet wird an dieser Stelle einzig die Linux-Kompatibilit&auml;t und nicht die Qualit&auml;t des Produktes.<div style="height: 3px;"></div>Sollten Sie dieses Produkt besitzen, dann helfen Sie bitte auch anderen Linux-Benutzern, indem Sie dessen
            //	   <a href="#comment-box">Linux-Kompatibilit&auml;t bewerten</a>.';
            //set tooltip depending on logged in or not (due to google rating)
            global $txt_tooltip;
            global $txt_amz_tooltip_loggedin;
            global $txt_amz_tooltip_not_loggedin;
            if (is_user_logged_in()) {
                $txt_tooltip = $txt_amz_tooltip_loggedin;
            }
            if (!is_user_logged_in()) {
                $txt_tooltip = $txt_amz_tooltip_not_loggedin;
            }
            $tooltip = $txt_tooltip;
            //'Bewertet wird an dieser Stelle einzig die Linux-Kompatibilit&auml;t und nicht die Qualit&auml;t des Produktes. Sollten Sie dieses Produkt besitzen, dann helfen Sie bitte auch anderen Linux-Benutzern, indem Sie dessen Linux-Kompatibilit&auml;t im Kommentar-Bereich dieser Seite bewerten.';
            $returnval .= "\n\t<b>{$txt_compat}:</b>";
            $returnval .= '
      <span class="tooltip">
        	' . tooltip($tooltip, -118, 380, -178) . '
      </span>';
            $returnval .= '

      <br />

  <div style="border: 0px solid #eee;">

    <div style="border: 0px solid #eee; width:80px; float: left;">
        ' . the_ratings_results($post->ID, 0, 0, 0, 10) . '
    </div>
    ';
            //Rich Snippet start
            //$returnval .= '<div itemscope itemtype="http://data-vocabulary.org/Review">';
            if ($rating_total == 1) {
                $returnval .= '
    <div style="border: 0px solid #eee; white-space: nowrap;">
        &nbsp;&nbsp;(<span class="rating">
          	<span class="value-title" title="' . round($rating / $rating_total, 1) . '">
                                ' . round($rating / $rating_total, 1) . '
                </span>
        </span> ' . $txt_with . '

        <span class="votes">
        	<span class="value-title" title="' . $rating_total . '">
                                ' . $rating_total . '
                </span>
        </span> ' . $txt_rating . ')
    </div>

  </div>' . "\n";
            }
            if ($rating_total == 0) {
                $rate_average_value = 0;
            } else {
                $rate_average_value = round($rating / $rating_total, 1);
            }
            if ($rating_total != 1) {
                $returnval .= '
    <div style="border: 0px solid #eee; white-space: nowrap;">
  	&nbsp;&nbsp;(<span class="rating">
        	<span class="value-title" title="' . $rate_average_value . '">
                                ' . $rate_average_value . '
                </span>
        </span> ' . $txt_with . '

        <span class="votes">
        	<span class="value-title" title="' . $rating_total . '">
                                ' . $rating_total . '
                </span>
        </span> ' . $txt_ratings . ')
    </div>
  </div>' . "\n";
            }
            //Rich Snippet end
            //$returnval .= '</div>';
            $returnval .= '
  <br />
';
            //also store cheapest price - not used. Use central price DB instead
            #$cheapest_price = lhg_db_get_cheapest_price($post->ID);
            #print "<br>Cheapest: $cheapest_price";
            #$meta="cheapest_price_".$region;
            #update_post_meta($post->ID,$meta,$cheapest_price);
            #                                $returnval .= '<div class="amaz-grey-box" style="border: 0px solid #eee; background-color: #eee;">';
            //if ($rating_total != 1) $returnval .= ' ('.$rating_total.' Bewertungen)</div></div><br>'."\n";
            //$returnval .= '				<hr noshade="noshade" size="1" />'."\n";
            //$returnval .= '				<div align="left">'."\n";
            //$returnval .= '					<table class="amazon-product-price" cellpadding="0">'."\n";
            //if($extratext!=''){
            //$returnval .= '						<tr>'."\n";
            //$returnval .= '							<td class="amazon-post-text" colspan="2">'.$extratext.'</td>'."\n";
            //$returnval .= '						</tr>'."\n";
            //}
            //If($result["PriceHidden"]==1 ){
            //	$returnval .= '						<tr>'."\n";
            //	$returnval .= '							<td class="amazon-list-price-label">'.$appip_text_listprice.':</td>'."\n";
            //	$returnval .= '							<td class="amazon-list-price-label">'.$amazonhiddenmsg.'</td>'."\n";
            //	$returnval .= '						</tr>'."\n";
            //}elseif($result["ListPrice"]!='0'){
            //	$returnval .= '						<tr>'."\n";
            //	$returnval .= '							<td class="amazon-list-price-label">Preis: '.$appip_text_listprice.':</td>'."\n";
            //$returnval .= '							Preis: '.$appip_text_listprice.':'."\n";
            //$returnval .= '							'.  mb_convert_encoding($result["ListPrice"], $encodemode, mb_detect_encoding( $result["ListPrice"], "auto" )) .' '."\n";
            //	$returnval .= '							<td class="amazon-list-price">'.  mb_convert_encoding($result["ListPrice"], $encodemode, mb_detect_encoding( $result["ListPrice"], "auto" )) .'</td>'."\n";
            //	$returnval .= '						</tr>'."\n";
            //}
            if (isset($newPrice)) {
                #print "AAH!";
                #$result["LowestNewPrice"])){
                #if($result["LowestNewPrice"]=='Too low to display'){
                #	$newPrice = 'Check Amazon For Pricing';
                #}else{
                #	#$newPrice = $result["LowestNewPrice"];
                #}
                //$returnval .= '						<tr>'."\n";
                //$returnval .= '							<td class="amazon-new-label">'.$appip_text_newfrom.':</td>'."\n";
                #					$returnval .= '							'.$txt_price.':'."\n";
                #if ($result["TotalNew"] == '') $returnval.="Warn \n";
                #if($result["TotalNew"]>0){
                //$ship=scrape($asin);
                //print_r($ship);
                //$returnval .= "Total: ".$SalePrice['FormattedPrice']."-".$result["ListPrice"]."+".$ship[1]."<br>";
                #not needed any longer. Stored in DB
                //$newPrice
                $myFile = "/home/wordpressftp/amazon-{$region}.txt";
                $fh = fopen($myFile, 'a') or die("can't open file");
                $stringData = $post->ID . ";" . $newPrice . "\n";
                fwrite($fh, $stringData);
                fwrite($fh, $stringData);
                fclose($fh);
                # store price - currently disabled
                #                //$newPrice with date
                $myFile = "/home/wordpressftp/amazon_date-{$region}.txt";
                $timeInf = time();
                $fh = fopen($myFile, 'a') or die("can't open file");
                $stringData = $post->ID . ";" . $newPrice . ";" . $timeInf . ";" . $result["URL"] . "\n";
                fwrite($fh, $stringData);
                fclose($fh);
                #lhg_amazon_price_to_db($region, $post->ID, $asin, $newPrice, $result["URL"], $timeInf);
                //remove Amazon string Symbol
                $newPrice = lhg_remove_amazon_currency_symbol($newPrice, $region);
                //add currency symbol
                #                                        $returnval .= lhg_get_currency_symbol ( $region );
                /*
                                                if ($region == "co.uk") $returnval .= "&pound;";
                                                if ($region == "co.jp") $returnval .= "&yen;";
                                                if ($region == "cn") {
                                                	$returnval .= "&yen;";
                                                        $newPrice  = substr($newPrice,2);
                                                }
                                                if ($region == "co.jp") $newPrice  = substr($newPrice,2);
                */
                #                                        $returnval .= '							'. mb_convert_encoding($newPrice , $encodemode, mb_detect_encoding( $newPrice, "auto" )).' <span itemprop="availability" content="in_stock" class="instock"> ('.$txt_on_stock.') </span>'."\n";
                #                                        $returnval .= '<br><div class="shipping"><font size="1">('.$txt_shipping.')';
                global $txt_tooltip2;
                $tooltip = $txt_tooltip2;
                //"Die von Amazon zur Verf&uuml;gung gestellten Preise sind exklusive m&ouml;glicherweise zus&auml;tzlich anfallender Versandkosten (abh&auml;ngig vom jeweiligen Anbieter des Amazon-Marketplace).";
                #                	                $returnval .= '<span class="tooltip">'.tooltip($tooltip).'<span>';
                #                                        $returnval .= '</font></div>';
                #
                #					}else{
                #//						$returnval .= '							'. mb_convert_encoding($newPrice , $encodemode, mb_detect_encoding( $newPrice, "auto" )).' <span class="outofstock">'.$appip_text_outofstock.'</span>'."\n";
                #						$returnval .= 'BB unbekannt							'; //. mb_convert_encoding($newPrice , $encodemode, mb_detect_encoding( $newPrice, "auto" )).' <span class="outofstock">'.$appip_text_outofstock.'</span>'."\n";
                #}
                //if($result["TotalNew"]>0){
                //	$returnval .= '							<td class="amazon-new">'. mb_convert_encoding($newPrice , $encodemode, mb_detect_encoding( $newPrice, "auto" )).' <span class="instock">'.$appip_text_instock.'</span></td>'."\n";
                //}else{
                //	$returnval .= '							<td class="amazon-new">'. mb_convert_encoding($newPrice , $encodemode, mb_detect_encoding( $newPrice, "auto" )).' <span class="outofstock">'.$appip_text_outofstock.'</span></td>'."\n";
                //}
                //$returnval .= '						</tr>'."\n";
                //				$returnval .= '								</div>'."\n";
                //store in DB
                $meta = "price-amazon." . $region;
                update_post_meta($post->ID, $meta, $newPrice);
                //$meta="url-amazon.".$region;
                //update_post_meta($post->ID,$meta,$result["URL"]);
            } elseif ($region != "pl") {
                #Price tag
                $aid = get_id();
                //if( ($errors!='') && ($region == "en")){
                //   $returnval .='Not available at <a target="_blank" href="http://www.amazon.'.$region.'/b/?_encoding=UTF8&camp=1789&creative=390957&linkCode=ur2&node=2956536011&tag=linuhardguid-20">Amazon.'.$region.'</a><img src="https://www.assoc-amazon.com/e/ir?t=linuhardguid-20&l=ur2&o=1" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />';
                //}else{
                //$returnval .= '							'.$txt_price.':'."\n";
                $ProductIsUnavailable = 1;
                if ($result["URL"] == "") {
                    $meta = "url-amazon." . $region;
                    $result["URL"] = get_post_meta($post->ID, $meta, true);
                }
                //still undefined?
                if ($result["URL"] == "") {
                    $region_tmp = $region;
                    if ($region == "nl") {
                        $region_tmp = "de";
                    }
                    $result["URL"] = 'http://www.amazon.' . $region_tmp . '/?_encoding=UTF8&amp;camp=15121&amp;creative=390961&amp;linkCode=ur2&amp;tag=' . $aid;
                    $NoUrlAvailable = 1;
                }
                #                                        $returnval .= '							'. mb_convert_encoding($newPrice , $encodemode, mb_detect_encoding( $newPrice, "auto" )).' <span class="outofstock">('.$txt_out_of_stock.')</span>'."\n";
                #     					if ($region !== "de") if ($NoUrlAvailable != 1) $returnval .='<br><div class="amazon-cr"></div>'.$txt_not_avail_at.' <a target="_blank" href="http://www.amazon.'.$region.'/?_encoding=UTF8&camp=15121&creative=390961&linkCode=ur2&tag='.$aid.'" rel="nofollow">Amazon.'.$region.'</a><div class="amazon-cr"></div>';
                #     					if ($region !== "de") if ($NoUrlAvailable == 1) $returnval .='<br><div class="amazon-cr"></div>'.$txt_never_avail.' <a target="_blank" href="http://www.amazon.'.$region.'/?_encoding=UTF8&camp=15121&creative=390961&linkCode=ur2&tag='.$aid.'" rel="nofollow">Amazon.'.$region.'</a><div class="amazon-cr"></div>';
                #     					if ($region == "de") $returnval .='<br>Nicht lieferbar von <a target="_blank" href="http://www.amazon.'.$region.'/?_encoding=UTF8&camp=15121&creative=390961&linkCode=ur2&tag='.$aid.'" rel="nofollow">Amazon.'.$region.'</a>';
                //<img src="https://www.assoc-amazon.com/e/ir?t=linuhardguid-20&l=ur2&o=1" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />';
                // $returnval .= '							'. mb_convert_encoding($newPrice , $encodemode, mb_detect_encoding( $newPrice, "auto" )).' <span class="instock"> (auf Lager) </span>'."\n";
                //}
                #Not needed any longer. Stored in DB
                $myFile = "/home/wordpressftp/amazon-{$region}.txt";
                $fh = fopen($myFile, 'a') or die("can't open file");
                $stringData = $post->ID . ";" . $txt_out_of_stock . "\n";
                fwrite($fh, $stringData);
                fclose($fh);
                # store price to file currently disabled
                #
                #              //print 'Res:'. $result["URL"];
                #               //$newPrice with date
                $myFile = "/home/wordpressftp/amazon_date-{$region}.txt";
                $timeInf = time();
                $fh = fopen($myFile, 'a') or die("can't open file");
                $stringData = $post->ID . ";" . $newPrice . ";" . $timeInf . ";" . $result["URL"] . "\n";
                fwrite($fh, $stringData);
                fclose($fh);
                //store in DB
                $newPrice = "out of stock";
                if ($region === "de") {
                    $newPrice = "nicht lieferbar";
                }
                $meta = "price-amazon." . $region;
                update_post_meta($post->ID, $meta, $newPrice);
                //$meta="url-amazon.".$region;
                //update_post_meta($post->ID,$meta,$result["URL"]);
                #print "BBB<br>";
                #lhg_amazon_price_to_db($region, $post->ID, $asin, $newPrice, $result["URL"], $timeInf);
                //                                $returnval.="Warn \n";
            }
            //if(isset($result["LowestUsedPrice"])){
            //	$returnval .= '						<tr>'."\n";
            //	$returnval .= '							<td class="amazon-used-label">'.$appip_text_usedfrom.':</td>'."\n";
            //	if($result["TotalUsed"]>0){
            //
            //		$returnval .= '						<td class="amazon-used">'. mb_convert_encoding($result["LowestUsedPrice"], $encodemode, mb_detect_encoding( $result["LowestUsedPrice"], "auto" )) .' <span class="instock">'.$appip_text_instock.'</span></td>'."\n";
            //	}else{
            //		$returnval .= '						<td class="amazon-new">'. mb_convert_encoding($result["LowestNewPrice"], $encodemode, mb_detect_encoding( $result["LowestUsedPrice"], "auto" )) . ' <span class="outofstock">'.$appip_text_outofstock.'</span></td>'."\n";
            //	}
            //	$returnval .= '						</tr>'."\n";
            //}
            //$returnval .= '						<tr>'."\n";
            //$returnval .= '							<td valign="top" colspan="2">'."\n";
            //$returnval .= '								<div class="amazon-dates">'."\n";
            //if(isset($result["ReleaseDate"])){
            //	if(strtotime($result["ReleaseDate"]) > strtotime(date("Y-m-d",time()))){
            //$returnval .= '									<span class="amazon-preorder"><br />'.$appip_text_releasedon.' '.date("F j, Y", strtotime($result["ReleaseDate"])).'.</span>'."\n";
            //	}else{
            //$returnval .= '									<span class="amazon-release-date">'.$appip_text_reldate.' '.date("F j, Y", strtotime($result["ReleaseDate"])).'.</span>'."\n";
            //	}
            //}
            //update amazon price first (see above), now show the button with updated price
            $returnval .= lhg_get_shop_button($post->ID);
            if ($errors == '') {
                //product not available at amazon
                if ($result["URL"] == "") {
                    $meta = "url-amazon." . $region;
                    $result["URL"] = get_post_meta($post->ID, $meta, true);
                }
                //still undefined?
                if ($result["URL"] == "") {
                    $result["URL"] = 'http://www.amazon.' . $region . '/?_encoding=UTF8&camp=15121&creative=390961&linkCode=ur2&tag=' . $aid;
                    $NoUrlAvailable = 1;
                }
                // href="http://www.amazon.'.$region.'/?_encoding=UTF8&camp=15121&creative=390961&linkCode=ur2&tag='.$aid.'">
                //gif for german page
                #                                if ($lang == "de") $returnval .= '<br><a href="' . $result["URL"] .'" rel="nofollow"><img src="'.$txt_button.'" border="0" '.$txt_button_width.'></a>';
                #
                #                                //dynamic button for everyone else
                #        			if ($lang != "de") {
                #
                #                                        global $txt_button_string;
                #
                #                                        if ($ProductIsUnavailable == 1) if ($NoUrlAvailable == 1) {
                ##                                        	$txt_button_string = $txt_search_at.' Amazon.'.$region;
                #                                       	$returnval .= '<br><a href="'. $result["URL"] .'" class="css_btn_class" rel="nofollow"><i class="icon-search icon-large3"></i>&nbsp;'.$txt_button_string.'</a>';
                #                                       }
                #
                #                                       if ($ProductIsUnavailable == 1) if ($NoUrlAvailable != 1) {
                #                                       	$txt_button_string = $txt_preorder.' Amazon.'.$region;
                #                                        	$returnval .= '<br><a href="'. $result["URL"] .'" class="css_btn_class" rel="nofollow"><i class="icon-shopping-cart icon-large3"></i>&nbsp;'.$txt_button_string.'</a>';
                #                                        }
                #
                #                                        if ($ProductIsUnavailable != 1) {
                #                                                $txt_button_string = $txt_buy_from.' Amazon.'.$region;
                #                                                $returnval .= '<br><a href="'. $result["URL"] .'" class="css_btn_class" rel="nofollow"><i class="icon-shopping-cart icon-large3"></i>&nbsp;'.$txt_button_string.'</a>';
                #	                        	}
                #	                        }
            }
            if ($extrabutton == 1 && $aws_partner_locale != '.com') {
                //$returnval .= '									<br /><div><a style="display:block;margin-top:8px;margin-bottom:5px;width:165px;" '. $apippnewwindowhtml .' href="' . $result["URL"] .'"><img src="'.WP_PLUGIN_URL.'/amazon-product-in-a-post-plugin/images/buyamzon-button.png" border="0" style="border:0 none !important;margin:0px !important;background:transparent !important;"/></a></div>'."\n";
            }
            //close amzbox
            $returnval .= '</div>';
            #                                $returnval .= '</div></div>'."\n";
            //$returnval .= '							</td>'."\n";
            //$returnval .= '						</tr>'."\n";
            //If(!isset($result["LowestUsedPrice"]) && !isset($result["LowestNewPrice"]) && !isset($result["ListPrice"])){
            //	$returnval .= '						<tr>'."\n";
            //	$returnval .= '							<td class="amazon-price-save-label" colspan="2">'.$appip_text_notavalarea.'</td>'."\n";
            //	$returnval .= '						</tr>'."\n";
            //}
            //$returnval .= '					</table>'."\n";
            //				$returnval .= '				</div>';
            // <br style="clear:left;">'."\n";
            //$returnval .= '				</div>'."\n";
            //$returnval .= '			</td>'."\n";
            //$returnval .= '		</tr>'."\n";
            //$returnval .= '	</table>'."\n";
            //$siteurl="linux-hardware-guide.com";
            $catlist = category_links();
            global $lhg_is_mobile_mode;
            if ($lhg_is_mobile_mode != 1) {
                $returnval = $returnval . '<div class="amazon-cat-list">' . $catlist . "</div>";
            }
            /*<table class=producttop border=0>
              #<tr class="producttop">
              #<td class="producttop" width=50%>'.
              $returnval
              .'</td>
              <td class="producttop" width=50%>'. $catlist .' </td></tr></table>';
              */
            if ($lhg_is_mobile_mode == 1) {
                $returnval = '<div class="amazon_product_top">' . $returnval . '</div>
                                <div class="amazon-cat-list">' . $catlist . ' </div>
                                <br style="clear:left;" /> ';
            }
            if (is_category()) {
                // is category, not chart output
                // echo "<h2>Cat</h2>";
            } else {
                if ($errors == '') {
                    # creation of chart should be performed on separate machine
                    # currently disabled
                    #
                    #     //echo "Here";
                    start_pricechart($post->ID);
                    //print "lang: $lang";
                    // Pricetrend image alt text:
                    $currency = lhg_get_currency_symbol($region);
                    $imgtext = $txt_pricetrend;
                    if (file_exists("/var/www/charts/" . $post->ID . "-" . $region . ".dat")) {
                        $myFile = "/var/www/charts/" . $post->ID . "-" . $region . ".dat";
                        $file = file($myFile);
                        list($min, $max, $chartdate) = split(";", $file[0]);
                        //echo "Min, Max: $min $max";
                        $title = get_the_title();
                        //echo "T: $title";
                        $sp = strpos($title, "(");
                        //echo "Pos: $sp";
                        if ($sp != "") {
                            $title = substr($title, 0, $sp);
                        }
                        //echo "T: $title";
                        $imgtext = $txt_pricetrend . "\n" . translate_title($title) . "\n-\nMinimum: {$currency} {$min} \nMaximum: {$currency} {$max}  \n{$txt_updated}: {$chartdate}";
                    }
                    if ($lang == "de") {
                        // en has no support for multiple affiliates a.t.m.
                        //if (file_exists("/var/www/charts/".$post->ID."m.png")){
                        if (false) {
                            $returnval .= '<br style="clear:left;" /><img src="http://' . $siteurl . '/wp-uploads/charts/' . $post->ID . 'm.png" alt="' . $imgtext . '" title="' . $imgtext . '" />';
                        } else {
                            if (file_exists("/var/www/charts/" . $post->ID . "-" . $region . ".png")) {
                                if ($charterror == 0) {
                                    $returnval .= '<br style="clear:left;" /><img src="/wp-uploads/charts/' . $post->ID . '-' . $region . '.png" alt="' . $imgtext . '" title="' . $imgtext . '" />';
                                }
                            }
                        }
                    } else {
                        if ($charterror == 0) {
                            if (file_exists("/var/www/charts/" . $post->ID . "-" . $region . ".png")) {
                                $returnval .= '<br style="clear:left;" /><img src="/wp-uploads/charts/' . $post->ID . "-" . $region . '.png" alt="' . $imgtext . '" title="' . $imgtext . '" />';
                            }
                        }
                    }
                    #list known prices
                    #if (file_exists("/var/www/charts/list".$post->ID.".txt")){
                    #$PriceList = file("/var/www/charts/list".$post->ID.".txt");
                    #
                    #$returnval .= '<ul>Preisvergleich
                    #               <li>Amazon.de: '.mb_convert_encoding($newPrice , $encodemode, mb_detect_encoding( $newPrice, "auto" )).' (<a href="' . $result["URL"] .'">bestellen</a>)';
                    #
                    #$returnval .= $PriceList[0];
                    #$returnval .="</ul>";
                    #}
                }
            }
            //List related categories
            //$returnval .= category_links();
            //show CPU table
            #if (in_category('CPU')) $returnval .= cpu_comparison();
            $googlecom = '<script async src="http://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="ca-pub-5383503261197603"
     data-ad-slot="4611540473"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>';
            $googlede = '<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Linux-Hardware-Guide.de -->
<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="ca-pub-5383503261197603"
     data-ad-slot="3000901678"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>';
            $google_small_mobile = '
<center>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Mobile Banner -->
<ins class="adsbygoogle"
     style="display:inline-block;width:320px;height:50px"
     data-ad-client="ca-pub-5383503261197603"
     data-ad-slot="9621646075"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</center>';
            global $lhg_is_mobile_mode;
            global $lhg_mobile_size;
            if ($lhg_is_mobile_mode != 1) {
                if ($lang == "en") {
                    if (!is_user_logged_in()) {
                        $returnval .= $googlecom;
                    }
                }
            }
            //
            if ($rating_total == 0) {
                $rate_average_value = 0;
            } else {
                $rate_average_value = round($rating / $rating_total, 1);
            }
            //only show in case of low rating
            if ($lhg_is_mobile_mode != 1) {
                if ($lang == "de") {
                    if ($rate_average_value < 5) {
                        if (!is_user_logged_in()) {
                            $returnval .= $googlede;
                        }
                    }
                }
            }
            if ($lhg_is_mobile_mode == 1) {
                if (!is_user_logged_in()) {
                    if ($lhg_mobile_size == "small") {
                        $returnval .= $google_small_mobile;
                    } elseif ($lhg_mobile_size == "large") {
                        $returnval .= $googlecom;
                    } else {
                        $returnval .= $google_small_mobile;
                    }
                }
            }
            //show article header
            //itemprop description is closed in related-post-thumbnails
            $returnval .= '<br /><h2>' . $txt_Compat . '</h2><div itemprop="description"><div class="description">';
            $returnval .= affilinet();
            //article_list();
            return $returnval;
        }
    }
}