/** * addItemeditorHelperApp * * @return string */ public static function addItemeditorHelperApp() { static $link = false; if ($link) { return $link; } $doc = JFactory::getDocument(); $app = JFactory::getApplication(); list($isAdmin, $option, $controller, $task, $view, $layout, $id) = AutotweetBaseHelper::getControllerParams(); $js = "var autotweetUrlRoot = '" . JUri::root() . "';\n"; $js .= "var autotweetUrlBase = '" . JUri::base() . "';\n"; $mediaPath = 'media/com_autotweet/js/itemeditor/templates/'; $ext = '.txt'; $joomlaPart = '.j' . (EXTLY_J3 ? '3' : '25'); $sitePart = $isAdmin ? '.admin' : '.site'; $tpl0 = $mediaPath . $option . $ext; $tpl1 = $mediaPath . $option . $joomlaPart . $ext; $tpl2 = $mediaPath . $option . $sitePart . $joomlaPart . $ext; $tpl3 = $mediaPath . $option . $sitePart . $ext; if (file_exists(JPATH_ROOT . '/' . $tpl2)) { $tpl = $tpl2; } elseif (file_exists(JPATH_ROOT . '/' . $tpl1)) { $tpl = $tpl1; } elseif (file_exists(JPATH_ROOT . '/' . $tpl3)) { $tpl = $tpl3; } elseif (file_exists(JPATH_ROOT . '/' . $tpl0)) { $tpl = $tpl0; } else { $tpl = $mediaPath . 'com_joocial-default' . $joomlaPart . $ext; } $tpl = JUri::root() . $tpl . '?version=' . CAUTOTWEETNG_VERSION; $js .= "var autotweetPanelTemplate = 'text!" . $tpl . "';\n"; $doc->addScriptDeclaration($js); $link = 'index.php?option=com_autotweet&view=itemeditor&layout=modal&tmpl=component&' . JSession::getFormToken() . '=1'; // Add Advanced Attributes $params = null; // Case Request edit page if ($option == CAUTOTWEETNG && $view == 'request' && $task == 'edit') { $params = AdvancedattrsHelper::getAdvancedAttrByReq($id); } elseif ($id > 0) { $params = AdvancedattrsHelper::getAdvancedAttrs($option, $id); } if (!$params) { $params = new StdClass(); $params->description = ''; $params->hashtags = ''; $params->fulltext = ''; $params->postthis = EParameter::getComponentParam(CAUTOTWEETNG, 'joocial_postthis', PlgAutotweetBase::POSTTHIS_DEFAULT); $params->evergreen = PlgAutotweetBase::POSTTHIS_NO; $params->agenda = array(); $params->unix_mhdmd = ''; $params->repeat_until = ''; $params->image = ''; $params->image_url = ''; $params->channels = ''; $params->channels_text = ''; } // Migrating old objects if (!isset($params->description)) { $params->description = ''; } // Migrating old objects if (!isset($params->hashtags)) { $params->hashtags = ''; } // Migrating old objects if (!isset($params->fulltext)) { $params->fulltext = ''; } // Migrating old objects if (!isset($params->image_url)) { $params->image_url = ''; } $params->editorTitle = VersionHelper::getFlavourName() . ' ' . JText::_('COM_AUTOTWEET_VIEW_ITEMEDITOR_TITLE'); $params->postthisLabel = JText::_('COM_AUTOTWEET_VIEW_ITEMEDITOR_POSTTHIS'); $params->evergreenLabel = JText::_('COM_AUTOTWEET_VIEW_ITEMEDITOR_EVERGREEN'); $params->agendaLabel = JText::_('COM_AUTOTWEET_VIEW_ITEMEDITOR_SCHEDULER'); $params->unix_mhdmdLabel = JText::_('COM_XTCRONJOB_TASKS_FIELD_UNIX_MHDMD'); $params->repeat_untilLabel = JText::_('COM_AUTOTWEET_VIEW_ITEMEDITOR_REPEAT_UNTIL'); $params->imageLabel = JText::_('COM_AUTOTWEET_VIEW_ITEMEDITOR_IMAGES'); $params->channelLabel = JText::_('COM_AUTOTWEET_VIEW_ITEMEDITOR_CHANNELS'); $params->postthisDefaultLabel = '<i class="xticon xticon-circle-o"></i> ' . JText::_('COM_AUTOTWEET_DEFAULT_LABEL'); $params->postthisYesLabel = '<i class="xticon xticon-check"></i> ' . JText::_('JYES'); $params->postthisNoLabel = '<i class="xticon xticon-times"></i> ' . JText::_('JNO'); $params->descriptionLabel = JText::_('COM_AUTOTWEET_VIEW_ITEMEDITOR_MSG'); $params->hashtagsLabel = JText::_('COM_AUTOTWEET_VIEW_ITEMEDITOR_HASHTAGS'); $params->fulltextLabel = JText::_('COM_AUTOTWEET_VIEW_ITEMEDITOR_FULLTEXT_DESC'); if (!isset($params->channels_text)) { $params->channels_text = ''; } AutotweetBaseHelper::convertUTCLocalAgenda($params->agenda); $js = 'var autotweetAdvancedAttrs = ' . json_encode($params) . ";\n"; $doc->addScriptDeclaration($js); $file = EHtml::getRelativeFile('js', 'com_autotweet/itemeditor.helper.min.js'); if ($file) { $paths = array(); $paths = array('text' => Extly::JS_LIB . 'require/text.min'); $deps = array('itemeditor.helper' => array('text', 'underscore')); Extly::getScriptManager(false); Extly::initApp(CAUTOTWEETNG_VERSION, $file, $deps, $paths); } return $link; }
/** * sendRequest * * @param string &$request Param * @param string &$post Param * @param object $userid Param * * @return boolean */ protected function sendRequest(&$request, &$post, $userid = null) { $success = false; $this->logger->log(JLog::INFO, 'sendRequest request', $request); $this->logger->log(JLog::INFO, 'sendRequest post', $post); $rule_engine = RuleEngineHelper::getInstance(); $plugin = $request->plugin; $rule_engine->load($plugin); // Channels - Rules $channel_rules = $rule_engine->getChannels($request->plugin, $post); $hasRules = !empty($channel_rules); if ($hasRules) { $channel_rules_ids = array_keys($channel_rules); $this->logger->log(JLog::INFO, 'getChannels:Rules found for plugin ' . $plugin . ' n=' . count($channel_rules)); } else { $this->logger->log(JLog::INFO, 'getChannels: No rules found for plugin ' . $plugin); $channel_rules_ids = array(); } $author = $post->xtform->get('author', null); $channels = ChannelFactory::getInstance()->getChannels($author); if (AUTOTWEETNG_JOOCIAL) { $params = AdvancedattrsHelper::getAdvancedAttrByReq($request->id); if (isset($params->channels) && is_array($params->channels) && count($params->channels) > 0) { $filtered_channels = array(); foreach ($params->channels as $c) { if (array_key_exists($c, $channels)) { $filtered_channels[$c] = $channels[$c]; } } $channels = $filtered_channels; } } if ($this->denyall_rulemode) { $this->logger->log(JLog::INFO, 'sendRequest denyall_rulemode'); // Only rule channels are processed $remaining_channels_ids = array(); $success = true; } else { // Rest of the Channels $channels_ids = array_keys($channels); $remaining_channels_ids = array_diff($channels_ids, $channel_rules_ids); } // Save orginal url for log and other usages $post->org_url = $post->url; // A request for each Channel - Rule $result_msg = ''; $initial_autopublish_state = $post->autopublish; $initial_show_url_state = $post->show_url; $initial_target_id = $post->xtform->get('target_id'); $this->logger->log(JLog::INFO, 'sendRequest channel_rules', $channel_rules_ids); $this->logger->log(JLog::INFO, 'sendRequest remaining_channels_ids', $remaining_channels_ids); foreach ($channel_rules as $channel_id => $rule) { $this->logger->log(JLog::INFO, 'sendRequest channel_rules processing: ' . $channel_id); // There's a rule, but the channel is not enabled if (!isset($channels[$channel_id])) { continue; } $channel = $channels[$channel_id]; $channelpost = clone $post; $channelpost->id = 0; $channelpost->channel_id = $channel_id; $channelpost->autopublish = $channel->isAutopublish() && $initial_autopublish_state; $channelpost->show_url = $initial_show_url_state; $channelpost->xtform->set('target_id', $initial_target_id); $rule_engine->executeRule($rule, $channel, $channelpost); $success = $this->_sendRequest($channel, $channelpost); // If one channel fails, it's stopped if (!$success) { $this->logger->log(JLog::INFO, 'sendRequest: failed, stopping process (1).'); return false; } } // A request for each of the remaining Channels foreach ($remaining_channels_ids as $channel_id) { $this->logger->log(JLog::INFO, 'sendRequest remaining_channels_ids processing: ' . $channel_id); $channel = $channels[$channel_id]; $post->id = 0; $post->channel_id = $channel_id; $post->autopublish = $channel->isAutopublish() && $initial_autopublish_state; $post->show_url = $initial_show_url_state; if ($initial_target_id) { $post->xtform->set('target_id', $initial_target_id); } else { $post->xtform->set('target_id', $channel->getTargetId()); } $success = $this->_sendRequest($channel, $post, $userid); // If one channel fails, it's stopped if (!$success) { $this->logger->log(JLog::INFO, 'sendRequest: failed, stopping process (2).'); return false; } } $success = true; $this->logger->log(JLog::INFO, 'sendRequest: success, no more channels to process.'); // True when message is sent return $success; }
<?php /** * @package Extly.Components * @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'); if (AUTOTWEETNG_JOOCIAL) { $params = AdvancedattrsHelper::getAdvancedAttrByReq($this->item->id); AutotweetBaseHelper::convertUTCLocalAgenda($params->agenda); if (!empty($params->image)) { $this->item->image_url = $params->image; $params->image = null; } $this->item->autotweet_advanced_attrs = $params; } echo EJSON_START . json_encode($this->item) . EJSON_END;