Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add Tumblr, Multiple Email Types, Tooltips, and Prefix/Suffix Escape #61

Merged
merged 9 commits into from
Jan 7, 2023
1 change: 0 additions & 1 deletion dist/ThemeCustomizer.0.0.2.js

This file was deleted.

1 change: 1 addition & 0 deletions dist/ThemeCustomizer.0.0.3.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/has-admin-appearance.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/has-admin-emails.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions dist/has-admin-emails.js.LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/** @license URI.js v4.4.1 (c) 2011 Gary Court. License: http://github.com/garycourt/uri-js */
2 changes: 1 addition & 1 deletion dist/has-admin-settings.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/has-email-modal.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/has-themes.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/highlight-and-share.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions highlight-and-share.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Plugin URI: https://has.dlxplugins.com
* Description: Select text, inline highlight, or use a Click to Share block and show social networks.
* Author: DLX Plugins
* Version: 4.0.3
* Version: 4.0.5
* Requires at least: 5.1
* Requires PHP: 7.2
* Author URI: https://dlxplugins.com
Expand All @@ -17,7 +17,7 @@

namespace DLXPlugins\HAS;

define( 'HIGHLIGHT_AND_SHARE_VERSION', '4.0.3' );
define( 'HIGHLIGHT_AND_SHARE_VERSION', '4.0.5' );
define( 'HIGHLIGHT_AND_SHARE_FILE', __FILE__ );

// Support for site-level autoloading.
Expand Down
8 changes: 5 additions & 3 deletions php/Emails.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,12 @@ public function ajax_send_has_email() {
}
}

// Get email name and address from options.
$email_name = trim( sanitize_text_field( $options['from_name'] ) );
$email_from = trim( sanitize_text_field( $options['from_email'] ) );

// Set Email Variables.
$email_to = trim( sanitize_text_field( $ajax_data['toEmail'] ) );
$email_from = trim( sanitize_text_field( $ajax_data['fromEmail'] ) );
$email_name = trim( urldecode( $ajax_data['fromName'] ) );
$email_subject = trim( urldecode( $ajax_data['subject'] ) );
$email_selected_text = trim( urldecode( $ajax_data['shareText'] ) );

Expand Down Expand Up @@ -241,7 +243,7 @@ public function ajax_send_has_email() {
if ( $maybe_spam ) {
wp_send_json_error(
array(
'message' => _x( 'The email coult not be sent.', 'The email was flagged for spam.', 'highlight-and-share' ),
'message' => _x( 'The email could not be sent.', 'The email was flagged for spam.', 'highlight-and-share' ),
)
);
}
Expand Down
92 changes: 72 additions & 20 deletions php/Frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ public function wp_loaded() {
*/
$show_email = (bool) apply_filters( 'has_show_email', $settings['show_email'] ?? $settings['enable_emails'] );

/**
* Filter: has_show_tumblr
*
* Hide or show the Tumblr sharing option.
*
* @param bool true to show Tumblr, false to not.
*/
$show_tumblr = (bool) apply_filters( 'has_show_tumblr', $settings['show_tumblr'] );

/**
* Filter: has_show_copy
*
Expand Down Expand Up @@ -108,7 +117,7 @@ public function wp_loaded() {
$show_signal = false;

// If no social network is active, exit.
if ( ! $show_facebook && ! $show_twitter && ! $show_linkedin && ! $show_ok && ! $show_email && ! $show_copy && ! $show_reddit && ! $show_telegram && ! $show_whatsapp ) {
if ( ! $show_facebook && ! $show_twitter && ! $show_linkedin && ! $show_ok && ! $show_email && ! $show_copy && ! $show_reddit && ! $show_telegram && ! $show_whatsapp && ! $show_tumblr ) {
return;
}

Expand Down Expand Up @@ -220,6 +229,7 @@ public function add_footer_html() {
$social_networks_ordered = Options::get_plugin_options_social_networks(); // ordered social networks (appearances tab).
$theme_options = Options::get_theme_options(); // appearance options (appearances tab).
$settings = Options::get_plugin_options(); // main plugin options (settings tab).
$email_options = Options::get_email_options(); // email options (emails tab).

// Get HAS container classes.
$has_container_classes = array(
Expand All @@ -239,6 +249,18 @@ public function add_footer_html() {
$has_container_classes[] = 'hide-has-labels';
}

// Tooltip styles.
ob_start();
?>
<style>
.highlight-and-share-wrapper div.has-tooltip:hover:after {
background-color: <?php echo esc_attr( $theme_options['tooltips_background_color'] ); ?> !important;
color: <?php echo esc_attr( $theme_options['tooltips_text_color'] ); ?> !important;
}
</style>
<?php
$tooltip_styles = ob_get_clean();

// Get custom theme styles.
$custom_styles = false;
if ( 'custom' === $theme_options['theme'] ) {
Expand Down Expand Up @@ -336,6 +358,14 @@ public function add_footer_html() {
color: <?php echo esc_attr( $theme_options['icon_colors']['reddit']['icon_color_hover'] ); ?> !important;
background: <?php echo esc_attr( $theme_options['icon_colors']['reddit']['background_hover'] ); ?> !important;
}
.highlight-and-share-wrapper .has_tumblr a {
color: <?php echo esc_attr( $theme_options['icon_colors']['tumblr']['icon_color'] ); ?> !important;
background: <?php echo esc_attr( $theme_options['icon_colors']['tumblr']['background'] ); ?> !important;
}
.highlight-and-share-wrapper .has_tumblr a:hover {
color: <?php echo esc_attr( $theme_options['icon_colors']['tumblr']['icon_color_hover'] ); ?> !important;
background: <?php echo esc_attr( $theme_options['icon_colors']['tumblr']['background_hover'] ); ?> !important;
}
.highlight-and-share-wrapper .has_xing a {
color: <?php echo esc_attr( $theme_options['icon_colors']['xing']['icon_color'] ); ?> !important;
background: <?php echo esc_attr( $theme_options['icon_colors']['xing']['background'] ); ?> !important;
Expand Down Expand Up @@ -473,6 +503,9 @@ public function add_footer_html() {
if ( $custom_styles ) {
$html .= $custom_styles;
}
if ( $tooltip_styles ) {
$html .= $tooltip_styles;
}

// Loop through order and outout social network HTML.
foreach ( $social_networks_ordered as $social_network ) {
Expand All @@ -495,6 +528,10 @@ public function add_footer_html() {
case 'reddit':
$html .= '<div class="has_reddit ' . ( $theme_options['show_tooltips'] ? 'has-tooltip' : '' ) . '" style="display: none;" data-type="reddit" data-tooltip="' . esc_attr( apply_filters( 'has_reddit_tooltip', $settings['reddit_tooltip'] ) ) . '"><a href="https://www.reddit.com/submit?resubmit=true&url=%url%&title=%title%" target="_blank" rel="nofollow"><svg class="has-icon"><use xlink:href="#has-reddit-icon"></use></svg><span class="has-text">&nbsp;' . esc_html( apply_filters( 'has_reddit_text', $settings['reddit_label'] ) ) . '</span></a></div>';
break;
case 'tumblr':
// If "via" is blank, no username will show in Twitter.
$html .= '<div class="has_tumblr ' . ( $theme_options['show_tooltips'] ? 'has-tooltip' : '' ) . '" style="display: none;" data-type="tumblr" data-tooltip="' . esc_attr( apply_filters( 'has_tumblr_tooltip', $settings['tumblr_tooltip'] ) ) . '"><a href="https://tumblr.com/widgets/share/tool?canonicalUrl=%url%&content=%prefix%%text%%suffix%&title=%title%&posttype=quote" target="_blank" rel="nofollow"><svg class="has-icon"><use xlink:href="#has-tumblr"></use></svg><span class="has-text">&nbsp;' . esc_html( apply_filters( 'has_tumblr_text', $settings['tumblr_label'] ) ) . '</span></a></div>';
break;
case 'telegram':
$html .= '<div class="has_telegram ' . ( $theme_options['show_tooltips'] ? 'has-tooltip' : '' ) . '" style="display: none;" data-type="telegram" data-tooltip="' . esc_attr( apply_filters( 'has_telegram_tooltip', $settings['telegram_tooltip'] ) ) . '"><a href="https://t.me/share/url?url=%url%&text=%prefix%%text%%suffix%" target="_blank" rel="nofollow"><svg class="has-icon"><use xlink:href="#has-telegram-icon"></use></svg><span class="has-text">&nbsp;' . esc_html( apply_filters( 'has_telegram_text', $settings['telegram_label'] ) ) . '</span></a></div>';
break;
Expand Down Expand Up @@ -524,24 +561,38 @@ public function add_footer_html() {
break;
case 'email':
global $post;
$post_id = $post->ID ?? 0;
$ajax_nonce = wp_create_nonce( 'has_share_' . get_permalink( $post_id ) );
$ajax_url = admin_url( 'admin-ajax.php' );
$ajax_url = add_query_arg(
array(
'action' => 'has_email_social_modal',
'permalink' => '%url%',
'nonce' => $ajax_nonce,
'text' => '%prefix%%text%%suffix%',
'post_id' => $post_id,
'type' => '%type%',
),
$ajax_url
);
$html .= '<div class="has_email ' . ( $theme_options['show_tooltips'] ? 'has-tooltip' : '' ) . '" style="display: none;" data-type="email" data-title="%title%" data-url="%url%" data-tooltip="' . esc_attr( apply_filters( 'has_email_tooltip', $settings['email_tooltip'] ) ) . '"><a href="' . esc_url( $ajax_url ) . '" target="_blank" rel="nofollow"><svg class="has-icon"><use xlink:href="#has-email-icon"></use></svg><span class="has-text">&nbsp;' . esc_html( apply_filters( 'has_email_text', $settings['email_label'] ) ) . '</span></a></div>';
$post_id = $post->ID ?? 0;
$email_url = '';
$email_class = 'has_email_form';
if ( 'mailto' === $email_options['email_send_type'] ) {
$email_url = add_query_arg(
array(
'body' => '%prefix%%text%%suffix%',
'subject' => __( '[Shared Post]', 'highlight-and-share' ) . ' %title%',

),
'mailto:ronalfy@gmail.com'
);
$email_class = 'has_email_mailto';
} else {
$ajax_nonce = wp_create_nonce( 'has_share_' . get_permalink( $post_id ) );
$email_url = admin_url( 'admin-ajax.php' );
$email_url = add_query_arg(
array(
'action' => 'has_email_social_modal',
'permalink' => '%url%',
'nonce' => $ajax_nonce,
'text' => '%prefix%%text%%suffix%',
'post_id' => $post_id,
'type' => '%type%',
),
$email_url
);
}
$html .= '<div class="has_email ' . esc_attr( $email_class ) . ' ' . ( $theme_options['show_tooltips'] ? 'has-tooltip' : '' ) . '" style="display: none;" data-type="email" data-title="%title%" data-url="%url%" data-tooltip="' . esc_attr( apply_filters( 'has_email_tooltip', $settings['email_tooltip'] ) ) . '"><a href="' . esc_url( $email_url ) . '" target="_blank" rel="nofollow"><svg class="has-icon"><use xlink:href="#has-email-icon"></use></svg><span class="has-text">&nbsp;' . esc_html( apply_filters( 'has_email_text', $settings['email_label'] ) ) . '</span></a></div>';

// Enqueue the modal script.
if ( ! wp_script_is( 'fancybox', 'enqueued' ) ) {
if ( ! wp_script_is( 'fancybox', 'enqueued' ) && 'form' === $email_options['email_send_type'] ) {
wp_enqueue_script(
'fancybox',
Functions::get_plugin_url( '/js/fancybox.umd.js' ),
Expand Down Expand Up @@ -569,7 +620,7 @@ public function add_footer_html() {
$this->get_footer_svgs();

// Enqueue / print fancybox styles.
if ( wp_style_is( 'fancybox', 'registered' ) && ! wp_style_is( 'fancybox', 'done' ) ) {
if ( wp_style_is( 'fancybox', 'registered' ) && ! wp_style_is( 'fancybox', 'done' ) && 'form' === $email_options['email_send_type'] ) {
wp_print_styles( 'fancybox' );
}
}
Expand Down Expand Up @@ -634,6 +685,7 @@ private function get_footer_svgs() {
<path fill="currentColor" d="m 567.69877,-429.06912 c 3.15618,-10.38133 0,-18.0247 -15.11579,-18.0247 h -49.91013 c -12.70096,0 -18.55706,6.59763 -21.73232,13.87977 0,0 -25.38286,60.76685 -61.33724,100.25768 -11.63627,11.40806 -16.92197,15.05863 -23.27242,15.05863 -3.17519,0 -7.77644,-3.63156 -7.77644,-14.0319 v -97.13948 c 0,-12.47278 -3.68869,-18.0247 -14.26014,-18.0247 h -78.44923 c -7.92857,0 -12.70097,5.78005 -12.70097,11.27491 0,11.80736 17.98666,14.54527 19.83094,47.78071 v 72.21293 c 0,15.83815 -2.9091,18.70918 -9.25948,18.70918 -16.92197,0 -58.08598,-61.05206 -82.51817,-130.90731 -4.75337,-13.59458 -9.56381,-19.07042 -22.32175,-19.07042 h -49.92915 c -14.26014,0 -17.11213,6.59763 -17.11213,13.87977 0,12.96714 16.92197,77.38454 78.81059,162.58363 41.25909,58.18101 99.34506,89.72424 152.25931,89.72424 31.73343,0 35.65018,-6.99691 35.65018,-19.07043 v -43.978 c 0,-14.01288 3.00405,-16.80786 13.0622,-16.80786 7.41521,0 20.09716,3.65057 49.71998,31.69536 33.84387,33.25443 39.41486,48.16093 58.46622,48.16093 h 49.91026 c 14.26,0 21.40913,-6.99691 17.30216,-20.81966 -4.5252,-13.78473 -20.68653,-33.76783 -42.11468,-57.47752 -11.63621,-13.49953 -29.09043,-28.04479 -34.37631,-35.32694 -7.41508,-9.33557 -5.30458,-13.4995 0,-21.80835 0,0 60.80491,-84.15334 67.15549,-112.73048 z" />
</g>
</symbol>
<symbol aria-hidden="true" data-prefix="fab" data-icon="tumblr" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512" id="has-tumblr"><path fill="currentColor" d="M309.8 480.3c-13.6 14.5-50 31.7-97.4 31.7-120.8 0-147-88.8-147-140.6v-144H17.9c-5.5 0-10-4.5-10-10v-68c0-7.2 4.5-13.6 11.3-16 62-21.8 81.5-76 84.3-117.1.8-11 6.5-16.3 16.1-16.3h70.9c5.5 0 10 4.5 10 10v115.2h83c5.5 0 10 4.4 10 9.9v81.7c0 5.5-4.5 10-10 10h-83.4V360c0 34.2 23.7 53.6 68 35.8 4.8-1.9 9-3.2 12.7-2.2 3.5.9 5.8 3.4 7.4 7.9l22 64.3c1.8 5 3.3 10.6-.4 14.5z"></path></symbol>
</svg>
<?php
}
Expand Down Expand Up @@ -856,8 +908,8 @@ public function add_scripts() {
$json_arr['email_text'] = apply_filters( 'has_email_text', _x( 'E-mail', 'E-mail share text', 'highlight-and-share' ) );

// Load prefix and suffix (before/after text).
$json_arr['prefix'] = isset( $settings['sharing_prefix'] ) ? sanitize_text_field( $settings['sharing_prefix'] ) : '';
$json_arr['suffix'] = isset( $settings['sharing_suffix'] ) ? sanitize_text_field( $settings['sharing_suffix'] ) : '';
$json_arr['prefix'] = isset( $settings['sharing_prefix'] ) ? stripslashes_deep( sanitize_text_field( $settings['sharing_prefix'] ) ) : '';
$json_arr['suffix'] = isset( $settings['sharing_suffix'] ) ? stripslashes_deep( sanitize_text_field( $settings['sharing_suffix'] ) ) : '';

// Localize.
wp_localize_script( 'highlight-and-share', 'highlight_and_share', $json_arr );
Expand Down
61 changes: 43 additions & 18 deletions php/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public static function get_email_settings_defaults() {
'recaptcha_site_key' => '',
'recaptcha_secret_key' => '',
'recaptcha_score_threshold' => 0.5,
'from_name' => get_bloginfo( 'name' ),
'from_email' => get_bloginfo( 'admin_email' ),
'email_send_type' => 'form', /* can be form|mailto */
);
}

Expand Down Expand Up @@ -141,20 +144,28 @@ public static function get_social_network_defaults() {
'order' => 6,
'custom' => false,
),
'tumblr' => array(
'label' => __( 'Tumblr', 'highlight-and-share' ),
'slug' => 'tumblr',
'color' => '#000000',
'background' => '#fff',
'order' => 7,
'custom' => false,
),
'copy' => array(
'label' => __( 'Copy', 'highlight-and-share' ),
'slug' => 'copy',
'color' => '#000',
'background' => '#fff',
'order' => 7,
'order' => 8,
'custom' => false,
),
'email' => array(
'label' => __( 'Email', 'highlight-and-share' ),
'slug' => 'email',
'color' => '#000',
'background' => '#fff',
'order' => 8,
'order' => 9,
'custom' => false,
),
);
Expand Down Expand Up @@ -191,43 +202,45 @@ public static function get_block_editor_defaults() {
*/
public static function get_theme_defaults() {
$defaults = array(
'theme' => 'default',
'icons_only' => true, /* custom theme option */
'orientation' => 'horizontal',
'show_tooltips' => true,
'group_icons' => true, /* custom theme option */
'background_color' => '#000000', /* only applicable if icons are grouped */
'background_color_hover' => '#333333', /* only applicable if icons are grouped */
'icon_colors_group' => '#FFFFFF', /* only applicable if icons are grouped */
'icon_colors_group_hover' => '#FFFFFF', /* only applicable if icons are grouped */
'border_radius_group' => array( /* only applicable if icons are grouped */
'theme' => 'default',
'icons_only' => true, /* custom theme option */
'orientation' => 'horizontal',
'show_tooltips' => true,
'tooltips_text_color' => '#FFFFFF',
'tooltips_background_color' => '#000000',
'group_icons' => true, /* custom theme option */
'background_color' => '#000000', /* only applicable if icons are grouped */
'background_color_hover' => '#333333', /* only applicable if icons are grouped */
'icon_colors_group' => '#FFFFFF', /* only applicable if icons are grouped */
'icon_colors_group_hover' => '#FFFFFF', /* only applicable if icons are grouped */
'border_radius_group' => array( /* only applicable if icons are grouped */
'attrTop' => 0,
'attrRight' => 0,
'attrBottom' => 0,
'attrLeft' => 0,
'attrUnit' => 'px',
'attrSyncUnits' => false,
),
'icon_border_radius' => array( /* only applicable if icons are NOT grouped */
'icon_border_radius' => array( /* only applicable if icons are NOT grouped */
'attrTop' => 0,
'attrRight' => 0,
'attrBottom' => 0,
'attrLeft' => 0,
'attrUnit' => 'px',
'attrSyncUnits' => false,
),
'font_size' => 14,
'icon_padding' => array( /* Applicable to grouped and ungrouped icons */
'font_size' => 14,
'icon_padding' => array( /* Applicable to grouped and ungrouped icons */
'attrTop' => 12,
'attrRight' => 20,
'attrBottom' => 12,
'attrLeft' => 20,
'attrUnit' => 'px',
'attrSyncUnits' => false,
),
'icon_size' => 25, /* Applicable to grouped and ungrouped icons */
'icon_gap' => 0, /* Applicable to ungrouped icons */
'icon_colors' => array( /* Social Icon Colors */
'icon_size' => 25, /* Applicable to grouped and ungrouped icons */
'icon_gap' => 0, /* Applicable to ungrouped icons */
'icon_colors' => array( /* Social Icon Colors */
'twitter' => array(
'label' => __( 'Twitter', 'highlight-and-share' ),
'slug' => 'twitter',
Expand Down Expand Up @@ -268,6 +281,14 @@ public static function get_theme_defaults() {
'icon_color' => '#fff',
'icon_color_hover' => '#fff',
),
'tumblr' => array(
'label' => __( 'Tumblr', 'highlight-and-share' ),
'slug' => 'tumblr',
'background' => '#000000',
'background_hover' => '#333333',
'icon_color' => '#fff',
'icon_color_hover' => '#fff',
),
'linkedin' => array(
'label' => __( 'LinkedIn', 'highlight-and-share' ),
'slug' => 'linkedin',
Expand Down Expand Up @@ -326,6 +347,7 @@ public static function get_defaults() {
'enable_mobile' => true,
'show_reddit' => false,
'show_telegram' => false,
'show_tumblr' => false,
'show_signal' => false,
'enable_content' => true,
'enable_excerpt' => true,
Expand Down Expand Up @@ -360,6 +382,8 @@ public static function get_defaults() {
'copy_tooltip' => __( 'Copy Selection', 'highlight-and-share' ),
'email_label' => __( 'Email', 'highlight-and-share' ),
'email_tooltip' => __( 'Share via email', 'highlight-and-share' ),
'tumblr_label' => __( 'Tumblr', 'highlight-and-share' ),
'tumblr_tooltip' => __( 'Share on Tumblr', 'highlight-and-share' ),
);
return $defaults;
}
Expand Down Expand Up @@ -475,6 +499,7 @@ public static function get_plugin_options_social_networks( $force = false ) {
$settings['whatsapp']['enabled'] = (bool) apply_filters( 'has_show_whatsapp', ( $plugin_options['show_whats_app'] ?? false ) );
$settings['xing']['enabled'] = (bool) apply_filters( 'has_show_xing', ( $plugin_options['show_xing'] ?? false ) );
$settings['reddit']['enabled'] = (bool) apply_filters( 'has_show_reddit', ( $plugin_options['show_reddit'] ?? false ) );
$settings['tumblr']['enabled'] = (bool) apply_filters( 'has_show_tumblr', ( $plugin_options['show_tumblr'] ?? false ) );
$settings['telegram']['enabled'] = (bool) apply_filters( 'has_show_telegram', ( $plugin_options['show_telegram'] ?? false ) );

// Now sort the arrays based on order.
Expand Down
Loading