Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> RavenNuke(tm) v2.5x
Author Message
AndyB
Worker
Worker



Joined: Jun 03, 2004
Posts: 231
Location: Torrevieja, Spain

PostPosted: Sat May 05, 2012 1:26 pm Reply with quote

OK; following on from previous threads;

this is based on the "old" Amazon block that shipped with nuke; updated for php 5.xx and ravennuke 2.5x

Instructions:

1. Copy the code below and edit with your own cafepress ID.
2. Save the file as block-cafepress.php
3. Upload it to your "blocks" folder on your server
4. Create a folder called Cafepress within \root\images\ (the full folder will be something like \root\images\cafepress
5. Go to your cafepress account, and download the images of each product you wish to appear randomly within the block. Remember to save the image as the product_code.jpg (or .gif) Also remember to resize the images to fit within the block. (On my theme, the images are 110px wide)

An example of the above (for myself) is
user name: audifans
image name: 643331412.jpg
Location on server: /images/cafepress/643331412.jpg

This links to:
[ Only registered users can see links on this board! Get registered or login! ]

Code:
<?php


/***********************************************/
/* Ravennuke -Nuke EVOLVED                                          */
/* ===========================                                          */
/*                                                                      */
/* Copyright (c) 2001 by Francisco Burzi (fbc@mandrakesoft.com)         */
/* http://phpnuke.org                                                   */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/* based on the original amazon block. This is for Cafepress affiliates */
/* modified by 5/05/12 by Andy Bowskill. version 2.0 Tested & used on  */
/* ravennuke version 2.5. See it in action at [ Only registered users can see links on this board! Get registered or login! ]           */
/************************************************************************/

if ( !defined('BLOCK_FILE') ) {
    Header('Location: ../index.php');
    die();
}

/*********************************************************************/
/* To use this block you only need to download .jpg or .gif          */
/* images from cafepress.com and copy them to the /images/cafepress  */
/* directory, then edit the $cafepress_id variable to fit your ID    */
/* of the Associates program. If you don't change the ID, it will    */
/* not work!                                                         */
/*                                                                   */
/* You need to know that any image in the cafepress directory        */
/* has the same title name as its filename given by Cafepress. If    */
/* you don't know what this is, leave it as is or disable it.        */
/*********************************************************************/

$cafepress_id = "CHANGE_THIS";

mt_srand((double)microtime()*1000000);
$imgs = dir('images/cafepress');
while ($file = $imgs->read()) {
      if (preg_match("/gif/", $file) || preg_match("/jpg/", $file)) {
   $imglist .= "$file ";
    }
}
closedir($imgs->handle);
$imglist = explode(" ", $imglist);
$a = sizeof($imglist)-2;
$random = mt_rand(0, $a);
$image = $imglist[$random];
$asin = explode(".", $image);
$content = "<br><center><a href=\"http://www.cafepress.com/$cafepress_id.$asin[0]\" target=\"_blank\">";
$content .= "<img src=\"images/cafepress/$image\" border=\"0\" alt=\"\"><br><br></center>";

?>


Comments/ suggestions welcome. Thanks to the input from everyone who helped with this- similar changes can be made for Amazon (look for my other posts)


Last edited by AndyB on Sat May 05, 2012 4:52 pm; edited 1 time in total 
View user's profile Send private message
spasticdonkey
RavenNuke(tm) Development Team



Joined: Dec 02, 2006
Posts: 1693
Location: Texas, USA

PostPosted: Sat May 05, 2012 1:47 pm Reply with quote

cool thanks for sharing and i'll try it out when i get a chance. Note that you shouldn't be using preg_replace in there though. For a block this should do instead
Code:
if ( !defined('BLOCK_FILE') ) {

    Header('Location: ../index.php');
    die();
}


You can see some of the other methods for securing files from direct access at: [ Only registered users can see links on this board! Get registered or login! ]
 
View user's profile Send private message Visit poster's website
AndyB







PostPosted: Sat May 05, 2012 4:51 pm Reply with quote

there was a discussion about this in the other thread..... -only I'd tested this and it had worked....

I'll edit the code in my original post, if I can, to show your changes...

Edit: I edited my post (within the code section)- please re-check if ok Wink
 
AndyB







PostPosted: Sat May 05, 2012 4:59 pm Reply with quote

looked at the link; interesting read. I bought a load of books when I was made redundant in 2008 with the intention or learning php/ mysql; I never did (or get a job for 6 months!!!)- the books are good for reference (once every three years or so???) lol.

Guess they're WAY out of date now! Wink
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> RavenNuke(tm) v2.5x

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©