turn boolean True if it is a bad bot. */ private function isBadBot() { $botList = aioseo()->options->deprecated->tools->blocker->custom->enable ? explode( "\n", aioseo()->options->deprecated->tools->blocker->custom->bots ) : $this->botList; $botList = apply_filters( 'aioseo_bad_bot_list', $botList ); if ( ! empty( $botList ) ) { if ( ! isset( $_SERVER['HTTP_USER_AGENT'] ) ) { return false; } $ua = ! empty( $_SERVER['HTTP_USER_AGENT'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) : ''; $uas = $this->prepareList( $botList ); if ( preg_match( '/' . $uas . '/i', $ua ) ) { return true; } } return false; } /** * Is this a bad referer? * * @since 4.0.0 * * @return boolean True if this is a bad referer. */ private function isBadReferer() { $refererList = aioseo()->options->deprecated->tools->blocker->custom->enable ? explode( "\n", aioseo()->options->deprecated->tools->blocker->custom->referer ) : $this->refererList; $refererList = apply_filters( 'aioseo_bad_referer_list', $refererList ); if ( ! empty( $refererList ) && ! empty( $_SERVER ) && ! empty( $_SERVER['HTTP_REFERER'] ) ) { $referer = esc_url_raw( sanitize_text_field( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) ); $regex = $this->prepareList( $refererList ); if ( preg_match( '/' . $regex . '/i', $referer ) ) { return true; } } return false; } /** * Quote List for Regex * * @since 4.0.0 * * @param $list * @param string $quote * @return string */ private function prepareList( $list, $quote = '/' ) { $regex = ''; $cont = 0; foreach ( $list as $l ) { $trim_l = trim( $l ); if ( ! empty( $trim_l ) ) { if ( $cont ) { $regex .= '|'; } $cont = 1; $regex .= preg_quote( trim( $l ), $quote ); } } return $regex; } /** * Tracks the bad bot that was blocked. * * @since 4.0.0 * * @param string $message The message to log. * @return void */ public function track( $message ) { if ( $this->log ) { $this->log->info( $message ); } } }