<?php /* LabWiki 1.2.1, 22 August 2012, by Santosh Patnaik, MD, PhD. Based on QwikiWiki 1.5 of David Barrett */ // QWFormatIndent function QWFormatIndent( $indent, $text, $align ) { $result = '<div style = "text-align: ' . $align . '; align: ' . $align . '; padding-left: ' . $indent * 25 . 'px;">' . $text . '</div>'; return $result; } // QWFormatMessage function QWFormatMessage( $message ) { // Just output the message, if it's there if( isset( $message ) ) {echo '<div class="QWResultBox"><img src="exclamationicon.gif" alt="!" /> '.$message.'</div>';} } // QWFormatHelp function QWFormatHelp( $message, $url ) { // Toggle which one to show global $QW; if( $QW['requestHelp'] ) { echo (' <div class="QWHelpBox"> <img src="questionicon.gif" alt="?" /> '.$message.' <div class="QWHelpToggle"> <a href="'.$url.$QW['debugURLSuffix'].'">[ Hide help ]</a> </div> </div> '); } else { echo (' <div class="QWHelpToggle"> <a href="'. $url.$QW['debugURLSuffix'].'&help=true">[ Show help ]</a> </div> '); } } // QWFormatArray function QWFormatArray( $name, &$array ) { // Output a titled table $out = '<strong>'. $name. '</strong>'; if( is_array( $array ) ){ if( count( $array ) ){ // Output the table $out .= '<table summary="formatted array" style="border:1;">'; foreach( $array as $key => $value ){ if(!is_array($value)){ $out .= '<tr><td>'.htmlspecialchars($key).'</td><td>'.htmlspecialchars($value).'</td></tr>'; } else{$out .= '<tr><td>'. QWFormatArray($key, &$value).'</td></tr>';} } $out .= '</table>'; } else {$out .= ' is an empty array.<br />';} } else {$out .= ' is not an array.<br />';} return $out; } // QWFormatDebug function QWFormatDebug( ) { // Output lots of data global $QW, $QW_REQUEST; $out = QWFormatArray( "REQUEST_VARS", $QW_REQUEST ); $out .= QWFormatArray( "QW", $QW ); $out .= QWFormatArray( "HTTP_COOKIE_VARS", $_COOKIE ); $out .= QWFormatArray( "HTTP_SERVER_VARS", $_SERVER ); $out .= QWFormatArray( "logs", $QW_LOG ); return $out; } // QWFormatRelativeDate function QWFormatRelativeDate( $nowTimestamp, $thenTimestamp ) { // Compute the difference $numSeconds = $nowTimestamp - $thenTimestamp; $numMinutes = round( $numSeconds / 60 ); $numHours = round( $numSeconds / 60 / 60 ); $numDays = round( $numSeconds / 60 / 60 / 24 ); $numWeeks = round( $numSeconds / 60 / 60 / 24 / 7 ); if( $numSeconds < 60 ) return "moments ago"; else if( $numMinutes == 1 ) return "1 minute ago"; else if( $numMinutes < 60 ) return "$numMinutes minutes ago"; else if( $numHours == 1 ) return "1 hour ago"; else if( $numHours < 24 ) return "$numHours hours ago"; else if( $numDays == 1 ) return "yesterday"; else if( $numDays < 7 ) return "$numDays days ago"; else if( $numWeeks == 1 ) return "last week"; else if( $numWeeks < 14 ) return "$numWeeks weeks ago"; else if( $numDays < 365 ) return "many months ago"; else return "ages ago"; } // QWFormatFileSize function QWFormatFileSize( $size ) { // Return the appropriate result $numBytes = $size; $numKBytes = round( $numBytes / 1024 ); $numMBytes = round( $numKBytes / 1024 ); $numGBytes = round( $numMBytes / 1024 ); if( $numBytes < 1024 ) return "$numBytes B"; else if( $numKBytes < 1024 ) return "$numKBytes KB"; else if( $numMBytes < 1024 ) return "$numMBytes MB"; else return "$numGBytes GB"; }