[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

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

   1  <?php
   2  // $Id: imagerotator.module,v 1.5.2.2 2009/04/22 21:39:33 stuartgreenfield Exp $
   3  
   4  /**
   5   * SWF Tools - Jeroen Wijering's Flash Players
   6   *
   7   * Enables the use of Jeroen Wijering's Flash Media and Flash Image
   8   * Rotator files, branded forms of which ship with SWF Tools module.
   9   *
  10   * Author's Site.
  11   * http://jeroenwijering.com
  12   */
  13  
  14  define('WIJERING_IMAGEROTATOR', 'wijering_imagerotator'); // 'player', can display images.
  15  define('IMAGEROTATOR_DOWNLOAD', 'http://www.jeroenwijering.com/?item=jw_image_rotator');
  16  
  17  /**
  18   * Implementation of swftools_methods hook
  19   * Report methods back to SWF Tools
  20   */
  21  function imagerotator_swftools_methods() {
  22  
  23    $methods = array();
  24    // And with rotator
  25    $image_rotator = array(
  26      'name'        => WIJERING_IMAGEROTATOR,
  27      'module'      => 'imagerotator',
  28      'file'        => 'file', // Define which flashvar to assign a 'file to play' variable.
  29      'version'     => '7',
  30      'shared_file' => 'flash_image_rotator/imagerotator.swf',
  31      'title'       => t('JW Image Rotator 3'),
  32      'download'    => IMAGEROTATOR_DOWNLOAD,
  33      'width'       => '400',
  34      'height'      => '320',
  35    );
  36    $methods[SWFTOOLS_IMAGE_DISPLAY_LIST][WIJERING_IMAGEROTATOR] = $image_rotator;
  37  
  38    return $methods;
  39  }
  40  
  41  /**
  42   * Implementation of hook_menu().
  43   */
  44  function imagerotator_menu() {
  45  
  46    $items = array();
  47  
  48      //$items['admin/media/swf/imagerotator'] = array(
  49      $items['admin/settings/swftools/imagerotator'] = array(
  50        'title' => 'JW Image Rotator 3',
  51        'description' => 'Plug-in for '. l('Jeroen Wijering\'s Image Rotator 3', IMAGEROTATOR_DOWNLOAD) .'.',
  52        'access arguments' => array('administer flash'),
  53        'page callback' => 'drupal_get_form',
  54        'page arguments' => array('imagerotator_admin_form'),
  55        'file' => 'imagerotator.admin.inc',
  56        'file path' => drupal_get_path('module', 'imagerotator'),
  57      );
  58  
  59    return $items;
  60  }
  61  
  62  
  63  /**
  64   * These are the default settings as they are stored in the database and displayed
  65   * on the settings page.
  66   */
  67  function _imagerotator_settings($player) {
  68    $opts = _imagerotator_options();
  69  
  70    switch ($player) {
  71      case WIJERING_IMAGEROTATOR:
  72        // Define the settings list.
  73        $defaults['boolean'] = array(
  74          'shuffle'             => 'default',
  75          'shownavigation'      => 'default',
  76          'linkfromdisplay'     => 'default',
  77          'showicons'           => 'default',
  78          'enablejs'            => 'default',
  79        );
  80        $defaults['color'] = array(
  81          'backcolor'           => '',
  82          'frontcolor'          => '',
  83          'lightcolor'          => '',
  84        );
  85        $defaults['url'] = array(
  86          'logo'                => '',
  87          'link'                => '',
  88        );
  89        $defaults['integer'] = array(
  90          'width'               => '400',
  91          'height'              => '320',
  92          'rotatetime'          => '3',
  93        );
  94        $defaults['other'] = array(
  95          'transition'          => 'default',
  96          'linktarget'          => 'default',
  97          'overstretch'         => 'default',
  98        );
  99        $saved_settings = variable_get('swftools_'. WIJERING_IMAGEROTATOR, array());
 100        break;
 101    }
 102  
 103    // Overwrite initialised variables with those that might be already saved.
 104    foreach ($defaults AS $category => $vars) {
 105      foreach ($vars AS $key => $setting) {
 106        if (isset($saved_settings[$key])) {
 107          $defaults[$category][$key] = $saved_settings[$key];
 108        }
 109      }
 110    }
 111  
 112    return $defaults;
 113  }
 114  
 115  /**
 116   * Implementation of swftools_flashvars hook.
 117   * Return an array of flashvars.
 118   */
 119  function imagerotator_swftools_flashvars($action, &$methods, &$vars) {
 120  
 121    // Pad out the user parameters (like those passed through swf(), with our
 122    // configured defaults, allowing the user parameters to dominate.
 123    $saved_settings = _imagerotator_flashvars($methods->player['name']);
 124  
 125    $saved = array();
 126    foreach ($saved_settings AS $category => $settings) {
 127      $saved = array_merge($saved, $settings);
 128    }
 129    $flashvars = array_merge($saved, $vars->flashvars);
 130    if (isset($flashvars['image']) && !valid_url($flashvars['image'], TRUE)) {
 131      $flashvars['image'] = swftools_get_media_url(swftools_get_media_path() . $flashvars['image']);
 132    }
 133  
 134    if ($vars->params['width']) {$flashvars['width'] = $vars->params['width'];}
 135    if ($vars->params['height']) {$flashvars['height'] = $vars->params['height'];}
 136  
 137    // Return an array of flash variables
 138    return $flashvars;
 139  }
 140  
 141  /**
 142   * This function is called from imagerotator_swftools_flashvars() which is called from swf()
 143   * It will return the default flashvar configuration, just prior to any overrides
 144   * passed into swf(). We start with the settings defined on admin/swf/imagerotator
 145   * which are returned by _imagerotator_settings(). Then we prepare these values for output
 146   * to html (eg. '1' become 'true') and we unset undefined flashvars to prevent their output.
 147   *
 148   */
 149  function _imagerotator_flashvars($this_player) {
 150    // Cache this.
 151    static $flashvars = array();
 152    if (!count($flashvars)) {
 153  
 154      // Media Player
 155      foreach (array(WIJERING_IMAGEROTATOR) AS $player) {
 156  
 157        // Get saved settings for this method.
 158        $defaults = _imagerotator_settings($player);
 159        foreach ($defaults AS $category => $vars) {
 160          foreach ($vars AS $key => $setting) {
 161            if (!$setting || $setting == 'default') {
 162              unset($defaults[$category][$key]);
 163            }
 164            else {
 165              switch ($category) {
 166                case 'color':
 167                  $defaults['color'][$key] = str_replace('#', '0x', $defaults['color'][$key]);
 168                  break;
 169                case 'boolean':
 170                  $defaults['boolean'][$key] = _swftools_tf($defaults['boolean'][$key]);
 171                  break;
 172              }
 173            }
 174          }
 175        }
 176  
 177        // Not the same as width/height. This determines the extended width OR height
 178        // past the main view area where the actual playlist file names can be found.
 179        // Setting both together is not supported.
 180        if ($defaults['integer']['displaywidth']) {
 181          unset($defaults['integer']['displayheight']);
 182        }
 183        else {
 184          unset($defaults['integer']['displaywidth']);
 185        }
 186  
 187        $flashvars[$player] = $defaults;
 188      }
 189    }
 190  
 191    return $flashvars[$this_player];
 192  }
 193  
 194  /**
 195   * flashvar and param option arrays. These are used for options settings in the
 196   * configuration screen.
 197   *
 198   */
 199  function _imagerotator_options() {
 200    $options['overstretch'] = array('default' => 'default', 'false' => 'false', 'true' => 'true', 'fit' => 'fit', 'none' => 'none', );
 201    $options['repeat'] = array('default' => 'default', 'false' => 'false', 'true' => 'true', 'list' => 'list', );
 202    $options['linktarget'] = array('default' => 'default', '_self' => '_self', '_blank' => '_blank', );
 203    $options['transition'] = array('default' => 'default', 'fade' => 'fade', 'bgfade' => 'bgfade', 'blocks' => 'blocks', 'bubbles' => 'bubbles', 'circles' => 'circles', 'flash' => 'flash', 'fluids' => 'fluids', 'lines' => 'lines', 'slowfade' => 'slowfade', 'random' => 'random', );
 204    $options['bool'] = array('default' => 'default', 'true' => 'true', 'false' => 'false');
 205    return $options;
 206  }
 207  
 208  
 209  function imagerotator_wijering_imagerotator_swftools_playlist($xml_data, &$method, &$vars) {
 210  
 211    $xml = '<playlist version="1" xmlns="http://xspf.org/ns/0/">
 212              <title>'. $xml_data['header']['title'] .'</title>
 213              <info></info>
 214              <annotation></annotation>
 215              <trackList>
 216              ';
 217  
 218    foreach($xml_data['playlist'] AS $track => $details) {
 219      
 220      $xml .= "<track>\n";
 221      $xml .= "<title>". $details['title'] ."</title>\n";
 222      $xml .= "<creator></creator>\n";
 223      $xml .= "<location>". $details['fileurl'] ."</location>\n";
 224      $xml .= "<info>". $details['fileurl'] ."</info>\n";
 225      $xml .= "</track>\n";
 226    }
 227    $xml .= '</trackList>
 228             </playlist>';
 229  
 230    return $xml;
 231  }
 232  
 233  
 234  /*
 235   * Implementation of hook_swftools_variable_mapping.
 236   *
 237   */
 238  function imagerotator_swftools_variable_mapping() {
 239    return array(
 240      WIJERING_IMAGEROTATOR => array(
 241        'shuffle'         => 'flashvars',
 242        'shownavigation'  => 'flashvars',
 243        'linkfromdisplay' => 'flashvars',
 244        'showicons'       => 'flashvars',
 245        'enablejs'        => 'flashvars',
 246        'backcolor'       => 'flashvars',
 247        'frontcolor'      => 'flashvars',
 248        'lightcolor'      => 'flashvars',
 249        'logo'            => 'flashvars',
 250        'link'            => 'flashvars',
 251        'rotatetime'      => 'flashvars',
 252        'transition'      => 'flashvars',
 253        'linktarget'      => 'flashvars',
 254        'overstretch'     => 'flashvars',
 255      ),
 256    );
 257  }
 258  
 259  
 260  /**
 261   * Implementation of hook_help
 262   */
 263  function imagerotator_help($path, $arg) {
 264    switch ($path) {
 265      case 'admin/settings/swftools/imagerotator':
 266        return '<p>'.t('These are the settings for Jeroen Wijering\'s imagerotator.swf
 267                        and correspond (by category and order) to the
 268                        <a href="@imagerotator">Media Player and Image Rotator read me</a>.
 269                        It is possible that you do not need to change any of
 270                        these settings and blank values will defer to friendly
 271                        defaults. Note that the label in (<em>brackets</em>)
 272                        is the actual flashvar name and corresponds to the read me.', array('@imagerotator' => 'http://jeroenwijering.com/extras/readme.html')).'</p>';
 273    }
 274  }


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