1 |
<?php |
2 |
|
3 |
/** |
4 |
* Another example of how to build a |
5 |
* parent PageWidget object to provide |
6 |
* a base class for building a consistent |
7 |
* look/feel accross a web application. |
8 |
* |
9 |
* |
10 |
* $Id: example3.php,v 1.5 2002/10/03 18:39:25 hemna Exp $ |
11 |
* |
12 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
13 |
* @package phpHtmlLib |
14 |
* @subpackage examples |
15 |
* @version 2.0.0 |
16 |
* |
17 |
*/ |
18 |
|
19 |
/** |
20 |
* Include the phphtmllib libraries |
21 |
*/ |
22 |
include_once("includes.inc"); |
23 |
|
24 |
|
25 |
//Some applications want to provide a |
26 |
//consistent layout with some common |
27 |
//elements that always live on each |
28 |
//page. |
29 |
// An easy way to do that is to |
30 |
//build a child class to the |
31 |
//PageWidget object that defines the |
32 |
//layout in logical blocks named as |
33 |
//methods. |
34 |
|
35 |
//For example, A common layout is |
36 |
//to have a header block at the top, |
37 |
//followed by a content block, which |
38 |
//contains a left block, and right block. |
39 |
//followed by a footer block. |
40 |
|
41 |
// -------------------------------- |
42 |
// | header block | |
43 |
// -------------------------------- |
44 |
// | | | <- Main |
45 |
// | left | right block | <- block |
46 |
// | block | | <- |
47 |
// | | | <- |
48 |
// -------------------------------- |
49 |
// | footer block | |
50 |
// -------------------------------- |
51 |
|
52 |
//You would then define 6 methods in |
53 |
//the child to PageWidget named |
54 |
//body_content() - contains the outer most |
55 |
// layout |
56 |
// |
57 |
//header_block() - builds the content for |
58 |
// the header block, which |
59 |
// stays the same among |
60 |
// many pages. |
61 |
// |
62 |
//main_block() - which builds the left |
63 |
// block (typically used for |
64 |
// navigation), and the |
65 |
// main content block |
66 |
//left_block() - contains the left |
67 |
// navigational elements |
68 |
//content_block() - the main content for any |
69 |
// page's specific data. |
70 |
// |
71 |
//footer_block() - which contains any |
72 |
// footer information that |
73 |
// remains the same on all |
74 |
// pages. |
75 |
|
76 |
//The nice thing about this approach is, |
77 |
//on each page of your application, |
78 |
//you only have to override the methods |
79 |
//for the content blocks that are different |
80 |
//or specific to that page. The other content |
81 |
//blocks and layout is automatically built |
82 |
//from the parent class. |
83 |
|
84 |
//most of the time your page will only |
85 |
//override the content_block() method, which |
86 |
//is the right block content that changes |
87 |
//from page to page. |
88 |
|
89 |
//This is exactly how this website is built. |
90 |
|
91 |
//enable the automatic detection of debugging |
92 |
define("DEBUG", TRUE); |
93 |
|
94 |
class MyLayoutPage extends PageWidget { |
95 |
|
96 |
|
97 |
/** |
98 |
* This is the constructor. |
99 |
* |
100 |
* @param string - $title - the title for the page and the |
101 |
* titlebar object. |
102 |
* @param - string - The render type (HTML, XHTML, etc. ) |
103 |
* |
104 |
*/ |
105 |
function MyLayoutPage($title, $render_type = HTML) { |
106 |
|
107 |
$this->PageWidget( $title, $render_type ); |
108 |
|
109 |
//add some css links |
110 |
//assuming that phphtmllib is installed in the doc root |
111 |
$this->add_css_link("/phphtmllib/examples/css/main.css"); |
112 |
$this->add_css_link("/phphtmllib/css/fonts.css"); |
113 |
$this->add_css_link("/phphtmllib/css/colors.css"); |
114 |
|
115 |
//add the phphtmllib widget css |
116 |
$this->add_css_link( "/phphtmllib/css/bluetheme.php" ); |
117 |
} |
118 |
|
119 |
/** |
120 |
* This builds the main content for the |
121 |
* page. |
122 |
* |
123 |
*/ |
124 |
function body_content() { |
125 |
|
126 |
//add the header area |
127 |
$this->add( html_comment( "HEADER BLOCK BEGIN") ); |
128 |
$this->add( $this->header_block() ); |
129 |
$this->add( html_comment( "HEADER BLOCK END") ); |
130 |
|
131 |
//add it to the page |
132 |
//build the outer wrapper div |
133 |
//that everything will live under |
134 |
$wrapper_div = html_div(); |
135 |
$wrapper_div->set_id( "phphtmllib" ); |
136 |
|
137 |
//add the main body |
138 |
$wrapper_div->add( html_comment( "MAIN BLOCK BEGIN") ); |
139 |
$wrapper_div->add( $this->main_block() ); |
140 |
$wrapper_div->add( html_comment( "MAIN BLOCK END") ); |
141 |
|
142 |
$this->add( $wrapper_div ); |
143 |
|
144 |
//add the footer area. |
145 |
$this->add( html_comment( "FOOTER BLOCK BEGIN") ); |
146 |
$this->add( $this->footer_block() ); |
147 |
$this->add( html_comment( "FOOTER BLOCK END") ); |
148 |
|
149 |
} |
150 |
|
151 |
|
152 |
/** |
153 |
* This function is responsible for building |
154 |
* the header block that lives at the top |
155 |
* of every page. |
156 |
* |
157 |
* @return HTMLtag object. |
158 |
*/ |
159 |
function header_block() { |
160 |
$header = html_div("pageheader"); |
161 |
|
162 |
$header->add( "HEADER BLOCK AREA" ); |
163 |
return $header; |
164 |
} |
165 |
|
166 |
|
167 |
/** |
168 |
* We override this method to automatically |
169 |
* break up the main block into a |
170 |
* left block and a right block |
171 |
* |
172 |
* @param TABLEtag object. |
173 |
*/ |
174 |
function main_block() { |
175 |
|
176 |
$main = html_div(); |
177 |
$main->set_id("maincontent"); |
178 |
|
179 |
$table = html_table("100%",0); |
180 |
$left_div = html_div("leftblock", $this->left_block() ); |
181 |
|
182 |
$table->add_row( html_td("leftblock", "", $left_div ), |
183 |
html_td("divider", "", " "), |
184 |
html_td("rightblock", "", $this->content_block() )); |
185 |
$main->add( $table ); |
186 |
|
187 |
return $main; |
188 |
} |
189 |
|
190 |
|
191 |
/** |
192 |
* this function returns the contents |
193 |
* of the left block. It is already wrapped |
194 |
* in a TD |
195 |
* |
196 |
* @return HTMLTag object |
197 |
*/ |
198 |
function left_block() { |
199 |
$div = html_div(); |
200 |
$div->set_style("padding-left: 6px;"); |
201 |
|
202 |
$div->add( "LEFT BLOCK" ); |
203 |
return $div; |
204 |
} |
205 |
|
206 |
|
207 |
|
208 |
/** |
209 |
* this function returns the contents |
210 |
* of the right block. It is already wrapped |
211 |
* in a TD |
212 |
* |
213 |
* @return HTMLTag object |
214 |
*/ |
215 |
function content_block() { |
216 |
$container = container( "CONTENT BLOCK", html_br(2), |
217 |
html_a($_SERVER["PHP_SELF"]."?debug=1", |
218 |
"Show Debug source"), |
219 |
html_br(10)); |
220 |
return $container; |
221 |
} |
222 |
|
223 |
|
224 |
/** |
225 |
* This function is responsible for building |
226 |
* the footer block for every page. |
227 |
* |
228 |
* @return HTMLtag object. |
229 |
*/ |
230 |
function footer_block() { |
231 |
|
232 |
$footer_div = html_div(); |
233 |
$footer_div->set_tag_attribute("id", "footerblock"); |
234 |
$footer_div->add("FOOTER BLOCK"); |
235 |
|
236 |
return $footer_div; |
237 |
} |
238 |
} |
239 |
|
240 |
|
241 |
$page = new MyLayoutPage("phpHtmlLib Example 3 - PageWidget child"); |
242 |
|
243 |
|
244 |
//this will render the entire page |
245 |
print $page->render(); |
246 |
?> |