Пример #1
0
 /**
  * callback.
  *
  * @return	void
  */
 public function callback()
 {
     if ($this->csrfProtection) {
         $this->_csrfProtection();
     }
     try {
         // $channelId = $this->input->getUint('channelId');
         $session = JFactory::getSession();
         $channelId = $session->get('channelId');
         // Invalidating
         $session->set('channelId', false);
         $code = $this->input->getString('code');
         $state = $this->input->getString('state');
         if (!empty($code)) {
             $channel = F0FTable::getAnInstance('Channel', 'AutoTweetTable');
             $result = $channel->load($channelId);
             if (!$result) {
                 throw new Exception('LinkedIn Channel failed to load!');
             }
             $lioauth2ChannelHelper = new LiOAuth2ChannelHelper($channel);
             $lioauth2ChannelHelper->authenticate($code, $state);
             // Redirect
             $url = 'index.php?option=com_autotweet&view=channels&task=edit&id=' . $channelId;
             $this->setRedirect($url);
             $this->redirect();
         }
     } catch (Exception $e) {
         $logger = AutotweetLogger::getInstance();
         $logger->log(JLog::ERROR, $e->getMessage());
         throw $e;
     }
 }
Пример #2
0
 /**
  * sendMessage.
  *
  * @param   string  $message  Params
  * @param   object  $data     Params
  *
  * @return  boolean
  */
 public function sendMessage($message, $data)
 {
     $title = $data->title;
     $text = $data->fulltext;
     $url = $data->url;
     $image_url = $data->image_url;
     $media_mode = $this->getMediaMode();
     $logger = AutotweetLogger::getInstance();
     $logger->log(JLog::INFO, 'sendLinkedinMessage', $message);
     $result = null;
     $content = array();
     // Post message and/or media
     switch ($media_mode) {
         case 'attachment':
             $post_attach = true;
             $post_msg = false;
             break;
         case 'both':
             $post_msg = true;
             $post_attach = true;
             break;
         case 'message':
         default:
             $post_msg = true;
             $post_attach = false;
     }
     // Media: do also not post when text and image are empty
     if ($post_attach && !empty($title) && !empty($url)) {
         // Prepare content
         $content['title'] = TextUtil::truncString($title, self::MAX_CHARS_TITLE);
         $content['submitted-url'] = $url;
         $content['submitted-image-url'] = $image_url;
         // Strlen shorter than JString::strlen for UTF-8  - 2 char languages E.g. Hebrew
         $text = TextUtil::truncString($text, self::MAX_CHARS_DESC);
         $content['description'] = $text;
     }
     // Message
     if ($post_msg) {
         $content['comment'] = $title;
     }
     // Default for visibility
     $private = false;
     try {
         $api = $this->getApiInstance();
         $response = $api->companyShare($this->get('company_id'), 'new', $content, $private);
         $result = $this->_processResponse($response);
     } catch (Exception $e) {
         $result = array(false, $e->getMessage());
     }
     return $result;
 }
Пример #3
0
 /**
  * sendMessage.
  *
  * @param   string  $message  Params
  * @param   object  $data     Params
  *
  * @return	boolean
  */
 public function sendMessage($message, $data)
 {
     $title = $data->title;
     $text = $data->fulltext;
     $url = $data->url;
     $org_url = $data->org_url;
     $image_url = $data->image_url;
     $media_mode = $this->getMediaMode();
     $logger = AutotweetLogger::getInstance();
     $logger->log(JLog::INFO, 'sendFacebookMessage', $message);
     if (empty($image_url)) {
         return array(true, 'No photo.');
     }
     $fb_id = $this->getFbChannelId();
     $fbalbum_id = $this->get('fbalbum_id');
     $fb_token = $this->get('fbchannel_access_token');
     $result = null;
     $status_type = array('value' => 'added_photos');
     // Photo object: /user/photos
     $arguments = array('message' => $message, 'url' => $image_url, 'access_token' => $fb_token, 'type' => 'photo', 'created_time' => JFactory::getDate()->toISO8601(), 'status_type' => json_encode($status_type));
     $isUserProfile = $this->isUserProfile();
     if ($isUserProfile) {
         $privacy = $this->get('sharedwith', 'EVERYONE');
         $privacy = array('value' => $privacy);
         $arguments['privacy'] = json_encode($privacy);
     }
     $target_id = $data->xtform->get('target_id');
     if (EParameter::getComponentParam(CAUTOTWEETNG, 'targeting', false) && $target_id) {
         $this->addTargetArguments($arguments, $target_id);
     }
     try {
         $api = $this->getApiInstance();
         $api->setFileUploadSupport(true);
         // Simulated
         if ($this->channel->params->get('use_own_api') == 0) {
             $this->getApiInstance()->api("/me/permissions");
             $result = array(true, JText::_('COM_AUTOTWEET_VIEW_SIMULATED_OK'));
         } else {
             if ($fbalbum_id) {
                 $result = $this->getApiInstance()->api("/{$fbalbum_id}/photos", 'post', $arguments);
             } else {
                 $result = $this->getApiInstance()->api("/{$fb_id}/photos", 'post', $arguments);
             }
             $msg = 'Facebook id: ' . $result['id'];
             $result = array(true, $msg);
         }
     } catch (Exception $e) {
         $result = array(false, $e->getCode() . ' - ' . $e->getMessage());
     }
     return $result;
 }
Пример #4
0
 /**
  * route.
  *
  * @return	void
  */
 public function route()
 {
     header('Content-type: text/plain');
     $url = base64_decode($this->input->get('url', 'index.php', 'BASE64'));
     @ob_end_clean();
     $routed_url = JRoute::_($url, false);
     if (RouteHelp::isMultilingual()) {
         $routed_url = str_replace('/component/autotweet/', '/', $routed_url);
     }
     echo base64_encode($routed_url);
     flush();
     $logger = AutotweetLogger::getInstance();
     $logger->log(JLog::INFO, 'AutotweetControllerSef route: ' . $url . ' = ' . $routed_url);
     JFactory::getApplication()->close();
 }
Пример #5
0
 /**
  * ShorturlHelper. No public access (singleton pattern).
  *
  */
 protected function __construct()
 {
     JLoader::register('AutotweetShortservice', dirname(__FILE__) . '/urlshortservices/autotweetshortservice.php');
     JLoader::register('AutotweetURLShortserviceFactory', dirname(__FILE__) . '/urlshortservices/autotweeturlshortservicefactory.php');
     // General params for message and posting
     $this->resend_attempts = EParameter::getComponentParam(CAUTOTWEETNG, 'resend_attempts', 2);
     $this->shorturl_service = EParameter::getComponentParam(CAUTOTWEETNG, 'shorturl_service', 'Tinyurlcom');
     // Bit.ly, Goog.gl and yourls account data
     $this->bit_username = EParameter::getComponentParam(CAUTOTWEETNG, 'bit_username', null);
     $this->bit_key = EParameter::getComponentParam(CAUTOTWEETNG, 'bit_key', null);
     $this->google_api_key = EParameter::getComponentParam(CAUTOTWEETNG, 'google_api_key', null);
     $this->yourls_host = EParameter::getComponentParam(CAUTOTWEETNG, 'yourls_host', null);
     $this->yourls_token = EParameter::getComponentParam(CAUTOTWEETNG, 'yourls_token', null);
     // Init AutoTweet logging
     $this->logger = AutotweetLogger::getInstance();
 }
Пример #6
0
 /**
  * postMessages
  *
  * @return  void
  */
 public function publishPosts()
 {
     if ($this->cron_enabled) {
         if (AUTOTWEETNG_JOOCIAL) {
             $now = JFactory::getDate();
             if (VirtualManager::getInstance()->isWorking($now)) {
                 PostHelper::publishCronjobPosts($this->max_posts);
             } else {
                 $logger = AutotweetLogger::getInstance();
                 $logger->log(JLog::INFO, 'CronjobHelper::publishPosts - VM not working now ' . $now->toISO8601(true));
             }
         } else {
             PostHelper::publishCronjobPosts($this->max_posts);
         }
     }
 }
Пример #7
0
 /**
  * sendMessage.
  *
  * @param   string  $message  Params
  * @param   object  $data     Params
  *
  * @return  boolean
  */
 public function sendMessage($message, $data)
 {
     $title = $data->title;
     // Strlen shorter than JString::strlen for UTF-8  - 2 char languages E.g. Hebrew
     $text = TextUtil::truncString($data->fulltext, self::MAX_CHARS_TEXT);
     $url = $data->url;
     $image_url = $data->image_url;
     $media_mode = $this->getMediaMode();
     $logger = AutotweetLogger::getInstance();
     $logger->log(JLog::INFO, 'sendLinkedinMessage', $message);
     $result = null;
     // Post message and/or media
     switch ($media_mode) {
         case 'attachment':
             $post_attach = true;
             $post_msg = false;
             break;
         case 'both':
             $post_msg = true;
             $post_attach = true;
         case 'message':
         default:
             $post_msg = true;
             $post_attach = false;
     }
     try {
         $api = $this->getApiInstance();
         if (empty($text)) {
             $text = JFactory::getConfig()->get('MetaDesc');
         }
         if (empty($text)) {
             $text = JFactory::getConfig()->get('sitename');
         }
         if (empty($text)) {
             $text = $title;
         }
         if ($post_attach) {
             $response = $api->createPost($this->get('group_id'), $title, $text, $url);
         } else {
             $response = $api->createPost($this->get('group_id'), $title, $text, $url, $image_url);
         }
         $result = $this->_processResponse($response);
     } catch (Exception $e) {
         $result = array(false, $e->getMessage());
     }
     return $result;
 }
Пример #8
0
 /**
  * sendMessage
  *
  * @param   string  $message  Param
  * @param   string  $data     Param
  *
  * @return	bool
  */
 public function sendMessage($message, $data)
 {
     $sender_mail = $this->get('mail_sender_email');
     $sender_name = $this->get('mail_sender_name');
     $recipient_mail = $this->get('mail_recipient_email');
     $logger = AutotweetLogger::getInstance();
     $logger->log(JLog::INFO, 'sendMailMessage', $message);
     $result = null;
     $this->mailer->isHtml(true);
     $this->mailer->SetFrom($sender_mail, $sender_name);
     $this->mailer->AddAddress($recipient_mail);
     $this->mailer->Subject = TextUtil::truncString($data->title, self::MAX_CHARS_SUBJECT);
     $this->mailer->Body = $this->renderPost($this->channel->id, 'mailchannel', $message, $data);
     if (!$this->mailer->Send()) {
         $result = array(false, 'error sending mail');
     } else {
         $result = array(true, 'successfully sent');
     }
     return $result;
 }
Пример #9
0
 /**
  * SharingHelper
  *
  */
 protected function __construct()
 {
     // Cron job mode
     $this->cron_enabled = EParameter::getComponentParam(CAUTOTWEETNG, 'cron_enabled', 0);
     // Duplicate post detection
     $this->dpcheck_enabled = EParameter::getComponentParam(CAUTOTWEETNG, 'dpcheck_enabled', 1);
     // Banned Words check
     $this->banned_words = EParameter::getComponentParam(CAUTOTWEETNG, 'banned_words', '');
     $this->bannedwordscheck_enabled = !empty($this->banned_words);
     if ($this->bannedwordscheck_enabled) {
         $this->banned_words = str_replace(',', '|', $this->banned_words);
     }
     // Hours to seconds
     $this->dpcheck_time_intval = EParameter::getComponentParam(CAUTOTWEETNG, 'dpcheck_time_intval', 12) * 3600;
     $this->shorturl_always = EParameter::getComponentParam(CAUTOTWEETNG, 'shorturl_always', 1);
     $this->resend_attempts = EParameter::getComponentParam(CAUTOTWEETNG, 'resend_attempts', 2);
     // Deny All Rule Mode
     $this->denyall_rulemode = EParameter::getComponentParam(CAUTOTWEETNG, 'denyall_rulemode', 0);
     // Init AutoTweet logging
     $this->logger = AutotweetLogger::getInstance();
 }
Пример #10
0
 /**
  * callback.
  *
  * @return	void
  */
 public function callback()
 {
     // CSRF prevention disabled, we are trusting in code authentication
     /*
     if ($this->csrfProtection)
     {
     	$this->_csrfProtection();
     }
     */
     try {
         // $channelId = $this->input->getUint('channelId');
         $session = JFactory::getSession();
         $channelId = $session->get('channelId');
         // Invalidating
         $session->set('channelId', false);
         $gpluscode = $this->input->getVar('code');
         $logger = AutotweetLogger::getInstance();
         $logger->log(JLog::INFO, 'GplusChannels callback: ' . $gpluscode);
         // Error throw
         if (!empty($gpluscode)) {
             $channel = F0FTable::getAnInstance('Channel', 'AutoTweetTable');
             $result = $channel->load($channelId);
             if (!$result) {
                 $msg = 'Channel failed to load!';
                 $logger->log(JLog::ERROR, $msg);
                 throw new Exception($msg);
             }
             $gplusChannelHelper = new GplusChannelHelper($channel);
             $gplusChannelHelper->authenticate($gpluscode);
             // Redirect
             $url = 'index.php?option=com_autotweet&view=channels&task=edit&id=' . $channelId;
             $this->setRedirect($url);
             $this->redirect();
         }
     } catch (Exception $e) {
         $logger = AutotweetLogger::getInstance();
         $logger->log(JLog::ERROR, $e->getMessage());
         throw $e;
     }
 }
Пример #11
0
 /**
  * import
  *
  * @param   object  &$feed  Params
  *
  * @return	void
  */
 public function import(&$feed)
 {
     if (isset($feed->params)) {
         $feed->xtform = EForm::paramsToRegistry($feed);
     }
     $import_frequency = $feed->xtform->get('import_frequency', self::ALWAYS_EXPRESSION);
     if ($import_frequency != self::ALWAYS_EXPRESSION) {
         $automators = F0FModel::getTmpInstance('Automators', 'AutoTweetModel');
         $key = 'feed-' . $feed->id;
         $lastexec = $automators->lastRun($key);
         if ($lastexec->toUnix() < JFactory::getDate()->toUnix()) {
             $lastexec = 'now';
         }
         $next = TextUtil::nextScheduledDate($import_frequency, $lastexec);
         $logger = AutotweetLogger::getInstance();
         $logger->log(JLog::INFO, "Feed import: lastRunCheck {$lastexec} ({$key}, 0, {$next})");
         if (!$automators->lastRunCheck($key, 0, $next)) {
             $logger->log(JLog::INFO, "Feed import: lastRunCheck skipped!");
             return;
         }
     }
     $result = new StdClass();
     $result->added_items = 0;
     $simplePie = $this->_createSimplePie($feed);
     if ($simplePie->get_type() & SIMPLEPIE_TYPE_NONE) {
         throw new Exception(JText::sprintf('COM_AUTOTWEET_FEED_UNABLE_TO_PROCESS', $feed->xtform->get('title') . ' (' . $feed->xtform->get('feed') . ')'));
     } elseif ($simplePie->error) {
         throw new Exception("SimplePie error (ID={$feed->id}): " . $simplePie->error . ' for ' . $feed->xtform->get('title') . ' (' . $feed->xtform->get('feed') . ')');
     }
     $title = $simplePie->get_title();
     $c = (int) $feed->xtform->get('import_limit');
     $items = $simplePie->get_items(0, $c);
     $result->title = $title;
     $result->items = $items;
     $simplePie->__destruct();
     unset($items, $simplePie);
     // End SimplePie processing
     return $result;
 }
 /**
  * postQueuedMessages
  *
  * @param   integer  $max  Param
  *
  * @return	boolean
  */
 public function postQueuedMessages($max)
 {
     $now = JFactory::getDate();
     $logger = AutotweetLogger::getInstance();
     if (AUTOTWEETNG_JOOCIAL && !VirtualManager::getInstance()->isWorking($now)) {
         $logger->log(JLog::INFO, 'AutotweetPostHelper - VM not working now ' . $now->toISO8601(true));
         return false;
     }
     // Get msgs from queue (sending is allowed only, when publish date is not in the future)
     // Sub 1 minute to avoid problems when automator plugin and extension plugin are executed at the same time...
     $check_date = $now->toUnix();
     // Sub 1 minute check
     $mincheck_time_intval = EParameter::getComponentParam(CAUTOTWEETNG, 'mincheck_time_intval', 60);
     $check_date = $check_date - $mincheck_time_intval;
     $check_date = JFactory::getDate($check_date);
     $requests = RequestHelp::getRequestList($check_date, $max);
     $sharingHelper = SharingHelper::getInstance();
     $logger->log(JLog::INFO, 'postQueuedMessages Requests: ' . count($requests));
     foreach ($requests as $request) {
         $result = false;
         $message = null;
         try {
             $result = $sharingHelper->publishRequest($request);
         } catch (Exception $e) {
             $message = $e->getMessage();
             $logger->log(JLog::ERROR, 'postQueuedMessages: Exception! ' . $message);
         }
         if ($result) {
             RequestHelp::processed($request->id);
         } else {
             RequestHelp::saveError($request->id, $message);
         }
     }
     if (AUTOTWEETNG_JOOCIAL && empty($requests)) {
         $logger->log(JLog::INFO, 'VirtualManager: anything else to publish?');
         VirtualManager::getInstance()->enqueueEvergreenMessage($check_date, $max);
     }
 }
 /**
  * Checks for new events in the database (no triggers).
  *
  * @return	void
  */
 private function _onAfterRender()
 {
     $app = JFactory::getApplication();
     if ($app->isAdmin()) {
         return;
     }
     $option = $app->input->get('option');
     $task = $app->input->get('task');
     if ($option == 'com_autotweet' && $task == 'route') {
         return;
     }
     $this->cron_enabled = EParameter::getComponentParam(CAUTOTWEETNG, 'cron_enabled', false);
     if ($this->cron_enabled) {
         return;
     }
     $automators = F0FModel::getTmpInstance('Automators', 'AutoTweetModel');
     if (!$automators->lastRunCheck('automator', $this->interval)) {
         return;
     }
     $logger = AutotweetLogger::getInstance();
     // Bot/crawler detection
     $http_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null;
     $remote_addr = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null;
     if (0 < $this->detect_bots && ($this->detectCrawlerByAgent($http_user_agent) || $this->detectCrawlerByIP($remote_addr))) {
         $logger->log(JLog::WARNING, 'AutoTweet NG Automator-Plugin - crawler detected. IP: ' . $remote_addr . ', Agent: ' . $http_user_agent);
         return;
     }
     $logger->log(JLog::INFO, 'AutoTweet NG Automator-Plugin - executed - IP: ' . $remote_addr . ', Agent: ' . $http_user_agent);
     define('AUTOTWEET_AUTOMATOR_RUNNING', true);
     $helper = AutotweetPostHelper::getInstance();
     $helper->postQueuedMessages($this->max_posts);
     $feeds_enabled = EParameter::getComponentParam(CAUTOTWEETNG, 'feeds_enabled', false);
     if ($feeds_enabled) {
         $helper = FeedLoaderHelper::getInstance();
         $helper->importFeeds();
     }
 }
Пример #14
0
 /**
  * postArticle
  *
  * @param   object  $article  The item object.
  *
  * @return	boolean
  */
 public function postArticle($article)
 {
     $logger = AutotweetLogger::getInstance();
     $logger->log(JLog::INFO, 'Manual Post', $article);
     $xtform = json_decode($article['params']);
     $cats = $this->getContentCategories($xtform->catid);
     $catIds = $cats[0];
     $isIncluded = $this->isCategoryIncluded($catIds);
     $isExcluded = $this->isCategoryExcluded($catIds);
     if (!$isIncluded || $isExcluded) {
         return true;
     }
     if (!$this->enabledAccessLevel($this->accesslevels)) {
         return true;
     }
     if (AUTOTWEETNG_JOOCIAL && $article['autotweet_advanced_attrs']) {
         $this->advanced_attrs = AdvancedattrsHelper::retrieveAdvancedAttrs($article['autotweet_advanced_attrs']);
         if (isset($this->advanced_attrs->ref_id)) {
             // Safe to save
             $this->saveAdvancedAttrs($this->advanced_attrs->ref_id);
             unset($article['autotweet_advanced_attrs']);
         }
     }
     $params = null;
     if (array_key_exists('params', $article)) {
         $params = $article['params'];
     }
     // To avoid duplication
     unset($article['id']);
     $native_object = json_encode($article);
     if (empty($article['plugin'])) {
         $article['plugin'] = 'autotweetpost';
     }
     $this->_name = $article['plugin'];
     // $this->content_language = $article['language'];
     return $this->postStatusMessage($article['ref_id'], $article['publish_up'], $article['description'], self::TYPE_POST, $article['url'], $article['image_url'], $native_object, $params);
 }
Пример #15
0
 /**
  * queueMessage
  *
  * @param   string  $articleid         Param
  * @param   string  $source_plugin     Param
  * @param   string  $publish_up        Param
  * @param   string  $description       Param
  * @param   string  $typeinfo          Param
  * @param   string  $url               Param
  * @param   string  $image_url         Param
  * @param   object  &$native_object    Param
  * @param   string  &$advanced_attrs   Param
  * @param   string  &$params           Param
  * @param   string  $content_language  Param
  *
  * @return	mixed - false, or id of request
  */
 public static function insertRequest($articleid, $source_plugin, $publish_up, $description, $typeinfo = 0, $url = '', $image_url = '', &$native_object = null, &$advanced_attrs = null, &$params = null, $content_language = null)
 {
     $logger = AutotweetLogger::getInstance();
     // Check if message is already queued (it makes no sense to queue message more than once when modfied)
     // if message is already queued, correct the publish date
     $requestsModel = F0FModel::getTmpInstance('Requests', 'AutoTweetModel');
     $requestsModel->set('ref_id', $articleid);
     $requestsModel->set('plugin', $source_plugin);
     $requestsModel->set('typeinfo', $typeinfo);
     $row = $requestsModel->getFirstItem();
     $id = $row->id;
     // Avoid databse warnings when desc is longer then expected
     if (!empty($description)) {
         $description = TextUtil::cleanText($description);
         $description = JString::substr($description, 0, SharingHelper::MAX_CHARS_TITLE);
     }
     $routeHelp = RouteHelp::getInstance();
     if ($content_language) {
         $routeHelp->setContentLanguage($content_language);
     }
     if (AUTOTWEETNG_JOOCIAL && EParameter::getComponentParam(CAUTOTWEETNG, 'paywall_mode') && EParameter::getComponentParam(CAUTOTWEETNG, 'paywall_donot_post_url')) {
         $url = 'index.php';
     }
     $url = $routeHelp->getAbsoluteUrl($url);
     if (AUTOTWEETNG_JOOCIAL && EParameter::getComponentParam(CAUTOTWEETNG, 'paywall_mode') && EParameter::getComponentParam(CAUTOTWEETNG, 'paywall_donot_image_url')) {
         $image_url = null;
     }
     if (empty($image_url)) {
         // Default image: used in media mode when no image is available
         $image_url = EParameter::getComponentParam(CAUTOTWEETNG, 'default_image', '');
     }
     if (!empty($image_url)) {
         $image_url = $routeHelp->getAbsoluteUrl($image_url, true);
     }
     $row->reset();
     if ($id) {
         $row->load($id);
     }
     // If there's no date, it means now
     if (empty($publish_up)) {
         $publish_up = JFactory::getDate()->toSql();
     }
     $request = array('id' => $id, 'ref_id' => $articleid, 'plugin' => $source_plugin, 'publish_up' => $publish_up, 'description' => $description, 'typeinfo' => $typeinfo, 'url' => $url, 'image_url' => $image_url, 'native_object' => $native_object, 'params' => $params, 'published' => 0);
     $logger->log(JLog::INFO, 'Enqueued request', $request);
     // Saving the request
     $queued = $row->save($request);
     if (!$queued) {
         $logger->log(JLog::ERROR, 'queueMessage: error storing message to database message queue, article id = ' . $articleid . ', error message = ' . $row->getError());
     } else {
         $logger->log(JLog::INFO, 'queueMessage: message stored/updated to database message queue, article id = ' . $articleid);
     }
     if (!$id) {
         $id = $row->id;
     }
     if ($advanced_attrs && isset($advanced_attrs->attr_id)) {
         $row = F0FModel::getTmpInstance('Advancedattrs', 'AutoTweetModel')->getTable();
         $row->reset();
         $row->load($advanced_attrs->attr_id);
         $attr = array('id' => $advanced_attrs->attr_id, 'request_id' => $id);
         // Updating attr
         $result = $row->save($attr);
         if (!$result) {
             $logger->log(JLog::ERROR, 'Updating attr, attr_id = ' . $advanced_attrs->attr_id . ', error message = ' . $row->getError());
         } else {
             $logger->log(JLog::INFO, 'Updating attr, attr_id = ' . $advanced_attrs->attr_id);
         }
     }
     $app = JFactory::getApplication();
     if ($app->isAdmin() && JFactory::getConfig()->get('show_req_notification', true)) {
         $msg = VersionHelper::getFlavourName() . ': ' . JText::sprintf('COM_AUTOTWEET_REQUEST_ENQUEUED_MSG', $id);
         $app->enqueueMessage($msg);
     }
     return $queued ? $id : false;
 }
Пример #16
0
    echo $thirdparty_item['message'];
    ?>
								</td>
							</tr>
							<?php 
}
?>
						</tbody>
					</table>

				</div>

				<div class="span4">
					<?php 
include_once 'systeminfo.php';
$logger = AutotweetLogger::getInstance();
$log_level = $logger->isLogging();
switch ($log_level) {
    case 8:
        $msg = JText::_('COM_AUTOTWEET_COMPARAM_LOGLEVEL_ERROR_1');
        break;
    case 16:
        $msg = '<span class="badge badge-info">' . JText::_('COM_AUTOTWEET_COMPARAM_LOGLEVEL_WARN_2') . '</span>';
        break;
    case 64:
        $msg = '<span class="badge badge-info">' . JText::_('COM_AUTOTWEET_COMPARAM_LOGLEVEL_ALL_3') . '</span>';
        break;
    default:
        $msg = JText::_('COM_AUTOTWEET_COMPARAM_LOGLEVEL_OFF_0');
}
if ($log_level) {
Пример #17
0
 /**
  * sendMessage.
  *
  * @param   string  $message  Params
  * @param   object  $data     Params
  *
  * @return  boolean
  */
 public function sendMessage($message, $data)
 {
     $title = $data->title;
     $text = $data->fulltext;
     $url = $data->url;
     $image_url = $data->image_url;
     $media_mode = $this->getMediaMode();
     $logger = AutotweetLogger::getInstance();
     $logger->log(JLog::INFO, 'LiOAuth2ChannelHelper sendMessage', $message);
     $result = null;
     $content = array();
     // Post message and/or media
     switch ($media_mode) {
         case 'attachment':
             $post_attach = true;
             $post_msg = false;
             break;
         case 'both':
             $post_msg = true;
             $post_attach = true;
             break;
         case 'message':
         default:
             $post_msg = true;
             $post_attach = false;
     }
     if (!empty($title)) {
         $title = TextUtil::truncString($title, self::MAX_CHARS_TITLE);
         $content['title'] = $title;
     }
     if (!empty($text)) {
         $text = TextUtil::truncString($text, self::MAX_CHARS_TEXT);
         $content['description'] = $text;
     }
     if (!empty($url)) {
         $content['submitted-url'] = $url;
     }
     if ($post_attach && !empty($image_url)) {
         $content['submitted-image-url'] = $image_url;
     }
     // Message
     if ($post_msg) {
         $content['comment'] = $message;
     }
     // Default for visibility
     $private = false;
     try {
         $response = $this->getApiInstance()->share2('new', $content, $private);
         $result = $this->processResponse($response);
     } catch (Exception $e) {
         $result = array(false, $e->getMessage());
     }
     return $result;
 }
Пример #18
0
 /**
  * uploadImage
  *
  * @param   string  $image_url  Param
  *
  * @return	object
  */
 public function uploadImage($image_url)
 {
     if (empty($image_url)) {
         return false;
     }
     $imagefile = ImageUtil::getInstance()->downloadImage($image_url);
     if (!$imagefile) {
         return false;
     }
     $status = false;
     try {
         $uid = $this->getUserId();
         $gid = $this->channel->params->get('vkgroup_id');
         $vk = $this->getApiInstance();
         if ($gid) {
             $parameters = array('gid' => $gid);
         } else {
             $parameters = array('uid' => $uid);
         }
         $result = $vk->api('photos.getWallUploadServer', $parameters);
         if (array_key_exists('response', $result)) {
             $response = $result['response'];
             if (array_key_exists('upload_url', $response)) {
                 $upload_url = $response['upload_url'];
                 $ch = curl_init();
                 $data = array('photo' => '@' . $imagefile);
                 curl_setopt($ch, CURLOPT_URL, $upload_url);
                 curl_setopt($ch, CURLOPT_POST, 1);
                 curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                 $status = curl_exec($ch);
                 if (!$status && curl_errno($ch)) {
                     $logger = AutotweetLogger::getInstance();
                     $logger->log(JLog::ERROR, curl_error($ch));
                 } else {
                     $status = json_decode($status);
                     $photo = json_decode($status->photo);
                     $parameters = array('server' => $status->server, 'photo' => $status->photo, 'hash' => $status->hash);
                     if ($gid) {
                         $parameters['gid'] = $gid;
                     } else {
                         $parameters['uid'] = $uid;
                     }
                     $status = $vk->api('photos.saveWallPhoto', $parameters);
                     if (array_key_exists('response', $status) && is_array($status['response']) && count($status['response']) == 1) {
                         $status = $status['response'][0];
                     }
                 }
                 curl_close($ch);
             }
         }
         if (array_key_exists('error', $result)) {
             $message = 'Error (' . $result['error']['error_code'] . ' ' . $result['error']['error_msg'] . ')';
             $logger = AutotweetLogger::getInstance();
             $logger->log(JLog::ERROR, $message);
         }
     } catch (Exception $e) {
         $logger = AutotweetLogger::getInstance();
         $logger->log(JLog::ERROR, $e->getMessage());
     }
     ImageUtil::getInstance()->releaseImage($imagefile);
     return $status;
 }
Пример #19
0
 /**
  * correctUrlLang.
  *
  * @param   string  $url  Param
  *
  * @return	string
  */
 private function correctUrlLang($url)
 {
     $language = null;
     $logger = AutotweetLogger::getInstance();
     if (self::LANGMGMT_REPLACECONTENTLANG == $this->langmgmt_enabled && !empty($this->langmgmt_content_language)) {
         $language = $this->langmgmt_content_language;
         $logger->log(JLog::INFO, "correctUrlLang LANGMGMT_REPLACECONTENTLANG " . $language);
         if ($language == '*') {
             $logger->log(JLog::WARNING, "correctUrlLang: language * nothing to do.");
             return $url;
         }
         if (empty($language)) {
             $logger->log(JLog::WARNING, 'correctUrlLang: no language definition. Mode: ' . self::LANGMGMT_REPLACECONTENTLANG);
             return $url;
         }
         $langSefValue = $this->getLanguageSef($language);
         return $this->correctUrlLangReplace($url, $langSefValue);
     }
     if (self::LANGMGMT_REPLACELANG == $this->langmgmt_enabled && !empty($this->langmgmt_default_language)) {
         $language = $this->langmgmt_default_language;
         $logger->log(JLog::INFO, "correctUrlLang LANGMGMT_REPLACELANG " . $language);
         if (empty($language)) {
             $logger->log(JLog::WARNING, 'correctUrlLang: no language definition. Mode: ' . self::LANGMGMT_REPLACELANG);
             return $url;
         }
         $langSefValue = $this->getLanguageSef($language);
         return $this->correctUrlLangReplace($url, $langSefValue);
     }
     if (self::LANGMGMT_REMOVELANG == $this->langmgmt_enabled) {
         $logger->log(JLog::INFO, "correctUrlLang LANGMGMT_REMOVELANG");
         return $this->correctUrlLangReplace($url, '');
     }
     return $url;
 }
Пример #20
0
 /**
  * download
  *
  * @param   array  $params  Params
  *
  * @return	bool
  */
 public function download($params)
 {
     $logger = AutotweetLogger::getInstance();
     $rel_src = $params->get('rel_src');
     $img_folder = $params->get('img_folder');
     $sub_folder = $params->get('sub_folder');
     $img_name_type = $params->get('img_name_type');
     $imageHelper = ImageUtil::getInstance();
     $filename = $imageHelper->downloadImage($this->src);
     if (!$filename || !file_exists($filename)) {
         $logger->log(JLog::ERROR, 'download: failed ' . $this->src);
         return false;
     }
     // Main folder
     $path = JPATH_ROOT . DIRECTORY_SEPARATOR . $img_folder;
     // Sub folder
     $path_subfolder = $this->_getSubfolder($path, $sub_folder);
     if (!JFolder::exists($path_subfolder)) {
         $result = JFolder::create($path_subfolder);
         if (!$result) {
             $imageHelper->releaseImage($filename);
             $logger->log(JLog::ERROR, 'download: JFolder::create subfolder ' . $path_subfolder);
             return false;
         }
     }
     $img_filename = $this->_getImgFilename($filename, $img_name_type);
     $final_filename = $path_subfolder . DIRECTORY_SEPARATOR . $img_filename;
     $result = JFile::move($filename, $final_filename);
     if (!$result) {
         $imageHelper->releaseImage($filename);
         $logger->log(JLog::ERROR, 'download: JFile::move ' . $filename . ' - ' . $final_filename);
         return false;
     }
     $imgurl = str_replace(JPATH_ROOT . DIRECTORY_SEPARATOR, '', $final_filename);
     $this->original_src = $this->src;
     if ($rel_src) {
         $this->src = $imgurl;
     } else {
         $this->src = RouteHelp::getInstance()->getRoot() . $imgurl;
     }
     return true;
 }
Пример #21
0
 /**
  * loadINI
  *
  * @return	bool
  */
 protected static function loadINI()
 {
     if (self::$_compinfo && self::$_pluginfo) {
         return true;
     }
     self::$_compinfo = array();
     self::$_pluginfo = array();
     self::$_thirdparty = array();
     // Get component parameter
     $version_check = EParameter::getComponentParam(CAUTOTWEETNG, 'version_check', 1);
     $remoteFile = self::SERVER_INI_PATH . self::SERVER_INI_FILE;
     $localFile = JPATH_AUTOTWEET_HELPERS . '/' . self::SERVER_INI_FILE;
     $file = $localFile;
     if ($version_check) {
         try {
             $ch = curl_init($remoteFile);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
             curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, self::CXN_TIMEOUT);
             curl_setopt($ch, CURLOPT_TIMEOUT, self::EXEC_TIMEOUT);
             $data = curl_exec($ch);
             curl_close($ch);
             file_put_contents($localFile, $data);
         } catch (Exception $e) {
             $msg = $e->getMessage();
             $logger->log(JLog::ERROR, 'AutoTweetNG - ' . $msg);
         }
     }
     jimport('joomla.error.error');
     jimport('joomla.registry.registry');
     $registry = new JRegistry();
     if (!$registry->loadFile($file, 'INI', array('processSections' => 'true'))) {
         $logger->log(JLog::ERROR, 'AutoTweetNG - error reading INI file ' . $file);
         return false;
     }
     // Init logging
     $logger = AutotweetLogger::getInstance();
     $db = JFactory::getDBO();
     // Get component info and remove from array
     $data = JApplicationHelper::parseXMLInstallFile(JPATH_COMPONENT_ADMINISTRATOR . DIRECTORY_SEPARATOR . self::COMP_INSTALL_FILE);
     self::$_compinfo = array('id' => $registry->get('component.id'), 'name' => $registry->get('component.name'), 'server_version' => $registry->get('component.version'), 'client_version' => $data['version'], 'home' => $registry->get('component.home'), 'faq' => $registry->get('component.faq'), 'download' => $registry->get('component.download'), 'support' => $registry->get('component.support'), 'products' => $registry->get('component.products'), 'twitter' => $registry->get('component.twitter'), 'jed' => $registry->get('component.jed'), 'message' => $registry->get('component.message'), 'news' => $registry->get('component.news'));
     $extensions = TextUtil::listToArray($registry->get('component.extensions'));
     foreach ($extensions as $extension) {
         $state = self::EXT_NOTINSTALLED;
         $config = '';
         $client_version = '';
         $type = $registry->get($extension . '.type');
         $id = $registry->get($extension . '.id');
         $source = $registry->get($extension . '.source');
         if ('module' == $type) {
             $mod_filename = 'mod_' . $id;
             // Get the module id and set url for config
             $pluginsModel = F0FModel::getTmpInstance('Extensions', 'ExtlyModel');
             $pluginsModel->savestate(false)->setState('element', $mod_filename);
             $rows = $pluginsModel->getItemList();
             if (!empty($rows)) {
                 $row = $rows[0];
                 if ($row->client_id) {
                     $path = JPATH_ADMINISTRATOR . '/modules/' . $mod_filename . DIRECTORY_SEPARATOR . $mod_filename . '.xml';
                 } else {
                     $path = JPATH_ROOT . '/modules/' . $mod_filename . DIRECTORY_SEPARATOR . $mod_filename . '.xml';
                 }
                 $data = JApplicationHelper::parseXMLInstallFile($path);
                 $client_version = $data['version'];
                 if (self::_isEnabled($mod_filename)) {
                     $state = self::EXT_ENABLED;
                 } else {
                     $state = self::EXT_DISABLED;
                 }
                 // $config = 'index.php?option=com_modules&task=module.edit&id=' . $row->extension_id;
             }
         } else {
             // Get the plugin id and set url for config
             $pluginsModel = F0FModel::getTmpInstance('Plugins', 'AutoTweetModel');
             $pluginsModel->savestate(false)->set('element_id', $id);
             $rows = $pluginsModel->getItemList();
             if (!empty($rows)) {
                 $row = $rows[0];
                 $path = JPATH_PLUGINS . DIRECTORY_SEPARATOR . $row->folder . DIRECTORY_SEPARATOR . $row->element . DIRECTORY_SEPARATOR . $row->element . '.xml';
                 $data = JApplicationHelper::parseXMLInstallFile($path);
                 $client_version = $data['version'];
                 if (JPluginHelper::isEnabled($row->folder, $row->element)) {
                     $state = self::EXT_ENABLED;
                 } else {
                     $state = self::EXT_DISABLED;
                 }
                 $config = 'index.php?option=com_plugins&task=plugin.edit&extension_id=' . $row->id;
             }
         }
         // Append plugin state to result arrays
         if (self::FM_EXT_SOURCE == $source) {
             self::$_pluginfo[] = array('id' => $id, 'name' => $registry->get($extension . '.name'), 'state' => $state, 'client_version' => $client_version, 'server_version' => $registry->get($extension . '.version'), 'message' => $registry->get($extension . '.message'), 'config' => $config);
         } else {
             self::$_thirdparty[] = array('id' => $id, 'name' => $registry->get($extension . '.name'), 'state' => $state, 'client_version' => $client_version, 'message' => $registry->get($extension . '.message'), 'config' => $config, 'source' => $source, 'download' => $registry->get($extension . '.download'));
         }
     }
     // Add installed plugins without entry in ini file to 3rd party list
     $pluginsModel = F0FModel::getTmpInstance('Plugins', 'AutoTweetModel');
     $pluginsModel->savestate(false);
     $plugins = $pluginsModel->getItemList();
     foreach ($plugins as $plugin) {
         $id = $plugin->element;
         $type = $plugin->folder;
         if (!self::in_array_recursive($id, self::$_pluginfo) && !self::in_array_recursive($id, self::$_thirdparty)) {
             $path = JPATH_PLUGINS . DIRECTORY_SEPARATOR . $type . DIRECTORY_SEPARATOR . $id . DIRECTORY_SEPARATOR . $id . '.xml';
             $data = JApplicationHelper::parseXMLInstallFile($path);
             $client_version = $data['version'];
             if (JPluginHelper::isEnabled($type, $id)) {
                 $state = self::EXT_ENABLED;
             } else {
                 $state = self::EXT_DISABLED;
             }
             $config = 'index.php?option=com_plugins&task=plugin.edit&extension_id=' . $plugin->id;
             if (!empty($data['authorUrl'])) {
                 $source = $data['authorUrl'];
                 $download = $data['authorUrl'];
             } else {
                 $source = self::EXT_UNKNOWN;
                 $download = '';
             }
             self::$_thirdparty[] = array('id' => $id, 'name' => $plugin->name, 'state' => $state, 'client_version' => $client_version, 'message' => 'unknown extension plugin', 'config' => $config, 'source' => $source, 'download' => $download);
         }
     }
     return true;
 }
Пример #22
0
 /**
  * getImportBegin
  *
  * @return	void
  */
 public function getImportEnd()
 {
     // CSRF prevention
     if ($this->csrfProtection) {
         $this->_csrfProtection();
     }
     $message = array('status' => false, 'error_message' => JText::_('COM_AUTOTWEET_VIEW_FEEDS_IMPORT_FAILED_ERR'));
     try {
         $logger = AutotweetLogger::getInstance();
         $logger->log(JLog::INFO, "getImportEnd");
         $message = array('status' => true, 'error_message' => 'ok');
     } catch (Exception $e) {
         $message['status'] = false;
         $message['error_message'] .= ' End ' . $e->getMessage();
     }
     $message = json_encode($message);
     echo EJSON_START . $message . EJSON_END;
     flush();
     JFactory::getApplication()->close();
 }
Пример #23
0
 /**
  * getFullText
  *
  * @param   string  $permalink    Params
  * @param   bool    $extractOnly  Params
  *
  * @return	string
  */
 private function _getFullText($permalink, $extractOnly = false)
 {
     // Get Source Full Text
     include_once JPATH_ADMINISTRATOR . '/components/com_autotweet/libs/readability/Readability.php';
     $result = false;
     try {
         $page = FeedTextHelper::getUrl($permalink, 'html');
         if (empty($page)) {
             return false;
         }
         $parts = FeedTextHelper::extractHttp($page);
         if (!(array_key_exists('body', $parts) && array_key_exists('header', $parts))) {
             return false;
         }
         $body = FeedTextHelper::convertToUtf8($parts['body'], $parts['header']);
         if (empty($body)) {
             // Failed to Get Source Full Text: body empty');
             return false;
         }
         if (function_exists('tidy_parse_string')) {
             $tidy = tidy_parse_string($body, array(), 'UTF8');
             $tidy->cleanRepair();
             $body = $tidy->value;
         }
         if ($extractOnly) {
             return $body;
         }
         $readability = new phpreadability\Readability($body, $permalink);
         $readability->debug = false;
         $readability->convertLinksToFootnotes = self::$_params->get('link_table');
         if (!$readability->init()) {
             return false;
         }
         $this->_cleanSpecifically($readability);
         $innerHTML = $readability->getContent()->innerHTML;
         if ($innerHTML == '<p>Sorry, Readability was unable to parse this page for content.</p>') {
             // Failed to Get Source Full Text: Readability unable to parse');
             return false;
         }
         if (function_exists('tidy_parse_string')) {
             $tidy = tidy_parse_string($innerHTML, array('indent' => true, 'show-body-only' => true), 'UTF8');
             $tidy->cleanRepair();
             $innerHTML = $tidy->value;
         }
         // Got Source Full Text
         $result = new StdClass();
         $result->title = $readability->getTitle()->textContent;
         $text = $this->_adjustText($innerHTML);
         // No Ids or readability, classes pls
         $text = str_replace('id="readability-', 'class="joo-', $text);
         $text = str_replace('readability-', 'joo-', $text);
         $text = str_replace('<h3>References</h3>', '<h3>' . JText::_('COM_AUTOTWEET_VIEW_FEED_REFERENCES') . '</h3>', $text);
         $result->content = $text;
     } catch (Exception $e) {
         $error_message = $e->getMessage();
         AutotweetLogger::getInstance()->log(JLog::ERROR, 'AutoTweetNG - ' . $error_message);
     }
     return $result;
 }
Пример #24
0
 /**
  * sendMessage.
  *
  * @param   string  $message  Params
  * @param   object  $data     Params
  *
  * @return	booleans
  */
 public function sendMessage($message, $data)
 {
     $isUserProfile = $this->isUserProfile();
     if ($this->channel->params->get('open_graph_features') && $isUserProfile) {
         return $this->sendFacebookOG($message, $data->title, $data->fulltext, $data->url, $data->org_url, $data->image_url, $this->getMediaMode(), $data);
     }
     $title = $data->title;
     $text = $data->fulltext;
     $url = $data->url;
     $org_url = $data->org_url;
     $image_url = $data->image_url;
     $media_mode = $this->getMediaMode();
     $logger = AutotweetLogger::getInstance();
     $logger->log(JLog::INFO, 'sendFacebookMessage', $message);
     $fb_id = $this->getFbChannelId();
     $fb_token = $this->get('fbchannel_access_token');
     // Includes a workaround for Facebook ?ref=nf url extension problem and short urls
     // if API bug is fixed, replace all org_url variables by url
     $result = null;
     // Post message and/or attachment
     switch ($media_mode) {
         case 'attachment':
             $post_attach = true;
             $post_msg = false;
             break;
         case 'both':
             $post_msg = true;
             $post_attach = true;
             break;
         case 'message':
         default:
             $post_msg = true;
             $post_attach = false;
     }
     if (empty($org_url)) {
         $post_attach = false;
     }
     if (empty($text) && empty($image_url)) {
         $post_attach = false;
     }
     // Attachment: do also not post when text and image are empty
     if ($post_attach) {
         // Extract data for action link
         $url_comps = parse_url($org_url);
         $actionlink_text = $url_comps['host'];
         $actions = array();
         $actions['name'] = $actionlink_text;
         $actions['link'] = $org_url;
         $status_type = array('value' => 'wall_post');
         $title = TextUtil::truncString($title, self::MAX_CHARS_NAME);
         $arguments = array('link' => $org_url, 'name' => $title, 'caption' => $actionlink_text, 'description' => $text, 'actions' => json_encode($actions), 'access_token' => $fb_token, 'status_type' => json_encode($status_type));
         if ($isUserProfile) {
             $privacy = $this->get('sharedwith', 'EVERYONE');
             $privacy = array('value' => $privacy);
             $arguments['privacy'] = json_encode($privacy);
         }
         // Include image tag only, when image url is not empty to avoid error "... must have a valid src..."
         if (!empty($image_url)) {
             $arguments['picture'] = $image_url;
         }
         // Message
         if ($post_msg) {
             $arguments['message'] = $message;
         }
     } else {
         $arguments = array('message' => $message, 'access_token' => $fb_token);
     }
     $target_id = $data->xtform->get('target_id');
     if (EParameter::getComponentParam(CAUTOTWEETNG, 'targeting', false) && $target_id) {
         $this->addTargetArguments($arguments, $target_id);
     }
     try {
         $fbapi = $this->getApiInstance();
         // Simulated
         if ($this->channel->params->get('use_own_api') == 0) {
             $fbapi->api("/me/permissions");
             $result = array(true, JText::_('COM_AUTOTWEET_VIEW_SIMULATED_OK'));
         } else {
             $result = $fbapi->api("/{$fb_id}/feed", 'post', $arguments);
             $msg = 'Facebook id: ' . $result['id'];
             $result = array(true, $msg);
         }
     } catch (Exception $e) {
         $code = $e->getCode();
         $msg = $code . ' - ' . $e->getMessage();
         $donot_fberror02 = EParameter::getComponentParam(CAUTOTWEETNG, 'donot_fberror02', 0);
         $donottrack_error = $donot_fberror02 && ($code == 0 || $code == 2);
         if ($donottrack_error) {
             $logger = AutotweetLogger::getInstance();
             $logger->log(JLog::ERROR, 'DONOT_FBERROR02: ' . $msg);
             $result = array(true, $msg);
         } else {
             $result = array(false, $msg);
         }
     }
     return $result;
 }
Пример #25
0
 /**
  * getChannels
  *
  * @param   string  $author  Param
  *
  * @return	array
  */
 public function getChannels($author)
 {
     $channels = F0FModel::getTmpInstance('Channels', 'AutoTweetModel');
     $channels->set('published', true);
     $channels->set('scope', 'S');
     $channels->set('filter_order', 'ordering');
     $channels->set('filter_order_Dir', 'ASC');
     $list = $channels->getItemList(true);
     if (!empty($author)) {
         $user_id = JUserHelper::getUserId($author);
         if ($user_id) {
             $userChannels = F0FModel::getTmpInstance('Channels', 'AutoTweetModel');
             $userChannels->set('published', true);
             $userChannels->set('scope', 'U');
             $userChannels->set('created_by', $user_id);
             $userChannels->set('filter_order', 'ordering');
             $userChannels->set('filter_order_Dir', 'ASC');
             $userList = $userChannels->getItemList(true);
             $list = array_merge($list, $userList);
         }
     }
     $channels = array();
     foreach ($list as $channel) {
         $channels[$channel->id] = self::createChannel($channel);
     }
     $logger = AutotweetLogger::getInstance();
     $channels_ids = array_keys($channels);
     $logger->log(JLog::INFO, 'ChannelFactory getChannels user=' . $author, $channels_ids);
     return $channels;
 }
Пример #26
0
 /**
  * isUserProfile.
  *
  * @return	boolean
  */
 protected function isUserProfile()
 {
     try {
         $fb_id = $this->getFbChannelId();
         $fb_token = $this->get('fbchannel_access_token');
         $arguments = array('access_token' => $fb_token, 'metadata' => 1);
         $user = $this->getApiInstance()->api('/' . $fb_id, $arguments);
         if (isset($user['metadata']['type'])) {
             return $user['metadata']['type'] == 'user';
         }
         return $user['id'] == $fb_id && array_key_exists('link', $user) && strpos($user['link'], 'www.facebook.com/app_scoped_user_id') !== false;
     } catch (Exception $e) {
         $code = $e->getCode();
         $msg = $code . ' - ' . $e->getMessage();
         $logger = AutotweetLogger::getInstance();
         $logger->log(JLog::ERROR, 'isUserProfile: ' . $msg);
     }
     return false;
 }
Пример #27
0
 /**
  * _sendTwitterMessageWithImage
  *
  * @param   string  $status_msg  Param
  * @param   string  $imagefile   Param
  *
  * @return	array
  */
 private function _sendTwitterMessageWithImage($status_msg, $imagefile)
 {
     $logger = AutotweetLogger::getInstance();
     $logger->log(JLog::INFO, '_sendTwitterMessageWithImage: ' . $status_msg . ' - ' . $imagefile);
     $api = $this->getApiInstance();
     if ($imagefile) {
         $basename = basename($imagefile);
         list($width, $height, $type, $attr) = getimagesize($imagefile);
         $mimetype = image_type_to_mime_type($type);
         $binaryimage_load = EParameter::getComponentParam(CAUTOTWEETNG, 'binaryimage_load');
         if ($binaryimage_load) {
             $handle = fopen($imagefile, "rb");
             $postimage = fread($handle, filesize($imagefile));
             fclose($handle);
         } else {
             $postimage = '@' . $imagefile;
         }
         $code = $api->request('POST', $api->url('1.1/statuses/update_with_media'), array('media[]' => "{$postimage};type={$mimetype};filename={$basename}", 'status' => $status_msg), true, true);
     } else {
         $code = $api->request('POST', $api->url('1.1/statuses/update'), array('status' => $status_msg));
     }
     return $this->_processResponse($code, $api);
 }
Пример #28
0
 /**
  * nextScheduledDate
  *
  * @param   string  $unix_mhdmd  Param
  * @param   string  $now         Param
  *
  * @return	string
  */
 public static function nextScheduledDate($unix_mhdmd, $now = 'now')
 {
     JLoader::import('extly.scheduler.scheduler');
     try {
         $cron = Scheduler::getParser($unix_mhdmd);
         $cron->setExpression($unix_mhdmd);
         $nextDate = $cron->getNextRunDate($now)->getTimestamp();
         $nextDate = JFactory::getDate($nextDate);
         return $nextDate;
     } catch (Exception $e) {
         $logger = AutotweetLogger::getInstance();
         $logger->log(JLog::ERROR, 'nextScheduledDate: ' . $e->getMessage());
         return null;
     }
 }
Пример #29
0
 /**
  * save
  *
  * @param   array   &$content  Params
  * @param   object  &$params   Params
  *
  * @return	int
  */
 public function save(&$content, &$params)
 {
     $pending_to_feature = array();
     $value = 0;
     $c = 0;
     $logger = AutotweetLogger::getInstance();
     foreach ($content as $article) {
         try {
             $id = $this->_save($article, $params);
             if ($id) {
                 $c++;
                 if ($article->featured) {
                     $pending_to_feature[] = $id;
                     $value = $article->featured;
                 }
             } else {
                 $logger->log(JLog::WARNING, 'FeedGeneratorHelper: save ID=' . $id . ' Title=' . $article->title);
             }
         } catch (Exception $e) {
             $logger->log(JLog::ERROR, 'FeedGeneratorHelper: save ' . $e->getMessage());
         }
     }
     if (!empty($pending_to_feature)) {
         $modelName = $params->get('contenttype_id');
         $model = F0FModel::getTmpInstance($modelName, 'AutoTweetModel');
         $model->featured($pending_to_feature, $value);
     }
     return $c;
 }
Пример #30
0
 /**
  * insertRequest
  *
  * @param   int     $ref_id            Param
  * @param   string  $plugin            Param
  * @param   date    $publish_up        Param
  * @param   string  $description       Param
  * @param   int     $typeinfo          Param
  * @param   string  $url               Param
  * @param   string  $image_url         Param
  * @param   json    &$native_object    Param
  * @param   object  &$advanced_attrs   Param
  * @param   object  &$params           Param
  * @param   string  $content_language  Param
  *
  * @return	mixed (bool or request Id)
  */
 public static function insertRequest($ref_id, $plugin, $publish_up, $description, $typeinfo = 0, $url = '', $image_url = '', &$native_object = null, &$advanced_attrs = null, &$params = null, $content_language = null)
 {
     if ($publish_up == 0) {
         $publish_up = JFactory::getDate()->toSql();
     }
     if ($advanced_attrs) {
         if (!empty($advanced_attrs->description)) {
             $description = $advanced_attrs->description;
         }
         if (!empty($advanced_attrs->hashtags)) {
             $description .= ' ' . $advanced_attrs->hashtags;
         }
         if ($advanced_attrs->postthis == PlgAutotweetBase::POSTTHIS_NO) {
             // Post this or not
             return null;
         }
         if (($image = $advanced_attrs->image) && !empty($image)) {
             // This image
             if ($image == 'none') {
                 $image_url = null;
             } else {
                 $image_url = $image;
             }
         }
         if (isset($advanced_attrs->image_url) && ($image = $advanced_attrs->image_url) && !empty($image)) {
             $image_url = $image;
         }
         if (($agenda = $advanced_attrs->agenda) && count($agenda) > 0) {
             // The first date, it's the next date
             $publish_up = AdvancedattrsHelper::getNextAgendaDate($agenda);
             if (empty($publish_up)) {
                 $logger = AutotweetLogger::getInstance();
                 $logger->log(JLog::INFO, 'insertRequest: ref_id=' . $ref_id . ' - No Next Agenda Date.');
                 return false;
             }
         }
     }
     $result = RequestHelp::insertRequest($ref_id, $plugin, $publish_up, $description, $typeinfo, $url, $image_url, $native_object, $advanced_attrs, $params, $content_language);
     return $result;
 }