Here’s another one with some changes:
- &offline and &online parameters support following:
* chunkname
* @FILE:path/to/file
* @CODE:return value as text
- Added &usecurl [1/0] parameter to make it use curl to get the picture. Some servers don’t allow fopen for urls (like mine). There is still one limiting thing with this too, the curl has to follow redirects to get the picture, but if safe mode is enabled in your server, you cannot use that CURLOPT_FOLLOWLOCATION option.
<?php
// Copyright @ 2007, iamask (icq: 43471815), modified by doze
// For modxcms.com : [!icq? &icq=`43471815` &online=`online` &offline=`offline`!]
//
if (!function_exists('icqGetTemplate')) {
function icqGetTemplate($tpl){
global $modx;
$template = "";
if ($modx->getChunk($tpl) != "") {
$template = $modx->getChunk($tpl);
} else if(substr($tpl, 0, 6) == "@FILE:") {
$template = $this->get_file_contents($modx->config['base_path'].substr($tpl, 6));
} else if(substr($tpl, 0, 6) == "@CODE:") {
$template = substr($tpl, 6);
} else {
$template = FALSE;
}
return $template;
}
}
if (!function_exists('icqGet_file_contents')) {
function icqGet_file_contents($filename) {
// Function written at http://www.nutt.net/2006/07/08/file_get_contents-function-for-php-4/#more-210
// Returns the contents of file name passed
if (!function_exists('file_get_contents')) {
$fhandle = fopen($filename, "r");
$fcontents = fread($fhandle, filesize($filename));
fclose($fhandle);
} else {
$fcontents = file_get_contents($filename);
}
return $fcontents;
}
}
$icq=(isset($icq))? $icq : "43471815";
$offline=(isset($offline))? icqGetTemplate($offline) : "offline";
$online=(isset($online))? icqGetTemplate($online) : "online";
$usecurl=(isset($usecurl))? $usecurl : false;
$handle;
if ($usecurl) {
$tempfile = $modx->config['base_path'].'assets/cache/icq.temp';
$ch = curl_init("http://wwp.icq.com/scripts/online.dll?icq=$icq&img=5");
$handle = fopen ($tempfile, "w");
curl_setopt ($ch, CURLOPT_FILE, $handle);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_exec ($ch);
curl_close ($ch);
fclose ($handle);
$handle = fopen($tempfile, "rb");
} else {
$handle = fopen("http://wwp.icq.com/scripts/online.dll?icq=$icq&img=5", "rb");
}
$contentbig="";
while (!feof($handle)) {
$contentbig .= fread($handle, 1024);
}
fclose($handle);
if ($usecurl) {
unlink($tempfile);
}
if(strlen($contentbig)==141){
return $online;
} else {
return $offline;
}
?>