/**
  * 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 #2
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;
 }
 /**
  * retrieveAdvancedAttrs
  *
  * @return	void
  */
 public function retrieveAdvancedAttrs()
 {
     if (!AUTOTWEETNG_JOOCIAL) {
         return;
     }
     $input = new F0FInput();
     $autotweet_advanced = $input->get('autotweet_advanced_attrs', null, 'string');
     if ($autotweet_advanced) {
         $this->advanced_attrs = AdvancedattrsHelper::retrieveAdvancedAttrs($autotweet_advanced);
         if (isset($this->advanced_attrs->ref_id)) {
             // Safe to save
             $this->saveAdvancedAttrs($this->advanced_attrs->ref_id);
         }
     }
 }
Example #4
0
 /**
  * This method runs before the $data is saved to the $table. Return false to
  * stop saving.
  *
  * @param   array   &$data   Param
  * @param   JTable  &$table  Param
  *
  * @return bool
  */
 protected function onBeforeSave(&$data, &$table)
 {
     $data['params'] = EForm::paramsToString($data);
     if (array_key_exists('publish_up', $data)) {
         $data['publish_up'] = EParameter::convertLocalUTC($data['publish_up']);
     } else {
         $data['publish_up'] = JFactory::getDate()->toSql();
     }
     // Cleaning annoying spaces
     $data = array_map('trim', $data);
     if (array_key_exists('autotweet_advanced_attrs', $data)) {
         $this->advanced_attrs = AdvancedattrsHelper::retrieveAdvancedAttrs($data['autotweet_advanced_attrs']);
     }
     return parent::onBeforeSave($data, $table);
 }
 /**
  * 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);
 }