root/releases/0.672/lib/templates.php

Revision 735, 56.3 kB (checked in by sven, 2 years ago)

kill some PHP notices, help query cache

  • Property svn:eol-style set to native
Line 
1 <?php
2
3 /*** NZVLE TODO
4  ***
5  *** + Break the html/css bits of the default template into separate files
6  ***   they mess up the code layout and indentation, and generally don't
7  ***   belong here.
8  *** + Clean up and document the calling conventions -- get rid of $parameter
9  *** + the callbacks to template_variables_substitute are *evil* -- rework
10  ***
11  ***/
12
13 function default_template () {
14
15     global $CFG;
16     global $template;
17     global $template_definition;
18     $sitename = $CFG->sitename;
19
20     $run_result = '';
21
22     $template_definition[] = array(
23                                     'id' => 'css',
24                                     'name' => __gettext("Stylesheet"),
25                                     'description' => __gettext("The Cascading Style Sheet for the template."),
26                                     'glossary' => array(),
27                                     'display'  => 1,
28                                     );
29
30     $template['css'] = file_get_contents($CFG->templatesroot . "Default_Template/css");
31     
32     $template_definition[] = array(
33                                    'id' => 'pageshell',
34                                    'name' => __gettext("Page Shell"),
35                                    'description' => __gettext("The main page shell, including headers and footers."),
36                                    'glossary' => array(
37                                                        '{{metatags}}' => __gettext("Page metatags (mandatory) - must be in the 'head' portion of the page"),
38                                                        '{{title}}' => __gettext("Page title"),
39                                                        '{{menu}}' => __gettext("Menu"),
40                                                        '{{topmenu}}' => __gettext("Status menu"),
41                                                        '{{mainbody}}' => __gettext("Main body"),
42                                                        '{{sidebar}}' => __gettext("Sidebar")
43                                                        )
44                                    );
45     
46     $welcome = __gettext("Welcome"); // gettext variable
47       
48     $template['pageshell'] = file_get_contents($CFG->templatesroot . "Default_Template/pageshell");
49
50     $template['frontpage_loggedout'] = file_get_contents($CFG->templatesroot . "Default_Template/frontpage_loggedout");
51     $template['frontpage_loggedin'] = file_get_contents($CFG->templatesroot . "Default_Template/frontpage_loggedin");
52     
53     // REMOVED stylesheet (was old version and should not have been here)
54     // TODO: extract all default template stuff from lib/templates.php
55
56 $template_definition[] = array(
57                                     'id' => 'contentholder',
58                                     'name' => __gettext("Content holder"),
59                                     'description' => __gettext("Contains the main content for a page (as opposed to the sidebar or the title)."),
60                                     'glossary' => array(
61                                                             '{{title}}' => __gettext("The title"),
62                                                             '{{submenu}}' => __gettext("The page submenu"),
63                                                             '{{body}}' => __gettext("The body of the page")
64                                                         )
65                                     );   
66
67     $template['contentholder'] = <<< END
68     
69     <div class="SectionContent">
70     
71     <h1>{{title}}</h1>
72     {{submenu}}
73     </div>
74     {{body}}
75     
76 END;
77
78     $template_definition[] = array(
79                                     'id' => 'ownerbox',
80                                     'name' => __gettext("Owner box"),
81                                     'description' => __gettext("A box containing a description of the owner of the current profile."),
82                                     'glossary' => array(
83                                                             '{{name}}' => __gettext("The user's name"),
84                                                             '{{profileurl}}' => __gettext("The URL of the user's profile page, including terminating slash"),
85                                                             '{{usericon}}' => __gettext("The user's icon, if it exists"),
86                                                             '{{tagline}}' => __gettext("A short blurb about the user"),
87                                                             '{{usermenu}}' => __gettext("Links to friend / unfriend a user"),
88                                                             '{{lmshosts}}' => __gettext("Links to any lms hosts the user is attached to"),
89                                                         )
90                                     );
91
92     $tags = __gettext("Tags");
93     $resources = __gettext("Resources");
94     $template['ownerbox'] = <<< END
95     
96     <div class="me">
97         <div style="float: left; width: 70px"><a href="{{profileurl}}">{{usericon}}</a></div>
98         <div style="margin-left: 75px; margin-top: 0px; padding-top: 0px; text-align: left" ><p>
99             <span class="userdetails">{{name}}<br /><a href="{{profileurl}}rss/">RSS</a> | <a href="{{profileurl}}tags/">$tags</a> | <a href="{{profileurl}}newsclient/">$resources</a></span></p>
100             <p>{{tagline}}</p>
101             <p>{{lmshosts}}</p>
102             <p style="margin-bottom: 3px" class="usermenu">{{usermenu}}</p>
103         </div>
104     </div>
105
106 END;
107                                     
108     $template_definition[] = array(
109                                     'id' => 'infobox',
110                                     'name' => __gettext("Information Box"),
111                                     'description' => __gettext("A box containing a caption and some text, used extensively throughout the site. For example, the 'friends' box and most page bodies are info boxes. Of course, you can alter this template however you wish - it doesn't need to be an actual box."),
112                                     'glossary' => array(
113                                                             '{{name}}' => __gettext("The title"),
114                                                             '{{contents}}' => __gettext("The contents of the box")
115                                                         )
116                                     );
117     $template['infobox'] = <<< END
118
119 <table class="infobox" width="100%">
120     <caption align="top">
121         {{name}}
122     </caption>
123     <tr>
124         <td>
125 {{contents}}
126         </td>
127     </tr>
128 </table><br />
129 END;
130
131     $template_definition[] = array(
132                                     'id' => 'messageshell',
133                                     'name' => __gettext("System message shell"),
134                                     'description' => __gettext("A list of system messages will be placed within the message shell."),
135                                     'glossary' => array(
136                                                             '{{messages}}' => __gettext("The messages")
137                                                         )
138                                     );
139
140     $template['messageshell'] = <<< END
141     
142     <div id="js">{{messages}}</div><br />
143     
144 END;
145
146     $template_definition[] = array(
147                                     'id' => 'messages',
148                                     'name' => __gettext("Individual system messages"),
149                                     'description' => __gettext("Each individual system message."),
150                                     'glossary' => array(
151                                                             '{{message}}' => __gettext("The system message")
152                                                         )
153                                     );
154
155     $template['messages'] = <<< END
156
157     <p>
158         {{message}}
159     </p>
160     
161 END;
162     
163
164     $template_definition[] = array(
165                                     'id' => 'menu',
166                                     'name' => __gettext("Main menu shell"),
167                                     'description' => __gettext("A list of main menu items will be placed within the menubar shell."),
168                                     'glossary' => array(
169                                                             '{{menuitems}}' => __gettext("The menu items")
170                                                         )
171                                     );
172
173     $template['menu'] = <<< END
174     
175       {{menuitems}}
176 END;
177
178     $template_definition[] = array(
179                                     'id' => 'menuitem',
180                                     'name' => __gettext("Individual main menu item"),
181                                     'description' => __gettext("This is the template for each individual main menu item. A series of these is placed within the menubar shell template."),
182                                     'glossary' => array(
183                                                             '{{location}}' => __gettext("The URL of the menu item"),
184                                                             '{{name}}' => __gettext("The menu item's name")
185                                                         )
186                                     );
187
188     $template['menuitem'] = <<< END
189     
190     <li><a href="{{location}}">{{name}}</a></li>
191     
192 END;
193
194 $template_definition[] = array(
195                                     'id' => 'selectedmenuitem',
196                                     'name' => __gettext("Selected individual main menu item"),
197                                     'description' => __gettext("This is the template for an individual main menu item if it is selected."),
198                                     'glossary' => array(
199                                                             '{{location}}' => __gettext("The URL of the menu item"),
200                                                             '{{name}}' => __gettext("The menu item's name")
201                                                         )
202                                     );
203
204     $template['selectedmenuitem'] = <<< END
205     
206     <li><a class="current" href="{{location}}">{{name}}</a></li>
207     
208 END;
209
210     $template_definition[] = array(
211                                     'id' => 'submenu',
212                                     'name' => __gettext("Sub-menubar shell"),
213                                     'description' => __gettext("A list of sub-menu items will be placed within the menubar shell."),
214                                     'glossary' => array(
215                                                             '{{submenuitems}}' => __gettext("The menu items")
216                                                         )
217                                     );
218
219     $template['submenu'] = <<< END
220     
221         <h3>
222             {{submenuitems}}
223         </h3>
224 END;
225
226     $template_definition[] = array(
227                                     'id' => 'submenuitem',
228                                     'name' => __gettext("Individual sub-menu item"),
229                                     'description' => __gettext("This is the template for each individual sub-menu item. A series of these is placed within the sub-menubar shell template."),
230                                     'glossary' => array(
231                                                             '{{location}}' => __gettext("The URL of the menu item"),
232                                                             '{{menu}}' => __gettext("The menu item's name")
233                                                         )
234                                     );
235
236     $template['submenuitem'] = <<< END
237     
238     <a href="{{location}}">{{name}}</a>&nbsp;|
239     
240 END;
241
242     $template_definition[] = array(
243                                     'id' => 'topmenu',
244                                     'name' => __gettext("Status menubar shell"),
245                                     'description' => __gettext("A list of statusbar menu items will be placed within the status menubar shell."),
246                                     'glossary' => array(
247                                                             '{{topmenuitems}}' => __gettext("The menu items")
248                                                         )
249                                     );
250
251     $template['topmenu'] = <<< END
252     
253         <div id="StatusRight">
254             {{topmenuitems}}
255         </div>
256
257 END;
258
259 $template_definition[] = array(
260                                     'id' => 'topmenuitem',
261                                     'name' => __gettext("Individual statusbar menu item"),
262                                     'description' => __gettext("This is the template for each individual statusbar menu item. A series of these is placed within the status menubar shell template."),
263                                     'glossary' => array(
264                                                             '{{location}}' => __gettext("The URL of the menu item"),
265                                                             '{{menu}}' => __gettext("The menu item's name")
266                                                         )
267                                     );
268
269     $template['topmenuitem'] = <<< END
270     
271     [<a href="{{location}}">{{name}}</a>]&nbsp;
272     
273 END;
274
275     $template_definition[] = array(
276                                     'id' => 'databox',
277                                     'name' => __gettext("Data input box (two columns)"),
278                                     'description' => __gettext("This is mostly used whenever some input is taken from the user. For example, each of the fields in the profile edit screen is a data input box."),
279                                     'glossary' => array(
280                                                             '{{name}}' => __gettext("The name for the data we're inputting"),
281                                                             '{{column1}}' => __gettext("The first item of data"),
282                                                             '{{column2}}' => __gettext("The second item of data")
283                                                         )
284                                     );
285
286     $template['databox'] = <<< END
287
288 <div class="infobox">
289     <table width="95%" class="profiletable" align="center" style="margin-bottom: 3px">
290     <tr>
291
292         <td width="20%" class="fieldname" valign="top">
293             <p><b>{{name}}</b></p>
294         </td>
295         <td width="50%" valign="top">
296             <p>{{column1}}</p>
297         </td>
298         <td width="30%" valign="top">
299             <p>{{column2}}</p>
300         </td>
301     </tr>
302     </table>
303 </div>
304         
305 END;
306
307     $template_definition[] = array(
308                                     'id' => 'databox1',
309                                     'name' => __gettext("Data input box (one column)"),
310                                     'description' => __gettext("A single-column version of the data box."),
311                                     'glossary' => array(
312                                                             '{{name}}' => __gettext("The name of the data we're inputting"),
313                                                             '{{column1}}' => __gettext("The data itself")
314                                                         )
315                                     );
316
317     $template['databox1'] = <<< END
318
319 <div class="infobox">
320     <table width="95%" class="profiletable" align="center" style="margin-bottom: 3px">
321     <tr>
322
323         <td width="20%" class="fieldname" valign="top">
324             <p><b>{{name}}</b></p>
325         </td>
326         <td width="80%" valign="top">
327             <p>{{column1}}</p>
328         </td>
329     </tr>
330     </table>
331 </div>
332         
333 END;
334
335     $template_definition[] = array(
336                                     'id' => 'databoxvertical',
337                                     'name' => __gettext("Data input box (vertical)"),
338                                     'description' => __gettext("A slightly different version of the data box, used on this edit page amongst other places."),
339                                     'glossary' => array(
340                                                             '{{name}}' => __gettext("Name of the data we\'re inputting"),
341                                                             '{{contents}}' => __gettext("The data itself")
342                                                         )
343                                     );
344
345     $template['databoxvertical'] = <<< END
346 <div class="infobox">
347     <table width="95%" class="fileTable" align="center" style="margin-bottom: 3px">
348         <tr>
349             <td class="fieldname">
350                 <p><b>{{name}}</b></p>
351             </td>
352         </tr>
353         <tr>
354             <td>
355                 <p>{{contents}}</p>
356             </td>
357         </tr>
358     </table>
359 </div>
360         
361 END;
362 return $run_result;
363 }
364
365 function templates_main () {
366
367     global $PAGE;
368
369     $run_result = '';
370
371     /*
372     *    Templates unit
373     */
374
375     // Load default values
376         $function['init'][] = path . "units/templates/default_template.php";
377         
378     // Actions
379         $function['templates:init'][] = path . "units/templates/template_actions.php";
380
381     // Draw template (returns HTML as opposed to echoing it straight to the screen)
382         $function['templates:draw'][] = path . "units/templates/template_draw.php";
383         
384     // Function to substitute variables within a template, used in templates:draw
385         $function['templates:variables:substitute'][] = path . "units/templates/variables_substitute.php";
386
387     // Function to draw the page, once supplied with a main body and title
388         $function['templates:draw:page'][] = path . "units/templates/page_draw.php";
389         
390     // Function to display a list of templates
391         $function['templates:view'][] = path . "units/templates/templates_view.php";
392         $function['templates:preview'][] = path . "units/templates/templates_preview.php";
393                 
394     // Function to display input fields for template editing
395         $function['templates:edit'][] = path . "units/templates/templates_edit.php";
396         
397     // Function to allow the user to create a new template
398         $function['templates:add'][] = path . "units/templates/templates_add.php";
399         
400     if ($context == "account") {
401         $PAGE->menu_sub[] = array( 'name' => 'template:edit',
402                                    'html' => templates_draw(array( 'context' => 'submenuitem',
403                                                                    'name' => __gettext("Change theme"),
404                                                                    'location' => url . '_templates/')));
405     }
406
407     return $run_result;
408 }
409
410 function templates_page_setup (){
411
412     global $PAGE;
413     global $CFG;
414
415     if (!empty($PAGE->setupdone)) {
416         return false; // don't run twice
417     }
418
419     $PAGE->setupdone = true; // leave your mark
420
421     //
422     // Populate $PAGE with links for non-module core code
423     //
424
425     if (isadmin()) {
426     $PAGE->menu_top [] = array( 'name' => 'admin',
427                                 //'html' => a_href("{$CFG->wwwroot}_admin/",
428                                 //                "Administration"));
429                                 'html' => "<li><a href=\"" . $CFG->wwwroot . "_admin/\">" . __gettext("Administration") . "</a></li>");
430     }
431     
432     $PAGE->menu_top[] = array(
433                               'name' => 'userdetails',
434                               //'html' => a_href("{$CFG->wwwroot}_userdetails/",
435                               //                  "Account settings"));
436                               'html' => "<li><a href=\"" . $CFG->wwwroot . "_userdetails/\">" . __gettext("Account settings") . "</a></li>");
437
438     $PAGE->menu_top[] = array(
439                               'name' => 'logoff',
440                               //'html' => a_href("{$CFG->wwwroot}login/logout.php",
441                               //                 "Log off"));
442                               'html' => "<li><a href=\"" . $CFG->wwwroot . "login/logout.php\">" . __gettext("Log off") . "</a></li>");
443
444     if (defined("context") && context == "account") {
445         $PAGE->menu_sub[] = array(
446                                   'name' => 'user:edit',
447                                   'html' => a_href("{$CFG->wwwroot}_userdetails/",
448                                                    __gettext("Edit user details")));
449         $PAGE->menu_sub[] = array(
450                                   'name' => 'user:icon',
451                                   'html' => a_href("{$CFG->wwwroot}_icons/",
452                                                    __gettext("Your site picture")));
453     }
454
455     if (defined("context") && context == "admin" && logged_on && user_flag_get("admin", $_SESSION['userid'])) {
456         $PAGE->menu_sub[] = array(
457                                   'name' => 'admin',
458                                   'html' => a_href("{$CFG->wwwroot}_admin/",
459                                                    __gettext("Main")));
460   
461         $PAGE->menu_sub[] = array(
462                                   'name' =>