Mar
Automated Data Integration
One of the aspects of BHSEO with Affiliate Marketing in mind is data integration. This could be from RSS feeds to straight XML files, even just research on one product and finding offshoots yourself. I haven’t given away any “stunning” code lately (or any for that matter …) so I figured I’ll release a little source here to help you all along with automation. I’m going to keep the post here short and sweet, and let you all use your imagination with the code itself but I’ll give you a few unique uses for it.
Before I start telling you how to use it, here’s what you need – and what you may want to have.
What you NEED:
- PHP 5
- WordPress
- Desire to Learn and Think Abstractly
What you may want (and will help …)
Here’s a few things to think about with the code …
- This uses XMLRPC so will work with Splog Ping Crawl
- Can be integrated with Google Blog Search for avoiding duplicate content penalties *hint hint*
- Can be used full steam, throttled back, etc.
Now I’m going to admit this right now. It’s 3:15 in the morning right now and I’m tired as hell – but I did want to get this out because I promised a few of you I would get it done. So please forgive me if the code itself isn’t so clean, but my goal is purely to prove it can be done – and it’s not too hard to do either. My goal here on Contempt is to help you re-think about Automation in general and help you create ways to make your online endeavours much easier. For some Automation in general is considered blackhat, and to those people I’d like to remind them to wake up. Everything in life is getting automated whether you like it or not. Personally in my opinion blackhat seo is nothing other than a label for “holy shit that’s automatic”. Usually this is by people that don’t know how to do it, or have a problem looking at their newfound power and ability and can’t control it enough to not go overboard. This usually results in “i can spam links, go buy viagra go!”. It’s true – the same methods that I use sometimes could be used as an attempt to rank for buy viagra – and you know what, I’m sure with some time I could – but why? I want long term residual income off my endeavours, and right now I’m doing enough research to plan the methods down to successful ones so I don’t make stupid mistakes over and over on sites I’ve invested money into.
Anyway – like I said – It’s 3:30 so I’m ranting. Let’s move on. Here’s my overall goal with this post. In the following code I’m going to show you very simple code to extract information from a CSV, and how to format it into a good post for a review or shopping site. Here’s how you do that using PHP5 ..
<?php
$row = 1;
$handle = fopen("datafeed.csv", "r");
while (($data = fgetcsv($handle, 5000, ",")) !== FALSE) {
$num = count($data);
echo "<p> $num fields in line $row: <br /></p>\n";
$row++;
for ($c=0; $c < $num; $c++) {
echo "$c - ".$data[$c] . "<br />\n";
}
if($row > 5)
die();
}
fclose($handle);
?>I wrote this up quick to view the first 5 rows in a datafeed file. This’ll allow me to look at (with most feeds) the names of the fields, and then the first 4 lines to see sample data. This is an easy way to sort out “oh #5 is the URL” and “#10 is the image”. Next we’ll work on a template file so that when we post it to wordpress it’ll at least look decent. I’m not going to say my HTML is stellar, but I’m doing this as I write this so it’s purely an example. Here’s an example with a quick table, 2 sections – image and purchase URL on the left, description on the right … and of course, phpbay under it haha – Contempt style!
<?php
$row = 1;
$handle = fopen("datafeed.csv", "r");
while (($data = fgetcsv($handle, 5000, ",")) !== FALSE) {
$num = count($data);
echo "<p> $num fields in line $row: <br /></p>\n";
$row++;
$purchase_url = $data[8];
$image = $data[25];
$desc = $data[12];
$title = $data[16];
$var = "<center><table width=\"50%\"><tr><td>
<a href=\"$purchase_url\"><img src=\"$image\">
</a></td><td>$desc</td></tr></table><br><br>
Used Items:<br><br>[phpbay]$title, 10[/phpbay]";
echo $var."<BR><BR><BR><BR>";
if($row > 5)
die();
}
fclose($handle);
?>And just so you all have this, here’s the function that I use to post to WordPress blogs with XMLRPC. The external libs I’ll throw into a RAR (click here). Here’s the function:
<?php
function post_to_blog($url, $pass, $title, $posttext, $nick = null)
{
$xmlrpcurl = $url;
$client = new xmlrpc_client($xmlrpcurl);
$params[] = new xmlrpcval("n/a");
$params[] = new xmlrpcval("n/a");
if(isset($nick))
$params[] = new xmlrpcval("$nick"); //your wordpress login
else
$params[] = new xmlrpcval("Admin"); //your wordpress login
$params[] = new xmlrpcval("$pass"); //your wordpress password
$params[] = new xmlrpcval(
"<title>$title</title>". //the title of your post
"<category>1</category>". //the category
$posttext); //the body
$params[] = new xmlrpcval("true"); //publish now = true
$msg = new xmlrpcmsg("blogger.newPost",$params);
$response = $client->send($msg);
}
?>So yeah, when we put them together we have this…
<?php
$row = 1;
$handle = fopen("datafeed.csv", "r");
while (($data = fgetcsv($handle, 5000, ",")) !== FALSE) {
$num = count($data);
echo "<p> $num fields in line $row: <br /></p>\n";
$row++;
$purchase_url = $data[8];
$image = $data[25];
$desc = $data[12];
$title = $data[16];
$var = "<center><table width=\"50%\"><tr><td>
<a href=\"$purchase_url\"><img src=\"$image\">
</a></td><td>$desc</td></tr></table><br><br>
Used Items:<br><br>[phpbay]$title, 10[/phpbay]";
post_to_blog("http://myblog.com/xmlrpc.php", "password", $title, $var);
if($row > 5)
die();
}
fclose($handle);
function post_to_blog($url, $pass, $title, $posttext, $nick = null)
{
$xmlrpcurl = $url;
$client = new xmlrpc_client($xmlrpcurl);
$params[] = new xmlrpcval("n/a");
$params[] = new xmlrpcval("n/a");
if(isset($nick))
$params[] = new xmlrpcval("$nick"); //your wordpress login
else
$params[] = new xmlrpcval("Admin"); //your wordpress login
$params[] = new xmlrpcval("$pass"); //your wordpress password
$params[] = new xmlrpcval(
"<title>$title</title>". //the title of your post
"<category>1</category>". //the category
$posttext); //the body
$params[] = new xmlrpcval("true"); //publish now = true
$msg = new xmlrpcmsg("blogger.newPost",$params);
$response = $client->send($msg);
}
?>So there you have it. Loading a CSV file into wordpress with a template, to start up your own affiliate-based eStore. Once again I thank you for joining me on this Code-Enriched version of Contempt Can’t Sleep. I figured keeping this short and sweet would be more beneficial than posting with fluff and other dumb crap to try to impress you.
The reason I recommended phpBay is because of the fact that it’ll allow you to post direct links from PJN (PepperjamNetwork) or EPN (eBay Partner Network) with the new items. New & Used. The WFReview will actually allow people to rate the items, comment on them with star ratings, and post random generated ratings on them to make the site look like a good well traffic’d site. A must have for larger scale op’s and just fun in general! This also is an easier way to automate the CSV to WordPress operation. So once again, those links are in this paragraph if you wanted to try those out.
I hope you enjoyed the read as well as the Contempt experience, and I hope it’s worthy enough to have you pull the trigger on subscribing to the feed!
Trackbacks & Pingbacks
- Pingback by phpBay Pro and Wordpress-MU | Neglected Minds on July 22, 2009 @ 5:14 pm





(9 votes, average: 3.89 out of 5)



WFReview also contains a feature to import a CSV file against a template without any coding needed. It can read the category and posting date from the CSV or randomly select a future/past posting date in a date range you select.
Pretty slick stuff!
You could also either use an online tool or simply do it yourself with something like magpie, but turn the data form the cvs into an rss feed and manipulate it into your blog that way…
tie it up with the other feeds (category/main, etc..) from the site and now you’ve got a powerful list of every single link ready to be shared with the world….. ;p
great post
nice to see some raw code, looks like half my library’s!
:p
Great Post man. Time to test this for myself.
This is great stuff. I need to re-read this 4 or 5 times to make sure I know what the hell you’re talking about, but I think I get the idea.
Fucking awesome, as ever
Working on my own automated system. Been lookin for something on how to do xmlrpc with word-press. Although I’m taking a different approach, this could come handy in the future.
Rage9 – although i know folks like contempt here favor the incutio xml-rpc library u might also want to checkout the new version of the zend xml-rpc functions….for some use-cases it can speed shit up
Very nice.
Is xmlrpc_client() a standard function? I can seem to get the code to work and it keeps failing on that line. I check and php was compiled with xmlrpc extensions. I also check the php.net manual (http://us2.php.net/manual/en/ref.xmlrpc.php) and see no mention of xmlrpc_client() and ideas?
Ok… For anyone else who can’t call the xmlrpc_client() function.
I was confused. There is an xmlrpc php extension. This must be compiled with php and is not the same thing as the xmlrpc source forge project, which I think is what is being used in this example.
You can download the xmlrpc project from: http://phpxmlrpc.sourceforge.net/#download
Then simply inlude the file: xmlrpc.php and this tutorial will work.
We definitely see a great result using a mix of WfReview,phpBay and Phpzon.
For the content we use the new Amazon Scraper – Optimal Product Finder which allows us to either get the amazon products according to keywords, browse amazon’s catalog. It also allows the scraping of the top 10 best sellers, hot new items etc. We then download the resulting CSV and image folder list for further use in WFreview. We use the ASIN code within the PhpZon plugin and call another few data fields.
The tip with the xmlrpc.php is a great addition to my work.