Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions reroute/ReroutePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function hasCpSection()
return true;
}

public function hookRegisterCpRoutes()
public function registerCpRoutes()
{
return array(
'reroute\/new' => 'reroute/_form',
Expand All @@ -43,8 +43,8 @@ public function init() {
$reroute = craft()->reroute->getByUrl($url);

if ($reroute) {
craft()->request->redirect($reroute['newUrl'], true, 301);
craft()->request->redirect($reroute['newUrl'], true, $reroute['type']);
}
}
}
}
}
5 changes: 3 additions & 2 deletions reroute/controllers/RerouteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class RerouteController extends BaseController
*/
public function __construct()
{
$this->requirePostRequest();
$this->requirePostRequest();
}


Expand All @@ -29,6 +29,7 @@ public function actionSave()
$data = craft()->request->getPost('reroute');
$model->oldUrl = $data['oldUrl'];
$model->newUrl = $data['newUrl'];
$model->type = $data['type'];

// Did we pass validation?
if($model->validate()) {
Expand Down Expand Up @@ -57,4 +58,4 @@ public function actionDelete()

$this->returnJson(array('success' => $result));
}
}
}
5 changes: 3 additions & 2 deletions reroute/models/RerouteModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ protected function defineAttributes()
return array(
'id' => AttributeType::Number,
'oldUrl' => array(AttributeType::String, 'required' => true),
'newUrl' => array(AttributeType::String, 'required' => true)
'newUrl' => array(AttributeType::String, 'required' => true),
'type' => array(AttributeType::Number, 'required' => true, 'values' => array(301,302))
);
}
}
}
12 changes: 10 additions & 2 deletions reroute/records/RerouteRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ protected function defineAttributes()
{
return array(
'oldUrl' => array(AttributeType::String, 'required' => true),
'newUrl' => array(AttributeType::String, 'required' => true)
'newUrl' => array(AttributeType::String, 'required' => true),
'type' => array(AttributeType::Number, 'required' => true, 'values' => array(301,302))
);
}
}

public function defineIndexes()
{
return array(
array('columns' => array('oldUrl'), 'unique' => true),
);
}
}
6 changes: 3 additions & 3 deletions reroute/services/RerouteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct($record = null)
public function getAll()
{
$reroutes = craft()->db->createCommand()
->select('id, oldUrl, newUrl')
->select('id, oldUrl, newUrl, type')
->from('reroute')
->queryAll();

Expand Down Expand Up @@ -54,7 +54,7 @@ public function getById($rerouteId)
*/
public function getByUrl($url) {
$reroute = craft()->db->createCommand()
->select('id, oldUrl, newUrl')
->select('id, oldUrl, newUrl, type')
->from('reroute')
->where('oldUrl = :url', array(':url' => $url))
->limit(1)
Expand Down Expand Up @@ -117,4 +117,4 @@ public function deleteById($id)
{
return $this->record->deleteByPk($id);
}
}
}
23 changes: 16 additions & 7 deletions reroute/templates/_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

{% if rerouteId is not defined %}{% set rerouteId = null %}{% endif %}
{% if reroute is not defined %}
{% if rerouteId %}
{% set reroute = craft.reroute.getById(rerouteId) %}
{% if not reroute %}{% exit 404 %}{% endif %}
{% else %}
{% set reroute = null %}
{% endif %}
{% if rerouteId %}
{% set reroute = craft.reroute.getById(rerouteId) %}
{% if not reroute %}{% exit 404 %}{% endif %}
{% else %}
{% set reroute = null %}
{% endif %}
{% endif %}

{% set title = reroute ? 'Edit Reroute'|t : 'New Reroute'|t %}
Expand Down Expand Up @@ -36,9 +36,18 @@
errors: reroute ? reroute.errors('newUrl') : null,
}) }}

{{ forms.select({
label: 'Type',
required: true,
name: 'reroute[type]',
value: reroute ? reroute.type : 301,
errors: reroute ? reroute.errors('newUrl') : null,
options: [301, 302]
}) }}

<div class="buttons">
<input type="submit" class="btn submit" value="{{ 'Save'|t }}">
</div>
</form>

{% endset %}
{% endset %}
4 changes: 3 additions & 1 deletion reroute/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<thead>
<th scope="col">{{ 'Old Url'|t }}</th>
<th scope="col">{{ 'New Url'|t }}</th>
<th scope="col">{{ 'Type'|t }}</th>
<th class="thin"></th>
<th scope="col">{{ 'Delete'|t }}</th>
</thead>
Expand All @@ -23,6 +24,7 @@
<tr data-id="{{ reroute.id }}" data-name="{{ 'Reroute for {url}' | t({ url: reroute.oldUrl }) }}">
<td><a href="{{ url('reroute/'~reroute.id) }}">{{ reroute.oldUrl }}</a></td>
<td>{{ reroute.newUrl }}</td>
<td>{{ reroute.type }}</td>
<td><a href="{{ reroute.oldUrl }}" target="_blank" class="go">{{ 'View'|t }}</a></td>
<td><a class="delete icon" title="{{ 'Delete'|t }}"></a></td>
</tr>
Expand All @@ -45,4 +47,4 @@
});
{% endset %}

{% includeJs js %}
{% includeJs js %}