コード例 #1
0
ファイル: redirect.php プロジェクト: sedici/wpmu-istec
 /**
  * Checks if current request is direct for Events cats/tags and redirects
  * to filtered calendar.
  *
  * @param WP $wpobj WP object.
  *
  * @return void Method does not return.
  */
 public function handle_categories_and_tags(WP $wpobj)
 {
     $cats = Ai1ec_Event_Taxonomy::CATEGORIES;
     $tags = Ai1ec_Event_Taxonomy::TAGS;
     if (!isset($wpobj->query_vars) || !isset($wpobj->query_vars[$cats]) && !isset($wpobj->query_vars[$tags])) {
         return;
     }
     $is_cat = isset($wpobj->query_vars[$cats]);
     $is_tag = isset($wpobj->query_vars[$tags]);
     if ($is_cat) {
         $query_ident = $cats;
         $url_ident = 'cat_ids';
     }
     if ($is_tag) {
         $query_ident = $tags;
         $url_ident = 'tag_ids';
     }
     $term = get_term_by('slug', $wpobj->query_vars[$query_ident], $query_ident);
     if (!$term) {
         return;
     }
     $href = $this->_registry->get('html.element.href', array($url_ident => $term->term_id));
     return Ai1ec_Http_Response_Helper::redirect($href->generate_href(), 301);
 }
コード例 #2
0
ファイル: helper.php プロジェクト: pivotlearning/wpsite
 /**
  * Install robotx.txt into current Wordpress instance
  *
  * @return void
  */
 public function install()
 {
     $option = $this->_registry->get('model.option');
     $settings = $this->_registry->get('model.settings');
     $robots = $option->get('ai1ec_robots_txt');
     if (isset($robots['page_id']) && $robots['page_id'] == $settings->get('calendar_page_id')) {
         return;
     }
     $ftp_base_dir = defined('FTP_BASE') ? FTP_BASE . DIRECTORY_SEPARATOR : '';
     // we can't use ABSPATH for ftp, if ftp user is not chrooted they need
     // to define FTP_BASE in wp-config.php
     $robots_file = $ftp_base_dir . 'robots.txt';
     $robots_txt = array();
     $is_installed = false;
     $current_rules = null;
     $custom_rules = $this->rules('', false);
     $url = wp_nonce_url('edit.php?post_type=ai1ec_event&page=all-in-one-event-calendar-settings', 'ai1ec-nonce');
     $redirect_url = ai1ec_admin_url('edit.php?post_type=ai1ec_event&page=all-in-one-event-calendar-settings&noredirect=1');
     if (!function_exists('request_filesystem_credentials')) {
         return;
     }
     $type = get_filesystem_method();
     if ('direct' === $type) {
         // we have to use ABSPATH for direct
         $robots_file = ABSPATH . 'robots.txt';
     }
     $creds = request_filesystem_credentials($url, $type, false, false, null);
     if (!WP_Filesystem($creds)) {
         $error_v = isset($_POST['hostname']) || isset($_POST['username']) || isset($_POST['password']) || isset($_POST['connection_type']);
         if ($error_v) {
             // if credentials are given and we don't have access to
             // wp filesystem show notice to user
             // we could use request_filesystem_credentials with true error
             // parameter but in this case second ftp credentials screen
             // would appear
             $notification = $this->_registry->get('notification.admin');
             $err_msg = Ai1ec_I18n::__('<strong>ERROR:</strong> There was an error connecting to the server, Please verify the settings are correct.');
             $notification->store($err_msg, 'error', 1);
             // we need to avoid infinity loop if FS_METHOD direct
             // and robots.txt is not writable
             if (!isset($_REQUEST['noredirect'])) {
                 Ai1ec_Http_Response_Helper::redirect($redirect_url);
             }
         }
         return;
     }
     global $wp_filesystem;
     // sometimes $wp_filesystem could be null
     if (null === $wp_filesystem) {
         return;
     }
     $redirect = false;
     if ($wp_filesystem->exists($robots_file) && $wp_filesystem->is_readable($robots_file) && $wp_filesystem->is_writable($robots_file)) {
         // Get current robots txt content
         $current_rules = $wp_filesystem->get_contents($robots_file);
         // Update robots.txt
         $custom_rules = $this->rules($current_rules, false);
     }
     $robots_txt['is_installed'] = $wp_filesystem->put_contents($robots_file, $custom_rules, FS_CHMOD_FILE);
     if (false === $robots_txt['is_installed']) {
         $err_msg = Ai1ec_I18n::__('<strong>ERROR:</strong> There was an error storing <strong>robots.txt</strong> to the server, the file could not be written.');
         $this->_registry->get('notification.admin')->store($err_msg, 'error');
         $redirect = true;
     }
     // Set Page ID
     $robots_txt['page_id'] = $settings->get('calendar_page_id');
     // Update Robots Txt
     $option->set('ai1ec_robots_txt', $robots_txt);
     // Update settings textarea
     $settings->set('edit_robots_txt', $custom_rules);
     // we need to avoid infinity loop if FS_METHOD direct
     // and robots.txt is not writable
     if ($redirect && !isset($_REQUEST['noredirect'])) {
         Ai1ec_Http_Response_Helper::redirect($redirect_url);
     }
 }
コード例 #3
0
 /**
  * Redirect the user either to the front page or the dashbord page
  *
  * @return void Method does not return
  */
 protected function redirect($suggested_url = null)
 {
     $url = ai1ec_get_site_url();
     if (is_admin()) {
         $url = null !== $suggested_url ? $suggested_url : ai1ec_get_admin_url();
     }
     Ai1ec_Http_Response_Helper::redirect($url);
 }
コード例 #4
0
ファイル: page.php プロジェクト: piratas/piratas-site
 /**
  * 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;
 }
 /**
  * Redirect the user either to the front page or the dashbord page
  *
  * @return void Method does not return
  */
 protected function redirect()
 {
     if (is_admin()) {
         Ai1ec_Http_Response_Helper::redirect(get_admin_url());
     } else {
         Ai1ec_Http_Response_Helper::redirect(get_site_url());
     }
 }