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
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
18 function templates_shortname_to_file($shortname) {
19 $shortname = str_replace(" ","_",$shortname);
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
28 function templates_file_to_shortname($foldername) {
29 $foldername = str_replace("_"," ",$foldername);
33 function default_template () {
37 global $template_definition;
38 $sitename = $CFG->sitename
;
42 $template_definition[] = array(
44 'name' => __gettext("Stylesheet"),
45 'description' => __gettext("The Cascading Style Sheet for the template."),
46 'glossary' => array(),
50 $template['css'] = file_get_contents($CFG->templatesroot
. "Default_Template/css");
52 $template_definition[] = array(
54 'name' => __gettext("Page Shell"),
55 'description' => __gettext("The main page shell, including headers and footers."),
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")
66 $welcome = __gettext("Welcome"); // gettext variable
68 $template['pageshell'] = file_get_contents($CFG->templatesroot
. "Default_Template/pageshell");
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");
73 // REMOVED stylesheet (was old version and should not have been here)
74 // TODO: extract all Default_Template stuff from lib/templates.php
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)."),
81 '{{title}}' => __gettext("The title"),
82 '{{submenu}}' => __gettext("The page submenu"),
83 '{{body}}' => __gettext("The body of the page")
87 $template['contentholder'] = <<< END
89 <div
class="SectionContent">
98 $template_definition[] = array(
100 'name' => __gettext("Owner box"),
101 'description' => __gettext("A box containing a description of the owner of the current profile."),
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"),
112 $tags = __gettext("Tags");
113 $resources = __gettext("Resources");
114 $template['ownerbox'] = <<< END
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
>
122 <p style
="margin-bottom: 3px" class="usermenu">{{usermenu
}}</p
>
128 $template_definition[] = array(
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."),
133 '{{name}}' => __gettext("The title"),
134 '{{contents}}' => __gettext("The contents of the box")
137 $template['infobox'] = <<< END
139 <table
class="infobox" width
="100%">
140 <caption align
="top">
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."),
156 '{{messages}}' => __gettext("The messages")
160 $template['messageshell'] = <<< END
162 <div id
="js">{{messages
}}</div
><br
/>
166 $template_definition[] = array(
168 'name' => __gettext("Individual system messages"),
169 'description' => __gettext("Each individual system message."),
171 '{{message}}' => __gettext("The system message")
175 $template['messages'] = <<< END
184 $template_definition[] = array(
186 'name' => __gettext("Main menu shell"),
187 'description' => __gettext("A list of main menu items will be placed within the menubar shell."),
189 '{{menuitems}}' => __gettext("The menu items")
193 $template['menu'] = <<< END
198 $template_definition[] = array(
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."),
203 '{{location}}' => __gettext("The URL of the menu item"),
204 '{{name}}' => __gettext("The menu item's name")
208 $template['menuitem'] = <<< END
210 <li
><a href
="{{location}}">{{name
}}</a
></li
>
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."),
219 '{{location}}' => __gettext("The URL of the menu item"),
220 '{{name}}' => __gettext("The menu item's name")
224 $template['selectedmenuitem'] = <<< END
226 <li
><a
class="current" href
="{{location}}">{{name
}}</a
></li
>
230 $template_definition[] = array(
232 'name' => __gettext("Sub-menubar shell"),
233 'description' => __gettext("A list of sub-menu items will be placed within the menubar shell."),
235 '{{submenuitems}}' => __gettext("The menu items")
239 $template['submenu'] = <<< END
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."),
251 '{{location}}' => __gettext("The URL of the menu item"),
252 '{{menu}}' => __gettext("The menu item's name")
256 $template['submenuitem'] = <<< END
258 <a href
="{{location}}">{{name
}}</a
> 
;|
262 $template_definition[] = array(
264 'name' => __gettext("Status menubar shell"),
265 'description' => __gettext("A list of statusbar menu items will be placed within the status menubar shell."),
267 '{{topmenuitems}}' => __gettext("The menu items")
271 $template['topmenu'] = <<< END
273 <div id
="StatusRight">
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."),
284 '{{location}}' => __gettext("The URL of the menu item"),
285 '{{menu}}' => __gettext("The menu item's name")
289 $template['topmenuitem'] = <<< END
291 [<a href
="{{location}}">{{name
}}</a
>] 
;
295 $template_definition[] = array(
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."),
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")
306 $template['databox'] = <<< END
308 <div
class="infobox">
309 <table width
="95%" class="profiletable" align
="center" style
="margin-bottom: 3px">
312 <td width
="20%" class="fieldname" valign
="top">
313 <p
><b
>{{name
}}</b
></p
>
315 <td width
="50%" valign
="top">
318 <td width
="30%" valign
="top">
327 $template_definition[] = array(
329 'name' => __gettext("Data input box (one column)"),
330 'description' => __gettext("A single-column version of the data box."),
332 '{{name}}' => __gettext("The name of the data we're inputting"),
333 '{{column1}}' => __gettext("The data itself")
337 $template['databox1'] = <<< END
339 <div
class="infobox">
340 <table width
="95%" class="profiletable" align
="center" style
="margin-bottom: 3px">
343 <td width
="20%" class="fieldname" valign
="top">
344 <p
><b
>{{name
}}</b
></p
>
346 <td width
="80%" valign
="top">
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."),
360 '{{name}}' => __gettext("Name of the data we\'re inputting"),
361 '{{contents}}' => __gettext("The data itself")
365 $template['databoxvertical'] = <<< END
366 <div
class="infobox">
367 <table width
="95%" class="fileTable" align
="center" style
="margin-bottom: 3px">
369 <td
class="fieldname">
370 <p
><b
>{{name
}}</b
></p
>
385 function templates_main () {
395 // Load default values
396 $function['init'][] = path
. "units/templates/default_template.php";
399 $function['templates:init'][] = path
. "units/templates/template_actions.php";
401 // Draw template (returns HTML as opposed to echoing it straight to the screen)
402 $function['templates:draw'][] = path
. "units/templates/template_draw.php";
404 // Function to substitute variables within a template, used in templates:draw
405 $function['templates:variables:substitute'][] = path
. "units/templates/variables_substitute.php";
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";
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";
414 // Function to display input fields for template editing
415 $function['templates:edit'][] = path
. "units/templates/templates_edit.php";
417 // Function to allow the user to create a new template
418 $function['templates:add'][] = path
. "units/templates/templates_add.php";
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/')));
430 function templates_page_setup (){
435 if (!empty($PAGE->setupdone
)) {
436 return false; // don't run twice
439 $PAGE->setupdone
= true; // leave your mark
442 // Populate $PAGE with links for non-module core code
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>");
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>");
459 $PAGE->menu_top
[] = array(
461 //'html' => a_href("{$CFG->wwwroot}login/logout.php",
463 'html' => "<li><a href=\"" . $CFG->wwwroot
. "login/logout.php\">" . __gettext("Log off") . "</a></li>");
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 'name' => 'user:icon',
473 'html' => a_href("{$CFG->wwwroot}_icons/",
474 __gettext("Your site picture")));
477 if (defined("context") && context
== "admin" && logged_on
&& user_flag_get("admin", $_SESSION['userid'])) {
478 $PAGE->menu_sub
[] = array(
480 'html' => a_href("{$CFG->wwwroot}_admin/",
483 $PAGE->menu_sub
[] = array(
484 'name' => 'admin:useradd',
485 'html' => a_href("{$CFG->wwwroot}_admin/users_add.php",
486 __gettext("Add users")));
488 $PAGE->menu_sub
[] = array(
489 'name' => 'admin:users',
490 'html' => a_href("{$CFG->wwwroot}_admin/users.php",
491 __gettext("Manage users")));
493 $PAGE->menu_sub
[] = array(
494 'name' => 'admin:flaggedcontent',
495 'html' => a_href("{$CFG->wwwroot}_admin/flags.php",
496 __gettext("Manage flagged content")));
498 $PAGE->menu_sub
[] = array(
499 'name' => 'admin:spam',
500 'html' => a_href("{$CFG->wwwroot}_admin/antispam.php",
501 __gettext("Spam control")));
507 // Give a chance to all registered modules
509 if ($allmods = get_list_of_plugins('mod') ) {
510 foreach ($allmods as $mod) {
511 $mod_pagesetup = $mod . '_pagesetup';
512 if (function_exists($mod_pagesetup)) {
515 notify("Function $mod_pagesetup doesn't exist!");
521 function templates_page_draw ($param) {
522 // Draws the page, given a title and a main body (parameters[0] and [1]).
524 $mainbody = $param[1];
531 //// Prepare things for the module run
532 //// populating $PAGE as required
534 if (empty($PAGE->setupdone
)) {
535 templates_page_setup();
539 if (isset($messages) && sizeof($messages) > 0) {
540 foreach($messages as $message) {
541 $messageshell .=templates_draw(array(
542 'context' => 'messages',
543 'message' => $message
547 $messageshell =templates_draw(array(
548 'context' => 'messageshell',
549 'messages' => $messageshell
554 // If $parameter[2] is set, we'll substitute it for the
556 if (isset($param[2])) {
557 $sidebarhtml = $param[2];
559 $sidebarhtml = run("display:sidebar");
562 $run_result .= templates_draw(array(
563 'context' => 'pageshell',
564 'title' => htmlspecialchars($title, ENT_COMPAT
, 'utf-8'),
565 'menu' => displaymenu(),
566 'submenu' => displaymenu_sub(),
567 'top' => displaymenu_top(),
568 'sidebar' => $sidebarhtml,
569 'mainbody' => $mainbody,
570 'messageshell' => $messageshell
576 function templates_actions() {
578 global $CFG,$USER,$db;
582 global $template, $messages, $CFG;
584 $action = optional_param('action');
592 case "templates:select":
593 $id = optional_param('selected_template');
594 if (substr($id, 0, 2) == "db") {
595 $template_id = (int) substr($id,2);
596 $exists = record_exists_sql('SELECT ident, shortname FROM '.$CFG->prefix
.'templates WHERE ident = '.$template_id.' AND (owner = '.$USER->ident
." OR public='yes')");
598 $exists = file_exists($CFG->templatesroot
. templates_shortname_to_file($id));
601 $affected_areas = optional_param('affected_areas',0,PARAM_INT
);
602 if(is_array($affected_areas)) {
603 foreach($affected_areas as $index => $value) {
604 //TODO - check security
605 set_field('users','template_name',$id,'ident',$value);
607 $messages[] = __gettext("The templates have been changed according to your choices.");
609 $messages[] = __gettext("No changes made as no area of change was selected!");
615 case "templates:save":
616 $templatearray = optional_param('template','','');
617 $id = optional_param('save_template_id',0,PARAM_INT
);
618 $templatetitle = trim(optional_param('templatetitle'));
619 if (!empty($templatearray) && !empty($id) && !empty($templatetitle)) {
620 unset($_SESSION['template_element_cache'][$id]);
621 $exists = record_exists('templates','ident',$id,'owner',$USER->ident
);
623 set_field('templates','name',$templatetitle,'ident',$id);
624 delete_records('template_elements','template_id',$id);
625 foreach($templatearray as $name => $content) {
626 //TODO Fix this with PARAM_CLEANHTML or similar
627 $cleanname = trim($name);
628 $cleancontent = trim($content);
629 if ($content != "" && $content != $template[$name]) {
631 $te->name
= $cleanname;
632 $te->content
= $cleancontent;
633 $te->template_id
= $id;
634 insert_record('template_elements',$te);
637 $messages[] = __gettext("Your template has been updated.");
643 case "deletetemplate":
644 $id = optional_param('delete_template_id',0,PARAM_INT
);
645 unset($_SESSION['template_element_cache'][$id]);
646 $exists = record_exists('templates','ident',$id,'owner',$USER->ident
);
648 //$db->execute('UPDATE '.$CFG->prefix.'users SET template_id = -1 WHERE template_id = '.$id);
649 set_field('users', 'template_id', -1, 'template_id', $id);
650 delete_records('template_elements','template_id',$id);
651 delete_records('templates','ident',$id);
652 $messages[] = __gettext("Your template was deleted.");
657 case "templates:create":
658 $based_on = optional_param('template_based_on');
659 $name = trim(optional_param('new_template_name'));
660 if (empty($CFG->disable_usertemplates
) && !empty($name)) {
664 $t->owner
= $USER->ident
;
665 $new_template_id = insert_record('templates',$t);
666 $t->shortname
= 'db'.$new_template_id;
667 $t->ident
= $new_template_id;
668 update_record('templates',$t);
669 foreach(array('pageshell','css') as $template_element) {
670 if ($result = get_template_element($based_on, $template_element)) {
671 $element = new stdClass
;
672 $element->template_id
= $new_template_id;
673 $element->content
= $result->content
;
674 $element->name
= $template_element;
675 insert_record('template_elements',$element);
684 /// NOTE: this function takes a named array as single parameter
685 function templates_draw ($parameter) {
687 // Draw a page element using a specified template (or, if the template is -1, the default)
688 // $parameter['template'] = the template ID, $parameter['element'] = the template element,
689 // all other $parameter[n] = template elements
691 // Initialise global template variable, which contains the Default_Template
694 // Initialise global template ID variable, which contains the template ID we're using
695 global $template_name;
699 global $page_template_cache;
703 if ($parameter['context'] === 'topmenuitem') {
704 // error_log("templates_draw pcontext " . print_r($parameter,1));
706 // Get template details
707 if (!isset($template_name)) {
708 if (!isset($page_owner) ||
$page_owner == -1) {
709 $template_name = "Default_Template";
711 if (!$template_name = user_info('template_name',$page_owner)) {
712 $template_name = "Default_Template";
717 // Template ID override
718 $t = optional_param('template_preview');
723 // Grab the template content
724 if ($template_name == "Default_Template" ||
($parameter['context'] != "css" && $parameter['context'] != "pageshell")) {
725 $template_element = $template[$parameter['context']];
727 if (!isset($page_template_cache[$parameter['context']])) {
728 if ($result = get_template_element($template_name, $parameter['context'])) {
729 $page_template_cache[$parameter['context']] = $result;
731 $page_template_cache[$parameter['context']] = $template[$parameter['context']];
734 $result = $page_template_cache[$parameter['context']];
736 if (!empty($result)) {
737 $template_element = $result->content
;
739 $template_element = $template[$parameter['context']];
743 if (!empty($CFG->templates
->variables_substitute
) && !empty($CFG->templates
->variables_substitute
[$parameter['context']])) {
744 if (is_array($CFG->templates
->variables_substitute
[$parameter['context']])) {
745 foreach ($CFG->templates
->variables_substitute
[$parameter['context']] as $sub_function) {
746 $template_element .= $sub_function($vars);
748 } elseif (is_callable($CFG->templates
->variables_substitute
[$parameter['context']])) {
749 $template_element .= $CFG->templates
->variables_substitute
[$parameter['context']]($vars);
753 if ($parameter['context'] === 'topmenuitem') {
754 // error_log("templates_draw pcontext " . print_r($template_element));
757 // Substitute elements
760 \$passed = array(".var_export($parameter,true).",\$matches[1], '" . $template_name . "');
761 return templates_variables_substitute(\$passed);
764 // $template_element = templates_variables_substitute(array($parameter,$template_element));
765 $body = preg_replace_callback("/\{\{([A-Za-z_0-9: ]*)\}\}/i",create_function('$matches',$functionbody),$template_element);
772 *** Draws a form to create a new template based on one of the existing choices.
774 function templates_add () {
778 // Create a new template
779 $header = __gettext("Create theme"); // gettext variable
780 $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
786 <form action
="index.php" method
="post">
794 $panel .=templates_draw(array(
795 'context' => 'databox1',
796 'name' => __gettext("Theme name"),
797 'column1' => display_input_field(array("new_template_name","","text"))
801 $default = __gettext("Default Template"); // gettext variable
802 $templates_list = templates_list();
803 $column1 = "<select name=\"template_based_on\">";
804 foreach($templates_list as $template) {
805 $name = __gettext($template['name']);
806 $column1 .= "<option value=\"".$template['name']."\"";
807 if ($template['name'] == "Default Template") {
808 $column1 .= " selected=\"selected\"";
810 $column1 .= ">" . $name . "</option>";
817 $panel .=templates_draw(array(
818 'context' => 'databox1',
819 'name' => __gettext("Based on"),
820 'column1' => $column1
824 $buttonValue = __gettext("Create Theme"); // gettext variable
828 <input type
="hidden" name
="action" value
="templates:create" />
829 <input type
="submit" value
="$buttonValue" />
839 function templates_edit () {
843 global $template_definition;
846 if (!isset($parameter)) {
847 // Get template details
848 if (!$template_name = user_info('template_name',$USER->ident
)) {
849 $template_name = "Default_Template";
852 if (!is_array($parameter)) {
853 $template_name = trim($parameter);
855 $template_name = "Default_Template";
859 // Grab title, see if we can edit the template
861 if ($template_name == "Default_Template") {
862 $templatetitle = __gettext("Default Theme");
864 if ($templatestuff = get_record('templates','shortname',$template_name)) {
865 $templatetitle = $templatestuff->name
;
866 if ($templatestuff->owner
== $USER->ident
) {
869 if (($templatestuff->owner
!= $USER->ident
) && ($templatestuff->public != 'yes')) {
870 $template_name = 'Default_Template';
875 // Grab the template content
876 if ($template_name == "Default_Template") {
877 $current_template = $template;
880 if (substr($template_name, 0, 2) == "db") {
881 $template_id = (int) substr($template_name,2);
882 $result = get_record('template_elements','template_id',$template_id,'name',$element_name);
883 if ($elements = get_records('template_elements','template_id',$template_id)) {
884 foreach($result as $element) {
885 $current_template[$element->name
] = $element->content
;
888 $current_template = $template;
891 foreach(array('pageshell','css') as $element_name) {
892 $template_file = $CFG->templatesroot
. templates_shortname_to_file($template_name) . '/' . $element_name;
893 if ($element_content = file_get_contents($template_file)) {
894 $current_template[$element_name] = $element_content;
900 $run_result .= <<< END
902 <form action
="" method
="post">
906 $run_result .= templates_draw(array(
907 'context' => 'databoxvertical',
908 'name' => __gettext("Theme Name"),
909 'contents' => display_input_field(array("templatetitle",$templatetitle,"text"))
913 foreach($template_definition as $element) {
915 $name = "<b>" . $element['name'] . "</b><br /><i>" . $element['description'] . "</i>";
916 $glossary = __gettext("Glossary"); // gettext variable
918 if (is_array($element['glossary']) && sizeof($element['glossary']) > 0) {
919 $column1 = "<b>$glossary</b><br />";
920 foreach($element['glossary'] as $gloss_id => $gloss_descr) {
921 $column1 .= $gloss_id . " -- " . $gloss_descr . "<br />";
927 if ($current_template[$element['id']] == "" ||
!isset($current_template[$element['id']])) {
928 $current_template[$element['id']] = $template[$element['id']];
931 $column2 = display_input_field(array("template[" . $element['id'] . "]",$current_template[$element['id']],"longtext"));
933 $run_result .=templates_draw(array(
934 'context' => 'databox',
936 'column2' => $column1,
937 'column1' => $column2
941 $run_result .=templates_draw(array(
942 'context' => 'databoxvertical',
944 'contents' => $column1 . "<br />" . $column2
952 $save = __gettext("Save"); // gettext variable
953 $run_result .= <<< END
956 <input type
="hidden" name
="action" value
="templates:save" />
957 <input type
="hidden" name
="save_template_id" value
="$template_id" />
958 <input type
="submit" value
="$save" />
963 $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
964 $run_result .= <<< END
972 $run_result .= <<< END
980 function templates_preview () {
987 // Basic page elements
989 $name = "Basic page elements";
990 $heading1 = __gettext("Heading one"); // gettext variable
991 $heading2 = __gettext("Heading two"); // gettext variable
992 $bulletList = __gettext("A bullet list"); // gettext variable
993 $heading3 = __gettext("Heading three"); // gettext variable
994 $numberedList = __gettext("A numbered list"); // gettext variable
997 <img src
="{$CFG->wwwroot}_templates/leaves.jpg" width
="300" height
="225" alt
="A test image" align
="right" />
999 <p
>Paragraph text
</p
>
1002 <li
>$bulletList</li
>
1006 <li
>$numberedList</li
>
1011 $run_result .= templates_draw(array(
1012 'context' => 'contentholder',
1020 $name = "Data input";
1022 $body =templates_draw(array(
1023 'context' => 'databox',
1024 'name' => __gettext("Some text input"),
1025 'column1' => display_input_field(array("blank","","text")),
1026 'column2' => run("display:access_level_select",array("blank","PUBLIC"))
1029 $body .=templates_draw(array(
1030 'context' => 'databox1',
1031 'name' => __gettext("Some longer text input"),
1032 'column1' => display_input_field(array("blank","","longtext"))
1035 $body .=templates_draw(array(
1036 'context' => 'databoxvertical',
1037 'name' => __gettext("Further text input"),
1038 'contents' => display_input_field(array("blank","","longtext")) . "<br />" . display_input_field(array("blank","","text")) . "<br /><input type='button' value='Button' />"
1042 $run_result .=templates_draw(array(
1043 'context' => 'contentholder',
1053 *** Returns a list of templates as an array.
1055 function templates_list() {
1057 $template_list = array();
1058 if ($templates = get_list_of_plugins('mod/template/templates','theme_master')) {
1059 foreach($templates as $template) {
1060 $template_list[] = array(
1061 'name' => templates_file_to_shortname($template),
1063 'shortname' => $template
1067 if ($templates = get_records('templates','public','yes')) {
1068 foreach($templates as $template) {
1069 $template_list[] = array(
1070 'name' => $template->name
,
1071 'id' => $template->ident
,
1072 'shortname' => $template->shortname
1076 return $template_list;
1079 function templates_view () {
1083 $user_template = user_info('template_name',$USER->ident
);
1084 $sitename = sitename
;
1085 $title = __gettext("Select / Create / Edit Themes"); // gettext variable
1086 $header = __gettext("Public Themes"); // gettext variable
1087 $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
1091 <form action
="" method
="post">
1101 $template_list[] = array(
1102 'name' => __gettext("Default Theme"),
1103 'shortname' => "Default_Template",
1107 $template_list = templates_list();
1108 foreach($template_list as $template) {
1109 if ($template['name'] == "Default Template") {
1110 $template['name'] = __gettext("Default Template");
1112 $name = "<input type='radio' name='selected_template' value='".$template['shortname']."' ";
1113 if ($template['shortname'] == $user_template) {
1114 $name .= "checked=\"checked\"";
1117 $column1 = "<b>" . $template['name'] . "</b>";
1118 $column2 = "<a href=\"".url
."_templates/preview.php?template_preview=".$template['shortname']."\" target=\"preview\">" . __gettext("Preview") . "</a>";
1119 $panel .=templates_draw(array(
1120 'context' => 'databox1',
1121 'name' => $name . $column1,
1122 'column1' => $column2,
1128 $templates = get_records('templates','owner',$USER->ident
);
1129 $header2 = __gettext("Personal themes"); // gettext variable
1130 $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
1132 if (is_array($templates) && sizeof($templates) > 0) {
1143 foreach($templates as $template) {
1144 $name = "<input type='radio' name='selected_template' value='".$template->ident
."'";
1145 if ($template->shortname
== $user_template) {
1146 $name .= " checked=\"checked\"";
1149 $column1 = "<b>" . $template->name
. "</b>";
1150 $column2 = "<a href=\"".url
."_templates/preview.php?template_preview=".$template->shortname
."\" target=\"preview\">" . __gettext("Preview") . "</a>";
1152 $column2 .= " | <a href=\"".url
."_templates/edit.php?id=".$template->ident
."\" >". __gettext("Edit") ."</a>";
1153 $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>";
1154 $panel .=templates_draw(array(
1155 'context' => 'databox1',
1156 'name' => $name . $column1,
1157 'column1' => $column2,
1158 // 'column2' => $column2
1164 $ownerCommunities = get_records('users','owner',$USER->ident
);
1165 $header3 = __gettext("Change templates");
1166 $decs3 = __gettext("The selected changes will affect:");
1178 $name = "<input type='checkbox' name='affected_areas[]' value='".$USER->ident
."' checked=\"checked\" />";
1179 $column1 = "<h4>User page</h4>";
1180 $column2 = "<h4>". __gettext("Your personal space") ."</h4>";
1181 $panel .= templates_draw(array(
1182 'context' => 'adminTable',
1184 'column1' => $column1,
1185 'column2' => $column2
1189 if(!empty($ownerCommunities)) {
1190 foreach($ownerCommunities as $ownerCommunity) {
1191 $name = "<input type='checkbox' name='affected_areas[]' value='".$ownerCommunity->ident
."' />";
1192 $column1 = "<h4>".stripslashes($ownerCommunity->name
)."</h4>";
1193 $column2 = "<h4>".__gettext("Community: ") . stripslashes($ownerCommunity->name
)."</h4>";
1194 $panel .= templates_draw(array(
1195 'context' => 'adminTable',
1197 'column1' => $column1,
1198 'column2' => $column2
1205 $submitValue = __gettext("Select new theme"); // gettext variable
1209 <input type
="submit" value
="$submitValue" />
1210 <input type
="hidden" name
="action" value
="templates:select" />
1217 $run_result .= $panel;
1221 function templates_variables_substitute ($param) {
1225 $variables = $param[0];
1226 $template_variable = $param[1];
1230 // Substitute variables in templates:
1231 // where {{variablename}} is found in the template, this function is passed
1232 // "variablename" and returns the proper variable
1238 global $template_id;
1239 global $template_name;
1242 //error_log("tvs " . print_r($template_variable,1));
1245 if (isset($variables[$template_variable])) {
1246 $result .= $variables[$template_variable];
1249 if (substr_count($template_variable,":") > 0) {
1250 $vars = explode(":",$template_variable);
1251 $template_variable = $vars[0];
1253 switch($template_variable) {
1257 $result = $_SESSION['username'];
1259 $result = __gettext("Guest");
1264 $result = user_info("icon",$_SESSION['userid']);
1271 $result = htmlspecialchars($_SESSION['name'], ENT_COMPAT
, 'utf-8');
1273 $result = __gettext("Guest");
1276 case "userfullname":
1278 $result = __gettext("Welcome") . " " . htmlspecialchars($_SESSION['name'], ENT_COMPAT
, 'utf-8');
1280 $result = __gettext("Welcome") . " " . __gettext("Guest") . " [<a href=\"".url
."login/index.php\">" . __gettext("Log in") . "</a>]";
1285 $result = templates_draw(array(
1286 'menuitems' => menu_join('', $PAGE->menu
),
1293 $result = templates_draw(array(
1294 'submenuitems' => menu_join(' | ', $PAGE->menu_sub
),
1295 'context' => 'submenu'
1300 $result = templates_draw(array(
1301 'topmenuitems' => menu_join('', $PAGE->menu_top
),
1302 'context' => 'topmenu'
1311 $result = $CFG->sitename
;
1315 $result = $CFG->tagline
;
1319 // $run_result = "<link href=\"/".$template_variable.".css\" rel=\"stylesheet\" type=\"text/css\" />";
1320 $result = "<style type=\"text/css\">\n"
1321 . templates_draw(array(
1322 'template' => $template_name,
1331 $perf = get_performance_info();
1332 if (defined('ELGG_PERFTOLOG')) {
1333 error_log("PERF: " . $perf['txt']);
1335 if (defined('ELGG_PERFTOFOOT') ||
$CFG->debug
> 7 ||
$CFG->perfdebug
> 7) {
1336 $result = $perf['html'];
1344 if (isset($vars[1])) {
1345 $vars[1] = (int) $vars[1];
1350 if ($users = get_records_sql("SELECT DISTINCT u.*,i.filename AS iconfile, ".$db->random
." as rand
1351 FROM ".$CFG->prefix
."profile_data t JOIN ".$CFG->prefix
."users u ON u.ident = t.owner
1352 LEFT JOIN ".$CFG->prefix
."icons i ON i.ident = u.icon
1353 WHERE t.name IN (?,?,?) AND u.icon != ? AND t.access = ? AND u.user_type = ?
1354 ORDER BY rand LIMIT " . $vars[1],array('biography','minibio','interests',-1,'PUBLIC','person'))) {
1356 foreach($users as $user) {
1357 if ($usercount > 0) {
1362 $result .= "<a href=\"" . $CFG->wwwroot
. $user->username
. "/\">" . $user->name
. "</a>";
1366 $result .= __gettext("Sorry, no users have filled in their profiles yet.");
1372 if (isset($vars[1])) {
1373 $vars[1] = $db->qstr($vars[1]);
1375 $vars[1] = "'interests'";
1378 if (isset($vars[2])) {
1379 $vars[2] = $db->qstr($vars[2]);
1384 if (isset($vars[3])) {
1385 $vars[3] = (int) $vars[3];
1390 $users = get_records_sql("SELECT users.*, icons.filename as iconfile, icons.ident as iconid FROM ".$CFG->prefix
."tags LEFT JOIN ".$CFG->prefix
."users ON users.ident = tags.owner left join ".$CFG->prefix
."icons on icons.ident = users.icon WHERE tags.tag = ".$vars[2]." AND tags.tagtype = ".$vars[1]." AND users.icon != -1 AND tags.access = 'PUBLIC' and users.user_type = 'person' ORDER BY rand( ) LIMIT " . $vars[3]);
1391 if (sizeof($users) > 0 && is_array($users)) {
1394 <table width
="550px" border
="0" cellpadding
="0" cellspacing
="0">
1398 foreach($users as $user) {
1402 <div
class="image_holder">
1403 <a href
="{$CFG->wwwroot}{$user->username}/"><img src
="{$CFG->wwwroot}_icon/user/{$user->iconid}/w/80/h/80" border
="0" /></a
>
1405 <div
class="userdetails">
1406 <p
><a href
="{$CFG->wwwroot}{$user->username}/">{$user->name
}</a
></p
>
1420 if (isset($vars[1])) {
1421 $vars[1] = $db->qstr($vars[1]);
1423 $vars[1] = "'town'";
1425 $tags = get_records_sql("SELECT tag, count(ident) as numtags FROM `".$CFG->prefix
."tags` WHERE access = 'public' and tagtype=".$vars[1]." group by tag order by numtags desc limit 20");
1427 foreach($tags as $tag) {
1428 $result .= "<a href=\"".url
."tag/".urlencode(htmlspecialchars(strtolower($tag->tag
), ENT_COMPAT
, 'utf-8'))."\" title=\"".htmlspecialchars($tag->tag
, ENT_COMPAT
, 'utf-8')." (" .$tag->numtags
. ")\">";
1429 $result .= $tag->tag
. "</a>";
1430 if ($tag_count < sizeof($tags) - 1) {
1440 $tags = get_records_sql("SELECT tag, count(ident) as numtags FROM `".$CFG->prefix
."tags` WHERE access = 'public' and tag!='' group by tag having numtags > 1 order by ident desc limit 20");
1442 foreach($tags as $tag) {
1443 if ($tag->numtags
> $max) {
1444 $max = $tag->numtags
;
1449 foreach($tags as $tag) {
1452 $size = round((log($tag->numtags
) / log($max)) * 300);
1457 $result .= "<a href=\"".url
."tag/".urlencode(htmlspecialchars(strtolower($tag->tag
), ENT_COMPAT
, 'utf-8'))."\" style=\"font-size: $size%\" title=\"".htmlspecialchars($tag->tag
, ENT_COMPAT
, 'utf-8')." (" .$tag->numtags
. ")\">";
1458 $result .= $tag->tag
. "</a>";
1459 if ($tag_count < sizeof($tags) - 1) {
1471 if (!empty($CFG->templates
->variables_substitute
) && !empty($CFG->templates
->variables_substitute
[$template_variable])) {
1472 if (is_array($CFG->templates
->variables_substitute
[$template_variable])) {
1473 foreach ($CFG->templates
->variables_substitute
[$template_variable] as $sub_function) {
1474 $result .= $sub_function($vars);
1476 } elseif (is_callable($CFG->templates
->variables_substitute
[$template_variable])) {
1477 $result .= $CFG->templates
->variables_substitute
[$template_variable]($vars);
1480 $run_result .= $result;
1485 *** Fetches the template elements from disk or db.
1486 *** If $template_name starts with 'db', it will assume the rest of the name
1487 *** is a database ident. Otherwise, it will
1489 function get_template_element ($template_name, $element_name) {
1491 static $template_cache;
1493 // $template_name = strtolower(clean_param($template_name, PARAM_ALPHANUM));
1495 if ($CFG->templatestore
=== 'db') {
1496 if (substr($template_name, 0, 2) == "db") {
1497 $template_id = (int) substr($template_name,2);
1498 $result = get_record('template_elements','template_id',$template_id,'name',$element_name);
1500 $template_file = $CFG->templatesroot
. templates_shortname_to_file($template_name) . '/' . $element_name;
1501 if ($element_content = @file_get_contents
($template_file)) {
1502 $result = new StdClass
;
1503 $result->content
= $element_content;
1504 $result->ident
= NULL;
1505 $result->name
= $element_name;
1506 $result->shortname
= $template_name;
1510 // $template_name = get_field('templates', 'name', 'ident', $template_id);
1511 // $template_name = strtolower(clean_param($template_name, PARAM_ALPHANUM));
1512 $template_file = $CFG->templatesroot
. templates_shortname_to_file($template_name) . '/' . $element_name;
1514 if ($element_content = @file_get_contents
($template_file)) {
1515 $result = new StdClass
;
1516 $result->content
= $element_content;
1517 $result->ident
= $template_id;
1518 $result->name
= $element_name;
1519 $result->shortname
= $template_name;
1526 *** performs a join on one of
1527 *** the $PAGE->menu* variables
1530 function menu_join ($separator, $menuarray) {
1532 foreach ($menuarray as $entry) {
1533 array_push($html, $entry['html']);
1535 return join($separator, $html);