There are a number of static functions and variables that you may find useful to use in your scripts which have been included in the common class.
Accessible via common::$Variable_Name
Adds a line to a log file for debugging purposes
Example
common::timeLog($str,$groupKey='default');
Check for a current cache file
Example
$output = common::getCacheFile($filesArray,$prefix,$folder,$extraVars,$otherFilesMTime,$ext,$refreshCache);
/*
$output = array(
'contents'=>(contents string or false),
'filename'=>(filename string),
'timestamp'=>(Unix timestamp [filemtime] of the cache file)
)
*/
Saves a string to a cache file with parameters for checking the cache again in future.
Example
common::saveCacheFile($filesArray,$prefix,$content,$folder,$extraVars,$otherFilesMTime,$ext);
Get a clean path instead of folder traversing statements
Example
$path = 'www/htdocs/../secret/';
$simplePath = common::simplePath($path);
//$simplePath = www/secret/
Returns an array of files matching a given regular expression in a given location
Example
$files = common::findFiles($path,$regex);
/*
$files = array(
array(
"path"=>(string),
"filename"=>(string)
),
array(
"path"=>(string),
"filename"=>(string)
)
)
*/
Will return a string rounded to the nearest second, minute, hour, day, month or year depending on how much time has elapsed. Similar behaviour to that on a Tweet when using Twitter.
Example
$ptime = strtotime("-27 hours");
$niceTime = common::time_elapsed_string($ptime);
//$niceTime = 1 day
Returns if a robot/spider is detected browsing your website.
Example
$isRobot = common::isBot();
//$isRobot = (boolean)
Returns a filesize and dynamically chooses what units to use (bytes,KB,MB,GB)
Example
$bytes = file_get_contents("/path/to/file");
$filesize = common::formatSizeUnits($bytes);
//$filesize = 1KB
Unsets any array keys that are false (boolean) recursively.
Example
$array = array(1, 2, false,array(3, false));
$newArray = common::stripFalseArray($array);
//$newArray = array(1, 2, array(3));
Performs a Curl request returning the contents and last modified time of multiple URLs
Example
$array = array("http://url.com/page","http://url2.com/file.js");
$fileTimes = common::getFileTimes($array);
/*
$fileTimes = array(
array(
"contents"=>(string),
"timestamp"=>(Unix timestamp)
),
array(
"contents"=>(string),
"timestamp"=>(Unix timestamp)
)
);
*/
Performs a Curl request returning the contents and last modified time of a single URLs
Example
$url = "http://url.com/page";
$fileTime = common::getFileTime($url);
/*
$fileTime = array(
"contents"=>(string),
"timestamp"=>(Unix timestamp)
);
*/
Add caching headers and detect/return a 301 header and empty page where applicable for a single file. It will also check any files that have been included to see if they have been modified.
Example
$file = "/var/www/bw.codes/htdocs/index.php";
$lastModified = common::pageCacheHeaders($file);
// The script may be terminated in this function. If not:
/*
$lastModified = (unix timestamp)
*/
Cleans a string for use in SEO friendly querystrings/clean URLs
Example
$itemName = "Yummy teapot";
$cleanName = common::querystringName($itemName);
/*
$cleanName = "yummy-teapot";
*/
Check all known server variables for the Client's IP address until a valid IP is found.
Example
$clientIP = common::getClientIP();
/*
$clientIP = 123.223.32.41;
*/