2014-01-14 11:20:10 -08:00
< ? php
/*
* Copyright ( c ) e107 Inc e107 . org , Licensed under GNU GPL ( http :// www . gnu . org / licenses / gpl . txt )
* $Id : e_shortcode . php 12438 2011 - 12 - 05 15 : 12 : 56 Z secretr $
*
* Featurebox shortcode batch class - shortcodes available site - wide . ie . equivalent to multiple . sc files .
*/
if ( ! defined ( 'e107_INIT' )) { exit ; }
2014-02-18 12:58:03 -08:00
2014-01-14 11:20:10 -08:00
class social_shortcodes extends e_shortcode
{
2015-04-10 01:38:22 -07:00
public function getProviders ()
{
$emailMessage = " Check out this link: " ; //TODO LAN
//TODO LANS ie. "Share on [x]" in English_global.php
$providers = array (
2015-06-07 18:47:51 -07:00
'email' => array ( 'icon' => 'e-social-mail' , 'title' => " Email to someone " , 'url' => " mailto:EMAIL_RECIPIENT?subject=[t]&body= " . rawurlencode ( $emailMessage ) . " [u] " ),
2015-04-10 01:38:22 -07:00
'facebook-like' => array ( 'icon' => 'e-social-thumbs-up' , 'title' => " Like on Facebook " , 'url' => " http://www.facebook.com/plugins/like.php?href=[u] " ),
'facebook-share' => array ( 'icon' => 'e-social-facebook' , 'title' => " Share on Facebook " , 'url' => " http://www.facebook.com/sharer.php?u=[u]&t=[t] " ),
'twitter' => array ( 'icon' => 'e-social-twitter' , 'title' => " Share on Twitter " , 'url' => " http://twitter.com/share?url=[u]&text=[t] " ),
'google-plus1' => array ( 'icon' => 'e-social-gplus' , 'title' => " +1 on Google " , 'url' => " https://apis.google.com/_/+1/fastbutton?usegapi=1&size=large&hl=en&url=[u] " ),
// 'google-plus' => array('icon' => 'fa-google-plus', 'title'=>"On Google Plus", 'url' => "https://plusone.google.com/_/+1/confirm?hl=en&url=[u]"),
'linkedin' => array ( 'icon' => 'e-social-linkedin' , 'title' => " Share on LinkedIn " , 'url' => " http://www.linkedin.com/shareArticle?mini=true&url=[u] " ),
'pinterest' => array ( 'icon' => 'e-social-pinterest' , 'title' => " Share on Pinterest " , 'url' => " http://www.pinterest.com/pin/create/button/?url=[u]&description=[t]&media=[m] " ),
// 'thumblr' => array('icon' => 'fa-tumblr', 'title'=>"On Tumblr", 'url' => "http://www.tumblr.com/share/link?url=[u]&name=[t]&description=[d]"),
'stumbleupon' => array ( 'icon' => 'e-social-stumbleupon' , 'title' => " Share on StumbleUpon " , 'url' => " http://www.stumbleupon.com/submit?url=[u]&title=[t] " ),
'reddit' => array ( 'icon' => 'e-social-reddit' , 'title' => " Share on Reddit " , 'url' => " http://reddit.com/submit?url=[u]&title=[t] " ),
'digg' => array ( 'icon' => 'e-social-digg' , 'title' => " Share on Digg " , 'url' => " http://www.digg.com/submit?url=[u] " ),
//http://reddit.com/submit?url=http%3A%2F%2Fwebsite.com&title=Website%20Title // no fa icon available
//http://www.digg.com/submit?url=http%3A%2F%2Fwebsite.com // no fa icon available
);
return $providers ;
}
2014-01-23 09:18:40 -08:00
2014-02-18 12:58:03 -08:00
public $var ;
2014-01-23 09:18:40 -08:00
/**
* { XURL_ICONS : size = 2 x }
*/
2014-01-14 11:20:10 -08:00
function sc_xurl_icons ( $parm = '' )
{
$social = array (
2015-04-14 15:26:26 -07:00
'rss' => array ( 'href' => ( e107 :: isInstalled ( 'rss_menu' ) ? e107 :: url ( 'rss_menu' , 'index' , array ( 'rss_url' => 'news' )) : '' ), 'title' => 'RSS/Atom Feed' ),
2014-01-14 11:20:10 -08:00
'facebook' => array ( 'href' => deftrue ( 'XURL_FACEBOOK' ), 'title' => 'Facebook' ),
'twitter' => array ( 'href' => deftrue ( 'XURL_TWITTER' ), 'title' => 'Twitter' ),
2014-01-29 11:10:05 -08:00
'google-plus' => array ( 'href' => deftrue ( 'XURL_GOOGLE' ), 'title' => 'Google Plus' ),
2014-01-14 11:20:10 -08:00
'linkedin' => array ( 'href' => deftrue ( 'XURL_LINKEDIN' ), 'title' => 'LinkedIn' ),
2014-08-10 16:29:51 +02:00
'github' => array ( 'href' => deftrue ( 'XURL_GITHUB' ), 'title' => 'Github' ),
2014-01-14 11:20:10 -08:00
'pinterest' => array ( 'href' => deftrue ( 'XURL_PINTEREST' ), 'title' => 'Pinterest' ),
2014-08-10 16:29:51 +02:00
'flickr' => array ( 'href' => deftrue ( 'XURL_FLICKR' ), 'title' => 'Flickr' ),
2014-01-14 11:20:10 -08:00
'instagram' => array ( 'href' => deftrue ( 'XURL_INSTAGRAM' ), 'title' => 'Instagram' ),
'youtube' => array ( 'href' => deftrue ( 'XURL_YOUTUBE' ), 'title' => 'YouTube' ),
'vimeo' => array ( 'href' => deftrue ( 'XURL_VIMEO' ), 'title' => 'Vimeo' )
);
2014-01-15 11:04:44 -08:00
2014-01-14 11:20:10 -08:00
2014-01-15 11:04:44 -08:00
$class = ( vartrue ( $parm [ 'size' ])) ? 'fa-' . $parm [ 'size' ] : '' ;
2014-01-14 11:20:10 -08:00
$text = '' ;
foreach ( $social as $id => $data )
{
if ( $data [ 'href' ] != '' )
{
2016-03-09 20:33:59 -08:00
$text .= '<a rel="external" href="' . $data [ 'href' ] . '" class="e-tip social-icon social-' . $id . '" title="' . $data [ 'title' ] . '"><span class="fa fa-' . $id . ' ' . $class . '"></span></a>' ;
$text .= " \n " ;
2014-01-14 11:20:10 -08:00
}
}
if ( $text != '' )
{
2016-01-17 16:24:54 -08:00
return '<p class="xurl-social-icons hidden-print">' . $text . '</p>' ;
2014-01-14 11:20:10 -08:00
}
}
2015-02-05 16:24:54 -08:00
function sc_social_login ( $parm = null )
{
$pref = e107 :: pref ( 'core' , 'social_login_active' );
if ( empty ( $pref ))
{
return ;
}
$sc = e107 :: getScBatch ( 'signup' );
2015-04-04 12:54:34 -07:00
$text = " <p>Sign in with:</p> " ;
2015-02-05 16:24:54 -08:00
$text .= $sc -> sc_signup_xup_login ( $parm );
$text .= "
< div class = 'clearfix' ></ div >< hr class = 'clearfix' /> " ;
return $text ;
}
2014-01-23 09:18:40 -08:00
2015-06-07 19:45:19 -07:00
private function getHashtags ( $extraTags = '' )
{
$hashtags = e107 :: pref ( 'social' , 'sharing_hashtags' , '' );
$hashtags = str_replace ( array ( " " , '#' ), " " , $hashtags );
$ret = explode ( ',' , $hashtags );
if ( ! empty ( $extraTags ))
{
$extraTags = str_replace ( array ( " " , '#' ), " " , $extraTags );
$tmp = explode ( ',' , $extraTags );
foreach ( $tmp as $v )
{
$ret [] = $v ;
}
}
if ( ! empty ( $ret ))
{
return implode ( ',' , $ret );
}
}
2014-01-23 09:18:40 -08:00
/**
* { SOCIALSHARE : url = x & title = y }
2014-02-18 12:58:03 -08:00
* @ example { SOCIALSHARE : type = basic } - Show only Email , Facebook , Twitter and Google .
* @ example { SOCIALSHARE : dropdown = 1 & type = basic } - Show only Email , Facebook , Twitter and Google in a drop - down button
* @ example for plugin developers : send 'var' values for use by the social shortcode . ( useful for loops where the value must change regularly )
* $socialArray = array ( 'url' => 'your-url-here' , 'title' => 'your-title-here' );
e107 :: getScBatch ( 'social' ) -> setVars ( $socialArray );
2014-01-23 09:18:40 -08:00
*/
function sc_socialshare ( $parm = '' ) // Designed so that no additional JS required.
2015-04-10 01:38:22 -07:00
{
$pref = e107 :: pref ( 'social' );
if ( varset ( $pref [ 'sharing_mode' ]) == 'off' )
{
return '' ;
}
2015-06-07 19:45:19 -07:00
// $hashtags = vartrue($pref['sharing_hashtags']);
2015-04-10 01:38:22 -07:00
2014-02-18 12:58:03 -08:00
$defaultUrl = vartrue ( $this -> var [ 'url' ], e_REQUEST_URL );
$defaultTitle = vartrue ( $this -> var [ 'title' ], deftrue ( 'e_PAGETITLE' ) . " | " . SITENAME );
$defaultDiz = vartrue ( $this -> var [ 'description' ], e107 :: getUrl () -> response () -> getMetaDescription ());
2015-06-08 00:12:19 -07:00
$defaultTags = vartrue ( $this -> var [ 'tags' ], '' );
2014-02-18 12:58:03 -08:00
2014-01-23 09:18:40 -08:00
$tp = e107 :: getParser ();
2015-04-10 01:38:22 -07:00
$providers = $this -> getProviders ();
if ( empty ( $parm )) // No parms so use prefs instead.
{
$parm [ 'dropdown' ] = ( $pref [ 'sharing_mode' ] == 'dropdown' ) ? 1 : 0 ;
$parm [ 'providers' ] = ! empty ( $pref [ 'sharing_providers' ]) ? array_keys ( $pref [ 'sharing_providers' ]) : array_keys ( $providers );
}
else
{
$parm [ 'providers' ] = array_keys ( $providers );
}
2014-02-18 12:58:03 -08:00
$url = varset ( $parm [ 'url' ], $defaultUrl );
$title = varset ( $parm [ 'title' ], $defaultTitle ) ;
$description = varset ( $parm [ 'title' ], $defaultDiz );
2015-06-08 00:12:19 -07:00
$tags = varset ( $parm [ 'tags' ], $defaultTags );
2014-01-23 09:18:40 -08:00
$media = " " ;
2014-02-18 12:58:03 -08:00
$label = varset ( $parm [ 'label' ], $tp -> toGlyph ( 'e-social-spread' ));
2014-01-23 09:18:40 -08:00
2014-02-18 12:58:03 -08:00
$size = varset ( $parm [ 'size' ], 'md' );
2015-06-08 00:12:19 -07:00
2015-06-07 19:45:19 -07:00
2015-04-09 20:15:20 -07:00
2015-04-10 01:38:22 -07:00
2014-01-23 09:18:40 -08:00
$data = array ( 'u' => rawurlencode ( $url ), 't' => rawurlencode ( $title ), 'd' => rawurlencode ( $description ), 'm' => rawurlencode ( $media ));
if ( ! vartrue ( $parm [ 'dropdown' ]))
{
$butSize = ( $size == 'lg' || $size == 'sm' || $size == 'xs' ) ? 'btn-' . $size : '' ;
}
else
{
2014-01-25 05:18:31 -08:00
$butSize = 'btn-social' ;
2014-01-23 09:18:40 -08:00
}
2015-05-11 14:06:31 -07:00
2014-01-23 09:18:40 -08:00
$opt = array ();
2015-05-11 14:06:31 -07:00
2015-06-07 19:45:19 -07:00
// $hashtags = '';
// $hashtags .= str_replace(array(" ",'#'),"", $hashtags); // "#mytweet";
$hashtags = $this -> getHashtags ( $tags );
2015-05-11 14:06:31 -07:00
$twitterAccount = basename ( XURL_TWITTER );
// return print_a($hashtags,true);
2014-02-18 12:58:03 -08:00
foreach ( $providers as $k => $val )
2014-01-23 09:18:40 -08:00
{
2015-04-10 01:38:22 -07:00
if ( ! in_array ( $k , $parm [ 'providers' ]))
{
continue ;
}
2014-01-23 17:24:02 -08:00
$pUrl = str_replace ( " & " , " & " , $val [ 'url' ]);
2015-05-11 14:06:31 -07:00
2014-01-23 17:24:02 -08:00
$shareUrl = $tp -> lanVars ( $pUrl , $data );
2015-05-11 14:06:31 -07:00
if ( $k == 'twitter' )
{
if ( ! empty ( $hashtags ))
{
$shareUrl .= " &hashtags= " . rawurlencode ( $hashtags );
}
if ( ! empty ( $twitterAccount ))
{
$shareUrl .= " &via= " . $twitterAccount ;
}
}
2014-01-23 09:18:40 -08:00
2014-02-18 12:58:03 -08:00
$opt [ $k ] = " <a class='e-tip btn " . $butSize . " btn-default social-share' target='_blank' title=' " . $val [ " title " ] . " ' href=' " . $shareUrl . " '> " . $tp -> toIcon ( $val [ " icon " ]) . " </a> " ;
2014-01-23 09:18:40 -08:00
}
2014-02-18 12:58:03 -08:00
// Show only Email, Facebook, Twitter and Google.
if ( varset ( $parm [ 'type' ]) == 'basic' )
{
$remove = array ( 'linkedi' , 'pinterest' , 'stumbleupon' , 'digg' , 'reddit' , 'linkedin' );
foreach ( $remove as $v )
{
unset ( $opt [ $v ]);
}
}
2014-01-23 09:18:40 -08:00
if ( vartrue ( $parm [ 'dropdown' ]))
{
$dir = ( $parm [ 'dropdown' ] == 'right' ) ? 'pull-right' : '' ;
2016-03-09 20:33:59 -08:00
$class = varset ( $parm [ 'class' ], 'btn-group' );
2016-01-17 16:24:54 -08:00
$text = '<div class="btn-group hidden-print ' . $dir . ' " >
2014-01-25 05:32:40 -08:00
< a class = " e-tip btn btn-dropdown btn-default btn-'. $size .' dropdown-toggle " data - toggle = " dropdown " href = " # " title = " Share " > '.$label.' </ a >
2014-01-23 09:18:40 -08:00
2015-04-09 20:15:20 -07:00
< ul class = " dropdown-menu " role = " menu " style = " min-width:435px " >
2014-01-23 09:18:40 -08:00
2016-03-09 20:33:59 -08:00
< li >< div class = " '. $class .' " style = " padding-left: 7px; " > '.implode("\n",$opt).' </ div ></ li >
2014-01-23 09:18:40 -08:00
</ ul >
</ div > ' ;
return $text ;
}
else
{
2016-03-09 20:33:59 -08:00
$class = varset ( $parm [ 'class' ], 'btn-group' );
return '<div class="' . $class . ' text-center hidden-print">' . implode ( " \n " , $opt ) . " </div> " ;
2014-01-23 09:18:40 -08:00
}
}
2014-02-05 06:17:41 -08:00
/**
* @ example { TWITTER_TIMELINE : id = xxxxxxx & theme = light }
*/
function sc_twitter_timeline ( $parm )
{
$ns = e107 :: getRender ();
2015-05-11 14:06:31 -07:00
$account = basename ( XURL_TWITTER );
2014-02-05 06:17:41 -08:00
//data-related="twitterapi,twitter"
$text = '<a class="twitter-timeline" href="' . XURL_TWITTER . '" data-widget-id="' . varset ( $parm [ 'id' ]) . '" data-theme="' . varset ( $parm [ 'theme' ], 'light' ) . '" data-link-color="#cc0000" data-aria-polite="assertive" width="100%" height="' . varset ( $parm [ 'height' ], 300 ) . '" lang="' . e_LAN . '">Tweets by @' . $account . '</a>' ;
2014-01-23 09:18:40 -08:00
2014-02-05 06:17:41 -08:00
$text .= <<< TMPL
< script >! function ( d , s , id ){ var js , fjs = d . getElementsByTagName ( s )[ 0 ], p =/^ http :/. test ( d . location ) ? 'http' : 'https' ; if ( ! d . getElementById ( id )){ js = d . createElement ( s ); js . id = id ; js . src = p + " ://platform.twitter.com/widgets.js " ; fjs . parentNode . insertBefore ( js , fjs );}}( document , " script " , " twitter-wjs " ); </ script >
TMPL ;
return ( vartrue ( $parm [ 'render' ])) ? $ns -> tablerender ( '' , $text , 'twitter-timeline' , true ) : $text ;
}
2014-01-23 09:18:40 -08:00
2014-01-14 11:20:10 -08:00
}
2014-01-23 09:18:40 -08:00
?>