Changeset 1470

Show
Ignore:
Timestamp:
12/17/07 02:48:21 (8 months ago)
Author:
rho
Message:

Path #213, admin can view error log inside elggadmin

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

Files:

Legend:

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

    r1430 r1470  
    1717 
    1818        elggadmin_add_rule('mod/elggadmin/?$', 'elggadmin_page'); 
    19         elggadmin_add_rule('mod/elggadmin/(theme|frontpage)$', 'elggadmin_page'); 
    20         elggadmin_add_rule('mod/elggadmin/index.php/?(theme|frontpage)?$', 'elggadmin_page'); 
     19        elggadmin_add_rule('mod/elggadmin/(theme|frontpage|logs)$', 'elggadmin_page'); 
     20        elggadmin_add_rule('mod/elggadmin/index.php/?(theme|frontpage|logs)?$', 'elggadmin_page'); 
    2121 
    2222        elggadmin_add_function('elggadmin_page_before', 'elggadmin_actions'); 
     
    5353        // submenu options 
    5454        pages_submenu_add('elggadmin', __gettext('Configuration manager'), get_url(null, 'elggadmin::')); 
    55         pages_submenu_add('elggadmin', __gettext('Default theme editor'), get_url(null, 'elggadmin::theme')); 
    56         pages_submenu_add('elggadmin', __gettext('Frontpage template editor'), get_url(null, 'elggadmin::frontpage')); 
     55        pages_submenu_add('elggadmin:theme', __gettext('Default theme editor'), get_url(null, 'elggadmin::theme')); 
     56        pages_submenu_add('elggadmin:frontpage', __gettext('Frontpage template editor'), get_url(null, 'elggadmin::frontpage')); 
     57        pages_submenu_add('elggadmin:logs', __gettext('Error log'), get_url(null, 'elggadmin::logs')); 
    5758 
    5859        sidebar_add(50, 'sidebar-'.elggadmin_currentpage(), elggadmin_sidebar()); 
     
    8485            $url = get_url(null, 'elggadmin::') . '/frontpage'; 
    8586            break; 
     87        case 'elggadmin::logs': 
     88            $url = get_url(null, 'elggadmin::') . '/logs'; 
     89            break; 
     90 
    8691    } 
    8792 
  • devel/mod/elggadmin/lib/elggadmin.inc.php

    r1447 r1470  
    3030        $page = elggadmin_page_frontpage(); 
    3131        elggadmin_currentpage('frontpage'); 
     32    } elseif ($page_name == 'logs') { 
     33        $page = elggadmin_page_logs(); 
     34        elggadmin_currentpage('logs'); 
    3235    } else { 
    3336        $page = elggadmin_page_config(); 
     
    212215} 
    213216 
     217function elggadmin_page_logs() { 
     218    global $CFG; 
     219 
     220    $action = optional_param('action'); 
     221    if ($action == 'elggadmin:logs:clear') { 
     222        elggadmin_writefile($CFG->dataroot.'errors.log',""); 
     223        header_redirect(get_url(null,'elggadmin::logs'), __gettext('Error log cleared')); 
     224    } 
     225 
     226    $logs = elggadmin_tailfile($CFG->dataroot.'errors.log', 50); 
     227 
     228    $clear = '&raquo; ' . pages_html_a(get_url_query(1, 'elggadmin::logs', 'action=elggadmin:logs:clear'), __gettext('Clear error log')); 
     229 
     230    $page = new StdClass; 
     231    $page->title = __gettext('Error log'); 
     232    $page->body = pages_html_wrap('p', $clear); 
     233    $page->body .= pages_html_wrap('textarea', $logs, array('wrap'=>'off', 'readonly'=>'readonly')); 
     234 
     235    return $page; 
     236} 
     237 
    214238function elggadmin_page_theme() { 
    215239    $page = new StdClass; 
     
    436460} 
    437461 
    438 function elggadmin_tpltextarea($tplname, $title=null) { 
     462function elggadmin_tpltextarea($tplname, $title=null, $attrs=null) { 
    439463    $output = ''; 
     464    $_attrs = array('name' => $tplname, 'style' => 'width:95%;height:300px;margin:0px 10px 20px 10px;'); 
     465 
    440466    if (is_string($title)) { 
    441467        $output .= pages_html_wrap('h2', $title); 
     
    446472    } 
    447473 
    448     $output .= pages_html_wrap('textarea', empty($tpl) ? ' ' : $tpl, array('name' => $tplname, 'style' => 'width:95%;height:300px;margin:0px 10px 20px 10px;')); 
     474    if ($is_array($attrs)) { 
     475        $_attrs = array_merge($attrs, $_attrs); 
     476    } 
     477 
     478    $output .= pages_html_wrap('textarea', empty($tpl) ? ' ' : $tpl, $_attrs); 
    449479 
    450480    return $output; 
     
    498528} 
    499529 
     530function elggadmin_tailfile($file, $lines=20) { 
     531    if ($fp = @fopen($file, 'r')) { 
     532        $pos = -1; 
     533        $t = ' '; 
     534        $content = ''; 
     535 
     536        if ($lines < 0) { 
     537            $lines = 20; 
     538        } 
     539 
     540        while ($lines > 0) { 
     541            if (!fseek($fp, $pos, SEEK_END)) { 
     542                $t = fgetc($fp); 
     543                $pos--; 
     544                if ($t == "\n") { 
     545                    $lines--; 
     546                } 
     547                $content = $t . $content; 
     548            } else { 
     549                rewind($fp); 
     550                $lines--; 
     551            } 
     552        } 
     553 
     554        @fclose($fp); 
     555        return $content; 
     556    } else { 
     557        return null; 
     558    } 
     559} 
     560 
    500561?>