示例#1
0
 function onPrepareContent(&$article, &$params, $limitstart)
 {
     $app = JFactory::getApplication();
     if ($app->isAdmin()) {
         return;
     }
     //Get Social RenderKey
     jimport('joomla.filesystem.file');
     $libFile = JPATH_ROOT . DS . 'components' . DS . 'com_jfbconnect' . DS . 'libraries' . DS . 'facebook.php';
     if (!JFile::exists($libFile)) {
         return;
     }
     require_once $libFile;
     $jfbcLibrary = JFBConnectFacebookLibrary::getInstance();
     $renderKey = $jfbcLibrary->getSocialTagRenderKey();
     if ($renderKey) {
         $renderKeyString = " key=" . $renderKey;
     } else {
         $renderKeyString = "";
     }
     $configModel = $jfbcLibrary->getConfigModel();
     $showComments = $this->showSocialItemInArticle($article, $configModel->getSetting('social_comment_article_include_ids'), $configModel->getSetting('social_comment_article_exclude_ids'), $configModel->getSetting('social_comment_cat_include_type'), $configModel->getSetting('social_comment_cat_ids'), $configModel->getSetting('social_comment_sect_include_type'), $configModel->getSetting('social_comment_sect_ids'));
     $showLike = $this->showSocialItemInArticle($article, $configModel->getSetting('social_like_article_include_ids'), $configModel->getSetting('social_like_article_exclude_ids'), $configModel->getSetting('social_like_cat_include_type'), $configModel->getSetting('social_like_cat_ids'), $configModel->getSetting('social_like_sect_include_type'), $configModel->getSetting('social_like_sect_ids'));
     $view = JRequest::getVar('view');
     $showCommentsInView = $this->showSocialItemInView($article, $view, $configModel->getSetting('social_comment_article_view'), $configModel->getSetting('social_comment_frontpage_view'), $configModel->getSetting('social_comment_category_view'), $configModel->getSetting('social_comment_section_view'));
     $showLikeInView = $this->showSocialItemInView($article, $view, $configModel->getSetting('social_like_article_view'), $configModel->getSetting('social_like_frontpage_view'), $configModel->getSetting('social_like_category_view'), $configModel->getSetting('social_like_section_view'));
     if ($showComments == true && $showCommentsInView == true) {
         $showAtTop = $configModel->getSetting('social_comment_position');
         $width = $configModel->getSetting('social_comment_width');
         $numposts = $configModel->getSetting('social_comment_max_num');
         $colorscheme = $configModel->getSetting('social_comment_color_scheme');
         //Figure out href based on current page
         $href = plgContentJFBCContent::getCurrentArticleURL($article);
         $commentText = '{JFBCComments href=' . $href . ' width=' . $width . ' num_posts=' . $numposts . ' colorscheme=' . $colorscheme . $renderKeyString . '}';
         plgContentJFBCContent::addTextToArticle($article->text, $commentText, $showAtTop);
     }
     if ($showLike == true && $showLikeInView == true) {
         $showLikePosition = $configModel->getSetting('social_like_position');
         $buttonStyle = $configModel->getSetting('social_like_layout_style');
         $showFaces = $configModel->getSetting('social_like_show_faces');
         $width = $configModel->getSetting('social_like_width');
         $verbToDisplay = $configModel->getSetting('social_like_verb_to_display');
         $font = $configModel->getSetting('social_like_font');
         $colorScheme = $configModel->getSetting('social_like_color_scheme');
         $url = plgContentJFBCContent::getCurrentArticleURL($article);
         $likeText = '{JFBCLike layout=' . $buttonStyle . ' show_faces=' . $showFaces . ' width=' . $width . ' action=' . $verbToDisplay . ' font=' . $font . ' colorscheme=' . $colorScheme . ' url=' . $url . $renderKeyString . '}';
         plgContentJFBCContent::addTextToArticle($article->text, $likeText, $showLikePosition);
     }
     //Add first image from article if enabled
     $socialGraphEnabled = $configModel->getSetting('social_graph_enabled');
     $socialGraphFirstImage = $configModel->getSetting('social_graph_first_image');
     if ($socialGraphEnabled == "1" && $socialGraphFirstImage == "1" && $view == 'article') {
         $firstImage = $this->_getFirstImage($article->text);
         if ($firstImage != '') {
             $graphTag = '{JFBCGraph image=' . $firstImage . $renderKeyString . '}';
             plgContentJFBCContent::addTextToArticle($article->text, $graphTag, false);
         }
     }
 }
示例#2
0
 function __construct(&$subject, $params)
 {
     require_once JPATH_SITE . DS . 'components' . DS . 'com_jfbconnect' . DS . 'libraries' . DS . 'facebook.php';
     $this->jfbcLibrary = JFBConnectFacebookLibrary::getInstance();
     $this->configModel = $this->jfbcLibrary->getConfigModel();
     $this->profileName = $params['name'];
     $this->_db = JFactory::getDBO();
     parent::__construct($subject, $params);
 }
示例#3
0
 function onAfterRoute()
 {
     $app = JFactory::getApplication();
     if (!$app->isAdmin()) {
         jimport('joomla.filesystem.file');
         $libFile = JPATH_ROOT . DS . 'components' . DS . 'com_jfbconnect' . DS . 'libraries' . DS . 'facebook.php';
         if (!JFile::exists($libFile)) {
             return;
         }
         require_once $libFile;
         $this->jfbcLibrary = JFBConnectFacebookLibrary::getInstance();
     }
 }
示例#4
0
 function _sendEmail($subject, $body)
 {
     $jfbcLibrary = JFBConnectFacebookLibrary::getInstance();
     $configModel = $jfbcLibrary->getConfigModel();
     $toname = $configModel->getSetting('social_notification_email_address');
     $toname = explode(',', $toname);
     // Don't send emails to no one :)
     if ($toname[0] == "") {
         return;
     }
     $app =& JFactory::getApplication();
     $sitename = $app->getCfg('sitename');
     $mailfrom = $app->getCfg('mailfrom');
     $fromname = $app->getCfg('fromname');
     $subject = $subject . " - " . $sitename;
     JUtility::sendMail($mailfrom, $fromname, $toname, $subject, $body);
 }
示例#5
0
 function display($tpl = null)
 {
     $jfbcLibrary = JFBConnectFacebookLibrary::getInstance();
     $fbUserId = $jfbcLibrary->getUserId(FALSE);
     $fbUserProfile = $jfbcLibrary->_getUserName($fbUserId);
     $configModel = $jfbcLibrary->getConfigModel();
     if ($fbUserId == null) {
         $app = JFactory::getApplication();
         $app->redirect('index.php');
     }
     $app =& JFactory::getApplication();
     JPluginHelper::importPlugin('jfbcprofiles');
     $profileFields = $app->triggerEvent('jfbcProfilesOnShowRegisterForm');
     JHTML::_('behavior.mootools');
     $this->assignRef('fbClient', $fbClient);
     $this->assignRef('fbUserId', $fbUserId);
     $this->assignRef('fbUserProfile', $fbUserProfile);
     $this->assignRef('configModel', $configModel);
     $this->assignRef('profileFields', $profileFields);
     $this->assignRef('fbUserEmail', $this->_getDisplayEmail($fbUserProfile['email']));
     parent::display($tpl);
 }
示例#6
0
 function display($tpl = null)
 {
     require_once JPATH_COMPONENT_SITE . DS . 'libraries' . DS . 'facebook.php';
     require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'assets' . DS . 'sourcecoast.php';
     $jfbcLibrary = JFBConnectFacebookLibrary::getInstance();
     $configModel = $this->getModel();
     $usermapModel = $this->getModel('usermap');
     // TODO: In addition to just checking if the key is set, check if the connection to FB also works
     if ($jfbcLibrary->facebookApiKey) {
         $params = array('method' => 'admin.getAppProperties', 'properties' => array('application_name', 'description', 'connect_url', 'base_domain', 'logo_url'));
         $appProperties = $jfbcLibrary->rest($params, FALSE);
         /*
          require_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_jfbconnect'.DS.'helpers'.DS.'insightshelper.php');
          $jfbcInsights = new JFBConnectInsightsHelper();
          //$jfbcInsights->getStatTypes();
          $chartPageActiveUsers = $jfbcInsights->createChart('application_active_users', 'day');
         */
         $fql = "SELECT monthly_active_users, weekly_active_users, daily_active_users FROM application WHERE app_id=" . $jfbcLibrary->facebookAppId;
         $params = array('method' => 'fql.query', 'query' => $fql);
         $appStats = $jfbcLibrary->rest($params, FALSE);
         $appStats = $appStats[0];
         $appStats['monthly_active_users'] = $appStats['monthly_active_users'] != "" ? $appStats['monthly_active_users'] : "0";
         $appStats['weekly_active_users'] = $appStats['weekly_active_users'] != "" ? $appStats['weekly_active_users'] : "0";
         $appStats['daily_active_users'] = $appStats['daily_active_users'] != "" ? $appStats['daily_active_users'] : "0";
     } else {
         $appStats['monthly_active_users'] = "0";
         $appStats['weekly_active_users'] = "0";
         $appStats['daily_active_users'] = "0";
     }
     $this->versionChecker = new sourceCoastConnect('jfbconnect');
     $this->assignRef('configModel', $configModel);
     $this->assignRef('appProperties', $appProperties);
     $this->assignRef('clientError', $clientError);
     $this->assignRef('jfbcLibrary', $jfbcLibrary);
     $this->assignRef('usermapModel', $usermapModel);
     $this->assignRef('appStats', $appStats);
     parent::display($tpl);
 }
示例#7
0
 function onAuthenticate($credentials, $options, &$response)
 {
     # authentication via facebook for Joomla always uses the FB API and secret keys
     # When this is present, the user's FB uid is used to look up their Joomla uid and log that user in
     jimport('joomla.filesystem.file');
     $configFile = JPATH_ROOT . DS . 'administrator' . DS . 'components' . DS . 'com_jfbconnect' . DS . 'models' . DS . 'config.php';
     if (JFile::exists($configFile)) {
         include_once JPATH_ROOT . DS . 'administrator' . DS . 'components' . DS . 'com_jfbconnect' . DS . 'models' . DS . 'config.php';
         $configModel = new JFBConnectModelConfig();
         # always check the secret username and password to indicate this is a JFBConnect login
         #echo "Entering JFBConnectAuth<br>";
         if ($credentials['username'] != $configModel->getSetting('facebook_api_key') || $credentials['password'] != $configModel->getSetting('facebook_secret_key')) {
             $response->status = JAUTHENTICATE_STATUS_FAILURE;
             $response->error_message = 'Facebook authentication failed';
             return false;
         }
         #echo "Passed API/Secret key check, this is a FB login<br>";
         include_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jfbconnect' . DS . 'models' . DS . 'usermap.php';
         $userMapModel = new JFBConnectModelUserMap();
         include_once JPATH_ROOT . DS . 'components' . DS . 'com_jfbconnect' . DS . 'libraries' . DS . 'facebook.php';
         $fbClient = JFBConnectFacebookLibrary::getInstance();
         $fbUserId = $fbClient->getUserId(FALSE);
         $app =& JFactory::getApplication();
         #echo "Facebook user = "******"User is logged into FB<br>";
             # Test if user has a Joomla mapping
             $jUserId = $userMapModel->getJoomlaUserId($fbUserId);
             if ($jUserId) {
                 #echo "User has joomla mapping<br>";
                 $jUser = JUser::getInstance($jUserId);
                 if ($jUser->id == null) {
                     #echo "user NOT loaded, deleting";
                     $userMapModel->deleteMapping($fbUserId);
                     return false;
                 }
                 $isAllowed = true;
                 # Trigger the jfbcProfile onAuthenticate to see if the user is allowed to login
                 if ($jUser->block) {
                     $isAllowed = false;
                     $app->enqueueMessage(JText::_('E_NOLOGIN_BLOCKED'), 'error');
                 } else {
                     JPluginHelper::importPlugin('jfbcprofiles');
                     $args = array($jUserId, $fbUserId);
                     $responses = $app->triggerEvent('jfbcProfilesOnAuthenticate', $args);
                     $return = base64_decode(JRequest::getVar('return'));
                     $isAllowed = true;
                     foreach ($responses as $response) {
                         if (is_object($response) && !$response->status) {
                             $isAllowed = false;
                             $app->enqueueMessage($response->message, 'error');
                         }
                     }
                 }
                 if ($isAllowed) {
                     $response->status = JAUTHENTICATE_STATUS_SUCCESS;
                     $response->username = $jUser->username;
                     if (!$configModel->getSetting('create_new_users')) {
                         // Update the J user's email to what it is in Facebook
                         $fbProfileFields = $fbClient->getUserProfile($fbUserId, array('email'));
                         if ($fbProfileFields != null && $fbProfileFields['email']) {
                             $jUser->email = $fbProfileFields['email'];
                             $jUser->save();
                         }
                     }
                     $response->email = $jUser->email;
                     $response->fullname = $jUser->name;
                     $response->error_message = '';
                     return true;
                 }
             } else {
                 if (!$configModel->getSetting('create_new_users')) {
                     # User is not in system, should create their account automatically
                     #echo "Creating a pseudo-user<br>";
                     $fbUser = $fbClient->_getUserName($fbUserId);
                     if ($fbUser == null) {
                         # no information returned from FB
                         return false;
                     }
                     // Get the email to use from Facebook
                     $fbProfileFields = $fbClient->getUserProfile($fbUserId, array('email'));
                     if ($fbProfileFields == null || !$fbProfileFields['email']) {
                         $newEmail = $fbUser['first_name'] . "_" . $fbUserId . "@unknown.com";
                     } else {
                         $newEmail = $fbProfileFields['email'];
                     }
                     $fullname = $fbUser['name'];
                     $username = "******" . $fbUserId;
                     #Use the Joomla User plugin to create the User row in the database
                     JPluginHelper::importPlugin('user');
                     $user['fullname'] = $fullname;
                     $user['username'] = $username;
                     $user['password_clear'] = "";
                     $user['email'] = $newEmail;
                     $jUser = $app->triggerEvent('_getUser', array($user));
                     $jUser = $jUser[0];
                     #Map the new user
                     include_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jfbconnect' . DS . 'models' . DS . 'usermap.php';
                     $userMapModel = new JFBConnectModelUserMap();
                     if ($userMapModel->mapUser($fbUserId, $jUser->get('id'))) {
                         $app->enqueueMessage(JText::_('MAP USER SUCCESS'));
                     } else {
                         $app->enqueueMessage(JText::_('MAP USER FAIL'));
                     }
                     $response->status = JAUTHENTICATE_STATUS_SUCCESS;
                     $response->email = $newEmail;
                     $response->fullname = $fullname;
                     $response->username = $username;
                     $response->error_message = '';
                     return true;
                 }
             }
         }
     }
     # catch everything else as an authentication failure
     #echo "Authentication Failure<br>";
     $response->status = JAUTHENTICATE_STATUS_FAILURE;
     $response->error_message = 'Facebook authentication failed';
     return false;
 }
示例#8
0
 function loginFacebookUser()
 {
     $app = JFactory::getApplication();
     $jfbcLibrary = JFBConnectFacebookLibrary::getInstance();
     $fbUserId = $jfbcLibrary->getUserId(FALSE);
     #echo "Con. Logging in FB User : "******"<br>";
     require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jfbconnect' . DS . 'models' . DS . 'usermap.php';
     $userMapModel = new JFBConnectModelUserMap();
     $configModel = $jfbcLibrary->configModel;
     $user = JFactory::getUser();
     if ($user->guest) {
         # Guest: Check if they have a Joomla user and log that user in. If not, create them one
         $jUserId = $userMapModel->getJoomlaUserId($fbUserId);
         if (!$fbUserId) {
             # Facebook isn't returning information about this user.  Redirect them.
             $app->enqueueMessage('We were unable to retrieve your Facebook account information. Please try again');
             $app->redirect('index.php');
         }
         # Check if automatic email mapping is allowed, and see if that email is registered
         # AND the Facebook user doesn't already have a Joomla account
         if ($configModel->getSetting('facebook_auto_map_by_email') && !$jUserId) {
             $fbProfileFields = $jfbcLibrary->getUserProfile($fbUserId, array('email'));
             if ($fbProfileFields != null && $fbProfileFields['email']) {
                 $fbEmail = $fbProfileFields['email'];
                 $jUserEmailId = $userMapModel->getJoomlaUserIdFromEmail($fbEmail);
                 if ($jUserEmailId && $jUserEmailId != 0) {
                     // Found a user with the same email address
                     // do final check to make sure there isn't a FB account already mapped to it
                     $jUserId = $userMapModel->getFacebookUserId($jUserEmailId);
                     if (!$jUserId) {
                         if ($userMapModel->mapUser($fbUserId, $jUserEmailId)) {
                             $app->enqueueMessage(JText::_('MAP USER SUCCESS'));
                         } else {
                             $app->enqueueMessage(JText::_('MAP USER FAIL'));
                         }
                         $app->enqueueMessage(JText::_('MAP USER SUCCESS'));
                         $jUserId = $jUserEmailId;
                         // Update the temp jId so that we login below
                     }
                 }
             }
         }
         if ($configModel->getSetting('create_new_users') && $jUserId == null) {
             # User not in system, create new users setting enabled. Redirect to the login/register form
             $app->redirect(JRoute::_('index.php?option=com_jfbconnect&view=loginregister', false));
         }
         #set the initial registration variable so that the user plugin knows to map user and trigger onAfterRegistration
         if ($jUserId == null) {
             $jfbcLibrary->setInitialRegistration();
         }
         require_once JPATH_COMPONENT . DS . 'controllers' . DS . 'loginregister.php';
         $loginController = new JFBConnectControllerLoginRegister();
         $loginController->login();
         // Perform the login function
     } else {
         #echo "Updating mapping only";
         if ($userMapModel->mapUser($fbUserId)) {
             $app->enqueueMessage(JText::_('MAP USER SUCCESS'));
         } else {
             $app->enqueueMessage(JText::_('MAP USER FAIL'));
         }
     }
     $return = base64_decode(JRequest::getVar('return'));
     $app->redirect($return);
 }
示例#9
0
 * @license         http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 * @version         Release v6.4.2
 * @build-date      2015/08/24
 */
// no direct access
defined('_JEXEC') or die('Restricted access');
jimport('joomla.filesystem.file');
$jfbcLibraryFile = JPATH_ROOT . '/components/com_jfbconnect/libraries/facebook.php';
if (!JFile::exists($jfbcLibraryFile)) {
    echo "JFBConnect not found. Please reinstall.";
    return;
}
require_once $jfbcLibraryFile;
require_once dirname(__FILE__) . '/helper.php';
$helper = new modJFBCSocialShareHelper($params);
$fbClient = JFBConnectFacebookLibrary::getInstance();
$fbAppId = JFBCFactory::provider('facebook')->appId;
$renderKey = $fbClient->getSocialTagRenderKey();
$renderKeyString = " key=" . $renderKey;
//General
$url = $params->get('url');
$href = '';
if (!$url) {
    $url = SCSocialUtilities::getStrippedUrl();
}
if ($url) {
    $href = ' href=' . $url;
}
$layout = $params->get('layout_style');
$orientation = $params->get('orientation');
$position = $params->get('position');
示例#10
0
 function mapCurrentUser()
 {
     $app = JFactory::getApplication();
     require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jfbconnect' . DS . 'models' . DS . 'usermap.php';
     $jfbcLibrary = JFBConnectFacebookLibrary::getInstance();
     $userMapModel = new JFBConnectModelUserMap();
     # quick check to ensure no baddies
     $rawFbUserId = $jfbcLibrary->getUserId(FALSE);
     if ($rawFbUserId != JRequest::getVar('fbid', '', 'POST')) {
         $return = JRoute::_('index.php?option=com_jfbconnect&view=loginregister', false);
         $app->enqueueMessage(JText::_('MAP USER FAIL'), 'error');
         $app->redirect($return);
     }
     $username = JRequest::getVar('username', '', 'POST');
     $password = JRequest::getVar('password', '', 'POST');
     $error = $app->login(array('username' => $username, 'password' => $password));
     if (!JError::isError($error)) {
         # logged in successfully
         $lang = JFactory::getLanguage();
         $lang->load('com_jfbconnect');
         if ($userMapModel->mapUser($rawFbUserId)) {
             $app->enqueueMessage(JText::_('MAP USER SUCCESS'));
         } else {
             $app->enqueueMessage(JText::_('MAP USER FAIL'));
         }
         #$return = base64_decode(JRequest::getVar('return'));
         $configModel = $jfbcLibrary->configModel;
         $redirectURL = $configModel->getSetting('facebook_new_user_url', 'index.php');
         $app->redirect($redirectURL);
     } else {
         $return = JRoute::_('index.php?option=com_jfbconnect&view=loginregister', false);
         $app->redirect($return);
     }
 }
示例#11
0
 function getFbClient()
 {
     if (!isset(self::$_facebook)) {
         include_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jfbconnect' . DS . 'assets' . DS . 'facebook-api' . DS . 'facebook.php';
         self::$_facebook = new JFBCFacebook(array('appId' => $this->facebookAppId, 'secret' => $this->facebookSecretKey, 'cookie' => true));
         // check if Auto-Login is set, and if so, try to log any valid user's in
         if ($this->configModel->getSetting('facebook_auto_login', '0')) {
             $jUser =& JFactory::getUser();
             if ($jUser->guest) {
                 // Check if they should be logged in
                 $fbUserId = $this->getUserId(false);
                 $userMapModel = new JFBConnectModelUserMap();
                 if ($userMapModel->getJoomlaUserId($fbUserId)) {
                     // User found, log them in
                     $app = JFactory::getApplication();
                     $lang = JFactory::getLanguage();
                     $lang->load('com_jfbconnect');
                     $app->enqueueMessage(JText::_('AUTOMATIC LOGIN'));
                     $app->login(array('username' => $this->facebookApiKey, 'password' => $this->facebookSecretKey));
                     // Get the login redirect
                     // TODO: This code duplicates what's in the controller.php block and should be made into a function
                     $redirect = "";
                     $return = base64_decode(JRequest::getVar('return'));
                     if ($this->configModel->getSetting('facebook_login_redirect_enable')) {
                         $redirectId = $this->configModel->getSetting('facebook_login_redirect', 'index.php');
                         $redirect = JRoute::_("index.php?Itemid=" . $redirectId, false);
                     } else {
                         if ($return != "") {
                             $redirect = $return;
                         } else {
                             $redirect = JRoute::_('index.php');
                         }
                     }
                     $app->redirect($redirect);
                 }
             }
         }
     }
     return self::$_facebook;
 }