/*
* This grabs the HTML from http://www.fetcheveryone.com/userprofile.php?id=32814&show=training , and pulls out just the HTML I need.
* It then caches the results for 24 hours so I don't hammer the remote server.
*/
public function action_block_content_fetraining( $block, $theme )
{
if ( Cache::has( __CLASS__ . '__fetraining' ) && !Cache::expired( __CLASS__ . '__fetraining' ) ) {
$block->trainings = Cache::get( __CLASS__ . '__fetraining' );
} else {
$trainurl = "http://www.fetcheveryone.com/userprofile.php?id=32814&show=training";
$output = RemoteRequest::get_contents( $trainurl );
// First, strip out all newlines and tabs
$newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
$content = str_replace($newlines, "", html_entity_decode($output));
// Grab the training table
$notes = '';
$dist = '';
$type = '';
$date = '';
$time = '';
$start = strpos($content, '
');
$end = strpos($content, '
', $start)+8;
$training = substr($content, $start, $end-$start);
if ( $training != '') {
// Now split on tr
preg_match_all("||U", $training, $rows);
// Split row 2 (as row 1 is the title row)
preg_match_all("||U", $rows[0][1], $cells);
$date = strip_tags( $cells[0][0] );
list($dist, $time, $type) = explode(',', strip_tags( str_replace( ' ', ',', $cells[0][1] ) ) );
$notes = strip_tags( $cells[0][2], ' ');
}
// grab the total training table
$start = strpos($content, '');
$end = strpos($content, ' ', $start)+8;
$ttl = substr($content, $start, $end-$start);
if ( $ttl != '' ) {
// Now split on tr
preg_match_all("| |
|U", $ttl, $rows);
// Split row 3
preg_match_all("|| |U", $rows[0][2], $cells);
$ttl = round( strip_tags( $cells[0][13] ) * 1.609 ); // Convert to Km and round
}
$trainings = array(
'notes' => $notes,
'dist' => $dist,
'type' => $type,
'date' => $date,
'time' => $time,
'total' => $ttl
);
Cache::set( __CLASS__ . '__fetraining', $trainings, 86400 ); // 24 hours
$block->trainings = $trainings;
}
} |