Plugin Directory

Changeset 1476156

Timestamp:
08/17/2016 12:37:14 AM (10 years ago)
Author:
micropat
Message:

1.7

  • Simplify AddToAny asynchronous loading method
  • Use HTML5 data attributes for AddToAny instances
  • Remove old script block in footer
  • Increase support for AJAX loading by listening for the post-load event on non-AJAX requests
  • AddToAny readiness check in AddToAny settings
  • Add placement option for media pages in AddToAny settings
  • Handle "Show sharing buttons" option for media when updating from the WordPress editor
  • Add Copy Link button
  • Add Facebook Messenger share button
  • Add Trello share button
  • Update a few packaged icons
Location:
add-to-any/trunk
Files:
4 added
8 edited

Legend:

Unmodified
Added
Removed
  • add-to-any/trunk/README.txt

    r1441389 r1476156  
    33Tags: AddToAny, sharing, share, social, share button, share buttons, share links, social icons, social media, media, marketing, bookmark, bookmarks, save, post, posts, page, pages, images, image, admin, analytics, statistics, stats, links, plugin, shortcode, sidebar, widget, responsive, email, e-mail, print, seo, button, amp, woocommerce, ecommerce, e-commerce, amazon, delicious, google, tumblr, linkedin, digg, reddit, facebook, facebook share, facebook like, like, twitter, twitter button, twitter share, tweet, tweet button, google plus, pinterest, pin, pin it, pinit, wanelo, buffer, stumbleupon, bitly, whatsapp, instagram, behance, flickr, foursquare, vimeo, youtube, feed, rss, addthis, sociable, share this, sharethis, shareaholic, icon, icons, vector, SVG, floating, floating buttons, wpml, wpmu, Add to Any
    44Requires at least: 3.7
    5 Tested up to: 4.5
    6 Stable tag: 1.6.18
     5Tested up to: 4.
     6Stable tag: 1.
    77
    88Share buttons for WordPress including the AddToAny sharing button, Facebook, Twitter, Google+, Pinterest, WhatsApp, many more, and follow icons too.
     
    3636
    3737* Automatic Google Analytics integration (<a href="https://www.addtoany.com/ext/google_analytics/">access guide</a>) for sharing analytics
    38 * Track shared links with bit.ly, awe.sm, goo.gl, and custom URL shorteners
     38* Track shared links with bit.ly, goo.gl, and custom URL shorteners
    3939* Display share counts on posts and pages
    4040
     
    4242
    4343* Loads asynchronously so your content always loads before or in parallel with AddToAny
    44 * Supports theme features such as HTML5 & XHTML, widgets, infinite scroll, post formats
     44* Supports theme features such as HTML5, widgets, infinite scroll, post formats
    4545* Supports multilingual sites and multisite networks
    4646* No signup, no login, no account necessary
     
    7474See also:
    7575
    76 * The standard <a href="https://www.addtoany.com/buttons/for/website">share buttons</a> code
    77 * The universal <a href="https://www.addtoany.com/buttons/for/wordpress_com">share button for WordPress.com</a>
     76* The
     77* The <a href="https://www.addtoany.com/buttons/for/wordpress_com">share button for WordPress.com</a>
    7878
    7979<a href="https://www.addtoany.com/blog/">AddToAny Blog</a> | <a href="https://www.addtoany.com/privacy">Privacy Policy</a>
     
    135135Use Facebook's <a href="https://developers.facebook.com/tools/debug/sharing/" target="_blank">Sharing Debugger</a> on your pages to see how Facebook reads your site. "Scrape Again" to test site changes and clear Facebook's cache of a page, or use the <a href="https://developers.facebook.com/tools/debug/sharing/batch/" target="_blank">Batch Invalidator</a> to purge Facebook's cache of multiple URLs.
    136136
    137 To change the title, description and/or image on Facebook, your theme's header file should be modified according to <a href="https://developers.facebook.com/docs/sharing/opengraph" target="_blank">Facebook's OpenGraph specification</a>. With WordPress, this can be accomplished with plugins such as <a href="https://wordpress.org/plugins/wordpress-seo/">Yoast SEO</a> or <a href="https://wordpress.org/plugins/all-in-one-seo-pack/">All in One SEO Pack</a>. Please see those plugins for details, and post in the WordPress or plugin author's forums for more support.
     137To change the title, description and/or image on Facebook, your theme's header file should be modified according to <a href="https://developers.facebook.com/docs/sharing/opengraph" target="_blank">Facebook's OpenGraph specification</a>. With WordPress, this can be accomplished with plugins such as <a href="https://wordpress.org/plugins/wordpress-seo/">Yoast SEO</a> or <a href="https://wordpress.org/plugins/all-in-one-seo-pack/">All in One SEO Pack</a>. Please see those plugins for details, and post in the WordPress or plugin author's forums for more support.
    138138
    139139For more technical information on setting your pages up for Facebook sharing, see "Sharing Best Practices for Websites" in <a href="https://developers.facebook.com/docs/sharing/best-practices">Facebook's documentation</a>.
     
    187187        'linkname'  => 'Example Page',
    188188        'linkurl'   => 'https://www.example.com/page.html',
     189
     190
     191
     192
     193
     194
     195
     196
     197
     198
     199
     200
     201
    189202    ) );
    190203} ?>`
     
    291304= Does the plugin output W3C valid code? =
    292305
    293 Yes, this plugin outputs 100% W3C valid HTML5 & XHTML and W3C valid CSS 3 by default.
    294 
    295 If you use the Facebook Like, Twitter Tweet or Google +1 buttons in an HTML5 theme, note that the button iframes use the `scrolling` attribute, which is valid XHTML but the attribute has been deprecated in HTML5. It's needed to prevent scrollbars from appearing over the Like, Tweet, and +1 buttons inside of the iframes.
    296 
    297 Regardless of circumstances for passing W3C tests, the plugin will always output semantically valid and robot-readable code, so publishers do not have to worry about search engine crawler errors due to invalid code. Both <a href="https://en.wikipedia.org/wiki/Web_standards">web standards</a> and <a href="https://en.wikipedia.org/wiki/Cross-browser">cross-browser</a> compatibility are taken seriously.
     306Yes, this plugin outputs 100% W3C valid HTML5 and W3C valid CSS 3 by default.
    298307
    299308= How can I load the buttons after content insertion with AJAX and infinite scroll? =
     
    302311`jQuery( 'body' ).trigger( 'post-load' );`
    303312
    304 A few prerequisites:
     313A prerequisites:
    305314
    306315 * The request has an `HTTP_X_REQUESTED_WITH` header set to `xmlhttprequest`
    307316 * `jQuery` available
    308  * AddToAny `<script>` blocks in the response need to execute, so don't use jQuery's `load` method *with a selector expression*. Selector expression usage with that method will cause `<script>` blocks in the response <a href="https://api.jquery.com/load/#script-execution">to be stripped out</a>
    309317
    310318= Why does the menu appear behind embedded objects (like Flash)? =
     
    326334
    327335== Changelog ==
     336
     337
     338
     339
     340
     341
     342
     343
     344
     345
     346
     347
     348
    328349
    329350= 1.6.18 =
  • add-to-any/trunk/add-to-any.php

    r1441389 r1476156  
    44Plugin URI: https://www.addtoany.com/
    55Description: Share buttons for your pages including AddToAny's universal sharing button, Facebook, Twitter, Google+, Pinterest, WhatsApp and many more.
    6 Version: 1.6.18
     6Version: 1.
    77Author: AddToAny
    88Author URI: https://www.addtoany.com/
     
    1212
    1313// Explicitly globalize to support bootstrapped WordPress
    14 global $_addtoany_counter, $_addtoany_init, $_addtoany_targets, $A2A_locale, $A2A_FOLLOW_services,
     14global $A2A_locale, $A2A_FOLLOW_services,
    1515    $A2A_SHARE_SAVE_plugin_basename, $A2A_SHARE_SAVE_options, $A2A_SHARE_SAVE_plugin_dir, $A2A_SHARE_SAVE_plugin_url_path, $A2A_SHARE_SAVE_services;
    1616
     
    7676// Combine ADDTOANY_SHARE_SAVE_ICONS and ADDTOANY_SHARE_SAVE_BUTTON
    7777function ADDTOANY_SHARE_SAVE_KIT( $args = array() ) {
    78     global $_addtoany_counter;
    79    
    80     $_addtoany_counter++;
    81    
    8278    $options = get_option( 'addtoany_options' );
    8379   
     80
     81
     82
     83
     84
     85
    8486    $defaults = array(
    85         'output_later'         => false,
    86         'icon_size'            => isset( $options['icon_size'] ) ? $options['icon_size'] : '32',
     87        'output_later'     => false,
     88        'icon_size'        => isset( $options['icon_size'] ) ? $options['icon_size'] : '32',
     89        'use_current_page' => false,
    8790    );
     91
    8892   
    8993    $args = wp_parse_args( $args, $defaults );
     
    99103    // Custom icons enabled?
    100104    $custom_icons = ( isset( $options['custom_icons'] ) && $options['custom_icons'] == 'url' && isset( $options['custom_icons_url'] ) ) ? true : false;
    101 
     105   
    102106    $kit_additional_classes = '';
     107
     108
     109
    103110    $kit_style = '';
    104111   
     
    141148   
    142149    if ( ! isset( $args['html_container_open'] ) ) {
    143         $args['html_container_open'] = '<div class="a2a_kit' . $icon_size_classname . $kit_additional_classes . ' a2a_target"';
    144         $args['html_container_open'] .= ' id="wpa2a_' . $_addtoany_counter . '"'; // ID is later removed by JS (for AJAX)
    145         $args['html_container_open'] .= $kit_style;
    146         $args['html_container_open'] .= '>';
     150        $args['html_container_open'] = '<div class="a2a_kit' . $icon_size_classname . $kit_additional_classes . '"'
     151            . $kit_data_url . $kit_data_title . $kit_data_media . $kit_style . '>';
    147152        $args['is_kit'] = true;
    148153    }
     
    360365    // $args array = output_later, html_container_open, html_container_close, html_wrap_open, html_wrap_close, linkname, linkurl, no_universal_button
    361366
    362     global $A2A_SHARE_SAVE_plugin_url_path, $_addtoany_targets, $_addtoany_counter, $_addtoany_init;
     367    global $A2A_SHARE_SAVE_plugin_url_path;
    363368   
    364369    $options = get_option( 'addtoany_options' );
     
    367372    $linkurl = isset( $args['linkurl'] ) ? $args['linkurl'] : false;
    368373    $linkmedia = isset( $args['linkmedia'] ) ? $args['linkmedia'] : false;
    369     $_addtoany_targets = ( isset( $_addtoany_targets ) ) ? $_addtoany_targets : array();
    370374
    371375    $args = array_merge($args, A2A_SHARE_SAVE_link_vars($linkname, $linkurl, $linkmedia)); // linkname_enc, etc.
     
    393397    extract( $args );
    394398   
    395     // If not enclosed in an AddToAny Kit, count & target this button (instead of Kit) for async loading
    396     if ( ! $args['is_kit'] ) {
    397         $_addtoany_counter++;
    398         $button_class = ' a2a_target';
    399         $button_id = ' id="wpa2a_' . $_addtoany_counter . '"';  // ID is later removed by JS (for AJAX)
    400     } else {
    401         $button_class = '';
    402         $button_id = '';
    403     }
    404    
    405     /* AddToAny button */
    406    
    407399    $is_feed = is_feed();
    408400    $is_amp = function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ? true : false;
     401
     402
     403
     404
    409405    $button_target = $is_amp ? ' target="_blank"' : '';
    410406    $button_href_querystring = ($is_feed || $is_amp) ? '#url=' . $linkurl_enc . '&amp;title=' . $linkname_enc : '';
     
    466462        }
    467463       
    468         $button_html = $html_container_open . $html_wrap_open . '<a class="a2a_dd' . $button_class . ' addtoany_share_save" href="https://www.addtoany.com/share' .$button_href_querystring . '"' . $button_id
    469             . $style . $button_target
     464        $button_html = $html_container_open . $html_wrap_open . '<a class="a2a_dd' . $button_class . ' addtoany_share_save" href="https://www.addtoany.com/share' .$button_href_querystring . '"'
     465            . $style . $button_target
    470466            . '>' . $button . '</a>';
    471467   
     
    473469        // Universal button disabled
    474470        $button_html = '';
    475     }
    476    
    477     // Hook to disable script output
    478     // Example: add_filter( 'addtoany_script_disabled', '__return_true' );
    479     $script_disabled = apply_filters( 'addtoany_script_disabled', false );
    480     // Doing AJAX? (the DOING_AJAX constant can be unreliable)
    481     $ajax = ( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && strtolower( $_SERVER['HTTP_X_REQUESTED_WITH'] ) == 'xmlhttprequest' ) ? true : false;
    482    
    483     // If not a feed and script is not disabled,
    484     // and not admin (unless doing AJAX, probably through admin-ajax.php)
    485     if ( ! $is_feed && ! $script_disabled && ( ! is_admin() || $ajax ) ) {
    486         if ($use_current_page) {
    487             $button_config = "\n{title:document.title,"
    488                 . "url:location.href}";
    489             $_addtoany_targets[] = $button_config;
    490         } else {
    491             // wp_json_encode available since 4.1
    492             $linkname_sanitized = function_exists( 'wp_json_encode' ) ? wp_json_encode ( $linkname ) : json_encode( $linkname );
    493             $linkmedia_optional = ! empty( $linkmedia ) ? ',media:"' . $linkmedia . '"' : '' ;
    494             $button_config = "\n{title:". $linkname_sanitized . ','
    495                 . 'url:"' . $linkurl . '"'
    496                 . $linkmedia_optional . '}';
    497             $_addtoany_targets[] = $button_config;
    498         }
    499        
    500         // If doing AJAX (the DOING_AJAX constant can be unreliable)
    501         if ( $ajax ) {
    502             $javascript_button_config = "<script type=\"text/javascript\"><!--\n"
    503                 . "if(wpa2a.targets)wpa2a.targets.push("
    504                     . $button_config
    505                 . ");\n";
    506            
    507             if ( ! $_addtoany_init ) {
    508                 // Catch post-load event to support infinite scroll (and more?)
    509                 $javascript_button_config .= "\nif('function'===typeof(jQuery))"
    510                     . "jQuery(document).ready(function($){"
    511                         . "$('body').on('post-load',function(){"
    512                             . "if(wpa2a.script_ready)wpa2a.init();"
    513                             . "wpa2a.script_load();" // Load external script if not already called
    514                         . "});"
    515                     . "});";
    516             }
    517            
    518             $javascript_button_config .= "\n//--></script>\n";
    519         } else {
    520             $javascript_button_config = '';
    521         }
    522        
    523         if ( ! $_addtoany_init ) {
    524             $javascript_load_early = "\n<script type=\"text/javascript\"><!--\n"
    525                 . "if(wpa2a)wpa2a.script_load();"
    526                 . "\n//--></script>\n";
    527         } else {
    528             $javascript_load_early = "";
    529         }
    530        
    531         $button_html .= $javascript_load_early . $javascript_button_config;
    532         $_addtoany_init = true;
    533471    }
    534472   
     
    786724    $A2A_SHARE_SAVE_external_script_called = true;
    787725   
    788     $javascript_header = "\n" . '<script type="text/javascript">' . "<!--\n"
    789    
    790             . "var a2a_config=a2a_config||{},"
    791             . "wpa2a={done:false,"
    792             . "html_done:false,"
    793             . "script_ready:false,"
    794             . "script_load:function(){"
    795                 . "var a=document.createElement('script'),"
    796                     . "s=document.getElementsByTagName('script')[0];"
    797                 . "a.type='text/javascript';a.async=true;"
    798                 . "a.src='" . $static_server . "/page.js';"
    799                 . "s.parentNode.insertBefore(a,s);"
    800                 . "wpa2a.script_load=function(){};"
    801             . "},"
    802             . "script_onready:function(){"
    803                 . "wpa2a.script_ready=true;"
    804                 . "if(wpa2a.html_done)wpa2a.init();"
    805             . "},"
    806             . "init:function(){"
    807                 . "for(var i=0,el,target,targets=wpa2a.targets,length=targets.length;i<length;i++){"
    808                     . "el=document.getElementById('wpa2a_'+(i+1));"
    809                     . "target=targets[i];"
    810                     . "a2a_config.linkname=target.title;"
    811                     . "a2a_config.linkurl=target.url;"
    812                     . "a2a_config.linkmedia=target.media;"
    813                     . "if(el){"
    814                         . "a2a.init('page',{target:el});"
    815                         . "el.id='';" // Remove ID so AJAX can reuse the same ID
    816                     . "}"
    817                     . "wpa2a.done=true;"
    818                 . "}"
    819                 . "wpa2a.targets=[];" // Empty targets array so AJAX can reuse from index 0
    820             . "}"
    821         . "};"
    822        
     726    $javascript_header = "\n" . '<script type="text/javascript">' . "\n"
     727   
     728        . "var a2a_config=a2a_config||{};"
    823729        . "a2a_config.callbacks=a2a_config.callbacks||[];"
    824         . "a2a_config.callbacks.push({ready:wpa2a.script_onready});"
    825730        . "a2a_config.templates=a2a_config.templates||{};"
    826731        . A2A_menu_locale()
    827732        . $script_configs
    828733       
    829         . "\n//--></script>\n";
     734        . "\n</script>\n"
     735       
     736        . '<script type="text/javascript" src="' . $static_server . '/page.js" async="async"></script>' . "\n";
    830737   
    831738     echo $javascript_header;
     
    835742
    836743function A2A_SHARE_SAVE_footer_script() {
    837     global $_addtoany_targets;
    838    
    839     // Hook to disable script output
    840     // Example: add_filter( 'addtoany_script_disabled', '__return_true' );
    841     $script_disabled = apply_filters( 'addtoany_script_disabled', false );
    842    
    843     if ( is_admin() || is_feed() || $script_disabled )
     744    if ( is_admin() || is_feed() )
    844745        return;
    845        
    846     $_addtoany_targets = ( isset( $_addtoany_targets ) ) ? $_addtoany_targets : array();
    847746   
    848747    $floating_html = ADDTOANY_SHARE_SAVE_FLOATING( array( 'output_later' => true ) );
    849748   
    850     $javascript_footer = "\n" . '<script type="text/javascript">' . "<!--\n"
    851         . "wpa2a.targets=["
    852             . implode( ",", $_addtoany_targets )
    853         . "];\n"
    854         . "wpa2a.html_done=true;"
    855         . "if(wpa2a.script_ready&&!wpa2a.done)wpa2a.init();" // External script may load before html_done=true, but will only init if html_done=true.  So call wpa2a.init() if external script is ready, and if wpa2a.init() hasn't been called already.  Otherwise, wait for callback to call wpa2a.init()
    856         . "wpa2a.script_load();" // Load external script if not already called with the first AddToAny button.  Fixes issues where first button code is processed internally but without actual code output
    857         . "\n//--></script>\n";
    858    
    859     echo $floating_html . $javascript_footer;
     749    echo $floating_html;
    860750}
    861751
     
    918808            // Individual pages
    919809            ( is_page() && isset( $options['display_in_pages'] ) && $options['display_in_pages'] == '-1' ) ||
     810
     811
    920812            // <!--nosharesave--> legacy tag
    921813            ( (strpos( $content, '<!--nosharesave-->') !== false ) )
     
    1077969add_action( 'wp_print_styles', 'A2A_SHARE_SAVE_stylesheet' );
    1078970
     971
     972
     973
     974
     975
     976
     977
     978
     979
     980
    1079981
    1080982/**
  • add-to-any/trunk/addtoany.admin.js

    r1394811 r1476156  
    77   
    88    function addtoany_init() {
    9         if ( ! wpa2a )
    10             return;
    11        
    12         if (wpa2a.script_ready)
    13             wpa2a.init();
    14        
    15         // Load external script if not already called
    16         wpa2a.script_load();
     9        if ( window.a2a ) {
     10            a2a.init_all( 'page' );
     11        }
    1712    }
    1813   
  • add-to-any/trunk/addtoany.admin.php

    r1394811 r1476156  
    6868add_action( 'admin_init', 'A2A_SHARE_SAVE_add_meta_box' );
    6969add_action( 'save_post', 'A2A_SHARE_SAVE_meta_box_save' );
     70
    7071
    7172/**
     
    271272            $new_options['display_in_posts'] = ( isset( $_POST['A2A_SHARE_SAVE_display_in_posts'] ) && $_POST['A2A_SHARE_SAVE_display_in_posts'] == '1' ) ? '1' : '-1';
    272273            $new_options['display_in_pages'] = ( isset( $_POST['A2A_SHARE_SAVE_display_in_pages'] ) && $_POST['A2A_SHARE_SAVE_display_in_pages'] == '1' ) ? '1' : '-1';
     274
    273275            $new_options['display_in_feed'] = ( isset( $_POST['A2A_SHARE_SAVE_display_in_feed'] ) && $_POST['A2A_SHARE_SAVE_display_in_feed'] == '1' ) ? '1' : '-1';
    274276            $new_options['show_title'] = ( isset( $_POST['A2A_SHARE_SAVE_show_title'] ) && $_POST['A2A_SHARE_SAVE_show_title'] == '1' ) ? '1' : '-1';
     
    360362       
    361363        ?>
    362         <div class="updated fade"><p><strong><?php _e( 'Settings saved.' ); ?></strong></p></div>
     364        <div class="updated></p></div>
    363365        <?php
    364366       
     
    608610                    <?php printf(__('Display at the %s of pages', 'add-to-any'), position_in_content( $options, false )); ?>
    609611                </label>
     612
     613
     614
     615
     616
     617
     618
    610619               
    611620            <?php
     
    645654                </label>
    646655                <p>
    647                     <a href="https://www.addtoany.com/buttons/share_save/menu_style/wordpress" class="button-secondary" title="<?php _e("Open the AddToAny Menu Styler in a new window", 'add-to-any'); ?>" target="_blank" onclick="document.getElementById('A2A_SHARE_SAVE_additional_js_variables').focus(); document.getElementById('A2A_SHARE_SAVE_menu_styler_note').style.display='';"><?php _e("Open Menu Styler", 'add-to-any'); ?></a>
     656                    <a href="https://www.addtoany.com/buttons/share/menu_style/wordpress" class="button-secondary" title="<?php _e("Open the AddToAny Menu Styler in a new window", 'add-to-any'); ?>" target="_blank" onclick="document.getElementById('A2A_SHARE_SAVE_additional_js_variables').focus(); document.getElementById('A2A_SHARE_SAVE_menu_styler_note').style.display='';"><?php _e("Open Menu Styler", 'add-to-any'); ?></a>
    648657                </p>
    649658            </fieldset></td>
     
    816825    </div>
    817826   
    818     <script type="text/javascript" src="http<?php if ( is_ssl() ) echo 's'; ?>://static.addtoany.com/menu/page.js"></script>
    819     <script type="text/javascript">if ( a2a && a2a.svg_css ) a2a.svg_css();</script>
     827    <script src="http<?php if ( is_ssl() ) echo 's'; ?>://static.addtoany.com/menu/page.js"></script>
     828    <script>
     829    if ( window.a2a && a2a.svg_css ) a2a.svg_css();
     830    jQuery(document).ready( function() { if ( ! window.a2a) jQuery('<div class="error"><p><strong>Something is preventing AddToAny from loading. Try disabling content blockers such as ad-blocking add-ons, or try another web browser.</strong></p></div>').insertBefore('.nav-tab-wrapper:eq(0)'); });   
     831    </script>
    820832
    821833<?php
  • add-to-any/trunk/addtoany.services.php

    r1394811 r1476156  
    107107        "icon" => "citeulike",
    108108    ),
     109
     110
     111
     112
    109113    "delicious" => array(
    110114        "name" => "Delicious",
     
    147151        "icon" => "evernote",
    148152    ),
     153
     154
     155
     156
    149157    "fark" => array(
    150158        "name" => "Fark",
     
    338346        "name" => "Telegram",
    339347        "icon" => "telegram",
     348
     349
     350
     351
    340352    ),
    341353    "tuenti" => array(
Note: See TracChangeset for help on using the changeset viewer.