/** * Shows the course calendar. * * @since 1.0.0 */ function course_calendar($atts) { global $post; extract(shortcode_atts(array('course_id' => in_the_loop() ? get_the_ID() : false, 'month' => false, 'year' => false, 'pre' => __('« Previous', 'cp'), 'next' => __('Next »', 'cp'), 'date_indicator' => 'indicator_light_block'), $atts, 'course_calendar')); if (!empty($course_id)) { $course_id = (int) $course_id; } $month = sanitize_text_field($month); $month = 'true' == $month ? true : false; $year = sanitize_text_field($year); $year = 'true' == $year ? true : false; $pre = sanitize_text_field($pre); $next = sanitize_text_field($next); $date_indicator = sanitize_text_field($date_indicator); if (empty($course_id)) { if ($post && 'course' == $post->post_type) { $course_id = $post->ID; } else { $parent_id = do_shortcode('[get_parent_course_id]'); $course_id = 0 != $parent_id ? $parent_id : $course_id; } } $args = array(); if (!empty($month) && !empty($year)) { $args = array('course_id' => $course_id, 'month' => $month, 'year' => $year); } else { $args = array('course_id' => $course_id); } $args['date_indicator'] = $date_indicator; $cal = new Course_Calendar($args); return $cal->create_calendar($pre, $next); }
function refresh_course_calendar() { $ajax_response = array(); $ajax_status = 1; //success if (!empty($_POST['date']) && !empty($_POST['course_id'])) { $date = getdate(strtotime(str_replace('-', '/', $_POST['date']))); $pre = !empty($_POST['pre_text']) ? $_POST['pre_text'] : false; $next = !empty($_POST['next_text']) ? $_POST['next_text'] : false; $calendar = new Course_Calendar(array('course_id' => $_POST['course_id'], 'month' => $date['mon'], 'year' => $date['year'])); $html = ''; if ($pre && $next) { $html = $calendar->create_calendar($pre, $next); } else { $html = $calendar->create_calendar(); } $ajax_response['calendar'] = $html; } $response = array('what' => 'refresh_course_calendar', 'action' => 'refresh_course_calendar', 'id' => $ajax_status, 'data' => json_encode($ajax_response)); ob_end_clean(); ob_start(); $xmlResponse = new WP_Ajax_Response($response); $xmlResponse->send(); ob_end_flush(); }