1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-20 21:32:09 +02:00

Social plugin now provides social share links in admin after creating/updating a news item.

This commit is contained in:
Cameron
2018-02-08 15:43:38 -08:00
parent 986aabb062
commit e045c6c91c
4 changed files with 149 additions and 37 deletions

View File

@@ -6,7 +6,9 @@
class social_admin
{
private $twitterActive = false;
private $_twitter_active = false;
private $_default_providers = array('facebook-share'=>'fa-facebook', 'twitter'=>'fa-twitter');
function __construct()
@@ -15,7 +17,7 @@ class social_admin
if(!empty($pref) && !empty($pref['Twitter']) && is_array($pref['Twitter']))
{
$this->twitterActive = vartrue($pref['Twitter']['keys']['key']);
$this->_twitter_active = vartrue($pref['Twitter']['keys']['key']);
}
}
@@ -39,7 +41,7 @@ class social_admin
case "page":
case "news":
if($this->twitterActive == true)
if($this->_twitter_active == true)
{
$config['fields']['twitter'] = array ( 'title' =>LAN_SOCIAL_202, 'type' => 'text', 'tab'=>2, 'writeParms'=> array('size'=>'xxlarge', 'placeholder'=>LAN_SOCIAL_203), 'width' => 'auto', 'help' => '', 'readParms' => '', 'class' => 'left', 'thclass' => 'left', );
}
@@ -57,22 +59,98 @@ class social_admin
* Process Posted Data.
* @param $ui admin-ui object
*/
public function process($ui, $id=0)
public function process(e_admin_ui $ui, $id=0)
{
$data = $ui->getPosted();
$data = $ui->getPosted();
$action = $ui->getAction(); // current mode: create, edit, list
$type = $ui->getEventName(); // eg. 'news'
$changed = $ui->getModel()->dataHasChanged();
$tp = e107::getParser();
//e107::getHybridAuth('twitter');
e107::getMessage()->addDebug("e107_plugins/social/e_admin.php :: process method called.");
e107::getMessage()->addDebug("ID: ".$id);
e107::getMessage()->addDebug("Action: ".$action);
e107::getMessage()->addDebug(print_a($data,true));
// e107::getMessage()->addDebug("e107_plugins/social/e_admin.php :: process method called.");
// e107::getMessage()->addDebug("ID: ".$id);
// e107::getMessage()->addDebug("Action: ".$action);
// e107::getMessage()->addDebug(print_a($data,true));
if($changed === false || $type !== 'news' || intval($data['news_class']) !== e_UC_PUBLIC) // social links only when item is public.
{
return null;
}
if($action === 'create' || $action === 'edit')
{
$data['news_id'] = $id;
$shareData = array(
'title' => $data['news_title'],
'url' => e107::getUrl()->create('news/view/item', $data, 'full=1'),
'hashtags' => $data['news_meta_keywords']
);
$message = '
<div class="well social-plugin" style="width:450px">
<div class="media">
<div class="media-left">'.$tp->toImage($data['news_thumbnail'][0], array('w'=>100, 'h'=>100, 'class'=>'media-object')).'</div>
<div class="media-body">
<h4 class="media-header">'.$data['news_title'].'</h4>
<p><small>'.$data['news_meta_description']."</small></p>".$this->share($shareData).'
</div>
</div>
</div>
';
//FIXME setTitle doesn't work across sessions.
e107::getMessage()->setTitle(LAN_PLUGIN_SOCIAL_NAME." (".LAN_OPTIONAL.")",E_MESSAGE_INFO)->addInfo($message);
}
}
/**
* Build social share links for the admin area.
* @param $data
* @return string
*/
private function share($data)
{
// $pref = e107::pref('social');
$soc = e107::getScBatch('social');
$tp = e107::getParser();
$providers = /*!empty($pref['sharing_providers']) ? array_keys($pref['sharing_providers']) :*/ $this->_default_providers;
$links = array();
$allProviders = $soc->getProviders();
$options = array(
'twitterAccount' => basename(XURL_TWITTER),
'hashtags' => $data['hashtags']
);
foreach($allProviders as $key=>$row)
{
if(!array_key_exists($key,$providers))
{
continue;
}
$shareURL = $soc->getShareUrl($key, $row['url'], $data, $options);
$links[] = "<a class='btn btn-primary btn-xs' target='_blank' href='".$shareURL."'>".$tp->toGlyph($providers[$key]).$row['title']."</a>";
}
return implode(" ",$links);
}
}
?>