-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexit.php
More file actions
55 lines (45 loc) · 2.2 KB
/
exit.php
File metadata and controls
55 lines (45 loc) · 2.2 KB
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
<?php
# Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity Developer Team)
# All rights reserved. See LICENSE file for licensing details
declare(strict_types=1);
include 'serendipity_config.inc.php';
$url = $serendipity['baseURL'];
$trust_url = false;
$open_redir = false;
if (isset($_GET['url_id']) && !empty($_GET['url_id']) && isset($_GET['entry_id']) && !empty($_GET['entry_id'])) {
// See if the submitted link is in our database and should be tracked
$links = serendipity_db_query("SELECT link FROM {$serendipity['dbPrefix']}references WHERE id = " . (int)$_GET['url_id'] . " AND entry_id = " . (int)$_GET['entry_id'], true);
if (is_array($links) && isset($links['link'])) {
// URL is valid. Track it.
$url = str_replace('&', '&', $links['link']);
$trust_url = true;
serendipity_track_url('exits', $url, (int) $_GET['entry_id']);
} elseif (isset($_GET['url']) && !empty($_GET['url'])) {
// URL is invalid. But a URL-location was sent, so we want to redirect the user kindly.
$url = str_replace('&', '&', base64_decode($_GET['url']));
}
} elseif (isset($_GET['url']) && !empty($_GET['url'])) {
// No entry-link ID was submitted. Possibly a spammer tried to mis-use the script to get into the top-list.
$url = strip_tags(str_replace('&', '&', base64_decode($_GET['url'])));
}
if (serendipity_isResponseClean($url)) {
if (serendipity_plugin_api::exists('serendipity_event_trackexits')) {
// Get configuration of plugin
$configValues = serendipity_db_query("SELECT value FROM {$serendipity['dbPrefix']}config WHERE name LIKE 'serendipity_event_trackexits:%/commentredirection'");
if (is_array($configValues)) {
foreach($configValues AS $configValue) {
if ($configValue['value'] == 's9y') {
$open_redir = true;
}
}
}
}
if ($trust_url || $open_redir) {
header(serendipity_getServerProtocol() . ' 301 Moved Permanently', true, 301); // force
header('Status: 301 Moved Permanently'); // overwrite Status 200
header('Location: ' . $url);
}
}
exit;
/* vim: set sts=4 ts=4 expandtab : */
?>