/** * 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; }
/** * 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; }
/** * 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; }
* * @author Prieco S.A. <*****@*****.**> * @copyright Copyright (C) 2007 - 2015 Prieco, S.A. All rights reserved. * @license http://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'); F0FModel::getTmpInstance('Plugins', 'AutoTweetModel'); $result = array(); if ($count = count($this->items)) { foreach ($this->items as $item) { $native_object = json_decode($item->native_object); $has_error = isset($native_object->error) && $native_object->error; $description = htmlentities($item->description, ENT_COMPAT, 'UTF-8'); $description = TextUtil::truncString($description, AutotweetDefaultView::MAX_CHARS_TITLE_SHORT_SCREEN, true); $elem = array('id' => $item->id, 'title' => $description, 'start' => JHtml::_('date', $item->publish_up, DateTime::RFC3339), 'className' => $item->published ? $has_error ? 'req-error' : 'req-success' : ($has_error ? 'req-warning' : 'req-info')); /* if (!empty($item->url)) { $elem['url'] = TextUtil::renderUrl($item->url); } */ $elem['url'] = 'index.php?option=com_autotweet&view=composer&req-id=' . $item->id; if (!empty($item->image_url)) { $elem['image_url'] = TextUtil::renderUrl($item->image_url); } $result[] = $elem; } } echo json_encode($result);
/** * 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; }
/** * 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; }
/** * 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); }
?> </a> </td> <td><?php echo EHtmlGrid::lockedWithIcons($checkedout); ?> <a href="<?php echo $link; ?> "> <?php $message = $item->message; if ($this->isModule) { $message = TextUtil::truncString($message, AutotweetDefaultView::MAX_CHARS_TITLE_SHORT_SCREEN, true); } else { $message = TextUtil::truncString($message, AutotweetDefaultView::MAX_CHARS_TITLE_SCREEN, true); } echo htmlentities($message, ENT_COMPAT, 'UTF-8'); ?> </a> <?php if (!empty($item->url)) { echo ' <a href="' . TextUtil::renderUrl($item->url) . '" target="_blank"><i class="xticon xticon-globe"></i></a>'; } if (!empty($item->image_url)) { echo ' <a href="' . TextUtil::renderUrl($item->image_url) . '" target="_blank"><i class="xticon xticon-image"></i></a>'; } ?> </td> <td><span class="channel-<?php
/** * Apply the text pattern in the data array * * @param string $text Param * @param array $tag Param * @param array $subject Param * * @return void */ private static function _applyTextPattern($text, $tag, $subject) { $pattern = '/\\[' . $tag . '\\,?([0-9]+)?\\]/i'; if (preg_match($pattern, $text, $matches)) { if (count($matches) > 1) { $limit = $matches[1]; $subject = TextUtil::truncString($subject, $limit); } $text = preg_replace($pattern, $subject, $text); } return $text; }
/** * 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; }