89 lines
4.1 KiB
PHP
89 lines
4.1 KiB
PHP
|
<?php
|
||
|
/*
|
||
|
* URL management
|
||
|
*/
|
||
|
|
||
|
namespace Sakura;
|
||
|
|
||
|
class Urls {
|
||
|
|
||
|
// Unformatted links [0] = no mod_rewrite, [1] = mod_rewrite
|
||
|
protected $urls = [
|
||
|
|
||
|
// General site sections
|
||
|
'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_MEMBERS' => ['/members.php', '/members'],
|
||
|
'SITE_PREMIUM' => ['/support.php', '/support'],
|
||
|
'SITE_FAQ' => ['/faq.php', '/faq'],
|
||
|
'SITE_LOGIN' => ['/authenticate.php', '/login'],
|
||
|
'SITE_REGISTER' => ['/authenticate.php', '/register'],
|
||
|
'CHANGELOG' => ['/changelog.php', '/changelog'],
|
||
|
'INFO_PAGE' => ['/index.php?p=%s', '/p/%s'],
|
||
|
'AUTH_ACTION' => ['/authenticate.php', '/authenticate'],
|
||
|
|
||
|
// Forums
|
||
|
'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'],
|
||
|
|
||
|
// Image serve references
|
||
|
'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'],
|
||
|
|
||
|
// User actions
|
||
|
'USER_LOGOUT' => ['/authenticate.php?mode=logout&time=%u&session=%s&redirect=%s', '/logout?mode=logout&time=%u&session=%s&redirect=%s'],
|
||
|
'USER_PROFILE' => ['/profile.php?u=%s', '/u/%s'],
|
||
|
'USER_REPORT' => ['/report.php?mode=user&u=%u', '/u/%u/report'],
|
||
|
|
||
|
// Settings urls
|
||
|
'SETTINGS_INDEX' => ['/settings.php', '/settings'],
|
||
|
'SETTING_CAT' => ['/settings.php?cat=%s', '/settings/%s'],
|
||
|
'SETTING_MODE' => ['/settings.php?cat=%s&mode=%s', '/settings/%s/%s'],
|
||
|
'MESSAGES_INDEX' => ['/settings.php?cat=messages', '/messages'],
|
||
|
'MESSAGES_MODE' => ['/settings.php?cat=messages&mode=%s', '/messages/%s'],
|
||
|
|
||
|
// Friend Actions
|
||
|
'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'],
|
||
|
|
||
|
// Manage urls
|
||
|
'MANAGE_INDEX' => ['/manage.php', '/manage']
|
||
|
|
||
|
];
|
||
|
|
||
|
// Get a formatted url
|
||
|
public function format($id, $args = [], $rewrite = null) {
|
||
|
|
||
|
// Check if the requested url exists
|
||
|
if(!array_key_exists($id, $this->urls)) {
|
||
|
|
||
|
return null;
|
||
|
|
||
|
}
|
||
|
|
||
|
// Check if mod_rewrite is enabled
|
||
|
$rewrite = ($rewrite === null ? Configuration::getConfig('url_rewrite') : $rewrite) ? 1 : 0;
|
||
|
|
||
|
// Format urls
|
||
|
$formatted = vsprintf($this->urls[$id][$rewrite], $args);
|
||
|
|
||
|
// Return the formatted url
|
||
|
return $formatted;
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|