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', '
'); 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[] = '