Skip to content

Commit 25e3f29

Browse files
committed
Use more getURI functions everywhere
1 parent 7ca318f commit 25e3f29

File tree

8 files changed

+34
-23
lines changed

8 files changed

+34
-23
lines changed

src/templates/Credits.phtml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ require("./header.inc.phtml");
9797
$pfx = ""; $sfx = "";
9898
} else {
9999
if (!isset($users[$item->user_id])) $users[$item->user_id] = new User($item->user_id);
100-
$pfx = "<a href=\"" . Common::relativeUrlToAbsolute("/user/" . urlencode($item->user_id) . "/"
101-
. Common::sanitizeForUrl($users[$item->user_id]->getName(), true)) . "\">"
100+
$pfx = "<a href=\"" . $users[$item->user_id]->getURI() . "\">"
102101
. "<img class=\"avatar\" src=\"https:"
103102
. $getAvatar($avatars, $users[$item->user_id])->getUrl(22, "identicon")
104103
. "\"/> ";
@@ -124,8 +123,7 @@ require("./header.inc.phtml");
124123
$pfx = ""; $sfx = "";
125124
} else {
126125
if (!isset($users[$item->user_id])) $users[$item->user_id] = new User($item->user_id);
127-
$pfx = "<a href=\"" . Common::relativeUrlToAbsolute("/user/" . urlencode($item->user_id) . "/"
128-
. Common::sanitizeForUrl($users[$item->user_id]->getName(), true)) . "\">"
126+
$pfx = "<a href=\"" . $users[$item->user_id]->getURI() . "\">"
129127
. "<img class=\"avatar\" src=\"https:"
130128
. $getAvatar($avatars, $users[$item->user_id])->getUrl(22, "identicon")
131129
. "\"/> ";

src/templates/Document/View.phtml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ $description = "The requested document does not exist or could not be found.";
1616
$this->opengraph->attach(new Pair("type", "article"));
1717

1818
$url = Common::relativeUrlToAbsolute("/document/" . urlencode($object_id));
19-
if ($object) {
2019

21-
$url = $object->getURI();
22-
$this->opengraph->attach(new Pair("url", $url));
20+
if ($object) {
2321

22+
$url = $object->getURI();
2423
$title = htmlspecialchars($object->getTitle(), ENT_HTML5, "UTF-8");
24+
2525
$description = Common::stripUpTo(trim(filter_var(
2626
$object->getContent(true), FILTER_SANITIZE_STRING
2727
)), "\n", 300);
@@ -31,10 +31,10 @@ if ($object) {
3131
$user_url = $object->getUser()->getURI();
3232
$user_avatar = "https:" . (new Gravatar($object->getUser()->getEmail()))->getUrl(22, "identicon");
3333

34-
} else {
35-
$this->opengraph->attach(new Pair("url", "/document/" . urlencode($object_id)));
3634
}
3735

36+
$this->opengraph->attach(new Pair("url", $url));
37+
3838
#$this->additional_css[] = "/a/document.css";
3939
$this->additional_css[] = "/a/comments.css";
4040
require("./header.inc.phtml");

src/templates/News.phtml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if (is_null($news_posts) || empty($news_posts)) {
2727
</article>
2828
<?php
2929
} else {
30-
30+
3131
$user_session = $this->getContext()->user_session;
3232
$logged_in = ($user_session ? new User($user_session->user_id) : null);
3333
$edit_visible = ($logged_in && ($logged_in->getOptionsBitmask()
@@ -46,8 +46,7 @@ if (is_null($news_posts) || empty($news_posts)) {
4646

4747
$users = [];
4848
foreach ($this->getContext()->news_posts as $news_post) {
49-
$url = Common::relativeUrlToAbsolute("/news/" . urlencode($news_post->getId()));
50-
$url .= "/" . Common::sanitizeForUrl($news_post->getTitle(), true);
49+
$url = $news_post->getURI();
5150
$edit_url = Common::relativeUrlToAbsolute("/news/edit?id=" . urlencode($news_post->getId()));
5251
$delete_url = Common::relativeUrlToAbsolute("/news/delete?id=" . urlencode($news_post->getId()));
5352
$user_id = $news_post->getUserId();

src/templates/News.rss.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use \BNETDocs\Libraries\Common;
1616
<?php foreach ($this->context->news_posts as $news_post) { ?>
1717
<item>
1818
<title><?php echo htmlentities($news_post->getTitle(), ENT_XML1, "UTF-8"); ?></title>
19-
<link><?php echo htmlentities(Common::relativeUrlToAbsolute("/news/" . $news_post->getId() . "/" . Common::sanitizeForUrl($news_post->getTitle(), true)), ENT_XML1, "UTF-8"); ?></link>
19+
<link><?php echo htmlentities($news_post->getURI(), ENT_XML1, "UTF-8"); ?></link>
2020
<category><?php echo htmlentities($news_post->getCategory()->getLabel(), ENT_XML1, "UTF-8"); ?></category>
2121
<description><?php echo htmlentities(html_entity_decode($news_post->getContent(true), ENT_HTML5, "UTF-8"), ENT_XML1, "UTF-8"); ?></description>
2222
<pubDate><?php echo htmlentities($news_post->getPublishedDateTime()->format("r"), ENT_XML1, "UTF-8"); ?></pubDate>

src/templates/News/View.phtml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,26 @@ $description = Common::stripUpTo(trim(filter_var(
1919
FILTER_SANITIZE_STRING
2020
)), "\n", 300);
2121

22-
$this->opengraph->attach(new Pair("url", "/news/" . urlencode($object_id)));
2322
$this->opengraph->attach(new Pair("type", "article"));
23+
24+
$url = Common::relativeUrlToAbsolute("/news/" . urlencode($object_id));
25+
2426
if ($object) {
27+
28+
$url = $object->getURI();
29+
2530
$this->opengraph->attach(new Pair("image", "/a/news_categories/" . $object->getCategory()->getFilename()));
2631
$this->opengraph->attach(new Pair("article:published_time", $object->getCreatedDateTime()->format("c")));
2732
if (!is_null($object->getEditedDateTime())) {
2833
$this->opengraph->attach(new Pair("article:modified_time", $object->getEditedDateTime()->format("c")));
2934
}
3035
$this->opengraph->attach(new Pair("article:author:username", $object->getUser()->getName()));
3136
$this->opengraph->attach(new Pair("article:section", $object->getCategory()->getLabel()));
37+
3238
}
3339

34-
$url = Common::relativeUrlToAbsolute("/news/" . urlencode($object_id));
40+
$this->opengraph->attach(new Pair("url", $url));
41+
3542
$edit_url = Common::relativeUrlToAbsolute("/news/edit?id=" . urlencode($object_id));
3643
$delete_url = Common::relativeUrlToAbsolute("/news/delete?id=" . urlencode($object_id));
3744
$edit_visible = ($logged_in && ($logged_in->getOptionsBitmask()
@@ -40,7 +47,6 @@ $delete_visible = ($logged_in && ($logged_in->getOptionsBitmask()
4047
& User::OPTION_ACL_NEWS_DELETE));
4148

4249
if ($object) {
43-
$url .= "/" . Common::sanitizeForUrl($object->getTitle(), true);
4450
$user_name = $object->getUser()->getName();
4551
$user_id = $object->getUserId();
4652
$user_url = $object->getUser()->getURI();

src/templates/Packet/Index.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ require("./header.inc.phtml");
4949
$packet_id = $packet->getPacketId(true);
5050
?>
5151
<tr>
52-
<td><a href="<?php echo Common::relativeUrlToAbsolute("/packet/" . urlencode($packet->getId()) . "/" . Common::sanitizeForUrl($packet->getPacketName(), true)); ?>"><?php echo htmlspecialchars($packet->getPacketDirectionTag() . " " . $packet_id . " " . $packet->getPacketName(), ENT_HTML5, "UTF-8"); ?></a></td>
52+
<td><a href="<?php echo $packet->getURI(); ?>"><?php echo htmlspecialchars($packet->getPacketDirectionTag() . " " . $packet_id . " " . $packet->getPacketName(), ENT_HTML5, "UTF-8"); ?></a></td>
5353
<td><?php if ($user) { ?><a href="<?php echo $user_url; ?>"><img class="avatar" src="<?php echo $avatar_url; ?>"/> <?php echo htmlspecialchars($user->getName(), ENT_HTML5, "UTF-8"); ?></a><?php } else { ?>Anonymous<?php } ?></td>
5454
</tr>
5555
<?php } ?>

src/templates/Packet/View.phtml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ $description = "The requested packet does not exist or could not be found.";
1515
$this->opengraph->attach(new Pair("type", "article"));
1616

1717
$url = Common::relativeUrlToAbsolute("/packet/" . urlencode($object_id));
18+
1819
if ($object) {
19-
$url .= "/" . Common::sanitizeForUrl($object->getPacketName(), true);
20-
$this->opengraph->attach(new Pair("url", "/packet/" . urlencode($object_id)
21-
. "/" . Common::sanitizeForUrl($object->getPacketName(), true)));
2220

21+
$url = $object->getURI();
2322
$packet_id = $object->getPacketId(true);
2423

2524
$title = htmlspecialchars($object->getPacketDirectionTag(), ENT_HTML5, "UTF-8")
2625
. " " . $packet_id . " "
2726
. htmlspecialchars($object->getPacketName(), ENT_HTML5, "UTF-8");
27+
2828
$description = Common::stripUpTo(trim(filter_var(
2929
$object->getPacketRemarks(true), FILTER_SANITIZE_STRING
3030
)), "\n", 300);
@@ -41,10 +41,10 @@ if ($object) {
4141
$user_avatar = null;
4242
}
4343

44-
} else {
45-
$this->opengraph->attach(new Pair("url", "/packet/" . urlencode($object_id)));
4644
}
4745

46+
$this->opengraph->attach(new Pair("url", $url));
47+
4848
$this->additional_css[] = "/a/packet.css";
4949
$this->additional_css[] = "/a/comments.css";
5050
require("./header.inc.phtml");

src/templates/User/View.phtml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ $object = $this->getContext()->user;
1111

1212
$title = ($object ? $object->getName() : "User Not Found");
1313
$description = ($object ? $object->getName() . "'s user profile on BNETDocs" : "The requested user does not exist or could not be found.");
14-
$this->opengraph->attach(new Pair("url", "/user/" . urlencode($object_id)));
14+
1515
$this->opengraph->attach(new Pair("type", "profile"));
1616

17+
$url = Common::relativeUrlToAbsolute("/user/" . urlencode($object_id));
18+
1719
if ($object) {
20+
21+
$url = $object->getURI();
22+
1823
$this->opengraph->attach(new Pair("profile:username", $object->getName()));
1924

2025
$gravatar = new Gravatar($object->getEmail());
@@ -24,8 +29,11 @@ if ($object) {
2429

2530
if ($this->getContext()->biography) $description = $this->getContext()->biography;
2631
$safe_biography = htmlspecialchars($this->getContext()->biography, ENT_HTML5, "UTF-8");
32+
2733
}
2834

35+
$this->opengraph->attach(new Pair("url", $url));
36+
2937
$this->additional_css[] = "/a/userprofile.css";
3038
require("./header.inc.phtml");
3139
?>

0 commit comments

Comments
 (0)