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
8 *** + Clean up and document the calling conventions -- get rid of $parameter
9 *** + the callbacks to template_variables_substitute are *evil* -- rework
13 function default_template () {
17 global $template_definition;
18 $sitename = $CFG->sitename
;
22 $template_definition[] = array(
24 'name' => gettext("Page Shell"),
25 'description' => gettext("The main page shell, including headers and footers."),
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")
36 $welcome = gettext("Welcome"); // gettext variable
38 $template['pageshell'] = <<< END
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">
43 <title
>{{title
}}</title
>
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
-->
54 </div
><!-- end statusbar
-->
55 <div id
="header"><!-- start header
-->
57 <h2
>Community learning space
</h2
>
61 </div
><!-- end header
-->
62 <div id
="content_holder"><!-- start contentholder
-->
63 <div id
="maincontent_container"><!-- start main content
-->
66 </div
><!-- end main content
-->
67 <div id
="sidebar_container">
68 <div id
="sidebar"><!-- start sidebar
-->
69 <ul
><!-- open sidebar lists
-->
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
-->
85 // REMOVED stylesheet (was old version and should not have been here)
86 // TODO: extract all default template stuff from lib/templates.php
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)."),
93 '{{title}}' => gettext("The title"),
94 '{{submenu}}' => gettext("The page submenu"),
95 '{{body}}' => gettext("The body of the page")
99 $template['contentholder'] = <<< END
101 <div
class="SectionContent">
110 $template_definition[] = array(
112 'name' => gettext("Owner box"),
113 'description' => gettext("A box containing a description of the owner of the current profile."),
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"),
124 $tags = gettext("Tags");
125 $resources = gettext("Resources");
126 $template['ownerbox'] = <<< END
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
>
134 <p style
="margin-bottom: 3px" class="usermenu">{{usermenu
}}</p
>
140 $template_definition[] = array(
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."),
145 '{{name}}' => gettext("The title"),
146 '{{contents}}' => gettext("The contents of the box")
149 $template['infobox'] = <<< END
151 <table
class="infobox" width
="100%">
152 <caption align
="top">
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."),
168 '{{messages}}' => gettext("The messages")
172 $template['messageshell'] = <<< END
174 <div id
="js">{{messages
}}</div
><br
/>
178 $template_definition[] = array(
180 'name' => gettext("Individual system messages"),
181 'description' => gettext("Each individual system message."),
183 '{{message}}' => gettext("The system message")
187 $template['messages'] = <<< END
196 $template_definition[] = array(
198 'name' => gettext("Main menu shell"),
199 'description' => gettext("A list of main menu items will be placed within the menubar shell."),
201 '{{menuitems}}' => gettext("The menu items")
205 $template['menu'] = <<< END
210 $template_definition[] = array(
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."),
215 '{{location}}' => gettext("The URL of the menu item"),
216 '{{name}}' => gettext("The menu item's name")
220 $template['menuitem'] = <<< END
222 <li
><a href
="{{location}}">{{name
}}</a
></li
>
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."),
231 '{{location}}' => gettext("The URL of the menu item"),
232 '{{name}}' => gettext("The menu item's name")
236 $template['selectedmenuitem'] = <<< END
238 <li
><a
class="current" href
="{{location}}">{{name
}}</a
></li
>
242 $template_definition[] = array(
244 'name' => gettext("Sub-menubar shell"),
245 'description' => gettext("A list of sub-menu items will be placed within the menubar shell."),
247 '{{submenuitems}}' => gettext("The menu items")
251 $template['submenu'] = <<< END
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."),
263 '{{location}}' => gettext("The URL of the menu item"),
264 '{{menu}}' => gettext("The menu item's name")
268 $template['submenuitem'] = <<< END
270 <a href
="{{location}}">{{name
}}</a
> 
;|
274 $template_definition[] = array(
276 'name' => gettext("Status menubar shell"),
277 'description' => gettext("A list of statusbar menu items will be placed within the status menubar shell."),
279 '{{topmenuitems}}' => gettext("The menu items")
283 $template['topmenu'] = <<< END
285 <div id
="StatusRight">
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."),
296 '{{location}}' => gettext("The URL of the menu item"),
297 '{{menu}}' => gettext("The menu item's name")
301 $template['topmenuitem'] = <<< END
303 [<a href
="{{location}}">{{name
}}</a
>] 
;
307 $template_definition[] = array(
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."),
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")
318 $template['databox'] = <<< END
320 <div
class="infobox">
321 <table width
="95%" class="profiletable" align
="center" style
="margin-bottom: 3px">
324 <td width
="20%" class="fieldname" valign
="top">
325 <p
><b
>{{name
}}</b
></p
>
327 <td width
="50%" valign
="top">
330 <td width
="30%" valign
="top">
339 $template_definition[] = array(
341 'name' => gettext("Data input box (one column)"),
342 'description' => gettext("A single-column version of the data box."),
344 '{{name}}' => gettext("The name of the data we're inputting"),
345 '{{column1}}' => gettext("The data itself")
349 $template['databox1'] = <<< END
351 <div
class="infobox">
352 <table width
="95%" class="profiletable" align
="center" style
="margin-bottom: 3px">
355 <td width
="20%" class="fieldname" valign
="top">
356 <p
><b
>{{name
}}</b
></p
>
358 <td width
="80%" valign
="top">
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."),
372 '{{name}}' => gettext("Name of the data we\'re inputting"),
373 '{{contents}}' => gettext("The data itself")
377 $template['databoxvertical'] = <<< END
378 <div
class="infobox">
379 <table width
="95%" class="fileTable" align
="center" style
="margin-bottom: 3px">
381 <td
class="fieldname">
382 <p
><b
>{{name
}}</b
></p
>
397 function templates_main () {
407 // Load default values
408 $function['init'][] = path
. "units/templates/default_template.php";
411 $function['templates:init'][] = path
. "units/templates/template_actions.php";
413 // Draw template (returns HTML as opposed to echoing it straight to the screen)
414 $function['templates:draw'][] = path
. "units/templates/template_draw.php";
416 // Function to substitute variables within a template, used in templates:draw
417 $function['templates:variables:substitute'][] = path
. "units/templates/variables_substitute.php";
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";
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";
426 // Function to display input fields for template editing
427 $function['templates:edit'][] = path
. "units/templates/templates_edit.php";
429 // Function to allow the user to create a new template
430 $function['templates:add'][] = path
. "units/templates/templates_add.php";
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/')));
442 function templates_page_setup (){
447 if (!empty($PAGE->setupdone
)) {
448 return false; // don't run twice
451 $PAGE->setupdone
= true; // leave your mark
454 // Populate $PAGE with links for non-module core code
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>");
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>");
470 $PAGE->menu_top
[] = array(
472 //'html' => a_hrefg("{$CFG->wwwroot}login/logout.php",
474 'html' => "<li><a href=\"" . $CFG->wwwroot
. "login/logout.php\">" . gettext("Log off") . "</a></li>");
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"));
487 if (context
== "admin" && logged_on
&& run("users:flags:get",array("admin", $_SESSION['userid']))) {
488 $PAGE->menu_sub
[] = array(
490 'html' => a_hrefg("{$CFG->wwwroot}_admin/",
493 $PAGE->menu_sub
[] = array(
494 'name' => 'admin:useradd',
495 'html' => a_hrefg("{$CFG->wwwroot}_admin/users_add.php",
498 $PAGE->menu_sub
[] = array(
499 'name' => 'admin:users',
500 'html' => a_hrefg("{$CFG->wwwroot}_admin/users.php",
503 $PAGE->menu_sub
[] = array(
504 'name' => 'admin:flaggedcontent',
505 'html' => a_hrefg("{$CFG->wwwroot}_admin/flags.php",
506 "Manage flagged content"));
508 $PAGE->menu_sub
[] = array(
509 'name' => 'admin:spam',
510 'html' => a_hrefg("{$CFG->wwwroot}_admin/antispam.php",
517 // Give a chance to all registered modules
519 if ($allmods = get_list_of_plugins('mod') ) {
520 foreach ($allmods as $mod) {
521 $mod_pagesetup = $mod . '_pagesetup';
522 if (function_exists($mod_pagesetup)) {
525 notify("Function $mod_pagesetup doesn't exist!");
531 function templates_page_draw ($param) {
532 // Draws the page, given a title and a main body (parameters[0] and [1]).
534 $mainbody = $param[1];
541 //// Prepare things for the module run
542 //// populating $PAGE as required
544 if (empty($PAGE->setupdone
)) {
545 templates_page_setup();
549 if (isset($messages) && sizeof($messages) > 0) {
550 foreach($messages as $message) {
551 $messageshell .=templates_draw(array(
552 'context' => 'messages',
553 'message' => $message
557 $messageshell =templates_draw(array(
558 'context' => 'messageshell',
559 'messages' => $messageshell
564 // If $parameter[2] is set, we'll substitute it for the
566 if (isset($param[2])) {
567 $sidebarhtml = $param[2];
569 $sidebarhtml = run("display:sidebar");
572 $run_result .= templates_draw(array(
573 'context' => 'pageshell',
575 'menu' => displaymenu(),
576 'submenu' => displaymenu_sub(),
577 'top' => displaymenu_top(),
578 'sidebar' => $sidebarhtml,
579 'mainbody' => $mainbody,
580 'messageshell' => $messageshell
586 function templates_actions () {
588 global $CFG,$USER,$db;
595 $action = optional_param('action');
603 case "templates:select":
604 $id = optional_param('selected_template',0,PARAM_INT
);
608 $exists = record_exists_sql('SELECT ident FROM '.$CFG->prefix
.'templates WHERE ident = '.$id.' AND (owner = '.$USER->ident
." OR public='yes')");
612 $t->template_id
= $id;
613 $t->ident
= $USER->ident
;
614 update_record('users',$t);
616 $messages[] = gettext("Your current template has been changed.");
620 case "templates:save":
621 $template = optional_param('template');
622 $id = optional_param('save_template_id',0,PARAM_INT
);
623 $templatetitle = optional_param('templatetitle');
624 if (!empty($template) && !empty($id) && !empty($templatetitle)) {
625 unset($_SESSION['template_element_cache'][$id]);
626 $exists = record_exists('templates','ident',$id,'owner',$USER->ident
);
629 $t->name
= $templatetitle;
631 update_record('templates',$t);
632 delete_records('template_elements','template_id',$id);
633 $contents = optional_param('template');
634 foreach ($contents as $name => $content) {
635 //TODO Fix this with PARAM_CLEANHTML or similar
636 $slashname = addslashes($name);
637 $slashcontent = addslashes($content);
638 if ($content != "" && $content != $template[$name]) {
640 $te->name
= $slashname;
641 $te->content
= $slashcontent;
642 $te->template_id
= $id;
643 insert_record('template_elements',$te);
646 $messages[] = gettext("Your template has been updated.");
650 case "deletetemplate":
651 $id = optional_param('delete_template_id',0,PARAM_INT
);
652 unset($_SESSION['template_element_cache'][$id]);
653 $exists = record_exists('templates','ident',$id,'owner',$USER->ident
);
655 $db->execute('UPDATE '.$CFG->prefix
.'users SET template_id = -1 WHERE template_id = '.$id);
656 delete_records('template_elements','template_id',$id);
657 delete_records('template','ident',$id);
658 $messages[] = gettext("Your template was deleted.");
661 case "templates:create":
662 $based_on = optional_param('template_based_on',0,PARAM_INT
);
663 $name = optional_param('new_template_name');
664 if (!empty($name)) { // $based_on can be empty, surely? -Penny
668 $t->owner
= $USER->ident
;
669 $new_template_id = insert_record('templates',$t);
670 if ($based_on != -1) {
671 $exists = record_exists_sql('SELECT ident FROM '.$CFG->prefix
.'templates WHERE ident = ? AND (owner = ? OR public = ?)',array($based_on,$USER->ident
,'yes'));
673 if ($elements = get_records('template_elements','template_id',$based_on)) {
674 foreach($elements as $element) {
675 $element->template_id
= $new_template_id;
676 insert_record('template_elements',$element);
687 /// NOTE: this function takes a named array as single parameter
688 function templates_draw ($parameter) {
690 // Draw a page element using a specified template (or, if the template is -1, the default)
691 // $parameter['template'] = the template ID, $parameter['element'] = the template element,
692 // all other $parameter[n] = template elements
694 // Initialise global template variable, which contains the default template
697 // Initialise global template ID variable, which contains the template ID we're using
701 global $page_template_cache;
705 if ($parameter['context'] === 'topmenuitem') {
706 // error_log("templates_draw pcontext " . print_r($parameter,1));
708 // Get template details
709 if (!isset($template_id)) {
710 if (!isset($page_owner) ||
$page_owner == -1) {
713 // if (!isset($_SESSION['template_id_cache'][$page_owner])) {
714 if (!$template_id = get_field('users','template_id','ident',$page_owner)) {
718 // $template_id = $_SESSION['template_id_cache'][$page_owner];
722 // Template ID override
723 $t = optional_param('template_preview',0,PARAM_INT
);
728 // Grab the template content
729 if ($template_id == -1 ||
($parameter['context'] != "css" && $parameter['context'] != "pageshell")) {
730 $template_element = $template[$parameter['context']];
732 $template_context = addslashes($parameter['context']);
733 if (!isset($page_template_cache[$parameter['context']])) {
734 $result = get_template_element($template_id, $template_context);
735 $page_template_cache[$parameter['context']] = $result;
737 $result = $page_template_cache[$parameter['context']];
739 if (!empty($result)) {
740 $template_element = stripslashes($result->content
);
742 $template_element = $template[$parameter['context']];
746 if ($parameter['context'] === 'topmenuitem') {
747 // error_log("templates_draw pcontext " . print_r($template_element));
750 // Substitute elements
753 \$passed = array(".var_export($parameter,true).",\$matches[1], " . $template_id . ");
754 return templates_variables_substitute(\$passed);
757 // $template_element = templates_variables_substitute(array($parameter,$template_element));
758 $body = preg_replace_callback("/\{\{([A-Za-z_0-9]*)\}\}/i",create_function('$matches',$functionbody),$template_element);
764 function templates_add () {
767 // Create a new template
768 $header = gettext("Create theme"); // gettext variable
769 $desc = gettext("Here you can create your own themes based on one of the existing public themes. Just select which public theme you would like to alter and then create your own. You will now have edit privilages."); // gettext variable
775 <form action
="index.php" method
="post">
783 $panel .=templates_draw(array(
784 'context' => 'databox1',
785 'name' => gettext("Theme name"),
786 'column1' => display_input_field(array("new_template_name","","text"))
790 $default = gettext("Default Theme"); // gettext variable
793 <select name
="template_based_on">
794 <option value
="-1">$default</option
>
797 if ($templates = get_records_select('templates','owner = '.$USER->ident
." OR public = 'yes'",'public')) {
798 foreach($templates as $template) {
799 $column1 .= "<option value=\"".$template->ident
."\">".stripslashes($template->name
) . "</option>";
807 $panel .=templates_draw(array(
808 'context' => 'databox1',
809 'name' => gettext("Based on"),
810 'column1' => $column1
814 $buttonValue = gettext("Create Theme"); // gettext variable
818 <input type
="hidden" name
="action" value
="templates:create" />
819 <input type
="submit" value
="$buttonValue" />
826 $run_result .= $panel;
830 function templates_edit () {
834 global $template_definition;
837 if (!isset($parameter)) {
838 // Get template details
839 if (!$template_id = get_field('users','template_id','ident',$USER->ident
)) {
843 if (!is_array($parameter)) {
844 $template_id = (int) $parameter;
850 // Grab title, see if we can edit the template
852 if ($template_id == -1) {
853 $templatetitle = gettext("Default Theme");
855 $templatestuff = get_record('templates','ident',$template_id);
856 $templatetitle = stripslashes($templatestuff->name
);
857 if ($templatestuff->owner
== $USER->ident
) {
860 if (($templatestuff->owner
!= $USER->ident
) && ($templatestuff->public != 'yes')) {
865 // Grab the template content
866 if ($template_id == -1) {
867 $current_template = $template;
869 if ($elements = get_records('template_elements','template_id',$template_id)) {
870 foreach($result as $element) {
871 $current_template[stripslashes($element->name
)] = stripslashes($element->content
);
874 $current_template = $template;
878 $run_result .= <<< END
880 <form action
="" method
="post">
884 $run_result .= templates_draw(array(
885 'context' => 'databoxvertical',
886 'name' => gettext("Theme Name"),
887 'contents' => display_input_field(array("templatetitle",$templatetitle,"text"))
891 foreach($template_definition as $element) {
893 $name = "<b>" . $element['name'] . "</b><br /><i>" . $element['description'] . "</i>";
894 $glossary = gettext("Glossary"); // gettext variable
896 if (is_array($element['glossary']) && sizeof($element['glossary']) > 0) {
897 $column1 = "<b>$glossary</b><br />";
898 foreach($element['glossary'] as $gloss_id => $gloss_descr) {
899 $column1 .= $gloss_id . " -- " . $gloss_descr . "<br />";
905 if ($current_template[$element['id']] == "" ||
!isset($current_template[$element['id']])) {
906 $current_template[$element['id']] = $template[$element['id']];
909 $column2 = display_input_field(array("template[" . $element['id'] . "]",$current_template[$element['id']],"longtext"));
911 $run_result .=templates_draw(array(
912 'context' => 'databox',
914 'column2' => $column1,
915 'column1' => $column2
919 $run_result .=templates_draw(array(
920 'context' => 'databoxvertical',
922 'contents' => $column1 . "<br />" . $column2
930 $save = gettext("Save"); // gettext variable
931 $run_result .= <<< END
934 <input type
="hidden" name
="action" value
="templates:save" />
935 <input type
="hidden" name
="save_template_id" value
="$template_id" />
936 <input type
="submit" value
="$save" />
941 $noEdit = gettext("You may not edit this theme. To create a new, editable theme based on the default, go to <a href=\"index.php\">the main themes page</a>."); // gettext variable
942 $run_result .= <<< END
950 $run_result .= <<< END
958 function templates_preview () {
964 // Basic page elements
966 $name = "Basic page elements";
967 $heading1 = gettext("Heading one"); // gettext variable
968 $heading2 = gettext("Heading two"); // gettext variable
969 $bulletList = gettext("A bullet list"); // gettext variable
970 $heading3 = gettext("Heading three"); // gettext variable
971 $numberedList = gettext("A numbered list"); // gettext variable
974 <img src
="{$CFG->wwwroot}_templates/leaves.jpg" width
="300" height
="225" alt
="A test image" align
="right" />
976 <p
>Paragraph text
</p
>
983 <li
>$numberedList</li
>
988 $run_result .=templates_draw(array(
989 'context' => 'contentholder',
997 $name = "Data input";
999 $body =templates_draw(array(
1000 'context' => 'databox',
1001 'name' => gettext("Some text input"),
1002 'column1' => display_input_field(array("blank","","text")),
1003 'column2' => run("display:access_level_select",array("blank","PUBLIC"))
1006 $body .=templates_draw(array(
1007 'context' => 'databox1',
1008 'name' => gettext("Some longer text input"),
1009 'column1' => display_input_field(array("blank","","longtext"))
1012 $body .=templates_draw(array(
1013 'context' => 'databoxvertical',
1014 'name' => gettext("Further text input"),
1015 'contents' => display_input_field(array("blank","","longtext")) . "<br />" . display_input_field(array("blank","","text")) . "<br /><input type='button' value='Button' />"
1019 $run_result .=templates_draw(array(
1020 'context' => 'contentholder',
1029 function templates_view () {
1032 $user_template = get_field('users','template_id','ident',$USER->ident
);
1033 $sitename = sitename
;
1034 $title = gettext("Select / Create / Edit Themes"); // gettext variable
1035 $header = gettext("Public Themes"); // gettext variable
1036 $desc = sprintf(gettext("The following are public themes that you can use to change the way your %s looks - these do not change the content only the appearance. Check the preview and then select the one you want. If you wish you can adapt one of these using the 'create theme' option below."), $sitename); // gettext variable
1040 <form action
="" method
="post">
1050 $template_list[] = array(
1051 'name' => gettext("Default Theme"),
1054 if ($templates = get_records('templates','public','yes')) {
1055 foreach($templates as $template) {
1056 $template_list[] = array(
1057 'name' => stripslashes($template->name
),
1058 'id' => stripslashes($template->ident
)
1062 foreach($template_list as $template) {
1063 $name = "<input type='radio' name='selected_template' value='".$template['id']."' ";
1064 if ($template['id'] == $user_template) {
1065 $name .= "checked=\"checked\"";
1068 $column1 = "<b>" . $template['name'] . "</b>";
1069 $column2 = "<a href=\"".url
."_templates/preview.php?template_preview=".$template['id']."\" target=\"preview\">" . gettext("preview") . "</a>";
1070 $panel .=templates_draw(array(
1071 'context' => 'databox',
1073 'column1' => $column1,
1074 'column2' => $column2
1079 $templates = get_records('templates','owner',$USER->ident
);
1080 $header2 = gettext("Personal themes"); // gettext variable
1081 $desc2 = gettext("These are themes that you have created. You can edit and delete these. These theme(s) only control actual look and feel - you cannot change any content here. To change any of your content you need to use the other menu options such as: edit profile, update weblog etc."); // gettext variable
1083 if (is_array($templates) && sizeof($templates) > 0) {
1094 foreach($templates as $template) {
1095 $name = "<input type='radio' name='selected_template' value='".$template->ident
."'";
1096 if ($template->ident
== $user_template) {
1097 $name .= "checked=\"checked\"";
1100 $column1 = "<b>" . stripslashes($template->name
) . "</b>";
1101 $column2 = "<a href=\"".url
."_templates/preview.php?template_preview=".$template->ident
."\" target=\"preview\">" . gettext("preview") . "</a>";
1103 $column2 .= " | <a href=\"".url
."_templates/edit.php?id=".$template->ident
."\" >". gettext("Edit") ."</a>";
1104 $column2 .= " | <a href=\"".url
."_templates/?action=deletetemplate&delete_template_id=".$template->ident
."\" onclick=\"return confirm('" . gettext("Are you sure you want to permanently remove this template?") . "')\">" . gettext("Delete") . "</a>";
1105 $panel .=templates_draw(array(
1106 'context' => 'databox',
1108 'column1' => $column1,
1109 'column2' => $column2
1115 $submitValue = gettext("Select new theme"); // gettext variable
1119 <input type
="submit" value
=$submitValue />
1120 <input type
="hidden" name
="action" value
="templates:select" />
1127 $run_result .= $panel;
1131 function templates_variables_substitute ($param) {
1135 $variables = $param[0];
1136 $template_variable = $param[1];
1140 // Substitute variables in templates:
1141 // where {{variablename}} is found in the template, this function is passed
1142 // "variablename" and returns the proper variable
1148 global $template_id;
1150 //error_log("tvs " . print_r($template_variable,1));
1152 if (isset($variables[$template_variable])) {
1153 return $variables[$template_variable];
1155 switch($template_variable) {
1159 return $_SESSION['username'];
1161 return gettext("Guest");
1165 case "userfullname":
1167 return $_SESSION['name'];
1169 return gettext("Guest")
1170 . " [<a href=\"".url
."login/index.php\">" . gettext("Log in") . "</a>]";
1175 return templates_draw(array(
1176 'menuitems' => menu_join('', $PAGE->menu
),
1183 return templates_draw(array(
1184 'submenuitems' => menu_join(' | ', $PAGE->menu_sub
),
1185 'context' => 'submenu'
1191 return templates_draw(array(
1192 'topmenuitems' => menu_join('', $PAGE->menu_top
),
1193 'context' => 'topmenu'
1202 case "userfullname":
1204 if (!isset($page_owner) ||
$page_owner == -1) {
1207 return run("users:id_to_name", $page_owner);
1212 // $run_result = "<link href=\"/".$template_variable.".css\" rel=\"stylesheet\" type=\"text/css\" />";
1213 return "<style type=\"text/css\"><!--\n"
1214 . templates_draw(array(
1215 'template' => $template_id,
1219 . "// -->\n</style>\n"
1224 $perf = get_performance_info();
1225 if (defined('ELGG_PERFTOLOG')) {
1226 error_log("PERF: " . $perf['txt']);
1228 if (defined('ELGG_PERFTOFOOT') ||
$CFG->debug
> 7 ||
$CFG->perfdebug
> 7) {
1229 return $perf['html'];
1239 *** Fetches the template elements from disk or db.
1241 function get_template_element ($template_id, $element_name) {
1244 if ($CFG->templatestore
=== 'db') {
1245 $result = get_record('template_elements','template_id',$template_id,'name',$element_name);
1247 $template_name = get_field('templates', 'name', 'ident', $template_id);
1248 $template_name = strtolower(clean_param($template_name, PARAM_ALPHANUM
));
1249 $template_file = $CFG->templatesroot
. $template_name . '/' . $element_name;
1251 if (! $element_content = file_get_contents($template_file)) {
1252 trigger_error("Problems retrieving template element from $template_file");
1254 $result = new StdClass
;
1255 $result->content
= $element_content;
1256 $result->ident
= $template_id;
1257 $result->name
= $element_name;
1264 *** performs a join on one of
1265 *** the $PAGE->menu* variables
1268 function menu_join ($separator, $menuarray) {
1270 foreach ($menuarray as $entry) {
1271 array_push($html, $entry['html']);
1273 return join($separator, $html);