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