plugins/SpecialUserFuncs.php
changeset 111 b348ace50bc7
parent 105 f7750e454168
child 115 261f367623af
equal deleted inserted replaced
110:68e030f8dfa6 111:b348ace50bc7
  1097   
  1097   
  1098   // sort order
  1098   // sort order
  1099   $sortkeys = array(
  1099   $sortkeys = array(
  1100       'uid' => 'u.user_id',
  1100       'uid' => 'u.user_id',
  1101       'username' => 'u.username',
  1101       'username' => 'u.username',
  1102       'email' => 'u.email'
  1102       'email' => 'u.email',
       
  1103       'regist' => 'u.reg_time'
  1103     );
  1104     );
  1104   
  1105   
  1105   $sortby = ( isset($_GET['sort']) && isset($sortkeys[$_GET['sort']]) ) ? $_GET['sort'] : 'username';
  1106   $sortby = ( isset($_GET['sort']) && isset($sortkeys[$_GET['sort']]) ) ? $_GET['sort'] : 'username';
  1106   $sort_sqllet = $sortkeys[$sortby];
  1107   $sort_sqllet = $sortkeys[$sortby];
  1107   
  1108   
  1131   // formatter parameters
  1132   // formatter parameters
  1132   $formatter = new MemberlistFormatter();
  1133   $formatter = new MemberlistFormatter();
  1133   $formatters = array(
  1134   $formatters = array(
  1134     'username' => array($formatter, 'username'),
  1135     'username' => array($formatter, 'username'),
  1135     'user_level' => array($formatter, 'user_level'),
  1136     'user_level' => array($formatter, 'user_level'),
  1136     'email' => array($formatter, 'email')
  1137     'email' => array($formatter, 'email'),
       
  1138     'reg_time' => array($formatter, 'reg_time')
  1137     );
  1139     );
  1138   
  1140   
  1139   // User search             
  1141   // User search             
  1140   if ( isset($_GET['finduser']) )
  1142   if ( isset($_GET['finduser']) )
  1141   {
  1143   {
  1162                  </th>
  1164                  </th>
  1163                  <th>
  1165                  <th>
  1164                    <a href="' . makeUrlNS('Special', 'Memberlist', $finduser_url . 'letter=' . $startletter . '&sort=username&orderby=' . $sortorders['username'], true) . '">Username</a>
  1166                    <a href="' . makeUrlNS('Special', 'Memberlist', $finduser_url . 'letter=' . $startletter . '&sort=username&orderby=' . $sortorders['username'], true) . '">Username</a>
  1165                  </th>
  1167                  </th>
  1166                  <th>
  1168                  <th>
       
  1169                    Title
       
  1170                  </th>
       
  1171                  <th>
  1167                    <a href="' . makeUrlNS('Special', 'Memberlist', $finduser_url . 'letter=' . $startletter . '&sort=email&orderby=' . $sortorders['email'], true) . '">E-mail</a>
  1172                    <a href="' . makeUrlNS('Special', 'Memberlist', $finduser_url . 'letter=' . $startletter . '&sort=email&orderby=' . $sortorders['email'], true) . '">E-mail</a>
       
  1173                  </th>
       
  1174                  <th>
       
  1175                    <a href="' . makeUrlNS('Special', 'Memberlist', $finduser_url . 'letter=' . $startletter . '&sort=regist&orderby=' . $sortorders['regist'], true) . '">Registered</a>
  1168                  </th>
  1176                  </th>
  1169                </tr>';
  1177                </tr>';
  1170                
  1178                
  1171   // determine number of rows
  1179   // determine number of rows
  1172   $q = $db->sql_query('SELECT u.user_id FROM '.table_prefix.'users AS u WHERE ' . $username_where . ' AND u.username != "Anonymous";');
  1180   $q = $db->sql_query('SELECT u.user_id FROM '.table_prefix.'users AS u WHERE ' . $username_where . ' AND u.username != "Anonymous";');
  1181     $s = ( $num_rows == 1 ) ? '' : 'es';
  1189     $s = ( $num_rows == 1 ) ? '' : 'es';
  1182     echo "<h3 style='float: left;'>Search returned $num_rows match$s</h3>";
  1190     echo "<h3 style='float: left;'>Search returned $num_rows match$s</h3>";
  1183   }
  1191   }
  1184   
  1192   
  1185   // main selector
  1193   // main selector
  1186   $q = $db->sql_unbuffered_query('SELECT u.user_id, u.username, u.reg_time, u.email, u.user_level, x.email_public FROM '.table_prefix.'users AS u
  1194   $q = $db->sql_unbuffered_query('SELECT u.user_id, u.username, u.reg_time, u.email, u.user_level, u.reg_time, x.email_public FROM '.table_prefix.'users AS u
  1187                                     LEFT JOIN '.table_prefix.'users_extra AS x
  1195                                     LEFT JOIN '.table_prefix.'users_extra AS x
  1188                                       ON ( u.user_id = x.user_id )
  1196                                       ON ( u.user_id = x.user_id )
  1189                                     WHERE ' . $username_where . ' AND u.username != "Anonymous"
  1197                                     WHERE ' . $username_where . ' AND u.username != "Anonymous"
  1190                                     ORDER BY ' . $sort_sqllet . ' ' . $target_order . ';');
  1198                                     ORDER BY ' . $sort_sqllet . ' ' . $target_order . ';');
  1191   if ( !$q )
  1199   if ( !$q )
  1193   
  1201   
  1194   $html = paginate(
  1202   $html = paginate(
  1195             $q,                                                                                                       // MySQL result resource
  1203             $q,                                                                                                       // MySQL result resource
  1196             '<tr>
  1204             '<tr>
  1197                <td class="{_css_class}">{user_id}</td>
  1205                <td class="{_css_class}">{user_id}</td>
  1198                <td class="{_css_class}" style="text-align: left;">{username}<br /><small>{user_level}</small></td>
  1206                <td class="{_css_class}" style="text-align: left;">{username}</td>
       
  1207                <td class="{_css_class}">{user_level}</td>
  1199                <td class="{_css_class}">{email}</small></td>
  1208                <td class="{_css_class}">{email}</small></td>
       
  1209                <td class="{_css_class}">{reg_time}</td>
  1200              </tr>
  1210              </tr>
  1201              ',                                                                                                       // TPL code for rows
  1211              ',                                                                                                       // TPL code for rows
  1202              $num_rows,                                                                                               // Number of results
  1212              $num_rows,                                                                                               // Number of results
  1203              makeUrlNS('Special', 'Memberlist', ( str_replace('%', '%%', $finduser_url) ) . 'letter=' . $startletter . '&offset=%s&sort=' . $sortby . '&orderby=' . $target_order ), // Result URL
  1213              makeUrlNS('Special', 'Memberlist', ( str_replace('%', '%%', $finduser_url) ) . 'letter=' . $startletter . '&offset=%s&sort=' . $sortby . '&orderby=' . $target_order ), // Result URL
  1204              $offset,                                                                                                 // Start at this number
  1214              $offset,                                                                                                 // Start at this number
  1281     else
  1291     else
  1282     {
  1292     {
  1283       return '<small>&lt;Non-public&gt;</small>';
  1293       return '<small>&lt;Non-public&gt;</small>';
  1284     }
  1294     }
  1285   }
  1295   }
       
  1296   /**
       
  1297    * Format a time as a reference to a day, with user-friendly "X days ago"/"Today"/"Yesterday" returned when relevant.
       
  1298    * @param int UNIX timestamp
       
  1299    * @return string
       
  1300    */
       
  1301   
       
  1302   function format_date($time)
       
  1303   {
       
  1304     // Our formattting string to pass to date()
       
  1305     // This should not include minute/second info, only today's date in whatever format suits your fancy
       
  1306     $formatstring = 'F j, Y';
       
  1307     // Today's date
       
  1308     $today = date($formatstring);
       
  1309     // Yesterday's date
       
  1310     $yesterday = date($formatstring, (time() - (24*60*60)));
       
  1311     // Date on the input
       
  1312     $then = date($formatstring, $time);
       
  1313     // "X days ago" logic
       
  1314     for ( $i = 2; $i <= 6; $i++ )
       
  1315     {
       
  1316       // hours_in_day * minutes_in_hour * seconds_in_minute * num_days
       
  1317       $offset = 24 * 60 * 60 * $i;
       
  1318       $days_ago = date($formatstring, (time() - $offset));
       
  1319       // so does the input timestamp match the date from $i days ago?
       
  1320       if ( $then == $days_ago )
       
  1321       {
       
  1322         // yes, return $i
       
  1323         return "$i days ago";
       
  1324       }
       
  1325     }
       
  1326     // either yesterday, today, or before 6 days ago
       
  1327     switch($then)
       
  1328     {
       
  1329       case $today:
       
  1330         return 'Today';
       
  1331       case $yesterday:
       
  1332         return 'Yesterday';
       
  1333       default:
       
  1334         return $then;
       
  1335     }
       
  1336     //     .--.
       
  1337     //    |o_o |
       
  1338     //    |!_/ |
       
  1339     //   //   \ \
       
  1340     //  (|     | )
       
  1341     // /'\_   _/`\
       
  1342     // \___)=(___/
       
  1343     return 'Linux rocks!';
       
  1344   }
       
  1345   function reg_time($time, $row)
       
  1346   {
       
  1347     return $this->format_date($time);
       
  1348   }
  1286 }
  1349 }
  1287 
  1350 
  1288 ?>
  1351 ?>