plugins/AdminAlerts.php
changeset 1 133e54e4f21d
parent 0 f166d28a778d
child 2 a63e0337a68e
equal deleted inserted replaced
0:f166d28a778d 1:133e54e4f21d
     1 <?php
     1 <?php
     2 /*
     2 /**!info**
     3 Plugin Name: Administrator's alerts
     3 {
     4 Plugin URI: http://enanocms.org/
     4   "Plugin Name"  : "Administrators' Alerts",
     5 Description: Provides a sidebar block with information on unapproved comments, inactive users, and pages with deletion votes
     5   "Plugin URI"   : "http://enanocms.org/plugin/admin-alerts",
     6 Author: Dan Fuhry
     6   "Description"  : "Provides a sidebar block with information on unapproved comments, inactive users, and pages with deletion votes",
     7 Version: 1.0.1
     7   "Author"       : "Dan Fuhry",
     8 Author URI: http://enanocms.org/
     8   "Version"      : "0.1",
     9 */
     9   "Author URI"   : "http://enanocms.org/"
       
    10 }
       
    11 **!*/
    10 
    12 
    11 /*
    13 /*
    12  * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
    14  * Administrators' Alerts plugin for Enano CMS
    13  * Version 1.0.1 (Loch Ness)
    15  * Version 0.1
    14  * Copyright (C) 2006-2007 Dan Fuhry
    16  * Copyright (C) 2006-2008 Dan Fuhry
    15  *
    17  *
    16  * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
    18  * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
    17  * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
    19  * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
    18  *
    20  *
    19  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
    21  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
    29   global $db, $session, $paths, $template, $plugins; // Common objects
    31   global $db, $session, $paths, $template, $plugins; // Common objects
    30   
    32   
    31   // restrict this block to administrators
    33   // restrict this block to administrators
    32   $content = '{restrict auth_admin}';
    34   $content = '{restrict auth_admin}';
    33   
    35   
    34   $content .= '<p style="margin: 0; padding: 0;"><b>Unapproved comments:</b><br />';
    36   if ( $session->user_level >= USER_LEVEL_ADMIN )
    35   
       
    36   // unapproved comments
       
    37   $q = $db->sql_query('SELECT comment_id, page_id, namespace, user_id, name, comment_data, subject, time FROM '.table_prefix.'comments WHERE approved=0 ORDER BY time ASC;');
       
    38   if ( !$q )
       
    39     $db->_die();
       
    40   
       
    41   if ( $db->numrows() < 1 )
       
    42   {
    37   {
    43     $content .= 'No unapproved comments.';
    38     
       
    39     $content .= '<p style="margin: 0; padding: 0;"><b>Unapproved comments:</b><br />';
       
    40     
       
    41     // unapproved comments
       
    42     $q = $db->sql_query('SELECT comment_id, page_id, namespace, user_id, name, comment_data, subject, time FROM '.table_prefix.'comments WHERE approved=0 ORDER BY time ASC;');
       
    43     if ( !$q )
       
    44       $db->_die();
       
    45     
       
    46     if ( $db->numrows() < 1 )
       
    47     {
       
    48       $content .= 'No unapproved comments.';
       
    49     }
       
    50     else
       
    51     {
       
    52       $content .= '<div class="tblholder" style="max-height: 100px; clip: rect(0px,auto,auto,0px); overflow: auto;">
       
    53                    <table border="0" cellspacing="1" cellpadding="2">';
       
    54       $class = 'row3';
       
    55       while ( $row = $db->fetchrow() )
       
    56       {
       
    57         $class = ( $class == 'row1' ) ? 'row3' : 'row1';
       
    58         $preview = substr($row['comment_data'], 0, 100);
       
    59         $preview = htmlspecialchars($preview);
       
    60         $subj = substr($row['subject'], 0, 20);
       
    61         if ( $subj != $row['subject'] )
       
    62           $subj .= '...';
       
    63         $subj = htmlspecialchars($subj);
       
    64         if ( $row['user_id'] == 1 )
       
    65         {
       
    66           $name_link = htmlspecialchars($row['name']) . ' [G]';
       
    67         }
       
    68         else
       
    69         {
       
    70           $memberlist_link = makeUrlNS('Special', 'Memberlist', 'finduser=' . urlencode($row['name']), true);
       
    71           $name = urlencode($row['name']);
       
    72           $name_link = "<a href=\"$memberlist_link\">$name</a>";
       
    73         }
       
    74         
       
    75         $page_url = makeUrlNS($row['namespace'], sanitize_page_id($row['page_id']));
       
    76         $title    = get_page_title_ns($row['page_id'], $row['namespace']);
       
    77         $page_link = "<a href=\"$page_url#do:comments\">$title</a>";
       
    78         $timestamp = date('n/j H:i', intval($row['time']));
       
    79         
       
    80         $content .= '<tr><td title="' . $preview . '" class="' . $class . '">';
       
    81         
       
    82         $content .= '<b>' . $subj . '</b> by ' . $name_link . '<br />';
       
    83         $content .= "$page_link, $timestamp";
       
    84         
       
    85         $content .= '</td></tr>';
       
    86       }
       
    87       $content .= '</table></div>';
       
    88     }
       
    89     $db->free_result();
       
    90     
       
    91     $content .= '</p>';
       
    92     
       
    93     // Inactive users
       
    94     
       
    95     $content .= '<p style="margin: 3px 0 0 0; padding: 0;"><b>Inactive user accounts:</b><br />';
       
    96     
       
    97     $q = $db->sql_query('SELECT username,reg_time FROM '.table_prefix.'users WHERE account_active=0 AND user_id > 1;');
       
    98     if ( !$q )
       
    99       $db->_die();
       
   100     
       
   101     if ( $db->numrows() < 1 )
       
   102     {
       
   103       $content .= 'No inactive users.';
       
   104     }
       
   105     else
       
   106     {
       
   107       $users = array();
       
   108       while ( $row = $db->fetchrow() )
       
   109       {
       
   110         $url  = makeUrlNS('Special', 'Administration', 'module=' . $paths->nslist['Admin'] . 'UserManager&src=get&username=' . urlencode($row['username']), true);
       
   111         $uname= htmlspecialchars($row['username']);
       
   112         $uname_js = addslashes($row['username']);
       
   113         $link = "<a href=\"$url\" onclick=\"ajaxAdminUser('$uname_js'); return false;\">$uname</a>";
       
   114         $users[] = $link;
       
   115       }
       
   116       $content .= implode(', ', $users);
       
   117     }
       
   118     $db->free_result();
       
   119     
       
   120     $content .= '</p>';
       
   121     
       
   122     // Pages with deletion requests
       
   123     
       
   124     $content .= '<p style="margin: 3px 0 0 0; padding: 0;"><b>Pages voted for deletion:</b><br />';
       
   125     
       
   126     $q = $db->sql_query('SELECT name, urlname, namespace, delvotes FROM '.table_prefix.'pages WHERE delvotes > 0 ORDER BY delvotes DESC;');
       
   127     if ( !$q )
       
   128       $db->_die();
       
   129     
       
   130     if ( $db->numrows() < 1 )
       
   131     {
       
   132       $content .= 'No pages nominated for deletion.';
       
   133     }
       
   134     else
       
   135     {
       
   136       $pages = array();
       
   137       while ( $row = $db->fetchrow() )
       
   138       {
       
   139         $url = makeUrlNS($row['namespace'], sanitize_page_id($row['urlname']), false, true);
       
   140         $name = htmlspecialchars($row['name']);
       
   141         $link = "<a href=\"$url\">$name</a> ({$row['delvotes']})";
       
   142         $pages[] = $link;
       
   143       }
       
   144       $content .= implode("<br />\n      ", $pages);
       
   145     }
       
   146     $db->free_result();
       
   147     
       
   148     $content .= '</p>';
    44   }
   149   }
    45   else
       
    46   {
       
    47     $content .= '<div class="tblholder" style="max-height: 100px; clip: rect(0px,auto,auto,0px); overflow: auto;">
       
    48                  <table border="0" cellspacing="1" cellpadding="2">';
       
    49     $class = 'row3';
       
    50     while ( $row = $db->fetchrow() )
       
    51     {
       
    52       $class = ( $class == 'row1' ) ? 'row3' : 'row1';
       
    53       $preview = substr($row['comment_data'], 0, 100);
       
    54       $preview = htmlspecialchars($preview);
       
    55       $subj = substr($row['subject'], 0, 20);
       
    56       if ( $subj != $row['subject'] )
       
    57         $subj .= '...';
       
    58       $subj = htmlspecialchars($subj);
       
    59       if ( $row['user_id'] == 1 )
       
    60       {
       
    61         $name_link = htmlspecialchars($row['name']) . ' [G]';
       
    62       }
       
    63       else
       
    64       {
       
    65         $memberlist_link = makeUrlNS('Special', 'Memberlist', 'finduser=' . urlencode($row['name']), true);
       
    66         $name = urlencode($row['name']);
       
    67         $name_link = "<a href=\"$memberlist_link\">$name</a>";
       
    68       }
       
    69       
       
    70       $page_url = makeUrlNS($row['namespace'], sanitize_page_id($row['page_id']));
       
    71       $title    = get_page_title_ns($row['page_id'], $row['namespace']);
       
    72       $page_link = "<a href=\"$page_url#do:comments\">$title</a>";
       
    73       $timestamp = date('n/j H:i', intval($row['time']));
       
    74       
       
    75       $content .= '<tr><td title="' . $preview . '" class="' . $class . '">';
       
    76       
       
    77       $content .= '<b>' . $subj . '</b> by ' . $name_link . '<br />';
       
    78       $content .= "$page_link, $timestamp";
       
    79       
       
    80       $content .= '</td></tr>';
       
    81     }
       
    82     $content .= '</table></div>';
       
    83   }
       
    84   $db->free_result();
       
    85   
       
    86   $content .= '</p>';
       
    87   
       
    88   // Inactive users
       
    89   
       
    90   $content .= '<p style="margin: 3px 0 0 0; padding: 0;"><b>Inactive user accounts:</b><br />';
       
    91   
       
    92   $q = $db->sql_query('SELECT username,reg_time FROM '.table_prefix.'users WHERE account_active=0 AND user_id > 1;');
       
    93   if ( !$q )
       
    94     $db->_die();
       
    95   
       
    96   if ( $db->numrows() < 1 )
       
    97   {
       
    98     $content .= 'No inactive users.';
       
    99   }
       
   100   else
       
   101   {
       
   102     $users = array();
       
   103     while ( $row = $db->fetchrow() )
       
   104     {
       
   105       $url  = makeUrlNS('Special', 'Administration', 'module=' . $paths->nslist['Admin'] . 'UserManager&src=get&username=' . urlencode($row['username']), true);
       
   106       $uname= htmlspecialchars($row['username']);
       
   107       $uname_js = addslashes($row['username']);
       
   108       $link = "<a href=\"$url\" onclick=\"ajaxAdminUser('$uname_js'); return false;\">$uname</a>";
       
   109       $users[] = $link;
       
   110     }
       
   111     $content .= implode(', ', $users);
       
   112   }
       
   113   $db->free_result();
       
   114   
       
   115   $content .= '</p>';
       
   116   
       
   117   // Pages with deletion requests
       
   118   
       
   119   $content .= '<p style="margin: 3px 0 0 0; padding: 0;"><b>Pages voted for deletion:</b><br />';
       
   120   
       
   121   $q = $db->sql_query('SELECT name, urlname, namespace, delvotes FROM '.table_prefix.'pages WHERE delvotes > 0 ORDER BY delvotes DESC;');
       
   122   if ( !$q )
       
   123     $db->_die();
       
   124   
       
   125   if ( $db->numrows() < 1 )
       
   126   {
       
   127     $content .= 'No pages nominated for deletion.';
       
   128   }
       
   129   else
       
   130   {
       
   131     $pages = array();
       
   132     while ( $row = $db->fetchrow() )
       
   133     {
       
   134       $url = makeUrlNS($row['namespace'], sanitize_page_id($row['urlname']), false, true);
       
   135       $name = htmlspecialchars($row['name']);
       
   136       $link = "<a href=\"$url\">$name</a> ({$row['delvotes']})";
       
   137       $pages[] = $link;
       
   138     }
       
   139     $content .= implode("<br />\n      ", $pages);
       
   140   }
       
   141   $db->free_result();
       
   142   
       
   143   $content .= '</p>';
       
   144   
   150   
   145   $template->sidebar_widget('Administrator alerts', '<div style="padding: 5px; font-size: smaller;">' . $content . '</div>');
   151   $template->sidebar_widget('Administrator alerts', '<div style="padding: 5px; font-size: smaller;">' . $content . '</div>');
   146 }
   152 }
   147 
   153 
   148 ?>
   154 ?>