1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 20:00:37 +02:00

Social plugin: Twitter menu and Facebook comments engine added.

This commit is contained in:
Cameron
2015-04-08 16:24:58 -07:00
parent 1bc43a35ff
commit 74e8551cb4
5 changed files with 299 additions and 3 deletions

View File

@@ -3259,7 +3259,7 @@ if (!getperms('P'))
class ".$thePlugin."_admin extends e_admin_dispatcher
class ".$thePlugin."_adminArea extends e_admin_dispatcher
{
protected \$modes = array(
@@ -3572,7 +3572,7 @@ $text .= "
} // End LOOP.
$text .= '
new '.$thePlugin.'_admin();
new '.$thePlugin.'_adminArea();
require_once(e_ADMIN."auth.php");
e107::getAdminUI()->runPage();

View File

@@ -0,0 +1,157 @@
<?php
// Generated e107 Plugin Admin Area
require_once('../../class2.php');
if (!getperms('P'))
{
header('location:'.e_BASE.'index.php');
exit;
}
class social_adminarea extends e_admin_dispatcher
{
protected $modes = array(
'main' => array(
'controller' => 'social_ui',
'path' => null,
'ui' => 'social_form_ui',
'uipath' => null
),
);
protected $adminMenu = array(
// 'main/list' => array('caption'=> LAN_MANAGE, 'perm' => 'P'),
// 'main/create' => array('caption'=> LAN_CREATE, 'perm' => 'P'),
'main/prefs' => array('caption'=> LAN_PREFS, 'perm' => 'P'),
// 'main/custom' => array('caption'=> 'Custom Page', 'perm' => 'P')
);
protected $adminMenuAliases = array(
'main/edit' => 'main/list'
);
protected $menuTitle = 'social';
}
class social_ui extends e_admin_ui
{
protected $pluginTitle = 'Social';
protected $pluginName = 'social';
// protected $eventName = 'social-social'; // remove comment to enable event triggers in admin.
// protected $table = 'social';
// protected $pid = 'interview_id';
protected $perPage = 10;
protected $batchDelete = true;
// protected $batchCopy = true;
// protected $sortField = 'somefield_order';
// protected $orderStep = 10;
// protected $tabs = array('Tabl 1','Tab 2'); // Use 'tab'=>0 OR 'tab'=>1 in the $fields below to enable.
// protected $listQry = "SELECT * FROM `#tableName` WHERE field != '' "; // Example Custom Query. LEFT JOINS allowed. Should be without any Order or Limit.
protected $listOrder = '';
protected $fields = array();
protected $fieldpref = array();
protected $preftabs = array('Twitter Menu');
protected $prefs = array(
'twitter_menu_height' => array('title'=> 'Height', 'type'=>'number', 'tab'=>0, 'data' => 'int','help'=>'Height in px'),
'twitter_menu_limit' => array('title'=> 'Limit', 'type'=>'number', 'tab'=>0, 'data' => 'int','help'=>'Number of tweets to display.'),
);
public function init()
{
// print_a($this->fields);
}
// ------- Customize Create --------
public function beforeCreate($new_data)
{
return $new_data;
}
public function afterCreate($new_data, $old_data, $id)
{
// do something
}
public function onCreateError($new_data, $old_data)
{
// do something
}
// ------- Customize Update --------
public function beforeUpdate($new_data, $old_data, $id)
{
return $new_data;
}
public function afterUpdate($new_data, $old_data, $id)
{
// do something
}
public function onUpdateError($new_data, $old_data, $id)
{
// do something
}
/*
// optional - a custom page.
public function customPage()
{
$ns = e107::getRender();
$text = 'Hello World!';
$ns->tablerender('Hello',$text);
}
*/
}
class social_form_ui extends e_admin_form_ui
{
}
new social_adminarea();
require_once(e_ADMIN."auth.php");
e107::getAdminUI()->runPage();
require_once(e_ADMIN."footer.php");
exit;
?>

View File

@@ -0,0 +1,93 @@
<?php
/**
* e107 website system
*
* Copyright (C) 2008-2015 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
*/
class social_comment
{
private $facebookActive;
function __construct()
{
$social = e107::pref('core','social_login');
$this->facebookActive = vartrue($social['Facebook']['keys']['id']);
}
public function config() // Admin Area Configuration.
{
$engine = e107::pref('core','comments_engine','e107');
if($engine == 'social::facebook' && empty($this->facebookActive))
{
e107::getMessage()->addInfo("Facebook comments requires that you have a facebook App ID. See the 'social login' area in admin-preferences to add one.");
}
$config = array();
$config[] = array('name' => "Facebook", 'function'=>'facebook');
return $config;
}
function facebook($data)
{
if(empty($this->facebookActive))
{
return "<div class='alert alert-important alert-danger'>Unable to render comments. Missing Facebook appID.</div>";
}
$head = "
window.fbAsyncInit = function() {
FB.init({
appId : '".$this->facebookActive."',
xfbml : true,
version : 'v2.3'
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = '//connect.facebook.net/en_US/sdk.js';
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
";
e107::js('footer-inline', $head);
if(E107_DEBUG_LEVEL > 0)
{
$link = "http://developers.facebook.com/docs/plugins/comments/";
}
else
{
$link = e_REQUEST_URL;
}
//TODO Consider adding prefs to colorscheme and number of posts to the social admin area.
$text = '<div class="fb-comments" data-href="'.$link.'" data-width="100%" data-numposts="10" data-colorscheme="light">Loading...</div>';
return $text;
}
}

View File

@@ -1,4 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<e107Plugin name="Social" version="1.0" date="2012-12-01" compatibility="2.0" installRequired="false" >
<category>menu</category>
<category>misc</category>
<adminLinks>
<link url="admin_config.php" description="" icon="" iconSmall="" primary="true" >LAN_CONFIGURE</link>
</adminLinks>
</e107Plugin>

View File

@@ -0,0 +1,43 @@
<?php
/**
* e107 website system
*
* Copyright (C) 2008-2015 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
*/
//@see https://dev.twitter.com/web/embedded-timelines
if(deftrue('XURL_TWITTER'))
{
e107::js('footer-inline', '
!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");
');
$pref = e107::pref('social');
$screenName = basename(XURL_TWITTER);
$limit = vartrue($pref['twitter_menu_limit'], 5);
$height = vartrue($pref['twitter_menu_height'], 600);
$theme = vartrue($pref['twitter_menu_theme'], 'light');
$widgetId = '585932823665647616'; //@e107
$text = '<a class="twitter-timeline" data-theme="'.$theme.'" href="'.XURL_TWITTER.'" data-tweet-limit="'.$limit.'" data-widget-id="'.$widgetId.'" height="'.$height.'" data-screen-name="'.$screenName.'" data-chrome="noheader nofooter transparent noscrollbar">Tweets by @'.$screenName.'</a>';
e107::getRender()->tablerender('Twitter',$text,'twitter-menu');
}elseif(ADMIN)
{
$text = "<div class='alert alert-danger'>Unable to display feed. Twitter URL has not been defined in preferences.</div>";
e107::getRender()->tablerender('Twitter',$text,'twitter-menu');
}