PDA

View Full Version : Show signature only once?


Bonee70
09-06-2004, 07:44 PM
Is there a hack that shows a users signature only once per thread (in the first post by the user but then not again when the user replies for another time in the same thread)?

Thx!

CarCdr
09-06-2004, 10:26 PM
If you want to show something only once for a page that is being generated, start with the template that is used to produce the bits for the pages -- threadbits, forumbits, memberbits, whatever. In that template, to conditionalize the thing being displayed, use an associative array. An associate array has a key and a value. When you see "$frobs['thing']", that is a reference to an associate array and will return the VALUE for the KEY named 'thing'.

We're getting there...

So, in the template that you have to modify, you can *create* an associative array. Yes, you can create one that is not created by the PHP code that uses the template. So, let's say that you want to only show a signature once on a page, you would create an associative array that is keyed by userid or username. We will stick with userid. The first time the process to output a page encounters a userid, set a value in the associative array for userid "###', like so:

$userid_has_been_seen[###] = 'Yup'

The next time that the template is run, check to see if you have already seen this user. You would do that like so with a template conditional:
<if condition="NOT $userid_has_been_seen[###]">
do stuff for a user we have not yet seen on this page
</if>
Now, the "###' shown above will have to be replaced with the a reference to a userid, but you get the idea. Also, the conditional I showed is not quite right. What you really want is a test that checks to see if you have seen this user before, and *if* you have not, then note it so that you will notice the next time that you have seen it. Here's how you would do that:
<if condition="NOT $userid_has_been_seen['###'] AND $userid_has_been_seen[###] = true">
do stuff for the first time you have seen this user
</if>
This will strike a non-programmer as an odd looking idiom, so we'll break it down. It is a test that is composed of two sub-tests: if the first one fails (I have not yet seen this user), then the second one runs (note that I have seen this user).

With this code, the second time that you encounter the userid, the HTML between the "<if ...>" line and the "</if>" line will not be included in the output.

The final step is to ask how this would work in the case of a user's signature when displaying a page of posts.

Posts are displayed by showthread.php. In there it uses the "postbit" template to generate the output for every post. Look inside the "postbit" template and find out how they are referring to the USERID.

I am looking right now...

In the "postbit" template, they refer to the USERID as "$post[userid]". That is our '###' reference we used earlier. What I need to do is replace my '###' with this real reference. If I do that, the code I offered above becomes this:
<if condition="NOT $userid_has_been_seen[$post[userid]] AND $userid_has_been_seen[$post[userid]] = true">
do stuff for the first time you have seen this user
</if>

All I did was replace the '###' above with '$post[userid]'.

There is only one more lie to reveal. I used "NOT" to make things clear, but for PHP you have to say "!" to mean "NOT". So, if you want to turn a test around, you use "!" before the test.

The very last step is to find the code in the template that emits the signature.

I am looking... :) ... Here is is from "postbit":
<if condition="$post['signature']">
<!-- sig -->
<div>
__________________<br />
$post[signature]
</div>
<!-- / sig -->
</if>
So what you want to do is put this line before this section:
<if condition="! $userid_has_been_seen[$post[userid]] AND $userid_has_been_seen[$post[userid]] = true">

and then put this line after that section:
</if>

Bonee70
09-07-2004, 12:12 PM
Wow man, thx a lot for this little coding lesson, nice work. A guy on another board guided me to another code I use now to show the signatures only once.

Open includes/function_showthread.php, find:

$post['signature'] = $sigcache["$post[userid]"];

Replace with:

//$post['signature'] = $sigcache["$post[userid]"];
$post['signature'] = "";


It works perfectly.

Thx again man, I realy apreciate doing such a long post for a coding monkey like I'm ....

CarCdr
09-07-2004, 12:25 PM
Wow man, thx a lot for this little coding lesson, nice work. A guy on another board guided me to another code I use now to show the signatures only once.

See previous post for showthread.php mod...

It works perfectly.

Thx again man, I realy apreciate doing such a long post for a coding monkey like I'm ....
My pleasure.

One minor point for other readers though...

The approach you have adopted does suffer from the disadvantage of requiring a mod to a script file rather than a straight template edit to add a couple of lines.

Dybukk
10-18-2005, 05:27 PM
Any idea what file this would be on 3.5?

Andreas
10-18-2005, 05:29 PM
<a href="https://vborg.vbsupport.ru/showthread.php?t=96368" target="_blank">https://vborg.vbsupport.ru/showthread.php?t=96368</a>