Skip to content

Instantly share code, notes, and snippets.

@Sama34
Created July 22, 2014 07:22
Show Gist options
  • Save Sama34/34ec1f3ea80efceefb94 to your computer and use it in GitHub Desktop.
Save Sama34/34ec1f3ea80efceefb94 to your computer and use it in GitHub Desktop.
OUGC Hide Users With Bad-words In Usernames From Member List
<?php
/***************************************************************************
*
* OUGC Hide Users With Bad-words In Usernames From Member List plugin (/inc/plugins/ougc_hibanamem.php.php)
* Author: Omar Gonzalez
* Copyright: © 2014 Omar Gonzalez
*
* Website: http://omarg.me
*
* Hide users which usernames contains bad words in usernames from the member list page.
*
***************************************************************************
****************************************************************************
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
// Die if IN_MYBB is not defined, for security reasons.
defined('IN_MYBB') or die('Direct initialization of this file is not allowed.');
// Add our hook
defined('IN_ADMINCP') or $plugins->add_hook('memberlist_intermediate', 'ougc_hibanamem');
// Plugin API
function ougc_hibanamem_info()
{
return array(
'name' => 'OUGC Hide Users With Bad-words In Usernames From Member List',
'description' => 'Hide users which usernames contains bad words in usernames from the member list page.',
'website' => 'http://omarg.me',
'author' => 'Omar G.',
'authorsite' => 'http://omarg.me',
'version' => '1.0',
'versioncode' => 1000,
'compatibility' => '17*',
'guid' => ''
);
}
// _activate() routine
function ougc_hibanamem_activate()
{
global $cache;
// Insert/update version into cache
$plugins = $cache->read('ougc_plugins');
if(!$plugins)
{
$plugins = array();
}
$info = ougc_hibanamem_info();
if(!isset($plugins['hibanamem']))
{
$plugins['hibanamem'] = $info['versioncode'];
}
/*~*~* RUN UPDATES START *~*~*/
/*~*~* RUN UPDATES END *~*~*/
$plugins['hibanamem'] = $info['versioncode'];
$cache->update('ougc_plugins', $plugins);
}
// _is_installed() routine
function ougc_hibanamem_is_installed()
{
global $cache;
$plugins = (array)$cache->read('ougc_plugins');
return !empty($plugins['hibanamem']);
}
// _uninstall() routine
function ougc_hibanamem_uninstall()
{
global $cache;
// Delete version from cache
$plugins = (array)$cache->read('ougc_plugins');
if(isset($plugins['hibanamem']))
{
unset($plugins['hibanamem']);
}
if(!empty($plugins))
{
$cache->update('ougc_plugins', $plugins);
}
else
{
global $db;
$db->delete_query('datacache', 'title=\'ougc_plugins\'');
!is_object($cache->handler) or $cache->handler->delete('ougc_plugins');
}
}
// Dark magic
function ougc_hibanamem()
{
global $cache, $search_query, $db;
$badwords_cache = (array)$cache->read('badwords');
if(!empty($badwords_cache))
{
foreach($badwords_cache as $badword)
{
$badword = my_strtolower($badword['badword']);
$search_query .= ' AND LOWER(u.username) NOT LIKE \'%'.$db->escape_string_like($badword).'%\'';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment