Changeset 1179925
- Timestamp:
- 06/12/2015 10:06:20 PM (10 years ago)
- Location:
- forms-actions
- Files:
-
- 2 added
- 4 edited
- 7 copied
Legend:
- Unmodified
- Added
- Removed
-
forms-actions/trunk/Forms_actions.php
r1133374 r1179925 25 25 require_once( plugin_dir_path( __FILE__ ) . '/inc/php_alpaca_api.php' ); 26 26 27 require_once( plugin_dir_path( __FILE__ ) . '/widgets/join_widget.php' ); 28 27 29 /* METABOX start ------------------------------------ */ 28 30 29 31 function fa_add_meta_box() { 30 32 31 33 /* build post types array to display ACF frontend metabox */ 32 $post_types = get_post_types( '', 'names' ); 33 34 foreach ( $post_types as $key => $value) { 35 $screens[] = $key; 36 } 37 38 if( $screen == 'acf' ){ 39 $title_box = __( 'Forms global ACTIONS', 'forms_actions' ); 40 }else{ 34 35 41 36 $title_box = __( 'Forms ACTIONS (ACF extention)', 'forms_actions' ); 42 }43 44 foreach ( $screens as $screen ) {45 37 /* only editors or administrator can display forms */ 46 38 if( current_user_can('edit_others_pages') ) { … … 54 46 ); 55 47 } 56 } 57 } 48 49 } 50 51 58 52 add_action( 'add_meta_boxes', 'fa_add_meta_box'); 59 60 53 function fa_meta_box_callback( $post ) { 61 62 /* create ACF global guardian */ 63 if( get_post_type( $post->ID ) == 'acf'){ 64 $gloabal_guardian = false; 65 echo '<div style="font-weight:bold; border-bottom:1px solid #eee; margin-bottom:10px; padding-bottom:5px">'.__('Global properties for').' '.$post->post_title.'</div>'; 66 } 67 /* check is globals are defined (in first fieldgroup) */ 68 69 /* TODO checkit - propably array [0] is error*/ 70 $fieldsArray = apply_filters('acf/get_field_groups', array()); 71 $global_form_id = $fieldsArray[0]['id']; 72 $global_alpaca = get_post_meta( $global_form_id, '_meta_fa_box_alpaca', true ); 73 74 /* -------------------------- */ 75 76 /* Add an nonce field so we can check for it later. */ 77 wp_nonce_field( 'fa_meta_box', 'fa_meta_box_nonce' ); 78 79 $create_object = get_post_meta( $post->ID, '_meta_fa_create_object', true ); // bolean 80 $value_alpaca = get_post_meta( $post->ID, '_meta_fa_box_alpaca', true ); 81 82 /* overwrite lolal settings for global ACF settings */ 83 if($global_alpaca != ''){ 84 /* insert global data olny with create new post (no edit) */ 85 if($create_object != 'false'){ 86 $value_alpaca = $global_alpaca; 87 } 88 } 89 90 echo '<input type="hidden" id="fa_create_object" name="fa_create_object" value="'.$create_object.'" size="25" />'; 91 echo '<input type="hidden" id="fa_alpaca_data" name="fa_alpaca_data" value="'.$value_alpaca.'" size="25" />'; 92 93 ?><div id="fa_options" style=""></div> 94 <script type="text/javascript"> 95 jQuery(document).ready(function($) { 96 $("#fa_options").alpaca({ 97 /* ----------------------------------------------------------------------- */ 98 <?php if($value_alpaca != ''){ ?> 99 "data" : <?php echo urldecode ( $value_alpaca );?>, 100 <?php } ?> 101 102 "options": { 103 "fields": { 104 105 "fa_clear_form": { 106 "rightLabel": "Clear to defaults" 107 }, 108 "fa_send_new_password": { 109 "rightLabel":"Send new password", 110 }, 111 112 "fa_send_email": { 113 "rightLabel": "Send email" 114 }, 115 "fa_create_post_dependency": { 116 "rightLabel": "Create post" 117 }, 118 "fa_create_post":{ 119 "description": "Select type to created output", 120 "fields": { 121 122 "redirect_to_id":{ 123 "dataSource":<?php echo render_posttype_to_alpaca_string('page'); ?>, 124 "rightLabel": "Redirect", 125 "type":"select" 126 }, 127 "redirect_to_me": { 128 "rightLabel": "Redirect to created element" 129 } 130 } 131 132 133 }, 134 "fa_update_post": { 135 "rightLabel": "Update post" 136 }, 137 "fa_login_user_dependency": { 138 "rightLabel": "Login user" 139 }, 140 141 "fa_login_user": { 142 "fields": { 143 "logout_unconfirmed":{ 144 145 "rightLabel": "Logout unconfirmed", 146 147 }, 148 "redirect_to_id":{ 149 "dataSource":<?php echo render_posttype_to_alpaca_string('page'); ?>, 150 "rightLabel": "Redirect", 151 "type":"select" 152 } 153 } 154 }, 155 156 157 "fa_register_user_dependency": { 158 "rightLabel": "Register user" 159 }, 160 "fa_register_user": { 161 "fields": { 162 "confirm_by_email":{ 163 "rightLabel": "Confirm by email" 164 }, 165 "login_as_email": { 166 //"required": false, 167 "rightLabel": "Login as email" 168 }, 169 "redirect_to_id":{ 170 "dataSource":<?php echo render_posttype_to_alpaca_string('page'); ?>, 171 "rightLabel": "Redirect", 172 "type":"select" 173 } 174 } 175 }, 176 177 "fa_update_user": { 178 "rightLabel": "Update user" 179 }, 180 181 182 "fa_targeted_questions_dependency": { 183 "rightLabel": "Targeted questions" 184 }, 185 "fa_targeted_questions": { 186 "fields": { 187 "item": { 188 "fields": { 189 "post_type": { 190 "type": "select", 191 "dataSource": <?php echo render_posttype_to_alpaca_string('page'); ?>, 192 } 193 } 194 } 195 }, 196 "items": { 197 "addItemLabel": "Add target", 198 "removeItemLabel": "Remove", 199 "showMoveDownItemButton": false, 200 "showMoveUpItemButton": false, 201 } 202 }, 203 204 "fa_dont_display_after_send": { 205 "rightLabel": "Dont display form after you send" 206 }, 207 "fa_redirect_dependency": { 208 "rightLabel": "Redirect" 209 }, 210 } 211 }, 212 "schema": { 213 //"title": "Form extended options", 214 //"description": "Define your special display properties", 215 "type": "object", 216 "properties": { 217 218 /* -------------------------- */ 219 "fa_clear_form": { 220 "description": "Always clear your form to defaults", 221 "type": "boolean" 222 }, 223 /* -------------------------- */ 224 "fa_send_email": { 225 "description": "Name your form field as: email (addres to send), subject* (email subject), message* (email message), succes (mesage after send)", 226 "type": "boolean" 227 }, 228 /* -------------------------- */ 229 "fa_create_post_dependency": { 230 "description": "Use form to create new post or edit exist. Name your form field as: post_title, post_content, post_excerpt, succes (mesage after send)", 231 "type": "boolean" 232 }, 233 /* -------------------------- */ 234 "fa_create_post": { 235 "dependencies": "fa_create_post_dependency", 236 "type": "object", 237 "properties": { 238 "post_type": { 239 //"required": false, 240 "title": "Select post type", 241 "enum": [<?php echo render_posttypes_list_to_alpaca_array(); ?>] 242 }, 243 "category":{ 244 "title": "insert field name to mapped with category", 245 }, 246 "redirect_to_me": { 247 //"required": false, 248 "type": "boolean" 249 }, 250 "redirect_to_id": { 251 //"required": false, 252 "title": "post to redirect", 253 }, 254 "redirect_param":{ 255 "title": "add url parameters to redirect", 256 }, 257 "redirect_to_url": { 258 //"required": false, 259 "title": "url to redirect", 260 }, 261 262 } 263 }, 264 "fa_update_post": { 265 "description": "Update your post from fields: post_title, post_content etc.", 266 "type": "boolean" 267 }, 268 /* -------------------------- */ 269 "fa_register_user_dependency": { 270 "description": "Use form to register new user or edit exist. Name your form field as: user_name, user_pass, user_email", 271 "type": "boolean" 272 }, 273 /* -------------------------- */ 274 "fa_register_user": { 275 "dependencies": "fa_register_user_dependency", 276 "type": "object", 277 "properties": { 278 "confirm_by_email": { 279 //"required": false, 280 "type": "boolean" 281 }, 282 "login_as_email": { 283 //"required": false, 284 "type": "boolean" 285 }, 286 "redirect_to_id": { 287 //"required": false, 288 "title": "Redirect after register", 289 } 290 } 291 }, 292 "fa_update_user": { 293 "description": "Update your user from fields: user_email, first_name etc.", 294 "type": "boolean" 295 }, 296 /* -------------------------- */ 297 /* -------------------------- */ 298 "fa_login_user_dependency": { 299 "description": "Login user by user_login and user_password", 300 "type": "boolean" 301 }, 302 "fa_login_user": { 303 "dependencies": "fa_login_user_dependency", 304 "type": "object", 305 "properties": { 306 "logout_unconfirmed": { 307 //"required": false, 308 "type": "boolean" 309 }, 310 "redirect_to_id":{ 311 "title": "element to redirect", 312 313 } 314 } 315 }, 316 /* -------------------------- */ 317 /* -------------------------- */ 318 "fa_send_new_password": { 319 "description": "Name your form field as user_pass field", 320 "type": "boolean" 321 }, 322 323 324 "fa_targeted_questions_dependency": { 325 "description": "Matching your form results with targeted pages and redirect to best choose.", 326 "type": "boolean" 327 }, 328 /* -------------------------- */ 329 "fa_targeted_questions": { 330 "dependencies": "fa_targeted_questions_dependency", 331 "type": "array", 332 "items": { 333 "type": "object", 334 "properties": { 335 "post_type": { 336 //"dependencies": "fa_targeted_questions_dependency", 337 "title": "Add target pages", 338 "description": "Add and select target pages to redirect after send form - algorytm choose best choice", 339 "type": "string" 340 } 341 } 342 } 343 }, 344 345 "fa_dont_display_after_send": { 346 "description": "Dont display form again, after you send data", 347 "type": "boolean" 348 }, 349 /* -------------------------- */ 350 "fa_redirect_dependency": { 351 "description": "Set page target to skip after send", 352 "type": "boolean" 353 }, 354 "fa_redirect": { 355 "dependencies": "fa_redirect_dependency", 356 "description": "add url to redirect", 357 358 } 359 } 360 }, 361 362 /*"view": { 363 //"parent": "bootstrap-edit", 364 "layout": { 365 "template": "threeColumnGridLayout", 366 "bindings": { 367 "fa_redirect_dependency": "column-1", 368 "fa_redirect": "column-1", 369 370 } 371 }, 372 "templates": { 373 "threeColumnGridLayout": '<div class="row">' + '{{#if options.label}}<h2>{{options.label}}</h2><span></span>{{/if}}' + '{{#if options.helper}}<p>{{options.helper}}</p>{{/if}}' + '<div id="column-1" class="col-md-6"> </div>' + '<div id="column-2" class="col-md-6"> </div>' + '<div id="column-3" class="col-md-12"> </div>' + '<div class="clear"></div>' + '</div>' 374 } 375 },*/ 376 377 /* ----------------------------------------------------------------------- */ 378 "postRender": function(renderedForm) { 379 $('#fa_options select, #fa_options input, #fa_options textarea').live('change',function() { 380 381 //if (renderedForm.isValid(true)) { 382 var val2 = renderedForm.getValue(); 383 $('#fa_alpaca_data').val(encodeURIComponent(JSON.stringify(val2))); 384 //} 385 }); 386 } 387 /* ----------------------------------------------------------------------- */ 388 }); 389 }); 390 </script><?php 54 global $post; 55 if($post->post_type == 'acf'){ 56 require_once( plugin_dir_path( __FILE__ ) . '/inc/fa_metabox_and_schema.php' ); 57 }else{ 58 echo 'to set form actions go to <a href="wp-admin/edit.php?post_type=acf">ACF form</a>'; 59 } 391 60 } 392 61 … … 445 114 446 115 /* DISPLAY filter ------------------------------------ */ 447 function fa_realize_form_actions() { 448 449 if( isset($_POST['acf_nonce']) && wp_verify_nonce($_POST['acf_nonce'], 'input') ) 450 { 451 452 global $post; 453 116 function my_acf_save_post( $post_id ) { 117 if ( ! is_admin() ) { 118 //global $post; 454 119 455 120 global $returnObj; … … 460 125 ); 461 126 462 463 127 // ADD gloal prop 464 128 $get_globals = afd_form_permision(); 129 465 130 foreach ($get_globals as $key => $value) { 466 131 if(get_post_meta( $value, '_meta_fa_box_alpaca', true )!=''){ 132 467 133 $args = json_decode(urldecode(get_post_meta( $value, '_meta_fa_box_alpaca', true ))); 468 469 134 process_actions($args); 470 135 471 136 } 472 137 } 473 $args = json_decode(urldecode(get_post_meta( $post->ID, '_meta_fa_box_alpaca', true ))); 474 process_actions($args); 138 139 140 475 141 476 142 if($returnObj["redirect_param"] != null){ … … 489 155 } 490 156 491 492 157 if($returnObj["redirect_to_url"] != null){ 493 158 … … 501 166 } 502 167 503 504 $args_AFD = json_decode( urldecode ( get_post_meta($post->ID,'_meta_afd_form_render_box_alpaca', true )), true ); 505 if($args_AFD['display_edit']){506 wp_redirect(get_permalink($post->ID));507 exit; 508 } 509 510 //echo 'you propably send ACF form';511 return $returnObj; 512 513 } 514 515 516 } 168 //$args_AFD = json_decode( urldecode ( get_post_meta($post_id,'_meta_afd_form_render_box_alpaca', true )), true ); 169 170 wp_redirect(get_permalink($post->ID).'?acf_message='.$GLOBALS['acf_validation_errors']); 171 exit; 172 173 } 174 } 175 add_action('acf/save_post', 'my_acf_save_post', 30); 176 177 178 179 180 181 517 182 518 183 function process_actions($args, $post_id = '', $ajax = false){ … … 538 203 $swith = substr($key, -10); 539 204 if( $swith != 'dependency'){ 205 206 /* forced edit post */ 207 if($_GET['pid']!='' ){ 208 if($key == 'fa_create_post'){ 209 $key = 'fa_update_post'; 210 } 211 } 212 540 213 @call_user_func_array($key,array($value)); 541 //echo $key.'('.array($value).')<br/>'; 542 //var_dump($key,$value); 214 //var_dump('action:'.$key,$value); 543 215 } 544 216 } 545 217 546 218 } 547 548 foreach ($args as $key => $value) { 549 if($key == 'fa_clear_form'){ 550 $swith = substr($key, -10); 551 if( $swith != 'dependency'){ 552 @call_user_func_array($key,array($value)); 553 //echo $key.'('.array($value).')<br/>'; 219 if($_GET['pid']=='' ){ 220 foreach ($args as $key => $value) { 221 if($key == 'fa_clear_form'){ 222 $swith = substr($key, -10); 223 if( $swith != 'dependency'){ 224 @call_user_func_array($key,array($value)); 225 //var_dump('action:'.$key,$value); 226 227 } 554 228 } 229 555 230 } 556 557 231 } 558 232 … … 564 238 { 565 239 // editor + administrator = moderate_comments; 566 add_menu_page('Forms actions', 'Forms actions', 'administrator', 'forms_actions', 'forms_actions_callback');240 //add_menu_page('Forms actions', 'Forms actions', 'administrator', 'forms_actions', 'forms_actions_callback'); 567 241 // submenu with calbac 568 //add_submenu_page(' acf', 'UiGEN hierarchy', 'UiGEN hierarchy', 'administrator', 'url_uigen_hierarchy', 'UiGEN_hierarchy_callback');242 //add_submenu_page('forms_actions', 'UiGEN hierarchy', 'UiGEN hierarchy', 'administrator', 'url_uigen_hierarchy', 'forms_actions_database_calback'); 569 243 // submenu from defined posttype 570 244 //add_submenu_page('url_uigen_core', 'UiGEN hierarchy', 'UiGEN hierarchy', 'manage_options', 'edit.php?post_type=template_hierarchy'); //add_submenu_page('url_uigencore', 'Dodaj', 'Dodaj', 'administrator', 'url_add_mod', 'moderator_ADD'); … … 576 250 require_once( plugin_dir_path( __FILE__ ) . '/inc/fa_admin_gui.php' ); 577 251 } 252 253 function forms_actions_database_calback(){ 254 require_once( plugin_dir_path( __FILE__ ) . '/inc/fa_admin_gui_database.php' ); 255 } 256 257 258 259 260 261 -
forms-actions/trunk/ajax/db.php
r1133370 r1179925 1 1 <?php 2 2 require_once("../../../../wp-load.php"); 3 if ( current_user_can( 'manage_options' ) ) {3 if ( current_user_can( 'manage_options' ) && $_POST['object_data'] != NULL ) { 4 4 /* A user with admin privileges */ 5 6 7 8 5 require_once plugin_dir_path( __DIR__ ) . '/inc/Spyc.php'; 9 6 /* ----------------------------------- */ … … 23 20 $db_array = array_merge( $db_old_array , $db_array ); 24 21 25 26 27 28 22 file_put_contents( plugin_dir_path( __DIR__ ) . 'yaml/database/arguments/database-arguments.yaml' , Spyc::YAMLDump( $db_array )); 29 23 30 24 // create new table 31 25 32 26 global $wpdb; … … 49 43 50 44 $db_create_table_string .= " PRIMARY KEY (`ID`) \n"; 51 $db_create_table_string .= " CHARACTER SET utf8 COLLATE utf8_general_ci \n";45 //$db_create_table_string .= " CHARACTER SET utf8 COLLATE utf8_general_ci \n"; 52 46 $db_create_table_string .= " ) \n"; 53 47 $db_tables_array[$db_tb_name] = $db_create_table_string; … … 56 50 57 51 // Create tables 58 echo '<pre style="font-size:9px">'; 59 foreach ($db_tables_array as $db_tb => $db_sql_synax) { 60 echo '<br/>----------------<br/>create '.$db_tb.'<br/>----------------<br/>'; 61 echo $db_sql_synax; 62 $wpdb->query($db_sql_synax); 63 52 function print_resoult(){ 53 echo '<pre style="font-size:9px">'; 54 foreach ($db_tables_array as $db_tb => $db_sql_synax) { 55 echo '<br/>----------------<br/>create '.$db_tb.'<br/>----------------<br/>'; 56 echo $db_sql_synax; 57 $db_msg = $wpdb->query($db_sql_synax); 58 59 echo '<br/>----------------return----------------<br/>'; 60 echo $db_msg; 61 } 62 echo '</pre>'; 64 63 } 65 echo '</pre>'; 64 } 65 66 /* AJAX METHODS */ 67 if($_POST['wpdbselect'] != NULL){ 68 global $wpdb; 69 //global $WP_user; 70 71 72 $sql = 73 " 74 SELECT * 75 FROM ".$wpdb->prefix.$_POST['from']." 76 WHERE id_spotkanie = ".$_POST['where']['id_spotkanie']." 77 "; 78 79 $resoults = $wpdb->get_results($sql); 80 81 82 foreach ($resoults as &$value) { 83 $value->avatar = get_user_meta($value->id_user,'avatar',true); 84 } 66 85 67 86 } 87 88 echo json_encode($resoults); 89 68 90 ?> -
forms-actions/trunk/inc/fa_controllers.php
r1133370 r1179925 1 1 <?php 2 /* DONT USAGE ECHO, PRINT AND VAR_DUMP HERE - all comments go to ajax responces!!!! */ 3 2 4 function fa_targeted_questions($args){ 3 5 … … 11 13 $post_id = $value -> post_type; 12 14 $thisArray = get_fields($post_id); 13 /*14 echo '<pre>';15 var_dump($thisArray);16 echo '</pre>';17 */18 15 19 16 /* check arrays */ … … 28 25 $counter++; 29 26 } 30 31 27 $percent = ( $points / $counter ) * 100; 32 33 28 echo '----------------------<br/>'.$points.' '.__('points'); 34 29 echo '<br/>'.$percent.' %<br/>'; 35 36 30 if( $points > $max_points ){ 37 31 $max_points = $points; … … 40 34 41 35 } 42 43 36 echo '<h1>'.__('The WINNER is:').' '.get_the_title($winner_id).'</h1>'; 44 37 } … … 114 107 $message.= '</table>'; 115 108 116 /*117 echo '<pre>';118 var_dump($messages_array);119 echo '</pre>';120 */121 122 109 wp_mail( $emails_array , reset($subjects_array) , $message, $headers , $attachments_array ); 123 110 … … 125 112 126 113 function fa_create_post($args){ 114 115 global $post; 116 global $FA_ajax; 117 global $ACF; 118 119 120 127 121 128 122 … … 133 127 $new_post['post_type'] = $args->post_type; 134 128 $new_post['post_status'] = 'publish'; 129 130 135 131 $this_form_array = get_fields($post->ID); 136 137 132 138 133 foreach ($this_form_array as $key => $value) { … … 144 139 $new_post['post_content'] = $value; 145 140 } 141 if($key == 'post_excerpt'){ 142 $new_post['post_excerpt'] = $value; 143 } 144 if($key == 'post_date'){ 145 $new_post['post_date'] = $value; 146 } 146 147 if($key == $category){ 147 $new_post['post_category'] = $value; 148 // przy selekcie idzie pojedyncza wartosc a przy czecjoboxach chyba tablica (trzeba to sprawdzić) 149 $new_post['post_category'] = array($value); 148 150 } 149 151 if($key == 'post_status'){ … … 159 161 $guardian_meta = false; 160 162 161 if($key == 'post_title'){163 /* if($key == 'post_title'){ 162 164 $guardian_meta = true; 163 165 } … … 165 167 $guardian_meta = true; 166 168 } 169 if($key == 'post_excerpt'){ 170 $guardian_meta = true; 171 } 172 if($key == 'post_date'){ 173 $guardian_meta = true; 174 }*/ 167 175 168 176 169 177 if($guardian_meta == false){ 170 178 update_post_meta($post_id,$key,$value); 171 var_dump($key.'_'.$value);172 179 } 173 180 } … … 206 213 $returnObj['redirect_param'] = $args->redirect_param; 207 214 } 215 216 $return_msg = 'Post created succesfull'; 217 if($FA_ajax == true){ 218 $this_form_array['ID'] = $post_id; 219 220 /* convert to rest */ 221 $this_form_array['my_metas']['address'] = $this_form_array['miejsce']; 222 $this_form_array['my_metas']['time'] = $new_post['post_date']; 223 224 225 $yourcat = get_category ($this_form_array['post_category']); 226 227 $this_form_array['terms']['category'][0]['id'] = $yourcat->term_id; 228 $this_form_array['terms']['category'][0]['name'] = $yourcat->name; 229 $this_form_array['terms']['category'][0]['slug'] = $yourcat->slug; 230 231 $this_form_array['title'] = $new_post['post_title']; 232 233 $this_form_array['author']['avatar'] = get_user_meta(get_current_user_id(),'avatar',true); 234 235 $this_form_array['my_metas']['photo']['image_0'] = 'http://wiki.openstreetmap.org/w/images/thumb/9/9d/Climbing_icon_no_rope.svg/400px-Climbing_icon_no_rope.svg.png'; 236 echo json_encode( $this_form_array ); 237 238 }else{ 239 $GLOBALS['acf_validation_errors'] = urlencode($return_msg); 240 return $return_msg; 241 242 } 243 244 245 246 208 247 } 209 248 function fa_update_post($args){ 210 249 211 250 $this_form_array = get_fields($post->ID); 251 252 if($args->category != ''){ 253 $category = $args->category; 254 } 255 212 256 foreach ($this_form_array as $key => $value) { 213 257 if($key == 'post_title'){ … … 218 262 } 219 263 if($key == $category){ 220 $my_post['post_category'] = $value;264 $my_post['post_category'] = array($value); 221 265 } 222 266 if($key == 'post_status'){ … … 226 270 } 227 271 wp_update_post( $my_post ); 228 } 229 230 272 273 } 274 275 /* ADD COMMENT ------------------------------------------------- */ 276 function fa_add_comment($args){ 277 278 global $post; 279 global $FA_ajax; 280 281 $time = current_time('mysql'); 282 $data = array( 283 'comment_post_ID' => $post->ID, 284 //'comment_author' => 'admin', 285 //'comment_author_email' => '', 286 //'comment_author_url' => '', 287 'comment_content' => '', 288 //'comment_type' => '', 289 'comment_parent' => 0, 290 'user_id' => get_current_user_id(), 291 //'comment_author_IP' => '127.0.0.1', 292 //'comment_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 (.NET CLR 3.5.30729)', 293 'comment_date' => $time, 294 'comment_approved' => 1, 295 ); 296 297 $this_form_array = get_fields($post->ID); 298 foreach ($this_form_array as $key => $value) { 299 if($key == 'post_id'){ 300 $data['comment_post_ID'] = $value; 301 } 302 if($key == 'comment_content'){ 303 $data['comment_content'] = $value; 304 } 305 } 306 $comment = wp_insert_comment($data); 307 308 if($FA_ajax == true){ 309 if($return_msg != ''){ 310 echo $return_msg; 311 }else{ 312 /* transform result to REST API shema */ 313 $user_data = get_userdata( $data['user_id'] ); 314 $this_form_array["author"]["id"] = $data['user_id']; 315 $this_form_array["author"]["nickname"] = $user_data->user_login; 316 $this_form_array["content"] = $this_form_array["comment_content"]; 317 unset($this_form_array["comment_content"]); 318 echo json_encode($this_form_array); 319 } 320 }else{ 321 $GLOBALS['acf_validation_errors'] = urlencode($return_msg); 322 echo $return_msg; 323 } 324 325 } 326 327 /* REGISTER USER ------------------------------------------------- */ 231 328 function fa_register_user($args){ 232 329 … … 274 371 $userdata['user_login'] = $userdata['user_email']; 275 372 } 276 373 277 374 $user_id = wp_insert_user($userdata); 278 375 … … 296 393 $guardian_meta = true; 297 394 } 298 299 395 300 396 if($guardian_meta == false){ 301 update_user_meta($post_id,$key,$value); 397 update_user_meta($user_id,$key,$value); 398 399 400 302 401 } 303 402 } … … 306 405 if ( is_wp_error($user_id) ){ 307 406 308 $my_message = $user_id->get_error_message();309 310 echo '<div class="message updated">'.$my_message.'</div>';407 /* message */ 408 $GLOBALS['acf_validation_errors'] = urlencode($user_id->get_error_message()); 409 311 410 312 411 }else{ … … 314 413 if ( $user_id && !is_wp_error( $user_id ) ) { 315 414 316 $user_data = get_userdata( $user_id ); 317 $code = sha1( $user_id . $user_data->user_registered ); 318 $id_to_redirect = $args->redirect_to_id; 319 $activation_link = add_query_arg( array( 'key' => $code, 'user' => $user_id, 'redirect_id' => $id_to_redirect ), get_permalink( /* YOUR ACTIVATION PAGE ID HERE */ )); 320 321 echo $activation_link; 322 323 global $post; 324 $display_args = json_decode( urldecode ( get_post_meta($post->ID,'_meta_afd_form_render_box_alpaca', true )), true ); 325 326 327 function replace_code($string,$codes){ 328 foreach ($codes as $key => $value) { 329 $string = str_replace($key,$value,$string); 330 } 331 return $string; 332 } 333 334 if($display_args['dependence_three'] == true){ 335 $code = array( 336 '{user_login}' => $userdata['user_login'], 337 '{user_pass}' => $userdata['user_pass'], 338 '{user_email}' => $userdata['user_email'], 339 '{active_link}' => '<a href="'.$activation_link.'">'.$activation_link.'</a>', 340 '{blog_name}' => get_bloginfo( 'name' ) 341 ); 342 $mail_message = replace_code($display_args['display_messages_after_signon_v_email'],$code); 343 $mail_title = replace_code($display_args['display_messages_after_signon_mail_title'],$code); 344 $mail_content = replace_code($display_args['display_messages_after_signon_mail_content'],$code); 415 /* ACTIVATION BY EMAIL */ 416 if($args->confirm_by_email == true){ 345 417 346 }else{ 347 $mail_message = 'Mail with activation link was send to: '.$userdata['user_email']; 348 $mail_title = get_bloginfo( 'name' ).' : Confirmation email'; 349 $mail_content = 'Welcome '.$userdata['user_login'].' <br/><br/> Please confirm this email by link: <a href="'.$activation_link.'">'.$activation_link.'</a> <br><br>Best<br>'.get_bloginfo( 'name' ); 418 $user_data = get_userdata( $user_id ); 419 $code = sha1( $user_id . $user_data->user_registered ); 420 $id_to_redirect = $args->redirect_to_id; 421 $activation_link = add_query_arg( array( 'key' => $code, 'user' => $user_id, 'redirect_id' => $id_to_redirect ), get_permalink( /* YOUR ACTIVATION PAGE ID HERE */ )); 422 423 echo $activation_link; 350 424 351 } 352 353 $message = ''; 354 $message .= '<div class="message updated">'; 355 $message .= '<p>'.$mail_message.'</p>'; 356 $message .= '</div>'; 357 358 echo $message; 359 360 add_user_meta( $user_id, '_activation_key', $code, true ); 361 add_filter('wp_mail_content_type',create_function('', 'return "text/html"; ')); 362 wp_mail( $userdata['user_email'], $mail_title, '<html><body>'.$mail_content.'</body></html>' ); 363 364 // wp_mail( $userdata['user_email'], 'Potwierdzenie rejestracji w grze', '<html><body><p>Graczu,</p><p>Dziękujmy za rejestrację. Aktywuj swoje konto klikając w poniższy link:</br> ' . $activation_link . '</p><p>Graj, baw się i wygrywaj.</p><p>Pozdrawiamy<br/>Kruger Sp. z.o.o</p></body></html>' ); 365 425 global $post; 426 $display_args = json_decode( urldecode ( get_post_meta($post->ID,'_meta_afd_form_render_box_alpaca', true )), true ); 427 428 function replace_code($string,$codes){ 429 foreach ($codes as $key => $value) { 430 $string = str_replace($key,$value,$string); 431 } 432 return $string; 433 } 434 435 /* check messages settings */ 436 if($display_args['dependence_three'] == true){ 437 $code = array( 438 '{user_login}' => $userdata['user_login'], 439 '{user_pass}' => $userdata['user_pass'], 440 '{user_email}' => $userdata['user_email'], 441 '{active_link}' => '<a href="'.$activation_link.'">'.$activation_link.'</a>', 442 '{blog_name}' => get_bloginfo( 'name' ) 443 ); 444 $mail_message = replace_code($display_args['display_messages_after_signon_v_email'],$code); 445 $mail_title = replace_code($display_args['display_messages_after_signon_mail_title'],$code); 446 $mail_content = replace_code($display_args['display_messages_after_signon_mail_content'],$code); 447 448 }else{ 449 $mail_message = 'Mail with activation link was send to: '.$userdata['user_email']; 450 $mail_title = get_bloginfo( 'name' ).' : Confirmation email'; 451 $mail_content = 'Welcome '.$userdata['user_login'].' <br/><br/> Please confirm this email by link: <a href="'.$activation_link.'">'.$activation_link.'</a> <br><br>Best<br>'.get_bloginfo( 'name' ); 452 453 } 454 455 $message = ''; 456 $message .= '<div class="message updated">'; 457 $message .= '<p>'.$mail_message.'</p>'; 458 $message .= '</div>'; 459 460 echo $message; 461 462 add_user_meta( $user_id, '_activation_key', $code, true ); 463 add_filter('wp_mail_content_type',create_function('', 'return "text/html"; ')); 464 wp_mail( $userdata['user_email'], $mail_title, '<html><body>'.$mail_content.'</body></html>' ); 465 466 // wp_mail( $userdata['user_email'], 'Potwierdzenie rejestracji w grze', '<html><body><p>Graczu,</p><p>Dziękujmy za rejestrację. Aktywuj swoje konto klikając w poniższy link:</br> ' . $activation_link . '</p><p>Graj, baw się i wygrywaj.</p><p>Pozdrawiamy<br/>Kruger Sp. z.o.o</p></body></html>' ); 467 468 }else{ 469 470 $GLOBALS['acf_validation_errors'] = urlencode('User created succesfull'); 471 472 global $returnObj; 473 $returnObj['redirect_to_url'] = get_permalink($args->redirect_to_id); 474 475 } 366 476 } 367 477 } … … 369 479 370 480 function fa_update_user($args){ 371 481 482 global $FA_ajax; 483 372 484 $this_form_array = get_fields($post->ID); 373 485 foreach ($this_form_array as $key => $value) { … … 384 496 $my_user['last_name'] = $value; 385 497 } 498 386 499 387 500 } 388 501 wp_update_user( $my_user ); 502 503 504 505 foreach ($this_form_array as $key => $value) { 506 507 $guardian_meta = false; 508 509 if( 510 ($key == 'user_pass')|| 511 ($key == 'user_login')|| 512 ($key == 'user_nicename')|| 513 ($key == 'user_url')|| 514 ($key == 'user_email')|| 515 ($key == 'display_name')|| 516 ($key == 'nickname')|| 517 ($key == 'first_name')|| 518 ($key == 'lase_name')|| 519 ($key == 'description')|| 520 ($key == 'role') 521 ){ 522 $guardian_meta = true; 523 } 524 525 if($guardian_meta == false){ 526 update_user_meta($my_user['ID'],$key,$value); 527 528 529 } 530 531 if($key == 'avatar_file'){ 532 $value = json_decode(urldecode($value),true); 533 update_usermeta($my_user['ID'], 'avatar', $value['image_0']); 534 } 535 } 536 537 538 539 if($FA_ajax == true){ 540 if($return_msg != ''){ 541 echo $return_msg; 542 }else{ 543 echo json_encode($this_form_array); 544 } 545 }else{ 546 $GLOBALS['acf_validation_errors'] = urlencode($return_msg); 547 } 389 548 } 390 549 391 550 function fa_login_user($args){ 551 552 global $message; 392 553 393 554 global $post; 394 555 global $FA_ajax; 395 396 397 556 398 557 $this_form_array = get_fields($post->ID); … … 411 570 $user = wp_signon( $creds, false ); 412 571 572 413 573 if ( is_wp_error($user) ){ 414 574 $return_msg = $user->get_error_message(); … … 416 576 }else{ 417 577 418 419 578 global $returnObj; 420 579 $returnObj['redirect_to_url'] = get_permalink($args->redirect_to_id); 421 /* 580 /* 581 redirect is removed to globals 422 582 wp_redirect($args->redirect); 423 583 exit;*/ … … 431 591 } 432 592 }else{ 433 echo $return_msg; 434 } 435 436 437 438 439 440 441 } 442 593 594 595 $GLOBALS['acf_validation_errors'] = urlencode($return_msg); 596 } 597 598 } 443 599 444 600 function fa_clear_form($args){ … … 463 619 464 620 } 621 622 function fa_bd_relation($args){ 623 624 // TO MOŻNA ZROBĆ UŻYWAJĄC WIELU MET O TEJ SAMEJ NAZWIE - RELACJA OBIEKT USER W RELACJI WIELE DO WIELU !!!! 625 // DODAJEMY WIELE JEDNEJ METY RELATED USERS !!!! 626 global $FA_ajax; 627 global $wpdb; 628 $fields = get_fields($post->ID); 629 630 $msg = "gotowy do robienia relacji"; 631 632 require_once plugin_dir_path( __DIR__ ) . '/inc/Spyc.php'; 633 $db_array = Spyc::YAMLLoad( plugin_dir_path( __DIR__ ) . '/yaml/database/arguments/database-arguments.yaml'); 634 635 $table_name = $args->bd_table; 636 637 $columns = $db_array[$table_name]["object_data"]["db_table_columns"]; 638 $col_names = array(); 639 $col_types = array(); 640 641 foreach ($columns as $key => $value) { 642 $col_names[$value['db_column_name']] = $fields[$value['db_column_name']]; 643 $col_types[] = parse_type($value['db_column_type']); 644 645 } 646 647 $results = $wpdb->get_results( 648 " 649 SELECT * 650 FROM ".$wpdb->base_prefix.$table_name." 651 WHERE id_spotkanie = ".$fields['id_spotkanie']." 652 AND id_user = ".$fields['id_user']." 653 " 654 ); 655 if (empty($results)) { 656 657 $return = $wpdb->insert( 658 $wpdb->base_prefix.$table_name, 659 $col_names, 660 $col_types 661 ); 662 663 $msg = $col_names; 664 665 }else{ 666 $msg = "relation exist"; 667 // Default usage. 668 $wpdb->delete( $wpdb->base_prefix.$table_name , array( 'id_spotkanie' => $fields['id_spotkanie'], 'id_user' => $fields['id_user'] ) ); 669 $msg = $col_names; 670 } 671 672 //$msg = $return; 673 674 if($FA_ajax == true){ 675 if($return_msg != ''){ 676 echo $return_msg; 677 }else{ 678 echo json_encode($msg); 679 } 680 }else{ 681 echo $return_msg; 682 } 683 684 } 685 function parse_type($type){ 686 if( ($type == 'int(255)') || ($type == 'int(1)') ){ 687 return '%d'; 688 } 689 } -
forms-actions/trunk/yaml/database/arguments/database-arguments.yaml
r1133370 r1179925 1 1 --- 2 custom_relations: 3 object_data: 4 object_name: custom_relations 5 db_table_columns: 6 - 7 db_column_name: field1 8 db_column_type: char(255) 9 - 10 db_column_name: field2 11 db_column_type: char(255) 12 - 13 db_column_name: field3 14 db_column_type: char(255) 15 super_table_mixer: 16 object_data: 17 object_name: super_table_mixer 18 db_table_columns: 19 - 20 db_column_name: serial 21 db_column_type: char(255) 22 - 23 db_column_name: modern 24 db_column_type: char(255) 25 - 26 db_column_name: strong 27 db_column_type: char(255) 28 - 29 db_column_name: box 30 db_column_type: char(255) 31 - 32 db_column_name: gender 33 db_column_type: char(255) 2
Note: See TracChangeset
for help on using the changeset viewer.