/** * @param TabTable $tab * @param UserTable $user * @param int $ui * @return null|string */ public function getDisplayTab( $tab, $user, $ui ) { global $_CB_framework, $_CB_database; if ( ( ! Application::MyUser()->isGlobalModerator() ) || Application::User( (int) $user->get( 'id' ) )->isGlobalModerator() ) { return null; } if ( ! ( $tab->params instanceof ParamsInterface ) ) { $tab->params = new Registry( $tab->params ); } $blocksEnabled = ( $this->params->get( 'general_block', 1 ) && $tab->params->get( 'tab_block', $this->tabBlock ) ); $whitelistsEnabled = ( $this->params->get( 'general_whitelist', 1 ) && $tab->params->get( 'tab_whitelist', $this->tabWhitelist ) ); $attemptsEnabled = ( $this->params->get( 'general_attempts', 1 ) && $tab->params->get( 'tab_attempts', $this->tabAttempts ) ); $logsEnabled = ( $this->params->get( 'general_log', 1 ) && $tab->params->get( 'tab_logs', $this->tabLogs ) ); $return = null; if ( $blocksEnabled || $whitelistsEnabled || $attemptsEnabled || $logsEnabled ) { $tabPrefix = 'tab_' . (int) $tab->get( 'tabid' ) . '_'; $viewer = CBuser::getMyUserDataInstance(); outputCbJs( 1 ); outputCbTemplate( 1 ); cbimport( 'cb.pagination' ); cbantispamClass::getTemplate( 'tab' ); $ipAddress = cbantispamClass::getUserIP( $user ); $emailParts = explode( '@', $user->get( 'email' ) ); $emailDomain = null; if ( count( $emailParts ) > 1 ) { $emailDomain = array_pop( $emailParts ); } $blocks = null; if ( $blocksEnabled ) { cbantispamClass::getTemplate( 'blocks' ); $blocksPrefix = $tabPrefix . 'blocks_'; $limit = (int) $tab->params->get( 'tab_limit', 15 ); $limitstart = $_CB_framework->getUserStateFromRequest( $blocksPrefix . 'limitstart{com_comprofiler}', $blocksPrefix . 'limitstart' ); $query = 'SELECT COUNT(*)' . "\n FROM " . $_CB_database->NameQuote( '#__comprofiler_plugin_antispam_block' ) . "\n WHERE ( " . $_CB_database->NameQuote( 'type' ) . " = " . $_CB_database->Quote( 'user' ) . ' AND ' . $_CB_database->NameQuote( 'value' ) . ' = ' . (int) $user->get( 'id' ) . ' )' . ' OR ( ' . $_CB_database->NameQuote( 'type' ) . ' = ' . $_CB_database->Quote( 'email' ) . ' AND ' . $_CB_database->NameQuote( 'value' ) . ' = ' . $_CB_database->Quote( $user->get( 'email' ) ) . ' )'; if ( $ipAddress ) { $query .= ' OR ( ' . $_CB_database->NameQuote( 'type' ) . ' = ' . $_CB_database->Quote( 'ip' ) . ' AND ' . $_CB_database->NameQuote( 'value' ) . ' = ' . $_CB_database->Quote( $ipAddress ) . ' )'; } if ( $emailDomain ) { $query .= ' OR ( ' . $_CB_database->NameQuote( 'type' ) . ' = ' . $_CB_database->Quote( 'domain' ) . ' AND ' . $_CB_database->NameQuote( 'value' ) . ' = ' . $_CB_database->Quote( $emailDomain ) . ' )'; } $_CB_database->setQuery( $query ); $total = $_CB_database->loadResult(); if ( $total <= $limitstart ) { $limitstart = 0; } $pageNav = new cbPageNav( $total, $limitstart, $limit ); $pageNav->setInputNamePrefix( $blocksPrefix ); $query = 'SELECT *' . "\n FROM " . $_CB_database->NameQuote( '#__comprofiler_plugin_antispam_block' ) . "\n WHERE ( " . $_CB_database->NameQuote( 'type' ) . " = " . $_CB_database->Quote( 'user' ) . ' AND ' . $_CB_database->NameQuote( 'value' ) . ' = ' . (int) $user->get( 'id' ) . ' )' . ' OR ( ' . $_CB_database->NameQuote( 'type' ) . ' = ' . $_CB_database->Quote( 'email' ) . ' AND ' . $_CB_database->NameQuote( 'value' ) . ' = ' . $_CB_database->Quote( $user->get( 'email' ) ) . ' )'; if ( $ipAddress ) { $query .= ' OR ( ' . $_CB_database->NameQuote( 'type' ) . ' = ' . $_CB_database->Quote( 'ip' ) . ' AND ' . $_CB_database->NameQuote( 'value' ) . ' = ' . $_CB_database->Quote( $ipAddress ) . ' )'; } if ( $emailDomain ) { $query .= ' OR ( ' . $_CB_database->NameQuote( 'type' ) . ' = ' . $_CB_database->Quote( 'domain' ) . ' AND ' . $_CB_database->NameQuote( 'value' ) . ' = ' . $_CB_database->Quote( $emailDomain ) . ' )'; } $query .= "\n ORDER BY " . $_CB_database->NameQuote( 'id' ) . " ASC"; if ( $tab->params->get( 'tab_paging', 1 ) ) { $_CB_database->setQuery( $query, $pageNav->limitstart, $pageNav->limit ); } else { $_CB_database->setQuery( $query ); } $rows = $_CB_database->loadObjectList( null, 'cbantispamBlockTable', array( $_CB_database ) ); $blocks = HTML_cbantispamBlocks::showBlocks( $rows, $pageNav, $viewer, $user, $tab, $this ); } $whitelists = null; if ( $whitelistsEnabled ) { cbantispamClass::getTemplate( 'whitelists' ); $whitelistsPrefix = $tabPrefix . 'whitelists_'; $limit = (int) $tab->params->get( 'tab_limit', 15 ); $limitstart = $_CB_framework->getUserStateFromRequest( $whitelistsPrefix . 'limitstart{com_comprofiler}', $whitelistsPrefix . 'limitstart' ); $query = 'SELECT COUNT(*)' . "\n FROM " . $_CB_database->NameQuote( '#__comprofiler_plugin_antispam_whitelist' ) . "\n WHERE ( " . $_CB_database->NameQuote( 'type' ) . " = " . $_CB_database->Quote( 'user' ) . ' AND ' . $_CB_database->NameQuote( 'value' ) . ' = ' . (int) $user->get( 'id' ) . ' )' . ' OR ( ' . $_CB_database->NameQuote( 'type' ) . ' = ' . $_CB_database->Quote( 'email' ) . ' AND ' . $_CB_database->NameQuote( 'value' ) . ' = ' . $_CB_database->Quote( $user->get( 'email' ) ) . ' )'; if ( $ipAddress ) { $query .= ' OR ( ' . $_CB_database->NameQuote( 'type' ) . ' = ' . $_CB_database->Quote( 'ip' ) . ' AND ' . $_CB_database->NameQuote( 'value' ) . ' = ' . $_CB_database->Quote( $ipAddress ) . ' )'; } if ( $emailDomain ) { $query .= ' OR ( ' . $_CB_database->NameQuote( 'type' ) . ' = ' . $_CB_database->Quote( 'domain' ) . ' AND ' . $_CB_database->NameQuote( 'value' ) . ' = ' . $_CB_database->Quote( $emailDomain ) . ' )'; } $_CB_database->setQuery( $query ); $total = $_CB_database->loadResult(); if ( $total <= $limitstart ) { $limitstart = 0; } $pageNav = new cbPageNav( $total, $limitstart, $limit ); $pageNav->setInputNamePrefix( $whitelistsPrefix ); $query = 'SELECT *' . "\n FROM " . $_CB_database->NameQuote( '#__comprofiler_plugin_antispam_whitelist' ) . "\n WHERE ( " . $_CB_database->NameQuote( 'type' ) . " = " . $_CB_database->Quote( 'user' ) . ' AND ' . $_CB_database->NameQuote( 'value' ) . ' = ' . (int) $user->get( 'id' ) . ' )' . ' OR ( ' . $_CB_database->NameQuote( 'type' ) . ' = ' . $_CB_database->Quote( 'email' ) . ' AND ' . $_CB_database->NameQuote( 'value' ) . ' = ' . $_CB_database->Quote( $user->get( 'email' ) ) . ' )'; if ( $ipAddress ) { $query .= ' OR ( ' . $_CB_database->NameQuote( 'type' ) . ' = ' . $_CB_database->Quote( 'ip' ) . ' AND ' . $_CB_database->NameQuote( 'value' ) . ' = ' . $_CB_database->Quote( $ipAddress ) . ' )'; } if ( $emailDomain ) { $query .= ' OR ( ' . $_CB_database->NameQuote( 'type' ) . ' = ' . $_CB_database->Quote( 'domain' ) . ' AND ' . $_CB_database->NameQuote( 'value' ) . ' = ' . $_CB_database->Quote( $emailDomain ) . ' )'; } $query .= "\n ORDER BY " . $_CB_database->NameQuote( 'id' ) . " ASC"; if ( $tab->params->get( 'tab_paging', 1 ) ) { $_CB_database->setQuery( $query, $pageNav->limitstart, $pageNav->limit ); } else { $_CB_database->setQuery( $query ); } $rows = $_CB_database->loadObjectList( null, 'cbantispamWhitelistTable', array( $_CB_database ) ); $whitelists = HTML_cbantispamWhitelists::showWhitelists( $rows, $pageNav, $viewer, $user, $tab, $this ); } $attempts = null; if ( $attemptsEnabled ) { cbantispamClass::getTemplate( 'attempts' ); $attemptsPrefix = $tabPrefix . 'attempts_'; $limit = (int) $tab->params->get( 'tab_limit', 15 ); $limitstart = $_CB_framework->getUserStateFromRequest( $attemptsPrefix . 'limitstart{com_comprofiler}', $attemptsPrefix . 'limitstart' ); if ( $ipAddress ) { $query = 'SELECT COUNT(*)' . "\n FROM " . $_CB_database->NameQuote( '#__comprofiler_plugin_antispam_attempts' ) . "\n WHERE " . $_CB_database->NameQuote( 'ip_address' ) . " = " . $_CB_database->Quote( $ipAddress ); $_CB_database->setQuery( $query ); $total = $_CB_database->loadResult(); } else { $total = 0; } if ( $total <= $limitstart ) { $limitstart = 0; } $pageNav = new cbPageNav( $total, $limitstart, $limit ); $pageNav->setInputNamePrefix( $attemptsPrefix ); if ( $ipAddress ) { $query = 'SELECT *' . "\n FROM " . $_CB_database->NameQuote( '#__comprofiler_plugin_antispam_attempts' ) . "\n WHERE " . $_CB_database->NameQuote( 'ip_address' ) . " = " . $_CB_database->Quote( $ipAddress ) . "\n ORDER BY " . $_CB_database->NameQuote( 'date' ) . " DESC"; if ( $tab->params->get( 'tab_paging', 1 ) ) { $_CB_database->setQuery( $query, $pageNav->limitstart, $pageNav->limit ); } else { $_CB_database->setQuery( $query ); } $rows = $_CB_database->loadObjectList( null, 'cbantispamAttemptsTable', array( $_CB_database ) ); } else { $rows = array(); } $attempts = HTML_cbantispamAttempts::showAttempts( $rows, $pageNav, $viewer, $user, $tab, $this ); } $logs = null; if ( $logsEnabled ) { cbantispamClass::getTemplate( 'logs' ); $logsPrefix = $tabPrefix . 'logs_'; $limit = (int) $tab->params->get( 'tab_limit', 15 ); $limitstart = $_CB_framework->getUserStateFromRequest( $logsPrefix . 'limitstart{com_comprofiler}', $logsPrefix . 'limitstart' ); $query = 'SELECT COUNT(*)' . "\n FROM " . $_CB_database->NameQuote( '#__comprofiler_plugin_antispam_log' ) . "\n WHERE " . $_CB_database->NameQuote( 'user_id' ) . " = " . (int) $user->get( 'id' ); $_CB_database->setQuery( $query ); $total = $_CB_database->loadResult(); if ( $total <= $limitstart ) { $limitstart = 0; } $pageNav = new cbPageNav( $total, $limitstart, $limit ); $pageNav->setInputNamePrefix( $logsPrefix ); $query = 'SELECT *' . "\n FROM " . $_CB_database->NameQuote( '#__comprofiler_plugin_antispam_log' ) . "\n WHERE " . $_CB_database->NameQuote( 'user_id' ) . " = " . (int) $user->get( 'id' ) . "\n ORDER BY " . $_CB_database->NameQuote( 'date' ) . " DESC"; if ( $tab->params->get( 'tab_paging', 1 ) ) { $_CB_database->setQuery( $query, $pageNav->limitstart, $pageNav->limit ); } else { $_CB_database->setQuery( $query ); } $rows = $_CB_database->loadObjectList( null, 'cbantispamLogTable', array( $_CB_database ) ); $logs = HTML_cbantispamLogs::showLogs( $rows, $pageNav, $viewer, $user, $tab, $this ); } $class = $this->params->get( 'general_class', null ); $return = '<div id="cbAntiSpam" class="cbAntiSpam' . ( $class ? ' ' . htmlspecialchars( $class ) : null ) . '">' . '<div id="cbAntiSpamInner" class="cbAntiSpamInner">' . HTML_cbantispamTab::showTab( $blocks, $whitelists, $attempts, $logs, $viewer, $user, $tab, $this ) . '</div>' . '</div>'; } return $return; }
/** * Displays whitelist user page * * @param int $id * @param string $type * @param UserTable $user * @param null|string $message * @param null|string $messageType */ public function showWhitelist( $id, $type, $user, $message = null, $messageType = 'error' ) { global $_CB_framework; $profileUrl = $_CB_framework->userProfileUrl( (int) $user->get( 'id' ), false, $this->_tab ); if ( ! $user->get( 'id' ) ) { cbRedirect( $profileUrl, CBTxt::T( 'Not authorized.' ), 'error' ); } $ipAddress = cbantispamClass::getUserIP( $user ); $value = null; switch ( $type ) { case 'user': $value = (int) $user->get( 'id' ); break; case 'ip': $value = $ipAddress; break; case 'email': $value = $user->get( 'email' ); break; case 'domain': $emailParts = explode( '@', $user->get( 'email' ) ); if ( count( $emailParts ) > 1 ) { $value = array_pop( $emailParts ); } break; } $row = new cbantispamWhitelistTable(); if ( $id ) { $row->load( (int) $id ); } cbantispamClass::getTemplate( 'whitelist' ); $input = array(); $listType = array(); $listType[] = moscomprofilerHTML::makeOption( 'user', CBTxt::T( 'User' ) ); $listType[] = moscomprofilerHTML::makeOption( 'ip', CBTxt::T( 'IP Address' ) ); $listType[] = moscomprofilerHTML::makeOption( 'email', CBTxt::T( 'Email Address' ) ); $listType[] = moscomprofilerHTML::makeOption( 'domain', CBTxt::T( 'Email Domain' ) ); $type = $this->input( 'post/type', $row->get( 'type', $type ), GetterInterface::STRING ); $typeTooltip = cbTooltip( null, CBTxt::T( 'Select whitelist block type. Type determines what value should be supplied.' ), null, null, null, null, null, 'data-hascbtooltip="true"' ); $input['type'] = moscomprofilerHTML::selectList( $listType, 'type', 'class="form-control required"' . ( $typeTooltip ? ' ' . $typeTooltip : null ), 'value', 'text', $type, 1, true, false, false ); $valueTooltip = cbTooltip( null, CBTxt::T( 'Input whitelist value in relation to the type. User type use the users user_id (e.g. 42). IP Address type use a full valid IP Address (e.g. 192.168.0.1). Email type use a fill valid email address (e.g. invalid@cb.invalid). Email Domain type use a full email address domain after @ (e.g. example.com).' ), null, null, null, null, null, 'data-hascbtooltip="true"' ); $input['value'] = '<input type="text" id="value" name="value" value="' . htmlspecialchars( $this->input( 'post/value', $row->get( 'value', $value ), GetterInterface::STRING ) ) . '" class="form-control required" size="25"' . ( $valueTooltip ? ' ' . $valueTooltip : null ) . ' />'; $reasonTooltip = cbTooltip( null, CBTxt::T( 'Optionally input whitelist reason. Note this is for administrative purposes only.' ), null, null, null, null, null, 'data-hascbtooltip="true"' ); $input['reason'] = '<textarea id="reason" name="reason" class="form-control" cols="40" rows="5"' . ( $reasonTooltip ? ' ' . $reasonTooltip : null ) . '>' . htmlspecialchars( $this->input( 'post/reason', $row->get( 'reason' ), GetterInterface::STRING ) ) . '</textarea>'; if ( $message ) { $_CB_framework->enqueueMessage( $message, $messageType ); } HTML_cbantispamWhitelist::showWhitelist( $row, $input, $type, $this->_tab, $user, $this ); }