Пример #1
0
 /**
  * Responsible to revoke access for the specific oauth client
  *
  * @param	null
  * @return	null
  **/
 public function revoke()
 {
     $mainframe = JFactory::getApplication();
     $id = JRequest::getCmd('id');
     $return = JRequest::getCmd('return', 'user');
     $activechild = JRequest::getCmd('activechild', '');
     $my = JFactory::getUser($id);
     $url = JRoute::_('index.php?option=com_easyblog&view=dashboard&layout=profile', false);
     $type = JRequest::getWord('type');
     $config = EasyBlogHelper::getConfig();
     if ($my->id == 0) {
         $mainframe->enqueueMessage(JText::_('COM_EASYBLOG_OAUTH_INVALID_USER'), 'error');
         $this->setRedirect($return);
     }
     $oauth = EB::table('OAuth');
     $oauth->loadByUser($my->id, $type);
     // Revoke the access through the respective client first.
     $callback = trim(JURI::base(), "/") . JRoute::_('/index.php?option=com_easyblog&c=oauth&task=grant&type=' . $type . '&return=' . $return . '&activechild=' . $activechild . '&id=' . $id, false, true);
     $key = $config->get('integrations_' . $type . '_api_key');
     $secret = $config->get('integrations_' . $type . '_secret_key');
     $consumer = EasyBlogOauthHelper::getConsumer($type, $key, $secret, $callback);
     $consumer->setAccess($oauth->access_token);
     switch ($return) {
         case 'settings':
             $redirect = JRoute::_('index.php?option=com_easyblog&view=settings&active=social&activechild=' . $activechild, false);
             break;
         case 'user':
         default:
             $redirect = JRoute::_('index.php?option=com_easyblog&c=user&id=' . $id . '&task=edit', false);
             break;
     }
     // @task: Only show errors when the user is really authenticated with the respective provider.
     if (!$consumer->revokeApp() && !empty($oauth->access_token)) {
         $mainframe->enqueueMessage(JText::_('There was an error when trying to revoke your app.'), 'error');
         $this->setRedirect($redirect);
         return;
     }
     $oauth->delete();
     $mainframe->enqueueMessage(JText::_('Application revoked successfully.'));
     $this->setRedirect($redirect);
 }
Пример #2
0
 /**
  * Ajax method to share content to social networks
  *
  * @param	int		$blogId		The blog's id.
  * @param	int		$oauthId	The oauth id.
  **/
 function ajaxSocialShare($blogId, $type)
 {
     $ajax = new Ejax();
     $config = EasyBlogHelper::getConfig();
     $my = JFactory::getUser();
     $userId = $my->id;
     $oauth = EasyBlogHelper::getTable('Oauth', 'Table');
     $oauth->loadByUser($userId, $type);
     if (!$oauth->id) {
         $ajax->script('eblog.spinner.publish(\'' . $blogId . '\', 0);');
         $ajax->alert(JText::_('COM_EASYBLOG_OAUTH_INVALID_ID'), JText::_('COM_EASYBLOG_INFO'), 450, 'auto');
         $ajax->send();
         return;
     }
     if (!$config->get('integrations_' . $oauth->type)) {
         $ajax->script('eblog.spinner.publish(\'' . $blogId . '\', 0);');
         $ajax->alert(JText::sprintf('COM_EASYBLOG_OAUTH_TYPE_DISABLED', ucfirst($oauth->type)), JText::_('COM_EASYBLOG_INFO'), 450, 'auto');
         $ajax->send();
         return;
     }
     $blog = EasyBlogHelper::getTable('blog', 'Table');
     $blog->load($blogId);
     if ($blog->published != POST_ID_PUBLISHED) {
         $ajax->script('eblog.spinner.publish(\'' . $blogId . '\', 0);');
         $ajax->alert(JText::_('COM_EASYBLOG_DASHBOARD_ENTRIES_NOT_ABLE_TO_SOCIAL_SHARE'), JText::_('COM_EASYBLOG_INFO'), 450, 'auto');
         $ajax->send();
         return;
     }
     $key = $config->get('integrations_' . $oauth->type . '_api_key');
     $secret = $config->get('integrations_' . $oauth->type . '_secret_key');
     if (empty($key) || empty($secret)) {
         $ajax->script('eblog.spinner.publish("' . $blogId . '", 0);');
         $ajax->alert(JText::_('COM_EASYBLOG_OAUTH_KEY_INVALID'), JText::_('COM_EASYBLOG_INFO'), 450, 'auto');
         $ajax->send();
         return;
     }
     $callback = EasyBlogRouter::getRoutedURL('index.php?option=com_easyblog&controller=oauth&task=grant&type=' . $oauth->type, false, true);
     require_once EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'oauth.php';
     $consumer = EasyBlogOauthHelper::getConsumer($oauth->type, $key, $secret, $callback);
     $consumer->setAccess($oauth->access_token);
     if (!EasyBlogSocialShareHelper::share($blog, $oauth->type)) {
         $ajax->script('eblog.spinner.publish("' . $blogId . '", 0);');
         $ajax->alert(JText::_('COM_EASYBLOG_OAUTH_ERROR_POSTING'), JText::_('COM_EASYBLOG_INFO'), 450, 'auto');
         $ajax->send();
         return;
     }
     // @todo: mark this as sent!
     $oauthPost = EasyBlogHelper::getTable('OauthPost', 'Table');
     $oauthPost->loadByOauthId($blog->id, $oauth->id);
     $date = EasyBlogHelper::getDate();
     $oauthPost->post_id = $blog->id;
     $oauthPost->oauth_id = $oauth->id;
     $oauthPost->created = $date->toMySQL();
     $oauthPost->modified = $date->toMySQL();
     $oauthPost->sent = $date->toMySQL();
     $oauthPost->store();
     // Update message
     $img = JURI::root() . '/components/com_easyblog/assets/icons/socialshare/' . JString::strtolower($oauth->type) . '.png';
     $ajax->script('$("#oauth_img_' . $oauth->type . '_' . $blog->id . '").attr("src", "' . $img . '");');
     $ajax->script('eblog.spinner.publish(\'' . $blog->id . '\', 0);');
     $ajax->alert(JText::sprintf('COM_EASYBLOG_OAUTH_POST_SUCCESS', ucfirst($oauth->type)), JText::_('COM_EASYBLOG_INFO'), 450, 'auto');
     $ajax->send();
 }
Пример #3
0
 /**
  * Shares a story through 3rd party oauth clients
  *
  * @param	TableBlog	$blog	A blog table object
  * @param	string		$type	The type of oauth client
  *
  * @return	boolean		True on success and false otherwise.
  **/
 public function share($blog, $type, $useCentralized = false)
 {
     JTable::addIncludePath(EBLOG_TABLES);
     $oauth = EasyBlogHelper::getTable('Oauth', 'Table');
     $oauths = array();
     $config = EasyBlogHelper::getConfig();
     // @rule: Process centralized notifications, be it a page or an account update
     if ($useCentralized) {
         $userId = $config->get('integrations_' . strtolower($type) . '_centralized_userid');
         $message = $config->get('integrations_' . JString::strtolower($type) . '_centralized_auto_post');
         $auto = $config->get('integrations_' . JString::strtolower($type) . '_centralized_auto_post');
         $oauth->loadByUser($userId, $type);
         // For legacy fix prior to 3.0, we need to set system=1
         if ($oauth->id && !$oauth->system) {
             $oauth->system = 1;
             $oauth->store();
         }
         // @task: Now we try to load the real object
         $oauth->loadSystemByType($type);
         if ($oauth->id) {
             $oauths[] = $oauth;
         }
     } else {
         if ($config->get('integrations_' . JString::strtolower($type) . '_centralized_and_own')) {
             JTable::addIncludePath(EBLOG_TABLES);
             $oauth = EasyBlogHelper::getTable('Oauth', 'Table');
             $oauth->loadByUser($blog->created_by, $type);
             $oauths[] = $oauth;
         }
     }
     $key = $config->get('integrations_' . $type . '_api_key');
     $secret = $config->get('integrations_' . $type . '_secret_key');
     // @rule: Set callback URLs
     $callback = EasyBlogRouter::getRoutedURL('index.php?option=com_easyblog&controller=oauth&task=grant&type=' . $type, false, true);
     if ($oauths) {
         foreach ($oauths as $oauth) {
             // Skip processing anything that does not have an access token
             if (!$oauth->access_token) {
                 continue;
             }
             $acl = EasyBlogACLHelper::getRuleSet($blog->created_by);
             $rule = 'update_' . $type;
             // @task: If entry is already shared or automatic postings is disabled do not share this entry.
             if ($oauth->isShared($blog->id, $useCentralized) || !$acl->rules->{$rule} && !EasyBlogHelper::isSiteAdmin()) {
                 continue;
             }
             // @rule: Retrieve the consumer object for this oauth client.
             $consumer = EasyBlogOauthHelper::getConsumer($type, $key, $secret, $callback);
             $consumer->setAccess($oauth->access_token);
             if ($consumer->share($blog, $oauth->message, $oauth, $useCentralized)) {
                 // @task: mark this as sent!
                 $oauthPost = EasyBlogHelper::getTable('OauthPost', 'Table');
                 $oauthPost->loadByOauthId($blog->id, $oauth->id);
                 $date = EasyBlogHelper::getDate();
                 $oauthPost->post_id = $blog->id;
                 $oauthPost->oauth_id = $oauth->id;
                 $oauthPost->created = $date->toMySQL();
                 $oauthPost->modified = $date->toMySQL();
                 $oauthPost->sent = $date->toMySQL();
                 $oauthPost->store();
             }
         }
     }
     return true;
 }
Пример #4
0
 /**
  * Responsible to revoke access for the specific oauth client
  *
  * @param	null
  * @return	null
  **/
 public function revoke()
 {
     $mainframe = JFactory::getApplication();
     $my = JFactory::getUser();
     $url = EasyBlogRouter::_('index.php?option=com_easyblog&view=dashboard&layout=profile', false);
     $redirect = JRequest::getVar('redirect', '');
     $type = JRequest::getWord('type');
     $config = EasyBlogHelper::getConfig();
     if (!empty($redirect)) {
         $url = base64_decode($redirect);
     }
     if (!EasyBlogHelper::isLoggedIn()) {
         EasyBlogHelper::setMessageQueue(JText::_('COM_EASYBLOG_YOU_MUST_LOGIN_FIRST'), 'error');
         $this->setRedirect(EasyBlogRouter::_('index.php?option=com_easyblog', false));
         return;
     }
     $oauth = EasyBlogHelper::getTable('OAuth', 'Table');
     $oauth->loadByUser($my->id, $type);
     // Revoke the access through the respective client first.
     $callback = EasyBlogRouter::getRoutedURL('index.php?option=com_easyblog&controller=oauth&task=grant&type=' . $type, false, true);
     $key = $config->get('integrations_' . $type . '_api_key');
     $secret = $config->get('integrations_' . $type . '_secret_key');
     $consumer = EasyBlogOauthHelper::getConsumer($type, $key, $secret, $callback);
     $consumer->setAccess($oauth->access_token);
     // @task: Only show errors when the user is really authenticated with the respective provider.
     if (!$consumer->revokeApp() && !empty($oauth->access_token)) {
         EasyBlogHelper::setMessageQueue(JText::_('COM_EASYBLOG_APPLICATION_REVOKED_ERROR'), 'error');
         $this->setRedirect(EasyBlogRouter::_('index.php?option=com_easyblog&view=dashboard&layout=profile', false));
         return;
     }
     $oauth->delete();
     EasyBlogHelper::setMessageQueue(JText::_('COM_EASYBLOG_APPLICATION_REVOKED_SUCCESSFULLY'));
     $this->setRedirect($url);
 }