Changeset 906

Show
Ignore:
Timestamp:
09/23/07 03:51:17 (14 months ago)
Author:
smerrill
Message:

* trying out iconv functions in Utils::truncate(), per issue 430. Please report issues on that ticket, in order to centralize any discussion.

* first stab at filtering log entries. Filtering by "type" does not work; nor does deleting log entries (that bit still needs to be wired up). Please report issues to -dev for discussion.

* fixing a problem with the dashboard's display of total number of posts.

Location:
trunk/htdocs/system
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/htdocs/system/admin/dashboard.php

    r868 r906  
    8181      <h3><?php _e( 'Site Statistics' ); ?></h3> 
    8282      <table id="site-stats" width="100%" cellspacing="0"> 
    83         <tr><td><?php _e( 'Total Posts' ); ?></td><td><?php echo Posts::count_total( Post::status( 'all' ) ); ?></td></tr> 
     83        <tr><td><?php _e( 'Total Posts' ); ?></td><td><?php echo Posts::count_total( Post::status( 'any' ) ); ?></td></tr> 
    8484        <tr><td><?php _e( 'Number of Your Posts' ); ?></td><td><?php echo Posts::count_by_author( User::identify()->id, Post::status( 'all' ) ); ?></td></tr> 
    8585        <tr><td><?php _e( 'Number of Comments' ); ?></td><td><?php echo Comments::count_total(); ?></td></tr> 
  • trunk/htdocs/system/admin/logs.php

    r867 r906  
    88    </div> 
    99    <div class="dashboard-block c3" id="log-activity"> 
     10    <form method="post" action="<?php URL::out('admin', 'page=logs'); ?>" class="buttonform"> 
     11    <p>Search log entries:  
     12    <input type="textbox" size="50" name='search' value="<?php echo $search; ?>"> <input type="submit" name="do_search" value="<?php _e('Search'); ?>"> 
     13    <?php printf( _t('Limit: %s'), Utils::html_select('limit', $limits, $limit)); ?> 
     14    <?php printf( _t('Page: %s'), Utils::html_select('index', $pages, $index)); ?> 
     15    <a href="<?php URL::out('admin', 'page=logs'); ?>">Reset</a> 
     16    </p> 
    1017        <table id="log-activity-table" width="100%" cellspacing="0"> 
    1118            <thead> 
    1219                <tr> 
     20                    <th></th> 
    1321                    <th align="left">Date</th> 
    1422                    <th align="left">User</th> 
    1523                    <th align="left">Type</th> 
     24                    <th align="center">Severity</th> 
    1625                    <th align="left">Message</th> 
    17                     <th align="center">Severity</th> 
    1826                </tr> 
    1927            </thead> 
    20             <?php foreach( eventlog::get( array( 'nolimit' => true ) ) as $log ){ ?> 
    2128            <tr> 
     29            <td></td> 
     30            <td><?php echo Utils::html_select('date', $dates, $date); ?></td> 
     31            <td><?php echo Utils::html_select('user', $users, $user); ?></td> 
     32            <td><?php echo Utils::html_select('type', $types, $type); ?></td> 
     33            <td><?php echo Utils::html_select('severity', $severities, $severity); ?></td> 
     34            <td align="right"><input type="submit" name="filter" value="<?php _e('Filter'); ?>"></td> 
     35            </tr> 
     36            <?php foreach( $logs as $log ){ ?> 
     37            <tr> 
     38                <td align="center"><input type="checkbox" name="log_ids[]" value="<?php echo $log->id; ?>"></td> 
    2239                <td><?php echo $log->timestamp; ?></td> 
    2340                <td><?php if ( $log->user_id ) { $user= User::get_by_id( $log->user_id ); echo $user->username; } ?></td> 
    2441                <td><?php echo $log->type; ?></td> 
     42                <td><?php echo $log->severity; ?></td> 
    2543                <td><p><?php echo $log->message; ?></p></td> 
    26                 <td><?php echo $log->severity; ?></td> 
    2744            </tr> 
    2845            <?php } ?> 
     46            <tr><td colspan="6"> 
     47            <input type="hidden" name="nonce" value="<?php echo $wsse['nonce']; ?>"> 
     48             <input type="hidden" name="timestamp" value="<?php echo $wsse['timestamp']; ?>"> 
     49             <input type="hidden" name="PasswordDigest" value="<?php echo $wsse['digest']; ?>"> 
     50             <input type="submit" name="do_delete" value="<?php _e('Delete'); ?>"> 
    2951        </table> 
    3052    </div> 
  • trunk/htdocs/system/classes/adminhandler.php

    r900 r906  
    542542    } 
    543543     
     544    public function get_logs() 
     545    { 
     546        $this->post_logs(); 
     547    } 
     548 
     549    public function post_logs() 
     550    { 
     551        $locals= array( 
     552            'do_update' => false, 
     553            'log_ids' => null, 
     554            'nonce' => '', 
     555            'timestamp' => '', 
     556            'PasswordDigest' => '', 
     557            'change' => '', 
     558            'limit' => 20, 
     559            'user' => 0, 
     560            'date' => 'any', 
     561            'type' => 'any', 
     562            'severity' => 'any', 
     563            'search' => '', 
     564            'do_search' => false, 
     565            'index' => 1, 
     566        ); 
     567        foreach ( $locals as $varname => $default ) { 
     568            $$varname= isset($this->handler_vars[$varname]) ? $this->handler_vars[$varname] : $default; 
     569            $this->theme->{$varname}= $$varname; 
     570        } 
     571        $this->theme->severities= LogEntry::list_severities(); 
     572        $types= array( 0 => 'Any'); 
     573        $this->theme->types= array_merge( $types, LogEntry::list_types() ); 
     574 
     575        // set up the users 
     576        $users_temp= DB::get_results( 'SELECT username, user_id FROM ' . DB::table('users') . ' JOIN ' . DB::table('log') . ' ON ' . DB::table('users') . '.id=' . DB::table('log') . '.user_id GROUP BY user_id ORDER BY username ASC'); 
     577        array_unshift( $users_temp, new QueryRecord(array('username' => 'All', 'user_id' => 0))); 
     578        foreach ($users_temp as $user) { 
     579            $users[$user->user_id]= $user->username; 
     580        } 
     581        $this->theme->users= $users; 
     582         
     583        // set up dates. 
     584        $dates= DB::get_column("SELECT DATE_FORMAT(timestamp, '%Y-%m') FROM " . DB::table('log') . ' ORDER BY timestamp DESC'); 
     585        array_unshift( $dates, 'Any'); 
     586        $dates= array_combine( $dates, $dates ); 
     587        $this->theme->dates= $dates; 
     588 
     589        // set up the limit select box 
     590        $limits= array( 5, 10, 20, 50, 100 ); 
     591        $limits= array_combine( $limits, $limits ); 
     592        $this->theme->limits= $limits; 
     593 
     594        // prepare the WSSE tokens 
     595        $this->theme->wsse= Utils::WSSE(); 
     596 
     597        $arguments= array( 
     598            'type' => $type, 
     599            'severity' => LogEntry::severity($severity), 
     600            'limit' => $limit, 
     601            'offset' => ( $index - 1) * $limit, 
     602        ); 
     603        if ( 'any' != strtolower($date) ) { 
     604            list($arguments['year'], $arguments['month'])= explode( '-', $date ); 
     605        } 
     606        if ( '' != $search ) { 
     607            $arguments['criteria']= $search; 
     608        } 
     609        $this->theme->logs= EventLog::get( $arguments ); 
     610 
     611        // get the page count 
     612        $arguments['count']= 'id'; 
     613        unset($arguments['limit']); 
     614        unset($arguments['offset']); 
     615        $totalpages= EventLog::get( $arguments ); 
     616        $pagecount= ceil( $totalpages / $limit ); 
     617 
     618        // put the page numbers into an array 
     619        $pages= array(); 
     620        for ( $z= 1; $z <= $pagecount; $z++ ) { 
     621            $pages[$z]= $z; 
     622        } 
     623        $this->theme->pagecount= $pagecount; 
     624        $this->theme->pages= $pages; 
     625 
     626        $this->display( 'logs' ); 
     627    } 
     628 
    544629    /** 
    545630     * Assembles the main menu for the admin area. 
  • trunk/htdocs/system/classes/eventlog.php

    r820 r906  
    5454        DB::query( 'DELETE FROM ' . DB::Table('log_types') . ' WHERE module = ? AND type = ?', array( self::get_module($module), $type ) ); 
    5555    } 
    56      
     56 
    5757    /** 
    5858     * Write an entry to the event log. 
     
    162162                    $params[]= $paramset['user_id']; 
    163163                } 
    164                 if ( isset( $paramset['severity'] ) ) { 
    165                     $where[]= "severity= ?"; 
    166                     $params[]= $paramset['severity']; 
     164                if ( isset( $paramset['severity'] ) && ( 'any' != LogEntry::severity_name($paramset['severity']) ) ) { 
     165                    $where[]= "severity_id= ?"; 
     166                    $params[]= LogEntry::severity($paramset['severity']); 
    167167                } 
    168168                if ( isset( $paramset['type_id'] ) ) { 
    169169                    $where[]= "type_id= ?"; 
    170170                    $params[]= $paramset['type_id']; 
     171                } 
     172 
     173                /* do searching */ 
     174                if ( isset( $paramset['criteria'] ) ) { 
     175                    preg_match_all( '/(?<=")(\\w[^"]*)(?=")|(\\w+)/', $paramset['criteria'], $matches ); 
     176                    foreach ( $matches[0] as $word ) { 
     177                        $where[] .= "(message LIKE CONCAT('%',?,'%'))"; 
     178                        $params[] = $word; 
     179                    } 
    171180                } 
    172181                 
  • trunk/htdocs/system/classes/logentry.php

    r830 r906  
    1717     */ 
    1818    private static $severities= array( 
     19        'any', 
    1920        'none', // should not be used 
    2021        'debug', 'info', 'notice', 'warning', 'err', 'crit', 'alert', 'emerg', 
     
    7071     
    7172    /** 
    72      * Returns an associative array of post types 
     73     * Returns an associative array of LogEntry types 
    7374     * 
    7475     * @param bool whether to force a refresh of the cached values 
     
    8586        } 
    8687        return self::$types; 
    87     }        
     88    } 
     89 
     90    /** 
     91     * Return an array of Severities 
     92     * @return array An array of severity ID => name pairs 
     93    **/ 
     94    public static function list_severities() 
     95    { 
     96        foreach ( self::$severities as $id => $name ) { 
     97            if ( 'none' == $name ) { 
     98                continue; 
     99            } 
     100            $results[$id]= $name; 
     101        } 
     102        return $results; 
     103    } 
     104 
     105    /** 
     106     * Returns an array of LogEntry modules 
     107     * @param bool Whether to refresh the cached values 
     108     * @return array An array of LogEntry module id => name pairs 
     109    **/ 
     110    public static function list_modules( $refresh= false ) 
     111    { 
     112        $types= self::list_logentry_types( $refresh ); 
     113        foreach ($types as $module => $types) { 
     114            $modules[]= $module; 
     115        } 
     116    } 
     117 
     118    /** 
     119     * Returns an array of LogEntry types 
     120     * @param bool Whether to refresh the cached values 
     121     * @return array An array of LogEntry id => name pairs 
     122    **/ 
     123    public static function list_types( $refresh= false ) 
     124    { 
     125        $types= array(); 
     126        $matrix= self::list_logentry_types( $refresh ); 
     127        foreach ($matrix as $module => $module_types) { 
     128            $types= array_merge($types, $module_types); 
     129        } 
     130        return array_flip($types); 
     131    } 
    88132     
    89133    /** 
     
    102146     
    103147    /** 
    104      * Get the string representation of teh severity numeric value. 
     148     * Get the string representation of the severity numeric value. 
    105149     * 
    106150     * @param integer $severity The severity index. 
     
    251295     
    252296    /** 
    253      * Overrides QueryRecord __get to implement custom object properties 
     297     * Overrides QueryRecord __set to implement custom object properties 
    254298     * 
    255299     * @param string Name of property to return 
  • trunk/htdocs/system/classes/utils.php

    r905 r906  
    690690            } 
    691691            // if the string is less than the length specified, bail out 
    692             if ( strlen($str) <= $len ) { 
     692            if ( iconv_strlen($str) <= $len ) { 
    693693                    return $str; 
    694694            } 
     
    699699                    $len = round(($len-3)/2); 
    700700                    // and place an ellipse in between the pieces 
    701                     return substr($str, 0, $len) . '...' . substr($str, -$len); 
     701                    return iconv_substr($str, 0, $len) . '...' . substr($str, -$len); 
    702702            } else { 
    703703                    // no, the ellipse goes at the end 
    704704                    $len= $len-3; 
    705                     return substr($str, 0, $len ) . '...'; 
     705                    return iconv_substr($str, 0, $len ) . '...'; 
    706706            } 
    707707    }