$v){ $_GET[$k] = rawurldecode(strip_tags($v)); } //------------------------------------------------------------------------------ // Extract product attributes from $_GET if available //------------------------------------------------------------------------------ if(isset($_GET["linkto"])) $linkto = $_GET['linkto']; if(isset($_GET["productid"])) $productid = $_GET['productid']; if(isset($_GET["product"])) $product = $_GET['product']; if(isset($_GET["tmbn_url"])) $tmbn_url = $_GET['tmbn_url']; //------------------------------------------------------------------------------ // Identify page to link // // If the linkto file is a physical ".html" file in the root directory use the linkto URL. // Otherwise try to find the best matching ".html" file in the root // If all else fails link to the home page. // //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ // Setup working elements //------------------------------------------------------------------------------ $root = getenv('DOCUMENT_ROOT'); if($root[strlen($root)-1]!=="/") $root.="/"; $host = "http://".$_SERVER["HTTP_HOST"]."/"; $url_info = parse_url($linkto); $img_info = parse_url($tmbn_url); //------------------------------------------------------------------------------ // If the linkto file is a physical ".html" file in the root directory use the linkto URL. //------------------------------------------------------------------------------ if((strpos($linkto,".html")!==false)){ if(is_file($root.$url_info["path"])) $link_URL = $host.$url_info["path"]; } //------------------------------------------------------------------------------ // If not found try a URL based on the product ID and product name //------------------------------------------------------------------------------ if($link_URL==""){ $product_url = str_replace(" ","-",$product); preg_replace("/[^0-9a-zA-Z_-]/","",$product_url); $product_url .= "-p-$productid.html"; if(is_file($host.$product_url)) $link_URL = $host.$product_url; } //------------------------------------------------------------------------------ // If not found search for an HTML file using the product ID only //------------------------------------------------------------------------------ if(($link_URL=="")&&($productid!=="")){ $d = dir($root); $search = $productid.".html"; while (false !== ($entry = $d->read())) { if(strpos($entry, $search)!==false) $url_list[]=$entry; } $d->close(); if(count($url_list)>0) $link_URL = $host.$url_list[0]; } //------------------------------------------------------------------------------ // If not found link to the referring page //------------------------------------------------------------------------------ if($link_URL=="") $link_URL = $linkto; //------------------------------------------------------------------------------ // Last resort: If not found link to the home page //------------------------------------------------------------------------------ if($link_URL=="") $link_URL = $host; //------------------------------------------------------------------------------ // Check that thumbnail image exists if defined in $_GET //------------------------------------------------------------------------------ if(isset($tmbn_url)){ if(is_file($root.$img_info["path"])) $image_URL = $tmbn_url; } //------------------------------------------------------------------------------ // Load target page and parse out product name and thumbnail if required //------------------------------------------------------------------------------ if(($product=="")||($image_URL=="")){ ob_start(); include ( $link_URL ); $html = ob_get_contents(); ob_end_clean(); } if($product==""){ // Extract product name preg_match("/(.*)<\/title>/iX",$html,$matches); $product = $matches[1]; } if($image_URL==""){ // Extract product image URL $match_string = "/<A href=\"#productdetail\"\>[^\>]*>/iX"; preg_match($match_string,$html,$matches); $match_string = "/src=[\"']([^(\"|')]*)/iX"; preg_match_all($match_string,$matches[0],$matches); $image_URL = trim($matches[1][0], "\"' "); } if(isset($html)) unset($html); // Unload target page //------------------------------------------------------------------------------ // Create output string //------------------------------------------------------------------------------ $output = ""; if($image_URL!=="") $output .= "<a href='$link_URL' target='_top'><img src='$image_URL' alt='$product' style='border: 0px;' /></a><p>"; $output .= "<a href='$link_URL' target='_top'>$product</a><p>"; $output .= "Available from <a href='http://www.heritagetoys.com/' target='_top'>Link to this</a><p>"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <?php //------------------------------------------------------------------------------ // Output comments //------------------------------------------------------------------------------ /* echo "\n\n<!--\n\n"; echo "root $root\n\n"; echo "Link to: $linkto\n\n"; echo "$url_info ";print_r($url_info);echo "\n\n"; echo "$query_string ";print_r($query_string);echo "\n\n"; echo "Product ID: $productid \n"; echo "$url_list ";print_r($url_list);echo "\n\n"; echo "Product name: $product \n"; echo "Image: $image_url \n"; echo "Product URL: $product_url \n"; echo "\n\n -->\n\n "; */ ?> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="robots" content="noarchive" /> <title>Link to <?php echo $product; ?>

Link to

Choose from the options below and link to this product from a blog, website, MySpace profile, forum...!

Option 1: Link for Email or IM

Option 2: Copy and paste HTML



Option 3: Image URL

What you'll see on your blog or website