Example #1
0
function wpr_bigcontentsearchpost($keyword,$num,$start) {
	
	if(empty($keyword)) {
		$return["error"]["module"] = "Big Content Search";
		$return["error"]["reason"] = "No keyword";
		$return["error"]["message"] = __("No keyword specified.","wprobot");
		return $return;	
	}	
	
	$options = unserialize(get_option("wpr_options"));	
	$template = "{article}";

	$x = 0;
	$bcontent = array();$uniques = array();

	for ($i = 1; $i <= $num; $i++) {
		$pxml = wpr_bigcontentsearchrequest($keyword,$uniques);

		if(!empty($pxml->error_msg)) {
			$bcontent["error"]["module"] = "Big Content Search";
			$bcontent["error"]["reason"] = "Request fail";
			$bcontent["error"]["message"] = $pxml->error_msg;	
			return $bcontent;		
		} elseif ($pxml === False) {
			$bcontent["error"]["module"] = "Big Content Search";
			$bcontent["error"]["reason"] = "Request fail";
			$bcontent["error"]["message"] = __("API request could not be sent.","wprobot");	
			return $bcontent;	
		} elseif (is_array($pxml) && !empty($pxml["error"]["message"])) {
			return $pxml;				
		} elseif (isset($pxml->response->text)) {
			$title = $pxml->response->title;					
			$text = $pxml->response->text;				
			$unique = $pxml->response->uid;			
	
			$content = $template;
			$content = wpr_random_tags($content);
			$content = str_replace("{article}", $text, $content);
			$content = str_replace("{title}", $title, $content);		
				if(function_exists("wpr_translate_partial")) {
					$content = wpr_translate_partial($content);
				}
				if(function_exists("wpr_rewrite_partial")) {
					$content = wpr_rewrite_partial($content,$options);
				}	
				
			$bcontent[$x]["unique"] = $unique;
			$bcontent[$x]["title"] = $title;
			$bcontent[$x]["content"] = $content;
			$uniques[] = $unique;
			$x++;			
		}
	}
	
	if(empty($bcontent)) {
		$bcontent["error"]["module"] = "Big Content Search";
		$bcontent["error"]["reason"] = "No content";
		$bcontent["error"]["message"] = __("No (more) Big Content Search items found.","wprobot");	
		return $bcontent;		
	} else {
		return $bcontent;	
	}		
}
Example #2
0
function wpr_twitterpost($keyword, $num, $start, $optional = "", $comments = "")
{
    global $wpdb, $wpr_table_templates;
    $options = unserialize(get_option("wpr_options"));
    if ($keyword == "") {
        // If keyword is empty return error
        $return["error"]["module"] = "Twitter";
        $return["error"]["reason"] = "No keyword";
        $return["error"]["message"] = __("No keyword specified.", "wprobot");
        return $return;
    }
    $template = $wpdb->get_var("SELECT content FROM " . $wpr_table_templates . " WHERE type = 'twitter'");
    if ($template == false || empty($template)) {
        // If module template is empty return error
        $return["error"]["module"] = "Twitter";
        $return["error"]["reason"] = "No template";
        $return["error"]["message"] = __("Module Template does not exist or could not be loaded.", "wprobot");
        return $return;
    }
    $x = 0;
    $itemcontent = array();
    $pxml = wpr_twitterrequest($keyword, $num, $start);
    // Send API request
    if (!empty($pxml["error"])) {
        return $pxml;
    }
    if ($pxml === False) {
        $itemcontent["error"]["module"] = "Twitter";
        $itemcontent["error"]["reason"] = "Request fail";
        $itemcontent["error"]["message"] = __("API request could not be sent.", "wprobot");
        return $itemcontent;
    } else {
        if (isset($pxml->entry)) {
            foreach ($pxml->entry as $news) {
                $title = $news->title;
                $summary = $news->content;
                if ($options['wpr_twitter_striplinks'] == 'yes') {
                    $summary = wpr_strip_selected_tags($summary, array('a', 'iframe', 'script'));
                }
                $authorurl = $news->author->uri;
                $authorname = $news->author->name;
                $date = $news->published;
                $author = "<a rel=\"nofollow\" href=\"{$authorurl}\">{$authorname}</a><br/><br/>";
                $content = $template;
                $content = wpr_random_tags($content);
                $content = str_replace("{title}", $title, $content);
                $content = str_replace("{tweet}", $summary, $content);
                $content = str_replace("{author}", $author, $content);
                $content = str_replace("{authorname}", $authorname, $content);
                $content = str_replace("{authorurl}", $authorurl, $content);
                $content = str_replace("{date}", $date, $content);
                $noqkeyword = str_replace('"', '', $keyword);
                $content = str_replace("{keyword}", $noqkeyword, $content);
                $content = str_replace("{Keyword}", ucwords($noqkeyword), $content);
                if (function_exists("wpr_translate_partial")) {
                    $content = wpr_translate_partial($content);
                }
                if (function_exists("wpr_rewrite_partial")) {
                    $content = wpr_rewrite_partial($content, $options);
                }
                $itemcontent[$x]["unique"] = $news->id;
                $itemcontent[$x]["title"] = $title;
                $itemcontent[$x]["content"] = $content;
                $x++;
            }
            if (empty($itemcontent)) {
                // Return error if no content has been found.
                $itemcontent["error"]["module"] = "Twitter";
                $itemcontent["error"]["reason"] = "No content";
                $itemcontent["error"]["message"] = __("No (more) Twitter items found.", "wprobot");
                return $itemcontent;
            } else {
                return $itemcontent;
            }
        } else {
            if (isset($pxml->Message)) {
                // Check for API error messages in results and if found return them.
                $message = __('There was a problem with your API request. This is the error returned:', "wprobot") . ' <b>' . $pxml->Message . '</b>';
                $itemcontent["error"]["module"] = "Twitter";
                $itemcontent["error"]["reason"] = "API fail";
                $itemcontent["error"]["message"] = $message;
                return $itemcontent;
            } else {
                // Return error if no content has been found.
                $itemcontent["error"]["module"] = "Twitter";
                $itemcontent["error"]["reason"] = "No content";
                $itemcontent["error"]["message"] = __("No (more) Twitter items found.", "wprobot");
                return $itemcontent;
            }
        }
    }
}
Example #3
0
function wpr_yahooanswerspost($keyword,$num,$start,$yapcat,$getcomments) {
	global $wpdb,$wpr_table_templates;
	
	if($keyword == "") {
		$return["error"]["module"] = "Yahoo Answers";
		$return["error"]["reason"] = "No keyword";
		$return["error"]["message"] = __("No keyword specified.","wprobot");
		return $return;	
	}	
	
	$options = unserialize(get_option("wpr_options"));	
	$template = $wpdb->get_var("SELECT content FROM " . $wpr_table_templates . " WHERE type = 'yahooanswers'");	
	if($template == false || empty($template)) {
		$return["error"]["module"] = "Yahoo Answers";
		$return["error"]["reason"] = "No template";
		$return["error"]["message"] = __("Module Template does not exist or could not be loaded.","wprobot");
		return $return;	
	}	
	$pxml = wpr_yahooanswersrequest($keyword,$num,$start,$yapcat);
	if(!empty($pxml["error"])) {return $pxml;}
	$x = 0;
	$posts = array();
	
	if ($pxml === False) {
		$posts["error"]["module"] = "Yahooanswers";
		$posts["error"]["reason"] = "Request fail";
		$posts["error"]["message"] = __("API request could not be sent.","wprobot");	
		return $posts;		
	} else {
		if (isset($pxml->Question)) {
			foreach($pxml->Question as $question) {
			
				$attrs = $question->attributes();
				$qid = $question['id']; 			
				$title = $question->Subject;
				$content = $question->Content;
				$url = $question->Link;
				$user = $question->UserNick;
				$answercount = $question->NumAnswers;
				
				if ($options['wpr_ya_striplinks_q']=='yes') {$content = wpr_strip_selected_tags($content, array('a','iframe','script'));}
				
				$post = $template;				
				$post = wpr_random_tags($post);
				
				// Answers
				$answerpost = "";
				preg_match('#\{answers(.*)\}#iU', $post, $rmatches);			
				if ($rmatches[0] != false || $getcomments == 1) {
					$answers = wpr_yap_getanswers($qid,$answercount);				
				}
				if ($rmatches[0] != false && !empty($answers)) {
					$answernum = substr($rmatches[1], 1);
					for ($i = 0; $i < $answercount; $i++) {
						if($i == $answernum) {break;} else {	
							$answerpost .= "<p><i>Answer by ".$answers[$i]["author"]."</i><br/>".$answers[$i]["content"]."</p>";
							// Remove posted answer from comments array
							unset($answers[$i]);
						}
					}
					$answers = array_values($answers);
					$post = str_replace($rmatches[0], $answerpost, $post);				
				} else {
					$post = str_replace($rmatches[0], "", $post);					
				}				
				
				$content = str_replace("$", "$ ", $content); 
				$post = str_replace("{question}", $content, $post);							
				$noqkeyword = str_replace('"', '', $keyword);
				$post = str_replace("{keyword}", $noqkeyword, $post);
				$post = str_replace("{Keyword}", ucwords($noqkeyword), $post);					
				$post = str_replace("{url}", $url, $post);	
				$post = str_replace("{user}", $user, $post);	
				$post = str_replace("{title}", $title, $post);	
					if(function_exists("wpr_translate_partial")) {
						$post = wpr_translate_partial($post);
					}
					
				$posts[$x]["unique"] = $qid;
				$posts[$x]["title"] = $title;
				$posts[$x]["content"] = $post;	
				$posts[$x]["comments"] = $answers;	
				$x++;
			}
			
			if(empty($posts)) {
				$posts["error"]["module"] = "Yahooanswers";
				$posts["error"]["reason"] = "No content";
				$posts["error"]["message"] = __("No (more) Yahoo Answers content found.","wprobot");	
				return $posts;			
			} else {
				return $posts;	
			}				
			
		} else {
			if (isset($pxml->Message)) {
				$message = __('There was a problem with your API request. This is the error Yahoo returned:',"wprobot").' <b>'.$pxml->Message.'</b>';	
				$posts["error"]["module"] = "Yahooanswers";
				$posts["error"]["reason"] = "API fail";
				$posts["error"]["message"] = $message;	
				return $posts;				
			} else {
				$posts["error"]["module"] = "Yahooanswers";
				$posts["error"]["reason"] = "No content";
				$posts["error"]["message"] = __("No (more) Yahoo Answers content found.","wprobot");	
				return $posts;						
			}			
		}
	}	
}
Example #4
0
function wpr_commissionjunctionpost($keyword, $num, $start, $optional = "", $comments = "")
{
    global $wpdb, $wpr_table_templates;
    $buyUrl = "buy-url";
    $imageUrl = "image-url";
    $rPrice = "retail-price";
    $sPrice = "sale-price";
    $advertiserName = "advertiser-name";
    $inStock = "in-stock";
    $errormessage = "error-message";
    if ($keyword == "") {
        // If keyword is empty return error
        $return["error"]["module"] = "Commission Junction";
        $return["error"]["reason"] = "No keyword";
        $return["error"]["message"] = __("No keyword specified.", "wprobot");
        return $return;
    }
    $template = $wpdb->get_var("SELECT content FROM " . $wpr_table_templates . " WHERE type = 'commissionjunction'");
    if ($template == false || empty($template)) {
        // If module template is empty return error
        $return["error"]["module"] = "Commission Junction";
        $return["error"]["reason"] = "No template";
        $return["error"]["message"] = __("Module Template does not exist or could not be loaded.", "wprobot");
        return $return;
    }
    $x = 0;
    $itemcontent = array();
    $pxml = wpr_commissionjunctionrequest($keyword, $num, $start);
    // Send API request
    //print_r($pxml);
    if (!empty($pxml["error"])) {
        return $pxml;
    }
    if ($pxml === False) {
        $itemcontent["error"]["module"] = "Commission Junction";
        $itemcontent["error"]["reason"] = "Request fail";
        $itemcontent["error"]["message"] = __("API request could not be sent.", "wprobot");
        return $itemcontent;
    } else {
        if (isset($pxml->products->product)) {
            foreach ($pxml->products->product as $item) {
                $title = $item->name;
                $summary = $item->description;
                $url = $item->{$buyUrl};
                $price = number_format($item->price, 2, '.', '');
                $currency = $item->currency;
                $listprice = $item->{$rPrice};
                if ($listprice == "0.0") {
                    $listprice = "";
                }
                $saleprice = $item->{$sPrice};
                if ($saleprice == "0.0") {
                    $saleprice = "";
                }
                $img = $item->{$imageUrl};
                $advert = $item->{$advertiserName};
                $isinstock = $item->{$inStock};
                $skipit = 0;
                $skip = $options["wpr_commissionjunction_skip"];
                if ($skip == "noimg" || $skip == "nox") {
                    if (empty($img)) {
                        $skipit = 1;
                    }
                }
                if ($skip == "nodesc" || $skip == "nox") {
                    if (empty($summary)) {
                        $skipit = 1;
                    }
                }
                if (!empty($img)) {
                    $thumbnail = '<a alt="' . $title . '" href="' . $url . '" rel="nofollow"><img style="float:left;width:150px;margin: 0 20px 10px 0;" src="' . $img . '" /></a>';
                } else {
                    $thumbnail = '';
                }
                if ($skipit == 0) {
                    $content = $template;
                    $content = wpr_random_tags($content);
                    $content = str_replace("{thumbnail}", $thumbnail, $content);
                    $content = str_replace("{imageurl}", $img, $content);
                    $content = str_replace("{title}", $title, $content);
                    $content = str_replace("{description}", $summary, $content);
                    $content = str_replace("{price}", $price, $content);
                    $content = str_replace("{currency}", $currency, $content);
                    $content = str_replace("{saleprice}", $saleprice, $content);
                    $content = str_replace("{listprice}", $listprice, $content);
                    $content = str_replace("{url}", $url, $content);
                    $noqkeyword = str_replace('"', '', $keyword);
                    $content = str_replace("{keyword}", $noqkeyword, $content);
                    $content = str_replace("{Keyword}", ucwords($noqkeyword), $content);
                    $content = str_replace("{advertiser}", $advert, $content);
                    $content = str_replace("{instock}", $isinstock, $content);
                    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->upc) && $item->upc != "") {
                        $unique = $item->upc;
                    } elseif (!empty($item->sku)) {
                        $unique = $item->sku;
                    } elseif (!empty($item->isbn)) {
                        $unique = $item->isbn;
                    }
                    $customfield = array();
                    $customfield["cjtitle"] = $title;
                    $customfield["cjthumbnail"] = $img;
                    $customfield["cjprice"] = $saleprice;
                    $customfield["cjlink"] = $url;
                    $customfield["cjadvertiser"] = $advert;
                    $itemcontent[$x]["unique"] = $unique;
                    $itemcontent[$x]["title"] = $title;
                    $itemcontent[$x]["content"] = $content;
                    $itemcontent[$x]["customfield"] = $customfield;
                    //print_r($itemcontent);
                }
                $x++;
            }
            if (empty($itemcontent)) {
                // Return error if no content has been found.
                $itemcontent["error"]["module"] = "Commission Junction";
                $itemcontent["error"]["reason"] = "No content";
                $itemcontent["error"]["message"] = __("No (more) CJ products found.", "wprobot");
                return $itemcontent;
            } else {
                return $itemcontent;
            }
        } else {
            if (isset($pxml->{$errormessage})) {
                // Check for API error messages in results and if found return them.
                $message = __('There was a problem with your API request. This is the error returned:', "wprobot") . ' <b>' . $pxml->{$errormessage} . '</b>';
                $itemcontent["error"]["module"] = "Commission Junction";
                $itemcontent["error"]["reason"] = "API fail";
                $itemcontent["error"]["message"] = $message;
                return $itemcontent;
            } else {
                // Return error if no content has been found.
                $itemcontent["error"]["module"] = "Commission Junction";
                $itemcontent["error"]["reason"] = "No content";
                $itemcontent["error"]["message"] = __("No (more) CJ products found.", "wprobot");
                return $itemcontent;
            }
        }
    }
}
Example #5
0
function wpr_yahoonewspost($keyword, $num, $start, $optional = "", $comments = "")
{
    global $wpdb, $wpr_table_templates;
    if ($keyword == "") {
        $return["error"]["module"] = "Yahoo News";
        $return["error"]["reason"] = "No keyword";
        $return["error"]["message"] = __("No keyword specified.", "wprobot");
        return $return;
    }
    $template = $wpdb->get_var("SELECT content FROM " . $wpr_table_templates . " WHERE type = 'yahoonews'");
    if ($template == false || empty($template)) {
        $return["error"]["module"] = "Yahoo News";
        $return["error"]["reason"] = "No template";
        $return["error"]["message"] = __("Module Template does not exist or could not be loaded.", "wprobot");
        return $return;
    }
    $x = 0;
    $newscontent = array();
    $pxml = wpr_yahoonewsrequest($keyword, $num, $start);
    if (!empty($pxml["error"])) {
        return $pxml;
    }
    if ($pxml === False) {
        $newscontent["error"]["module"] = "Yahoonews";
        $newscontent["error"]["reason"] = "Request fail";
        $newscontent["error"]["message"] = __("API request could not be sent.", "wprobot");
        return $newscontent;
    } else {
        if (isset($pxml->results->results)) {
            foreach ($pxml->results->results as $news) {
                // abstract, title, date, clickurl, source, language, ...
                $title = $news->title;
                $summary = $news->content;
                $url = $news->unescapedUrl;
                $source = $news->publisher;
                $sourceurl = $news->sourceurl;
                $language = $news->language;
                $date = $news->publishedDate;
                $thumb = $news->image->url;
                $source = "Read more on <a rel=\"nofollow\" href=\"{$url}\">{$source}</a><br/><br/>";
                if ($thumb != "") {
                    $thumbnail = '<a href="' . $url . '" rel="nofollow"><img style="width:150px;float:left;margin: 0 20px 10px 0;" src="' . $thumb . '" /></a>';
                } else {
                    $thumbnail = '';
                }
                $content = $template;
                $content = wpr_random_tags($content);
                $content = str_replace("{thumbnail}", $thumbnail, $content);
                $content = str_replace("{title}", $title, $content);
                $summary = strip_tags($summary);
                $summary = str_replace("\$", "\$ ", $summary);
                $content = str_replace("{summary}", $summary, $content);
                $content = str_replace("{source}", $source, $content);
                $content = str_replace("{url}", $url, $content);
                $content = str_replace("{date}", $date, $content);
                $content = str_replace("{sourceurl}", $sourceurl, $content);
                $content = str_replace("{language}", $language, $content);
                $noqkeyword = str_replace('"', '', $keyword);
                $content = str_replace("{keyword}", $noqkeyword, $content);
                $content = str_replace("{Keyword}", ucwords($noqkeyword), $content);
                if (function_exists("wpr_translate_partial")) {
                    $content = wpr_translate_partial($content);
                }
                if (function_exists("wpr_rewrite_partial")) {
                    $content = wpr_rewrite_partial($content, $options);
                }
                $newscontent[$x]["unique"] = $url;
                $newscontent[$x]["title"] = $title;
                $newscontent[$x]["content"] = $content;
                $x++;
            }
            if (isset($pxml->description)) {
                $message = __('There was a problem with your API request. This is the error Yahoo returned:', "wprobot") . ' <b>' . $pxml->description . '</b>';
                $newscontent["error"]["module"] = "Yahoonews";
                $newscontent["error"]["reason"] = "API fail";
                $newscontent["error"]["message"] = $message;
                return $newscontent;
            } elseif (empty($newscontent)) {
                $newscontent["error"]["module"] = "Yahoonews";
                $newscontent["error"]["reason"] = "No content";
                $newscontent["error"]["message"] = __("No (more) Yahoo news items found.", "wprobot");
                return $newscontent;
            } else {
                return $newscontent;
            }
        } else {
            if (isset($pxml->description)) {
                $message = __('There was a problem with your API request. This is the error Yahoo returned:', "wprobot") . ' <b>' . $pxml->description . '</b>';
                $newscontent["error"]["module"] = "Yahoonews";
                $newscontent["error"]["reason"] = "API fail";
                $newscontent["error"]["message"] = $message;
                return $newscontent;
            } else {
                $newscontent["error"]["module"] = "Yahoonews";
                $newscontent["error"]["reason"] = "No content";
                $newscontent["error"]["message"] = __("No (more) Yahoo news items found.", "wprobot");
                return $newscontent;
            }
        }
    }
}
Example #6
0
function wpr_plrpost($keyword, $num, $start, $optional = "", $comments = "")
{
    global $wpdb, $wpr_table_templates, $wpr_cache;
    /*if($keyword == "") {
    		$return["error"]["module"] = "Yahoo News";
    		$return["error"]["reason"] = "No keyword";
    		$return["error"]["message"] = __("No keyword specified.","wprobot");
    		return $return;	
    	}
    	*/
    $options = unserialize(get_option("wpr_options"));
    $template = $wpdb->get_var("SELECT content FROM " . $wpr_table_templates . " WHERE type = 'plr'");
    if ($template == false || empty($template)) {
        $template = "{article}";
    }
    $wpr_saveurl = WPR_URLPATH . "plr";
    $folder = $wpr_cache . "/";
    $plrcontent = array();
    for ($i = 0; $i < $num; $i++) {
        $filename = wpr_plr_randomfile($folder, 'txt|pdf');
        //echo $filename . "<br>";
        $output = "";
        $title = "";
        $file = fopen($filename, "r");
        if (empty($file) || $file == false) {
            $plrcontent["error"]["module"] = "PLR";
            $plrcontent["error"]["reason"] = "No content";
            $plrcontent["error"]["message"] = __("No (more) PLR items found.", "wprobot");
            return $plrcontent;
        }
        while (!feof($file)) {
            if (empty($title)) {
                $title = fgets($file, 4096);
            }
            $output = $output . fgets($file, 4096);
            //read file line by line into variable
        }
        fclose($file);
        //$output = utf8_encode($output);
        if (function_exists('iconv')) {
            $output = iconv('UTF-8', 'ISO-8859-1//IGNORE', $output);
        }
        //echo $title . "<br>";
        //echo $output . "<br>";
        if (!empty($output) && !empty($title)) {
            // Keyword filter
            $kw = $keyword;
            if ($kw != "" && $options['wpr_plr_filter'] == 'yes') {
                $kw = str_replace('"', '', $kw);
                $kws = explode(" AND ", $kw);
                //print_r($kws);
                foreach ($kws as $kwx) {
                    $kw2 = " " . $kwx . " ";
                    //echo $kw2."<br>";
                    $c1 = stripos($output, $kw2);
                    $c2 = stripos($title, $kw2);
                    if ($c1 != false || $c2 != false) {
                        //echo "keyword was found<br>";
                        $abort = 0;
                    } else {
                        //echo "keyword was not found<br>";
                        $plrcontent["error"]["module"] = "PLR";
                        $plrcontent["error"]["reason"] = "IncNum";
                        $plrcontent["error"]["message"] = __("File skipped because filter keyword was not found.", "wprobot");
                        return $plrcontent;
                    }
                }
            }
            $content = $template;
            $content = wpr_random_tags($content);
            $content = str_replace("{article}", $output, $content);
            $content = str_replace("{title}", $title, $content);
            $noqkeyword = str_replace('"', '', $keyword);
            $content = str_replace("{keyword}", $noqkeyword, $content);
            $content = str_replace("{Keyword}", ucwords($noqkeyword), $content);
            if (function_exists("wpr_translate_partial")) {
                $content = wpr_translate_partial($content);
            }
            if (function_exists("wpr_rewrite_partial")) {
                $content = wpr_rewrite_partial($content, $options);
            }
            $ren = rename($filename, $filename . "2");
            if ($ren == true) {
            } else {
            }
            $plrcontent[$i]["unique"] = rand(1, 10000);
            $plrcontent[$i]["title"] = $title;
            $plrcontent[$i]["content"] = $content;
        }
    }
    if (empty($plrcontent)) {
        $plrcontent["error"]["module"] = "PLR";
        $plrcontent["error"]["reason"] = "No content";
        $plrcontent["error"]["message"] = __("No (more) PLR items found.", "wprobot");
        return $plrcontent;
    } else {
        return $plrcontent;
    }
}
Example #7
0
function wpr_youtubepost($keyword, $num, $start, $optional = "", $getcomments)
{
    global $wpdb, $wpr_table_templates;
    if ($keyword == "") {
        $return["error"]["module"] = "Youtube";
        $return["error"]["reason"] = "No keyword";
        $return["error"]["message"] = __("No keyword specified.", "wprobot");
        return $return;
    }
    $template = $wpdb->get_var("SELECT content FROM " . $wpr_table_templates . " WHERE type = 'youtube'");
    if ($template == false || empty($template)) {
        $return["error"]["module"] = "Youtube";
        $return["error"]["reason"] = "No template";
        $return["error"]["message"] = __("Module Template does not exist or could not be loaded.", "wprobot");
        return $return;
    }
    $options = unserialize(get_option("wpr_options"));
    $pxml = wpr_youtuberequest($keyword, $num, $start);
    if (!empty($pxml["error"])) {
        return $pxml;
    }
    $videos = array();
    $x = 0;
    if ($pxml === False) {
        $videos["error"]["module"] = "Youtube";
        $videos["error"]["reason"] = "API fail";
        $videos["error"]["message"] = __("Youtube API request did not work.", "wprobot");
        return $videos;
    } else {
        if (isset($pxml->entry)) {
            foreach ($pxml->entry as $entry) {
                $media = $entry->children('http://search.yahoo.com/mrss/');
                $title = $media->group->title;
                $description = $media->group->description;
                $attrs = $media->group->thumbnail[0]->attributes();
                $thumbnail = '<img alt="' . $title . '" src="' . $attrs['url'] . '" />';
                $thumbnailurl = $attrs['url'];
                //$yt = $entry->children('http://gdata.youtube.com/schemas/2007');
                //$attrs = $yt->statistics->attributes();
                //$viewCount = $attrs['viewCount'];
                $yt = $media->children('http://gdata.youtube.com/schemas/2007');
                $videoid = $yt->videoid;
                $gd = $entry->children('http://schemas.google.com/g/2005');
                if ($gd->rating) {
                    $attrs = $gd->rating->attributes();
                    $rating = round($attrs['average'], 2);
                } else {
                    $rating = 0;
                }
                $attrs = $media->group->player->attributes();
                $playerUrl = $attrs['url'];
                $gd = $entry->children('http://schemas.google.com/g/2005');
                if ($gd->comments->feedLink) {
                    $attrs = $gd->comments->feedLink->attributes();
                    $commentsUrl = $attrs['href'];
                    $commentsCount = $attrs['countHint'];
                }
                if (empty($options['wpr_yt_width'])) {
                    $options['wpr_yt_width'] = "425";
                }
                if (empty($options['wpr_yt_height'])) {
                    $options['wpr_yt_height'] = "355";
                }
                // 425 // 355
                $video = '
				<object width="' . $options['wpr_yt_width'] . '" height="' . $options['wpr_yt_height'] . '">
				<param name="movie" value="http://www.youtube.com/v/' . $videoid . '?fs=1"></param>
				<param name="allowFullScreen" value="true"></param>
				<embed src="http://www.youtube.com/v/' . $videoid . '?fs=1&rel=0" type="application/x-shockwave-flash" width="' . $options['wpr_yt_width'] . '" height="' . $options['wpr_yt_height'] . '" allowfullscreen="true"></embed>
				</object>';
                //$video ='<object type="application/x-shockwave-flash" style="width:'.$options['wpr_yt_width'].'px;height:'.$options['wpr_yt_height'].'px;" data="http://www.youtube.com/v/'.$videoid.'">
                //<param name="movie" value="http://www.youtube.com/v/'.$videoid.'" />
                //</object>';
                if ($options['wpr_yt_striplinks_desc'] == 'yes') {
                    $description = wpr_strip_selected_tags($description, array('a', 'iframe', 'script'));
                }
                $vid = $template;
                $vid = wpr_random_tags($vid);
                // Comments
                $commentspost = "";
                preg_match('#\\{comments(.*)\\}#iU', $vid, $rmatches);
                if ($rmatches[0] != false || $getcomments == 1) {
                    $comments = wpr_yt_getcomments($commentsUrl, $commentsCount);
                }
                if ($rmatches[0] != false && !empty($comments)) {
                    $cnum = substr($rmatches[1], 1);
                    for ($i = 0; $i < $commentsCount; $i++) {
                        if ($i == $cnum) {
                            break;
                        } else {
                            $commentspost .= "<p><b>Comment by " . $comments[$i]["author"] . "</b><br/>" . $comments[$i]["content"] . "</p>";
                        }
                    }
                    $vid = str_replace($rmatches[0], $commentspost, $vid);
                }
                $vid = str_replace("{description}", $description, $vid);
                $vid = str_replace("{thumbnail}", $thumbnail, $vid);
                //$vid = str_replace("{viewcount}", $viewCount, $vid);
                $vid = str_replace("{rating}", $rating, $vid);
                $noqkeyword = str_replace('"', '', $keyword);
                $vid = str_replace("{keyword}", $noqkeyword, $vid);
                $vid = str_replace("{Keyword}", ucwords($noqkeyword), $vid);
                $vid = str_replace("{video}", $video, $vid);
                $vid = str_replace("{title}", $title, $vid);
                $vid = str_replace("{url}", "http://www.youtube.com/watch?v=" . $videoid, $vid);
                if (function_exists("wpr_translate_partial")) {
                    $vid = wpr_translate_partial($vid);
                }
                if (function_exists("wpr_rewrite_partial")) {
                    $vid = wpr_rewrite_partial($vid, $options);
                }
                $customfield = array();
                $customfield["youtubetitle"] = $title;
                $customfield["video"] = $videoid;
                $customfield["youtubethumbnail"] = $thumbnailurl;
                $customfield["youtuberating"] = $rating;
                $videos[$x]["unique"] = $videoid;
                $videos[$x]["title"] = $title;
                $videos[$x]["content"] = $vid;
                $videos[$x]["comments"] = $comments;
                $videos[$x]["customfield"] = $customfield;
                $x++;
            }
            if (empty($videos)) {
                $videos["error"]["module"] = "Youtube";
                $videos["error"]["reason"] = "No content";
                $videos["error"]["message"] = __("No (more) Youtube videos found.", "wprobot");
                return $videos;
            } else {
                return $videos;
            }
        } else {
            $videos["error"]["module"] = "Youtube";
            $videos["error"]["reason"] = "No content";
            $videos["error"]["message"] = __("No (more) Youtube videos found.", "wprobot");
            return $videos;
        }
    }
}
Example #8
0
function wpr_clickbankpost($keyword, $num, $start, $optional = "", $comments = "")
{
    global $wpdb, $wpr_table_templates;
    if ($keyword == "") {
        $return["error"]["module"] = "Clickbank";
        $return["error"]["reason"] = "No keyword";
        $return["error"]["message"] = __("No keyword specified.", "wprobot");
        return $return;
    }
    $template = $wpdb->get_var("SELECT content FROM " . $wpr_table_templates . " WHERE type = 'clickbank'");
    if ($template == false || empty($template)) {
        $return["error"]["module"] = "Clickbank";
        $return["error"]["reason"] = "No template";
        $return["error"]["message"] = __("Module Template does not exist or could not be loaded.", "wprobot");
        return $return;
    }
    $options = unserialize(get_option("wpr_options"));
    $affid = $options['wpr_cb_affkey'];
    if ($affid == '') {
        $affid = 'lun4tic';
    }
    $keyword = str_replace('"', "", $keyword);
    $keyword = str_replace(" ", "+", $keyword);
    $page = $start / 50;
    $page = (string) $page;
    $page = explode(".", $page);
    $page = (int) $page[0];
    $page++;
    if ($page == 0 || empty($page)) {
        $page = 1;
    }
    $prep = floor($start / 50);
    $numb = $start - $prep * 50;
    $search_url = "http://www.clickbank.com/mkplSearchResult.htm?dores=true&includeKeywords={$keyword}&firstResult={$start}";
    $search_url = "http://www.cbengine.com/res/search.cfm?search=1&op=AND&field=any&ap=0&ao=Or&am=0&sc=rank&so=asc&mode=engine&custom1=mntm&kw={$keyword}&pg={$page}";
    $wpr_cb_cat = $options['wpr_cb_cat'];
    if (!empty($wpr_cb_cat)) {
        $search_url .= "&cat=" . $wpr_cb_cat . ".all";
    }
    $posts = array();
    // make the cURL request to $search_url
    if (function_exists('curl_init')) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_USERAGENT, 'Firefox (WindowsXP) - Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6');
        curl_setopt($ch, CURLOPT_URL, $search_url);
        curl_setopt($ch, CURLOPT_FAILONERROR, true);
        curl_setopt($ch, CURLOPT_AUTOREFERER, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, 45);
        $html = curl_exec($ch);
        if (!$html) {
            $return["error"]["module"] = "Clickbank";
            $return["error"]["reason"] = "cURL Error";
            $return["error"]["message"] = __("cURL Error Number ", "wprobot") . curl_errno($ch) . ": " . curl_error($ch);
            return $return;
        }
        curl_close($ch);
    } else {
        $html = @file_get_contents($search_url);
        if (!$html) {
            $return["error"]["module"] = "Clickbank";
            $return["error"]["reason"] = "cURL Error";
            $return["error"]["message"] = __("cURL is not installed on this server!", "wprobot");
            return $return;
        }
    }
    // parse the html into a DOMDocument
    $dom = new DOMDocument();
    @$dom->loadHTML($html);
    $xpath1 = new DOMXPath($dom);
    $paras1 = $xpath1->query("//a[@class='a18 dblue']");
    $end = $numb + $num;
    $x = 0;
    if ($paras1->length == 0) {
        $posts["error"]["module"] = "Clickbank";
        $posts["error"]["reason"] = "No content";
        $posts["error"]["message"] = __("No (more) Clickbank products found.", "wprobot");
        return $posts;
    }
    if ($end > $paras1->length) {
        $end = $paras1->length;
    }
    for ($i = $numb; $i < $end; $i++) {
        //for ($i = $numb;  $i < $paras1->length; $i++ ) {		//$paras->length
        /*if($i < $num) {
        			$para1 = $paras1->item($i);
        			$urlt = $para1->textContent;	
        
        			if($urlt == '' | $urlt == null) {
        				$posts["error"]["module"] = "Clickbank";
        				$posts["error"]["reason"] = "No content";
        				$posts["error"]["message"] = __("No (more) Clickbank products found.","wprobot");	
        				return $posts;	
        			} else {*/
        $xpath2 = new DOMXPath($dom);
        $paras2 = $xpath2->query("//span[@class='v13']");
        $para2 = $paras2->item($i);
        $description = $para2->textContent;
        $xpath3 = new DOMXPath($dom);
        $paras3 = $xpath3->query("//a[@class='a18 dblue']");
        $para3 = $paras3->item($i);
        $title = $para3->textContent;
        $url = $para3->getAttribute('href');
        $url = explode("/id/", $url);
        $url = "http://" . $affid . "." . $url[1] . ".hop.clickbank.net";
        $xpath4 = new DOMXPath($dom);
        $paras4 = $xpath4->query("//div[@class='screenshot']/a/img");
        $para4 = $paras4->item($i);
        $thumbnail = $para4->getAttribute('src');
        $link = '<a rel="nofollow" href="' . $url . '">' . $title . '</a>';
        $image = '<a href="' . $url . '" rel="nofollow"><img style="float:left;margin: 0 20px 10px 0;" src="' . $thumbnail . '" alt="' . $title . '" /></a>';
        $ff = $options['wpr_cb_filter'];
        $stop = 0;
        if ($ff == "yes") {
            $pos = strpos($description, "Commission");
            if ($pos !== false) {
                $stop = 1;
            }
            $pos = strpos($description, "commission");
            if ($pos !== false) {
                $stop = 1;
            }
            $pos = strpos($description, "affiliate");
            if ($pos !== false) {
                $stop = 1;
            }
            $pos = strpos($description, "Affiliate");
            if ($pos !== false) {
                $stop = 1;
            }
            $pos = strpos($description, "affiliates");
            if ($pos !== false) {
                $stop = 1;
            }
        }
        if ($stop == 0) {
            $post = $template;
            $post = wpr_random_tags($post);
            $post = str_replace("{thumbnail}", $image, $post);
            $post = str_replace("{imageurl}", $thumbnail, $post);
            $post = str_replace("{link}", $link, $post);
            $post = str_replace("{description}", $description, $post);
            $post = str_replace("{url}", $url, $post);
            $noqkeyword = str_replace('"', '', $keyword);
            $post = str_replace("{keyword}", $noqkeyword, $post);
            $post = str_replace("{Keyword}", ucwords($noqkeyword), $post);
            $post = str_replace("{title}", $title, $post);
            if (function_exists("wpr_translate_partial")) {
                $post = wpr_translate_partial($post);
            }
            if (function_exists("wpr_rewrite_partial")) {
                $post = wpr_rewrite_partial($post, $options);
            }
            $posts[$x]["unique"] = $title;
            $posts[$x]["title"] = $title;
            $posts[$x]["content"] = $post;
            $x++;
        }
        //}
        //}
    }
    if (empty($posts)) {
        $posts["error"]["module"] = "Clickbank";
        $posts["error"]["reason"] = "No content";
        $posts["error"]["message"] = __("No (more) Clickbank ads found.", "wprobot");
        return $posts;
    } else {
        return $posts;
    }
}
Example #9
0
function wpr_flickrpost($keyword,$num,$start,$optional="",$getcomments) {
	global $wpdb,$wpr_table_templates;
	
	if($keyword == "") {
		$return["error"]["module"] = "Flickr";
		$return["error"]["reason"] = "No keyword";
		$return["error"]["message"] = __("No keyword specified.","wprobot");
		return $return;	
	}	
	
	$options = unserialize(get_option("wpr_options"));	
	$width = $options["wpr_fl_width"];
	$apikey = trim($options["wpr_fl_apikey"]);		
	$cont = $options["wpr_fl_content"];
	$sort = $options["wpr_fl_sort"];
	$license = $options["wpr_fl_license"];
	
	$template = $wpdb->get_var("SELECT content FROM " . $wpr_table_templates . " WHERE type = 'flickr' AND name = 'standard'");
	if($template == false || empty($template)) {
		$return["error"]["module"] = "Flickr";
		$return["error"]["reason"] = "No template";
		$return["error"]["message"] = __("Module Template does not exist or could not be loaded.","wprobot");
		return $return;	
	}				
	$pxml = wpr_flickrrequest($keyword,$apikey,$cont,$sort,$license,$start,$num);
	if(!empty($pxml["error"])) {return $pxml;}
		//echo "<br/>---FLICKR---<br/>";print_r($pxml);echo "<br/>---FLICKR---<br/>";
	$end = $start + $num;
	//$i = 0;
	$x = 0;			
	$photos = array();
	
	if ($pxml === False) {
		$photos["error"]["module"] = "Flickr";
		$photos["error"]["reason"] = "API fail";
		$photos["error"]["message"] = __("Flickr API request did not work.","wprobot");	
		return $photos;	
	} else {
		if (isset($pxml->err)) {
			$message = '<p>'.__("There was a problem with your Flickr API request. This is the error Flickr returned:","wprobot").'</p>
			<p><i><b>'.$pxml->err['code'].':</b> '.$pxml->err['msg'].'</i></p>';	
			$photos["error"]["module"] = "Flickr";
			$photos["error"]["reason"] = "API fail";
			$photos["error"]["message"] = $message;	
			return $photos;			
		}
		if (isset($pxml->photos->photo)) {	
			foreach($pxml->photos->photo as $photo) {
				//if($i >= $start && $i <= $end) { // PROBLEM HERE ???!!!

					$title = $photo['title'];
					$date = $photo['datetaken'];	
					$owner = $photo['ownername'];
					$urlt = $photo['url_t'];
					$urls = $photo['url_s'];
					$urlm = $photo['url_m'];
					$urlo = $photo['url_o'];
					//$description = $photo['description'];	
					$description = $photo->description;	
					$ownerid = $photo['owner'];
					$photoid = $photo['id'];					
				
					if($options["wpr_fl_size"] == "small") {
						$img = '<img alt="'.$keyword.'" src="'.$urls.'" width="'.$width.'"/><br/>';
					} elseif($options["wpr_fl_size"] == "med") {
						$img = '<img alt="'.$keyword.'" src="'.$urlm.'" width="'.$width.'"/><br/>';
					} else {
						$img = '<img alt="'.$keyword.'" src="'.$urlo.'" width="'.$width.'"/><br/>';
					}
					
					$link = 'http://www.flickr.com/photos/'.$ownerid.'/'.$photoid;				
				
					$photo = $template;
					$photo = wpr_random_tags($photo);
					
					// Comments
					$commentspost = "";
					preg_match('#\{comments(.*)\}#iU', $photo, $rmatches);
					if ($rmatches[0] != false || $getcomments == 1) {	
						$comments = wpr_fl_getcomments($photoid,$apikey);				
					}
					if ($rmatches[0] != false && !empty($comments)) {
						$cnum = substr($rmatches[1], 1);
						for ($i = 0; $i < count($comments); $i++) {
							if($i == $cnum) {break;} else {	
								$commentspost .= "<p><b>Comment by ".$comments[$i]["author"]."</b><br/>".$comments[$i]["content"]."</p>";
							}
						}
						$photo = str_replace($rmatches[0], $commentspost, $photo);				
					}						
					
					$photo = str_replace("{image}", $img, $photo);	
					$photo = str_replace("{date}", $date, $photo);
					$photo = str_replace("{owner}", $owner, $photo);
					$photo = str_replace("{url}", $link, $photo);
					$photo = str_replace("{keyword}", $keyword, $photo);
					$photo = str_replace("{description}", $description, $photo);	
					$photo = str_replace("{title}", $title, $photo);	
					if(function_exists("wpr_translate_partial")) {
						$photo = wpr_translate_partial($photo);
					}
					
					$customfield = array();
					$customfield["flickrtitle"] = $title;
					$customfield["flickrimage"] = $urlm;
					$customfield["flickrowner"] = $owner;			
					
					$photos[$x]["unique"] = $photoid;
					$photos[$x]["title"] = $title;
					$photos[$x]["content"] = $photo;	
					$photos[$x]["comments"] = $comments;
					$photos[$x]["customfield"] = $customfield;
					$x++;
				//}
				//$i++;
			}
			if(empty($photos)) {
				$photos["error"]["module"] = "Flickr";
				$photos["error"]["reason"] = "No content";
				$photos["error"]["message"] = __("No (more) Flickr images found.","wprobot");	
				return $photos;	
			} else {
				return $photos;	
			}
		} else {
			$photos["error"]["module"] = "Flickr";
			$photos["error"]["reason"] = "No content";
			$photos["error"]["message"] = __("No (more) Flickr images found.","wprobot");	
			return $photos;	
		}
	}	
}
Example #10
0
function wpr_shareasalepost($keyword, $num, $start, $optional = "", $comments = "")
{
    global $wpdb, $wpr_table_templates;
    $options = unserialize(get_option("wpr_options"));
    // Load WP Robot Options Array
    $affid = $options['wpr_shareasale_aff'];
    // If necessary retreive the API key from the options...
    if (empty($affid)) {
        $affid = "435192";
    }
    if ($keyword == "") {
        // If keyword is empty return error
        $return["error"]["module"] = "Shareasale";
        $return["error"]["reason"] = "No keyword";
        $return["error"]["message"] = __("No keyword specified.", "wprobot");
        return $return;
    }
    $template = $wpdb->get_var("SELECT content FROM " . $wpr_table_templates . " WHERE type = 'shareasale'");
    if ($template == false || empty($template)) {
        // If module template is empty return error
        $return["error"]["module"] = "Shareasale";
        $return["error"]["reason"] = "No template";
        $return["error"]["message"] = __("Module Template does not exist or could not be loaded.", "wprobot");
        return $return;
    }
    $x = 0;
    $itemcontent = array();
    if (empty($start)) {
        $start = 1;
    }
    if (empty($num)) {
        $num = 1;
    }
    $total = $num + $start;
    if (($handle = fopen(WPR_URLPATH . "datafeed.csv", "r")) !== FALSE) {
        for ($i = 1; $i < $total; $i++) {
            if ($i >= $start && $x != $num) {
                $data = fgetcsv($handle, 0, "|");
                $xxx = count($data);
                //echo "<p> $xxx fields in line $i: <br /></p>\n";
                //print_r($data);
                $pid = $data[0];
                $title = $data[1];
                $url = str_replace("YOURUSERID", $affid, $data[4]);
                $thumb = $data[5];
                $bigimage = $data[6];
                $description = $data[11];
                $merchant = $data[3];
                $custom1 = $data[12];
                $custom2 = $data[13];
                $custom3 = $data[14];
                $category = $data[9];
                $manufacturer = $data[19];
                $isbn = $data[24];
                $status = $data[18];
                $price = "\$ " . $data[7];
                $listprice = "\$ " . $data[8];
                if ($thumb != "") {
                    $thumbnail = '<a href="' . $url . '" rel="nofollow"><img style="float:left;margin: 0 20px 10px 0;" src="' . $thumb . '" /></a>';
                } else {
                    $thumbnail = '';
                }
                $abort = 0;
                if ($keyword != "" && $options['wpr_shareasale_filter'] == 'yes') {
                    $keyword = str_replace('"', '', $keyword);
                    $keywords = explode(" AND ", $keyword);
                    foreach ($keywords as $kwx) {
                        $kw2 = " " . $kwx . " ";
                        //echo $kw2."<br/>";
                        $c2 = stripos($description, $kw2);
                        $c3 = stripos($title, $kw2);
                        if ($c2 != false || $c3 != false) {
                            // echo "keyword was found $c2 $c3<br/>";
                            $abort = 0;
                        } else {
                            //echo "keyword was not found<br/>";
                            $abort = 1;
                        }
                    }
                }
                $content = $template;
                $content = wpr_random_tags($content);
                $content = str_replace("{thumbnail}", $thumbnail, $content);
                $content = str_replace("{title}", $title, $content);
                $content = str_replace("{bigimage}", $bigimage, $content);
                $content = str_replace("{description}", $description, $content);
                $content = str_replace("{url}", $url, $content);
                $content = str_replace("{keyword}", $keyword, $content);
                $content = str_replace("{merchant}", $merchant, $content);
                $content = str_replace("{custom1}", $custom1, $content);
                $content = str_replace("{custom2}", $custom2, $content);
                $content = str_replace("{custom3}", $custom3, $content);
                $content = str_replace("{category}", $category, $content);
                $content = str_replace("{manufacturer}", $manufacturer, $content);
                $content = str_replace("{isbn}", $isbn, $content);
                $content = str_replace("{status}", $status, $content);
                $content = str_replace("{price}", $price, $content);
                $content = str_replace("{listprice}", $listprice, $content);
                if (function_exists("wpr_translate_partial")) {
                    $content = wpr_translate_partial($content);
                }
                if (function_exists("wpr_rewrite_partial")) {
                    $content = wpr_rewrite_partial($content, $options);
                }
                $customfield = array();
                $customfield["custom1"] = $custom1;
                $customfield["custom2"] = $custom2;
                $customfield["custom3"] = $custom3;
                if (empty($pid)) {
                    $pid = $i;
                }
                $itemcontent[$x]["unique"] = $pid;
                $itemcontent[$x]["title"] = $title;
                $itemcontent[$x]["content"] = $content;
                $itemcontent[$x]["customfield"] = $customfield;
                $x++;
            } else {
                $data = fgetcsv($handle, 0, "|");
                //echo "<p> Skipping over line $i: <br /></p>\n";
            }
            if ($abort == 1) {
                $return["error"]["module"] = "Shareasale";
                $return["error"]["reason"] = "IncNum";
                $return["error"]["message"] = __("Post skipped because your filter keyword has not been found in the datafeed entry.", "wprobot");
                return $return;
            }
            if ($data === false) {
                $return["error"]["module"] = "Shareasale";
                $return["error"]["reason"] = "No datafeed";
                $return["error"]["message"] = __("End of datafeed file reached.", "wprobot");
                return $return;
            }
        }
    } else {
        $return["error"]["module"] = "Shareasale";
        $return["error"]["reason"] = "No datafeed";
        $return["error"]["message"] = __("Datafeed file could not be opened or does not exist.", "wprobot");
        return $return;
    }
    if (empty($itemcontent)) {
        // Return error if no content has been found.
        $itemcontent["error"]["module"] = "Shareasale";
        $itemcontent["error"]["reason"] = "No content";
        $itemcontent["error"]["message"] = __("No (more) Shareasale items found.", "wprobot");
        return $itemcontent;
    } else {
        return $itemcontent;
    }
}
Example #11
0
function wpr_itunespost($keyword, $num, $start, $optional = "", $comments = "")
{
    global $wpdb, $wpr_table_templates;
    $options = unserialize(get_option("wpr_options"));
    $uid = $options['wpr_itunes_unique'];
    if ($keyword == "") {
        // If keyword is empty return error
        $return["error"]["module"] = "iTunes";
        $return["error"]["reason"] = "No keyword";
        $return["error"]["message"] = __("No keyword specified.", "wprobot");
        return $return;
    }
    $template = $wpdb->get_var("SELECT content FROM " . $wpr_table_templates . " WHERE type = 'itunes'");
    if ($template == false || empty($template)) {
        // If module template is empty return error
        $return["error"]["module"] = "iTunes";
        $return["error"]["reason"] = "No template";
        $return["error"]["message"] = __("Module Template does not exist or could not be loaded.", "wprobot");
        return $return;
    }
    $x = 0;
    $r = 0;
    $itemcontent = array();
    $pxml = wpr_itunesrequest($keyword, $num, $start, $options);
    // Send API request
    if (is_array($pxml) && isset($pxml["error"])) {
        return $pxml;
    }
    if ($pxml === False) {
        $itemcontent["error"]["module"] = "iTunes";
        $itemcontent["error"]["reason"] = "Request fail";
        $itemcontent["error"]["message"] = __("API request could not be sent.", "wprobot");
        return $itemcontent;
    } else {
        if (isset($pxml->results)) {
            foreach ($pxml->results as $item) {
                if ($r >= $start) {
                    $artistName = $item->artistName;
                    $collectionName = $item->collectionName;
                    $trackId = $item->trackId;
                    $collectionId = $item->collectionId;
                    $trackName = $item->trackName;
                    $artistViewUrl = $item->artistViewUrl;
                    $collectionViewUrl = $item->collectionViewUrl;
                    $trackViewUrl = $item->trackViewUrl;
                    $previewUrl = $item->previewUrl;
                    $artworkUrl30 = $item->artworkUrl30;
                    $artworkUrl60 = $item->artworkUrl60;
                    $artworkUrl100 = $item->artworkUrl100;
                    $collectionPrice = $item->collectionPrice;
                    $trackPrice = $item->trackPrice;
                    $currency = $item->currency;
                    $primaryGenreName = $item->primaryGenreName;
                    if ($artworkUrl60 != "") {
                        $thumbnail = '<a href="' . $collectionViewUrl . '" rel="nofollow"><img style="float:left;margin: 0 20px 10px 0;" src="' . $artworkUrl60 . '" /></a>';
                    } else {
                        $thumbnail = '';
                    }
                    $content = $template;
                    $content = wpr_random_tags($content);
                    $content = str_replace("{thumbnail}", $thumbnail, $content);
                    $content = str_replace("{keyword}", $keyword, $content);
                    $content = str_replace("{trackname}", $trackName, $content);
                    $content = str_replace("{collectionname}", $collectionName, $content);
                    $content = str_replace("{artistname}", $artistName, $content);
                    $content = str_replace("{artworkUrl30}", $artworkUrl30, $content);
                    $content = str_replace("{artworkUrl60}", $artworkUrl60, $content);
                    $content = str_replace("{artworkUrl100}", $artworkUrl100, $content);
                    $content = str_replace("{collectionPrice}", $collectionPrice, $content);
                    $content = str_replace("{trackPrice}", $trackPrice, $content);
                    $content = str_replace("{currency}", $currency, $content);
                    $content = str_replace("{genre}", $primaryGenreName, $content);
                    $content = str_replace("{artisturl}", $artistViewUrl, $content);
                    $content = str_replace("{collectionurl}", $collectionViewUrl, $content);
                    $content = str_replace("{trackurl}", $trackViewUrl, $content);
                    $content = str_replace("{previewurl}", $previewUrl, $content);
                    if (function_exists("wpr_translate_partial")) {
                        $content = wpr_translate_partial($content);
                    }
                    if (function_exists("wpr_rewrite_partial")) {
                        $content = wpr_rewrite_partial($content, $options);
                    }
                    if ($uid == "track") {
                        $uid2 = $trackId;
                    } else {
                        $uid2 = $collectionId;
                    }
                    $itemcontent[$x]["unique"] = $uid2;
                    $itemcontent[$x]["title"] = $artistName . " - " . $trackName;
                    $itemcontent[$x]["content"] = $content;
                    $x++;
                }
                $r++;
            }
            if (empty($itemcontent)) {
                // Return error if no content has been found.
                $itemcontent["error"]["module"] = "iTunes";
                $itemcontent["error"]["reason"] = "No content";
                $itemcontent["error"]["message"] = __("No (more) Yahoo news items found.", "wprobot");
                return $itemcontent;
            } else {
                return $itemcontent;
            }
        } else {
            if (isset($pxml->Message)) {
                // Check for API error messages in results and if found return them.
                $message = __('There was a problem with your API request. This is the error returned:', "wprobot") . ' <b>' . $pxml->Message . '</b>';
                $itemcontent["error"]["module"] = "iTunes";
                $itemcontent["error"]["reason"] = "API fail";
                $itemcontent["error"]["message"] = $message;
                return $itemcontent;
            } else {
                // Return error if no content has been found.
                $itemcontent["error"]["module"] = "iTunes";
                $itemcontent["error"]["reason"] = "No content";
                $itemcontent["error"]["message"] = __("No (more) iTunes items found.", "wprobot");
                return $itemcontent;
            }
        }
    }
}
Example #12
0
function wpr_yelppost($keyword, $num, $start, $optional = "", $comments = "")
{
    global $wpdb, $wpr_table_templates;
    $end = $start + $num;
    if ($keyword == "") {
        // If keyword is empty return error
        $return["error"]["module"] = "Yelp";
        $return["error"]["reason"] = "No keyword";
        $return["error"]["message"] = __("No keyword specified.", "wprobot");
        return $return;
    }
    if ($start >= 20) {
        // If keyword is empty return error
        $return["error"]["module"] = "Yelp";
        $return["error"]["reason"] = "No content";
        $return["error"]["message"] = __("No more content: The Yelp API does only return the first 20 results for any keyword.", "wprobot");
        return $return;
    }
    $template = $wpdb->get_var("SELECT content FROM " . $wpr_table_templates . " WHERE type = 'yelp'");
    if ($template == false || empty($template)) {
        // If module template is empty return error
        $return["error"]["module"] = "Yelp";
        $return["error"]["reason"] = "No template";
        $return["error"]["message"] = __("Module Template does not exist or could not be loaded.", "wprobot");
        return $return;
    }
    $x = 0;
    $yy = 0;
    $itemcontent = array();
    $pxml = wpr_yelprequest($keyword, $num, $start);
    // Send API request
    if (is_array($pxml) && isset($pxml["error"])) {
        return $pxml;
    }
    if ($pxml === False) {
        $itemcontent["error"]["module"] = "Yelp";
        $itemcontent["error"]["reason"] = "Request fail";
        $itemcontent["error"]["message"] = __("API request could not be sent.", "wprobot");
        return $itemcontent;
    } else {
        if (isset($pxml->businesses)) {
            foreach ($pxml->businesses as $item) {
                if ($yy >= $start && $yy < $end) {
                    $title = $item->name;
                    $url = $item->url;
                    $address1 = $item->address1;
                    $address2 = $item->address2;
                    $address3 = $item->address3;
                    $address = $address1 . "<br/>" . $address2 . "<br/>" . $address3 . "<br/>";
                    $city = $item->city;
                    $phone = $item->phone;
                    $photo_url = $item->photo_url;
                    $avg_rating = $item->avg_rating;
                    $review_count = $item->review_count;
                    $reviews = array();
                    if (isset($item->reviews)) {
                        $r = 0;
                        foreach ($item->reviews as $review) {
                            $reviews[$r]["author"] = $review->user_name;
                            $reviews[$r]["rating"] = $review->rating;
                            $rtemplate = "<i>Review by {author}</i><br/>{content}<br/><b>Rating: {rating}</b><br/><br/>";
                            $rtemplate = str_replace("{content}", strip_tags($review->text_excerpt, '<br><strong>'), $rtemplate);
                            $rtemplate = str_replace("{rating}", $review->rating, $rtemplate);
                            $rtemplate = str_replace("{author}", $review->user_name, $rtemplate);
                            $reviews[$r]["content"] = $rtemplate;
                            $r++;
                        }
                    }
                    $source = "Read more on <a rel=\"nofollow\" href=\"{$url}\">{$source}</a><br/><br/>";
                    if ($photo_url != "") {
                        $thumbnail = '<a href="' . $url . '" rel="nofollow"><img style="float:left;margin: 0 20px 10px 0;" src="' . $photo_url . '" /></a>';
                    } else {
                        $thumbnail = '';
                    }
                    $content = $template;
                    $content = wpr_random_tags($content);
                    $content = str_replace("{thumbnail}", $thumbnail, $content);
                    $content = str_replace("{title}", $title, $content);
                    $content = str_replace("{rating}", $avg_rating, $content);
                    $content = str_replace("{reviewscount}", $review_count, $content);
                    $content = str_replace("{url}", $url, $content);
                    $content = str_replace("{keyword}", $keyword, $content);
                    $content = str_replace("{address}", $address1, $content);
                    $content = str_replace("{city}", $city, $content);
                    // reviews
                    $reviewspost = "";
                    $reviewsnum = $review_count;
                    preg_match('#\\{reviews(.*)\\}#iU', $content, $rmatches);
                    if ($rmatches[0] == false) {
                    } elseif (empty($reviews)) {
                        $content = str_replace($rmatches[0], $reviewspost, $content);
                    } else {
                        $reviewnum = substr($rmatches[1], 1);
                        for ($i = 0; $i < $reviewnum; $i++) {
                            if ($i == $reviewsnum || $i == 3) {
                                break;
                            } else {
                                $reviewspost .= $reviews[$i]["content"];
                            }
                        }
                        $content = str_replace($rmatches[0], $reviewspost, $content);
                    }
                    if (function_exists("wpr_translate_partial")) {
                        $content = wpr_translate_partial($content);
                    }
                    if (function_exists("wpr_rewrite_partial")) {
                        $content = wpr_rewrite_partial($content, $options);
                    }
                    $itemcontent[$x]["unique"] = $item->id;
                    $itemcontent[$x]["title"] = $title;
                    $itemcontent[$x]["content"] = $content;
                    $x++;
                }
                $yy++;
            }
            if (empty($itemcontent)) {
                // Return error if no content has been found.
                $itemcontent["error"]["module"] = "Yelp";
                $itemcontent["error"]["reason"] = "No content";
                $itemcontent["error"]["message"] = __("No (more) Yelp items found.", "wprobot");
                return $itemcontent;
            } else {
                return $itemcontent;
            }
        } else {
            if (isset($pxml->message->text) && $pxml->message->code != 0) {
                // Check for API error messages in results and if found return them.
                $message = __('There was a problem with your API request. This is the error returned by Yelp:', "wprobot") . ' <b>' . $pxml->message->code . ': ' . $pxml->message->text . '</b>';
                $itemcontent["error"]["module"] = "Yelp";
                $itemcontent["error"]["reason"] = "API fail";
                $itemcontent["error"]["message"] = $message;
                return $itemcontent;
            } else {
                // Return error if no content has been found.
                $itemcontent["error"]["module"] = "Yelp";
                $itemcontent["error"]["reason"] = "No content";
                $itemcontent["error"]["message"] = __("No (more) Yelp items found.", "wprobot");
                return $itemcontent;
            }
        }
    }
}
Example #13
0
function wpr_eventfulpost($keyword, $num, $start, $optional = "", $comments = "")
{
    global $wpdb, $wpr_table_templates;
    $options = unserialize(get_option("wpr_options"));
    if ($keyword == "") {
        // If keyword is empty return error
        $return["error"]["module"] = "Eventful";
        $return["error"]["reason"] = "No keyword";
        $return["error"]["message"] = __("No keyword specified.", "wprobot");
        return $return;
    }
    $template = $wpdb->get_var("SELECT content FROM " . $wpr_table_templates . " WHERE type = 'eventful'");
    if ($template == false || empty($template)) {
        // If module template is empty return error
        $return["error"]["module"] = "Eventful";
        $return["error"]["reason"] = "No template";
        $return["error"]["message"] = __("Module Template does not exist or could not be loaded.", "wprobot");
        return $return;
    }
    $x = 0;
    $itemcontent = array();
    $pxml = wpr_eventfulrequest($keyword, $num, $start, $options);
    // Send API request
    if (!empty($pxml["error"])) {
        return $pxml;
    }
    if ($pxml === False) {
        $itemcontent["error"]["module"] = "Eventful";
        $itemcontent["error"]["reason"] = "Request fail";
        $itemcontent["error"]["message"] = __("API request could not be sent.", "wprobot");
        return $itemcontent;
    } else {
        if (isset($pxml->events)) {
            foreach ($pxml->events->event as $item) {
                $attrs = $item->attributes();
                $uid = $attrs['id'];
                $title = $item->title;
                $description = trim($item->description);
                $url = $item->url;
                $start_time = $item->start_time;
                $stop_time = $item->stop_time;
                $venue_name = $item->venue_name;
                $venue_url = $item->venue_url;
                $venue_address = $item->venue_address;
                $city_name = $item->city_name;
                $country_name = $item->country_name;
                $content = $template;
                $content = wpr_random_tags($content);
                $content = str_replace("{title}", $title, $content);
                $content = str_replace("{description}", $description, $content);
                $content = str_replace("{url}", $url, $content);
                $content = str_replace("{keyword}", $keyword, $content);
                $content = str_replace("{begin}", $start_time, $content);
                $content = str_replace("{end}", $stop_time, $content);
                $content = str_replace("{venuename}", $venue_name, $content);
                $content = str_replace("{venueurl}", $venue_url, $content);
                $content = str_replace("{venueaddress}", $venue_address, $content);
                $content = str_replace("{city}", $city_name, $content);
                $content = str_replace("{country}", $country_name, $content);
                if (function_exists("wpr_translate_partial")) {
                    $content = wpr_translate_partial($content);
                }
                if (function_exists("wpr_rewrite_partial")) {
                    $content = wpr_rewrite_partial($content, $options);
                }
                if ("yes" == $options['wpr_eventful_skip'] && empty($description) && $num == 1) {
                    $itemcontent["error"]["module"] = "Eventful";
                    $itemcontent["error"]["reason"] = "No content";
                    $itemcontent["error"]["message"] = __("Event skipped because of empty description.", "wprobot");
                    return $itemcontent;
                }
                $itemcontent[$x]["unique"] = $uid;
                $itemcontent[$x]["title"] = $title;
                $itemcontent[$x]["content"] = $content;
                $x++;
            }
            if (empty($itemcontent)) {
                // Return error if no content has been found.
                $itemcontent["error"]["module"] = "Eventful";
                $itemcontent["error"]["reason"] = "No content";
                $itemcontent["error"]["message"] = __("No (more) Yahoo news items found.", "wprobot");
                return $itemcontent;
            } else {
                return $itemcontent;
            }
        } else {
            if (isset($pxml->description)) {
                // Check for API error messages in results and if found return them.
                $message = __('There was a problem with your API request. This is the error returned:', "wprobot") . ' <b>' . $pxml->description . '</b>';
                $itemcontent["error"]["module"] = "Eventful";
                $itemcontent["error"]["reason"] = "API fail";
                $itemcontent["error"]["message"] = $message;
                return $itemcontent;
            } else {
                // Return error if no content has been found.
                $itemcontent["error"]["module"] = "Eventful";
                $itemcontent["error"]["reason"] = "No content";
                $itemcontent["error"]["message"] = __("No (more) Eventful items found.", "wprobot");
                return $itemcontent;
            }
        }
    }
}
Example #14
0
function wpr_articlepost($keyword, $num, $start, $optional = "", $comments = "")
{
    global $wpdb, $wpr_table_templates;
    if ($keyword == "") {
        $return["error"]["module"] = "Article";
        $return["error"]["reason"] = "No keyword";
        $return["error"]["message"] = __("No keyword specified.", "wprobot");
        return $return;
    }
    $template = $wpdb->get_var("SELECT content FROM " . $wpr_table_templates . " WHERE type = 'article'");
    if ($template == false || empty($template)) {
        $return["error"]["module"] = "Article";
        $return["error"]["reason"] = "No template";
        $return["error"]["message"] = __("Module Template does not exist or could not be loaded.", "wprobot");
        return $return;
    }
    $posts = array();
    $options = unserialize(get_option("wpr_options"));
    $proxy == "";
    if ($options["wpr_trans_use_proxies"] == "yes") {
        $proxies = str_replace("\r", "", $options["wpr_trans_proxies"]);
        $proxies = explode("\n", $proxies);
        $rand = array_rand($proxies);
        list($proxy, $proxytype, $proxyuser) = explode("|", $proxies[$rand]);
    }
    $keyword2 = $keyword;
    $keyword = str_replace(" ", "+", $keyword);
    $keyword = urlencode($keyword);
    $blist[] = "Mozilla/5.0 (compatible; Konqueror/4.0; Microsoft Windows) KHTML/4.0.80 (like Gecko)";
    $blist[] = "Mozilla/5.0 (compatible; Konqueror/3.92; Microsoft Windows) KHTML/3.92.0 (like Gecko)";
    $blist[] = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506; Media Center PC 5.0; .NET CLR 1.1.4322; Windows-Media-Player/10.00.00.3990; InfoPath.2";
    $blist[] = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; Dealio Deskball 3.0)";
    $blist[] = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; NeosBrowser; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
    $ua = $blist[array_rand($blist)];
    // SOURCE
    $source = array();
    if ($options['wpr_eza_source_ab'] == 1 || $options['wpr_eza_source'] == "ab" || $options['wpr_eza_source'] == "rand") {
        $source[] = "ab";
    }
    if ($options['wpr_eza_source_goa'] == 1 || $options['wpr_eza_source'] == "goa" || $options['wpr_eza_source'] == "rand") {
        $source[] = "goa";
    }
    if ($options['wpr_eza_source_buk'] == 1 || $options['wpr_eza_source'] == "buk" || $options['wpr_eza_source'] == "rand") {
        $source[] = "buk";
    }
    if ($options['wpr_eza_source_ezm'] == 1 || $options['wpr_eza_source'] == "ezm" || $options['wpr_eza_source'] == "rand") {
        $source[] = "ezm";
    }
    $rand_key = array_rand($source);
    if ($source[$rand_key] == "ab") {
        $options['wpr_eza_source'] = "ab";
    } elseif ($source[$rand_key] == "goa") {
        $options['wpr_eza_source'] = "goa";
    } elseif ($source[$rand_key] == "buk") {
        $options['wpr_eza_source'] = "buk";
    } elseif ($source[$rand_key] == "ezm") {
        $options['wpr_eza_source'] = "ezm";
    }
    //print_r($source);echo "source: ".$rand_key . " ". $options['wpr_eza_source'] . "\n";
    /*if($options["wpr_eza_source"] == "rand") {
    		$rand = rand(0,3);
    		if($rand == 0) {$options["wpr_eza_source"] = "buk";
    		} elseif($rand == 1) {$options["wpr_eza_source"] = "goa";
    		} elseif($rand == 2) {$options["wpr_eza_source"] = "ezm";		
    		} else {$options["wpr_eza_source"] = "ab";}	
    	}*/
    if ($options["wpr_eza_source"] == "buk") {
        return wpr_bukisapost($keyword, $num, $start, $optional, $comments, $options, $template, $ua, $proxy, $proxytype, $proxyuser);
    } elseif ($options["wpr_eza_source"] == "goa") {
        return wpr_goarticlepost($keyword, $num, $start, $optional, $comments, $options, $template, $ua, $proxy, $proxytype, $proxyuser);
    } elseif ($options["wpr_eza_source"] == "ezm") {
        return wpr_ezinemarkpost($keyword, $num, $start, $optional, $comments, $options, $template, $ua, $proxy, $proxytype, $proxyuser);
    }
    if (empty($start)) {
        $start = 0;
    }
    $search_url = "http://ezinearticles.com/search/?q={$keyword}&index={$start}";
    //
    // make the cURL request to $search_url
    if (function_exists('curl_init')) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_USERAGENT, $ua);
        if ($proxy != "") {
            //curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
            curl_setopt($ch, CURLOPT_PROXY, $proxy);
            if ($proxyuser) {
                curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyuser);
            }
            if ($proxytype == "socks") {
                curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
            }
        }
        curl_setopt($ch, CURLOPT_URL, $search_url);
        curl_setopt($ch, CURLOPT_FAILONERROR, true);
        curl_setopt($ch, CURLOPT_AUTOREFERER, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, 45);
        $html = curl_exec($ch);
        if (!$html) {
            $return["error"]["module"] = "Article";
            $return["error"]["reason"] = "cURL Error";
            $return["error"]["message"] = __("cURL Error Number ", "wprobot") . curl_errno($ch) . ": " . curl_error($ch);
            return $return;
        }
        curl_close($ch);
    } else {
        $html = @file_get_contents($search_url);
        if (!$html) {
            $return["error"]["module"] = "Article";
            $return["error"]["reason"] = "cURL Error";
            $return["error"]["message"] = __("cURL is not installed on this server!", "wprobot");
            return $return;
        }
    }
    // parse the html into a DOMDocument
    $dom = new DOMDocument();
    @$dom->loadHTML($html);
    // Grab Product Links
    $xpath = new DOMXPath($dom);
    $paras = $xpath->query("//div/h3/a");
    $x = 0;
    $end = $num;
    if ($paras->length == 0) {
        $posts["error"]["module"] = "Article";
        $posts["error"]["reason"] = "No content";
        $posts["error"]["message"] = __("No (more) articles found.", "wprobot");
        return $posts;
    }
    if ($end > $paras->length) {
        $end = $paras->length;
    }
    for ($i = 0; $i <= $end; $i++) {
        $para = $paras->item($i);
        if (empty($para)) {
            $posts["error"]["module"] = "Article";
            $posts["error"]["reason"] = "No content";
            $posts["error"]["message"] = __("No (more) articles found.", "wprobot");
            return $posts;
        } else {
            $target_url = "http://ezinearticles.com" . $para->getAttribute('href');
            // $target_url = "http://www.articlesbase.com" . $para->getAttribute('href');
            // make the cURL request to $search_url
            if (function_exists('curl_init')) {
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_USERAGENT, $ua);
                if ($proxy != "") {
                    //curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
                    curl_setopt($ch, CURLOPT_PROXY, $proxy);
                    if ($proxyuser) {
                        curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyuser);
                    }
                    if ($proxytype == "socks") {
                        curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
                    }
                }
                curl_setopt($ch, CURLOPT_URL, $target_url);
                curl_setopt($ch, CURLOPT_FAILONERROR, true);
                curl_setopt($ch, CURLOPT_AUTOREFERER, true);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_TIMEOUT, 45);
                $html = curl_exec($ch);
                if (!$html) {
                    $return["error"]["module"] = "Article";
                    $return["error"]["reason"] = "cURL Error";
                    $return["error"]["message"] = __("cURL Error Number ", "wprobot") . curl_errno($ch) . ": " . curl_error($ch);
                    return $return;
                }
                curl_close($ch);
            } else {
                $html = @file_get_contents($target_url);
                if (!$html) {
                    $return["error"]["module"] = "Article";
                    $return["error"]["reason"] = "cURL Error";
                    $return["error"]["message"] = __("cURL is not installed on this server!", "wprobot");
                    return $return;
                }
            }
            // parse the html into a DOMDocument
            $dom = new DOMDocument();
            @$dom->loadHTML($html);
            // Grab Article Title
            $xpath1 = new DOMXPath($dom);
            $paras1 = $xpath1->query("//div/h1");
            $para1 = $paras1->item(0);
            $title = $para1->textContent;
            // Grab Article
            $xpath2 = new DOMXPath($dom);
            $paras2 = $xpath2->query("//div[@id='article-content']");
            $para2 = $paras2->item(0);
            $string = $dom->saveXml($para2);
            //$string = preg_replace('#<div class="articles">(.*)</div>#smiU', '', $string);
            //$string = preg_replace('#<a title="(.*)" href="/authors/(.*)</a>#smiU', '', $string);
            //$string = preg_replace('#<strong>(.*)</strong>#smiU', '', $string);
            $string = strip_tags($string, '<p><strong><b><a><br>');
            $string = str_replace("&nbsp;", "", $string);
            $string = str_replace("]]>", "", $string);
            $string = str_replace("\$", "\$ ", $string);
            if ($options['wpr_eza_striplinks'] == 'yes') {
                $string = wpr_strip_selected_tags($string, array('a', 'iframe', 'script'));
            }
            $articlebody .= $string . ' ';
            // Grab Ressource Box
            $xpath3 = new DOMXPath($dom);
            $paras3 = $xpath3->query("//div[@id='article-resource']");
            //$para = $paras->item(0);
            $ressourcetext = "";
            for ($y = 0; $y < $paras3->length; $y++) {
                //$paras->length
                $para3 = $paras3->item($y);
                $ressourcetext .= $dom->saveXml($para3);
            }
            $xpath2 = new DOMXPath($dom);
            $paras2 = $xpath2->query("//div[@id='article-body']/p");
            $para2 = $paras2->item(0);
            $ressourcetext .= str_replace('href="', 'href="http://ezinearticles.com', $dom->saveXml($para2));
            $title = utf8_decode($title);
            // Split into Pages
            if ($options['wpr_eza_split'] == "yes") {
                $articlebody = wordwrap($articlebody, $options['wpr_eza_splitlength'], "<!--nextpage-->");
            }
            $post = $template;
            $post = wpr_random_tags($post);
            $post = str_replace("{article}", $articlebody, $post);
            $post = str_replace("{authortext}", $ressourcetext, $post);
            $noqkeyword = str_replace('"', '', $keyword2);
            $post = str_replace("{keyword}", $noqkeyword, $post);
            $post = str_replace("{Keyword}", ucwords($noqkeyword), $post);
            $post = str_replace("{title}", $title, $post);
            $post = str_replace("{url}", $target_url, $post);
            if (function_exists("wpr_rewrite_partial")) {
                $post = wpr_rewrite_partial($post, $options);
            }
            if (function_exists("wpr_translate_partial")) {
                $post = wpr_translate_partial($post);
            }
            $posts[$x]["unique"] = $target_url;
            $posts[$x]["title"] = $title;
            $posts[$x]["content"] = $post;
            $x++;
        }
    }
    return $posts;
}
Example #15
0
function wpr_oodlepost($keyword, $num, $start, $optional = "", $comments = "")
{
    global $wpdb, $wpr_table_templates;
    if ($keyword == "") {
        // If keyword is empty return error
        $return["error"]["module"] = "oodle";
        $return["error"]["reason"] = "No keyword";
        $return["error"]["message"] = __("No keyword specified.", "wprobot");
        return $return;
    }
    $template = $wpdb->get_var("SELECT content FROM " . $wpr_table_templates . " WHERE type = 'oodle'");
    if ($template == false || empty($template)) {
        // If module template is empty return error
        $return["error"]["module"] = "oodle";
        $return["error"]["reason"] = "No template";
        $return["error"]["message"] = __("Module Template does not exist or could not be loaded.", "wprobot");
        return $return;
    }
    $x = 0;
    $itemcontent = array();
    $pxml = wpr_oodlerequest($keyword, $num, $start);
    // Send API request
    if (!empty($pxml["error"])) {
        return $pxml;
    }
    if ($pxml === False) {
        $itemcontent["error"]["module"] = "oodle";
        $itemcontent["error"]["reason"] = "Request fail";
        $itemcontent["error"]["message"] = __("API request could not be sent.", "wprobot");
        return $itemcontent;
    } else {
        if (isset($pxml->listings->element)) {
            foreach ($pxml->listings->element as $item) {
                $title = $item->title;
                $listing = $item->body;
                $url = $item->url;
                $img = $item->images->element[0]->src;
                $address = $item->location->address;
                $city = $item->location->zip . " " . $item->location->name . ", " . $item->location->country;
                $lat = $item->location->latitude;
                $long = $item->location->longitude;
                $price = $item->attributes->price_display;
                $price = str_replace("\$", "\$ ", $price);
                $condition = $item->attributes->condition;
                $features = $item->attributes->features;
                $seller_type = $item->attributes->seller_type;
                $delivery = $item->attributes->delivery;
                if ($img != "") {
                    $thumbnail = '<a href="' . $url . '" rel="nofollow"><img style="float:left;margin: 0 20px 10px 0;" src="' . $img . '" /></a>';
                } else {
                    $thumbnail = '';
                }
                $content = $template;
                $content = wpr_random_tags($content);
                $content = str_replace("{thumbnail}", $thumbnail, $content);
                $content = str_replace("{title}", $title, $content);
                $content = str_replace("{content}", $listing, $content);
                $content = str_replace("{url}", $url, $content);
                $content = str_replace("{city}", $city, $content);
                $content = str_replace("{address}", $address, $content);
                $content = str_replace("{latitude}", $latitude, $content);
                $content = str_replace("{longitude}", $longitude, $content);
                $content = str_replace("{price}", $price, $content);
                $content = str_replace("{condition}", $condition, $content);
                $content = str_replace("{features}", $features, $content);
                $content = str_replace("{seller_type}", $seller_type, $content);
                $content = str_replace("{delivery}", $delivery, $content);
                $noqkeyword = str_replace('"', '', $keyword);
                $content = str_replace("{keyword}", $noqkeyword, $content);
                $content = str_replace("{Keyword}", ucwords($noqkeyword), $content);
                if (function_exists("wpr_translate_partial")) {
                    $content = wpr_translate_partial($content);
                }
                if (function_exists("wpr_rewrite_partial")) {
                    $content = wpr_rewrite_partial($content, $options);
                }
                $customfield = array();
                $customfield["oodletitle"] = $title;
                $customfield["oodleprice"] = $price;
                $customfield["oodlethumbnail"] = $img;
                if (!empty($listing)) {
                    $itemcontent[$x]["unique"] = $item->id;
                    $itemcontent[$x]["title"] = $title;
                    $itemcontent[$x]["content"] = $content;
                    $itemcontent[$x]["customfield"] = $customfield;
                }
                $x++;
            }
            if (empty($itemcontent)) {
                // Return error if no content has been found.
                $itemcontent["error"]["module"] = "oodle";
                $itemcontent["error"]["reason"] = "No content";
                $itemcontent["error"]["message"] = __("No (more) oodle items found.", "wprobot");
                return $itemcontent;
            } else {
                return $itemcontent;
            }
        } else {
            if (isset($pxml->Message)) {
                // Check for API error messages in results and if found return them.
                $message = __('There was a problem with your API request. This is the error returned:', "wprobot") . ' <b>' . $pxml->Message . '</b>';
                $itemcontent["error"]["module"] = "oodle";
                $itemcontent["error"]["reason"] = "API fail";
                $itemcontent["error"]["message"] = $message;
                return $itemcontent;
            } else {
                // Return error if no content has been found.
                $itemcontent["error"]["module"] = "oodle";
                $itemcontent["error"]["reason"] = "No content";
                $itemcontent["error"]["message"] = __("No (more) oodle items found.", "wprobot");
                return $itemcontent;
            }
        }
    }
}
Example #16
0
function wpr_articlebuilderpost($keyword, $num, $start)
{
    $keyword = explode(">", $keyword);
    $category = str_replace('"', "", $keyword[0]);
    $kws = explode(",", $keyword[1]);
    if (empty($category)) {
        $return["error"]["module"] = "Article Builder";
        $return["error"]["reason"] = "No keyword";
        $return["error"]["message"] = __("No keyword specified.", "wprobot");
        return $return;
    }
    /*$allcats = array(0 => "acid reflux", 1 => "acne", 2 => "acupuncture", 3 => "affiliate marketing", 4 => "aging", 5 => "allergies", 6 => "anxiety", 7 => "arthritis", 8 => "article marketing", 9 => "asthma", 10 => "auto repair", 11 => "back pain", 12 => "basketball", 13 => "beauty", 14 => "blogging", 15 => "camping", 16 => "cancer", 17 => "car shopping", 18 => "carpet cleaning", 19 => "cats", 20 => "coffee", 21 => "college", 22 => "cooking", 23 => "cosmetic surgery", 24 => "coupons", 25 => "credit cards", 26 => "credit repair", 27 => "debt consolidation", 28 => "dental care", 29 => "depression", 30 => "diabetes", 31 => "dog training", 32 => "dogs", 33 => "email marketing", 34 => "employment", 35 => "facebook marketing", 36 => "fashion", 37 => "fishing", 38 => "fitness", 39 => "forex", 40 => "furniture", 41 => "gardening", 42 => "gold", 43 => "golf", 44 => "green energy", 45 => "hair care", 46 => "hair loss", 47 => "hemorrhoids", 48 => "home business", 49 => "home improvement", 50 => "home security", 51 => "homeschooling", 52 => "insurance - auto", 53 => "insurance - general", 54 => "insurance - health", 55 => "insurance - home owner's", 56 => "insurance - life", 57 => "interior design", 58 => "internet marketing", 59 => "ipad", 60 => "iphone", 61 => "jewelry", 62 => "juicing", 63 => "landscaping", 64 => "lawyers", 65 => "massage", 66 => "memory", 67 => "mobile marketing", 68 => "muscle building", 69 => "network marketing", 70 => "nutrition", 71 => "online shopping", 72 => "organic gardening", 73 => "panic attacks", 74 => "parenting", 75 => "payday loans", 76 => "personal bankruptcy", 77 => "personal development", 78 => "personal finance", 79 => "personal injury", 80 => "pest control", 81 => "photography", 82 => "plumbing", 83 => "pregnancy", 84 => "quit smoking", 85 => "real estate - buying", 86 => "real estate - commercial", 87 => "real estate - selling", 88 => "roofing", 89 => "search engine optimization", 90 => "skin care", 91 => "sleep apnea", 92 => "snoring", 93 => "soccer", 94 => "social media marketing", 95 => "solar energy", 96 => "stock market", 97 => "stress", 98 => "teeth whitening", 99 => "tinnitus", 100 => "travel", 101 => "video games", 102 => "video marketing", 103 => "web design", 104 => "web hosting", 105 => "weddings", 106 => "weight loss", 107 => "wine", 108 => "yeast infection" );
    	
    	foreach($allcats as $allcat) {
    		$carr[$allcat] = $allcat;
    	}
    	
    	print_r($carr);
    	
    	if(!in_array($category, $allcats)) {
    		$return["error"]["module"] = "Article Builder";
    		$return["error"]["reason"] = "No keyword";
    		$return["error"]["message"] = __('Article Builder only supports a defined lists of categories which can be used as keywords in WP Robot. Please enter one of the following: "affiliate marketing","article marketing","email marketing","forex","home business","internet marketing","mobile marketing","network marketing","search engine optimization","social media marketing","credit cards","credit repair","insurance - auto","insurance - general","insurance - life","personal bankruptcy","personal finance","real estate - buying","real estate - commercial","stock market","acne","aging","allergies","anxiety","arthritis","asthma","back pain","beauty","cancer","cosmetic surgery","depression","diabetes","fitness","hair care","hair loss","hemorrhoids","insurance - health","juicing","memory","muscle building","nutrition","panic attacks","personal development","quit smoking","skin care","snoring","stress","teeth whitening","tinnitus","weight loss","cooking","dog training","gardening","home improvement","insurance - home owner\'s","landscaping","organic gardening","parenting","plumbing","pregnancy","fishing","golf","photography","travel","jewelry","real estate - selling","weddings","blogging","green energy","web design","web hosting"',"wprobot");
    		return $return;		
    	}*/
    $options = unserialize(get_option("wpr_options"));
    $template = "{article}";
    $url = 'http://articlebuilder.net/api.php';
    $data = array();
    $data['action'] = 'authenticate';
    $data['format'] = 'php';
    $data['username'] = $options['wpr_ab_email'];
    $data['password'] = $options['wpr_ab_pw'];
    $output = unserialize(wpr_ab_curl_post($url, $data, $info));
    /*$session = $output['session'];
    	$data = array();
    	$data['session'] = $session;
    	$data['action'] = 'categories';
    	$data['format'] = 'php';
    
    	$asdf = unserialize(wpr_ab_curl_post($url, $data, $info));	
    	
    	print_r($asdf);	*/
    if ($output['success'] == 'true') {
        $session = $output['session'];
        $data = array();
        $data['session'] = $session;
        $data['action'] = 'categories';
        $cats = wpr_ab_curl_post($url, $data, $info);
        if (strpos($cats, $category) === false) {
            $return["error"]["module"] = "Article Builder";
            $return["error"]["reason"] = "No keyword";
            $return["error"]["message"] = __('Article Builder only supports a defined lists of categories which can be used as keywords in WP Robot. See <a href="http://wprobot.net/go/articlebuilder">articlebuilder.net for a list of supported keywords</a>.', "wprobot");
            return $return;
        }
        $data = array();
        $data['session'] = $session;
        $data['format'] = 'php';
        $data['action'] = 'buildArticle';
        $data['apikey'] = $apikey;
        $data['category'] = $category;
        $subs = "";
        if (is_array($kws)) {
            foreach ($kws as $kw) {
                $subs .= $kw . "\n";
            }
        }
        $data['subtopics'] = $subs;
        $data['wordcount'] = $options['wpr_ab_wordcount'];
        $data['superspun'] = $options['wpr_ab_superspun'];
        //print_r($data);
        $posts = array();
        for ($i = 0; $i < $num; $i++) {
            $output = wpr_ab_curl_post($url, $data, $info);
            $output = unserialize($output);
            if ($output['success'] == 'true') {
                $arts = preg_split('/\\r\\n|\\r|\\n/', $output['output'], 2);
                $art = str_replace("\r", "<br>", str_replace("\n\n", "<p>", $arts[1]));
                $title = $arts[0];
                $post = $template;
                $post = wpr_random_tags($post);
                $post = str_replace("{article}", $art, $post);
                if (function_exists("wpr_translate_partial")) {
                    $post = wpr_translate_partial($post);
                }
                if (function_exists("wpr_rewrite_partial")) {
                    $post = wpr_rewrite_partial($post, $options);
                }
                if ($options['wpr_ab_comments'] == 1) {
                    $comments = array();
                    $cnum = rand(2, 5);
                    for ($x = 1; $x <= $cnum; $x++) {
                        $data = array();
                        $data['session'] = $session;
                        $data['format'] = 'php';
                        $data['action'] = 'getTip';
                        $data['apikey'] = $apikey;
                        $data['category'] = $category;
                        //$data['keywords'] = $title;
                        $data['superspun'] = $options['wpr_ab_superspun'];
                        $coutput = wpr_ab_curl_post($url, $data, $info);
                        $coutput = unserialize($coutput);
                        if ($coutput['success'] == 'true') {
                            $tip = $coutput['output'];
                            $comments[$x]["author"] = $category . " tips " . rand(99, 9999);
                            $comments[$x]["content"] = $tip;
                            //$x++;
                        }
                    }
                    //print_r($comments);
                }
                $posts[$i]["unique"] = rand(0, 999999);
                $posts[$i]["title"] = $title;
                $posts[$i]["content"] = $post;
                $posts[$i]["comments"] = $comments;
            } else {
                $return["error"]["module"] = "Article Builder";
                $return["error"]["reason"] = "No keyword";
                $return["error"]["message"] = $output["error"];
                return $return;
            }
        }
        if (empty($posts)) {
            $posts["error"]["module"] = "Article Builder";
            $posts["error"]["reason"] = "No content";
            $posts["error"]["message"] = __("No Article Builder content found.", "wprobot");
            return $posts;
        } else {
            return $posts;
        }
    } else {
        $return["error"]["module"] = "Article Builder";
        $return["error"]["reason"] = "No keyword";
        $return["error"]["message"] = $output["error"];
        return $return;
    }
}
Example #17
0
function wpr_articlebuilderpost($keyword,$num,$start) {

	$keyword = explode(">", $keyword);
	$category = str_replace('"', "", $keyword[0]);
	$kws = explode(",", $keyword[1]);	
	
	if(empty($category)) {
		$return["error"]["module"] = "Article Builder";
		$return["error"]["reason"] = "No keyword";
		$return["error"]["message"] = __("No keyword specified.","wprobot");
		return $return;	
	}	
	$allcats = array("affiliate marketing","article marketing","email marketing","forex","home business","internet marketing","mobile marketing","network marketing","search engine optimization","social media marketing","credit cards","credit repair","insurance - auto","insurance - general","insurance - life","personal bankruptcy","personal finance","real estate - buying","real estate - commercial","stock market","acne","aging","allergies","anxiety","arthritis","asthma","back pain","beauty","cancer","cosmetic surgery","depression","diabetes","fitness","hair care","hair loss","hemorrhoids","insurance - health","juicing","memory","muscle building","nutrition","panic attacks","personal development","quit smoking","skin care","snoring","stress","teeth whitening","tinnitus","weight loss","cooking","dog training","gardening","home improvement","insurance - home owner's","landscaping","organic gardening","parenting","plumbing","pregnancy","fishing","golf","photography","travel","jewelry","real estate - selling","weddings","blogging","green energy","web design","web hosting","college","homeschooling","coupons","payday loans","coffee","sleep apnea","yeast infection","interior design","camping","video games","fashion","iphone");

	if(!in_array($category, $allcats)) {
		$return["error"]["module"] = "Article Builder";
		$return["error"]["reason"] = "No keyword";
		$return["error"]["message"] = __('Article Builder only supports a defined lists of categories which can be used as keywords in WP Robot. Please enter one of the following: "affiliate marketing","article marketing","email marketing","forex","home business","internet marketing","mobile marketing","network marketing","search engine optimization","social media marketing","credit cards","credit repair","insurance - auto","insurance - general","insurance - life","personal bankruptcy","personal finance","real estate - buying","real estate - commercial","stock market","acne","aging","allergies","anxiety","arthritis","asthma","back pain","beauty","cancer","cosmetic surgery","depression","diabetes","fitness","hair care","hair loss","hemorrhoids","insurance - health","juicing","memory","muscle building","nutrition","panic attacks","personal development","quit smoking","skin care","snoring","stress","teeth whitening","tinnitus","weight loss","cooking","dog training","gardening","home improvement","insurance - home owner\'s","landscaping","organic gardening","parenting","plumbing","pregnancy","fishing","golf","photography","travel","jewelry","real estate - selling","weddings","blogging","green energy","web design","web hosting"',"wprobot");
		return $return;		
	}
	
	$options = unserialize(get_option("wpr_options"));	
	$template = "{article}";

	$url = 'http://articlebuilder.net/api.php';

	$data = array();
	$data['action'] = 'authenticate';
	$data['format'] = 'php';
	$data['username'] = $options['wpr_ab_email'];
	$data['password'] = $options['wpr_ab_pw'];

	$output = unserialize(wpr_ab_curl_post($url, $data, $info));

	if($output['success']=='true'){
		$session = $output['session'];

		$data = array();
		$data['session'] = $session;
		$data['format'] = 'php';
		$data['action'] = 'buildArticle';  
		$data['apikey'] = $apikey;
		$data['category'] = $category;

		$subs = "";
		if(is_array($kws)) {
			foreach($kws as $kw) {
				$subs .= $kw . "\n";
			}
		}
		$data['subtopics'] = $subs;
		$data['wordcount'] = $options['wpr_ab_wordcount'];
		$data['superspun'] = $options['wpr_ab_superspun'];
//print_r($data);
		$posts = array();
		for ($i = 0; $i < $num; $i++) {

			$output = wpr_ab_curl_post($url, $data, $info);
			$output = unserialize($output);
			
			if($output['success']=='true'){
			
				$arts = preg_split('/\r\n|\r|\n/', $output['output'], 2);
				$art = str_replace("\r", "<br>", str_replace("\n\n", "<p>", $arts[1]));
				
				$title = $arts[0];
				
				$post = $template;				
				$post = wpr_random_tags($post);		

				$post = str_replace("{article}", $art, $post);							
		
				if(function_exists("wpr_translate_partial")) {
					$post = wpr_translate_partial($post);
				}
				if(function_exists("wpr_rewrite_partial")) {
					$post = wpr_rewrite_partial($post,$options);
				}			
					
				$posts[$i]["unique"] = rand(0, 999999);
				$posts[$i]["title"] = $title;
				$posts[$i]["content"] = $post;	
			} else {
				$return["error"]["module"] = "Article Builder";
				$return["error"]["reason"] = "No keyword";
				$return["error"]["message"] = $output["error"];
				return $return;	
			}
		}
		if(empty($posts)) {
			$posts["error"]["module"] = "Article Builder";
			$posts["error"]["reason"] = "No content";
			$posts["error"]["message"] = __("No Article Builder content found.","wprobot");	
			return $posts;			
		} else {
			return $posts;	
		}			
	} else {
		$return["error"]["module"] = "Article Builder";
		$return["error"]["reason"] = "No keyword";
		$return["error"]["message"] = $output["error"];
		return $return;	
	}	
}
Example #18
0
function wpr_linksharepost($keyword, $num, $start, $optional = "", $comments = "")
{
    global $wpdb, $wpr_table_templates;
    if ($keyword == "") {
        // If keyword is empty return error
        $return["error"]["module"] = "Linkshare";
        $return["error"]["reason"] = "No keyword";
        $return["error"]["message"] = __("No keyword specified.", "wprobot");
        return $return;
    }
    $template = $wpdb->get_var("SELECT content FROM " . $wpr_table_templates . " WHERE type = 'linkshare'");
    if ($template == false || empty($template)) {
        // If module template is empty return error
        $return["error"]["module"] = "Linkshare";
        $return["error"]["reason"] = "No template";
        $return["error"]["message"] = __("Module Template does not exist or could not be loaded.", "wprobot");
        return $return;
    }
    $x = 0;
    $itemcontent = array();
    $pxml = wpr_linksharerequest($keyword, $num, $start);
    // Send API request
    if (!empty($pxml["error"])) {
        return $pxml;
    }
    if ($pxml === False) {
        $itemcontent["error"]["module"] = "Linkshare";
        $itemcontent["error"]["reason"] = "Request fail";
        $itemcontent["error"]["message"] = __("API request could not be sent.", "wprobot");
        return $itemcontent;
    } else {
        if (isset($pxml->item)) {
            foreach ($pxml->item as $item) {
                $unique = $item->sku;
                $title = $item->productname;
                $merchantname = $item->merchantname;
                $shortdesc = $item->description->short;
                $longdesc = $item->description->long;
                if (strlen($shortdesc) > strlen($longdesc)) {
                    $longdesc = $shortdesc;
                }
                $longdesc = htmlspecialchars_decode($longdesc);
                //echo html_entity_decode($longdesc);
                $url = $item->linkurl;
                $cat = $item->category->primary;
                $thumb = $item->imageurl;
                $price = "\$ " . number_format($item->price, 2, '.', '');
                if ($thumb != "") {
                    $thumbnail = '<a href="' . $url . '" rel="nofollow"><img style="float:left;margin: 0 20px 10px 0;" src="' . $thumb . '" /></a>';
                } else {
                    $thumbnail = '';
                }
                $content = $template;
                $content = wpr_random_tags($content);
                $content = str_replace("{thumbnail}", $thumbnail, $content);
                $content = str_replace("{imageurl}", $thumb, $content);
                $content = str_replace("{title}", $title, $content);
                $content = str_replace("{summary}", $shortdesc, $content);
                $content = str_replace("{description}", $longdesc, $content);
                $content = str_replace("{category}", $cat, $content);
                $content = str_replace("{price}", $price, $content);
                $content = str_replace("{url}", $url, $content);
                $content = str_replace("{keyword}", $keyword, $content);
                $content = str_replace("{merchant}", $merchantname, $content);
                if (function_exists("wpr_translate_partial")) {
                    $content = wpr_translate_partial($content);
                }
                if (function_exists("wpr_rewrite_partial")) {
                    $content = wpr_rewrite_partial($content, $options);
                }
                $customfield = array();
                $customfield["linksharetitle"] = $title;
                $customfield["linksharethumbnail"] = $thumb;
                $customfield["linkshareprice"] = $price;
                $customfield["lsmerchant"] = $merchantname;
                $itemcontent[$x]["unique"] = $unique;
                $itemcontent[$x]["title"] = $title;
                $itemcontent[$x]["content"] = $content;
                $itemcontent[$x]["customfield"] = $customfield;
                $x++;
            }
            if (empty($itemcontent)) {
                // Return error if no content has been found.
                $itemcontent["error"]["module"] = "Linkshare";
                $itemcontent["error"]["reason"] = "No content";
                $itemcontent["error"]["message"] = __("No (more) Linkshare items found.", "wprobot");
                return $itemcontent;
            } else {
                return $itemcontent;
            }
        } else {
            if (isset($pxml->Errors)) {
                // Check for API error messages in results and if found return them.
                $message = __('There was a problem with your API request. This is the error returned:', "wprobot") . ' <b>' . $pxml->Errors->ErrorText . '</b>';
                $itemcontent["error"]["module"] = "Linkshare";
                $itemcontent["error"]["reason"] = "API fail";
                $itemcontent["error"]["message"] = $message;
                return $itemcontent;
            } else {
                // Return error if no content has been found.
                $itemcontent["error"]["module"] = "Linkshare";
                $itemcontent["error"]["reason"] = "No content";
                $itemcontent["error"]["message"] = __("No (more) Linkshare items found.", "wprobot");
                return $itemcontent;
            }
        }
    }
}
Example #19
0
function wpr_shopzillapost($keyword, $num, $start, $optional = "", $comments = "")
{
    global $wpdb, $wpr_table_templates;
    if ($keyword == "") {
        // If keyword is empty return error
        $return["error"]["module"] = "Shopzilla";
        $return["error"]["reason"] = "No keyword";
        $return["error"]["message"] = __("No keyword specified.", "wprobot");
        return $return;
    }
    $template = $wpdb->get_var("SELECT content FROM " . $wpr_table_templates . " WHERE type = 'shopzilla'");
    if ($template == false || empty($template)) {
        // If module template is empty return error
        $return["error"]["module"] = "Shopzilla";
        $return["error"]["reason"] = "No template";
        $return["error"]["message"] = __("Module Template does not exist or could not be loaded.", "wprobot");
        return $return;
    }
    $x = 0;
    $itemcontent = array();
    $pxml = wpr_shopzillarequest($keyword, $num, $start);
    // Send API request
    if (!empty($pxml["error"])) {
        return $pxml;
    }
    if ($pxml === False) {
        $itemcontent["error"]["module"] = "Shopzilla";
        $itemcontent["error"]["reason"] = "Request fail";
        $itemcontent["error"]["message"] = __("API request could not be sent.", "wprobot");
        return $itemcontent;
    } else {
        if (isset($pxml->Products->Product)) {
            foreach ($pxml->Products->Product as $item) {
                $attrs = $item->attributes();
                $id = $attrs['id'];
                $title = $item->title;
                $description = $item->description;
                $manufacturer = $item->manufacturer;
                $url = $item->url;
                $thumb = $item->Images->Image[0];
                $detailurl = $item->detailUrl;
                $minprice = str_replace("\$", "\$ ", $item->PriceSet->minPrice);
                $maxprice = str_replace("\$", "\$ ", $item->PriceSet->maxPrice);
                if (isset($item->Offers->Offer)) {
                    $offertable = '<table class="offertable">';
                    foreach ($item->Offers->Offer as $offer) {
                        $offertable .= "<tr>";
                        $condition = $offer->condition;
                        $offerurl = $offer->url;
                        $price = str_replace("\$", "\$ ", $offer->price);
                        $shipamount = str_replace("\$", "\$ ", $offer->shipAmount);
                        $merchantname = $offer->merchantName;
                        $merchantlogo = $offer->merchantLogoUrl;
                        $offertable .= '<td style="padding:5px;"><a href="' . $offerurl . '" rel="nofollow"><strong>' . $merchantname . '</strong><br/><img src="' . $merchantlogo . '" /></a></td>';
                        //	$offertable .= "<td>$merchantname</td>";
                        $offertable .= "<td style=\"padding:5px;\">{$price}";
                        if (!empty($shipamount)) {
                            $offertable .= "<br/><small>+ {$shipamount} shipping</small>";
                        }
                        $offertable .= "</td>";
                        $offertable .= "</tr>";
                    }
                    $offertable .= "</table>";
                } else {
                    $offertable = "";
                }
                if ($thumb != "") {
                    $thumbnail = '<a href="' . $url . '" rel="nofollow"><img style="float:left;margin: 0 20px 10px 0;" src="' . $thumb . '" /></a>';
                } else {
                    $thumbnail = '';
                }
                $content = $template;
                $content = wpr_random_tags($content);
                $content = str_replace("{thumbnail}", $thumbnail, $content);
                $content = str_replace("{title}", $title, $content);
                $content = str_replace("{description}", $description, $content);
                $content = str_replace("{manufacturer}", $manufacturer, $content);
                $content = str_replace("{url}", $url, $content);
                $content = str_replace("{detailurl}", $url, $content);
                $content = str_replace("{minprice}", $minprice, $content);
                $content = str_replace("{maxprice}", $maxprice, $content);
                $content = str_replace("{offers}", $offertable, $content);
                $noqkeyword = str_replace('"', '', $keyword);
                $content = str_replace("{keyword}", $noqkeyword, $content);
                $content = str_replace("{Keyword}", ucwords($noqkeyword), $content);
                if (function_exists("wpr_translate_partial")) {
                    $content = wpr_translate_partial($content);
                }
                if (function_exists("wpr_rewrite_partial")) {
                    $content = wpr_rewrite_partial($content, $options);
                }
                $customfield = array();
                $customfield["shopzillatitle"] = $title;
                $customfield["shopzillaprice"] = $minprice;
                $customfield["shopzillathumbnail"] = $thumb;
                $itemcontent[$x]["unique"] = $id;
                $itemcontent[$x]["title"] = $title;
                $itemcontent[$x]["content"] = $content;
                $itemcontent[$x]["customfield"] = $customfield;
                $x++;
            }
            if (empty($itemcontent)) {
                // Return error if no content has been found.
                $itemcontent["error"]["module"] = "Shopzilla";
                $itemcontent["error"]["reason"] = "No content";
                $itemcontent["error"]["message"] = __("No (more) Shopzilla items found.", "wprobot");
                return $itemcontent;
            } else {
                return $itemcontent;
            }
        } else {
            if (isset($pxml->Products->Offer)) {
                // Check for API error messages in results and if found return them.
                $itemcontent["error"]["module"] = "Shopzilla";
                $itemcontent["error"]["reason"] = "IncNum";
                $itemcontent["error"]["message"] = __("Product skipped because Shopzilla returned no comparison data for it.", "wprobot");
                return $itemcontent;
            } elseif (isset($pxml->Message)) {
                // Check for API error messages in results and if found return them.
                $message = __('There was a problem with your API request. This is the error returned:', "wprobot") . ' <b>' . $pxml->Message . '</b>';
                $itemcontent["error"]["module"] = "Shopzilla";
                $itemcontent["error"]["reason"] = "API fail";
                $itemcontent["error"]["message"] = $message;
                return $itemcontent;
            } else {
                // Return error if no content has been found.
                $itemcontent["error"]["module"] = "Shopzilla";
                $itemcontent["error"]["reason"] = "No content";
                $itemcontent["error"]["message"] = __("No (more) Shopzilla items found.", "wprobot");
                return $itemcontent;
            }
        }
    }
}
Example #20
0
function wpr_post($camp_id, $keyword="", $retry=1, $manual=0) {
	global $wpdb, $wpr_table_campaigns, $wpr_table_posts, $wpr_table_errors;

	if($retry > 0) {$retrymsg = " <b>(".__("Retry","wprobot")." $retry)</b>";} else {$retrymsg = "";}	
	$time = current_time('mysql');	
	$errors = array();
	
    $options = unserialize(get_option("wpr_options"));	
	$result = $wpdb->get_row("SELECT * FROM " . $wpr_table_campaigns . " WHERE id = '$camp_id'"); 
	if($result->pause == 1 && $manual == 0) {return false;}

	// select KEYWORD
	$keywords = unserialize($result->keywords);
	if(!$keyword) {
		if(empty($keywords)) {
			// SAVE and DISPLAY error
			$esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
			$esql .= " ( '$camp_id', '$keyword', '', 'Inactive', ".__("'Post skipped because no keywords were found in the campaign.$retrymsg'", 'wprobot').", '$time' );";
			$results = $wpdb->query($esql);			
			return false;		
		}			
		// REMOVE KEYWORDS WHERE SKIPPED = 5 (better way without loop?)
		$keywords2 = $keywords;
		foreach($keywords as $key => $keyword) {
			if($keyword["skipped"] >= $options['wpr_err_disable'] && !$keyword["feed"]) {
				unset($keywords2[$key]);
			}
		}
		//echo "<pre>";print_r($keywords2);echo "</pre>";	
		//$keywords = array_values($keywords);		
		$rnd = array_rand($keywords2);
		$keyword = $keywords[$rnd][0];
		if($rnd === "" || $keyword === "" && !empty($keyword["feed"]) || !is_numeric($rnd)) {
			// SAVE and DISPLAY error
			$esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
			$esql .= " ( '$camp_id', '$keyword', '', 'Inactive', ".__("'No active keywords or feeds for this campaign, possibly because they were disabled due to repeated errors. Check the status and reenable them on the campaign detail page.$retrymsg'", 'wprobot').", '$time' );";
			$results = $wpdb->query($esql);			
			return false;		
		}		
	} else {
		foreach($keywords as $key => $kw) {
			if($kw[0] == $keyword) {
				$rnd = $key;
			}
		}
	}
	$keywordsbackup = $keywords[$rnd];

	// select CATEGORY
	$categories = unserialize($result->categories);
	if(!empty($categories[0]["id"])) {$categories = wpr_transform_cats($categories);}
	$catarray = array();
	if(count($categories) == 1) {
		foreach($categories[0] as $cats) {$catarray[] = $cats["id"];}		
		//$category = $categories[0]["id"];
	} else {
		foreach($categories[$rnd] as $cats) {$catarray[] = $cats["id"];}
		//$category = $categories[$rnd]["id"];	
	}	
	
	// select TEMPLATE
	$templates = unserialize($result->templates);
	$i = 1;
	foreach($templates as $tchance) {
		$tch[$i] = $templates[$i]["chance"];
		$i++;
	}
	
	$random = rand(1,100);
	foreach($tch as $name => $chance){
		$luck += $chance;
		if($random <= $luck && empty($templatenum)){
			$templatenum = $name;
		}
	} 	
	$template = $templates[$templatenum]["content"];
	
	$templateexcerpt = substr(strip_tags($template), 0, 130);
	$templateusedmsg = '<a target="_blank" class="tooltip" href="#">?<span>'.__('The template used for this post was: <strong>Post Template ',"wprobot").$templatenum.__('</strong>, starting with:<br/>',"wprobot").$templateexcerpt.__('<br/><br/><strong>If there was an error please check the associated module messages directly below this one!</strong>',"wprobot") .'</span></a>';

	// Wordpress action hook
	do_action('wpr_before_post', $insert); 	
	
	$content = $template;//echo $template."<br>";
	$noqkeyword = str_replace('"', '', $keyword);
	$content = str_replace("{keyword}", $noqkeyword, $content);
	$content = str_replace("{Keyword}", ucwords($noqkeyword), $content);	
	$content = str_replace("{title}", $title, $content);	
	$catreplace = get_category_link( $catarray[0] );
	if (!is_wp_error($catreplace)) {
	$content = str_replace("{catlink}", $catreplace, $content);	
	} else {$content = str_replace("{catlink}", "", $content);	}
	
	// AMAZON
	preg_match_all('#\{amazonlist(.*)\}#iU', $content, $matches, PREG_SET_ORDER);
	if ($matches) {
		foreach($matches as $match) {
			$match[1] = substr($match[1], 1);
			if($match[1]) {$amanum = $match[1];} else {$amanum = 1;}
			$amalist = wpr_amazon_getlist($keywords[$rnd][0],$amanum);
			if(isset($amalist["error"]) && is_array($amalist)) {$errors[] = $amalist["error"];$content = str_replace($match[0], "", $content);}
			$content = str_replace($match[0], $amalist, $content);				
		}
	}		
	// THUMBNAIL
	preg_match_all('#\{thumbnail(.*)\}#iU', $content, $matches, PREG_SET_ORDER);
	if ($matches) {
		foreach($matches as $match) {
			$match[1] = substr($match[1], 1);
			if($match[1]) {$tkw = $match[1];} else {$tkw = $keywords[$rnd][0];}
			$thumbnail = wpr_flickr_getthumbnail($tkw);
			if(!empty($thumbnail["error"])) {$errors[] = $thumbnail["error"];}
			$content = str_replace($match[0], $thumbnail[0]["content"], $content);				
		}
	}	
	// RANDOM Tags
	$content = wpr_random_tags($content);
	
	$title = $templates[$templatenum]["title"];
	$noqkeyword = str_replace('"', '', $keyword);
	$title = str_replace("{keyword}", $noqkeyword, $title);
	$title = str_replace("{Keyword}", ucwords($noqkeyword), $title);
	if(!empty($keywords[$rnd]["alternative"])) {
		$ll = 1;
		foreach($keywords[$rnd]["alternative"] as $alternative) {
			$content = str_replace("{keyword$ll}", $alternative, $content);	
			$title = str_replace("{keyword$ll}", $alternative, $title);
			$ll++;
		}
	}
	
	// RANDOM Tags
	$title = wpr_random_tags($title);

	$raz[0] = "{";$raz[1] = "}";
	preg_match_all("/\\".$raz[0]."[^\\".$raz[1]."]+\\".$raz[1]."/s", $content, $matches);
	$counts = array_count_values  (  $matches[0]  ); //echo $counts["{amazon}"];		
	$wpr_modulesnum = count($matches[0]);
	if($wpr_modulesnum <= 0) {
		// SAVE and DISPLAY error
		$esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
		$esql .= " ( '$camp_id', '$keyword', '', 'Inactive', ".__("'Post skipped because no modules were found in the template.$retrymsg'", 'wprobot').", '$time' );";
		$results = $wpdb->query($esql);			
		return false;		
	}		

	$usql = "INSERT INTO ".$wpr_table_posts." ( campaign, keyword, module, unique_id, time ) VALUES";
	// Get Content for each Module
	// ["content"] = Content of the item (replaced module template code)
	// ["title"] = Title of the item (i.e. Product title)
	// ["unique"] = Unique ID (i.e. ASIN)
	// ["comments"] = Possible comment content of the item (i.e. reviews)
	$contents = array();
	$commentsarray = array();
	$titleerror = 0;
	$duplicatecount = 0;
	$errorcount = 0;
	
	foreach($counts as $module => $count) {
		$modulname = str_replace(array("{","}"), "", $module);
		$function = "wpr_".$modulname."post";
		
		$optional = "";$comments = "";
		switch ($modulname) {
			case "amazon":
				$optional = array($result->amazon_department,$keywords[$rnd]["node"]);
				break;
			case "ebay":
				$optional = $result->ebay_cat;
				break;
			case "flickr":			
				$comments = $templates[$templatenum]["comments"]["$modulname"];
				break;
			case "youtube":
				$comments = $templates[$templatenum]["comments"]["$modulname"];
				break;
			case "yahooanswers":
				$optional = $result->yahoo_cat;
				$comments = $templates[$templatenum]["comments"]["$modulname"];
				break;	
			case "rss":
				$optional = $keywords[$rnd]["feed"];
				break;							
		}
		
		// GET CONTENT
		if(function_exists($function)) {
			$contents["$modulname"] = $function($keyword, $count, $keywords[$rnd][1]["$modulname"], $optional, $comments);
			if(!empty($contents["$modulname"]["error"])) {
				$errors[] = $contents["$modulname"]["error"];
				$errorcount = $errorcount + 1 * $counts["{".$modulname."}"];
			}
		} else {
			$title = str_replace("{".$modulname."title}", "", $title);
			$errors[] = array("module" => ucwords($modulname), "reason" => "Not Installed", "message" => __("$modulname is not installed on this weblog and has been skipped.", 'wprobot'));						
			$errorcount = $errorcount + 1;
		}
		
		// CONTENT REPLACE
		$$modulname = 0;
		$dupl = 0;
	
		foreach ($matches[0] as $element) {
			if($element=="{".$modulname."}") {
				$unique = $contents["$modulname"][$$modulname]["unique"];
				if($unique != "" || $modulname == "ebay" ) {	
					$dcheck = wpr_check_unique($unique);
					//echo "CHECK".$dcheck;
					if($options['wpr_check_unique_old'] == "Yes") {$dcheck2 = wpr_check_unique_old($contents["$modulname"][$$modulname]["title"]);} else {$dcheck2 = false;}
					if($dcheck == false && $dcheck2 == false) {
						$content = preg_replace('/\{'.$modulname.'\}/', $contents["$modulname"][$$modulname]["content"], $content, 1);
						if(!isset($contents["$modulname"]["error"]) ) {
							$unique = $wpdb->escape($unique);
							$ekeyword = $wpdb->escape($keyword);
							$usql .= " ( '$camp_id', '$ekeyword', '$modulname', '$unique', '$time' ),";
						}
						if($templates[$templatenum]["comments"]["$modulname"] == 1) {$commentsarray[] = $contents["$modulname"][$$modulname]["comments"];}
					} else {
						// DUPLICATE POST
						$dupl = 1;
						$duplicatecount++;
						$content = preg_replace('/\{'.$modulname.'\}/', "", $content, 1);	
						$errors[] = array("module" => ucwords($modulname), "reason" => "Duplicate", "message" => __("Skipping ", 'wprobot').ucwords($modulname).__(" module because the content has already been posted.", 'wprobot'));						
						$errorcount = $errorcount + 1;
					}
				}
				
				//echo "------------DEBUG START------------<br/>";
				//echo $dupl." DUPLICATE<br/>";
				//echo $contents["$modulname"]["error"]." ERROR<br/>";
				//echo $counts["{".$modulname."}"]." FIRST COUNT<br/>";
				//echo $$modulname." SECOND COUNT<br/>";
				// TITLE REPLACE	
				$titlecheck = strpos($title, "{".$modulname."title}");
				$titlecheck2 = strpos($title, "{title}");				
				$modulecheckvar = $$modulname + 1;
				if ($titlecheck !== false || $titlecheck2 !== false) {
					if ($counts["{".$modulname."}"] > $modulecheckvar && $dupl == 1 || $counts["{".$modulname."}"] > $modulecheckvar && !empty($contents["$modulname"]["error"])) {
						// Dont Replace Title because there is another title module item
					} elseif($counts["{".$modulname."}"] <= $modulecheckvar && $dupl == 1) {
						// Title Duplicate					
						$titleduplicate = 1;		
					} elseif($counts["{".$modulname."}"] <= $modulecheckvar && !empty($contents["$modulname"]["error"]) || $counts["{".$modulname."}"] <= $modulecheckvar && empty($contents["$modulname"][0]["title"])) {
						// Title Error
						$titleerror = 1;
					} else {
						// Replace Title
						$title = str_replace("{".$modulname."title}", $contents["$modulname"][$$modulname]["title"], $title);
						$title = str_replace("{title}", $contents["$modulname"][$$modulname]["title"], $title);	
					}
				}
				$$modulname++;				
			}		
		}	

		if($contents["$modulname"]["error"]["reason"] == "IncNum") {$incnum = 1;} else {$incnum = 0;}
		// INCREASE NUMS
		if(empty($contents["$modulname"]["error"]) || $contents["$modulname"]["error"]["reason"] == "IncNum") { // don't increase NUMs if ERROR for module
			$keywords[$rnd][1]["$modulname"] = $keywords[$rnd][1]["$modulname"] + $$modulname;

			// RESET POST COUNT
			if($keywords[$rnd][1]["$modulname"] > $options['wpr_resetcount'] && $options['wpr_resetcount'] != "no") {$keywords[$rnd][1]["$modulname"] = 0;}
			if($modulename == "ebay" && $keywords[$rnd][1]["$modulname"] > 50) {$keywords[$rnd][1]["$modulname"] = 0;}		
		}	
		$content = str_replace("{".$modulname."}","",$content);		
	}

	// check ERRORS
	//$errorsnum = count($errors);	
	$errorsnum = $errorcount;	
	$skip = 0;
	if(!empty($keywords[$rnd]["feed"])) {$errkeyword = "Feed";} elseif(!empty($keywords[$rnd]["node"])) {$errkeyword = "Node:".$keywords[$rnd]["node"];} else {$errkeyword = $wpdb->escape($keyword);}
	
	// EXCLUDE KEYWORDS Check $options["wpr_global_exclude"]
	$excludeskip = 0;
	$excludes = unserialize($result->excludekws);
	
	$globals = str_replace("\r", "", $options["wpr_global_exclude"]);
	$globals = explode("\n", $globals);
	$excludes = array_merge($excludes, $globals);
	
	if(!empty($excludes)) {
		foreach($excludes as $exclude) {
			if($exclude != "" && $exclude != " " ) {
				$excheck = stripos($content, $exclude);
				$texcheck = stripos($title, $exclude);
				if($excheck === false && $texcheck === false) {
				} else {
					$excludeskip = 1;	$errors = array();
					$errors[] = array("module" => "", "reason" => "Exclude", "message" => __("Skipping post because exclude keyword $exclude was found.$retrymsg $templateusedmsg", 'wprobot'), "time" => "$time");
					break;
				}
			}
		}
	}
	
	if($excludeskip == 0) {
		// MARK KEYWORD AS yellow, orange, etc
		$wpr_modulessuccess = $wpr_modulesnum - $errorsnum;
		$duplsuccess = $wpr_modulesnum - $duplicatecount;
		if($duplicatecount > $options["wpr_err_maxerr"] || $duplsuccess < $options["wpr_err_minmod"] || $titleduplicate == 1) { // DUPLICATE ERROR - WiTHOUT skipped INCREASE
			$errors[] = array("module" => "", "reason" => "Duplicate Content", "message" => __("Skipping post to prevent duplicate content.", 'wprobot')."$retrymsg $templateusedmsg", "time" => "$time");	
			$skip = 1;	
		} elseif($titleerror == 1) { 			
			if($incnum != 1) {$keywords[$rnd] = $keywordsbackup;}
			$keywords[$rnd]["skipped"] = $keywords[$rnd]["skipped"] + 1;
			$errors[] = array("module" => "", "reason" => "Post skipped", "message" => __("Skipping post because the main module (title module) returned an error.", 'wprobot')."$retrymsg $templateusedmsg", "time" => "$time");	
			$skip = 1;	
		} elseif($errorsnum > $options["wpr_err_maxerr"] || $wpr_modulessuccess < $options["wpr_err_minmod"]) {
			if($incnum != 1) {$keywords[$rnd] = $keywordsbackup;}		
			$keywords[$rnd]["skipped"] = $keywords[$rnd]["skipped"] + 1;
			$errors[] = array("module" => "", "reason" => "Post skipped", "message" => __("Skipping post because too many module errors were encountered.", 'wprobot')."$retrymsg $templateusedmsg", "time" => "$time");	
			$skip = 1;
		} else {
			$keywords[$rnd]["skipped"] = 0;	
		}	
	}		
		
	// SAVE ERRORS
	if($errorsnum > 0 || $excludeskip == 1 || $titleerror == 1) {
		$esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
		foreach($errors as $error) {
			$error["message"] = $wpdb->escape($error["message"]);
			$esql .= " ( '$camp_id', '$errkeyword', '".$error["module"]."', '".$error["reason"]."', '".$error["message"]."', '$time' ),";
		}
		$esql = substr_replace($esql ,";",-1);
		$results = $wpdb->query($esql);		
	}		
	
	// SKIP if EXCLUDE found, errors > MAXERRORS or modules < MINMODULES
	if($excludeskip == 1 || $skip == 1) {
		// - update campaign entry with new NUMS	

		$keywords = serialize($keywords);
		$keywords = $wpdb->escape($keywords);
		$sql = "UPDATE " . $wpr_table_campaigns . " SET `keywords` = '".$keywords."' WHERE `id` = '".$camp_id."'";
		$results = $wpdb->query($sql);		
		return false;
	}
	
    // SAVE IMAGES
	if($options['wpr_save_images'] == "Yes") {

		$allimages = wpr_findimages($content);
		$imageurls = $allimages[2];
		//echo "<pre>";print_r($allimages[2]);echo "</pre>";
		
		if(sizeof($imageurls)) {
			foreach($imageurls as $oldurl) {
				if(strpos($oldurl, plugin_basename( dirname(__FILE__) )) === false) {
					$newurl = wpr_saveimage($oldurl,$keyword);
					if($newurl) {$content = str_replace($oldurl, $newurl, $content);}	
				}
			} 
		}		
    }	
	
	// TRANSLATION
	if(function_exists("wpr_translate_partial")) {
		$title = wpr_translate_partial($title);
	}	
	$translation = unserialize($result->translation);
	if($translation["chance"] >= rand(1,100)) {
		if($translation["from"] != "no" && $translation["to1"] != "no") {
			$translationcontent = wpr_translate($content,$translation["from"],$translation["to1"],$translation["to2"],$translation["to3"]);
			//print_r($translationcontent);
			if($options["wpr_trans_titles"] == "yes") {
				$translationtitle = wpr_translate($title,$translation["from"],$translation["to1"],$translation["to2"],$translation["to3"]);
			}
			if(!empty($translationcontent["error"]["reason"])) {
				$esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
				$esql .= " ( '$camp_id', '$errkeyword', 'Translation', '".$translationcontent["error"]["reason"]."', '".$translationcontent["error"]["message"]."', '$time' );";
				$results = $wpdb->query($esql);		
				if($options['wpr_trans_fail'] == "skip") {
					$esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
					$esql .= " ( '$camp_id', '$errkeyword', '', 'Post skipped', '".__("Skipping post because translation failed ","wprobot")."$retrymsg $templateusedmsg', '$time' );";
					$results = $wpdb->query($esql);		
					return false;
				}
			} elseif(empty($translationcontent)) {
				$esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
				$esql .= " ( '$camp_id', '$errkeyword', 'Translation', 'Translation Failed', '".__("The post could not be translated.","wprobot")."', '$time' );";
				$results = $wpdb->query($esql);		
				if($options['wpr_trans_fail'] == "skip") {
					$esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
					$esql .= " ( '$camp_id', '$errkeyword', '', 'Post skipped', '".__("Skipping post because translation failed ","wprobot")."$retrymsg $templateusedmsg', '$time' );";
					$results = $wpdb->query($esql);		
					return false;
				}
			} else {
				$content = $translationcontent;
				if($options["wpr_trans_titles"] == "yes") {$title = $translationtitle;}
				if($translation["comments"] == 1) {$transcomments = 1;} else {$transcomments = 0;}
			}
		}
	}

	$yahoocat = unserialize($result->yahoo_cat);	
	if(!is_array($yahoocat)) {
		$yahoocat = array();
		$yahoocat["rw"] = 0;
		$yahoocat["ps"] = $result->yahoo_cat;
		$yahoocat["a"] = "";
	}
	
	// REWRITE
	if($yahoocat["rw"] == 1) {
		$rewriter = array();
		if($options['wpr_rewrite_active_tbs'] == 1 || $options['wpr_rewrite_active'] == "tbs" || $options['wpr_rewrite_active'] == "both") {
			$rewriter[] = "tbs";
		} if($options['wpr_rewrite_active_sc'] == 1 || $options['wpr_rewrite_active'] == "sc" || $options['wpr_rewrite_active'] == "both") {
			$rewriter[] = "sc";
		} if($options['wpr_rewrite_active_schimp'] == 1 || $options['wpr_rewrite_active'] == "schimp" || $options['wpr_rewrite_active'] == "both") {
			$rewriter[] = "schimp";
		} if($options['wpr_rewrite_active_ucg'] == 1 || $options['wpr_rewrite_active'] == "Yes" || $options['wpr_rewrite_active'] == "both") {
			$rewriter[] = "ucg";
		} if($options['wpr_rewrite_active_sr'] == 1) {
			$rewriter[] = "sr";
		} if($options['wpr_rewrite_active_wai'] == 1) {
			$rewriter[] = "wai";
		}
		
		$rand_key = array_rand($rewriter);
		if($rewriter[$rand_key] == "tbs") {
			$options['wpr_rewrite_active'] = "tbs";
		} elseif($rewriter[$rand_key] == "sc") {
			$options['wpr_rewrite_active'] = "sc";
		} elseif($rewriter[$rand_key] == "schimp") {
			$options['wpr_rewrite_active'] = "schimp";
		} elseif($rewriter[$rand_key] == "ucg") {
			$options['wpr_rewrite_active'] = "Yes";
		} elseif($rewriter[$rand_key] == "sr") {
			$options['wpr_rewrite_active'] = "sr";
		} elseif($rewriter[$rand_key] == "wai") {
			$options['wpr_rewrite_active'] = "wai";
		}

		//print_r($rewriter);echo "Rewriter: ".$rand_key . " ". $options['wpr_rewrite_active'] . "\n";
	}

	if($options['wpr_rewrite_active'] == "Yes" && $yahoocat["rw"] == 1) {
		// UCG
		if(empty($options['wpr_rewrite_email']) || empty($options['wpr_rewrite_key'])) {
			$esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
			$esql .= " ( '$camp_id', '$errkeyword', 'UCG Rewriter', 'UCG Rewriter', 'You need to enter your API Key and Email in the Options!', '$time' );";
			$results = $wpdb->query($esql);		
		} else {
			//echo "<br/><br/>-------orig-------------<br/><br/>".$content . "<br/><br/>---------rewrite----------<br/><br/>";//////////
			$rewrite = wpr_rewrite($content,$options['wpr_rewrite_level']);
			//echo $rewrite . "<br/><br/>--------------------<br/><br/>";	//////////
			if(!empty($rewrite["error"]["reason"])) {
				$esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
				$esql .= " ( '$camp_id', '$errkeyword', 'UCG Rewriter', '".$rewrite["error"]["reason"]."', '".$rewrite["error"]["message"]."', '$time' );";
				$results = $wpdb->query($esql);	
			} else {
				$content = $rewrite;
			}
		}
	} elseif($options['wpr_rewrite_active'] == "tbs" && $yahoocat["rw"] == 1) {
		// TBS
		if(empty($options['wpr_tbs_rewrite_pw']) || empty($options['wpr_tbs_rewrite_email'])) {
			$esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
			$esql .= " ( '$camp_id', '$errkeyword', 'TheBestSpinner', 'TheBestSpinner', 'You need to enter your TheBestSpinner email and password in the Options!', '$time' );";
			$results = $wpdb->query($esql);		
		} else {
			//echo "<br/><br/>-------orig-------------<br/><br/>".$content . "<br/><br/>---------rewrite----------<br/><br/>";//////////
			$rewrite = wpr_tbs_rewrite($content,$options['wpr_tbs_rewrite_email'],$options['wpr_tbs_rewrite_pw'],$options['wpr_tbs_spintxt'],$options['wpr_tbs_quality'],$keyword,$options['wpr_rewrite_protected']);
			//echo $rewrite . "<br/><br/>--------------------<br/><br/>";	//////////
			if(!empty($rewrite["error"]["reason"])) {
				$esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
				$esql .= " ( '$camp_id', '$errkeyword', 'TheBestSpinner', '".$rewrite["error"]["reason"]."', '".$rewrite["error"]["message"]."', '$time' );";
				$results = $wpdb->query($esql);	
			} else {			
				$content = $rewrite;
			//echo "<br/><br/>-------CONTENT-------------<br/><br/>".$content . "<br/><br/>---------CONTENT----------<br/><br/>";//////////				
			}	

			// REWRITE TITLE
			if($options['wpr_tbs_rewrite_title'] == "Yes") {			
				$rewritetitle = wpr_tbs_rewrite($title,$options['wpr_tbs_rewrite_email'],$options['wpr_tbs_rewrite_pw'],$options['wpr_tbs_spintxt'],$options['wpr_tbs_quality'],$keyword,$options['wpr_rewrite_protected']);
				if(!empty($rewritetitle["error"]["reason"])) {
					$esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
					$esql .= " ( '$camp_id', '$errkeyword', 'TheBestSpinner', '".$rewritetitle["error"]["reason"]."', '".$rewritetitle["error"]["message"]."', '$time' );";
					$results = $wpdb->query($esql);	
				} else {
					$title = $rewritetitle;
				}	
			}	
		}
	} elseif($options['wpr_rewrite_active'] == "sc" && $yahoocat["rw"] == 1) {
		// Spinnerchief
		if(empty($options['wpr_sc_rewrite_pw']) || empty($options['wpr_sc_rewrite_email'])) {
			$esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
			$esql .= " ( '$camp_id', '$errkeyword', 'SpinnerChief', 'SpinnerChief', 'You need to enter your SpinnerChief username and password in the Options!', '$time' );";
			$results = $wpdb->query($esql);		
		} else {
			//echo "<br/><br/>-------orig-------------<br/><br/><div>".$content . "</div><br/><br/>---------rewrite----------<br/><br/>";//////////
			$rewrite = wpr_sc_rewrite($content,$options['wpr_sc_rewrite_email'],$options['wpr_sc_rewrite_pw'],$options['wpr_sc_quality'],$keyword,$options['wpr_rewrite_protected'],$options['wpr_sc_port'], $options['wpr_sc_thesaurus']);
			//echo "<div>".$rewrite . "</div><br/><br/>--------------------<br/><br/>";	//////////
			if(!empty($rewrite["error"]["reason"])) {
				$esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
				$esql .= " ( '$camp_id', '$errkeyword', 'SpinnerChief', '".$rewrite["error"]["reason"]."', '".$wpdb->escape($rewrite["error"]["message"])."', '$time' );";
				$results = $wpdb->query($esql);	
			} else {			
				$content = $rewrite;
			//echo "<br/><br/>-------CONTENT-------------<br/><br/>".$content . "<br/><br/>---------CONTENT----------<br/><br/>";//////////				
			}	

			// REWRITE TITLE
			if($options['wpr_tbs_rewrite_title'] == "Yes") {
				$rewritetitle = wpr_sc_rewrite($title,$options['wpr_sc_rewrite_email'],$options['wpr_sc_rewrite_pw'],$options['wpr_sc_quality'],$keyword,$options['wpr_rewrite_protected'],$options['wpr_sc_port'], $options['wpr_sc_thesaurus']);
				if(!empty($rewritetitle["error"]["reason"])) {
					$esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
					$esql .= " ( '$camp_id', '$errkeyword', 'SpinnerChief', '".$rewritetitle["error"]["reason"]."', '".$rewritetitle["error"]["message"]."', '$time' );";
					$results = $wpdb->query($esql);	
				} else {
					$title = $rewritetitle;
				}	
			}	
		}
	} elseif($options['wpr_rewrite_active'] == "schimp" && $yahoocat["rw"] == 1) {
		// SpinChimp
		if(empty($options['wpr_schimp_rewrite_pw']) || empty($options['wpr_schimp_rewrite_email'])) {
			$esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
			$esql .= " ( '$camp_id', '$errkeyword', 'SpinnerChief', 'SpinnerChief', 'You need to enter your SpinnerChief username and password in the Options!', '$time' );";
			$results = $wpdb->query($esql);		
		} else {
			//echo "<br/><br/>-------orig-------------<br/><br/><div>".$content . "</div><br/><br/>---------rewrite----------<br/><br/>";//////////
			$rewrite = wpr_schimp_rewrite($content,$options['wpr_schimp_rewrite_email'],$options['wpr_schimp_rewrite_pw'],$options['wpr_schimp_quality'],$keyword,$options['wpr_rewrite_protected']);
			//echo "<div>".$rewrite . "</div><br/><br/>--------------------<br/><br/>";	//////////
			if(!empty($rewrite["error"]["reason"])) {
				$esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
				$esql .= " ( '$camp_id', '$errkeyword', 'SpinnerChief', '".$rewrite["error"]["reason"]."', '".$wpdb->escape($rewrite["error"]["message"])."', '$time' );";
				$results = $wpdb->query($esql);	
			} else {			
				$content = $rewrite;
			//echo "<br/><br/>-------CONTENT-------------<br/><br/>".$content . "<br/><br/>---------CONTENT----------<br/><br/>";//////////				
			}	

			// REWRITE TITLE
			if($options['wpr_tbs_rewrite_title'] == "Yes") {
				$rewritetitle = wpr_schimp_rewrite($title,$options['wpr_schimp_rewrite_email'],$options['wpr_schimp_rewrite_pw'],$options['wpr_schimp_quality'],$keyword,$options['wpr_rewrite_protected']);
				if(!empty($rewritetitle["error"]["reason"])) {
					$esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
					$esql .= " ( '$camp_id', '$errkeyword', 'SpinnerChief', '".$rewritetitle["error"]["reason"]."', '".$rewritetitle["error"]["message"]."', '$time' );";
					$results = $wpdb->query($esql);	
				} else {
					$title = $rewritetitle;
				}	
			}	
		}
	} elseif($options['wpr_rewrite_active'] == "sr" && $yahoocat["rw"] == 1) {
		// Spin Rewriter
		if(empty($options['wpr_sr_rewrite_pw']) || empty($options['wpr_sr_rewrite_email'])) {
			$esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
			$esql .= " ( '$camp_id', '$errkeyword', 'SpinRewriter', 'SpinRewriter', 'You need to enter your SpinRewriter email and password in the Options!', '$time' );";
			$results = $wpdb->query($esql);		
		} else {
			//echo "<br/><br/>-------orig-------------<br/><br/><div>".$content . "</div><br/><br/>---------rewrite----------<br/><br/>";//////////
			$rewrite = wpr_sr_rewrite($content,$options['wpr_sr_rewrite_email'],$options['wpr_sr_rewrite_pw'],$options['wpr_sr_quality'],$keyword,$options['wpr_rewrite_protected']);
			//echo "<div>".$rewrite . "</div><br/><br/>--------------------<br/><br/>";	//////////
			if(!empty($rewrite["error"]["reason"])) {
				$esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
				$esql .= " ( '$camp_id', '$errkeyword', 'SpinRewriter', '".$rewrite["error"]["reason"]."', '".$wpdb->escape($rewrite["error"]["message"])."', '$time' );";
				$results = $wpdb->query($esql);	
			} else {			
				$content = $rewrite;
			//echo "<br/><br/>-------CONTENT-------------<br/><br/>".$content . "<br/><br/>---------CONTENT----------<br/><br/>";//////////				
			}	

			// REWRITE TITLE
			if($options['wpr_tbs_rewrite_title'] == "Yes") {
				$rewritetitle = wpr_sr_rewrite($title,$options['wpr_sr_rewrite_email'],$options['wpr_sr_rewrite_pw'],$options['wpr_sr_quality'],$keyword,$options['wpr_rewrite_protected']);
				if(!empty($rewritetitle["error"]["reason"])) {
					$esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
					$esql .= " ( '$camp_id', '$errkeyword', 'SpinRewriter', '".$rewritetitle["error"]["reason"]."', '".$rewritetitle["error"]["message"]."', '$time' );";
					$results = $wpdb->query($esql);	
				} else {
					$title = $rewritetitle;
				}	
			}	
		}
	} elseif($options['wpr_rewrite_active'] == "wai" && $yahoocat["rw"] == 1) {
		// WordAI
		if(empty($options['wpr_wai_rewrite_pw']) || empty($options['wpr_wai_rewrite_email'])) {
			$esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
			$esql .= " ( '$camp_id', '$errkeyword', 'WordAI', 'WordAI', 'You need to enter your WordAI email and password in the Options!', '$time' );";
			$results = $wpdb->query($esql);		
		} else {
			//echo "<br/><br/>-------orig-------------<br/><br/><div>".$content . "</div><br/><br/>---------rewrite----------<br/><br/>";//////////
			$rewrite = wpr_wai_rewrite($content,$options['wpr_wai_rewrite_email'],$options['wpr_wai_rewrite_pw'],$options['wpr_wai_quality'],$keyword,$options['wpr_rewrite_protected']);
			//echo "<div>".$rewrite . "</div><br/><br/>--------------------<br/><br/>";	//////////
			if(!empty($rewrite["error"]["reason"])) {
				$esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
				$esql .= " ( '$camp_id', '$errkeyword', 'WordAI', '".$rewrite["error"]["reason"]."', '".$wpdb->escape($rewrite["error"]["message"])."', '$time' );";
				$results = $wpdb->query($esql);	
			} else {			
				$content = $rewrite;
			//echo "<br/><br/>-------CONTENT-------------<br/><br/>".$content . "<br/><br/>---------CONTENT----------<br/><br/>";//////////				
			}	

			// REWRITE TITLE
			if($options['wpr_tbs_rewrite_title'] == "Yes") {
				$rewritetitle = wpr_wai_rewrite($title,$options['wpr_wai_rewrite_email'],$options['wpr_wai_rewrite_pw'],$options['wpr_wai_quality'],$keyword,$options['wpr_rewrite_protected']);
				if(!empty($rewritetitle["error"]["reason"])) {
					$esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
					$esql .= " ( '$camp_id', '$errkeyword', 'WordAI', '".$rewritetitle["error"]["reason"]."', '".$rewritetitle["error"]["message"]."', '$time' );";
					$results = $wpdb->query($esql);	
				} else {
					$title = $rewritetitle;
				}	
			}	
		}
	}
	
	// REPLACES
	$replaces = unserialize($result->replacekws);
	if(!empty($replaces)) {	
		foreach($replaces as $replace) {
			if($replace["chance"] >= rand(1,100)) {
				$replace["from"] = trim($replace["from"]);
				$replace["to"] = trim($replace["to"]);
				if($replace["code"] == "1") {
					$content = str_replace($replace["from"], $replace["to"], $content);
					$title = str_replace($replace["from"], $replace["to"], $title);					
				} else {
					$content = str_replace(" ".$replace["from"], " ".$replace["to"], $content);
					$title = str_replace(" ".$replace["from"], " ".$replace["to"], $title);				
				}
			}
		}
	}
	
	// Wordpress action hook
	do_action('wpr_before_post_save', $content,$title,$catarray); 	
	
	// INSERT POST into db	
	$insert = wpr_insertpost($content,$title,$catarray,$yahoocat["ps"],$yahoocat["a"],"","",$yahoocat["pt"]);
	if (is_wp_error($insert)) {
		$errormessage = $insert->get_error_message();
		// SAVE and DISPLAY error
		$esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
		$esql .= " ( '$camp_id', '$errkeyword', '', 'Insert failed', ".__("'Wordpress Error: ", 'wprobot')."$errormessage $retrymsg $templateusedmsg', '$time' );";
		$results = $wpdb->query($esql);			
		return false;		
	} elseif(isset($insert)) {
		// - update campaign entry with new NUMS	
		$posts_created = $result->posts_created + 1;
		$keywords[$rnd][1]["total"] = $keywords[$rnd][1]["total"] + 1;	
		$keywords = serialize($keywords);
		$keywords = $wpdb->escape($keywords);
		$sql = "UPDATE " . $wpr_table_campaigns . " SET `keywords` = '".$keywords."', `posts_created` = '".$posts_created."' WHERE `id` = '".$camp_id."'";
		$results = $wpdb->query($sql);	

		// - save UNIQUE IDS to post table
		$usql = substr_replace($usql ,";",-1);
		$results = $wpdb->query($usql);	
		//echo $usql;echo "RES".$results;
		
		// - insert COMMENTS 
		wpr_insertcomments($insert,$commentsarray,"",$transcomments,$translation);
		
		// - insert CUSTOM FIELDS
		//if($counts["{amazon}"] > 0) {
		//	add_post_meta($insert, 'ma_amazonpost', $contents["amazon"][0]["unique"]);
		//}
			//add_post_meta($insert, 'wpr_keyword', $keyword);
				
		$customfield = unserialize($result->customfield);
		if(isset($customfield["name"])) {
			$customfields = array();
			$customfields[1]["name"] = $customfield["name"];
			$customfields[1]["value"] = $customfield["value"];
			$customfield = $customfields;
		}	
		if($yahoocat["t"] == 1 || !empty($customfield)) {
			if(!empty($contents["amazon"][0]["customfield"]["amazonthumbnail"]))
			{$ximage = $contents["amazon"][0]["customfield"]["amazonthumbnail"];
			} elseif(!empty($contents["commissionjunction"][0]["customfield"]["cjthumbnail"]))
			{$ximage = $contents["commissionjunction"][0]["customfield"]["cjthumbnail"];
			} elseif(!empty($contents["rss"][0]["customfield"]["rssimage"]))
			{$ximage = $contents["rss"][0]["customfield"]["rssimage"];
			} elseif(!empty($contents["flickr"][0]["customfield"]["flickrimage"]))
			{$ximage = $contents["flickr"][0]["customfield"]["flickrimage"];
			} elseif(!empty($thumbnail[0]["customfield"]["thumbnail"]))
			{$ximage = $thumbnail[0]["customfield"]["thumbnail"];
			} elseif(!empty($contents["youtube"][0]["customfield"]["youtubethumbnail"]))
			{$ximage = $contents["youtube"][0]["customfield"]["youtubethumbnail"];
			} elseif(!empty($contents["oodle"][0]["customfield"]["oodlethumbnail"]))
			{$ximage = $contents["oodle"][0]["customfield"]["oodlethumbnail"];
			} elseif(!empty($contents["shopzilla"][0]["customfield"]["shopzillathumbnail"]))
			{$ximage = $contents["shopzilla"][0]["customfield"]["shopzillathumbnail"];
			} elseif(!empty($contents["avantlink"][0]["customfield"]["avantlinkthumbnail"]))
			{$ximage = $contents["avantlink"][0]["customfield"]["avantlinkthumbnail"];
			} elseif(!empty($contents["pressrelease"][0]["customfield"]["prthumbnail"]))
			{$ximage = $contents["pressrelease"][0]["customfield"]["prthumbnail"];			
			} else {$ximage = "";}		
		
			if($options['wpr_save_images'] == "Yes" && !empty($ximage)) {
				if(strpos($ximage, plugin_basename( dirname(__FILE__) )) === false) {
					$newurl = wpr_saveimage($ximage,$keyword);
					if($newurl) {$ximage = $newurl;}					
				}
			}	

			$blogurl = get_bloginfo( "url" );
			$yimage = str_replace($blogurl."/","",$newurl);	
			//echo $ximage."<br>";	
		}
		
		for ($i = 1; $i <= count($customfield); $i++) {	
			$cfname = $wpdb->escape($customfield[$i]["name"]);
			$cfcontent = $customfield[$i]["value"];
			if($cfcontent != "" && $cfname != "") {

				$cfcontent = wpr_random_tags($cfcontent);
				$cfcontent = str_replace("{image}", $ximage, $cfcontent);
				$cfcontent = str_replace("{image-relative}", $yimage, $cfcontent);
				$cfcontent = str_replace("{keyword}", $keyword, $cfcontent);	

				// NEW CUSTOM FIELD REPLACE
				foreach($contents as $content) {
					if(!empty($content[0]["customfield"])) {
						foreach($content[0]["customfield"] as $key => $value) {
							$cfcontent = str_replace("{".$key."}", $value, $cfcontent);
						}
					}
				}
				
				$cfcontent = preg_replace('#\{(.*)\}#smiU', '', $cfcontent);
				$cfcontent = $wpdb->escape($cfcontent);
				if(!empty($cfcontent)) {add_post_meta($insert, $cfname, $cfcontent);}
			}
		}
		
		// Post Thumbnails
		if($yahoocat["t"] == 1 && !empty($ximage)) {
			$upload_dir = wp_upload_dir();
			$zimage = str_replace($upload_dir['baseurl']. "/","",$ximage);	
			//echo $zimage." ZIMAGE<br>";
			$post_thumbnail = wpr_insertpost($content,$title,$catarray,$yahoocat["ps"],$yahoocat["a"],$zimage,$insert);
			if(isset($post_thumbnail)) {
				add_post_meta($post_thumbnail, "_wp_attached_file", $zimage);

				list($width, $height) = getimagesize($ximage);
				$wpameta = array("file" => $zimage, "width" => $width, "height" => $height);
				//print_r($wpameta);
				add_post_meta($post_thumbnail, "_wp_attachment_metadata", serialize($wpameta));
				
				add_post_meta($insert, "_thumbnail_id", $post_thumbnail);
			}
		}
		
		/*
Array
(
[width] => 1001
[height] => 1500
[hwstring_small] => height='96' width='64'
[file] => 2011/01/la3-5-1500-001.jpg
[sizes] => Array
(
	[thumbnail] => Array
	(
	[file] => la3-5-1500-001-150x150.jpg
	[width] => 150
	[height] => 150
	)

)

)
		*/

		// Wordpress action hook
		do_action('wpr_after_post', $insert); 
		
		// - display success message IN OTHER FUNCTION
		$esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
		$esql .= " ( '$camp_id', '$errkeyword', '', 'Post created', ".__("'The post has been created successfully.", 'wprobot')."$retrymsg $templateusedmsg'".", '$time' );";
		$results = $wpdb->query($esql);		
		return true;
		
	} else {
		// SAVE and DISPLAY error
		$esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
		$esql .= " ( '$camp_id', '$errkeyword', '', 'Insert failed', ".__("'The post could not be inserted into the Wordpress database.", 'wprobot')."$retrymsg $templateusedmsg', '$time' );";
		$results = $wpdb->query($esql);			
		return false;
	}
}
Example #21
0
function wpr_amazonpost($keywords,$count,$start,$optional,$comments="") {
	global $wpdb,$wpr_table_templates;

	$searchindex = $optional[0];
	$browsenode = $optional[1];	
	if($searchindex == "") {$searchindex = "All";}
	
	if($keywords == "" && $browsenode  == "") {
		$return["error"]["module"] = "Amazon";
		$return["error"]["reason"] = "No keyword";
		$return["error"]["message"] = __("No keyword or BrowseNode specified.","wprobot");	
		return $return;	
	}

	$start2 = $start / 10;
	$start2 = (string) $start2; 
	$start2 = explode(".", $start2);
	$page=(int)$start2[0];	
	$page++;				
	$cnum=(int)$start2[1]; 
	
	$template = $wpdb->get_var("SELECT content FROM " . $wpr_table_templates . " WHERE type = 'amazon'");
	if($template == false || empty($template)) {
		$return["error"]["module"] = "Amazon";
		$return["error"]["reason"] = "No template";
		$return["error"]["message"] = __("Module Template does not exist or could not be loaded.","wprobot");
		return $return;	
	}		
	
	$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();
	$site = $options['wpr_aa_site'];	
	if($site == "us") {$site = "com";}
	if($site == "uk") {$site = "co.uk";} 	
	
	if($browsenode == "") {$browsenode = 0;}	

	while($added_post < $count) {
		if($searchindex == "All") {
		$pxml = wpr_aws_request($site, array(
		"Operation"=>"ItemSearch",
		"AssociateTag"=>$affid,
		"Keywords"=>$keywords,
		"SearchIndex"=>$searchindex,
		"MerchantId"=>"All",
		"ItemPage"=>$page,
		"ReviewSort"=>"-HelpfulVotes",
		"TruncateReviewsAt"=>"5000",
		"IncludeReviewsSummary"=>"False",
		"ResponseGroup"=>"Large"
		), $public_key, $private_key);	
		} elseif($browsenode != 0) {
		$pxml = wpr_aws_request($site, array(
		"Operation"=>"ItemSearch",
		"AssociateTag"=>$affid,
		"SearchIndex"=>$searchindex,
		"Keywords"=>$keywords,
		"BrowseNode"=>$browsenode,
		"MerchantId"=>"All",
		"ItemPage"=>$page,
		"ReviewSort"=>"-HelpfulVotes",
		"TruncateReviewsAt"=>"5000",
		"IncludeReviewsSummary"=>"False",
		"ResponseGroup"=>"Large"
		), $public_key, $private_key);					
		} else {
		$pxml = wpr_aws_request($site, array(
		"Operation"=>"ItemSearch",
		"AssociateTag"=>$affid,
		"Keywords"=>$keywords,
		"SearchIndex"=>$searchindex,
		"MerchantId"=>"All",
		"ItemPage"=>$page,
		"ReviewSort"=>"-HelpfulVotes",
		"TruncateReviewsAt"=>"5000",
		"IncludeReviewsSummary"=>"False",
		"ResponseGroup"=>"Large"
		), $public_key, $private_key);					
		}
		if(!empty($pxml["error"])) {return $pxml;}
		//echo "<pre>";print_r($pxml);echo "</pre>";

		if($count<=10){
			$count_this = $count;
		} else{
			$count_this = 10;
		}
		$rr=0;
		$yy=1;
		
		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 = '<p>'.__("There was a problem with your Amazon API request. This is the error Amazon returned:","wprobot").'</p>
			<p><i><b>'.$pxml->Error->Code.':</b> '.$pxml->Error->Message.'</i></p>';	
			$return["error"]["module"] = "Amazon";
			$return["error"]["reason"] = "API fail";
			$return["error"]["message"] = $message;	
			return $return;
		}	

		if (isset($pxml->Items->Request->Errors->Error->Code)) {
			$message = '<p>'.__("There was a problem with your Amazon API request. This is the error Amazon returned:","wprobot").'</p>
			<p><i><b>'.$pxml->Items->Request->Errors->Error->Code.':</b> '.$pxml->Items->Request->Errors->Error->Message.'</i></p>';
			$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(empty($item->MediumImage->URL) && empty($item->SmallImage->URL)) {$skipit = 1;}}	
				if($skip == "nodesc" || $skip == "nox") {if(empty($item->EditorialReviews->EditorialReview->Content)) {$skipit = 1;}}			
				/*
				if($skipit == 1 && $count == 1) {
					$return["error"]["module"] = "Amazon";
					$return["error"]["reason"] = "No content";
					$return["error"]["message"] = __("Product skipped because no image and/or description was found.","wprobot");	
					return $return;					
				}*/

				if ($rr<$count_this && $skipit == 0) {
					$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,'<br>');
						$desc = substr($desc, 0, $elength);
					}				
					
					$features = "";
					if (isset($item->ItemAttributes->Feature)) {	
						$features = "<ul>";
						foreach($item->ItemAttributes->Feature as $feature) {
							$posx = strpos($feature, "href=");
							if ($posx === false) {
								$features .= "<li>".$feature."</li>";		
							}
						}	
						$features .= "</ul>";				
					}
					
					$timg = $item->MediumImage->URL;
					if($timg == "") {$timg = $item->SmallImage->URL;}				
					$thumbnail = '<a href="'.$item->DetailPageURL.'" rel="nofollow"><img style="float:left;margin: 0 20px 10px 0;" src="'.$timg.'" /></a>';					
					$link = '<a href="'.$item->DetailPageURL.'" rel="nofollow">'.$item->ItemAttributes->Title.'</a>';	

					// REVIEWS -  Replace for Nov 11 API Change

					$product_review = $item->CustomerReviews->IFrameURL;
					$reviewsiframe = '<iframe style="margin-top: 10px;" src="'.$product_review.'" width="100%" height="450px"><p>Your browser does not support iframes.</p></iframe>';
					$revcontent = file_get_contents($product_review); 
					if (preg_match('~<body[^>]*>(.*?)</body>~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;
					}
					
					$content = $template;
		
					preg_match('#\[has_reviews\](.*)\[/has_reviews\]#smiU', $template, $check);
					if ($check[0] != false) {
						if($item->CustomerReviews->TotalReviews == "" || $item->CustomerReviews->TotalReviews == 0 || !$item->CustomerReviews->TotalReviews) {
							$content = str_replace($check[0], "", $content);
						}
					}	
					$content = str_replace(array("[has_reviews]","[/has_reviews]"), "", $content);		
					preg_match('#\[has_listprice\](.*)\[/has_listprice\]#smiU', $template, $matches);//print_r($matches);
					if ($matches[0] != false) {
						if($listprice == "" || !$listprice) {
							$content = str_replace($matches[0], "", $content);
						}
					}
					$content = str_replace(array("[has_listprice]","[/has_listprice]"), "", $content);
					
					$asin = $item->ASIN;
					$content = wpr_random_tags($content);				
					$content = str_replace("{title}", $item->ItemAttributes->Title, $content);
					$content = str_replace("{description}", $desc, $content);
					$content = str_replace("{features}", $features, $content);
					$content = str_replace("{thumbnail}", $thumbnail, $content);
					$content = str_replace("{smallimage}", $item->SmallImage->URL, $content);	
					$content = str_replace("{mediumimage}", $item->MediumImage->URL, $content);	
					$content = str_replace("{largeimage}", $item->LargeImage->URL, $content);
					$content = str_replace("{buynow}", '<a href="'.$item->DetailPageURL.'" rel="nofollow"><img src="'.$imagepath.'buynow-small.gif" /></a>', $content);		
					$content = str_replace("{buynow-big}", '<a href="'.$item->DetailPageURL.'" rel="nofollow"><img src="'.$imagepath.'buynow-big.gif" /></a>', $content);					
					$content = str_replace("{buynow-ger}", '<a href="'.$item->DetailPageURL.'" rel="nofollow"><img src="'.$imagepath.'buynow-ger.gif" /></a>', $content);					
					$content = str_replace("{price}", $price, $content);
					$content = str_replace("{listprice}", $listprice, $content);
					$savings = str_replace("$ ", "", $listprice) - str_replace("$ ", "", $price);
					$content = str_replace("{savings}", $savings, $content);
					$content = str_replace("{url}", $item->DetailPageURL, $content);	
					$content = str_replace("{avgrating}", $item->CustomerReviews->AverageRating, $content);	
					$content = str_replace("{reviewsnum}", $item->CustomerReviews->TotalReviews, $content);		
					$noqkeyword = str_replace('"', '', $keywords);
					$content = str_replace("{keyword}", $noqkeyword, $content);
					$content = str_replace("{Keyword}", ucwords($noqkeyword), $content);					
					$content = str_replace("{link}", $link, $content);
					$content = str_replace("{asin}", $asin, $content);
					$content = str_replace("{price-updating}", '[wpramaprice asin="'.$asin.'"]', $content);
					
					// rating
					if (strpos($content, "{rating}") != false) {			 
						$image = wpr_star_rating($item->CustomerReviews->AverageRating);
						$content = str_replace("{rating}",$image,$content);
					}	
					
					// reviews
					$content = str_replace("{reviews-url}", $product_review, $content);	
					//$content = str_replace("{reviews-iframe}", $reviewsiframe, $content);
					$content = str_replace("{reviews-iframe}", '[wpramareviews asin="'.$asin.'"]', $content);
					$content = str_replace("{reviews-noiframe}", $reviewsnoiframe, $content);					
					preg_match('#\{reviews(.*)\}#iU', $content, $rmatches);
					if ($rmatches[0] == false) {					
					} else {
						$content = str_replace($rmatches[0], $reviewsiframe, $content);				
					}	
					
					if(function_exists("wpr_translate_partial")) {
						$content = wpr_translate_partial($content);
					}
					
					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["amazonprice"] = $price;
					$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;
					$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;
}
Example #22
0
function wpr_clickbankpost($keyword,$num,$start,$optional="",$comments="") {
	global $wpdb,$wpr_table_templates;

	if($keyword == "") {
		$return["error"]["module"] = "Clickbank";
		$return["error"]["reason"] = "No keyword";
		$return["error"]["message"] = __("No keyword specified.","wprobot");
		return $return;	
	}
	
	$template = $wpdb->get_var("SELECT content FROM " . $wpr_table_templates . " WHERE type = 'clickbank'");
	if($template == false || empty($template)) {
		$return["error"]["module"] = "Clickbank";
		$return["error"]["reason"] = "No template";
		$return["error"]["message"] = __("Module Template does not exist or could not be loaded.","wprobot");
		return $return;	
	}			
	$options = unserialize(get_option("wpr_options"));
	$affid = $options['wpr_cb_affkey'];if ($affid == '') { $affid = 'lun4tic' ;}
	$keyword = str_replace( '"',"",$keyword );	
	$keyword = str_replace( " ","+",$keyword );
	$search_url = "http://www.clickbank.com/mkplSearchResult.htm?dores=true&includeKeywords=$keyword&firstResult=$start";
	$posts = array();

	// make the cURL request to $search_url
	if ( function_exists('curl_init') ) {
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_USERAGENT, 'Firefox (WindowsXP) - Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6');
		curl_setopt($ch, CURLOPT_URL,$search_url);
		curl_setopt($ch, CURLOPT_FAILONERROR, true);
		curl_setopt($ch, CURLOPT_AUTOREFERER, true);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
		curl_setopt($ch, CURLOPT_TIMEOUT, 45);
		$html = curl_exec($ch);
		if (!$html) {
			$return["error"]["module"] = "Clickbank";
			$return["error"]["reason"] = "cURL Error";
			$return["error"]["message"] = __("cURL Error Number ","wprobot").curl_errno($ch).": ".curl_error($ch);	
			return $return;
		}		
		curl_close($ch);
	} else { 				
		$html = @file_get_contents($search_url);
		if (!$html) {
			$return["error"]["module"] = "Clickbank";
			$return["error"]["reason"] = "cURL Error";
			$return["error"]["message"] = __("cURL is not installed on this server!","wprobot");	
			return $return;		
		}
	}

	// parse the html into a DOMDocument  

	$dom = new DOMDocument();
	@$dom->loadHTML($html);
	
	$xpath1 = new DOMXPath($dom);			
	$paras1 = $xpath1->query("//div[@id='results']//tr/td[@class='details']/h4/a");

	for ($i = 0;  $i < $paras1->length; $i++ ) {		//$paras->length
		if($i < $num) {
			$para1 = $paras1->item($i);
			$urlt = $para1->textContent;	

			if($urlt == '' | $urlt == null) {
				$posts["error"]["module"] = "Clickbank";
				$posts["error"]["reason"] = "No content";
				$posts["error"]["message"] = __("No (more) Clickbank products found.","wprobot");	
				return $posts;	
			} else {
				$url = $para1->getAttribute('href');
				$url = str_replace("zzzzz", $affid, $url);	

				$xpath2 = new DOMXPath($dom);
				$paras2 = $xpath2->query("//div[@id='results']//td[@class='details']//div[@class='description']");
					$para2 = $paras2->item($i);
					$description = $para2->textContent;	
					
				$xpath3 = new DOMXPath($dom);			
				$paras3 = $xpath3->query("//div[@id='results']//td[@class='details']//h4/a");
					$para3 = $paras3->item($i);
					$title = $para3->textContent;					
				
				$link = '<a rel="nofollow" href="'.$url.'">'.$title . '</a>';	

				$ff = $options['wpr_cb_filter'];
				$stop = 0;
				if($ff == "yes") {
					$pos = strpos($description, "Commission");
					if ($pos !== false) {$stop = 1;}				
					$pos = strpos($description, "commission");
					if ($pos !== false) {$stop = 1;}
					$pos = strpos($description, "affiliate");
					if ($pos !== false) {$stop = 1;}	
					$pos = strpos($description, "Affiliate");
					if ($pos !== false) {$stop = 1;}						
					$pos = strpos($description, "affiliates");
					if ($pos !== false) {$stop = 1;}						
				}								
				
				if($stop == 0) {				
					$post = $template;
					$post = wpr_random_tags($post);
					$post = str_replace("{link}", $link, $post);							
					$post = str_replace("{description}", $description, $post);
					$post = str_replace("{url}", $url, $post);	
					$noqkeyword = str_replace('"', '', $keyword);
					$post = str_replace("{keyword}", $noqkeyword, $post);
					$post = str_replace("{Keyword}", ucwords($noqkeyword), $post);				
					$post = str_replace("{title}", $title, $post);	
					if(function_exists("wpr_translate_partial")) {
						$post = wpr_translate_partial($post);
					}
					
					$posts[$i]["unique"] = $title;
					$posts[$i]["title"] = $title;
					$posts[$i]["content"] = $post;	
				}	
			}
		}
	}
	
	if(empty($posts)) {
		$posts["error"]["module"] = "Clickbank";
		$posts["error"]["reason"] = "No content";
		$posts["error"]["message"] = __("No (more) Clickbank ads found.","wprobot");	
		return $posts;			
	} else {
		return $posts;	
	}					
}
Example #23
0
function wpr_pressreleasepost($keyword, $num, $start, $optional = "", $comments = "")
{
    global $wpdb, $wpr_table_templates;
    if ($keyword == "") {
        $return["error"]["module"] = "Press Release";
        $return["error"]["reason"] = "No keyword";
        $return["error"]["message"] = __("No keyword specified.", "wprobot");
        return $return;
    }
    $template = $wpdb->get_var("SELECT content FROM " . $wpr_table_templates . " WHERE type = 'pressrelease'");
    if ($template == false || empty($template)) {
        $return["error"]["module"] = "Press Release";
        $return["error"]["reason"] = "No template";
        $return["error"]["message"] = __("Module Template does not exist or could not be loaded.", "wprobot");
        return $return;
    }
    $options = unserialize(get_option("wpr_options"));
    $posts = array();
    $keyword2 = $keyword;
    $keyword = str_replace(" ", "+", $keyword);
    $keyword = urlencode($keyword);
    $blist[] = "Mozilla/5.0 (compatible; Konqueror/4.0; Microsoft Windows) KHTML/4.0.80 (like Gecko)";
    $blist[] = "Mozilla/5.0 (compatible; Konqueror/3.92; Microsoft Windows) KHTML/3.92.0 (like Gecko)";
    $blist[] = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506; Media Center PC 5.0; .NET CLR 1.1.4322; Windows-Media-Player/10.00.00.3990; InfoPath.2";
    $blist[] = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; Dealio Deskball 3.0)";
    $blist[] = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; NeosBrowser; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
    $ua = $blist[array_rand($blist)];
    $page = $start / 25;
    $page = (string) $page;
    $page = explode(".", $page);
    $page = (int) $page[0];
    $page++;
    if ($page == 0) {
        $page = 1;
    }
    $prep = floor($start / 25);
    $numb = $start - $prep * 25;
    $search_url = "http://www.prweb.com/Search.aspx?Search-releases={$keyword}&start={$page}";
    // make the cURL request to $search_url
    if (function_exists('curl_init')) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_USERAGENT, 'Firefox (WindowsXP) - Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6');
        curl_setopt($ch, CURLOPT_URL, $search_url);
        curl_setopt($ch, CURLOPT_FAILONERROR, true);
        curl_setopt($ch, CURLOPT_AUTOREFERER, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, 45);
        $html = curl_exec($ch);
        if (!$html) {
            $return["error"]["module"] = "Press Release";
            $return["error"]["reason"] = "cURL Error";
            $return["error"]["message"] = __("cURL Error Number ", "wprobot") . curl_errno($ch) . ": " . curl_error($ch);
            return $return;
        }
        curl_close($ch);
    } else {
        $html = @file_get_contents($search_url);
        if (!$html) {
            $return["error"]["module"] = "Press Release";
            $return["error"]["reason"] = "cURL Error";
            $return["error"]["message"] = __("cURL is not installed on this server!", "wprobot");
            return $return;
        }
    }
    // parse the html into a DOMDocument
    $dom = new DOMDocument();
    @$dom->loadHTML($html);
    // Grab Product Links
    $xpath = new DOMXPath($dom);
    $paras = $xpath->query("//div[@id='releases']//h3//a");
    $x = 0;
    $end = $numb + $num;
    if ($end > $paras->length) {
        $end = $paras->length;
    }
    if ($end == 0 || $end == $numb) {
        $posts["error"]["module"] = "Press Release";
        $posts["error"]["reason"] = "No content";
        $posts["error"]["message"] = __("No (more) pressreleases found.", "wprobot");
        return $posts;
    }
    for ($i = $numb; $i < $end; $i++) {
        $para = $paras->item($i);
        if ($para == '' | $para == null) {
            $posts["error"]["module"] = "Press Release";
            $posts["error"]["reason"] = "No content";
            $posts["error"]["message"] = __("No (more) pressreleases found.", "wprobot");
            return $posts;
        } else {
            $target_url = $para->getAttribute('href');
            // make the cURL request to $search_url
            if (function_exists('curl_init')) {
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_USERAGENT, 'Firefox (WindowsXP) - Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6');
                curl_setopt($ch, CURLOPT_URL, $target_url);
                curl_setopt($ch, CURLOPT_FAILONERROR, true);
                curl_setopt($ch, CURLOPT_AUTOREFERER, true);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_TIMEOUT, 45);
                $html = curl_exec($ch);
                if (!$html) {
                    $return["error"]["module"] = "Press Release";
                    $return["error"]["reason"] = "cURL Error";
                    $return["error"]["message"] = __("cURL Error Number ", "wprobot") . curl_errno($ch) . ": " . curl_error($ch);
                    return $return;
                }
                curl_close($ch);
            } else {
                $html = @file_get_contents($target_url);
                if (!$html) {
                    $return["error"]["module"] = "Press Release";
                    $return["error"]["reason"] = "cURL Error";
                    $return["error"]["message"] = __("cURL is not installed on this server!", "wprobot");
                    return $return;
                }
            }
            // parse the html into a DOMDocument
            $dom = new DOMDocument();
            @$dom->loadHTML($html);
            // Grab Press Release Title
            $xpath1 = new DOMXPath($dom);
            $paras1 = $xpath1->query("//h1[@class='title']");
            $para1 = $paras1->item(0);
            $title = $para1->textContent;
            // Grab Press Release Summary
            $xpath1 = new DOMXPath($dom);
            $paras1 = $xpath1->query("//h2[@class='subtitle']");
            $para1 = $paras1->item(0);
            $summary = $para1->textContent;
            // Grab Press Release Thumbnail
            $xpath1 = new DOMXPath($dom);
            $paras1 = $xpath1->query("//div/div[@class='mediaBox']/div/img[@class='newsImage']");
            $para1 = $paras1->item(0);
            if (isset($para1)) {
                $imgurl = $para1->getAttribute('src');
            }
            if (!empty($imgurl)) {
                $thumbnail = '<img style="float:left;margin: 0 20px 10px 0;" src="' . $imgurl . '" />';
            } else {
                $thumbnail = "";
            }
            // Grab Press Release
            $xpath2 = new DOMXPath($dom);
            //$paras2 = $xpath2->query("//div/div[@class='fullWidth floatLeft dottedTop']");
            $paras2 = $xpath2->query("//div/div[@class='one content']/div[@class='fullWidth floatLeft dottedTop']");
            $para2 = $paras2->item(0);
            $string = $dom->saveXml($para2);
            //	$string = preg_replace('#\#\#\#(.*)#smiU', '', $string);
            //	$string = preg_replace('Share: (.*)#smiU', '', $string);
            //	$string = preg_replace('#PRWeb News Center(.*)#smiU', '', $string);
            //	$string = preg_replace('#Create Account(.*)#smiU', '', $string);
            //	$string = preg_replace('#(.*)Printer Friendly Version#smiU', '', $string);
            //	$string = preg_replace('#<h1 class="h1">(.*)</h1>#smiU', '', $string);
            $string = preg_replace('#<div(.*)<p class="releaseDateline">#smiU', '', $string);
            $string = preg_replace('#<div(.*)</div>#smiU', '', $string);
            $string = preg_replace('#<p style=\\"text-align: center; font-weight: bold; clear: both;\\">(.*)</p>#smiU', '', $string);
            $string = preg_replace('#<p style=\\"text-align: center;  font-weight: bold;clear:both\\">(.*)</p>#smiU', '', $string);
            $string = str_replace("clear:both", "", $string);
            $string = str_replace("clear: both", "", $string);
            $string = str_replace("]]>", '', $string);
            $string = str_replace('xml:lang="en" lang="en" xmlns="http://www.w3.org/1999/xhtml"&gt;', '', $string);
            $string = strip_tags($string, '<p><strong><b><br><i><img>');
            $string = str_replace("\$", "\$ ", $string);
            //$string = utf8_decode($string);
            if (function_exists('iconv')) {
                $string = iconv('UTF-8', 'ISO-8859-1//IGNORE', $string);
            }
            $pressreleasebody = $string;
            $pos2 = strpos($string, "301 Moved");
            if ($pos2 !== false) {
                $return["error"]["module"] = "Press Release";
                $return["error"]["reason"] = "IncNum";
                $return["error"]["message"] = __("Press release has been deleted or moved and was skipped.", "wprobot");
                return $return;
            }
            if (empty($pressreleasebody)) {
                $return["error"]["module"] = "Press Release";
                $return["error"]["reason"] = "No Content";
                $return["error"]["message"] = __("No press release found.", "wprobot");
                return $return;
            }
            //$title = utf8_decode($title);
            if (function_exists('iconv')) {
                $summary = iconv('UTF-8', 'ISO-8859-1//IGNORE', $summary);
            }
            if (function_exists('iconv')) {
                $title = iconv('UTF-8', 'ISO-8859-1//IGNORE', $title);
            }
            $post = $template;
            $post = wpr_random_tags($post);
            $post = str_replace("{pressrelease}", $pressreleasebody, $post);
            $post = str_replace("{summary}", $summary, $post);
            $post = str_replace("{thumbnail}", $thumbnail, $post);
            $noqkeyword = str_replace('"', '', $keyword2);
            $post = str_replace("{keyword}", $noqkeyword, $post);
            $post = str_replace("{Keyword}", ucwords($noqkeyword), $post);
            $post = str_replace("{title}", $title, $post);
            $post = str_replace("{url}", $target_url, $post);
            if (function_exists("wpr_translate_partial")) {
                $post = wpr_translate_partial($post);
            }
            if (function_exists("wpr_rewrite_partial")) {
                $post = wpr_rewrite_partial($post, $options);
            }
            $posts[$x]["unique"] = $target_url;
            $posts[$x]["title"] = $title;
            $posts[$x]["content"] = $post;
            $x++;
        }
    }
    return $posts;
}
Example #24
0
function wpr_rsspost($keyword="",$num,$start,$url,$comments="") {
   global $wpdb, $wpr_table_templates;

	$template = $wpdb->get_var("SELECT content FROM " . $wpr_table_templates . " WHERE type = 'rss'");
	if($template == false || empty($template)) {
		$return["error"]["module"] = "RSS";
		$return["error"]["reason"] = "No template";
		$return["error"]["message"] = __("Module Template does not exist or could not be loaded.","wprobot");
		return $return;	
	}	
	$options = unserialize(get_option("wpr_options"));	

	$kw = $keyword;
	$url = trim($url);
	$url2 = urldecode($url);
	$start = 0;
	$found = 0;

	if ( function_exists('curl_init') ) {
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Konqueror/4.0; Microsoft Windows) KHTML/4.0.80 (like Gecko)");
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_URL, $url2);
		curl_setopt($ch, CURLOPT_TIMEOUT, 60);
		$response = curl_exec($ch);
		if (!$response) {
			$return["error"]["module"] = "RSS";
			$return["error"]["reason"] = "cURL Error";
			$return["error"]["message"] = __("cURL Error Number ","wprobot").curl_errno($ch).": ".curl_error($ch);	
			return $return;
		}		
		curl_close($ch);
	} else { 				
		$response = @file_get_contents($url2);
		if (!$response) {
			$return["error"]["module"] = "RSS";
			$return["error"]["reason"] = "cURL Error";
			$return["error"]["message"] = __("cURL is not installed on this server!","wprobot");	
			return $return;		
		}
	}
    
    $therss = @simplexml_load_string($response);
	if (!$therss){
		$therss = @simplexml_load_file($url);
	}
	//echo "<pre>".print_r($therss)."</pre>";	
	if (empty($therss)) {
		$return["error"]["module"] = "RSS";
		$return["error"]["reason"] = "RSS Error";
		$return["error"]["message"] = __("RSS Feed could not be loaded or is empty!","wprobot");	
		return $return;		
	}
	

	$posts = array();

	if(isset($therss->entry)) {$fee = $therss->entry;$ffr="blogger";} 
	elseif(isset($therss->channel->item)) {$fee = $therss->channel->item;} 
	elseif(isset($therss->item)) {$fee = $therss->item;} 
	else {$fee = "stop";}

	if($ffr=="blogger") {
	$ctitle = $therss->title;			
	} else {
	$ctitle = $therss->channel->title;
	$clink = $therss->channel->link;
	$cdesc = $therss->channel->description;			
	}

	if($fee == "stop") {
		$return["error"]["module"] = "RSS";
		$return["error"]["reason"] = "Invalid Feed";
		$return["error"]["message"] = __("Invalid Feed","wprobot");	
		return $return;			
	} else {
		foreach ($fee as $item) {

			$allabort = 0;	
			$abort = 0;		
//print_r($item);
			$title = $item->title;
			$title = preg_replace('/[\r\n\s]+/xms', ' ', trim($title));
			$title = strip_tags($title);
		
			$guid = $item->guid;	


			
			$gattr = $guid->attributes();			
			if($gattr['isPermaLink'] != "false" && !empty($guid)) {$unguid = $guid;} else {$unguid = "";}

			if($ffr=="blogger") {
				$link = $item->link;
				$descr = $item->summary;
				$fullcontent = $item->content; 
				$date = $item->published;

				if($kw != "" && $options['wpr_rss_filter']=='yes') {
					$kw = str_replace('"', '', $kw);
					
					$kws = explode(" AND ", $kw);
					//print_r($kws);
					foreach($kws as $kwx) {
						$kw2 = " ".$kwx." ";
						//echo $kw2."<br>";
						$c1 = stripos($fullcontent, $kw2);
						$c2 = stripos($descr, $kw2);
						$c3 = stripos($title, $kw2);
						if($c1 != false || $c2 != false || $c3 != false) {
							//echo "keyword was found<br>";
							$abort = 0;
						} else {
							//echo "keyword was not found<br>";			
							$abort = 1;
							$allabort = 1;
						}						
					}
				}
				
				foreach ($item->link as $link) {
				
					$attr = $link->attributes();
					if($link['rel'] == "replies" && $link['type'] == "application/atom+xml") {$commentRss = $link['href'];}
					if($link['rel'] == "alternate") {$sourcelink = $link['href']; }		
//echo $sourcelink . "<br><br>";			print_r($link);		
				}							

			} else {
				$sourcelink = $item->link;	


				
				$descr = $item->description;
				$date = $item->pubDate;	

				$dc  = $item->children("http://purl.org/dc/elements/1.1/");
				$creator = (string) $dc->creator;
				
				$ccc = $item->children("http://purl.org/rss/1.0/modules/content/");
				$fullcontent = (string)trim($ccc->encoded);
				
				
				if($kw != "" && $options['wpr_rss_filter']=='yes') {
					$kw = str_replace('"', '', $kw);
					
					$kws = explode(" AND ", $kw);
					//print_r($kws);
					foreach($kws as $kwx) {
						$kw2 = " ".$kwx." ";
						//echo $kw2."<br>";
						$c1 = stripos($fullcontent, $kw2);
						$c2 = stripos($descr, $kw2);
						$c3 = stripos($title, $kw2);
						if($c1 != false || $c2 != false || $c3 != false) {
							//echo "keyword was found<br>";
							$abort = 0;
						} else {
							//echo "keyword was not found<br>";			
							$abort = 1;
							$allabort = 1;
						}						
					}
				}
				
				$wfw = $item->children("http://wellformedweb.org/CommentAPI/");
				$commentRss = $wfw->commentRss;	
				
				$enclosure = $item->enclosure["url"];
				
				$media = $item->children('http://search.yahoo.com/mrss/');
				if($media->player) {
					$attrs = $media->player->attributes();
					$mediaplayer = $attrs['url']; 					  
				}
				if($media->content) {							
					$attrs = $media->content->attributes();
					$mediacontent = $attrs['url']; 
					$mediatype = $attrs['type']; 
					$mediaheight = $attrs['height']; 
					$mediawidth = $attrs['width'];  
					$video ='
					<object width="'.$mediawidth.'" height="'.$mediaheight.'">
					<param name="movie" value="'.$mediacontent.'"></param>
					<embed src="'.$mediacontent.'" type="'.$mediatype.'" width="'.$mediawidth.'" height="'.$mediaheight.'"></embed>
					</object>';		
					}
				if($media->thumbnail) {								  
					$attrs = $media->thumbnail[0]->attributes();
					$mediathumbnail = $attrs['url']; 
				}	
			}
			
			if(!empty($unguid)) {$uid = $unguid;} else {$uid = $sourcelink;}	

			if($abort == 0 && $allabort == 0 && !wpr_check_unique($uid)) {
	
				$source = '<a rel="nofollow" href="'.$sourcelink.'">'.$ctitle.'</a>';						
				if($fullcontent != "" && $options['wpr_rss_content']=='full') {$content = $fullcontent;} else {$content = $descr;}
				
				if ($options['wpr_rss_striplinks']=='yes') {$content = wpr_strip_selected_tags($content, array('a','iframe','script'));}
				
				if($options['wpr_rss_content']=='trunc') {$content = substr($content,0,350). "...";}
				
				$post = $template;	
				$post = wpr_random_tags($post);
				$content = str_replace("$", "$ ", $content); 
				$content = str_replace("\n\r", " ", $content); 				
				$content = str_replace("\n", " ", $content); 
				$post = str_replace("{content}", $content, $post);			
				$post = str_replace("{source}", $source, $post);	
				$post = str_replace("{author}", $creator, $post);
				$noqkeyword = str_replace('"', '', $keyword);
				$post = str_replace("{keyword}", $noqkeyword, $post);
				$post = str_replace("{Keyword}", ucwords($noqkeyword), $post);			
				$post = str_replace("{url}", $sourcelink, $post);	
				$post = str_replace("{title}", $title, $post);	
				$post = str_replace("{mediacontent}", $video, $post);
				$post = str_replace("{mediathumbnail}", $mediathumbnail, $post);							
				$post = str_replace("{enclosure}", $enclosure, $post);					
					if(function_exists("wpr_translate_partial")) {
						$post = wpr_translate_partial($post);
					}		
					if(function_exists("wpr_rewrite_partial")) {
						$post = wpr_rewrite_partial($post,$options);
					}	
					
				if(!empty($mediathumbnail)) {$customfield = $mediathumbnail;} elseif(!empty($enclosure)) {$customfield = $enclosure;} else {$customfield = "";}	
					
					$customfield2 = array();
					$customfield2["rsstitle"] = $title;
					$customfield2["rssmediacontent"] = $video;
					$customfield2["rssenclosure"] = $enclosure;
					$customfield2["rsssource"] = $sourcelink;
					$customfield2["rssimage"] = $customfield;						
					
				$posts[$found]["unique"] = $uid;
				$posts[$found]["title"] = $title;
				$posts[$found]["content"] = $post;	
				$posts[$found]["customfield"] = $customfield2;
				
				$found++;
				
			}
	
			if ($found==$num){break;}
		}
	}			

	//print_r($posts);
	
	if($found > 0) {
		return $posts;		
	} elseif($abort == 1) {
		// error: no posts found for keywords
		$posts["error"]["module"] = "RSS";
		$posts["error"]["reason"] = "No content";
		$posts["error"]["message"] = __("No post found in RSS feed for keyword $kw","wprobot");	
		return $posts;					
	} elseif($found == 0) {
		// error: no posts found
		$posts["error"]["module"] = "RSS";
		$posts["error"]["reason"] = "No content";
		$posts["error"]["message"] = __("No unposted RSS items found!","wprobot");	
		return $posts;	
	} elseif(empty($posts)) {
		// error: no posts found
		$posts["error"]["module"] = "RSS";
		$posts["error"]["reason"] = "No content";
		$posts["error"]["message"] = __("No items found in this feed!","wprobot");	
		return $posts;		
	} else {
		// error: no posts found
		$posts["error"]["module"] = "RSS";
		$posts["error"]["reason"] = "No content";
		$posts["error"]["message"] = __("No items found in this feed!","wprobot");	
		return $posts;			
	}
}
Example #25
0
function wpr_articlepost($keyword,$num,$start,$optional="",$comments="") {
	global $wpdb,$wpr_table_templates;
	
	if($keyword == "") {
		$return["error"]["module"] = "Article";
		$return["error"]["reason"] = "No keyword";
		$return["error"]["message"] = __("No keyword specified.","wprobot");
		return $return;	
	}	
	
	$template = $wpdb->get_var("SELECT content FROM " . $wpr_table_templates . " WHERE type = 'article'");
	if($template == false || empty($template)) {
		$return["error"]["module"] = "Article";
		$return["error"]["reason"] = "No template";
		$return["error"]["message"] = __("Module Template does not exist or could not be loaded.","wprobot");
		return $return;	
	}		
	$options = unserialize(get_option("wpr_options"));
 	$posts = array();
	
	$keyword2 = $keyword;	
	$keyword = str_replace( " ","+",$keyword );	
	$keyword = urlencode($keyword);
	
	$blist[] = "Mozilla/5.0 (compatible; Konqueror/4.0; Microsoft Windows) KHTML/4.0.80 (like Gecko)";
    $blist[] = "Mozilla/5.0 (compatible; Konqueror/3.92; Microsoft Windows) KHTML/3.92.0 (like Gecko)";
    $blist[] = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506; Media Center PC 5.0; .NET CLR 1.1.4322; Windows-Media-Player/10.00.00.3990; InfoPath.2";
    $blist[] = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; Dealio Deskball 3.0)";
    $blist[] = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; NeosBrowser; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
    $ua = $blist[array_rand($blist)];	

	$page = $start / 15;
	$page = (string) $page; 
	$page = explode(".", $page);	
	$page=(int)$page[0];	
	$page++;	

	if($page == 0) {$page = 1;}
	$prep = floor($start / 15);
	$numb = $start - $prep * 15;

	$lang = $options['wpr_eza_lang'];
	if($lang == "en") {
		$search_url = "http://www.articlesbase.com/find-articles.php?q=$keyword&page=$page";
	} elseif($lang == "fr") {
		$search_url = "http://fr.articlesbase.com/find-articles.php?q=$keyword&page=$page";	
	} elseif($lang == "es") {
		$search_url = "http://www.articuloz.com/find-articles.php?q=$keyword&page=$page";
	} elseif($lang == "pg") {
		$search_url = "http://www.artigonal.com/find-articles.php?q=$keyword&page=$page";
	} elseif($lang == "ru") {
		$search_url = "http://www.rusarticles.com/find-articles.php?q=$keyword&page=$page";
	}

	// make the cURL request to $search_url
	if ( function_exists('curl_init') ) {
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_USERAGENT, 'Firefox (WindowsXP) - Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6');
		curl_setopt($ch, CURLOPT_URL,$search_url);
		curl_setopt($ch, CURLOPT_FAILONERROR, true);
		curl_setopt($ch, CURLOPT_AUTOREFERER, true);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
		curl_setopt($ch, CURLOPT_TIMEOUT, 45);
		$html = curl_exec($ch);
		if (!$html) {
			$return["error"]["module"] = "Article";
			$return["error"]["reason"] = "cURL Error";
			$return["error"]["message"] = __("cURL Error Number ","wprobot").curl_errno($ch).": ".curl_error($ch);	
			return $return;
		}		
		curl_close($ch);
	} else { 				
		$html = @file_get_contents($search_url);
		if (!$html) {
			$return["error"]["module"] = "Article";
			$return["error"]["reason"] = "cURL Error";
			$return["error"]["message"] = __("cURL is not installed on this server!","wprobot");	
			return $return;		
		}
	}	

	// parse the html into a DOMDocument  

	$dom = new DOMDocument();
	@$dom->loadHTML($html);

	// Grab Product Links  

	$xpath = new DOMXPath($dom);
	$paras = $xpath->query("//div//h3/a");
	
	$x = 0;
	$end = $numb + $num;
	
		if($paras->length == 0) {
			$posts["error"]["module"] = "Article";
			$posts["error"]["reason"] = "No content";
			$posts["error"]["message"] = __("No (more) articles found.","wprobot");	
			return $posts;		
		}	
	
	if($end > $paras->length) { $end = $paras->length;}
	for ($i = $numb;  $i < $end; $i++ ) {
	
		$para = $paras->item($i);
	
		if(empty($para)) {
			$posts["error"]["module"] = "Article";
			$posts["error"]["reason"] = "No content";
			$posts["error"]["message"] = __("No (more) articles found.","wprobot");	
			//print_r($posts);
			return $posts;		
		} else {
		
			$target_url = $para->getAttribute('href'); // $target_url = "http://www.articlesbase.com" . $para->getAttribute('href');		
			
			// make the cURL request to $search_url
			if ( function_exists('curl_init') ) {
				$ch = curl_init();
				curl_setopt($ch, CURLOPT_USERAGENT, 'Firefox (WindowsXP) - Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6');
				curl_setopt($ch, CURLOPT_URL,$target_url);
				curl_setopt($ch, CURLOPT_FAILONERROR, true);
				curl_setopt($ch, CURLOPT_AUTOREFERER, true);
				curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
				curl_setopt($ch, CURLOPT_TIMEOUT, 45);
				$html = curl_exec($ch);
				if (!$html) {
					$return["error"]["module"] = "Article";
					$return["error"]["reason"] = "cURL Error";
					$return["error"]["message"] = __("cURL Error Number ","wprobot").curl_errno($ch).": ".curl_error($ch);	
					return $return;
				}		
				curl_close($ch);
			} else { 				
				$html = @file_get_contents($target_url);
				if (!$html) {
					$return["error"]["module"] = "Article";
					$return["error"]["reason"] = "cURL Error";
					$return["error"]["message"] = __("cURL is not installed on this server!","wprobot");	
					return $return;		
				}
			}

			// parse the html into a DOMDocument  

			$dom = new DOMDocument();
			@$dom->loadHTML($html);
				
			// Grab Article Title 			
			$xpath1 = new DOMXPath($dom);
			$paras1 = $xpath1->query("//div/h1");
			$para1 = $paras1->item(0);
			$title = $para1->textContent;	

			// Grab Article	Syndicate Box
			//$xpath2 = new DOMXPath($dom);			
			//$paras2 = $xpath2->query("//textarea[@id='texttocopy']"); 
			//$para2 = $paras2->item(0);	
			//echo strip_tags($dom->saveXml($para2),'<p><strong><b><a><br>');			
			
			// Grab Article	
			$xpath2 = new DOMXPath($dom);
			//$paras2 = $xpath2->query("//div[@class='KonaBody']"); 
			$paras2 = $xpath2->query("//div[@class='article_cnt']/div[@class='KonaBody']"); 
			$para2 = $paras2->item(0);		
			$string = $dom->saveXml($para2);	
		
			$string = strip_tags($string,'<p><strong><b><a><br>');
			$string = str_replace('<div class="KonaBody">', "", $string);	
			$string = str_replace("</div>", "", $string);
			$string = str_replace("&nbsp;", "", $string);	
			if ($options['wpr_eza_striplinks']=='yes') {$string = wpr_strip_selected_tags($string, array('a','iframe','script'));}	
			//if($lang == "es") {$string = utf8_decode  (  $string  );	}		
			$articlebody .= $string . ' ';			

			// Grab Ressource Box	

			$xpath3 = new DOMXPath($dom);
			$paras3 = $xpath3->query("//div[@class='author_details']/p");		//$para = $paras->item(0);		
			
			$ressourcetext = "";
			for ($y = 0;  $y < $paras3->length; $y++ ) {  //$paras->length
				$para3 = $paras3->item($y);
				$ressourcetext .= $dom->saveXml($para3);	
			}	
			
			$ressourcetext .= '<br/>Article from <a href="'.$target_url.'">articlesbase.com</a>';
			
			$title = utf8_decode($title);
			
			// Split into Pages
			if($options['wpr_eza_split'] == "yes") {
				$articlebody = wordwrap($articlebody, $options['wpr_eza_splitlength'], "<!--nextpage-->");
			}
			
			$post = $template;
			$post = wpr_random_tags($post);
			$post = str_replace("{article}", $articlebody, $post);			
			$post = str_replace("{authortext}", $ressourcetext, $post);	
			$noqkeyword = str_replace('"', '', $keyword2);
			$post = str_replace("{keyword}", $noqkeyword, $post);
			$post = str_replace("{Keyword}", ucwords($noqkeyword), $post);				
			$post = str_replace("{title}", $title, $post);	
			$post = str_replace("{url}", $target_url, $post);
			
					if(function_exists("wpr_translate_partial")) {
						$post = wpr_translate_partial($post);
					}	
					
			$posts[$x]["unique"] = $target_url;
			$posts[$x]["title"] = $title;
			$posts[$x]["content"] = $post;				
			$x++;
		}	
	}	
	return $posts;
}
Example #26
0
function wpr_kontentmachinepost($keyword, $num, $start)
{
    if (empty($keyword)) {
        $return["error"]["module"] = "Big Content Search";
        $return["error"]["reason"] = "No keyword";
        $return["error"]["message"] = __("No keyword specified.", "wprobot");
        return $return;
    }
    $options = unserialize(get_option("wpr_options"));
    $template = "{article}";
    $x = 0;
    $bcontent = array();
    $pxml = wpr_kontentmachinerequest($keyword);
    if ($pxml->status == "error") {
        $bcontent["error"]["module"] = "Kontent Machine";
        $bcontent["error"]["reason"] = "Request fail";
        $bcontent["error"]["message"] = $pxml->message;
        return $bcontent;
    } elseif ($pxml === False) {
        $bcontent["error"]["module"] = "Kontent Machine";
        $bcontent["error"]["reason"] = "Request fail";
        $bcontent["error"]["message"] = __("API request could not be sent.", "wprobot");
        return $bcontent;
    } elseif (is_array($pxml) && !empty($pxml["error"]["message"])) {
        return $pxml;
    } elseif ($pxml->status == "success") {
        foreach ($pxml->result as $article) {
            $article2 = explode("[/WP-TITLE]", $article);
            $title = str_replace("[WP-TITLE]", "", $article2[0]);
            $article2 = $article2[1];
            $content = $template;
            $content = wpr_random_tags($content);
            $content = str_replace("{article}", $article2, $content);
            if (function_exists("wpr_translate_partial")) {
                $content = wpr_translate_partial($content);
            }
            if (function_exists("wpr_rewrite_partial")) {
                $content = wpr_rewrite_partial($content, $options);
            }
            $bcontent[$x]["unique"] = rand(0, 9999999);
            $bcontent[$x]["title"] = $title;
            $bcontent[$x]["content"] = $content;
            $x++;
        }
    }
    if (empty($bcontent)) {
        $bcontent["error"]["module"] = "Kontent Machine";
        $bcontent["error"]["reason"] = "No content";
        $bcontent["error"]["message"] = __("No (more) Kontent Machine items found.", "wprobot");
        return $bcontent;
    } else {
        return $bcontent;
    }
}