<?php

if (!class_exists('AxcotoFontBirdUtil')) {

    class AxcotoFontBirdUtil {

        static public function redirect($title, $message, $page, $url) {
            include AxcotoFontBird::singleton()->pluginPath . '/templates/common/redirect.php';
        }

        static public function e(&$value, $default='') {
            echo self::g($value, $default);
        }

        static public function g(&$value, $default='') {
            if (isset($value)) {
                return $value;
            } else {
                return $default;
            }
        }

        static public function isValidUrl($url) {
            $parts = parse_url($url);

            if (!$parts) {
                return false; /* the URL was seriously wrong */
            }

            $options = array(
                CURLOPT_RETURNTRANSFER => true, // return web page
                CURLOPT_HEADER => true, // don't return headers
                CURLOPT_NOBODY => true, // don't return headers
                CURLOPT_FOLLOWLOCATION => true, // follow redirects
                CURLOPT_ENCODING => "", // handle all encodings
                CURLOPT_USERAGENT => "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)", // who am i
                CURLOPT_AUTOREFERER => true, // set referer on redirect
                CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
                CURLOPT_TIMEOUT => 120, // timeout on response
                CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
                CURLOPT_POST => 0, // i am sending post data
                CURLOPT_SSL_VERIFYHOST => 0, // don't verify ssl
                CURLOPT_SSL_VERIFYPEER => false, //
                CURLOPT_VERBOSE => 1
            );
            //Do refereal

            $ch = curl_init();
            curl_setopt_array($ch, $options);
            curl_setopt($ch, CURLOPT_URL, $url);
            $content = curl_exec($ch);
            curl_close($ch);
            if (preg_match('/HTTP\/1\.\d+\s+(\d+)/', $content, $matches)) {
                $code = intval($matches[1]);
            } else {
                return false;
            };
            return ($code != 404);
            //return (($code >= 200) && ($code < 400));
        }

    }

}