src/php/lib/class.ext_transmission.php
/**
	 * Return result
	 * 
	 * @access public
	 * @return false on failure|array of the torrents
	 */
Return result

@access public
@return false on failure|array of the torrents
Return result @access public @return false on failure|array of the torrents
public function result() {
		if ($this->_res === false) {
			return false;
		}
		$rows = array();
		$rows[] = array(
			'type' => 'header',
			'columns' => array(
				'Torrent',
				array(1, 'Done', '10%'),
				'State',
				'Have',
				'Uploaded',
				'Time Left',
				'Ratio',
				'Up',
				'Down'
			)
		);
				if (count($this->_torrents) == 0)  {
			$rows[] = array(
				'type' => 'none',
				'columns' => array(
					array(9, 'None found')
				)
			);
		}
		else {
			$status_tally = array();
			$status_tally['Downloaded'] = 0;
			$status_tally['Uploaded'] = 0;
			$status_tally['Ratio'] = '';
			foreach ($this->_torrents as $torrent) {
				$status_tally[$torrent['state']] = !array_key_exists($torrent['state'], $status_tally) ? 1 : $status_tally[$torrent['state']] + 1;
				$have_bytes = false;
				if ($torrent['have'] != 'None') {
					$have_parts = explode(' ', $torrent['have'], 2);
					if (is_numeric($have_parts[0]) && $have_parts[0] > 0) {
						switch ($have_parts[1]) {
							case 'TiB':
								$have_bytes = (float) $have_parts[0] * 1099511627776;
							break;
							case 'GiB':
								$have_bytes = (float) $have_parts[0] * 1073741824;
							break;
							case 'MiB':
								$have_bytes = (float) $have_parts[0] * 1048576;
							break;
							case 'KiB':
								$have_bytes = (float) $have_parts[0] * 1024;
							break;
						}
					}
				}
				$uploaded_bytes = false;
				if (is_numeric($have_bytes) && $have_bytes > 0 && is_numeric($torrent['ratio']) && $torrent['ratio'] > 0) 
					$uploaded_bytes = $torrent['ratio'] * $have_bytes;
				if (is_numeric($have_bytes) && $have_bytes > 0 && is_numeric($uploaded_bytes) && $uploaded_bytes > 0) {
					$status_tally['Downloaded'] += $have_bytes;
					$status_tally['Uploaded'] += $uploaded_bytes;
				}
				$rows[] = array(
					'type' => 'values',
					'columns' => array (
						wordwrap(htmlspecialchars($torrent['torrent']), 50, ' ', true),
						'<div class="bar_chart">
							<div class="bar_inner" style="width: '.(int) $torrent['done'].'%;">
								<div class="bar_text">
									'.($torrent['done'] ? $torrent['done'].'%' : '0%').'
								</div>
							</div>
						</div>
						',
						$torrent['state'],
						$have_bytes !== false ? LinfoCommon::byteConvert($have_bytes) : $torrent['have'],
						$uploaded_bytes !== false ? LinfoCommon::byteConvert($uploaded_bytes) : 'None',
						$torrent['eta'],
						$torrent['ratio'],
						LinfoCommon::byteConvert($torrent['up']) . '/s',
						LinfoCommon::byteConvert($torrent['down']) . '/s'
					)
				);
			}
			$status_tally['Ratio'] = $status_tally['Downloaded'] > 0 && $status_tally['Uploaded'] > 0 ? round($status_tally['Uploaded'] / $status_tally['Downloaded'], 2) : 'N/A';
			$status_tally['Downloaded'] = $status_tally['Downloaded'] > 0 ? LinfoCommon::byteConvert($status_tally['Downloaded']) : 'None';
			$status_tally['Uploaded'] = $status_tally['Uploaded'] > 0 ? LinfoCommon::byteConvert($status_tally['Uploaded']) : 'None';
			if (count($status_tally) > 0) {
				$tally_contents = array();
				foreach ($status_tally as $state => $tally)
					$tally_contents[] = "$state: $tally";
				$rows[] = array(
					'type' => 'values',
					'columns' => array(
						array(9, implode(', ', $tally_contents))
					)
				);
			}
		}
		if (
			is_array($this->_stats) &&
			array_key_exists('downloaded-bytes', $this->_stats) &&
			array_key_exists('uploaded-bytes', $this->_stats) &&
			array_key_exists('seconds-active', $this->_stats
		)) {
			$extra_vals = array(
				'title' => 'Transmission Stats',
				'values' => array(
					array('Total Downloaded', LinfoCommon::byteConvert($this->_stats['downloaded-bytes'])),
					array('Total Uploaded', LinfoCommon::byteConvert($this->_stats['uploaded-bytes'])),
					$this->_stats['uploaded-bytes'] > 0 && $this->_stats['downloaded-bytes'] > 0 ? array('Total Ratio', round($this->_stats['uploaded-bytes'] / $this->_stats['downloaded-bytes'], 3)) : false,
					array('Duration', LinfoCommon::secondsConvert($this->_stats['seconds-active']))
				)
			);
		}
		else
			$extra_vals = false;
		return array(
			'root_title' => 'Transmission Torrents',
			'rows' => $rows,
			'extra_type' => 'k->v',
			'extra_vals' => $extra_vals
		);
	}
public function result ( ) { if ( $ this -> _res === false ) { return false ; } $ rows = array ( ) ; $ rows [ ] = array ( 'type' => 'header' , 'columns' => array ( 'Torrent' , array ( 1 , 'Done' , '10%' ) , 'State' , 'Have' , 'Uploaded' , 'Time Left' , 'Ratio' , 'Up' , 'Down' ) ) ; if ( count ( $ this -> _torrents ) == 0 ) { $ rows [ ] = array ( 'type' => 'none' , 'columns' => array ( array ( 9 , 'None found' ) ) ) ; } else { $ status_tally = array ( ) ; $ status_tally [ 'Downloaded' ] = 0 ; $ status_tally [ 'Uploaded' ] = 0 ; $ status_tally [ 'Ratio' ] = '' ; foreach ( $ this -> _torrents as $ torrent ) { $ status_tally [ $ torrent [ 'state' ] ] = ! array_key_exists ( $ torrent [ 'state' ] , $ status_tally ) ? 1 : $ status_tally [ $ torrent [ 'state' ] ] + 1 ; $ have_bytes = false ; if ( $ torrent [ 'have' ] != 'None' ) { $ have_parts = explode ( ' ' , $ torrent [ 'have' ] , 2 ) ; if ( is_numeric ( $ have_parts [ 0 ] ) && $ have_parts [ 0 ] > 0 ) { switch ( $ have_parts [ 1 ] ) { case 'TiB' : $ have_bytes = ( float ) $ have_parts [ 0 ] * 1099511627776 ; break ; case 'GiB' : $ have_bytes = ( float ) $ have_parts [ 0 ] * 1073741824 ; break ; case 'MiB' : $ have_bytes = ( float ) $ have_parts [ 0 ] * 1048576 ; break ; case 'KiB' : $ have_bytes = ( float ) $ have_parts [ 0 ] * 1024 ; break ; } } } $ uploaded_bytes = false ; if ( is_numeric ( $ have_bytes ) && $ have_bytes > 0 && is_numeric ( $ torrent [ 'ratio' ] ) && $ torrent [ 'ratio' ] > 0 ) $ uploaded_bytes = $ torrent [ 'ratio' ] * $ have_bytes ; if ( is_numeric ( $ have_bytes ) && $ have_bytes > 0 && is_numeric ( $ uploaded_bytes ) && $ uploaded_bytes > 0 ) { $ status_tally [ 'Downloaded' ] += $ have_bytes ; $ status_tally [ 'Uploaded' ] += $ uploaded_bytes ; } $ rows [ ] = array ( 'type' => 'values' , 'columns' => array ( wordwrap ( htmlspecialchars ( $ torrent [ 'torrent' ] ) , 50 , ' ' , true ) , '<div class="bar_chart">
							<div class="bar_inner" style="width: ' . ( int ) $ torrent [ 'done' ] . '%;">
								<div class="bar_text">
									' . ( $ torrent [ 'done' ] ? $ torrent [ 'done' ] . '%' : '0%' ) . '
								</div>
							</div>
						</div>
						' , $ torrent [ 'state' ] , $ have_bytes !== false ? LinfoCommon :: byteConvert ( $ have_bytes ) : $ torrent [ 'have' ] , $ uploaded_bytes !== false ? LinfoCommon :: byteConvert ( $ uploaded_bytes ) : 'None' , $ torrent [ 'eta' ] , $ torrent [ 'ratio' ] , LinfoCommon :: byteConvert ( $ torrent [ 'up' ] ) . '/s' , LinfoCommon :: byteConvert ( $ torrent [ 'down' ] ) . '/s' ) ) ; } $ status_tally [ 'Ratio' ] = $ status_tally [ 'Downloaded' ] > 0 && $ status_tally [ 'Uploaded' ] > 0 ? round ( $ status_tally [ 'Uploaded' ] / $ status_tally [ 'Downloaded' ] , 2 ) : 'N/A' ; $ status_tally [ 'Downloaded' ] = $ status_tally [ 'Downloaded' ] > 0 ? LinfoCommon :: byteConvert ( $ status_tally [ 'Downloaded' ] ) : 'None' ; $ status_tally [ 'Uploaded' ] = $ status_tally [ 'Uploaded' ] > 0 ? LinfoCommon :: byteConvert ( $ status_tally [ 'Uploaded' ] ) : 'None' ; if ( count ( $ status_tally ) > 0 ) { $ tally_contents = array ( ) ; foreach ( $ status_tally as $ state => $ tally ) $ tally_contents [ ] = " $ state :  $ tally " ; $ rows [ ] = array ( 'type' => 'values' , 'columns' => array ( array ( 9 , implode ( ', ' , $ tally_contents ) ) ) ) ; } } if ( is_array ( $ this -> _stats ) && array_key_exists ( 'downloaded-bytes' , $ this -> _stats ) && array_key_exists ( 'uploaded-bytes' , $ this -> _stats ) && array_key_exists ( 'seconds-active' , $ this -> _stats ) ) { $ extra_vals = array ( 'title' => 'Transmission Stats' , 'values' => array ( array ( 'Total Downloaded' , LinfoCommon :: byteConvert ( $ this -> _stats [ 'downloaded-bytes' ] ) ) , array ( 'Total Uploaded' , LinfoCommon :: byteConvert ( $ this -> _stats [ 'uploaded-bytes' ] ) ) , $ this -> _stats [ 'uploaded-bytes' ] > 0 && $ this -> _stats [ 'downloaded-bytes' ] > 0 ? array ( 'Total Ratio' , round ( $ this -> _stats [ 'uploaded-bytes' ] / $ this -> _stats [ 'downloaded-bytes' ] , 3 ) ) : false , array ( 'Duration' , LinfoCommon :: secondsConvert ( $ this -> _stats [ 'seconds-active' ] ) ) ) ) ; } else $ extra_vals = false ; return array ( 'root_title' => 'Transmission Torrents' , 'rows' => $ rows , 'extra_type' => 'k->v' , 'extra_vals' => $ extra_vals ) ; }
Return result
Return result
// Don't bother if it didn't go well // it did; continue // Store rows here // Start showing connections // No torrents?
 // Store a total amount of certain torrents here: // As well as uploaded/downloaded // Go through each torrent // Status count tally // Make some sense of the have so we can get it into bytes, which we can then have fun with // Try getting amount uploaded, based upon ratio and exact amount downloaded above // Save amount uploaded/downloaded tally // Save result // Finish the size totals // Create a row for the tally of statuses // Store list of k: v'ish values here // Populate that // Save this final row // Handle stats which might not exist // Give it off