|
<?php |
|
/** |
|
* Wrapper function for social links. |
|
* |
|
* @param string $url URL for the link's href value. |
|
* @param string $media Name of social network. |
|
* @return string Onclick attribute for sharing links. |
|
*/ |
|
function xx_social_link_wrapper( $url = FALSE, $media = FALSE ) { |
|
if ( ! $url ) |
|
return; |
|
|
|
switch( $media ) { |
|
case 'facebook' : |
|
$options = "'facebook-share-dialog', 'width=626,height=436'"; |
|
default : |
|
$options = "'', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600'"; |
|
} |
|
return "onclick=\"window.open( {$url}, {$options} ); return false;\""; |
|
} |
|
|
|
/** |
|
* Generate social sharing links |
|
* |
|
* @param string $media Name of social network. |
|
* @param string $url Sharing URL. |
|
* @param string $title Title to be used for sharing purposes. |
|
* @return string Formatted sharing link attributes. |
|
*/ |
|
function xx_social_share_link( $media, $url = FALSE, $title = FALSE ) { |
|
$url = "encodeURIComponent('" . ( $url ? $url : get_the_permalink() ) . "')"; |
|
$title = "encodeURIComponent('" . ( $title ? $title : get_the_title() ) . "')"; |
|
$img = "encodeURIComponent('" . ( get_the_post_thumbnail() ? get_the_post_thumbnail_url( get_the_ID(), 'large' ) : '' ) . "')"; |
|
|
|
switch( $media ) { |
|
case 'facebook' : |
|
return xx_social_link_wrapper( "'https://www.facebook.com/sharer/sharer.php?u='+{$url}", 'facebook' ); |
|
case 'twitter' : |
|
return xx_social_link_wrapper( "'https://twitter.com/home?status='+{$title}+'%20'+{$url}" ); |
|
case 'pinterest' : |
|
return xx_social_link_wrapper( "'https://pinterest.com/pin/create/button/?url='+{$url}+'&media='+{$img}+'&description='+{$title}" ); |
|
case 'google' : |
|
return xx_social_link_wrapper( "'https://plus.google.com/share?url='+{$url}" ); |
|
default : |
|
return; |
|
} |
|
} |