• Resolved sammy.salter

    (@sammysalter)


    Hi there,

    thanks for the plugin, very happy with it so far. Your documentation is really excellent. Our problem at the moment is that the calendar is only syncing up to around a month in advance, even though events continue well beyond that. Is this an error, or a deliberate decision with the plugin?

    Best wishes,

    Sammy

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author EuroCizia

    (@eurocizia)

    Hi Sammy,

    First thank you for using WP Google Calendar Manager. Our plugin is based on Google calendar API and we didn’t defined a limit for the imported events, so if you have a limited imported events that would be probably because you are importing much events, and it would be the API limits, even so that will not be a month limit, because we tested syncing up to around 3 months of full events (daily) in advance and we had everything sync’ed.

    Greetings,
    Eurocizia Team

    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!

    Thread Starter sammy.salter

    (@sammysalter)

    Plugin Author EuroCizia

    (@eurocizia)

    Hi sammy,

    Thank you for the reference. As you can see the “maxResults” field is controlling the maximum number of resources the server returns in the response, but in our script we are not using this field so the results are depending on the server limit that can’t be exceeded.

    Greetings,
    Eurocizia Team

    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, 5 months ago by sammy.salter.
    • This reply was modified 8 years, 5 months ago by sammy.salter. Reason: thought of more to ask
    Plugin Author EuroCizia

    (@eurocizia)

    Hi sammy,

    WP Google Calendar Manager can import more than 90 events from a single calendar, the easiest way to test it is by creating a repeated event in your calendar, and then click the sync button.

    Greetings,
    Eurocizia Team

    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)

    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)

    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.
    Plugin Author EuroCizia

    (@eurocizia)

    Hi sammysalter,

    We tested your fix and it’s working, Thanks for your help to improve the plugin and we will deploy a new version with your fix.

    Greetings,
    Eurocizia Team

    Thread Starter sammy.salter

    (@sammysalter)

    great! Glad to help

    I’ll mark this as closed, then.

    Plugin Author EuroCizia

    (@eurocizia)

    Hi sammysalter,

    Yes sure you can mark it as resolved (you solved it), also we just released a new update with the fix. Thank you

    Greetings,
    Eurocizia Team

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Calendar only syncing events up to around a month in adv’ is closed to new replies.