Skip to content

Commit b979c6b

Browse files
wilsongephproberto
authored andcommitted
[imp] Add ability to set redirect headers in com_redirect. Fixes #4292
Change language string names Add extra large class to field Don't check for empty new url if in advanced mode Remove not null constraint in db Remove not null constraint in db (2/2) Add extra check for a 3xx code Port to all databases Add missing update files
1 parent 8f2f8e6 commit b979c6b

File tree

17 files changed

+262
-47
lines changed

17 files changed

+262
-47
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE `#__redirect_links` ADD header smallint(3) NOT NULL DEFAULT 301;
2+
ALTER TABLE `#__redirect_links` MODIFY new_url varchar(255);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE "#__redirect_links" ADD COLUMN "header"INTEGER DEFAULT 301 NOT NULL;
2+
ALTER TABLE "#__redirect_links" ALTER COLUMN "new_url" DROP NOT NULL;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE [#__redirect_links] ADD [header] [smallint] NOT NULL DEFAULT 301;
2+
ALTER TABLE [#__redirect_links] ALTER COLUMN [new_url] [nvarchar](255) NULL;

administrator/components/com_redirect/config.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,19 @@
1414
component="com_redirect"
1515
section="component" />
1616
</fieldset>
17+
<fieldset name="redirect"
18+
label="COM_REDIRECT_ADVANCED_OPTIONS"
19+
>
20+
<field
21+
name="mode"
22+
type="radio"
23+
class="btn-group btn-group-yesno"
24+
default="0"
25+
label="COM_REDIRECT_MODE_LABEL"
26+
description="COM_REDIRECT_MODE_DESC"
27+
>
28+
<option value="1">JYES</option>
29+
<option value="0">JNO</option>
30+
</field>
31+
</fieldset>
1732
</config>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!DOCTYPE html><title></title>
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<?php
2+
/**
3+
* @package Joomla.Administrator
4+
* @subpackage com_redirect
5+
*
6+
* @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
7+
* @license GNU General Public License version 2 or later; see LICENSE.txt
8+
*/
9+
10+
defined('JPATH_BASE') or die;
11+
12+
JFormHelper::loadFieldClass('list');
13+
14+
/**
15+
* A drop down containing all valid HTTP 1.1 response codes.
16+
*
17+
* @package Joomla.Administrator
18+
* @subpackage com_redirect
19+
* @since 3.4
20+
*/
21+
class JFormFieldRedirect extends JFormFieldList
22+
{
23+
/**
24+
* The form field type.
25+
*
26+
* @var string
27+
* @since 3.4
28+
*/
29+
protected $type = 'Redirect';
30+
31+
/**
32+
* A map of integer HTTP 1.1 response codes to the full HTTP Status for the headers.
33+
*
34+
* @var object
35+
* @since 3.4
36+
* @see http://www.iana.org/assignments/http-status-codes/
37+
*/
38+
protected $responseMap = array(
39+
100 => 'HTTP/1.1 100 Continue',
40+
101 => 'HTTP/1.1 101 Switching Protocols',
41+
102 => 'HTTP/1.1 102 Processing',
42+
200 => 'HTTP/1.1 200 OK',
43+
201 => 'HTTP/1.1 201 Created',
44+
202 => 'HTTP/1.1 202 Accepted',
45+
203 => 'HTTP/1.1 203 Non-Authoritative Information',
46+
204 => 'HTTP/1.1 204 No Content',
47+
205 => 'HTTP/1.1 205 Reset Content',
48+
206 => 'HTTP/1.1 206 Partial Content',
49+
207 => 'HTTP/1.1 207 Multi-Status',
50+
208 => 'HTTP/1.1 208 Already Reported',
51+
226 => 'HTTP/1.1 226 IM Used',
52+
300 => 'HTTP/1.1 300 Multiple Choices',
53+
301 => 'HTTP/1.1 301 Moved Permanently',
54+
302 => 'HTTP/1.1 302 Found',
55+
303 => 'HTTP/1.1 303 See other',
56+
304 => 'HTTP/1.1 304 Not Modified',
57+
305 => 'HTTP/1.1 305 Use Proxy',
58+
306 => 'HTTP/1.1 306 (Unused)',
59+
307 => 'HTTP/1.1 307 Temporary Redirect',
60+
308 => 'HTTP/1.1 308 Permanent Redirect',
61+
400 => 'HTTP/1.1 400 Bad Request',
62+
401 => 'HTTP/1.1 401 Unauthorized',
63+
402 => 'HTTP/1.1 402 Payment Required',
64+
403 => 'HTTP/1.1 403 Forbidden',
65+
404 => 'HTTP/1.1 404 Not Found',
66+
405 => 'HTTP/1.1 405 Method Not Allowed',
67+
406 => 'HTTP/1.1 406 Not Acceptable',
68+
407 => 'HTTP/1.1 407 Proxy Authentication Required',
69+
408 => 'HTTP/1.1 408 Request Timeout',
70+
409 => 'HTTP/1.1 409 Conflict',
71+
410 => 'HTTP/1.1 410 Gone',
72+
411 => 'HTTP/1.1 411 Length Required',
73+
412 => 'HTTP/1.1 412 Precondition Failed',
74+
413 => 'HTTP/1.1 413 Payload Too Large',
75+
414 => 'HTTP/1.1 414 URI Too Long',
76+
415 => 'HTTP/1.1 415 Unsupported Media Type',
77+
416 => 'HTTP/1.1 416 Requested Range Not Satisfiable',
78+
417 => 'HTTP/1.1 417 Expectation Failed',
79+
418 => 'HTTP/1.1 418 I\'m a teapot',
80+
422 => 'HTTP/1.1 422 Unprocessable Entity',
81+
423 => 'HTTP/1.1 423 Locked',
82+
424 => 'HTTP/1.1 424 Failed Dependency',
83+
425 => 'HTTP/1.1 425 Reserved for WebDAV advanced collections expired proposal',
84+
426 => 'HTTP/1.1 426 Upgrade Required',
85+
428 => 'HTTP/1.1 428 Precondition Required',
86+
429 => 'HTTP/1.1 429 Too Many Requests',
87+
431 => 'HTTP/1.1 431 Request Header Fields Too Large',
88+
500 => 'HTTP/1.1 500 Internal Server Error',
89+
501 => 'HTTP/1.1 501 Not Implemented',
90+
502 => 'HTTP/1.1 502 Bad Gateway',
91+
503 => 'HTTP/1.1 503 Service Unavailable',
92+
504 => 'HTTP/1.1 504 Gateway Timeout',
93+
505 => 'HTTP/1.1 505 HTTP Version Not Supported',
94+
506 => 'HTTP/1.1 506 Variant Also Negotiates (Experimental)',
95+
507 => 'HTTP/1.1 507 Insufficient Storage',
96+
508 => 'HTTP/1.1 508 Loop Detected',
97+
510 => 'HTTP/1.1 510 Not Extended',
98+
511 => 'HTTP/1.1 511 Network Authentication Required',
99+
);
100+
101+
/**
102+
* Method to get the field input markup.
103+
*
104+
* @return string The field input markup.
105+
* @since 3.4
106+
*/
107+
protected function getOptions()
108+
{
109+
$options = array();
110+
111+
foreach ($this->responseMap as $key => $value)
112+
{
113+
$options[] = JHtml::_('select.option', $key, $value);
114+
}
115+
116+
// Merge any additional options in the XML definition.
117+
$options = array_merge(parent::getOptions(), $options);
118+
119+
return $options;
120+
}
121+
}

administrator/components/com_redirect/models/forms/link.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,14 @@
9292
readonly="true"
9393
filter="unset" />
9494
</fieldset>
95+
<fieldset name="advanced">
96+
<field
97+
name="header"
98+
type="redirect"
99+
default="301"
100+
class="input-xlarge"
101+
label="COM_REDIRECT_FIELD_REDIRECT_STATUS_CODE_LABEL"
102+
description="COM_REDIRECT_FIELD_REDIRECT_STATUS_CODE_DESC"
103+
/>
104+
</fieldset>
95105
</form>

administrator/components/com_redirect/models/link.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ public function getForm($data = array(), $loadData = true)
107107
$form->setFieldAttribute('published', 'filter', 'unset');
108108
}
109109

110+
// If in advanced mode then we make sure the new url field is not compulsory and the header
111+
// field compulsory in case people select non-3xx redirects
112+
if (JComponentHelper::getParams('com_redirect')->get('mode', 0) == true)
113+
{
114+
$form->setFieldAttribute('new_url', 'required', 'false');
115+
$form->setFieldAttribute('header', 'required', 'true');
116+
}
117+
110118
return $form;
111119
}
112120

administrator/components/com_redirect/tables/link.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,23 @@ public function check()
4848
return false;
4949
}
5050

51-
// Check for valid name.
52-
if (empty($this->new_url))
51+
// Check for valid name if not in advanced mode.
52+
if (empty($this->new_url) && JComponentHelper::getParams('com_redirect')->get('mode', 0) == false)
5353
{
5454
$this->setError(JText::_('COM_REDIRECT_ERROR_DESTINATION_URL_REQUIRED'));
5555

5656
return false;
5757
}
58+
elseif (empty($this->new_url) && JComponentHelper::getParams('com_redirect')->get('mode', 0) == true)
59+
{
60+
// Else if an empty URL and in redirect mode only throw the same error if the code is a 3xx status code
61+
if ($this->header < 400 && $this->header >= 300)
62+
{
63+
$this->setError(JText::_('COM_REDIRECT_ERROR_DESTINATION_URL_REQUIRED'));
64+
65+
return false;
66+
}
67+
}
5868

5969
// Check for duplicates
6070
if ($this->old_url == $this->new_url)

administrator/components/com_redirect/views/link/tmpl/edit.php

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,36 +31,17 @@
3131
<?php echo JHtml::_('bootstrap.startTabSet', 'myTab', array('active' => 'basic')); ?>
3232

3333
<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'basic', empty($this->item->id) ? JText::_('COM_REDIRECT_NEW_LINK', true) : JText::sprintf('COM_REDIRECT_EDIT_LINK', $this->item->id, array('jsSafe' => true))); ?>
34-
<div class="control-group">
35-
<div class="control-label"><?php echo $this->form->getLabel('old_url'); ?></div>
36-
<div class="controls"><?php echo rawurldecode($this->form->getInput('old_url')); ?></div>
37-
</div>
38-
<div class="control-group">
39-
<div class="control-label"><?php echo $this->form->getLabel('new_url'); ?></div>
40-
<div class="controls"><?php echo rawurldecode($this->form->getInput('new_url')); ?></div>
41-
</div>
42-
<div class="control-group">
43-
<div class="control-label"><?php echo $this->form->getLabel('published'); ?></div>
44-
<div class="controls"><?php echo $this->form->getInput('published'); ?></div>
45-
</div>
46-
<div class="control-group">
47-
<div class="control-label"><?php echo $this->form->getLabel('comment'); ?></div>
48-
<div class="controls"><?php echo $this->form->getInput('comment'); ?></div>
49-
</div>
50-
<div class="control-group">
51-
<div class="control-label"><?php echo $this->form->getLabel('id'); ?></div>
52-
<div class="controls"><?php echo $this->form->getInput('id'); ?></div>
53-
</div>
54-
<div class="control-group">
55-
<div class="control-label"><?php echo $this->form->getLabel('created_date'); ?></div>
56-
<div class="controls"><?php echo $this->form->getInput('created_date'); ?></div>
57-
</div>
58-
<div class="control-group">
59-
<div class="control-label"><?php echo $this->form->getLabel('modified_date'); ?></div>
60-
<div class="controls"><?php echo $this->form->getInput('modified_date'); ?></div>
61-
</div>
34+
<?php echo $this->form->renderField('old_url'); ?>
35+
<?php echo $this->form->renderField('new_url'); ?>
36+
<?php echo $this->form->renderField('published'); ?>
37+
<?php echo $this->form->renderField('comment'); ?>
38+
<?php echo $this->form->renderField('id'); ?>
39+
<?php echo $this->form->renderField('created_date'); ?>
40+
<?php echo $this->form->renderField('modified_date'); ?>
41+
<?php if (JComponentHelper::getParams('com_redirect')->get('mode')) : ?>
42+
<?php echo $this->form->renderFieldset('advanced'); ?>
43+
<?php endif; ?>
6244
<?php echo JHtml::_('bootstrap.endTab'); ?>
63-
6445
<?php echo JHtml::_('bootstrap.endTabSet'); ?>
6546

6647
<input type="hidden" name="task" value="" />

0 commit comments

Comments
 (0)