Example #1
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;
 }