src = $src; $this->read(); } } function read ($src = null) { if ( $src == null ) $src = &$this->src; if(strpos($src,'chatlog')){ $this->log_data = simplexml_load_file($src); echo "
"; print_r($this->log_data); echo ""; }else{ $this->log_data = $this->load_file($src); } $this->get_info(); return $this->parse(); } function parse ($log_data = null) { if ( $log_data == null ) $log_data = &$this->log_data; preg_match_all("/
(.*?)<\/pre>|(.*?))<\/div>/i", $log_data, $data);
if ( !empty($data) ) {
foreach( $data[1] as $key => $value ) {
if ( $value == 'send' || $value == 'receive' ) {
if ( preg_match("/(.*):.*/i", $data[3][$key], $sender) ) {
$sender = $sender[1];
} else {
$sender = $data[3][$key];
}
$this->data[] = array(
'type' => $value,
'time' => $data[2][$key],
'timestamp' => $this->get_timestamp($data[2][$key]),
'user' => $sender,
'message' => $data[4][$key]
);
if ( $value == 'send' ) {
$this->count_sent++;
} else {
$this->count_received++;
}
} elseif ( $value == 'status' ) {
$this->data[] = array(
'type' => $value,
'message' => $data[5][$key]
);
$this->count_status++;
}
$this->count++;
}
return true;
}
return false;
}
function get_timestamp ($time) {
if ( preg_match("/([0-9]{1,2}):([0-9]{2}):([0-9]{2})\s(AM|PM)/i", $time, $stamp) ) {
$year = ( !empty($this->info->year) ) ? $this->info->year : 0 ;
$month = ( !empty($this->info->month) ) ? $this->info->month : 0 ;
$day = ( !empty($this->info->month) ) ? $this->info->day : 0 ;
$hour = $stamp[1];
$minute = $stamp[2];
$second = $stamp[3];
if ( strtoupper($stamp[4]) == 'AM' ) {
if ( $hour == 12 ) $hour = 0;
} elseif ( strtoupper($stamp[4]) == 'PM' ) {
if ( $hour < 12 ) $hour = $hour + 12;
}
return mktime($hour, $minute, $second, $month, $day, $year);
} else {
return false;
}
}
function get_info () {
if ( preg_match("/(.*?)\.(.*?)\/(?:.*?)\/(.*)\s+\(([0-9]{4})[-,|]{1}([0-9]{2})[-,|]{1}([0-9]{2})\)\.AdiumHTMLLog$/i", $this->src, $info) ) {
$this->info = (object) array(
'protocol' => basename($info[1]),
'account' => $info[2],
'contact' => $info[3],
'year' => $info[4],
'month' => $info[5],
'day' => $info[6],
'timestamp' => mktime(0, 0, 0, $info[5], $info[6], $info[4]),
);
return true;
} elseif (preg_match("/(.*)\s\(([0-9]{4})[-,|]{1}([0-9]{2})[-,|]{1}([0-9]{2})\)\.AdiumHTMLLog$/i", basename($this->src), $info)) {
$this->info = (object) array(
'contact' => $info[1],
'year' => $info[2],
'month' => $info[3],
'day' => $info[4],
'timestamp' => mktime(0, 0, 0, $info[3], $info[4], $info[2]),
);
return true;
}
return false;
}
function load_file ($src) {
if ( preg_match('/^(?:http|https|ftp):\/\//i', $src) ) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $src);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
$return = curl_exec($ch);
curl_close($ch);
return $return;
} elseif (is_readable($src)) {
if (!($fh = fopen($src,'r'))) return false;
$return = fread($fh, filesize($src));
fclose($fh);
return $return;
} else {
return false;
}
}
}
?>