User Menu
Keywords
|
Plugins > UserListWhen installed, the UserList plugin allows all visitors to browse and search through the database of registered users. It's a fairly simple plugin to create and makes use of the widely used query class in /include/search/all.php. To create UserList we made very standard config.php and links.php files and then added the custom userlist.php file. The userlist.php file is annotated with some explanations and tips, but feel free to ask questions. config.php<?php $requiredVersion = '1.5.3'; links.php<?php $specialLinks['List']['script'] = 'userlist.php'; $specialLinks['List']['header'] = 'Users'; $specialLinks['List']['label'] = 'User List'; links.php<?php defined('WikyBlog') or die("Not an entry point..."); includeFile('search/all.php'); class plugin_userlist extends query{ function plugin_userlist(){ global $page,$pageOwner,$wbTables,$wbPluginSpace; $this->searchUrl = '/Special/'.$pageOwner['username'].'/'.$wbPluginSpace.'/List'; //Set the form so searching is submitted properly $page->formAction = $this->searchUrl; if( !empty($_GET['user']) ){ $page->formAction .= '?user='.$_GET['user']; } $page->formMethod = 'get'; //these are used in abbrevOutput() to format rows $this->classes = array(); $this->classes[] = ' class="tableRowOdd" '; $this->classes[] = ' class="tableRowEven" '; //this is where the sql work starts //note the use of $wbTables.. try uncommenting the following line to find out more about these tables //message(showArray($wbTables)); //showArray() can be used with objects too $this->rowLimit = 25; $this->query = 'SELECT SQL_CALC_FOUND_ROWS `user_id`, `username`, `visited` FROM '.$wbTables['users']; if( !empty($_GET['user']) ){ $this->query .= ' WHERE `username` LIKE "'.wbDB::escape($_GET['user']).'" '; } $this->query .= ' ORDER BY `user_id` '; $this->browse('User List'); } function mysqlFetch(&$result){ return mysql_fetch_assoc($result); } function displayPre(){ global $langA; //just good practice so we don't get warnings $_GET += array('user'=>''); //The search form echo '<div style="float:right;margin:1em;text-align:right;">'; echo '<b>'.$langA['username'].':</b> '; echo '<input type="text" name="user" value="'.$_GET['user'].'" size="20" />'; echo '<br/>'; echo '<input type="submit" name="cmd" value="'.$langA['search'].'" />'; echo '<br/>'; echo '<span class="sm">(% and _ are wildcharacters)</span>'; echo '</div>'; //start the display table echo '<table class="tableRows"><tr>'; echo '<th>ID</th>'; echo '<th>'.$langA['username'].'</th>'; echo '<th>Last Login</th>'; echo '</tr>'; } //this function is called for each row found function abbrevOutput(&$row,$i){ global $langA; echo '<tr'.$this->classes[$i%2].'>'; echo '<td>'; echo $row['user_id']; echo '</td>'; echo '<td>'; echo wbLinks::local('/'.$row['username'],toDisplay($row['username'])); echo '</td>'; echo '<td>'; echo dbFromDate($row['visited'],'1'); echo '</td>'; echo '</tr>'; } //called after all rows have been output function displayPost(&$prev,&$pages,&$next){ echo '</table>'; parent::displayPost($prev,$pages,$next); } } //and it all starts here, at the end of the file new plugin_userlist(); |