You are here

theme.inc in CDN 6

Same filename and directory in other branches
  1. 6.2 theme.inc
  2. 7.2 theme.inc

File

theme.inc
View source
<?php

/**
 * Render the CDN integration page statistics.
 *
 * @param $file_count
 *   The number of files detected on this page.
 * @param $cdn_file_count
 *   The number of files on this page that are served from a CDN.
 * @param $synced_files_per_server_count
 *   The number of files synced to each server.
 * @param $total_time
 *   The total time it took to get all current CDN URLs.
 * @param $synced_files
 *   Array of synchronized files.
 * @param $unsynced_files
 *   Array of unsynchronized files.
 * @return
 *   The rendered HTML.
 */
function theme_cdn_page_stats($file_count, $cdn_file_count, $synced_files_per_server_count, $total_time, $synced_files, $unsynced_files) {
  $output = '';
  $items = array();
  $mode = variable_get(CDN_MODE_VARIABLE, CDN_MODE_BASIC);
  $output .= '<div id="cdn-integration-page-stats">';
  $items[] = 'Total number of files on this page: <strong>' . $file_count . '</strong>.';
  $percentage = $file_count == 0 ? '100' : number_format($cdn_file_count / $file_count * 100);
  $items[] = 'Number of files available on CDNs: <strong>' . $cdn_file_count . '</strong> (' . $percentage . '% coverage).';
  if ($mode == CDN_MODE_ADVANCED) {
    foreach (array_keys($synced_files_per_server_count) as $server) {
      $items[] = t('Number of files served from the server %server: !count', array(
        '%server' => $server,
        '!count' => $synced_files_per_server_count[$server],
      ));
    }
  }
  else {
    $items[] = 'All files are being served from a single CDN, because basic mode is being used.';
  }
  $items[] = t('Total time it took to look up the CDN URLs for these files:
                !total-time ms, or !avg-time ms on average per file.', array(
    '!total-time' => round($total_time * 1000, 3),
    '!avg-time' => round($total_time * 1000 / $file_count, 3),
  ));

  // Nested list of unsynced files.
  if (count($unsynced_files)) {
    $unsynced_items = array();
    foreach ($unsynced_files as $file) {
      $unsynced_items[] = array(
        l($file, $file),
      );
    }
    $items[] = 'The files that are not (yet?) synchronized to the CDN:' . theme('item_list', $unsynced_items, NULL, 'ol');
  }

  // Nested list of synced files.
  if (count($synced_files)) {
    $synced_items = array();
    foreach ($synced_files as $synced_file) {
      $file = $synced_file['file'];
      $cdn_url = $synced_file['cdn_url'];
      $server = $synced_file['server'];
      $text = $mode == CDN_MODE_BASIC ? '!file' : '!file (server: !server)';
      $synced_items[] = array(
        l(t($text, array(
          '!file' => $file,
          '!server' => $server,
        )), $cdn_url, array(
          'attributes' => array(
            'title' => $synced_file['absolute path'],
          ),
        )),
      );
    }
    $items[] = 'The files that are synchronized to the CDN:' . theme('item_list', $synced_items, NULL, 'ol');
  }
  $output .= theme('item_list', $items, '<strong>' . t('CDN integration statistics for %drupal_path', array(
    '%drupal_path' => $_GET['q'],
  )) . '</strong>');
  $output .= '</div>';
  return $output;
}

Functions

Namesort descending Description
theme_cdn_page_stats Render the CDN integration page statistics.