andy's php projects
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Script and site usage:
All of the scripts on this site are provided free for non-commerical, personal or non-profit use. If you find these scripts useful to you, appreciate the free support, or are just an all round nice person, then why not donate a little dosh? If you wish to use any of these in a commercial system, please refer to the payment plan.


Tutorial ...

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    php.amnuts.com Forum Index -> CafePress Box
View previous topic :: View next topic  
Author Message
hunnebal
Newbie


Joined: 06 Mar 2004
Posts: 6

PostPosted: Mon Mar 08, 2004 1:07 am    Post subject: Tutorial ... Reply with quote

Dear Andy and other guru, as I read thru the forum, I'm really interested with your program. How/where do I start? Is there configuration file I have to tweak? Do I need a database and initialize with my data first before I can see it working using the data I have?(BTW: I love the demo).

Thanks in advance

/Hunn
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Mon Mar 08, 2004 7:08 am    Post subject: Reply with quote

Hi Hunn,

The only thing you need to start with is a CafePress account. Do you have one of those? If so, that's all you really need. You don't need a database at all, because you don't even need to download anything from the CafePress website. If you want to cache the data (to make subsequent loading faster), then you'll need to add a directory and be able to make that writeable by the web server, but that shouldn't be tough at all.

Okay, so to begin with. The minimum amount of code you need to get the thing working is this:

PHP:
<?php

    
require_once 'class.cafepressbox.php';
    
$cp = new cafePressBox('your_cafepress_id');
    
$cp->displayItem(true);

?>


replacing 'your_cafepress_id' with, believe it or not, your CafePress id. Smile

That should display a random item with the standard template and do no caching of any data. The 'true' parameter in the 'displayItem' call makes the product a link to the product information page on CafePress.

If you want to cache information, do something like this:

PHP:
<?php

    
require_once 'class.cafepressbox.php';
    
$cp = new cafePressBox('your_cafepress_id');
    
$cp->setCacheDir('./cache');
    
$cp->setCacheTime(86400);
    
$cp->setCacheImages(true);
    
$cp->displayItem(true);

?>


Notice that I have added three new lines to set where I would like my data to be cached (this is the new directory you'll have to give web server write permission to), how long I want the cache to last for before refreshing (in seconds), and whether I also want to download the images and cache them, too.

If I cache the images, I also have the ability to resize them, like this:

PHP:
<?php

    
require_once 'class.cafepressbox.php';
    
$cp = new cafePressBox('your_cafepress_id');
    
$cp->setCacheDir('./cache');
    
$cp->setCacheTime(86400);
    
$cp->setCacheImages(true);
    
$cp->setResizeCachedImages(75);
    
$cp->displayItem(true);

?>


Which will resize the images I download and cache to be 75 pixels in width or height.

If you want to change the way the box looks, then you can easily do this by using the 'setTemplate' function, such as:

PHP:
<?php

    
require_once 'class.cafepressbox.php';
    
$cp = new cafePressBox('your_cafepress_id');
    
$cp->setCacheDir('./cache');
    
$cp->setCacheTime(86400);
    
$cp->setCacheImages(true);
    
$cp->setResizeCachedImages(75);
    
$cp->setTemplate('<div style="width:250px;">[TXT]</div><br>[IMG]');
    
$cp->displayItem(true);

?>


Teh template can look like anything, but you need the '[TXT]' and '[IMG]' strings in the template, as these will be replaced with the text and image from CafePress.

If you look at the code for the class, you should see some comments above each function. Read these to get some more insight into the code and to find out all the bits I didn't mention in this (hopefully) easy-to-follow introduction. Also, check out the demo code that comes with the class for a slightly more complex example (using different templates and changing the store id to read different products, and so on.)

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    php.amnuts.com Forum Index -> CafePress Box All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group