pluf2

pluf2 Commit Details


Date:2009-02-16 15:17:27 (15 years 10 months ago)
Author:Loic d'Anterroches
Branch:master
Commit:687725ab2a690b5a8393d8fce3391955d4228dd9
Parents: eb9dd9a39a47533338b50319cba92c02ac5bcbcb
Message:Better redirection to have canonical URLs.

Changes:

File differences

src/Pluf/Dispatcher.php
121121
122122
123123
124
124
125125
126126
127127
......
163163
164164
165165
166
166
167
168
169
170
171
172
173
174
167175
168176
169177
foreach ($GLOBALS['_PX_views'] as $key => $ctl) {
$match = array();
if (preg_match($ctl['regex'], $req->query, $match)) {
$req->view = $ctl;
$req->view = array($ctl, $match);
$m = new $ctl['model']();
if (isset($m->{$ctl['method'].'_precond'})) {
// Here we have preconditions to respects. If
}
if ($firstpass and substr($req->query, -1) != '/') {
$req->query .= '/';
return self::match($req, false);
$res = self::match($req, false);
if ($res->status_code != 404) {
Pluf::loadFunction('Pluf_HTTP_URL_urlForView');
$name = (isset($req->view[0]['name'])) ?
$req->view[0]['name'] :
$req->view[0]['model'].'::'.$req->view[0]['method'];
$url = Pluf_HTTP_URL_urlForView($name, array_slice($req->view[1], 1));
return new Pluf_HTTP_Response_Redirect($url, 301);
}
}
return new Pluf_HTTP_Response_NotFound($req);
}
src/Pluf/HTTP/Response/Redirect.php
2323
2424
2525
26
26
27
28
29
30
31
32
2733
2834
2935
3036
31
37
3238
3339
class Pluf_HTTP_Response_Redirect extends Pluf_HTTP_Response
{
function __construct($url)
/**
* Redirect response to a given URL.
*
* @param string URL
* @paran int Redirect code (302) or 301 for permanent
*/
function __construct($url, $code=302)
{
$content = sprintf(__('<a href="%s">Please, click here to be redirected</a>.'), $url);
parent::__construct($content);
$this->headers['Location'] = $url;
$this->status_code = 302;
$this->status_code = $code;
}
}

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.06282s using 13 queries.