/** * 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: edit calendar * @return void */ public function editAction() { $nonceAction = $this->_generateNonceAction('edit'); check_admin_referer($nonceAction); if (!empty($_POST['_wpnonce'])) { $formData = $this->_processFormData(); if (wp_verify_nonce($_POST['_wpnonce'], $nonceAction) && $this->_model->updateCalendar($formData)) { $this->_view->messageHelper(__('Calendar Updated', 'sbc')); $this->indexAction(); return; } else { $this->_view->messageHelper(__('Failed to update calendar', 'sbc')); } } else { $formData = $this->_model->getCalendar(); if (!$formData) { $this->_view->messageHelper(__('No calendar found', 'sbc')); $this->indexAction(); return; } } $this->_view->setTemplate('controller/edit')->assign('controllerUrl', $this->getControllerUrl())->assign('calendarName', $formData['calendarName'])->assign('calendarData', json_decode($formData['calendarJson']))->assign('actionName', __('Edit Calendar', 'sbc'))->assign('nonceAction', $nonceAction)->render(); }
/** * 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(); }