X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Link Bait on the Fly | SEO Marketing (https://forum.x-cart.com/showthread.php?t=31515)

davidsaldana 05-29-2007 06:29 PM

Link Bait on the Fly | SEO Marketing
 
This program creates "link bait on the fly", to each specific product. The html snippets will open in a new window.

Create linktothis.php in the xcart dir. (wherever the "yoursite" appears, you will need to change to your site)

linktothis.php:

Code:


<?php
//------------------------------------------------------------------------------
// Initialize
//------------------------------------------------------------------------------

        $linkto = "";
        $productid = "";
        $product = "";
        $tmbn_url = "";

        $link_URL = "";
        $image_URL = "";
       
//------------------------------------------------------------------------------
// Sanitize inputs
//------------------------------------------------------------------------------

foreach($_GET as $k => $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>(.*)<\/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.yoursite.com/' target='_top'>Your Link Output Keywords</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; ?></title>


        <style>
body {
        margin: 10px;
        margin-bottom: 0px;
}

body, p, div, label {
        font-family: verdana, helvetica, arial;
        font-size: 12px;
        padding: 0;
}

.wrap {
        margin:0;
        height: 620px;
        width: 900px;
        position:relative;
        left:0;
        top:0;
}




p {
        margin: 10px 0 5px 0;
}

input, textarea {
        padding: 3px;
}

input.permalink {
        margin-left: 25px;
        _margin-bottom: -5px;
        padding-right: 0px;
        _padding-right: 3px;
}

input.permalink, textarea {
        border: solid 1px #bad0d1;       
        margin: 0 0 15px 0;
}

#preview {
        position: absolute;
        left: 340px;
        top: 5px;
        text-align: center;
        padding: 0;
        margin: 0;
        width: 430px;
}

#previewBox {
        border: solid 0px #666;
        margin: 0px auto;
        padding: 30px 0 0 0;
        width: 300px;
        position: relative;
}

#previewImage {
        margin-bottom: 15px;
}

textarea {
        position: relative;
        top: -15px;
        margin-bottom: 0px;
        padding-bottom: 0px;
}

.option {
        margin-top: 0px;
        padding-top: 0px;
        font-weight: bold;
}

.message {
        font-size: 10px;
        margin: 5px;
        position: relative;
        top: -10px;
}

.suggestions {
        margin-top: 25px;
}

.share {
        font-weight: bold;
        margin-bottom: 5px;
        padding:10px;
        font-size:18px;
}

.shareDescription {
        margin-top: 0px;
        margin-bottom: 15px;
}

#option2 {
        position: relative;
}
ol li {
        margin:0px;
        font-size: 12px;
        padding:0px;
}
.permalink, #sourceHTML, #imageURL {
        width: 280px;
}


#pick {
        position:relative;
        top: 5px;
        left: 10px;
        width: 300px;
        padding: 10px;
        border: #bad0d1 solid 1px;
        margin:0;
}


</style>
       
       
<LINK rel="stylesheet" href="http://yoursite.com//store/skin1/skin1.css">
<LINK rel="stylesheet" href="http://yoursite.com//store/skin1/tabs.css">


</head>
<body onload="javascript:setvars()">

<center>
        <h1 style="background-image:url(http://www.yoursite.com/store/skin1/images/dialog_bg_n.gif)">Link to <?php echo $product; ?></h1>
</center>

<div class="wrap">
       
        <div id="pick">

                <p class="shareDescription">
                        Choose from the options below and link to this product from a blog, website, MySpace profile, forum...!
                </p>
               
                <p class="option">Option 1: Link for Email or IM</p>
                <input class="permalink" onclick="javascript:this.focus();this.select();" value="<?php echo $link_URL ?>" type="text" readonly="readonly">
               
                <p class="option">Option 2: Copy and paste HTML</p>
                <br />
                        <textarea id="sourceHTML" onclick="javascript:this.focus();this.select();" rows="7" readonly="readonly"><div style="text-align: center; line-height: 150%"><?php echo $output ?></div></textarea>
                <br />

                <p class="option">Option 3: Image URL</p>
                <input class="permalink" onclick="javascript:this.focus();this.select();" value="<?php echo $image_URL ?>" type="text" readonly="readonly">

        </div>

        <div id="preview">

                What you'll see on your blog or website</h2>

                <div id="previewBox">
                        <?php echo $output ?>
                </div>

        </div>

</div>
</div>
</body>
</html>


Wherever you want the "link to this link" place the following code on product.tpl in your skin1/customer/main folder

Code:

<P><A class="LinkToThis" href="javascript:void(0)" onClick="window.open('http://www.yoursite.com/store/linktothis.php?linkto='+escape(window.location.href),'','width=800,height=400,resizeable=true')">Link to this</a><!-- { $product.tmbn_url } --></P>

Audiolines 05-31-2007 07:26 AM

Re: Link Bait on the Fly | SEO Marketing
 
it just seems to be linking to my homepage.

also, how does the image link work?

check it out here:

http://www.audiolines.com/product.php?productid=15530&cat=0&page=1

davidsaldana 06-01-2007 01:25 PM

Re: Link Bait on the Fly | SEO Marketing
 
You have to change these lines of code inside the text:

$output .= "Available from <a href='http://www.yoursite.com/' target='_top'>Your Link Output Keywords</a><p>";


<LINK rel="stylesheet" href="http://yoursite.com//store/skin1/skin1.css">
<LINK rel="stylesheet" href="http://yoursite.com//store/skin1/tabs.css">

<center>
<h1 style="background-image:url(http://www.yoursite.com/store/skin1/images/dialog_bg_n.gif)">Link to <?php echo $product; ?></h1>
</center>

Basically anywhere where it says "yoursite", needs to be modified

You can see working version of this mod on our site (right above the save 15%):

http://www.mailboxixchange.com/store/product.php?productid=18674&cat=0&page=1

HWT 06-04-2007 06:29 AM

Re: Link Bait on the Fly | SEO Marketing
 
Quick question. I get pushed to my 404 page when I click on the "link to this" text link. Any ideas why?

davidsaldana 06-04-2007 06:44 AM

Re: Link Bait on the Fly | SEO Marketing
 
You have to change the text in the link to this link:

<P><A class="LinkToThis" href="javascript:void(0)" onClick="window.open('http://www.yoursite.com/store/linktothis.php?linkto='+escape(window.location.hre f),'','width=800,height=400,resizeable=true')">Lin k to this</a><!-- { $product.tmbn_url } --></P>

Make sure your site is in the text and that you do need to have the "store" directory

-DS

HWT 06-04-2007 06:52 AM

Re: Link Bait on the Fly | SEO Marketing
 
1 Attachment(s)
Quote:

Originally Posted by davidsaldana

Are the images and text coming up?
-DS


N
o. I get a quick glimpse of what looks like the proper url in the title bar, and then it pushes into the 404.


Perhaps I messed up the linktothis.php file?

Attachment 423

davidsaldana 06-04-2007 06:55 AM

Re: Link Bait on the Fly | SEO Marketing
 
I would make sure you need to have the /store/ directory. I am running this mod on 4.0.18 with no modification to the URL's. It will work for both the dynamic site and the html catalog.

HWT 06-04-2007 07:06 AM

Re: Link Bait on the Fly | SEO Marketing
 
Quote:

Originally Posted by davidsaldana
I would make sure you need to have the /store/ directory.


It's always the simple things that trip you up when you're moving too fast.

root dir installs need to get rid of the "/store" in the linktothis.php and url.

thanks.

Next I have to get it to display the images properly in 4.1.7.

vtonya 06-05-2007 02:04 PM

Re: Link Bait on the Fly | SEO Marketing
 
thank you for this mod David, but i have the same problem in x-cart 4.1.7

you can check it here under product image http://www.medsmarket.net/product.php?productid=46&cat=0&page=1&featured

davidsaldana 06-05-2007 02:09 PM

Re: Link Bait on the Fly | SEO Marketing
 
I am sorry, but I dont have 4.1.7. The only program I have is 4.0.18. I am sure it can be modified, but someone else will have to do it.
Hopefully they will post the changes!!
-David


All times are GMT -8. The time now is 05:51 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.