コード例 #1
0
ファイル: easyblog.php プロジェクト: knigherrant/decopatio
 /**
  * Formats microblog posts. Use EB::quickpost()->getAdapter('source')->format($blog);
  *
  * @deprecated	4.0
  */
 public static function formatMicroblog(&$row)
 {
     $adapter = EB::quickpost()->getAdapter($row->posttype);
     if ($adapter === false) {
         return;
     }
     $adapter->format($row);
 }
コード例 #2
0
ファイル: standard.php プロジェクト: knigherrant/decopatio
 /**
  * Formats the microblog posts
  *
  * @since	5.0
  * @access	public
  * @param	string
  * @return
  */
 public static function formatMicroblog(EasyBlogPost &$blog)
 {
     $adapter = EB::quickpost()->getAdapter($blog->posttype);
     if ($adapter === false) {
         return;
     }
     $adapter->format($blog);
 }
コード例 #3
0
ファイル: view.ajax.php プロジェクト: knigherrant/decopatio
 /**
  * Retrieves the quickpost object
  *
  * @since	4.0
  * @access	public
  * @param	string
  * @return
  */
 private function getQuickpostObject($type)
 {
     $adapter = EB::quickpost()->getAdapter($type);
     return $adapter;
 }
コード例 #4
0
ファイル: twitter.php プロジェクト: BetterBetterBetter/B3App
 /**
  * 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);
 }