'300', 'width' => '400', 'alt' => '
'.__('The Flash plugin is required to view this object.', 'swfobj').'
', 'required_player_version' => '8.0.0', 'express_install_swf' => plugins_url().'/swfobj/expressInstall.swf', 'allowfullscreen' => 'false', 'wmode' => 'window', 'dynamic_embed' => 'false' ); $saved_options = get_option($this->admin_options_saved); if (!empty($saved_options)) { foreach($saved_options as $key => $val) { $admin_options[$key] = $val; } } update_option($this->admin_options_saved, $admin_options); return $admin_options; } function init() { // Wordpress 3.0 uses version 2.2 of swfobject.js if ( version_compare( get_bloginfo( 'version' ) , '3.0' , '<' ) ) { wp_enqueue_script('swfobject'); } else { // Wordpress < 3.0 uses the older swfobject.js version (2.1) // Use the plugin version of swfobject as it is current wp_deregister_script('swfobject'); wp_register_script('swfobject', plugins_url().'/swfobj/swfobject.js', false, '2.2'); wp_enqueue_script('swfobject'); } } function activate() { $this->get_options(); } // Add Javascript to end of page to register all swf objects. function swfobj_footer() { global $registered_objects; global $flag_static_embed; // register any swf files on the page if (count($registered_objects) > 0) { echo ' '."\n"; } } // [swfobj] shortcode handler function swfobj_func($atts, $content=null) { global $registered_objects; global $flag_static_embed; $defaults = $this->get_options(); extract(shortcode_atts(array( 'src' => '', 'width' => $defaults['width'], 'height' => $defaults['height'], 'id' => 'swfobj_'.count($registered_objects), 'alt' => $defaults['alt'], 'name' => false, 'class' => false, 'align' => false, 'required_player_version' => $defaults['required_player_version'], 'express_install_swf' => $defaults['express_install_swf'], 'quality' => false, 'bgcolor' => false, 'getvars' => false, 'scale' => false, 'salign' => false, 'wmode' => $defaults['wmode'], 'base' => false, 'allownetworking' => false, 'allowscriptaccess' => false, 'callbackFn' => false, // The following parameters are true/false only // TODO: Check if they are set to true or false, if not, ignore them? 'allowfullscreen' => $defaults['allowfullscreen'], 'flashvars' => false, 'loop' => false, 'menu' => false, 'play' => false, 'swliveconnect' => false, 'seamlesstabbing' => false, 'devicefont' => false, 'dynamic_embed' => $defaults['dynamic_embed'] ), $atts)); // pull alt from inner content if it exists if ($content !== null) { $alt = $content; } $extraparams = array( 'align' => false, 'allowfullscreen' => 'false', 'bgcolor' => false, 'getvars' => false, 'quality' => false, 'flashvars' => false, 'name' => false, 'scale' => false, 'salign' => false, 'loop' => false, 'menu' => false, 'play' => false, 'wmode' => 'window', 'base' => false, 'swliveconnect' => false, 'seamlesstabbing' => false, 'allownetworking' => false, 'allowscriptaccess' => false, 'devicefont' => false, 'callbackFn' => false ); $params = ''; $attributes = ''; $flag_static_embed = !($dynamic_embed == 'true'); if ($flag_static_embed) { // SWF is embedded statically (directly in the HTML) // loop through all params and get value foreach( $extraparams as $param => $default ){ if( ${$param} !== false && ${$param} != $default ){ $params .= "\n ".''; $attributes .= ' '.$param.'="'.${$param}.'"'; } } // Add this object to the array so it will be registered in the header $registered_objects[] = array('id' => $id, 'required_player_version' => $required_player_version, 'express_install_swf' => $express_install_swf, 'embed' => 'static'); $swfobj = ' '; } else { // SWF is embedded dynamically (using Javascript) // Only place the alternative content on the page // loop through all params and get values $params = array(); $flash_vars = array(); foreach( $extraparams as $param => $default ){ // make sure you aren't adding anything you don't need here // params are different in the dynamic version if( ${$param} !== false && ${$param} != $default ){ // extract flashvars out separately if ( $param == 'flashvars' ) { $tmpvars = explode('&', ${$param}); if ( count($tmpvars) < 2 ) { // make sure they didn't separate vars with & instead of $#038; $tmpvars = explode('&', ${$param}); } foreach ($tmpvars as $tmpvar) { $tmpvararray = explode('=', $tmpvar); $flash_vars[ $tmpvararray[0] ] = $tmpvararray[1]; } } else { $params[$param] = ${$param}; } } } // Get all attribute values $attributes = array(); if ($name) { $attributes['name'] = $name; } // Add this object to the array so it will be registered // (swfUrl, id, width, height, version, expressInstallSwfurl, flashvars, params, attributes, callbackFn) $registered_objects[] = array( 'swfUrl' => $src, 'id' => $id, 'width' => $width, 'height' => $height, 'version' => $required_player_version, 'expressInstallSwfurl' => $express_install_swf, 'flashvars' => $flash_vars, 'params' => $params, 'attributes' => $attribute, 'callbackFn' => $callbackFn, 'embed' => 'dynamic' ); $swfobj = '
';
}
function media_upload_flash() {
if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
// Upload File button was clicked
$id = media_handle_upload('async-upload', $_REQUEST['post_id']);
unset($_FILES);
if ( is_wp_error($id) ) {
$errors['upload_error'] = $id;
$id = false;
}
}
if ( !empty($_POST['insertonlybutton']) ) {
$src = $_POST['insertonly']['src'];
$title = stripslashes( htmlspecialchars ($_POST['insertonly']['post_title'], ENT_QUOTES));
$alt = $_POST['insertonly']['post_content'];
if ( !empty($src) && !strpos($src, '://') ) {
$src = "http://$src";
}
// append any additional properties passed to the object.
// I don't like that I'm doing the same thing here in two places
// TODO: Need to make this so it only happens in one location.
$extras = '';
if ( !empty($_POST['insertonly']['width']) && intval($_POST['insertonly']['width']) ) {
$extras .= ' width="'.stripslashes( htmlspecialchars ($_POST['insertonly']['width'], ENT_QUOTES)).'"';
}
if ( !empty($_POST['insertonly']['height']) && intval($_POST['insertonly']['height']) ) {
$extras .= ' height="'.stripslashes( htmlspecialchars ($_POST['insertonly']['height'], ENT_QUOTES)).'"';
}
if ( !empty($_POST['insertonly']['id']) ) {
$extras .= ' id="'.stripslashes( htmlspecialchars ($_POST['insertonly']['id'], ENT_QUOTES)).'"';
}
if ( !empty($_POST['insertonly']['name']) ) {
$extras .= ' name="'.stripslashes( htmlspecialchars ($_POST['insertonly']['name'], ENT_QUOTES)).'"';
}
if ( !empty($_POST['insertonly']['class']) ) {
$extras .= ' class="'.stripslashes( htmlspecialchars ($_POST['insertonly']['class'], ENT_QUOTES)).'"';
}
if ( isset($_POST['insertonly']['align']) ) {
$extras .= ' align="'.$_POST['insertonly']['align'].'"';
}
if ( isset($_POST['insertonly']['allowfullscreen']) ) {
$extras .= ' allowfullscreen="'.$_POST['insertonly']['allowfullscreen'].'"';
}
if ( !empty($_POST['insertonly']['required_player_version']) ) {
$extras .= ' required_player_version="'.stripslashes( htmlspecialchars ($_POST['insertonly']['required_player_version'], ENT_QUOTES)).'"';
}
if ( !empty($src) ) {
$html = '[swfobj src="'.$src.'"'.$extras.( ($alt != '') ? ']'.$alt.'[/swfobj]' : '] ');
}
return media_send_to_editor($html);
}
if ( !empty($_POST) ) {
$return = media_upload_form_handler();
if ( is_string($return) )
return $return;
if ( is_array($return) )
$errors = $return;
}
if ( isset($_POST['save']) ) {
$errors['upload_notice'] = __('Saved.');
}
if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' ) {
return wp_iframe( 'media_upload_type_url_form', 'flash', $errors, $id );
}
return wp_iframe( 'media_upload_type_form', 'flash', $errors, $id );
}
function modify_post_mime_types($post_mime_types) {
if ( function_exists( '_n_noop' ) ) :
$post_mime_types['application/x-shockwave-flash'] = array(__('Flash', 'swfobj'), __('Manage Flash', 'swfobj'), _n_noop('Flash (%s)', 'Flash (%s)', 'swfobj'));
else :
$post_mime_types['application/x-shockwave-flash'] = array(__('Flash', 'swfobj'), __('Manage Flash', 'swfobj'), __ngettext_noop('Flash (%s)', 'Flash (%s)', 'swfobj'));
endif;
return $post_mime_types;
}
function flash_media_send_to_editor($html) {
if ( isset($_POST['send']) ) {
$keys = array_keys($_POST['send']);
$send_id = (int) array_shift($keys);
$flashobj = $_POST['attachments'][$send_id];
// only process Flash objects here
if ( isset($flashobj['media_type']) && $flashobj['media_type'] == 'application/x-shockwave-flash' ) {
$src = $flashobj['src'];
$title = stripslashes( htmlspecialchars ($flashobj['post_title'], ENT_QUOTES));
$alt = $flashobj['post_content'];
// append any additional properties passed to the object.
$extras = '';
if ( !empty($flashobj['width']) && intval($flashobj['width']) ) {
$extras .= ' width="'.stripslashes( htmlspecialchars ($flashobj['width'], ENT_QUOTES)).'"';
}
if ( !empty($flashobj['height']) && intval($flashobj['height']) ) {
$extras .= ' height="'.stripslashes( htmlspecialchars ($flashobj['height'], ENT_QUOTES)).'"';
}
if ( !empty($flashobj['id']) ) {
$extras .= ' id="'.stripslashes( htmlspecialchars ($flashobj['id'], ENT_QUOTES)).'"';
}
if ( !empty($flashobj['name']) ) {
$extras .= ' name="'.stripslashes( htmlspecialchars ($flashobj['name'], ENT_QUOTES)).'"';
}
if ( !empty($flashobj['class']) ) {
$extras .= ' class="'.stripslashes( htmlspecialchars ($flashobj['class'], ENT_QUOTES)).'"';
}
if ( isset($flashobj['align']) ) {
$extras .= ' align="'.$flashobj['align'].'"';
}
if ( isset($flashobj['allowfullscreen']) ) {
$extras .= ' allowfullscreen="'.$flashobj['allowfullscreen'].'"';
}
if ( !empty($flashobj['required_player_version']) ) {
$extras .= ' required_player_version="'.stripslashes( htmlspecialchars ($flashobj['required_player_version'], ENT_QUOTES)).'"';
}
$html = '[swfobj src="'.$src.'"'.$extras.( ($alt != '') ? ']'.$alt.'[/swfobj]' : '] ');
}
}
return $html;
}
function flash_attachment_fields_to_edit($form_fields, $post) {
if ( substr($post->post_mime_type, -5) == 'flash' ) {
$form_fields['post_title']['required'] = true;
unset( $form_fields['post_excerpt'] );
unset( $form_fields['url'] );
$form_fields['post_content']['label'] = __('Alternate html');
$form_fields['post_content']['helps'][] = __('Displayed when Flash is unavailable, e.g. "<p>Cool Flash game.</p>"');
$form_fields['size'] = array( 'label' => __('Size').' '.__('width/height').'',
'input' => 'html',
'html' => '
' );
// Advanced options
// sneaking in a hidden media_type input so only flash items are processed
// by this plugin when they are inserted in the post.
$form_fields['advanced_open'] = array( 'label' => __('Advanced Options'),
'input' => 'html',
'html' => '| * | |
|---|---|
Displayed when Flash is unavailable, e.g. "<p>Cool Flash game.</p>" |
|
Advanced Options | |
Minimum Flash player required to play this object. |
|