/**
  * Initiate default filters for arguments parser
  */
 public function __construct(array $argv = null, $default_action = null)
 {
     parent::__construct($argv);
     $action_list = array('posterboard', 'month', 'oneday', 'week', 'agenda');
     foreach ($action_list as $action) {
         $action_list[] = 'ai1ec_' . $action;
     }
     if (!in_array($default_action, $action_list)) {
         $default_action = current($action_list);
     }
     $this->add_rule('action', false, 'string', $default_action, $action_list);
     $this->add_rule('page_offset', false, 'int', 0, false);
     $this->add_rule('month_offset', false, 'int', 0, false);
     $this->add_rule('oneday_offset', false, 'int', 0, false);
     $this->add_rule('week_offset', false, 'int', 0, false);
     $this->add_rule('time_limit', false, 'int', 0, false);
     $this->add_rule('cat_ids', false, 'int', null, ',');
     $this->add_rule('tag_ids', false, 'int', null, ',');
     $this->add_rule('post_ids', false, 'int', null, ',');
     $this->add_rule('term_ids', false, 'int', null, ',');
     $this->add_rule('exact_date', false, 'string', null, false);
     // This is the type of the request: Standard, json or jsonp
     $this->add_rule('request_type', false, 'string', 'standard', false);
     // This is the format of the request. For now it's html but if we implement templates it could be json
     $this->add_rule('request_format', false, 'string', 'html', false);
     // The callback function for jsonp calls
     $this->add_rule('callback', false, 'string', false, false);
     // Whether to include navigation controls
     $this->add_rule('no_navigation', false, 'string', false, false);
     $this->add_rule('applying_filters', false, 'string', false, false);
     $this->add_rule('shortcode', false, 'string', false, false);
 }
示例#2
0
 /**
  * Initiate default filters for arguments parser
  */
 public function __construct(Ai1ec_Registry_Object $registry, array $argv = null, $default_action = null)
 {
     parent::__construct($registry, $argv);
     $settings_view = $this->_registry->get('model.settings-view');
     $action_list = array_keys($settings_view->get_all());
     foreach ($action_list as $action) {
         $action_list[] = 'ai1ec_' . $action;
     }
     if (null === $default_action) {
         $default_action = $settings_view->get_default();
     }
     $this->add_rule('action', false, 'string', $default_action, $action_list);
     $this->add_rule('page_offset', false, 'int', 0, false);
     $this->add_rule('month_offset', false, 'int', 0, false);
     $this->add_rule('oneday_offset', false, 'int', 0, false);
     $this->add_rule('week_offset', false, 'int', 0, false);
     $this->add_rule('time_limit', false, 'int', 0, false);
     $this->add_rule('cat_ids', false, 'int', null, ',');
     $this->add_rule('tag_ids', false, 'int', null, ',');
     $this->add_rule('post_ids', false, 'int', null, ',');
     $this->add_rule('auth_ids', false, 'int', null, ',');
     $this->add_rule('term_ids', false, 'int', null, ',');
     $this->add_rule('exact_date', false, 'string', null, false);
     // This is the type of the request: Standard, json or jsonp
     $this->add_rule('request_type', false, 'string', 'html', false);
     // This is the format of the request. For now it's html but if we implement templates it could be json
     $this->add_rule('request_format', false, 'string', 'html', false);
     // The callback function for jsonp calls
     $this->add_rule('callback', false, 'string', null, false);
     // Whether to include navigation controls
     $this->add_rule('no_navigation', false, 'string', false, false);
     $this->add_rule('applying_filters', false, 'string', false, false);
     $this->add_rule('shortcode', false, 'string', false, false);
 }
 /**
  * route_request function
  *
  * Determines if the page viewed should be handled by this plugin, and if so
  * schedule new content to be displayed.
  *
  * @return void
  **/
 function route_request()
 {
     global $ai1ec_settings, $ai1ec_calendar_controller, $ai1ec_events_controller, $ai1ec_events_helper, $ai1ec_view_helper;
     // This is needed to load the correct javascript
     $is_calendar_page = false;
     $this->process_request();
     $type = $this->request->get('request_type');
     // Find out if the calendar page ID is defined, and we're on it
     if ($curr_page = $this->is_calendar_page()) {
         // Proceed only if the page password is correctly entered OR
         // the page doesn't require a password
         if (!post_password_required($curr_page)) {
             // Save rendered page content to local variable.
             $this->page_content = $ai1ec_calendar_controller->get_calendar_page($this->request);
             if ($type === 'json') {
                 $ai1ec_view_helper->json_response($this->page_content);
             } elseif ($type === 'jsonp') {
                 $ai1ec_view_helper->jsonp_response($this->page_content, $this->request->get('callback'));
             } else {
                 // Replace page content - make sure it happens at (almost) the very end of
                 // page content filters (some themes are overly ambitious here)
                 add_filter('the_content', array(&$this, 'append_content'), PHP_INT_MAX - 1);
                 // Tell the javascript loader to load the js for the calendar
                 $is_calendar_page = true;
             }
         }
     } elseif (get_post_type() === AI1EC_POST_TYPE) {
         if ($type === 'json') {
             $ai1ec_view_helper->json_response($this->page_content);
         } elseif ($type === 'jsonp') {
             $data = array('html' => $ai1ec_events_controller->event_content_jsonp($this->request));
             $ai1ec_view_helper->jsonp_response($data, $this->request->get('callback'));
         } else {
             // Filter event post content, in single- and multi-post views
             add_filter('the_content', array($ai1ec_events_controller, 'event_content'), PHP_INT_MAX - 1);
         }
     }
     do_action('ai1ec_load_frontend_js', $is_calendar_page);
 }
示例#4
0
 /**
  * Get the parameters for the view from the request object
  *
  * @param Ai1ec_Abstract_Query $request
  *
  * @return array
  */
 protected function get_view_args_for_view(Ai1ec_Abstract_Query $request)
 {
     $settings = $this->_registry->get('model.settings');
     // Define arguments for specific calendar sub-view (month, agenda, etc.)
     // Preprocess action.
     // Allow action w/ or w/o ai1ec_ prefix. Remove ai1ec_ if provided.
     $action = $request->get('action');
     if (0 === strncmp($action, 'ai1ec_', 6)) {
         $action = substr($action, 6);
     }
     $view_args = $request->get_dict(apply_filters('ai1ec_view_args_for_view', array('post_ids', 'auth_ids', 'cat_ids', 'tag_ids', 'events_limit')));
     $add_defaults = array('cat_ids' => 'categories', 'tag_ids' => 'tags');
     foreach ($add_defaults as $query => $default) {
         if (empty($view_args[$query])) {
             $setting = $settings->get('default_tags_categories');
             if (isset($setting[$default])) {
                 $view_args[$query] = $setting[$default];
             }
         }
     }
     $type = $request->get('request_type');
     $view_args['data_type'] = $this->return_data_type_for_request_type($type);
     $view_args['request_format'] = $request->get('request_format');
     $exact_date = $this->get_exact_date($request);
     $view_args['no_navigation'] = $request->get('no_navigation') === 'true';
     // Find out which view of the calendar page was requested, and render it
     // accordingly.
     $view_args['action'] = $action;
     $view_args['request'] = $request;
     $view_args = apply_filters('ai1ec_view_args_array', $view_args);
     if (null === $exact_date) {
         $href = $this->_registry->get('html.element.href', $view_args)->generate_href();
         return Ai1ec_Http_Response_Helper::redirect($href, 307);
     }
     return $view_args;
 }
 /**
  * Get the exact date from request if available, or else from settings.
  *
  * @param Ai1ec_Abstract_Query $request
  * @return boolean|int
  */
 private function get_exact_date(Ai1ec_Abstract_Query $request)
 {
     global $ai1ec_settings;
     // Preprocess exact_date.
     // Check to see if a date has been specified.
     $exact_date = $request->get('exact_date');
     // Let's check if we have a date
     if (false !== $exact_date) {
         // If it's not a timestamp
         if (!Ai1ec_Validation_Utility::is_valid_time_stamp($exact_date)) {
             // Try to parse it
             $exact_date = $this->return_gmtime_from_exact_date($exact_date);
         }
     }
     // Last try, let's see if an exact date is set in settings.
     if (false === $exact_date && $ai1ec_settings->exact_date !== '') {
         $exact_date = $this->return_gmtime_from_exact_date($ai1ec_settings->exact_date);
     }
     return $exact_date;
 }