Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixed issue #899 redirects #1055

Merged
merged 14 commits into from

2 participants

el2ro Phil Sturgeon
el2ro

Fixed issue #899 - #899

Redirect will now support 301 or 302 redirect type.
Redirect support "*" wildcards in "From" field.
To fields support $1, $2 same way as in regexp.

No full regexp support only * are supported.

el2ro added some commits
el2ro el2ro Fixed issue 899. Redirects will now have 301 or 302 dropdown in redir…
…ects.

Redirects will now support * wildcard in from field and optionally
$1,$2... in to field.
6847d62
el2ro el2ro Cleanup 85b6e49
system/cms/core/Public_Controller.php
@@ -8,13 +8,29 @@ 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
Phil Sturgeon Owner

Hey could you make this line into:

if ( ! $this->input->is_ajax_request() AND $_SERVER['REQUEST_METHOD'] == 'GET')

It can be up to 120 chars and there spacing on the if is currently not matching our style guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Phil Sturgeon philsturgeon commented on the diff
system/cms/core/Public_Controller.php
((13 lines not shown))
{
- 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)
Phil Sturgeon Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Phil Sturgeon

So other than those minor tweaks we're looking good, but can you change the migration to be 74?

el2ro

Ok, I will take a look on those tomorrow.

el2ro added some commits
el2ro el2ro Small style changes to match Pyro coding quide. Updated migration num…
…ber to 76.
b1b2f1e
el2ro el2ro Merge remote-tracking branch 'pyro/2.1/develop' into issue-899-redirects
Conflicts:
	system/cms/config/migration.php
	system/cms/modules/redirects/controllers/admin.php
f8de942
Phil Sturgeon
Owner

"This pull request cannot be automatically merged."

el2ro

@philsturgeon This should be right again... for a day or two

el2ro

Don't pull this yet. Found one issue which need to be fixed first. This exotic active record query does not work correctly on all input data. Need to build that query manually to fix it.

system/cms/modules/redirects/models/redirect_m.php
((5 lines not shown))
//$this->db->where('site_id', $this->site->id);
- return $this->db->get('redirects')->row();
+ $this->db->where($this->db->escape($from)." LIKE ".
Phil Sturgeon Owner

Use ->db->like()?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
el2ro

I am pretty sure I tried that ->db->like() in the first place and it didn't work. I will look in to that at evening.

el2ro

Everything should be now just ok!

system/cms/modules/redirects/models/redirect_m.php
((5 lines not shown))
//$this->db->where('site_id', $this->site->id);
- return $this->db->get('redirects')->row();
+ $redirects_table = $this->db->dbprefix('redirects');
+ $data = $this->db->query("SELECT * FROM (`$redirects_table`) WHERE ? LIKE $redirects_table.from",
Phil Sturgeon Owner

Can this be ActiveRecord too please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
el2ro

Well it was ActiveRecord, but it was not working in all cases. So I had to change it to query binding to make it work in all cases. In ActiveRecord when there were dot . in URI ($from) it added DB prefix to uri and made the query brake. I didn't study if that problem could be fixed by fixing AR / some thing you have added on top of that. Do you have plans for some other DB or why you want AR so badly?

Phil Sturgeon
el2ro el2ro Merge branch '2.1/develop' into issue-899-redirects
Conflicts:
	system/cms/config/migration.php
47acc63
Phil Sturgeon

Hey looks like this one has some conflicts. Can you update them and push the changes so I can merge?

el2ro

I have tried to get reverse like query working with AR but no luck.

Best I can do is to provide version which has platform check and own queries for MySQL and Postgres. PG query is not tested, but at should be quite close. How does this sound?

Phil Sturgeon
Owner

Could you explain "not working"? It could be that the from is not being escaped properly and thus causing syntax errors?

el2ro

This should generate SQL query like this:

SELECT * FROM default_redirects WHERE 'blog/my-post' LIKE default_redirects.from

$this->db->where($this->db->escape($from)." LIKE ".$this->db->dbprefix('redirects').".from", null, false);
$data = $this->db->get('redirects')->row();
return $data;

This is working as long as is no dot in the URL. When there is dot in URL (in $from param) it will generate SQL query like this:

SELECT * FROM default_redirects WHERE 'blog/my-post' LIKE default_'redirects.from'

and it obviously fails.

Phil Sturgeon
Owner
el2ro

AR like query is not done for that purpose.

Here are the results from AR like queries.
Error Number: 1054
Unknown column 'blog/my-post' in 'where clause'

(path 'blog/my-post')
SELECT * FROM (default_redirects) WHERE blog/my-post LIKE '%redirects.from%'
(just domain name)
SELECT * FROM (default_redirects) WHERE ` LIKE '%redirects.from%'

Setting 3rd param to 'none' instead of false does not change much:
$this->db->like($from, 'redirects.from', 'none');

SELECT * FROM (default_redirects) WHERE blog/my-post LIKE 'redirects.from'

It would need total rework to AR like query to make it work that way.

Phil Sturgeon
Owner

Ok lets go with what you have. One last update on your branch then we can merge.

el2ro

@philsturgeon hey take a look

Phil Sturgeon philsturgeon merged commit f6db56b into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 2, 2012
  1. el2ro

    Fixed issue 899. Redirects will now have 301 or 302 dropdown in redir…

    el2ro authored
    …ects.
    
    Redirects will now support * wildcard in from field and optionally
    $1,$2... in to field.
  2. el2ro

    Cleanup

    el2ro authored
Commits on Jan 23, 2012
  1. el2ro
  2. el2ro

    Merge remote-tracking branch 'pyro/2.1/develop' into issue-899-redirects

    el2ro authored
    Conflicts:
    	system/cms/config/migration.php
    	system/cms/modules/redirects/controllers/admin.php
Commits on Feb 7, 2012
  1. el2ro
Commits on Feb 14, 2012
  1. el2ro

    Merge branch '2.1/develop' into issue-899-redirects

    el2ro authored
    Conflicts:
    	system/cms/core/Public_Controller.php
  2. el2ro
Commits on Feb 15, 2012
  1. el2ro
  2. el2ro

    Fixed the DB query problem.

    el2ro authored
Commits on Feb 28, 2012
  1. el2ro

    Merge branch '2.1/develop' into issue-899-redirects

    el2ro authored
    Conflicts:
    	system/cms/config/migration.php
Commits on Mar 2, 2012
  1. el2ro
  2. el2ro
Commits on Mar 8, 2012
  1. el2ro

    Merge remote-tracking branch 'pyro/2.1/develop' into issue-899-redirects

    el2ro authored
    Conflicts:
    	system/cms/modules/redirects/language/german/redirects_lang.php
  2. el2ro
This page is out of date. Refresh to see the latest.
Showing with 235 additions and 75 deletions.
  1. +2 −2 system/cms/config/migration.php
  2. +24 −7 system/cms/core/Public_Controller.php
  3. +20 −0 system/cms/migrations/080_Add_type_field_to_redirects.php
  4. +26 −22 system/cms/modules/redirects/controllers/admin.php
  5. +5 −0 system/cms/modules/redirects/language/arabic/redirects_lang.php
  6. +5 −0 system/cms/modules/redirects/language/brazilian/redirects_lang.php
  7. +5 −0 system/cms/modules/redirects/language/chinese_traditional/redirects_lang.php
  8. +5 −0 system/cms/modules/redirects/language/czech/redirects_lang.php
  9. +5 −0 system/cms/modules/redirects/language/danish/redirects_lang.php
  10. +5 −0 system/cms/modules/redirects/language/dutch/redirects_lang.php
  11. +5 −0 system/cms/modules/redirects/language/english/redirects_lang.php
  12. +5 −0 system/cms/modules/redirects/language/finnish/redirects_lang.php
  13. +5 −0 system/cms/modules/redirects/language/french/redirects_lang.php
  14. +5 −0 system/cms/modules/redirects/language/german/redirects_lang.php
  15. +5 −0 system/cms/modules/redirects/language/greek/redirects_lang.php
  16. +5 −0 system/cms/modules/redirects/language/hebrew/redirects_lang.php
  17. +5 −0 system/cms/modules/redirects/language/italian/redirects_lang.php
  18. +5 −0 system/cms/modules/redirects/language/lithuanian/redirects_lang.php
  19. +5 −0 system/cms/modules/redirects/language/polish/redirects_lang.php
  20. +18 −13 system/cms/modules/redirects/language/russian/redirects_lang.php
  21. +5 −0 system/cms/modules/redirects/language/slovenian/redirects_lang.php
  22. +5 −0 system/cms/modules/redirects/language/spanish/redirects_lang.php
  23. +5 −0 system/cms/modules/redirects/language/vietnamese/redirects_lang.php
  24. +36 −22 system/cms/modules/redirects/models/redirect_m.php
  25. +13 −5 system/cms/modules/redirects/views/admin/form.php
  26. +6 −4 system/cms/modules/redirects/views/admin/index.php
4 system/cms/config/migration.php
View
@@ -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 */
31 system/cms/core/Public_Controller.php
View
@@ -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)
Phil Sturgeon Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ {
+ 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').'.');
20 system/cms/migrations/080_Add_type_field_to_redirects.php
View
@@ -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');
+ }
+}
48 system/cms/modules/redirects/controllers/admin.php
View
@@ -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,7 +37,7 @@ class Admin extends Admin_Controller
public function __construct()
{
parent::__construct();
-
+
// Load the required classes
$this->load->library('form_validation');
$this->load->model('redirect_m');
@@ -40,7 +45,7 @@ public function __construct()
$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,11 +87,11 @@ 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
@@ -94,29 +99,28 @@ public function add()
* @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
@@ -124,9 +128,9 @@ public function edit($id = 0)
* @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,12 +148,12 @@ 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'));
@@ -157,7 +161,7 @@ public function delete($id = 0)
redirect('admin/redirects');
}
-
+
/**
* Callback method for validating the redirect's name
* @access public
5 system/cms/modules/redirects/language/arabic/redirects_lang.php
View
@@ -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 system/cms/modules/redirects/language/brazilian/redirects_lang.php
View
@@ -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 system/cms/modules/redirects/language/chinese_traditional/redirects_lang.php
View
@@ -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 system/cms/modules/redirects/language/czech/redirects_lang.php
View
@@ -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 system/cms/modules/redirects/language/danish/redirects_lang.php
View
@@ -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 system/cms/modules/redirects/language/dutch/redirects_lang.php
View
@@ -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 system/cms/modules/redirects/language/english/redirects_lang.php
View
@@ -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';
5 system/cms/modules/redirects/language/finnish/redirects_lang.php
View
@@ -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 system/cms/modules/redirects/language/french/redirects_lang.php
View
@@ -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 system/cms/modules/redirects/language/german/redirects_lang.php
View
@@ -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 system/cms/modules/redirects/language/greek/redirects_lang.php
View
@@ -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 system/cms/modules/redirects/language/hebrew/redirects_lang.php
View
@@ -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 system/cms/modules/redirects/language/italian/redirects_lang.php
View
@@ -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';
5 system/cms/modules/redirects/language/lithuanian/redirects_lang.php
View
@@ -5,6 +5,11 @@
$lang['redirects.to'] = 'Kam';
$lang['redirects.edit'] = 'Redaguoti';
$lang['redirects.delete'] = 'Ištrinti';
+$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'] = 'Pridėti nukreipimą';
5 system/cms/modules/redirects/language/polish/redirects_lang.php
View
@@ -5,6 +5,11 @@
$lang['redirects.to'] = 'Do';
$lang['redirects.edit'] = 'Edytuj';
$lang['redirects.delete'] = 'Usuń';
+$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'] = 'Dodaj przekierowanie';
31 system/cms/modules/redirects/language/russian/redirects_lang.php
View
@@ -9,23 +9,28 @@
*/
// подписи
-$lang['redirects.from'] = 'Откуда';
-$lang['redirects.to'] = 'Куда';
-$lang['redirects.edit'] = 'Редактировать';
-$lang['redirects.delete'] = 'Удалить';
+$lang['redirects.from'] = 'Откуда';
+$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
// заголовки
-$lang['redirects.add_title'] = 'Создать перенаправление';
-$lang['redirects.edit_title'] = 'Редактирование перенаправления';
-$lang['redirects.list_title'] = 'Перенаправления';
+$lang['redirects.add_title'] = 'Создать перенаправление';
+$lang['redirects.edit_title'] = 'Редактирование перенаправления';
+$lang['redirects.list_title'] = 'Перенаправления';
// сообщения
-$lang['redirects.no_redirects'] = 'Перенаправления отсутствуют.';
-$lang['redirects.add_success'] = 'Перенаправление добавлено.';
-$lang['redirects.add_error'] = 'Во время добавления перенаправления произошла ошибка.';
-$lang['redirects.edit_success'] = 'Перенаправление сохранено.';
-$lang['redirects.edit_error'] = 'Во время сохранения перенаправления произошла ошибка.';
-$lang['redirects.mass_delete_error'] = 'Во время удаления перенаправления "%s" произошла ошибка.';
+$lang['redirects.no_redirects'] = 'Перенаправления отсутствуют.';
+$lang['redirects.add_success'] = 'Перенаправление добавлено.';
+$lang['redirects.add_error'] = 'Во время добавления перенаправления произошла ошибка.';
+$lang['redirects.edit_success'] = 'Перенаправление сохранено.';
+$lang['redirects.edit_error'] = 'Во время сохранения перенаправления произошла ошибка.';
+$lang['redirects.mass_delete_error'] = 'Во время удаления перенаправления "%s" произошла ошибка.';
$lang['redirects.mass_delete_success'] = '%s перенаправлений из %s удалено.';
$lang['redirects.no_select_error'] = 'Вы должны выбрать хотя бы одно перенаправление для удаления.';
$lang['redirects.request_conflict_error'] = 'Перенаправление для "%s" уже существует.';
5 system/cms/modules/redirects/language/slovenian/redirects_lang.php
View
@@ -5,6 +5,11 @@
$lang['redirects.to'] = 'Za';
$lang['redirects.edit'] = 'Uredi';
$lang['redirects.delete'] = 'Izbriši';
+$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'] = 'Dodaj preusmeritev';
5 system/cms/modules/redirects/language/spanish/redirects_lang.php
View
@@ -5,6 +5,11 @@
$lang['redirects.to'] = 'A';
$lang['redirects.edit'] = 'Editar';
$lang['redirects.delete'] = 'Eliminar';
+$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'] = 'Agregar Redirección';
5 system/cms/modules/redirects/language/vietnamese/redirects_lang.php
View
@@ -15,6 +15,11 @@
$lang['redirects.to'] = 'Đến';
$lang['redirects.edit'] = 'Sửa';
$lang['redirects.delete'] = 'Xóa';
+$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'] = 'Thêm Redirect';
58 system/cms/modules/redirects/models/redirect_m.php
View
@@ -15,9 +15,21 @@ function get_all()
function get_from($from)
{
- $this->db->where('`from`', $from);
//$this->db->where('site_id', $this->site->id);
- return $this->db->get('redirects')->row();
+ // Reverse like query
+ $redirects_table = $this->db->dbprefix('redirects');
+ if ($this->db->platform() == 'mysql')
+ {
+ $data = $this->db->query("SELECT * FROM (`$redirects_table`) WHERE ? LIKE $redirects_table.from",
+ array($from))->row();
+ }
+ // Postgres version * Not tested *
+ else
+ {
+ $data = $this->db->query("SELECT * FROM $redirects_table WHERE ? LIKE $redirects_table.from",
+ array($from))->row();
+ }
+ return $data;
}
function count_all()
@@ -26,27 +38,29 @@ function count_all()
return $this->db->count_all_results('redirects');
}
- function insert($input = array())
- {
- return $this->db->insert('redirects', array(
- '`from`' => $input['from'],
- '`to`' => trim($input['to'], '/'),
+ function insert($input = array())
+ {
+ return $this->db->insert('redirects', array(
+ '`type`' => $input['type'],
+ '`from`' => str_replace('*', '%', $input['from']),
+ '`to`' => trim($input['to'], '/'),
// 'site_id' => $this->site->id
- ));
- }
+ ));
+ }
- function update($id, $input = array())
- {
+ function update($id, $input = array())
+ {
$this->db->where(array(
'id' => $id,
// 'site_id' => $this->site->id
));
- return $this->db->update('redirects', array(
- '`from`' => $input['from'],
- '`to`' => trim($input['to'], '/')
- ));
- }
+ return $this->db->update('redirects', array(
+ '`type`' => $input['type'],
+ '`from`' => str_replace('*', '%', $input['from']),
+ '`to`' => trim($input['to'], '/')
+ ));
+ }
function delete($id)
{
@@ -56,17 +70,17 @@ function delete($id)
));
}
- // Callbacks
- function check_from($from, $id = 0)
- {
+ // Callbacks
+ function check_from($from, $id = 0)
+ {
if($id > 0)
{
$this->db->where('id !=', $id);
}
- return $this->db->where(array(
- '`from`' => $from,
+ return $this->db->where(array(
+ '`from`' => str_replace('*', '%', $from),
// 'site_id' => $this->site->id
))->count_all_results('redirects');
- }
+ }
}
18 system/cms/modules/redirects/views/admin/form.php
View
@@ -12,20 +12,28 @@
<?php echo form_open(uri_string(), 'class="crud"'); ?>
<ul>
<li>
+ <label for="type"><?php echo lang('redirects.type');?></label><br>
+ <?php echo form_dropdown('type',
+ array('301'=>lang('redirects.301'),'302'=>lang('redirects.302')),
+ !empty($redirect->type) ? $redirect->type : '302');?>
+ </li>
+
+ <hr>
+ <li>
<label for="from"><?php echo lang('redirects.from');?></label><br>
- <?php echo form_input('from', $redirect->from);?>
+ <?php echo form_input('from', str_replace('%', '*', $redirect->from));?>
</li>
-
+
<hr>
-
+
<li>
<label for="to"><?php echo lang('redirects.to');?></label><br>
<?php echo form_input('to', $redirect->to);?>
</li>
</ul>
-
+
<hr>
-
+
<div class="buttons">
<?php $this->load->view('admin/partials/buttons', array('buttons' => array('save', 'cancel') )); ?>
</div>
10 system/cms/modules/redirects/views/admin/index.php
View
@@ -3,14 +3,15 @@
</section>
<?php if ($redirects): ?>
-
+
<section class="item">
-
+
<?php echo form_open('admin/redirects/delete'); ?>
<table border="0" class="table-list">
<thead>
<tr>
- <th width="30"><?php echo form_checkbox(array('name' => 'action_to_all', 'class' => 'check-all'));?></th>
+ <th width="15"><?php echo form_checkbox(array('name' => 'action_to_all', 'class' => 'check-all'));?></th>
+ <th width="25"><?php echo lang('redirects.type');?></th>
<th width="25%"><?php echo lang('redirects.from');?></th>
<th><?php echo lang('redirects.to');?></th>
<th width="200"></th>
@@ -27,7 +28,8 @@
<?php foreach ($redirects as $redirect): ?>
<tr>
<td><?php echo form_checkbox('action_to[]', $redirect->id); ?></td>
- <td><?php echo $redirect->from;?></td>
+ <td><?php echo $redirect->type;?></td>
+ <td><?php echo str_replace('%', '*', $redirect->from);?></td>
<td><?php echo $redirect->to;?></td>
<td class="align-center">
<div class="actions">
Something went wrong with that request. Please try again.