Plugin Directory

Changeset 1179925


Ignore:
Timestamp:
06/12/2015 10:06:20 PM (10 years ago)
Author:
gdurtan
Message:

up to 1.0.3

Location:
forms-actions
Files:
2 added
4 edited
7 copied

Legend:

Unmodified
Added
Removed
  • forms-actions/trunk/Forms_actions.php

    r1133374 r1179925  
    2525require_once( plugin_dir_path( __FILE__ ) . '/inc/php_alpaca_api.php' );
    2626
     27require_once( plugin_dir_path( __FILE__ ) . '/widgets/join_widget.php' );
     28
    2729/* METABOX start ------------------------------------ */
    2830
    2931function fa_add_meta_box() {
    30    
     32
    3133    /* 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
    4136        $title_box = __( 'Forms ACTIONS (ACF extention)', 'forms_actions' );
    42     }
    43 
    44     foreach ( $screens as $screen ) {
    4537        /* only editors or administrator can display forms */
    4638        if( current_user_can('edit_others_pages') ) {           
     
    5446            );
    5547        }
    56     }
    57 }
     48       
     49}
     50
     51
    5852add_action( 'add_meta_boxes', 'fa_add_meta_box');
    59 
    6053function 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    }
    39160}
    39261
     
    445114
    446115/* 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 
     116function my_acf_save_post( $post_id ) {
     117if ( ! is_admin() ) {
     118        //global $post;
    454119
    455120        global $returnObj;
     
    460125        );
    461126
    462 
    463127        // ADD gloal prop
    464128        $get_globals = afd_form_permision();
     129
    465130        foreach ($get_globals as $key => $value) {
    466131            if(get_post_meta( $value, '_meta_fa_box_alpaca', true )!=''){
     132               
    467133                $args = json_decode(urldecode(get_post_meta( $value, '_meta_fa_box_alpaca', true )));
    468                
    469134                process_actions($args);         
    470135
    471136            }               
    472137        }
    473         $args = json_decode(urldecode(get_post_meta( $post->ID, '_meta_fa_box_alpaca', true )));
    474         process_actions($args);
     138       
     139
     140       
    475141       
    476142        if($returnObj["redirect_param"] != null){
     
    489155        }
    490156
    491 
    492157        if($returnObj["redirect_to_url"] != null){
    493158
     
    501166        }
    502167
    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}
     175add_action('acf/save_post', 'my_acf_save_post', 30);
     176
     177
     178
     179
     180
     181
    517182
    518183function process_actions($args, $post_id = '', $ajax = false){
     
    538203                    $swith = substr($key, -10);
    539204                    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
    540213                        @call_user_func_array($key,array($value));
    541                         //echo $key.'('.array($value).')<br/>';
    542                         //var_dump($key,$value);
     214                        //var_dump('action:'.$key,$value);
    543215                    }
    544216                }
    545217
    546218            }
    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                        }
    554228                    }
     229
    555230                }
    556 
    557231            }
    558232
     
    564238{   
    565239  // 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');
    567241  // 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');
    569243  // submenu from defined posttype
    570244  //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'); 
     
    576250    require_once( plugin_dir_path( __FILE__ ) . '/inc/fa_admin_gui.php' );
    577251}
     252
     253function 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  
    11<?php
    22require_once("../../../../wp-load.php");
    3 if ( current_user_can( 'manage_options' ) ) {
     3if ( current_user_can( 'manage_options' ) && $_POST['object_data'] != NULL ) {
    44    /* A user with admin privileges */
    5 
    6 
    7 
    85            require_once plugin_dir_path( __DIR__ ) . '/inc/Spyc.php';
    96            /* ----------------------------------- */
     
    2320            $db_array = array_merge( $db_old_array , $db_array );
    2421
    25            
    26 
    27 
    2822            file_put_contents( plugin_dir_path( __DIR__ ) . 'yaml/database/arguments/database-arguments.yaml' , Spyc::YAMLDump( $db_array ));
    2923
    30                         // create new table
     24            // create new table
    3125
    3226            global $wpdb;   
     
    4943
    5044                $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";
    5246                $db_create_table_string .= " )  \n";
    5347                $db_tables_array[$db_tb_name] = $db_create_table_string;
     
    5650
    5751            // 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>';
    6463            }
    65             echo '</pre>';
     64}
     65
     66/* AJAX METHODS */
     67if($_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    }
    6685
    6786}
     87
     88echo json_encode($resoults);
     89
    6890?>
  • forms-actions/trunk/inc/fa_controllers.php

    r1133370 r1179925  
    11<?php
     2/* DONT USAGE ECHO, PRINT AND VAR_DUMP HERE - all comments go to ajax responces!!!! */
     3
    24function fa_targeted_questions($args){
    35
     
    1113            $post_id = $value -> post_type;
    1214            $thisArray = get_fields($post_id);
    13             /* 
    14             echo '<pre>';
    15             var_dump($thisArray);
    16             echo '</pre>';
    17             */
    1815
    1916            /* check arrays */
     
    2825                $counter++;
    2926            }
    30 
    3127            $percent =  ( $points / $counter ) * 100;
    32 
    3328            echo '----------------------<br/>'.$points.' '.__('points');
    3429            echo '<br/>'.$percent.' %<br/>';
    35 
    3630            if( $points > $max_points ){
    3731                $max_points = $points;
     
    4034
    4135        }
    42 
    4336        echo '<h1>'.__('The WINNER is:').' '.get_the_title($winner_id).'</h1>';
    4437}
     
    114107    $message.= '</table>';
    115108
    116     /*
    117     echo '<pre>';
    118     var_dump($messages_array);
    119     echo '</pre>';
    120     */
    121 
    122109    wp_mail( $emails_array , reset($subjects_array) , $message, $headers , $attachments_array );
    123110
     
    125112
    126113function fa_create_post($args){
     114
     115    global $post;
     116    global $FA_ajax;
     117    global $ACF;
     118
     119
     120
    127121
    128122
     
    133127    $new_post['post_type'] = $args->post_type;
    134128    $new_post['post_status'] = 'publish';
     129   
     130
    135131    $this_form_array = get_fields($post->ID);
    136 
    137132
    138133    foreach ($this_form_array as $key => $value) {
     
    144139            $new_post['post_content'] = $value;
    145140        }
     141        if($key == 'post_excerpt'){
     142            $new_post['post_excerpt'] = $value;
     143        }
     144        if($key == 'post_date'){
     145            $new_post['post_date'] = $value;
     146        }
    146147        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);
    148150        }
    149151        if($key == 'post_status'){
     
    159161        $guardian_meta = false;
    160162
    161         if($key == 'post_title'){
     163/*      if($key == 'post_title'){
    162164            $guardian_meta = true;
    163165        }
     
    165167            $guardian_meta = true;
    166168        }
     169        if($key == 'post_excerpt'){
     170            $guardian_meta = true;
     171        }
     172        if($key == 'post_date'){
     173            $guardian_meta = true;
     174        }*/
    167175
    168176
    169177        if($guardian_meta == false){
    170178            update_post_meta($post_id,$key,$value);
    171             var_dump($key.'_'.$value);
    172179        }
    173180    }
     
    206213        $returnObj['redirect_param'] = $args->redirect_param;
    207214    }
     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
    208247}
    209248function fa_update_post($args){
    210249
    211250    $this_form_array = get_fields($post->ID);
     251   
     252    if($args->category != ''){
     253        $category = $args->category;
     254    }
     255
    212256    foreach ($this_form_array as $key => $value) {
    213257        if($key == 'post_title'){
     
    218262        }
    219263        if($key == $category){
    220             $my_post['post_category'] = $value;
     264            $my_post['post_category'] = array($value);
    221265        }
    222266        if($key == 'post_status'){
     
    226270    }
    227271    wp_update_post( $my_post );
    228 }
    229 
    230 
     272   
     273}
     274
     275/* ADD COMMENT ------------------------------------------------- */
     276function 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 ------------------------------------------------- */
    231328function fa_register_user($args){
    232329
     
    274371        $userdata['user_login'] = $userdata['user_email'];
    275372    }
    276 
     373   
    277374    $user_id = wp_insert_user($userdata);
    278375
     
    296393            $guardian_meta = true;
    297394        }
    298    
    299395
    300396        if($guardian_meta == false){
    301             update_user_meta($post_id,$key,$value);
     397            update_user_meta($user_id,$key,$value);
     398
     399           
     400           
    302401        }
    303402    }
     
    306405    if ( is_wp_error($user_id) ){
    307406
    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       
    311410
    312411    }else{
     
    314413        if ( $user_id && !is_wp_error( $user_id ) ) {
    315414
    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){
    345417               
    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;
    350424               
    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            }
    366476        }
    367477    }
     
    369479
    370480function fa_update_user($args){
    371 
     481   
     482    global $FA_ajax;
     483   
    372484    $this_form_array = get_fields($post->ID);
    373485    foreach ($this_form_array as $key => $value) {
     
    384496            $my_user['last_name'] = $value;
    385497        }
     498       
    386499
    387500    }
    388501    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    }
    389548}
    390549
    391550function fa_login_user($args){
     551
     552    global $message;
    392553
    393554    global $post;
    394555    global $FA_ajax;
    395 
    396 
    397556
    398557    $this_form_array = get_fields($post->ID);
     
    411570    $user = wp_signon( $creds, false );
    412571
     572
    413573    if ( is_wp_error($user) ){
    414574        $return_msg =  $user->get_error_message();
     
    416576    }else{
    417577
    418 
    419578        global $returnObj;
    420579        $returnObj['redirect_to_url'] = get_permalink($args->redirect_to_id);
    421         /*
     580        /*     
     581        redirect is removed to globals
    422582        wp_redirect($args->redirect);
    423583        exit;*/
     
    431591        }
    432592    }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}
    443599
    444600function fa_clear_form($args){
     
    463619
    464620}
     621
     622function 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}
     685function 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  
    11---
    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.