Tip: adding "new topic" button to the topic screen (Display.template.php)

Started by pctwo, September 14, 2006, 10:28:47 AM

Previous topic - Next topic

pctwo

Motivation: there's no "new topic" button when viewing a topic.  An unsophisticated or lazy user may not realize he needs to go back to the message index (board) to post a new topic, and is liable to just hit reply when he really means to start a new topic.

(I realize there's a good counter argument for NOT putting the new topic button in the topic display, as it encourages people to start topics unnecessarily.  Judge for yourself whether you want to add this.)

Howto:

First, add the button code to Display.template.php.  Find



// Build the normal button array.
$normal_buttons = array(
'reply' => array('test' => 'can_reply', 'text' => 146, 'image' => 'reply.gif', 'lang' => true, 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';num_replies=' . $context['num_replies']),
'notify' => array('test' => 'can_mark_notify', 'text' => 125, 'image' => 'notify.gif', 'lang' => true, 'custom' => 'onclick="return confirm(\'' . ($context['is_marked_notify'] ? $txt['notification_disable_topic'] : $txt['notification_enable_topic']) . '\');"', 'url' => $scripturl . '?action=notify;sa=' . ($context['is_marked_notify'] ? 'off' : 'on') . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';sesc=' . $context['session_id']),
'custom' => array(),
'send' => array('test' => 'can_send_topic', 'text' => 707, 'image' => 'sendtopic.gif', 'lang' => true, 'url' => $scripturl . '?action=sendtopic;topic=' . $context['current_topic'] . '.0'),
'print' => array('text' => 465, 'image' => 'print.gif', 'lang' => true, 'custom' => 'target="_blank"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0'),
);



The code for the new topic button is found in MessageIndex.template.php.  It's located here.  They look similar, right?


// Create the button set...
$normal_buttons = array(
'markread' => array('text' => 'mark_read_short', 'image' => 'markread.gif', 'lang' => true, 'url' => $scripturl . '?action=markasread;sa=board;board=' . $context['current_board'] . '.0;sesc=' . $context['session_id']),
'notify' => array('test' => 'can_mark_notify', 'text' => 125, 'image' => 'notify.gif', 'lang' => true, 'custom' => 'onclick="return confirm(\'' . ($context['is_marked_notify'] ? $txt['notification_disable_board'] : $txt['notification_enable_board']) . '\');"', 'url' => $scripturl . '?action=notifyboard;sa=' . ($context['is_marked_notify'] ? 'off' : 'on') . ';board=' . $context['current_board'] . '.' . $context['start'] . ';sesc=' . $context['session_id']),
'new_topic' => array('test' => 'can_post_new', 'text' => 'smf258', 'image' => 'new_topic.gif', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0'),
'post_poll' => array('test' => 'can_post_poll', 'text' => 'smf20', 'image' => 'new_poll.gif', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0;poll'),
);



Copy the relevant part and insert it into Display.template.php.  To be consistent, we'll put it next to the notify button



// Build the normal button array.
$normal_buttons = array(
'reply' => array('test' => 'can_reply', 'text' => 146, 'image' => 'reply.gif', 'lang' => true, 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';num_replies=' . $context['num_replies']),
'notify' => array('test' => 'can_mark_notify', 'text' => 125, 'image' => 'notify.gif', 'lang' => true, 'custom' => 'onclick="return confirm(\'' . ($context['is_marked_notify'] ? $txt['notification_disable_topic'] : $txt['notification_enable_topic']) . '\');"', 'url' => $scripturl . '?action=notify;sa=' . ($context['is_marked_notify'] ? 'off' : 'on') . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';sesc=' . $context['session_id']),
// modified
'new_topic' => array('test' => 'can_post_new', 'text' => 'smf258', 'image' => 'new_topic.gif', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0'),
'custom' => array(),
'send' => array('test' => 'can_send_topic', 'text' => 707, 'image' => 'sendtopic.gif', 'lang' => true, 'url' => $scripturl . '?action=sendtopic;topic=' . $context['current_topic'] . '.0'),
'print' => array('text' => 465, 'image' => 'print.gif', 'lang' => true, 'custom' => 'target="_blank"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0'),
);


One more thing to do: we need to define $context['can_post_new'] in Sources/Display.php.  Find


// Now set all the wonderful, wonderful permissions... like moderation ones...
$common_permissions = array(
'can_sticky' => 'make_sticky',
'can_merge' => 'merge_any',
'can_split' => 'split_any',
'calendar_post' => 'calendar_post',
'can_mark_notify' => 'mark_any_notify',
'can_send_topic' => 'send_topic',
'can_send_pm' => 'pm_send',
'can_report_moderator' => 'report_any',
'can_moderate_forum' => 'moderate_forum',
);


add 'can_post_new' to the list, like this


// Now set all the wonderful, wonderful permissions... like moderation ones...
$common_permissions = array(
'can_sticky' => 'make_sticky',
'can_merge' => 'merge_any',
'can_split' => 'split_any',
'calendar_post' => 'calendar_post',
'can_mark_notify' => 'mark_any_notify',
'can_send_topic' => 'send_topic',
'can_send_pm' => 'pm_send',
'can_report_moderator' => 'report_any',
'can_moderate_forum' => 'moderate_forum',
// define can_post_new for modified Display.template.php
'can_post_new' => 'post_new'
);



VOILA :)

gameballa

Online Videogame Competitions = Play 4 Free or 4 Cash @ GamerComp.com


"The only way you will ever have peace is if you no longer believe the lie is true"

Joshua Dickerson

Test it out, if it works, add it to the mod site:

<?xml version="1.0"?>
<!DOCTYPE modification SYSTEM "http://www.simplemachines.org/xml/modification">
<!-- This package was generated by SleePys Modification Maker at http://sleepycode.com -->
<modification xmlns="http://www.simplemachines.org/xml/modification" xmlns:smf="http://www.simplemachines.org/">
<id>pctwo:New_Topic_on_Display.php</id>
<version>0.1</version>
<file name="$sourcedir/Display.php">
<operation>
<search position="before" whitespace="loose"><![CDATA[      'can_moderate_forum' => 'moderate_forum',]]></search>
<add><![CDATA[ // define can_post_new for modified Display.template.php
'can_post_new' => 'post_new']]></add>
</operation>
</file>
<file name="$themedir/display.template.php">
<operation>
<search position="replace" whitespace="loose"><![CDATA[($context['is_marked_notify'] ? $txt['notification_disable_board'] : $txt['notification_enable_board']) . '\');"', 'url' => $scripturl . '?action=notifyboard;sa=' . ($context['is_marked_notify'] ? 'off' : 'on') . ';board=' . $context['current_board'] . '.' . $context['start'] . ';sesc=' . $context['session_id']),]]></search>
<add><![CDATA[($context['is_marked_notify'] ? $txt['notification_disable_board'] : $txt['notification_enable_board']) . '\');"', 'url' => $scripturl . '?action=notifyboard;sa=' . ($context['is_marked_notify'] ? 'off' : 'on') . ';board=' . $context['current_board'] . '.' . $context['start'] . ';sesc=' . $context['session_id']),
      'new_topic' => array('test' => 'can_post_new', 'text' => 'smf258', 'image' => 'new_topic.gif', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0'),]]></add>
</operation>
</file>
</modification>
Come work with me at Promenade Group



Need help? See the wiki. Want to help SMF? See the wiki!

Did you know you can help develop SMF? See us on Github.

How have you bettered the world today?

the-punisher

can u make a mod for this feature i really needs it and didnt understand this
i Just Love SMF!

devil_jin

Same here it would be nice to have a mod of this....

Thanks for the tip though..

Arantor

Well, the original author wrote it 3 years ago, though it should still work fine in 1.1.10. Don't think it'll be the same in 2.0 though.

Advertisement: