root/releases/elgg0.8rc2/lib/templates.php

Revision 1055, 63.6 kB (checked in by ben, 2 years ago)

{{populartags}} now supports {{populartags:n}} where n is the number of tags you want to display.

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