Example #1
0
 public function processForm($data)
 {
     if (!isset($data['post'])) {
         return;
     }
     $form = $data['post'];
     $message = $data['message'];
     $notification = $data['notification'];
     $messages = $data['messages'];
     $this->setFormData($form->ID, $form->post_title);
     //  register field values
     $this->processFormForStrings($form->post_content, 'Value: ');
     // register form title
     $this->registerString('Form Title: ' . $form->post_title, $form->post_title);
     $this->registerString('Display Message: ' . $form->post_title, $message);
     // register Notification Data also
     if ($notification && isset($notification->notifications) && is_array($notification->notifications)) {
         foreach ($notification->notifications as $ii => $nott) {
             // new format
             // these are not relevant in new format for localization
             /*switch($nott['to']['type'])
               {
                   case 'wp_user':
                       $this->registerString('CRED Notification '.$ii.' Mail To', $nott['to']['user']);
                       break;
                   case 'specific_mail':
                       $this->registerString('CRED Notification '.$ii.' Mail To', $nott['to']['address']);
                       if (isset($nott['to']['name']))
                           $this->registerString('CRED Notification '.$ii.' Mail To Name', $nott['to']['name']);
                       if (isset($nott['to']['lastname']))
                           $this->registerString('CRED Notification '.$ii.' Mail To LastName', $nott['to']['lastname']);
                       break;
                   default:
                       break;
               }*/
             $hashSubject = CRED_Helper::strHash($nott['mail']['subject']);
             $hashBody = CRED_Helper::strHash($nott['mail']['body']);
             $this->registerString('CRED Notification Subject ' . $hashSubject, $nott['mail']['subject']);
             $this->registerString('CRED Notification Body ' . $hashBody, $nott['mail']['body']);
         }
     }
     // register messages also
     foreach ($messages as $msgid => $msg) {
         $this->registerString('Message_' . $msgid, $msg);
     }
     // register options from select and checkboxes/radio fields, force form build
     CRED_Loader::load('CLASS/Form_Builder');
     CRED_Form_Builder::init();
     CRED_Form_Builder::getForm($form->ID, null, false);
     // allow 3rd-party to add extra localization
     do_action('cred_localize_form', $data);
 }
Example #2
0
 public static function getForm($form, $preview = false, $post = null)
 {
     CRED_Loader::load('CLASS/Form_Builder');
     return CRED_Form_Builder::getForm($form, $post, $preview);
 }
Example #3
0
 public static function replaceContentWithForm($content)
 {
     global $post, $wp_query;
     //resolve problem when view templates are added in sidebar widgets
     remove_filter('the_content', array(__CLASS__, 'replaceContentWithForm'), 1000);
     // if it is front page and form preview is required
     if (array_key_exists('cred_form_preview', $_GET)) {
         CRED_Loader::load('CLASS/Form_Builder');
         return CRED_Form_Builder::getForm(intval($_GET['cred_form_preview']), null, true);
     }
     if (array_key_exists('cred_user_form_preview', $_GET)) {
         CRED_Loader::load('CLASS/Form_Builder');
         return CRED_Form_Builder::getUserForm(intval($_GET['cred_user_form_preview']), null, true);
     }
     global $_creds_created;
     if (!isset($_creds_created)) {
         $_creds_created = array();
     }
     if (!empty($_creds_created) && in_array($_GET['cred-edit-form'], $_creds_created)) {
         return apply_filters('the_content', $content);
     }
     if (strpos($content, 'cred-edit-form=' . $_GET['cred-edit-form']) !== false || array_key_exists('cred-edit-form', $_GET) && !is_admin()) {
         array_push($_creds_created, $_GET['cred-edit-form']);
         CRED_Loader::load('CLASS/Form_Builder');
         // get a localised form if exists
         return CRED_Form_Builder::getForm(self::getLocalisedID(intval($_GET['cred-edit-form'])), $post->ID, false);
     }
     if (array_key_exists('cred-edit-form', $_GET) && !is_admin()) {
         if (strpos($content, 'cred-edit-form=' . $_GET['cred-edit-form']) !== false) {
             array_push($_creds_created, $_GET['cred-edit-form']);
             // Show if the content has a cred-edit-form link.
             CRED_Loader::load('CLASS/Form_Builder');
             // get a localised form if exists
             return CRED_Form_Builder::getForm(self::getLocalisedID(intval($_GET['cred-edit-form'])), $post->ID, false);
         } else {
             // Check if it's called from the_content function or wpv-post-body function.
             $db = debug_backtrace();
             //StaticClass::_pre($db);
             foreach ($db as $n => $dbf) {
                 if (isset($dbf['function']) && ($dbf['function'] == 'the_content' || $dbf['function'] == 'wpv_shortcode_wpv_post_body') || $dbf['function'] == 'apply_filters' && in_array('the_content', $dbf['args'])) {
                     array_push($_creds_created, $_GET['cred-edit-form']);
                     CRED_Loader::load('CLASS/Form_Builder');
                     return CRED_Form_Builder::getForm(self::getLocalisedID(intval($_GET['cred-edit-form'])), $post->ID, false);
                 }
             }
             //                if (isset($db[3]['function']) && ($db[3]['function'] == 'the_content' || $db[3]['function'] == 'wpv_shortcode_wpv_post_body')) {
             //                    CRED_Loader::load('CLASS/Form_Builder');
             //                    return CRED_Form_Builder::getForm(self::getLocalisedID(intval($_GET['cred-edit-form'])), $post->ID, false);
             //                }
         }
     }
     // else do nothing
     return $content;
 }