/[drupal]/contributions/modules/swftools/swfobject2/swfobject2.module
ViewVC logotype

Contents of /contributions/modules/swftools/swfobject2/swfobject2.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.9 - (show annotations) (download) (as text)
Mon Mar 30 22:19:12 2009 UTC (7 months, 3 weeks ago) by stuartgreenfield
Branch: MAIN
CVS Tags: HEAD
Changes since 1.8: +44 -17 lines
File MIME type: text/x-php
Enhanced support for CCK filefields - multiple filefields will can be converted to a playlist using the 'SWF Tools - playlist' formatter.
1 <?php
2 // $Id: swfobject2.module,v 1.8 2009/03/15 15:24:37 stuartgreenfield Exp $
3
4 /**
5 * SWF Tools - SWFObject2
6 *
7 * Enables the use of swfobject.js which provides image replacement
8 * for Flash content. swfobject.js must be downloaded separately. (Add
9 * the contents of the zip file to swftools/shared/swfobject2)
10 * This module produces standards compliant mark that will pass W3C
11 * validation
12 *
13 */
14
15 /**
16 * Implementation of hook_swftools_methods().
17 */
18 function swfobject2_swftools_methods() {
19
20 // Initialise an array to hold results
21 $methods = array();
22
23 // Define the swfobject2 embedding action
24 $methods[SWFTOOLS_EMBED]['swfobject2_replace'] = array(
25 'name' => 'swfobject2_replace',
26 'module' => 'swfobject2',
27 'shared_file' => 'swfobject2/swfobject.js',
28 'title' => t('SWFObject 2 - JavaScript'),
29 'download' => 'http://code.google.com/p/swfobject/',
30 );
31
32 // Return results
33 return $methods;
34 }
35
36
37 /**
38 * Implementation of hook_swftools_embed().
39 *
40 * @param $action
41 * The action requested, if add_js then the function is being called to add
42 * JavaScript to the page header only, if it is an SWF Tools action then it
43 * defines the markup being produced, e.g. SWFTOOLS_FLV_DISPLAY.
44 * @param $methods
45 * Object containing two keys - player and method. Each consists of an array
46 * that defines the details of the resolved player and embedding method that
47 * is being used for this file.
48 * @param $vars
49 * Object containing three keys - othervars, flashvars and params. These are
50 * arrays containing key/value pairs that contain all the data assigned to this
51 * file. Refer to swf() for more details about the $vars array.
52 * @param $html_alt
53 * The string of markup that will be included if the embedding fails.
54 * @return
55 * A string of markup, or nothing if the function was called to only add JavaScript to the page.
56 */
57 function swfobject2_swftools_embed($action = 'add_js', $methods = FALSE, $vars = FALSE, $html_alt = '') {
58
59 swfobject2_push_js();
60
61 // If the only action requested was add_js then return
62 if ($action == 'add_js') {
63 return;
64 }
65
66 // If swfobject api is installed then use it here
67 if (defined('SWFOBJECT_API_INSTALLED')) {
68
69 // Anything in $vars->params will be output - we don't want src_path
70 unset($vars->params['src_path']);
71
72 // Unset flashvars string - we can use the array format and let drupal_to_js handle things
73 unset($vars->params['flashvars']);
74
75 // Put html alt in to params in right place for SWF Object API
76 $vars->params['no_flash'] = $html_alt;
77
78 // theme_swfobject_api($url, $params = array(), $vars = array(), $id = NULL, $attributes = array(), $inline = FALSE) {
79 //return theme('swfobject_api', $vars->params['src'], $vars->params , $vars->flashvars, '', '', FALSE);
80 // Call SWF Object API, but add the content inline so we can cache the result
81 return theme('swfobject_api', $vars->params['src'], $vars->params , $vars->flashvars, '', '', SWFOBJECT_API_INLINE);
82
83 }
84
85
86
87 // Initialise a counter to give each div a unique id
88 static $unique_id = 0;
89
90 // Increment the counter each time the function is called
91 $unique_id++;
92
93 // Construct a unique id for each div by using time() combined with $unique_id
94 // This is necessary to prevent clashes between cached content
95 $id = time() . $unique_id;
96
97 // Anything in $vars->params will be output - we don't want src_path
98 unset($vars->params['src_path']);
99
100 // Unset flashvars string - we can use the array format and let drupal_to_js handle things
101 unset($vars->params['flashvars']);
102
103 // Generate js string ready for output to the page header
104 // swfObject takes parameters swfURL, id, width, height, version, expressinstall, flashvars, params, attributes
105 // At the moment expressInstall isn't enabled
106 $swf_js = t('swfobject.embedSWF("!url", "!id", "!width", "!height", "!version", "", !flashvars, !params, !attributes);', array(
107 '!url' => $vars->params['src'],
108 '!id' => 'swfobject2-id-' . $id,
109 '!width' => $vars->params['width'],
110 '!height' => $vars->params['height'],
111 '!version' => $vars->params['version'],
112 '!flashvars' => drupal_to_js($vars->flashvars),
113 '!params' => drupal_to_js($vars->params),
114 '!attributes' => drupal_to_js(array('id' => 'swf' . $id)),
115 ));
116
117 // Generate the html markup ready to receive the substitution
118 $html = '<div id="swfobject2-id-' . $id . '" class="swftools swfobject2">' . "\n";
119 $html .= $html_alt . "\n";
120 $html .= '</div>' . "\n";
121
122 // Although SWF Object 2 recommends adding js to the page header that will prevent cached filters being used
123 // So we add js to the page body in order that it gets cached too
124 $html .= '<script type="text/javascript">' . "\n";
125 $html .= $swf_js . "\n";
126 $html .= '</script>' . "\n";
127
128 // Return html markup
129 return $html;
130 }
131
132
133 function swfobject2_push_js() {
134
135 // Set flag to indicate if the javascript has been added to the header
136 static $swfobject2_has_run;
137
138 // Output JavaScript to the header to load the SWF Object code, if not already done
139 if (!$swfobject2_has_run) {
140
141 // Add swfobject.js
142 drupal_add_js(swftools_get_player_path() . '/swfobject2/swfobject.js');
143
144 // Set flag to show this is complete
145 $swfobject2_has_run = TRUE;
146 }
147 }

  ViewVC Help
Powered by ViewVC 1.1.2