Skip to content

Commit 4f21038

Browse files
committed
Merge pull request #82 from featherbb/urlfor-routes
Use urlFor() everywhere
2 parents 2d929d5 + 159af5d commit 4f21038

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+398
-402
lines changed

featherbb/Controller/Admin/Index.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ public function display($action = null)
8181
$this->feather->template->setPageInfo(array(
8282
'title' => array(Utils::escape($this->config['o_board_title']), __('Admin'), __('Index')),
8383
'active_page' => 'admin',
84-
'admin_console' => true,
85-
'install_file_exists' => is_dir($this->feather->forum_env['FEATHER_ROOT'].'install'),
84+
'admin_console' => true
8685
)
8786
)->addTemplate('admin/index.php')->display();
8887
}

featherbb/Controller/Admin/Maintenance.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Maintenance
1717
public function __construct()
1818
{
1919
$this->feather = \Slim\Slim::getInstance();
20-
$this->model = new \FeatherBB\Model\Admin\maintenance();
20+
$this->model = new \FeatherBB\Model\Admin\Maintenance();
2121
load_textdomain('featherbb', $this->feather->forum_env['FEATHER_ROOT'].'featherbb/lang/'.$this->feather->user->language.'/admin/maintenance.mo');
2222
}
2323

featherbb/Controller/Admin/Plugins.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,27 @@ public function index()
4949
)->addTemplate('admin/plugins.php')->display();
5050
}
5151

52-
public function activate()
52+
public function activate($pluginName = null)
5353
{
5454
// The plugin to load should be supplied via GET
55-
$class = $this->request->get('plugin') ? $this->request->get('plugin') : null;
56-
if (!$class) {
55+
// $pluginName = $this->request->get('plugin') ? $this->request->get('plugin') : null;
56+
if (!$pluginName) {
5757
throw new Error(__('Bad request'), 400);
5858
}
5959

6060
// Check if plugin follows PSR-4 conventions and extends base forum plugin
61-
if (!class_exists($class) || !property_exists($class, 'isValidFBPlugin')) {
62-
throw new Error(sprintf(__('No plugin message'), Utils::escape($class)), 400);
61+
if (!class_exists($pluginName) || !property_exists($pluginName, 'isValidFBPlugin')) {
62+
throw new Error(sprintf(__('No plugin message'), Utils::escape($pluginName)), 400);
6363
}
6464

65-
$plugin = new $class;
65+
$plugin = new $pluginName;
6666
try {
67-
$plugin->activate($class);
67+
$plugin->activate($pluginName);
6868
} catch (\Exception $e) {
6969
Url::redirect($this->feather->urlFor('adminPlugins'), $e->getMessage());
7070
}
7171
// Plugin has been activated, confirm and redirect
72-
Url::redirect($this->feather->urlFor('adminPlugins'), 'Plugin "'.$class::$name.'" activated!');
72+
Url::redirect($this->feather->urlFor('adminPlugins'), 'Plugin "'.$pluginName::$name.'" activated!');
7373
}
7474

7575
public function deactivate()

featherbb/Controller/Auth.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function login()
6060
Url::redirect($this->feather->urlFor('home'), __('Login redirect'));
6161
}
6262
}
63-
throw new Error(__('Wrong user/pass').' <a href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%3C%2Fspan%3E%27%3C%2Fspan%3E.%3Cspan+class%3D"x x-first">Url::get('login/action/forget/').'">'.__('Forgotten pass').'</a>', 403);
63+
throw new Error(__('Wrong user/pass').' <a href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%3C%2Fspan%3E%27%3C%2Fspan%3E.%3Cspan+class%3D"pl-s1">$this->feather->urlFor('resetPassword').'">'.__('Forgotten pass').'</a>', 403);
6464
} else {
6565
$this->feather->template->setPageInfo(array(
6666
'active_page' => 'login',
@@ -135,7 +135,7 @@ public function forget()
135135

136136
// Do the user specific replacements to the template
137137
$cur_mail_message = str_replace('<username>', $user->username, $mail_message);
138-
$cur_mail_message = str_replace('<activation_url>', Url::get('user/'.$user->id.'/action/change_pass/?key='.$new_password_key), $cur_mail_message);
138+
$cur_mail_message = str_replace('<activation_url>', $this->feather->urlFor('profileAction', ['action' => 'change_pass']).'?key='.$new_password_key, $cur_mail_message);
139139
$cur_mail_message = str_replace('<new_password>', $new_password, $cur_mail_message);
140140
$cur_mail_message = $this->feather->hooks->fire('cur_mail_message_password_forgotten', $cur_mail_message);
141141

featherbb/Controller/Edit.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ public function editpost($id)
6969
// Edit the post
7070
$this->model->edit_post($id, $can_edit_subject, $post, $cur_post, $is_admmod);
7171

72-
// Url::redirect($this->feather->urlFor('viewPost', array('pid' => $id)), __('Post redirect'));
73-
Url::redirect($this->feather->url->get('post/'.$id.'/#p'.$id), __('Post redirect'));
72+
Url::redirect($this->feather->urlFor('viewPost', ['pid' => $id]).'#p'.$id, __('Post redirect'));
7473
}
7574
} else {
7675
$post = '';

featherbb/Controller/Forum.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ public function __autoload($class_name)
2626
require $this->feather->forum_env['FEATHER_ROOT'] . $class_name . '.php';
2727
}
2828

29-
public function display($id, $name = null, $page = null)
29+
public function display($fid, $name = null, $page = null)
3030
{
3131
// Fetch some informations about the forum
32-
$cur_forum = $this->model->get_info_forum($id);
32+
$cur_forum = $this->model->get_info_forum($fid);
3333

3434
// Is this a redirect forum? In that case, redirect!
3535
if ($cur_forum['redirect_url'] != '') {
@@ -45,7 +45,7 @@ public function display($id, $name = null, $page = null)
4545

4646
// Can we or can we not post new topics?
4747
if (($cur_forum['post_topics'] == '' && $this->feather->user->g_post_topics == '1') || $cur_forum['post_topics'] == '1' || $is_admmod) {
48-
$post_link = "\t\t\t".'<p class="postlink conr"><a href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%3C%2Fspan%3E%27%3C%2Fspan%3E.%3Cspan+class%3D"x x-first">Url::get('post/new-topic/'.$id.'/').'">'.__('Post topic').'</a></p>'."\n";
48+
$post_link = "\t\t\t".'<p class="postlink conr"><a href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%3C%2Fspan%3E%27%3C%2Fspan%3E.%3Cspan+class%3D"pl-s1">$this->feather->urlFor('newTopic', ['fid' => $fid]).'">'.__('Post topic').'</a></p>'."\n";
4949
} else {
5050
$post_link = '';
5151
}
@@ -58,24 +58,24 @@ public function display($id, $name = null, $page = null)
5858
$url_forum = Url::url_friendly($cur_forum['forum_name']);
5959

6060
// Generate paging links
61-
$paging_links = '<span class="pages-label">'.__('Pages').' </span>'.Url::paginate($num_pages, $p, 'forum/'.$id.'/'.$url_forum.'/#');
61+
$paging_links = '<span class="pages-label">'.__('Pages').' </span>'.Url::paginate($num_pages, $p, 'forum/'.$fid.'/'.$url_forum.'/#');
6262

63-
$forum_actions = $this->model->get_forum_actions($id, $this->feather->forum_settings['o_forum_subscriptions'], $cur_forum['is_subscribed']);
63+
$forum_actions = $this->model->get_forum_actions($fid, $this->feather->forum_settings['o_forum_subscriptions'], $cur_forum['is_subscribed']);
6464

65-
$this->feather->template->addAsset('canonical', Url::get('forum/'.$id.'/'.$url_forum.'/'));
65+
$this->feather->template->addAsset('canonical', $this->feather->urlFor('Forum', ['id' => $fid, 'name' => $url_forum]));
6666
if ($num_pages > 1) {
6767
if ($p > 1) {
68-
$this->feather->template->addAsset('prev', Url::get('forum/'.$id.'/'.$url_forum.'/page/'.($p - 1).'/'));
68+
$this->feather->template->addAsset('prev', $this->feather->urlFor('ForumPaginate', ['id' => $fid, 'name' => $url_forum, 'page' => intval($p-1)]));
6969
}
7070
if ($p < $num_pages) {
71-
$this->feather->template->addAsset('next', Url::get('forum/'.$id.'/'.$url_forum.'/page/'.($p + 1).'/'));
71+
$this->feather->template->addAsset('next', $this->feather->urlFor('ForumPaginate', ['id' => $fid, 'name' => $url_forum, 'page' => intval($p+1)]));
7272
}
7373
}
7474

7575
if ($this->feather->forum_settings['o_feed_type'] == '1') {
76-
$this->feather->template->addAsset('feed', 'extern.php?action=feed&amp;fid='.$id.'&amp;type=rss', array('title' => __('RSS forum feed')));
76+
$this->feather->template->addAsset('feed', 'extern.php?action=feed&amp;fid='.$fid.'&amp;type=rss', array('title' => __('RSS forum feed')));
7777
} elseif ($this->feather->forum_settings['o_feed_type'] == '2') {
78-
$this->feather->template->addAsset('feed', 'extern.php?action=feed&amp;fid='.$id.'&amp;type=atom', array('title' => __('Atom forum feed')));
78+
$this->feather->template->addAsset('feed', 'extern.php?action=feed&amp;fid='.$fid.'&amp;type=atom', array('title' => __('Atom forum feed')));
7979
}
8080

8181
$this->feather->template->setPageInfo(array(
@@ -84,9 +84,9 @@ public function display($id, $name = null, $page = null)
8484
'page_number' => $p,
8585
'paging_links' => $paging_links,
8686
'is_indexed' => true,
87-
'id' => $id,
88-
'fid' => $id,
89-
'forum_data' => $this->model->print_topics($id, $sort_by, $start_from),
87+
'id' => $fid,
88+
'fid' => $fid,
89+
'forum_data' => $this->model->print_topics($fid, $sort_by, $start_from),
9090
'cur_forum' => $cur_forum,
9191
'post_link' => $post_link,
9292
'start_from' => $start_from,

featherbb/Controller/Post.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function newpost($fid = null, $tid = null, $qid = null)
124124
$this->model->increment_post_count($post, $new['tid']);
125125
}
126126

127-
Url::redirect(Url::get('post/'.$new['pid'].'/#p'.$new['pid']), __('Post redirect'));
127+
Url::redirect($this->feather->urlFor('viewPost', ['pid' => $new['pid']]).'#p'.$new['pid'], __('Post redirect'));
128128
}
129129
}
130130

@@ -133,18 +133,18 @@ public function newpost($fid = null, $tid = null, $qid = null)
133133
// If a topic ID was specified in the url (it's a reply)
134134
if ($tid) {
135135
$action = __('Post a reply');
136-
$form = '<form id="post" method="post" action="proxy.php?url=https%3A%2F%2Fgithub.com%2F%3C%2Fspan%3E%27%3C%2Fspan%3E.%3Cspan+class%3D"x x-first">Url::get('post/reply/'.$tid.'/').'" onsubmit="this.submit.disabled=true;if(process_form(this)){return true;}else{this.submit.disabled=false;return false;}">';
136+
$form = '<form id="post" method="post" action="proxy.php?url=https%3A%2F%2Fgithub.com%2F%3C%2Fspan%3E%27%3C%2Fspan%3E.%3Cspan+class%3D"pl-s1">$this->feather->urlFor('newReply', ['tid' => $tid]).'" onsubmit="this.submit.disabled=true;if(process_form(this)){return true;}else{this.submit.disabled=false;return false;}">';
137137

138138
// If a quote ID was specified in the url
139139
if (isset($qid)) {
140140
$quote = $this->model->get_quote_message($qid, $tid);
141-
$form = '<form id="post" method="post" action="proxy.php?url=https%3A%2F%2Fgithub.com%2F%3C%2Fspan%3E%27%3C%2Fspan%3E.%3Cspan+class%3D"x x-first">Url::get('post/reply/'.$tid.'/quote/'.$qid.'/').'" onsubmit="this.submit.disabled=true;if(process_form(this)){return true;}else{this.submit.disabled=false;return false;}">';
141+
$form = '<form id="post" method="post" action="proxy.php?url=https%3A%2F%2Fgithub.com%2F%3C%2Fspan%3E%27%3C%2Fspan%3E.%3Cspan+class%3D"pl-s1">$this->feather->urlFor('newQuoteReply', ['pid' => $tid, 'qid' => $qid]).'" onsubmit="this.submit.disabled=true;if(process_form(this)){return true;}else{this.submit.disabled=false;return false;}">';
142142
}
143143
}
144144
// If a forum ID was specified in the url (new topic)
145145
elseif ($fid) {
146146
$action = __('Post new topic');
147-
$form = '<form id="post" method="post" action="proxy.php?url=https%3A%2F%2Fgithub.com%2F%3C%2Fspan%3E%27%3C%2Fspan%3E.%3Cspan+class%3D"x x-first">Url::get('post/new-topic/'.$fid.'/').'" onsubmit="return process_form(this)">';
147+
$form = '<form id="post" method="post" action="proxy.php?url=https%3A%2F%2Fgithub.com%2F%3C%2Fspan%3E%27%3C%2Fspan%3E.%3Cspan+class%3D"pl-s1">$this->feather->urlFor('newTopic', ['fid' => $fid]).'" onsubmit="return process_form(this)">';
148148
} else {
149149
throw new Error(__('Bad request'), 404);
150150
}

featherbb/Controller/Profile.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ public function display($id, $section = null)
164164
throw new Error(__('Bad request'), 404);
165165
}
166166

167-
$avatar_field = '<span><a href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%3C%2Fspan%3E%27%3C%2Fspan%3E.%3Cspan+class%3D"x x-first">Url::get('user/'.$id.'/action/upload_avatar/').'">'.__('Change avatar').'</a></span>';
167+
$avatar_field = '<span><a href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%3C%2Fspan%3E%27%3C%2Fspan%3E.%3Cspan+class%3D"pl-s1">$this->feather->urlFor('profileAction', ['id' => $id, 'action' => 'upload_avatar']).'">'.__('Change avatar').'</a></span>';
168168

169169
$user_avatar = Utils::generate_avatar_markup($id);
170170
if ($user_avatar) {
171-
$avatar_field .= ' <span><a href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%3C%2Fspan%3E%27%3C%2Fspan%3E.%3Cspan+class%3D"x x-first">Url::get('user/'.$id.'/action/delete_avatar/').'">'.__('Delete avatar').'</a></span>';
171+
$avatar_field .= ' <span><a href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%3C%2Fspan%3E%27%3C%2Fspan%3E.%3Cspan+class%3D"pl-s1">$this->feather->urlFor('profileAction', ['id' => $id, 'action' => 'delete_avatar']).'">'.__('Delete avatar').'</a></span>';
172172
} else {
173-
$avatar_field = '<span><a href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%3C%2Fspan%3E%27%3C%2Fspan%3E.%3Cspan+class%3D"x x-first">Url::get('user/'.$id.'/action/upload_avatar/').'">'.__('Upload avatar').'</a></span>';
173+
$avatar_field = '<span><a href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%3C%2Fspan%3E%27%3C%2Fspan%3E.%3Cspan+class%3D"pl-s1">$this->feather->urlFor('profileAction', ['id' => $id, 'action' => 'upload_avatar']).'">'.__('Upload avatar').'</a></span>';
174174
}
175175

176176
if ($user['signature'] != '') {

featherbb/Controller/Register.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ public function display()
8181

8282
public function cancel()
8383
{
84-
$this->feather->redirect($this->feather->urlFor('home'));
84+
Url::redirect($this->feather->urlFor('home'));
8585
}
8686

8787
public function rules()
8888
{
8989
// If we are logged in, we shouldn't be here
9090
if (!$this->user->is_guest) {
91-
$this->feather->redirect($this->feather->urlFor('home'));
91+
Url::redirect($this->feather->urlFor('home'));
9292
}
9393

9494
// Display an error message if new registrations are disabled
@@ -97,7 +97,7 @@ public function rules()
9797
}
9898

9999
if ($this->config['o_rules'] != '1') {
100-
$this->feather->redirect($this->feather->urlFor('register'));
100+
Url::redirect($this->feather->urlFor('register'));
101101
}
102102

103103
$this->feather->template->setPageInfo(array(

featherbb/Controller/Topic.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ public function display($id = null, $name = null, $page = null, $pid = null)
8888
'promptQuote' => __('promptQuote')
8989
);
9090

91-
$this->feather->template->addAsset('canonical', Url::get('forum/'.$id.'/'.$url_forum.'/'));
91+
$this->feather->template->addAsset('canonical', $this->feather->urlFor('Forum', ['id' => $id, 'name' => $url_forum]));
9292
if ($num_pages > 1) {
9393
if ($p > 1) {
94-
$this->feather->template->addAsset('prev', Url::get('forum/'.$id.'/'.$url_forum.'/page/'.($p - 1).'/'));
94+
$this->feather->template->addAsset('prev', $this->feather->urlFor('ForumPaginate', ['id' => $id, 'name' => $url_forum, 'page' => intval($p-1)]));
9595
}
9696
if ($p < $num_pages) {
97-
$this->feather->template->addAsset('next', Url::get('forum/'.$id.'/'.$url_forum.'/page/'.($p + 1).'/'));
97+
$this->feather->template->addAsset('next', $this->feather->urlFor('ForumPaginate', ['id' => $id, 'name' => $url_forum, 'page' => intval($p+1)]));
9898
}
9999
}
100100

0 commit comments

Comments
 (0)