예제 #1
0
 /**
  * sharePost
  *
  * @param   object  &$channel  Param
  * @param   object  &$post     Param
  * @param   int     $userid    Param
  *
  * @return	array
  */
 protected function sharePost(&$channel, &$post, $userid = null)
 {
     // Check for duplicate post
     if ($this->dpcheck_enabled) {
         $isDuplicated = PostHelper::isDuplicatedPost($post->id, $post->ref_id, $post->plugin, $post->channel_id, $post->message, $this->dpcheck_time_intval);
         if ($isDuplicated) {
             $this->logger->log(JLog::INFO, 'sendPost: duplicate post detection - message is already posted, article id = ' . $post->ref_id . ', plugin = ' . $post->plugin . ', interval = ' . $this->dpcheck_time_intval);
             return array('state' => AutotweetPostHelper::POST_ERROR, 'result_msg' => 'COM_AUTOTWEET_ERROR_DUPLICATED');
         }
     }
     // Check for banned post
     if ($this->bannedwordscheck_enabled) {
         $isBanned = PostHelper::isBannedPost($post->message, $this->banned_words);
         if ($isBanned) {
             $this->logger->log(JLog::INFO, 'sendPost: banned post detection - message has banned words, article id = ' . $post->ref_id . ', plugin = ' . $post->plugin);
             return array('state' => AutotweetPostHelper::POST_ERROR, 'result_msg' => 'COM_AUTOTWEET_ERROR_BANNED');
         }
     }
     // Get short url one time and if needed only (better performance)
     if (AutotweetPostHelper::SHOWURL_OFF != $post->show_url && !empty($post->org_url) && !array_key_exists($post->org_url, $this->current_short_url)) {
         $shorturlHelper = ShorturlHelper::getInstance();
         $this->current_short_url[$post->org_url] = $shorturlHelper->getShortUrl($post->org_url);
     }
     $current_short_url = null;
     if (array_key_exists($post->org_url, $this->current_short_url)) {
         $current_short_url = $this->current_short_url[$post->org_url];
     }
     // Construct url and truncate message, if necessary
     $finalUrlMessage = TextUtil::getMessageWithUrl($channel, $post, $current_short_url, $this->shorturl_always);
     // Switch original url to short url to use short url also for all other links
     $post->url = $finalUrlMessage['url'];
     $message = $finalUrlMessage['message'];
     // Just in case we want to repeat the message
     // $post->message = $message;
     return $this->sharePostChannel($message, $channel, $post);
 }