Pastoid

The page you are looking at now is at this URL: http://pastoid.com/b7p

This paste was last updated on September 26, 2011 at 3:14 pm.

Pasted Coderaw

	/*
	 * 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, '<table width="100%" class="standard">');
			$end = strpos($content, '</table>', $start)+8;
			$training = substr($content, $start, $end-$start);
			if ( $training != '') {
				// Now split on tr
				preg_match_all("|<tr(.*)</tr>|U", $training, $rows);
				// Split row 2 (as row 1 is the title row)
				preg_match_all("|<td(.*)</td>|U", $rows[0][1], $cells);
 
				$date = strip_tags( $cells[0][0] );
				list($dist, $time, $type) = explode(',', strip_tags( str_replace( '<br/>', ',', $cells[0][1] ) ) );
				$notes = strip_tags( $cells[0][2], '<br>');
			}
 
			// grab the total training table
			$start = strpos($content, '<table class="standard" width="100%" cellspacing="0">');
			$end = strpos($content, '</table>', $start)+8;
			$ttl = substr($content, $start, $end-$start);
			if ( $ttl != '' ) {
				// Now split on tr
				preg_match_all("|<tr(.*)</tr>|U", $ttl, $rows);
				// Split row 3
				preg_match_all("|<td(.*)</td>|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;
		}
	}

Toggle wordwrap

Referring DomainHits
Unknown Referer 127
pastoid.com 28
www.pastoid.com 2
Is this paste spam?
<Hide