[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/swftools/flowplayer3/ -> flowplayer3.module (source)

   1  <?php
   2  // $Id: flowplayer3.module,v 1.19.2.7 2009/04/22 21:59:44 stuartgreenfield Exp $
   3  
   4  /**
   5   * SWF Tools - FlowPlayer 3
   6   *
   7   * Enables the use of FlowPlayer 3 for media files.
   8   * http://flowplayer.org
   9   */
  10  
  11  /**
  12   * Define constants that can be used to reference aspects relating to FlowPlayer3
  13   */
  14  define('FLOWPLAYER3_MEDIAPLAYER', 'flowplayer3_mediaplayer');
  15  define('FLOWPLAYER3_MEDIAPLAYER_FILE', 'flowplayer-3.2.4.swf');
  16  define('FLOWPLAYER3_MEDIAPLAYER_STREAM_PLUGIN', 'flowplayer.rtmp-3.2.4.swf');
  17  define('FLOWPLAYER3_DOWNLOAD', 'http://flowplayer.org/');
  18  
  19  /**
  20   * Implementation of hook_swftools_methods().
  21   */
  22  function flowplayer3_swftools_methods() {
  23  
  24    // Initialise an array to hold the results
  25    $methods = array();
  26  
  27    /**
  28     * Define the FlowPlayer3 media player
  29     *   name         internal name used to refer to this player
  30     *   module       name of the module that provides this player
  31     *   file         name of flash variable to assign the name of the file to be played
  32     *   version      minimum version of flash needed to use this player
  33     *   shared_file  path to the shared file (relative to swftools/shared/
  34     *   title        human readable name of this player
  35     *   download     download path to the player (used to help users obtain the player)
  36     */
  37    $media_player = array(
  38      'name'        => FLOWPLAYER3_MEDIAPLAYER,
  39      'module'      => 'flowplayer3',
  40      'file'        => '', // Return nothing - do not make a file assignment
  41      'version'     => '9',
  42      'shared_file' => 'flowplayer3/' . variable_get('flowplayer3_mediaplayer_file', FLOWPLAYER3_MEDIAPLAYER_FILE),
  43      'title'       => t('FlowPlayer 3'),
  44      'download'    => FLOWPLAYER3_DOWNLOAD,
  45      'width'       => '500',
  46      'height'      => '375',
  47    );
  48  
  49    
  50    /**
  51     * Define actions that the player can support by returning an array with keys
  52     * [action][name_of_player][player_details]
  53     */
  54    $methods[SWFTOOLS_FLV_DISPLAY][FLOWPLAYER3_MEDIAPLAYER] = $media_player;
  55    $methods[SWFTOOLS_FLV_DISPLAY_LIST][FLOWPLAYER3_MEDIAPLAYER] = $media_player;
  56    $methods[SWFTOOLS_MP3_DISPLAY][FLOWPLAYER3_MEDIAPLAYER] = $media_player;
  57    $methods[SWFTOOLS_MP3_DISPLAY_LIST][FLOWPLAYER3_MEDIAPLAYER] = $media_player;
  58    $methods[SWFTOOLS_MEDIA_DISPLAY][FLOWPLAYER3_MEDIAPLAYER] = $media_player;
  59    $methods[SWFTOOLS_MEDIA_DISPLAY_LIST][FLOWPLAYER3_MEDIAPLAYER] = $media_player;
  60  
  61    // Return the method results
  62    return $methods;
  63  }
  64  
  65  /**
  66   * Implementation of hook_menu().
  67   */
  68  function flowplayer3_menu() {
  69  
  70    $items = array();
  71  
  72    $items['admin/settings/swftools/flowplayer3'] = array(
  73      'title' => 'FlowPlayer 3',
  74      'description' => 'Settings for ' . l('FlowPlayer 3', FLOWPLAYER3_DOWNLOAD) . '.',
  75      'access arguments' => array('administer flash'),
  76      'page callback' => 'drupal_get_form',
  77      'page arguments' => array('flowplayer3_admin_settings'),
  78      'file' => 'flowplayer3.admin.inc',
  79      'file path' => drupal_get_path('module', 'flowplayer3'),
  80    );
  81  
  82    return $items;
  83  }
  84  
  85  
  86  /**
  87   * Implementation of swftools_flashvars hook().
  88   * Note that $methods and $vars are passed by reference, so the player module
  89   * can manipulate them directly if necessary.
  90   
  91   * @param $action
  92   *   String defining the action that is to be performed, eg SWFTOOLS_FLV_DISPLAY
  93   * @param &$methods
  94   *   Object containing two keys - player and method. Each consists of an array
  95   *   that defines the details of the resolved player and embedding method that
  96   *   is being used for this file.
  97   * @param &$vars
  98   *   Object containing three keys - othervars, flashvars and params. These are
  99   *   arrays containing key/value pairs that contain all the data assigned to this
 100   *   file so far. Refer to swf() for more details about the $vars array.
 101   * @return
 102   *   Return an array of flashvars needed to allow the player to work.
 103   */
 104  function flowplayer3_swftools_flashvars($action, &$methods, &$vars) {
 105    
 106    // Initialise array of FlowPlayer3 configuration settings
 107    $flowplayer = array();
 108  
 109    // Initialise array to hold data
 110    $playlist = array();
 111  
 112    // Initialise flag to show it this content is being streamed
 113    $stream = FALSE;
 114    
 115    // Is this file to be streamed? Check for the stream variable being set
 116    if (isset($vars->othervars['stream'])) {
 117      
 118      // Set stream flag to true
 119      $stream = TRUE;
 120      
 121    }
 122    
 123    // If an image was supplied to be the splash then put this first in the list
 124    // This code doesn't seem to be working - the player objects to { url: '' }
 125    if (isset($vars->othervars['image'])) {
 126      $playlist[] = array(
 127        // Get url, checking for file existence, and using a relative url if possible.
 128        'url' => swftools_get_media_url(swftools_get_media_path() . $vars->othervars['image']),
 129        'autoPlay' => 'true',
 130      );
 131    }
 132  
 133    // If the passed variables includes 'playlist_data' we have a playlist
 134    if (isset($vars->othervars['playlist_data'])) {
 135     
 136      // Get file paths out of the playlist_data array and add to FlowPlayer playlist
 137      foreach ($vars->othervars['playlist_data']['playlist'] as $play) {
 138        
 139        // If this is a streamed playlist, use filename, otherwise use fileurl  
 140        if ($stream) {
 141          $playlist[]['url'] = $play['filename'];
 142        }
 143        else {
 144          $playlist[]['url'] = $play['fileurl'];
 145        }
 146      }
 147    }
 148  
 149    else {
 150      // Not a playlist, so populate FlowPlayer3 playlist with the file_url
 151      $playlist[]['url'] = $vars->othervars['file_url'];
 152    }
 153  
 154    // Attach the completed playlist to flowplayer array
 155    $flowplayer['playlist'] = $playlist;
 156  
 157    // Retrieve the current FlowPlayer3 settings
 158    $saved_settings = _flowplayer3_settings();
 159     
 160    // Scan through each setting to see if it is over-ridden in $vars->othervars
 161    // Unset properties that are blank to keep the resulting code 'tidy'
 162    foreach ($saved_settings as $category => $data) {
 163      foreach ($data as $property => $value) {
 164        if (isset($vars->othervars[$property])) {
 165          $saved_settings[$category][$property] = $vars->othervars[$property];
 166        }
 167        if (!$saved_settings[$category][$property]) {
 168          unset($saved_settings[$category][$property]);
 169        }
 170      }
 171    }
 172    
 173    // If the object doesn't have a width set then assign one
 174    if (!isset($vars->params['width'])) {
 175      $vars->params['width'] = $saved_settings['canvas']['width'];
 176    }
 177  
 178    // If the object doesn't have a height set then assign one
 179    if (!isset($vars->params['height'])) {
 180      $vars->params['height'] = $saved_settings['canvas']['height'];
 181    }
 182  
 183    // Add the properties to the flowplayer array ready for rendering
 184    $flowplayer['canvas'] = $saved_settings['canvas'];
 185    $flowplayer['clip'] = $saved_settings['clip'];
 186    $flowplayer['plugins']['controls'] = $saved_settings['controls'];
 187  
 188    // If we are streaming this file, add the stream plugin
 189    if (isset($vars->othervars['stream'])) {
 190  
 191      // Define the clip provider as 'stream'
 192      $flowplayer['clip']['provider'] = 'stream';
 193      
 194      // Get the name of the stream plugin
 195      $flowplayer['plugins']['stream']['url'] = variable_get('flowplayer3_mediaplayer_stream_plugin', FLOWPLAYER3_MEDIAPLAYER_STREAM_PLUGIN);
 196      
 197      // Set the path to the source of the stream
 198      $flowplayer['plugins']['stream']['netConnectionUrl'] = $vars->othervars['stream'];
 199      
 200    }
 201    
 202    // Add product key if it has been set
 203    if (variable_get('flowplayer3_product_key', '')) {
 204      $flowplayer['key'] = variable_get('flowplayer3_product_key', '');
 205    }
 206    
 207    // Convert flowplayer array to JSON, and assign to a flashvar called config
 208    $flashvars['config'] = drupal_to_js($flowplayer);
 209  
 210    // Replace " with ', and remove quotes from around true and false, to satisfy FlowPlayer
 211    $flashvars['config'] = str_replace(array('"', "'false'", "'true'", "'[", "]'"), array("'", "false", "true", "[", "]"), $flashvars['config']);
 212  
 213    // The ' has been escaped, so reverse it where it occurs in the playlist (it gets escaped again later!)
 214    //$flashvars['config'] = str_replace(array("\'"), array("'"), $flashvars['config']);
 215    
 216    // Return the finished array of flash variables
 217    return $flashvars;
 218  }
 219  
 220  
 221  /**
 222   * Implementation of hook_{player}_swftools_playlist().
 223   * This function builds the content needed to write to an xml playlist. In the
 224   * case of FlowPlayer3 it is not actually necessary to produce an xml playlist,
 225   * but we must support this hook as SWF Tools uses its presence to detect that
 226   * the player is capable of supporting playlists.
 227   * DO WE NEED TO DO THIS? IF THE PLAYER DOESN'T SUPPORT LIST ACTIONS THEN WE ALREADY KNOW THIS?
 228   *
 229   * @param $xml_data
 230   *   Array of data that can be used to build the xml playlist. Contains keys
 231   *     [header][title]  Title data that can be used for the playlist
 232   *     [playlist][key][filepath]  The filepath to the file
 233   *     [playlist][key][filename]  The filename of the file
 234   *     [playlist][key][fileurl]   The url of the file
 235   *     [playlist][key][title]     The title of the file
 236   *     [action]  The action to be performed by this playlist (e.g. SWFTOOLS_MP3_DISPLAY_LIST)
 237   * @param $method
 238   *   Object containing two keys - player and method. Each consists of an array
 239   *   that defines the details of the resolved player and embedding method that
 240   *   is being used for this file.   
 241   * @param $vars
 242   *   Object containing three keys - othervars, flashvars and params. These are
 243   *   arrays containing key/value pairs that contain all the data assigned to this
 244   *   file so far. THE ARRAY othervars CONTAINS A KEY playlist_data THAT APPEARS
 245   *   TO REPEAT THE CONTENTS OF xml_data. IS IT NECESSARY TO PASS BOTH?
 246   * @return
 247   *   String of text that be written to the xml file defining the playlist.
 248   */
 249  function flowplayer3_flowplayer3_mediaplayer_swftools_playlist($xml_data, &$method, &$vars) {
 250   
 251    // For FlowPlayer3 return nothing and let the handler create an empty xml file
 252    return;
 253  
 254  }
 255  
 256  
 257  /*
 258   * Implementation of hook_swftools_variable_mapping().
 259   *
 260   * @return
 261   *   Array of data describing how parameters passed to the player should be
 262   *   mapped. The first keys describe the name of the player, and this contains 
 263   *   a sub-array that consists of key/value pairs. The key describes the name
 264   *   of the parameter, the value describes what it maps to, e.g. flashvars
 265   */
 266  function flowplayer3_swftools_variable_mapping() {
 267    
 268    // FlowPlayer3 doesn't need to make any variable mappings
 269    return array(
 270      FLOWPLAYER3_MEDIAPLAYER => array(),
 271    );
 272  }
 273  
 274  
 275  /**
 276   * Return player configurations settings that will be used if not over-ridden.
 277   * 
 278   * @return
 279   *   Because there are so many settings for FlowPlayer3 the defaults are defined
 280   *   in the array returned by this function. The function initialises an array
 281   *   of defaults, merges settings from the configuration page, and returns the
 282   *   result.
 283   */
 284  function _flowplayer3_settings() {
 285  
 286    // Define the settings list
 287    $defaults['clip'] = array(
 288      'autoPlay' => 'false',
 289      'autoBuffering' => 'false',
 290      'scaling' => 'scale',
 291      'start' => '',
 292      'duration' => '',
 293      'accelerated' => 'false',
 294      'bufferLength' => '',
 295      'provider' => '',
 296      'fadeInSpeed' => '',
 297      'fadeOutSpeed' => '',
 298      'linkUrl' => '',
 299      'linkWindow' => '_blank',
 300      'live' => 'false',
 301      'cuePointMultiplier' => '',
 302    );
 303  
 304    $defaults['controls'] = array(
 305      'backgroundColor' => '#000000',
 306      'timeColor' => '#01DAFF',
 307      'durationColor' => '#FFFFFF',
 308      'progressColor' => '#015B7A',
 309      'backgroundGradient' => 'medium',
 310      'progressGradient' => 'medium',
 311      'bufferColor' => '#6C9CBC',
 312      'bufferGradient' => 'none',
 313      'sliderColor' => '#000000',
 314      'sliderGradient' => 'none',
 315      'buttonColor' => '#889AA4',
 316      'buttonOverColor' => '#92B2BD',
 317      'autoHide' => 'fullscreen',
 318      'play' => 'true',
 319      'volume' => 'true',
 320      'mute' => 'true',
 321      'time' => 'true',
 322      'stop' => 'false',
 323      'playlist' => 'false',
 324      'fullscreen' => 'true',
 325      'scrubber' => 'true',
 326      'top' => '',
 327      'left' => '',
 328      'bottom' => '',
 329      'right' => '',
 330      'opacity' => '',
 331    );
 332    
 333    $defaults['canvas'] = array(
 334      'width' => 500,
 335      'height' => 375,
 336      'backgroundColor' => '#000000',
 337      'backgroundImage' => '',
 338      'backgroundRepeat' => 'repeat',
 339      'backgroundGradient' => 'low',
 340      'border' => '',
 341      'borderRadius' => '',
 342    );
 343  
 344    // Retrieve settings from database, if available
 345    $saved_settings = variable_get(FLOWPLAYER3_MEDIAPLAYER, array());
 346    $saved_colors = variable_get('flowplayer3_palette', array());
 347    
 348    if ($saved_colors) {
 349      // Move background color to canvas
 350      $saved_settings['canvas']['backgroundColor'] = $saved_colors['backgroundColor'];
 351      
 352      // Move control bar background color to controls
 353      $saved_colors['backgroundColor'] = $saved_colors['controlbarbackgroundColor'];
 354      unset($saved_colors['controlbarbackgroundColor']);
 355  
 356      $saved_settings['controls'] += $saved_colors;
 357    }
 358    
 359    // Merge the two sets together
 360    $defaults = array_merge($defaults, $saved_settings);
 361  
 362    // Return resulting defaults
 363    return $defaults;
 364  }
 365  
 366  
 367  /**
 368   * Implementation of hook_help().
 369   */
 370  function flowplayer3_help($path, $arg) {
 371    switch ($path) {
 372      case 'admin/settings/swftools/flowplayer3':
 373        return '<p>' . t('These are the settings for the FlowPlayer 3 media player.
 374                        For details of what each parameter does refer to the
 375                        <a href="@flowplayer">FlowPlayer 3 documentation</a>.
 376                        It is possible that you do not need to change any of
 377                        these settings and blank values will use FlowPlayer
 378                        defaults.
 379                        If content is embedded using the SWF Tools filter then each parameter
 380                        can be over-ridden by specifying a new value in the filter string.', array('@flowplayer' => 'http://flowplayer.org/documentation/configuration')) . '</p>';
 381    }
 382  }
 383  
 384  /**
 385   * Implementation of hook_theme().
 386   */
 387  function flowplayer3_theme() {
 388    return array(
 389      'flowplayer3_scheme_form' => array(
 390        'arguments' => array('form' => NULL),
 391        'file' => 'flowplayer3.admin.inc',
 392      ),
 393    );
 394  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7