View Single Post
  #2  
Old 09-06-2004, 10:26 PM
CarCdr CarCdr is offline
 
Join Date: Apr 2004
Posts: 242
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:
Code:
<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:
Code:
<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:
Code:
<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":
Code:
		<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>
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01197 seconds
  • Memory Usage 1,783KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_code
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete