WordPress.org

Plugin Directory

Changeset 587002


Ignore:
Timestamp:
08/17/12 22:03:30 (20 months ago)
Author:
mdawaffe
Message:

Sharing: Consistency in sharing URLs.

  • Always use the sharing_permalink filter for each sharing service.
  • Standardize on rawurlencode()
  • Fix Tumblr sharing from home/archive pages by explicitly setting the URL to share
  • Fix some escaping.

http://wordpress.org/support/topic/plugin-jetpack-by-wordpresscom-support-for-sharing_permalink-filter-inconsistent

File:
1 edited

Legend:

Unmodified
Added
Removed
  • jetpack/trunk/modules/sharedaddy/sharing-sources.php

    r586704 r587002  
    2828    } 
    2929     
     30    public function get_share_url( $post_id ) { 
     31        return apply_filters( 'sharing_permalink', get_permalink( $post_id ), $post_id, $this->id ); 
     32    } 
     33 
    3034    public function has_custom_button_style() { 
    3135        return false; 
     
    358362            $via = ''; 
    359363        } 
     364 
     365        $share_url = $this->get_share_url( $post->ID ); 
     366 
    360367        if ( $this->smart ) { 
    361             return '<div class="twitter_button"><iframe allowtransparency="true" frameborder="0" scrolling="no" src="' . esc_url( 'http://platform.twitter.com/widgets/tweet_button.html?url=' . rawurlencode( apply_filters( 'sharing_permalink', get_permalink( $post->ID ), $post->ID, $this->id ) ) . '&counturl=' . rawurlencode( str_replace( 'https://', 'http://', get_permalink( $post->ID ) ) ) . '&count=horizontal&text=' . rawurlencode( $post->post_title . ':' ) . $via ) . '" style="width:101px; height:20px;"></iframe></div>'; 
     368            return '<div class="twitter_button"><iframe allowtransparency="true" frameborder="0" scrolling="no" src="' . esc_url( 'http://platform.twitter.com/widgets/tweet_button.html?url=' . rawurlencode( $share_url ) . '&counturl=' . rawurlencode( str_replace( 'https://', 'http://', get_permalink( $post->ID ) ) ) . '&count=horizontal&text=' . rawurlencode( $post->post_title . ':' ) . $via ) . '" style="width:101px; height:20px;"></iframe></div>'; 
    362369        } else { 
    363370            if ( 'icon-text' == $this->button_style || 'text' == $this->button_style ) 
     
    369376    public function process_request( $post, array $post_data ) { 
    370377        $post_title = $post->post_title; 
    371         $post_link = apply_filters( 'sharing_permalink', get_permalink( $post->ID ), $post->ID, $this->id ); 
     378        $post_link = $this->get_share_url( $post->ID ); 
    372379 
    373380        if ( function_exists( 'mb_stripos' ) ) { 
     
    447454    public function get_display( $post ) { 
    448455        if ( $this->smart ) 
    449             return '<div class="stumbleupon_button"><iframe src="http://www.stumbleupon.com/badge/embed/1/?url=' . urlencode( get_permalink( $post->ID ) ) . '&amp;title=' . urlencode( $post->post_title ) . '" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:74px; height: 18px;" allowTransparency="true"></iframe></div>'; 
     456            return '<div class="stumbleupon_button"><iframe src="http://www.stumbleupon.com/badge/embed/1/?url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&amp;title=' . rawurlencode( $post->post_title ) . '" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:74px; height: 18px;" allowTransparency="true"></iframe></div>'; 
    450457        else 
    451458            return $this->get_link( get_permalink( $post->ID ), _x( 'StumbleUpon', 'share to', 'jetpack' ), __( 'Click to share on StumbleUpon', 'jetpack' ), 'share=stumbleupon' ); 
     
    453460     
    454461    public function process_request( $post, array $post_data ) { 
    455         $stumbleupon_url = 'http://www.stumbleupon.com/submit?url=' . urlencode( get_permalink( $post->ID ) ) . '&title=' . urlencode( $post->post_title ); 
     462        $stumbleupon_url = 'http://www.stumbleupon.com/submit?url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&title=' . rawurlencode( $post->post_title ); 
    456463         
    457464        // Record stats 
     
    481488    public function get_display( $post ) { 
    482489        if ( $this->smart ) 
    483             return '<div class="reddit_button"><iframe src="http://www.reddit.com/static/button/button1.html?width=120&amp;url=' . urlencode( apply_filters( 'sharing_permalink', get_permalink( $post->ID ), $post->ID, $this->id ) ) . '&amp;title=' . rawurlencode( $post->post_title ) . '" height="22" width="120" scrolling="no" frameborder="0"></iframe></div>'; 
     490            return '<div class="reddit_button"><iframe src="http://www.reddit.com/static/button/button1.html?width=120&amp;url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&amp;title=' . rawurlencode( $post->post_title ) . '" height="22" width="120" scrolling="no" frameborder="0"></iframe></div>'; 
    484491        else 
    485492            return $this->get_link( get_permalink( $post->ID ), __( 'Reddit', 'share to', 'jetpack' ), __( 'Click to share on Reddit', 'jetpack' ), 'share=reddit' ); 
     
    487494     
    488495    public function process_request( $post, array $post_data ) { 
    489         $reddit_url = 'http://reddit.com/submit?url=' . urlencode( apply_filters( 'sharing_permalink', get_permalink( $post->ID ), $post->ID, $this->id ) ) . '&title=' . urlencode( $post->post_title ); 
     496        $reddit_url = 'http://reddit.com/submit?url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&title=' . rawurlencode( $post->post_title ); 
    490497         
    491498        // Record stats 
     
    519526    public function get_display( $post ) { 
    520527        if ( $this->smart ) { 
    521             $url = $this->get_link( 'http://digg.com/submit?url='. urlencode( apply_filters( 'sharing_permalink', get_permalink( $post->ID ), $post->ID, $this->id ) ) . '&amp;title=' . urlencode( $post->post_title ), 'Digg', __( 'Click to Digg this post', 'jetpack' ) ); 
     528            $url = $this->get_link( 'http://digg.com/submit?url='. rawurlencode( $this->get_share_url( $post->ID ) ) . '&amp;title=' . rawurlencode( $post->post_title ), 'Digg', __( 'Click to Digg this post', 'jetpack' ) ); 
    522529            return '<div class="digg_button">' . str_replace( 'class="', 'class="DiggThisButton DiggCompact ', $url ) . '</div>'; 
    523530        } else { 
     
    527534     
    528535    public function process_request( $post, array $post_data ) { 
    529         $digg_url = 'http://digg.com/submit?url=' . urlencode( apply_filters( 'sharing_permalink', get_permalink( $post->ID ), $post->ID, $this->id ) ) . '&title=' . urlencode( $post->post_title ); 
     536        $digg_url = 'http://digg.com/submit?url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&title=' . rawurlencode( $post->post_title ); 
    530537         
    531538        // Record stats 
     
    574581 
    575582    public function get_display( $post ) { 
    576         $permalink = get_permalink( $post->ID ); 
     583        $share_url = $this->get_share_url( $post->ID ); 
    577584        $display = ''; 
    578585         
    579586        if ( $this->smart ) 
    580             $display .= sprintf( '<div class="linkedin_button"><script type="in/share" data-url="%s" data-counter="right"></script></div>', esc_url( $permalink ) ); 
    581         else 
    582             $display = $this->get_link( $permalink, _x( 'LinkedIn', 'share to', 'jetpack' ), __( 'Click to share on LinkedIn', 'jetpack' ), 'share=linkedin', 'sharing-linkedin-' . $post->ID ); 
     587            $display .= sprintf( '<div class="linkedin_button"><script type="in/share" data-url="%s" data-counter="right"></script></div>', esc_url( $share_url ) ); 
     588        else 
     589            $display = $this->get_link( get_permalink( $post->ID ), _x( 'LinkedIn', 'share to', 'jetpack' ), __( 'Click to share on LinkedIn', 'jetpack' ), 'share=linkedin', 'sharing-linkedin-' . $post->ID ); 
    583590 
    584591        if ( 'icon-text' == $this->button_style || 'text' == $this->button_style ) 
     
    592599        setup_postdata( $post ); 
    593600 
    594         $post_link = apply_filters( 'sharing_permalink', get_permalink( $post->ID ), $post->ID, $this->id ); 
     601        $post_link = $this->get_share_url( $post->ID ); 
    595602 
    596603        // http://www.linkedin.com/shareArticle?mini=true&url={articleUrl}&title={articleTitle}&summary={articleSummary}&source={articleSource} 
     
    606613        $source = get_bloginfo( 'name' ); 
    607614 
    608         $query = add_query_arg( array( 
     615        $linkedin_url = add_query_arg( array( 
    609616            'title' => $encoded_title, 
    610617            'url' => rawurlencode( $post_link ), 
    611618            'source' => rawurlencode( $source ), 
    612619            'summary' => $encoded_summary, 
    613         ) ); 
    614  
    615         $linkedin_url = 'http://www.linkedin.com/shareArticle?mini=true' . $query; 
     620        ), 'http://www.linkedin.com/shareArticle?mini=true' ); 
    616621         
    617622        // Record stats 
     
    683688 
    684689    public function get_display( $post ) { 
     690        $share_url = $this->get_share_url( $post->ID ); 
    685691        if ( $this->smart ) { 
    686             $url = 'http://www.facebook.com/plugins/like.php?href=' . rawurlencode( get_permalink( $post->ID ) ) . '&amp;layout=button_count&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;height=21'; 
     692            $url = 'http://www.facebook.com/plugins/like.php?href=' . rawurlencode( $share_url ) . '&amp;layout=button_count&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;height=21'; 
    687693             
    688694            // Default widths to suit English 
     
    725731     
    726732    public function process_request( $post, array $post_data ) { 
    727         $fb_url = 'http://www.facebook.com/sharer.php?u=' . urlencode( apply_filters( 'sharing_permalink', get_permalink( $post->ID ), $post->ID, $this->id ) ) . '&t=' . urlencode( $post->post_title ); 
     733        $fb_url = 'http://www.facebook.com/sharer.php?u=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&t=' . rawurlencode( $post->post_title ); 
    728734         
    729735        // Record stats 
     
    756762 
    757763    public function get_display( $post ) { 
    758         return $this->get_link( get_permalink( $post->ID ). ( ( is_single() || is_page() ) ? '#print': '' ), _x( 'Print', 'share to', 'jetpack' ), __( 'Click to print', 'jetpack' ) ); 
     764        return $this->get_link( get_permalink( $post->ID ) . ( ( is_single() || is_page() ) ? '#print': '' ), _x( 'Print', 'share to', 'jetpack' ), __( 'Click to print', 'jetpack' ) ); 
    759765    } 
    760766} 
     
    786792        $blog = current( $blogs ); 
    787793 
    788         $url = $blog->siteurl.'/wp-admin/press-this.php?u='.urlencode( apply_filters( 'sharing_permalink', get_permalink( $post->ID ), $post->ID, $this->id ) ).'&t='.urlencode( $post->post_title ).'&v=4'; 
     794        $url = $blog->siteurl.'/wp-admin/press-this.php?u='.rawurlencode( $this->get_share_url( $post->ID ) ).'&t='.rawurlencode( $post->post_title ).'&v=4'; 
    789795 
    790796        if ( isset( $_GET['sel'] ) ) 
    791             $url .= '&s='.urlencode( $_GET['sel'] ); 
     797            $url .= '&s='.rawurlencode( $_GET['sel'] ); 
    792798 
    793799        // Record stats 
     
    823829    public function get_display( $post ) { 
    824830        // Smart or not, return the G+ button 
    825         return '<div class="googleplus1_button"><g:plusone size="medium" callback="sharing_plusone" href="' . esc_attr( get_permalink( $post->ID ) ) . '"></g:plusone></div>'; 
     831        return '<div class="googleplus1_button"><g:plusone size="medium" callback="sharing_plusone" href="' . esc_url( $this->get_share_url( $post->ID ) ) . '"></g:plusone></div>'; 
    826832    } 
    827833     
     
    919925    public function process_request( $post, array $post_data ) { 
    920926        $url = str_replace( '&amp;', '&', $this->url ); 
    921         $url = str_replace( '%post_url%', urlencode( apply_filters( 'sharing_permalink', get_permalink( $post->ID ), $post->ID, $this->id ) ), $url ); 
    922         $url = str_replace( '%post_full_url%', urlencode( get_permalink( $post->ID ) ), $url ); 
    923         $url = str_replace( '%post_title%', urlencode( $post->post_title ), $url ); 
     927        $url = str_replace( '%post_url%', rawurlencode( $this->get_share_url( $post->ID ) ), $url ); 
     928        $url = str_replace( '%post_full_url%', rawurlencode( get_permalink( $post->ID ) ), $url ); 
     929        $url = str_replace( '%post_title%', rawurlencode( $post->post_title ), $url ); 
    924930 
    925931        if ( strpos( $url, '%post_tags%' ) !== false ) { 
     
    929935            if ( $tags ) { 
    930936                foreach ( $tags AS $tag ) { 
    931                     $tagged[] = urlencode( $tag->name ); 
     937                    $tagged[] = rawurlencode( $tag->name ); 
    932938                } 
    933939             
     
    946952            $url_excerpt = wp_html_excerpt( $url_excerpt, 100 ); 
    947953            $url_excerpt = rtrim( preg_replace( '/[^ .]*$/', '', $url_excerpt ) ); 
    948             $url = str_replace( '%post_excerpt%', urlencode( $url_excerpt ), $url ); 
     954            $url = str_replace( '%post_excerpt%', rawurlencode( $url_excerpt ), $url ); 
    949955        } 
    950956 
     
    10651071    public function get_display( $post ) { 
    10661072        if ( $this->smart ) 
    1067             return '<a href="http://www.tumblr.com/share" title="Share on Tumblr" style="display:inline-block; text-indent:-9999px; overflow:hidden; width:62px; height:20px; background:url(\'http://platform.tumblr.com/v1/share_2.png\') top left no-repeat transparent;">Share on Tumblr</a>'; 
     1073            return '<a href="http://www.tumblr.com/share/link/?url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&name=' . rawurlencode( $post->post_title ) . '" title="Share on Tumblr" style="display:inline-block; text-indent:-9999px; overflow:hidden; width:62px; height:20px; background:url(\'http://platform.tumblr.com/v1/share_2.png\') top left no-repeat transparent;">Share on Tumblr</a>'; 
    10681074        else 
    10691075            return $this->get_link( get_permalink( $post->ID ), _x( 'Tumblr', 'share to', 'jetpack' ), __( 'Click to share on Tumblr', 'jetpack' ), 'share=tumblr' ); 
     
    10751081         
    10761082        // Redirect to Tumblr's sharing endpoint (a la their bookmarklet) 
    1077         $url = 'http://www.tumblr.com/share?v=3&u=' . rawurlencode( get_permalink( $post->ID ) ) . '&t=' . rawurlencode( $post->post_title ) . '&s='; 
     1083        $url = 'http://www.tumblr.com/share?v=3&u=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&t=' . rawurlencode( $post->post_title ) . '&s='; 
    10781084        wp_redirect( $url ); 
    10791085        die(); 
     
    11321138    public function get_display( $post ) { 
    11331139        if ( $this->smart ) 
    1134             return '<div class="pinterest_button"><a href="http://pinterest.com/pin/create/button/?url='. rawurlencode( apply_filters( 'sharing_permalink', get_permalink( $post->ID ), $post->ID, $this->id ) ) . '&description=' . rawurlencode( esc_attr( $post->post_title ) ) . '&media=' . rawurlencode( esc_url(  $this->get_post_image( $post->post_content ) ) ) . '" class="pin-it-button" count-layout="horizontal"> '. __( 'Pin It', 'jetpack') .'</a></div>'; 
     1140            return '<div class="pinterest_button"><a href="' . esc_url( 'http://pinterest.com/pin/create/button/?url='. rawurlencode( $this->get_share_url( $post->ID ) ) . '&description=' . rawurlencode( $post->post_title ) . '&media=' . rawurlencode( esc_url_raw( $this->get_post_image( $post->post_content ) ) ) ) . '" class="pin-it-button" count-layout="horizontal"> '. __( 'Pin It', 'jetpack') .'</a></div>'; 
    11351141        else 
    11361142            return $this->get_link( get_permalink( $post->ID ), _x( 'Pinterest', 'share to', 'jetpack' ), __( 'Click to share on Pinterest', 'jetpack' ), 'share=pinterest' ); 
     
    11381144     
    11391145    public function process_request( $post, array $post_data ) { 
    1140         $pinterest_url = 'http://pinterest.com/pin/create/button/?url=' . rawurlencode( get_permalink( $post->ID ) ) . '&description=' . rawurlencode( esc_attr( $post->post_title ) ) . '&media=' . rawurlencode( esc_url( $this->get_post_image( $post->post_content ) ) ); 
     1146        $pinterest_url = esc_url_raw( 'http://pinterest.com/pin/create/button/?url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&description=' . rawurlencode( $post->post_title ) . '&media=' . rawurlencode( esc_url_raw( $this->get_post_image( $post->post_content ) ) ) ); 
    11411147         
    11421148        // Record stats 
Note: See TracChangeset for help on using the changeset viewer.