diff --git a/languages/press-this-extended.pot b/languages/press-this-extended.pot new file mode 100644 index 0000000..c02b4e9 --- /dev/null +++ b/languages/press-this-extended.pot @@ -0,0 +1,160 @@ +# Copyright (C) 2015 Press This Extended +# This file is distributed under the same license as the Press This Extended package. +msgid "" +msgstr "" +"Project-Id-Version: Press This Extended 1.0.0-beta1\n" +"Report-Msgid-Bugs-To: http://wordpress.org/support/plugin/press-this-" +"extended\n" +"POT-Creation-Date: 2015-04-21 03:46:08+00:00\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"PO-Revision-Date: 2015-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" + +#: press-this-extended.php:89 +msgid "Content Grabbing" +msgstr "" + +#: press-this-extended.php:97 +msgid "Blockquote Formatting" +msgstr "" + +#: press-this-extended.php:101 +msgid "Citation Formatting" +msgstr "" + +#: press-this-extended.php:105 +msgid "Redirection" +msgstr "" + +#: press-this-extended.php:109 +msgid "Upon Publishing..." +msgstr "" + +#: press-this-extended.php:113 +msgid "Upon Saving a Draft..." +msgstr "" + +#: press-this-extended.php:117 +msgid "Text Editor" +msgstr "" + +#: press-this-extended.php:178 +msgctxt "Used in Press This to indicate where the content comes from." +msgid "Source:" +msgstr "" + +#: press-this-extended.php:211 +msgid "Should Press This suggest media to add to a new post?" +msgstr "" + +#: press-this-extended.php:223 +msgid "" +"Should Press This try to suggest a quote if you haven't preselected text?" +msgstr "" + +#: press-this-extended.php:235 +msgid "Use %1$s as a placeholder for the blockquote." +msgstr "" + +#: press-this-extended.php:247 +msgid "" +"Use %1$s and %2$s as a placeholders for the page URL and title, respectively." +msgstr "" + +#: press-this-extended.php:259 +msgid "" +"Upon publishing or saving a draft, close the Press This popup and redirect " +"the original tab." +msgstr "" + +#: press-this-extended.php:272 +msgid "Published Post" +msgstr "" + +#: press-this-extended.php:273 press-this-extended.php:290 +msgid "Standard Editor" +msgstr "" + +#: press-this-extended.php:276 +msgid "After publishing a post, you will be redirected to this location." +msgstr "" + +#: press-this-extended.php:289 +msgid "Remain in the Press This editor" +msgstr "" + +#: press-this-extended.php:293 +msgid "After saving a draft, you will be redirected to this location." +msgstr "" + +#: press-this-extended.php:334 +msgid "Enable the Text Editor in Press This" +msgstr "" + +#: press-this-extended.php:335 +msgid "" +"Experimental! This is not fully operational yet. Inserting detected media " +"will not work in the Text Editor. The \"Save Draft\" button will not " +"reappear until you focus within the Visual Editor.
There be dragons! " +"Your milage may vary. No warranty implied or stated!" +msgstr "" + +#: press-this-extended.php:445 +msgid "Press This" +msgstr "" + +#: press-this-extended.php:446 +msgid "" +"These options allow you to customize the Press This bookmarklet to do some " +"cool stuff." +msgstr "" + +#: press-this-extended.php:447 +msgid "" +"Content Grabbing refers to Press This suggesting media and text for you to " +"add in your pressed post. By default, Press This will suggest a blockfrom " +"from the page's description unless it appears to be autogenerated." +msgstr "" + +#: press-this-extended.php:448 +msgid "" +"Blockquote and Citation Formatting allows you to adjust the default HTML " +"template used when pressing a post." +msgstr "" + +#: press-this-extended.php:449 +msgid "" +"Redirection, Upon Publishing..., and Upon Saving A Draft... adjusts what " +"happens when you save your content from Press This." +msgstr "" + +#: press-this-extended.php:450 +msgid "" +"Text Editor adds the HTML option found in the common editor. Some features " +"of Press This, such as inserting the suggested media or the Save Draft text " +"changing may not work as expected when using the text editor." +msgstr "" + +#. Plugin Name of the plugin/theme +msgid "Press This Extended" +msgstr "" + +#. Plugin URI of the plugin/theme +msgid "https://www.brandonkraft.com/press-this-extended/" +msgstr "" + +#. Description of the plugin/theme +msgid "" +"Provides options for extending and modifying the Press This feature (WP 4.2+)" +msgstr "" + +#. Author of the plugin/theme +msgid "Brandon Kraft" +msgstr "" + +#. Author URI of the plugin/theme +msgid "https://www.brandonkraft.com" +msgstr "" diff --git a/press-this-extended.php b/press-this-extended.php new file mode 100644 index 0000000..f7e6cc3 --- /dev/null +++ b/press-this-extended.php @@ -0,0 +1,511 @@ + + * @copyright Copyright (c) 2015, Brandon Kraft + * @link https://www.brandonkraft.com/press-this-extended/ + * @license GPL-2.0+ + * + * @wordpress-plugin + * Plugin Name: Press This Extended + * Plugin URI: https://www.brandonkraft.com/press-this-extended/ + * Description: Provides options for extending and modifying the Press This feature (WP 4.2+) + * Version: 1.0.0 + * Author: Brandon Kraft + * Author URI: https://www.brandonkraft.com + * License: GPL-2.0+ + * License URI: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * Text Domain: press-this-extended + * Domain Path: /languages + */ + + /* + * This program is free software; you can redistribute it and/or modify it under the terms of the GNU + * General Public License version 2, as published by the Free Software Foundation. You may NOT assume + * that you can use any other version of the GPL. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + */ + +class Press_This_Extended { + + /** + * Sets the cruise control at 88 MPH. In other words, let's fire the engines + * + * Selectively adding hooks based on need so we don't cross streams resulting in every molecule in our bodies exploding. + * + * @since 1.0.0 + * @return void + */ + function __construct() { + global $pagenow; + + add_action( 'admin_init', array( $this, 'load_translations' ) , 1 ); // These filters are generally used within wp-admin. + add_action( 'admin_init', array( $this, 'add_settings' ) ); + add_action( 'admin_init', array( $this, 'legacy_conversion') ); + add_action( 'load-options-writing.php', array( $this, 'help_tab' ) ); + add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array( $this, 'action_links' ) ); + + if ( 'press-this.php' == $pagenow ) { // Only needed when Press This is loaded. + add_action( 'admin_init', array( $this, 'execute' ) ); + add_filter( 'http_headers_useragent', array( $this, 'ua_hack' ) ); // When WP is 5.3+, use anonymous function. + } + + if ( 'admin-ajax.php' == $pagenow ) { // These hooks are the only one used exclusively within the ajax context. + add_action( 'admin_init', array( $this, 'execute_ajax' ) ); + } + } + + /** + * Load the textdomain / translations for the plugin. + * + * @since 1.0.0 + * @return void + */ + function load_translations() { + $domain = 'press-this-extended'; + $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); + load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '/' . $domain . '-' . $locale . '.mo' ); + load_plugin_textdomain( $domain, false, basename( dirname( __FILE__ ) ) . '/languages' ); + } + + /** + * Add settings field to the the Settings->Writing page. + * + * @return void + * @since 1.0.0 + **/ + function add_settings() { + $slug = 'press-this-extended'; + + add_settings_section( $slug, 'Press This', null, 'writing'); + + add_settings_field( $slug . '-media', __( 'Content Grabbing', $slug ), array( $this, 'setting_media' ), 'writing', $slug ); + register_setting( 'writing', $slug . '-media', 'intval' ); + add_filter( 'default_option_'. $slug . '-media', '__return_true' ); + + add_settings_field( $slug . '-text', null, array( $this, 'setting_text' ), 'writing', $slug ); + register_setting( 'writing', $slug . '-text', 'intval' ); + add_filter( 'default_option_' . $slug . '-text', '__return_true' ); + + add_settings_field( $slug . '-blockquote', __('Blockquote Formatting', $slug), array( $this, 'setting_blockquote' ), 'writing', $slug ); + register_setting( 'writing', $slug . '-blockquote', 'wp_kses_post' ); + add_filter( 'default_option_' . $slug . '-blockquote', array( $this, 'default_blockquote' ) ); // When WP is 5.3+, use anonymous function. + + add_settings_field( $slug . '-citation', __('Citation Formatting', $slug), array( $this, 'setting_citation' ), 'writing', $slug ); + register_setting( 'writing', $slug . '-citation', 'wp_kses_post' ); + add_filter( 'default_option_' . $slug . '-citation', array( $this, 'default_citation' ) ); // When WP is 5.3+, use anonymous function. + + add_settings_field( $slug . '-parent', __('Redirection', $slug), array( $this, 'setting_parent' ), 'writing', $slug ); + register_setting( 'writing', $slug . '-parent', 'intval' ); + add_filter( 'default_option_' . $slug . '-parent', '__return_false' ); + + add_settings_field( $slug . '-save-publish', __( 'Upon Publishing...', 'press-this-extended' ), array( $this, 'setting_save_publish' ), 'writing', $slug ); + register_setting( 'writing', $slug . '-save-publish', array( $this, 'save_sanitize' ) ); + add_filter( 'default_option_' . $slug . '-save-publish', array( $this, 'default_publish' ) ); + + add_settings_field( $slug . '-save-draft', __( 'Upon Saving a Draft...', 'press-this-extended' ), array( $this, 'setting_save_draft' ), 'writing', $slug ); + register_setting( 'writing', $slug . '-save-draft', array( $this, 'save_sanitize' ) ); + add_filter( 'default_option_' . $slug . '-save-draft', array( $this, 'default_save' ) ); + + add_settings_field( $slug . '-editor', __('Text Editor', $slug), array( $this, 'setting_editor' ), 'writing', $slug ); + register_setting( 'writing', $slug . '-editor', 'intval' ); + add_filter( 'default_option_' . $slug . '-editor', '__return_false' ); + } + + + /** + * Santizes setting options for save_publish and save_draft settings. + * + * @return string Either 'pt', 'permalink', 'editor'. Defaults to 'editor' if validation fails. + * @since 1.0.0 + **/ + function save_sanitize( $value ) { + if ( $value != 'permalink' && $value != 'pt' ) { + $value = 'editor'; + } + + return $value; + } + + /** + * Converts pre-release Legacy option to standard options and delete option. + * + * This will be left in for version 1 to clean up the few beta testers. + * + * @return void + * @since 1.0.0 + **/ + function legacy_conversion() { + $legacy = get_option( 'press-this-extended-legacy', 'nothing' ); // sets a default value if setting is not present in the DB. Can't use false since that is a valid setting state in the db. + if ( $legacy == 1 ) { + $citation = '

via %2$s

'; + update_option( 'press-this-extended-media', false ); + update_option( 'press-this-extended-text', false ); + update_option( 'press-this-extended-citation', $citation ); + delete_option( 'press-this-extended-legacy' ); + } + elseif ( $legacy == false ) { + delete_option( 'press-this-extended-legacy' ); + } + } + + /** + * Returns the default blockquote wrapper original to Press This + * + * @return string Default blockquote wrapping with %1$s being the variable for the quote. + * @since 1.0.0 + **/ + function default_blockquote() { + return '
%1$s
'; + } + + /** + * Returns the default citation or "source" wrapper original to Press This. + * + * The default's use of "Source" is translated natively in WordPress Core, so no plugin language domain is indicated + * + * @return string Default source wrapping with %1$s representing the URL and %2$s the pressed page's title. + * @since 1.0.0 + **/ + function default_citation() { + $html = '

' . _x( 'Source:', 'Used in Press This to indicate where the content comes from.' ) . + ' %2$s

'; + return $html; + } + + /** + * Returns the default value for saving a draft. + * + * @return string Default draft redirect location. + * @since 1.0.0 + **/ + function default_save() { + return 'pt'; + } + + /** + * Returns the default value for publishing a post. + * + * @return string Default publish redirect location. + * @since 1.0.0 + **/ + function default_publish() { + return 'permalink'; + } + + /** + * Echos the Media Discovery setting form field + * + * @return void + * @since 1.0.0 + **/ + function setting_media(){ + $html = ''; + $html .= ''; + echo $html; + } + + /** + * Echos the Text Discovery setting form field + * + * @return void + * @since 1.0.0 + **/ + function setting_text(){ + $html = ''; + $html .= ''; + echo $html; + } + + /** + * Echos the Blockquote wrapper setting form field + * + * @return void + * @since 1.0.0 + **/ + function setting_blockquote(){ + $html = ''; + $html .= '

' . __( 'Use %1$s as a placeholder for the blockquote.', 'press-this-extended' ) .'

'; + echo $html; + } + + /** + * Echos the Citation wrapper setting form field + * + * @return void + * @since 1.0.0 + **/ + function setting_citation(){ + $html = ''; + $html .= '

' . __( 'Use %1$s and %2$s as a placeholders for the page URL and title, respectively.', 'press-this-extended' ) .'

'; + echo $html; + } + + /** + * Echos HTML for the Parent Redirection option setting form field. + * + * @return void + * @since 1.0.0 + **/ + function setting_parent() { + $html = ''; + $html .= ''; + + echo $html; + } + + /** + * Echos HTML for the selecting redirect when publishing a post. + * + * @return void + * @since 1.0.0 + **/ + function setting_save_publish() { + $options = array( + 'permalink' => __( 'Published Post', 'press-this-extended' ), + 'editor' => __( 'Standard Editor' ), + ); + + $extra_text = __( 'After publishing a post, you will be redirected to this location.', 'press-this-extended' ); + + $this->settings_select( 'press-this-extended-save-publish', $options, $extra_text ); + } + + /** + * Echos HTML for the selecting redirect when saving a draft. + * + * @return void + * @since 1.0.0 + **/ + function setting_save_draft() { + $options = array( + 'pt' => __( 'Remain in the Press This editor', 'press-this-extended' ), + 'editor' => __( 'Standard Editor' ), + ); + + $extra_text = __( 'After saving a draft, you will be redirected to this location.', 'press-this-extended' ); + + $this->settings_select( 'press-this-extended-save-draft', $options, $extra_text ); + } + + /** + * Echos HTML dropdown selection forms. + * + * @return void + * @since 1.0.0 + **/ + + function settings_select( $name, $values, $extra_text = '' ) { + if ( empty( $name ) || empty( $values ) || ! is_array( $values ) ) { + return; + } + $option = get_option( $name ); + ?> +
+ + +

+ +
+ '; + $html .= ''; + $html .= '

' . __( 'Experimental! This is not fully operational yet. Inserting detected media will not work in the Text Editor. The "Save Draft" button will not reappear until you focus within the Visual Editor.
There be dragons! Your milage may vary. No warranty implied or stated!', 'press-this-extended' ) .'

'; + echo $html; + } + + /** + * Used when filtering the default html from Press This based on the various options set in Press This Extended. + * + * @return array $html { + * @type string $quote Blockquote wrapping with placeholder %1$s for the quoted text. + * @type string $link Citation wrapping with placeholders %1$s and %2$s for Pressed URL and page title, respectively. + * } + * @since 1.0.0 + **/ + function execute_html( $html, $data ){ + $text_discovery = get_option( 'press-this-extended-text' ); + + $html = array( + 'quote' => get_option( 'press-this-extended-blockquote'), + 'link' => get_option( 'press-this-extended-citation'), + ); + + if ( $text_discovery == false && ! isset( $data['s'] ) ) { + $html['quote'] = ''; + } + + /* Leaving this in for now for future reference. + if ( $legacy ) { + if ( isset( $data['s'] ) ){ + $html = array( + 'quote' => '

%1$s

', + 'link' => '

via %2$s

', + ); + } + else { + $html = array( + 'quote' => '', + 'link' => '%2$s', + ); + } + }*/ + + return $html; + } + + /** + * Execute the settings by adding the filters specified by the various settings. + * + * @return void + * @since 1.0.0 + **/ + function execute() { + $text_discovery = get_option( 'press-this-extended-text' ); + $media_discovery = get_option( 'press-this-extended-media' ); + $redirect_parent = get_option( 'press-this-extended-parent' ); + $text_editor = get_option( 'press-this-extended-editor' ); + + if ( $media_discovery == false ) { + add_filter( 'enable_press_this_media_discovery', '__return_false' ); + } + + add_filter( 'press_this_suggested_html', array( $this, 'execute_html' ), 10, 2 ); + + if ( $text_editor ) { + add_filter('wp_editor_settings', array( $this, 'enable_text_editor' ) ); + add_action('admin_print_styles', array( $this, 'text_editor_style' ) ); + } + + if ( $redirect_parent ) { + add_filter( 'press_this_redirect_in_parent', '__return_true' ); + } + } + + /** + * Execute filters only used in the AJAX context. + * + * @return void + * @since 1.0.0 + **/ + function execute_ajax() { + add_filter( 'press_this_save_redirect', array( $this, 'redirect_publish'), 10, 3 ); + } + + /** + * Determines the redirected URL upon publishing a Press This post. + * + * This could be expanded in the future to do other fun things. + * + * @return URL of redirectoin + * @since 1.0.0 + */ + function redirect_publish( $redirect, $post_id, $post_status ) { + $save_publish = get_option( 'press-this-extended-save-publish' ); + $save_draft = get_option( 'press-this-extended-save-draft' ); + + if ( ( 'publish' == $post_status && $save_publish == 'editor' ) || 'publish' != $post_status && $save_draft == 'editor' ) { + $redirect = get_edit_post_link( $post_id, 'raw' ); + } + + return $redirect; // otherwise, it is using the default action within WordPress. We want their option in case we need to flesh this out later. + } + + /** + * Adds contextual help for Press This Extended options. + * + * @return void + * @since 1.0.0 + **/ + function help_tab() { + get_current_screen()->add_help_tab( array( + 'id' => 'options-press-this-extended', + 'title' => __('Press This'), + 'content' => '

' . __( 'These options allow you to customize the Press This bookmarklet to do some cool stuff.' ) . '

' . + '

' . __( 'Content Grabbing refers to Press This suggesting media and text for you to add in your pressed post. By default, Press This will suggest a blockfrom from the page\'s description unless it appears to be autogenerated.', 'press-this-extended' ) . '

' . + '

' . __( 'Blockquote and Citation Formatting allows you to adjust the default HTML template used when pressing a post.', 'press-this-extended' ) . '

' . + '

' . __( 'Redirection, Upon Publishing..., and Upon Saving A Draft... adjusts what happens when you save your content from Press This.', 'press-this-extended' ) . '

' . + '

' . __( 'Text Editor adds the HTML option found in the common editor. Some features of Press This, such as inserting the suggested media or the Save Draft text changing may not work as expected when using the text editor.', 'press-this-extended' ) . '

', + ) + ); + } + + /** + * Changes the UA on Press This scrapes to "WP Press This". + * + * Added since Medium and pehaps others block all requests with the UA of "WordPress" to stop pingback spam. + * + * @return string New UA string. + * @since 1.0.0 + **/ + function ua_hack() { + return 'WP Press This'; + } + + /** + * Adds inline styling to the Press This page via admin_print_styles hook for the text editor. + * + * + * @return void + * @see 'admin_print_styles' + * @since 1.0.0 + **/ + function text_editor_style(){ + echo ''; + } + + /** + * Enables the "quicktags" option in TinyMCE to flip between Visual and Text editors. + * + * Filter will retain all current TinyMCE settings except forcing the Visual/Text editor. + * @return array $settings { + * @type bool $quicktags Enables Visual/Text Editor buttons in TinyMCE + * } + * @since 1.0.0 + **/ + function enable_text_editor( $settings ){ + $settings['quicktags'] = true; + return $settings; + } + + /** + * Adds Settings link to plugin table. + * + * @return array $links + * + * @since 1.0.0 + **/ + function action_links( $links ) { + $links[] = 'Settings'; + return $links; + } +} + +// Giddy up. +$Press_This_Extended = new Press_This_Extended; \ No newline at end of file diff --git a/readme.txt b/readme.txt index 87df445..2d1a8f9 100644 --- a/readme.txt +++ b/readme.txt @@ -1,12 +1,40 @@ === Press This Extended === Contributors: kraftbj -Donate link: http://www.brandonkraft.com/donate/ +Donate link: https://www.brandonkraft.com/donate/ Tags: press this -Requires at least: 4.2 +Requires at least: 4.2 Tested up to: 4.2 -Stable tag: 0.1 +Stable tag: 1.0.0 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html -The new Press This in WordPress 4.2 includes new options that can be modified via code. Or via this plugin. +The new Press This in WordPress 4.2 includes new options that can be modified filters or a plugin like this. +== Description == + +The new Press This in WordPress 4.2 includes new options that can be modified filters or a plugin like this. + +Options include turning on or off the quick media insertion feature or automatically blockquoting the page's excerpt if you haven't selected text, and more. + +Development is taking place at https://github.com/kraftbj/press-this-extended + +== Installation == + +Via your site's wp-admin Dashboard: + +1. Visit Plugins->Add New +1. Search for "Press This Extended" +1. Click Install to add the plugin to your server +1. Click Activate Plugin to turn this plugin on. +1. Visit Settings->Writing to see the plugin's options. + +== Frequently Asked Questions == + += What is this? = + +The new Press This adds easy-to-use media discovery, blockquote insertion, cooler source links. It is really flexible, but no UI is included. This reveals the built-in flexibility. + +== Changelog == + += 1.0 = +* Initial Release \ No newline at end of file