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

HWT 06-05-2007 02:24 PM

Re: Link Bait on the Fly | SEO Marketing
 
David,

Could you post the pieces that deal with the image. I'm not proficient enough to write this stuff, but I'm persistent enough and catch just enough to beat around until I find a solution.

Thanks!

HWT 06-05-2007 02:33 PM

Re: Link Bait on the Fly | SEO Marketing
 
vtonya,

you may want to change the link wording from "Available from Your Link Output Keywords" to "Available from MedsMarket"

You'll find that here:

Code:


//------------------------------------------------------------------------------
// 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>";
 
?>


Also, mine outputs the name of the product, and yours does not. ???

Have a look: http://www.heritagetoys.com/Boston-Red-Sox-Toy-Chest-pr-19598.html

vtonya 06-05-2007 02:42 PM

Re: Link Bait on the Fly | SEO Marketing
 
Thanks HWT, i did changes and fogot to paste my site name. Thank you.

Ys, we have the same problem, hope we will solve it soon.

davidsaldana 06-06-2007 08:03 AM

Re: Link Bait on the Fly | SEO Marketing
 
Just my two cents. I would take a look at this line of code:

Code:


if(isset($_GET["tmbn_url"])) $tmbn_url = $_GET['tmbn_url'];


The 4.1.8 program could have changed the name of the tumbnail. Check in your database to see what it is called. It seems to be grabing the rest of the information.

Good Luck

-DS

vtonya 06-06-2007 08:21 AM

Re: Link Bait on the Fly | SEO Marketing
 
In x-cart 4.1.7 in product_thubmnail.tpl there is the following code:

Quote:

{if $config.Appearance.show_thumbnails eq "Y"}<img{if $id ne ''} id="{$id}"{/if} src="{if $tmbn_url}{$tmbn_url}{else}{if $full_url}{$http_location}{else}{$xcart_web_dir}{/if}/image.php?type={$type|default:"T"}&amp;id={$produc tid}{/if}"{if $image_x ne 0} width="{$image_x}"{/if}{if $image_y ne 0} height="{$image_y}"{/if} alt="{$product|escape}" />{/if}


davidsaldana 06-06-2007 08:25 AM

Re: Link Bait on the Fly | SEO Marketing
 
That seems to be the same.

The problem could be with the following code:

Code:

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], "\"' ");


vtonya 06-06-2007 08:28 AM

Re: Link Bait on the Fly | SEO Marketing
 
Problem can be anywhere, the question is how to find it...

pig@pp 11-18-2008 10:12 AM

Re: Link Bait on the Fly | SEO Marketing
 
I got this to work correctly on our site by changing the "Link to this" code that is to be placed in product.tpl

Replaced this.

<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>

With this.

<P><A class="LinkToThis" href="javascript:void(0)" onClick="window.open('http://www.yoursite.com/store/linktothis.php?linkto=http://www.yoursite.com/store/product.php?productid={$product.productid}&tmbn_ur l={$product.tmbn_url}&product={$product.product|ur lencode|default:'#no_string_value_found'}','','wid th=800,height=400,resizeable=true')">Link to this</a></P>

davidsaldana 11-20-2008 05:12 PM

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

Originally Posted by pig@pp
I got this to work correctly on our site by changing the "Link to this" code that is to be placed in product.tpl

Replaced this.

<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>

With this.

<P><A class="LinkToThis" href="javascript:void(0)" onClick="window.open('http://www.yoursite.com/store/linktothis.php?linkto=http://www.yoursite.com/store/product.php?productid={$product.productid}&tmbn_ur l={$product.tmbn_url}&product={$product.product|ur lencode|default:'#no_string_value_found'}','','wid th=800,height=400,resizeable=true')">Link to this</a></P>


Nice Work.......I totally forgot about this post......Thanks for resurecting it..........I hope people get full use of it. Its a damn cool mod (especially for products geared towards a younger crowd)

-ds

davidsaldana 11-20-2008 06:01 PM

Re: Link Bait on the Fly | SEO Marketing
 
FYI, I doubt this will now work on 4.1.11, since they changed the call to the thumbnail.....I am assuming the code will need to be altered.

lash 11-05-2009 07:30 AM

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

Originally Posted by pig@pp
I got this to work correctly on our site by changing the "Link to this" code that is to be placed in product.tpl

Replaced this.

<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>

With this.

<P><A class="LinkToThis" href="javascript:void(0)" onClick="window.open('http://www.yoursite.com/store/linktothis.php?linkto=http://www.yoursite.com/store/product.php?productid={$product.productid}&tmbn_ur l={$product.tmbn_url}&product={$product.product|ur lencode|default:'#no_string_value_found'}','','wid th=800,height=400,resizeable=true')">Link to this</a></P>


Are you running this on a 4.1.9? It looks good.
Anyone knows if this integrates with a mod rewrite, for example the CDSEO?
With so many bloggers out there this is a pretty neat function that more ppl should use. This contributed code needs to get more attention..

lash 11-09-2009 05:35 AM

Re: Link Bait on the Fly | SEO Marketing
 
Ok, I have played around a bit with this mod.

So far I don't get the product picture to display in the pop up window like
pig@pp manage to on his site. I used his code but so far no picture.

Also the links is not rewritten, I don't get the clean URLs, but it works. I have CDSEO mod.

I also noticed that when clicking on a product link in the pop up window I get to the product page for that product on my site, but the size of my site is the same as the pop up window and you cannot open it any bigger. Of course this is just for me. I assume it is cause it is not opened in a new window. I see it work nicely for pig@pp. I might have some more altering to do.

But if anyone has some advice or a complete solution could perhaps post one here for others to use.


All times are GMT -8. The time now is 08:27 PM.

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