mirror of
https://github.com/e107inc/e107.git
synced 2025-01-17 20:58:30 +01:00
Social plugin now provides social share links in admin after creating/updating a news item.
This commit is contained in:
parent
986aabb062
commit
e045c6c91c
@ -11,7 +11,7 @@ class _blank_admin
|
|||||||
* @param $ui admin-ui object
|
* @param $ui admin-ui object
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function config($ui)
|
public function config(e_admin_ui $ui)
|
||||||
{
|
{
|
||||||
$action = $ui->getAction(); // current mode: create, edit, list
|
$action = $ui->getAction(); // current mode: create, edit, list
|
||||||
$type = $ui->getEventName(); // 'wmessage', 'news' etc. (core or plugin)
|
$type = $ui->getEventName(); // 'wmessage', 'news' etc. (core or plugin)
|
||||||
@ -41,19 +41,20 @@ class _blank_admin
|
|||||||
* @param object $ui admin-ui
|
* @param object $ui admin-ui
|
||||||
* @param int|array $id - Primary ID of the record being created/edited/deleted or array data of a batch process.
|
* @param int|array $id - Primary ID of the record being created/edited/deleted or array data of a batch process.
|
||||||
*/
|
*/
|
||||||
public function process($ui, $id=0)
|
public function process(e_admin_ui $ui, $id=0)
|
||||||
{
|
{
|
||||||
|
|
||||||
$data = $ui->getPosted();
|
$data = $ui->getPosted(); // ie $_POST field-data
|
||||||
$type = $ui->getEventName();
|
$type = $ui->getEventName(); // eg. 'news'
|
||||||
$action = $ui->getAction(); // current mode: create, edit, list, batch
|
$action = $ui->getAction(); // current mode: create, edit, list, batch
|
||||||
|
$changed = $ui->getModel()->dataHasChanged(); // true when data has changed from what is in the DB.
|
||||||
|
|
||||||
if($action == 'delete')
|
if($action === 'delete')
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($action == 'batch')
|
if($action === 'batch')
|
||||||
{
|
{
|
||||||
$arrayOfRecordIds = $id['ids'];
|
$arrayOfRecordIds = $id['ids'];
|
||||||
$command = $id['cmd'];
|
$command = $id['cmd'];
|
||||||
@ -68,7 +69,7 @@ class _blank_admin
|
|||||||
if(!empty($data['x__blank_url']))
|
if(!empty($data['x__blank_url']))
|
||||||
{
|
{
|
||||||
|
|
||||||
// Save the data in 'blank' plugin table. .
|
// eg. Save the data in 'blank' plugin table. .
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,4 +87,3 @@ class _blank_admin
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
@ -6,7 +6,9 @@
|
|||||||
|
|
||||||
class social_admin
|
class social_admin
|
||||||
{
|
{
|
||||||
private $twitterActive = false;
|
private $_twitter_active = false;
|
||||||
|
|
||||||
|
private $_default_providers = array('facebook-share'=>'fa-facebook', 'twitter'=>'fa-twitter');
|
||||||
|
|
||||||
|
|
||||||
function __construct()
|
function __construct()
|
||||||
@ -15,7 +17,7 @@ class social_admin
|
|||||||
|
|
||||||
if(!empty($pref) && !empty($pref['Twitter']) && is_array($pref['Twitter']))
|
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 "page":
|
||||||
case "news":
|
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', );
|
$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.
|
* Process Posted Data.
|
||||||
* @param $ui admin-ui object
|
* @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
|
$action = $ui->getAction(); // current mode: create, edit, list
|
||||||
|
$type = $ui->getEventName(); // eg. 'news'
|
||||||
|
$changed = $ui->getModel()->dataHasChanged();
|
||||||
|
|
||||||
|
$tp = e107::getParser();
|
||||||
|
|
||||||
//e107::getHybridAuth('twitter');
|
//e107::getHybridAuth('twitter');
|
||||||
e107::getMessage()->addDebug("e107_plugins/social/e_admin.php :: process method called.");
|
// e107::getMessage()->addDebug("e107_plugins/social/e_admin.php :: process method called.");
|
||||||
e107::getMessage()->addDebug("ID: ".$id);
|
// e107::getMessage()->addDebug("ID: ".$id);
|
||||||
e107::getMessage()->addDebug("Action: ".$action);
|
// e107::getMessage()->addDebug("Action: ".$action);
|
||||||
e107::getMessage()->addDebug(print_a($data,true));
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
@ -17,6 +17,7 @@ class social_shortcodes extends e_shortcode
|
|||||||
public $var;
|
public $var;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function getProviders()
|
public function getProviders()
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -215,6 +216,55 @@ class social_shortcodes extends e_shortcode
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $type provider key. eg. facebook, twitter etc.
|
||||||
|
* @param string $urlScheme The URL scheme. @see getProviders 'url'
|
||||||
|
* @param array $data
|
||||||
|
* @param string $data['title'] Title for the URL
|
||||||
|
* @param string $data['description'] Description for the URL
|
||||||
|
* @param string $data['media']
|
||||||
|
* @param array $options Currently 'twitterAccount' and 'hashtags' are supported.
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getShareUrl($type, $urlScheme, $data=array(), $options=array())
|
||||||
|
{
|
||||||
|
$data = array('u'=> rawurlencode($data['url']), 't'=> rawurlencode($data['title']), 'd' => rawurlencode($data['description']), 'm' => rawurlencode($data['media']));
|
||||||
|
|
||||||
|
return $this->parseShareUrlScheme($type, $urlScheme, $data, $options);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $type
|
||||||
|
* @param string $providerUrlScheme
|
||||||
|
* @param array $data Array containing keys: 'u' (URL), 't' (Title), 'd' (Description)', 'm' (Media)
|
||||||
|
* @param array $options (optional) 'hashtags' and 'twitterAccount'
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function parseShareUrlScheme($type, $providerUrlScheme, $data=array(), $options=array())
|
||||||
|
{
|
||||||
|
$pUrl = str_replace("&","&",$providerUrlScheme);
|
||||||
|
|
||||||
|
$shareUrl = e107::getParser()->lanVars($pUrl,$data);
|
||||||
|
|
||||||
|
if($type === 'twitter')
|
||||||
|
{
|
||||||
|
if(!empty($options['hashtags']))
|
||||||
|
{
|
||||||
|
$shareUrl .= "&hashtags=".rawurlencode($options['hashtags']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!empty($options['twitterAccount']))
|
||||||
|
{
|
||||||
|
$shareUrl .= "&via=".$options['twitterAccount'];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return $shareUrl;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {SOCIALSHARE: url=x&title=y}
|
* {SOCIALSHARE: url=x&title=y}
|
||||||
* @example {SOCIALSHARE: type=basic} - Show only Email, Facebook, Twitter and Google.
|
* @example {SOCIALSHARE: type=basic} - Show only Email, Facebook, Twitter and Google.
|
||||||
@ -315,25 +365,7 @@ class social_shortcodes extends e_shortcode
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$shareUrl = $this->parseShareUrlScheme($k, $val['url'], $data, array('twitterAccount'=>$twitterAccount, 'hashtags'=>$hashtags));
|
||||||
|
|
||||||
$pUrl = str_replace("&","&",$val['url']);
|
|
||||||
|
|
||||||
$shareUrl = $tp->lanVars($pUrl,$data);
|
|
||||||
|
|
||||||
if($k == 'twitter')
|
|
||||||
{
|
|
||||||
if(!empty($hashtags))
|
|
||||||
{
|
|
||||||
$shareUrl .= "&hashtags=".rawurlencode($hashtags);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!empty($twitterAccount))
|
|
||||||
{
|
|
||||||
$shareUrl .= "&via=".$twitterAccount;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!empty($val['mobile']))
|
if(!empty($val['mobile']))
|
||||||
{
|
{
|
||||||
|
@ -514,10 +514,12 @@ i.s-message-warning { background-position: -777px -37px; width: 32px; height: 32
|
|||||||
i.s-message-info { background-position: -1480px 0; width: 32px; height: 32px; }
|
i.s-message-info { background-position: -1480px 0; width: 32px; height: 32px; }
|
||||||
i.s-message-debug { background-position: -1480px 0; width: 32px; height: 32px; }
|
i.s-message-debug { background-position: -1480px 0; width: 32px; height: 32px; }
|
||||||
|
|
||||||
|
.s-message .well { background-color: rgba(0,0,0,0.4) }
|
||||||
.s-message-body { padding-left: 42px; }
|
.s-message-body { padding-left: 42px; }
|
||||||
.s-message-item {}
|
.s-message-item {}
|
||||||
.s-message-item .btn { margin-top: 15px; }
|
.s-message-item .btn { margin-top: 15px; }
|
||||||
|
|
||||||
|
|
||||||
.e-footer-info { text-align: center }
|
.e-footer-info { text-align: center }
|
||||||
|
|
||||||
/* ************* Backwards Compatibility CSS *****************/
|
/* ************* Backwards Compatibility CSS *****************/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user