| @@ -1,143 +1,59 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | function rednao_smart_forms_load_form($title,$form_id,$returnComponent) |
| 3 | 3 | { |
| 4 | - require_once(SMART_FORMS_DIR.'additional_fields/smart-forms-additional-fields-list.php'); | |
| 5 | - //$options=get_transient("rednao_smart_forms_$form_id"); | |
| 4 | + $options=get_transient("rednao_smart_forms_$form_id"); | |
| 6 | 5 | $options=false; |
| 7 | 6 | if($options==false) |
| 8 | 7 | { |
| 9 | 8 | global $wpdb; |
| 10 | - /** @noinspection PhpUndefinedMethodInspection */ | |
| 11 | - $result=""; | |
| 12 | - if($form_id!=-1) | |
| 9 | + $result=$wpdb->get_results($wpdb->prepare("select form_id,element_options,form_options,client_form_options from ".SMART_FORMS_TABLE_NAME." where form_id=%d",$form_id)); | |
| 10 | + if(count($result)>0) | |
| 13 | 11 | { |
| 14 | - $result = $wpdb->get_results($wpdb->prepare("select form_id,element_options,form_options,client_form_options from " . SMART_FORMS_TABLE_NAME . " where form_id=%d", $form_id)); | |
| 15 | - if (count($result) > 0) | |
| 16 | - { | |
| 17 | - $result = $result[0]; | |
| 18 | - $options = array('elements' => $result->element_options, | |
| 19 | - 'options' => $result->form_options, | |
| 20 | - 'form_id' => $result->form_id, | |
| 21 | - 'client_form_options' => $result->client_form_options | |
| 22 | - ); | |
| 12 | + $result=$result[0]; | |
| 13 | + $options=array( 'elements'=>$result->element_options, | |
| 14 | + 'options'=>$result->form_options, | |
| 15 | + 'form_id'=>$result->form_id, | |
| 16 | + 'client_form_options'=>$result->client_form_options | |
| 17 | + ); | |
| 23 | 18 | |
| 24 | - set_transient("rednao_smart_forms_$form_id", $options); | |
| 25 | - } | |
| 26 | - }else | |
| 27 | - $options=array(1); | |
| 28 | - | |
| 29 | - } | |
| 30 | - | |
| 31 | - | |
| 32 | - $additionalFields=array(); | |
| 33 | - if(isset($_GET['sfpreview'])) | |
| 34 | - $additionalFields=apply_filters('smart_forms_af_names',$additionalFields); | |
| 35 | - else{ | |
| 36 | - $formOptions=json_decode($options['options'],true); | |
| 37 | - if(isset($formOptions["AdditionalFields"])) | |
| 38 | - { | |
| 39 | - foreach($formOptions["AdditionalFields"] as $field) | |
| 40 | - { | |
| 41 | - array_push($additionalFields,array("id"=>$field)); | |
| 42 | - } | |
| 19 | + set_transient("rednao_smart_forms_$form_id",$options); | |
| 43 | 20 | } |
| 44 | - } | |
| 45 | 21 | |
| 46 | - $generatorDependencies=array('isolated-slider','smart-forms-event-manager','smart-forms-generator-interface','smart-forms-form-elements'); | |
| 47 | - foreach($additionalFields as $field) | |
| 48 | - { | |
| 49 | - array_push($generatorDependencies,'smart-forms-af-'.$field['id']); | |
| 50 | - do_action('smart_forms_af_'.$field['id']); | |
| 51 | 22 | } |
| 52 | - | |
| 53 | - $formElementDependencies=array('isolated-slider','smart-forms-form-elements-container'); | |
| 54 | - $formElementDependencies=apply_filters('smart_forms_add_form_elements_dependencies',$formElementDependencies); | |
| 55 | - | |
| 56 | 23 | wp_enqueue_script('jquery'); |
| 57 | - wp_enqueue_script('smart-forms-event-manager',SMART_FORMS_DIR_URL.'js/formBuilder/eventmanager.js',array('isolated-slider'),SMART_FORMS_FILE_VERSION); | |
| 58 | - wp_enqueue_script('smart-forms-generator-interface',SMART_FORMS_DIR_URL.'js/subscriber_interfaces/ismart-forms-generator.js',array('isolated-slider'),SMART_FORMS_FILE_VERSION); | |
| 59 | - wp_enqueue_script('isolated-slider',plugin_dir_url(__FILE__).'js/rednao-isolated-jq.js',SMART_FORMS_FILE_VERSION); | |
| 60 | - wp_enqueue_script('smart-forms-generator',plugin_dir_url(__FILE__).'js/form-generator.js',$generatorDependencies,SMART_FORMS_FILE_VERSION); | |
| 61 | - wp_enqueue_script('smart-forms-form-elements-container',SMART_FORMS_DIR_URL.'js/formBuilder/container/Container.js',array('isolated-slider'),SMART_FORMS_FILE_VERSION); | |
| 62 | - wp_enqueue_script('smart-forms-form-elements',plugin_dir_url(__FILE__).'js/formBuilder/formelements.js',$formElementDependencies,SMART_FORMS_FILE_VERSION); | |
| 63 | - wp_enqueue_script('smart-forms-formula',SMART_FORMS_DIR_URL.'js/formBuilder/formula/formula.js',array('isolated-slider','smart-forms-event-manager'),SMART_FORMS_FILE_VERSION); | |
| 64 | - wp_enqueue_script('smart-forms-formula-manager',SMART_FORMS_DIR_URL.'js/formBuilder/formula/formulamanager.js',array('isolated-slider','smart-forms-event-manager','smart-forms-formula'),SMART_FORMS_FILE_VERSION); | |
| 65 | - wp_enqueue_script('smart-forms-elements-manipulators',SMART_FORMS_DIR_URL.'js/formBuilder/properties/manipulators.js',array('isolated-slider'),SMART_FORMS_FILE_VERSION); | |
| 66 | - wp_enqueue_script('smart-forms-conditional-handlers',SMART_FORMS_DIR_URL.'js/bundle/conditionalHandlers_bundle.js',array('isolated-slider'),SMART_FORMS_FILE_VERSION); | |
| 24 | + wp_enqueue_script('smart-forms-event-manager',SMART_FORMS_DIR_URL.'js/formBuilder/eventmanager.js',array('isolated-slider')); | |
| 25 | + wp_enqueue_script('isolated-slider',plugin_dir_url(__FILE__).'js/rednao-isolated-jq.js'); | |
| 26 | + wp_enqueue_script('smart-forms-generator',plugin_dir_url(__FILE__).'js/form-generator.js',array('isolated-slider',)); | |
| 27 | + wp_enqueue_script('smart-forms-form-elements',plugin_dir_url(__FILE__).'js/formBuilder/formelements.js',array('smart-forms-generator')); | |
| 28 | + wp_enqueue_script('smart-forms-formula',SMART_FORMS_DIR_URL.'js/formBuilder/formula/formula.js',array('isolated-slider','smart-forms-event-manager')); | |
| 29 | + wp_enqueue_script('smart-forms-formula-manager',SMART_FORMS_DIR_URL.'js/formBuilder/formula/formulamanager.js',array('isolated-slider','smart-forms-event-manager','smart-forms-formula')); | |
| 30 | + wp_enqueue_script('smart-forms-elements-manipulators',SMART_FORMS_DIR_URL.'js/formBuilder/properties/manipulators.js',array('isolated-slider')); | |
| 67 | 31 | |
| 68 | - if($form_id==-1) | |
| 69 | - wp_enqueue_script('smart-forms-preview-helper',plugin_dir_url(__FILE__).'js/formBuilder/previewHelper.js',array('smart-forms-generator'),SMART_FORMS_FILE_VERSION); | |
| 70 | - | |
| 71 | - do_action('smart_forms_loading_form',$options); | |
| 72 | - do_action('smart_forms_pr_add_form_elements_extensions'); | |
| 73 | - require_once(SMART_FORMS_DIR.'translations/form-elements-translation.php'); | |
| 74 | - require_once(SMART_FORMS_DIR.'smart-forms-bootstrap.php'); | |
| 75 | - | |
| 76 | - wp_enqueue_style('smart-forms-Slider',SMART_FORMS_DIR_URL.'css/smartFormsSlider/jquery-ui-1.10.2.custom.min.css',array(),SMART_FORMS_FILE_VERSION); | |
| 77 | - wp_enqueue_style('smart-forms-custom-elements',plugin_dir_url(__FILE__).'css/formBuilder/custom.css',array(),SMART_FORMS_FILE_VERSION); | |
| 78 | - | |
| 79 | - | |
| 32 | + wp_enqueue_style('smart-forms-Slider',SMART_FORMS_DIR_URL.'css/smartFormsSlider/jquery-ui-1.10.2.custom.min.css'); | |
| 33 | + wp_enqueue_style('smart-forms-custom-elements',plugin_dir_url(__FILE__).'css/formBuilder/custom.css'); | |
| 34 | + echo "<script type=\"text/javascript\">var ajaxurl = '".admin_url('admin-ajax.php')."';</script>"; | |
| 80 | 35 | $random=rand(); |
| 81 | - if($form_id==-1) | |
| 82 | - $random="sfpreviewcontainer"; | |
| 83 | 36 | |
| 84 | - if(!defined ("SMART_DONATIONS_PLUGIN_URL")) | |
| 85 | - define("SMART_DONATIONS_PLUGIN_URL",""); | |
| 86 | - | |
| 87 | - if(!defined ("SMART_DONATIONS_SANDBOX")) | |
| 88 | - define("SMART_DONATIONS_SANDBOX",""); | |
| 89 | - | |
| 90 | - | |
| 91 | - $user=wp_get_current_user(); | |
| 92 | - $userName=$user->user_login; | |
| 93 | - $firstName=''; | |
| 94 | - $lastName=''; | |
| 95 | - $email=''; | |
| 96 | - if($userName==false) | |
| 97 | - $userName=''; | |
| 98 | - else{ | |
| 99 | - $firstName=$user->user_firstname; | |
| 100 | - $lastName=$user->user_lastname; | |
| 101 | - $email=$user->user_email; | |
| 102 | - } | |
| 103 | - | |
| 104 | - | |
| 105 | 37 | if($returnComponent==false) |
| 106 | 38 | { |
| 107 | - echo "<script type=\"text/javascript\">var ajaxurl = '".esc_url(admin_url('admin-ajax.php'))."';</script>"; | |
| 108 | - echo "<div class='widget'>"; | |
| 109 | 39 | if($options==null) |
| 110 | - return null; | |
| 40 | + return; | |
| 111 | 41 | |
| 112 | 42 | if($title) |
| 113 | - echo "<div class='widget-wrapper'><h3 class='widgettitle widget-title'>".esc_html($title)."</h3>"; | |
| 43 | + echo "<div class='widget-wrapper'><h3 class='widgettitle'>$title</h3>" | |
| 114 | 44 | |
| 115 | 45 | ?> |
| 116 | 46 | |
| 47 | + <div id="formContainer<?php echo $random?>" class='rednaoFormContainer'></div> | |
| 117 | 48 | |
| 118 | - <div id="formContainer<?php echo esc_attr($random)?>" class='sfForm rednaoFormContainer bootstrap-wrapper SfFormElementContainer'></div> | |
| 119 | - <script type="text/javascript"> | |
| 120 | - var smartFormsSaveNonce=<?php echo json_encode(wp_create_nonce('save_form'))?>; | |
| 121 | - var smartFormsCurrentTime=new Date(<?php echo json_encode(date('D M d Y H:i:s O'))?>); | |
| 122 | - var smartFormsUserName=<?php echo json_encode($userName)?>; | |
| 123 | - var smartFormsFirstName=<?php echo json_encode($firstName)?>; | |
| 124 | - var smartFormsLastName=<?php echo json_encode($lastName)?>; | |
| 125 | - var smartFormsEmail=<?php echo json_encode($email)?>; | |
| 126 | - var smartFormsPath=<?php echo json_encode(plugin_dir_url(__FILE__))?>; | |
| 127 | - var smartDonationsRootPath=<?php echo json_encode(SMART_DONATIONS_PLUGIN_URL) ?>; | |
| 128 | - var smartDonationsSandbox=<?php echo json_encode(SMART_DONATIONS_SANDBOX) ?>; | |
| 129 | - var smartFormsDesignMode=false; | |
| 130 | - var smartFormsAdditionalFields<?php echo ($options['form_id']==null?0:intval($options['form_id']))?>=<?php echo json_encode($additionalFields)?>; | |
| 49 | + <script> | |
| 50 | + var smartFormsPath="<?php echo plugin_dir_url(__FILE__)?>"; | |
| 51 | + | |
| 131 | 52 | if(!window.smartFormsItemsToLoad) |
| 132 | - window.smartFormsItemsToLoad=[]; | |
| 53 | + window.smartFormsItemsToLoad=new Array();; | |
| 133 | 54 | |
| 134 | - window.smartFormsItemsToLoad.push(<?php echo json_encode([ | |
| 135 | - 'form_id'=>$options['form_id'], | |
| 136 | - 'elements'=>json_decode($options['elements']), | |
| 137 | - 'client_form_options'=>json_decode($options['client_form_options']), | |
| 138 | - 'container'=>'formContainer'.$random | |
| 139 | - ])?>); | |
| 55 | + window.smartFormsItemsToLoad.push({'form_id':<?php echo $options['form_id']?>, 'elements':<?php echo $options['elements']?>,'client_form_options':<?php echo $options['client_form_options']?>,'container':'formContainer<?php echo $random?>'}); | |
| 140 | 56 | |
| 141 | 57 | </script> |
| 142 | 58 | <?php |
| 143 | 59 | if($title) |
| @@ -142,91 +58,17 @@ | ||
| 142 | 58 | <?php |
| 143 | 59 | if($title) |
| 144 | 60 | echo "</div>"; |
| 145 | 61 | |
| 146 | - echo "</div>"; | |
| 147 | - | |
| 148 | 62 | }else{ |
| 149 | - | |
| 150 | - global $createdForms; | |
| 151 | - if($createdForms==null) | |
| 152 | - $createdForms=array(); | |
| 153 | - | |
| 154 | - $loadedForm=""; | |
| 155 | - if($form_id!=-1) | |
| 156 | - { | |
| 157 | - | |
| 158 | - | |
| 159 | - $newOptions=[]; | |
| 160 | - $newOptions['form_id']=$form_id; | |
| 161 | - $newOptions['elements']=json_decode($options['elements']); | |
| 162 | - $newOptions['client_form_options']=json_decode($options['client_form_options']); | |
| 163 | - $newOptions['container']='formContainer'.$random; | |
| 164 | - | |
| 165 | - $createdForms[]=$newOptions; | |
| 166 | - wp_localize_script('smart-forms-generator','smartFormsItemsToLoad',$createdForms); | |
| 167 | - | |
| 168 | - } | |
| 169 | - $script=" | |
| 170 | - var ajaxurl = '".admin_url('admin-ajax.php')."'; | |
| 171 | - var smartFormsCurrentTime=new Date('".date('D M d Y H:i:s O')."'); | |
| 172 | - var smartFormsSaveNonce=\"".wp_create_nonce('save_form')."\"; | |
| 173 | - var smartFormsUserName=\"".$userName."\"; | |
| 174 | - var smartFormsFirstName=\"".$firstName."\"; | |
| 175 | - var smartFormsLastName=\"".$lastName."\"; | |
| 176 | - var smartFormsEmail=\"".$email."\"; | |
| 177 | - var smartFormsPath=\"".plugin_dir_url(__FILE__)."\"; | |
| 178 | - var smartDonationsRootPath=\"".SMART_DONATIONS_PLUGIN_URL."\"; | |
| 179 | - var smartDonationsSandbox=\"".SMART_DONATIONS_SANDBOX."\"; | |
| 180 | - var smartFormsAdditionalFields".(!isset($options['form_id'])?0:$options['form_id'])."=".json_encode($additionalFields)."; | |
| 181 | - var smartFormsDesignMode=false; | |
| 182 | - if(!window.smartFormsItemsToLoad) | |
| 183 | - window.smartFormsItemsToLoad=new Array(); | |
| 184 | - "; | |
| 185 | - | |
| 186 | - $script.=$loadedForm; | |
| 187 | 63 | if($options==null) |
| 188 | 64 | return ""; |
| 189 | - | |
| 190 | - $container="<div id='formContainer$random' class='sfForm rednaoFormContainer SfFormElementContainer bootstrap-wrapper'></div>"; | |
| 191 | - $useInlineScript=false; | |
| 192 | - if($useInlineScript&&function_exists('wp_add_inline_script')) | |
| 193 | - { | |
| 194 | - wp_add_inline_script('smart-forms-generator',$script); | |
| 195 | - return $container; | |
| 196 | - }else | |
| 197 | - return $container."<script>$script</script>"; | |
| 198 | - | |
| 199 | - | |
| 65 | + return "<div id='formContainer$random' class='rednaoFormContainer'></div> | |
| 66 | + <script> | |
| 67 | + var smartDonationsRootPath=\"".plugin_dir_url(__FILE__)."\"; | |
| 68 | + if(!window.smartFormsItemsToLoad) | |
| 69 | + window.smartFormsItemsToLoad=new Array();; | |
| 70 | + window.smartFormsItemsToLoad.push({ 'form_id':".$options['form_id'].", 'elements':".$options['elements'].",'client_form_options':".$options['client_form_options'].",'container':'formContainer$random'}); | |
| 71 | + </script> | |
| 72 | + "; | |
| 200 | 73 | } |
| 201 | - | |
| 202 | - return null; | |
| 203 | -} | |
| 204 | - | |
| 205 | -function rednao_smart_forms_load_preview(){ | |
| 206 | - $previewPage=get_page_by_title("Smart Forms Page Preview","OBJECT","smartforms_preview"); | |
| 207 | - $page_id=0; | |
| 208 | - if($previewPage==null) | |
| 209 | - { | |
| 210 | - $post = array( | |
| 211 | - 'post_content' => '[sform]-1[/sform]', | |
| 212 | - 'post_name' => 'Smart Forms Page Preview', | |
| 213 | - 'post_title' => 'Smart Forms Page Preview', | |
| 214 | - 'post_status' => 'draft', | |
| 215 | - 'post_type' => 'smartforms_preview', | |
| 216 | - 'ping_status' => 'closed', | |
| 217 | - 'comment_status' => 'closed' | |
| 218 | - ); | |
| 219 | - $page_id = wp_insert_post( $post ); | |
| 220 | - wp_redirect( trailingslashit( site_url() ) . '?page_id='.$page_id.'&sfpreview=true'); | |
| 221 | - }else | |
| 222 | - $page_id=$previewPage->ID; | |
| 223 | - | |
| 224 | - $url=get_permalink($page_id); | |
| 225 | - | |
| 226 | - if(strpos($url,'?')===false) | |
| 227 | - $url.=$url.'?'; | |
| 228 | - | |
| 229 | - $url.='?page_id='.$previewPage->ID.'&sfpreview=true'; | |
| 230 | - wp_redirect($url); | |
| 231 | - | |
| 232 | 74 | } |