root/releases/0.6/lib/templates.php

Revision 356, 50.4 kB (checked in by sven, 3 years ago)

add some missing indices, fix couple of typos...

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