/** * Returns the information of a photo object. * * @access public * @param null * @return null */ public function getItem($uri) { // Get the photo id $photoId = EBMM::getFilename($uri); // If the account is already associated, we just need to get the photos from Flickr $client = EB::oauth()->getClient(EBLOG_OAUTH_FLICKR); $client->setAccess($this->oauth->access_token); $client->setParams($this->oauth->params); // Get the photo item from flickr $result = $client->getPhoto($photoId); // Decorate the photo object for MM $photo = $this->decorate($result, $uri); return $photo; }
/** * Displays the linkedin process to setup auto posting * * @since 4.0 * @access public * @return */ public function linkedin() { // Add the button JToolbarHelper::apply('linkedin.save'); // Set page details JToolbarHelper::title(JText::_('COM_EASYBLOG_AUTOPOSTING_LINKEDIN_TITLE')); $this->setHeading('COM_EASYBLOG_AUTOPOSTING_LINKEDIN_TITLE'); $associated = EB::oauth()->associated('linkedin'); // Initialize the default value $companies = array(); $client = EB::oauth()->getClient('linkedin'); if ($associated) { $oauth = EB::table('oauth'); $oauth->load(array('type' => 'linkedin', 'system' => true)); $client->setAccess($oauth->access_token); // Get the company data $data = $client->company('?is-company-admin=true'); $result = $data['linkedin']; $parser = JFactory::getXML($result, false); $result = $parser->children(); $companies = array(); if ($result) { foreach ($result as $item) { $company = new stdClass(); $company->id = (int) $item->id; $company->title = (string) $item->name; $companies[] = $company; } } } $storedCompanies = explode(',', $this->config->get('integrations_linkedin_company')); $this->set('client', $client); $this->set('storedCompanies', $storedCompanies); $this->set('companies', $companies); $this->set('associated', $associated); parent::display('autoposting/linkedin/default'); }
/** * Displays the author's form * * @since 4.0 * @access public * @param string * @return */ public function form() { // Check for access $this->checkAccess('easyblog.manage.user'); // Get the author's id $id = $this->input->get('id', 0, 'int'); $author = EB::user($id); // Get the session data $post = EB::getSession('EASYBLOG_REGISTRATION_POST'); // Set heading $title = 'COM_EASYBLOG_TITLE_EDIT_AUTHOR'; if (!$id) { $title = 'COM_EASYBLOG_TITLE_CREATE_AUTHOR'; } JToolBarHelper::title(JText::_($title), 'users'); $this->setHeading($title, '', 'fa-user'); $user = JFactory::getUser($id); // Determines if this is a new user or not $isNew = $user->id == 0 ? true : false; if ($isNew && !empty($post)) { unset($post['id']); $pwd = $post['password']; unset($post['password']); unset($post['password2']); $user->bind($post); $post['password'] = $pwd; $author->bind($post); } // Load up feedburner data $feedburner = EB::table('Feedburner'); $feedburner->load($author->id); // Load up twitter oauth client $twitter = EB::table('OAuth'); $twitter->load(array('user_id' => $user->id, 'type' => EBLOG_OAUTH_TWITTER, 'system' => false)); // Load up linkedin oauth table $linkedin = EB::table('OAuth'); $linkedin->load(array('user_id' => $user->id, 'type' => EBLOG_OAUTH_LINKEDIN, 'system' => false)); // Load up facebook oauth table $facebook = EB::table('OAuth'); $facebook->load(array('user_id' => $user->id, 'type' => EBLOG_OAUTH_FACEBOOK, 'system' => false)); $facebookClient = EB::oauth()->getClient(EBLOG_OAUTH_FACEBOOK); $twitterClient = EB::oauth()->getClient(EBLOG_OAUTH_TWITTER); $linkedinClient = EB::oauth()->getClient(EBLOG_OAUTH_LINKEDIN); // Load up adsense data $adsense = EB::table('Adsense'); $adsense->load($author->id); // If this is a new author and the post was submitted before if ($isNew && $post) { $feedburner->url = $post['feedburner_url']; $twitter->message = $post['integrations_twitter_message']; $twitter->auto = $post['integrations_twitter_auto']; $linkedin->auto = $post['integrations_linkedin_auto']; $linkedin->private = isset($post['integrations_linkedin_private']) ? $post['integrations_linkedin_private'] : false; $facebook->auto = $post['integrations_facebook_auto']; $adsense->published = $post['adsense_published']; $adsense->code = $post['adsense_code']; $adsense->display = $post['adsense_display']; } // Get the WYSIWYG editor $editor = JFactory::getEditor(); // Get the user params $params = $user->getParameters(true); // Get the params $bloggerParams = $author->getParams(); // Load up joomla's user forms require_once JPATH_ADMINISTRATOR . '/components/com_users/models/user.php'; $language = JFactory::getLanguage(); $language->load('com_users', JPATH_ADMINISTRATOR); JForm::addFormPath(JPATH_ADMINISTRATOR . '/components/com_users/models/forms'); JForm::addFieldPath(JPATH_ADMINISTRATOR . '/components/com_users/models/fields'); JForm::addFormPath(JPATH_ADMINISTRATOR . '/components/com_users/model/form'); JForm::addFieldPath(JPATH_ADMINISTRATOR . '/components/com_users/model/field'); $jUserModel = new UsersModelUser(); $form = $jUserModel->getForm(); $form->setValue('password', null); $form->setValue('password2', null); $this->set('linkedinClient', $linkedinClient); $this->set('twitterClient', $twitterClient); $this->set('facebookClient', $facebookClient); $this->set('form', $form); $this->set('editor', $editor); $this->set('bloggerParams', $bloggerParams); $this->set('user', $user); $this->set('author', $author); $this->set('params', $params); $this->set('feedburner', $feedburner); $this->set('adsense', $adsense); $this->set('twitter', $twitter); $this->set('facebook', $facebook); $this->set('linkedin', $linkedin); $this->set('isNew', $isNew); $this->set('post', $post); parent::display('bloggers/form'); }
/** * Revokes the access * * @since 4.0 * @access public * @param string * @return */ public function revoke() { // Check for acl rules. $this->checkAccess('autoposting'); // Determines if this request is a system request $system = $this->input->get('system', false, 'bool'); // Determines if this request is to revoke a user's access $userId = $this->input->get('userId', null, 'default'); $table = EB::table('OAuth'); if ($system) { $table->load(array('type' => 'twitter', 'system' => true)); } else { $table->load(array('type' => 'twitter', 'user_id' => $userId, 'system' => false)); } // Get the client $client = EB::oauth()->getClient('Twitter'); $client->setAccess($table->access_token); // Revoke the access $state = $client->revoke(); // Regardless of the state, delete the record. $table->delete(); // If there's a problem revoking the app, just delete the record and let the user know EB::info()->set(JText::_('COM_EASYBLOG_AUTOPOST_TWITTER_SUCCESS_REVOKING_ACCESS'), 'success'); $redirect = 'index.php?option=com_easyblog&view=autoposting&layout=twitter'; $this->app->redirect($redirect); }
/** * Pushes to the oauth site * * @since 4.0 * @access public * @param string * @return */ public function push(EasyBlogPost &$post) { // When there is no access token set on this oauth record, we shouldn't do anything if (!$this->access_token) { $this->setError(JText::sprintf('No access token available for autoposting on %1$s', $this->type)); return false; } $config = EB::config(); // Determines if this user is really allowed to auto post $author = $post->getAuthor(); // Check the author's acl $acl = EB::acl($author->id); $rule = 'update_' . $this->type; if (!$acl->get($rule) && !EB::isSiteAdmin($post->created_by)) { $this->setError(JText::sprintf('No access to autopost on %1$s', $this->type)); return false; } // we only check if the autopost on blog edit is disabled. if (!$config->get('integrations_' . $this->type . '_centralized_send_updates')) { // Check if the blog post was shared before. if ($this->isShared($post->id)) { $this->setError(JText::sprintf('Post %1$s has been shared to %2$s before.', $post->id, $this->type)); return false; } } // Ensure that the oauth data has been set correctly $config = EB::config(); $key = $config->get('integrations_' . $this->type . '_api_key'); $secret = $config->get('integrations_' . $this->type . '_secret_key'); // If either of this is empty, skip this if (!$key || !$secret) { return false; } // Set the callback URL $callback = JURI::base() . 'index.php?option=com_easyblog&task=oauth.grant&type=' . $this->type; // Now we do the real thing. Get the library and push $lib = EB::oauth()->getClient($this->type, $key, $secret, $callback); $lib->setAccess($this->access_token); // Try to share the post now $state = $lib->share($post, $this); if ($state === true) { $history = EB::table('OAuthPost'); $history->load(array('oauth_id' => $this->id, 'post_id' => $post->id)); $history->post_id = $post->id; $history->oauth_id = $this->id; $history->created = EB::date()->toSql(); $history->modified = EB::date()->toSql(); $history->sent = EB::date()->toSql(); $history->store(); return true; } return false; }
/** * Displays the quickpost layout * * @since 4.0 * @access public * @param string * @return */ public function quickpost() { // Require user to be logged in EB::requireLogin(); // Test if microblogging is allowed if (!$this->config->get('main_microblog')) { $this->info->set(JText::_('COM_EASYBLOG_NOT_ALLOWED'), 'error'); return $this->app->redirect(EBR::_('index.php?option=com_easyblog&view=dashboard', false)); } // Test ACL if add entry is allowed if (!$this->acl->get('add_entry')) { return $this->app->redirect(EBR::_('index.php?option=com_easyblog&view=dashboard', false)); } // Set the page title $title = EB::getPageTitle(JText::_('COM_EASYBLOG_DASHBOARD_SHARE_A_STORY_TITLE')); parent::setPageTitle($title, false, $this->config->get('main_pagetitle_autoappend')); // Get active tabs $active = $this->input->get('type', 'standard', 'word'); // Get a list of available auto post sites $facebook = EB::oauth()->isUserAssociated('facebook', $this->my->id); $twitter = EB::oauth()->isUserAssociated('twitter', $this->my->id); $linkedin = EB::oauth()->isUserAssociated('linkedin', $this->my->id); // Retrieve existing tags $tagsModel = EB::model('Tags'); $tags = $tagsModel->getTags(); $this->set('facebook', $facebook); $this->set('twitter', $twitter); $this->set('linkedin', $linkedin); $this->set('active', $active); $this->set('tags', $tags); parent::display('dashboard/quickpost/default'); }
/** * Allows caller to explicitly auto post blog posts into social sites * * @since 4.0 * @access public * @param string * @return */ public function autopost($sites = array()) { // Ensure that the sites are not empty if (!$sites) { return false; } // Get EasyBlog's configuration $config = EB::config(); // should add chechkfunction for multiple category here $category = EB::table('Category'); $category->load($this->getPrimaryCategory()); if (!$category->autopost) { return; } // These are the allowed auto posting sites $allowed = array(EBLOG_OAUTH_LINKEDIN, EBLOG_OAUTH_FACEBOOK, EBLOG_OAUTH_TWITTER); foreach ($sites as $site) { // Skip this if the site is not known if (!in_array($site, $allowed)) { continue; } // Process the centralize site options first // EB::oauth()->share($this, $site, true); // Process the user's options since users can also setup their own auto posting EB::oauth()->share($this, $site, false); } }
/** * Allows caller to import posts from twitter * * @since 5.0 * @access public * @param string * @return */ public function import() { $key = $this->config->get('integrations_twitter_api_key'); $secret = $this->config->get('integrations_twitter_secret_key'); // Ensure that the settings is enabled if (!$this->config->get('integrations_twitter_microblog')) { // TODO: Turn this into language string. return EB::exception('Twitter import has been disabled.', EASYBLOG_MSG_ERROR); } // Get a list of hashtags $hashtags = $this->config->get('integrations_twitter_microblog_hashes'); // If there are no hashtags, skip this if (!$hashtags) { // TODO: Turn this into language string. return EB::exception('No hashtags provided to search. Skipping this.', EASYBLOG_MSG_INFO); } $hashtags = explode(',', $hashtags); $total = count($hashtags); // Get the list of accounts $model = EB::model('OAuth'); $accounts = $model->getTwitterAccounts(); if (!$accounts) { return EB::exception('No Twitter accounts associated on the site. Skipping this', EASYBLOG_MSG_INFO); } // Get the default category to save the tweets into $categoryId = $this->config->get('integrations_twitter_microblog_category'); // Default state of the post $published = $this->config->get('integrations_twitter_microblog_publish'); // Determines if the post should be available on the frontpage $frontpage = $this->config->get('integrations_twitter_microblog_frontpage'); // Determines the total number of items imported $total = 0; // Go through each twitter accounts and search for the tags foreach ($accounts as $account) { $params = EB::registry($account->params); $screen = $params->get('screen_name'); // If we can't get the screen name, do not try to process it. if (!$screen) { continue; } // Get the twitter consumer $consumer = EB::oauth()->getClient('Twitter'); $consumer->setAccess($account->access_token); // Get the last tweet that has been imported so we don't try to search for anything prior to that $lastImport = $model->getLastTweetImport($account->id); // Prepare the search params $tweets = $consumer->search($hashtags, $lastImport); if (!$tweets) { return EB::exception('No tweets found. Skipping this.', EASYBLOG_MSG_INFO); } foreach ($tweets as $tweet) { $data = array(); $data['title'] = JString::substr($tweet->text, 0, 20) . JText::_('COM_EASYBLOG_ELLIPSES'); $data['posttype'] = EBLOG_MICROBLOG_TWITTER; $data['created_by'] = $account->user_id; $data['created'] = EB::date()->toSql(); $data['modified'] = EB::date()->toSql(); $data['publish_up'] = EB::date()->toSql(); $data['intro'] = $tweet->text; $data['published'] = $published; $data['frontpage'] = $frontpage; $data['source_id'] = '0'; $data['source_type'] = EASYBLOG_POST_SOURCE_SITEWIDE; $data['category_id'] = $categoryId; $data['categories'] = array($categoryId); // we need to set this as legacy post as the post did not go through composer. $data['doctype'] = EASYBLOG_POST_DOCTYPE_LEGACY; $post = EB::post(); $createOption = array('overrideDoctType' => 'legacy', 'checkAcl' => false, 'overrideAuthorId' => $account->user_id); $post->create($createOption); // binding $post->bind($data); $saveOptions = array('applyDateOffset' => false, 'validateData' => false, 'useAuthorAsRevisionOwner' => true, 'checkAcl' => false, 'overrideAuthorId' => $account->user_id); // Save the post now try { $post->save($saveOptions); } catch (EasyBlogException $exception) { return $exception; } // We need to save some of these tweets $adapter = EB::quickpost()->getAdapter('twitter'); if ($adapter) { $adapter->saveAsset($post->id, 'screen_name', $tweet->user->screen_name); $adapter->saveAsset($post->id, 'created_at', $tweet->created_at); } // Create a new history record $history = EB::table('TwitterMicroBlog'); $history->id_str = $tweet->id_str; $history->post_id = $post->id; $history->oauth_id = $account->id; $history->created = $post->created; $history->tweet_author = $screen; $history->store(); $total++; } } return EB::exception(JText::sprintf('%1$s tweets retrieved from twitter', $total), EASYBLOG_MSG_SUCCESS); }
/** * Sets the oauth access * * @since 4.0 * @access public * @param string * @return */ public function setAccess(EasyBlogTableOAuth $access) { $this->client = EB::oauth()->getClient('dropbox'); $this->client->setAccess($access->access_token); }
/** * Revokes the user's oauth access * * @since 5.0 * @access public * @param string * @return */ public function revoke() { // Require the user to be logged in EB::requireLogin(); // The default url $url = EBR::_('index.php?option=com_easyblog&view=dashboard&layout=profile', false); // Get any redirection url $redirect = $this->input->get('redirect', '', 'default'); // Get the oauth client $type = $this->input->get('client', '', 'cmd'); // If redirect url is provided, we know for sure where to redirect the user to if ($redirect) { $url = base64_decode($redirect); } // Load up the oauth object $table = EB::table('OAuth'); $table->loadByUser($this->my->id, $type); // Load up the oauth client and set the access $client = EB::oauth()->getClient($type); $client->setAccess($table->access_token); // Get the callback url $callback = EBR::getRoutedURL('index.php?option=com_easyblog&task=oauth.grant&client=' . $type, false, true); // Get the consumer and secret key $key = $this->config->get('integrations_' . $type . '_api_key'); $secret = $this->config->get('integrations_' . $type . '_secret_key'); // Try to revoke the app $state = $client->revoke(); // After revoking the access, delete the oauth record $table->delete(); $this->info->set(JText::_('COM_EASYBLOG_APPLICATION_REVOKED_SUCCESSFULLY'), 'success'); return $this->app->redirect($url, false); }