<?php


if ( ! class_exists( 'Util' ) ) {
    /**
     * Class Util
     * Some usages still exist but should be removed.
     * Source code located in brandonwamboldt/utilphp package
     *
     * @deprecated
     */
    class Util extends \utilphp\util
    {
        /**
         * Util::isBot()
         *
         * This function recognizes if source is a bot.
         * Function used for bypassing scripts set on site like age verification
         *
         * @author Martins Fridenbergs mtc <martins.fridenbergs@mtcmedia.co.uk>
         * @access public
         * @static
         * @return boolean is page viewed by a bot
         */
        public static function isBot()
        {
            $bots = [
                'yandexbot',
                'googlebot',
                'bingbot',
                'addthis',
                'yahoo',
                'slurp',
                'facebot',
                'facebookexternalhit',
                'twitterbot',
                'pinterest',
                'linkedinbot',
            ];
            $useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
            foreach ($bots as $bot) {
                if (strpos($useragent, $bot) !== false) {
                    return true;
                }
            }
            return false;
        }
    }
}
