SWFObject - the best way to embed Flash on your site. Version: 2.2.1.xxx-ver3 Author: Michael Bester [aside from fixes marked xxx] Author URI: http://www.kimili.com Update: http://www.kimili.com/plugins/kml_flashembed/wp */ /////////////////////////////////////////////////////////// // XXX fixes, 2012/05 /////////////////////////////////////////////////////////// // 1. Add option to use the WP version of swfobject.js, which is more up-to-date than the Google version, which is the version included in this plugin. Has security fixes. // 2. Fix enqeue/deregister notices in debug: // Notice: wp_deregister_script was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or init hooks. // Notice: wp_enqueue_script was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or init hooks. // 3. Fix has_cap deprecated notice in debug: // Notice: has_cap was called with an argument that is deprecated since version 2.0! Usage of user levels by plugins and themes is deprecated. Use roles and capabilities instead. /////////////////////////////////////////////////////////// /* * * KIMILI FLASH EMBED * * Copyright 2010 Michael Bester (http://www.kimili.com) * Released under the GNU General Public License (http://www.gnu.org/licenses/gpl.html) * */ /** * */ class KimiliFlashEmbed { var $version = '2.2.1'; var $staticSwfs = array(); var $dynamicSwfs = array(); /////////////////////////////////////////////////////////// // XXX add, 2012/05 /////////////////////////////////////////////////////////// function xxx_fix_admin_enqueue_scripts_kfe($hook) { // see http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts // print "\n"; // 2012/05/28: could restrict this to certain hooks. Need at least: // settings_page_kimili-flash-embed/kml_flashembed, post-new.php, post.php, ... // But to be sure, put on all admin pages! wp_enqueue_script( 'kimiliflashembed', plugins_url('/kimili-flash-embed/js/kfe.js'), array(), $this->version ); } function xxx_fix_enqueue_scripts_swfobject() { ////////////////////////////////////////////////////////////////////////////////////// // XXX NOTE 2012/05/27: as of WP 3.3.2, the WP version of swfobject.js (2.2-20120417) // has SECURITY FIXES not yet in the Gooogle version (2.2), the same as the // version included in this plugin. Development for 2.3 seems to have moved to GitHub. /////////////////////////////////////////////////////////////////////////////////////// $swfobject_source= get_option('kml_flashembed_swfobject_source'); if ( $swfobject_source ) { // Let's override WP's bundled swfobject, cause as of WP 2.9, it's still using 2.1 wp_deregister_script('swfobject'); // and register our own. if ( $swfobject_source == '1' ) { wp_register_script( 'swfobject', 'http' . (is_ssl() ? 's' : '') . '://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js', array(), '2.2' ); } else { wp_register_script( 'swfobject', plugins_url('/kimili-flash-embed/js/swfobject.js'), array(), '2.2' ); } } // otherwise, $swfobject_source == '0', use the Wordress version wp_enqueue_script('swfobject'); } /////////////////////////////////////////////////////////// function KimiliFlashEmbed() { // Register Hooks if (is_admin()) { // Load up the localization file if we're using WordPress in a different language // Place it in this plugin's "langs" folder and name it "kimili-flash-embed-[value in wp-config].mo" load_plugin_textdomain( 'kimili-flash-embed', FALSE, 'kimili-flash-embed/langs/'); // Default Options add_option('kml_flashembed_filename', 'untitled.swf'); add_option('kml_flashembed_target_class', 'flashmovie'); add_option('kml_flashembed_publish_method', '0'); add_option('kml_flashembed_version_major', '8'); add_option('kml_flashembed_version_minor', '0'); add_option('kml_flashembed_version_revision', '0'); add_option('kml_flashembed_alt_content', '

Get Adobe Flash player

'); add_option('kml_flashembed_reference_swfobject', '1'); add_option('kml_flashembed_swfobject_source', '0'); add_option('kml_flashembed_width', '400'); add_option('kml_flashembed_height', '300'); // Set up the options page add_action('admin_menu', array(&$this, 'options_menu')); // Add Quicktag if (current_user_can('edit_posts') || current_user_can('edit_pages') ) { add_action( 'edit_form_advanced', array(&$this, 'add_quicktags') ); add_action( 'edit_page_form', array(&$this, 'add_quicktags') ); } // Queue Embed JS add_action( 'admin_head', array(&$this, 'set_admin_js_vars')); /////////////////////////////////////////////////////////// // XXX del, 2012/05 /////////////////////////////////////////////////////////// // wp_enqueue_script( 'kimiliflashembed', plugins_url('/kimili-flash-embed/js/kfe.js'), array(), $this->version ); /////////////////////////////////////////////////////////// // XXX add /////////////////////////////////////////////////////////// add_action( 'admin_enqueue_scripts', array(&$this, 'xxx_fix_admin_enqueue_scripts_kfe')); /////////////////////////////////////////////////////////// } else { // Front-end if ($this->is_feed()) { $this->doObStart(); } else { add_action('wp_head', array(&$this, 'disableAutohide'), 9); add_action('wp_head', array(&$this, 'doObStart')); add_action('wp_head', array(&$this, 'addScriptPlaceholder')); add_action('wp_footer', array(&$this, 'doObEnd')); } } // Queue SWFObject if ( get_option('kml_flashembed_reference_swfobject') == '1') { /////////////////////////////////////////////////////////// // XXX del, 2012/05 /////////////////////////////////////////////////////////// // // Let's override WP's bundled swfobject, cause as of WP 2.9, it's still using 2.1 // wp_deregister_script('swfobject'); // // and register our own. // if ( get_option('kml_flashembed_swfobject_source') == '0' ) { // wp_register_script( 'swfobject', 'http' . (is_ssl() ? 's' : '') . '://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js', array(), '2.2' ); // } else { // wp_register_script( 'swfobject', plugins_url('/kimili-flash-embed/js/swfobject.js'), array(), '2.2' ); // } // wp_enqueue_script('swfobject'); /////////////////////////////////////////////////////////// // XXX add /////////////////////////////////////////////////////////// add_action( 'wp_enqueue_scripts', array(&$this, 'xxx_fix_enqueue_scripts_swfobject')); /////////////////////////////////////////////////////////// } } function parseShortcodes($content) { $pattern = '/(

[\s\n\r]*)?\[(kml_(flash|swf)embed)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?([\s\n\r]*<\/p>)?/s'; $temp = preg_replace_callback($pattern, array(&$this, 'processShortcode'), $content); $result = preg_replace_callback('/KML_FLASHEMBED_PROCESS_SCRIPT_CALLS/s', array(&$this, 'scriptSwfs'), $temp); return $result; } // Thanks to WP shortcode API Code function processShortcode($code) { $r = ""; $atts = $this->parseAtts($code[4]); $altContent = isset($code[6]) ? $code[6] : ''; $attpairs = preg_split('/\|/', $elements, -1, PREG_SPLIT_NO_EMPTY); if (isset($atts['movie'])) { $atts['height'] = (isset($atts['height'])) ? $atts['height'] : get_option('kml_flashembed_height'); $atts['width'] = (isset($atts['width'])) ? $atts['width'] : get_option('kml_flashembed_width'); $atts['fversion'] = (isset($atts['fversion'])) ? $atts['fversion'] : get_option('kml_flashembed_version_major').'.'.get_option('kml_flashembed_version_minor').'.'.get_option('kml_flashembed_version_revision'); $atts['targetclass'] = (isset($atts['targetclass'])) ? $atts['targetclass'] : get_option('kml_flashembed_target_class'); $atts['publishmethod'] = (isset($atts['publishmethod'])) ? $atts['publishmethod'] : (get_option('kml_flashembed_publish_method') ? 'dynamic' : 'static'); $atts['useexpressinstall'] = (isset($atts['useexpressinstall'])) ? $atts['useexpressinstall'] : 'false'; $atts['xiswf'] = plugins_url('/kimili-flash-embed/lib/expressInstall.swf'); $rand = mt_rand(); // For making sure this instance is unique // Extract the filename minus the extension... $swfname = (strrpos($atts['movie'], "/") === false) ? $atts['movie'] : substr($atts['movie'], strrpos($atts['movie'], "/") + 1, strlen($atts['movie'])); $swfname = (strrpos($swfname, ".") === false) ? $swfname : substr($swfname, 0, strrpos($swfname, ".")); // set an ID for the movie if necessary if (!isset($atts['fid'])) { // ... to use as a default ID if an ID is not defined. $atts['fid'] = "fm_" . $swfname . "_" . $rand; } if (!isset($atts['target'])) { // ... and a target ID if need be for the dynamic publishing method $atts['target'] = "so_targ_" . $swfname . "_" . $rand; } // Parse out the fvars if (isset($atts['fvars'])) { $fvarpair_regex = "/(?", $atts['alttext']) : $altContent; // Strip leading

and trailing

- detritius from the way the tags are parsed out of the RTE $patterns = array( "/^[\s\n\r]*<\/p>/i", "/

[\s\n\r]*$/i" ); $atts['alttext'] = preg_replace($patterns, "", $atts['alttext']); // If we're not serving up a feed, generate the script tags if (is_feed()) { $r = $this->buildObjectTag($atts); } else { if ($atts['publishmethod'] == 'static') { $r = $this->publishStatic($atts); } else { $r = $this->publishDynamic($atts); } } } return $r; } // Thanks to WP shortcode API Code function parseAtts($text) { $atts = array(); $pattern = '/(\w+)\s*=\s*"([^"]*)"(?:\s|$)|(\w+)\s*=\s*\'([^\']*)\'(?:\s|$)|(\w+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)/'; $text = preg_replace("/[\x{00a0}\x{200b}]+/u", " ", $text); if ( preg_match_all($pattern, $text, $match, PREG_SET_ORDER) ) { foreach ($match as $m) { if (!empty($m[1])) $atts[strtolower($m[1])] = stripcslashes($m[2]); elseif (!empty($m[3])) $atts[strtolower($m[3])] = stripcslashes($m[4]); elseif (!empty($m[5])) $atts[strtolower($m[5])] = stripcslashes($m[6]); elseif (isset($m[7]) and strlen($m[7])) $atts[] = stripcslashes($m[7]); elseif (isset($m[8])) $atts[] = stripcslashes($m[8]); } } else { $atts = ltrim($text); } return $atts; } function publishStatic($atts) { if (is_array($atts)) { extract($atts); } $this->staticSwfs[] = array( 'id' => $fid, 'version' => $fversion, 'useexpressinstall' => $useexpressinstall, 'xiswf' => $xiswf ); return $this->buildObjectTag($atts); } function publishDynamic($atts) { if (is_array($atts)) { extract($atts); } $this->dynamicSwfs[] = $atts; $out = array(); $out[] = '

'.$alttext.'
'; return join("\n", $out); } function addScriptPlaceholder() { echo 'KML_FLASHEMBED_PROCESS_SCRIPT_CALLS'; } function disableAutohide() { // If we want to use autohide, or we don't have any swfs on the page, drop out. if (get_option('kml_flashembed_swfobject_use_autohide')) { return false; } // Otherwise build out the script. $out = array(); $out[] = ''; $out[] = ''; $out[] = ''; echo join("\n", $out); } function scriptSwfs() { // If we don't have any swfs on the page, drop out. if (count($this->staticSwfs) == 0 && count($this->dynamicSwfs) == 0) { return ''; } // Otherwise build out the script. $out = array(); $out[] = ''; $out[] = ''; $out[] = ''; return join("\n", $out); } function buildObjectTag($atts) { $out = array(); if (is_array($atts)) { extract($atts); } // Build a query string based on the $fvars attribute $querystring = join("&", $this->parseFvars($fvars)); $out[] = ''; $out[] = ''; $out[] = ' '; if (count($fvars) > 0) $out[] = ' '; if (isset($play)) $out[] = ' '; if (isset($loop)) $out[] = ' '; if (isset($menu)) $out[] = ' '; if (isset($quality)) $out[] = ' '; if (isset($scale)) $out[] = ' '; if (isset($salign)) $out[] = ' '; if (isset($wmode)) $out[] = ' '; if (isset($bgcolor)) $out[] = ' '; if (isset($base)) $out[] = ' '; if (isset($swliveconnect)) $out[] = ' '; if (isset($devicefont)) $out[] = ' '; if (isset($allowscriptaccess)) $out[] = ' '; if (isset($seamlesstabbing)) $out[] = ' '; if (isset($allowfullscreen)) $out[] = ' '; if (isset($allownetworking)) $out[] = ' '; $out[] = ' '; $out[] = ' '; if (count($fvars) > 0) $out[] = ' '; if (isset($play)) $out[] = ' '; if (isset($loop)) $out[] = ' '; if (isset($menu)) $out[] = ' '; if (isset($quality)) $out[] = ' '; if (isset($scale)) $out[] = ' '; if (isset($salign)) $out[] = ' '; if (isset($wmode)) $out[] = ' '; if (isset($bgcolor)) $out[] = ' '; if (isset($base)) $out[] = ' '; if (isset($swliveconnect)) $out[] = ' '; if (isset($devicefont)) $out[] = ' '; if (isset($allowscriptaccess)) $out[] = ' '; if (isset($seamlesstabbing)) $out[] = ' '; if (isset($allowfullscreen)) $out[] = ' '; if (isset($allownetworking)) $out[] = ' '; $out[] = ' '; if (isset($alttext)) $out[] = ' '.$alttext; $out[] = ' '; $out[] = ' '; $out[] = ' '; $out[] = ''; $ret .= join("\n", $out); return $ret; } function parseFvars($fvars, $format='string') { $ret = array(); for ($i = 0; $i < count($fvars); $i++) { $thispair = trim($fvars[$i]); $nvpair = explode("=",$thispair); $name = trim($nvpair[0]); $value = ""; for ($j = 1; $j < count($nvpair); $j++) { // In case someone passes in a fvars with additional "=" $value .= trim($nvpair[$j]); $value = preg_replace('/&/', '&', $value); if ((count($nvpair) - 1) != $j) { $value .= "="; } } // Prune out JS or PHP values if (preg_match("/^\\$\\{.*\\}/i", $value)) { // JS $endtrim = strlen($value) - 3; $value = substr($value, 2, $endtrim); $value = str_replace(';', '', $value); } else if (preg_match("/^\\?\\{.*\\}/i", $value)) { // PHP $endtrim = strlen($value) - 3; $value = substr($value, 2, $endtrim); $value = eval("return " . $value); } if ($format == 'string') { $ret[] = $name . '=' . $value; } else { $ret[] = $name . ' : "' . $value . '"'; } } return $ret; } function doObStart() { ob_start(array(&$this, 'parseShortcodes')); } function doObEnd() { // Check the output buffer if (function_exists('ob_list_handlers')) { $active_handlers = ob_list_handlers(); } else { $active_handlers = array(); } if (sizeof($active_handlers) > 0 && strtolower($active_handlers[sizeof($active_handlers) - 1]) == strtolower('KimiliFlashEmbed::parseShortcodes')) { ob_end_flush(); } } function is_feed() { return preg_match("/(\/\?feed=|\/feed)/i",$_SERVER['REQUEST_URI']); } function set_admin_js_vars() { ?> '; ?> version ); /////////////////////////////////////////////////////////// // update options if (isset($_POST['action']) && $_POST['action'] == 'kml_flashembed_update') { $filename = preg_replace("/(^|&\S+;)|(<[^>]*>)/U", '', strip_tags($_POST['filename'])); $target_class = preg_replace("/(^|&\S+;)|(<[^>]*>)/U", '', strip_tags($_POST['target_class'])); $flash_id = preg_replace("/(^|&\S+;)|(<[^>]*>)/U", '', strip_tags($_POST['flash_id'])); $alt_content = $_POST['alt_content']; $fvars = $_POST['fvars']; $version_major = preg_replace("/\D/s", '', $_POST['version_major']); $version_minor = preg_replace("/\D/s", '', $_POST['version_minor']); $version_revision = preg_replace("/\D/s", '', $_POST['version_revision']); $width = preg_replace("/[\D[^%]]/", '', $_POST['width']); $height = preg_replace("/[\D[^%]]/", '', $_POST['height']); $bgcolor = (preg_match("/^#?[0-9a-f]{6}$/i", $_POST['bgcolor'])) ? $_POST['bgcolor'] : ""; $base = preg_replace("/(^|&\S+;)|(<[^>]*>)/U", '', strip_tags($_POST['base'])); if ($bgcolor != "" && !preg_match("/^#/", $bgcolor)) { $bgcolor = "#" . $bgcolor; } if (empty($version_major)) { $version_major = '8'; } if (empty($version_minor)) { $version_minor = '0'; } if (empty($version_revision)) { $version_revision = '0'; } if (empty($width)) { $width = '400'; } if (empty($height)) { $height = '300'; } $publish_method = ($_POST['publish_method'] == '1') ? $_POST['publish_method'] : '0'; $reference_swfobject = ($_POST['reference_swfobject'] == '0') ? $_POST['reference_swfobject'] : '1'; ///////////////////////////// // XXX del, 2012/05 ///////////////////////////// // $swfobject_source = ($_POST['swfobject_source'] == '1') ? $_POST['swfobject_source'] : '0'; ///////////////////////////// // XXX add ///////////////////////////// $swfobject_source = $_POST['swfobject_source']; $swfobject_source === '1' || $swfobject_source === '2' or $swfobject_source = '0'; ///////////////////////////// $swfobject_use_autohide = ($_POST['swfobject_use_autohide'] == '0') ? $_POST['swfobject_use_autohide'] : '1'; $use_express_install = ($_POST['use_express_install'] == '0') ? $_POST['use_express_install'] : '1'; $dimensions_unit = ($_POST['unit'] == 'percentage') ? $_POST['unit'] : 'pixels'; $message = $message_updated; update_option('kml_flashembed_filename', $filename); update_option('kml_flashembed_target_class', $target_class); update_option('kml_flashembed_flash_id', $flash_id); update_option('kml_flashembed_publish_method', $publish_method); update_option('kml_flashembed_version_major', $version_major); update_option('kml_flashembed_version_minor', $version_minor); update_option('kml_flashembed_version_revision', $version_revision); update_option('kml_flashembed_alt_content', $alt_content); update_option('kml_flashembed_reference_swfobject', $reference_swfobject); update_option('kml_flashembed_swfobject_source', $swfobject_source); update_option('kml_flashembed_swfobject_use_autohide', $swfobject_use_autohide); update_option('kml_flashembed_width', $width); update_option('kml_flashembed_height', $height); update_option('kml_flashembed_dimensions_unit', $dimensions_unit); update_option('kml_flashembed_use_express_install', $use_express_install); update_option('kml_flashembed_align', $_POST['align']); update_option('kml_flashembed_play', $_POST['play']); update_option('kml_flashembed_loop', $_POST['loop']); update_option('kml_flashembed_menu', $_POST['menu']); update_option('kml_flashembed_quality', $_POST['quality']); update_option('kml_flashembed_scale', $_POST['scale']); update_option('kml_flashembed_salign', $_POST['salign']); update_option('kml_flashembed_wmode', $_POST['wmode']); update_option('kml_flashembed_bgcolor', $bgcolor); update_option('kml_flashembed_devicefont', $_POST['devicefont']); update_option('kml_flashembed_seamlesstabbing', $_POST['seamlesstabbing']); update_option('kml_flashembed_swliveconnect', $_POST['swliveconnect']); update_option('kml_flashembed_allowfullscreen', $_POST['allowfullscreen']); update_option('kml_flashembed_allowscriptaccess', $_POST['allowscriptaccess']); update_option('kml_flashembed_allownetworking', $_POST['allownetworking']); update_option('kml_flashembed_base', $base); update_option('kml_flashembed_fvars', $fvars); if (function_exists('wp_cache_flush')) { wp_cache_flush(); } } ?>

/> />

. .
/> />

×


?

/> />
/> // /> //
// ? ///////////////////////////// // XXX add ///////////////////////////// $swfobject_source= get_option('kml_flashembed_swfobject_source'); ?>

/> (XXX: Recommended as of 2012/05/27)

/>

/>

?

/> />
?

»" />

version; } // Load the custom TinyMCE plugin function kml_flashembed_plugin( $plugins ) { $plugins['kimiliflashembed'] = plugins_url('/kimili-flash-embed/lib/tinymce3/editor_plugin.js'); return $plugins; } function kml_flashembed_button( $buttons ) { array_push( $buttons, 'separator', 'kimiliFlashEmbed' ); return $buttons; } ?>