Example #1
0
 /**
  * processed
  *
  * @param   int  $id  Param
  *
  * @return	boolean
  */
 public static function processed($id)
 {
     $request = F0FModel::getTmpInstance('Requests', 'AutotweetModel')->getTable();
     $request->reset();
     if (!$request->load($id)) {
         return;
     }
     // Native Object
     if (isset($request->native_object)) {
         $nativeObject = json_decode($request->native_object);
     } else {
         $nativeObject = new StdClass();
     }
     $nativeObject->error = false;
     $nativeObject->error_message = 'Ok!';
     // It's processed
     $data = array();
     $data['published'] = true;
     $data['native_object'] = json_encode($nativeObject);
     // Saving
     if (!AUTOTWEETNG_JOOCIAL) {
         $request->save($data);
         return;
     }
     AdvancedattrsHelper::execute($id, $data);
     $request->save($data);
 }
 /**
  * sampleAutoTweetNGIntegration
  *
  * @param   int    $productId  Param
  * @param   array  &$data      Param
  *
  * Example of how to save AutoTweetNG Request
  * Copy-paste into your extension, and customize freely
  *
  * @return	void
  */
 private static function sampleAutoTweetNGIntegration($productId, &$data)
 {
     // If product is not published, nothing else to do
     if (!$data['published']) {
         return;
     }
     $typeinfo = 99;
     $native_object = json_encode($data);
     // Product Url
     $viewProductUrl = EshopRoute::getProductRoute($productId, EshopHelper::getProductCategory($productId));
     // Image Url
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $query->clear();
     $query->select('image')->from('#__eshop_productimages')->where('product_id = ' . intval($productId))->order('ordering');
     $db->setQuery($query);
     $product_image = $db->loadResult();
     $image_url = null;
     if ($product_image && JFile::exists(JPATH_ROOT . '/media/com_eshop/products/' . $product_image)) {
         $image_url = 'media/com_eshop/products/' . $product_image;
     }
     $langmgmt_default_language = EParameter::getComponentParam(CAUTOTWEETNG, 'langmgmt_default_language');
     if ($langmgmt_default_language) {
         $key = 'product_name_' . $langmgmt_default_language;
         if (array_key_exists($key, $data)) {
             $title = $data[$key];
         }
         $key = 'product_desc_' . $langmgmt_default_language;
         if (array_key_exists($key, $data)) {
             $description = TextUtil::cleanText($data[$key]);
         }
     }
     if (empty($title)) {
         $title = $data['product_name'];
     }
     if (empty($description)) {
         $description = TextUtil::cleanText($data['product_desc']);
     }
     if (empty($title)) {
         return;
     }
     // Saving Advanced Attributes
     $autotweet_advanced = $data['autotweet_advanced_attrs'];
     $advanced_attrs = AdvancedattrsHelper::retrieveAdvancedAttrs($autotweet_advanced);
     AdvancedattrsHelper::saveAdvancedAttrs($advanced_attrs, $productId);
     // AutotweetAPI
     $id = self::insertRequest($productId, 'autotweetpost', JFactory::getDate()->toSql(), $title, $typeinfo, $viewProductUrl, $image_url, $native_object, $advanced_attrs);
     // Adding more information to the request
     $requestsModel = F0FModel::getTmpInstance('Requests', 'AutoTweetModel');
     $request = $requestsModel->getItem($id);
     $request = (array) $request;
     $request['xtform']->set('title', $title);
     $request['xtform']->set('fulltext', $description);
     $request['xtform']->set('author', JFactory::getUser()->username);
     $requestsModel->save($request);
 }
Example #3
0
 /**
  * This method runs after the data is saved to the $table.
  *
  * @param   F0FTable  &$table  The table which was saved
  *
  * @return  boolean
  */
 protected function onAfterSave(&$table)
 {
     $result = parent::onAfterSave($table);
     if (isset($this->advanced_attrs)) {
         $this->advanced_attrs->ref_id = $table->ref_id;
         AdvancedattrsHelper::saveAdvancedAttrs($this->advanced_attrs, $table->ref_id);
     }
     return $result;
 }
Example #4
0
 /**
  * applyAjaxPluginAction
  *
  * @return	void
  */
 public function applyAjaxPluginAction()
 {
     try {
         // CSRF prevention
         if ($this->csrfProtection) {
             $this->_csrfProtection();
         }
         $data = $this->_getAjaxData();
         if ($data['id'] == 0 || $data['ref_id'] == 0) {
             throw new Exception('Unknown Plugin Action (id/ref_id)');
         }
         $attr_id = null;
         // Autotweet_advanced_attrs
         if (AUTOTWEETNG_JOOCIAL && $data['autotweet_advanced_attrs']) {
             $advanced_attrs = AdvancedattrsHelper::retrieveAdvancedAttrs($data['autotweet_advanced_attrs']);
             if (isset($advanced_attrs->ref_id)) {
                 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)) {
                         $publish_up = EParameter::convertUTCLocal($publish_up);
                         $data['publish_up'] = $publish_up;
                     }
                 }
                 // Safe to save
                 $attr_id = AdvancedattrsHelper::saveAdvancedAttrs($advanced_attrs, $advanced_attrs->ref_id);
                 unset($data['autotweet_advanced_attrs']);
             }
         }
         // Load the model
         $model = $this->getThisModel();
         if (!$model->getId()) {
             $model->setIDsFromRequest();
         }
         $id = $model->getId();
         if (!$this->onBeforeApplySave($data)) {
             return false;
         }
         // Set the layout to form, if it's not set in the URL
         if (is_null($this->layout)) {
             $this->layout = 'form';
         }
         // Do I have a form?
         $model->setState('form_name', 'form.' . $this->layout);
         $status = $model->save($data);
         if ($status && $id != 0) {
             F0FPlatform::getInstance()->setHeader('Status', '201 Created', true);
             // Try to check-in the record if it's not a new one
             $status = $model->checkin();
         }
         if ($status) {
             $status = $this->onAfterApplySave();
         }
         $req_id = $model->getId();
         if ($attr_id) {
             AdvancedattrsHelper::assignRequestId($attr_id, $req_id);
         }
         $this->input->set('id', $req_id);
         $message = json_encode(array('status' => $status, 'request_id' => $status ? $model->getId() : false, 'message' => $status ? JText::_('COM_AUTOTWEET_COMPOSER_MESSAGE_SAVED') : implode('', $model->getErrors()), 'messageType' => $status ? 'success' : 'error', 'hash' => AutotweetBaseHelper::getHash()));
     } catch (Exception $e) {
         $message = json_encode(array('status' => false, 'message' => $e->getMessage(), 'messageType' => 'error', 'hash' => AutotweetBaseHelper::getHash()));
     }
     echo EJSON_START . $message . EJSON_END;
 }
Example #5
0
 /**
  * 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;
 }
Example #6
0
 /**
  * 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;
 }
 /**
  * executeContentPolling
  *
  * @return	boolean
  */
 protected function executeContentPolling()
 {
     $automators = F0FModel::getTmpInstance('Automators', 'AutoTweetModel');
     if ($automators->lastRunCheck('content', $this->interval)) {
         $check_from = $this->getContentPollingFrom();
         // Set date for posts
         $post_old_mode = false;
         if ($this->post_old) {
             // Special case: posting for old articles is enabled
             $post_old_mode = true;
             $last_post = JFactory::getDate($this->post_old_date);
             // Disable old article posting
             $this->disablePostOld();
         } else {
             $last_post = $check_from;
         }
         // Get new and changed articles form db
         $table_content = '#__content';
         // Get articles only when they are not in the queue and not in the message log for time horizon
         $db = JFactory::getDBO();
         $query = $this->getPollingQuery('autotweetcontent', $table_content, $last_post);
         $db->setQuery($query);
         $articles = $db->loadObjectList();
         $logger = AutotweetLogger::getInstance();
         $logger->log(JLog::INFO, 'PollingQuery: ' . $table_content . ' found ' . count($articles) . ' tasks.');
         $ids = array();
         // Post articles
         foreach ($articles as $article) {
             $ids[] = $article->id;
             if (AUTOTWEETNG_JOOCIAL) {
                 $this->advanced_attrs = AdvancedattrsHelper::getAdvancedAttrs($this->extension_option, $article->id);
             }
             $this->postArticle($article);
         }
         $logger->log(JLog::INFO, 'PollingQuery: ' . print_r($ids, true) . ' results.');
     }
 }
Example #8
0
<?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;
 /**
  * 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);
 }