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 $template_definition[] = array(
87 'name' => gettext("Stylesheet"),
88 'description' => gettext("The Cascading Style Sheet for the template."),
92 $template['css'] = <<< END
100 font
-family
: "Lucida Grande", verdana
, arial
, helvetica
, sans
-serif
;
108 text
-decoration
: none
;
109 font
-family
: verdana
, arial
, helvetica
;
115 font
-family
: arial
, helvetica
, Tahoma
;
122 font
-family
: arial
, helvetica
, Tahoma
;
127 font
-family
: arial
, helvetica
, Tahoma
;
131 font
-family
: arial
, helvetica
, Tahoma
;
138 /*-------------------------------------------------
140 -------------------------------------------------*/
144 padding
: 3px
10px
2px
0;
165 #StatusRight a:hover {
166 text
-decoration
: underline
;
184 /*-------------------------------------------------
186 -------------------------------------------------*/
191 border
: 1px solid
#ccc;
201 margin
: 7px
0 0 20px
;
215 font
-family
: "Lucida Grande", arial
, sans
-serif
;
226 font
-family
: verdana
;
231 text
-decoration
: none
;
234 /*-------------------------------------------------
236 -------------------------------------------------*/
257 #ContentFrame, .ContentFrame {
263 border
: 1px solid
#ccc;
265 background
-color
: #fff;
308 margin
: 10px
0 20px
20px
;
313 #Footer .performanceinfo {
317 #Footer a:link, #Footer a:visited {
327 /*-------------------------------------------------
329 -------------------------------------------------*/
342 list-style
-type
: none
;
346 #Tabs a:link, #Tabs a:visited {
353 border
: 0px solid
#036;
354 border
-bottom
: #eaeac7;
355 text
-decoration
: none
;
359 #Tabs a:link.current, #Tabs a:visited.current {
360 border
-bottom
: 1px solid
#fff;
375 /*-------------------------------------------------
377 -------------------------------------------------*/
395 .profiletable
.fieldname
{
396 background
-color
: #F9F9F9;
397 border
-right
: 2px solid
#eaeac7; /*#8B8C8C;*/
403 .profiletable
.fieldname p
{
408 background
-color
: #F9F9F9;
409 border
: 1px solid
#DDD;
418 /*-------------------------------------------------
420 -------------------------------------------------*/
428 border
-bottom
: 1px solid
#666;
435 font
-family
: verdana
;
443 .SectionContent h3 a
{
447 .SectionContent h3 a
:hover
{
448 text
-decoration
: underline
;
451 /*-------------------------------------------------
453 -------------------------------------------------*/
457 padding
: 0 0 20px
110px
;
464 margin
: 3px
0 10px
0;
470 /* padding-top: 5px;*/
476 text
-decoration
: none
;
482 text
-decoration
: underline
;
485 h2
.date
, h2
.weblogdateheader
{
493 border
-bottom
: 1px solid
#ccc;
516 font
-family
: verdana
;
525 text
-decoration
: none
;
526 border
-bottom
: 1px dotted
#666;
532 background
-color
: #666;
535 .Post h3 a
.commentlink
:link
{
540 .Post h3 a
.commentlink
:hover
{
546 margin
: 3px
0 10px
0;
557 list-style
-type
: square
;
571 /*-------------------------------------------------
573 -------------------------------------------------*/
576 padding
: 4px
0 2px
0;
577 border
-bottom
: 1px solid
#666;
583 .Sidebar p
.incategory
{
589 .Sidebar h2
, .Sidebar h2
.border
{
590 font
-family
: "Lucida Grande", arial
, sans
-serif
;
594 margin
: 20px
0 3px
0;
600 border
-bottom
: 1px solid
#d5d5d5;
605 /*background-color: #FAC83D;*/ /*#FAC83D;*/
612 background
-color
:#FAC83D;
618 color
: #000; /*#1181AA;*/
623 .box_user
.usermenu a
{
624 color
: #000; /*#1181AA;*/
628 text
-decoration
: underline
;
634 border
-color
: #ebebeb;
635 background
-color
: #ebebeb;
644 background
-color
: #fff;
650 border
: 1px solid
#D3322A;
662 /*-------------------------------------------------
664 -------------------------------------------------*/
672 border
-bottom
: 1px solid
#d5d5d5;
680 border
-bottom
: 1px solid
#333;
687 border
-bottom
: 1px solid
#efefef;
694 .Comments div
.Post
:after
{
702 /* Hides form IE-mac \*/
703 * html
.Comments div
.Post
{height
: 1%
;}
704 /* End hide from IE-mac */
706 .Comments
#OriginalPost {
713 border
: 2px solid
#ef9c00;
725 .Post
#Preview #PreviewBody {
729 .Post
#Preview #PreviewButtons {
735 div
.Comments img
.avatar
{
736 margin
: 0 10px
10px
0;
742 div
.Comments div
.Post ul
,
743 div
.Comments div
.Post ol
{
747 div
.Comments div
.Post ol li
,
748 div
.Comments div
.Post ul li
{
751 /*-------------------------------------------------
753 -------------------------------------------------*/
761 padding
: 0 30px
0 20px
;
767 border
-left
: 1px dotted
#dcdcdc;
777 /* ------------- help files -------------*/
780 font
-family
: arial
, helvetica
, Tahoma
;
786 /*-------------- extra blog classes -----*/
792 /* padding: 0.3em 2em 2em 0; */
797 .weblog_post
.post_content
{
801 .clearing
{clear
:both
;}
803 /* site news for home.php */
817 /* ---- feeds --------- */
821 border
-bottom
: 1px dotted
#aaaaaa;
822 background
: transparent
url("{$CFG->wwwroot}_templates/sunflower.jpg") bottom right no
-repeat
;
833 border
-style
: dotted
;
837 .feed_content a
:hover
{
842 border
: 1px solid
#666666;
850 padding
: 5px
10px
5px
5px
;
852 text
-decoration
:none
;
859 border
-style
: dotted
;
863 .feed_content h5 a
:hover
{
889 $template_definition[] = array(
890 'id' => 'contentholder',
891 'name' => gettext("Content holder"),
892 'description' => gettext("Contains the main content for a page (as opposed to the sidebar or the title)."),
894 '{{title}}' => gettext("The title"),
895 '{{submenu}}' => gettext("The page submenu"),
896 '{{body}}' => gettext("The body of the page")
900 $template['contentholder'] = <<< END
902 <div
class="SectionContent">
911 $template_definition[] = array(
913 'name' => gettext("Owner box"),
914 'description' => gettext("A box containing a description of the owner of the current profile."),
916 '{{name}}' => gettext("The user's name"),
917 '{{profileurl}}' => gettext("The URL of the user's profile page, including terminating slash"),
918 '{{usericon}}' => gettext("The user's icon, if it exists"),
919 '{{tagline}}' => gettext("A short blurb about the user"),
920 '{{usermenu}}' => gettext("Links to friend / unfriend a user"),
921 '{{lmshosts}}' => gettext("Links to any lms hosts the user is attached to"),
925 $tags = gettext("Tags");
926 $resources = gettext("Resources");
927 $template['ownerbox'] = <<< END
930 <div style
="float: left; width: 70px"><a href
="{{profileurl}}">{{usericon
}}</a
></div
>
931 <div style
="margin-left: 75px; margin-top: 0px; padding-top: 0px; text-align: left" ><p
>
932 <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
>
935 <p style
="margin-bottom: 3px" class="usermenu">{{usermenu
}}</p
>
941 $template_definition[] = array(
943 'name' => gettext("Information Box"),
944 '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."),
946 '{{name}}' => gettext("The title"),
947 '{{contents}}' => gettext("The contents of the box")
950 $template['infobox'] = <<< END
952 <table
class="infobox" width
="100%">
953 <caption align
="top">
964 $template_definition[] = array(
965 'id' => 'messageshell',
966 'name' => gettext("System message shell"),
967 'description' => gettext("A list of system messages will be placed within the message shell."),
969 '{{messages}}' => gettext("The messages")
973 $template['messageshell'] = <<< END
975 <div id
="js">{{messages
}}</div
><br
/>
979 $template_definition[] = array(
981 'name' => gettext("Individual system messages"),
982 'description' => gettext("Each individual system message."),
984 '{{message}}' => gettext("The system message")
988 $template['messages'] = <<< END
997 $template_definition[] = array(
999 'name' => gettext("Main menu shell"),
1000 'description' => gettext("A list of main menu items will be placed within the menubar shell."),
1001 'glossary' => array(
1002 '{{menuitems}}' => gettext("The menu items")
1006 $template['menu'] = <<< END
1011 $template_definition[] = array(
1013 'name' => gettext("Individual main menu item"),
1014 'description' => gettext("This is the template for each individual main menu item. A series of these is placed within the menubar shell template."),
1015 'glossary' => array(
1016 '{{location}}' => gettext("The URL of the menu item"),
1017 '{{name}}' => gettext("The menu item's name")
1021 $template['menuitem'] = <<< END
1023 <li
><a href
="{{location}}">{{name
}}</a
></li
>
1027 $template_definition[] = array(
1028 'id' => 'selectedmenuitem',
1029 'name' => gettext("Selected individual main menu item"),
1030 'description' => gettext("This is the template for an individual main menu item if it is selected."),
1031 'glossary' => array(
1032 '{{location}}' => gettext("The URL of the menu item"),
1033 '{{name}}' => gettext("The menu item's name")
1037 $template['selectedmenuitem'] = <<< END
1039 <li
><a
class="current" href
="{{location}}">{{name
}}</a
></li
>
1043 $template_definition[] = array(
1045 'name' => gettext("Sub-menubar shell"),
1046 'description' => gettext("A list of sub-menu items will be placed within the menubar shell."),
1047 'glossary' => array(
1048 '{{submenuitems}}' => gettext("The menu items")
1052 $template['submenu'] = <<< END
1059 $template_definition[] = array(
1060 'id' => 'submenuitem',
1061 'name' => gettext("Individual sub-menu item"),
1062 'description' => gettext("This is the template for each individual sub-menu item. A series of these is placed within the sub-menubar shell template."),
1063 'glossary' => array(
1064 '{{location}}' => gettext("The URL of the menu item"),
1065 '{{menu}}' => gettext("The menu item's name")
1069 $template['submenuitem'] = <<< END
1071 <a href
="{{location}}">{{name
}}</a
> 
;|
1075 $template_definition[] = array(
1077 'name' => gettext("Status menubar shell"),
1078 'description' => gettext("A list of statusbar menu items will be placed within the status menubar shell."),
1079 'glossary' => array(
1080 '{{topmenuitems}}' => gettext("The menu items")
1084 $template['topmenu'] = <<< END
1086 <div id
="StatusRight">
1092 $template_definition[] = array(
1093 'id' => 'topmenuitem',
1094 'name' => gettext("Individual statusbar menu item"),
1095 'description' => gettext("This is the template for each individual statusbar menu item. A series of these is placed within the status menubar shell template."),
1096 'glossary' => array(
1097 '{{location}}' => gettext("The URL of the menu item"),
1098 '{{menu}}' => gettext("The menu item's name")
1102 $template['topmenuitem'] = <<< END
1104 [<a href
="{{location}}">{{name
}}</a
>] 
;
1108 $template_definition[] = array(
1110 'name' => gettext("Data input box (two columns)"),
1111 '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."),
1112 'glossary' => array(
1113 '{{name}}' => gettext("The name for the data we're inputting"),
1114 '{{column1}}' => gettext("The first item of data"),
1115 '{{column2}}' => gettext("The second item of data")
1119 $template['databox'] = <<< END
1121 <div
class="infobox">
1122 <table width
="95%" class="profiletable" align
="center" style
="margin-bottom: 3px">
1125 <td width
="20%" class="fieldname" valign
="top">
1126 <p
><b
>{{name
}}</b
></p
>
1128 <td width
="50%" valign
="top">
1131 <td width
="30%" valign
="top">
1140 $template_definition[] = array(
1142 'name' => gettext("Data input box (one column)"),
1143 'description' => gettext("A single-column version of the data box."),
1144 'glossary' => array(
1145 '{{name}}' => gettext("The name of the data we're inputting"),
1146 '{{column1}}' => gettext("The data itself")
1150 $template['databox1'] = <<< END
1152 <div
class="infobox">
1153 <table width
="95%" class="profiletable" align
="center" style
="margin-bottom: 3px">
1156 <td width
="20%" class="fieldname" valign
="top">
1157 <p
><b
>{{name
}}</b
></p
>
1159 <td width
="80%" valign
="top">
1168 $template_definition[] = array(
1169 'id' => 'databoxvertical',
1170 'name' => gettext("Data input box (vertical)"),
1171 'description' => gettext("A slightly different version of the data box, used on this edit page amongst other places."),
1172 'glossary' => array(
1173 '{{name}}' => gettext("Name of the data we\'re inputting"),
1174 '{{contents}}' => gettext("The data itself")
1178 $template['databoxvertical'] = <<< END
1179 <div
class="infobox">
1180 <table width
="95%" class="fileTable" align
="center" style
="margin-bottom: 3px">
1182 <td
class="fieldname">
1183 <p
><b
>{{name
}}</b
></p
>
1198 function templates_main () {
1208 // Load default values
1209 $function['init'][] = path
. "units/templates/default_template.php";
1212 $function['templates:init'][] = path
. "units/templates/template_actions.php";
1214 // Draw template (returns HTML as opposed to echoing it straight to the screen)
1215 $function['templates:draw'][] = path
. "units/templates/template_draw.php";
1217 // Function to substitute variables within a template, used in templates:draw
1218 $function['templates:variables:substitute'][] = path
. "units/templates/variables_substitute.php";
1220 // Function to draw the page, once supplied with a main body and title
1221 $function['templates:draw:page'][] = path
. "units/templates/page_draw.php";
1223 // Function to display a list of templates
1224 $function['templates:view'][] = path
. "units/templates/templates_view.php";
1225 $function['templates:preview'][] = path
. "units/templates/templates_preview.php";
1227 // Function to display input fields for template editing
1228 $function['templates:edit'][] = path
. "units/templates/templates_edit.php";
1230 // Function to allow the user to create a new template
1231 $function['templates:add'][] = path
. "units/templates/templates_add.php";
1233 if ($context == "account") {
1234 $PAGE->menu_sub
[] = array( 'name' => 'template:edit',
1235 'html' => templates_draw(array( 'context' => 'submenuitem',
1236 'name' => gettext("Change theme"),
1237 'location' => url
. '_templates/')));
1243 function templates_page_setup (){
1248 if (!empty($PAGE->setupdone
)) {
1249 return false; // don't run twice
1252 $PAGE->setupdone
= true; // leave your mark
1255 // Populate $PAGE with links for non-module core code
1259 $PAGE->menu_top
[] = array( 'name' => 'admin',
1260 'html' => a_hrefg("{$CFG->wwwroot}_admin/",
1264 $PAGE->menu_top
[] = array(
1265 'name' => 'userdetails',
1266 'html' => a_hrefg("{$CFG->wwwroot}_userdetails/",
1267 "Account settings"));
1269 $PAGE->menu_top
[] = array(
1271 'html' => a_hrefg("{$CFG->wwwroot}login/logout.php",
1274 if (context
== "account") {
1275 $PAGE->menu_sub
[] = array(
1276 'name' => 'user:edit',
1277 'html' => a_hrefg("{$CFG->wwwroot}_userdetails/",
1278 "Edit user details"));
1279 $PAGE->menu_sub
[] = array(
1280 'name' => 'user:icon',
1281 'html' => a_hrefg("{$CFG->wwwroot}_icons/",
1282 "Your site picture"));
1285 if (context
== "admin" && logged_on
&& run("users:flags:get",array("admin", $_SESSION['userid']))) {
1286 $PAGE->menu_sub
[] = array(
1288 'html' => a_hrefg("{$CFG->wwwroot}_admin/",
1291 $PAGE->menu_sub
[] = array(
1292 'name' => 'admin:useradd',
1293 'html' => a_hrefg("{$CFG->wwwroot}_admin/users_add.php",
1296 $PAGE->menu_sub
[] = array(
1297 'name' => 'admin:users',
1298 'html' => a_hrefg("{$CFG->wwwroot}_admin/users.php",
1301 $PAGE->menu_sub
[] = array(
1302 'name' => 'admin:flaggedcontent',
1303 'html' => a_hrefg("{$CFG->wwwroot}_admin/flags.php",
1304 "Manage flagged content"));
1306 $PAGE->menu_sub
[] = array(
1307 'name' => 'admin:spam',
1308 'html' => a_hrefg("{$CFG->wwwroot}_admin/antispam.php",
1315 // Give a chance to all registered modules
1317 if ($allmods = get_list_of_plugins('mod') ) {
1318 foreach ($allmods as $mod) {
1319 $mod_pagesetup = $mod . '_pagesetup';
1320 if (function_exists($mod_pagesetup)) {
1323 notify("Function $mod_pagesetup doesn't exist!");
1329 function templates_page_draw ($param) {
1330 // Draws the page, given a title and a main body (parameters[0] and [1]).
1332 $mainbody = $param[1];
1339 //// Prepare things for the module run
1340 //// populating $PAGE as required
1342 if (empty($PAGE->setupdone
)) {
1343 templates_page_setup();
1347 if (isset($messages) && sizeof($messages) > 0) {
1348 foreach($messages as $message) {
1349 $messageshell .=templates_draw(array(
1350 'context' => 'messages',
1351 'message' => $message
1355 $messageshell =templates_draw(array(
1356 'context' => 'messageshell',
1357 'messages' => $messageshell
1362 // If $parameter[2] is set, we'll substitute it for the
1364 if (isset($param[2])) {
1365 $sidebarhtml = $param[2];
1367 $sidebarhtml = run("display:sidebar");
1370 $run_result .= templates_draw(array(
1371 'context' => 'pageshell',
1373 'menu' => displaymenu(),
1374 'submenu' => displaymenu_sub(),
1375 'top' => displaymenu_top(),
1376 'sidebar' => $sidebarhtml,
1377 'mainbody' => $mainbody,
1378 'messageshell' => $messageshell
1384 function templates_actions () {
1386 global $CFG,$USER,$db;
1393 $action = optional_param('action');
1401 case "templates:select":
1402 $id = optional_param('selected_template',0,PARAM_INT
);
1406 $exists = record_exists_sql('SELECT ident FROM '.$CFG->prefix
.'templates WHERE ident = '.$id.' AND (owner = '.$USER->ident
." OR public='yes')");
1410 $t->template_id
= $id;
1411 $t->ident
= $USER->ident
;
1412 update_record('users',$t);
1414 $messages[] = gettext("Your current template has been changed.");
1418 case "templates:save":
1419 $template = optional_param('template');
1420 $id = optional_param('save_template_id',0,PARAM_INT
);
1421 $templatetitle = optional_param('templatetitle');
1422 if (!empty($template) && !empty($id) && !empty($templatetitle)) {
1423 unset($_SESSION['template_element_cache'][$id]);
1424 $exists = record_exists('templates','ident',$id,'owner',$USER->ident
);
1427 $t->name
= $templatetitle;
1429 update_record('templates',$t);
1430 delete_records('template_elements','template_id',$id);
1431 $contents = optional_param('template');
1432 foreach ($contents as $name => $content) {
1433 //TODO Fix this with PARAM_CLEANHTML or similar
1434 $slashname = addslashes($name);
1435 $slashcontent = addslashes($content);
1436 if ($content != "" && $content != $template[$name]) {
1438 $te->name
= $slashname;
1439 $te->content
= $slashcontent;
1440 $te->template_id
= $id;
1441 insert_record('template_elements',$te);
1444 $messages[] = gettext("Your template has been updated.");
1448 case "deletetemplate":
1449 $id = optional_param('delete_template_id',0,PARAM_INT
);
1450 unset($_SESSION['template_element_cache'][$id]);
1451 $exists = record_exists('templates','ident',$id,'owner',$USER->ident
);
1453 $db->execute('UPDATE '.$CFG->prefix
.'users SET template_id = -1 WHERE template_id = '.$id);
1454 delete_records('template_elements','template_id',$id);
1455 delete_records('template','ident',$id);
1456 $messages[] = gettext("Your template was deleted.");
1459 case "templates:create":
1460 $based_on = optional_param('template_based_on',0,PARAM_INT
);
1461 $name = optional_param('new_template_name');
1462 if (!empty($name)) { // $based_on can be empty, surely? -Penny
1466 $t->owner
= $USER->ident
;
1467 $new_template_id = insert_record('templates',$t);
1468 if ($based_on != -1) {
1469 $exists = record_exists_sql('SELECT ident FROM '.$CFG->prefix
.'templates WHERE ident = ? AND (owner = ? OR public = ?)',array($based_on,$USER->ident
,'yes'));
1471 if ($elements = get_records('template_elements','template_id',$based_on)) {
1472 foreach($elements as $element) {
1473 $element->template_id
= $new_template_id;
1474 insert_record('template_elements',$element);
1485 /// NOTE: this function takes a named array as single parameter
1486 function templates_draw ($parameter) {
1488 // Draw a page element using a specified template (or, if the template is -1, the default)
1489 // $parameter['template'] = the template ID, $parameter['element'] = the template element,
1490 // all other $parameter[n] = template elements
1492 // Initialise global template variable, which contains the default template
1495 // Initialise global template ID variable, which contains the template ID we're using
1496 global $template_id;
1499 global $page_template_cache;
1503 if ($parameter['context'] === 'topmenuitem') {
1504 // error_log("templates_draw pcontext " . print_r($parameter,1));
1506 // Get template details
1507 if (!isset($template_id)) {
1508 if (!isset($page_owner) ||
$page_owner == -1) {
1511 // if (!isset($_SESSION['template_id_cache'][$page_owner])) {
1512 if (!$template_id = get_field('users','template_id','ident',$page_owner)) {
1516 // $template_id = $_SESSION['template_id_cache'][$page_owner];
1520 // Template ID override
1521 $t = optional_param('template_preview',0,PARAM_INT
);
1526 // Grab the template content
1527 if ($template_id == -1 ||
($parameter['context'] != "css" && $parameter['context'] != "pageshell")) {
1528 $template_element = $template[$parameter['context']];
1530 $template_context = addslashes($parameter['context']);
1531 if (!isset($page_template_cache[$parameter['context']])) {
1532 $result = get_template_element($template_id, $template_context);
1533 $page_template_cache[$parameter['context']] = $result;
1535 $result = $page_template_cache[$parameter['context']];
1537 if (!empty($result)) {
1538 $template_element = stripslashes($result->content
);
1540 $template_element = $template[$parameter['context']];
1544 if ($parameter['context'] === 'topmenuitem') {
1545 // error_log("templates_draw pcontext " . print_r($template_element));
1548 // Substitute elements
1551 \$passed = array(".var_export($parameter,true).",\$matches[1], " . $template_id . ");
1552 return templates_variables_substitute(\$passed);
1555 // $template_element = templates_variables_substitute(array($parameter,$template_element));
1556 $body = preg_replace_callback("/\{\{([A-Za-z_0-9]*)\}\}/i",create_function('$matches',$functionbody),$template_element);
1558 $run_result = $body;
1562 function templates_add () {
1565 // Create a new template
1566 $header = gettext("Create theme"); // gettext variable
1567 $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
1573 <form action
="index.php" method
="post">
1581 $panel .=templates_draw(array(
1582 'context' => 'databox1',
1583 'name' => gettext("Theme name"),
1584 'column1' => display_input_field(array("new_template_name","","text"))
1588 $default = gettext("Default Theme"); // gettext variable
1591 <select name
="template_based_on">
1592 <option value
="-1">$default</option
>
1595 if ($templates = get_records_select('templates','owner = '.$USER->ident
." OR public = 'yes'",'public')) {
1596 foreach($templates as $template) {
1597 $column1 .= "<option value=\"".$template->ident
."\">".stripslashes($template->name
) . "</option>";
1605 $panel .=templates_draw(array(
1606 'context' => 'databox1',
1607 'name' => gettext("Based on"),
1608 'column1' => $column1
1612 $buttonValue = gettext("Create Theme"); // gettext variable
1616 <input type
="hidden" name
="action" value
="templates:create" />
1617 <input type
="submit" value
="$buttonValue" />
1624 $run_result .= $panel;
1628 function templates_edit () {
1632 global $template_definition;
1635 if (!isset($parameter)) {
1636 // Get template details
1637 if (!$template_id = get_field('users','template_id','ident',$USER->ident
)) {
1641 if (!is_array($parameter)) {
1642 $template_id = (int) $parameter;
1648 // Grab title, see if we can edit the template
1650 if ($template_id == -1) {
1651 $templatetitle = gettext("Default Theme");
1653 $templatestuff = get_record('templates','ident',$template_id);
1654 $templatetitle = stripslashes($templatestuff->name
);
1655 if ($templatestuff->owner
== $USER->ident
) {
1658 if (($templatestuff->owner
!= $USER->ident
) && ($templatestuff->public != 'yes')) {
1663 // Grab the template content
1664 if ($template_id == -1) {
1665 $current_template = $template;
1667 if ($elements = get_records('template_elements','template_id',$template_id)) {
1668 foreach($result as $element) {
1669 $current_template[stripslashes($element->name
)] = stripslashes($element->content
);
1672 $current_template = $template;
1676 $run_result .= <<< END
1678 <form action
="" method
="post">
1682 $run_result .= templates_draw(array(
1683 'context' => 'databoxvertical',
1684 'name' => gettext("Theme Name"),
1685 'contents' => display_input_field(array("templatetitle",$templatetitle,"text"))
1689 foreach($template_definition as $element) {
1691 $name = "<b>" . $element['name'] . "</b><br /><i>" . $element['description'] . "</i>";
1692 $glossary = gettext("Glossary"); // gettext variable
1694 if (is_array($element['glossary']) && sizeof($element['glossary']) > 0) {
1695 $column1 = "<b>$glossary</b><br />";
1696 foreach($element['glossary'] as $gloss_id => $gloss_descr) {
1697 $column1 .= $gloss_id . " -- " . $gloss_descr . "<br />";
1703 if ($current_template[$element['id']] == "" ||
!isset($current_template[$element['id']])) {
1704 $current_template[$element['id']] = $template[$element['id']];
1707 $column2 = display_input_field(array("template[" . $element['id'] . "]",$current_template[$element['id']],"longtext"));
1709 $run_result .=templates_draw(array(
1710 'context' => 'databox',
1712 'column2' => $column1,
1713 'column1' => $column2
1717 $run_result .=templates_draw(array(
1718 'context' => 'databoxvertical',
1720 'contents' => $column1 . "<br />" . $column2
1728 $save = gettext("Save"); // gettext variable
1729 $run_result .= <<< END
1732 <input type
="hidden" name
="action" value
="templates:save" />
1733 <input type
="hidden" name
="save_template_id" value
="$template_id" />
1734 <input type
="submit" value
="$save" />
1739 $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
1740 $run_result .= <<< END
1748 $run_result .= <<< END
1756 function templates_preview () {
1762 // Basic page elements
1764 $name = "Basic page elements";
1765 $heading1 = gettext("Heading one"); // gettext variable
1766 $heading2 = gettext("Heading two"); // gettext variable
1767 $bulletList = gettext("A bullet list"); // gettext variable
1768 $heading3 = gettext("Heading three"); // gettext variable
1769 $numberedList = gettext("A numbered list"); // gettext variable
1772 <img src
="{$CFG->wwwroot}_templates/leaves.jpg" width
="300" height
="225" alt
="A test image" align
="right" />
1774 <p
>Paragraph text
</p
>
1777 <li
>$bulletList</li
>
1781 <li
>$numberedList</li
>
1786 $run_result .=templates_draw(array(
1787 'context' => 'contentholder',
1795 $name = "Data input";
1797 $body =templates_draw(array(
1798 'context' => 'databox',
1799 'name' => gettext("Some text input"),
1800 'column1' => display_input_field(array("blank","","text")),
1801 'column2' => run("display:access_level_select",array("blank","PUBLIC"))
1804 $body .=templates_draw(array(
1805 'context' => 'databox1',
1806 'name' => gettext("Some longer text input"),
1807 'column1' => display_input_field(array("blank","","longtext"))
1810 $body .=templates_draw(array(
1811 'context' => 'databoxvertical',
1812 'name' => gettext("Further text input"),
1813 'contents' => display_input_field(array("blank","","longtext")) . "<br />" . display_input_field(array("blank","","text")) . "<br /><input type='button' value='Button' />"
1817 $run_result .=templates_draw(array(
1818 'context' => 'contentholder',
1827 function templates_view () {
1830 $user_template = get_field('users','template_id','ident',$USER->ident
);
1831 $sitename = sitename
;
1832 $title = gettext("Select / Create / Edit Themes"); // gettext variable
1833 $header = gettext("Public Themes"); // gettext variable
1834 $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
1838 <form action
="" method
="post">
1848 $template_list[] = array(
1849 'name' => gettext("Default Theme"),
1852 if ($templates = get_records('templates','public','yes')) {
1853 foreach($templates as $template) {
1854 $template_list[] = array(
1855 'name' => stripslashes($template->name
),
1856 'id' => stripslashes($template->ident
)
1860 foreach($template_list as $template) {
1861 $name = "<input type='radio' name='selected_template' value='".$template['id']."' ";
1862 if ($template['id'] == $user_template) {
1863 $name .= "checked=\"checked\"";
1866 $column1 = "<b>" . $template['name'] . "</b>";
1867 $column2 = "<a href=\"".url
."_templates/preview.php?template_preview=".$template['id']."\" target=\"preview\">" . gettext("preview") . "</a>";
1868 $panel .=templates_draw(array(
1869 'context' => 'databox',
1871 'column1' => $column1,
1872 'column2' => $column2
1877 $templates = get_records('templates','owner',$USER->ident
);
1878 $header2 = gettext("Personal themes"); // gettext variable
1879 $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
1881 if (is_array($templates) && sizeof($templates) > 0) {
1892 foreach($templates as $template) {
1893 $name = "<input type='radio' name='selected_template' value='".$template->ident
."'";
1894 if ($template->ident
== $user_template) {
1895 $name .= "checked=\"checked\"";
1898 $column1 = "<b>" . stripslashes($template->name
) . "</b>";
1899 $column2 = "<a href=\"".url
."_templates/preview.php?template_preview=".$template->ident
."\" target=\"preview\">" . gettext("preview") . "</a>";
1901 $column2 .= " | <a href=\"".url
."_templates/edit.php?id=".$template->ident
."\" >". gettext("Edit") ."</a>";
1902 $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>";
1903 $panel .=templates_draw(array(
1904 'context' => 'databox',
1906 'column1' => $column1,
1907 'column2' => $column2
1913 $submitValue = gettext("Select new theme"); // gettext variable
1917 <input type
="submit" value
=$submitValue />
1918 <input type
="hidden" name
="action" value
="templates:select" />
1925 $run_result .= $panel;
1929 function templates_variables_substitute ($param) {
1933 $variables = $param[0];
1934 $template_variable = $param[1];
1938 // Substitute variables in templates:
1939 // where {{variablename}} is found in the template, this function is passed
1940 // "variablename" and returns the proper variable
1946 global $template_id;
1948 //error_log("tvs " . print_r($template_variable,1));
1950 if (isset($variables[$template_variable])) {
1951 return $variables[$template_variable];
1953 switch($template_variable) {
1957 return $_SESSION['username'];
1959 return gettext("Guest");
1963 case "userfullname":
1965 return $_SESSION['name'];
1967 return gettext("Guest")
1968 . " [<a href=\"".url
."login/index.php\">" . gettext("Log in") . "</a>]";
1973 return templates_draw(array(
1974 'menuitems' => menu_join('', $PAGE->menu
),
1981 return templates_draw(array(
1982 'submenuitems' => menu_join(' | ', $PAGE->menu_sub
),
1983 'context' => 'submenu'
1989 return templates_draw(array(
1990 'topmenuitems' => menu_join(' | ', $PAGE->menu_top
),
1991 'context' => 'topmenu'
2000 case "userfullname":
2002 if (!isset($page_owner) ||
$page_owner == -1) {
2005 return run("users:id_to_name", $page_owner);
2010 // $run_result = "<link href=\"/".$template_variable.".css\" rel=\"stylesheet\" type=\"text/css\" />";
2011 return "<style type=\"text/css\"><!--\n"
2012 . templates_draw(array(
2013 'template' => $template_id,
2017 . "// -->\n</style>\n"
2022 $perf = get_performance_info();
2023 if (defined('ELGG_PERFTOLOG')) {
2024 error_log("PERF: " . $perf['txt']);
2026 if (defined('ELGG_PERFTOFOOT') ||
$CFG->debug
> 7 ||
$CFG->perfdebug
> 7) {
2027 return $perf['html'];
2037 *** Fetches the template elements from disk or db.
2039 function get_template_element ($template_id, $element_name) {
2042 if ($CFG->templatestore
=== 'db') {
2043 $result = get_record('template_elements','template_id',$template_id,'name',$element_name);
2045 $template_name = get_field('templates', 'name', 'ident', $template_id);
2046 $template_name = strtolower(clean_param($template_name, PARAM_ALPHANUM
));
2047 $template_file = $CFG->templatesroot
. $template_name . '/' . $element_name;
2049 if (! $element_content = file_get_contents($template_file)) {
2050 trigger_error("Problems retrieving template element from $template_file");
2052 $result = new StdClass
;
2053 $result->content
= $element_content;
2054 $result->ident
= $template_id;
2055 $result->name
= $element_name;
2062 *** performs a join on one of
2063 *** the $PAGE->menu* variables
2066 function menu_join ($separator, $menuarray) {
2068 foreach ($menuarray as $entry) {
2069 array_push($html, $entry['html']);
2071 return join($separator, $html);