Changeset 1363

Show
Ignore:
Timestamp:
12/04/07 19:37:10 (1 year ago)
Author:
rho
Message:

improved sidebar plugin

  • Use default keyword {{sidebar}}
  • Support legacy sidebar blocks
  • Misc tweaks

Signed-off: Rolando Espinoza La fuente <rho@prosoftpeople.com>

Files:

Legend:

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

    r1355 r1363  
    55    global $CFG; 
    66    global $function; 
    7  
    8     // register template variable 
    9     $CFG->templates->variables_substitute['newsidebar'][] = 'sidebar_display'; 
     7    global $PAGE; 
    108 
    119    // base path 
     
    1513    $function['init'][] = $base_path . 'default_templates.php'; 
    1614    // legacy sidebar elements 
    17     $function['sidebar:legacy:logpane'][] = $CFG->dirroot . 'mod/display/lib/function_log_on_pane.php'; 
    18     $function['sidebar:legacy:stats'][] = $CFG->dirroot . 'mod/users/lib/function_number_of_users.php'; 
    19     $function['sidebar:legacy:friends'][] = $CFG->dirroot . 'mod/friend/lib/profile_friends.php'; 
    20     $function['sidebar:legacy:blog'][] = $CFG->dirroot . 'mod/blog/lib/weblogs_user_info_menu.php'; 
    21     $function['sidebar:legacy:communities'][] = $CFG->dirroot . 'mod/community/lib/community_memberships.php'; 
    22     $function['sidebar:legacy:mycommunities'][] = $CFG->dirroot . 'mod/community/lib/communities_owned.php'; 
    23     $function['sidebar:legacy:files'][] = $CFG->dirroot . 'mod/file/lib/files_user_info_menu.php'; 
     15    $PAGE->sidebar_legacy = array(); 
     16 
     17    $PAGE->sidebar_legacy['sidebar-profile'] = 10; 
     18    $function['sidebar-profile'][] = $CFG->dirroot . 'mod/display/lib/function_log_on_pane.php'; 
     19 
     20    $PAGE->sidebar_legacy['sidebar-stats'] = 50; 
     21    $function['sidebar-stats'][] = $CFG->dirroot . 'mod/users/lib/function_number_of_users.php'; 
     22 
     23    $PAGE->sidebar_legacy['sidebar-blog'] = 30; 
     24    $function['sidebar-blog'][] = $CFG->dirroot . 'mod/blog/lib/weblogs_user_info_menu.php'; 
     25 
     26    $PAGE->sidebar_legacy['sidebar-friends'] = 40; 
     27    $function['sidebar-friends'][] = $CFG->dirroot . 'mod/friend/lib/profile_friends.php'; 
     28 
     29    $PAGE->sidebar_legacy['sidebar-communities'] = 50; 
     30    $function['sidebar-communities'][] = $CFG->dirroot . 'mod/community/lib/community_memberships.php'; 
     31 
     32    $PAGE->sidebar_legacy['sidebar-mycommunities'] = 60; 
     33    $function['sidebar-mycommunities'][] = $CFG->dirroot . 'mod/community/lib/communities_owned.php'; 
     34 
     35    $PAGE->sidebar_legacy['sidebar-files'] = 60; 
     36    $function['sidebar-files'][] = $CFG->dirroot . 'mod/file/lib/files_user_info_menu.php'; 
    2437 
    2538    // others plugins 
    2639    if (is_readable($CFG->dirroot . 'mod/category/category_sidebar.php')) { 
    27         $function['sidebar:legacy:category'][] = $CFG->dirroot . 'mod/category/category_sidebar.php'; 
     40        $PAGE->sidebar_legacy['sidebar-blogcats'] = 30; 
     41        $function['sidebar-blogcats'][] = $CFG->dirroot . 'mod/category/category_sidebar.php'; 
    2842    } 
    2943 
    3044    if (is_readable($CFG->dirroot . 'mod/vanillaforum/lib/user_info_menu.php')) { 
    31         $function['sidebar:legacy:vanilla'][] = $CFG->dirroot . 'mod/vanillaforum/lib/user_info_menu.php'; 
     45        $PAGE->sidebar_legacy['sidebar-vanilla'] = 25; 
     46        $function['sidebar-vanilla'][] = $CFG->dirroot . 'mod/vanillaforum/lib/user_info_menu.php'; 
    3247    } 
    3348 
     
    3651function sidebar_pagesetup() { 
    3752    global $function; 
     53    global $PAGE; 
    3854 
     55    $runned = array(); 
    3956    // legacy sidebar blocks 
    40     sidebar_add(40, 'sidebar-profile', sidebar_legacy_wrap(run('sidebar:legacy:logpane'))); 
    41  
    42     sidebar_add(50, 'sidebar-stats', sidebar_legacy_wrap(run('sidebar:legacy:stats'))); 
    43  
    44     sidebar_add(20, 'sidebar-blog', sidebar_legacy_wrap(run('sidebar:legacy:blog'))); 
    45  
    46     sidebar_add(40, 'sidebar-friends', sidebar_legacy_wrap(run('sidebar:legacy:friends'))); 
    47  
    48     sidebar_add(50, 'sidebar-communities', sidebar_legacy_wrap(run('sidebar:legacy:communities'))); 
    49  
    50     sidebar_add(60, 'sidebar-mycommunities', sidebar_legacy_wrap(run('sidebar:legacy:mycommunities'))); 
    51  
    52     sidebar_add(30, 'sidebar-files', sidebar_legacy_wrap(run('sidebar:legacy:files'))); 
    53  
    54     if (isset($function['sidebar:legacy:category'])) { 
    55         sidebar_add(25, 'sidebar-blogcats', sidebar_legacy_wrap(run('sidebar:legacy:category'))); 
     57    if (is_array($PAGE->sidebar_legacy)) { 
     58        foreach ($PAGE->sidebar_legacy as $key => $weight) { 
     59            sidebar_add($weight, $key, sidebar_legacy_wrap(run($key))); 
     60            $runned[] = $function[$key]; 
     61            //print_object($key); 
     62        } 
    5663    } 
    5764 
    58     if (isset($function['sidebar:legacy:vanilla'])) { 
    59         sidebar_add(25, 'sidebar-vanilla', sidebar_legacy_wrap(run('sidebar:legacy:vanilla'))); 
     65    // filter legacy sidebar code already included 
     66    if (isset($function['display:sidebar'])) { 
     67        foreach ($function['display:sidebar'] as $n => $script) { 
     68            if (!in_arrayr($script, $runned)) { 
     69                // temp function() 
     70                $function["sidebar:$n"][] = $script; 
     71                // include as generic block 
     72                sidebar_add(99, "sidebar-$n", sidebar_legacy_wrap(run("sidebar:$n"))); 
     73                // unset 
     74                unset($function["sidebar:$n"]); 
     75            } 
     76        } 
     77        //print_object($runned); 
    6078    } 
     79 
     80    // replace old code 
     81    $function['display:sidebar'] = array(dirname(__FILE__) . '/lib/sidebar_display.php'); 
    6182} 
    6283 
     
    156177function sidebar_legacy_wrap($body) { 
    157178    // remove <li></li> 
    158     return preg_replace("#^\s*(<li|<li\s+id=\"[a-zA-Z0-9-_]+\"\s*)>(.*)</li>\s*$#si", "\${2}", $body); 
     179    return preg_replace("#^\s*(<li|<li\s+[\"\'\w-_\.\s\=]*\s*)>(.*)</li>\s*$#si", "\${2}", $body); 
     180
     181 
     182if (!function_exists('in_arrayr')) { 
     183    function in_arrayr($needle, $haystack) { 
     184        foreach ($haystack as $v) { 
     185            if ($needle == $v) { 
     186                return true; 
     187            } elseif (is_array($v)) { 
     188                if (in_arrayr($needle, $v) === true) { 
     189                    return true; 
     190                } 
     191            } 
     192        } 
     193 
     194        return false; 
     195    } 
    159196} 
    160197 
  • devel/mod/template/edit.php

    r1301 r1363  
    2424} 
    2525 
    26 $body = templates_draw(array( 
    27                              'context' => 'contentholder', 
    28                              'title' => $title, 
    29                              'body' => $body 
    30                              ) 
    31                        ); 
    32                         
    33 echo templates_page_draw( array( 
    34                                       $title, $body 
    35                                       ) 
    36          ); 
     26templates_page_output($title, $body); 
    3727 
    3828?> 
  • devel/mod/template/index.php

    r1301 r1363  
    1818        $body .= templates_add(); 
    1919         
    20         $body = templates_draw(array( 
    21                         'context' => 'contentholder', 
    22                         'title' => $title, 
    23                         'body' => $body 
    24                     ) 
    25                     ); 
    26          
    27         echo templates_page_draw( array( 
    28                         $title, $body 
    29                     ) 
    30                     ); 
     20        templates_page_output($title, $body); 
    3121 
    3222?> 
  • devel/mod/template/templates/Default_Template/pageshell

    r1353 r1363  
    2121                <div id="splitpane-sidebar"><!-- open splitpane-sidebar div --> 
    2222                    <div id="sidebar-contents"> 
    23                         {{newsidebar}} 
     23                        {{sidebar}} 
    2424                        </div> 
    2525                        <div id="sidebar-bottom"></div><!-- used to provide the rounded bottom -->