-
Notifications
You must be signed in to change notification settings - Fork 377
/
redirect.class.inc
153 lines (132 loc) · 2.82 KB
/
redirect.class.inc
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
/**
* Provides a HTTP redirect from one Backdrop internal path to another.
*/
class Redirect {
/**
* The redirect ID.
*
* @var integer
*/
public $rid;
/**
* The type of the redirect object. May be:
*
* - redirect: A redirect that is saved and loaded from the database.
* - manual: A single-use redirect that was manually created on-the-fly.
*
* @var string
*/
public $type = 'redirect';
/**
* The redirect language code.
*
* @var string
*/
public $langcode = LANGUAGE_NONE;
/**
* The from which the redirect will start.
*
* @var string
*/
public $source = '';
/**
* An array of options for the source of the redirect.
*
* @var array
*/
public $source_options = array();
/**
* The path to which the source will be redirected.
*
* @var string
*/
public $redirect;
/**
* An array of options for the redirect.
*
* @var array
*/
public $redirect_options = array();
/**
* The function callback that will execute the redirect.
*
* @var string
*/
public $callback = 'redirect_goto';
/**
* The redirect creator ID.
*
* @var int
*/
public $uid = 0;
/**
* The redirect status code.
*
* @var int
*/
public $status_code = 301;
/**
* The total number of times this redirect has been followed.
*
* @var int
*/
public $count = 0;
/**
* A timestamp of the last time this redirect was accessed.
*/
public $access = 0;
/**
* Hashes are an alternative ID by which a redirect may be loaded.
*
* @var string
*/
public $hash = '';
/**
* If this redirect is newly created and not yet saved to the database.
*
* @var bool
*/
public $is_new = FALSE;
/**
* Constructor for creating a new redirect.
*
* @param array $values
* An array of values to populate the redirect object.
*/
public function __construct(array $values = array()) {
// Set initial values.
foreach ($values as $key => $value) {
$this->$key = $value;
}
if (empty($this->rid)) {
$this->is_new = TRUE;
}
// Unserialize the URL option fields.
if (is_string($this->source_options)) {
$this->source_options = unserialize($this->source_options);
}
if (is_string($this->redirect_options)) {
$this->redirect_options = unserialize($this->redirect_options);
}
module_invoke_all('redirect_prepare', $this, $values);
}
/**
* Save this redirect object.
*/
public function save() {
return redirect_save($this);
}
/**
* Implements EntityInterface::delete().
*/
public function delete() {
return redirect_delete($this->rid);
}
/**
* Returns if this redirect is newly created and not yet saved.
*/
public function isNew() {
return !empty($this->is_new) || !$this->rid;
}
}