Changeset 1278

Show
Ignore:
Timestamp:
11/08/07 20:18:04 (1 year ago)
Author:
rho
Message:

close #135, now loads templates on demand. Added new function
templates_add_contenxt()

Sign-off-by: Rolando Espinoza La Fuente <rho@prosoftpeople.com>

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • devel/lib/templates.php

    r1251 r1278  
    681681            $template_name = $t; 
    682682        } 
     683 
     684        // TODO: Load templates on demand with backward compatibility 
     685        templates_load_context($parameter['context']); 
    683686 
    684687    // Grab the template content 
     
    15061509} 
    15071510 
     1511/** 
     1512 * Adds new template context 
     1513 * @param string $context  Context identificator 
     1514 * @param string $tpl      Template path relative to dirroot or inline template 
     1515 * @param bool   $is_file  Template is file or inline 
     1516 * @param bool   $override To override existing context 
     1517 */ 
     1518function templates_add_context($context, $tpl, $is_file=true, $override=false) { 
     1519    // TODO: this function should go int mod's? 
     1520    global $template, $template_files, $CFG; 
     1521 
     1522    if (!isset($template)) $template = array(); 
     1523    if (!isset($template_files)) $template_files = array(); 
     1524 
     1525    if (!empty($context)) { 
     1526        // clean file path string 
     1527        if ($is_file) { 
     1528            // FIXME: backward compatiblity, allow templatesroot full path 
     1529            if (substr_count($tpl, $CFG->templatesroot) > 0) { 
     1530                $file_path = $tpl; 
     1531            } else { 
     1532                //$file_path = $CFG->dirroot . clean_filename($tpl); 
     1533                // clean_filename replaces / directory separator 
     1534                $file_path = $CFG->dirroot . $tpl; 
     1535            } 
     1536        } 
     1537 
     1538        if ($is_file) { 
     1539            if ($override) { 
     1540                $template_files[$context] = array(); 
     1541            } 
     1542 
     1543            $template_files[$context][] = $file_path; 
     1544        } else { 
     1545            // inline template, backwards compatibility 
     1546            if (!$override && isset($template[$context])) { 
     1547                // append to existing context 
     1548                $template[$context] .= $tpl; 
     1549            } else { 
     1550                $template[$context] = $tpl; 
     1551            } 
     1552        } 
     1553    } 
     1554} 
     1555 
     1556/** 
     1557 * Load context if template is file  
     1558 * @param string $context Context identificator 
     1559 */ 
     1560function templates_load_context($context) { 
     1561    // TOOD: review check 
     1562    // currently check if starts with $CFG->dirrot and is file readable 
     1563    global $template, $template_files, $CFG; 
     1564 
     1565    static $loaded; 
     1566 
     1567    if (!isset($loaded)) $loaded = array(); 
     1568    if (!isset($template)) $template = array(); 
     1569    if (!isset($template_files)) $template_files = array(); 
     1570 
     1571    if (!isset($loaded[$context])) { 
     1572        if (isset($template_files[$context])) { 
     1573            if (!isset($template[$context])) { 
     1574                $template[$context] = ''; 
     1575            } 
     1576 
     1577            // load templates from files 
     1578            foreach ($template_files[$context] as $k => $tpl) { 
     1579                // TODO: check again if is readable? 
     1580                $template[$context] .= @file_get_contents($tpl); 
     1581                //print_object('Loaded: ' . $tpl); 
     1582            } 
     1583        } else { 
     1584            // do nothing if not file 
     1585        } 
     1586 
     1587        $loaded[$context] = true; 
     1588    } 
     1589} 
    15081590 
    15091591?> 
  • devel/mod/blog/default_template.php

    r1079 r1278  
    4747    ); 
    4848 
    49     $template['weblogpost'] = file_get_contents(dirname(__FILE__)."/templates/blog_post.html"); 
    50     $template['weblogcomments'] = file_get_contents(dirname(__FILE__)."/templates/blog_comments.html"); 
    51     $template['weblogcomment'] = file_get_contents(dirname(__FILE__)."/templates/blog_comment.html"); 
     49    templates_add_context('weblogpost', 'mod/blog/templates/blog_post.html'); 
     50    templates_add_context('weblogcomments', 'mod/blog/templates/blog_comments.html'); 
     51    templates_add_context('weblogcomment', 'mod/blog/templates/blog_comment.html'); 
    5252?> 
  • devel/mod/commentwall/lib.php

    r1277 r1278  
    1919                 
    2020                // Define some templates 
    21                $template['commentwallobject'] = file_get_contents($CFG->dirroot . "mod/commentwall/template"); 
    22                $template['commentwallfooter'] = file_get_contents($CFG->dirroot . "mod/commentwall/footer"); 
    23                $template['css'] .= file_get_contents($CFG->dirroot . "mod/commentwall/css"); 
     21        templates_add_context('commentwallobject', 'mod/commentwall/template'); 
     22        templates_add_context('commentwallfooter', 'mod/commentwall/footer'); 
     23        templates_add_context('css', 'mod/commentwall/css'); 
    2424                 
    2525                // Set up the database 
  • devel/mod/community/default_template.php

    r1080 r1278  
    5353    ); 
    5454 
    55 $template["community_members"] = "<div id=\"networktable\"><table width=\"80%\" cellspacing=\"5\"><tr>{{members}}</tr></table></div>"
    56 $template["community_member"] = file_get_contents(dirname(__FILE__)."/templates/community_member_view.html"); 
    57 $template["community_membership"] = file_get_contents(dirname(__FILE__)."/templates/community_membership_view.html"); 
    58 $template["community_create"] = file_get_contents(dirname(__FILE__)."/templates/community_create.html"); 
     55templates_add_context('community_members', "<div id=\"networktable\"><table width=\"80%\" cellspacing=\"5\"><tr>{{members}}</tr></table></div>", false)
     56templates_add_context('community_member', 'mod/community/templates/community_member_view.html'); 
     57templates_add_context('community_membership', 'mod/community/templates/community_membership_view.html'); 
     58templates_add_context('community_create', 'mod/community/templates/community_create.html'); 
    5959 
    6060?> 
  • devel/mod/contenttoolbar/default_template.php

    r1081 r1278  
    4040); 
    4141 
    42 $template["contenttoolbar"] = file_get_contents(dirname(__FILE__)."/templates/contenttoolbar.html"); 
    43 $template["video_wizard"] = file_get_contents(dirname(__FILE__)."/templates/video_wizard.html"); 
     42templates_add_context('contenttoolbar', 'mod/contenttoolbar/templates/contenttoolbar.html'); 
     43templates_add_context('video_wizard', 'mod/contenttoolbar/templates/video_wizard.html'); 
    4444?> 
  • devel/mod/friend/default_template.php

    r1248 r1278  
    3131    ); 
    3232 
    33  $template['friends_friends'] = "<div id=\"networktable\"><table width=\"80%\" cellspacing=\"5\"><tr>{{friends}}</tr></table></div>"
    34  $template['friends_friend'] = file_get_contents(dirname(__FILE__)."/templates/friends_friend.html"); 
     33 templates_add_context('friends_friends', "<div id=\"networktable\"><table width=\"80%\" cellspacing=\"5\"><tr>{{friends}}</tr></table></div>", false)
     34 templates_add_context('friends_friend', 'mod/friend/templates/friends_friend.html'); 
    3535?> 
  • devel/mod/generic_comments/lib.php

    r1185 r1278  
    3030                river_register_friendlyname_hook('file::file', 'generic_comments_get_friendly_name'); 
    3131        } 
    32         $template['embeddedcomments'] = file_get_contents($CFG->dirroot . "mod/generic_comments/comments"); 
    33         $template['embeddedcomment'] = file_get_contents($CFG->dirroot . "mod/generic_comments/comment"); 
    34          
    35         $template['css'] .= file_get_contents($CFG->dirroot . "mod/generic_comments/css"); 
     32    templates_add_context('embeddedcomments', 'mod/generic_comments/comments'); 
     33    templates_add_context('embeddedcomment', 'mod/generic_comments/comment'); 
     34    templates_add_context('css', 'mod/generic_comments/css', true, false); 
    3635 
    3736} 
  • devel/mod/widget/init.php

    r1030 r1278  
    22 
    33    global $CFG, $template; 
    4     $template['css'] .= file_get_contents($CFG->dirroot . "mod/widget/css"); 
     4    templates_add_context('css', 'mod/widget/css'); 
    55 
    66?> 
  • devel/units/templates/default_template.php

    r1110 r1278  
    1313                                    ); 
    1414 
    15     $template['css'] = file_get_contents($CFG->templatesroot . "Default_Template/css"); 
     15    templates_add_context('css', $CFG->templatesroot . 'Default_Template/css'); 
    1616 
    1717    $template_definition[] = array( 
     
    3030                                    ); 
    3131     
    32     $template['pageshell'] = file_get_contents($CFG->templatesroot . "Default_Template/pageshell"); 
    33      
    34     $template['frontpage_loggedout'] = file_get_contents($CFG->templatesroot . "Default_Template/frontpage_loggedout"); 
    35     $template['frontpage_loggedin'] = file_get_contents($CFG->templatesroot . "Default_Template/frontpage_loggedin"); 
     32    templates_add_context('pageshell', $CFG->templatesroot . 'Default_Template/pageshell'); 
     33     
     34    templates_add_context('frontpage_loggedout', $CFG->templatesroot . 'Default_Template/frontpage_loggedout'); 
     35    templates_add_context('frontpage_loggedin', $CFG->templatesroot . 'Default_Template/frontpage_loggedin'); 
    3636 
    3737    $template_definition[] = array(