diff --git a/Upload/inc/languages/english/admin/ougc_hal.lang.php b/Upload/inc/languages/english/admin/ougc_hal.lang.php index 813cb27..070fc67 100644 --- a/Upload/inc/languages/english/admin/ougc_hal.lang.php +++ b/Upload/inc/languages/english/admin/ougc_hal.lang.php @@ -2,40 +2,42 @@ /*************************************************************************** * - * OUGC Pages plugin (/inc/languages/english/admin/ougc_hal.lang.php) + * OUGC Hide Administrator Location plugin (/inc/languages/english/admin/ougc_hal.lang.php) * Author: Omar Gonzalez - * Copyright: © 2016 - 2020 Omar Gonzalez + * Copyright: © 2016 - 2023 Omar Gonzalez * * Website: https://ougc.network * - * Hide administrator's location at WOL list. + * Hide administrator's location from the Who Is Online (WOL) list. * *************************************************************************** - -**************************************************************************** - 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. + **************************************************************************** + 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. - You should have received a copy of the GNU General Public License - along with this program. If not, see . -****************************************************************************/ + 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. -// Plugin API -$l['setting_group_ougc_hal'] = 'OUGC Hide Administrator Location'; -$l['setting_group_ougc_hal_desc'] = 'Hide administrator\'s location at WOL list.'; + You should have received a copy of the GNU General Public License + along with this program. If not, see . + ****************************************************************************/ -// Settings -$l['setting_ougc_hal_uids'] = 'Hide Specific Users'; -$l['setting_ougc_hal_uids_descs'] = 'Insert the UID of the users that you want to hide from the WOL list.'; -$l['setting_ougc_hal_gids'] = 'Hide Specific Groups'; -$l['setting_ougc_hal_gids_desc'] = 'Select the groups that you want to hide from the WOL list.'; +$l = [ + // Plugin API + 'setting_group_ougc_hal' => 'OUGC Hide Administrator Location', + 'setting_group_ougc_hal_desc' => 'Hide administrator\'s location from the Who Is Online (WOL) list.', -// PluginLibrary -$l['ougc_hal_pluginlibrary'] = 'This plugin requires PluginLibrary version {2} or later to be uploaded to your forum. Please uplaod the required files.'; \ No newline at end of file + // Settings + 'setting_ougc_hal_uids' => 'Hide Specific Users', + 'setting_ougc_hal_uids_descs' => 'Insert the UID of the users that you want to hide from the Who Is Online (WOL) list.', + 'setting_ougc_hal_gids' => 'Hide Specific Groups', + 'setting_ougc_hal_gids_desc' => 'Select the groups that you want to hide from the Who Is Online (WOL) list.', + + // PluginLibrary + 'ougc_hal_pluginlibrary' => 'This plugin requires PluginLibrary version {2} or later to be uploaded to your forum. Please upload the required files.', +]; \ No newline at end of file diff --git a/Upload/inc/languages/espanol/admin/ougc_hal.lang.php b/Upload/inc/languages/espanol/admin/ougc_hal.lang.php index cba6ffd..425f817 100644 --- a/Upload/inc/languages/espanol/admin/ougc_hal.lang.php +++ b/Upload/inc/languages/espanol/admin/ougc_hal.lang.php @@ -2,40 +2,42 @@ /*************************************************************************** * - * OUGC Pages plugin (/inc/languages/spanol/admin/ougc_hal.lang.php) + * OUGC Hide Administrator Location plugin (/inc/languages/spanol/admin/ougc_hal.lang.php) * Author: Omar Gonzalez - * Copyright: © 2016 - 2020 Omar Gonzalez + * Copyright: © 2016 - 2023 Omar Gonzalez * * Website: https://ougc.network * - * Hide administrator's location at WOL list. + * Hide administrator's location from the Who Is Online (WOL) list. * *************************************************************************** - -**************************************************************************** - 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. + **************************************************************************** + 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. - You should have received a copy of the GNU General Public License - along with this program. If not, see . -****************************************************************************/ + 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. -// Plugin API -$l['setting_group_ougc_hal'] = 'OUGC Hide Administrator Location'; -$l['setting_group_ougc_hal_desc'] = 'Oculta la ubicacion de los administradores de la lista WOL.'; + You should have received a copy of the GNU General Public License + along with this program. If not, see . + ****************************************************************************/ -// Settings -$l['setting_ougc_hal_uids'] = 'Ocultar Usuarios Especificos'; -$l['setting_ougc_hal_uids_descs'] = 'Escribe el UID de los usuarios que quieres ocultar del listado WOL.'; -$l['setting_ougc_hal_gids'] = 'Ocultar Grupos Especificos'; -$l['setting_ougc_hal_gids_desc'] = 'Selecciona a los grupos que quieres ocultar del listado WOL.'; +$l = [ + // Plugin API + 'setting_group_ougc_hal' => 'OUGC Hide Administrator Location', + 'setting_group_ougc_hal_desc' => 'Oculta la ubicacion de los administradores de la lista de Quien Esta en Linea.', -// PluginLibrary -$l['ougc_hal_pluginlibrary'] = 'Este plugin requiere PluginLibrary version {2} para funcionar. Por favor sube los archivos necesarios.'; \ No newline at end of file + // Settings + 'setting_ougc_hal_uids' => 'Ocultar Usuarios Especificos', + 'setting_ougc_hal_uids_descs' => 'Escribe el UID de los usuarios que quieres ocultar del listado de Quien Esta en Linea.', + 'setting_ougc_hal_gids' => 'Ocultar Grupos Especificos', + 'setting_ougc_hal_gids_desc' => 'Selecciona a los grupos que quieres ocultar del listado de Quien Esta en Linea.', + + // PluginLibrary + 'ougc_hal_pluginlibrary' => 'Este plugin requiere PluginLibrary version {2} para funcionar. Por favor sube los archivos necesarios.', +]; \ No newline at end of file diff --git a/Upload/inc/plugins/ougcHideAdminLoc/admin.php b/Upload/inc/plugins/ougcHideAdminLoc/admin.php new file mode 100644 index 0000000..164820e --- /dev/null +++ b/Upload/inc/plugins/ougcHideAdminLoc/admin.php @@ -0,0 +1,127 @@ +. + ****************************************************************************/ + +namespace OUGCHideAdminLoc\Admin; + +function pluginInfo() : array { + global $lang; + + \OUGCHideAdminLoc\Core\loadLanguage(); + + return [ + 'name' => 'OUGC Hide Administrator Location', + 'description' => $lang->setting_group_ougc_hal_desc, + 'website' => 'https://ougc.network', + 'author' => 'Omar G.', + 'authorsite' => 'https://ougc.network', + 'version' => '1.8.33', + 'versioncode' => 1833, + 'compatibility' => '183*', + 'codename' => 'ougc_hal', + 'pl' => [ + 'version' => 13, + 'url' => 'http://community.mybb.com/mods.php?action=view&pid=573' + ] + ]; +} + +function pluginActivate() : true { + global $PL, $lang, $cache; + + \OUGCHideAdminLoc\Core\loadPluginLibrary(); + + // Add settings group + $PL->settings('ougc_hal', $lang->setting_group_ougc_hal, $lang->setting_group_ougc_hal_desc, [ + 'uids' => [ + 'title' => $lang->setting_ougc_hal_uids, + 'description' => $lang->setting_ougc_hal_uids_descs, + 'optionscode' => 'text', + 'value' => '', + ], + 'gids' => [ + 'title' => $lang->setting_ougc_hal_gids, + 'description' => $lang->setting_ougc_hal_gids_desc, + 'optionscode' => 'groupselect', + 'value' => 4, + ] + ]); + + // Insert/update version into cache + $plugins = (array) $cache->read('ougc_plugins'); + + if(!$plugins) { + $plugins = []; + } + + if(!isset($plugins['ougc_hal'])) { + $plugins['ougc_hal'] = pluginInfo()['versioncode']; + } + + /*~*~* RUN UPDATES START *~*~*/ + + /*~*~* RUN UPDATES END *~*~*/ + + $plugins['ougc_hal'] = pluginInfo()['versioncode']; + + $cache->update('ougc_plugins', $plugins); + + return true; +} + +function pluginIsInstalled() : bool { + global $cache; + + $plugins = $cache->read('ougc_plugins'); + + return isset($plugins['ougc_hal']); +} + +function pluginUninstall() : true { + global $db, $PL, $cache; + + \OUGCCoinbasePoints\Core\loadPluginLibrary(); + + $PL->settings_delete('ougc_hal'); + + // Delete version from cache + $plugins = (array) $cache->read('ougc_plugins'); + + if(isset($plugins['ougc_hal'])) { + unset($plugins['ougc_hal']); + } + + if(!empty($plugins)) { + $cache->update('ougc_plugins', $plugins); + } + else { + $PL->cache_delete('ougc_plugins'); + } + + return true; +} \ No newline at end of file diff --git a/Upload/inc/plugins/ougcHideAdminLoc/core.php b/Upload/inc/plugins/ougcHideAdminLoc/core.php new file mode 100644 index 0000000..45e0641 --- /dev/null +++ b/Upload/inc/plugins/ougcHideAdminLoc/core.php @@ -0,0 +1,109 @@ +. + ****************************************************************************/ + +namespace OUGCHideAdminLoc\Core; + +function loadLanguage() : true { + global $lang; + + if(!isset($lang->setting_group_ougc_hal)) { + $lang->load('ougc_hal'); + } + + return true; +} + +function pluginLibraryRequirements() : object { + return (object) \OUGCHideAdminLoc\Admin\pluginInfo()['pl']; +} + +function loadPluginLibrary(bool $doCheck = true) : bool { + global $PL, $lang; + + loadLanguage(); + + if($fileExists = file_exists(PLUGINLIBRARY)) { + ($PL instanceof PluginLibrary) or require_once PLUGINLIBRARY; + } + + if(!$doCheck) { + return false; + } + + if(!$fileExists || $PL->version < pluginLibraryRequirements()->version) { + flash_message( + $lang->sprintf( + $lang->ougc_hal_pluginlibrary, + pluginLibraryRequirements()->url, + pluginLibraryRequirements()->version + ), + 'error' + ); + + admin_redirect('index.php?module=config-plugins'); + } + + return true; +} + +function addHooks(string $namespace) : true { + global $plugins; + + $namespaceLowercase = strtolower($namespace); + $definedUserFunctions = get_defined_functions()['user']; + + foreach($definedUserFunctions as $callable) { + $namespaceWithPrefixLength = strlen($namespaceLowercase) + 1; + + if(substr($callable, 0, $namespaceWithPrefixLength) == $namespaceLowercase.'\\') { + $hookName = substr_replace($callable, '', 0, $namespaceWithPrefixLength); + + $priority = substr($callable, -2); + + if(is_numeric(substr($hookName, -2))) { + $hookName = substr($hookName, 0, -2); + } + else { + $priority = 10; + } + + $plugins->add_hook($hookName, $callable, $priority); + } + } + + return true; +} + +function getSetting( string $settingKey = '') : string { + global $mybb; + + $string = 'OUGC_HAL_'.strtoupper($settingKey); + + return defined($string) ? constant($string) : (string) $mybb->settings['ougc_hal_'.$settingKey]; +} \ No newline at end of file diff --git a/Upload/inc/plugins/ougcHideAdminLoc/forumHooks.php b/Upload/inc/plugins/ougcHideAdminLoc/forumHooks.php new file mode 100644 index 0000000..6ce4d1f --- /dev/null +++ b/Upload/inc/plugins/ougcHideAdminLoc/forumHooks.php @@ -0,0 +1,111 @@ +. + ****************************************************************************/ + +namespace OUGCHideAdminLoc\ForumHooks; + +function online_user() : bool { + global $user, $mybb; + + static $adminUsers = null; + + static $hiddenUsers = null; + + if($adminUsers === null) { + $adminUsers = [ + 'users' => array_map( + 'intval', + explode( + ',', + (string) $mybb->config['super_admins'] + ) + ), + 'groups' => [] + ]; + + foreach((array) $mybb->cache->cache['usergroups'] as $groupPermissions) { + if((bool) $groupPermissions['cancp']) { + $adminUsers['groups'][] = (int) $groupPermissions['gid']; + } + } + + foreach(OUGC_HAL_SETTING_UIDS as $userID) { + $adminUsers['users'][] = (int) $userID; + } + + foreach(OUGC_HAL_SETTING_GIDS as $groupID) { + $adminUsers['groups'][] = (int) $groupID; + } + + $hiddenUsers = [ + 'users' => array_merge( + $adminUsers['users'], + array_map( + 'intval', + explode( + ',', + \OUGCHideAdminLoc\Core\getSetting('uids') + ) + ) + ), + 'groups' => array_merge( + $adminUsers['groups'], + array_map( + 'intval', + explode( + ',', + \OUGCHideAdminLoc\Core\getSetting('gids') + ) + ) + ) + ]; + } + + if( + in_array($mybb->user['uid'], $adminUsers['users']) || + is_member($adminUsers['groups']) + ) { + return false; + } + + $userData = [ + 'usergroup' => $user['usergroup'], + 'additionalgroups' => '' // unsure why the core ignores this for the WOL + ]; + + if( + in_array($user['uid'], $hiddenUsers['users']) || + is_member($hiddenUsers['groups'], $userData) || + (int) \OUGCHideAdminLoc\Core\getSetting('gids') === -1 + ) { + $user['ip'] = ''; + $user['location'] = '/index.php?'; + } + + return true; +} \ No newline at end of file diff --git a/Upload/inc/plugins/ougc_hal.php b/Upload/inc/plugins/ougc_hal.php index 9a49ea5..d5dd1c6 100644 --- a/Upload/inc/plugins/ougc_hal.php +++ b/Upload/inc/plugins/ougc_hal.php @@ -4,216 +4,69 @@ * * OUGC Hide Administrator Location (/inc/plugins/ougc_hal.php) * Author: Omar Gonzalez - * Copyright: © 2016 - 2020 Omar Gonzalez + * Copyright: © 2016 - 2023 Omar Gonzalez * * Website: https://ougc.network * - * Hide administrator's location at WOL list. + * Hide administrator's location from the Who Is Online (WOL) list. * *************************************************************************** -**************************************************************************** - 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 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. + 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 . -****************************************************************************/ + You should have received a copy of the GNU General Public License + along with this program. If not, see . + ****************************************************************************/ // Die if IN_MYBB is not defined, for security reasons. defined('IN_MYBB') or die('Direct initialization of this file is not allowed.'); +// The following users and groups will be able to bypass this plugin and see the location of any user +const OUGC_HAL_SETTING_UIDS = []; // comma separated users (uid) to hide +const OUGC_HAL_SETTING_GIDS = []; // comma separated groups (gid) to hide + +const OUGC_HAL = MYBB_ROOT . 'inc/plugins/ougcHideAdminLoc'; + +require_once OUGC_HAL.'/core.php'; + // PLUGINLIBRARY defined('PLUGINLIBRARY') or define('PLUGINLIBRARY', MYBB_ROOT.'inc/plugins/pluginlibrary.php'); -// Tell MyBB when to run the hook -if(!defined('IN_ADMINCP')) -{ - $plugins->add_hook('online_user', 'online_user'); +// Add our hooks +if(defined('IN_ADMINCP')) { + require_once OUGC_HAL.'/admin.php'; } +else { + require_once OUGC_HAL.'/forumHooks.php'; -// Settings -define('OUGC_HAL_SETTING_UIDS', ''); // comma separated users (uid) to hide -define('OUGC_HAL_SETTING_GIDS', ''); // comma separated groups (gid) to hide -// Thread as a "additional administrators" settings, as they will be able to bypass the system and view any location -// To hide the location of specific users or groups without them being able treated as admins use the added settings instead + \OUGCHideAdminLoc\Core\addHooks('OUGCHideAdminLoc\ForumHooks'); +} // Plugin API -function ougc_hal_info() -{ - global $lang; - - isset($lang->setting_group_ougc_hal) || $lang->load('ougc_hal'); - - return array( - 'name' => 'OUGC Hide Administrator Location', - 'description' => $lang->setting_group_ougc_hal_desc, - 'website' => 'https://ougc.network', - 'author' => 'Omar G.', - 'authorsite' => 'https://ougc.network', - 'version' => '1.8.20', - 'versioncode' => 1820, - 'compatibility' => '18*', - 'codename' => 'ougc_hal', - 'pl' => array( - 'version' => 13, - 'url' => 'http://community.mybb.com/mods.php?action=view&pid=573' - ) - ); +function ougc_hal_info() : array { + return \OUGCHideAdminLoc\Admin\pluginInfo(); } // _activate() routine -function ougc_hal_activate() -{ - global $PL, $lang, $mybb; - ougc_hal_load_pluginlibrary(); - - // Add settings group - $PL->settings('ougc_hal', $lang->setting_group_ougc_hal, $lang->setting_group_ougc_hal_desc, array( - 'uids' => array( - 'title' => $lang->setting_ougc_hal_uids, - 'description' => $lang->setting_ougc_hal_uids_descs, - 'optionscode' => 'text', - 'value' => '', - ), - 'gids' => array( - 'title' => $lang->setting_ougc_hal_gids, - 'description' => $lang->setting_ougc_hal_gids_desc, - 'optionscode' => 'groupselect', - 'value' => 4, - ) - )); - - // Insert/update version into cache - $plugins = $mybb->cache->read('ougc_plugins'); - if(!$plugins) - { - $plugins = array(); - } - - $plugin = ougc_hal_info(); - - if(!isset($plugins['ougc_hal'])) - { - $plugins['ougc_hal'] = $plugin['versioncode']; - } - - /*~*~* RUN UPDATES START *~*~*/ - - /*~*~* RUN UPDATES END *~*~*/ - - $plugins['ougc_hal'] = $plugin['versioncode']; - $mybb->cache->update('ougc_plugins', $plugins); +function ougc_hal_activate() : true { + return \OUGCHideAdminLoc\Admin\pluginActivate(); } // _is_installed() routine -function ougc_hal_is_installed() -{ - global $cache; - - $plugins = $cache->read('ougc_plugins'); - - return isset($plugins['ougc_hal']); +function ougc_hal_is_installed() : bool { + return \OUGCHideAdminLoc\Admin\pluginIsInstalled(); } // _uninstall() routine -function ougc_hal_uninstall() -{ - global $PL, $cache; - ougc_hal_load_pluginlibrary(); - - $PL->settings_delete('ougc_hal'); - - // Delete version from cache - $plugins = (array)$cache->read('ougc_plugins'); - - if(isset($plugins['ougc_hal'])) - { - unset($plugins['ougc_hal']); - } - - if(!empty($plugins)) - { - $cache->update('ougc_plugins', $plugins); - } - else - { - $PL->cache_delete('ougc_plugins'); - } -} - -// PluginLibrary requirement check -function ougc_hal_load_pluginlibrary() -{ - global $lang, $PL; - - $plugin = ougc_hal_info(); - - !file_exists(PLUGINLIBRARY) || $PL or require_once PLUGINLIBRARY; - - isset($lang->setting_group_ougc_hal) || $lang->load('ougc_hal'); - - if(!file_exists(PLUGINLIBRARY) || empty($PL->version) || $PL->version < $plugin['pl']['version']) - { - flash_message($lang->printf($lang->ougc_hal_pluginlibrary, $plugin['pl']['url'], $plugin['pl']['version']), 'error'); - admin_redirect('index.php?module=config-plugins'); - } -} - -// Add our moderation option -function online_user() -{ - global $user, $mybb; - - static $admins = null; - - if($admins === null) - { - $admins = array(); - - global $mybb; - - $admins['users'] = explode(',', (string)$mybb->config['super_admins']); - - $admins['groups'] = array(); - - foreach($mybb->cache->cache['usergroups'] as $group) - { - if((bool)$group['cancp']) - { - $admins['groups'][(int)$group['gid']] = $group['gid']; - } - } - - $admins['users'] = array_filter(array_map('intval', array_merge($admins['users'], explode(',', OUGC_HAL_SETTING_UIDS)))); - $admins['groups'] = array_filter(array_map('intval', array_merge($admins['groups'], explode(',', OUGC_HAL_SETTING_GIDS)))); - } - - if(in_array($mybb->user['uid'], $admins['users']) || is_member($admins['groups'])) - { - return; - } - - $uids = array_filter(array_map('intval', array_merge($admins['users'], explode(',', $mybb->settings['ougc_hal_uids'])))); - - if( - in_array($user['uid'], $uids) || - in_array($user['uid'], $admins['users']) || - is_member($admins['groups'], $user) || - $mybb->settings['ougc_hal_gids'] == -1 - ) - { - $user['ip'] = ''; - //$user['nopermission'] = 1; - $user['location'] = '/index.php?'; - //$user['uid'] = 0; - //$user['invisible'] = 1; - } +function ougc_hal_uninstall() : true { + return \OUGCHideAdminLoc\Admin\pluginUninstall(); } \ No newline at end of file