HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/NVonken/mijneigenlied.com/wwwroot/Core/Core Parts/general.part.php
<?php

class general
{
    /**
     *
     * @string[]
     */
    public static $months = array(
        "Januari",
        "Februari",
        "Maart",
        "April",
        "Mei",
        "Juni",
        "Juli",
        "Augustus",
        "September",
        "Oktober",
        "November",
        "December"
    );

    public static $ImgMimeTypes = array(
        "gif" => "image/gif"
    , "png" => "image/png"
    , "jpeg" => "image/jpeg"
    , "jpg" => "image/jpg"
    , "pjpeg" => "image/pjpeg"
    );

    public static $FileMimeTypes = array(
        "pdf" => "application/pdf"
    , "docx" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
    , "doc" => "application/msword"
    , "xls" => "application/vnd.ms-excel"
    , "ppt" => "application/vnd.ms-powerpoint"
    , "txt" => "text/plain"
    , "mpeg" => "video/mpeg"
    , "mpg" => "video/mpeg"
    , "mpe" => "video/mpeg"
    , "mov" => "video/quicktime"
    , "avi" => "video/x-msvideo"
    , "3gp" => "video/3gpp"
    , "jsc" => "application/javascript"
    , "js" => "application/javascript"
    );

    /**
     * Shorten a string to fit and append some text
     * @static
     * @param string $str
     * @param int $length
     * @param string $append
     * @return string
     */
    public static function ShortString($str, $length = 100, $append = "..")
    {
        if (strlen($str) > $length) {
            $str = substr($str, 0, $length - strlen($append)) . $append;
        }
        return $str;
    }

    /**
     * Transform a string to safe to use string for an url
     * @static
     * @param string $string string to convert
     * @return string the converted string
     */
    public static function UrlSafe($string)
    {
        $string = preg_replace("`\[.*\]`U", "", $string);
        $string = preg_replace('`&(amp;)?#?[a-z0-9]+;`i', '-', $string);
        $string = htmlentities($string, ENT_COMPAT);
        $string = preg_replace("`&([a-z])(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig|quot|rsquo);`i", "\\1", $string);
        $string = preg_replace(array("`[^a-z0-9]`i", "`[-]+`"), "-", $string);
        return strtolower(trim($string, '-'));
    }

    /**
     * Format a numeric value
     * @static
     * @param float $int the numeric value
     * @param int $decimals number of decimals
     * @return string formated value
     */
    public static function FormatNumber($int, $decimals = 2)
    {
        $int = !is_numeric($int) ? 0 : $int;
        return number_format($int, $decimals, NUMBER_DECIMAL_SEPERATOR, NUMBER_THOUSAND_SEPERATOR);
    }

    /**
     * Convert a dutch number to database ready numeric
     * @static
     * @param string $str
     * @return int
     */
    public static function ConvertNumber($str)
    {
        $foundDot = false;
        for ($i = strlen($str); $i >= 0; $i--) {
            if (!$foundDot && $str[$i] == ",") {
                $foundDot = true;
                $str[$i] = ".";
            } elseif ($str[$i] == "," | $str[$i] == ".")
                $str[$i] = "";
        }
        return $str;
    }

    /**
     * Creates a json object
     * @static
     * @param mixed $json
     * @return string json encoded string
     */
    public static function JsonEncode($json)
    {
        $json = json_encode($json);
        return mysql_real_escape_string($json);
    }

    /**
     * Normalize a timetamp to the beginning of the dat
     * @static
     * @param int $time
     * @return int
     */
    public static function NormalizeTime($time)
    {
        return strtotime(date("Y-m-d 00:00:00", $time));
    }

    /**
     * Parse a string trough the UBB parser
     * @static
     * @param string $str input ubb code
     * @return string parsed string
     */
    public static function Ubb($str)
    {
        require_once('Core/UBB/ubb.class.php');
        $ubb = new eamBBParser();
        $str = $ubb->getHTML($str);

        return $str;
    }

    /**
     * Get a field of an object out of an array
     * @static
     * @param $objects
     * @param $field
     * @return array
     */
    public static function GetField($objects, $field)
    {
        $array = array();
        if (is_array($objects) && count($objects) > 0) {
            foreach ($objects as $o)
                $array[] = $o->{$field};
        }
        return $array;
    }

    /**
     * validates an email address
     * @static
     * @param string $email
     * @return bool
     */
    public static function ValidEmail($email)
    {
        return preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email);
    }

    /**
     * Create a encoded string for anti spam detection of email adress
     * @static
     * @param string $email
     * @return string
     */
    public static function SafeEmail($email)
    {
        $chars = "@abcdefghijklmnopqrstuvwxyz";
        for ($i = 0; $i < strlen($chars); $i++) {
            if ($i != 0)
                $email = str_replace($chars[$i], "&#" . ($i + 96) . ";", $email);
            else
                $email = str_replace($chars[$i], "&#64;", $email);
        }

        return $email;
    }

    /**
     * Load an domain class
     * @static
     * @param string $name name of the domain
     */
    public static function Load($name)
    {
        require_once("Core/Domain/" . $name . ".php");
    }

    /**
     * Send an email
     * @static
     * @param string $subject
     * @param string $reciever email address
     * @param string $body
     */
    public static function Email($subject, $receiver, $body, $isHTML = true)
    {

        require_once("Libs/PHPMailer/class.phpmailer.php");

        $mail = new PHPMailer();

        $mail->Mailer = "mail";

        //$mail->Host = 'retail.smtp.com'; // Specify main and backup server
        //$mail->SMTPAuth = true; // Enable SMTP authentication
        //$mail->Username = 'user'; // SMTP username
        //$mail->Password = 'pass'; // SMTP password
        //$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted

        $mail->From = MAIL_SENDER_EMAIL;
        $mail->FromName = MAIL_SENDER_NAME;
        $mail->AddAddress($receiver);
        $mail->AddReplyTo(MAIL_SENDER_REPLY_TO, MAIL_SENDER_NAME);

        $mail->WordWrap = 50; // Set word wrap to 50 characters
        $mail->IsHTML($isHTML); // Set email format to HTML

        $mail->Subject = $subject;
        $mail->Body = $body;
        //$mail->AltBody = strip_tags($body);

        if (!$mail->Send()) {
            General::WriteToLog("Email", $mail->ErrorInfo);
            return false;
        }
        return true;
    }

    private $Lang;

    /**
     * This function is responsible for the language (array) in de the folder Core/Languages
     * The function produces columns of the language items in the available languages
     * @return string Returns the right Admin template
     */
    private function _action_siteitems()
    {
        #@var $lang array
        /**
         * @var $lang array
         */
        $languages = General::LoadLanguages();
        $headerItems = "";
        $langList = array();
        foreach ($languages as $langId) { // Check for existing language files
            if (file_exists("Core/Languages/" . $langId . "/" . strtolower($langId) . ".lang.php"))
                require("Core/Languages/" . $langId . "/" . strtolower($langId) . ".lang.php");
            $langList[$langId] = $lang; // Language header i.e. (NL || EN)
            $this->_tpl->assign("headerItemName", $langId); // Represents the column
            $headerItems .= $this->_tpl->parse("Admin/SiteItems/header-lang-item");
        }
        $this->_tpl->assign("headerItems", $headerItems);

        $langListItems = array();
        foreach ($langList[DEFAULT_LANGUAGE] as $langListItem => $data) { // Checks the language items for the default language
            if (!strstr($langListItem, "Admin") || $this->_user->SuperAdmin)
                $langListItems[] = $langListItem;
        }
        $this->_tpl->assign("displaySuperAdmin", $this->_user->SuperAdmin != 1 ? "display:none;" : ""); // Notice about appending new languages

        $tableBody = "";
        foreach ($langListItems as $langListItem) { // Produces language table body, all language items
            $bodyItems = "";
            foreach ($languages as $langId) {
                $this->_tpl->assign("langItemName", $langListItem);
                $this->_tpl->assign("lang", $langId);
                $this->_tpl->assign("bodyLangItem", $langList[$langId][$langListItem]);

                $bodyItems .= $this->_tpl->parse("Admin/SiteItems/body-lang-item");
            }
            $this->_tpl->assign("langItems", $bodyItems);
            $this->_tpl->assign("langItemName", $langListItem);

            $tableBody .= $this->_tpl->parse("Admin/SiteItems/overview-item");
        }
        $this->_tpl->assign("siteItemsList", $tableBody);
        return $this->_tpl->parse("Admin/SiteItems/overview");
    }

    public static function CreateScriptTag($file)
    {
        $tpl = new tpl();
        $tpl->assign("file", $file);
        return $tpl->parse("General/script-tag");
    }

    /**
     * Resize all types of pictures
     * @static
     * @param string $filename filepath to to picture
     * @param string $ext Extension of the current file
     * @param int $maxWidth Max width of the picture
     * @param int $maxHeight Max height of the picture
     */
    public static function ResizeImg($filename, $ext, $maxWidth = 0, $maxHeight = 0)
    {
        switch (strtolower($ext)) {
            case "pjeg":
                $ext = "jpeg";
                break;
            case "jpg"  :
                $ext = "jpeg";
                break;
            default:
                break;
        }
        $extension = strtolower($ext);
        $func = "imagecreatefrom{$extension}";
        $img = $func($filename);

        $width = imagesx($img);
        $height = imagesy($img);

        $factorHeight = 0;
        $factorWidth = 0;
        if ($width != 0) {
            if ($width > $maxWidth)
                $factorWidth = $width / $maxWidth;
            else
                $factorWidth = ($maxWidth / $width) - 1;
        }
        if ($height != 0) {
            if ($height > $maxHeight)
                $factorHeight = $height / $maxHeight;
            else
                $factorHeight = ($maxHeight / $height) - 1;
        }

        $factor = $factorHeight < $factorWidth ? $factorWidth : $factorHeight;

        $newWidth = floor($width / $factor);
        $newHeight = floor($height / $factor);

        $targetImg = imagecreatetruecolor($newWidth, $newHeight);

        $trans_colour = imagecolorallocatealpha($targetImg, 0, 0, 0, 127);
        imagefill($targetImg, 0, 0, $trans_colour);

        imagealphablending($targetImg, true);
        imagesavealpha($targetImg, true);

        imagecopyresampled($targetImg, $img, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);

        $imgFunc = "image{$extension}";
        $imgFunc($targetImg, $filename);
        imagedestroy($targetImg);
    }

    /**
     * @param $filename
     * @param $maxWidth
     */
    public static function ResizePhoto($filename, $maxWidth)
    {

        $type = getimagesize($filename);
        switch ($type[2]) {
            case 3: //"IMAGETYPE_PNG":
                $img = imagecreatefrompng($filename);
                break;
            case 1: //"IMAGETYPE_GIF":
                $img = imagecreatefromgif($filename);
                break;
            default:
                $img = imagecreatefromjpeg($filename);
                break;
        }

        $width = imagesx($img);
        $height = imagesy($img);

        if ($width > $maxWidth) {
            $factor = $width / $maxWidth;

            $newWidth = floor($width / $factor);
            $newHeight = floor($height / $factor);

            $targetImg = imagecreatetruecolor($newWidth, $newHeight);
            imagecopyresampled($targetImg, $img, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
            imagejpeg($targetImg, $filename);
            imagedestroy($targetImg);
        } else {
            //convert image to JPG :-)
            imagejpeg($img, $filename);
        }
        imagedestroy($img);
    }

    //naming inside function is legency from old CMS.
    public static function CreateThumbnail($srcImage, $desImage, $size)
    {
        $type = getimagesize($srcImage);
        switch ($type[2]) {
            case 3: //"IMAGETYPE_PNG":
                $TempPlaatje = imagecreatefrompng($srcImage);
                break;
            case 1: //"IMAGETYPE_GIF":
                $TempPlaatje = imagecreatefromgif($srcImage);
                break;
            default:
                $TempPlaatje = imagecreatefromjpeg($srcImage);
                break;
        }

        $Breedte = imagesx($TempPlaatje);
        $Hoogte = imagesy($TempPlaatje);

        $max = max($Breedte, $Hoogte);

        $knipLengte = $Breedte == $max ? $Hoogte : $Breedte;

        $BronPlaatje = imagecreatetruecolor($knipLengte, $knipLengte);

        imagecopyresampled($BronPlaatje, $TempPlaatje, 0, 0,
            floor(($Breedte - $knipLengte) / 2) /* hier de x margin voor het midden*/,
            floor(($Hoogte - $knipLengte) / 2) /* hier de y margin voor het midden*/,
            $knipLengte, $knipLengte, $knipLengte, $knipLengte);

        $Breedte = imagesx($BronPlaatje);
        $Hoogte = imagesy($BronPlaatje);

        $max = max($Breedte, $Hoogte);

        $AantalKeerTeGroot = $max / $size;
        $BreedteCorrectie = $Breedte > $size ? $Breedte % $size : 0;
        $HoogteCorrectie = $Hoogte > $size ? $Hoogte % $size : 0;
        $NieuweHoogte = round($Hoogte / $AantalKeerTeGroot);
        $NieuweBreedte = round($Breedte / $AantalKeerTeGroot);

        $ThumbPlaatje = imagecreatetruecolor($NieuweBreedte, $NieuweHoogte);
        imagecopyresampled($ThumbPlaatje, $BronPlaatje, 0, 0, 0, 0, ($NieuweBreedte), ($NieuweHoogte), $Breedte, $Hoogte);
        imagejpeg($ThumbPlaatje, $desImage);
        imagedestroy($ThumbPlaatje);
        imagedestroy($BronPlaatje);
        imagedestroy($TempPlaatje);

    }

    public static function RandomString($length)
    {
        $characters = "0123456789abcdefghijklmnopqrstuvwxyz";
        $string = "";
        for ($p = 0; $p < $length; $p++) {
            $string .= $characters[mt_rand(0, strlen($characters))];
        }
        return $string;
    }

    public static function Highlight($text, $words)
    {
        //for better word finding, make them lower
        $text = strtolower($text);
        $text = htmlspecialchars($text);
        //new text with highlighted elements
        $newText = "";
        //loop words
        foreach ($words as $word) {
            //make word small
            $word = strtolower($word);
            //word position
            $startWord = strpos($text, $word);
            //if found
            if ($startWord !== false) {
                //get start of the string
                $start = $startWord - 50;
                $start = $start < 0 ? 0 : $start;
                //end of the string to use for highlighting
                $end = $startWord + 50;
                $length = strlen($text);
                $end = $end > $length ? $length : $end;
                //get the string and put into new var
                $tempDisc = strtolower(substr($text, $start, $end));
                //UGLY: HTML Code, but performance wise, the best
                $tempDisc = '...' . str_replace(strtolower($word), "<strong>" . $word . "</strong>", $tempDisc) . '...<br/>';
                //remove highlighted piece from the string
                $text = substr($text, strlen($text) - $end);
                $newText .= $tempDisc;
            }
        }
        if ($newText == "")
            $newText = "...";
        //return highlighted text
        return $newText;
    }

    public static function ToJSLineEndings($text)
    {
        $text = str_replace("\r", "", $text);
        $text = str_replace("\n", "\\n", $text);
        return $text;
    }

    public static function MapArray($array, $id)
    {
        if (is_array($array) && count($array) > 0) {
            $mappedArray = array();
            foreach ($array as $item)
                $mappedArray[$item->$id] = $item;

            return $mappedArray;
        }
        return $array;
    }

    public static function WriteToLog($logName, $message)
    {
        $file = fopen("logs/" . $logName . ".log", "a");
        fwrite($file, date("d-m-Y H:i:s") . ">" . $message . "\r");
        fclose($file);
    }

    public static function hex2bin($h)
    {
        if (!is_string($h)) return null;
        $r = '';
        for ($a = 0; $a < strlen($h); $a += 2) {
            $r .= chr(hexdec($h{$a} . $h{($a + 1)}));
        }
        return $r;
    }

    public static function LoadGenderTypes()
    {
        return array(1 => "Heren",
            2 => "Dames",
            3 => "Kinderen",
            4 => "n.v.t.");
    }

    public static function LoadComponents()
    {
        $components = array();

        $dirComponents = opendir("Core/Components/");
        while (($component = readdir($dirComponents)) !== false) {
            if (!is_dir("Core/Components/" . $component) && strpos($component, "com") !== false) {
                include_once("Core/Components/" . $component);
                $comName = substr($component, 0, strpos($component, "."));
                if (class_exists($comName)) {
                    if (method_exists($comName, "Settings"))
                        $components[] = $comName::Settings();
                }
            }
        }
        closedir($dirComponents);
        return $components;
    }

    public static function LoadElements()
    {
        $elements = array();

        $dirElements = opendir("Core/Page Elements/");
        while (($element = readdir($dirElements)) !== false) {
            if (!is_dir("Core/Page Elements/" . $element) && strpos($element, "element") !== false) {
                include_once("Core/Page Elements/" . $element);
                $elementName = "Element_" . substr($element, 0, strpos($element, "."));
                if (class_exists($elementName)) {
                    if (method_exists($elementName, "Settings"))
                        $elements[] = $elementName::Settings();
                }
            }
        }
        closedir($dirElements);
        return $elements;
    }

    public static function LoadLanguages()
    {
        $languages = array();

        $dirLanguages = opendir("Core/Languages/");
        while (($lang = readdir($dirLanguages)) !== false) {
            if (is_dir("Core/Languages/" . $lang) && strpos($lang, ".") === false) {
                $languages[] = $lang;
            }
        }
        closedir($dirLanguages);
        return $languages;
    }

    public static function LoadLayouts()
    {
        $layouts = array();
        $dirLayouts = opendir("Core/Templates/Layout");
        while (($layout = readdir($dirLayouts)) !== false) {
            if (!is_dir("Core/Templates/Layout/" . $layout) && strpos($layout, ".tpl") !== false) {
                $layouts[] = str_replace(".tpl", "", $layout);
            }
        }
        closedir($dirLayouts);
        return $layouts;
    }

    public static function GetURLData($url)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $data = curl_exec($ch);
        curl_close($ch);
        return $data;
    }


}

?>