diff --git a/css/video-container UNCOMPRESSED.css b/css/video-container UNCOMPRESSED.css deleted file mode 100644 index b81fdb8..0000000 --- a/css/video-container UNCOMPRESSED.css +++ /dev/null @@ -1,16 +0,0 @@ -.ce-video-container { - position: relative; - padding-bottom: 56.25%; - height: 0; - overflow: hidden; -} - -.ce-video-container iframe, -.ce-video-container object, -.ce-video-container embed { - position: absolute; - top: 0; - left: 0; - width: 100%; - height: 100%; -} \ No newline at end of file diff --git a/css/video-container.css b/css/video-container.css index 1e000ba..2029079 100644 --- a/css/video-container.css +++ b/css/video-container.css @@ -1 +1,16 @@ -.ce-video-container{position:relative;padding-bottom:56.25%;height:0;overflow:hidden;}.ce-video-container iframe,.ce-video-container object,.ce-video-container embed{position:absolute;top:0;left:0;width:100%;height:100%;} \ No newline at end of file +.ce-video-container { + position: relative; + padding-bottom: 56.25%; + height: 0; + overflow: hidden; +} + +.ce-video-container iframe, +.ce-video-container object, +.ce-video-container embed { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; +} diff --git a/css/video-container.min.css b/css/video-container.min.css new file mode 100644 index 0000000..1e000ba --- /dev/null +++ b/css/video-container.min.css @@ -0,0 +1 @@ +.ce-video-container{position:relative;padding-bottom:56.25%;height:0;overflow:hidden;}.ce-video-container iframe,.ce-video-container object,.ce-video-container embed{position:absolute;top:0;left:0;width:100%;height:100%;} \ No newline at end of file diff --git a/includes/add-embeds.php b/includes/add-embeds.php index 05aa817..5696ded 100644 --- a/includes/add-embeds.php +++ b/includes/add-embeds.php @@ -1,317 +1,327 @@ - 1 ) { $res_pos = strpos( $suffix, '_RES', 1 ); } - - if ( $res_pos !== false ) { - - // If responsive section found, check it's at the end of has an underscore afterwards - // Otherwise it may be part of something else - - if ( $res_pos == strlen( $suffix) - 4 ) { - $responsive = true; - } else { - if ( substr( $suffix, $res_pos+4, 1 ) == '_' ) { - $responsive = true; - $max_width = substr( $suffix, $res_pos + 5 ); - if ( !is_numeric( $max_width ) ) { $max_width = ''; } - } - } - - if ( $responsive ) { $suffix = substr( $suffix, 0, $res_pos ); } - } - - // Get the custom field data and replace in the post - - $search = $options[ 'opening_ident' ] . $options[ 'keyword_ident' ] . $suffix . $options[ 'closing_ident' ]; - - // Get the meta for the current post - - $post_meta = get_post_meta( $post -> ID, $options[ 'keyword_ident' ].$suffix, false ); - if ( isset( $post_meta[ 0 ] ) ) { - $html = $post_meta[ 0 ]; - } else { - // No meta found, so look for it elsewhere - $html = ce_get_embed_code( $options[ 'keyword_ident' ], $suffix ); - } - - // Build the string to search for - - $search = $options[ 'opening_ident' ] . $options[ 'keyword_ident' ] . $full_suffix . $options[ 'closing_ident' ]; - - // Build the string of code to replace with - - $replace = ce_generate_code( $html, 'Code Embed', $responsive, $max_width, $options[ 'debug' ] ); - - // Now modify all references - - $content = str_replace( $search , $replace, $content ); - - } - $found_pos = strpos( $content, $options[ 'opening_ident' ] . $options[ 'keyword_ident' ], $found_pos + 1 ); - } - - // Loop around the post content looking for HTTP addresses - - $content = ce_quick_replace( $content, $options, 'http://' ); - - // Loop around the post content looking for HTTPS addresses - - $content = ce_quick_replace( $content, $options, 'https://' ); - - return $content; -} - -add_filter( 'the_content', 'ce_filter' ); -add_filter( 'widget_content', 'ce_filter' ); - -/** -* Quick Replace -* -* Function to do a quick search/replace of the content -* -* @since 2.0 -* -* @param $content string The content -* @param $options string The options array -* @param $search string The string to search for -* @return string The updated content -*/ - -function ce_quick_replace( $content = '', $options = '', $search = '' ) { - - $start_pos = strpos( $content, $options[ 'opening_ident' ] . $search, 0 ); - $prefix_len = strlen( $options[ 'opening_ident' ] ); - - while ( $start_pos !== false ) { - - $start_pos = $start_pos + strlen( $options[ 'opening_ident' ] ); - $end_pos = strpos( $content, $options[ 'closing_ident' ], $start_pos ); - if ( $end_pos !== false ) { - $url = substr( $content, $start_pos, $end_pos - $start_pos ); - $file = ce_get_file( $url ); - $content = str_replace ( $options[ 'opening_ident' ] . $url . $options[ 'closing_ident' ], $file[ 'file' ], $content ); - } - $start_pos = strpos( $content, $options[ 'opening_ident' ] . $search, $found_pos ); - - } - - return $content; -} - -/** -* Generate Embed Code -* -* Function to generate the embed code that will be output -* -* @since 2.0 -* -* @param $html string The embed code (required) -* @param $plugin_name string The name of the plugin (required) -* @param $responsive string Responsive output required? (optional) -* @param $max_width string Maximum width of responsive output (optional) -* @param $debug boolean Whether to suppress debug output (1) or not -* @return string The embed code -*/ - -function ce_generate_code( $html, $plugin_name, $responsive = '', $max_width = '', $debug = '' ) { - - $code = "\n"; - if ( $debug != 1 ) { $code .= '\n"; } - - if ( $max_width !== false ) { $code .= '
'; } - - if ( $responsive ) { $code .= '
'; } - - $code .= $html; - - if ( $responsive ) { $code .= '
'; } - - if ( $max_width !== false ) { $code .= '
'; } - - $code .= "\n"; - if ( $debug != 1 ) { $code .= '\n"; } - - return $code; -} - -/** -* Get the Global Embed Code -* -* Function to look for and, if available, return the global embed code -* -* @since 1.6 -* -* @uses ce_report_error Generate an error message -* -* @param $ident string The embed code opening identifier -* @param $suffix string The embed code suffix -* @return string The embed code (or error) -*/ - -function ce_get_embed_code( $ident, $suffix ) { - - // Meta was not found in current post so look across meta table - find the number of distinct code results - - $meta_name = $ident . $suffix; - global $wpdb; - $unique_records = $wpdb -> get_results( "SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = '" . $meta_name . "'" ); - $records = $wpdb -> num_rows; - - if ( $records > 0 ) { - - // Results were found - - $meta = $wpdb -> get_results( "SELECT meta_value, post_title, ID FROM $wpdb->postmeta, $wpdb->posts WHERE meta_key = '" . $meta_name . "' AND post_id = ID" ); - $total_records = $wpdb -> num_rows; - - if ( $records == 1 ) { - - // Only one unique code result returned so assume this is the global embed - - foreach ( $meta as $meta_data ) { - $html = $meta_data -> meta_value; - } - - } else { - - // More than one unique code result returned, so output the list of posts - - $error = sprintf( __( 'Cannot use %s as a global code as it is being used to store %d unique pieces of code in %d posts - click here for more details', 'simple-embed-code' ), $meta_name, $records, $total_records, get_bloginfo( 'wpurl' ) . '/wp-admin/admin.php?page=ce-search&suffix=' . $suffix ); - $html = ce_report_error( $error, 'Code Embed', false ); - } - } else { - - // No meta code was found so write out an error - - $html = ce_report_error( sprintf( __( 'No embed code was found for %s', 'simple-embed-code' ), $meta_name ), 'Code Embed', false ); - - } - return $html; -} - -/** -* Fetch a file (1.6) -* -* Use WordPress API to fetch a file and check results -* RC is 0 to indicate success, -1 a failure -* -* @since 2.0 -* -* @param string $filein File name to fetch -* @param string $header Only get headers? -* @return string Array containing file contents and response -*/ - -function ce_get_file( $filein, $header = false ) { - - $rc = 0; - $error = ''; - if ( $header ) { - $fileout = wp_remote_head( $filein ); - if ( is_wp_error( $fileout ) ) { - $error = 'Header: ' . $fileout -> get_error_message(); - $rc = -1; - } - } else { - $fileout = wp_remote_get( $filein ); - if ( is_wp_error( $fileout ) ) { - $error = 'Body: ' . $fileout -> get_error_message(); - $rc = -1; - } else { - if ( isset( $fileout[ 'body' ] ) ) { - $file_return[ 'file' ] = $fileout[ 'body' ]; - } - } - } - - $file_return[ 'error' ] = $error; - $file_return[ 'rc' ] = $rc; - if ( !is_wp_error( $fileout ) ) { - if ( isset( $fileout[ 'response' ][ 'code' ] ) ) { - $file_return[ 'response' ] = $fileout[ 'response' ][ 'code' ]; - } - } - - return $file_return; -} - -/** -* Report an error (1.4) -* -* Function to report an error -* -* @since 1.6 -* -* @param $error string Error message -* @param $plugin_name string The name of the plugin -* @param $echo string True or false, depending on whether you wish to return or echo the results -* @return string True or the output text -*/ - -function ce_report_error( $error, $plugin_name, $echo = true ) { - - $output = '

' . $plugin_name . ': ' . $error . "

\n"; - - if ( $echo ) { - echo $output; - return true; - } else { - return $output; - } - -} -?> \ No newline at end of file +ID, $options['keyword_ident'] . $suffix, false ); + if ( isset( $post_meta[0] ) ) { + $html = $post_meta[0]; + } else { + // No meta found, so look for it elsewhere + $html = ce_get_embed_code( $options['keyword_ident'], $suffix ); + } + + // Build the string to search for + + $search = $options['opening_ident'] . $options['keyword_ident'] . $full_suffix . $options['closing_ident']; + + // Build the string of code to replace with + + $replace = ce_generate_code( $html, $responsive, $max_width, $options['debug'] ); + + // Now modify all references + + $content = str_replace( $search, $replace, $content ); + + } + $found_pos = strpos( $content, $options['opening_ident'] . $options['keyword_ident'], $found_pos + 1 ); + } + + // Loop around the post content looking for HTTP addresses + + $content = ce_quick_replace( $content, $options, 'http://' ); + + // Loop around the post content looking for HTTPS addresses + + $content = ce_quick_replace( $content, $options, 'https://' ); + + return $content; +} + +add_filter( 'the_content', 'ce_filter' ); +add_filter( 'widget_content', 'ce_filter' ); + +/** +* Quick Replace +* +* Function to do a quick search/replace of the content +* +* @since 2.0 +* +* @param $content string The content +* @param $options string The options array +* @param $search string The string to search for +* @return string The updated content +*/ + +function ce_quick_replace( $content = '', $options = '', $search = '' ) { + + $start_pos = strpos( $content, $options['opening_ident'] . $search, 0 ); + $prefix_len = strlen( $options['opening_ident'] ); + + while ( false !== $start_pos ) { + + $start_pos = $start_pos + strlen( $options['opening_ident'] ); + $end_pos = strpos( $content, $options['closing_ident'], $start_pos ); + + if ( false !== $end_pos ) { + $url = substr( $content, $start_pos, $end_pos - $start_pos ); + $file = ce_get_file( $url ); + if ( false !== $file ) { + $content = str_replace( $options['opening_ident'] . $url . $options['closing_ident'], $file['file'], $content ); + } else { + ce_report_error( __( 'File could not be fetched', 'simple-embed-code' ), 'Code Embed', false ); + } + } + } + + return $content; +} + +/** +* Generate Embed Code +* +* Function to generate the embed code that will be output +* +* @since 2.0 +* +* @param $html string The embed code (required) +* @param $responsive string Responsive output required? (optional) +* @param $max_width string Maximum width of responsive output (optional) +* @param $debug boolean Whether to suppress debug output (1) or not +* @return string The embed code +*/ + +function ce_generate_code( $html, $responsive = '', $max_width = '', $debug = '' ) { + + $code = "\n"; + if ( 1 !== $debug ) { + $code .= '\n"; + } + + if ( false !== $max_width ) { + $code .= '
'; + } + + if ( $responsive ) { + $code .= '
'; + } + + $code .= $html; + + if ( $responsive ) { + $code .= '
'; + } + + if ( false !== $max_width ) { + $code .= '
'; + } + + $code .= "\n"; + if ( 1 !== $debug ) { + $code .= '\n"; + } + + return $code; +} + +/** +* Get the Global Embed Code +* +* Function to look for and, if available, return the global embed code +* +* @since 1.6 +* +* @uses ce_report_error Generate an error message +* +* @param $ident string The embed code opening identifier +* @param $suffix string The embed code suffix +* @return string The embed code (or error) +*/ + +function ce_get_embed_code( $ident, $suffix ) { + + // Meta was not found in current post so look across meta table - find the number of distinct code results + + $meta_name = $ident . $suffix; + global $wpdb; + $unique_records = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = %s", $meta_name ) ); // @codingStandardsIgnoreLine -- requires the latest data when called, so caching is inappropriate + $records = $wpdb->num_rows; + + if ( 0 < $records ) { + + // Results were found + + $meta = $wpdb->get_results( $wpdb->prepare( "SELECT meta_value, post_title, ID FROM $wpdb->postmeta, $wpdb->posts WHERE meta_key = %s AND post_id = ID", $meta_name ) ); // @codingStandardsIgnoreLine -- requires the latest data when called, so caching is inappropriate + $total_records = $wpdb->num_rows; + + if ( 1 === $records ) { + + // Only one unique code result returned so assume this is the global embed + + foreach ( $meta as $meta_data ) { + $html = $meta_data->meta_value; + } + } else { + + // More than one unique code result returned, so output the list of posts + + /* translators: %1$s: embed name, %2$d: number of pieces of code being stored with that name, %3$d: number of posts using that embed name */ + $error = sprintf( __( 'Cannot use %1$s as a global code as it is being used to store %2$d unique pieces of code in %3$d posts', 'simple-embed-code' ), $meta_name, $records, $total_records ); + $html = ce_report_error( $error, 'Code Embed', false ); + } + } else { + + // No meta code was found so write out an error + + /* translators: %s: the embed name */ + $html = ce_report_error( sprintf( __( 'No embed code was found for %s', 'simple-embed-code' ), $meta_name ), 'Code Embed', false ); + + } + return $html; +} + +/** +* Fetch a file +* +* Use WordPress API to fetch a file and check results +* +* @since 2.0 +* +* @param string $filein File name to fetch +* @param string $header Only get headers? +* @return string Array containing file contents or false to indicate a failure +*/ + +function ce_get_file( $filein ) { + + if ( function_exists( 'vip_safe_wp_remote_get' ) ) { + + $response = vip_safe_wp_remote_get( $filein, '', 3, 3 ); + + } else { + + $response = wp_remote_get( $filein, array( 'timeout' => 3 ) ); // @codingStandardsIgnoreLine -- for non-VIP environments + + } + + if ( is_array( $response ) ) { + + return $response['body']; + + } else { + + return false; + + } +} + +/** +* Report an error (1.4) +* +* Function to report an error +* +* @since 1.6 +* +* @param $error string Error message +* @param $plugin_name string The name of the plugin +* @param $echo string True or false, depending on whether you wish to return or echo the results +* @return string True or the output text +*/ + +function ce_report_error( $error, $plugin_name, $echo = true ) { + + $output = '

' . $plugin_name . ': ' . $error . "

\n"; + + if ( $echo ) { + echo esc_html( $output ); + return true; + } else { + return $output; + } + +} + diff --git a/includes/add-scripts.php b/includes/add-scripts.php index f1a2446..7d8cd72 100644 --- a/includes/add-scripts.php +++ b/includes/add-scripts.php @@ -1,27 +1,26 @@ - \ No newline at end of file +' . __( 'Settings', 'simple-embed-code' ) . ''; - array_unshift( $links, $settings_link ); - } - - return $links; -} - -add_filter( 'plugin_action_links', 'ce_add_settings_link', 10, 2 ); - -/** -* Add meta to plugin details -* -* Add options to plugin meta line -* -* @since 1.6 -* -* @param string $links Current links -* @param string $file File in use -* @return string Links, now with settings added -*/ - -function ce_set_plugin_meta( $links, $file ) { - - if ( strpos( $file, 'code-embed.php' ) !== false ) { $links = array_merge( $links, array( '' . __( 'Support', 'simple-embed-code' ) . '' ) ); } - - return $links; -} - -add_filter( 'plugin_row_meta', 'ce_set_plugin_meta', 10, 2 ); - -/** -* Code Embed Menu -* -* Add a new option to the Admin menu and context menu -* -* @since 1.4 -* -* @uses ce_help Return help text -*/ - -function ce_menu() { - - // Add search sub-menu - - global $ce_search_hook; - - $ce_search_hook = add_submenu_page( 'tools.php', __( 'Code Embed Search', 'simple-embed-code' ), __( 'Code Search', 'simple-embed-code' ), 'edit_posts', 'ce-search', 'ce_search' ); - - add_action('load-'.$ce_search_hook, 'ce_add_search_help'); - - // Add options sub-menu - - global $ce_options_hook; - - $ce_options_hook = add_submenu_page( 'options-general.php', __( 'Code Embed Settings', 'simple-embed-code' ), __( 'Code Embed', 'simple-embed-code' ), 'manage_options', 'ce-options', 'ce_options' ); - - add_action('load-'.$ce_options_hook, 'ce_add_options_help'); - -} - -add_action( 'admin_menu','ce_menu' ); - -/** -* Add Options Help -* -* Add help tab to options screen -* -* @since 2.0 -* -* @uses ce_options_help Return help text -*/ - -function ce_add_options_help() { - - global $ce_options_hook; - $screen = get_current_screen(); - - if ( $screen->id != $ce_options_hook ) { return; } - - $screen -> add_help_tab( array( 'id' => 'ce-options-help-tab', 'title' => __( 'Help', 'simple-embed-code' ), 'content' => ce_options_help() ) ); -} - -/** -* Add Search Help -* -* Add help tab to search screen -* -* @since 2.0 -* -* @uses ce_search_help Return help text -*/ - -function ce_add_search_help() { - - global $ce_search_hook; - $screen = get_current_screen(); - - if ( $screen->id != $ce_search_hook ) { return; } - - $screen -> add_help_tab( array( 'id' => 'ce-search-help-tab', 'title' => __( 'Help', 'simple-embed-code' ), 'content' => ce_search_help() ) ); -} - -/** -* Code Embed Options -* -* Define an option screen -* -* @since 1.4 -*/ - -function ce_options() { - - include_once( WP_PLUGIN_DIR . '/' . str_replace( basename( __FILE__ ), '', plugin_basename( __FILE__ ) ) . 'options-screen.php' ); - -} - -/** -* Code Embed Search -* -* Define a the search screen -* -* @since 1.6 -*/ - -function ce_search() { - - include_once( WP_PLUGIN_DIR . '/' . str_replace( basename( __FILE__ ), '', plugin_basename( __FILE__ ) ) . 'search-screen.php' ); - -} - -/** -* Code Embed Options Help -* -* Return help text for options screen -* -* @since 1.5 -* -* @return string Help Text -*/ - -function ce_options_help() { - - $help_text = '

' . __( 'Use this screen to modify the various settings, including the identifiers and keyword used to specify your embedded code.', 'simple-embed-code' ) . '

'; - $help_text .= '

' . __( 'The first option allows to suppress debug output. Normally this is an HTML comment in your page source - if you wish to hide this then simply tick this option.', 'simple-embed-code' ) . '

'; - $help_text .= '

' . __( 'The second option allows to specify whether code embed requests should work in excerpts.', 'simple-embed-code' ) . '

'; - $help_text .= '

' . __( 'The keyword is the name used for your custom field. The custom field\'s value is the code that you wish to embed.', 'simple-embed-code' ) . '

'; - $help_text .= '

' . __( 'The keyword, sandwiched with the identifier before and after, is what you then need to add to your post or page to activate the embed code.', 'simple-embed-code' ) . '

'; - - return $help_text; -} - -/** -* Code Embed Search Help -* -* Return help text for search screen -* -* @since 1.6 -* -* @return string Help Text -*/ - -function ce_search_help() { - - $help_text = '

' . __( 'This screen allows you to search for the post and pages that a particular code embed has been used in.', 'simple-embed-code' ) . '

'; - $help_text .= '

' . __( 'Simply enter the code suffix that you wish to search for and press the \'Search\' key to display a list of all the posts using it. In addition the code will be shown alongside it. Click on the post name to edit the post.', 'simple-embed-code' ) . '

'; - $help_text .= '

' . __( 'The search results are grouped together in matching code groups, so posts with the same code will be shown together with the same color background.', 'simple-embed-code' ) . '

'; - - return $help_text; -} -?> \ No newline at end of file +' . __( 'Settings', 'simple-embed-code' ) . ''; + array_unshift( $links, $settings_link ); + } + + return $links; +} + +add_filter( 'plugin_action_links', 'ce_add_settings_link', 10, 2 ); + +/** +* Add meta to plugin details +* +* Add options to plugin meta line +* +* @since 1.6 +* +* @param string $links Current links +* @param string $file File in use +* @return string Links, now with settings added +*/ + +function ce_set_plugin_meta( $links, $file ) { + + if ( false !== strpos( $file, 'code-embed.php' ) ) { + + $links = array_merge( $links, array( '' . __( 'Github', 'simple-embed-code' ) . '' ) ); + + $links = array_merge( $links, array( '' . __( 'Support', 'simple-embed-code' ) . '' ) ); + } + + return $links; +} + +add_filter( 'plugin_row_meta', 'ce_set_plugin_meta', 10, 2 ); + +/** +* Code Embed Menu +* +* Add a new option to the Admin menu and context menu +* +* @since 1.4 +* +* @uses ce_help Return help text +*/ + +function ce_menu() { + + // Add search sub-menu + + global $ce_search_hook; + + $ce_search_hook = add_submenu_page( 'tools.php', __( 'Code Embed Search', 'simple-embed-code' ), __( 'Code Search', 'simple-embed-code' ), 'edit_posts', 'ce-search', 'ce_search' ); + + add_action( 'load-' . $ce_search_hook, 'ce_add_search_help' ); + + // Add options sub-menu + + global $ce_options_hook; + + $ce_options_hook = add_submenu_page( 'options-general.php', __( 'Code Embed Settings', 'simple-embed-code' ), __( 'Code Embed', 'simple-embed-code' ), 'manage_options', 'ce-options', 'ce_options' ); + + add_action( 'load-' . $ce_options_hook, 'ce_add_options_help' ); + +} + +add_action( 'admin_menu', 'ce_menu' ); + +/** +* Add Options Help +* +* Add help tab to options screen +* +* @since 2.0 +* +* @uses ce_options_help Return help text +*/ + +function ce_add_options_help() { + + global $ce_options_hook; + $screen = get_current_screen(); + + if ( $screen->id !== $ce_options_hook ) { + return; + } + + $screen->add_help_tab( + array( + 'id' => 'ce-options-help-tab', + 'title' => __( 'Help', 'simple-embed-code' ), + 'content' => ce_options_help(), + ) + ); + + $screen->set_help_sidebar( ce_help_sidebar() ); +} + +/** +* Add Search Help +* +* Add help tab to search screen +* +* @since 2.0 +* +* @uses ce_search_help Return help text +*/ + +function ce_add_search_help() { + + global $ce_search_hook; + $screen = get_current_screen(); + + if ( $screen->id !== $ce_search_hook ) { + return; + } + + $screen->add_help_tab( + array( + 'id' => 'ce-search-help-tab', + 'title' => __( 'Help', 'simple-embed-code' ), + 'content' => ce_search_help(), + ) + ); + + $screen->set_help_sidebar( ce_help_sidebar() ); +} + +/** +* Code Embed Options +* +* Define an option screen +* +* @since 1.4 +*/ + +function ce_options() { + + include_once( WP_PLUGIN_DIR . '/' . str_replace( basename( __FILE__ ), '', plugin_basename( __FILE__ ) ) . 'options-screen.php' ); + +} + +/** +* Code Embed Search +* +* Define a the search screen +* +* @since 1.6 +*/ + +function ce_search() { + + include_once( WP_PLUGIN_DIR . '/' . str_replace( basename( __FILE__ ), '', plugin_basename( __FILE__ ) ) . 'search-screen.php' ); + +} + +/** +* Code Embed Options Help +* +* Return help text for options screen +* +* @since 1.5 +* +* @return string Help Text +*/ + +function ce_options_help() { + + $help_text = '

' . __( 'Use this screen to modify the various settings, including the identifiers and keyword used to specify your embedded code.', 'simple-embed-code' ) . '

'; + $help_text .= '

' . __( 'The first option allows to suppress debug output. Normally this is an HTML comment in your page source - if you wish to hide this then simply tick this option.', 'simple-embed-code' ) . '

'; + $help_text .= '

' . __( 'The second option allows to specify whether code embed requests should work in excerpts.', 'simple-embed-code' ) . '

'; + $help_text .= '

' . __( 'The keyword is the name used for your custom field. The custom field\'s value is the code that you wish to embed.', 'simple-embed-code' ) . '

'; + $help_text .= '

' . __( 'The keyword, sandwiched with the identifier before and after, is what you then need to add to your post or page to activate the embed code.', 'simple-embed-code' ) . '

'; + + return $help_text; +} + +/** +* Code Embed Search Help +* +* Return help text for search screen +* +* @since 1.6 +* +* @return string Help Text +*/ + +function ce_search_help() { + + $help_text = '

' . __( 'This screen allows you to search for the post and pages that a particular code embed has been used in.', 'simple-embed-code' ) . '

'; + $help_text .= '

' . __( 'Simply enter the code suffix that you wish to search for and press the \'Search\' key to display a list of all the posts using it. In addition the code will be shown alongside it. Click on the post name to edit the post.', 'simple-embed-code' ) . '

'; + $help_text .= '

' . __( 'The search results are grouped together in matching code groups, so posts with the same code will be shown together with the same color background.', 'simple-embed-code' ) . '

'; + + return $help_text; +} + +/** +* Code Embed Help Sidebar +* +* Return sidebar help text +* +* @since 2.3 +* +* @return string Help Text +*/ + +function ce_help_sidebar() { + + $help_text = '

' . __( 'For more information:', 'simple-embed-code' ) . '

'; + $help_text .= '

' . __( 'Instructions', 'simple-embed-code' ) . '

'; + $help_text .= '

' . __( 'Github (code and issues)', 'simple-embed-code' ) . '

'; + $help_text .= '

' . __( 'Support Forum', 'simple-embed-code' ) . '

'; + + return $help_text; +} diff --git a/includes/initialise.php b/includes/initialise.php index 5821c9d..91468f2 100644 --- a/includes/initialise.php +++ b/includes/initialise.php @@ -1,57 +1,58 @@ - '%', - 'keyword_ident' => 'CODE', - 'closing_ident' => '%', - 'debug' => '', - 'excerpts' => '', - ); - - // Merge existing and default options - any missing from existing will take the default settings - - $new_options = array_merge( $default_array, $options ); - - // Update the options, if changed, and return the result - - if ( $options != $new_options ) { update_option( 'artiss_code_embed', $new_options ); } - - } - -} - -add_action( 'init', 'ce_initialisation' ); -?> \ No newline at end of file + '{{', + 'keyword_ident' => 'CODE', + 'closing_ident' => '}}', + 'debug' => '', + 'excerpts' => '', + ); + + // Merge existing and default options - any missing from existing will take the default settings + + $new_options = array_merge( $default_array, $options ); + + // Update the options, if changed, and return the result + + if ( $options !== $new_options ) { + update_option( 'artiss_code_embed', $new_options ); + } + } +} + +add_action( 'init', 'ce_initialisation' ); diff --git a/includes/options-screen.php b/includes/options-screen.php index 205cdcf..b965fec 100644 --- a/includes/options-screen.php +++ b/includes/options-screen.php @@ -1,97 +1,130 @@ - -
-

-' ) ) ); - $options[ 'keyword_ident' ] = sanitize_text_field( strtoupper( trim( $_POST[ 'code_embed_keyword' ], '[]<>' ) ) ); - $options[ 'closing_ident' ] = sanitize_text_field( strtoupper( trim( $_POST[ 'code_embed_closing' ], '[]<>' ) ) ); - - if ( isset( $_POST[ 'code_embed_debug' ] ) ) { $options[ 'debug' ] = sanitize_text_field( $_POST[ 'code_embed_debug' ] ); } else { $options[ 'debug' ] = ''; } - if ( isset( $_POST[ 'code_embed_excerpt' ] ) ) { $options[ 'excerpt' ] = sanitize_text_field( $_POST[ 'code_embed_excerpt' ] ); } else { $options[ 'excerpt' ] = ''; } - - // If any fields are blank assign default values - - if ( $options[ 'opening_ident' ] == '' ) { $options[ 'opening_ident' ] = '%'; } - if ( $options[ 'keyword_ident' ] == '' ) { $options[ 'keyword_ident' ] = 'CODE'; } - if ( $options[ 'closing_ident' ] == '' ) { $options[ 'closing_ident' ] = '%'; } - - update_option( 'artiss_code_embed', $options ); -} - -// Fetch options into an array - -$options = get_option( 'artiss_code_embed' ); -?> - -
- - - - - - - - - - - -
/>
/>
- -' . __( 'Identifier Format', 'simple-embed-code' ) . '' . __( 'Specify the format that will be used to define the way the code is embedded in your post. The formats are case insensitive and characters < > [ ] are invalid.', 'simple-embed-code' ); ?> - - - - - - - - - - - - - - - - - - -

- - - -
- -
- -

" . __( 'How to Embed', 'simple-embed-code' ) . "

\n"; -echo '

' . sprintf ( __( 'Based upon your current settings to embed some code simply add a custom field named %s, where %s is any suffix you wish. The code to embed is then added as the field value.', 'simple-embed-code' ), '' . $options[ 'keyword_ident' ] . 'x', 'x' ) . "\n"; -echo ' ' . sprintf ( __( 'Then, to add the code into your post simple add %s where you wish it to appear. %s is the suffix you used for the custom field name.', 'simple-embed-code' ), '' . $options[ 'opening_ident' ] . $options[ 'keyword_ident' ] . "x" . $options[ 'closing_ident' ] . '', 'x' ) . "

\n"; -echo '

' . sprintf ( __( 'For example, I may add a custom field named %s, where the value is the code I wish to embed. I would then in my post add %s where I wish the code to then appear.', 'simple-embed-code' ), '' . $options[ 'keyword_ident' ].'1', '' . $options[ 'opening_ident' ] . $options[ 'keyword_ident' ] . "1" . $options[ 'closing_ident' ] . '' ) . "

\n"; -echo '

' . sprintf ( __( 'To embed the same code but to make it responsive you would use %s. To set a maximum width you would use %s, where %s is the maximum width in pixels.', 'simple-embed-code' ), '' . $options[ 'opening_ident' ] . $options[ 'keyword_ident' ] . "x_RES" . $options[ 'closing_ident' ] . '', '' . $options[ 'opening_ident' ] . $options[ 'keyword_ident' ] . "x_RES_y" . $options[ 'closing_ident' ] . '', 'y' ) . "

\n"; -echo '

' . sprintf ( __( 'To embed an external URL you would type %s, where %s is the URL.', 'simple-embed-code' ), '' . $options[ 'opening_ident' ] . 'url' . $options[ 'closing_ident' ] . '', 'url' ) . "

\n"; -?> - -
\ No newline at end of file + +
+

+

' . esc_html( __( 'Settings saved.', 'simple-embed-code' ) ) . "

\n"; +} + +// Fetch options into an array + +$options = get_option( 'artiss_code_embed' ); +?> + +
+ + + + + + + + + + + +
+/>
+/>
+ +' . esc_html( ucwords( __( 'Identifier format', 'simple-embed-code' ) ) ) . '' . esc_html__( 'Specify the format that will be used to define the way the code is embedded in your post. The formats are case insensitive and characters < > [ ] are invalid.', 'simple-embed-code' ); ?> + + + + + + + + + + + + + + + + + + +

+ + + +
+ +
+ +

' . esc_html( ucwords( __( 'How to embed', 'simple-embed-code' ) ) ) . "

\n"; + +/* translators: %1$s: example of custom field key value to use based on current settings, %2$s: details of key used in example */ +echo '

' . sprintf( esc_html__( 'Based upon your current settings to embed some code simply add a custom field named %1$s, where %2$s is any suffix you wish. The code to embed is then added as the field value.', 'simple-embed-code' ), '' . esc_html( $options['keyword_ident'] ) . 'x', 'x' ) . "\n"; + +/* translators: %1$s: example of how to embed code in a post based on current settings, %2$s: details of key used in example */ +echo ' ' . sprintf( esc_html__( 'Then, to add the code into your post simple add %1$s where you wish it to appear. %2$s is the suffix you used for the custom field name.', 'simple-embed-code' ), '' . esc_html( $options['opening_ident'] ) . esc_html( $options['keyword_ident'] ) . 'x' . esc_html( $options['closing_ident'] ) . '', 'x' ) . "

\n"; + +/* translators: %1$s: another example of adding a custom field, %2$s: another example of adding embed to a post */ +echo '

' . sprintf( esc_html__( 'For example, I may add a custom field named %1$s, where the value is the code I wish to embed. I would then in my post add %2$s where I wish the code to then appear.', 'simple-embed-code' ), '' . esc_html( $options['keyword_ident'] ) . '1', '' . esc_html( $options['opening_ident'] ) . esc_html( $options['keyword_ident'] ) . '1' . esc_html( $options['closing_ident'] ) . '' ) . "

\n"; + +/* translators: %1$s: example embedding for responsive layout , %2$s: details of key used in example */ +echo '

' . sprintf( esc_html__( 'To embed the same code but to make it responsive you would use %1$s. To set a maximum width you would use %2$s, where %3$s is the maximum width in pixels.', 'simple-embed-code' ), '' . esc_html( $options['opening_ident'] ) . esc_html( $options['keyword_ident'] ) . 'x_RES' . esc_html( $options['closing_ident'] ) . '', '' . esc_html( $options['opening_ident'] ) . esc_html( $options['keyword_ident'] ) . 'x_RES_y' . esc_html( $options['closing_ident'] ) . '', 'y' ) . "

\n"; + +/* translators: %1$s: example of embedding a file, %2$s: details of key used in example */ +echo '

' . sprintf( esc_html__( 'To embed an external URL you would type %1$s, where %2$s is the URL.', 'simple-embed-code' ), '' . esc_html( $options['opening_ident'] ) . 'url' . esc_html( $options['closing_ident'] ) . '', 'url' ) . "

\n"; +?> + + diff --git a/includes/search-screen.php b/includes/search-screen.php index 628293f..d269e5d 100644 --- a/includes/search-screen.php +++ b/includes/search-screen.php @@ -1,93 +1,94 @@ - -
-

- -' . __( 'Enter the suffix to search for below and press the \'Search\' button to view the results. Further help can be found by clicking on the Help tab at the top right-hand of the screen.', 'simple-embed-code' ) . '

'; -?> - - - -
- - - - - - - - - - - -
- - get_results( "SELECT meta_value, post_title, ID FROM $wpdb->postmeta, $wpdb->posts WHERE meta_key = '" . $options[ 'keyword_ident' ] . $suffix . "' AND post_id = ID ORDER BY meta_value" ); - $records = $wpdb -> num_rows; - - if ( $records > 0 ) { - - echo ''; - $color1 = 'dfdfdf'; - $color2 = 'ececec'; - $color = $color1; - $prev_html = ''; - - foreach ( $meta as $meta_data ) { - $html = $meta_data -> meta_value; - $post_title = $meta_data -> post_title; - $post_id = $meta_data -> ID; - - // Switch background colours as the code changes - - if ( $html != $prev_html ) { if ( $color == $color1 ) { $color = $color2; } else { $color = $color1; } } - - echo "\n"; - echo '\n"; - echo '\n"; - echo "\n"; - - $prev_html = $html; - } - - echo "
'.$post_title."
\n"; - - } else { - - echo "

" . __( 'No posts were found containing that embed code.', 'simple-embed-code' ) . "

\n"; - - } -} -?> - -
\ No newline at end of file + +
+

+ +' . esc_html__( 'Enter the suffix to search for below and press the \'Search\' button to view the results. Further help can be found by clicking on the Help tab at the top right-hand of the screen.', 'simple-embed-code' ) . '

'; +?> + + + +
+ + + + + + + + + + + +
+ +get_results( $wpdb->prepare( "SELECT meta_value, post_title, ID FROM $wpdb->postmeta, $wpdb->posts WHERE meta_key = %s AND post_id = ID ORDER BY meta_value", esc_html( $options['keyword_ident'] ) . esc_html( $suffix ) ) ); // @codingStandardsIgnoreLine -- being used for a simple, ad-hoc search feature in admin. Unlikely to be used much and caching on this is overkill + $records = $wpdb->num_rows; + + if ( 0 < $records ) { + + echo ''; + $color1 = 'dfdfdf'; + $color2 = 'ececec'; + $color = $color1; + $prev_html = ''; + + foreach ( $meta as $meta_data ) { + $html = $meta_data->meta_value; + $post_title = $meta_data->post_title; + $post_id = $meta_data->ID; + + // Switch background colours as the code changes + + if ( $html !== $prev_html ) { + if ( $color === $color1 ) { + $color = $color2; + } else { + $color = $color1; } + } + + echo '\n"; + echo '\n"; + echo '\n"; + echo "\n"; + + $prev_html = $html; + } + + echo "
' . esc_html( $post_title ) . "
\n"; + + } else { + + echo '

' . esc_html__( 'No posts were found containing that embed code.', 'simple-embed-code' ) . "

\n"; + + } +} +?> + +
diff --git a/readme.txt b/readme.txt index 7301b65..ba76853 100644 --- a/readme.txt +++ b/readme.txt @@ -2,9 +2,9 @@ Contributors: dartiss Tags: code, embed, html, javascript, script Requires at least: 4.6 -Tested up to: 4.9 +Tested up to: 4.9.4 Requires PHP: 5.3 -Stable tag: 2.2.2 +Stable tag: 2.3 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -12,7 +12,7 @@ Code Embed provides a very easy and efficient way to embed code (JavaScript and == Description == -Code Embed allows you to embed code - JavaScript and HTML primarily - in a post. This is incredibly useful for embedding video, etc, when required and is used, amongst other, by Mozilla. It cannot be used for server side code, such as PHP. +Code Embed allows you to embed code (JavaScript and HTML - it can't be used for server-side code, such as PHP) in a post, without the content being changed by the editor. This is incredibly useful for embedding third-party scripts, etc. The plugin is used by many large sites, including Mozilla. Key features include... @@ -31,6 +31,8 @@ Technical specification... * Designed for both single and multi-site installations * PHP7 compatible * Fully internationalized, ready for translations **If you would like to add a translation to this plugin then please head to our [Translating WordPress](https://translate.wordpress.org/projects/wp-plugins/simple-embed-code "Translating WordPress") page** +* GDPR compliant +* See FAQ for Gutenberg compatibility Please visit the [Github page](https://github.com/dartiss/code-embed "Github") for the latest code development, planned enhancements and known issues. @@ -40,9 +42,9 @@ Here's how easy it is to use… 1. Once you have the plugin installed start a new post or page. 2. In the `Custom Fields` meta box enter a name of CODE1 and your embed code as the value. Save this. -3. In your post add `%CODE1%` where you wish the embed code to appear. +3. In your post add `{{CODE1}}` where you wish the embed code to appear. -And that's it - when the post or page is viewed `%CODE1%` will be replaced with the code that you asked to be embedded. +And that's it - when the post or page is viewed `{{CODE1}}` will be replaced with the code that you asked to be embedded. **If you cannot find the location of the `Custom Fields` meta box on your post editor screen, please see the FAQ section for more information** @@ -66,9 +68,9 @@ To embed in a post you need to find the meta box under the post named "Custom Fi Now create a new custom field with the name of your keyword - e.g. `CODE`. The value of this field will be the code that you wish to embed. Save this custom field. -Now, wherever you wish the code to appear in your post, simply put the full identifier (opening, keyword and closing characters). For example, `%CODE%`. +Now, wherever you wish the code to appear in your post, simply put the full identifier (opening, keyword and closing characters). For example, `{{CODE}}`. -If you wish to embed multiple pieces of code within a post you can add a suffix to the keyword. So we may set up 2 custom fields named `CODE1` and `CODE2`. Then in our post we would specify either `%CODE1%` or `%CODE2%` depending on which you wish to display. +If you wish to embed multiple pieces of code within a post you can add a suffix to the keyword. So we may set up 2 custom fields named `CODE1` and `CODE2`. Then in our post we would specify either `{{CODE1}}` or `{{CODE2}}` depending on which you wish to display. Don't forget - via the options screen you can change any part of this identifier to your own taste. @@ -80,11 +82,11 @@ Obviously, be careful when embedding a URL that you have no control over, as thi For example, using the default options you could embed the contents of a URL using the following method... -`%http://www.example.com/code.php%` +`{{http://www.example.com/code.php}}` or -`%https://www.example.com/code.html%` +`{{https://www.example.com/code.html}}` == Global Embedding == @@ -92,7 +94,7 @@ You can also create global embeds - that is creating one piece of embed code and To do this simply make reference to an already defined (but unique) piece of embed code from another post or page. -So, let's say in one post you define a custom field named `CODE1`. You can, if you wish, place `%CODE1%` not just in that post but also in another and it will work. +So, let's say in one post you define a custom field named `CODE1`. You can, if you wish, place `{{CODE1}}` not just in that post but also in another and it will work. However, bear in mind that the embed code name must be unique - you can't have defined it in multiple posts otherwise the plugin won't know which one you're referring to (although it will report this and list the posts that it has been used in). @@ -106,7 +108,7 @@ Natively you cannot use the embed facilities within sidebar widgets. However, if * In Administration, select the Widgets page from the Appearance menu. At the bottom there will be a set of Widget Logic options. * Ensure Use 'widget_content' filter is ticked and press Save. -Although you cannot set up embed code within a widget you can make reference to it, for example by writing `%CODE1%` in the widget. +Although you cannot set up embed code within a widget you can make reference to it, for example by writing `{{CODE1}}` in the widget. == Responsive Output Conversion == @@ -114,11 +116,11 @@ Responsive output is where an element on a web page dynamically resizes dependin Code Embed provides a simple suffix that can be added to an embed code and will convert the output to being responsive. This works best with videos. -To use, when adding the embed code onto the page, simply add `_RES` to the end, before the final identifier. For example, `%CODE1_RES%`. The `_RES` should not be added to the custom fields definition. +To use, when adding the embed code onto the page, simply add `_RES` to the end, before the final identifier. For example, `{{CODE1_RES}}`. The `_RES` should not be added to the custom fields definition. This will now output the embedded code full width, but a width that is dynamic and will resize when required. -If you don't wish the output to be full width you can specify a maximum width by adding an additional `_x` on the end, where `x` is the required width in pixels. For example, `%CODE1_RES_500%` this will output `CODE1` as responsive but with a maximum width of 500 pixels. +If you don't wish the output to be full width you can specify a maximum width by adding an additional `_x` on the end, where `x` is the required width in pixels. For example, `{{CODE1_RES_500}}` this will output `CODE1` as responsive but with a maximum width of 500 pixels. **It should be noted that this is an experimental addition and will not work in all circumstances.** @@ -161,7 +163,15 @@ If you still can't find it then you may have a theme or plugin that removes this = What's the maximum size of the embed code that I can save in a custom field? = -WordPress stores the custom field contents in a MySQL table using the `longtext` format. This can hold over 4 billion characters. +WordPress stores the custom field contents in a MySQL table using the `longtext` format. This can hold over 4 billion characters. + +== Does this work with Gutenberg? == + +Right now, no, as the custom fields meta box will not be present. However, a rather smart plugin named [Custom Fields for Gutenberg](https://wordpress.org/plugins/custom-fields-gutenberg/) will add this functionality back in - with that active, you can happily continue to use this plugin. + +== Is this GDPR compliant? == + +It is, in that it doesn't save any data that could be odds with GDPR compliance (i.e. it's compliant by design). However, if you use this to embed third-party scripts, then those scripts may not be and you will need to speak to the providers for further details. == Screenshots == @@ -176,6 +186,17 @@ WordPress stores the custom field contents in a MySQL table using the `longtext` [Learn more about my version numbering methodology](https://artiss.blog/2016/09/wordpress-plugin-versioning/ "WordPress Plugin Versioning") += 2.3 = +* Enhancement: All the code is now compliant with the full-fat VIP coding standards. It was no mean feat but, as a result, the plugin is more secure than ever before +* Enhancement: The default is to now use double braces around your embed name, which is kind-of the universal default for template tags such as this. If you're an existing user, your current configuration won't change, though - this only affects new users +* Enhancement: Improved translation output, including where I'd accidentally added an extra character to the text domain +* Enhancement: Using the `checked` function on fields, rather than the form parameter +* Enhancement: Added a useful links sidebar to the Help for both screens +* Maintenance: Throughout, use Yoda conditions I now do +* Maintenance: Added links to the sparkly new Github repo +* Bug: When updating the options you sometimes didn't get a confirmation message. You do now! +* Bug: Fixed a weird one where I was referencing a variable that I was never using ¯\_(ツ)_/¯ + = 2.2.2 = * Maintenance: Updated README to work better with new plugin directory format. Also, now converting all text to US English, which is the WordPress standard. Snazzy. * Maintenance: Updated all links to artiss.blog and removed donation links. Clickable. @@ -268,5 +289,5 @@ versions of this plugin == Upgrade Notice == -= 2.2.2 = -* Maintenance updates \ No newline at end of file += 2.3 = +* Numerous bug fixed and enhancements \ No newline at end of file diff --git a/simple-code-embed.php b/simple-code-embed.php index bc914f4..d7bd4c9 100644 --- a/simple-code-embed.php +++ b/simple-code-embed.php @@ -1,40 +1,39 @@ - \ No newline at end of file + \ No newline at end of file +