Created
December 17, 2014 12:12
-
-
Save Zalvie/b6dbb656da65b80135ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined('IN_MYBB') OR die('No'); | |
function filter_avatars_info() { | |
return array( | |
'name' => 'Filter Avatars', | |
'description' => '', | |
'author' => 'Cake', | |
'website' => 'http://keybase.io/to', | |
'version' => '1.0', | |
'compatibility' => '18*' | |
); | |
} | |
function filter_avatars_activate() { | |
global $db; | |
$setting_group = array('name' => 'filter_avatars', 'title' => 'Filter Avatars'); | |
$gid = $db->insert_query("settinggroups", $setting_group); | |
$setting = array('name' => 'filter_domains', | |
'gid' => $gid, | |
'title' => 'Domains to blacklist', | |
'description' => 'Enter domains to blacklist line by line', | |
'optionscode' => 'textarea' | |
'disporder' => 1); | |
$db->insert_query('settings', $setting); | |
rebuild_settings(); | |
} | |
function filter_avatars_deactivate() { | |
global $db; | |
$db->delete_query('settings', "name = 'filter_domains'"); | |
$db->delete_query('settinggroups', "name = 'filter_avatars'"); | |
rebuild_settings(); | |
} | |
function filter_avatars_check() { | |
global $mybb, $tmp_url, $settings; | |
$mybb->input['avatarurl'] = trim($mybb->get_input('avatarurl')); | |
if (empty($mybb->input['remove']) && !empty($mybb->input['avatarurl']) && !empty($settings['filter_domains'])) { | |
if(validate_email_format($mybb->input['avatarurl']) == false) { | |
$parsed = parse_url($mybb->input['avatarurl'], PHP_URL_HOST); | |
$test_regex = implode('|', array_map('preg_quote', array_map('trim', explode(PHP_EOL, $settings['filter_domains'])))); | |
if (preg_match('#^'. $test_regex.'$#i', $parsed)) { | |
$tmp_url = $mybb->input['avatarurl']; | |
unset($mybb->input['avatarurl']); | |
} | |
} | |
} | |
} | |
function filter_avatars_error() { | |
global $mybb, $avatar_error, $tmp_url; | |
if (!empty($tmp_url)) { | |
$avatar_error = inline_error('Specified avatar url is blacklisted.'); | |
} | |
} | |
$plugins->add_hook('usercp_do_avatar_start', 'filter_avatars_check'); | |
$plugins->add_hook('usercp_avatar_start', 'filter_avatars_error'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment