Plugin Directory

Changeset 1809716


Ignore:
Timestamp:
01/26/2018 01:00:17 AM (8 years ago)
Author:
DevonOstendorf
Message:

Code comprising all fixes, functionality, and improvements for v1.1.0

  • README.txt:
  • Updated Tested up to tag to 4.9


  • Added Requires PHP tag (set to 5.6)
  • Added description of shortcode functionality, in Description section


  • Revised FAQ items, concerning translation and open source analytics, to make current


  • Supplemented FAQ section to explain various aspects of shortcode use
  • admin/class-local-like-and-share-admin.php:
  • Modified add_local_like_and_share_admin_menu() function, passing 'dashicons-heart' as icon_url parameter, to add_menu_page() call
  • admin/views/local-like-and-share-admin-display-options.php:
  • Removed question mark from "Show on individual post?" field label in Share Settings section, to match corresponding field label in Like Settings section (NO functionality change)


  • includes/class-local-like-and-share.php:


  • Modified define_public_hooks() function, adding action to register Like and Share shortcodes and renaming callback functions for localization of button handler scripts


  • languages/local-like-and-share.pot:
  • Revised source translation text file to contain complete set of Local Like And Share's translatable strings up through v1.1.0


  • public/class-local-like-and-share-public.php:
  • Modified enqueue_styles() function, replacing configurable styling code with call to new define_configurable_css() function
  • Added new define_configurable_css() function


  • Added new register_shortcodes() function


  • Added new render_shortcode_button() function
  • Added new override_configured_css() function
  • Modified add_like_and_share_buttons_to_content() function, preventing Like and Share buttons from displaying on search results pages, since, depending on positioning settings, buttons may not render properly. With shortcodes now available, admins can instead place buttons directly into their search page template.


  • Modified add_like_button_to_content() function, adding $id parameter and updating Like button creation code to use it to uniquely assign Like buttons, allowing for greater control over button positioning. Renamed HTML element IDs to prevent naming clashes with other plugins' elements. Replaced divs with spans, for Like buttons, to allow shortcode-generated Like buttons to be dropped in the middle of post/page body. Replaced multiple calls to get_the_ID() (WordPress core) function with a single call, assigned to a variable, and then referenced throughout, to improve performance.


  • Modified add_share_button_to_content() function, adding $id parameter and updating Share button creation code to use it to uniquely assign Share buttons, allowing for greater control over button positioning. Renamed HTML element IDs to prevent naming clashes with other plugins' elements. Replaced divs with spans, for Share buttons, to allow shortcode-generated Share buttons to be dropped in the middle of post/page body. Replaced multiple calls to get_the_ID() (WordPress core) function with a single call, assigned to a variable, and then referenced throughout, to improve performance.


  • Renamed like_button_clicked_enqueue() function to localize_like_button_handler_script to more accurately reflect its purpose
  • Modified like_button_clicked_ajax_handler() function, removing obsolete assignment of $button_num variable and updating wp_send_json() call to reference $post_id instead. Renamed HTML element IDs to prevent naming clashes with other plugins' elements.


  • Renamed share_button_clicked_enqueue() function to localize_share_button_handler_script to more accurately reflect its purpose


  • public/css/local-like-and-share-shortcode.css:
  • New (blank) file used as attachment point for wp_add_inline_style() function call


  • public/js/local-like-and-share-public.js:
  • Modified AJAX callback function, triggered when a Like button is pressed, to handle (potentially) multiple like buttons for a specific post or page


  • public/js/local-like-and-share-public.min.js:


  • Updated JavaScript file containing minified local-like-and-share-public.js code
Location:
local-like-and-share/trunk
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • local-like-and-share/trunk/README.txt

    r1527830 r1809716  
    44Tags: like, share, local, self-hosted, standalone, track like, track share
    55Requires at least: 4.3
    6 Tested up to: 4.6
     6Tested up to: 4.9
     7Requires PHP: 5.6
    78Stable tag: 1.0.6
    89License: GPLv2 or later
     
    4445    * No shares found
    4546   
     47* Versatile shortcode functionality:
     48    * Generate like button directly in content
     49    * Generate share button directly in content
     50    * Usable in posts and on pages
     51   
    4652* Configurable widget labels/input field placeholders:
    4753    * Show like section?
     
    105111= Why isn't Local Like And Share translated into my language? =
    106112
    107 It is because no one who speaks your language has translated this plugin yet.  If you'd like to do so, you'll find the current local-like-and-share.pot file in the local-like-and-share/languages directory.  [Please contact me](https://devonostendorf.com) with any translation files you create - thanks much!
     113It is because no one who speaks your language has translated this plugin yet.  If you'd like to do so, you'll find the current local-like-and-share.pot file in the local-like-and-share/languages directory.  [Please contact me](https://devonostendorf.com) with any translation files you create; I will help you get set up as a Project Translation Editor (PTE) with the WordPress.org [Polyglots team](https://make.wordpress.org/polyglots/) to create a language pack for Local Like And Share - thanks much!
    108114
    109115= Why build another like and share plugin? =
    110116
    111 This was a somewhat spontaneous project; I wanted to add an easy-to-set-up way to allow likes and shares without requiring the user to sign into some other service.  And lots of people choose not to use Facebook or Twitter.  If you do, there are plenty of other plugins available.  There are also other existing plugins that provide similar functionality but require you to maintain an account on their server(s) to access statistics.  My aim was to provide a simple, self-contained, and locally-hosted tool where your stats stay with you (in the same way that the excellent [Piwik](http://piwik.org) does for analytics).  All while being independent from and unaffected by the whims of outside organizations that may change things without your knowledge or permission.
     117This was a somewhat spontaneous project; I wanted to add an easy-to-set-up way to allow likes and shares without requiring the user to sign into some other service.  And lots of people choose not to use Facebook or Twitter.  If you do, there are plenty of other plugins available.  There are also other existing plugins that provide similar functionality but require you to maintain an account on their server(s) to access statistics.  My aim was to provide a simple, self-contained, and locally-hosted tool where your stats stay with you (in the same way that the excellent [Matomo](https://matomo.org) does for analytics).  All while being independent from and unaffected by the whims of outside organizations that may change things without your knowledge or permission.
    112118
    113119= How do I reset like or share counts? =
    114120
    115121Go to the View Statistics page (Local Like And Share >> View Statistics), select the "All-time" tab, and press either the "Reset all like counts" or "Reset all share counts" button.  This will reset ALL of your likes or shares (depending on which button you press).  You will be presented with an "Undo" link immediately after having pressed a delete button.  If you pressed a delete button by accident, or change your mind about deleting your counts, you must click the undo link IMMEDIATELY; your action CANNOT be reversed later.
     122
     123= How do I use the shortcodes? =
     124
     1251. Go to Settings >> Local Like And Share and make sure the settings in the Common Settings, Like Settings, and Share Settings sections are populated to your liking   
     126<br /><br /> 
     127
     128    **Note**: "Button(s) position on post", "Show on post index pages", and "Show on individual post" are not relevant to the shortcodes.   
     129<br /><br /> 
     130
     1312. Add `[llas_like]` or `[llas_share]` to a post or page   
     132<br /><br /> 
     133
     1343. If you use either shortcode more than once in a post or on a page, you MUST specify a unique value for the `id` attribute
     135
     136    Here is an example, passing the id attribute:   
     137   
     138    Somewhere in the middle of a post, we drop a like button.
     139    <pre>[llas_like id="1"]</pre>
     140    It is fine to reuse the same id for a share button.
     141    <pre>[llas_share id="1"]</pre>
     142    But we need to make the like button ids unique and here is a second one.
     143    <pre>[llas_like id="2"]</pre>
     144    And the second share button id must also be unique (among share buttons).
     145    <pre>[llas_share id="2"]</pre>
     146    That's all there is to it!
    116147
    117148== Screenshots ==
  • local-like-and-share/trunk/admin/class-local-like-and-share-admin.php

    r1499267 r1809716  
    263263            ,'local-like-and-share-menu'
    264264            ,null
    265             ,''
     265            ,'dashicons-heart'
    266266            ,$local_like_and_share_options_arr['admin_menu_position']
    267267        );
  • local-like-and-share/trunk/admin/views/local-like-and-share-admin-display-options.php

    r1500010 r1809716  
    216216                    <tr valign="top">
    217217                        <th scope="row">
    218                             <?php esc_html_e( 'Show on individual post?:', 'local-like-and-share' ); ?>
     218                            <?php esc_html_e( 'Show on individual post:', 'local-like-and-share' ); ?>
    219219                        </th>
    220220                        <td>
  • local-like-and-share/trunk/includes/class-local-like-and-share.php

    r1527830 r1809716  
    221221        $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
    222222
     223        // Register Like and Share shortcodes
     224        $this->loader->add_action( 'init', $plugin_public, 'register_shortcodes' );
     225
    223226        // Display Like and Share buttons on posts
    224227        $this->loader->add_filter( 'the_content', $plugin_public, 'add_like_and_share_buttons_to_content' );
    225228
    226229        // Like button functionality
    227         $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'like_button_clicked_enqueue' );
     230        $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'localize_like_button_handler_script' );
    228231        $this->loader->add_action( 'wp_ajax_like_button_clicked', $plugin_public, 'like_button_clicked_ajax_handler' );
    229232        $this->loader->add_action( 'wp_ajax_nopriv_like_button_clicked', $plugin_public, 'like_button_clicked_ajax_handler' );
    230233
    231234        // Share button functionality
    232         $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'share_button_clicked_enqueue' );
     235        $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'localize_share_button_handler_script' );
    233236        $this->loader->add_action( 'wp_ajax_share_button_clicked', $plugin_public, 'share_button_clicked_ajax_handler' );
    234237        $this->loader->add_action( 'wp_ajax_nopriv_share_button_clicked', $plugin_public, 'share_button_clicked_ajax_handler' );
  • local-like-and-share/trunk/languages/local-like-and-share.pot

    r1527830 r1809716  
    1 # Copyright (C) 2016 Local Like And Share
     1# Copyright (C) 2018 Local Like And Share
    22# This file is distributed under the same license as the Local Like And Share package.
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Local Like And Share 1.0.6\n"
     5"Project-Id-Version: Local Like And Share 1.1.0\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/local-like-and-"
    77"share\n"
    8 "POT-Creation-Date: 2016-11-03 15:12:15+00:00\n"
     8"POT-Creation-Date: 2018-01-25 21:43:49+00:00\n"
    99"MIME-Version: 1.0\n"
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "PO-Revision-Date: 2016-MO-DA HO:MI+ZONE\n"
     12"PO-Revision-Date: 2018-MO-DA HO:MI+ZONE\n"
    1313"Last-Translator: Devon Ostendorf <[email protected]>\n"
    1414"Language-Team: Devon Ostendorf <[email protected]>\n"
     
    154154
    155155#: admin/views/local-like-and-share-admin-display-options.php:131
     156#: admin/views/local-like-and-share-admin-display-options.php:218
    156157msgid "Show on individual post:"
    157158msgstr ""
     
    186187#: admin/views/local-like-and-share-admin-display-options.php:198
    187188msgid "Share Settings"
    188 msgstr ""
    189 
    190 #: admin/views/local-like-and-share-admin-display-options.php:218
    191 msgid "Show on individual post?:"
    192189msgstr ""
    193190
  • local-like-and-share/trunk/public/class-local-like-and-share-public.php

    r1500010 r1809716  
    7575        wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/local-like-and-share-public.min.css', array(), $this->version, 'all' );
    7676
    77         // Define all configurable styling here (everything else is in .css file)
    78        
    79         $local_like_and_share_options_arr = get_option( 'local_like_and_share_settings' );
    80 
    81         $btn_hover_message_background_color = $local_like_and_share_options_arr['btn_hover_message_background_color'];
    82         $btn_hover_message_text_color = $local_like_and_share_options_arr['btn_hover_message_text_color'];
    83 
    84         $count_background_color = $local_like_and_share_options_arr['count_background_color'];
    85         $count_outline_color = $local_like_and_share_options_arr['count_outline_color'];
    86         $count_text_color = $local_like_and_share_options_arr['count_text_color'];
    87    
    88         $like_button_color = $local_like_and_share_options_arr['like_btn_color'];
    89         $like_button_hover_color = $local_like_and_share_options_arr['like_btn_hover_color'];
    90 
    91         $share_button_color = $local_like_and_share_options_arr['share_btn_color'];
    92         $share_button_hover_color = $local_like_and_share_options_arr['share_btn_hover_color'];
    93        
    94         if ( 'left' == $local_like_and_share_options_arr['button_posn_horiz'] ) {
    95        
    96             // Position button to left of post
    97             $button_posn = 'float:left;margin:0px 10px 10px 0px';
    98         }
    99         else {
    100            
    101             // Position button to right of post
    102             $button_posn = 'float:right;margin:0px 0px 10px 10px';
    103         }
    104 
    105         $llas_buttons_style = '
    106             .llas-like-button-active {
    107                 ' . $button_posn . ';           
    108             }
    109             .llas-like-button-active i {
    110                 cursor: pointer;
    111                 cursor: hand;
    112             }
    113             .llas-like-button-active a,
    114             .llas-like-button-active a:visited,
    115             .llas-like-button-active a:focus {
    116                 color: ' . esc_html( $like_button_color ) . ';
    117             }
    118             .llas-like-button-active a:hover {
    119                 color: ' . esc_html( $like_button_hover_color ) . ';
    120             }
    121             .llas-like-button-inactive {
    122                 ' . $button_posn . ';           
    123             }
    124             .llas-like-button-inactive a,
    125             .llas-like-button-inactive a:visited,
    126             .llas-like-button-inactive a:focus,
    127             .llas-like-button-inactive a:hover {
    128                 color: ' . esc_html( $like_button_color ) . ';
    129             }
    130 
    131             .llas-share-button-active {
    132                 ' . $button_posn . ';           
    133             }
    134             .llas-share-button-active i {
    135                 cursor: pointer;
    136                 cursor: hand;
    137             }
    138             .llas-share-button-active a,
    139             .llas-share-button-active a:visited,
    140             .llas-share-button-active a:focus {
    141                 color: ' . esc_html( $share_button_color ) . ';
    142             }
    143             .llas-share-button-active a:hover {
    144                 color: ' . esc_html( $share_button_hover_color ) . ';
    145             }
    146 
    147             .llas-callout {
    148                 background-color: ' . esc_html( $count_background_color ) . ';
    149                 color: ' . esc_html( $count_text_color ) . ';
    150             }
    151             .llas-callout .llas-notch {
    152                 border-right: 5px solid ' . esc_html( $count_background_color ). ';     
    153             }
    154             .llas-border-callout {
    155                 border: 1px solid ' . esc_html( $count_outline_color ) . ';
    156                 padding: 2px 9px;
    157             }
    158             .llas-border-callout .llas-border-notch {
    159                 border-right-color: ' . esc_html( $count_outline_color ) . ';
    160                 left: -6px;
    161             }   
    162            
    163             .tipsy-inner {
    164                 background-color: ' . esc_html( $btn_hover_message_background_color ) . ';
    165                 color: ' . esc_html( $btn_hover_message_text_color ) . ';
    166                 max-width: 200px;
    167                 padding: 5px 8px 4px 8px;
    168                 text-align: center;
    169                 font-size: 13px;
    170             }
    171             .tipsy-arrow-n {
    172                 border-bottom-color: ' . esc_html( $btn_hover_message_background_color ) . ';
    173             }
    174         ';
    175         wp_add_inline_style( $this->plugin_name, $llas_buttons_style );
     77        // Define all configurable styling
     78        $this->define_configurable_css();
    17679
    17780    }
     
    198101    }
    199102
     103    /**
     104     * Define CSS based on configured settings.
     105     *
     106     * @since   1.1.0
     107     * @access  private
     108     */
     109    private function define_configurable_css() {
     110               
     111        // Define all configurable styling here (everything else is in .css file)
     112       
     113        $local_like_and_share_options_arr = get_option( 'local_like_and_share_settings' );
     114
     115        $btn_hover_message_background_color = $local_like_and_share_options_arr['btn_hover_message_background_color'];
     116        $btn_hover_message_text_color = $local_like_and_share_options_arr['btn_hover_message_text_color'];
     117
     118        $count_background_color = $local_like_and_share_options_arr['count_background_color'];
     119        $count_outline_color = $local_like_and_share_options_arr['count_outline_color'];
     120        $count_text_color = $local_like_and_share_options_arr['count_text_color'];
     121   
     122        $like_button_color = $local_like_and_share_options_arr['like_btn_color'];
     123        $like_button_hover_color = $local_like_and_share_options_arr['like_btn_hover_color'];
     124
     125        $share_button_color = $local_like_and_share_options_arr['share_btn_color'];
     126        $share_button_hover_color = $local_like_and_share_options_arr['share_btn_hover_color'];
     127       
     128        if ( 'left' == $local_like_and_share_options_arr['button_posn_horiz'] ) {
     129       
     130            // Position button to left of post
     131            $button_posn = 'float:left;margin:0px 10px 10px 0px';
     132        }
     133        else {
     134           
     135            // Position button to right of post
     136            $button_posn = 'float:right;margin:0px 0px 10px 10px';
     137        }
     138
     139        $llas_buttons_style = '
     140            .llas-like-button-active {
     141                ' . $button_posn . ';           
     142            }
     143            .llas-like-button-active i {
     144                cursor: pointer;
     145                cursor: hand;
     146            }
     147            .llas-like-button-active a,
     148            .llas-like-button-active a:visited,
     149            .llas-like-button-active a:focus {
     150                color: ' . esc_html( $like_button_color ) . ';
     151            }
     152            .llas-like-button-active a:hover {
     153                color: ' . esc_html( $like_button_hover_color ) . ';
     154            }
     155            .llas-like-button-inactive {
     156                ' . $button_posn . ';           
     157            }
     158            .llas-like-button-inactive a,
     159            .llas-like-button-inactive a:visited,
     160            .llas-like-button-inactive a:focus,
     161            .llas-like-button-inactive a:hover {
     162                color: ' . esc_html( $like_button_color ) . ';
     163            }
     164
     165            .llas-share-button-active {
     166                ' . $button_posn . ';           
     167            }
     168            .llas-share-button-active i {
     169                cursor: pointer;
     170                cursor: hand;
     171            }
     172            .llas-share-button-active a,
     173            .llas-share-button-active a:visited,
     174            .llas-share-button-active a:focus {
     175                color: ' . esc_html( $share_button_color ) . ';
     176            }
     177            .llas-share-button-active a:hover {
     178                color: ' . esc_html( $share_button_hover_color ) . ';
     179            }
     180
     181            .llas-callout {
     182                background-color: ' . esc_html( $count_background_color ) . ';
     183                color: ' . esc_html( $count_text_color ) . ';
     184            }
     185            .llas-callout .llas-notch {
     186                border-right: 5px solid ' . esc_html( $count_background_color ). ';     
     187            }
     188            .llas-border-callout {
     189                border: 1px solid ' . esc_html( $count_outline_color ) . ';
     190                padding: 2px 9px;
     191            }
     192            .llas-border-callout .llas-border-notch {
     193                border-right-color: ' . esc_html( $count_outline_color ) . ';
     194                left: -6px;
     195            }   
     196           
     197            .tipsy-inner {
     198                background-color: ' . esc_html( $btn_hover_message_background_color ) . ';
     199                color: ' . esc_html( $btn_hover_message_text_color ) . ';
     200                max-width: 200px;
     201                padding: 5px 8px 4px 8px;
     202                text-align: center;
     203                font-size: 13px;
     204            }
     205            .tipsy-arrow-n {
     206                border-bottom-color: ' . esc_html( $btn_hover_message_background_color ) . ';
     207            }
     208        ';
     209        wp_add_inline_style( $this->plugin_name, $llas_buttons_style );
     210       
     211    }
     212
     213   
     214    // Functions related to like and share button shortcodes
     215   
     216    /**
     217     * Register shortcodes to render Like and Share buttons directly in
     218     *  post/page content.
     219     *
     220     * @since   1.1.0
     221     */
     222    public function register_shortcodes() {
     223       
     224        add_shortcode( 'llas_like', array( $this, 'render_shortcode_button' ) );
     225        add_shortcode( 'llas_share', array( $this, 'render_shortcode_button' ) );
     226       
     227    }
     228
     229    /**
     230     * Render shortcode-generated button.
     231     *
     232     * @since   1.1.0
     233     * @param   array   $atts   An associative array of attributes, or an empty string if no attributes are given.
     234     * @param   string  $content    The enclosed content (if the shortcode is used in its enclosing form).
     235     * @param   string  $tag    The shortcode name.
     236     * @return  string  The HTML to render Like or Share button.
     237     */
     238    public function render_shortcode_button( $atts, $content = null, $tag ) {
     239
     240        $type = substr( $tag, 5 );
     241       
     242        $clean_atts = shortcode_atts(
     243            array(
     244                'id' => '1'
     245            )
     246            ,$atts
     247            ,$tag
     248        );
     249       
     250        $this->override_configured_css( $type, $clean_atts );
     251
     252        $button_method = "add_{$type}_button_to_content";
     253        if ( method_exists( $this, $button_method ) ) {
     254           
     255            return $this->$button_method( $clean_atts['id'] );
     256           
     257        }
     258               
     259    }
     260   
     261    /**
     262     * Override configured CSS for specific shortcode-generated button, allowing
     263     *  for its display directly in post/page content.
     264     *
     265     * @since   1.1.0
     266     * @access  private
     267     * @param   string  $type   Type of shortcode ("like" or "share").
     268     * @param   array   $atts   An associative array of attributes, or an empty string if no attributes are given.
     269     */
     270    private function override_configured_css( $type, $atts ) {
     271
     272        global $post;
     273
     274        $post_id = get_the_ID();
     275
     276        // NOTE: This is a blank stylesheet, merely used as an attachment point for wp_add_inline_style()
     277        wp_enqueue_style( $this->plugin_name . '-shortcode', plugin_dir_url( __FILE__ ) . 'css/local-like-and-share-shortcode.css', array(), $this->version, 'all' );
     278       
     279       $llas_buttons_style = '
     280            #id_llas_spn_' . $type . '_button_' . $post_id . '_' . $atts['id'] . ' {
     281                float: none;           
     282            }
     283        ';
     284       
     285        wp_add_inline_style( $this->plugin_name.'-shortcode', $llas_buttons_style );
     286   
     287   }
     288   
    200289   
    201290    // Functions related to display of like and share buttons and (AJAX) handling of
     
    212301
    213302        global $post;
    214 
     303       
    215304        // Only show buttons on published posts
    216         if ( ( 'post' != $post->post_type ) || ( 'publish' != $post->post_status ) ) {
     305        if ( ( 'post' != $post->post_type ) || ( 'publish' != $post->post_status ) || ( is_search() ) ) {
    217306           
    218307            return $content;
     
    258347            $content = $buttons_html . '<br />' .  $content;
    259348        }           
    260                
     349           
    261350        return $content;
    262351       
     
    306395     * @since   1.0.0
    307396     * @access  private
     397     * @param   string  $id Shortcode ID.
    308398     * @return  string  The Like button HTML.
    309399     */
    310     private function add_like_button_to_content() {
     400    private function add_like_button_to_content( $id = 'classic' ) {
    311401
    312402        global $post;
    313403        global $wpdb;
    314404       
     405        $post_id = get_the_ID();
     406       
    315407        $local_like_and_share_options_arr = get_option( 'local_like_and_share_settings' );
    316408
    317409        // Get like total for specific post from post meta data
    318         $like_total = get_post_meta( get_the_ID(), 'local_like_and_share_like_total', true );
     410        $like_total = get_post_meta( $post_id, 'local_like_and_share_like_total', true );
    319411        if ( empty( $like_total ) ) {
    320412            $like_total = 0;
     
    324416       
    325417        $like_count_span =
    326             '<span id="id_spnLikeCount" class="llas-callout llas-border-callout">'
     418            '<span id="id_llas_spn_like_count_' . $post_id . '_' . $id . '" class="llas-callout llas-border-callout">'
    327419            . Local_Like_And_Share_Misc::format_count_display( $like_total )
    328420            . '<b class="llas-border-notch llas-notch"></b>'
     
    331423        ;
    332424       
    333         $user_already_liked = $this->current_user_already_liked_post( $this->get_current_user_identifier(), get_the_ID() );
     425        $user_already_liked = $this->current_user_already_liked_post( $this->get_current_user_identifier(), $post_id );
    334426        if ( $user_already_liked ) {
    335427                     
     
    337429            $button_link = '<a id="id_dummy" rel="tipsy" title="' . esc_attr( $local_like_and_share_options_arr['like_btn_hover_info_message_already_liked'] ) . '">';
    338430
    339             $like_button = '<div class="llas-like-button-inactive">'
     431            $like_button = '<span class="llas-like-button-inactive" id="id_llas_spn_like_button_' . $post_id . '_' . $id . '">'
    340432                . $button_link
    341433                . $button_icon
    342434                . '</a>'
    343435                . $like_count_span
    344                 . '</div>'
     436                . '</span>'
    345437            ;
    346438
     
    349441
    350442            // Current user/visitor has NOT yet liked this post
    351             $button_link = '<a class="like_button" id="id_lnkLikeButton_' . get_the_ID() . '" data-post-id="' . get_the_ID() . '" rel="tipsy" title="' . esc_attr( $local_like_and_share_options_arr['like_btn_hover_call_to_action'] ) . '">';
    352 
    353             $like_button = '<div class="llas-like-button-active" id="id_divLikeButton_' . get_the_ID() . '">'
     443            $button_link = '<a class="like_button" id="id_llas_lnk_like_button_' . $post_id . '_' . $id . '" data-post-id="' . $post_id . '" rel="tipsy" title="' . esc_attr( $local_like_and_share_options_arr['like_btn_hover_call_to_action'] ) . '">';
     444
     445            $like_button = '<span class="llas-like-button-active" id="id_llas_spn_like_button_' . $post_id . '_' . $id . '">'
    354446                . $button_link
    355447                . $button_icon
    356448                . '</a>'
    357449                . $like_count_span
    358                 . '</div>'
     450                . '</span>'
    359451            ;
    360452
     
    432524     * @since   1.0.0
    433525     * @access  private
     526     * @param   string  $id Shortcode ID.
    434527     * @return  string  The Share button HTML.
    435528     */
    436     private function add_share_button_to_content() {
     529    private function add_share_button_to_content( $id = 'classic' ) {
    437530       
    438531        global $post;
    439532        global $wpdb;
    440533       
     534        $post_id = get_the_ID();
     535       
    441536        $local_like_and_share_options_arr = get_option( 'local_like_and_share_settings' );
    442537
    443538        // Get share total for specific post from post meta data
    444         $share_total = get_post_meta( get_the_ID(), 'local_like_and_share_share_total', true );
     539        $share_total = get_post_meta( $post_id, 'local_like_and_share_share_total', true );
    445540        if ( empty( $share_total ) ) {
    446541            $share_total = 0;
     
    450545       
    451546        $share_count_span =
    452             '<span id="id_spnShareCount" class="llas-callout llas-border-callout">'
     547            '<span id="id_llas_spn_share_count" class="llas-callout llas-border-callout">'
    453548            . Local_Like_And_Share_Misc::format_count_display( $share_total )
    454549            . '<b class="llas-border-notch llas-notch"></b>'
     
    462557        // Replace variables in both the share post email subject and body
    463558           
    464         $post_attribs = get_post( get_the_ID() );
     559        $post_attribs = get_post( $post_id );
    465560        $post_title = $post_attribs->post_title;
    466         $post_permalink = get_permalink( get_the_ID() );
     561        $post_permalink = get_permalink( $post_id );
    467562
    468563        $share_email_subject = $local_like_and_share_options_arr['share_eml_subj'];
     
    482577            . '&body=' . esc_attr( $share_email_body )
    483578            . '" '
    484             . 'id="id_lnkShareButton_' . get_the_ID() . '" data-post-id="' . get_the_ID() . '" rel="tipsy" title="' . esc_attr( $local_like_and_share_options_arr['share_btn_hover_call_to_action'] ) . '">';
    485 
    486         $share_button = '<div class="llas-share-button-active" id="id_divShareButton_' . get_the_ID() . '">'
     579            . 'id="id_llas_lnk_share_button_' . $post_id . '_' . $id . '" data-post-id="' . $post_id . '" rel="tipsy" title="' . esc_attr( $local_like_and_share_options_arr['share_btn_hover_call_to_action'] ) . '">';
     580
     581        $share_button = '<span class="llas-share-button-active" id="id_llas_spn_share_button_' . $post_id . '_' . $id . '">'
    487582            . $button_link
    488583            . $button_icon
    489584            . '</a>'
    490585            . $share_count_span
    491             . '</div>'
     586            . '</span>'
    492587        ;
    493588
     
    495590           
    496591    }           
    497    
    498     /**
    499      * Enqueue AJAX script that fires when "Like" button (on post) is pressed.
    500      *
    501      * @since   1.0.0
     592
     593    /**
     594     * Localize AJAX script that fires when "Like" button (on post/page) is pressed.
     595     *
     596     * @since   1.1.0
    502597     * @param   string  $hook   The current page name.
    503598     */
    504     public function like_button_clicked_enqueue( $hook ) {
     599    public function localize_like_button_handler_script( $hook ) {
    505600   
    506601        $like_button_clicked_nonce = wp_create_nonce( 'like_button_clicked' );
     
    533628        $button_id = $_POST['btn_id'];
    534629       
    535         // Button number starts at position 17 in $button_id (due to prefix of 'id_lnkLikeButton_')
    536         $button_num = substr( $button_id, 17);
    537 
    538630        // Get like total for specific post from post meta data
    539631        $like_total = get_post_meta( $post_id, 'local_like_and_share_like_total', true );
     
    555647            $like_total += 1;
    556648            $like_count_span =
    557                 '<span id="id_spnLikeCount" class="llas-callout llas-border-callout">'
     649                '<span id="id_llas_spn_like_count" class="llas-callout llas-border-callout">'
    558650                . Local_Like_And_Share_Misc::format_count_display( $like_total )
    559651                . '<b class="llas-border-notch llas-notch"></b>'
     
    598690                // Manually kill AJAX handler
    599691                wp_die();
     692
    600693            }
    601694        }
     
    604697            // User ALREADY liked this!
    605698            $like_count_span =
    606                 '<span id="id_spnLikeCount" class="llas-callout llas-border-callout">'
     699                '<span id="id_llas_spn_like_count" class="llas-callout llas-border-callout">'
    607700                . Local_Like_And_Share_Misc::format_count_display( $like_total )
    608701                . '<b class="llas-border-notch llas-notch"></b>'
     
    623716        }
    624717
    625         wp_send_json( array( 'button_num' => $button_num, 'message' => $like_button_clicked_msg ) );
     718        wp_send_json( array( 'post_id' => $post_id, 'message' => $like_button_clicked_msg ) );
    626719               
    627720    }
    628721
    629722    /**
    630      * Enqueue AJAX script that fires when "Share" button (on post) is pressed.
    631      *
    632      * @since   1.0.0
     723     * Localize AJAX script that fires when "Share" button (on post/page) is pressed.
     724     *
     725     * @since   1.1.0
    633726     * @param   string  $hook   The current page name.
    634727     */
    635     public function share_button_clicked_enqueue( $hook ) {
     728    public function localize_share_button_handler_script( $hook ) {
    636729   
    637730        $share_button_clicked_nonce = wp_create_nonce( 'share_button_clicked' );
     
    694787        wp_die();
    695788       
    696    }
    697      
     789   }   
     790
    698791}   
  • local-like-and-share/trunk/public/js/local-like-and-share-public.js

    r1309636 r1809716  
    1616                // Hide old Tipsy tooltip
    1717                $('.tipsy:last').remove();
    18                
    19                 // Deactivate button
    20                 jQuery("#id_divLikeButton_" + data.button_num).removeClass("llas-like-button-active").addClass("llas-like-button-inactive");
    21  
    22                 // Render deactivated button, new tooltip message, and updated like count
    23                 jQuery("#id_divLikeButton_" + data.button_num).html(data.message);             
     18               
     19                // Handle (potentially) multiple like buttons, per post/page
     20                $("[id^=id_llas_spn_like_button_"+data.post_id+"]").each(function(index) {
     21
     22                    // Deactivate button
     23                    $(this).removeClass("llas-like-button-active").addClass("llas-like-button-inactive");
     24               
     25                    // Render deactivated button, new tooltip message, and updated like count, for each button
     26                    $(this).html(data.message);                 
     27                });
     28                   
    2429                $('a[rel="tipsy"]').tipsy({fade: true, opacity: 1});
    2530            });
  • local-like-and-share/trunk/public/js/local-like-and-share-public.min.js

    r1379566 r1809716  
    1 !function(t){"use strict";function i(t,i){return"function"==typeof t?t.call(i):t}function e(t){for(;t=t.parentNode;)if(t==document)return!0;return!1}function n(i,e){this.$element=t(i),this.options=e,this.enabled=!0,this.fixTitle()}t(function(){t(".like_button").click(function(i){var e=t(this),n=e.data("post-id"),s=e.attr("id");t.post(like_button_clicked_ajax_obj.ajax_url,{_ajax_nonce:like_button_clicked_ajax_obj.nonce,action:"like_button_clicked",post_id:n,btn_id:s},function(i){t(".tipsy:last").remove(),jQuery("#id_divLikeButton_"+i.button_num).removeClass("llas-like-button-active").addClass("llas-like-button-inactive"),jQuery("#id_divLikeButton_"+i.button_num).html(i.message),t('a[rel="tipsy"]').tipsy({fade:!0,opacity:1})})})}),t(function(){t(".share_button").click(function(i){var e=t(this),n=e.data("post-id");t.post(share_button_clicked_ajax_obj.ajax_url,{_ajax_nonce:share_button_clicked_ajax_obj.nonce,action:"share_button_clicked",post_id:n},function(t){location.reload()})})}),t(function(){t('a[rel="tipsy"]').tipsy({fade:!0,opacity:1})}),n.prototype={show:function(){var e=this.getTitle();if(e&&this.enabled){var n=this.tip();n.find(".tipsy-inner")[this.options.html?"html":"text"](e),n[0].className="tipsy",n.remove().css({top:0,left:0,visibility:"hidden",display:"block"}).prependTo(document.body);var s,o=t.extend({},this.$element.offset(),{width:this.$element[0].offsetWidth,height:this.$element[0].offsetHeight}),a=n[0].offsetWidth,l=n[0].offsetHeight,f=i(this.options.gravity,this.$element[0]);switch(f.charAt(0)){case"n":s={top:o.top+o.height+this.options.offset,left:o.left+o.width/2-a/2};break;case"s":s={top:o.top-l-this.options.offset,left:o.left+o.width/2-a/2};break;case"e":s={top:o.top+o.height/2-l/2,left:o.left-a-this.options.offset};break;case"w":s={top:o.top+o.height/2-l/2,left:o.left+o.width+this.options.offset}}2==f.length&&("w"==f.charAt(1)?s.left=o.left+o.width/2-15:s.left=o.left+o.width/2-a+15),n.css(s).addClass("tipsy-"+f),n.find(".tipsy-arrow")[0].className="tipsy-arrow tipsy-arrow-"+f.charAt(0),this.options.className&&n.addClass(i(this.options.className,this.$element[0])),this.options.fade?n.stop().css({opacity:0,display:"block",visibility:"visible"}).animate({opacity:this.options.opacity}):n.css({visibility:"visible",opacity:this.options.opacity})}},hide:function(){this.options.fade?this.tip().stop().fadeOut(function(){t(this).remove()}):this.tip().remove()},fixTitle:function(){var t=this.$element;(t.attr("title")||"string"!=typeof t.attr("original-title"))&&t.attr("original-title",t.attr("title")||"").removeAttr("title")},getTitle:function(){var t,i=this.$element,e=this.options;this.fixTitle();var t,e=this.options;return"string"==typeof e.title?t=i.attr("title"==e.title?"original-title":e.title):"function"==typeof e.title&&(t=e.title.call(i[0])),t=(""+t).replace(/(^\s*|\s*$)/,""),t||e.fallback},tip:function(){return this.$tip||(this.$tip=t('<div class="tipsy"></div>').html('<div class="tipsy-arrow"></div><div class="tipsy-inner"></div>'),this.$tip.data("tipsy-pointee",this.$element[0])),this.$tip},validate:function(){this.$element[0].parentNode||(this.hide(),this.$element=null,this.options=null)},enable:function(){this.enabled=!0},disable:function(){this.enabled=!1},toggleEnabled:function(){this.enabled=!this.enabled}},t.fn.tipsy=function(i){function e(e){var s=t.data(e,"tipsy");return s||(s=new n(e,t.fn.tipsy.elementOptions(e,i)),t.data(e,"tipsy",s)),s}function s(){var t=e(this);t.hoverState="in",0==i.delayIn?t.show():(t.fixTitle(),setTimeout(function(){"in"==t.hoverState&&t.show()},i.delayIn))}function o(){var t=e(this);t.hoverState="out",0==i.delayOut?t.hide():setTimeout(function(){"out"==t.hoverState&&t.hide()},i.delayOut)}if(i===!0)return this.data("tipsy");if("string"==typeof i){var a=this.data("tipsy");return a&&a[i](),this}if(i=t.extend({},t.fn.tipsy.defaults,i),i.live||this.each(function(){e(this)}),"manual"!=i.trigger){var l=i.live?"live":"bind",f="hover"==i.trigger?"mouseenter":"focus",r="hover"==i.trigger?"mouseleave":"blur";this[l](f,s)[l](r,o)}return this},t.fn.tipsy.defaults={className:null,delayIn:0,delayOut:0,fade:!1,fallback:"",gravity:"n",html:!1,live:!1,offset:0,opacity:.8,title:"title",trigger:"hover"},t.fn.tipsy.revalidate=function(){t(".tipsy").each(function(){var i=t.data(this,"tipsy-pointee");i&&e(i)||t(this).remove()})},t.fn.tipsy.elementOptions=function(i,e){return t.metadata?t.extend({},e,t(i).metadata()):e},t.fn.tipsy.autoNS=function(){return t(this).offset().top>t(document).scrollTop()+t(window).height()/2?"s":"n"},t.fn.tipsy.autoWE=function(){return t(this).offset().left>t(document).scrollLeft()+t(window).width()/2?"e":"w"},t.fn.tipsy.autoBounds=function(i,e){return function(){var n={ns:e[0],ew:e.length>1?e[1]:!1},s=t(document).scrollTop()+i,o=t(document).scrollLeft()+i,a=t(this);return a.offset().top<s&&(n.ns="n"),a.offset().left<o&&(n.ew="w"),t(window).width()+t(document).scrollLeft()-a.offset().left<i&&(n.ew="e"),t(window).height()+t(document).scrollTop()-a.offset().top<i&&(n.ns="s"),n.ns+(n.ew?n.ew:"")}}}(jQuery);
     1!function(t){"use strict";function i(t,i){return"function"==typeof t?t.call(i):t}function e(t){for(;t=t.parentNode;)if(t==document)return!0;return!1}function s(i,e){this.$element=t(i),this.options=e,this.enabled=!0,this.fixTitle()}t(function(){t(".like_button").click(function(i){var e=t(this),s=e.data("post-id"),n=e.attr("id");t.post(like_button_clicked_ajax_obj.ajax_url,{_ajax_nonce:like_button_clicked_ajax_obj.nonce,action:"like_button_clicked",post_id:s,btn_id:n},function(i){t(".tipsy:last").remove(),t("[id^=id_llas_spn_like_button_"+i.post_id+"]").each(function(e){t(this).removeClass("llas-like-button-active").addClass("llas-like-button-inactive"),t(this).html(i.message)}),t('a[rel="tipsy"]').tipsy({fade:!0,opacity:1})})})}),t(function(){t(".share_button").click(function(i){var e=t(this).data("post-id");t.post(share_button_clicked_ajax_obj.ajax_url,{_ajax_nonce:share_button_clicked_ajax_obj.nonce,action:"share_button_clicked",post_id:e},function(t){location.reload()})})}),t(function(){t('a[rel="tipsy"]').tipsy({fade:!0,opacity:1})}),s.prototype={show:function(){var e=this.getTitle();if(e&&this.enabled){var s=this.tip();s.find(".tipsy-inner")[this.options.html?"html":"text"](e),s[0].className="tipsy",s.remove().css({top:0,left:0,visibility:"hidden",display:"block"}).prependTo(document.body);var n,o=t.extend({},this.$element.offset(),{width:this.$element[0].offsetWidth,height:this.$element[0].offsetHeight}),a=s[0].offsetWidth,l=s[0].offsetHeight,f=i(this.options.gravity,this.$element[0]);switch(f.charAt(0)){case"n":n={top:o.top+o.height+this.options.offset,left:o.left+o.width/2-a/2};break;case"s":n={top:o.top-l-this.options.offset,left:o.left+o.width/2-a/2};break;case"e":n={top:o.top+o.height/2-l/2,left:o.left-a-this.options.offset};break;case"w":n={top:o.top+o.height/2-l/2,left:o.left+o.width+this.options.offset}}2==f.length&&("w"==f.charAt(1)?n.left=o.left+o.width/2-15:n.left=o.left+o.width/2-a+15),s.css(n).addClass("tipsy-"+f),s.find(".tipsy-arrow")[0].className="tipsy-arrow tipsy-arrow-"+f.charAt(0),this.options.className&&s.addClass(i(this.options.className,this.$element[0])),this.options.fade?s.stop().css({opacity:0,display:"block",visibility:"visible"}).animate({opacity:this.options.opacity}):s.css({visibility:"visible",opacity:this.options.opacity})}},hide:function(){this.options.fade?this.tip().stop().fadeOut(function(){t(this).remove()}):this.tip().remove()},fixTitle:function(){var t=this.$element;(t.attr("title")||"string"!=typeof t.attr("original-title"))&&t.attr("original-title",t.attr("title")||"").removeAttr("title")},getTitle:function(){var t=this.$element,i=this.options;this.fixTitle();var e;return"string"==typeof(i=this.options).title?e=t.attr("title"==i.title?"original-title":i.title):"function"==typeof i.title&&(e=i.title.call(t[0])),(e=(""+e).replace(/(^\s*|\s*$)/,""))||i.fallback},tip:function(){return this.$tip||(this.$tip=t('<div class="tipsy"></div>').html('<div class="tipsy-arrow"></div><div class="tipsy-inner"></div>'),this.$tip.data("tipsy-pointee",this.$element[0])),this.$tip},validate:function(){this.$element[0].parentNode||(this.hide(),this.$element=null,this.options=null)},enable:function(){this.enabled=!0},disable:function(){this.enabled=!1},toggleEnabled:function(){this.enabled=!this.enabled}},t.fn.tipsy=function(i){function e(e){var n=t.data(e,"tipsy");return n||(n=new s(e,t.fn.tipsy.elementOptions(e,i)),t.data(e,"tipsy",n)),n}if(!0===i)return this.data("tipsy");if("string"==typeof i){var n=this.data("tipsy");return n&&n[i](),this}if((i=t.extend({},t.fn.tipsy.defaults,i)).live||this.each(function(){e(this)}),"manual"!=i.trigger){var o=i.live?"live":"bind",a="hover"==i.trigger?"mouseenter":"focus",l="hover"==i.trigger?"mouseleave":"blur";this[o](a,function(){var t=e(this);t.hoverState="in",0==i.delayIn?t.show():(t.fixTitle(),setTimeout(function(){"in"==t.hoverState&&t.show()},i.delayIn))})[o](l,function(){var t=e(this);t.hoverState="out",0==i.delayOut?t.hide():setTimeout(function(){"out"==t.hoverState&&t.hide()},i.delayOut)})}return this},t.fn.tipsy.defaults={className:null,delayIn:0,delayOut:0,fade:!1,fallback:"",gravity:"n",html:!1,live:!1,offset:0,opacity:.8,title:"title",trigger:"hover"},t.fn.tipsy.revalidate=function(){t(".tipsy").each(function(){var i=t.data(this,"tipsy-pointee");i&&e(i)||t(this).remove()})},t.fn.tipsy.elementOptions=function(i,e){return t.metadata?t.extend({},e,t(i).metadata()):e},t.fn.tipsy.autoNS=function(){return t(this).offset().top>t(document).scrollTop()+t(window).height()/2?"s":"n"},t.fn.tipsy.autoWE=function(){return t(this).offset().left>t(document).scrollLeft()+t(window).width()/2?"e":"w"},t.fn.tipsy.autoBounds=function(i,e){return function(){var s={ns:e[0],ew:e.length>1&&e[1]},n=t(document).scrollTop()+i,o=t(document).scrollLeft()+i,a=t(this);return a.offset().top<n&&(s.ns="n"),a.offset().left<o&&(s.ew="w"),t(window).width()+t(document).scrollLeft()-a.offset().left<i&&(s.ew="e"),t(window).height()+t(document).scrollTop()-a.offset().top<i&&(s.ns="s"),s.ns+(s.ew?s.ew:"")}}}(jQuery);
Note: See TracChangeset for help on using the changeset viewer.