From 1b86e2c8b5c621b1297322f05f7eab8dd44019d4 Mon Sep 17 00:00:00 2001 From: Cameron Date: Tue, 18 Feb 2014 12:58:03 -0800 Subject: [PATCH] News updated to support the {SOCIALSHARE} shortcode in its 'default' template. --- e107_plugins/news/templates/news_template.php | 2 +- e107_plugins/social/e_shortcode.php | 50 ++++++++++++++----- news.php | 10 ++++ 3 files changed, 48 insertions(+), 14 deletions(-) diff --git a/e107_plugins/news/templates/news_template.php b/e107_plugins/news/templates/news_template.php index b2a63a923..219a2e972 100644 --- a/e107_plugins/news/templates/news_template.php +++ b/e107_plugins/news/templates/news_template.php @@ -97,7 +97,7 @@ $NEWS_TEMPLATE['default']['item'] = ' {NEWSBODY}
-
{NEWSCOMMENTLINK: glyph=comments&class=btn btn-default}{EMAILICON: class=btn btn-default}{PRINTICON: class=btn btn-default}{PDFICON}{ADMINOPTIONS: class=btn btn-default}
+
{NEWSCOMMENTLINK: glyph=comments&class=btn btn-default}{PRINTICON: class=btn btn-default}{PDFICON}{SOCIALSHARE: type=basic}{ADMINOPTIONS: class=btn btn-default}
'; diff --git a/e107_plugins/social/e_shortcode.php b/e107_plugins/social/e_shortcode.php index ac7690f99..d8715bf47 100644 --- a/e107_plugins/social/e_shortcode.php +++ b/e107_plugins/social/e_shortcode.php @@ -8,10 +8,13 @@ if (!defined('e107_INIT')) { exit; } + + + class social_shortcodes extends e_shortcode { - + public $var; /** * {XURL_ICONS: size=2x} */ @@ -66,18 +69,27 @@ class social_shortcodes extends e_shortcode /** * {SOCIALSHARE: url=x&title=y} + * @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); */ function sc_socialshare($parm='') // Designed so that no additional JS required. - { - - $tp = e107::getParser(); - $url = varset($parm['url'], e_REQUEST_URL); - $title = varset($parm['title'], deftrue('e_PAGETITLE'). " | ". SITENAME ) ; - $description = varset($parm['title'], e107::getUrl()->response()->getMetaDescription()); - $media = ""; - $label = varset($parm['label'], $tp->toGlyph('e-social-spread')); + { + $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()); - $size = varset($parm['size'],'md'); + $tp = e107::getParser(); + + $url = varset($parm['url'], $defaultUrl); + $title = varset($parm['title'], $defaultTitle) ; + $description = varset($parm['title'], $defaultDiz); + $media = ""; + $label = varset($parm['label'], $tp->toGlyph('e-social-spread')); + + $size = varset($parm['size'], 'md'); //TODO LANS ie. "Share on [x]" in English_global.php @@ -116,15 +128,24 @@ class social_shortcodes extends e_shortcode $opt = array(); - foreach($providers as $val) + foreach($providers as $k=>$val) { $pUrl = str_replace("&","&",$val['url']); $shareUrl = $tp->lanVars($pUrl,$data); - $opt[] = "".$tp->toIcon($val["icon"]).""; + $opt[$k] = "".$tp->toIcon($val["icon"]).""; } + // 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]); + } + } if(vartrue($parm['dropdown'])) { @@ -144,7 +165,10 @@ class social_shortcodes extends e_shortcode else { - return '
'.implode("\n",$opt)."
"; + + + + return '
'.implode("\n",$opt)."
"; } diff --git a/news.php b/news.php index 27315e7a2..e772b59d5 100644 --- a/news.php +++ b/news.php @@ -820,11 +820,18 @@ else { $news = $newsAr[$i]; + // Set the Values for the social shortcode usage. + $socialArray = array('url'=>e107::getUrl()->create('news/view/item', $news, 'full=1'), 'title'=>$tp->toText($news['news_title'])); + e107::getScBatch('social')->setVars($socialArray); + + + if(function_exists("news_style")) // BC { $template = news_style($news, $action, $param); } + // render new date header if pref selected ... $thispostday = strftime("%j", $news['news_datestamp']); if ($newpostday != $thispostday && (isset($pref['news_newdateheader']) && $pref['news_newdateheader'])) @@ -839,6 +846,9 @@ else } // $template = false; $ix->render_newsitem($news, 'default', '', $template, $param); + + + $i++; }