[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

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

   1  <?php
   2  // $Id: wijering4.module,v 1.7.2.4 2009/04/23 22:25:55 stuartgreenfield Exp $
   3  
   4  /**
   5   * SWF Tools - Jeroen Wijering's Media Player version 4
   6   *
   7   * Enables the use of Jeroen Wijering's FLV Media Player version 4
   8   *
   9   * Author's Site.
  10   * http://jeroenwijering.com
  11   */
  12  
  13  define('WIJERING4_MEDIAPLAYER', 'wijering4_mediaplayer'); // 'player', can display mixed files
  14  define('WIJERING4_IMAGEROTATOR', 'wijering4_imagerotator'); // 'player', can display images.
  15  define('WIJERING4_DOWNLOAD', 'http://www.jeroenwijering.com/?item=JW_FLV_Media_Player');
  16  
  17  /**
  18   * Implementation of swftools_methods hook
  19   * Report methods back to SWF Tools
  20   */
  21  function wijering4_swftools_methods() {
  22  
  23    // Wijering4 now comes in two versions - viral and non-viral - since we now cache the results of this function we can
  24    // check which is present, testing for the viral one first
  25    
  26    // Start with the viral player
  27    $player = 'flash_media_player/player-viral.swf';
  28    
  29    // Discover if the viral player is present
  30    if (!file_exists(swftools_get_player_path() . '/' . $player)) {
  31     
  32      // If not, try the non-viral version
  33      $player = 'flash_media_player/player.swf';
  34      
  35      if (!file_exists(swftools_get_player_path() . '/' . $player)) {
  36        
  37        // If non-viral isn't present either revert to viral for purposes of the download message (since viral is the default)
  38        $player = 'flash_media_player/player-viral.swf';
  39        
  40      }
  41      
  42    }
  43    
  44    // Define the media player
  45    $media_player = array(
  46      'name'        => WIJERING4_MEDIAPLAYER,
  47      'module'      => 'wijering4',
  48      'file'        => 'file', // Define which flashvar to assign a 'file to play' variable.
  49      'version'     => '7',
  50      'shared_file' => $player,
  51      'title'       => t('JW Media Player 4'),
  52      'download'    => WIJERING4_DOWNLOAD,
  53      'width'       => '400',
  54      'height'      => '300',
  55    );
  56  
  57    // Wijering support various actions with the same player and info.
  58    $methods[SWFTOOLS_FLV_DISPLAY][WIJERING4_MEDIAPLAYER] = $media_player;
  59    $methods[SWFTOOLS_FLV_DISPLAY_LIST][WIJERING4_MEDIAPLAYER] = $media_player;
  60    $methods[SWFTOOLS_MP3_DISPLAY][WIJERING4_MEDIAPLAYER] = $media_player;
  61    $methods[SWFTOOLS_MP3_DISPLAY_LIST][WIJERING4_MEDIAPLAYER] = $media_player;
  62    $methods[SWFTOOLS_MEDIA_DISPLAY][WIJERING4_MEDIAPLAYER] = $media_player;
  63    $methods[SWFTOOLS_MEDIA_DISPLAY_LIST][WIJERING4_MEDIAPLAYER] = $media_player;
  64    $methods[SWFTOOLS_IMAGE_DISPLAY_LIST][WIJERING4_MEDIAPLAYER] = $media_player;
  65  
  66    // Return methods
  67    return $methods;
  68  }
  69  
  70  /**
  71   * Implementation of hook_menu().
  72   */
  73  function wijering4_menu() {
  74  
  75    $items = array();
  76  
  77      //$items['admin/media/swf/wijering4'] = array(
  78      $items['admin/settings/swftools/wijering4'] = array(
  79        'title' => 'JW Media Player 4',
  80        'description' => 'Settings for '. l('Jeroen Wijering\'s FLV Media Player 4', WIJERING4_DOWNLOAD) .'.',
  81        'access arguments' => array('administer flash'),
  82        'page callback' => 'drupal_get_form',
  83        'page arguments' => array('wijering4_admin_form'),
  84        'file' => 'wijering4.admin.inc',
  85        'file path' => drupal_get_path('module', 'wijering4'),
  86      );
  87  
  88    return $items;
  89  }
  90  
  91  
  92  /**
  93   * These are the default settings as they are stored in the database and displayed
  94   * on the settings page.
  95   */
  96  function _wijering4_settings($player) {
  97  
  98    switch ($player) {
  99      case WIJERING4_MEDIAPLAYER:
 100        // Define the settings list.
 101        $defaults['boolean'] = array(
 102          'shuffle'             => 'default',
 103          'fullscreen'          => 'default',
 104          'autostart'           => 'default',
 105          'quality'             => 'default',
 106        );
 107        $defaults['color'] = array(
 108          'backcolor'           => '',
 109          'frontcolor'          => '',
 110          'lightcolor'          => '',
 111          'screencolor'         => '',
 112        );
 113        $defaults['url'] = array(
 114          'logo'                => '',
 115          'captions'            => '',
 116          'link'                => '',
 117          'streamscript'        => '',
 118          'skin'                => '',
 119        );
 120        $defaults['integer'] = array(
 121          'width'               => '400',
 122          'height'              => '320',
 123          'playlistsize'        => '',
 124          'bufferlength'        => '',
 125          'volume'              => '',
 126        );
 127        $defaults['other'] = array(
 128          'type'                => 'default',
 129          'repeat'              => 'default',
 130          'linktarget'          => 'default',
 131          'stretching'          => 'default',
 132          'playlist'            => 'default',
 133          'controlbar'          => 'default',
 134          'displayclick'        => 'default',
 135        );
 136        $defaults['accessibility'] = array(
 137          'accessible'          => FALSE,
 138          'accessible_visible'  => TRUE,
 139        );
 140        
 141        $saved_settings = variable_get('swftools_'. WIJERING4_MEDIAPLAYER, array());
 142        break;
 143  
 144    }
 145  
 146    // Overwrite initialised variables with those that might be already saved.
 147    foreach ($defaults AS $category => $vars) {
 148      foreach ($vars AS $key => $setting) {
 149        if (isset($saved_settings[$key])) {
 150          $defaults[$category][$key] = $saved_settings[$key];
 151        }
 152      }
 153    }
 154  
 155    return $defaults;
 156  }
 157  
 158  /**
 159   * Implementation of swftools_flashvars hook.
 160   * Return an array of flashvars.
 161   */
 162  function wijering4_swftools_flashvars($action, &$methods, &$vars) {
 163  
 164    // Pad out the user parameters (like those passed through swf(), with our
 165    // configured defaults, allowing the user parameters to dominate.
 166    $saved_settings = _wijering4_flashvars($methods->player['name']);
 167  
 168    $saved = array();
 169    foreach ($saved_settings AS $category => $settings) {
 170      $saved = array_merge($saved, $settings);
 171    }
 172    $flashvars = array_merge($saved, $vars->flashvars);
 173  
 174    if (isset($flashvars['image']) && !valid_url($flashvars['image'], TRUE)) {
 175      $flashvars['image'] = swftools_get_media_url(swftools_get_media_path() . $flashvars['image']);
 176    }
 177  
 178    if ($vars->params['width']) {$flashvars['width'] = $vars->params['width'];}
 179    if ($vars->params['height']) {$flashvars['height'] = $vars->params['height'];}
 180  
 181    // Is this file to be streamed? Check for the stream variable being set
 182    if (isset($vars->othervars['stream'])) {
 183  
 184      // Extract path info from the $file_url variable describing the file
 185      $info = pathinfo($vars->othervars['file_url']);
 186      
 187      // Set the streamer flashvar
 188      $vars->flashvars['streamer'] = $vars->othervars['stream'];
 189      
 190      // Replace the current (non streamed) file url with the stream filename
 191      $vars->othervars['file_url'] = $info['basename'];
 192      
 193    }
 194    
 195    // Return an array of flash variables
 196    return $flashvars;
 197  }
 198  
 199  /**
 200   * This function is called from wijering4_swftools_flashvars() which is called from swf()
 201   * It will return the default flashvar configuration, just prior to any overrides
 202   * passed into swf(). We start with the settings defined on admin/swf/wijering
 203   * which are returned by _wijering4_settings(). Then we prepare these values for output
 204   * to html (eg. '1' become 'true') and we unset undefined flashvars to prevent their output.
 205   *
 206   */
 207  function _wijering4_flashvars($this_player) {
 208    // Cache this.
 209    static $flashvars = array();
 210    if (!count($flashvars)) {
 211  
 212      // Media Player
 213      foreach (array(WIJERING4_MEDIAPLAYER) AS $player) {
 214  
 215        // Get saved settings for this method.
 216        $defaults = _wijering4_settings($player);
 217        foreach ($defaults AS $category => $vars) {
 218          foreach ($vars AS $key => $setting) {
 219            if (!$setting || $setting == 'default') {
 220              unset($defaults[$category][$key]);
 221            }
 222            else {
 223              switch ($category) {
 224                case 'color':
 225                  $defaults['color'][$key] = str_replace('#', '0x', $defaults['color'][$key]);
 226                  break;
 227                case 'boolean':
 228                  $defaults['boolean'][$key] = _swftools_tf($defaults['boolean'][$key]);
 229                  break;
 230              }
 231            }
 232          }
 233        }
 234  
 235        // Not the same as width/height. This determines the extended width OR height
 236        // past the main view area where the actual playlist file names can be found.
 237        // Setting both together is not supported.
 238        if ($defaults['integer']['displaywidth']) {
 239          unset($defaults['integer']['displayheight']);
 240        }
 241        else {
 242          unset($defaults['integer']['displaywidth']);
 243        }
 244  
 245        $flashvars[$player] = $defaults;
 246      }
 247    }
 248  
 249    return $flashvars[$this_player];
 250  }
 251  
 252  /**
 253   * flashvar and param option arrays. These are used for options settings in the
 254   * configuration screen.
 255   *
 256   */
 257  function _wijering4_options() {
 258    $options['type'] = array('default' => 'default', 'sound' => 'sound', 'image' => 'image', 'video' => 'video', 'youtube' => 'youtube', 'camera' => 'camera', 'http' => 'http', 'rtmp' => 'rtmp', );
 259    $options['overstretch'] = array('default' => 'default', 'uniform' => 'uniform', 'fill' => 'fill', 'exactfit' => 'exactfit', 'none' => 'none', );
 260    $options['repeat'] = array('default' => 'default', 'none' => 'none', 'list' => 'list', 'always' => 'always', );
 261    $options['linktarget'] = array('default' => 'default', '_self' => '_self', '_blank' => '_blank', 'none' => 'none', );
 262    $options['playlist'] = array('default' => 'default', 'bottom' => 'bottom', 'over' => 'over', 'right' => 'right', 'none' => 'none', );
 263    $options['controlbar'] = array('default' => 'default', 'bottom' => 'bottom', 'over' => 'over', 'none' => 'none', );
 264    $options['displayclick'] = array('default' => 'default', 'play' => 'play', 'link' => 'link', 'fullscreen' => 'fullscreen', 'none' => 'none', 'mute' => 'mute', 'next' => 'next', );
 265    $options['bool'] = array('default' => 'default', 'true' => 'true', 'false' => 'false');
 266    return $options;
 267  }
 268  
 269  function wijering4_wijering4_mediaplayer_swftools_playlist($xml_data, &$method, &$vars) {
 270  
 271    $xml = '<playlist version="1" xmlns="http://xspf.org/ns/0/">
 272              <title>'. $xml_data['header']['title'] .'</title>
 273              <info></info>
 274              <annotation></annotation>
 275              <trackList>
 276              ';
 277    foreach ($xml_data['playlist'] AS $track => $details) {
 278  
 279      if (!isset($details['background']) && strtolower(substr($details['fileurl'], -3, 3)) == 'mp3') {
 280        if (isset($vars->flashvars['image'])) {
 281          $details['background'] = swftools_get_media_url(swftools_get_media_path() . $vars->flashvars['image']);
 282        } else {
 283          $details['background'] = SWFTOOLS_DEFAULT_BG;
 284        }
 285      }
 286      $xml .= "<track>\n";
 287      $xml .= "<title>". $details['title'] ."</title>\n";
 288      $xml .= "<creator></creator>\n";
 289      $xml .= "<location>". $details['fileurl'] ."</location>\n";
 290      $xml .= "<image>". $details['background'] ."</image>\n";
 291      $xml .= "<info>". $details['fileurl'] ."</info>\n";
 292      $xml .= "</track>\n";
 293    }
 294    $xml .= '</trackList>
 295             </playlist>';
 296    return $xml;
 297  }
 298  
 299  
 300  /*
 301   * Implementation of hook_swftools_variable_mapping.
 302   *
 303   */
 304  function wijering4_swftools_variable_mapping() {
 305    return array(
 306      WIJERING4_MEDIAPLAYER => array(
 307        'shuffle'             => 'flashvars',
 308        'fullscreen'          => 'flashvars',
 309        'autostart'           => 'flashvars',
 310        'quality'             => 'flashvars',
 311        'backcolor'           => 'flashvars',
 312        'frontcolor'          => 'flashvars',
 313        'lightcolor'          => 'flashvars',
 314        'screencolor'         => 'flashvars',
 315        'logo'                => 'flashvars',
 316        'captions'            => 'flashvars',
 317        'link'                => 'flashvars',
 318        'streamscript'        => 'flashvars',
 319        'skin'                => 'flashvars',
 320        'playlistsize'        => 'flashvars',
 321        'bufferlength'        => 'flashvars',
 322        'volume'              => 'flashvars',
 323        'type'                => 'flashvars',
 324        'repeat'              => 'flashvars',
 325        'linktarget'          => 'flashvars',
 326        'stretching'          => 'flashvars',
 327        'playlist'            => 'flashvars',
 328        'controlbar'          => 'flashvars',
 329        'displayclick'        => 'flashvars',
 330      ),
 331    );
 332  }
 333  
 334  
 335  /**
 336   * Implementation of hook_help
 337   */
 338  function wijering4_help($path, $arg) {
 339    switch ($path) {
 340      case 'admin/settings/swftools/wijering4':
 341        return '<p>'.t('These are the settings for Jeroen Wijering\'s FLV Media Player 4.
 342                        For details of what each parameter does refer to the
 343                        <a href="@wijering">JW Player for Flash wiki page</a>.
 344                        It is possible that you do not need to change any of
 345                        these settings and blank values will defer to friendly
 346                        defaults. Note that the label in (<em>brackets</em>)
 347                        is the actual flashvar name and corresponds to the wiki page.
 348                        If content is embedded using the SWF Tools filter then each parameter
 349                        can be over-ridden by specifying a new value in the filter string.', array('@wijering' => 'http://code.jeroenwijering.com/trac/wiki/FlashVars')).'</p>';
 350    }
 351  }
 352  
 353  
 354  /**
 355   * Determine if accessible links should be added below the Wijering player.
 356   * 
 357   * @param $vars
 358   *   The array of variables being processed.
 359   * @param $id
 360   *   The id for the object being added.
 361   * @return
 362   *   An empty string, or markup containing the accessible links.
 363   */
 364  function wijering4_accessible(&$vars, $id) {
 365    
 366    // If the accessible option is set then add links to the page, respecting visibility setting
 367    if ($vars->flashvars['accessible']) {
 368  
 369      // Add css to enabled hiding of accessible controls
 370      drupal_add_css(drupal_get_path('module', 'wijering4') . '/wijering4.css');
 371      
 372      // Build content
 373      $return[] = $vars->flashvars['accessible_visible'] ? '<ul>' : '<ul class="wijering4-accessible-hidden">';
 374      $return[] = "<li><a href=\"javascript:document.getElementById('$id').sendEvent('PLAY');\">" . t('Play/pause') . '</a></li>';
 375      $return[] = "<li><a href=\"javascript:document.getElementById('$id').sendEvent('MUTE');\">" . t('Mute/unmute') . '</a></li>';
 376      $return[] = "<li><a href=\"javascript:document.getElementById('$id').sendEvent('STOP');\">" . t('Rewind and stop') . '</a></li>';
 377      $return[] = '</ul>';
 378      
 379      //Implode array to a string
 380      $return = implode($return, "\n");
 381  
 382      // Unset the accessible parameters from flashvars so they are not output
 383      unset($vars->flashvars['accessible'], $vars->flashvars['accessible_visible']);
 384    }
 385    else {
 386      $return = '';
 387    }
 388    
 389    // Return the result
 390    return $return;
 391  
 392  }


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