Fixed issue #899 redirects #1055

Merged
merged 14 commits into from Mar 9, 2012
Jump to file
+235 −75
Split
@@ -23,7 +23,7 @@
|
*/
-$config['migration_version'] = 79;
+$config['migration_version'] = 80;
/*
|--------------------------------------------------------------------------
@@ -37,4 +37,4 @@
*/
$config['migration_path'] = APPPATH . 'migrations/';
-/* End of file migration.php */
+/* End of file migration.php */
@@ -16,13 +16,30 @@ public function __construct()
parent::__construct();
$this->benchmark->mark('public_controller_start');
-
- // Check for a redirect
- $this->load->model('redirects/redirect_m');
- $uri = trim(uri_string(), '/');
- if ($redirect = $this->redirect_m->get_from($uri))
+
+ // Check redirects if GET and Not AJAX
+ if ( ! $this->input->is_ajax_request() AND $_SERVER['REQUEST_METHOD'] == 'GET')
{
- redirect($redirect->to);
+ $this->load->model('redirects/redirect_m');
+ $uri = trim(uri_string(), '/');
+
+ if ($redirect = $this->redirect_m->get_from($uri))
+ {
+ // Check if it was direct match
+ if ($redirect->from == $uri)
philsturgeon
philsturgeon Jan 22, 2012 Member

Can you add brackets to this line to match the style guide :)

+ {
+ redirect($redirect->to,'location',$redirect->type);
+ }
+
+ // If it has back reference
+ if (strpos($redirect->to, '$') !== FALSE)
+ {
+ $from = str_replace('%', '(.*?)', $redirect->from);
+ $redirect->to = preg_replace('#^'.$from.'$#', $redirect->to, $uri);
+ }
+ // Redirect with wanted redirect header type
+ redirect($redirect->to,'location',$redirect->type);
+ }
}
Events::trigger('public_controller');
@@ -41,7 +58,7 @@ public function __construct()
// Load the current theme so we can set the assets right away
ci()->theme = $this->theme_m->get();
-
+
if (empty($this->theme->slug))
{
show_error('This site has been set to use a theme that does not exist. If you are an administrator please '.anchor('admin/themes', 'change the theme').'.');
@@ -0,0 +1,20 @@
+<?php defined('BASEPATH') OR exit('No direct script access allowed');
+
+class Migration_Add_type_field_to_redirects extends CI_Migration {
+
+ public function up()
+ {
+ $this->dbforge->add_column('redirects', array(
+ 'type' => array(
+ 'type' => 'int',
+ 'null' => FALSE,
+ 'default' => 302
+ )
+ ));
+ }
+
+ public function down()
+ {
+ $this->dbforge->drop_column('redirects', 'type');
+ }
+}
@@ -13,6 +13,11 @@ class Admin extends Admin_Controller
*/
protected $validation_rules = array(
array(
+ 'field' => 'type',
+ 'label' => 'lang:redirects.type',
+ 'rules' => 'trim|required|integer'
+ ),
+ array(
'field' => 'from',
'label' => 'lang:redirects.from',
'rules' => 'trim|required|max_length[250]|callback__check_unique'
@@ -23,7 +28,7 @@ class Admin extends Admin_Controller
'rules' => 'trim|required|max_length[250]'
)
);
-
+
/**
* Constructor method
* @access public
@@ -32,15 +37,15 @@ class Admin extends Admin_Controller
public function __construct()
{
parent::__construct();
-
+
// Load the required classes
$this->load->library('form_validation');
$this->load->model('redirect_m');
$this->lang->load('redirects');
$this->form_validation->set_rules($this->validation_rules);
}
-
+
/**
* List all redirects
* @access public
@@ -51,19 +56,19 @@ public function index()
// Create pagination links
$total_rows = $this->redirect_m->count_all();
$this->data->pagination = create_pagination('admin/redirects/index', $total_rows);
-
+
// Using this data, get the relevant results
$this->data->redirects = $this->redirect_m->order_by('`from`')->limit($this->data->pagination['limit'])->get_all();
$this->template->build('admin/index', $this->data);
}
-
+
/**
* Create a new redirect
* @access public
* @return void
*/
public function add()
- {
+ {
// Got validation?
if ($this->form_validation->run())
{
@@ -73,7 +78,7 @@ public function add()
redirect('admin/redirects');
}
-
+
$this->data->messages['error'] = lang('redirects.add_error');
}
@@ -82,51 +87,50 @@ public function add()
{
$redirect->{$rule['field']} = set_value($rule['field']);
}
-
+
$this->data->redirect =& $redirect;
$this->template->build('admin/form', $this->data);
}
-
+
/**
* Edit an existing redirect
* @access public
* @param int $id The ID of the redirect
* @return void
*/
public function edit($id = 0)
- {
+ {
// Got ID?
$id or redirect('admin/redirects');
-
+
// Get the redirect
$redirect = $this->redirect_m->get($id);
-
+
if ($this->form_validation->run())
- {
+ {
if ($this->redirect_m->update($id, $_POST))
{
$this->session->set_flashdata('success', $this->lang->line('redirects.edit_success'));
redirect('admin/redirects');
}
-
+
$this->data->messages['error'] = lang('redirects.edit_error');
}
-
$this->data->redirect =& $redirect;
$this->template->build('admin/form', $this->data);
- }
-
+ }
+
/**
* Delete an existing redirect
* @access public
* @param int $id The ID of the redirect
* @return void
*/
public function delete($id = 0)
- {
+ {
$id_array = ( ! empty($id)) ? array($id) : $this->input->post('action_to');
-
+
// Delete multiple
if( ! empty($id_array))
{
@@ -144,20 +148,20 @@ public function delete($id = 0)
}
$to_delete++;
}
-
+
if ($deleted > 0)
{
$this->session->set_flashdata('success', sprintf($this->lang->line('redirects.mass_delete_success'), $deleted, $to_delete));
}
- }
+ }
else
{
$this->session->set_flashdata('error', $this->lang->line('redirects.no_select_error'));
}
redirect('admin/redirects');
}
-
+
/**
* Callback method for validating the redirect's name
* @access public
@@ -5,6 +5,11 @@
$lang['redirects.to'] = 'إلى';
$lang['redirects.edit'] = 'تعديل';
$lang['redirects.delete'] = 'حذف';
+$lang['redirects.type'] = 'Type'; #translate
+
+// redirect types
+$lang['redirects.301'] = '301 - Moved Permanently'; #translate
+$lang['redirects.302'] = '302 - Moved Temporarily'; #translate
// titles
$lang['redirects.add_title'] = 'إضافة توجيه';
@@ -5,6 +5,11 @@
$lang['redirects.to'] = 'Para';
$lang['redirects.edit'] = 'Editar';
$lang['redirects.delete'] = 'Remover';
+$lang['redirects.type'] = 'Type'; #translate
+
+// redirect types
+$lang['redirects.301'] = '301 - Moved Permanently'; #translate
+$lang['redirects.302'] = '302 - Moved Temporarily'; #translate
// titles
$lang['redirects.add_title'] = 'Adicionar redirecionamento';
@@ -5,6 +5,11 @@
$lang['redirects.to'] = '目標網址';
$lang['redirects.edit'] = '編輯';
$lang['redirects.delete'] = '刪除';
+$lang['redirects.type'] = 'Type'; #translate
+
+// redirect types
+$lang['redirects.301'] = '301 - Moved Permanently'; #translate
+$lang['redirects.302'] = '302 - Moved Temporarily'; #translate
// titles
$lang['redirects.add_title'] = '新增轉址';
@@ -5,6 +5,11 @@
$lang['redirects.to'] = 'Na';
$lang['redirects.edit'] = 'Upravit';
$lang['redirects.delete'] = 'Vymazat';
+$lang['redirects.type'] = 'Type'; #translate
+
+// redirect types
+$lang['redirects.301'] = '301 - Moved Permanently'; #translate
+$lang['redirects.302'] = '302 - Moved Temporarily'; #translate
// titles
$lang['redirects.add_title'] = 'Přidat přesměrování';
@@ -5,6 +5,11 @@
$lang['redirects.to'] = 'til';
$lang['redirects.edit'] = 'Redigér';
$lang['redirects.delete'] = 'Slet';
+$lang['redirects.type'] = 'Type'; #translate
+
+// redirect types
+$lang['redirects.301'] = '301 - Moved Permanently'; #translate
+$lang['redirects.302'] = '302 - Moved Temporarily'; #translate
// titles
$lang['redirects.add_title'] = 'Tilføj omadressering';
@@ -5,6 +5,11 @@
$lang['redirects.to'] = 'Naar';
$lang['redirects.edit'] = 'Wijzig';
$lang['redirects.delete'] = 'Verwijder';
+$lang['redirects.type'] = 'Type'; #translate
+
+// redirect types
+$lang['redirects.301'] = '301 - Moved Permanently'; #translate
+$lang['redirects.302'] = '302 - Moved Temporarily'; #translate
// titles
$lang['redirects.add_title'] = 'Voeg verwijzing toe';
@@ -5,6 +5,11 @@
$lang['redirects.to'] = 'To';
$lang['redirects.edit'] = 'Edit';
$lang['redirects.delete'] = 'Delete';
+$lang['redirects.type'] = 'Type';
+
+// redirect types
+$lang['redirects.301'] = '301 - Moved Permanently';
+$lang['redirects.302'] = '302 - Moved Temporarily';
// titles
$lang['redirects.add_title'] = 'Add Redirect';
@@ -12,6 +12,11 @@
$lang['redirects.to'] = 'Mihin';
$lang['redirects.edit'] = 'Muokkaa';
$lang['redirects.delete'] = 'Poista';
+$lang['redirects.type'] = 'Tyyppi';
+
+// redirect types
+$lang['redirects.301'] = '301 - Siirretty pysyvästi';
+$lang['redirects.302'] = '302 - Siirretty tilapäisesti';
// titles
$lang['redirects.add_title'] = 'Lisää uudelleenohjaus';
@@ -5,6 +5,11 @@
$lang['redirects.to'] = 'Vers';
$lang['redirects.edit'] = 'Editer';
$lang['redirects.delete'] = 'Supprimer';
+$lang['redirects.type'] = 'Type'; #translate
+
+// redirect types
+$lang['redirects.301'] = '301 - Moved Permanently'; #translate
+$lang['redirects.302'] = '302 - Moved Temporarily'; #translate
// titles
$lang['redirects.add_title'] = 'Ajouter une redirection';
@@ -5,6 +5,11 @@
$lang['redirects.to'] = 'Zu';
$lang['redirects.edit'] = 'Bearbeiten';
$lang['redirects.delete'] = 'L&ouml;schen';
+$lang['redirects.type'] = 'Type'; #translate
+
+// redirect types
+$lang['redirects.301'] = '301 - Moved Permanently'; #translate
+$lang['redirects.302'] = '302 - Moved Temporarily'; #translate
// titles
$lang['redirects.add_title'] = 'Umleitung hinzuf&uuml;gen';
@@ -5,6 +5,11 @@
$lang['redirects.to'] = 'Στο';
$lang['redirects.edit'] = 'Επεξεργασία';
$lang['redirects.delete'] = 'Διαγραφή';
+$lang['redirects.type'] = 'Type'; #translate
+
+// redirect types
+$lang['redirects.301'] = '301 - Moved Permanently'; #translate
+$lang['redirects.302'] = '302 - Moved Temporarily'; #translate
// titles
$lang['redirects.add_title'] = 'Προσθήκη Ανακατεύθυνσης';
@@ -5,6 +5,11 @@
$lang['redirects.to'] = 'אל';
$lang['redirects.edit'] = 'ערוך';
$lang['redirects.delete'] = 'מחק';
+$lang['redirects.type'] = 'Type'; #translate
+
+// redirect types
+$lang['redirects.301'] = '301 - Moved Permanently'; #translate
+$lang['redirects.302'] = '302 - Moved Temporarily'; #translate
// titles
$lang['redirects.add_title'] = 'הוסף הפניה';
@@ -7,6 +7,11 @@
$lang['redirects.to'] = 'A';
$lang['redirects.edit'] = 'Modifica';
$lang['redirects.delete'] = 'Elimina';
+$lang['redirects.type'] = 'Type'; #translate
+
+// redirect types
+$lang['redirects.301'] = '301 - Moved Permanently'; #translate
+$lang['redirects.302'] = '302 - Moved Temporarily'; #translate
// titles
$lang['redirects.add_title'] = 'Aggiungi Reindirizzo';
Oops, something went wrong.