You are here

function _swftools_status_players in SWF Tools 6

Same name and namespace in other branches
  1. 6.3 includes/swftools.admin.status.inc \_swftools_status_players()
  2. 6.2 swftools.admin.status.inc \_swftools_status_players()

Generate a status report for the player modules and media defaults Called from swftools_status() and returns markup

1 call to _swftools_status_players()
swftools_status in ./swftools.admin.status.inc
Generate a status report for SWF Tools methods / players / media defaults

File

./swftools.admin.status.inc, line 125

Code

function _swftools_status_players() {

  // Initialise requirements array for players and playback defaults
  $player_requirements = array();
  $playback_defaults = array();

  // Get player directory
  $player_directory = swftools_get_player_path() . '/';

  // Build an array of player methods
  $types = array(
    SWFTOOLS_FLV_DISPLAY => 'Single flv',
    SWFTOOLS_FLV_DISPLAY_LIST => 'List of flvs',
    SWFTOOLS_MP3_DISPLAY => 'Single mp3',
    SWFTOOLS_MP3_DISPLAY_LIST => 'List of mp3s',
    SWFTOOLS_MEDIA_DISPLAY_LIST => 'List of mixed media',
    SWFTOOLS_SWF_DISPLAY => 'Single swf',
    SWFTOOLS_IMAGE_DISPLAY_LIST => 'List of images',
  );

  // Iterate each method type
  foreach ($types as $type => $description) {

    // Obtain list of players that support the given method type
    $methods = swftools_methods_available($type);

    // Get the current default player for this type and store it in the player defaults array
    // To start with we assume it is missing, until we find the player module in a moment
    $playback_defaults[$type] = array(
      'title' => $types[$type],
      'value' => swftools_get_player($type),
      'description' => $playback_defaults[$type]['value'] == t('None') ? '' : t('The specified player no longer appears to be available. Check the <a href="@modules">modules page</a> to ensure that the necessary module is enabled, or choose a different player on the <a href="@handling">file handling</a> page.', array(
        '@modules' => url('admin/build/modules'),
        '@handling' => url('admin/settings/swftools/handling'),
      )),
      'severity' => REQUIREMENT_ERROR,
    );

    // Reset 0 to text string none and clear warning - we assume playback of this type isn't required
    if (!$playback_defaults[$type]['value']) {
      $playback_defaults[$type]['value'] = t('None');
      $playback_defaults[$type]['severity'] = REQUIREMENT_OK;
      $playback_defaults[$type]['description'] = '';
    }

    // If methods were returned for this type
    if (count($methods)) {

      // Iterate through the available methods for this type
      foreach ($methods as $method => $player) {

        // Did we already process this player?
        if (!$player_requirements[$player['title']]) {

          // If this player file doesn't exist set a warning, otherwise set ok
          if (!file_exists($player_directory . $player['shared_file'])) {
            $player_requirements[$player['title']] = array(
              'title' => $player['title'],
              'value' => t('Missing'),
              'description' => t('<a href="@url">Download</a> the required supporting file and upload it to %path.', array(
                '@url' => $player['download'],
                '%path' => $player_directory . $player['shared_file'],
              )),
              'severity' => REQUIREMENT_WARNING,
            );
          }
          else {
            $player_requirements[$player['title']] = array(
              'title' => $player['title'],
              'value' => t('OK'),
              'severity' => REQUIREMENT_OK,
            );
          }
        }

        // Is the current default method for this media type the method we currently have?
        if ($playback_defaults[$type]['value'] == $method) {

          // If yes, set name of this player as the value
          $playback_defaults[$type]['value'] = $player['title'];

          // Set the rest of the data for this player according to the status of the player file
          if ($player_requirements[$player['title']]['severity'] == REQUIREMENT_OK) {
            $playback_defaults[$type]['severity'] = REQUIREMENT_OK;
            $playback_defaults[$type]['description'] = '';
          }
          else {
            $playback_defaults[$type]['severity'] = REQUIREMENT_ERROR;
            $playback_defaults[$type]['description'] = $player_requirements[$player['title']]['description'];
            $player_requirements[$player['title']]['severity'] = REQUIREMENT_ERROR;
          }
        }
      }
    }
  }

  // Sort list of players by name, since we used their title as the key
  asort($player_requirements);

  // Generate the output string and return it
  $html = '';
  $html .= t('<h3>Playback defaults</h3>');
  $html .= t('<p>The table below shows the default methods that have been assigned to different types of media. An error indicates that a player has been specified but the supporting player file is not available, or the method cannot be found. Default playback methods can be configured on the <a href="@handling">file handling settings</a> page.</p>', array(
    '@handling' => url('admin/settings/swftools/handling'),
  ));
  $html .= theme('status_report', $playback_defaults);
  $html .= t('<h3>Players</h3>');
  $html .= t('<p>This table shows which media players are currently enabled and ready for use. A warning is shown if the required supporting file is not available, and an error is shown if the supporting file is not available <em>and</em> the method is currently set as a playback default for any media type.</p>');
  $html .= theme('status_report', $player_requirements);
  return $html;
}