Skip to content
This repository has been archived by the owner on Jan 25, 2021. It is now read-only.

Commit

Permalink
Friendly URLs [almost] everywhere! (close #3)
Browse files Browse the repository at this point in the history
But halt! Further improvement is coming! Some old-fashioned URLs
(index.php?module=xxxx&id=x) are still there!! I need to program some
patterns to modify the controllers (e.g.: variables like ID, instead of
t_id, p_id, m_id, etc).
  • Loading branch information
brunnopleffken committed Feb 13, 2015
1 parent f1bb536 commit 99b74e6
Show file tree
Hide file tree
Showing 21 changed files with 107 additions and 76 deletions.
30 changes: 30 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<IfModule mod_rewrite.c>
RewriteEngine On

# AdminCP is... well... admin! Do not rewrite it!
RewriteRule ^(admin|user)($|/) - [L]

# /logout is not a controller, just a shortcut
RewriteRule ^(logout)$ index.php?module=login&act=logout
RewriteRule ^(logout)/$ index.php?module=login&act=logout

# /foo = index.php?module=foo
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?module=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?module=$1

# /foo/2 = index.php?module=foo&id=2
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)$ index.php?module=$1&id=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)/$ index.php?module=$1&id=$2

# /foo/bar = index.php?module=foo&view=bar
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z]+)$ index.php?module=$1&view=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z]+)/$ index.php?module=$1&view=$2

# /foo/2/bar = index.php?module=foo&id=2&act=bar
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)/([a-zA-Z0-9_-]+)$ index.php?module=$1&id=$2&act=$3
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)/([a-zA-Z0-9_-]+)/$ index.php?module=$1&id=$2&act=$3

# Thread specific URLs (SEO friendly)
# /thread/1-lorem-ipsum-dolor-sit-amet = index.php?module=thread&id=1
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)\-([a-zA-Z0-9-]+)$ index.php?module=$1&id=$2
</IfModule>
10 changes: 5 additions & 5 deletions controllers/community.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

## ---------------------------------------------------
# ADDICTIVE COMMUNITY
## ---------------------------------------------------
Expand All @@ -25,9 +25,9 @@
// ---------------------------------------------------
// Get room list
// ---------------------------------------------------

// If member is Admin, show invisible rooms too

if($this->member['usergroup'] != 1) {
$visibility = "WHERE invisible = '0'";
}
Expand Down Expand Up @@ -64,7 +64,7 @@
}
else {
$result['icon'] = "<i class=\"fa fa-comment-o fa-fw fleft\"></i>";
$result['title'] = "<a href=\"index.php?module=thread&amp;id={$result['t_id']}\">{$result['title']}</a>";
$result['title'] = "<a href=\"thread/{$result['t_id']}\">{$result['title']}</a>";
}

// Store result in array
Expand All @@ -80,4 +80,4 @@
$pageinfo['title'] = "";
$pageinfo['bc'] = array();

?>
?>
2 changes: 1 addition & 1 deletion controllers/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
ORDER BY s.activity_time DESC;");

while($members = $this->Db->Fetch($members_online)) {
$online[] = "<a href=\"index.php?module=profile&amp;id={$members['member_id']}\">{$members['username']}</a>";
$online[] = "<a href=\"profile/{$members['member_id']}\">{$members['username']}</a>";
}

$memberCount = count($online);
Expand Down
5 changes: 3 additions & 2 deletions controllers/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
header("Location: " . getenv("HTTP_REFERER"));
}
else {
header("Location: index.php");
header("Location: " . $this->Core->config['general_communityurl']);
}
}
else {
Expand All @@ -55,6 +55,7 @@
break;

case "logout":

// Get referrer URL and member ID
$from = getenv('HTTP_REFERER');
$m_id = $this->member['m_id'];
Expand All @@ -63,7 +64,7 @@
$this->Session->DestroySession($m_id);

// Redirect
header("Location: " . $from);
header("Location: " . $this->Core->config['general_communityurl']);

exit;
break;
Expand Down
8 changes: 4 additions & 4 deletions controllers/messenger.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,24 +155,24 @@
// Read message
// ---------------------------------------------------

$read = Html::Request("read");
$id = Html::Request("id");

if($read) {
if($id) {
// Hide "inbox" view
$view = null;

// Get message info and post
$this->Db->Query("SELECT p.*, m.username, m.signature, m.member_title, m.email, m.photo, m.photo_type
FROM c_messages p LEFT JOIN c_members m ON (p.from_id = m.m_id)
WHERE pm_id = {$read} AND to_id = " . $this->member['m_id'] . ";");
WHERE pm_id = {$id} AND to_id = " . $this->member['m_id'] . ";");

if($this->Db->Rows() == 1) {
$message = $this->Db->Fetch();

// If not, set message as read
if($message['status'] == 1) {
$time = time();
$this->Db->Query("UPDATE c_messages SET status = 0, read_date = {$time} WHERE pm_id = {$read}");
$this->Db->Query("UPDATE c_messages SET status = 0, read_date = {$time} WHERE pm_id = {$id}");
}

// Format content
Expand Down
4 changes: 2 additions & 2 deletions controllers/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@

Template::Add ("<tr>
<td class=\"tLabel\">{$threads['start_date']}</td>
<td><a href=\"index.php?module=thread&amp;id={$threads['t_id']}\">{$threads['title']}</a></td>
<td><a href=\"thread/{$threads['t_id']}\">{$threads['title']}</a></td>
</tr>");
}

Expand All @@ -111,7 +111,7 @@

Template::Add("<tr>
<td class=\"tLabel\">{$posts['post_date']}</td>
<td><a href=\"index.php?module=thread&amp;id={$posts['t_id']}\"><b>{$posts['title']}</b></a></td>
<td><a href=\"thread/{$posts['t_id']}\"><b>{$posts['title']}</b></a></td>
</tr>
<tr>
<td colspan=\"2\" class=\"parsing\" style=\"border-bottom: 1px solid #eee; padding: 10px 10px 20px 10px\">{$posts['post']}</td>
Expand Down
6 changes: 3 additions & 3 deletions controllers/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@
);

// Find for already registered email address
$this->Db->Query("SELECT email FROM c_members "
. "WHERE email = '{$registerInfo['email']}' OR "
. "username = '{$registerInfo['username']}';");
$this->Db->Query("SELECT email FROM c_members
WHERE email = '{$registerInfo['email']}' OR
username = '{$registerInfo['username']}';");
$emailExistsCount = $this->Db->Rows();

if($emailExistsCount > 0) {
Expand Down
4 changes: 2 additions & 2 deletions controllers/thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,11 @@
if($threadInfo['author_member_id'] == $this->member['m_id'] && $result['author_id'] != $this->member['m_id']) {
if($result['best_answer'] == 0) {
// Set post as Best Answer
$result['thread_controls'] = "<a href='?module=thread&amp;act=setbestanswer&amp;id={$result['p_id']}' class='smallButton grey transition'>" . i18n::Translate("T_BEST_SET") . "</a>";
$result['thread_controls'] = "<a href='thread/{$result['p_id']}/setbestanswer' class='smallButton grey transition'>" . i18n::Translate("T_BEST_SET") . "</a>";
}
else {
// Unset post as Best Answer
$result['thread_controls'] = "<a href='?module=thread&amp;act=unsetbestanswer&amp;id={$result['p_id']}' class='smallButton grey transition'>" . i18n::Translate("T_BEST_UNSET") . "</a>";
$result['thread_controls'] = "<a href='thread/{$result['p_id']}/unsetbestanswer' class='smallButton grey transition'>" . i18n::Translate("T_BEST_UNSET") . "</a>";
}
}

Expand Down
5 changes: 3 additions & 2 deletions templates/default/ajax.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title><?php __($this->Core->config['general_communityname']) ?> (Powered by Addictive Community)</title>
<base href="<?php echo $this->Core->config['general_communityurl'] ?>">
<script src="resources/main.js" type="text/javascript"></script>
</head>
<body>

<?php __($this->content) ?>

</body>
</html>
</html>
4 changes: 2 additions & 2 deletions templates/default/calendar.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

<div class="fright">
<form>
<input type="button" onclick="window.location.href='?module=calendar&view=addevent'" value="<?php __("C_ADD") ?>">
<input type="button" onclick="window.location.href='?module=calendar'" value="<?php __("C_SHOW") ?>">
<input type="button" onclick="window.location.href='calendar/addevent'" value="<?php __("C_ADD") ?>">
<input type="button" onclick="window.location.href='calendar'" value="<?php __("C_SHOW") ?>">
</form>
</div>

Expand Down
4 changes: 2 additions & 2 deletions templates/default/community.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<tr>
<td class="image"><?php __($_rooms[$k]['icon']) ?></td>
<td class="info">
<a href="?module=room&amp;id=<?php __($_rooms[$k]['r_id']) ?>" class="title"><?php __($_rooms[$k]['name']) ?></a>
<a href="room/<?php __($_rooms[$k]['r_id']) ?>" class="title"><?php __($_rooms[$k]['name']) ?></a>
<p class="description"><?php __($_rooms[$k]['description']) ?></p>
<div class="lastPost">
<span><i class="fa fa-comment"></i>&nbsp; <?php __($_rooms[$k]['title']) ?></span>
<span><i class="fa fa-user"></i>&nbsp; <a href="?module=profile&amp;id=<?php __($_rooms[$k]['lastpost_member']) ?>"><?php __($_rooms[$k]['username']) ?></a></span>
<span><i class="fa fa-user"></i>&nbsp; <a href="profile/<?php __($_rooms[$k]['lastpost_member']) ?>"><?php __($_rooms[$k]['username']) ?></a></span>
<span><i class="fa fa-clock-o"></i>&nbsp; <?php __($_rooms[$k]['lastpost_date']) ?></span>
</div>
</td>
Expand Down
23 changes: 12 additions & 11 deletions templates/default/default.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<meta charset="utf-8">
<title><?php echo $html['title'] . $this->Core->config['general_communityname'] ?> (Powered by Addictive Community)</title>
<base href="<?php echo $this->Core->config['general_communityurl'] ?>">
<!-- META -->
<meta name="generator" content="Addictive Community <?php VERSION ?>">
<meta name="description" content="<?php echo $this->Core->config['seo_description'] ?>">
Expand Down Expand Up @@ -35,18 +36,18 @@
<?php if($this->member['usergroup'] == 1): ?>
<a href="admin/" target="_blank" class="transition">Admin CP</a>
<?php endif; ?>
<a href="?module=search" class="transition"><?php __("SEARCH") ?></a>
<a href="?module=members" class="transition"><?php __("MEMBERLIST") ?></a>
<a href="?module=calendar" class="transition"><?php __("CALENDAR") ?></a>
<a href="?module=help" class="transition"><?php __("HELP") ?></a>
<a href="search" class="transition"><?php __("SEARCH") ?></a>
<a href="members" class="transition"><?php __("MEMBERLIST") ?></a>
<a href="calendar" class="transition"><?php __("CALENDAR") ?></a>
<a href="help" class="transition"><?php __("HELP") ?></a>
</div>
<div class="fix"></div>
</div>
</div>

<div id="logo">
<div class="wrapper">
<a href="index.php"><img src="<?php echo $this->p['IMG'] . "/" . $this->Core->config['general_communitylogo'] ?>" class="logo" alt="<?php echo $this->Core->config['general_communityname'] ?>"></a>
<a href="#"><img src="<?php echo $this->p['IMG'] . "/" . $this->Core->config['general_communitylogo'] ?>" class="logo" alt="<?php echo $this->Core->config['general_communityname'] ?>"></a>
<div id="search">
<form action="index.php" method="get" class="validate">
<input type="text" name="q" size="25" class="required" value="<?php echo Html::Request("q") ?>" placeholder="<?php __("SEARCH_BOX") ?>">
Expand All @@ -58,7 +59,7 @@
</div>

<div class="wrapper">
<div id="breadcrumb"><a href="index.php"><?php echo $this->Core->config['general_communityname'] ?></a> <?php echo $html['breadcrumb'] ?></div>
<div id="breadcrumb"><a href="#"><?php echo $this->Core->config['general_communityname'] ?></a> <?php echo $html['breadcrumb'] ?></div>
</div>

<div class="wrapper">
Expand All @@ -71,7 +72,7 @@
<div class="user">
<div class="userInfo">
<b><?php __("SIDEBAR_WELCOME") ?></b><br>
<a class="fancybox fancybox.ajax" href="?module=login"><?php __("SIDEBAR_LOGIN") ?></a> | <a href="?module=register" class="highlight"><?php __("SIDEBAR_C_ACCOUNT") ?></a>
<a class="fancybox fancybox.ajax" href="login"><?php __("SIDEBAR_LOGIN") ?></a> | <a href="register" class="highlight"><?php __("SIDEBAR_C_ACCOUNT") ?></a>
</div>
</div>
</div>
Expand All @@ -82,8 +83,8 @@
<?php __(Html::Crop($this->member['avatar'], 30, 30, "img")) ?>
</div>
<div class="userInfo">
<b><a href="?module=profile&amp;id=<?php echo $this->member['m_id'] ?>" title="<?php __("SIDEBAR_PROFILE", array($this->member['username'])) ?>"><?php __($this->member['username']) ?></a></b><br>
<a href="?module=usercp"><?php __("SIDEBAR_USERCP") ?></a> | <a href="?module=messenger"><?php __("SIDEBAR_INBOX", array($unreadMessages['total'])) ?></a> | <a href="?module=login&amp;act=logout"><?php __("SIDEBAR_LOGOUT") ?></a>
<b><a href="profile/<?php echo $this->member['m_id'] ?>" title="<?php __("SIDEBAR_PROFILE", array($this->member['username'])) ?>"><?php __($this->member['username']) ?></a></b><br>
<a href="usercp"><?php __("SIDEBAR_USERCP") ?></a> | <a href="messenger"><?php __("SIDEBAR_INBOX", array($unreadMessages['total'])) ?></a> | <a href="logout"><?php __("SIDEBAR_LOGOUT") ?></a>
</div>
</div>
</div>
Expand All @@ -94,7 +95,7 @@
<div class="list">
<?php foreach($_siderooms as $k => $v): ?>
<div class="item transition">
<a href="?module=room&amp;id=<?php echo $_siderooms[$k]['r_id'] ?>">
<a href="room/<?php echo $_siderooms[$k]['r_id'] ?>">
<?php echo $_siderooms[$k]['name'] ?>
</a>
<span><?php echo $_siderooms[$k]['threads'] ?></span>
Expand All @@ -119,7 +120,7 @@
<span class="statsName fleft"><?php __("SIDEBAR_S_THREADS") ?></span><b class="fright"><?php echo $_stats['threads'] ?></b><br>
<span class="statsName fleft"><?php __("SIDEBAR_S_REPLIES") ?></span><b class="fright"><?php echo $_stats['replies'] ?></b><br>
<span class="statsName fleft"><?php __("SIDEBAR_S_MEMBERS") ?></span><b class="fright"><?php echo $_stats['members'] ?></b><br>
<span class="statsName fleft"><?php __("SIDEBAR_S_LAST") ?></span><b class="fright"><a href="?module=profile&amp;id=<?php echo $_stats['lastmemberid'] ?>"><?php echo $_stats['lastmembername'] ?></a></b>
<span class="statsName fleft"><?php __("SIDEBAR_S_LAST") ?></span><b class="fright"><a href="profile/<?php echo $_stats['lastmemberid'] ?>"><?php echo $_stats['lastmembername'] ?></a></b>
<div class="fix"></div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/default/help.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<img src="<?php __($this->p['IMG']) ?>/help.png" style="margin-top: 6px; margin-right: 15px;">
</div>
<div>
<b><a href="?module=help&amp;id=<?php __($_topics[$k]['h_id']) ?>" style="font-size: 14px"><?php __($_topics[$k]['title']) ?></a></b>
<b><a href="help/<?php __($_topics[$k]['h_id']) ?>" style="font-size: 14px"><?php __($_topics[$k]['title']) ?></a></b>
<br>
<em><?php __($_topics[$k]['short_desc']) ?></em>
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/default/login.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</td>
</tr>
<tr>
<td colspan="2" class="center"><?php __("L_NO_ACCOUNT", array("?module=register")) ?></td>
<td colspan="2" class="center"><?php __("L_NO_ACCOUNT", array("register")) ?></td>
</tr>
<tr>
<td colspan="2" class="center">
Expand Down
4 changes: 2 additions & 2 deletions templates/default/members.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@

<tr>
<td class="min"><?php __(Html::Crop($_result[$k]['avatar'], 42, 42, "avatar")) ?></td>
<td style="font-size: 14px;"><a href="?module=profile&amp;id=<?php __($_result[$k]['m_id']) ?>"><b><?php __($_result[$k]['username']) ?></b></a></td>
<td style="font-size: 14px;"><a href="profile/<?php __($_result[$k]['m_id']) ?>"><b><?php __($_result[$k]['username']) ?></b></a></td>
<td><?php __($_result[$k]['joined']) ?></td>
<td><?php __($_result[$k]['posts']) ?></td>
<td><?php __($_result[$k]['location']) ?></td>
<td><?php __($_result[$k]['name']) ?></td>
<td class="min" style="font-size: 16px"><a href="?module=profile&amp;id=1"><i class="fa fa-search"></i></a></td>
<td class="min" style="font-size: 16px"><a href="profile/<?php __($_result[$k]['m_id']) ?>"><i class="fa fa-search"></i></a></td>
</tr>

<?php
Expand Down
Loading

0 comments on commit 99b74e6

Please sign in to comment.