Understanding the code of phpBB


10pages on
this wiki
Add New Page
Talk0 Share
File info
Filename: faq.php
Directory: ../
CVS Version: 1.29
Part: Frontend
Primary function: To show the FAQ page

Ajay General workflow of faq.phpEdit

  • Initialize
  • Determine mode based on passed variable(from url) and add corresponding language item
  • Grab data from language pack and fit them into an array
  • Output data to template class
  • Output the page

Detailed anaylsis of the codeEdit

Line 1 to 21 : These are the common task done in a frontend file.

Line 23 : Get variable 'mode' that was passed by GET method.

Line 25 to 37 : Load the corresponding language files into the user object.

First, switch according to the mode variable that we just get. In case of 'bbcode', we load language file bbcode, and set the page title accrodingly, in all other cases we load the default faq language file and set the title as language item 'FAQ'.

Line 40 to 44 : Initialize some loop index and the array to hold the data.

Line 46 : Pull out one block of data from $user->help (That's the language file data we've just loaded) each iteration and store it temporately in $help_ary for processing later.

Data Structure of $help_block(which is how the faq data is stored temporately) :

It is a three dimensional array, which contained arrays of sections. The index is section no. (section 0, section 1, etc). Each section contains arrays of entries. The index is the entry no. in that section. (Hence each section start with entry no. 0, then no. 1,etc) Each entry is an array which has id(similar to entry no. , except it didn't start again in each section) , question, and answer.

This is best demostarted using an example:

|  |--0 id: 0
|  |    question: blah
|  |    answer: blah
|  |
|  |--1 id: 1
|       question: blah
|       answer: blah
   |--0 id: 2
   |    question: blah
   |    answer: blah
   |--1 id: 3
	    question: blah 
           answer: blah	


Line 48 to 56 : If the element of the array pulled out(Check help_faq.php for the data structure) with index 0 isn't -- , in other words if it isn't the section title, set the following

   |--$counter id: $counter_2
               question: $help_ary[0]
               answer: $help_ary[1]

In above, $j is the section counter, $counter is the entry counter within a section only, $counter_2 is an independent entry counter. The other two(refer to line 51 and 52) are simply to copy the content to their respective location.

Then we increment both of the counters by one(because we're still within the same section, so both counter goes up)

Line 57 to 65: In case we get a section title(see above for explanation), we need to store the section title separately, and the counters(as mentioned above) must be handled differently.

If the section counter $j is 0, we know this is the first title and we set section counter as 0; otherwise we just increment section counter.

We use an array called $help_block_titles to store the titles, with section counter as index.

The independent entry counter $counter_2 remains the same because we're not handling entry; but since this is a new section the section counter $j must be reset to 0.

Navigation bar
Introduction - Getting started - Basic Anaylsis - Basic classes - File by file anaylsis - Function reference guide - Common tasks - Coding tour

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.