', $review);
$reviews[$y]["content"] = $review;
}
$xpath = new DOMXPath($dom);
$paras = $xpath->query("//table[@class='crIFrameReviewList']//tr/td/div/div[3]/div/div/a/span");
for ($y = 0; $y < $paras->length; $y++ ) { //$paras->length
$para = $paras->item($y);
$author = $para->textContent; // $dom->saveXml($para);
$reviews[$y]["author"] = $author;
}
//print_r($reviews);
if(function_exists("wpr_translate_partial")) {
$content = wpr_translate_partial($content);
}
if(function_exists("wpr_rewrite_partial")) {
$content = wpr_rewrite_partial($content,$options);
}
if(!empty($item->MediumImage->URL)) {$largestimage = $item->MediumImage->URL;}
elseif(!empty($item->SmallImage->URL)) {$largestimage = $item->SmallImage->URL;}
elseif(!empty($item->LargeImage->URL)) {$largestimage = $item->LargeImage->URL;}
$customfield = array();
$customfield["amazontitle"] = $item->ItemAttributes->Title;
$customfield["amazonthumbnail"] = $largestimage;
$customfield["amazonthumbnaillarge"] = $item->LargeImage->URL;
$customfield["amazonprice"] = $price;
$customfield["amazonlistprice"] = $listprice;
$customfield["amazonsaving"] = $savings;
$customfield["amazonlink"] = $item->DetailPageURL;
$customfield["amazonasin"] = $asin;
$customfield["asin"] = $asin;
$customfield["amazonrating"] = $item->CustomerReviews->AverageRating;
$single = array();
$single["unique"] = $asin;
$single["title"] = $item->ItemAttributes->Title;
if($options['wpr_aa_shortcode'] == "Yes") {
$single["content"] = '[wpramazon asin="'.$asin.'"]';
} else {
$single["content"] = $content;
}
$single["comments"] = $reviews;
$single["customfield"] = $customfield;
$added_post = $added_post + 1;
array_push($return, $single);
$rr++;
}
}
$yy++;
}
$page++;$cnum=0;
}
return $return;
}
function wpr_amazon_getlist($keywords,$count) {
global $wpdb,$wpr_table_templates;
$searchindex = "All";
$maxitems = $count;
$itemcount = 0;
if($keywords == "") {
$return["error"]["module"] = "Amazon";
$return["error"]["reason"] = "No keyword";
$return["error"]["message"] = __("No keyword specified.","wprobot");
return $return;
}
$start = rand(1, 17);
$start2 = $start / 10;
$start2 = (string) $start2;
$start2 = explode(".", $start2);
$page=(int)$start2[0];
$page++;
$cnum=(int)$start2[1];
//$imagepath = get_option('siteurl').'/wp-content/plugins/WPRobot3/images/';
$imagepath = WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__));
$imagepath = str_replace("/modules/","/images/",$imagepath);
$options = unserialize(get_option("wpr_options"));
$public_key = $options['wpr_aa_apikey'];
$private_key = $options['wpr_aa_secretkey'];
$affid = $options['wpr_aa_affkey'];
$added_post = 0;
$return = array();
$ads = "";
$site = $options['wpr_aa_site'];
if($site == "us") {$site = "com";}
if($site == "uk") {$site = "co.uk";}
if($browsenode == "") {$browsenode = 0;}
while($added_post < $count) {
$pxml = wpr_aws_request($site, array(
"Operation"=>"ItemSearch",
"AssociateTag"=>$affid,
"SearchIndex"=>"All",
"Keywords"=>$keywords,
"ItemPage"=>$page,
"ReviewSort"=>"-HelpfulVotes",
"ResponseGroup"=>"Large"
), $public_key, $private_key);
if(!empty($pxml["error"])) {return $pxml;}
//echo "
";print_r($pxml);echo "
";
if($count<=10){
$count_this = $count;
} else{
$count_this = 10;
}
$i=0;
$yy=0;
if (!$pxml) {
$return["error"]["module"] = "Amazon";
$return["error"]["reason"] = "Request fail";
$return["error"]["message"] = __("API request could not be sent.","wprobot");
return $return;
}
if (isset($pxml->Error)) {
$message = '
'.__("There was a problem with your Amazon API request. This is the error Amazon returned:","wprobot").'
'.$pxml->Error->Code.': '.$pxml->Error->Message.'
';
$return["error"]["module"] = "Amazon";
$return["error"]["reason"] = "API fail";
$return["error"]["message"] = $message;
return $return;
}
if (isset($pxml->Items->Request->Errors->Error->Code)) {
$message = '
'.__("There was a problem with your Amazon API request. This is the error Amazon returned:","wprobot").'
'.$pxml->Items->Request->Errors->Error->Code.': '.$pxml->Items->Request->Errors->Error->Message.'
';
$return["error"]["module"] = "Amazon";
$return["error"]["reason"] = "API fail";
$return["error"]["message"] = $message;
return $return;
}
if (!$pxml->Items->Item) {
$return["error"]["module"] = "Amazon";
$return["error"]["reason"] = "No content";
$return["error"]["message"] = __("No (more) products found for this keyword.","wprobot");
return $return;
}
foreach($pxml->Items->Item as $item) {
if($yy >= $cnum) {
$skipit = 0;
$skip = $options["wpr_aa_skip"];
if($skip == "noimg" || $skip == "nox") {if($item->MediumImage->URL == "" && $item->SmallImage->URL) {$skipit = 1;}}
if($skip == "nodesc" || $skip == "nox") {if($item->EditorialReviews->EditorialReview->Content == "") {$skipit = 1;}}
if ($i<$count_this && $skipit == 0) {
$dcontent = "";
if (isset($item->EditorialReviews->EditorialReview)) {
foreach($item->EditorialReviews->EditorialReview as $descs) {
$dcontent .= $descs->Content;
}
$dcontent = strip_tags($dcontent);
$dcontent = substr($dcontent, 0, 130);
$dcontent .= '... ';
}
$timg = $item->LargeImage->URL;
$thumbnail = '
';
$link = '
'.$item->ItemAttributes->Title.'';
if($maxitems >= $itemcount) {
$ads .= '
'.$thumbnail.$link.'
'.$dcontent.'
';
$itemcount++;
}
$added_post++;
$i++;
}
}
$yy++;
}
$page++;$cnum=0;
}
return $ads;
}
function wpr_amazon_options_default() {
$options = array(
"wpr_aa_affkey" => "",
"wpr_aa_apikey" => "",
"wpr_aa_secretkey" => "",
"wpr_aa_skip" => "",
"wpr_aa_revtemplate" => "
Review by {author} for {link}
Rating: {rating}
{content}
",
"wpr_aa_excerptlength" => "500",
"wpr_aa_site" => "us",
"wpr_aa_shortcode" => "No"
);
return $options;
}
function wpr_amazon_options($options) {
?>
}
function wpr_aws_getnodename($nodeid) {
$options = unserialize(get_option("wpr_options"));
$public_key = $options['wpr_aa_apikey'];
$affid = $options['wpr_aa_affkey'];
$private_key = $options['wpr_aa_secretkey'];
$locale = $options['wpr_aa_site'];
if($locale == "us") {$locale = "com";}
if($locale == "uk") {$locale = "co.uk";}
$pxml = wpr_aws_request($locale, array(
"Operation"=>"BrowseNodeLookup",
"BrowseNodeId"=>$nodeid,
"AssociateTag"=>$affid,
"ResponseGroup"=>"BrowseNodeInfo"
), $public_key, $private_key);
//echo "
";print_r($pxml);echo "
";
if ($pxml === False) {
return false;
} else {
if($pxml->BrowseNodes->BrowseNode->Name) {
return $pxml->BrowseNodes->BrowseNode->Name;
} elseif($pxml->BrowseNodes->Request->Errors->Error->Message) {
$return["message"] = $pxml->BrowseNodes->Request->Errors->Error->Message;
return $return;
} else {
return false;
}
}
}
function wpr_ama_price($atts, $content = null) {
$options = unserialize(get_option("wpr_options"));
$public_key = $options['wpr_aa_apikey'];
$private_key = $options['wpr_aa_secretkey'];
$affid = $options['wpr_aa_affkey'];
$locale = $options['wpr_aa_site'];
if($locale == "us") {$locale = "com";}
if($locale == "uk") {$locale = "co.uk";}
$pxml = wpr_aws_request($locale, array(
"Operation"=>"ItemLookup",
"ItemId"=>$atts["asin"],
"AssociateTag"=>$affid,
//"IncludeReviewsSummary"=>"False",
//"TruncateReviewsAt"=>"9216",
"ResponseGroup"=>"OfferSummary"
), $public_key, $private_key);
//echo "
";print_r($pxml);echo "
";
if ($pxml === False) {
return false;
} else {
if($pxml->Items->Item->OfferSummary->LowestNewPrice->FormattedPrice) {
$price = str_replace("$", "$ ", $pxml->Items->Item->OfferSummary->LowestNewPrice->FormattedPrice);
if($price == "Too low to display" || $price == "Price too low to display") {
$price = str_replace("$", "$ ", $item->ItemAttributes->ListPrice->FormattedPrice);
}
return $price;
} else {
return $content;
}
}
}
add_shortcode('wpramaprice', 'wpr_ama_price' );
function wpr_ama_reviews($atts, $content = null) {
$options = unserialize(get_option("wpr_options"));
$public_key = $options['wpr_aa_apikey'];
$private_key = $options['wpr_aa_secretkey'];
$locale = $options['wpr_aa_site'];
$affid = $options['wpr_aa_affkey'];
if($locale == "us") {$locale = "com";}
if($locale == "uk") {$locale = "co.uk";}
$pxml = wpr_aws_request($locale, array(
"Operation"=>"ItemLookup",
"ItemId"=>$atts["asin"],
"IncludeReviewsSummary"=>"False",
"AssociateTag"=>$affid,
"TruncateReviewsAt"=>"5000",
"ResponseGroup"=>"Reviews"
), $public_key, $private_key);
//echo "
";print_r($pxml);echo "
";
if ($pxml === False) {
return false;
} else {
if($pxml->Items->Item->CustomerReviews->IFrameURL) {
$product_review = $pxml->Items->Item->CustomerReviews->IFrameURL;
$reviewsiframe = '
';
return $reviewsiframe;
} else {
return $content;
}
}
}
add_shortcode('wpramareviews', 'wpr_ama_reviews' );
function wpr_ama_handler($atts, $content = null) {
global $wpdb,$wpr_table_templates;
$template = $wpdb->get_var("SELECT content FROM " . $wpr_table_templates . " WHERE type = 'amazon'");
$imagepath = WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__));
$imagepath = str_replace("/modules/","/images/",$imagepath);
$options = unserialize(get_option("wpr_options"));
$public_key = $options['wpr_aa_apikey'];
$private_key = $options['wpr_aa_secretkey'];
$locale = $options['wpr_aa_site'];
$affid = $options['wpr_aa_affkey'];
if($locale == "us") {$locale = "com";}
if($locale == "uk") {$locale = "co.uk";}
$pxml = wpr_aws_request($locale, array(
"Operation"=>"ItemLookup",
"ItemId"=>$atts["asin"],
"IncludeReviewsSummary"=>"False",
"AssociateTag"=>$affid,
"TruncateReviewsAt"=>"5000",
"ResponseGroup"=>"Large"
), $public_key, $private_key);
//echo "
";print_r($pxml);echo "
";
if ($pxml === False) {
return false;
} else {
if($pxml->Items->Item->CustomerReviews->IFrameURL) {
foreach($pxml->Items->Item as $item) {
$desc = "";
if (isset($item->EditorialReviews->EditorialReview)) {
foreach($item->EditorialReviews->EditorialReview as $descs) {
$desc .= $descs->Content;
}
}
$elength = ($options['wpr_aa_excerptlength']);
if ($elength != 'full') {
$desc = strip_tags($desc,'
');
$desc = substr($desc, 0, $elength);
}
$features = "";
if (isset($item->ItemAttributes->Feature)) {
$features = "
";
foreach($item->ItemAttributes->Feature as $feature) {
$posx = strpos($feature, "href=");
if ($posx === false) {
$features .= "- ".$feature."
";
}
}
$features .= "
";
}
$timg = $item->MediumImage->URL;
if($timg == "") {$timg = $item->LargeImage->URL;}
$thumbnail = '
';
$link = '
'.$item->ItemAttributes->Title.'';
$product_review = $item->CustomerReviews->IFrameURL;
$reviewsiframe = '
';
$revcontent = file_get_contents($product_review);
if (preg_match('~]*>(.*?)~si', $revcontent, $body)) { $reviewsnoiframe = str_replace('class="crVotingButtons">', "", $body[1]); } else {$reviewsnoiframe = "";}
$price = str_replace("$", "$ ", $item->OfferSummary->LowestNewPrice->FormattedPrice);
$listprice = str_replace("$", "$ ", $item->ItemAttributes->ListPrice->FormattedPrice);
if($price == "Too low to display" || $price == "Price too low to display") {
$price = $listprice;
}
$acontent = $template;
preg_match('#\[has_reviews\](.*)\[/has_reviews\]#smiU', $template, $check);
if ($check[0] != false) {
if(empty($item->CustomerReviews->TotalReviews)) {
$acontent = str_replace($check[0], "", $acontent);
}
}
$acontent = str_replace(array("[has_reviews]","[/has_reviews]"), "", $acontent);
preg_match('#\[has_listprice\](.*)\[/has_listprice\]#smiU', $template, $matches);//print_r($matches);
if ($matches[0] != false) {
if(empty($listprice)) {
$acontent = str_replace($matches[0], "", $acontent);
}
}
$acontent = str_replace(array("[has_listprice]","[/has_listprice]"), "", $acontent);
$asin = $item->ASIN;
$acontent = wpr_random_tags($acontent);
$acontent = str_replace("{title}", $item->ItemAttributes->Title, $acontent);
$acontent = str_replace("{description}", $desc, $acontent);
$acontent = str_replace("{features}", $features, $acontent);
$acontent = str_replace("{thumbnail}", $thumbnail, $acontent);
$acontent = str_replace("{smallimage}", $item->SmallImage->URL, $acontent);
$acontent = str_replace("{mediumimage}", $item->MediumImage->URL, $acontent);
$acontent = str_replace("{largeimage}", $item->LargeImage->URL, $acontent);
$acontent = str_replace("{buynow}", '
', $acontent);
$acontent = str_replace("{buynow-big}", '
', $acontent);
$acontent = str_replace("{buynow-ger}", '
', $acontent);
$acontent = str_replace("{price}", $price, $acontent);
$acontent = str_replace("{listprice}", $listprice, $acontent);
$savings = str_replace("$ ", "", $listprice) - str_replace("$ ", "", $price);
$acontent = str_replace("{savings}", $savings, $acontent);
$acontent = str_replace("{url}", $item->DetailPageURL, $acontent);
$acontent = str_replace("{avgrating}", $item->CustomerReviews->AverageRating, $acontent);
$acontent = str_replace("{reviewsnum}", $item->CustomerReviews->TotalReviews, $acontent);
$noqkeyword = str_replace('"', '', $keywords);
$acontent = str_replace("{keyword}", $noqkeyword, $acontent);
$acontent = str_replace("{Keyword}", ucwords($noqkeyword), $acontent);
$acontent = str_replace("{link}", $link, $acontent);
$acontent = str_replace("{asin}", $asin, $acontent);
$acontent = str_replace("{price-updating}", $price, $acontent);
// rating
if (strpos($acontent, "{rating}") != false) {
$image = wpr_star_rating($item->CustomerReviews->AverageRating);
$acontent = str_replace("{rating}",$image,$acontent);
}
// reviews
$acontent = str_replace("{reviews-url}", $product_review, $acontent);
$acontent = str_replace("{reviews-iframe}", $reviewsiframe, $acontent);
$acontent = str_replace("{reviews-noiframe}", $reviewsnoiframe, $acontent);
preg_match('#\{reviews(.*)\}#iU', $acontent, $rmatches);
if ($rmatches[0] == false) {
} else {
$acontent = str_replace($rmatches[0], $reviewsiframe, $acontent);
}
}
return $acontent;
} else {
return $content;
}
}
}
add_shortcode('wpramazon', 'wpr_ama_handler' );
?>
Wyszukiwarka
Podobne podstrony:
Jagoda Acai dar natury z AmazoniiAmazon StealthAmazons Greek MythologyDeszczowy las AmazoniiJak kupowac muzyke na Amazon co ukAmazon Search Dominator Delux Training And RolodexAmazonkawięcej podobnych podstron