Carrying Topic Title

Started by JFS, October 07, 2012, 11:54:13 PM

Previous topic - Next topic

JFS

Using version 2.0.2.

When a new topic is started a title (subject) must be entered. This title is shown on the board index.



When a user makes a reply to a topic he has the ability to change the title because the subject field is open.



Any user can do this:



And if someone does this the topic title shown on the board index will not reflect that of the opening post. It would show Last Post in "I can do this".  I need to remove the ability to change the subject on any post that is not the opening post (first post). I don't code php but I am able to plod though some of it and google some things together. I suppose there are several ways to do this, the easiest would be to copy whatever code the quickreply editor uses to carry over the topic title. When you make a quick reply you don't have the ability to change the subject, it is carried over. See, no subject field:



What I need is code (or point me in a direction) to both auto-fill the subject field with the opening post's title (like the quick reply does) and to disallow editing of the subject on any posts other than the opening posts. Or another route to go would be to have the board index give the title of the last post replied to the title of the opening post, rather than the title of the reply.

Files I'm looking in:

Post.template.php

// Now show the subject box for this post.
echo '
<dt>
<span', isset($context['post_error']['no_subject']) ? ' class="error"' : '', ' id="caption_subject">', $txt['subject'], ':</span>
</dt>
<dd>
<input type="text" name="subject"', $context['subject'] == '' ? '' : ' value="' . $context['subject'] . '"', ' tabindex="', $context['tabindex']++, '" size="80" maxlength="80" class="input_text" />
</dd>
<dt class="clear_left">
', $txt['message_icon'], ':
</dt>
<dd>
<select name="icon" id="icon" onchange="showimage()">';


Post.php

// Get a response prefix (like 'Re:') in the default forum language.
if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
{
if ($language === $user_info['language'])
$context['response_prefix'] = $txt['response_prefix'];
else
{
loadLanguage('index', $language, false);
$context['response_prefix'] = $txt['response_prefix'];
loadLanguage('index');
}
cache_put_data('response_prefix', $context['response_prefix'], 600);
}




Hj Ahmad Rasyid Hj Ismail

Have you try changing Post.template.php from this:

// Now show the subject box for this post.
echo '
<dt>
<span', isset($context['post_error']['no_subject']) ? ' class="error"' : '', ' id="caption_subject">', $txt['subject'], ':</span>
</dt>
<dd>
<input type="text" name="subject"', $context['subject'] == '' ? '' : ' value="' . $context['subject'] . '"', ' tabindex="', $context['tabindex']++, '" size="80" maxlength="80" class="input_text" />
</dd>
<dt class="clear_left">
', $txt['message_icon'], ':
</dt>
<dd>
<select name="icon" id="icon" onchange="showimage()">';

To this?:

// Now show the subject box for this post.
echo '
<dt class="clear_left">
', $txt['message_icon'], ':
</dt>
<dd>
<select name="icon" id="icon" onchange="showimage()">';


If you haven't try that and see if there is error(s).

Otherwise we can just hide it by adding its css a display none.

JFS

That does not work for me because it removes the ability to have a subject in the opening post as well.

Hj Ahmad Rasyid Hj Ismail

#3
Oh ya. I forgot about that. I guess you will be needing a mod to do that.

Please look at this code (further down from the above code):

if (isset($context['previous_posts']) && count($context['previous_posts']) > 0)


Use it to hide if it is a reply. Otherwise, it is a new post, then show the topic title box to be filled in. I think it is like this. Change from:

// Now show the subject box for this post.
echo '
<dt>
<span', isset($context['post_error']['no_subject']) ? ' class="error"' : '', ' id="caption_subject">', $txt['subject'], ':</span>
</dt>
<dd>
<input type="text" name="subject"', $context['subject'] == '' ? '' : ' value="' . $context['subject'] . '"', ' tabindex="', $context['tabindex']++, '" size="80" maxlength="80" class="input_text" />
</dd>
<dt class="clear_left">
', $txt['message_icon'], ':
</dt>
<dd>
<select name="icon" id="icon" onchange="showimage()">';


// Now show the subject box for this post.
if (isset($context['previous_posts']) && count($context['previous_posts']) > 0)
{
echo '
<dt class="clear_left">
', $txt['message_icon'], ':
</dt>
<dd>
<select name="icon" id="icon" onchange="showimage()">';
}
else
{
echo '
<dt>
<span', isset($context['post_error']['no_subject']) ? ' class="error"' : '', ' id="caption_subject">', $txt['subject'], ':</span>
</dt>
<dd>
<input type="text" name="subject"', $context['subject'] == '' ? '' : ' value="' . $context['subject'] . '"', ' tabindex="', $context['tabindex']++, '" size="80" maxlength="80" class="input_text" />
</dd>
<dt class="clear_left">
', $txt['message_icon'], ':
</dt>
<dd>
<select name="icon" id="icon" onchange="showimage()">';
}


Sorry, I haven't test this BUT it might work.

JFS

Perhaps editing the BoardIndex.template.php file would be the way to go? If I can make it label the "last post in" title from the title of the opening post and never from a reply post. Something in this needs to be modified:

BoardIndex.template.php
<td class="lastpost">';

/* The board's and children's 'last_post's have:
time, timestamp (a number that represents the time.), id (of the post), topic (topic id.),
link, href, subject, start (where they should go for the first unread post.),
and member. (which has id, name, link, href, username in it.) */
if (!empty($board['last_post']['id']))
echo '
<p><strong>', $txt['last_post'], '</strong>  ', $txt['by'], ' ', $board['last_post']['member']['link'] , '<br />
', $txt['in'], ' ', $board['last_post']['link'], '<br />
<span class="smalltext">', $txt['on'], ' ', $board['last_post']['time'],'</span>
</p>';
echo '
</td>';

if (!$board['is_redirect'])
echo '
<td class="stats windowbg">
<span>', $board['posts'], '</span> ', $txt['posts'],'<span><br />', $board['topics'], '</span> ', $txt['topics'], '
</td>';

Hj Ahmad Rasyid Hj Ismail

I have edited my post above with the code. You might want to try it out.

JFS

Quote from: ahrasis on October 08, 2012, 02:13:04 AM
I have edited my post above with the code. You might want to try it out.

Getting somewhere. But that doesn't quite work. I still need to carry the title over as it is required for each post.


Hj Ahmad Rasyid Hj Ismail

In that case, we have to use display none. I try to code it for you.

Hj Ahmad Rasyid Hj Ismail

Ok try this one instead.

// Now show the subject box for this post.
if (isset($context['previous_posts']) && count($context['previous_posts']) > 0)
{
echo '
<div  style="display:none;"><dt>
<span', isset($context['post_error']['no_subject']) ? ' class="error"' : '', ' id="caption_subject">', $txt['subject'], ':</span>
</dt>
<dd>
<input type="text" name="subject"', $context['subject'] == '' ? '' : ' value="' . $context['subject'] . '"', ' tabindex="', $context['tabindex']++, '" size="80" maxlength="80" class="input_text" />
</dd></div>
<dt class="clear_left">
', $txt['message_icon'], ':
</dt>
<dd>
<select name="icon" id="icon" onchange="showimage()">';
}
else
{
echo '
<dt>
<span', isset($context['post_error']['no_subject']) ? ' class="error"' : '', ' id="caption_subject">', $txt['subject'], ':</span>
</dt>
<dd>
<input type="text" name="subject"', $context['subject'] == '' ? '' : ' value="' . $context['subject'] . '"', ' tabindex="', $context['tabindex']++, '" size="80" maxlength="80" class="input_text" />
</dd>
<dt class="clear_left">
', $txt['message_icon'], ':
</dt>
<dd>
<select name="icon" id="icon" onchange="showimage()">';
}


I just add <div  style="display:none;"> and its closing </div> with the original code there.

JFS

Success! So simple yet fixes a lot of potential headaches. Thanks for the help. This was a fun learning experience too. Makes me feel like opening my php book.

JFS

For the record I do get the gist of that code, I just don't quite know all the details of coding yet.

if (isset($context['previous_posts']) && count($context['previous_posts']) > 0)

Basically this means if the number of previous posts are greater than 0 (meaning it's not a new thread), then proceed with the following code. Nifty.

Hj Ahmad Rasyid Hj Ismail

Glad it works and helps. I almost think my skills are rusted already...

Advertisement: