/[drupal]/contributions/modules/flash_filter/flash_filter.module
ViewVC logotype

Contents of /contributions/modules/flash_filter/flash_filter.module

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


Revision 1.1 - (show annotations) (download) (as text)
Fri Apr 21 13:33:56 2006 UTC (3 years, 7 months ago) by tomsys
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-4-7
File MIME type: text/x-php
*** empty log message ***
1 <?php // $Id$ //
2
3 require_once ( drupal_get_path('module', 'flash_filter').'/swfheader.class.php' );
4 theme_add_style ( drupal_get_path('module', 'flash_filter').'/flash_filter.css' );
5
6 /**
7 * Drupal core hooks and setting are defined here, at the beginning of code
8 * Just to keep my record on progress, please post TODO here
9 *
10 */
11
12 function flash_filter_help($section = 'admin/help#flash_filter') {
13 $output = '';
14 switch ($section) {
15 case 'admin/help#flash_filter':
16 return t('<h3>Introduction</h3>
17 <p>This module here is to assist when we want to add a Flash Movie inside the body of a node or a block. This can be compleated either with a special meta-tag [flash:filename.swf] that will be replaced with a proper HTML &lt;embed&gt; tag or we can handle all attachments in an automatic mode. If any of attached files is a valid Flash content then flash_filter will try to display that attachment inline accordingly to your flash_filter general settings, otherwise a small icon as a link to that particular Flash Movie will be inserted.</p>
18 <h3>Installation</h3>
19 <p>This module has nothing extra ordinary and installation is very same as other Drupal modules, no tables required. Default installation path is in /modules/flash_filter directory.</p>
20 <p>Here is a complete list of all supplied files with this module:
21 <ul>
22 <p><b>swfheader.class.php</b> Small utility class to determine basic data from a SWF file header. With a little help of this class we are able to validate all attachments and automatically retrieve movie dimensions.</p>
23 <p><b>flash_filter.module</b> This is module itself</p>
24 <p><b>flash_filter.css</b> Here we can specify some style properties for our embedded Flash object and icon item</p>
25 <p><b>flash_filter_page.css</b> This style page is used when we are displaying Flash object alone on a single page</p>
26 <p><b>flash_icon.png</b> This is an icon image file, it can be replaced with your own custom file, name has to remain the same but size can be any of your choice</p>
27 <p><b>flash_logo.png</b> This image is only used on module settings page, nothing special though</p>
28 <p><b>README.txt</b> This file contains some short information about flash_filter module for Drupal</p>
29 </ul></p>
30 <h3>Configuration</h3>
31 <p><ol>
32 <li>First of all you should visit <a href="%core_settings">flash filter</a> main settings page, to define some core parameters what will be used as we proceed. All parameters are explained there, please follow carefully to the field descriptions.</li><br />
33 <li>Afterwards please specify for each node type on how to handle Flash attachments, this can be done on <a href="%content_types">content types</a> configuration page. Please note that default status for auto-displaying is disabled.</li><br />
34 <li>To enable content filtering and meta-tag replacement feature please visit the <a href="%filters">filters configuration</a> page.</li><br />
35 </ol></p>
36 <h3>Important notes</h3>
37 <p>Auto attachment filtering will respect your default site-wide uploaded content user access rules, but when the meta-tag [flash:filename.swf] is used in node body or in block content, those access rules will be ignored, it means that you should really take care to whom you are giving right\'s to use this filter.</p>
38 <p>For this content filter to work properly it has to be executed only after HTML filter has completed. That\'s why you should remember to change flash_filter order to fit your requirements.</p>
39 <p>flash_filter was written and tested against Drupal 4.7 RC - III</p>
40 ', array('%filters' => url('admin/filters'), '%core_settings' => url('admin/settings/flash_filter'), '%content_types' => url('admin/settings/content-types')) );
41 case 'admin/modules#description':
42 return t('Allows users to display uploaded Flash files inline. Automatic file handling requires') . ' <b>upload.module</b> ' . t('to work');
43 case 'filter#short-tip':
44 return t('You may add Flash files uploaded with this node <a href="%explanation-url">using special meta-tags</a>', array('%explanation-url' => url('filter/tips', NULL, 'image')));
45 case 'filter#long-tip':
46 return t('<p>You may link to Flash files uploaded in your files folders</p><p>If requested file is a valid Flash movie, it will be displayed inline, otherwise an icon with link to the file will be inserted.</p> ');
47 }
48 }
49
50 function flash_filter_filter_tips($delta, $format, $long = false) {
51 if ($long) {
52 return t('
53 <h3 id="filter-flash_filter">Flash Filter</h3>
54 <p>There are two options for you to choose from:</p>
55 <blockquote><pre><ol><li>[flash:filename.swf]</li><li>[flash_link:filename.swf]</li></ol></pre></blockquote>
56 <p>The first one will try to display flash file inline and only if it fit\'s to your flash_filter general settings then it will be rendered inline otherwise an icon will be rendered. The second example will add a small icon with a link to a single page where Flash movie will be displayed.</p>
57 <p>You can forward extra parameters to any movie or icon. Those parameters will override flash_filter default\'s. Movie width and height parameters are detected automatically.</p>
58 <blockquote><pre>[flash:filename.swf name="sample" title="My Flash" loop="false" bgcolor"#FF0000"]</pre></blockquote>
59 Flash Filter will accept following parameters:
60 <p><ul>
61 <li>align - (l, t, r, b)</li>
62 <li>bgcolor - (#RRGGBB, hexadecimal RGB value)</li>
63 <li>height - decimal value or percentage</li>
64 <li>loop - (true, false)</li>
65 <li>menu - (true, false)</li>
66 <li>name - short string to use as refference</li>
67 <li>play - (true, false)</li>
68 <li>quality - (low, high, autolow, autohigh, best )</li>
69 <li>salign - (l, t, r, b, tl, tr, bl, br)</li>
70 <li>scale - (showall, noborder, exactfit)</li>
71 <li>swliveconnect - (true, false)</li>
72 <li>title - short string to assign title under an icon object</li>
73 <li>width - decimal value or percentage</li>
74 <li>wmode - (window, opaque, transparent)</li>
75 </ul></p>
76 <p>For more detailed information about each parameter please visit <a href="%macromedia" target="_blank">Macromedia</a> web-site and look for Flash OBJECT and EMBED tag attributes</p>
77 <p>Additionally you can pass flashvars via following syntax, name attribute is used as refference:
78 <blockquote><pre>[flash:file.swf name="<b><font color="#990000">sample_name</font></b>"]<br />[flashvars:<b><font color="#990000">sample_name</font></b> VAR1=customer support<b>&</b>VAR2=tomsys<b>&</b>VAR3=landline<b>&</b>VAR4=+44 20 8123 5754]</pre></blockquote>
79 <p>Accordingly in Flash you will get those four variables: _root.VAR1, _root.VAR2, _root.VAR3, _root.VAR4</p>
80 </p>
81 ',array('%macromedia' => url('http://www.macromedia.com')));
82 }
83 else {
84 return t('You may use <a href="%flash_filter_help">[flash:filename.swf]</a> to display Flash files inline', array("%flash_filter_help" => url("filter/tips/$format", NULL, 'filter-flash_filter')));
85 }
86 }
87
88 function flash_filter_settings() {
89 $form = array();
90 $form['FF'] = array(
91 '#type' => 'fieldset',
92 '#title' => '[' . t('General settings') . ']',
93 '#attributes' => array('style' => 'background : #FFFFFF url(/' . drupal_get_path('module', 'flash_filter') . '/flash_logo.png' . ') bottom right no-repeat; -moz-border-radius : .5em;'),
94 '#prefix' => '<p>' . t('For more information about this module please take a look at ') . l( 'flash_filter', check_url('admin/help/flash_filter') ) . t(' help section, provided with this module.') . '</p>' ,
95 );
96
97 $form['FF']['flash_filter_teaser_movie_size'] = array(
98 '#type' => 'textfield',
99 '#title' => t('Specify the maximum width and height for Flash movies in node teaser (format: XXX,YYY)'),
100 '#size' => 10,
101 '#maxlength' => 10,
102 '#required' => TRUE,
103 '#default_value' => variable_get('flash_filter_teaser_movie_size', '100,100'),
104 '#description' => t('This setting will affect the dimensions of displayed Flash content in node teaser part. Movies larger than these dimensions will not be shown automatically.'),
105 );
106
107 $form['FF']['flash_filter_movie_size'] = array(
108 '#type' => 'textfield',
109 '#title' => t('Specify the maximum width and height for Flash movies in node body (format: XXX,YYY)'),
110 '#size' => 10,
111 '#maxlength' => 10,
112 '#required' => TRUE,
113 '#default_value' => variable_get('flash_filter_movie_size', '640,480'),
114 '#description' => t('This setting will affect the dimensions of displayed Flash content in node body part. Movies larger than these dimensions will not be shown automatically.'),
115 );
116
117 $form['FF']['flash_filter_link_movie'] = array(
118 '#type' => 'radios',
119 '#title' => t('Specify on how to auto-handle attached Flash Movies'),
120 '#default_value' => variable_get('flash_filter_link_movie', 0),
121 '#options' => array('0' => t('Try to display inline via &lt;embed&gt; tag'), '1' => t('Display small icon as link to Flash Movie object in a single page')),
122 '#description' => t('All valid Flash Movies which are exceeding pre-defined maximum width or height will be automatically replaced with an icon.'),
123 );
124
125 $form['FF']['flash_filter_teaser_order'] = array(
126 '#type' => 'radios',
127 '#title' => t('Specify on where to display attached Flash Movies for node teaser'),
128 '#default_value' => variable_get('flash_filter_teaser_order', 0),
129 '#options' => array('0' => t('At the very end of a teaser part'),'1' => t('At the very beginning of a teaser part')),
130 '#description' => t('We need to specify for auto filetering on where to add attached Flash Movies.'),
131 );
132
133 $form['FF']['flash_filter_body_order'] = array(
134 '#type' => 'radios',
135 '#title' => t('Specify on where to display attached Flash Movies for node body'),
136 '#default_value' => variable_get('flash_filter_body_order', 0),
137 '#options' => array('0' => t('At the very end of a node body part'),'1' => t('At the very beginning of a node body part')),
138 '#description' => t('We need to specify for auto filetering on where to add attached Flash Movies.'),
139 );
140
141 $form['FF_embed'] = array(
142 '#type' => 'fieldset',
143 '#collapsible' => 'TRUE',
144 '#collapsed' => 'TRUE',
145 '#title' => '['.t('Default settings for embedding').']',
146 '#attributes' => array('style' => 'background : #FFFFFF; -moz-border-radius: .5em;'),
147 );
148 $form['FF_embed']['flash_filter_movie_swliveconnect'] = array(
149 '#type' => 'checkbox',
150 '#title' => t('<strong>SWLIVECONNECT</strong> Specifies whether the browser should start Java when loading the Flash Player for the first time. The default value is false if this attribute is omitted. If you use JavaScript and Flash on the same page, Java must be running for the FSCommand to work.'),
151 '#default_value' => variable_get('flash_filter_movie_swliveconnect', false),
152 '#description' => t('This value will be used with auto embedding and also as a default value when no user input is found in [flash:filename.swf swliveconnect="true|false"] meta-tag'),
153 );
154
155 $form['FF_embed']['flash_filter_movie_play'] = array(
156 '#type' => 'checkbox',
157 '#title' => t('<strong>PLAY</strong> Specifies whether the movie begins playing immediately on loading in the browser. The default value is true if this attribute is omitted.'),
158 '#default_value' => variable_get('flash_filter_movie_play', true),
159 '#description' => t('This value will be used with auto embedding and also as a default value when no user input is found in [flash:filename.swf play="true|false"] meta-tag'),
160 );
161
162 $form['FF_embed']['flash_filter_movie_loop'] = array(
163 '#type' => 'checkbox',
164 '#title' => t('<strong>LOOP</strong> Specifies whether the movie repeats indefinitely or stops when it reaches the last frame. The default value is true if this attribute is omitted.'),
165 '#default_value' => variable_get('flash_filter_movie_loop', true),
166 '#description' => t('This value will be used with auto embedding and also as a default value when no user input is found in [flash:filename.swf loop="true|false"] meta-tag'),
167 );
168
169 $form['FF_embed']['flash_filter_movie_menu'] = array(
170 '#type' => 'checkbox',
171 '#title' => t('<strong>MENU</strong> Displays the full menu, allowing the user a variety of options to enhance or control playback.'),
172 '#default_value' => variable_get('flash_filter_movie_menu', true),
173 '#description' => t('This value will be used with auto embedding and also as a default value when no user input is found in [flash:filename.swf menu="true|false"] meta-tag'),
174 );
175
176 $form['FF_embed']['flash_filter_movie_bgcolor'] = array(
177 '#type' => 'textfield',
178 '#title' => t('Background color in hexadecimal form'),
179 '#size' => 7,
180 '#maxlength' => 7,
181 '#required' => TRUE,
182 '#default_value' => variable_get('flash_filter_movie_bgcolor', '#FFFFFF'),
183 '#description' => t('(#RRGGBB, hexadecimal RGB value) Specifies the background color of the movie. Use this attribute to override the background color setting specified in the Flash file. This attribute does not affect the background color of the HTML page.<br />This value will be used with auto embedding and also as a default value when no user input is found in [flash:filename.swf bgcolor="#FFFFFF"] meta-tag'),
184 );
185
186 $form['FF_embed']['flash_filter_movie_quality'] = array(
187 '#type' => 'radios',
188 '#title' => t('Specify the Quality property'),
189 '#default_value' => variable_get('flash_filter_movie_quality', 4),
190 '#options' => array('0' => t('low'), '1' => t('autolow'), '2' => t('medium'), '3' => t('high'), '4' => t('autohigh'), '5' => t('best')),
191 '#description' => t('
192 <strong>QUALITY</strong> - (low, high, autolow, autohigh, best)
193 <ul><li><strong>Low</strong> favors playback speed over appearance and never uses anti-aliasing.</li>
194 <li><strong>Autolow</strong> emphasizes speed at first but improves appearance whenever possible. Playback begins with anti-aliasing turned off. If the Flash Player detects that the processor can handle it, anti-aliasing is turned on.</li>
195 <li><strong>Autohigh</strong> emphasizes playback speed and appearance equally at first but sacrifices appearance for playback speed if necessary. Playback begins with anti-aliasing turned on. If the actual frame rate drops below the specified frame rate, anti-aliasing is turned off to improve playback speed. Use this setting to emulate the View &gt; Antialias setting in Flash.</li>
196 <li><strong>Medium</strong> applies some anti-aliasing and does not smooth bitmaps. It produces a better quality than the Low setting, but lower quality than the High setting.</li>
197 <li><strong>High</strong> favors appearance over playback speed and always applies anti-aliasing. If the movie does not contain animation, bitmaps are smoothed; if the movie has animation, bitmaps are not smoothed.</li>
198 <li><strong>Best</strong> provides the best display quality and does not consider playback speed. All output is anti-aliased and all bitmaps are smoothed.</li>
199 </ul>This value will be used with auto embedding and also as a default value when no user input is found in [flash:filename.swf quality="low|autolow|medium|high|autohigh|best"] meta-tag'),
200 );
201
202 $form['FF_embed']['flash_filter_movie_scale'] = array(
203 '#type' => 'radios',
204 '#title' => t('Specify the Scale property'),
205 '#default_value' => variable_get('flash_filter_movie_scale', 0),
206 '#options' => array('0' => t('showall'), '1' => t('noborder'), '2' => t('exactfit')),
207 '#description' => t('
208 <strong>SCALE</strong> - (showall, noborder, exactfit)
209 <ul><li><strong>Default (Show all)</strong> makes the entire movie visible in the specified area without distortion, while maintaining the original aspect ratio of the movie. Borders may appear on two sides of the movie.</li>
210 <li><strong>No Border</strong> scales the movie to fill the specified area, without distortion but possibly with some cropping, while maintaining the original aspect ratio of the movie.</li>
211 <li><strong>Exact Fit</strong> makes the entire movie visible in the specified area without trying to preserve the original aspect ratio. Distortion may occur.</li>
212 </ul>This value will be used with auto embedding and also as a default value when no user input is found in [flash:filename.swf scale="showall|noborder|exactfit"] meta-tag'),
213 );
214
215 $form['FF_embed']['flash_filter_movie_wmode'] = array(
216 '#type' => 'radios',
217 '#title' => t('Specify the Window Mode property'),
218 '#default_value' => variable_get('flash_filter_movie_wmode', 0),
219 '#options' => array('0' => t('window'), '1' => t('opaque'), '2' => t('transparent')),
220 '#description' => t('
221 <strong>WMODE</strong> - (window, opaque, transparent) Sets the Window Mode property of the Flash movie for transparency, layering, and positioning in the browser.
222 <ul><li><strong>Window</strong> movie plays in its own rectangular window on a web page.</li>
223 <li><strong>Opaque</strong> the movie hides everything on the page behind it.</li>
224 <li><strong>Transparent</strong> the background of the HTML page shows through all transparent portions of the movie, this may slow animation performance.<br/>
225 </ul>This value will be used with auto embedding and also as a default value when no user input is found in [flash:filename.swf wmode="window|opaque|transparent"] meta-tag'),
226 );
227
228 return $form;
229 }
230
231 function flash_filter_form_alter($form_id, &$form) {
232 if (isset($form['type'])) {
233 if ($form['type']['#value'] .'_node_settings' == $form_id) {
234 $form['workflow']['auto_use_flash_filter_'. $form['type']['#value']] = array(
235 '#type' => 'radios',
236 '#title' => t('Automatically display attached Flash files'),
237 '#default_value' => variable_get('auto_use_flash_filter_'. $form['type']['#value'], 0),
238 '#options' => array(t('Disabled'), t('Only in teaser'), t('Only in body'), t('In teaser and in body')),
239 '#description' => t('There are more options available - %settings_url', array('%settings_url' => l(t('flash_filter'), 'admin/settings/flash_filter'))),
240 );
241 }
242 }
243 }
244
245 function flash_filter_filter($op, $delta = 0, $format = -1, $text = '') {
246 switch ($op) {
247 case 'list':
248 return array(0 => t('Flash Filter'));
249 case 'no cache':
250 return FALSE;
251 case 'description':
252 return t('Substitutes [flash:filename.swf] or [flash_link:filename.swf] meta-tags with HTML objects.');
253 case 'prepare':
254 return $text;
255 case 'process':
256 return _flash_filter_process_text($text);
257 default:
258 return $text;
259 }
260 }
261
262 function flash_filter_menu($may_cache) {
263 global $user;
264 $items = array();
265 if ($may_cache) {
266 $items[] = array(
267 'path' => 'flash_file',
268 'title' => t('Flash File'),
269 'callback' => 'flash_filter_page',
270 'access' => user_access('view uploaded files'),
271 'type' => MENU_CALLBACK,
272 );
273 }
274 return $items;
275 }
276
277 function flash_filter_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
278 if (user_access('view uploaded files')) {
279 if(is_array($node->files) && $op == 'view') {
280 if (variable_get('auto_use_flash_filter_'. $node->type, 0)) {
281 $node = _flash_filter_auto_add($node);
282 }
283 }
284 }
285 }
286
287 /**
288 * Our Internal Stuff starts here down below ...
289 * Feel free to comment drastically, it will help us to improve this module further
290 *
291 */
292
293 function flash_filter_page () {
294 $endl = chr(13);
295 $params = ($_POST['edit']);
296 $my_file = ($params['filepath'] ? file_create_path($params['filepath']) : file_create_path(arg(1)) );
297 if ( file_exists($my_file) ) {
298 $params = ( $params ? $params : _flash_filter_verify_movie_object($my_file));
299 if ($params) {
300 $html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' . $endl ;
301 $html .= '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">' . $endl ;
302 $html .= '<head>' . $endl ;
303 $html .= '<title>'. ($params['title'] ? strip_tags($params['title']) . '&nbsp;&divide;&nbsp;' . variable_get('site_name', 'drupal') : variable_get('site_name', 'drupal') ) . '</title>' . $endl ;
304 $html .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' . $endl ;
305 $html .= '<link href="/'.drupal_get_path('module','flash_filter').'/flash_filter_page.css" rel="stylesheet" type="text/css">' . $endl ;
306 $html .= '</head>' . $endl ;
307 $html .= '<body>' . $endl ;
308 $html .= '<table id="FlashFilter"><tr><td>' . $endl ;
309 $html .= theme('flash_filter_as_movie', $my_file, $params, $params['flashvars']) ;
310 $html .= '<div id="FlashBack">' . l(t('Go back').' …', referer_uri(), array('title' => t('Return to previous page') . ' …' )) . '</div>' . $endl ;
311 $html .= '</td></tr></table>' . $endl ;
312 $html .= '</body>' . $endl ;
313 $html .= '</html>' . $endl ;
314 echo $html;
315 }
316 else {
317 watchdog('Flash Filter', t('%page is not a valid Flash content.', array('%page' => theme('placeholder', $_GET['q']))), WATCHDOG_WARNING, l(t('view'), $_GET['q']));
318 return t('Requested file is not a valid Flash content.');
319 // drupal_access_denied();
320 }
321 }
322 else {
323 drupal_not_found();
324 }
325 }
326
327 function theme_flash_filter_as_link($filepath, $params = array(), $Flash_Vars = '') {
328 $endl = chr(13);
329 $html = '' . $endl;
330 $html .= '<form action="/flash_file/' . basename($filepath) . '" method="post" id="flash_link_icon_form" class="flash_link_icon_form' . ( $params['name'] ? '-' . $params['name'] : '' ) . '">' . $endl;
331 $html .= '<input type="hidden" name="edit[filepath]" value="' . $filepath . '" />' . $endl;
332 $html .= ($Flash_Vars ? '<input type="hidden" name="edit[flashvars]" value="' . check_plain($Flash_Vars) . '" />' . $endl : '' );
333 foreach ($params as $key => $value) {
334 $html .= '<input type="hidden" name="edit[' . $key . ']" value="' . $value . '" />' . $endl;
335 }
336 $flash_icon_title = ($params['title'] ? $params['title'] : t('Flash Movie Object:')) . ($params['name'] ? ' [ ' . $params['name']. ' ] ' : '' ) . ' ( X:' . $params['width'] . ' , Y:' . $params['height'] . ' )';
337 $flash_icon_string = substr(theme_image(drupal_get_path('module', 'flash_filter') . '/flash_icon.png', $flash_icon_title, $flash_icon_title, array('border' => 0, 'margin' => 0)), 5);
338 $html .= '<button name="' . ($params['name'] ? $params['name'] : 'Flash_Icon' ) . '" value="submit" type="submit" title="' . $flash_icon_title . '">' ;
339 $html .= '<img ' . $flash_icon_string . ($params['title'] ? '<br />' . $params['title'] : '' ) . '</button>' . $endl;
340 $html .= '</form>' . $endl;
341
342 return $html;
343 }
344
345 function theme_flash_filter_as_movie($file_path, $params = array(), $Flash_Vars = '') {
346 $endl = chr(13);
347 $quality = array('0' => "low", '1' => "autolow", '2' => "medium", '3' => "high", '4' => "autohigh", '5' => "best");
348 $wmode = array('0' => "window", '1' => "opaque", '2' => "transparent");
349 $scale = array('0' => "showall", '1' => "noborder", '2' => "exactfit");
350 $logics = array('0' => "false", '1' => "true");
351 $f_source = check_url( base_path() . file_create_path($file_path) );
352 $f_align = ($params['align'] ? $params['align'] : '');
353 $f_bgcolor = ($params['bgcolor'] ? $params['bgcolor'] : variable_get('flash_filter_movie_bgcolor', '#FFFFFF'));
354 $f_height = ($params['height'] ? $params['height'] : "100%");
355 $f_loop = ($params['loop'] ? $params['loop'] : $logics[variable_get('flash_filter_movie_loop', '1')]);
356 $f_menu = ($params['menu'] ? $params['menu'] : $logics[variable_get('flash_filter_movie_menu', '1')]);
357 $f_name = ($params['name'] ? $params['name'] : 'flash_object');
358 $f_play = ($params['play'] ? $params['play'] : $logics[variable_get('flash_filter_movie_play', '1')]);
359 $f_quality = ($params['quality'] ? $params['quality'] : $quality[variable_get('flash_filter_movie_quality', '1')]);
360 $f_salign = ($params['salign'] ? $params['salign'] : '');
361 $f_scale = ($params['scale'] ? $params['scale'] : $scale[variable_get('flash_filter_movie_scale', '0')]);
362 $f_width = ($params['width'] ? $params['width'] : "100%");
363 $f_wmode = ($params['wmode'] ? $params['wmode'] : $wmode[variable_get('flash_filter_movie_wmode', '0')]);
364 $f_swlive = ($params['swliveconnect'] ? $params['swliveconnect'] : $logics[variable_get('flash_filter_movie_swliveconnect', '0')]);
365
366 $html = '<span id="flash_object" class="flash_object' . ( $f_name ? '-' . $f_name : '' ) . '"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' . $swf->version . ',0,0,0" width="' . $f_width . '" height="' . $f_height . '" id="' . $f_name . ( $f_align ? '" align="' . $f_align : '' ) . '">' . $endl ;
367 $html .= '<param name="allowScriptAccess" value="sameDomain" />' . $endl ;
368 $html .= '<param name="bgcolor" value="'. $f_bgcolor .'" />' . $endl ;
369 $html .= '<param name="loop" value="'. $f_loop .'" />' . $endl ;
370 $html .= '<param name="menu" value="'. $f_menu .'" />' . $endl ;
371 $html .= '<param name="movie" value="'. $f_source .'" />' . $endl ;
372 $html .= '<param name="play" value="'. $f_play .'" />' . $endl ;
373 $html .= '<param name="quality" value="'. $f_quality .'" />' . $endl ;
374 $html .= ( $f_salign ? '<param name="salign" value="'. $f_salign .'" />' . $endl : '' ) ;
375 $html .= '<param name="scale" value="'. $f_scale .'" />' . $endl ;
376 $html .= '<param name="wmode" value="'. $f_wmode .'" />' . $endl ;
377 $html .= ( $f_swlive == 'true' ? '<param name="swliveconnect" value="'. $f_swlive .'" />' . $endl : '' ) ;
378 if ($Flash_Vars) {$html .= '<param name="FlashVars" value="' . $Flash_Vars . '" />' . $endl ;}
379 $html .= '<embed src="' . $f_source
380 .'" wmode="' . $f_wmode
381 .'" bgcolor="' . $f_bgcolor
382 .'" loop="' . $f_loop
383 .'" menu="' . $f_menu
384 .'" play="' . $f_play
385 .'" quality="' . $f_quality
386 .'" scale="' . $f_scale
387 .'" width="' . $f_width
388 .'" height="' . $f_height
389 .'" name="' . $f_name . '"'
390 . ( $f_salign ? ' salign="' . $f_salign . '"' : '' )
391 . ( $f_align ? ' align="' . $f_align . '"' : '' )
392 . ( $f_swlive == 'true' ? ' swliveconnect="' . $f_swlive . '"' : '' )
393 . ' allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"'
394 . ($Flash_Vars ? $endl.' FlashVars="'.$Flash_Vars.'"' : '')
395 .' />' . $endl ;
396 $html .= '</object></span>' . $endl ;
397
398 return $html;
399 }
400
401 function theme_flash_filter_add_to_teaser($node, $file, $params) {
402 $type = ((( variable_get('flash_filter_link_movie', 0) == 0 ) && $params['teaser']) ? 'movie' : 'link' );
403 if (variable_get('flash_filter_teaser_order', 0) == 1) {
404 return theme('flash_filter_as_' . $type, $file->filepath, $params) . $node->teaser;
405 }
406 else {
407 return $node->teaser . theme('flash_filter_as_' . $type, $file->filepath, $params);
408 }
409 }
410
411 function theme_flash_filter_add_to_body($node, $file, $params) {
412 $type = ((( variable_get('flash_filter_link_movie', 0) == 0 ) && $params['fits']) ? 'movie' : 'link' );
413 if (variable_get('flash_filter_body_order', 0) == 1) {
414 return theme('flash_filter_as_' . $type, $file->filepath, $params) . $node->body;
415 }
416 else {
417 return $node->body . theme('flash_filter_as_' . $type, $file->filepath, $params);
418 }
419 }
420
421 function _flash_filter_auto_add($node) {
422 $flash_filter_file = _flash_filter_fileobj($node, $value);
423 //0 Autofilter is disabled
424 //1 Attach ony to teaser
425 //2 Attach only to body
426 //3 Attach to teaser and body
427 switch (variable_get('auto_use_flash_filter_'. $node->type, 0)) {
428 case 1:
429 foreach ($node->files as $fid => $file) {
430 $params = _flash_filter_verify_movie_object($file->filepath);
431 if ( $params['is_flash'] ) {
432 $node->files[$fid]->flash_filter = TRUE;
433 $node->teaser = theme('flash_filter_add_to_teaser', $node, $file, array('width' => $params['width'], 'height' => $params['height'], 'teaser' => $params['teaser']));
434 }
435 else {
436 $node->files[$fid]->flash_filter = FALSE;
437 }
438 }
439 break;
440 case 2:
441 foreach ($node->files as $fid => $file) {
442 $params = _flash_filter_verify_movie_object($file->filepath);
443 if ( $params['is_flash'] ) {
444 $node->files[$fid]->flash_filter = TRUE;
445 $node->body = theme('flash_filter_add_to_body', $node, $file, array('width' => $params['width'], 'height' => $params['height'], 'fits' => $params['fits']));
446 }
447 else {
448 $node->files[$fid]->flash_filter = FALSE;
449 }
450 }
451 break;
452 case 3:
453 foreach ($node->files as $fid => $file) {
454 $params = _flash_filter_verify_movie_object($file->filepath);
455 if ( $params['is_flash'] ) {
456 $node->files[$fid]->flash_filter = TRUE;
457 $node->body = theme('flash_filter_add_to_body', $node, $file, array('width' => $params['width'], 'height' => $params['height'], 'fits' => $params['fits']));
458 $node->teaser = theme('flash_filter_add_to_teaser', $node, $file, array('width' => $params['width'], 'height' => $params['height'], 'teaser' => $params['teaser']));
459 }
460 else {
461 $node->files[$fid]->flash_filter = FALSE;
462 }
463 }
464 break;
465 }
466
467 return $node;
468 }
469
470 function _flash_filter_fileobj(&$node, $id) {
471 if (is_numeric($id)) {
472 $n=1;
473 foreach ($node->files as $file) {
474 if ($n == $id) {
475
476 return $file;
477 }
478 ++$n;
479 }
480
481 return NULL;
482 }
483 else
484 {
485 foreach ($node->files as $file) {
486 if ($file->filename == $id) {
487 return $file;
488 }
489 }
490
491 return NULL;
492 }
493 }
494
495 function _flash_filter_process_text($text) {
496 $endl = chr(13) ;
497 if (preg_match_all('/\[\s*flashvars\s*[:]{1,1}\s*(\w+)\s(.*?)\s*\]/i', $text, $flashvars)) {
498 foreach ($flashvars[1] as $v_key => $v_name) {$export_flashvars[$v_name] = $flashvars[2][check_plain($v_key)];
499 $matched[] = $flashvars[0][$v_key];
500 $rewrite[] = '';
501 }
502 }
503 if (preg_match_all('/\[\s*(flash|flash_link)\s*[:]{1,1}\s*([\w+\/\.]+)\s*(.*?)\s*?\]/i', $text, $match)) {
504 // $match[0][xx] .... fully matched string [flash:filename.swf parm_0="value_0" parm_1="value_1" parm_2="value_2"]
505 // $match[1][xx] .... matched tag type ( flash | flash_link )
506 // $match[2][xx] .... matched filename ( filename.swf )
507 // $match[3][xx] .... full params string what follows after filename.swf
508 foreach ($match[2] as $key => $value) {
509 preg_match_all('/\s+?(wmode|bgcolor|menu|play|loop|quality|salign|align|scale|swliveconnect|name|width|height|title)\s*=\s*[\"](.*?)[\"]+?/i',$match[0][$key],$params[$key]);
510 foreach ($params[$key][1] as $p_key => $p_name) {
511 $export_params[$key][$p_name] = $params[$key][2][$p_key];
512 // echo $endl."[".$key."][".$p_key."] ".$p_name." = " .$params[$key][2][$p_key];
513 }
514 }
515 foreach ($match[2] as $key => $value) {
516 $file_path = file_create_path($value);
517 $link_type = $match[1][$key];
518 $replace = '';
519 if (file_exists($file_path)) {
520 $swf_params = _flash_filter_verify_movie_object($file_path);
521 $export_params[$key]['width'] = ($export_params[$key]['width']) ? $export_params[$key]['width'] : $swf_params['width'];
522 $export_params[$key]['height'] = ($export_params[$key]['height']) ? $export_params[$key]['height'] : $swf_params['height'];
523 if ( $swf_params['fits'] && $link_type == 'flash' ) {
524 $replace = theme('flash_filter_as_movie', $file_path, $export_params[$key], filter_xss_bad_protocol($export_flashvars[$export_params[$key]['name']]));
525 }
526 elseif ( $swf_params['is_flash'] ) {
527 $replace = theme('flash_filter_as_link', $file_path, $export_params[$key], filter_xss_bad_protocol($export_flashvars[$export_params[$key]['name']]));
528 }
529 else {
530 $replace = '<br /><span style="color:red; font-weight:bold">' . t('Requested file:') . '&nbsp;[' .$value . ']&nbsp;' . t('isn\'t a valid Flash Movie object') . '</span><br />';
531 }
532 }
533 else {
534 $replace = '<br /><span style="color:red; font-weight:bold">' . t('Requested file:') . '&nbsp;[' .$value . ']&nbsp;' . t('doesn\'t exists') . '</span><br />';
535 }
536 $matched[] = $match[0][$key];
537 $rewrite[] = $replace;
538 }
539
540 return str_replace($matched, $rewrite, $text);
541 }
542
543 return $text;
544 }
545
546 function _flash_filter_verify_movie_object($file_path) {
547 $flash_file = file_create_path($file_path);
548 if (file_exists($flash_file)) {
549 $swf = new swfheader(false);
550 $swf->loadswf($flash_file);
551 if ($swf->valid) {
552 list($maxwidth, $maxheight) = explode(',',variable_get('flash_filter_movie_size', '640,480'));
553 list($teaser_width, $teaser_height) = explode(',',variable_get('flash_filter_teaser_movie_size', '100,100'));
554 if ($swf->width <= $maxwidth && $swf->height <= $maxheight) {
555 if ($swf->width <= $teaser_width && $swf->height <= $teaser_height) {
556 return array('width' => $swf->width, 'height' => $swf->height, 'fits' => TRUE, 'teaser' => TRUE, 'is_flash' => TRUE );
557 }
558 else {
559 return array('width' => $swf->width, 'height' => $swf->height, 'fits' => TRUE, 'teaser' => FALSE, 'is_flash' => TRUE );
560 }
561 }
562 else {
563 return array('width' => $swf->width, 'height' => $swf->height, 'fits' => FALSE, 'teaser' => FALSE, 'is_flash' => TRUE );
564 }
565 }
566 return FALSE;
567 }
568 return FALSE;
569 }
570 ?>

  ViewVC Help
Powered by ViewVC 1.1.2