Forum Replies Created

Viewing 15 replies - 16 through 30 (of 66 total)
  • Thread Starter conorseed

    (@conorseed)

    Brilliant idea.

    I assume that the $params would be the shortcode $atts? I don’t need to include any other parameters in there?

    Thread Starter conorseed

    (@conorseed)

    Sure thing ?? This is the quick and dirty version of it at the moment:

    /* API CALL */
    function cd_acuity_getCoursesv2( $course = '', $id = FALSE ){
    
        // Vars
        $userID = 'XXXXXXX';
        $key = 'XXXXXXXX';
        $date = new DateTime(); $fdate = new DateTime();
        $fdate = ($course !== 'DDC') ? $fdate->modify('+4 month') : $fdate->modify('+6 month');
    
        // URL
        if( $id ){
            $url = 'https://acuityscheduling.com/api/v1/availability/classes?appointmentTypeID='.$id;
        } else{
            $url = 'https://acuityscheduling.com/api/v1/availability/classes?minDate='.$date->format('Y-m-d').'&maxDate='.$fdate->format('Y-m-d'); //includeUnavailable=true&
        }
    
        // Initiate curl:
        // GET request, so no need to worry about setting post vars:
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
    
        // Grab response as string:
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
        // HTTP auth:
        curl_setopt($ch, CURLOPT_USERPWD, "$userID:$key");
    
        // Execute request:
        $result = curl_exec($ch); 
    
        // Don't forget to close the connection!
        curl_close($ch);
    
        // Catch Error or Return JSON
        return json_decode($result, true);
    }
    
    /* SHORTCODE */
    function cd_acuityShortcodev2($atts){
    
        // Set Atts
        $atts = shortcode_atts(
            array(
                'course' => '',
            ),
            $atts
        );
        
        $current_time = current_time('timestamp');
    
        // Get Saved Option
        $resultArr = json_decode( get_option('2ds_courses'), true );
    
        // If Saved json older than 1 hour, get updated courses
        if( $current_time - $resultArr['updated'] > 3599 ){
            // Vars
            $resultArr = array( 
                'data'      => [],
                'updated'   => ''
            );
            $ddcArr = [];
    
            // Get RF Courses
            $rfcourses = cd_acuity_getCoursesv2();
    
            // Error Check
            if (isset($rfcourses['error'])){
                return 'Uh oh. Something Went Wrong.';
            }
    
            // Output RF Courses
            foreach ($rfcourses as $rf){
    
                // Filter out DDC
                if ( strpos( $rf['name'], 'DDC' ) === FALSE ){
    
                    // Get Vars
                    $rfcourse = [];
                    $rfcourse['name'] = $rf['name'];
                    $rfcourse['date'] = cd_acuityGetDate($rf['time']);
                    $rfcourse['id'] = $rf['appointmentTypeID'];
                    $rfcourse['slots'] = $rf['slotsAvailable']; 
    
                    // Push to final array
                    array_push($resultArr['data'], $rfcourse);
                }
            }
    
            // Get DDC Courses
            $ddccourses = cd_acuity_getCoursesv2('DDC');
    
            // Error Check
            if (isset($ddccourses['error'])){
                return 'Uh oh. Something Went Wrong.';
            }
    
            // Output DDC Courses
            foreach ($ddccourses as $ddc){
                if ( strpos( $ddc['name'], 'DDC' ) !== FALSE ){
    
                    // Get Vars
                    $ddccourse = [];
                    $ddccourse['name'] = $ddc['name'];
                    $ddccourse['id'] = $ddc['appointmentTypeID'];
                    $ddccourse['slots'] = $ddc['slotsAvailable']; 
    
                    // Test
                    foreach ($ddcArr as $test){
                        if ($test === $ddccourse['id']){ continue 2;}
                    }
    
                    // Get Dates
                    $ddcdates = cd_acuity_getCoursesv2('', $ddccourse['id']);
                    $ddccourse['date'] = cd_acuityGetDate($ddcdates[0]['time']);
                    $ddccourse['date2'] = cd_acuityGetDate($ddcdates[1]['time']);
                    $ddccourse['date3'] = cd_acuityGetDate($ddcdates[2]['time']);
                    $ddccourse['date4'] = cd_acuityGetDate($ddcdates[3]['time']);
    
                    // Push to final array
                    array_push($resultArr['data'], $ddccourse);
    
                    // Push ID to ddcArr for testing
                    array_push($ddcArr, $ddccourse['id']);
                }
            }
    
            // Sort Final Array
            usort($resultArr['data'], function($a, $b){
                $t1 = strtotime($a['date']);
                $t2 = strtotime($b['date']);
                return $t1 - $t2;
            });
    
            // Add DateTime to Array
            $resultArr['updated'] = $current_time;
        } 
    
        // Change Final Array to JSON
        $json = json_encode($resultArr);
    
        // Update JSON in Database
        if( $current_time - $resultArr['updated'] > 3599 ){
            update_option( '2ds_courses', $json );
            error_log('UPDATED');
        }
        
    
        // Output
        $result = '<div class="acuity-courses-wrapper owl-carousel owl-theme"></div>';
        $result.= '<script type="text/javascript">var acuityCoursesArr = ' . $json . ';';
        $result.= 'var acuityCoursesFilter = "'.$atts['course'].'";';
        $result.= <<<EOT
        jQuery(function(a){acuityCoursesArr.data.length>0?(a.each(acuityCoursesArr.data,function(e,s){var t=s.name,p=~t.indexOf("DDC")?s.date+", "+s.date2+", "+s.date3+", "+s.date4:s.date,r=s.id,n=s.slots;acuityCoursesFilter?~t.indexOf(acuityCoursesFilter)&&a(".acuity-courses-wrapper").append('<div class="course" type="'+t+'"><span class="acuity-name">'+t+'</span><span class="acuity-date">'+p+'</span><a target="_blank" href="https://2drivesafe.as.me/?appointmentType='+r+'">Book Now<span>'+n+" Spots Left</span></a></div>"):a(".acuity-courses-wrapper").append('<div class="course" type="'+t+'"><span class="acuity-name">'+t+'</span><span class="acuity-date">'+p+'</span><a target="_blank" href="https://2drivesafe.as.me/?appointmentType='+r+'">Book Now<span>'+n+" Seats Left</span></a></div>")}),a(".acuity-courses-wrapper").owlCarousel({loop:!0,margin:10,nav:!0,navText:["< Prev","Next >"],responsive:{0:{items:1},600:{items:2},1e3:{items:3}}})):(a(".acuity-courses-wrapper").append("No courses found."),a(".acuity-courses-wrapper").owlCarousel())});
    EOT;
    
        $result.= '</script>';
    
        return $result;
    }
    add_shortcode('acuitycourses', 'cd_acuityShortcodev2');
    
    function cd_acuityGetDate($time){
        $date = new DateTime($time);
        return $date->format('D j M, g:ia');
    }
    Thread Starter conorseed

    (@conorseed)

    @craig-at-smash-balloon gaaaahhhh… I totally missed that this site had two cache plugins installed.

    Thanks for the reminder ?? All fixed now!!

    Thread Starter conorseed

    (@conorseed)

    The link was exactly what I was after. Thank you!

    Thread Starter conorseed

    (@conorseed)

    Thanks @amans2k.

    Will raise a support ticket with you ??

    Thread Starter conorseed

    (@conorseed)

    Will I need to contact my host to get that?

    Looking around some more, it seems that on some pages the request runs perfectly, but on others it gives the 403 error. Very strange!!

    Thread Starter conorseed

    (@conorseed)

    @hailite see edited reply above ??

    Thread Starter conorseed

    (@conorseed)

    Where would I find that on the server @hailite? ??

    EDIT: Sorry that was a dumb question. Here’s the log for that specific request:

    12/15/17 13:56:07.824 [101.98.234.26:49359 1 uJu] GET HTTP/1.1 /wp-admin/admin-ajax.php
    12/15/17 13:56:07.824 [101.98.234.26:49359 1 uJu] Query String: action=ptmcc&security=d47a335eed
    12/15/17 13:56:07.824 [101.98.234.26:49359 1 uJu] User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36
    12/15/17 13:56:07.824 [101.98.234.26:49359 1 uJu] Accept Encoding: gzip, deflate, br
    12/15/17 13:56:07.824 [101.98.234.26:49359 1 uJu] X-LSCACHE: true
    12/15/17 13:56:07.882 [101.98.234.26:49359 1 uJu] Media init
    12/15/17 13:56:07.882 [101.98.234.26:49359 1 uJu] CDN init
    12/15/17 13:56:07.883 [101.98.234.26:49359 1 uJu] Task init
    12/15/17 13:56:07.883 [101.98.234.26:49359 1 uJu] LSCWP_CTRL bypassed empty
    12/15/17 13:56:07.928 [101.98.234.26:49359 1 uJu] CHK html bypass: miss footer const
    12/15/17 13:56:07.928 [101.98.234.26:49359 1 uJu] not cacheable before ctrl finalize
    12/15/17 13:56:07.928 [101.98.234.26:49359 1 uJu] Router: get_uid: 0 \ LSC_Router::get_uid()@40 \ LSC_Vary->_finalize_default_vary()@294 \ LSC_Vary->_update_default_vary()@264 \ LSC_Vary->_finalize()@467
    12/15/17 13:56:07.928 [101.98.234.26:49359 1 uJu] Router: get_role: 
    12/15/17 13:56:07.928 [101.98.234.26:49359 1 uJu] Router: role: guest
    12/15/17 13:56:07.928 [101.98.234.26:49359 1 uJu] Vary: role id: failed, guest
    12/15/17 13:56:07.928 [101.98.234.26:49359 1 uJu] Vary: finalize bypassed due to no vary 
    12/15/17 13:56:07.928 [101.98.234.26:49359 1 uJu] X-LiteSpeed-Cache-Control: no-cache
    12/15/17 13:56:07.928 [101.98.234.26:49359 1 uJu] CHK html bypass: miss footer const
    12/15/17 13:56:07.928 [101.98.234.26:49359 1 uJu] Media bypass: Not frontend HTML type
    12/15/17 13:56:07.928 [101.98.234.26:49359 1 uJu] GUI bypassed by no counter
    12/15/17 13:56:07.928 [101.98.234.26:49359 1 uJu] Optimizer bypass: Not frontend HTML type
    12/15/17 13:56:07.928 [101.98.234.26:49359 1 uJu] CDN bypass
    12/15/17 13:56:07.928 [101.98.234.26:49359 1 uJu] End response
    --------------------------------------------------------------------------------
    • This reply was modified 6 years, 11 months ago by conorseed. Reason: Additional info
    Thread Starter conorseed

    (@conorseed)

    @hailite Awesome – my report number is: ADBDIYYD

    There’s no php errors that I can find. I setup wp-config.php to enable debugging and logging, and no errors.

    Thread Starter conorseed

    (@conorseed)

    @tishu & @hailite thanks for the replies.

    I’ve tried excluding “admin-ajax.php?action=” in the Do Not Cache URIs, to no effect.

    I’m unsure what a ‘report number’ is?

    And the 403 request is from a custom ajax call I wrote. It works perfectly when Litespeed Cache plugin is disabled, but gives a 403 error when called with Litespeed enabled.

    Thanks for your time ??

    Thread Starter conorseed

    (@conorseed)

    Legend thank you! I can’t believe I completely missed that.

    Thanks again for your time.

    @sajitkk Just came across the same error. Would love to know what your solution was ??

    Thread Starter conorseed

    (@conorseed)

    @findingitontheway absolute legend. T H A N K Y O U!!!

    FYI, I contacted @gfdiva outside of this forum and it looks like it’s an email setup & GoDaddy issue, and not like what the OP posted.

    I am working with @gfdiva to resolve it though ??

    Thread Starter conorseed

    (@conorseed)

    Hey @dcooney,

    No worries ??

    And potentially. The work around was to just give the user the role “admin”. Surely if max file size was the issue then it also wouldn’t work for Admins?

Viewing 15 replies - 16 through 30 (of 66 total)