root/devel/mod/template/lib.php

Revision 1571, 3.0 kB (checked in by misja, 9 months ago)

Misja Hoebe <misja@curverider.co.uk> Applied attachment:ticket:329:080312_default_template_changing.2.diff, closes #329

  • Property svn:eol-style set to native
Line 
1 <?php
2
3 function template_pagesetup() {
4     // register links --
5     global $profile_id;
6     global $PAGE;
7     global $CFG;
8
9     $page_owner = $profile_id;
10
11     if (defined("context") && context == "account" && !$CFG->disable_templatechanging  && user_info("user_type",$_SESSION['userid']) != "external") {
12         if ($page_owner == $_SESSION['userid'] && $page_owner != -1) {
13             $PAGE->menu_sub[] = array( 'name' => 'template:change',
14                                        'html' => a_href( "{$CFG->wwwroot}mod/template/",
15                                                           __gettext("Change theme"))); 
16         }
17     }
18     
19     $CFG->templates->variables_substitute['templatesroot'][] = "templates_root";
20 }
21
22 function template_init() {
23     global $CFG,$function;
24
25     // Load default values
26     $function['init'][] = dirname(__FILE__) . "/lib/default_template.php";
27         
28     // Actions
29     $function['templates:init'][] = dirname(__FILE__) . "/lib/template_actions.php";
30
31     // Draw template (returns HTML as opposed to echoing it straight to the screen)
32     $function['templates:draw'][] = dirname(__FILE__) . "/lib/template_draw.php";
33         
34     // Function to substitute variables within a template, used in templates:draw
35     $function['templates:variables:substitute'][] = dirname(__FILE__) . "/lib/variables_substitute.php";
36
37     // Function to draw the page, once supplied with a main body and title
38     $function['templates:draw:page'][] = dirname(__FILE__) . "/lib/page_draw.php";
39         
40     // Function to display a list of templates
41     $function['templates:view'][] = dirname(__FILE__) . "/lib/templates_view.php";
42     $function['templates:preview'][] = dirname(__FILE__) . "/lib/templates_preview.php";
43                 
44     // Function to display input fields for template editing
45     $function['templates:edit'][] = dirname(__FILE__) . "/lib/templates_edit.php";
46             
47     // Function to allow the user to create a new template
48     $function['templates:add'][] = dirname(__FILE__) . "/lib/templates_add.php";
49     
50     // Adds default template
51     listen_for_event("user","create","template_user_create");
52     // Delete users
53     listen_for_event("user","delete","template_user_delete");
54 }
55
56 function templates_root($vars) {
57     global $CFG;
58     return $CFG->templatesroot;
59 }
60
61 function template_user_create($object_type, $event, $object) {
62     global $CFG;
63     // add current default template
64     $object->template_name = $CFG->default_template;
65     return $object;
66 }
67
68 function template_user_delete($object_type, $event, $object) {
69     global $CFG, $data;
70     if (!empty($object->ident) && $object_type == "user" && $event == "delete") {
71         if ($templates = get_records_sql("select * from {$CFG->prefix}templates where owner = {$object->ident}")) {
72             foreach($templates as $template) {
73                 delete_records('template_elements','template_id',$template->ident);
74             }
75         }
76         delete_records('templates','owner',$object->ident);
77     }
78     return $object;
79 }
80
81 ?>
82
Note: See TracBrowser for help on using the browser.