-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgobacktionary.php
More file actions
executable file
·139 lines (124 loc) · 5.32 KB
/
gobacktionary.php
File metadata and controls
executable file
·139 lines (124 loc) · 5.32 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
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
<?php
// go_functions provides access to the function curPageURL()
require_once "go_functions.php";
require_once "config.php";
require_once "go.php";
require_once "header.php";
$letter = "a";
if (isset($_GET["letter"]) && preg_match("/^([A-Za-z0-9]|\[0-9\])$/", $_GET["letter"]) === 1) {
$letter = $_GET["letter"];
}
?>
<nav class="gonav">
<ul>
<li><a href="gobacktionary.php?letter=[0-9]">#</a></li>
<li><a href="gobacktionary.php?letter=a">A</a></li>
<li><a href="gobacktionary.php?letter=b">B</a></li>
<li><a href="gobacktionary.php?letter=c">C</a></li>
<li><a href="gobacktionary.php?letter=d">D</a></li>
<li><a href="gobacktionary.php?letter=e">E</a></li>
<li><a href="gobacktionary.php?letter=f">F</a></li>
<li><a href="gobacktionary.php?letter=g">G</a></li>
<li><a href="gobacktionary.php?letter=h">H</a></li>
<li><a href="gobacktionary.php?letter=i">I</a></li>
<li><a href="gobacktionary.php?letter=j">J</a></li>
<li><a href="gobacktionary.php?letter=k">K</a></li>
<li><a href="gobacktionary.php?letter=l">L</a></li>
<li><a href="gobacktionary.php?letter=m">M</a></li>
<li><a href="gobacktionary.php?letter=n">N</a></li>
<li><a href="gobacktionary.php?letter=o">O</a></li>
<li><a href="gobacktionary.php?letter=p">P</a></li>
<li><a href="gobacktionary.php?letter=q">Q</a></li>
<li><a href="gobacktionary.php?letter=r">R</a></li>
<li><a href="gobacktionary.php?letter=s">S</a></li>
<li><a href="gobacktionary.php?letter=t">T</a></li>
<li><a href="gobacktionary.php?letter=u">U</a></li>
<li><a href="gobacktionary.php?letter=v">V</a></li>
<li><a href="gobacktionary.php?letter=w">W</a></li>
<li><a href="gobacktionary.php?letter=x">X</a></li>
<li><a href="gobacktionary.php?letter=y">Y</a></li>
<li><a href="gobacktionary.php?letter=z">Z</a></li>
</ul>
</nav>
<div class="content">
<p><b>GO needs your help!</b> Find out how you can help by logging in to our <a href="admin.php">new self-service shortcut creation interface</a>!</p>
<p>You can also <a href="gotionary.php">view this list, sorted by the shortcut</a>.</p>
<?php
global $connection;
$where = "url LIKE 'http://{$letter}%' OR url LIKE 'https://{$letter}%' OR url LIKE 'http://www.{$letter}%' OR url LIKE 'https://www.{$letter}%'";
if ($letter == "[0-9]") {
$where = '';
for ($i = 0; $i < 10; $i++) {
$where .= "url LIKE 'http://{$i}%' OR url LIKE 'https://{$i}%' OR url LIKE 'http://www.{$i}%' OR url LIKE 'https://www.{$i}%' ";
if ($i != 9) {
$where .= 'OR ';
}
}
}
// Special case when w is selected, to avoid listing out nearly all URLs.
if ($letter == "w") {
$where = "url LIKE 'http://ww[!w]%' OR url LIKE 'http://www.{$letter}%' OR url LIKE 'https://ww[!w]%' OR url LIKE 'https://www.{$letter}%'";
}
$select = $connection->prepare("SELECT code.name AS name, code.description AS description, code.url AS url, alias.name AS alias FROM code LEFT JOIN alias ON (code.name = alias.code AND alias.institution = :inst1) WHERE {$where} AND code.institution = :inst2 AND public = 1 ORDER BY code.url, alias.name, code.name, code.description");
$select->bindValue(":inst1", $institution);
$select->bindValue(":inst2", $institution);
$select->execute();
// Collect all the rows for manipulation
$rows = $select->fetchAll(PDO::FETCH_ASSOC);
$sort = array();
// Strip the protocol and www from urls
foreach ($rows as $key => &$row) {
$urlParts = parse_url($row['url']);
$url = preg_replace('/^www\./', '', $urlParts['host']);
if(isset($urlParts['path'])) {
$url = $url . $urlParts['path'];
}
if(isset($urlParts['query'])) {
$url = $url . $urlParts['query'];
}
$row['print_url'] = $url;
$sort[$key] = $row['print_url'];
}
array_multisort($sort, SORT_ASC, $rows);
$lines = array();
$current_url = "";
print "<p> ";
foreach ($rows as $row) {
if ($current_url != $row['url']) {
print "</p>";
print "\n<p class='gobacktionary_info'>";
print "<a href=\"info.php?code=".$row['name']."\" class='info_link' title='Show Shortcut Information'>";
if (Code::isUrlValid($row['url']))
print "<img src='application-icons/info.png' alt='info'/>";
else
print "<img src='application-icons/alert.png' alt='alert'/>";
print "</a> ";
print "</p>\n<p class='gobacktionary_shortcut'>";
print htmlentities($row['print_url']);
print "<br />";
print "<em> ".(empty($row['description'])?'':htmlentities($row['description']))."</em>";
//add rel=nofollow and external class to external links
$host_url = parse_url($row['url'], PHP_URL_HOST);
$internal_host = false;
foreach ($internal_hosts as $host) {
if (preg_match($host, $host_url)) {
$internal_host = true;
}
}
if (!$internal_host) {
print "<br /> <a class='external' rel='nofollow' href=\"".Go::getShortcutUrl($row['name'], $institution)."\">go/".htmlentities($row['name'])."</a>";
} else {
print "<br /> <a href=\"".Go::getShortcutUrl($row['name'], $institution)."\">go/".htmlentities($row['name'])."</a>";
}
}
if ($row['alias']) {
print "<br /> <a href=\"".Go::getShortcutUrl($row['name'], $institution)."\">go/" . $row['alias'] . "</a>";
}
$current_url = $row['url'];
}
?>
</p>
</div>
</div>
<?php
require_once "footer.php";