'admin/settings/cdn', 'title' => t('CDN integration'), 'callback' => 'drupal_get_form', 'callback arguments' => array('cdn_admin_settings_form'), 'access' => user_access('administer site configuration'), 'type' => MENU_NORMAL_ITEM, ); } return $items; } /** * Implementation of hook_requirements(). */ function cdn_requirements($phase) { $requirements = array(); $t = get_t(); switch ($phase) { case 'install' : case 'runtime' : $path = drupal_get_path('module', 'cdn') .'/cdn_cron.php'; $cdn_cron_last = variable_get('cdn_cron_last', NULL); $requirements['cdn_cron']['title'] = $t('CDN synchronization'); if (!file_exists('cdn_cron.php') || (file_exists($path) && file_exists('cdn_cron.php') && md5_file($path) != md5_file('cdn_cron.php'))) { $requirements['cdn_cron'] += array( 'description' => $t( "In order for the CDN integration module to work correctly, it has to be able to synchronize. This can be done automatically through cron, but you will have to copy the file %file to the same directory as Drupal's cron.php.", array('%file' => $path) ), 'severity' => $phase == 'install' ? REQUIREMENT_WARNING : REQUIREMENT_ERROR, 'value' => $t('Copy cdn_cron.php'), ); } elseif (!file_exists($path)) { $requirements['cdn_cron'] += array( 'description' => $t( "You probably moved rather than copied the cdn_cron.php file from %file to the same directory as Drupal's cron.php. You should leave a copy of this file in the CDN integration module directory so that you will not lose this file when you upgrade to another revision of Drupal.", array('%file' => $path) ), 'severity' => $phase == 'install' ? REQUIREMENT_WARNING : REQUIREMENT_ERROR, 'value' => $t('Copy cdn_corn.php back'), ); } elseif (is_numeric($cdn_cron_last)) { $requirements['cdn_cron']['value'] = $t('Last run !time ago', array('!time' => format_interval(time() - $cdn_cron_last))); $requirements['cdn_cron']['description'] = variable_get('cdn_cron_last_stats', ''. $t('No statistics available.') .''); } else { $requirements['cdn_cron'] += array( 'description' => $t( 'CDN synchronization cron job has not run -- it appears it has not been setup on your system. Please check the help pages for configuring cron jobs.', array('@url' => 'http://drupal.org/cron') ), 'severity' => REQUIREMENT_ERROR, 'value' => $t('Never run'), ); } } return $requirements; } /** * Implementation of hook_exit(). */ function cdn_exit($destination = NULL) { global $user; if (!$destination && user_access('adminster site configuration') && variable_get('cdn_dev_page_stats', 0)) { $msg = ''; $stats = _cdn_devel_page_stats(); extract($stats); $msg .= 'CDN integration statistics
'; $msg .= ''; print $msg; } } //---------------------------------------------------------------------------- // Form API callbacks. /** * Form definition: CDN admin settings form. */ function cdn_admin_settings_form() { $form['dev'] = array( '#type' => 'fieldset', '#title' => t('Development'), '#collapsible' => TRUE, '#collapsed' => FALSE, ); $form['dev']['cdn_dev_page_stats'] = array( '#type' => 'radios', '#title' => t('Show statistics for the current page'), '#description' => t( 'Shows the CDN integration statistics of the current page, to users with adminster site configuration permissions.' ), '#options' => array( '0' => t('Disabled'), '1' => t('Enabled'), ), '#default_value' => variable_get('cdn_dev_page_stats', 0), ); $form['stats'] = array( '#type' => 'fieldset', '#title' => t('Site-wide statistics'), '#collapsible' => TRUE, '#collapsed' => FALSE, ); require_once 'cdn_cron.inc'; list($files_scheduled, $files_unique_settings, $files_update_settings) = _cdn_cron_get_files_to_sync(variable_get('cdn_sync_filters', FALSE)); unset($files_unique_settings, $files_update_settings); $files_scheduled_size = 0; foreach ($files_scheduled as $file => $size) { $files_scheduled_size += $size; } $files_synced = variable_get('cdn_files_synced', array()); $form['stats']['numbers'] = array( '#value' => theme('cdn_numbers', $files_scheduled, $files_scheduled_size, $files_synced), ); $form['stats']['list'] = array( '#type' => 'fieldset', '#title' => t('Complete list of files'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); $form['stats']['list']['table'] = array( '#value' => theme('cdn_synchronized_files_list', $files_synced), ); return system_settings_form($form); } //---------------------------------------------------------------------------- // Private functions. /** * Collects per-page CDN integration statistics. * * @param $file * The local file path. * @param $remote_file * The remote file path. * @param $remote_file_exists * TRUE if the remote file exists, FALSE otherwise. * @return * Only if no parameters were passed: the collected statistics. */ function _cdn_devel_page_stats($file = FALSE, $remote_file = '', $remote_file_exists = FALSE) { static $file_count, $remote_file_count, $local_files; if (!isset($local_files)) { $local_files = array(); } // If the function is called with parameters set, save the statistics. If no // parameters are passed, return the collected statistics. if ($file) { $file_count++; if ($remote_file_exists) { $remote_file_count++; } else { $local_files[] = $file; } } else { return array( 'file_count' => $file_count, 'remote_file_count' => $remote_file_count, 'local_files' => $local_files, ); } } //---------------------------------------------------------------------------- // Themeing functions. /** * @ingroup themeable * @{ */ function theme_cdn_numbers($files_scheduled, $files_scheduled_size, $files_synced) { $output = ''; $header = array( array('data' => t('Scheduled files')), array('data' => t('Size of scheduled files')), array('data' => t('Synchronized files')), array('data' => t('Coverage')) ); $rows[0] = array( 'data' => array( count($files_scheduled), number_format($files_scheduled_size / 1024) .' KB', count($files_synced), number_format(count($files_synced) / count($files_scheduled) * 100, 2) .'%' ), ); $output .= theme('table', $header, $rows); foreach ($files as $local_file => $remote_file) { } return $output; } /** * Render the list of synchronized files. * * @param $files * An array with as keys local files and as values remote files. * @return * The rendered HTML. */ function theme_cdn_synchronized_files_list($files) { $output = ''; if (!count($files)) { $output .= '

'. t('No files synchronized yet.') .'

'; } else { $header = array( array('data' => t('Local file')), array('data' => t('Remote file')), ); $rows = array(); foreach ($files as $local_file => $remote_file) { $rows[] = array('data' => array($local_file, $remote_file)); } $output .= theme('table', $header, $rows); } return $output; } /** * @} End of "ingroup themeable". */