/** * getInstance * * @return Instance */ public static function &getInstance() { if (!self::$_instance) { self::$_instance = new RouteHelp(); } return self::$_instance; }
/** * Checks the record for validity * * @return int True if the record is valid */ public function check() { if (empty($this->image_url)) { // Default image: used in media mode when no image is available $this->image_url = EParameter::getComponentParam(CAUTOTWEETNG, 'default_image', ''); } if (!empty($this->image_url)) { $routeHelp = RouteHelp::getInstance(); $this->image_url = $routeHelp->getAbsoluteUrl($this->image_url, true); } return true; }
/** * 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(); }
/** * getImageFromTextWithMarkdown * * @param string $text Param. * * @return string */ public static function getImageFromTextWithMarkdown($text) { $image = null; $pattern = '/!\\[[^\\n\\]]*\\]\\(([^\\n\\)]*)\\)/'; if (preg_match($pattern, $text, $match)) { $image = $match[1]; if (!RouteHelp::getInstance()->isAbsoluteUrl($image)) { // Guessing host $pattern = '/href=["|\'](.*)["|\']/'; if (preg_match($pattern, $text, $match)) { $url = $match[1]; $uri = JUri::getInstance($url); $uri->setQuery(''); $uri->setPath($image); $image = $uri->toString(); } } } return $image; }
/** * 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; }
/** * process * * @param object &$feed Params * @param array &$loadResult Params * @param bool $onlyFirstItem Params * * @return array */ public function process(&$feed, &$loadResult, $onlyFirstItem = false) { $this->setParams($feed->xtform); $this->routeHelp = RouteHelp::getInstance(); $this->_textAdjustmentsInitialization(); $this->_textCleaningInitialization(); $this->_htmlCleaningInit(); FeedTextHelper::hookTagCleaningInit(); $articles = array(); $feedTitle = $loadResult->title; $items = $loadResult->items; $this->_logger->log(JLog::INFO, 'FeedProcessorHelper process: ' . $feedTitle); $i = 0; if (empty($items)) { return array(); } foreach ($items as $item) { if ($onlyFirstItem && !empty($articles)) { return $articles; } FeedTextHelper::hookTagCleaningItemInit(); $article = new FeedContent(); // Basic Initialization $article->cat_id = self::$_params->get('cat_id'); $article->access = self::$_params->get('access'); $article->featured = self::$_params->get('front_page'); $article->language = self::$_params->get('language'); // Hash $hash = $this->getHash($item); $article->hash = $hash; // Permalink $permalink = $item->get_permalink(); $article->permalink = $permalink; // Category Term $category_term = $item->get_category(); $article->category_term = null; if (isset($category_term->term)) { $article->category_term = $category_term->term; } // FeedItemBase preg_match('#^[a-zA-Z\\d\\-+.]+://[^/]+#', $permalink, $matches); $feedItemBase = $matches[0] . '/'; $article->feedItemBase = $feedItemBase; $this->_clean_feed_config['base_url'] = $feedItemBase; // NamePrefix $namePrefix = $hash . '_'; $article->namePrefix = $namePrefix; // Feed Text $theText = $this->_createFeedText($item); // Default Intro if (empty($theText)) { $theText = self::$_params->get('introtext'); } // Feed Title $title = $item->get_title(); $this->_logger->log(JLog::INFO, 'FeedProcessorHelper process: ' . $title . ' - ' . $permalink); // Get external fulltext if (self::$_params->get('fulltext')) { $readability_result = $this->_getFullText($permalink); if ($readability_result) { $theText = $readability_result->content; if (self::$_params->get('readability_title')) { $title = $readability_result->title; } } } // Text Cleaning $theText = $this->_htmlCleaning($theText); // Test for empty content if (!self::$_params->get('ignore_empty_intro') && empty($theText)) { $this->_logger->log(JLog::INFO, "FeedProcessorHelper process: " . $article->title . ' - Empty intro!'); continue; } // Title & alias $article->title = $this->_createTitle($title, $feedTitle, $theText, $hash); $article->alias = $this->_createAlias($article->title); if ($this->_isDuplicated($article)) { $this->_logger->log(JLog::INFO, "FeedProcessorHelper isDuplicated: " . $article->title . ' - Duplicated!'); continue; } // Black White Listing Control $article->blacklisted = false; $article->whitelisted = false; // Check item filtering if (self::$_params->get('filtering')) { $alltext = array(); $alltext[] = $article->title; $alltext[] = $theText; $alltext[] = $article->category_term; $this->_alltext = strtolower(implode(' ', $alltext)); if (self::$_params->get('filter_category_term')) { if ($article->category_term != self::$_params->get('filter_category_term')) { continue; } } if (self::$_params->get('filter_blacklist')) { $article->blacklisted = $this->_checkBlackListed(); if ($article->blacklisted) { if (self::$_params->get('save_filter_result')) { $this->_logger->log(JLog::INFO, "FeedProcessorHelper process: " . $article->title . ' - Blacklisted!'); } continue; } } if (self::$_params->get('filter_whitelist')) { $article->whitelisted = $this->_checkWhiteListed(); if (!$article->whitelisted) { if (self::$_params->get('save_filter_result')) { $this->_logger->log(JLog::INFO, "FeedProcessorHelper process: " . $article->title . ' - Not Whitelisted!'); } continue; } } } // Set Creator/Author $article->created_by = $this->_getCreatedBy(); $author = $item->get_author(); $article->created_by_alias = $this->_getCreatedByAlias($author, $article->created_by, $feedTitle); // Process Feed Images $article->images = $this->_processImages($theText); // Enclosures - (!self::$_params->get('create_art', 1 if (self::$_params->get('process_enc')) { $enclosures = $item->get_enclosures(); $enclosures = $this->_processEnclosures($enclosures); $article->enclosures = $enclosures; } $article->showEnclosureImage = self::$_params->get('process_enc_images') && count($article->images) == 0 && count($article->enclosures); if ($article->showEnclosureImage) { $article->images = $this->_setDefaultEnclosureImage($article->enclosures); // Ups, no image in enclosures if (empty($article->images)) { $article->showEnclosureImage = false; } } // Get Image from Text $onlyFirstValid = false; $article->showImageFromText = false; if (empty($article->images) && self::$_params->get('imagefromtext')) { $htmlForImages = $this->_getFullText($permalink, true); $this->_logger->log(JLog::INFO, "FeedProcessorHelper imagefromtext: length=" . strlen($htmlForImages), $htmlForImages); if ($htmlForImages) { $article->images = $this->_processImages($htmlForImages); $this->_logger->log(JLog::INFO, "FeedProcessorHelper images:", $article->images); $onlyFirstValid = true; $article->showImageFromText = true; } } $article->showDefaultImage = self::$_params->get('img') && count($article->images) == 0; // Set Default Image if ($article->showDefaultImage) { $article->images = $this->_setDefaultImage(); } $this->_validateImages($article->images, $onlyFirstValid); if (empty($article->images) && $article->featured && self::$_params->get('featured_with_image')) { $article->featured = 0; } if (!empty($article->images) && !$article->featured && self::$_params->get('featured_with_image')) { $article->featured = 1; } $article->introtext = $this->_trimText($theText, self::$_params->get('trim_to'), self::$_params->get('trim_type')); list($article->introtext, $article->fulltext) = $this->_onlyIntro($article->introtext, $theText); $article->introtext = $this->_dotDotDot($article->introtext); // Shortlink (or not) $article->shortlink = $article->permalink; if (!empty($permalink) && $this->_shorturl_always && self::$_params->get('shortlink')) { $article->shortlink = ShorturlHelper::getInstance()->getShortUrl($article->permalink); } // Category if ($category = $item->get_category()) { $article->metakey .= $category->get_label(); } // Publication state and dates $this->_setPublicationState($article, $item->get_date()); $articles[] = $article; $i++; // End Item Processing } return $articles; }
* @subpackage com_autotweet - A powerful social content platform to manage multiple social networks. * * @author Prieco S.A. <*****@*****.**> * @copyright Copyright (C) 2007 - 2015 Prieco, S.A. All rights reserved. * @license http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL * @link http://www.extly.com http://support.extly.com */ // No direct access defined('_JEXEC') or die('Restricted access'); $input = $this->input; $message = $input->getString('message'); $image_url = $input->getString('image_url'); $url = $input->getString('url'); $org_url = $input->getString('org_url'); $sitename = JFactory::getConfig()->get('sitename'); $url = RouteHelp::getInstance()->getRoot(); ?> <p> <?php echo TextUtil::autoLink($message); ?> </p> <?php if (!empty($image_url)) { ?> <p> <a href="<?php echo $org_url; ?> "> <img src="<?php
/** * 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; }
/** * routeAjaxItemId. * * @return void */ public function routeAjaxItemId() { try { // CSRF prevention if ($this->csrfProtection) { $this->_csrfProtection(); } $itemId = $this->input->get('itemId', null, 'int'); $url = 'index.php?Itemid=' . $itemId; $url = RouteHelp::getInstance()->getAbsoluteUrl($url); $message = json_encode(array('status' => true, 'url' => $url)); } catch (Exception $e) { $message = json_encode(array('status' => false, 'message' => $e->getMessage(), 'messageType' => 'error', 'hash' => AutotweetBaseHelper::getHash())); } echo EJSON_START . $message . EJSON_END; }
/** * publishRequest * * @param array $request Param * @param object $userid Param * * @return boolean */ public function publishRequest($request, $userid = null) { $this->logger->log(JLog::INFO, 'publishRequest request', $request); // Default: generate new entry for repost of entry with state success $postid = 0; $data = $this->_getContentData($request); if (!$data) { return false; } // Convert array to object $json = json_encode($data); $post = json_decode($json); if (AUTOTWEETNG_JOOCIAL) { $params = AdvancedattrsHelper::getAdvancedAttrByReq($request->id); } $post->ref_id = $request->ref_id; $post->plugin = $request->plugin; $post->postdate = $request->publish_up; $post->message = $post->text; unset($post->text); // Url if (isset($post->url) && !empty($post->url)) { $routeHelp = RouteHelp::getInstance(); $url = $routeHelp->getAbsoluteUrl($post->url); $post->url = $url; } elseif (isset($request->url) && !empty($request->url)) { $post->url = $request->url; } else { $this->logger->log(JLog::INFO, 'publishRequest: No url'); $post->url = ''; } $this->logger->log(JLog::INFO, 'publishRequest: url = ' . $post->url); // Image url if (isset($post->image_url) && !empty($post->image_url)) { // If defined in getExtendedData, use this image_url $routeHelp = RouteHelp::getInstance(); $url = $routeHelp->getAbsoluteUrl($post->image_url); // Only if it's a valid Url if (!ImageUtil::getInstance()->isValidImageUrl($url)) { $url = null; } $post->image_url = $url; } elseif (isset($request->image_url) && !empty($request->image_url)) { $url = $request->image_url; // Only if it's a valid Url if (!ImageUtil::getInstance()->isValidImageUrl($url)) { $url = null; } // Use this image_url (it's already routed) $post->image_url = $url; } else { $this->logger->log(JLog::INFO, 'publishRequest: No image url'); $post->image_url = null; } $this->logger->log(JLog::INFO, 'publishRequest: image url = ' . $post->image_url); // Title // Truncate title and fulltext for new messages ('if' is for backward compatibillity) if (isset($post->title)) { $title = TextUtil::cleanText($post->title); $post->title = TextUtil::truncString($title, self::MAX_CHARS_TITLE); } else { $post->title = ''; } // Fulltext if (!isset($post->fulltext)) { $post->fulltext = ''; } if (AUTOTWEETNG_JOOCIAL) { if (isset($params->fulltext) && !empty($params->fulltext)) { $post->fulltext = $params->fulltext; } } if (AUTOTWEETNG_JOOCIAL && EParameter::getComponentParam(CAUTOTWEETNG, 'paywall_mode') && ($fulltext = EParameter::getComponentParam(CAUTOTWEETNG, 'paywall_titleonly'))) { $post->fulltext = $fulltext; } $fulltext = TextUtil::cleanText($post->fulltext); $post->fulltext = TextUtil::truncString($fulltext, self::MAX_CHARS_FULLTEXT); $post->xtform = new JRegistry(); // Catids if (isset($post->catids)) { $catids = $post->catids; unset($post->catids); $post->xtform->set('catids', $catids); } else { $post->xtform->set('catids', array()); } // Author if (isset($post->author)) { $author = $post->author; unset($post->author); $post->xtform->set('author', $author); } // Language if (isset($post->language)) { $language = $post->language; unset($post->language); $post->xtform->set('language', $language); } // Access if (isset($post->access)) { $access = $post->access; unset($post->access); $post->xtform->set('access', $access); } // Target_id if (isset($post->target_id)) { $target_id = $post->target_id; unset($post->target_id); $post->xtform->set('target_id', $target_id); } // Hashtags if (isset($post->hashtags)) { $hashtags = $post->hashtags; unset($post->hashtags); $post->xtform->set('hashtags', $hashtags); } // Native object if (isset($request->native_object)) { $native_object = $request->native_object; $native_object = json_decode($native_object); if ($native_object) { $post->xtform->set('native_object', $native_object); } else { $this->logger->log(JLog::INFO, 'publishRequest: Inavlid JSON native_object'); } } // Featured if (isset($post->featured)) { $post->xtform->set('featured', $post->featured); unset($post->featured); } return $this->sendRequest($request, $post, $userid); }
/** * url * * @param object &$article Param * * @return string */ public function url(&$article) { JLoader::register('JTableCategory', JPATH_PLATFORM . '/joomla/database/table/category.php'); $cats = plgAutotweetBase::getContentCategories($article->catid); $cat_ids = $cats[0]; $catNames = $cats[1]; $catAlias = $cats[2]; // Use main category for article url $cat_slug = $article->catid . ':' . TextUtil::convertUrlSafe($catAlias[0]); $id_slug = $article->id . ':' . TextUtil::convertUrlSafe($article->alias); // Create internal url for Joomla core content article JLoader::import('components.com_content.helpers.route', JPATH_ROOT); $url = ContentHelperRoute::getArticleRoute($id_slug, $cat_slug); $routeHelp = RouteHelp::getInstance(); $url = $routeHelp->getAbsoluteUrl($url); return $url; }
/** * Obtain a request token from Twitter * * @return string */ public function getRequestTokenUrl() { $input = new F0FInput(); $itemid = $input->getInt('Itemid'); $oauth_callback = 'index.php?option=com_autotweet&view=userchannels'; if ($itemid) { $oauth_callback .= '&Itemid=' . $itemid; } $oauth_callback = RouteHelp::getInstance()->getAbsoluteUrl($oauth_callback); // Send request for a request token $this->_twitter->request('POST', $this->_twitter->url('oauth/request_token', ''), array()); if ($this->_twitter->response['code'] == 200) { // Get and store the request token $response = $this->_twitter->extract_params($this->_twitter->response['response']); $session = JFactory::getSession(); $session->set('authtoken', $response['oauth_token']); $session->set('authsecret', $response['oauth_token_secret']); // State is now 1 $session->set('twitter-authstate', 1); // Redirect the user to Twitter to authorize $url = $this->_twitter->url('oauth/authorize', '') . '?oauth_token=' . $response['oauth_token']; return $url; } return false; }
/** * loadImage * * @param string $image_url Param * * @return string */ public function downloadImage($image_url) { $router = RouteHelp::getInstance(); $this->has_tmp_file = false; $imagefile = $image_url; // Is Url? if ($router->isAbsoluteUrl($image_url)) { $imagefile = str_replace($router->getRoot(), JPATH_ROOT . DIRECTORY_SEPARATOR, $image_url); // Is still Url ? if ($router->isAbsoluteUrl($imagefile)) { // Download it in a tmp file $imagefile = JInstallerHelper::downloadPackage($image_url); if ($imagefile) { $this->has_tmp_file = true; $imagefile = JFactory::getConfig()->get('tmp_path') . DIRECTORY_SEPARATOR . $imagefile; } } // $imagefile is an absolute file } else { // Is relative file? if (strpos($image_url, DIRECTORY_SEPARATOR) > 0) { $imagefile = JPATH_ROOT . DIRECTORY_SEPARATOR . $image_url; } // $imagefile is an absolute file } // External Image? Download it into a tmp file, just to post it if (!is_file($imagefile)) { return null; } $logger = AutotweetLogger::getInstance(); $logger->log(JLog::INFO, 'downloadImage: ' . $imagefile); if (!$this->isValidImageFile($imagefile)) { if ($this->has_tmp_file) { $this->releaseImage($imagefile); } return null; } return $imagefile; }
/** * Obtain a request token from Twitter * * @return string */ public function getRequestTokenUrl() { $input = new F0FInput(); $itemid = $input->getInt('Itemid'); $oauth_callback = 'index.php?option=com_autotweet&view=userchannels'; if ($itemid) { $oauth_callback .= '&Itemid=' . $itemid; } $oauth_callback = RouteHelp::getInstance()->getAbsoluteUrl($oauth_callback); $this->_linkedin->setCallbackUrl($oauth_callback); $response = $this->_linkedin->retrieveTokenRequest(); if ($response['info']['http_code'] == 200) { // Get and store the request token $session = JFactory::getSession(); $session->set('oauth_token', $response['linkedin']['oauth_token']); $session->set('oauth_token_secret', $response['linkedin']['oauth_token_secret']); // State is now 1 $session->set('linkedin-authstate', 1); // Redirect the user to Twitter to authorize $url = $response['linkedin']['xoauth_request_auth_url'] . '?oauth_token=' . $response['linkedin']['oauth_token']; return $url; } return false; }
/** * sendMessage. * * @param string $message Params * @param object $data Params * * @return boolean */ public function sendMessage($message, $data) { if ($this->channel->params->get('open_graph_features') && $this->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; if (empty($url)) { $url = $data->org_url; } if (empty($url)) { $url = RouteHelp::getInstance()->getRoot(); } $org_url = $data->org_url; if (empty($org_url)) { $org_url = $url; } $image_url = $data->image_url; $media_mode = $this->getMediaMode(); $url_comps = parse_url($org_url); $actionlink_text = $url_comps['host']; $actions = array(); $actions['name'] = $actionlink_text; $actions['link'] = $org_url; $logger = AutotweetLogger::getInstance(); $logger->log(JLog::INFO, 'sendFacebookMessage', $message); $fb_id = $this->getFbChannelId(); $fb_token = $this->get('fbchannel_access_token'); // Media mode is not used !! $result = null; $status_type = array('value' => 'wall_post'); $title = TextUtil::truncString($title, self::MAX_CHARS_NAME); // Link object: /user/links $arguments = array('message' => $message, 'link' => $url, 'name' => $title, 'caption' => $actionlink_text, 'actions' => json_encode($actions), 'access_token' => $fb_token, 'type' => 'link', '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); } // 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; } $target_id = $data->xtform->get('target_id'); if (EParameter::getComponentParam(CAUTOTWEETNG, 'targeting', false) && $target_id) { $this->addTargetArguments($arguments, $target_id); } try { // 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 { $result = $this->getApiInstance()->api("/{$fb_id}/links", 'post', $arguments); $msg = 'Facebook id: ' . $result['id']; $result = array(true, $msg); } } catch (Exception $e) { $result = array(false, $e->getCode() . ' - ' . $e->getMessage()); } return $result; }