1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77:
<?php
namespace VSP\Core\Traits;
defined( 'ABSPATH' ) || exit;
trait URL {
public static function get_first_segment( $segments ) {
$var = is_array( $segments ) ? $segments : self::segment_uri( $segments );
return array_shift( $var );
}
public static function segment_uri( $uri = null ) {
$uri = ( ! is_null( $uri ) ) ? $uri : $_SERVER['REQUEST_URI'];
return explode( '/', trim( $uri, '/' ) );
}
public static function generate_safe_slug( $slug ) {
$slug = preg_replace( '/[^a-zA-Z0-9]/', '-', $slug );
$slug = strtolower( trim( $slug, '-' ) );
$slug = preg_replace( '/\-{2,}/', '-', $slug );
return $slug;
}
public static function auto_link( $url, $custom = null ) {
$replace = ( null === $custom ) ? '<a href="http$2://$4">$1$2$3$4</a>' : '<a href="http$2://$4">' . $custom . '</a>';
return preg_replace( '@(http)?(s)?(://)?(([-\w]+\.)+([^\s]+)+[^,.\s])@', $replace, $url );
}
public static function get_port() {
return self::global_vars( 'SERVER_PORT' );
}
}