/** * Stores a log * * @param int $userId * @param string $type */ private function storeLog( $userId, $type = 'login' ) { global $_CB_framework, $_CB_database; if ( ! $this->params->get( 'general_log', 1 ) ) { return; } $ipAddresses = cbGetIParray(); $ipAddress = trim( array_shift( $ipAddresses ) ); if ( ! $ipAddress ) { return; } $query = 'SELECT *' . "\n FROM " . $_CB_database->NameQuote( '#__comprofiler_plugin_antispam_attempts' ) . "\n WHERE " . $_CB_database->NameQuote( 'ip_address' ) . " = " . $_CB_database->Quote( $ipAddress ); if ( $type ) { $query .= "\n AND " . $_CB_database->NameQuote( 'type' ) . ( is_array( $type ) ? " IN " . $_CB_database->safeArrayOfStrings( $type ) : " = " . $_CB_database->Quote( $type ) ); } $query .= "\n ORDER BY " . $_CB_database->NameQuote( 'date' ) . " DESC"; $_CB_database->setQuery( $query ); $attempts = $_CB_database->loadObjectList( null, 'cbantispamAttemptsTable', array( $_CB_database ) ); /** @var cbantispamAttemptsTable[] $attempts */ foreach ( $attempts as $attempt ) { $attempt->delete(); } $query = 'SELECT *' . "\n FROM " . $_CB_database->NameQuote( '#__comprofiler_plugin_antispam_log' ) . "\n WHERE " . $_CB_database->NameQuote( 'user_id' ) . " = " . (int) $userId . "\n AND " . $_CB_database->NameQuote( 'ip_address' ) . " = " . $_CB_database->Quote( $ipAddress ) . "\n ORDER BY " . $_CB_database->NameQuote( 'date' ) . " DESC"; $_CB_database->setQuery( $query, 0, 1 ); $row = new cbantispamLogTable(); $_CB_database->loadObject( $log ); if ( ! $row->get( 'id' ) ) { $row->set( 'user_id', (int) $userId ); $row->set( 'ip_address', $ipAddress ); $row->set( 'count', 1 ); } else { $row->set( 'count', ( (int) $row->get( 'count' ) + 1 ) ); } $row->set( 'date', $_CB_framework->getUTCDate() ); $row->store(); }
/** * Deletes a user log * * @param int $id * @param UserTable $user */ private function deleteLog( $id, $user ) { global $_CB_framework; $row = new cbantispamLogTable(); $row->load( (int) $id ); $profileUrl = $_CB_framework->userProfileUrl( (int) $user->get( 'id' ), false, $this->_tab ); if ( ! $row->get( 'id' ) ) { cbRedirect( $profileUrl, CBTxt::T( 'Not authorized.' ), 'error' ); } if ( ! $row->delete() ) { cbRedirect( $profileUrl, CBTxt::T( 'LOG_DELETE_FAILED', 'Log failed to delete! Error: [error]', array( '[error]' => $row->getError() ) ), 'error' ); } cbRedirect( $profileUrl, CBTxt::T( 'Log deleted successfully!' ) ); }