Friday, May 25, 2007

PHP-Get TemplateMonster data

// For more information: visit http://www.templatemonster.com/webapi/
$num_records = 4;
$aff_link = "http://www.all4yourwebsite.com/";
$tm_url = "http://www.templatemonster.com/";
$tm_url .= "webapi/templates_screenshots4.php";
$param['last_added'] = "Yes"; // this value is case sensitive
$param['full_path'] = "true";
$param['order'] = "asc";
$param['sort_by'] = "date";
$param['filter'] = "1";
// add additional filters / parameters here
// building querystring from the parameters
$qs = "?";
foreach ($param as $key => $val) {
$qs .= $key."=".$val."&";
}
$qs = rtrim($qs, "&");
// now get the records from the TM webapi
$request_from = $tm_url.$qs;
$all_rows = file($request_from);
// now split the data for each row into an multi dim. array
for ($i = 0; $i < $num_records; $i++) {
$data[$i] = explode("\t", $all_rows[$i]);
}
$t_row = "
\n";
foreach ($data as $row) {
// read the information about more attr.
$id = $row[0];
$price = $row[1];
$all_images = explode(",", trim($row[15], "{}"));
$t_row .= "
\n";
$t_row .= "
\n";
foreach ($all_images as $img) {
if (preg_match("/-m.jpg$/", $img)) {
$thumb = $img;
}
}
$thumb_size = getimagesize($thumb);
$t_row .= " ";
$t_row .= "\n";
$t_row .= "
\n";
$t_row .= "
\n";
$t_row .= "

Price: $".$price."

\n";
$t_row .= "
\n";
}
$t_row .= "
";
// How to use? Just "echo $t_row" inside the documents body.
?>

Disclaimer: Any code or advice given is for instructional purposes only. We will not be responsible for any loss or damage caused by using this script.

No comments: