PDA

View Full Version : Integrating a Php Script into the CMPS


Polo
07-28-2004, 10:44 AM
Ok, i have a php script... wich is a simple one page coded store.. and I was wondering how I could integrate it into my cmps...

the code is the following..


// SET VARIABLES //

$start = '<!-- Start Main Content -->';
$end = '<!-- End Content, Start Footer Include -->';
$stores = 'god180'; //EDIT THIS VARIABLE TO BE A LIST OF YOUR STORES
$url = 'http://www.cafeshops.com/';
$item = $_GET['item'];

// WRITE CAFEPRESS JAVASCRIPT TO PAGE //
echo '<script language="JavaScript1.1" src="http://www.cafeshops.com/commonscripts.js"></script>';

if ($item) { // Script has been called with a specific item, bring up detail page.
$detail = $url . $item;

$fp = fsockopen ("www.cafeshops.com", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br>\n";
} else {
fputs ($fp, "GET /$item HTTP/1.0\r\nHost: www.cafeshops.com\r\nUser-Agent: MS Internet Explorer\r\n\r\n");
while (!feof($fp)) {
$content .= fgets($fp,1024);
}
fclose ($fp);
}


$null = eregi("$start(.*)$end", $content, $cparray);
$pattern = "/\/cp/";
$replacement = "http://www.cafeshops.com/cp";
$itemdetail = preg_replace($pattern, $replacement, $cparray[1]);

$largeImgPattern = "/<a href=\"\//";
$largeImgReplacement = "<a href=\"store.php?item=";
$itemdetail = preg_replace($largeImgPattern, $largeImgReplacement, $itemdetail);

// The next four lines aren't truly necessary. They 1)make the add to cart button pop up //
// in its own window with the keep shopping button returning you to your custom store //
// 2)add a view cart button (vey handy) and 3) change the link to the CP legal questions page //

$itemdetail = preg_replace("/<form method=\"post\" action=\"http:\/\/www.cafeshops.com\/cp\/addtocart.aspx\">/i", "<form method=\"post\" name=cart action=\"http://www.cafeshops.com/cp/addtocart.aspx?keepshopping=javascript:self.close()\" target=\"cartWin\">", $itemdetail);
$itemdetail = preg_replace("/<input type=\"submit\"/", "<input type=submit onClick=\"cartWin = window.open ('','cartWin','toolbar=yes,location=no,directories=no,status=yes,scrollbars=yes, resizable=yes,copyhistory=no,width=800,height=500'); cartWin.focus(); return true;\"", $itemdetail);
$itemdetail = preg_replace("/Value=\"Add to Cart\"><\/td>/", "Value=\"Add to Cart\" >&nbsp;&nbsp;&nbsp;<input type=image src=viewcart_btn.gif onClick=\"cartWin = window.open ('http://www.cafeshops.com/cp/viewcart.aspx','cartWin','toolbar=yes,location=no,directories=no,status=yes,scro llbars=yes,resizable=yes,copyhistory=no,width=800,height=500'); cartWin.focus(); return true;\"></td>", $itemdetail);
$itemdetail = preg_replace("/<a href=\"http:\/\/www.cafepress.comhttp:\/\/www.cafeshops.com/" , "<a href=\"http://www.cafepress.com", $itemdetail);

echo "<script>";
echo "function e (z, h, w, b, g) {";
echo "document.write('<div style=\"width:'+w+';height:'+h+';background:white url(http://zoom.cafepress.com/'+(z%10)+'/'+z+'_zoom.jpg) no-repeat center center;\"><img border=\"'+b+'\" class=\"imageborder\" src=\"http://www.cafeshops.com/cp/img/'+(g?'zoom':'spacer')+'.gif\" width=\"'+w+'\" height=\"'+h+'\"></div>')";
echo "}";
echo "</script>";

echo $itemdetail;
}
else { // No item was requested when script was called, show items from all stores in the $stores variable.
$allitems = $url . $stores;

// connect to CP
$reqheader = "GET /$stores HTTP/1.0\r\nHost: www.cafeshops.com\r\nUser-Agent: MS Internet Explorer\r\n\r\n";
$socket = @fsockopen("www.cafeshops.com", 80, &$errno, &$errstr);
if ($socket)
{
fputs($socket, $reqheader);
while (!feof($socket))
{
$content .= fgets($socket, 4096);
}
}
fclose($socket);

$null = eregi("$start(.*)$end", $content, $cparray);
$pattern = "/<a href=\"\//";
$replacement = "<a href=\"store.php?item=";
$storeitems = preg_replace($pattern, $replacement, $cparray[1]);
$storeitems = preg_replace("/\/cp\/img\/saletag.gif/", "http://www.cafeshops.com/cp/img/saletag.gif", $storeitems);
$storeitems = preg_replace("/\/cp\/img\/fathersday_prodtag.gif/", "http://www.cafeshops.com/cp/img/fathersday_prodtag.gif", $storeitems);
$storeitems = preg_replace("/\/cp\/popupsurvey.aspx/", "http://www.cafeshops.com/cp/popupsurvey.aspx", $storeitems);
echo $storeitems;
}
?>


what it does it integrates a cafepress store in your site.

I have this installed in my website but I would like to integrate it into a my cmps...

to view a demo of this script click here (http://www.God180.com/store.php)

and as you can see there is space to put your custom header and footer in your page... i want to konw how to integrate this script in the vbacmps because i know that if i learn how to do it, soon i will be able to incorporate more scripts like this one into vbadvancedcmps...

hope someone can help me... thanks in advance...

Brian
07-28-2004, 11:23 AM
Have you taken a look at this thread (http://www.vbadvanced.com/forum/showthread.php?t=1082)?

Our Sponsors
 

interfx
12-23-2004, 12:54 PM
Did you ever implement this into your site? I'm interested to seeing if this worked for you or not?