예제 #1
0
 public static function getForm($form, $post_id = null, $preview = false)
 {
     self::initVars();
     ++self::$form_count;
     //add_filter('cred_form_validate',array($this,'check_hooks'),10);
     if (is_string($form) && !is_numeric($form)) {
         $form_p = get_page_by_title($form, OBJECT, CRED_FORMS_CUSTOM_POST_NAME);
         if ($form_p && is_object($form_p)) {
             $form = $form_p->ID;
         } else {
             return '';
         }
     }
     if (!array_key_exists($form . '_' . self::$form_count, self::$form_cache)) {
         // parse and cache form
         $fb = new CRED_Form_Builder($form, $post_id, $preview);
         self::$form_cache[$form . '_' . self::$form_count] = array('form' => $fb->form(), 'form_count' => self::$form_count, 'hide_comments' => $fb->getHideComments(), 'css_to_use' => $fb->css_to_use, 'extra' => $fb->getExtra(), 'form_js' => $fb->getFormJS(), 'hasRecaptcha' => $fb->hasRecaptcha);
     }
     // add filter to hide comments (new method)
     if (self::$form_cache[$form . '_' . self::$form_count]['hide_comments']) {
         self::hideComments();
     }
     return self::$form_cache[$form . '_' . self::$form_count]['form'];
 }
예제 #2
0
 private static function getCachedForm($form_id, $post_id, $preview, $force_count = false, $specific_post_id = null)
 {
     global $post;
     StaticClass::$_mail_error = get_option('_' . $form_id . '_last_mail_error', '');
     //put a sanitize someone could add _mail_error text injection?
     StaticClass::$_mail_error = sanitize_text_field(StaticClass::$_mail_error);
     StaticClass::$_cred_container_id = isset($_POST[StaticClass::PREFIX . 'cred_container_id']) ? intval($_POST[StaticClass::PREFIX . 'cred_container_id']) : $post->ID;
     //https://icanlocalize.basecamphq.com/projects/7393061-toolset/todo_items/196173458/comments
     //Security Check
     if (isset(StaticClass::$_cred_container_id) && !empty(StaticClass::$_cred_container_id)) {
         if (!is_numeric(StaticClass::$_cred_container_id)) {
             wp_die('Invalid data');
         }
     }
     $form_count = false !== $force_count ? $force_count : StaticClass::$_staticGlobal['COUNT'];
     if (false !== $force_count || !array_key_exists($form_id . '_' . StaticClass::$_staticGlobal['COUNT'], StaticClass::$_staticGlobal['CACHE'])) {
         // parse and cache form
         $fb = new CRED_Form_Builder();
         $form_post_type = get_post_type($form_id);
         $form = $form_post_type == CRED_USER_FORMS_CUSTOM_POST_NAME ? $fb->user_form($form_id, $post_id, $preview, $form_count, $specific_post_id) : $fb->form($form_id, $post_id, $preview, $form_count, $specific_post_id);
         /* StaticClass::$_staticGlobal['CACHE'][$form_id.'_'.$form_count]=array(
            'form' =>  $output,
            'count' => $form_count,
            'extra' => $this->_formData->getExtra(),
            'css_to_use' => $this->_formData->getCSS(),
            'js' => $this->getJS(),
            'hide_comments' =>  $this->_formData->hasHideComments(),
            'has_recaptcha' =>  $this->hasRecaptcha()
            ); */
         StaticClass::$_staticGlobal['CACHE'][$form_id . '_' . $form_count] = array('form' => $form, 'count' => $form_count, 'extra' => $fb->getExtra(), 'js' => $fb->getJS(), 'hide_comments' => $fb->hasHideComments(), 'has_recaptcha' => $fb->hasRecaptcha());
     }
     if (isset($post_id)) {
         $parent_post = get_post($post_id);
     }
     // add filter to hide comments (new method)
     if (StaticClass::$_staticGlobal['CACHE'][$form_id . '_' . $form_count]['hide_comments'] || isset($parent_post) && $parent_post->comment_status == 'closed') {
         CRED_Form_Builder_Helper::hideComments();
     }
     return StaticClass::$_staticGlobal['CACHE'][$form_id . '_' . $form_count]['form'];
 }