<?php
//------------------------------------------------------------------------
// CARDFOUNTAIN CF-ECARDS SCRIPT VERSION 3.2
//------------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////
// HERE WE'LL NEED TO GET THE CONFIGURATION FILE
//////////////////////////////////////////////////////////////////////////
require "config.php"; /* obtains your basic configuration settings */
require "compat.php"; /* tests for required specs, functions & globals */
//////////////////////////////////////////////////////////////////////////
// HERE WE'LL WORK OUT YOUR CURRENT SERVER AND SCRIPT INFORMATION VARS
//////////////////////////////////////////////////////////////////////////
if ($cf_compatible)
{
$cf_cur_host = $_SERVER[HTTP_HOST];
$cf_cur_user_ip = $_SERVER[REMOTE_ADDR];
$cf_cur_scrp_path = $_SERVER[SCRIPT_NAME];
$cf_cur_scrp_base = basename($_SERVER[SCRIPT_NAME]);
$cf_cur_directory = ereg_replace(quotemeta($cf_cur_scrp_base), "", $cf_cur_scrp_path);
if ($cf_cur_directory != "") /* get rid of any double back slashes and trim slashes */
{ // cures problems with double slashes causing directory location issues...
$cf_cur_directory = trim(ereg_replace("\/\/", "\/", $cf_cur_directory), " \\\/");
}
if ($cf_cur_directory != "") /* get rid of any double forward slashes and trim slashes */
{ // cures windows problems with doubles slashes causing directory location issues...
$cf_cur_directory = trim(ereg_replace("\\\\\\\\", "\/", $cf_cur_directory), " \\\/");
}
if ($cf_cur_directory != "") /* convert forward slashes to back slashes and trim slashes */
{ // adds compatibility for windows based servers where forward slashes may be used...
$cf_cur_directory = trim(ereg_replace("\\\\", "\/", $cf_cur_directory), " \\\/");
}
if ($cf_cur_directory != "") /* add a leading back slash if we are in a local directory */
{ // adds compatibility for root directory installs...
$cf_cur_directory = "/".$cf_cur_directory."";
}
}
//////////////////////////////////////////////////////////////////////////
// NOW WE'LL BUILD IMPORTANT VALUES FOR ISSUING THE CF SERVER REQUEST
//////////////////////////////////////////////////////////////////////////
if ($cf_compatible)
{ // l, aid, aiduip, and aidhost are all required here...
$cf_l = (trim(urldecode($_GET[cf_l])) != "") ? trim(urldecode($_GET[cf_l])) : "";
$cf_aid = (trim($cf_aid) != "") ? trim($cf_aid) : "000000"; /* set in config.php (optional) */
$cf_aiduip = ($cf_cur_user_ip != "") ? $cf_cur_user_ip : ""; /* remote user's IP address */
$cf_aidhost = "".$cf_cur_host."".$cf_cur_directory."/".$cf_cur_scrp_base."?cf_l=";
}
//////////////////////////////////////////////////////////////////////////
// NOW WE'LL SET THE VERSION NUMBER FOR THIS CF ECARDS SCRIPT
//////////////////////////////////////////////////////////////////////////
if ($cf_compatible)
{
/* this way we can notify you when there's a new version */
$cf_aidhost_version = "3.2"; /* current script version # */
}
//////////////////////////////////////////////////////////////////////////
// NOW WE'LL BUILD THE CF SERVER REQUEST BASED ON DIFFERENT SITUATIONS
//////////////////////////////////////////////////////////////////////////
if ($cf_l == "" && $cf_compatible)
{ // no location, get homepage content...
$cf_req = "?aid=".urlencode($cf_aid)."";
$cf_req .= "&aidhost_version=".urlencode($cf_aidhost_version)."";
$cf_req .= "&aiduip=".urlencode($cf_aiduip)."";
$cf_req .= "&aidhost=".urlencode($cf_aidhost)."";
$cf_req_url = "http://www.cardfountain.com/egreetings.php".$cf_req."";
}
else if (ereg("\?", $cf_l) && $cf_compatible)
{ // location with query string...
$cf_req = $cf_l; // ? already included...
$cf_req .= "&aid=".urlencode($cf_aid)."";
$cf_req .= "&aidhost_version=".urlencode($cf_aidhost_version)."";
$cf_req .= "&aiduip=".urlencode($cf_aiduip)."";
$cf_req .= "&aidhost=".urlencode($cf_aidhost)."";
$cf_req_url = "http://www.cardfountain.com".$cf_req."";
}
else if ($cf_compatible)
{ // location without query string...
$cf_req = $cf_l; // ? not included...
$cf_req .= "?aid=".urlencode($cf_aid)."";
$cf_req .= "&aidhost_version=".urlencode($cf_aidhost_version)."";
$cf_req .= "&aiduip=".urlencode($cf_aiduip)."";
$cf_req .= "&aidhost=".urlencode($cf_aidhost)."";
$cf_req_url = "http://www.cardfountain.com".$cf_req."";
}
/* -------------------------------------------------------------------- */
//////////////////////////////////////////////////////////////////////////
// START BUFFERING OUTPUT
//////////////////////////////////////////////////////////////////////////
ob_start(); // buffers output for later parsing...
//////////////////////////////////////////////////////////////////////////
// OPTIONAL HEADER ( EDIT THE header.php FILE TO CUSTOMIZE )
//////////////////////////////////////////////////////////////////////////
if ($cf_compatible)
{ // customized header...
require "header.php";
} // edit header.php to customize...
//////////////////////////////////////////////////////////////////////////
// GET THE DATA & CACHE IT ( ECARD DATA COMES FROM CARDFOUNTAIN )
//////////////////////////////////////////////////////////////////////////
if ($cf_compatible)
{
if ($cf_cache)
{ // cache enabled...
$cf_cache_dir = "cf-cache";
if (!is_dir($cf_cache_dir))
{ // create directory
@mkdir($cf_cache_dir, 0777);
}
else if (!is_writable($cf_cache_dir))
{ // set permissions
@chmod($cf_cache_dir, 0777);
}
if (is_dir($cf_cache_dir) && is_writable($cf_cache_dir))
{ // if we can write the cache...
$cf_cache_file = "".$cf_cache_dir."/".md5($cf_req_url)."";
if (!file_exists($cf_cache_file))
{ // and the cache does not exist...
$cf_ecards = @file_get_contents($cf_req_url);
if ($cf_ecards != "")
{ // if we have ecard output...
$cf_open_cache = @fopen($cf_cache_file, "w+");
if (@flock($cf_open_cache, LOCK_EX))
{ // if locked, write the cache...
@fwrite($cf_open_cache, $cf_ecards);
@flock($cf_open_cache, LOCK_UN);
} // release lock, close cache...
@fclose ($cf_open_cache);
} // add ecards to output...
echo $cf_ecards;
}
else
{ // if the cache already exists, check it's age...
$cf_last_cache = date("Y-m-d H:i:s", filemtime($cf_cache_file));
$cf_cache_expiration = date("Y-m-d H:i:s", mktime(date(H)-24, date(i), date(s), date(m), date(d), date(Y)));
if (strtotime($cf_cache_expiration) >= strtotime($cf_last_cache))
{ // if it's old, update the cache now...
$cf_ecards = @file_get_contents($cf_req_url);
if ($cf_ecards != "")
{ // if we have ecard output...
$cf_open_cache = @fopen($cf_cache_file, "w+");
if (@flock($cf_open_cache, LOCK_EX))
{ // if locked, write the cache...
@fwrite($cf_open_cache, $cf_ecards);
@flock($cf_open_cache, LOCK_UN);
} // release lock, close cache...
@fclose ($cf_open_cache);
} // add ecards to output...
echo $cf_ecards;
}
else
{ // we have a good cache, no connection needed...
$cf_ecards = @file_get_contents($cf_cache_file);
echo $cf_ecards; // add ecards to output...
}
}
}
else
{ // we can't write to the cache, no biggy...
$cf_ecards = @file_get_contents($cf_req_url);
echo $cf_ecards; // add ecards to output...
}
}
else
{ // caching is not enabled, no biggy...
$cf_ecards = @file_get_contents($cf_req_url);
echo $cf_ecards; // add ecards to output...
}
}
//////////////////////////////////////////////////////////////////////////
// OPTIONAL FOOTER ( EDIT THE footer.php FILE TO CUSTOMIZE )
//////////////////////////////////////////////////////////////////////////
if ($cf_compatible)
{ // customized footer...
require "footer.php";
} // edit footer.php to customize...
//////////////////////////////////////////////////////////////////////////
// GET OUTPUT FOR CONTENT PARSING
//////////////////////////////////////////////////////////////////////////
$cf_content = ob_get_contents();
//////////////////////////////////////////////////////////////////////////
// PARSE OUTPUT FOR TITLE, KEYWORDS, DESCRIPTION
//////////////////////////////////////////////////////////////////////////
preg_match("/<!\-\- description=\"(.*)\" \-\-\>/i", $cf_content, $cf_p_description);
preg_match("/<!\-\- keywords=\"(.*)\" \-\-\>/i", $cf_content, $cf_p_keywords);
preg_match("/<!\-\- title=\"(.*)\" \-\-\>/i", $cf_content, $cf_p_title);
//////////////////////////////////////////////////////////////////////////
// FILL TITLE, KEYWORDS, & DESCRIPTION VARS LOCALLY...
//////////////////////////////////////////////////////////////////////////
$cf_content = eregi_replace("%%title%%", $cf_p_title[1], $cf_content);
$cf_content = eregi_replace("%%keywords%%", $cf_p_keywords[1], $cf_content);
$cf_content = eregi_replace("%%description%%", $cf_p_description[1], $cf_content);
//////////////////////////////////////////////////////////////////////////
// END OUTPUT BUFFERING
//////////////////////////////////////////////////////////////////////////
ob_end_clean();
//////////////////////////////////////////////////////////////////////////
// DISPLAY OUTPUT
//////////////////////////////////////////////////////////////////////////
echo $cf_content;
?>