forked from rkingon/Craft-Plugin--Redirect-Manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRedirectmanagerPlugin.php
executable file
·62 lines (53 loc) · 1.13 KB
/
RedirectmanagerPlugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace Craft;
class RedirectmanagerPlugin extends BasePlugin
{
public function getName()
{
return Craft::t('Redirect Manager');
}
public function getVersion()
{
return 'Beta';
}
public function getDeveloper()
{
return 'Roi Kingon';
}
public function getDeveloperUrl()
{
return 'http://www.roikingon.com';
}
public function hasCpSection()
{
return true;
}
public function init()
{
// redirects only take place out of the CP
if(craft()->request->isSiteRequest()){
$path = craft()->request->getPath();
if( $location = craft()->redirectmanager->processRedirect($path) )
{
header("Location: ".$location['url'], true, $location['type']);
exit();
}
}
}
public function registerCpRoutes()
{
return array(
'redirectmanager\/new' => 'redirectmanager/_edit',
'redirectmanager\/(?P<redirectId>\d+)' => 'redirectmanager/_edit'
);
}
public function onAfterInstall()
{
$redirects = array(
array('uri' => '#^bad(.*)$#', 'location' => 'good$1', 'type' => "302")
);
foreach ($redirects as $redirect) {
craft()->db->createCommand()->insert('redirectmanager', $redirect);
}
}
}