/** * insertRequest * * @param int $ref_id Param * @param string $plugin Param * @param date $publish_up Param * @param string $description Param * @param int $typeinfo Param * @param string $url Param * @param string $image_url Param * @param json &$native_object Param * @param object &$advanced_attrs Param * @param object &$params Param * @param string $content_language Param * * @return mixed (bool or request Id) */ public static function insertRequest($ref_id, $plugin, $publish_up, $description, $typeinfo = 0, $url = '', $image_url = '', &$native_object = null, &$advanced_attrs = null, &$params = null, $content_language = null) { if ($publish_up == 0) { $publish_up = JFactory::getDate()->toSql(); } if ($advanced_attrs) { if (!empty($advanced_attrs->description)) { $description = $advanced_attrs->description; } if (!empty($advanced_attrs->hashtags)) { $description .= ' ' . $advanced_attrs->hashtags; } if ($advanced_attrs->postthis == PlgAutotweetBase::POSTTHIS_NO) { // Post this or not return null; } if (($image = $advanced_attrs->image) && !empty($image)) { // This image if ($image == 'none') { $image_url = null; } else { $image_url = $image; } } if (isset($advanced_attrs->image_url) && ($image = $advanced_attrs->image_url) && !empty($image)) { $image_url = $image; } 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)) { $logger = AutotweetLogger::getInstance(); $logger->log(JLog::INFO, 'insertRequest: ref_id=' . $ref_id . ' - No Next Agenda Date.'); return false; } } } $result = RequestHelp::insertRequest($ref_id, $plugin, $publish_up, $description, $typeinfo, $url, $image_url, $native_object, $advanced_attrs, $params, $content_language); return $result; }
/** * 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; }