Forum Replies Created

Viewing 15 replies - 1 through 15 (of 19 total)
  • Thread Starter sammy.salter

    (@sammysalter)

    great! Glad to help

    I’ll mark this as closed, then.

    Thread Starter sammy.salter

    (@sammysalter)

    Here’s a fix for anyone who needs it, paste the last big one into your functions.php file. The only lines I changed were:

    $data = $_POST["result"];
        $data = stripslashes_deep($data);

    to

    $data = json_decode(stripslashes_deep($_POST["result"]), true);

    and

    var events=resp.items

    to

    var events=JSON.stringify(resp.items);

    Here’s what to put into your functions.php file:

    remove_action('wp_ajax_wpgc_events_action', 'wpgc_events_action_callback');
    
    add_action('wp_ajax_wpgc_events_action', 'custom_events_action_callback');
    
    remove_action( 'admin_footer', 'my_action_javascript' );
    
    add_action( 'admin_footer', 'custom_action_javascript' );
    
    function custom_action_javascript() { ?>
    	<script type="text/javascript" >
        var CLIENT_ID=jQuery("div#settings").attr("clientID");var calendarId=jQuery("div#settings").attr("calendarId");var rooturl=jQuery("div#settings").attr("root");var priority=jQuery("div#settings").attr("priority");var SCOPES=["https://www.googleapis.com/auth/calendar"];var checkAuth=function(){gapi.auth.authorize({'client_id':CLIENT_ID,'scope':SCOPES.join(' '),'immediate':true},handleAuthResult);}
    	function handleAuthResult(authResult){var authorizeDiv=document.getElementById('authorize-div');if(authResult&&!authResult.error){loadCalendarApi();}else{}}
    	function handleAuthClick(event){gapi.auth.authorize({client_id:CLIENT_ID,scope:SCOPES,immediate:false},handleAuthResult);return false;}
    	function loadCalendarApi(){gapi.client.load('calendar','v3',listUpcomingEvents);}
    	function listUpcomingEvents(){jQuery('#res').html('<img src="'+rooturl+'/img/loading.gif" />');window.setTimeout(evlist,3000);}
    	var evlist=function(){var request=gapi.client.calendar.events.list({'calendarId':calendarId,'timeMin':(new Date()).toISOString(),'showDeleted':false,'singleEvents':true,/*'maxResults':10,*/'orderBy':'startTime'});request.execute(function(resp){var events=JSON.stringify(resp.items);console.log(events);var ajaxURL=rooturl+'includes/result.php';var data={events};var data={'action':'wpgc_events_action','result':events};jQuery.post(ajaxurl,data,function(response){jQuery('#res').html(response);});});}
    	</script> 
    <?php
    }
    
    function custom_events_action_callback() {
        global $wpdb;
        $data = json_decode(stripslashes_deep($_POST["result"]), true);
        $table_name = $wpdb->prefix . 'events';
        $wpdb->delete( $table_name, array( 'id' => "" ) );
        $tablee_name = $wpdb->prefix . "api_setting";
        $settings = $wpdb->get_row('select * from ' . $tablee_name );
        foreach ($data as $key => $value) {
            
            $s = $wpdb->get_row('select * from ' . $table_name . ' where id = "' . $value['id'] . '"');
            if(empty($s)){
                if($value['start']['dateTime']){
                    $date1 = explode('T', $value['start']['dateTime']);
                    $time1 = explode('Z', $date1[1]); 
                    $date2 = explode('T', $value['end']['dateTime']);
                    $time2 = explode('Z', $date2[1]);                
                    
                    $event = array(
                    'kind' => sanitize_text_field($value['kind']),
                    'etag' => sanitize_text_field($value['etag']),
                    'id' => sanitize_text_field($value['id']),
                    'status' => sanitize_text_field($value['status']),
                    'htmlLink' => sanitize_text_field($value['htmlLink']),
                    'created' => sanitize_text_field($value['created']),
                    'updated' => sanitize_text_field($value['updated']),
                    'summary' => sanitize_text_field($value['summary']),
                    'description' => sanitize_text_field($value['description']),
                    'location' => sanitize_text_field($value['location']),
                    'start_Date' => sanitize_text_field($date1[0]),
                    'start_Time' => sanitize_text_field($time1[0]),
                    'end_Date' => sanitize_text_field($date2[0]),
                    'end_Time' => sanitize_text_field($time2[0]),
                    'CalenderID' => sanitize_text_field($settings->calendarID)
                    );
                }else{
                    $event = array(
                    'kind' => sanitize_text_field($value['kind']),
                    'etag' => sanitize_text_field($value['etag']),
                    'id' => sanitize_text_field($value['id']),
                    'status' => sanitize_text_field($value['status']),
                    'htmlLink' => sanitize_text_field($value['htmlLink']),
                    'created' => sanitize_text_field($value['created']),
                    'updated' => sanitize_text_field($value['updated']),
                    'summary' => sanitize_text_field($value['summary']),
                    'description' => sanitize_text_field($value['description']),
                    'location' => sanitize_text_field($value['location']),
                    'start_Date' => sanitize_text_field($value['start']['date']),
                    'end_Date' => sanitize_text_field($value['end']['date']),
                    'CalenderID' => sanitize_text_field($settings->calendarID)
                    );
                }
                
                $add = $wpdb->insert($table_name,$event);
            }else{
    
                if($value['start']['dateTime']){
                    $date1 = explode('T', $value['start']['dateTime']);
                    $time1 = explode('Z', $date1[1]); 
                    $date2 = explode('T', $value['end']['dateTime']);
                    $time2 = explode('Z', $date2[1]);                
                    
                    $event = array(
                    'kind' => sanitize_text_field($value['kind']),
                    'etag' => sanitize_text_field($value['etag']),
                    'status' => sanitize_text_field($value['status']),
                    'htmlLink' => sanitize_text_field($value['htmlLink']),
                    'created' => sanitize_text_field($value['created']),
                    'updated' => sanitize_text_field($value['updated']),
                    'summary' => sanitize_text_field($value['summary']),
                    'description' => sanitize_text_field($value['description']),
                    'location' => sanitize_text_field($value['location']),
                    'start_Date' => sanitize_text_field($date1[0]),
                    'start_Time' => sanitize_text_field($time1[0]),
                    'end_Date' => sanitize_text_field($date2[0]),
                    'end_Time' => sanitize_text_field($time2[0]),
                    'CalenderID' => sanitize_text_field($settings->calendarID)
                    );
                }else{
                    $event = array(
                    'kind' => sanitize_text_field($value['kind']),
                    'etag' => sanitize_text_field($value['etag']),
                    'status' => sanitize_text_field($value['status']),
                    'htmlLink' => sanitize_text_field($value['htmlLink']),
                    'created' => sanitize_text_field($value['created']),
                    'updated' => sanitize_text_field($value['updated']),
                    'summary' => sanitize_text_field($value['summary']),
                    'description' => sanitize_text_field($value['description']),
                    'location' => sanitize_text_field($value['location']),
                    'start_Date' => sanitize_text_field($value['start']['date']),
                    'end_Date' => sanitize_text_field($value['end']['date']),
                    'CalenderID' => sanitize_text_field($settings->calendarID)
                    );
                }
    
                $edit = $wpdb->update($table_name,$event,array( 'id' => $value['id'] ));
            }
            $events = $wpdb->get_results('select * from ' . $table_name . ' where start_Date >= "'.date('Y-m-d').'" or end_Date >= "'.date('Y-m-d').'" ORDER BY start_Date ASC' );
        }?>
            <div id="loading"></div>
            <p class="wpgc-done"><?php echo strip_tags( __( 'Your events have been synchronized with your google calendar', 'wp-gcalendar' ) ); ?>!</p>
            <table class="wp-list-table widefat fixed striped posts">
                <thead>
                    <tr>
                        <th id="columnname" class="manage-column column-columnname" scope="col"><?php echo strip_tags( __( 'Title', 'wp-gcalendar' ) ); ?></th>
                        <th id="columnname" class="manage-column column-columnname" scope="col"><?php echo strip_tags( __( 'Location', 'wp-gcalendar' ) ); ?></th>
                        <th id="columnname" class="manage-column column-columnname" scope="col"><?php echo strip_tags( __( 'Start date', 'wp-gcalendar' ) ); ?></th>
                        <th id="columnname" class="manage-column column-columnname" scope="col"><?php echo strip_tags( __( 'End date', 'wp-gcalendar' ) ); ?></th>
                        <th id="columnname" class="manage-column column-columnname" scope="col"><?php echo strip_tags( __( 'Description', 'wp-gcalendar' ) ); ?></th>
                        <th id="columnname" class="manage-column column-columnname" scope="col"><?php echo strip_tags( __( 'Status', 'wp-gcalendar' ) ); ?></th>
                        <th id="columnname" class="manage-column column-columnname" scope="col"><?php echo strip_tags( __( 'Action', 'wp-gcalendar' ) ); ?></th>
                    </tr>
                </thead>
                <tbody>
                    <?php $ev = array(); 
                    $url = admin_url( 'admin.php?page=google-calendar-event');
                    $url2 = admin_url( 'admin.php?page=google-calendar-plg');
                    ?>
                    <?php foreach ($events as $event) { ?>
                    <tr>
                        <td class="column-columnname" scope="row"><?php echo esc_attr($event->summary) ?></td>
                        <td class="column-columnname"><?php echo esc_attr($event->location) ?></td>
                        <td class="column-columnname"><?php echo esc_attr($event->start_Date).' '.esc_attr($event->start_Time) ?></td>
                        <td class="column-columnname"><?php echo esc_attr($event->end_Date).' '.esc_attr($event->end_Time) ?></td>
                        <td class="column-columnname"><?php echo esc_attr(substr($event->description, 0, 45)); if(strlen($event->description) > 45) echo ' ...'; ?></td>
                        <td class="column-columnname"><?php echo esc_attr($event->status) ?></td>
                        <td class="column-columnname">
                            <?php if(empty($event->id)){ ?>
                            <a href="<?php echo $url. '&id_e='. esc_attr($event->localID) ?>"><span class="dashicons dashicons-edit"></span></a>
                            <?php } ?>
                            <a href="<?php echo $url2. '&d='. esc_attr($event->localID) ?>" onclick="return confirm('Are you sure you want to delete this event?');"><span class="dashicons dashicons-trash"></span></a>
                            
                        </td>
                    </tr>
                    <?php 
                        if($event->start_Date != '0000-00-00'){        
                        if(($event->start_Time != NULL) && ($event->end_Time != NULL)){
                            $tooltip = __( 'Title', 'wp-gcalendar-pro' ).": ".$event->summary."<br>";
                            $tooltip .= __( 'start', 'wp-gcalendar-pro' ).": ".$event->start_Date." ".__( 'at', 'wp-gcalendar-pro' )." ".$event->start_Time." <br> ";
                            $tooltip .= __( 'end', 'wp-gcalendar-pro' ).": ".$event->end_Date." ".__( 'at', 'wp-gcalendar-pro' )." ".$event->end_Time;
                            if(!empty($event->location)) $tooltip .= "<br>".__( 'Location', 'wp-gcalendar-pro' )." : ".$event->location;
                            if(!empty($event->description)) $tooltip .= "<br>".__( 'Description', 'wp-gcalendar-pro' )." : ".$event->description;
                            $ev[] = array(
                                'title' => "$event->summary",
                                'start' => $event->start_Date.'T'.$event->start_Time,
                                'end' => $event->end_Date.'T'.$event->end_Time,
                                'allDay' => false,
                                'tooltip' => $tooltip
                                ); 
                        }else{
                            $tooltip = __( 'Title', 'wp-gcalendar-pro' ).": ".$event->summary."<br>";
                            $tooltip .= __( 'start', 'wp-gcalendar-pro' ).": ".$event->start_Date." <br> ";
                            $tooltip .= __( 'end', 'wp-gcalendar-pro' ).": ".$event->end_Date;
                            if(!empty($event->location)) $tooltip .= "<br>".__( 'Location', 'wp-gcalendar-pro' )." : ".$event->location;
                            if(!empty($event->description)) $tooltip .= "<br>".__( 'Description', 'wp-gcalendar-pro' )." : ".$event->description;
                            $ev[] = array(
                                'title' => "$event->summary",
                                'start' => $event->start_Date,
                                'end' => $event->end_Date,
                                'tooltip' => $tooltip
                                ); 
                        }
                            } ?>
                        <?php } ?>  
                        <?php
                            $e = json_encode($ev, JSON_HEX_APOS);
                         ?>
                </tbody>
            </table>
            <?php if($settings->lang == NULL){$lang = 'en';}else{$lang = $settings->lang;} ?>
            <div style="display:none" defaultDate="<?php echo date('Y-m-d'); ?>" class="eventJson" data='<?php echo $e; ?>' lang="<?php echo $lang; ?>"></div>
            <script>
                jQuery(document).ready(function() {
                    var ev = eval(jQuery("div.eventJson").attr("data"));
                    var default_Date = jQuery("div.eventJson").attr("defaultDate"); 
                    var language = jQuery("div.eventJson").attr("lang");
                    jQuery('#calendar').fullCalendar({
                        lang: language,
                        header: {
                        left: 'prev,next today',
                        center: 'title',
                        right: 'month,agendaWeek,agendaDay'
                        },
                        defaultDate: default_Date,
                        selectable: false,
                        selectHelper: false,
                        select: function(start, end) {
                            var title = prompt('Event Title:');
                            var eventData;
                            if (title) {
                                eventData = {
                                    title: title,
                                    start: start,
                                    end: end
                                };
                                jQuery('#calendar').fullCalendar('renderEvent', eventData, true);
                            }
                            jQuery('#calendar').fullCalendar('unselect');
                        },
                        editable: false,
                        eventLimit: true,
                        events: ev,
                        eventRender: function(event, element) {
                            element.qtip({ 
                                content: {    
                                    text: event.tooltip 
                                },
                                position: {
                                    my: 'top center',  
                                    at: 'bottom center', 
                                    target: element 
                                }  
                            });
                        }
                    });
                });
            </script>
            <div id='calendar'></div>
    <?php
    }
    • This reply was modified 8 years, 5 months ago by sammy.salter.
    Thread Starter sammy.salter

    (@sammysalter)

    Ok, I figured it out. It’s the max_input_vars – each property of each event object counted as an “input var” as so I was easily reaching 1000.

    My solution was to JSON.stringify the events before sending them to the ajax function in functions.php and to json_decode them in ajax-callback.php – that way they are viewed as one single large variable by the server, well within the size limit 128MB, and well within the variable limit of 1000.

    Thread Starter sammy.salter

    (@sammysalter)

    I’ve been doing some digging in the code as I’ve finally got access to the codebase, and wondered if you have any insights. Your “evlist” function expression (from functions.php in admin/partials/) console.log’s out more than 250 events that you are getting from google, so I really don’t think that google is the problem. I’ve found that it’s the jquery ajax post call that seems to be limiting the data – the data going in has, as I said, around 250 events, but when I var_dump out the $_post data from ajax-callback.php (again in admin/partials/) it’s only 40 events. I’ve searched for anyone reporting a limit on a post request, but I’ve found nothing – the server’s php.ini is set to accept up to 128M post request size and max_input_vars of 1000.

    So do you have idea what’s going on? Any advice?

    Thread Starter sammy.salter

    (@sammysalter)

    thanks for replying.

    so does this mean ideally I’m looking for a different plugin that uses the api’s pagination features to get more events than the 42 currently showing? is it in your pro version?

    or is this some hard limit that is not documented?

    • This reply was modified 8 years, 6 months ago by sammy.salter.
    • This reply was modified 8 years, 6 months ago by sammy.salter. Reason: thought of more to ask
    Thread Starter sammy.salter

    (@sammysalter)

    Thread Starter sammy.salter

    (@sammysalter)

    Thanks for the speedy reply!

    Here’s a screenshot of Google’s api quotas

    screen shot of api quotas

    According to them I am nowhere near. Could you explain what you mean? Is there some other limit google isn’t telling me about?

    oh, and here’s a link to the calendar on the site itself if that helps. Using the standard google iframe is so ugly but it has what they want for the amount of events – it’s really critical for them!

    Nothing to say other than I’ve got the same error in the latest version of WP – even the betas. Did you manage to fix it?

    The only pointer I can give is that this does not happen on my local WAMP server but it is happening on 1and1.

    Thread Starter sammy.salter

    (@sammysalter)

    For the record, it was the chrome extension “unmobilize”.

    Thread Starter sammy.salter

    (@sammysalter)

    Nothing obviously wrong with the source but you gave me the idea that it might be something wrong with my browser. Going into incognito on chrome (where all my extensions were disabled) the site works perfectly, so I have some diagnosing to do to find the actual culprit but it’s definitely not woocommerce. Thanks for the prompt support!

    Thread Starter sammy.salter

    (@sammysalter)

    Seems the same to me, after turning it on. The full expanded version:

    jquery.js?ver=1.11.3:2 Uncaught Error: Syntax error, unrecognized expression:
    https://chris.localhost/wp-admin/post-new.php?post_type=product#linked_product_data
    ga.error @ jquery.js?ver=1.11.3:2
    ga.tokenize @ jquery.js?ver=1.11.3:2
    ga.select @ jquery.js?ver=1.11.3:2
    ga @ jquery.js?ver=1.11.3:2
    m.fn.extend.find @ jquery.js?ver=1.11.3:2
    m.fn.init @ jquery.js?ver=1.11.3:2
    jQuery.fn.init @ jquery-migrate.js?ver=1.2.1:225
    m @ jquery.js?ver=1.11.3:2
    (anonymous function) @ meta-boxes.js?ver=2.5.5:43
    m.event.dispatch @ jquery.js?ver=1.11.3:4r.handle @ jquery.js?ver=1.11.3:4
    Thread Starter sammy.salter

    (@sammysalter)

    I’ve tested out this one:

    if ( abs( $image_ratio - $image_ratio_compare ) < 0.002 * $image_ratio) {

    and I think it’s the best one to use. It depends how WP came up with the 0.002 number. This fix assumes it was best optimised for a square image ratio but if it’s known whatever image ratio it was optimised for just multiply the 0.002 by it.

    Thread Starter sammy.salter

    (@sammysalter)

    Another thought – it might be best to do some sort of “OR” statement to test portrait or landscape rather than increasing the value, making the test less sensitive.

    changing the line

    if ( abs( $image_ratio - $image_ratio_compare ) < 0.002 ) {

    to something like

    if ( abs( $image_ratio - $image_ratio_compare ) < 0.002 || abs( ( $image_ratio ** -1 ) - ( $image_ratio_compare ** -1 ) ) < 0.002) {

    I think that the issue really is caused by the fact that aspect ratios are not linear but the comparison is a linear approximation (one that works well for landscape images but is poor for portrait images). It might even be better to use a non-linear comparison, e.g.

    if ( abs( $image_ratio - $image_ratio_compare ) < 0.002 * $image_ratio) {

    But that would be harder to optimise. Either way a better solution is needed, as valid images are being filtered out by the function inappropriately.

    sammy.salter

    (@sammysalter)

    I can confirm the update fixed this issue for me, thank you.

    Thread Starter sammy.salter

    (@sammysalter)

    oh and if anyone else had this problem here is the filter I used

    function my_calculate_image_srcset( $sources, $size_array, $image_src, $image_meta, $attachment_id ) {
        /**
         * Let plugins pre-filter the image meta to be able to fix inconsistencies in the stored data.
         *
         * @param array  $image_meta    The image meta data as returned by 'wp_get_attachment_metadata()'.
         * @param array  $size_array    Array of width and height values in pixels (in that order).
         * @param string $image_src     The 'src' of the image.
         * @param int    $attachment_id The image attachment ID or 0 if not supplied.
         */
    
        $image_meta = apply_filters( 'wp_calculate_image_srcset_meta', $image_meta, $size_array, $image_src, $attachment_id );
    
        if ( empty( $image_meta['sizes'] ) ) {
          return false;
        }
    
        $image_sizes = $image_meta['sizes'];
    
        // Get the width and height of the image.
        $image_width = (int) $size_array[0];
        $image_height = (int) $size_array[1];
    
        // Bail early if error/no width.
        if ( $image_width < 1 ) {
            return false;
        }
    
        $image_basename = wp_basename( $image_meta['file'] );
    
        /*
         * WordPress flattens animated GIFs into one frame when generating intermediate sizes.
         * To avoid hiding animation in user content, if src is a full size GIF, a srcset attribute is not generated.
         * If src is an intermediate size GIF, the full size is excluded from srcset to keep a flattened GIF from becoming animated.
         */
        if ( ! isset( $image_sizes['thumbnail']['mime-type'] ) || 'image/gif' !== $image_sizes['thumbnail']['mime-type'] ) {
            $image_sizes['full'] = array(
                'width'  => $image_meta['width'],
                'height' => $image_meta['height'],
                'file'   => $image_basename,
            );
        } elseif ( strpos( $image_src, $image_meta['file'] ) ) {
            return false;
        }
    
        // Retrieve the uploads sub-directory from the full size image.
        $dirname = _wp_get_attachment_relative_path( $image_meta['file'] );
    
        if ( $dirname ) {
            $dirname = trailingslashit( $dirname );
        }
    
        $image_baseurl = _wp_upload_dir_baseurl();
        $image_baseurl = trailingslashit( $image_baseurl ) . $dirname;
    
        // Calculate the image aspect ratio.
        $image_ratio = $image_height / $image_width;
        /*
         * Images that have been edited in WordPress after being uploaded will
         * contain a unique hash. Look for that hash and use it later to filter
         * out images that are leftovers from previous versions.
         */
        $image_edited = preg_match( '/-e[0-9]{13}/', wp_basename( $image_src ), $image_edit_hash );
    
        /**
         * Filter the maximum image width to be included in a 'srcset' attribute.
         *
         * @since 4.4.0
         *
         * @param int   $max_width  The maximum image width to be included in the 'srcset'. Default '1600'.
         * @param array $size_array Array of width and height values in pixels (in that order).
         */
        $max_srcset_image_width = apply_filters( 'max_srcset_image_width', 1600, $size_array );
    
        // Array to hold URL candidates.
        $sources = array();
    
        /**
         * To make sure the ID matches our image src, we will check to see if any sizes in our attachment
         * meta match our $image_src. If no mathces are found we don't return a srcset to avoid serving
         * an incorrect image. See #35045.
         */
        $src_matched = false;
    
        /*
         * Loop through available images. Only use images that are resized
         * versions of the same edit.
         */
    
        foreach ( $image_sizes as $image ) {
    
            // If the file name is part of the <code>src</code>, we've confirmed a match.
            if ( ! $src_matched && false !== strpos( $image_src, $dirname . $image['file'] ) ) {
                $src_matched = true;
            }
    
            // Filter out images that are from previous edits.
            if ( $image_edited && ! strpos( $image['file'], $image_edit_hash[0] ) ) {
    
              continue;
    
            }
    
            /*
             * Filter out images that are wider than '$max_srcset_image_width' unless
             * that file is in the 'src' attribute.
             */
            if ( $max_srcset_image_width && $image['width'] > $max_srcset_image_width &&
                false === strpos( $image_src, $image['file'] ) ) {
    
              continue;
    
            }
    
            // Calculate the new image ratio.
            if ( $image['width'] ) {
                $image_ratio_compare = $image['height'] / $image['width'];
            } else {
                $image_ratio_compare = 0;
            }
    
            // If the new ratio differs by less than 0.005, use it.
            if ( abs( $image_ratio - $image_ratio_compare ) < 0.005 ) {
                // Add the URL, descriptor, and value to the sources array to be returned.
                $sources[ $image['width'] ] = array(
                    'url'        => $image_baseurl . $image['file'],
                    'descriptor' => 'w',
                    'value'      => $image['width'],
                );
    
            }
        }
    
        return $sources;
    }
    add_filter ('wp_calculate_image_srcset', 'my_calculate_image_srcset', null, 5);
Viewing 15 replies - 1 through 15 (of 19 total)