<?php

namespace auctionforge\inc\helpers;

class Tools
{
    public static function isYouTube($media)
    {
        $pattern = "/(?:https?:)?(?:\/\/)?(?:[0-9A-Z-]+\.)?(?:youtu\.be\/|youtube(?:-nocookie)?\.com\S*?[^\w\s-])([\w-]{11})(?=[^\w-]|$)(?![?=&+%\w.-]*(?:['\"][^<>]*>|<\/a>))[?=&+%\w.-]*/";
        $res = preg_match($pattern, $media);
        return (!empty($res));
    }

    public static function getYouTubeID($url)
    {
        preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $matches);
        if (!empty($matches) && isset($matches[1])) {
            return $matches[1];
        } else {
            return "";
        }
    }

    public static function getAssetImg($resource)
    {
        return plugins_url('auctionforge/assets/img/' . $resource);
    }
}
