2015-09-04 23:49:53 +00:00
|
|
|
<?php
|
2016-02-03 22:22:56 +00:00
|
|
|
/**
|
|
|
|
* Holds the url generation class.
|
2016-02-05 12:26:31 +00:00
|
|
|
*
|
2016-02-03 22:22:56 +00:00
|
|
|
* @package Sakura
|
|
|
|
*/
|
|
|
|
|
2015-09-04 23:49:53 +00:00
|
|
|
namespace Sakura;
|
|
|
|
|
2015-10-18 19:06:30 +00:00
|
|
|
/**
|
2016-02-02 21:04:15 +00:00
|
|
|
* Rewrite URL generator.
|
2016-02-05 12:26:31 +00:00
|
|
|
*
|
2015-10-18 19:06:30 +00:00
|
|
|
* @package Sakura
|
2016-02-02 21:04:15 +00:00
|
|
|
* @author Julian van de Groep <me@flash.moe>
|
2015-10-18 19:06:30 +00:00
|
|
|
*/
|
2015-09-14 20:51:23 +00:00
|
|
|
class Urls
|
|
|
|
{
|
2016-02-02 21:04:15 +00:00
|
|
|
/**
|
|
|
|
* Unformatted links
|
|
|
|
* 0 - Plain
|
|
|
|
* 1 - mod_rewrite
|
2016-02-05 12:26:31 +00:00
|
|
|
*
|
2016-02-02 21:04:15 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2015-09-04 23:49:53 +00:00
|
|
|
protected $urls = [
|
|
|
|
|
|
|
|
// General site sections
|
2015-09-14 21:41:43 +00:00
|
|
|
'SITE_HOME' => [
|
2016-01-30 13:25:18 +00:00
|
|
|
'/index.php',
|
2015-09-14 21:41:43 +00:00
|
|
|
'/',
|
|
|
|
],
|
|
|
|
'SITE_NEWS' => [
|
|
|
|
'/news.php',
|
|
|
|
'/news',
|
|
|
|
],
|
|
|
|
'SITE_NEWS_POST' => [
|
|
|
|
'/news.php?id=%u',
|
|
|
|
'/news/%u',
|
|
|
|
],
|
2016-01-09 21:57:54 +00:00
|
|
|
'SITE_NEWS_CAT' => [
|
|
|
|
'/news.php?cat=$s',
|
|
|
|
'/news/%s',
|
|
|
|
],
|
|
|
|
'SITE_NEWS_CAT_POST' => [
|
2016-01-30 13:25:18 +00:00
|
|
|
'/news.php?cat=%s&id=%u',
|
2016-01-09 21:57:54 +00:00
|
|
|
'/news/%s/%u',
|
|
|
|
],
|
2015-09-14 21:41:43 +00:00
|
|
|
'SITE_SEARCH' => [
|
|
|
|
'/search.php',
|
|
|
|
'/search',
|
|
|
|
],
|
|
|
|
'SITE_PREMIUM' => [
|
|
|
|
'/support.php',
|
|
|
|
'/support',
|
|
|
|
],
|
|
|
|
'SITE_DONATE_TRACK' => [
|
|
|
|
'/support.php?tracker=true',
|
|
|
|
'/support/tracker',
|
|
|
|
],
|
|
|
|
'SITE_FAQ' => [
|
|
|
|
'/faq.php',
|
|
|
|
'/faq',
|
|
|
|
],
|
|
|
|
'SITE_LOGIN' => [
|
2016-02-05 12:26:31 +00:00
|
|
|
'/authenticate.php?ref=login',
|
2015-09-14 21:41:43 +00:00
|
|
|
'/login',
|
|
|
|
],
|
|
|
|
'SITE_LOGOUT' => [
|
2016-02-05 12:26:31 +00:00
|
|
|
'/authenticate.php?ref=logout',
|
2015-09-14 21:41:43 +00:00
|
|
|
'/logout',
|
|
|
|
],
|
|
|
|
'SITE_REGISTER' => [
|
2016-02-05 12:26:31 +00:00
|
|
|
'/authenticate.php?ref=register',
|
2015-09-14 21:41:43 +00:00
|
|
|
'/register',
|
|
|
|
],
|
|
|
|
'SITE_FORGOT_PASSWORD' => [
|
2016-02-05 12:26:31 +00:00
|
|
|
'/authenticate.php?ref=forgotpassword',
|
2015-09-14 21:41:43 +00:00
|
|
|
'/forgotpassword',
|
|
|
|
],
|
|
|
|
'SITE_ACTIVATE' => [
|
2016-02-05 12:26:31 +00:00
|
|
|
'/authenticate.php?ref=activate',
|
2015-09-14 21:41:43 +00:00
|
|
|
'/activate',
|
|
|
|
],
|
|
|
|
'INFO_PAGE' => [
|
|
|
|
'/index.php?p=%s',
|
|
|
|
'/p/%s',
|
|
|
|
],
|
|
|
|
'AUTH_ACTION' => [
|
|
|
|
'/authenticate.php',
|
|
|
|
'/authenticate',
|
|
|
|
],
|
2015-09-05 16:11:04 +00:00
|
|
|
|
|
|
|
// Memberlist
|
2015-09-14 21:41:43 +00:00
|
|
|
'MEMBERLIST_INDEX' => [
|
|
|
|
'/members.php',
|
|
|
|
'/members',
|
|
|
|
],
|
|
|
|
'MEMBERLIST_SORT' => [
|
|
|
|
'/members.php?sort=%s',
|
|
|
|
'/members/%s',
|
|
|
|
],
|
|
|
|
'MEMBERLIST_RANK' => [
|
|
|
|
'/members.php?rank=%u',
|
|
|
|
'/members/%u',
|
|
|
|
],
|
|
|
|
'MEMBERLIST_PAGE' => [
|
|
|
|
'/members.php?page=%u',
|
2015-11-15 21:43:39 +00:00
|
|
|
'/members?page=%u',
|
2015-09-14 21:41:43 +00:00
|
|
|
],
|
2015-11-15 21:43:39 +00:00
|
|
|
'MEMBERLIST_ALL' => [
|
2015-09-14 21:41:43 +00:00
|
|
|
'/members.php?sort=%s&rank=%u',
|
|
|
|
'/members/%s/%u',
|
|
|
|
],
|
2015-09-04 23:49:53 +00:00
|
|
|
|
|
|
|
// Forums
|
2015-09-14 21:41:43 +00:00
|
|
|
'FORUM_INDEX' => [
|
|
|
|
'/index.php?forum=true',
|
|
|
|
'/forum',
|
|
|
|
],
|
|
|
|
'FORUM_SUB' => [
|
|
|
|
'/viewforum.php?f=%u',
|
|
|
|
'/forum/%u',
|
|
|
|
],
|
2015-11-21 15:27:37 +00:00
|
|
|
'FORUM_MARK_READ' => [
|
|
|
|
'/viewforum.php?f=%u&read=true&session=%s',
|
|
|
|
'/forum/%u?read=true&session=%s',
|
|
|
|
],
|
2015-09-14 21:41:43 +00:00
|
|
|
'FORUM_THREAD' => [
|
|
|
|
'/viewtopic.php?t=%u',
|
|
|
|
'/forum/thread/%u',
|
|
|
|
],
|
|
|
|
'FORUM_POST' => [
|
|
|
|
'/viewtopic.php?p=%u',
|
|
|
|
'/forum/post/%u',
|
|
|
|
],
|
|
|
|
'FORUM_REPLY' => [
|
|
|
|
'/posting.php?t=%u',
|
|
|
|
'/forum/thread/%u/reply',
|
|
|
|
],
|
|
|
|
'FORUM_NEW_THREAD' => [
|
|
|
|
'/posting.php?f=%u',
|
|
|
|
'/forum/%u/new',
|
|
|
|
],
|
|
|
|
'FORUM_EDIT_POST' => [
|
|
|
|
'/posting.php?p=%1$u&edit=%1$u',
|
|
|
|
'/forum/post/%u/edit',
|
|
|
|
],
|
|
|
|
'FORUM_DELETE_POST' => [
|
|
|
|
'/posting.php?p=%1$u&delete=%1$u',
|
|
|
|
'/forum/post/%u/delete',
|
|
|
|
],
|
|
|
|
'FORUM_QUOTE_POST' => [
|
|
|
|
'/posting.php?p=%1$u"e=%1$u',
|
|
|
|
'/forum/post/%u/quote',
|
|
|
|
],
|
2016-01-10 18:24:47 +00:00
|
|
|
'FORUM_LOCK' => [
|
|
|
|
'/viewtopic.php?t=%u&lock=%s',
|
|
|
|
'/forum/thread/%u?lock=%s',
|
|
|
|
],
|
|
|
|
'FORUM_STICKY' => [
|
|
|
|
'/viewtopic.php?t=%u&sticky=%s',
|
|
|
|
'/forum/thread/%u?sticky=%s',
|
|
|
|
],
|
|
|
|
'FORUM_ANNOUNCE' => [
|
|
|
|
'/viewtopic.php?t=%u&announce=%s',
|
|
|
|
'/forum/thread/%u?announce=%s',
|
|
|
|
],
|
|
|
|
'FORUM_RESTORE' => [
|
|
|
|
'/viewtopic.php?t=%u&restore=%s',
|
|
|
|
'/forum/thread/%u?restore=%s',
|
|
|
|
],
|
|
|
|
'FORUM_TRASH' => [
|
|
|
|
'/viewtopic.php?t=%u&trash=%s',
|
|
|
|
'/forum/thread/%u?trash=%s',
|
|
|
|
],
|
|
|
|
'FORUM_PRUNE' => [
|
|
|
|
'/viewtopic.php?t=%u&prune=%s',
|
|
|
|
'/forum/thread/%u?prune=%s',
|
|
|
|
],
|
2015-09-04 23:49:53 +00:00
|
|
|
|
|
|
|
// Image serve references
|
2015-09-14 21:41:43 +00:00
|
|
|
'IMAGE_AVATAR' => [
|
|
|
|
'/imageserve.php?m=avatar&u=%u',
|
|
|
|
'/a/%u',
|
|
|
|
],
|
|
|
|
'IMAGE_BACKGROUND' => [
|
|
|
|
'/imageserve.php?m=background&u=%u',
|
|
|
|
'/bg/%u',
|
|
|
|
],
|
|
|
|
'IMAGE_HEADER' => [
|
|
|
|
'/imageserve.php?m=header&u=%u',
|
|
|
|
'/u/%u/header',
|
|
|
|
],
|
2015-09-04 23:49:53 +00:00
|
|
|
|
|
|
|
// User actions
|
2015-09-14 21:41:43 +00:00
|
|
|
'USER_LOGOUT' => [
|
|
|
|
'/authenticate.php?mode=logout&time=%u&session=%s&redirect=%s',
|
|
|
|
'/logout?mode=logout&time=%u&session=%s&redirect=%s',
|
|
|
|
],
|
|
|
|
'USER_REPORT' => [
|
|
|
|
'/report.php?mode=user&u=%u',
|
|
|
|
'/u/%u/report',
|
|
|
|
],
|
|
|
|
'USER_PROFILE' => [
|
|
|
|
'/profile.php?u=%s',
|
|
|
|
'/u/%s',
|
|
|
|
],
|
2015-10-06 21:05:39 +00:00
|
|
|
'USER_COMMENTS' => [
|
|
|
|
'/profile.php?u=%u&view=comments',
|
|
|
|
'/u/%u/comments',
|
|
|
|
],
|
2015-10-12 18:25:37 +00:00
|
|
|
'USER_FRIENDS' => [
|
|
|
|
'/profile.php?u=%u&view=friends',
|
|
|
|
'/u/%u/friends',
|
|
|
|
],
|
|
|
|
'USER_GROUPS' => [
|
|
|
|
'/profile.php?u=%u&view=groups',
|
|
|
|
'/u/%u/groups',
|
|
|
|
],
|
|
|
|
'USER_THREADS' => [
|
|
|
|
'/profile.php?u=%u&view=threads',
|
|
|
|
'/u/%u/threads',
|
|
|
|
],
|
|
|
|
'USER_POSTS' => [
|
|
|
|
'/profile.php?u=%u&view=posts',
|
|
|
|
'/u/%u/posts',
|
|
|
|
],
|
2015-09-14 21:41:43 +00:00
|
|
|
'USER_GROUP' => [
|
|
|
|
'/group.php?g=%u',
|
|
|
|
'/g/%u',
|
|
|
|
],
|
2015-09-04 23:49:53 +00:00
|
|
|
|
|
|
|
// Settings urls
|
2015-09-14 21:41:43 +00:00
|
|
|
'SETTINGS_INDEX' => [
|
|
|
|
'/settings.php',
|
|
|
|
'/settings',
|
|
|
|
],
|
|
|
|
'SETTING_CAT' => [
|
|
|
|
'/settings.php?cat=%s',
|
|
|
|
'/settings/%s',
|
|
|
|
],
|
|
|
|
'SETTING_MODE' => [
|
|
|
|
'/settings.php?cat=%s&mode=%s',
|
|
|
|
'/settings/%s/%s',
|
|
|
|
],
|
2015-10-11 22:11:18 +00:00
|
|
|
'REQUEST_NOTIFICATIONS' => [
|
|
|
|
'/settings.php?request-notifications=true',
|
|
|
|
'/notifications',
|
|
|
|
],
|
2015-09-04 23:49:53 +00:00
|
|
|
|
|
|
|
// Friend Actions
|
2015-09-14 21:41:43 +00:00
|
|
|
'FRIEND_ACTION' => [
|
|
|
|
'/settings.php?friend-action=true',
|
|
|
|
'/friends',
|
|
|
|
],
|
|
|
|
'FRIEND_ADD' => [
|
|
|
|
'/settings.php?friend-action=true&add=%u&session=%s&time=%u&redirect=%s',
|
|
|
|
'/friends?add=%u&session=%s&time=%u&redirect=%s',
|
|
|
|
],
|
|
|
|
'FRIEND_REMOVE' => [
|
|
|
|
'/settings.php?friend-action=true&remove=%u&session=%s&time=%u&redirect=%s',
|
|
|
|
'/friends?remove=%u&session=%s&time=%u&redirect=%s',
|
|
|
|
],
|
2015-09-04 23:49:53 +00:00
|
|
|
|
|
|
|
// Manage urls
|
2015-09-14 21:41:43 +00:00
|
|
|
'MANAGE_INDEX' => [
|
|
|
|
'/manage.php',
|
|
|
|
'/manage',
|
|
|
|
],
|
|
|
|
'MANAGE_CAT' => [
|
|
|
|
'/manage.php?cat=%s',
|
|
|
|
'/manage/%s',
|
|
|
|
],
|
|
|
|
'MANAGE_MODE' => [
|
|
|
|
'/manage.php?cat=%s&mode=%s',
|
|
|
|
'/manage/%s/%s',
|
|
|
|
],
|
2015-09-04 23:49:53 +00:00
|
|
|
|
2015-09-18 21:56:54 +00:00
|
|
|
// Comments urls
|
|
|
|
'COMMENT_POST' => [
|
|
|
|
'/settings.php?comment-action=true',
|
|
|
|
'/comments',
|
|
|
|
],
|
2015-10-10 21:17:50 +00:00
|
|
|
'COMMENT_VOTE' => [
|
|
|
|
'/settings.php?comment-action=true&id=%u&mode=vote&state=%u&category=%s&session=%s',
|
|
|
|
'/comments?id=%u&mode=vote&state=%u&category=%s&session=%s',
|
2015-09-18 21:56:54 +00:00
|
|
|
],
|
|
|
|
'COMMENT_DELETE' => [
|
2015-10-10 15:51:24 +00:00
|
|
|
'/settings.php?comment-action=true&id=%u&category=%s&mode=delete&session=%s',
|
|
|
|
'/comments?id=%u&mode=delete&category=%s&session=%s',
|
2015-09-18 21:56:54 +00:00
|
|
|
],
|
|
|
|
|
2015-09-04 23:49:53 +00:00
|
|
|
];
|
|
|
|
|
2016-02-02 21:04:15 +00:00
|
|
|
/**
|
|
|
|
* Format a URL.
|
2016-02-05 12:26:31 +00:00
|
|
|
*
|
2016-02-02 21:04:15 +00:00
|
|
|
* @param string $lid The ID of a URL.
|
|
|
|
* @param array $args Additional arguments.
|
|
|
|
* @param bool $rewrite Toggle mod_rewrite.
|
2016-02-05 12:26:31 +00:00
|
|
|
*
|
2016-02-02 21:04:15 +00:00
|
|
|
* @return null|string The formatted URL.
|
|
|
|
*/
|
2016-03-28 01:18:59 +00:00
|
|
|
public function format($lid, $args = [], $rewrite = null, $b = true)
|
2015-09-14 20:51:23 +00:00
|
|
|
{
|
2015-09-04 23:49:53 +00:00
|
|
|
|
|
|
|
// Check if the requested url exists
|
2015-09-14 20:51:23 +00:00
|
|
|
if (!array_key_exists($lid, $this->urls)) {
|
2015-09-04 23:49:53 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-03-28 01:18:59 +00:00
|
|
|
if ($b && ($lid === 'SETTING_CAT' || $lid === 'SETTING_MODE')) {
|
|
|
|
if (in_array('messages', $args)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($lid === 'SETTING_CAT') {
|
|
|
|
return Router::route("settings.{$args[0]}");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($lid === 'SETTING_MODE') {
|
|
|
|
$a = implode('.', $args);
|
|
|
|
$a = str_replace("usertitle", "title", $a);
|
|
|
|
return Router::route("settings.{$a}");
|
|
|
|
}
|
|
|
|
}
|
2015-09-04 23:49:53 +00:00
|
|
|
|
|
|
|
// Format urls
|
2016-03-28 01:18:59 +00:00
|
|
|
$formatted = vsprintf($this->urls[$lid][0], $args);
|
2015-09-04 23:49:53 +00:00
|
|
|
|
|
|
|
// Return the formatted url
|
|
|
|
return $formatted;
|
|
|
|
}
|
|
|
|
}
|