| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Render the CDN integration page statistics.
|
| 6 |
*
|
| 7 |
* @param $file_count
|
| 8 |
* The number of files detected on this page.
|
| 9 |
* @param $cdn_file_count
|
| 10 |
* The number of files on this page that are served from a CDN.
|
| 11 |
* @param $synced_files_per_server_count
|
| 12 |
* The number of files synced to each server.
|
| 13 |
* @param $total_time
|
| 14 |
* The total time it took to get all current CDN URLs.
|
| 15 |
* @param $synced_files
|
| 16 |
* Array of synchronized files.
|
| 17 |
* @param $unsynced_files
|
| 18 |
* Array of unsynchronized files.
|
| 19 |
* @return
|
| 20 |
* The rendered HTML.
|
| 21 |
*/
|
| 22 |
function theme_cdn_page_stats($file_count, $cdn_file_count, $synced_files_per_server_count, $total_time, $synced_files, $unsynced_files) {
|
| 23 |
$output = '';
|
| 24 |
$items = array();
|
| 25 |
$mode = variable_get(CDN_MODE_VARIABLE, CDN_MODE_BASIC);
|
| 26 |
|
| 27 |
$output .= '<div id="cdn-integration-page-stats">';
|
| 28 |
$items[] = 'Total number of files on this page: <strong>'. $file_count .'</strong>.';
|
| 29 |
$percentage = ($file_count == 0) ? '100' : number_format($cdn_file_count / $file_count * 100);
|
| 30 |
$items[] = 'Number of files available on CDNs: <strong>'. $cdn_file_count .'</strong> ('. $percentage . '% coverage).';
|
| 31 |
if ($mode == CDN_MODE_ADVANCED) {
|
| 32 |
foreach (array_keys($synced_files_per_server_count) as $server) {
|
| 33 |
$items[] = t('Number of files served from the server %server: !count', array('%server' => $server, '!count' => $synced_files_per_server_count[$server]));
|
| 34 |
}
|
| 35 |
}
|
| 36 |
else {
|
| 37 |
$items[] = 'All files are being served from a single CDN, because basic mode is being used.';
|
| 38 |
}
|
| 39 |
$items[] = t('Total time it took to look up the CDN URLs for these files:
|
| 40 |
!total-time ms, or !avg-time ms on average per file.',
|
| 41 |
array(
|
| 42 |
'!total-time' => round($total_time * 1000, 3),
|
| 43 |
'!avg-time' => round($total_time * 1000 / $file_count, 3),
|
| 44 |
)
|
| 45 |
);
|
| 46 |
|
| 47 |
|
| 48 |
// Nested list of unsynced files.
|
| 49 |
if (count($unsynced_files)) {
|
| 50 |
$unsynced_items = array();
|
| 51 |
foreach ($unsynced_files as $file) {
|
| 52 |
$unsynced_items[] = array(l($file, $file));
|
| 53 |
}
|
| 54 |
$items[] = 'The files that are not (yet?) synchronized to the CDN:' . theme('item_list', $unsynced_items, NULL, 'ol');
|
| 55 |
}
|
| 56 |
|
| 57 |
// Nested list of synced files.
|
| 58 |
if (count($synced_files)) {
|
| 59 |
$synced_items = array();
|
| 60 |
foreach ($synced_files as $synced_file) {
|
| 61 |
$file = $synced_file['file'];
|
| 62 |
$cdn_url = $synced_file['cdn_url'];
|
| 63 |
$server = $synced_file['server'];
|
| 64 |
$text = ($mode == CDN_MODE_BASIC) ? '!file' : '!file (server: !server)';
|
| 65 |
$synced_items[] = array(l(t($text, array('!file' => $file, '!server' => $server)), $cdn_url, array('attributes' => array('title' => $synced_file['absolute path']))));
|
| 66 |
}
|
| 67 |
$items[] = 'The files that are synchronized to the CDN:' . theme('item_list', $synced_items, NULL, 'ol');
|
| 68 |
}
|
| 69 |
|
| 70 |
$output .= theme('item_list', $items, '<strong>'. t('CDN integration statistics for %drupal_path', array('%drupal_path' => $_GET['q'])) .'</strong>');
|
| 71 |
$output .= '</div>';
|
| 72 |
return $output;
|
| 73 |
}
|