Selectively Remove NewTopic Button from ViewForum.php

This forum is now closed as part of retiring phpBB2.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

This forum is now closed due to phpBB2.0 being retired.
Post Reply
cwight
Registered User
Posts: 4
Joined: Thu Sep 15, 2005 8:46 pm

Selectively Remove NewTopic Button from ViewForum.php

Post by cwight »

I'm am extremely green, but I am having trouble searching the forums to find an answer here. I need to figure out how to selectively remove the newtopic button from viewforum.php. I have set a particular forum to only allow new topics posting to admins in a forum, and it seems like overkill to display this button for normal users when I only return the Information "Sorry, but only administrators can post topics in this forum" when they click on it. If they can't use it, I don't want to display.

Does anyone know how to remove this option for normals, while keeping it in place for admins? Thanks in advance for your assistance!!

cwight
Registered User
Posts: 4
Joined: Thu Sep 15, 2005 8:46 pm

Post by cwight »

another, probably even more critical questions I have, is how can I modify the php files (either index.php or viewforum.php or posting.php I assume) to allow me to post multiple lines and/or pictures to the Subject of a topic. I want to be able to have a list of topics show up with a pic and multiple lines of text, and currently am limited to one line and no pic.

I am learning php, and hope I'm not in over my head here . . .

Syrathos
Registered User
Posts: 99
Joined: Sat Jan 22, 2005 11:24 am
Location: Australia
Contact:

Re: Selectively Remove NewTopic Button from ViewForum.php

Post by Syrathos »

cwight wrote: I'm am extremely green, but I am having trouble searching the forums to find an answer here. I need to figure out how to selectively remove the newtopic button from viewforum.php. I have set a particular forum to only allow new topics posting to admins in a forum, and it seems like overkill to display this button for normal users when I only return the Information "Sorry, but only administrators can post topics in this forum" when they click on it. If they can't use it, I don't want to display.

Does anyone know how to remove this option for normals, while keeping it in place for admins? Thanks in advance for your assistance!!


I've managed to do it, the only problem being is that the new topic button now has a border around it. I will sort this problem as soon as possible as I'm going to work now. Once sorted I will give you the code.

AcousticJames
Registered User
Posts: 970
Joined: Wed Jul 13, 2005 5:59 am
Location: St. Cloud, MN
Contact:

Re: Selectively Remove NewTopic Button from ViewForum.php

Post by AcousticJames »

cwight wrote: I'm am extremely green, but I am having trouble searching the forums to find an answer here. I need to figure out how to selectively remove the newtopic button from viewforum.php. I have set a particular forum to only allow new topics posting to admins in a forum, and it seems like overkill to display this button for normal users when I only return the Information "Sorry, but only administrators can post topics in this forum" when they click on it. If they can't use it, I don't want to display.

Does anyone know how to remove this option for normals, while keeping it in place for admins? Thanks in advance for your assistance!!


Lock the forum to admins only. Unless you want people to see what admins are talking about, but not let them post, which doesn't make a whole lot of sense.

One work around is to set a switch in viewforum_body.tpl to only display the button if the user_level is admin. Something like this:

Code: Select all

### VIEWFORUM_BODY.TPL LINE: 8###

<!-- BEGIN switch_admin_newpost_button -->
<td align="left" valign="middle" width="50"><a href="{U_POST_NEW_TOPIC}"><img src="{POST_IMG}" border="0" alt="{L_POST_NEW_TOPIC}" /></a></td>
<!-- END switch_admin_newpost_button -->

// repeat the same at line 47
That takes care of your .tpl file. Then, in viewforum.php, do something like this:

Code: Select all


if ($userdata['user_level'] == 'admin') { // not sure of actual value for admin, replace as necessary
   $template->assign_block_vars('switch_admin_newpost_button', array());
}
Now, all that is untested code, but it should give you an idea. In your .php file, you check to see what the user's level is. If it's an admin, then you switch on the code in the .tpl file to display the button. If the user isn't of the appropriate level, then you simply do not call the switch and the code doesn't show. Play around with it, I'm sure it's not that hard.

James

cwight
Registered User
Posts: 4
Joined: Thu Sep 15, 2005 8:46 pm

Post by cwight »

James and syrathos, thanks for the response. I plan on messing with this this evening. I look forward to your code syrathos.

James, to clarify a bit, I want people to be able to post to the thread, just not add topics to the forum, sorry for the confusion. Maybe I'm not explaining myself well. . .

BTW, any ideas on the subject line issue, adding multiple line and picture posting functionality? I have seen sites do it (for example snapgone.com), just don't know how it was accomplished. I might go to him directly, just thought there might be an easy fix I could be pointed to here.

Thanks guys . .

Syrathos
Registered User
Posts: 99
Joined: Sat Jan 22, 2005 11:24 am
Location: Australia
Contact:

Post by Syrathos »

Your code James, was my initial thought, until I thought it through. That would hide, the button no matter which forum section you went to regardless of the permissions if the user isn't an admin.

The following modification I have designed, hides both the new topic and reply buttons (if you want both) if the user is unable to make a new topic or reply to a post. For example, if you sent the post -> admin for a certain forum section, the new topic button will be hidden from normal users in that section but will show in other sections where they can post new topics.

Code: Select all

############################################################## 
## MOD Title: Remove Post Topic/Reply If Not Authorised 
## MOD Author: Syrathos < syrathos@final-revelation.net > (N/A) http://www.syrathos.net 
## MOD Description: Removes Post Topic/Reply button if the user is unable to post/reply in a certain forum section due to permissions set. 
## MOD Version: 1.0.0 
## 
## Installation Level: Easy 
## Installation Time: 2 Minutes 
## Files To Edit: viewforum.php, 
##      	  viewtopic.php, 
##      	  /templates/subSilver/viewforum_body.tpl, 
##      	  /templates/subSilver/viewtopic.tpl 
## Included Files: N/A
## License: http://opensource.org/licenses/gpl-license.php GNU General Public License v2 
############################################################## 
## For security purposes, please check: http://www.phpbb.com/mods/ 
## for the latest version of this MOD. Although MODs are checked 
## before being allowed in the MODs Database there is no guarantee 
## that there are no security problems within the MOD. No support 
## will be given for MODs not found within the MODs Database which 
## can be found at http://www.phpbb.com/mods/ 
############################################################## 
## Author Notes: 
## 
############################################################## 
## MOD History: 
## 
##   2005-09-23 - Version 1.0.0 
##      - First Release. 
## 
############################################################## 
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD 
############################################################## 

# 
#-----[ OPEN ]------------------------------------------ 
#
viewforum.php

# 
#-----[ FIND ]------------------------------------------ 
# 
	'body' => 'viewforum_body.tpl')
};

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
// Start of Remove Post Topic If Not Authorised
$post_link = "posting.$phpEx?mode=newtopic&" . POST_FORUM_URL . "=$forum_id";
$postnew2_img = '<img src="' . $images['post_new'] . '" border="0"/>';
$postnew_img = ( ( $is_auth['auth_post'] ) ? '<a href="' . $post_link . '">' . $postnew2_img . '</a>' : '' );
// End of Remove Post Topic If Not Authorised

# 
#-----[ FIND ]------------------------------------------ 
# 
	'POST_IMG' => ( $forum_row['forum_status'] == FORUM_LOCKED ) ? $images['post_locked'] : $images['post_new'],

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
	// Start of Remove Post Topic If Not Authorised
	'POSTNEW_IMG' => $postnew_img,
	// End of Remove Post Topic If Not Authorised

# 
#-----[ OPEN ]------------------------------------------ 
#
viewtopic.php

# 
#-----[ FIND ]------------------------------------------ 
# 
//
// Send vars to template
//

# 
#-----[ BEFORE, ADD ]------------------------------------------ 
#
// Start of Remove Post Topic/Reply If Not Authorised
$post_link = "posting.$phpEx?mode=newtopic&" . POST_FORUM_URL . "=$forum_id";
$postnew2_img = '<img src="' . $images['post_new'] . '" border="0"/>';
$postnew_img = ( ( $is_auth['auth_post'] ) ? '<a href="' . $post_link . '">' . $postnew2_img . '</a>' : '' );


$postreply_link = "posting.$phpEx?mode=reply&" . POST_TOPIC_URL . "=$topic_id";
$postreply2_img = '<img src="' . $images['reply_new'] . '" border="0"/>';
$postreply_img = ( ( $is_auth['auth_reply'] ) ? '<a href="' . $postreply_link . '">' . $postreply2_img . '</a>' : '' );
// End of Remove Post Topic/Reply If Not Authorised

# 
#-----[ FIND ]------------------------------------------ 
# 
	'MODERATE_IMG'=>$moderate_img,

#
#-----[ AFTER, ADD ]------------------------------------------ 
#
	// Start of Remove Post Topic/Reply If Not Authorised
	'POSTNEW_IMG' => $postnew_img,
	'POSTREPLY_IMG' => $postreply_img,
	// End of Remove Post Topic/Reply If Not Authorised

# 
#-----[ OPEN ]------------------------------------------ 
#
templates/subSilver/viewforum_body.tpl

# 
#-----[ FIND ]------------------------------------------ 
#
<a href="{U_POST_NEW_TOPIC}"><img src="{POST_IMG}" border="0" alt="{L_POST_NEW_TOPIC}" /></a>

# 
#-----[ REPLACE WITH ]------------------------------------------ 
#
{POSTNEW_IMG}

# 
#-----[ OPEN ]------------------------------------------ 
#
templates/subSilver/viewtopic_body.tpl

# 
#-----[ FIND ]------------------------------------------ 
# 
<a href="{U_POST_NEW_TOPIC}"><img src="{POST_IMG}" border="0" alt="{L_POST_NEW_TOPIC}" align="middle" /></a>&nbsp;&nbsp;&nbsp;<a href="{U_POST_REPLY_TOPIC}"><img src="{REPLY_IMG}" border="0" alt="{L_POST_REPLY_TOPIC}" align="middle" /></a>

# 
#-----[ REPLACE WITH ]------------------------------------------ 
# 
{POSTNEW_IMG}&nbsp;&nbsp;&nbsp;{POSTREPLY_IMG}

#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------ 
# 
# EoM 

cwight
Registered User
Posts: 4
Joined: Thu Sep 15, 2005 8:46 pm

Post by cwight »

That is killer!!! bravo . . thanks!

afterlife_69
I've Been Banned!
Posts: 630
Joined: Tue Nov 30, 2004 10:35 am

Post by afterlife_69 »

Wouldnt it be better to replace both buttons with a 'Locked' button?

AcousticJames
Registered User
Posts: 970
Joined: Wed Jul 13, 2005 5:59 am
Location: St. Cloud, MN
Contact:

Post by AcousticJames »

Syrathos wrote: Your code James, was my initial thought, until I thought it through. That would hide, the button no matter which forum section you went to regardless of the permissions if the user isn't an admin.

The following modification I have designed, hides both the new topic and reply buttons (if you want both) if the user is unable to make a new topic or reply to a post. For example, if you sent the post -> admin for a certain forum section, the new topic button will be hidden from normal users in that section but will show in other sections where they can post new topics.


Yeah, my code was pseudo-code at best, just to give the original author an idea of what I was thinking of. I wasn't expecting much from it at all. :D

Post Reply

Return to “[2.0.x] MOD Writers Discussion”