From 95015262f03527956333cc65a22c83294af3ef66 Mon Sep 17 00:00:00 2001 From: davidwolfpaw Date: Wed, 12 Jun 2024 07:41:10 -0400 Subject: [PATCH] updates to v2.0 --- .editorconfig | 33 +++ .eslintrc.json | 31 +++ .gitignore | 58 +++++- README.md | 16 +- assets/css/cc-post-republisher-admin.css | 1 + assets/css/cc-post-republisher.css | 153 +++++++------- cc-post-republisher.php | 78 ++++++- class-cc-post-republisher-admin.php | 83 +++----- class-cc-post-republisher-meta-box.php | 85 ++++---- class-cc-post-republisher.php | 220 ++++++-------------- languages/cc-post-republisher.pot | 253 +++++++++++------------ license-block/block.js | 70 +++++++ license-block/modal.js | 70 +++++++ 13 files changed, 676 insertions(+), 475 deletions(-) create mode 100644 .editorconfig create mode 100644 .eslintrc.json create mode 100644 license-block/block.js create mode 100644 license-block/modal.js diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..1f460e5 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,33 @@ +# This file is for unifying the coding style for different editors and IDEs +# editorconfig.org + +# WordPress Coding Standards +# https://make.wordpress.org/core/handbook/coding-standards/ + +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +indent_style = tab + +[*.{yml,yaml}] +indent_style = space +indent_size = 2 + +[*.php] +indent_size = 4 + +[*.{js,jsx,ts,tsx,json}] +indent_size = 2 + +[*.css] +indent_size = 4 + +[*.{html,htm}] +indent_size = 4 + +[*.md] +trim_trailing_whitespace = false diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..f1bdd2e --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,31 @@ +{ + "env": { + "browser": true, + "es6": true, + "node": true + }, + "extends": "eslint:recommended", + "parserOptions": { + "ecmaVersion": 2018, + "sourceType": "module" + }, + "rules": { + "indent": [ + "error", + 2 + ], + "linebreak-style": [ + "error", + "unix" + ], + "quotes": [ + "error", + "single" + ], + "semi": [ + "error", + "always" + ], + "no-console": "off" + } +} diff --git a/.gitignore b/.gitignore index d51105b..724c8ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,16 @@ +# WordPress specific +/wp-content/uploads/ +/wp-content/upgrade/ +/wp-content/cache/ +/wp-content/backup-db/ +/wp-content/advanced-cache.php +/wp-content/wp-cache-config.php +/wp-content/debug.log + +# Ignore wp-cli configuration +wp-cli.local.yml +wp-cli.yml + # compiled source # ################### *.com @@ -25,6 +38,11 @@ *.log *.sql *.sqlite +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* # OS generated files # ###################### @@ -38,15 +56,39 @@ Thumbs.db # IDE files # ############# -/.idea +.idea/ +.vscode/ *.sublime-project *.sublime-workspace +*.code-workspace + +# Coverage directory used by tools like istanbul +coverage + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +dist/ +build/ +# Ignore composer and npm files +composer.lock +package-lock.json +yarn.lock + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Output of `npm pack` +*.tgz + +# Output of `wp-scripts plugin-zip` +*.zip -# Test Suite files # -#################### -/bin -/tests -.travis.yml -phpcs.xml.dist -phpunit.xml.dist +# dotenv environment variables file +.env diff --git a/README.md b/README.md index 0f5cef6..d2638de 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,8 @@ Contributors: wolfpaw Donate link: https://davidwolfpaw.com/ Tags: creative commons, licensing Requires at least: 4.0.0 -Tested up to: 5.8.0 -Stable tag: 1.4.0 +Tested up to: 6.5.4 +Stable tag: 2.0.0 License: GPLv3 or later License URI: http://www.gnu.org/licenses/gpl-3.0.html @@ -25,6 +25,18 @@ A. You can reach me with questions about this plugin via david@fixupfox.com ## == Changelog == +### = 2.0.0 = +* Updates plugin to work with the Full Site Editor +* Plugin still works with Classic Editor +* Update required for ClassicPress or sites without Full Site Editor +* Republish button text can be changed +* Republish Terms default text updated +* Updates design of terms modal +* Displays globally set license in metabox +* Deprecated PHP updated for PHP v8.2 +* WordPress comment code no longer displayed +* Shortcodes converted to HTML in Republish box + ### = 1.4.0 = * Sets an option for CC0 No Rights Reserved * Sets an option for CC0 Public Domain Mark diff --git a/assets/css/cc-post-republisher-admin.css b/assets/css/cc-post-republisher-admin.css index a501c40..4a6eb5c 100755 --- a/assets/css/cc-post-republisher-admin.css +++ b/assets/css/cc-post-republisher-admin.css @@ -1,3 +1,4 @@ +/* License Details in Post Metabox */ .license-details { display: flex; border: 1px solid #ddd; diff --git a/assets/css/cc-post-republisher.css b/assets/css/cc-post-republisher.css index 85e0b13..f0fb61b 100755 --- a/assets/css/cc-post-republisher.css +++ b/assets/css/cc-post-republisher.css @@ -1,75 +1,90 @@ -#cc-post-republisher-modal-container { - position: fixed; - display: none; - top: 0; - left: 0; - background: rgba(0, 0, 0, 0.25); - z-index: 1000; - width: 100%; - height: 100vh; +/* Republish Button */ +#cc-post-republisher-modal-button-open { + display: block; + text-decoration: none; + width: auto; + cursor: pointer; + padding: 10px; + border: 1px solid #ccc; + border-radius: 5px; } -#cc-post-republisher-modal { - position: fixed; - top: 0; - left: 0; - background: rgba(255, 255, 255, 0.95); - z-index: 1001; - width: 100%; - height: 100vh; - padding: 4em 2em; - overflow-y: auto; +#cc-post-republisher-modal-button-open img { + vertical-align: middle; + margin-right: 1rem; + -webkit-box-shadow: none; + box-shadow: none; + border-radius: 0; + border: none; + display: inline; } -#cc-post-republisher-modal-button-open, -#cc-post-republisher-modal-button-close { - background-color: #efefef; - color: #333; - border: 1px solid #999; - padding: 0.5rem; - line-height: 1; - font-weight: 700; - display: block; - margin-bottom: 1rem; - text-decoration: none; - width: auto; +/* Republish Button - Block Editor */ +#cc-post-republisher-modal-button-open.editable-button { + border: 2px dashed #ccc; + cursor: text; + background-color: transparent; + color: #095d86; } -#cc-post-republisher-modal-button-open img { - vertical-align: middle; - margin-right: 1rem; - -webkit-box-shadow: none; - box-shadow: none; - border-radius: 0; - border: none; - display: inline; +#cc-post-republisher-modal-button-open.editable-button:hover, +#cc-post-republisher-modal-button-open.editable-button:focus, +#cc-post-republisher-modal-button-open.editable-button:active { + border-color: #095d86; } +/* Close Button */ #cc-post-republisher-modal-button-close { - display: inline-block; - cursor: pointer; - font-size: 2rem; - float: right; - margin-top: -0.6rem; + position: relative; + float: right; + top: 10px; + right: 10px; + background: none; + border: none; + font-size: 1.5rem; + cursor: pointer; + font-size: 2rem; + margin-top: -0.6rem; } -#cc-post-republisher-modal-button-open:hover, -#cc-post-republisher-modal-button-open:focus, -#cc-post-republisher-modal-button-open:active, #cc-post-republisher-modal-button-close:hover, -#cc-post-republisher-modal-button-close:focus, -#cc-post-republisher-modal-button-close:active { +#cc-post-republisher-modal-button-close:focus { + color: black; + text-decoration: none; cursor: pointer; - color: #efefef; - background-color: #333; } +/* Modal */ +#cc-post-republisher-modal-container { + box-sizing: border-box; + display: none; + position: fixed; + z-index: 1000; + top: 0; + left: 0; + width: 100%; + height: 100%; + background: rgba(0, 0, 0, 0.5); + overflow-y: scroll; +} + +#cc-post-republisher-modal { + box-sizing: border-box; + background: rgba(255, 255, 255, 0.95); + border: 1px solid #ccc; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); + padding: 4em 2em; + overflow-y: auto; + height: 100%; +} + +/* License Details */ #cc-post-republisher-license { - line-height: 1; - font-weight: 700; - display: block; - margin-bottom: 2rem; - text-decoration: none; + line-height: 1; + font-weight: 700; + display: block; + margin-bottom: 2rem; + text-decoration: none; } #cc-post-republisher-license img { @@ -79,29 +94,15 @@ #cc-post-republisher-post-content { padding: 0.5rem; - background-color: #efefef; - color: #333; } #cc-post-republisher-post-content textarea { - width: 100%; - padding: 0.8rem; - font-family: monospace; - font-size: 1rem; - line-height: 1.4; - background: #f0f0f0; - border: none; - border-radius: 0; - resize: none; - box-shadow: none; - overflow: scroll; - outline: none; - -webkit-box-flex: 1; - -webkit-flex: 1 0 auto; - -moz-box-flex: 1; - -ms-flex: 1 0 auto; - flex: 1 0 auto; - height: 32rem; + box-sizing: border-box; + width: 100%; + padding: 1rem; + font-family: monospace; + overflow-y: scroll; + height: clamp(10vh, 20em, 50vh); } #cc-post-republisher-post-content textarea::selection { diff --git a/cc-post-republisher.php b/cc-post-republisher.php index ad6f369..fc8822a 100644 --- a/cc-post-republisher.php +++ b/cc-post-republisher.php @@ -3,7 +3,7 @@ Plugin Name: Creative Commons Post Republisher Plugin URI: https://davidwolfpaw.com/ Description: Place a widget on post pages or after post content with a link to the Creative Commons license that you've applied to your site, as well as a republisher window that makes it easier for others to share your content while maintaining your licensing. -Version: 1.4.0 +Version: 2.0.0 Author: wolfpaw Author URI: https://davidwolfpaw.com/plugins License: GPLv3 or later @@ -29,7 +29,7 @@ die(); } -define( 'CCPR_VERSION', '1.4.0' ); +define( 'CCPR_VERSION', '2.0.0' ); define( 'CCPR_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); define( 'CCPR_ASSET_DIR', plugin_dir_url( __FILE__ ) . 'assets/' ); @@ -43,17 +43,83 @@ register_activation_hook( __FILE__, 'activate_cc_post_republisher' ); function activate_cc_post_republisher() { - CC_Post_Republisher_Admin::default_general_settings(); - } /** * Load the plugin textdomain */ function cc_post_republisher_init() { + load_plugin_textdomain( 'cc-post-republisher', false, basename( __DIR__ ) . 'languages/' ); +} +add_action( 'init', 'cc_post_republisher_init' ); + +/** + * Register block scripts and styles. + * If the full site editor is not available, fallback + */ +function cc_post_republisher_register_block() { + wp_register_script( + 'cc-post-republisher-block', + plugins_url( 'license-block/block.js', __FILE__ ), + array( 'wp-blocks', 'wp-element', 'wp-editor', 'wp-components' ), + CCPR_VERSION, + true + ); - load_plugin_textdomain( 'cc-post-republisher', false, basename( dirname( __FILE__ ) ) . 'languages/' ); + wp_register_script( + 'cc-post-republisher-modal', + plugins_url( 'license-block/modal.js', __FILE__ ), + array( 'jquery', 'wp-blocks', 'wp-element', 'wp-editor' ), + CCPR_VERSION, + true + ); + wp_register_style( + 'cc-post-republisher-style', + plugins_url( 'assets/css/cc-post-republisher.css', __FILE__ ), + array(), + CCPR_VERSION + ); + + register_block_type( + 'cc/post-republisher', + array( + 'editor_script' => 'cc-post-republisher-block', + 'style' => 'cc-post-republisher-style', + ) + ); + + wp_enqueue_script( 'cc-post-republisher-modal' ); + + // Fallback for ClassicPress or environments without FSE + // if ( has_action( 'wp_enqueue_scripts', 'wp_enqueue_classic_theme_styles' ) ) { + // add_filter( 'the_content', 'cc_post_republisher_add_to_content' ); + // } } -add_action( 'init', 'cc_post_republisher_init' ); +add_action( 'init', 'cc_post_republisher_register_block' ); + +// If the classic editor is active, fallback to placing button after the_content() +function cc_post_republisher_add_to_content( $content ) { + if ( is_singular() && in_the_loop() && is_main_query() ) { + ob_start(); + ?> +
+ + +
+
+ plugin_name = 'cc-post-republisher'; - $this->version = '1.4.0'; + $this->version = CCPR_VERSION; $this->assets_url = plugin_dir_url( __FILE__ ) . 'assets/'; add_action( 'admin_menu', array( $this, 'setup_plugin_options_menu' ), 9 ); add_action( 'admin_init', array( $this, 'initialize_general_settings' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'cc_post_republisher_scripts' ) ); - } /** * Loads plugin scripts and styles */ public function cc_post_republisher_scripts() { - - wp_enqueue_style( 'cc-post-republisher-admin-css', $this->assets_url . 'css/cc-post-republisher-admin.css', array(), '1.4.0' ); - + wp_enqueue_style( 'cc-post-republisher-admin-css', $this->assets_url . 'css/cc-post-republisher-admin.css', array(), CCPR_VERSION ); } /** @@ -38,7 +35,6 @@ public function setup_plugin_options_menu() { 'cc_post_republisher_settings', array( $this, 'render_settings_page_content' ) ); - } /** @@ -54,16 +50,17 @@ public static function default_general_settings() { $defaults = array( 'termstext' => sprintf( - 'REPUBLISHING TERMS

You may republish this article online or in print under our Creative Commons license. You may not edit or shorten the text, you must attribute the article to %s and you must include the author’s name in your republication.

If you have any questions, please email %s

', - esc_html( $site_name ), + 'REPUBLISHING TERMS +

You may republish this article online or in print under the selected Creative Commons license. You must provide attribution to the article when republishing. An ideal attribution to this article includes: Title, Author, Source, License. For more information on providing attribution, see: https://wiki.creativecommons.org/wiki/Recommended_practices_for_attribution

+

If you have any questions, please email %s

', esc_attr( $admin_email ), esc_attr( $admin_email ) ), 'license_type' => 'cc-by', + 'button_text' => 'Republish', ); update_option( 'cc_post_republisher_settings', $defaults ); - } /** @@ -141,51 +138,23 @@ public function initialize_general_settings() { ) ); + // add_settings_field( + // 'button_text', + // __( 'Button Text', 'cc-post-republisher' ), + // array( $this, 'text_input_callback' ), + // 'cc_post_republisher_general_settings', + // 'general_settings_section', + // array( + // 'label_for' => 'button_text', + // 'option_group' => 'cc_post_republisher_settings', + // 'option_id' => 'button_text', + // ) + // ); + register_setting( 'cc_post_republisher_general_settings', 'cc_post_republisher_settings' ); - - } - - /** - * Input Callbacks - */ - public function text_input_callback( $text_input ) { - - // Get arguments from setting - $option_group = $text_input['option_group']; - $option_id = $text_input['option_id']; - $option_name = "{$option_group}[{$option_id}]"; - - // Get existing option from database - $options = get_option( $option_group ); - $option_value = isset( $options[ $option_id ] ) ? $options[ $option_id ] : '0'; - - // Render the output - echo ""; - - } - - public function checkbox_input_callback( $checkbox_input ) { - - // Get arguments from setting - $option_group = $checkbox_input['option_group']; - $option_id = $checkbox_input['option_id']; - $option_name = "{$option_group}[{$option_id}]"; - $option_description = $checkbox_input['option_description']; - - // Get existing option from database - $options = get_option( $option_group ); - $option_value = isset( $options[ $option_id ] ) ? $options[ $option_id ] : ''; - - // Render the output - $input = ''; - $input .= "'; - $input .= ""; - - echo $input; - } public function wp_editor_input_callback( $wp_editor_input ) { @@ -204,7 +173,6 @@ public function wp_editor_input_callback( $wp_editor_input ) { ); // Render the output wp_editor( $content, $option_id, $settings ); - } public function license_input_callback( $license_input ) { @@ -220,7 +188,7 @@ public function license_input_callback( $license_input ) { $option_value = isset( $options[ $option_id ] ) ? $options[ $option_id ] : ''; // Render the output - echo "

{$option_description}

"; + echo '

' . esc_html( $option_description ) . '

'; ?>
@@ -350,6 +318,15 @@ public function license_input_callback( $license_input ) { '; + } // Validate inputs public function validate_inputs( $input ) { @@ -366,7 +343,5 @@ public function validate_inputs( $input ) { // Return the array processing any additional functions filtered by this action return apply_filters( 'validate_inputs', $output, $input ); } - - } new CC_Post_Republisher_Admin(); diff --git a/class-cc-post-republisher-meta-box.php b/class-cc-post-republisher-meta-box.php index 30d49a3..32acc35 100644 --- a/class-cc-post-republisher-meta-box.php +++ b/class-cc-post-republisher-meta-box.php @@ -3,17 +3,13 @@ * @package Creative Commons Post Republisher */ class CC_Post_Republisher_Meta_Box { - - private $screens = array( - 'post', - ); - /** * Class construct method. Adds actions to their respective WordPress hooks. */ public function __construct() { - - $this->fields = array( + $options = get_option( 'cc_post_republisher_settings' ); + $this->global_license = isset( $options['license_type'] ) ? $options['license_type'] : 'cc-by'; + $this->fields = array( array( 'id' => 'license-type', 'label' => 'License Type', @@ -36,7 +32,6 @@ public function __construct() { add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) ); add_action( 'save_post', array( $this, 'save_post' ) ); - } /** @@ -44,9 +39,14 @@ public function __construct() { * Goes through screens (post types) and adds the meta box. */ public function add_meta_boxes() { + $screens = array(); + $post_types = get_post_types( array( 'public' => true ), 'names' ); - foreach ( $this->screens as $screen ) { + foreach ( $post_types as $post_type ) { + $screens[] = $post_type; + } + foreach ( $screens as $screen ) { add_meta_box( 'creative-commons-post-republisher', __( 'Creative Commons', 'cc-post-republisher' ), @@ -55,9 +55,7 @@ public function add_meta_boxes() { 'side', 'default' ); - } - } /** @@ -66,87 +64,78 @@ public function add_meta_boxes() { * @param object $post WordPress post object */ public function add_meta_box_callback( $post ) { - wp_nonce_field( 'creative_commons_post_republisher_data', 'creative_commons_post_republisher_nonce' ); printf( - /* translators: admin url */ - __( 'Assign a license to this post. If no license is selected, the post will have the default license that is set in the Creative Commons Post Republisher Settings.', 'cc-post-republisher' ), - esc_url( admin_url() . 'options-general.php?page=cc_post_republisher_settings' ) + wp_kses( + /* translators: admin url */ + __( 'Assign a license to this post. If no license is selected, the post will have the default license that is set in the Creative Commons Post Republisher Settings.', 'cc-post-republisher' ), + array( + 'a' => array( + 'href' => array(), + ), + ) + ), + esc_url( admin_url( 'options-general.php?page=cc_post_republisher_settings' ) ) ); $this->generate_fields( $post ); - } /** * Generates the field's HTML for the meta box. */ public function generate_fields( $post ) { - - $output = ''; - foreach ( $this->fields as $field ) { - $label = ''; + $label = ''; $db_value = get_post_meta( $post->ID, 'creative_commons_post_republisher_' . $field['id'], true ); if ( empty( $db_value ) ) { $db_value = $field['default']; } $input = '
'; - $input .= '' . $field['label'] . ''; - $i = 0; + $input .= '' . esc_html( $field['label'] ) . ''; foreach ( $field['options'] as $key => $value ) { $field_value = ! is_numeric( $key ) ? $key : $value; - $input .= sprintf( + // Display what the default global license is set to + if ( 'default' === $key ) { + $value .= ' (' . esc_html( strtoupper( $this->global_license ) ) . ')'; + } + $input .= sprintf( '%s', - $db_value === $field_value ? 'checked' : '', - $field['id'], - $field['id'], - $field_value, - $value, - $i < count( $field['options'] ) - 1 ? '
' : '' + checked( $db_value, $field_value, false ), + esc_attr( $field['id'] ), + esc_attr( $field['id'] ), + esc_attr( $field_value ), + wp_kses( $value, array( 'strong' => array() ) ), + '
' ); - $i++; } $input .= '
'; - $output .= '

' . $input . '

'; - + echo '

' . $input . '

'; } - - echo $output; - } /** * Hooks into WordPress' save_post function */ public function save_post( $post_id ) { - - if ( ! isset( $_POST['creative_commons_post_republisher_nonce'] ) ) { - return $post_id; - } - - $nonce = $_POST['creative_commons_post_republisher_nonce']; - if ( ! wp_verify_nonce( $nonce, 'creative_commons_post_republisher_data' ) ) { + // Check for nonce + if ( ! isset( $_POST['creative_commons_post_republisher_nonce'] ) || ! wp_verify_nonce( $_POST['creative_commons_post_republisher_nonce'], 'creative_commons_post_republisher_data' ) ) { return $post_id; } + // Check for autosave if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return $post_id; } foreach ( $this->fields as $field ) { - if ( isset( $_POST[ $field['id'] ] ) ) { - - update_post_meta( $post_id, 'creative_commons_post_republisher_' . $field['id'], $_POST[ $field['id'] ] ); - + update_post_meta( $post_id, 'creative_commons_post_republisher_' . $field['id'], sanitize_text_field( $_POST[ $field['id'] ] ) ); } } - } - } new CC_Post_Republisher_Meta_Box(); diff --git a/class-cc-post-republisher.php b/class-cc-post-republisher.php index f0779bd..ec2878c 100644 --- a/class-cc-post-republisher.php +++ b/class-cc-post-republisher.php @@ -5,21 +5,11 @@ class CC_Post_Republisher { private static $post; - private $licenses; - // Get options from DB - // Get content and title of post - // Clean content and title of post public function __construct() { - - $this->plugin_name = 'cc-post-republisher'; - $this->version = '1.4.0'; - $this->assets_url = plugin_dir_url( __FILE__ ) . 'assets/'; - - $this->load_republish_on_single(); - - $this->licenses = array( + $this->assets_url = plugin_dir_url( __FILE__ ) . 'assets/'; + $this->licenses = array( 'cc-by' => array( 'license_type' => 'cc-by', 'license_image' => 'cc-by.png', @@ -74,7 +64,7 @@ public function __construct() { 'license_url' => __( 'https://creativecommons.org/licenses/by-nc-nd/4.0', 'cc-post-republisher' ), 'license_legal_url' => __( 'https://creativecommons.org/licenses/by-nc-nd/4.0/legalcode', 'cc-post-republisher' ), ), - 'cc0' => array( + 'cc0' => array( 'license_type' => 'cc0', 'license_image' => 'cc0.png', 'license_name' => __( 'No Rights Reserved', 'cc-post-republisher' ), @@ -83,7 +73,7 @@ public function __construct() { 'license_url' => __( 'https://creativecommons.org/publicdomain/zero/1.0/', 'cc-post-republisher' ), 'license_legal_url' => __( 'https://creativecommons.org/publicdomain/zero/1.0/legalcode', 'cc-post-republisher' ), ), - 'pdm' => array( + 'pdm' => array( 'license_type' => 'pdm', 'license_image' => 'pdm.png', 'license_name' => __( 'Public Domain Mark "No Known Copyright"', 'cc-post-republisher' ), @@ -94,153 +84,112 @@ public function __construct() { ), ); + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); + add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); } /** - * Loads republish box only on single posts - */ - public function load_republish_on_single() { - - add_action( 'wp_footer', array( $this, 'render_republish_box' ), 99 ); - add_action( 'wp_enqueue_scripts', array( $this, 'cc_post_republisher_scripts' ) ); - add_filter( 'the_content', array( $this, 'cc_post_republisher_open_modal' ) ); - - add_filter( 'body_class', array( $this, 'cc_post_republisher_body_class' ), 20 ); - - } - - /** - * Loads plugin scripts and styles + * Localizes the frontend script with necessary post data */ - public function cc_post_republisher_scripts() { - - if ( is_single() ) { - - wp_enqueue_style( 'cc-post-republisher-css', $this->assets_url . 'css/cc-post-republisher.css', array(), '1.4.0' ); - wp_enqueue_script( 'cc-post-republisher-js', $this->assets_url . 'js/cc-post-republisher.js', array(), '1.4.0', true ); - - } + public function enqueue_scripts() { + global $post; + // Localize the modal script with new data + wp_localize_script( + 'cc-post-republisher-modal', + 'wpApiSettings', + array( + 'root' => esc_url_raw( rest_url() ), + 'nonce' => wp_create_nonce( 'wp_rest' ), + 'postID' => $post->ID, + 'postType' => $post->post_type, + 'licenseContent' => $this->get_post_republish_license( isset( $post->ID ) ? $post->ID : 0 ), + 'termsContent' => $this->get_post_republish_terms(), + ) + ); } /** - * Loads plugin scripts and styles + * Localizes the dashboard script with necessary post data */ - public function cc_post_republisher_body_class( $classes ) { - - if ( is_single() ) { - - $classes[] = 'cc-post-republisher'; - - } - - return $classes; - + public function admin_enqueue_scripts() { + global $post; + $options = get_option( 'cc_post_republisher_settings' ); + $active_license = isset( $options['license_type'] ) ? $options['license_type'] : 'cc-by'; + $licenses = $this->licenses; + $active_license_image = isset( $licenses[ $active_license ] ) ? plugin_dir_url( __FILE__ ) . 'assets/img/' . $licenses[ $active_license ]['license_image'] : ''; + + // Localize the block script with new data + wp_localize_script( + 'cc-post-republisher-block', + 'blockSettings', + array( + 'activeLicense' => $active_license, + 'activeLicenseImage' => $active_license_image, + ) + ); } /** - * Loads button to open modal + * Gets the license of the post that we're going to republish */ - public function cc_post_republisher_open_modal( $content ) { - - if ( is_single() ) { - - // Get the license for this post - $post_license = $this->get_license(); - - // If this has a CC license attributed, display open modal - if ( 'no-cc-license' !== $post_license ) { - - $license_name = $this->licenses[ $post_license ]['license_name']; - $license_text = __( 'Creative Commons License', 'cc-post-republisher' ); - $license_img = $this->licenses[ $post_license ]['license_image']; - $license_image = "{$license_text} {$license_name}"; + public function get_license_type( $post_id ) { + // Get the license from the post meta if set for this specific post + $license_type = get_post_meta( $post_id, 'creative_commons_post_republisher_license-type', true ); - $content .= ''; - - } + if ( $license_type && 'default' !== $license_type ) { + return $license_type; } - return $content; - - } - - /** - * Gets the title of the post that we're going to republish - */ - public function get_post_republish_title() { - - return get_the_title(); - + // Fall back to the global setting + $options = get_option( 'cc_post_republisher_settings' ); + return isset( $options['license_type'] ) ? $options['license_type'] : 'cc-by'; } - /** - * Gets the content of the post that we're going to republish - */ - public function get_post_republish_content() { - - $content = get_the_content(); - - return ''; - - } /** * Gets the license of the post that we're going to republish */ - public function get_license() { + public function get_post_republish_license( $post_id ) { - // Get the license settings to pull the global default - $ccpr_options = get_option( 'cc_post_republisher_settings' ); + // Get the license for this post + $license_type = $this->get_license_type( $post_id ); - // Get the license selected for this specific post - $post_license = get_post_meta( get_the_id(), 'creative_commons_post_republisher_license-type' ); + if ( isset( $this->licenses[ $license_type ] ) ) { + $license = $this->licenses[ $license_type ]; + $license_image = "{$license["; + $license_type = "

License

{$license_image}{$license['license_name']}
"; - // If we've set to use the default post license (or none is set for this post), use the default - if ( empty( $post_license ) || 'default' === $post_license[0] ) { - $post_license = $ccpr_options['license_type']; - } else { - $post_license = $post_license[0]; + return $license_type; } - return $post_license; - - } - - /** - * Gets the license of the post that we're going to republish - */ - public function get_post_republish_license() { + if ( 'cc0' === $license_type || 'pdm' === $license_type ) { - // Get the license for this post - $post_license = $this->get_license(); - - if ( 'cc0' === $post_license || 'pdm' === $post_license ) { - - $license_url = $this->licenses[ $post_license ]['license_url']; - $license_name = $this->licenses[ $post_license ]['license_name']; - $license_img = $this->licenses[ $post_license ]['license_image']; + $license_url = $this->licenses[ $license_type ]['license_url']; + $license_name = $this->licenses[ $license_type ]['license_name']; + $license_img = $this->licenses[ $license_type ]['license_image']; $license_image = "{$license_name}"; - $license_type = "

License

{$license_image}{$license_name}
"; + $license_type = "

License

{$license_image}{$license_name}
"; return $license_type; } - if ( 'no-cc-license' !== $post_license ) { + if ( 'no-cc-license' !== $license_type ) { - $license_url = $this->licenses[ $post_license ]['license_url']; - $license_name = $this->licenses[ $post_license ]['license_name']; - $license_img = $this->licenses[ $post_license ]['license_image']; + $license_url = $this->licenses[ $license_type ]['license_url']; + $license_name = $this->licenses[ $license_type ]['license_name']; + $license_img = $this->licenses[ $license_type ]['license_image']; $license_image = "Creative Commons License {$license_name}"; - $license_type = "

License

{$license_image}Creative Commons {$license_name}
"; + $license_type = "

License

{$license_image}Creative Commons {$license_name}
"; return $license_type; } + return ''; } /** @@ -253,40 +202,5 @@ public function get_post_republish_terms() { if ( '' !== $ccpr_options['termstext'] ) { return wpautop( $ccpr_options['termstext'] ); } - } - - public function render_republish_box() { - - global $post; - - if ( is_single() ) { - - echo '
'; - - echo '
'; - - echo ''; - - echo $this->get_post_republish_terms(); - - echo $this->get_post_republish_license(); - - echo '
'; - - echo $this->get_post_republish_title(); - - echo $this->get_post_republish_content(); - - echo '
'; - - echo '
'; - - echo '
'; - - } - - } - } -new CC_Post_Republisher(); diff --git a/languages/cc-post-republisher.pot b/languages/cc-post-republisher.pot index 6cb3c9f..d438dd2 100755 --- a/languages/cc-post-republisher.pot +++ b/languages/cc-post-republisher.pot @@ -1,349 +1,346 @@ -# Copyright (C) 2021 wolfpaw +# Copyright (C) 2024 wolfpaw # This file is distributed under the GPLv3 or later. msgid "" msgstr "" -"Project-Id-Version: Creative Commons Post Republisher 1.4.0\n" -"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/cc-post-republisher\n" +"Project-Id-Version: Creative Commons Post Republisher 2.0.0\n" +"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/Creative-Commons-Post-Republisher\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"POT-Creation-Date: 2021-09-01T15:07:10+00:00\n" +"POT-Creation-Date: 2024-06-12T11:40:48+00:00\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"X-Generator: WP-CLI 2.5.1-alpha-0d94e07\n" +"X-Generator: WP-CLI 2.10.0\n" "X-Domain: cc-post-republisher\n" #. Plugin Name of the plugin +#: cc-post-republisher.php msgid "Creative Commons Post Republisher" msgstr "" #. Plugin URI of the plugin +#: cc-post-republisher.php msgid "https://davidwolfpaw.com/" msgstr "" #. Description of the plugin +#: cc-post-republisher.php msgid "Place a widget on post pages or after post content with a link to the Creative Commons license that you've applied to your site, as well as a republisher window that makes it easier for others to share your content while maintaining your licensing." msgstr "" #. Author of the plugin +#: cc-post-republisher.php msgid "wolfpaw" msgstr "" #. Author URI of the plugin +#: cc-post-republisher.php msgid "https://davidwolfpaw.com/plugins" msgstr "" -#: class-cc-post-republisher-admin.php:35 -#: class-cc-post-republisher-admin.php:77 +#: class-cc-post-republisher-admin.php:32 +#: class-cc-post-republisher-admin.php:74 msgid "Creative Commons Post Republisher Settings" msgstr "" -#: class-cc-post-republisher-admin.php:36 +#: class-cc-post-republisher-admin.php:33 #: class-cc-post-republisher-meta-box.php:52 msgid "Creative Commons" msgstr "" -#: class-cc-post-republisher-admin.php:112 +#: class-cc-post-republisher-admin.php:109 msgid "General Settings" msgstr "" -#: class-cc-post-republisher-admin.php:119 +#: class-cc-post-republisher-admin.php:116 msgid "Terms Text" msgstr "" -#: class-cc-post-republisher-admin.php:132 +#: class-cc-post-republisher-admin.php:129 msgid "Creative Commons License Type" msgstr "" -#: class-cc-post-republisher-admin.php:140 +#: class-cc-post-republisher-admin.php:137 msgid "Select the default license that you want to apply to your post content. This can be changed on individual posts." msgstr "" -#: class-cc-post-republisher-admin.php:231 +#: class-cc-post-republisher-admin.php:199 msgid "Creative Commons License Attribution CC BY" msgstr "" -#: class-cc-post-republisher-admin.php:232 -#: class-cc-post-republisher.php:26 +#: class-cc-post-republisher-admin.php:200 +#: class-cc-post-republisher.php:16 msgid "Attribution" msgstr "" -#: class-cc-post-republisher-admin.php:233 -#: class-cc-post-republisher.php:27 +#: class-cc-post-republisher-admin.php:201 +#: class-cc-post-republisher.php:17 msgid "CC BY" msgstr "" -#: class-cc-post-republisher-admin.php:236 -#: class-cc-post-republisher.php:28 +#: class-cc-post-republisher-admin.php:204 +#: class-cc-post-republisher.php:18 msgid "This license lets others distribute, remix, tweak, and build upon your work, even commercially, as long as they credit you for the original creation. This is the most accommodating of licenses offered. Recommended for maximum dissemination and use of licensed materials." msgstr "" -#: class-cc-post-republisher-admin.php:237 -#: class-cc-post-republisher.php:29 +#: class-cc-post-republisher-admin.php:205 +#: class-cc-post-republisher.php:19 msgid "https://creativecommons.org/licenses/by/4.0" msgstr "" -#: class-cc-post-republisher-admin.php:237 -#: class-cc-post-republisher-admin.php:251 -#: class-cc-post-republisher-admin.php:265 -#: class-cc-post-republisher-admin.php:279 -#: class-cc-post-republisher-admin.php:293 -#: class-cc-post-republisher-admin.php:307 -#: class-cc-post-republisher-admin.php:321 -#: class-cc-post-republisher-admin.php:335 +#: class-cc-post-republisher-admin.php:205 +#: class-cc-post-republisher-admin.php:219 +#: class-cc-post-republisher-admin.php:233 +#: class-cc-post-republisher-admin.php:247 +#: class-cc-post-republisher-admin.php:261 +#: class-cc-post-republisher-admin.php:275 +#: class-cc-post-republisher-admin.php:289 +#: class-cc-post-republisher-admin.php:303 msgid "View License Deed" msgstr "" -#: class-cc-post-republisher-admin.php:237 -#: class-cc-post-republisher.php:30 +#: class-cc-post-republisher-admin.php:205 +#: class-cc-post-republisher.php:20 msgid "https://creativecommons.org/licenses/by/4.0/legalcode" msgstr "" -#: class-cc-post-republisher-admin.php:237 -#: class-cc-post-republisher-admin.php:251 -#: class-cc-post-republisher-admin.php:265 -#: class-cc-post-republisher-admin.php:279 -#: class-cc-post-republisher-admin.php:293 -#: class-cc-post-republisher-admin.php:307 -#: class-cc-post-republisher-admin.php:321 +#: class-cc-post-republisher-admin.php:205 +#: class-cc-post-republisher-admin.php:219 +#: class-cc-post-republisher-admin.php:233 +#: class-cc-post-republisher-admin.php:247 +#: class-cc-post-republisher-admin.php:261 +#: class-cc-post-republisher-admin.php:275 +#: class-cc-post-republisher-admin.php:289 msgid "View Legal Code" msgstr "" -#: class-cc-post-republisher-admin.php:246 -#: class-cc-post-republisher.php:35 +#: class-cc-post-republisher-admin.php:214 +#: class-cc-post-republisher.php:25 msgid "Attribution-ShareAlike" msgstr "" -#: class-cc-post-republisher-admin.php:247 -#: class-cc-post-republisher.php:36 +#: class-cc-post-republisher-admin.php:215 +#: class-cc-post-republisher.php:26 msgid "CC BY-SA" msgstr "" -#: class-cc-post-republisher-admin.php:250 -#: class-cc-post-republisher.php:37 +#: class-cc-post-republisher-admin.php:218 +#: class-cc-post-republisher.php:27 msgid "This license lets others remix, tweak, and build upon your work even for commercial purposes, as long as they credit you and license their new creations under the identical terms. This license is often compared to “copyleft” free and open source software licenses. All new works based on yours will carry the same license, so any derivatives will also allow commercial use. This is the license used by Wikipedia, and is recommended for materials that would benefit from incorporating content from Wikipedia and similarly licensed projects." msgstr "" -#: class-cc-post-republisher-admin.php:251 -#: class-cc-post-republisher.php:38 +#: class-cc-post-republisher-admin.php:219 +#: class-cc-post-republisher.php:28 msgid "https://creativecommons.org/licenses/by-sa/4.0" msgstr "" -#: class-cc-post-republisher-admin.php:251 -#: class-cc-post-republisher.php:39 +#: class-cc-post-republisher-admin.php:219 +#: class-cc-post-republisher.php:29 msgid "https://creativecommons.org/licenses/by-sa/4.0/legalcode" msgstr "" -#: class-cc-post-republisher-admin.php:260 -#: class-cc-post-republisher.php:44 +#: class-cc-post-republisher-admin.php:228 +#: class-cc-post-republisher.php:34 msgid "Attribution-NoDerivs" msgstr "" -#: class-cc-post-republisher-admin.php:261 -#: class-cc-post-republisher.php:45 +#: class-cc-post-republisher-admin.php:229 +#: class-cc-post-republisher.php:35 msgid "CC BY-ND" msgstr "" -#: class-cc-post-republisher-admin.php:264 -#: class-cc-post-republisher.php:46 +#: class-cc-post-republisher-admin.php:232 +#: class-cc-post-republisher.php:36 msgid "This license allows for redistribution, commercial and non-commercial, as long as it is passed along unchanged and in whole, with credit to you." msgstr "" -#: class-cc-post-republisher-admin.php:265 -#: class-cc-post-republisher.php:47 +#: class-cc-post-republisher-admin.php:233 +#: class-cc-post-republisher.php:37 msgid "https://creativecommons.org/licenses/by-nd/4.0" msgstr "" -#: class-cc-post-republisher-admin.php:265 -#: class-cc-post-republisher.php:48 +#: class-cc-post-republisher-admin.php:233 +#: class-cc-post-republisher.php:38 msgid "https://creativecommons.org/licenses/by-nd/4.0/legalcode" msgstr "" -#: class-cc-post-republisher-admin.php:274 -#: class-cc-post-republisher.php:53 +#: class-cc-post-republisher-admin.php:242 +#: class-cc-post-republisher.php:43 msgid "Attribution-NonCommercial" msgstr "" -#: class-cc-post-republisher-admin.php:275 -#: class-cc-post-republisher.php:54 +#: class-cc-post-republisher-admin.php:243 +#: class-cc-post-republisher.php:44 msgid "CC BY-NC" msgstr "" -#: class-cc-post-republisher-admin.php:278 -#: class-cc-post-republisher.php:55 +#: class-cc-post-republisher-admin.php:246 +#: class-cc-post-republisher.php:45 msgid "This license lets others remix, tweak, and build upon your work non-commercially, and although their new works must also acknowledge you and be non-commercial, they don’t have to license their derivative works on the same terms." msgstr "" -#: class-cc-post-republisher-admin.php:279 -#: class-cc-post-republisher.php:56 +#: class-cc-post-republisher-admin.php:247 +#: class-cc-post-republisher.php:46 msgid "https://creativecommons.org/licenses/by-nc/4.0" msgstr "" -#: class-cc-post-republisher-admin.php:279 -#: class-cc-post-republisher.php:57 +#: class-cc-post-republisher-admin.php:247 +#: class-cc-post-republisher.php:47 msgid "https://creativecommons.org/licenses/by-nc/4.0/legalcode" msgstr "" -#: class-cc-post-republisher-admin.php:288 -#: class-cc-post-republisher.php:62 +#: class-cc-post-republisher-admin.php:256 +#: class-cc-post-republisher.php:52 msgid "Attribution-NonCommercial-ShareAlike" msgstr "" -#: class-cc-post-republisher-admin.php:289 -#: class-cc-post-republisher.php:63 +#: class-cc-post-republisher-admin.php:257 +#: class-cc-post-republisher.php:53 msgid "CC BY-NC-SA" msgstr "" -#: class-cc-post-republisher-admin.php:292 -#: class-cc-post-republisher.php:64 +#: class-cc-post-republisher-admin.php:260 +#: class-cc-post-republisher.php:54 msgid "This license lets others remix, tweak, and build upon your work non-commercially, as long as they credit you and license their new creations under the identical terms." msgstr "" -#: class-cc-post-republisher-admin.php:293 -#: class-cc-post-republisher.php:65 +#: class-cc-post-republisher-admin.php:261 +#: class-cc-post-republisher.php:55 msgid "https://creativecommons.org/licenses/by-nc-sa/4.0" msgstr "" -#: class-cc-post-republisher-admin.php:293 -#: class-cc-post-republisher.php:66 +#: class-cc-post-republisher-admin.php:261 +#: class-cc-post-republisher.php:56 msgid "https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode" msgstr "" -#: class-cc-post-republisher-admin.php:302 -#: class-cc-post-republisher.php:71 +#: class-cc-post-republisher-admin.php:270 +#: class-cc-post-republisher.php:61 msgid "Attribution-NonCommercial-NoDerivs" msgstr "" -#: class-cc-post-republisher-admin.php:303 -#: class-cc-post-republisher.php:72 +#: class-cc-post-republisher-admin.php:271 +#: class-cc-post-republisher.php:62 msgid "CC BY-NC-ND" msgstr "" -#: class-cc-post-republisher-admin.php:306 -#: class-cc-post-republisher.php:73 +#: class-cc-post-republisher-admin.php:274 +#: class-cc-post-republisher.php:63 msgid "This license is the most restrictive of our six main licenses, only allowing others to download your works and share them with others as long as they credit you, but they can’t change them in any way or use them commercially." msgstr "" -#: class-cc-post-republisher-admin.php:307 -#: class-cc-post-republisher.php:74 +#: class-cc-post-republisher-admin.php:275 +#: class-cc-post-republisher.php:64 msgid "https://creativecommons.org/licenses/by-nc-nd/4.0" msgstr "" -#: class-cc-post-republisher-admin.php:307 -#: class-cc-post-republisher.php:75 +#: class-cc-post-republisher-admin.php:275 +#: class-cc-post-republisher.php:65 msgid "https://creativecommons.org/licenses/by-nc-nd/4.0/legalcode" msgstr "" -#: class-cc-post-republisher-admin.php:316 -#: class-cc-post-republisher.php:80 +#: class-cc-post-republisher-admin.php:284 +#: class-cc-post-republisher.php:70 msgid "No Rights Reserved" msgstr "" -#: class-cc-post-republisher-admin.php:317 +#: class-cc-post-republisher-admin.php:285 msgid "CC0" msgstr "" -#: class-cc-post-republisher-admin.php:320 -#: class-cc-post-republisher.php:82 +#: class-cc-post-republisher-admin.php:288 +#: class-cc-post-republisher.php:72 msgid "The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission." msgstr "" -#: class-cc-post-republisher-admin.php:321 +#: class-cc-post-republisher-admin.php:289 msgid "https://creativecommons.org/publicdomain/zero/1.0" msgstr "" -#: class-cc-post-republisher-admin.php:321 -#: class-cc-post-republisher.php:84 +#: class-cc-post-republisher-admin.php:289 +#: class-cc-post-republisher.php:74 msgid "https://creativecommons.org/publicdomain/zero/1.0/legalcode" msgstr "" -#: class-cc-post-republisher-admin.php:330 -#: class-cc-post-republisher.php:90 +#: class-cc-post-republisher-admin.php:298 +#: class-cc-post-republisher.php:80 msgid "Public Domain Mark" msgstr "" -#: class-cc-post-republisher-admin.php:331 +#: class-cc-post-republisher-admin.php:299 msgid "PDM" msgstr "" -#: class-cc-post-republisher-admin.php:334 -#: class-cc-post-republisher.php:91 +#: class-cc-post-republisher-admin.php:302 +#: class-cc-post-republisher.php:81 msgid "The Public Domain Mark is recommended for works that are free of known copyright around the world. These will typically be very old works. It is not recommended for use with works that are in the public domain in some jurisdictions if they also known to be restricted by copyright in others." msgstr "" -#: class-cc-post-republisher-admin.php:335 -#: class-cc-post-republisher.php:92 -#: class-cc-post-republisher.php:93 +#: class-cc-post-republisher-admin.php:303 +#: class-cc-post-republisher.php:82 +#: class-cc-post-republisher.php:83 msgid "https://creativecommons.org/share-your-work/public-domain/pdm" msgstr "" -#: class-cc-post-republisher-admin.php:343 -#: class-cc-post-republisher-meta-box.php:32 +#: class-cc-post-republisher-admin.php:311 +#: class-cc-post-republisher-meta-box.php:28 msgid "Not Creative Commons Licensed" msgstr "" -#: class-cc-post-republisher-admin.php:346 +#: class-cc-post-republisher-admin.php:314 msgid "Defaults to non-licensed, allowing you to individually set licensing on posts." msgstr "" -#: class-cc-post-republisher-meta-box.php:23 +#: class-cc-post-republisher-meta-box.php:19 msgid "Default License" msgstr "" -#: class-cc-post-republisher-meta-box.php:24 +#: class-cc-post-republisher-meta-box.php:20 msgid "CC BY - Attribution" msgstr "" -#: class-cc-post-republisher-meta-box.php:25 +#: class-cc-post-republisher-meta-box.php:21 msgid "CC BY-SA - Attribution-ShareAlike" msgstr "" -#: class-cc-post-republisher-meta-box.php:26 +#: class-cc-post-republisher-meta-box.php:22 msgid "CC BY-ND - Attribution-NoDerivs" msgstr "" -#: class-cc-post-republisher-meta-box.php:27 +#: class-cc-post-republisher-meta-box.php:23 msgid "CC BY-NC - Attribution-NonCommercial" msgstr "" -#: class-cc-post-republisher-meta-box.php:28 +#: class-cc-post-republisher-meta-box.php:24 msgid "CC BY-NC-SA - Attribution-NonCommercial-ShareAlike" msgstr "" -#: class-cc-post-republisher-meta-box.php:29 +#: class-cc-post-republisher-meta-box.php:25 msgid "CC BY-NC-ND - Attribution-NonCommercial-NoDerivs" msgstr "" -#: class-cc-post-republisher-meta-box.php:30 +#: class-cc-post-republisher-meta-box.php:26 msgid "CC0 - No Rights Reserved" msgstr "" -#: class-cc-post-republisher-meta-box.php:31 +#: class-cc-post-republisher-meta-box.php:27 msgid "PDM - Public Domain Mark" msgstr "" #. translators: admin url -#: class-cc-post-republisher-meta-box.php:74 +#: class-cc-post-republisher-meta-box.php:72 msgid "Assign a license to this post. If no license is selected, the post will have the default license that is set in the Creative Commons Post Republisher Settings." msgstr "" -#: class-cc-post-republisher.php:81 +#: class-cc-post-republisher.php:71 msgid "CC0 1.0 Universal (CC0 1.0) Public Domain Dedication" msgstr "" -#: class-cc-post-republisher.php:83 +#: class-cc-post-republisher.php:73 msgid "https://creativecommons.org/publicdomain/zero/1.0/" msgstr "" -#: class-cc-post-republisher.php:89 +#: class-cc-post-republisher.php:79 msgid "Public Domain Mark \"No Known Copyright\"" msgstr "" - -#: class-cc-post-republisher.php:155 -msgid "Creative Commons License" -msgstr "" - -#: class-cc-post-republisher.php:159 -msgid "Republish" -msgstr "" diff --git a/license-block/block.js b/license-block/block.js new file mode 100644 index 0000000..eafb0a7 --- /dev/null +++ b/license-block/block.js @@ -0,0 +1,70 @@ +(function (blocks, element, editor, components) { + var el = element.createElement; + var RichText = editor.RichText; + + blocks.registerBlockType('cc/post-republisher', { + title: 'Creative Commons Post Republisher', + icon: 'admin-network', + category: 'common', + attributes: { + buttonText: { type: 'string', default: 'Republish' } + }, + edit: function (props) { + var attributes = props.attributes; + var setAttributes = props.setAttributes; + var activeLicense = blockSettings.activeLicense; + var activeLicenseImage = blockSettings.activeLicenseImage; + + var onChangeButtonText = function (newText) { + setAttributes({ buttonText: newText }); + }; + + return el('div', { className: 'components-placeholder' }, + el('div', { className: 'cc-description' }, 'The Post Republisher will display the globally set license by default, unless a license is chosen for a specific post/page.'), + el('div', { className: 'cc-global-license components-placeholder__label' }, + el('img', { src: activeLicenseImage, alt: 'License Image', style: { width: '88px', marginRight: '5px' } }), + 'Global License: ' + activeLicense + ), + el('div', { className: 'cc-republish-button' }, + el('button', { id: 'cc-post-republisher-modal-button-open', className: 'editable-button' }, + el('img', { src: activeLicenseImage, alt: 'License Image', style: { width: '88px', marginRight: '5px' } }), + el(RichText, { + tagName: 'span', + value: attributes.buttonText, + onChange: onChangeButtonText, + placeholder: 'Enter button text...' + }) + ) + ) + ); + }, + save: function (props) { + var attributes = props.attributes; + var activeLicenseImage = blockSettings.activeLicenseImage; + + return el('div', {}, + el('button', { + id: 'cc-post-republisher-modal-button-open', + }, + el('img', { src: activeLicenseImage, alt: 'License Image', style: { width: '88px', marginRight: '5px' } }), + el(RichText.Content, { + tagName: 'span', + value: attributes.buttonText + }) + ), + el('div', { + id: 'cc-post-republisher-modal-container' + }, + el('div', { + id: 'cc-post-republisher-modal' + }) + ) + ); + } + }); +})( + window.wp.blocks, + window.wp.element, + window.wp.editor, + window.wp.components +); diff --git a/license-block/modal.js b/license-block/modal.js new file mode 100644 index 0000000..1910c1d --- /dev/null +++ b/license-block/modal.js @@ -0,0 +1,70 @@ +jQuery(document).ready(function ($) { + $(document).on('click', '#cc-post-republisher-modal-button-open', function () { + var postId = wpApiSettings.postID; + var postType = wpApiSettings.postType; + + // Ensure postId is valid before making the AJAX request + if (postId) { + // Set the REST URL based on the post type (must be pluralized for posts and pages) + if (postType === 'post') { + postType = 'posts'; + } else if (postType === 'page') { + postType = 'pages'; + } + var postUrl = wpApiSettings.root + 'wp/v2/' + postType + '/' + postId; + + // AJAX request to get content + $.ajax({ + url: postUrl, + method: 'GET', + beforeSend: function (xhr) { + xhr.setRequestHeader('X-WP-Nonce', wpApiSettings.nonce); + }, + success: function (response) { + var modal = $('#cc-post-republisher-modal'); + var container = modal.closest('#cc-post-republisher-modal-container'); + + if (modal.length) { + var licenseContent = wpApiSettings.licenseContent; + var termsContent = wpApiSettings.termsContent; + + var content = ''; + content += termsContent; + content += licenseContent; + content += '
'; + content += ''; + content += '
'; + + modal.html(content); + container.css('display', 'block'); + } else { + console.error('Modal element not found'); + } + }, + error: function (error) { + console.error('AJAX error:', error); + } + }); + } else { + console.error('Post ID is not valid.'); + } + }); + + $(document).on('click', '#cc-post-republisher-modal-button-close', function () { + $('#cc-post-republisher-modal-container').css('display', 'none'); + }); + + // Close modal if clicking outside the modal + $(document).on('click', '#cc-post-republisher-modal-container', function (e) { + if ($(e.target).is('#cc-post-republisher-modal-container')) { + $(this).css('display', 'none'); + } + }); + + // Close modal if pressing the escape key + $(document).on('keydown', function (e) { + if (e.key === "Escape") { + $('#cc-post-republisher-modal-container').css('display', 'none'); + } + }); +});