2015-09-04 23:49:53 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* URL management
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Sakura;
|
|
|
|
|
2015-09-14 20:51:23 +00:00
|
|
|
class Urls
|
|
|
|
{
|
2015-09-04 23:49:53 +00:00
|
|
|
// Unformatted links [0] = no mod_rewrite, [1] = mod_rewrite
|
|
|
|
protected $urls = [
|
|
|
|
|
|
|
|
// General site sections
|
2015-09-14 21:41:43 +00:00
|
|
|
'SITE_HOME' => [
|
|
|
|
'/',
|
|
|
|
'/',
|
|
|
|
],
|
|
|
|
'SITE_NEWS' => [
|
|
|
|
'/news.php',
|
|
|
|
'/news',
|
|
|
|
],
|
|
|
|
'SITE_NEWS_PAGE' => [
|
|
|
|
'/news.php?page=%u',
|
|
|
|
'/news/p%u',
|
|
|
|
],
|
|
|
|
'SITE_NEWS_POST' => [
|
|
|
|
'/news.php?id=%u',
|
|
|
|
'/news/%u',
|
|
|
|
],
|
|
|
|
'SITE_NEWS_RSS' => [
|
|
|
|
'/news.php?xml=true',
|
|
|
|
'/news.xml',
|
|
|
|
],
|
|
|
|
'SITE_SEARCH' => [
|
|
|
|
'/search.php',
|
|
|
|
'/search',
|
|
|
|
],
|
|
|
|
'SITE_PREMIUM' => [
|
|
|
|
'/support.php',
|
|
|
|
'/support',
|
|
|
|
],
|
|
|
|
'SITE_DONATE_TRACK' => [
|
|
|
|
'/support.php?tracker=true',
|
|
|
|
'/support/tracker',
|
|
|
|
],
|
|
|
|
'SITE_DONATE_TRACK_PAGE' => [
|
|
|
|
'/support.php?tracker=true&page=%u',
|
|
|
|
'/support/tracker/%u',
|
|
|
|
],
|
|
|
|
'SITE_FAQ' => [
|
|
|
|
'/faq.php',
|
|
|
|
'/faq',
|
|
|
|
],
|
|
|
|
'SITE_LOGIN' => [
|
|
|
|
'/authenticate.php',
|
|
|
|
'/login',
|
|
|
|
],
|
|
|
|
'SITE_LOGOUT' => [
|
|
|
|
'/authenticate.php',
|
|
|
|
'/logout',
|
|
|
|
],
|
|
|
|
'SITE_REGISTER' => [
|
|
|
|
'/authenticate.php',
|
|
|
|
'/register',
|
|
|
|
],
|
|
|
|
'SITE_FORGOT_PASSWORD' => [
|
|
|
|
'/authenticate.php',
|
|
|
|
'/forgotpassword',
|
|
|
|
],
|
|
|
|
'SITE_ACTIVATE' => [
|
|
|
|
'/authenticate.php',
|
|
|
|
'/activate',
|
|
|
|
],
|
|
|
|
'CHANGELOG' => [
|
|
|
|
'/changelog.php',
|
|
|
|
'/changelog',
|
|
|
|
],
|
|
|
|
'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',
|
|
|
|
'/members/p%u',
|
|
|
|
],
|
|
|
|
'MEMBERLIST_SORT_RANK' => [
|
|
|
|
'/members.php?sort=%s&rank=%u',
|
|
|
|
'/members/%s/%u',
|
|
|
|
],
|
|
|
|
'MEMBERLIST_RANK_PAGE' => [
|
|
|
|
'/members.php?rank=%u&page=%u',
|
|
|
|
'/members/%u/p%u',
|
|
|
|
],
|
|
|
|
'MEMBERLIST_SORT_PAGE' => [
|
|
|
|
'/members.php?sort=%s&page=%u',
|
|
|
|
'/members/%s/p%u',
|
|
|
|
],
|
|
|
|
'MEMBERLIST_ALL' => [
|
|
|
|
'/members.php?sort=%s&rank=%u&page=%u',
|
|
|
|
'/members/%s/%u/p%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',
|
|
|
|
],
|
|
|
|
'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',
|
|
|
|
],
|
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',
|
|
|
|
],
|
|
|
|
'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-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
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
// Get a formatted url
|
2015-09-14 20:51:23 +00:00
|
|
|
public function format($lid, $args = [], $rewrite = null)
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if mod_rewrite is enabled
|
|
|
|
$rewrite = ($rewrite === null ? Configuration::getConfig('url_rewrite') : $rewrite) ? 1 : 0;
|
|
|
|
|
|
|
|
// Format urls
|
2015-09-14 20:51:23 +00:00
|
|
|
$formatted = vsprintf($this->urls[$lid][$rewrite], $args);
|
2015-09-04 23:49:53 +00:00
|
|
|
|
|
|
|
// Return the formatted url
|
|
|
|
return $formatted;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|