Plugin Directory

Changeset 2821633


Ignore:
Timestamp:
11/21/2022 04:11:15 PM (3 years ago)
Author:
pictureplanet
Message:

VC 2.11.3, reduction of API calls

Location:
verowa-connect
Files:
113 added
20 edited

Legend:

Unmodified
Added
Removed
  • verowa-connect/trunk/admin/admin_notices.php

    r2745654 r2821633  
    1212
    1313/**
    14  * If the verowa_instance or verowa_api_key is not set, it geneerate an admin notices
     14 * If the verowa_instance or verowa_api_key is not set, it generate an admin notices
    1515 */
    1616function verowa_api_member_error() {
  • verowa-connect/trunk/admin/admin_pages.php

    r2797642 r2821633  
    3535
    3636        // Option block "Events"
    37         update_option( 'verowa_keep_outdated_events_days', $_POST['verowa_keep_outdated_events_days'] ?? 0 );
     37        update_option( 'verowa_keep_outdated_events_days', intval($_POST['verowa_keep_outdated_events_days'] ?? 0) );
    3838
    3939        update_option( 'show-to-time', isset( $_POST['show-to-time'] ) ? 'on' : false);
     
    182182        echo '<b>' . _x( 'Settings for detail pages', 'Persons', 'verowa-connect' ) . '</strong></b><br />';
    183183
    184     // verowa_db_update_person_group();
    185184
    186185    echo verowa_checkbox_html(
     
    226225
    227226
    228 // sollte nicht mehr benötigt werden
    229 //function verowa_db_update_person_group() {
    230 //    global $wpdb;
    231 
    232 //    $select_groups_query = 'SELECT `post_id` FROM `' . $wpdb->prefix . 'postmeta` ' .
    233 //        'WHERE `meta_key` = "_verowa_person_assign" AND `meta_value` = "persongroup";';
    234 //    $arr_person_groups = $wpdb->get_results( $select_groups_query, ARRAY_A );
    235 
    236 //    // post ids mit gruppen 612, 604, 156, 2086, 2114, 2116, 2118, 2120, 2122, 2124, 2126
    237 //    foreach ( $arr_person_groups as $single_group ) {
    238 //        $int_group_id = get_post_meta( intval( $single_group['post_id'] ), '_verowa_person_group', true );
    239 
    240 //        update_post_meta( intval( $single_group['post_id'] ), '_person_singles',
    241 //            array( 0 => 'group-' . $int_group_id ) );
    242 
    243 //    }
    244 //}
    245 
    246 
    247 
    248227/*
    249228 * New Admin Page (Proof of concept)
     
    251230
    252231function verowa_register_admin_menu() {
     232    $user = wp_get_current_user();
     233    if ( in_array( 'administrator', (array)$user->roles ) ) {
    253234    add_menu_page( 'Verowa', 'Verowa', 'manage_options', 'verowa/main_options_menu.php',
    254235        'verowa_main_options_menu', plugins_url( 'verowa-connect/images/icon.png' ), 80 );
     
    257238        __( 'Verowa templates', 'verowa-connect' ) , 'switch_themes', 'verowa-options-templates',
    258239        'verowa_templates_configuration_page' );
     240    }
    259241}
    260242
  • verowa-connect/trunk/admin/save_post_action.php

    r2787679 r2821633  
    2727            $bool_update = false;
    2828
    29             // If an Id is not found, the update is executed.
     29            // If an id is not found, the update is executed.
    3030            if ( is_array( $arr_new_list_ids ) && count( $arr_new_list_ids ) > 0 )
    3131            {
  • verowa-connect/trunk/admin/subscriptions_admin_page.php

    r2787679 r2821633  
    1313
    1414/*
    15  *  Description: Admin-Page zum Eintragen von Projekten, URLs und Key Codes zum Monitoring
     15 *  Description: Admin page for entering projects, URLs and key codes for monitoring purposes
    1616*/
    1717
     
    3232
    3333
    34 //Anzeige in der Admin-Page
     34// Display in the admin page
    3535function render_subscriptions_options_page() {
    3636?>
     
    154154
    155155
     156/**
     157 * Set selected for dropdown-menu
     158 *
     159 * @param string $field_name
     160 * @param array $arr_options
     161 * @param string $value
     162 * @return string
     163 */
    156164function pp_set_dd_selected( $field_name, $arr_options, $value ) {
    157165    $ret = '';
     
    166174
    167175
     176/**
     177 * Set checked for checkboxes
     178 *
     179 * @param string $fild_name
     180 * @param array $arr_options
     181 * @return string
     182 */
    168183function pp_set_cb_checked( $fild_name, $arr_options ) {
    169184    $ret = '';
  • verowa-connect/trunk/admin/templates_edit.php

    r2797642 r2821633  
    212212
    213213            case 'persondetails':
    214                 verowa_persons_set_deprecated();
    215                 verowa_events_db_set_to_deprecated();
     214                verowa_general_set_deprecated_content( 'verowa_person' );
     215                verowa_general_set_deprecated_content( 'verowa_events' );
    216216                break;
    217217
     
    230230
    231231            case 'eventdetails':
    232                 verowa_events_db_set_to_deprecated();
     232                verowa_general_set_deprecated_content( 'verowa_events' );
    233233                break;
    234234        }
     
    299299                    <?php echo _x( 'add new', 'In Template Editor', 'verowa-connect' ); ?>
    300300                </a>
    301                 <div class="meta-box-sortables ui-sortable">
     301                <div class="meta-box-sortables ui-sortable verowa-template-overview">
    302302                    <form method="post">
    303303                        <?php
  • verowa-connect/trunk/events/shortcode/verowa_event_details_json.php

    r2809632 r2821633  
    3131        $arr_event_details = verowa_event_db_get_content( $atts['id'] );
    3232
    33         $subs_person_id = intval($arr_event_data['subs_person_id'] ?? 0);
     33        $subs_person_id = intval($arr_event_details['subs_person_id'] ?? 0);
    3434
    3535        // Is it a subscription, we get the current date from the API
    3636        if ( $subs_person_id > 0) {
    37             $arr_ret_api_call = verowa_api_call( 'geteventdetails', $event_id, true );
     37            $arr_ret_api_call = verowa_api_call( 'geteventdetails', $int_id, true );
    3838            $arr_event_details = $arr_ret_api_call['data'][0];
    3939            $int_request_status_code = $arr_ret_api_call['code'];
  • verowa-connect/trunk/functions/event.php

    r2809632 r2821633  
    2727    global $wpdb;
    2828
    29     if ( 0 == count($arr_event_data) ) {
     29    if ( true === is_array($arr_event_data) && count($arr_event_data) > 0 ) {
     30        $id = $arr_event_data['event_id'];
     31    } elseif ( 0 == $id ) {
    3032        $arr_event_data = verowa_event_db_get_content( $id );
    31     } elseif ( 0 == $id ) {
    32         $id = $arr_event_data['event_id'];
    3333    }
    3434
     
    4848        $arr_placeholder['EVENT_ID'] = $id;
    4949
    50         // Event title
    5150        $arr_placeholder['TITLE'] = $arr_event_data['title'];
    5251        $arr_placeholder['EVENT_TITLE'] = $arr_event_data['title']; /** @deprecated v 2.4.0 */
    5352
    54         // Topic
    5553        if ( key_exists('topic', $arr_event_data ?? array() ) && $arr_event_data['topic'] != '' ) {
    5654            $arr_placeholder['TOPIC'] = $arr_event_data['topic'];
     
    120118        }
    121119
    122         // Add short description
    123120        if ( '' != $arr_event_data['short_desc'] ) {
    124121            $arr_placeholder['SHORT_DESC'] = $arr_event_data['short_desc'];
    125122        }
    126123
    127         // Add detail description
    128124        if ( '' != $arr_event_data['long_desc'] ) {
    129125            $arr_placeholder['LONG_DESC'] = $arr_event_data['long_desc'];
     
    255251                    $arr_event_data['subs_date'] . $arr_event_data['subs_time'] . '59' > $str_datetime_now ) {
    256252
    257                     switch ($arr_event_data['subs_state'] ?? 'none')
    258                     {
     253                    switch ($arr_event_data['subs_state'] ?? 'none') {
    259254                        case 'waiting_list':
    260255                            // no fallback is required, the api set a default value
     
    320315        }
    321316
    322         $arr_placeholder['SUBS_FORM'] =
    323             do_shortcode('[verowa_subscription_form event_id=' . $id . ' show_event_info=0]');
     317        $arr_placeholder['SUBS_FORM'] = '[verowa_subscription_form event_id=' . $id . ' show_event_info=0]';
    324318        $arr_placeholder['SUBS_STATE'] = $arr_event_data['subs_state'] ?? 'none';
    325319
     
    578572    }
    579573
    580     // Location
    581574    if ( !empty( $arr_content['rooms'] ) ) {
    582575        $arr_placeholder['LOCATION'] = $arr_content['rooms'][0]['location_name'];
     
    601594    }
    602595
    603     // Anmeldebutton setzen wenn ein Formular ausgewählt wurde
     596    // Set registration button when a form has been selected
    604597    $arr_placeholder['SUPSCRIPTION_BUTTON'] = '';
    605598    $arr_placeholder['SUPS_BUTTON'] = '';
     
    653646    $arr_placeholder['SUBS_STATE'] = $arr_content['subs_state'] ?? 'none';
    654647
    655     // Detailbutton ändern wenn kein Formular ausgewählt wurde aber es trotzdem eine Anmeldezeit hat
     648    // Change detail button if no form is selected but it still has a login time
    656649    if ( 0 != $arr_content['subs_date'] && 0 != $arr_content['subs_person_id']
    657650        && $arr_content['subs_date'] . $arr_content['subs_time'] . '59' > $str_datetime_now ) {
     
    686679
    687680/**
    688  *
    689  *
    690  * @param mixed $event
     681 * Get date HTML for e.g. placeholder DATE_FROM_LONG
     682 *
     683 * @param array $event
    691684 * @return string
    692685 */
     
    746739
    747740/**
    748  *
     741 * Get event date and time
    749742 *
    750743 * @param array $event
     
    797790
    798791/**
    799  * Return a String with the event location
     792 * Return a string with the event location
     793 *
    800794 * @param array $arr_event_loc
    801795 *
     
    820814
    821815/**
    822  *
    823  *
     816 * Assembling an address block
     817 *
     818
    824819 * @param array $arr_event_loc
    825820 * @return string
     
    858853
    859854    $wpdb->query( 'START TRANSACTION' );
    860     try
    861     {
    862 
    863         $str_events_tablename = $wpdb->prefix . 'verowa_events';
    864         $arr_event_insert_formats = array( '%d', '%d', '%s', '%s', '%s', '%s', '%s', '%d', '%s', '%s', '%d' );
     855    try {
    865856        $str_content = json_encode( $arr_event, JSON_UNESCAPED_UNICODE );
    866857
    867         // Alles hashen. Mit dem Hash kann einfach geprüft werden ob etwas geändert wurde
     858        // Hash everything. With the hash it is easy to check whether something has been changed.
    868859        $str_hash = verowa_event_generate_hash( $arr_event, $arr_ids, $bool_has_subscription, $str_content );
    869860
     
    873864            $arr_event['short_desc'] : $arr_event['long_desc'];
    874865
    875         //  Create post object
    876866        $arr_post = [
    877867          'post_title'    => wp_strip_all_tags( $arr_event['title'] ),
     
    888878        if ( !is_wp_error( $int_post_id ) ) {
    889879            $wpdb->insert(
    890                 $str_events_tablename,
     880                $wpdb->prefix . 'verowa_events',
    891881                array(
    892882                    'event_id' => intval( $arr_event['event_id'] ),
     
    900890                    'content' => $str_content,
    901891                    'hash' => strval( $str_hash ),
    902                     'deprecated' => 0
     892                    'deprecated_content' => 0,
     893                    'deprecated' => 0,
    903894                ),
    904                 $arr_event_insert_formats
     895                array( '%d', '%d', '%s', '%s', '%s', '%s', '%s', '%d', '%s', '%s', '%d', '%d' )
    905896            );
    906897            $wpdb->query('COMMIT');
     
    908899            throw new Exception( $int_post_id->get_error_message() );
    909900        }
    910     }
    911     catch (Exception $exception)
    912     {
     901    } catch (Exception $exception) {
    913902        $obj_debug = new Verowa_Connect_Debugger();
    914903        $obj_debug->wirte_to_file( 'Fehler einfügen eines Events: ' . $exception->getMessage() );
    915         // Im Fehlerfall werde die Daten gelöscht
     904        // In the event of an error, the data is deleted
    916905        $wpdb->query('ROLLBACK');
    917906    }
     
    922911
    923912/**
    924  * Updatet an event in der DB
    925  *
     913 * Updates an event in the DB
     914 *
     915 * @param array $arr_event
     916 * @param bool $bool_has_subscription
     917 * @param string $str_hash
     918 * @param array $arr_ids
    926919 */
    927920function verowa_event_db_update( $arr_event, $bool_has_subscription, $str_hash, $arr_ids ) {
     
    949942
    950943        if( 0 == $current_post_id ) {
    951             //  Create post object
     944
    952945            $post = array(
    953946              'post_title'    => wp_strip_all_tags( $arr_event['title'] ),
     
    974967        }
    975968
    976         $arr_event_data_formats = array( '%d', '%s', '%s', '%s', '%s', '%s', '%d', '%s', '%s', '%d' );
    977         $arr_event_where_formats = array( '%d' );
    978 
    979969        if ( $int_post_id > 0 ) {
     970
    980971            $arr_event_data = array(
    981972                'post_id' => intval($int_post_id),
     
    988979                'content' => json_encode( $arr_event, JSON_UNESCAPED_UNICODE ),
    989980                'hash' => $str_hash,
     981                'deprecated_content' => 0,
    990982                'deprecated'    => 0,
    991983            );
     
    997989                    'event_id' => $arr_event['event_id']
    998990                ),
    999                 $arr_event_data_formats,
    1000                 $arr_event_where_formats
     991                array( '%d', '%s', '%s', '%s', '%s', '%s', '%d', '%s', '%s', '%d', '%d' ),
     992                array( '%d' )
    1001993            );
    1002994
     
    10361028            try {
    10371029                $wpdb->query( 'START TRANSACTION' );
    1038                 $ret_delete_post = wp_delete_post( $int_post_id, true );
    1039 
     1030                $ret_delete_post = verowa_delete_post( $int_post_id, 'verowa_event' );
    10401031                $ret_wp_delete = $wpdb->delete(
    10411032                    $str_events_tablename,
     
    11151106
    11161107    // Insert the post into the database
    1117     $int_post_id = verowa_general_insert_custom_post( $post, 'verowa_events', 'event_id', $arr_ret['script']);
     1108    verowa_general_insert_custom_post( $post, 'verowa_events', 'event_id', $arr_ret['script'] );
    11181109
    11191110}
     
    12961287    $arr_restrictions = array();
    12971288
     1289    // CWe,MPf: Prevent display event in the past
     1290    $obj_date_now = new DateTime();
     1291    $arr_restrictions[] = '`datetime_to` >= "' .  $obj_date_now->format( 'Y-m-d H:i:s' ) . '"';
     1292
    12981293    if ( 'now' === $obj_date ) {
    12991294        $obj_date = new DateTime();
     
    14081403
    14091404/**
    1410  *
    1411  *
     1405 * Return classes for the Weekend
     1406 *
     1407
    14121408 * @param array $event
    14131409 * @return string
  • verowa-connect/trunk/functions/general.php

    r2809632 r2821633  
    504504    if ( $wpdb->prefix . 'verowa_person' == $str_table_name ||
    505505        $wpdb->prefix . 'verowa_events' ==  $str_table_name ) {
     506        $post_type = '';
     507        if( $wpdb->prefix . 'verowa_person' == $str_table_name ) {
     508            $post_type = 'verowa_person';
     509        } else if( $wpdb->prefix . 'verowa_events' ==  $str_table_name) {
     510            $post_type = 'verowa_event';
     511        }
    506512
    507513        try {
     
    516522                foreach ( $arr_post_ids as $arr_row ) {
    517523                    // delete related Posts
    518                     verowa_delete_post( $arr_row['post_id'] );
     524                    verowa_delete_post( $arr_row['post_id'], $post_type );
    519525                }
    520526            }
     
    539545    }
    540546}
     547
     548
     549
     550
     551/**
     552 * Set content of verowa post deprecated. Force content update on request.
     553 *
     554 * @param string $str_table_name
     555 */
     556function verowa_general_set_deprecated_content( $str_table_name ) {
     557    global $wpdb;
     558    $wpdb->query(
     559        'UPDATE `' . $wpdb->prefix . $str_table_name . '` SET `deprecated_content` = 1' .
     560        ' WHERE `deprecated_content` = 0;'
     561    );
     562}
     563
     564
    541565
    542566
     
    593617        if ( !is_wp_error( $int_post_id ) ) {
    594618            // Ensures that the verowa_event is correctly linked to the post
    595             $ret_update = $wpdb->update(
     619            $wpdb->update(
    596620                $wpdb->prefix . $str_verowa_table_name,
    597621                array(
     
    622646 */
    623647function verowa_general_update_custom_post( $arr_post, $str_script = '' ) {
    624 
     648    $ret_update_post = '';
    625649    $int_post_id = $arr_post['ID'] ?? 0;
    626650    if ( $int_post_id > 0 ) {
     
    640664}
    641665
    642 /**
    643  *
    644  * @param int $post_id
    645  * @return void
    646  */
    647 function verowa_delete_post( $post_id ) {
    648     $post_id = $post_id ?? 0;
     666
     667
     668
     669/**
     670 * @param int $post_id
     671 * @param string $str_type post type
     672 *
     673 * @return bool|null|WP_Post
     674 */
     675function verowa_delete_post( $post_id, $str_type ) {
     676    global $wpdb;
     677    $ret = null;
     678
     679    $post_id = intval( $post_id ?? 0 );
    649680    if ( $post_id > 0) {
    650         wp_delete_post( $post_id, true );
    651     }
     681        $query = 'SELECT `post_type` FROM `' . $wpdb->posts . '` WHERE `ID` = ' . $post_id;
     682        $str_post_type = $wpdb->get_var( $query ) ?? '';
     683        if($str_post_type == $str_type) {
     684            $ret = wp_delete_post( $post_id, true );
     685    }
     686    }
     687    return $ret;
    652688}
    653689
     
    873909    return $arr_formfield_options;
    874910}
     911
     912
     913
     914
     915/**
     916 * The passed nodes are compiled into a tree
     917 * Each node required id, parent id and a children array
     918 *
     919 * @param array $arr_nodes
     920 * @param string $str_id id name
     921 * @param string $str_parent parent key name
     922 * @return array return the tree
     923 *
     924 */
     925function verowa_get_tree( $arr_pgroups, $str_id, $str_parent ) {
     926    $arr_tree = array();
     927
     928    $k = 0;
     929    do {
     930        foreach($arr_pgroups as $str_key => $arr_node)
     931        {
     932            // If the node does not have a parent node, it is added to the root node.
     933            if( 0 === intval( $arr_node[$str_parent] ) ) {
     934                $arr_tree[intval($arr_node[$str_id])] = $arr_node;
     935                unset($arr_pgroups[$str_key]);
     936            } else {
     937                // The parent node must be determined, in the first pass it could be that the node does not exist.
     938                $are_added = verowa_add_node_to_tree( $arr_tree, $arr_pgroups[$str_key], $str_id, $str_parent );
     939                if($are_added) {
     940                    unset($arr_pgroups[$str_key]);
     941                }
     942            }
     943        }
     944        $k++;
     945    } while( count( $arr_pgroups ) > 0 && $k <= 10 );
     946
     947    return $arr_tree;
     948}
     949
     950
     951
     952
     953/**
     954 * Add a node to its parent node
     955 *
     956 * @param array $arr_tree
     957 * @param array $arr_node
     958 * @param string $str_id
     959 * @param string $str_parent
     960 * @return bool
     961 */
     962function verowa_add_node_to_tree( &$arr_tree, $arr_node, $str_id, $str_parent ) {
     963    // If the parent node is in the first node level, it can be added directly.
     964    if( key_exists(intval($arr_node[$str_parent]), $arr_tree) ) {
     965        $arr_tree[intval($arr_node[$str_parent])]['children'][intval($arr_node[$str_id])] = $arr_node;
     966        return true;
     967    } else {
     968        // Parent node must be searched for in the tree
     969        $are_added = false;
     970        foreach($arr_tree as $ele) {
     971            $are_added = verowa_add_node_to_tree( $ele['children'], $arr_node, $str_id, $str_parent );
     972            if($are_added) {
     973                $arr_tree[intval($ele[$str_id])]['children'] = $ele['children'];
     974                break;
     975            }
     976        }
     977
     978        return $are_added;
     979    }
     980}
     981
     982
     983
     984
     985/**
     986 * Clean variables using sanitize_text_field. Arrays are cleaned recursively.
     987 * Non-scalar values are ignored.
     988 *
     989 * @param string|array $var Data to sanitize.
     990 * @return string|array
     991 */
     992function verowa_clean( $var ) {
     993    if ( is_array( $var ) ) {
     994        return array_map( 'verowa_clean', $var );
     995    } else {
     996        return is_scalar( $var ) ? sanitize_text_field( $var ) : $var;
     997    }
     998}
  • verowa-connect/trunk/functions/person.php

    r2809632 r2821633  
    102102                'hash' => $str_hash,
    103103                'web_visibility' => $str_web_visibility,
     104                'deprecated_content' => 0,
    104105                'deprecated' => 0,
    105106            ),
    106             array('%d', '%d', '%s', '%s', '%s', '%d')
     107            array( '%d', '%d', '%s', '%s', '%s', '%d', '%d' )
    107108        );
    108109
     
    140141                'hash' => $str_hash,
    141142                'deprecated' => 0,
     143                'deprecated_content' => 0,
    142144                'web_visibility' => $str_web_visibility,
    143145            ),
    144             array('%d', '%d', '%s', '%s', '%d', '%s')
     146            array( '%d', '%d', '%s', '%s', '%d', '%d', '%s' )
    145147        );
    146148    } catch (Exception $exception) {
     
    170172                'hash' => $str_hash,
    171173                'deprecated' => 0,
     174                'deprecated_content' => 0,
    172175                'web_visibility' => $str_web_visibility,
    173176            ),
     
    175178                'person_id' => $arr_person['person_id']
    176179            ),
    177             array('%d', '%s', '%s', '%d', '%s'),
     180            array( '%d', '%s', '%s', '%d', '%d', '%s' ),
    178181            array('%d')
    179182        );
     
    208211
    209212    $wpdb->insert(
    210         $str_persongroups_tablename,
     213        $wpdb->prefix . 'verowa_person_groups',
    211214        array(
    212215            'pgroup_id' => intval($arr_person_group['group_id']),
     
    216219            'deprecated' => 0,
    217220        ),
    218         $arr_pgroup_insert_formats
     221        array( '%d', '%d', '%s', '%s', '%s', '%s', '%d' )
    219222    );
    220223}
     
    233236    $bool_persons_without_detail_page = get_option('verowa_persons_without_detail_page', false) == 'on' ?
    234237        true : false;
    235 
    236     $obj_debug = new Verowa_Connect_Debugger();
    237     $obj_debug->wirte_to_file('Person Update');
    238238
    239239    $wpdb->query('START TRANSACTION');
     
    307307        $wpdb->query('COMMIT');
    308308    } catch (Exception $exception) {
    309         $obj_debug->wirte_to_file('Fehler Update persons: ' . $exception->getMessage());
     309        // $obj_debug->wirte_to_file( 'Fehler Update persons: ' . $exception->getMessage() );
    310310        // In the event of an error, the modifications are reversed
    311311        $wpdb->query('ROLLBACK');
     
    399399
    400400        if (null != $int_post_id) {
    401             verowa_delete_post($int_post_id);
     401            verowa_delete_post( $int_post_id, 'verowa_person');
    402402
    403403            $wpdb->delete(
     
    424424        try {
    425425            $int_post_id = intval($arr_single_pers_ids['post_id']);
    426             wp_delete_post($int_post_id, true);
     426            verowa_delete_post( $int_post_id, 'verowa_person' );
    427427
    428428            // remove post id from verowa person
     
    455455
    456456    foreach ($all_person as $single_post) {
    457         verowa_delete_post($single_post->ID);
     457        verowa_delete_post( $single_post->ID, 'verowa_person' );
    458458    }
    459459}
     
    517517 *
    518518 */
    519 function verowa_person_group_set_deprecated($int_group_id)
    520 {
     519function verowa_person_group_set_deprecated( $int_group_id ) {
    521520    global $wpdb;
    522521
     
    702701        if (null != $int_post_id && !is_wp_error( $int_post_id )) {
    703702
    704             $ret_update = $wpdb->update(
     703            $wpdb->update(
    705704                $str_table_name,
    706705                array(
  • verowa-connect/trunk/functions/roster.php

    r2801798 r2821633  
    7272
    7373            // Alles hashen. Mit dem Hash kann einfach geprüft werden ob etwas geändert wurde
    74             $str_hash = verowa_roster_duty_generate_hash( $roster_id, $arr_roster_duty, $str_content );
     74            $str_hash = verowa_roster_duty_generate_hash( $roster_id, $arr_roster_duty );
    7575
    7676            $obj_ret->content = $wpdb->insert(
     
    195195 * @return string md5 hash
    196196 */
    197 function verowa_roster_duty_generate_hash( $roster_id, $arr_roster_duty, $str_content ) {
     197function verowa_roster_duty_generate_hash( $roster_id, $arr_roster_duty) {
    198198    $str_content = json_encode( $arr_roster_duty['content'][0] ?? [], JSON_UNESCAPED_UNICODE );
    199199    return md5( strval( $roster_id ) . ';df=' . $arr_roster_duty['datetime_from'] .
  • verowa-connect/trunk/functions/user_data.php

    r2745654 r2821633  
    156156function verowa_set_connect_cookie($str_key) {
    157157    $str_name = 'verowa-connect-session';
    158     $expireTime = strtotime('+3 day');
     158
     159    // CWe/MPf: Das Cookie läuft am Ende der Sitzung ab, um Filterfehler zu vermeiden.
     160    $expireTime = 0;
    159161    $path = '/';
    160162    return setcookie($str_name, $str_key, $expireTime, $path, $_SERVER["SERVER_NAME"] );
  • verowa-connect/trunk/general/activate_config.php

    r2800460 r2821633  
    173173        `modified_when` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    174174        `created_when` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
     175        `deprecated_content` TINYINT NOT NULL DEFAULT 0 COMMENT "Post content is deprecated after template update",
    175176        `deprecated` TINYINT NOT NULL DEFAULT 0,
    176177        PRIMARY  KEY (event_id))
     
    186187        `modified_when` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    187188        `created_when` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
     189        `deprecated_content` TINYINT NOT NULL DEFAULT 0 COMMENT "Post content is deprecated after template update",
    188190        `deprecated` TINYINT NOT NULL DEFAULT 0,
    189191        PRIMARY  KEY (person_id)) ' . $str_charset . ';';
  • verowa-connect/trunk/general/class_verowa_formfields_rendering.php

    r2787679 r2821633  
    666666
    667667        $str_html = '<div class="multiple-choice-block' . $str_div_class . '" ' .
    668             'data-id="' . $this->str_field_id . '" >' .
     668            'data-id="' . $this->str_field_id . '"' . $str_affected .'>' .
    669669            '<input type="hidden" name="' . $this->str_field_name . '" value="" />' .
    670670            '<h4>' . $this->arr_single_formfield['label'] . '&nbsp;' .
  • verowa-connect/trunk/general/class_verowa_update_controller.php

    r2809632 r2821633  
    3838        $this->obj_debug = new Verowa_Connect_Debugger();
    3939        verowa_delete_duplicate_custom_post();
     40        set_time_limit( 300 );
    4041    }
    4142
     
    7677                $str_list_ids = is_array( $this->arr_list_ids ) ? implode( ',', $this->arr_list_ids ) : '';
    7778                $arr_ret_api_call = verowa_api_call( 'geteventslistmap',  $str_list_ids . '/0', true );
    78                 $this->arr_list_ids_for_event = $arr_ret_api_call['data'];
     79                $this->arr_list_ids_for_event = is_array ($arr_ret_api_call['data']) ? $arr_ret_api_call['data'] : [];
    7980                break;
    8081
     
    8384                $arr_ret_api_call = verowa_api_call( 'geteventslistmap', implode( ',', $this->arr_list_ids ) .
    8485                    '/0', true );
    85                 $this->arr_list_ids_for_event = $arr_ret_api_call['data'];
     86                $this->arr_list_ids_for_event = is_array ($arr_ret_api_call['data']) ? $arr_ret_api_call['data'] : [];
    8687                break;
    8788        }
     
    304305            }
    305306        }
     307
     308        // Update all event with deprecated_content
     309        $query = 'SELECT `post_id`, `content` FROM `' . $wpdb->prefix . 'verowa_events` ' .
     310            'WHERE `deprecated_content` = 1';
     311
     312        $arr_events = $wpdb->get_results( $query, ARRAY_N );
     313        foreach ( $arr_events as $single_dc_event ) {
     314            $arr_event = json_decode( $single_dc_event['content'], true );
     315            $arr_new_content = get_verowa_event_single_content( 0, $arr_event );
     316
     317            $arr_post = array(
     318                'ID' => intval( $single_dc_event['post_id'] ?? 0 ),
     319                'post_content'  => $arr_new_content['html'],
     320            );
     321
     322            verowa_general_update_custom_post( $arr_post, $arr_new_content['script'] );
     323        }
     324
     325        $wpdb->update(
     326            $wpdb->prefix . 'verowa_events',
     327            array(
     328                'deprecated_content' => 0,
     329            ),
     330            array(
     331                'deprecated_content' => 1,
     332            ),
     333            array( '%d' ),
     334            array( '%d' ),
     335        );
    306336    }
    307337
     
    371401                );
    372402
    373                 // prevent the event from being deleted
    374                 $wpdb->update(
    375                     $this->str_events_tablename,
    376                     array(
    377                         'deprecated' => 0,
    378                     ),
    379                     array(
    380                         'event_id' => $single_event['event_id'],
    381                     ),
    382                     null,
    383                     array( '%d' ),
    384                 );
     403                $query = 'UPDATE `' . $this->str_events_tablename . '` SET `deprecated` = 0 ' .
     404                    'WHERE `event_id` = ' . $single_event['event_id'] . ';';
     405                $wpdb->query($query);
    385406            }
    386407        } else {
     
    475496            $obj_person_ids_in_db = $wpdb->get_results(
    476497                'SELECT GROUP_CONCAT(person_id SEPARATOR ",") AS `person_ids`' .
    477                 ' FROM `' . $wpdb->prefix . 'verowa_person` WHERE (web_visibility IS NULL OR web_visibility = "" OR web_visibility = "FULL");' );
     498                ' FROM `' . $wpdb->prefix . 'verowa_person`;' );
    478499            $arr_person_ids_in_db = explode( ',', $obj_person_ids_in_db[0]->person_ids );
    479500
     
    486507            verowa_persons_set_deprecated();
    487508
     509            $query = 'SELECT `person_id`, `hash`, `deprecated` FROM `' . $wpdb->prefix . 'verowa_person`' .
     510                        ' WHERE `person_id` IN (' . implode( ', ', $arr_person_ids_from_verowa ) . ');';
     511            $arr_persons_hash = $wpdb->get_results( $query, OBJECT_K );
     512
    488513            foreach ( $arr_all_persons as $single_person ) {
    489514                $arr_all_person_data = array();
     
    508533                // If this person already exists we update it
    509534                if ( in_array( $arr_all_person_data['person_id'], $arr_person_ids_in_db ) ) {
    510                     $get_person_hash = 'SELECT `hash`, `deprecated` FROM `' . $wpdb->prefix . 'verowa_person`' .
    511                         ' WHERE `person_id` = ' . $arr_all_person_data['person_id'] . ';';
    512                     $arr_person_hash = $wpdb->get_results( $get_person_hash, ARRAY_A );
    513                     $is_deprecated = filter_var( $arr_person_hash[0]['deprecated'] ?? false, FILTER_VALIDATE_BOOLEAN );
    514                    
     535                    $is_deprecated = filter_var( $arr_persons_hash[$arr_all_person_data['person_id']]->deprecated ?? false, FILTER_VALIDATE_BOOLEAN );
    515536                    // deprecated entries will also be updated until the new update function is available
    516                     if ( $arr_person_hash[0]['hash'] !== $str_person_hash || true === $is_deprecated ) {
     537                    if ($arr_persons_hash[$arr_all_person_data['person_id']]->hash !== $str_person_hash
     538                        || true === $is_deprecated ) {
    517539                        verowa_person_db_update( $arr_all_person_data, 'FULL', $str_person_hash );
    518540                    } else if( false == $bool_persons_without_detail_page ) {
     
    529551                            array('%d')
    530552                        );
     553                    } else {
     554                        // prevent delte post
     555                        $wpdb->update(
     556                            $wpdb->prefix . 'verowa_person',
     557                            array(
     558                                'deprecated' => 0,
     559                            ),
     560                            array(
     561                                'person_id' => $arr_all_person_data['person_id'],
     562                            ),
     563                            array('%d'),
     564                            array('%d')
     565                        );
    531566                    }
    532567                } else {
  • verowa-connect/trunk/general/custom_post_action_filters.php

    r2809632 r2821633  
    2727add_filter('pre_get_posts', 'verowa_events_exclude_from_search' );
    2828
     29
     30add_action('wp_head', 'verowa_hook_add_metatags');
     31add_action('parse_request', 'verowa_parse_request_update_custom_post_if_deprecated');
    2932
    3033/**
     
    211214    if ( true === $show_unavailable_after_tag && strlen( $str_datetime_end ) > 0 ) {
    212215        echo '<meta name="robots" content="unavailable_after: ' . $str_datetime_end . '">' . PHP_EOL;
    213     }
    214 
    215 }
    216 
    217 add_action('wp_head', 'verowa_hook_add_metatags');
    218 
    219 
    220 
    221 
    222 
    223 add_action('parse_request', 'verowa_parse_request_update_custom_post_if_deprecated');
     216
     217}
     218
     219
     220
     221}
     222
     223
     224
    224225
    225226/**
     
    228229 * @param WP $query
    229230 */
    230 function verowa_parse_request_update_custom_post_if_deprecated($query)
    231 {
     231function verowa_parse_request_update_custom_post_if_deprecated($query) {
    232232    global $wpdb;
    233233
     
    235235        if (
    236236            key_exists('post_type', $query->query_vars ?? []) &&
    237             'verowa_event' === $query->query_vars['post_type'] ?? ''
    238         ) {
     237            'verowa_event' === $query->query_vars['post_type'] ?? '' ) {
    239238            $int_event_id = intval($query->query_vars['verowa_event'] ?? 0);
    240239            if ($int_event_id > 0) {
    241                 $str_query = 'SELECT `deprecated` FROM `' . $wpdb->prefix . 'verowa_events` ' .
     240                $str_query = 'SELECT * FROM `' . $wpdb->prefix . 'verowa_events` ' .
    242241                    'WHERE `event_id` = ' . $int_event_id;
    243                 $is_deprecated = filter_var($wpdb->get_var($str_query), FILTER_VALIDATE_BOOLEAN);
    244                 if (true === $is_deprecated) {
    245                     $obj_update = new Verowa_Update_Controller();
    246                     $obj_update->init('all');
    247                     $obj_update->update_verowa_events_in_db($int_event_id);
     242                $arr_ret = $wpdb->get_results( $str_query, ARRAY_A )[0] ?? array();
     243                $int_post_id = $arr_ret['post_id'] ?? 0;
     244                $is_deprecated = filter_var( $arr_ret['deprecated_content'] ?? false, FILTER_VALIDATE_BOOLEAN );
     245
     246                if ( true === $is_deprecated && $int_post_id > 0 ) {
     247                    $arr_event = json_decode( $arr_ret['content'], true );
     248                    $arr_new_content = get_verowa_event_single_content( 0, $arr_event );
     249
     250                    $arr_post = array(
     251                      'ID' => intval( $int_post_id ?? 0 ),
     252                      'post_title'    => wp_strip_all_tags( $arr_event['title'] ),
     253                      'post_content'  => $arr_new_content['html'],
     254                    );
     255
     256                    verowa_general_update_custom_post( $arr_post, $arr_new_content['script'] );
     257                    $wpdb->update(
     258                        $wpdb->prefix . 'verowa_events',
     259                        array(
     260                            'deprecated_content' => 0,
     261                        ),
     262                        array(
     263                            'event_id' => $int_event_id,
     264                        ),
     265                        array( '%d' ),
     266                        array( '%d' )
     267                    );
    248268                }
    249269            }
     
    253273            $int_person_id = intval($query->query_vars['verowa_person'] ?? 0);
    254274            if ($int_person_id > 0) {
    255                 $str_query = 'SELECT `deprecated` FROM `' . $wpdb->prefix . 'verowa_person` ' .
     275                $str_query = 'SELECT * FROM `' . $wpdb->prefix . 'verowa_person` ' .
    256276                    'WHERE `person_id` = ' . $int_person_id;
    257                 $is_deprecated = filter_var($wpdb->get_var($str_query), FILTER_VALIDATE_BOOLEAN);
    258                 if (true === $is_deprecated) {
    259                     $obj_update = new Verowa_Update_Controller();
    260                     $obj_update->init('all');
    261                     $obj_update->update_or_insert_single_verowa_person($int_person_id);
     277                $arr_ret = $wpdb->get_results($str_query, ARRAY_A)[0] ?? array();
     278                $int_post_id = $arr_ret['post_id'] ?? 0;
     279                $is_deprecated = filter_var( $arr_ret['deprecated_content'] ?? false, FILTER_VALIDATE_BOOLEAN );
     280                if ( true === $is_deprecated && $int_post_id > 0) {
     281                    $arr_person = json_decode( $arr_ret['content'], true );
     282                    $str_new_content = show_a_person_from_verowa_detail( $arr_person );
     283
     284                    $arr_title = [];
     285                    if('' != ($arr_person['firstname'] ?? '') ) {
     286                        $arr_title [] = $arr_person['firstname'];
    262287                }
     288
     289                    // if there is the first name AND the surname, separate with a space
     290                    if ( '' != ($arr_person['lastname'] ?? '') ) {
     291                        $arr_title [] = $arr_person['lastname'];
     292            }
     293
     294                    $str_title = implode( ' ', $arr_title );
     295
     296                    $arr_post = array(
     297                        'ID' => intval( $int_post_id ?? 0 ),
     298                        'post_title'    => $str_title,
     299                        'post_content'  => $str_new_content,
     300                    );
     301
     302                    verowa_general_update_custom_post( $arr_post, '' );
     303                    $wpdb->update(
     304                        $wpdb->prefix . 'verowa_person',
     305                        array(
     306                            'deprecated_content' => 0,
     307                        ),
     308                        array(
     309                            'person_id' => $int_person_id,
     310                        ),
     311                        array( '%d' ),
     312                        array( '%d' )
     313                    );
     314
     315                }
     316
    263317            }
    264318        }
    265319    }
    266 }
     320
     321}
  • verowa-connect/trunk/general/rest_routes.php

    r2797642 r2821633  
    287287    return array(
    288288        'version' => $plugin_data['Version'],
    289         'php_version' => phpversion(),
    290         'str_dir' => $str_dir,
    291289        'member' => get_option( 'verowa_instance', true ),
    292290        'culture' => get_locale(),
  • verowa-connect/trunk/general/update_cron.php

    r2797642 r2821633  
    2424
    2525/**
    26  * Summary of deactivate_verowa_data_hooks
     26 *
    2727 */
    2828function deactivate_verowa_data_hooks() {
     
    3535
    3636/**
    37  * Activate Config. also use this function
     37 * Activate configuration also use this function
    3838 *
    3939 * @return bool
  • verowa-connect/trunk/readme.txt

    r2809632 r2821633  
    44Requires at least: 5.0
    55Tested up to: 6.0.3
    6 Stable tag: 2.11.2
     6Stable tag: 2.11.3
    77Requires PHP: 7.3
    88License: GPLv2 or later
     
    6767
    6868== Changelog ==
     69
     70= 2.11.3 =
     71* Update post content when the template is updated
     72* Reduce API CAlls
    6973
    7074= 2.11.2 =
  • verowa-connect/trunk/subscriptions/verowa_subscription_form.php

    r2809632 r2821633  
    4747    if ( 0 != $event_id ) {
    4848        $arr_ret_api_call = verowa_api_call( 'geteventdetails', $event_id, true );
    49         $arr_event_details = $arr_ret_api_call['data'][0];
     49        $arr_event_details = $arr_ret_api_call['data'][0] ?? [];
    5050        $int_request_status_code = $arr_ret_api_call['code'];
    5151
  • verowa-connect/trunk/verowa-connect.php

    r2809632 r2821633  
    55 * Description: Include your Verowa data seamlessly into your WordPress project!
    66 * Author: Picture-Planet GmbH
    7  * Version: 2.11.2
     7 * Version: 2.11.3
    88 * Requires at least: 5.2
    99 * Requires PHP: 7.3
Note: See TracChangeset for help on using the changeset viewer.