Exemplo n.º 1
0
 private function parseUserInputs($form_id, &$post_id = null, $preview = false, $force_form_count = false, $specific_post_id = null)
 {
     global $post, $_post_to_create, $_current_post;
     // reference to the form submission method
     global ${'_' . StaticClass::METHOD};
     $method =& ${'_' . StaticClass::METHOD};
     // get post inputs
     if (isset($post_id) && !empty($post_id) && null !== $post_id && false !== $post_id && !$preview) {
         $post_id = intval($post_id);
     } elseif (isset($post->ID) && !$preview) {
         $post_id = $post->ID;
     } else {
         $post_id = false;
     }
     $formHelper = $this->_formHelper;
     // get recaptcha settings
     StaticClass::$_staticGlobal['RECAPTCHA'] = $formHelper->getRecaptchaSettings(StaticClass::$_staticGlobal['RECAPTCHA']);
     $form = $this->_formData;
     $this->_post_ID = $post_id;
     // load form data
     //$this->_formData=$formHelper->loadForm($form_id, $preview);
     if ($formHelper->isError($form)) {
         return $form;
     }
     $form_id = $form->getForm()->ID;
     $_fields = $form->getFields();
     $form_type = $_fields['form_settings']->form['type'];
     $post_type = $_fields['form_settings']->post['post_type'];
     // if this is an edit form and no post id given
     if (('edit' == $form_type && false === $post_id && !$preview || isset($_GET['action']) && $_GET['action'] == 'edit_translation' && 'translation' == $form_type) && false === $post_id && !$preview) {
         return $formHelper->error(__('No post specified', 'wp-cred'));
     }
     // get existing post data if edit form and post given
     if (('edit' == $form_type && !$preview || isset($_GET['action']) && $_GET['action'] == 'edit_translation' && 'translation' == $form_type) && !$preview) {
         if ($_current_post == 0) {
             $_current_post = $post_id;
         }
         $is_current_edit = false;
         if (is_null($specific_post_id) && $_current_post > 0) {
             $is_current_edit = true;
             $post_id = $_current_post;
         }
         $this->_post_ID = $post_id;
         //$this->_postData=$formHelper->getPostData($post_id);
         require_once "PostData.php";
         $postdata = new PostData();
         $this->_postData = $postdata->getUserData($post_id);
         if ($formHelper->isError($this->_postData)) {
             return $this->_postData;
         }
         if ($is_current_edit) {
             $post_type = $this->_postData->post->post_type;
         }
         if (!$is_current_edit && $this->_postData->post->post_type != $post_type) {
             return $formHelper->error(__('User Form type and post type do not match', 'wp-cred'));
         }
     } else {
         //Fixed https://icanlocalize.basecamphq.com/projects/7393061-toolset/todo_items/186563662/comments
         //conditional not working after failed submition
         //$this->_post_ID=$post_id;
         //removed creates side effect to other stuff !
     }
     // check if user has access to this form
     if (!$preview && !$formHelper->checkUserFormAccess($form_type, $form_id, $this->_postData)) {
         return $formHelper->error();
     }
     // Deprecated
     // set allowed file types
     StaticClass::$_staticGlobal['MIMES'] = $formHelper->getAllowedMimeTypes();
     // get custom post fields
     $fields_settings = $formHelper->getFieldSettings($post_type);
     // instantiate Zebra Form
     if (false !== $force_form_count) {
         $form_count = $force_form_count;
     } else {
         $form_count = StaticClass::$_globalStatic['COUNT'];
     }
     // strip any unneeded parsms from current uri
     $actionUri = $formHelper->currentURI(array('_tt' => time()), array('_success', '_success_message'));
     $prg_form_id = $formHelper->createPrgID($form_id, $form_count);
     $my_form_id = $formHelper->createFormID($form_id, $form_count);
     $this->_zebraForm = new CredForm($my_form_id, $form_type, $post_id, $actionUri, $preview);
     $this->_zebraForm->setLanguage(StaticClass::$_staticGlobal['LOCALES']);
     if ($formHelper->isError($this->_zebraForm)) {
         return $this->_zebraForm;
     }
     // all fine here
     $this->_postType = $post_type;
     $this->_content = $form->getForm()->post_content;
     $this->out_['fields'] = $fields_settings;
     $this->out_['count'] = $form_count;
     $this->out_['prg_id'] = $prg_form_id;
     return true;
 }