strlen( $suffix ) && substr( $host, -strlen( $suffix ) ) === $suffix; } return $host === $pattern; } /** * Trifft ein Host irgendein Muster der Liste? * * @param string $host Host. * @param string[]|string $patterns Muster als Array oder Text mit einem Eintrag je Zeile. * @return bool */ public static function matches_any( $host, $patterns ) { if ( is_string( $patterns ) ) { $patterns = preg_split( '/[\r\n]+/', $patterns ); } foreach ( (array) $patterns as $pattern ) { if ( is_string( $pattern ) && self::matches( $host, $pattern ) ) { return true; } } return false; } /** * Ist der Host die eigene Maschine oder die eigene Website? * `www.` und Gross-/Kleinschreibung spielen keine Rolle. * * @param string $host Host. * @param string[] $own_hosts Hosts der eigenen Website (siteurl, home). * @return bool */ public static function is_own_host( $host, array $own_hosts ) { $host = self::strip_www( strtolower( (string) $host ) ); if ( '' === $host ) { return false; } if ( in_array( $host, self::LOOPBACK_HOSTS, true ) ) { return true; } foreach ( $own_hosts as $own ) { $own = self::strip_www( self::host_of( $own ) ); if ( '' !== $own && $own === $host ) { return true; } } return false; } /** * Zeigt die aktuelle Adresse auf einen anderen Host als die gespeicherte * Live-Adresse? Ohne Live-Adresse oder bei ungueltiger Eingabe: nein. * Verglichen wird nur der Host (ohne `www.`), nicht Schema oder Port. * * @param string $current_url Aktuelle Adresse der Website. * @param string $live_url Gespeicherte Live-Adresse. * @return bool */ public static function differs_from_live( $current_url, $live_url ) { $live = self::strip_www( self::host_of( $live_url ) ); $current = self::strip_www( self::host_of( $current_url ) ); if ( '' === $live || '' === $current ) { return false; } return $live !== $current; } /** * Ist der Host die gespeicherte Live-Adresse? * * @param string $host Host. * @param string $live_url Gespeicherte Live-Adresse. * @return bool */ public static function is_live_host( $host, $live_url ) { $live = self::strip_www( self::host_of( $live_url ) ); $host = self::strip_www( strtolower( (string) $host ) ); return '' !== $live && $live === $host; } /** * @param string $host Host. * @return string */ private static function strip_www( $host ) { return 0 === strpos( $host, 'www.' ) ? substr( $host, 4 ) : $host; } }