/** * Outputs the content of the widget * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget. * @param array $instance The settings for the particular instance of the widget * @return string The content of the widget */ public function widget($args, $instance) { $settings = array(); foreach ($this->_supportedParams as $name) { if (!empty($instance[$name])) { $settings[$name] = apply_filters('widget_' . $name, $instance[$name]); } } $settings = WpSimpleBookingCalendar_Shortcode::validateAttributes($settings); // View setup $view = new WpSimpleBookingCalendar_View(); $model = new WpSimpleBookingCalendar_Model(); $view->setTemplate('widget/widget')->assign('widget', $this)->assign('showTitle', $settings['title'])->assign('calendar', $model->getCalendar())->assign('args', $args)->render(); }
/** * Ajax navigation (next/prev month) * @return void */ public function calendarNavigation() { $currentTimestamp = current_time('timestamp'); $currentYear = (int) gmdate('Y', $currentTimestamp); $currentMonth = (int) gmdate('m', $currentTimestamp); // Prepare variables $inputMonth = filter_input(INPUT_POST, 'month', FILTER_VALIDATE_INT, array('options' => array('default' => $currentMonth, 'min_range' => 1, 'max_range' => 12))); $inputYear = filter_input(INPUT_POST, 'year', FILTER_VALIDATE_INT, array('options' => array('default' => $currentYear, 'min_range' => $currentYear, 'max_range' => $currentYear + 15))); $operation = filter_input(INPUT_POST, 'operation', FILTER_SANITIZE_STRING); if (in_array($operation, array('nextMonth', 'prevMonth'))) { // Additional validation if ($operation == 'nextMonth' && $inputMonth == 12 && $inputYear >= $currentYear + 15) { $inputYear == $currentYear + 14; } if ($operation == 'prevMonth' && $inputMonth == 1 && $inputYear <= $currentYear) { $inputYear = $currentYear + 1; } $newTimestamp = strtotime(($operation == 'nextMonth' ? '+' : '-') . '1 month', gmmktime(1, 1, 1, $inputMonth, 1, $inputYear)); } else { $newTimestamp = gmmktime(null, null, null, $inputMonth, 1, $inputYear); } // Prepare calendar data $calendarData = filter_input(INPUT_POST, 'calendarData'); if (!empty($calendarData)) { $includeCalendarEditor = true; } else { $includeCalendarEditor = false; $model = new WpSimpleBookingCalendar_Model(); $calendar = $model->getCalendar(); $calendarData = isset($calendar['calendarJson']) ? $calendar['calendarJson'] : null; } // Disable cache header('Cache-Control: no-cache', true); header('Pragma: no-cache', true); // Render calendar $view = new WpSimpleBookingCalendar_View(); $view->setTemplate('calendar/calendar')->assign('timestamp', $newTimestamp)->assign('calendarData', json_decode($calendarData))->assign('includeCalendarEditor', $includeCalendarEditor)->render(); exit; }
/** * Action: delete calendar * @return void */ public function deleteAction() { $nonceAction = $this->_generateNonceAction('delete'); check_admin_referer($nonceAction); if (!isset($_GET['_wpnonce']) || !wp_verify_nonce($_GET['_wpnonce'], $nonceAction) || !$this->_model->getCalendar()) { $message = __('No calendar found', 'sbc'); } elseif ($this->_model->deleteCalendar()) { $message = __('Calendar Removed', 'sbc'); } else { $message = __('Unable to delete calendar', 'sbc'); } $this->_view->messageHelper($message); $this->indexAction(); }
/** * Processes the [sbc] shortcode * @param array $atts User defined attributes in shortcode tag * @param string $content * @return string Processed shortcode string */ public function processShortcode($atts, $content = '') { $values = $this->validateAttributes($atts); $model = new WpSimpleBookingCalendar_Model(); $view = new WpSimpleBookingCalendar_View(); return $view->setTemplate('shortcode/sbc')->assign('showTitle', $values['title'])->assign('calendar', $model->getCalendar())->fetch(); }