Safari: Read IT Books Online

Discussion in 'Affiliate Programs' started by webinv, Nov 23, 2005.

  1. #1
    Greetings,

    Is anybody else an affiliate for:

    http://safari.oreilly.com/affiliates/

    It is an excellent resources and they offer web services. The problem is that I understand how to use the web services, but I do not know how to get my affiliate code to correspond with the content. An example below shows how you can post the actual Table of Contents from a book, but when the visitor clicks on the link from the table of contents displayed it currently does not bring the affiliate id with it.

    Or, does anybody know of a Safari script similar to the free scripts that display the Amazon Marketplace, Clickbank Marketplace, and DMOZ from your own site?

    Example Clickbank: webmasterinvestments.com/store/search.php

    Example DMOZ: http://webmasterinvestments.com/dmoz/odp.php

    Thanks,

    -Jon


    Example: http://safari.oreilly.com/affiliates/affiliates.asp?p=example3

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>
    <head>
    <title>BookLab | Table of Contents</title>
    </head>

    <body>
    <div class="content">
    <h1>Table of Contents</h1>
    <?php
    // Set Local variables
    $safari_url = "http://safari.oreilly.com/xmlapi/";
    $view_type = "book";
    $isbn = $_GET['isbn'];
    $xml = "";
    $lasttitle = "";

    //Build Safari Request URL
    $url = "$safari_url?id=$isbn";

    //Get Amazon XML Results
    $aurl=fopen($url,"r");
    while (!feof ($aurl))
    $xml .= fgets($aurl, 4096);
    fclose ($aurl);

    //Fire up the built-in XML parser
    $parser = xml_parser_create();
    xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);

    //Set tag names and values
    xml_parse_into_struct($parser,$xml,$values,$index);

    //Close down XML parser
    xml_parser_free($parser);

    //Loop through the XML, setting values
    foreach ($index as $key=>$val) {

    // ** PRINT OUT BOOK DETAILS **

    if ($key == "book") {
    $books = $val;
    for ($b=0; $b < count($books); $b+=2) {
    $offset = $books[$b] + 1;
    $len = $books[$b + 1] - $offset;
    $bookdetail = array_slice($values, $offset, $len);
    $done = 0;
    for ($c=0; $c < count($bookdetail); $c++) {
    if ($done) { break; }
    $tag = $bookdetail[$c]["tag"];
    switch ($tag) {
    case "url":
    $url = $bookdetail[$c]["value"];
    break;
    case "title":
    $title = $bookdetail[$c]["value"];
    break;
    case "imprintname":
    $publisher = $bookdetail[$c]["value"];
    break;
    case "pubdate":
    $pubdate = $bookdetail[$c]["value"];
    break;
    case "imagemedium":
    $imagemedium = $bookdetail[$c]["value"];
    break;
    case "isbn":
    $isbn = $bookdetail[$c]["value"];
    break;
    case "pagenums":
    $pagenums = $bookdetail[$c]["value"];
    break;
    case "tableofcontents":
    $done = 1;
    break;
    }
    }
    echo "<h2>$title<br /><span class=\"author\">";
    echo "by Eric Newcomer</span></h2>";
    echo "<img style=\"margin:5px 5px 0px 0px;\" ";
    echo "src=\"$imagemedium\" border=\"0\" align=\"left\">";
    echo "Publisher : $publisher<br />";
    echo "Pub Date :$pubdate<br />";
    echo "ISBN : $isbn<br />";
    echo "Pages : $pagenums<br /><br />";
    }

    // ** PRINT OUT TABLE OF CONTENTS **

    } elseif ($key == "section") {
    $sections = $val;
    for ($i=0; $i < count($sections); $i+=2) {
    $offset = $sections[$i] + 1;
    $len = $sections[$i + 1] - $offset;
    $sectiondetail = array_slice($values, $offset, $len);
    for ($j=0; $j < count($sectiondetail); $j++) {
    $tag = $sectiondetail[$j]["tag"];
    switch ($tag) {
    case "url":
    $url = $sectiondetail[$j]["value"];
    break;
    case "title":
    $title = trim($sectiondetail[$j]["value"]);
    break;
    case "heading":
    if (isset($sectiondetail[$j]["value"])) {
    $heading = trim($sectiondetail[$j]["value"]);
    $heading = str_replace("Â", "", $heading);
    $heading .= "&nbsp;";
    } else {
    $heading = "";
    }
    break;
    case "type":
    if (isset($sectiondetail[$j]["value"])) {
    $type = $sectiondetail[$j]["value"];
    } else {
    $type = "";
    }
    break;
    }
    }
    if (($title != $lasttitle) && ($type != "")) {
    switch ($type) {
    case "section":
    echo '<div class="sub-section">';
    break;
    default:
    echo '<div class="section">';
    break;
    }
    echo "<a href=\"$url\">$heading$title</a></div>\n";
    }
    $lasttitle = $title;
    }
    }
    }
    ?>
    </body>
    </html>
     
    webinv, Nov 23, 2005 IP