<?php

use Illuminate\Support\Str;

/**
 * Safe redirect function that prevents redirects during CLI execution
 */
 
if (! function_exists('safeRedirect')) {
    function safeRedirect($url)
    {
        // Don't redirect during CLI commands (artisan, route:list, etc.)
        if (app()->runningInConsole() || php_sapi_name() === 'cli') {
            return null;
        }
        
        return redirect($url);
    }
}

/****
 * toAscii function
 */
if (! function_exists('toAscii')) {
    function toAscii($str, $replace = [], $delimiter = '-', $charset = 'ISO-8859-1')
    {

        $str = str_replace(
            [chr(145), chr(146), chr(147), chr(148), chr(150), chr(151), chr(133)],
            ["'", "'", '"', '"', '-', '--', '...'],
            $str); // by mordomiamil
        $str = iconv($charset, 'UTF-8', $str); // by lelebart
        if (! empty($replace)) {
            $str = str_replace((array) $replace, ' ', $str);
        }
        $clean = $str;
        try {
            $clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
        } catch (Exception $e) {

        }

        $str = preg_replace('/[^\x{0600}-\x{06FF}A-Za-z !@#$%^&*()]/u', '', $str);
        $clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
        $clean = strtolower(trim($clean, '-'));
        $clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);
        $clean = strtolower(trim($clean, '-'));

        return $clean;
    }
}

/**
 * Function to extract links, @mentions #hashtags e.t.c in a string
 */
if (! function_exists('extractIt')) {
    function extractIt($string)
    {		
        //require_once base_path('functions/extractor/Extractor.php');		
        
		//$extractor = Twitter_Extractor::create();

        //return $extractor->extract($string);
		
	    try {
			require_once base_path('functions/extractor/Extractor.php');
			$extractor = Twitter_Extractor::create();
			$result=$extractor->extract($string);
			//dd($result);
			return $result;
		} catch (\Exception $e) {
			// You can log the error or return a message
			//dd($e);
		}	
    }
}

/**
 * Perfect function to serialize and unserialize
 */
if (! function_exists('perfectSerialize')) {
    function perfectSerialize($string)
    {
        return base64_encode(serialize($string));
    }
}

if (! function_exists('perfectUnserialize')) {
    function perfectUnserialize($string)
    {

        if (base64_decode($string, true) == true) {

            return unserialize(base64_decode($string));
        } else {
            return @unserialize($string);
        }
    }
}

if (! function_exists('sanitizePostText')) {
    function sanitizePostText($string, $limit = false)
    {

        if (! is_string($string)) {
            return $string;
        }
        $string = lawedContent($string); // great one
        $string = trim($string);
        // $string = str_replace('<','&#60;',$string); //for editor
        // $string = str_replace('>','&#62;',$string); //for editor
        $string = str_replace("'", '&#39;', $string);
        $string = htmlspecialchars($string);        // for editor //uncommented
        $string = str_replace('\\r\\n', '<br>', $string);
        $string = str_replace('\\n\\n', '<br>', $string);
        // $string = stripslashes($string);
        $string = str_replace('&amp;#', '&#', $string);

        if ($limit) {
            $string = substr($string, 0, $limit);
        }

        return $string;
    }
}

if (! function_exists('sanitizeText')) {
    function sanitizeText($string, $limit = false)
    {

        if (! is_string($string)) {
            return $string;
        }
        $string = lawedContent($string); // great one
        $string = trim($string);
        $string = str_replace('<', '&#60;', $string);
        $string = str_replace('>', '&#62;', $string);
        $string = str_replace("'", '&#39;', $string);
        $string = htmlspecialchars($string);
        $string = str_replace('\\r\\n', '<br>', $string);
        $string = str_replace('\\n\\n', '<br>', $string);
        $string = stripslashes($string);
        $string = str_replace('&amp;#', '&#', $string);

        if ($limit) {
            $string = substr($string, 0, $limit);
        }

        return $string;
    }
}

function sanitizeUserInfo($info)
{
    // we also need to clean each info provided alsoe
    $newInfo = [];

    foreach ($info as $key => $value) {
        $newInfo[$key] = sanitizeText($value);
    }

    return $newInfo;
}

if (! function_exists('remoteFileExists')) {
    function remoteFileExists($remote)
    {
        $curl = curl_init($remote);
        curl_setopt($curl, CURLOPT_NOBODY, true);

        // do request
        $result = curl_exec($curl);

        $ret = false;

        // if request did not fail
        if ($result !== false) {
            // if request was ok, check response code
            $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);

            if ($statusCode == 200) {
                $ret = true;
            }
        }

        curl_close($curl);

        return $ret;
    }
}

/* DEPRECATED: timezoneList() function removed for performance optimization
 * Use config('site.general.timezone.data') instead for timezone data
 * This function was causing major performance issues with 400+ timezone entries
 * being generated on every page load. Now using static config array.
 */
/*
if (! function_exists('timezoneList')) {
    function timezoneList()
    {
        return [
            'UTC' => 'UTC',
            'Pacific/Midway' => 'Pacific/Midway',
            'Pacific/Niue' => 'Pacific/Niue',
            'Pacific/Pago_Pago' => 'Pacific/Pago_Pago',
            'Pacific/Honolulu' => 'Pacific/Honolulu',
            'Pacific/Rarotonga' => 'Pacific/Rarotonga',
            'Pacific/Tahiti' => 'Pacific/Tahiti',
            'Pacific/Marquesas' => 'Pacific/Marquesas',
            'America/Adak' => 'America/Adak',
            'Pacific/Gambier' => 'Pacific/Gambier',
            'America/Anchorage' => 'America/Anchorage',
            'America/Juneau' => 'America/Juneau',
            'America/Metlakatla' => 'America/Metlakatla',
            'America/Nome' => 'America/Nome',
            'America/Sitka' => 'America/Sitka',
            'America/Yakutat' => 'America/Yakutat',
            'Pacific/Pitcairn' => 'Pacific/Pitcairn',
            'America/Creston' => 'America/Creston',
            'America/Dawson' => 'America/Dawson',
            'America/Dawson_Creek' => 'America/Dawson_Creek',
            'America/Fort_Nelson' => 'America/Fort_Nelson',
            'America/Hermosillo' => 'America/Hermosillo',
            'America/Los_Angeles' => 'America/Los_Angeles',
            'America/Mazatlan' => 'America/Mazatlan',
            'America/Phoenix' => 'America/Phoenix',
            'America/Tijuana' => 'America/Tijuana',
            'America/Vancouver' => 'America/Vancouver',
            'America/Whitehorse' => 'America/Whitehorse',
            'America/Bahia_Banderas' => 'America/Bahia_Banderas',
            'America/Belize' => 'America/Belize',
            'America/Boise' => 'America/Boise',
            'America/Cambridge_Bay' => 'America/Cambridge_Bay',
            'America/Chihuahua' => 'America/Chihuahua',
            'America/Ciudad_Juarez' => 'America/Ciudad_Juarez',
            'America/Costa_Rica' => 'America/Costa_Rica',
            'America/Denver' => 'America/Denver',
            'America/Edmonton' => 'America/Edmonton',
            'America/El_Salvador' => 'America/El_Salvador',
            'America/Guatemala' => 'America/Guatemala',
            'America/Inuvik' => 'America/Inuvik',
            'America/Managua' => 'America/Managua',
            'America/Merida' => 'America/Merida',
            'America/Mexico_City' => 'America/Mexico_City',
            'America/Monterrey' => 'America/Monterrey',
            'America/Regina' => 'America/Regina',
            'America/Swift_Current' => 'America/Swift_Current',
            'America/Tegucigalpa' => 'America/Tegucigalpa',
            'Pacific/Galapagos' => 'Pacific/Galapagos',
            'America/Atikokan' => 'America/Atikokan',
            'America/Bogota' => 'America/Bogota',
            'America/Cancun' => 'America/Cancun',
            'America/Cayman' => 'America/Cayman',
            'America/Chicago' => 'America/Chicago',
            'America/Eirunepe' => 'America/Eirunepe',
            'America/Guayaquil' => 'America/Guayaquil',
            'America/Indiana/Knox' => 'America/Indiana/Knox',
            'America/Indiana/Tell_City' => 'America/Indiana/Tell_City',
            'America/Jamaica' => 'America/Jamaica',
            'America/Lima' => 'America/Lima',
            'America/Matamoros' => 'America/Matamoros',
            'America/Menominee' => 'America/Menominee',
            'America/North_Dakota/Beulah' => 'America/North_Dakota/Beulah',
            'America/North_Dakota/Center' => 'America/North_Dakota/Center',
            'America/North_Dakota/New_Salem' => 'America/North_Dakota/New_Salem',
            'America/Ojinaga' => 'America/Ojinaga',
            'America/Panama' => 'America/Panama',
            'America/Rankin_Inlet' => 'America/Rankin_Inlet',
            'America/Resolute' => 'America/Resolute',
            'America/Rio_Branco' => 'America/Rio_Branco',
            'America/Winnipeg' => 'America/Winnipeg',
            'Pacific/Easter' => 'Pacific/Easter',
            'America/Anguilla' => 'America/Anguilla',
            'America/Antigua' => 'America/Antigua',
            'America/Aruba' => 'America/Aruba',
            'America/Asuncion' => 'America/Asuncion',
            'America/Barbados' => 'America/Barbados',
            'America/Blanc-Sablon' => 'America/Blanc-Sablon',
            'America/Boa_Vista' => 'America/Boa_Vista',
            'America/Campo_Grande' => 'America/Campo_Grande',
            'America/Caracas' => 'America/Caracas',
            'America/Cuiaba' => 'America/Cuiaba',
            'America/Curacao' => 'America/Curacao',
            'America/Detroit' => 'America/Detroit',
            'America/Dominica' => 'America/Dominica',
            'America/Grand_Turk' => 'America/Grand_Turk',
            'America/Grenada' => 'America/Grenada',
            'America/Guadeloupe' => 'America/Guadeloupe',
            'America/Guyana' => 'America/Guyana',
            'America/Havana' => 'America/Havana',
            'America/Indiana/Indianapolis' => 'America/Indiana/Indianapolis',
            'America/Indiana/Marengo' => 'America/Indiana/Marengo',
            'America/Indiana/Petersburg' => 'America/Indiana/Petersburg',
            'America/Indiana/Vevay' => 'America/Indiana/Vevay',
            'America/Indiana/Vincennes' => 'America/Indiana/Vincennes',
            'America/Indiana/Winamac' => 'America/Indiana/Winamac',
            'America/Iqaluit' => 'America/Iqaluit',
            'America/Kentucky/Louisville' => 'America/Kentucky/Louisville',
            'America/Kentucky/Monticello' => 'America/Kentucky/Monticello',
            'America/Kralendijk' => 'America/Kralendijk',
            'America/La_Paz' => 'America/La_Paz',
            'America/Lower_Princes' => 'America/Lower_Princes',
            'America/Manaus' => 'America/Manaus',
            'America/Marigot' => 'America/Marigot',
            'America/Martinique' => 'America/Martinique',
            'America/Montserrat' => 'America/Montserrat',
            'America/Nassau' => 'America/Nassau',
            'America/New_York' => 'America/New_York',
            'America/Port-au-Prince' => 'America/Port-au-Prince',
            'America/Port_of_Spain' => 'America/Port_of_Spain',
            'America/Porto_Velho' => 'America/Porto_Velho',
            'America/Puerto_Rico' => 'America/Puerto_Rico',
            'America/Santo_Domingo' => 'America/Santo_Domingo',
            'America/St_Barthelemy' => 'America/St_Barthelemy',
            'America/St_Kitts' => 'America/St_Kitts',
            'America/St_Lucia' => 'America/St_Lucia',
            'America/St_Thomas' => 'America/St_Thomas',
            'America/St_Vincent' => 'America/St_Vincent',
            'America/Toronto' => 'America/Toronto',
            'America/Tortola' => 'America/Tortola',
            'America/Araguaina' => 'America/Araguaina',
            'America/Argentina/Buenos_Aires' => 'America/Argentina/Buenos_Aires',
            'America/Argentina/Catamarca' => 'America/Argentina/Catamarca',
            'America/Argentina/Cordoba' => 'America/Argentina/Cordoba',
            'America/Argentina/Jujuy' => 'America/Argentina/Jujuy',
            'America/Argentina/La_Rioja' => 'America/Argentina/La_Rioja',
            'America/Argentina/Mendoza' => 'America/Argentina/Mendoza',
            'America/Argentina/Rio_Gallegos' => 'America/Argentina/Rio_Gallegos',
            'America/Argentina/Salta' => 'America/Argentina/Salta',
            'America/Argentina/San_Juan' => 'America/Argentina/San_Juan',
            'America/Argentina/San_Luis' => 'America/Argentina/San_Luis',
            'America/Argentina/Tucuman' => 'America/Argentina/Tucuman',
            'America/Argentina/Ushuaia' => 'America/Argentina/Ushuaia',
            'America/Bahia' => 'America/Bahia',
            'America/Belem' => 'America/Belem',
            'America/Cayenne' => 'America/Cayenne',
            'America/Fortaleza' => 'America/Fortaleza',
            'America/Glace_Bay' => 'America/Glace_Bay',
            'America/Goose_Bay' => 'America/Goose_Bay',
            'America/Halifax' => 'America/Halifax',
            'America/Maceio' => 'America/Maceio',
            'America/Moncton' => 'America/Moncton',
            'America/Montevideo' => 'America/Montevideo',
            'America/Paramaribo' => 'America/Paramaribo',
            'America/Punta_Arenas' => 'America/Punta_Arenas',
            'America/Recife' => 'America/Recife',
            'America/Santarem' => 'America/Santarem',
            'America/Santiago' => 'America/Santiago',
            'America/Sao_Paulo' => 'America/Sao_Paulo',
            'America/Thule' => 'America/Thule',
            'Antarctica/Palmer' => 'Antarctica/Palmer',
            'Antarctica/Rothera' => 'Antarctica/Rothera',
            'Atlantic/Bermuda' => 'Atlantic/Bermuda',
            'Atlantic/Stanley' => 'Atlantic/Stanley',
            'America/St_Johns' => 'America/St_Johns',
            'America/Miquelon' => 'America/Miquelon',
            'America/Noronha' => 'America/Noronha',
            'Atlantic/South_Georgia' => 'Atlantic/South_Georgia',
            'America/Nuuk' => 'America/Nuuk',
            'Atlantic/Cape_Verde' => 'Atlantic/Cape_Verde',
            'Africa/Abidjan' => 'Africa/Abidjan',
            'Africa/Accra' => 'Africa/Accra',
            'Africa/Bamako' => 'Africa/Bamako',
            'Africa/Banjul' => 'Africa/Banjul',
            'Africa/Bissau' => 'Africa/Bissau',
            'Africa/Conakry' => 'Africa/Conakry',
            'Africa/Dakar' => 'Africa/Dakar',
            'Africa/Freetown' => 'Africa/Freetown',
            'Africa/Lome' => 'Africa/Lome',
            'Africa/Monrovia' => 'Africa/Monrovia',
            'Africa/Nouakchott' => 'Africa/Nouakchott',
            'Africa/Ouagadougou' => 'Africa/Ouagadougou',
            'Africa/Sao_Tome' => 'Africa/Sao_Tome',
            'America/Danmarkshavn' => 'America/Danmarkshavn',
            'America/Scoresbysund' => 'America/Scoresbysund',
            'Atlantic/Azores' => 'Atlantic/Azores',
            'Atlantic/Reykjavik' => 'Atlantic/Reykjavik',
            'Atlantic/St_Helena' => 'Atlantic/St_Helena',
            'Africa/Algiers' => 'Africa/Algiers',
            'Africa/Bangui' => 'Africa/Bangui',
            'Africa/Brazzaville' => 'Africa/Brazzaville',
            'Africa/Casablanca' => 'Africa/Casablanca',
            'Africa/Douala' => 'Africa/Douala',
            'Africa/El_Aaiun' => 'Africa/El_Aaiun',
            'Africa/Kinshasa' => 'Africa/Kinshasa',
            'Africa/Lagos' => 'Africa/Lagos',
            'Africa/Libreville' => 'Africa/Libreville',
            'Africa/Luanda' => 'Africa/Luanda',
            'Africa/Malabo' => 'Africa/Malabo',
            'Africa/Ndjamena' => 'Africa/Ndjamena',
            'Africa/Niamey' => 'Africa/Niamey',
            'Africa/Porto-Novo' => 'Africa/Porto-Novo',
            'Africa/Tunis' => 'Africa/Tunis',
            'Atlantic/Canary' => 'Atlantic/Canary',
            'Atlantic/Faroe' => 'Atlantic/Faroe',
            'Atlantic/Madeira' => 'Atlantic/Madeira',
            'Europe/Dublin' => 'Europe/Dublin',
            'Europe/Guernsey' => 'Europe/Guernsey',
            'Europe/Isle_of_Man' => 'Europe/Isle_of_Man',
            'Europe/Jersey' => 'Europe/Jersey',
            'Europe/Lisbon' => 'Europe/Lisbon',
            'Europe/London' => 'Europe/London',
            'Africa/Blantyre' => 'Africa/Blantyre',
            'Africa/Bujumbura' => 'Africa/Bujumbura',
            'Africa/Ceuta' => 'Africa/Ceuta',
            'Africa/Gaborone' => 'Africa/Gaborone',
            'Africa/Harare' => 'Africa/Harare',
            'Africa/Johannesburg' => 'Africa/Johannesburg',
            'Africa/Juba' => 'Africa/Juba',
            'Africa/Khartoum' => 'Africa/Khartoum',
            'Africa/Kigali' => 'Africa/Kigali',
            'Africa/Lubumbashi' => 'Africa/Lubumbashi',
            'Africa/Lusaka' => 'Africa/Lusaka',
            'Africa/Maputo' => 'Africa/Maputo',
            'Africa/Maseru' => 'Africa/Maseru',
            'Africa/Mbabane' => 'Africa/Mbabane',
            'Africa/Tripoli' => 'Africa/Tripoli',
            'Africa/Windhoek' => 'Africa/Windhoek',
            'Antarctica/Troll' => 'Antarctica/Troll',
            'Arctic/Longyearbyen' => 'Arctic/Longyearbyen',
            'Europe/Amsterdam' => 'Europe/Amsterdam',
            'Europe/Andorra' => 'Europe/Andorra',
            'Europe/Belgrade' => 'Europe/Belgrade',
            'Europe/Berlin' => 'Europe/Berlin',
            'Europe/Bratislava' => 'Europe/Bratislava',
            'Europe/Brussels' => 'Europe/Brussels',
            'Europe/Budapest' => 'Europe/Budapest',
            'Europe/Busingen' => 'Europe/Busingen',
            'Europe/Copenhagen' => 'Europe/Copenhagen',
            'Europe/Gibraltar' => 'Europe/Gibraltar',
            'Europe/Kaliningrad' => 'Europe/Kaliningrad',
            'Europe/Ljubljana' => 'Europe/Ljubljana',
            'Europe/Luxembourg' => 'Europe/Luxembourg',
            'Europe/Madrid' => 'Europe/Madrid',
            'Europe/Malta' => 'Europe/Malta',
            'Europe/Monaco' => 'Europe/Monaco',
            'Europe/Oslo' => 'Europe/Oslo',
            'Europe/Paris' => 'Europe/Paris',
            'Europe/Podgorica' => 'Europe/Podgorica',
            'Europe/Prague' => 'Europe/Prague',
            'Europe/Rome' => 'Europe/Rome',
            'Europe/San_Marino' => 'Europe/San_Marino',
            'Europe/Sarajevo' => 'Europe/Sarajevo',
            'Europe/Skopje' => 'Europe/Skopje',
            'Europe/Stockholm' => 'Europe/Stockholm',
            'Europe/Tirane' => 'Europe/Tirane',
            'Europe/Vaduz' => 'Europe/Vaduz',
            'Europe/Vatican' => 'Europe/Vatican',
            'Europe/Vienna' => 'Europe/Vienna',
            'Europe/Warsaw' => 'Europe/Warsaw',
            'Europe/Zagreb' => 'Europe/Zagreb',
            'Europe/Zurich' => 'Europe/Zurich',
            'Africa/Addis_Ababa' => 'Africa/Addis_Ababa',
            'Africa/Asmara' => 'Africa/Asmara',
            'Africa/Cairo' => 'Africa/Cairo',
            'Africa/Dar_es_Salaam' => 'Africa/Dar_es_Salaam',
            'Africa/Djibouti' => 'Africa/Djibouti',
            'Africa/Kampala' => 'Africa/Kampala',
            'Africa/Mogadishu' => 'Africa/Mogadishu',
            'Africa/Nairobi' => 'Africa/Nairobi',
            'Antarctica/Syowa' => 'Antarctica/Syowa',
            'Asia/Aden' => 'Asia/Aden',
            'Asia/Amman' => 'Asia/Amman',
            'Asia/Baghdad' => 'Asia/Baghdad',
            'Asia/Bahrain' => 'Asia/Bahrain',
            'Asia/Beirut' => 'Asia/Beirut',
            'Asia/Damascus' => 'Asia/Damascus',
            'Asia/Famagusta' => 'Asia/Famagusta',
            'Asia/Gaza' => 'Asia/Gaza',
            'Asia/Hebron' => 'Asia/Hebron',
            'Asia/Jerusalem' => 'Asia/Jerusalem',
            'Asia/Kuwait' => 'Asia/Kuwait',
            'Asia/Nicosia' => 'Asia/Nicosia',
            'Asia/Qatar' => 'Asia/Qatar',
            'Asia/Riyadh' => 'Asia/Riyadh',
            'Europe/Athens' => 'Europe/Athens',
            'Europe/Bucharest' => 'Europe/Bucharest',
            'Europe/Chisinau' => 'Europe/Chisinau',
            'Europe/Helsinki' => 'Europe/Helsinki',
            'Europe/Istanbul' => 'Europe/Istanbul',
            'Europe/Kirov' => 'Europe/Kirov',
            'Europe/Kyiv' => 'Europe/Kyiv',
            'Europe/Mariehamn' => 'Europe/Mariehamn',
            'Europe/Minsk' => 'Europe/Minsk',
            'Europe/Moscow' => 'Europe/Moscow',
            'Europe/Riga' => 'Europe/Riga',
            'Europe/Simferopol' => 'Europe/Simferopol',
            'Europe/Sofia' => 'Europe/Sofia',
            'Europe/Tallinn' => 'Europe/Tallinn',
            'Europe/Vilnius' => 'Europe/Vilnius',
            'Europe/Volgograd' => 'Europe/Volgograd',
            'Indian/Antananarivo' => 'Indian/Antananarivo',
            'Indian/Comoro' => 'Indian/Comoro',
            'Indian/Mayotte' => 'Indian/Mayotte',
            'Asia/Tehran' => 'Asia/Tehran',
            'Asia/Baku' => 'Asia/Baku',
            'Asia/Dubai' => 'Asia/Dubai',
            'Asia/Muscat' => 'Asia/Muscat',
            'Asia/Tbilisi' => 'Asia/Tbilisi',
            'Asia/Yerevan' => 'Asia/Yerevan',
            'Europe/Astrakhan' => 'Europe/Astrakhan',
            'Europe/Samara' => 'Europe/Samara',
            'Europe/Saratov' => 'Europe/Saratov',
            'Europe/Ulyanovsk' => 'Europe/Ulyanovsk',
            'Indian/Mahe' => 'Indian/Mahe',
            'Indian/Mauritius' => 'Indian/Mauritius',
            'Indian/Reunion' => 'Indian/Reunion',
            'Asia/Kabul' => 'Asia/Kabul',
            'Antarctica/Mawson' => 'Antarctica/Mawson',
            'Asia/Aqtau' => 'Asia/Aqtau',
            'Asia/Aqtobe' => 'Asia/Aqtobe',
            'Asia/Ashgabat' => 'Asia/Ashgabat',
            'Asia/Atyrau' => 'Asia/Atyrau',
            'Asia/Dushanbe' => 'Asia/Dushanbe',
            'Asia/Karachi' => 'Asia/Karachi',
            'Asia/Oral' => 'Asia/Oral',
            'Asia/Qyzylorda' => 'Asia/Qyzylorda',
            'Asia/Samarkand' => 'Asia/Samarkand',
            'Asia/Tashkent' => 'Asia/Tashkent',
            'Asia/Yekaterinburg' => 'Asia/Yekaterinburg',
            'Indian/Kerguelen' => 'Indian/Kerguelen',
            'Indian/Maldives' => 'Indian/Maldives',
            'Asia/Colombo' => 'Asia/Colombo',
            'Asia/Kolkata' => 'Asia/Kolkata',
            'Asia/Kathmandu' => 'Asia/Kathmandu',
            'Antarctica/Vostok' => 'Antarctica/Vostok',
            'Asia/Almaty' => 'Asia/Almaty',
            'Asia/Bishkek' => 'Asia/Bishkek',
            'Asia/Dhaka' => 'Asia/Dhaka',
            'Asia/Omsk' => 'Asia/Omsk',
            'Asia/Qostanay' => 'Asia/Qostanay',
            'Asia/Thimphu' => 'Asia/Thimphu',
            'Asia/Urumqi' => 'Asia/Urumqi',
            'Indian/Chagos' => 'Indian/Chagos',
            'Asia/Yangon' => 'Asia/Yangon',
            'Indian/Cocos' => 'Indian/Cocos',
            'Antarctica/Davis' => 'Antarctica/Davis',
            'Asia/Bangkok' => 'Asia/Bangkok',
            'Asia/Barnaul' => 'Asia/Barnaul',
            'Asia/Ho_Chi_Minh' => 'Asia/Ho_Chi_Minh',
            'Asia/Hovd' => 'Asia/Hovd',
            'Asia/Jakarta' => 'Asia/Jakarta',
            'Asia/Krasnoyarsk' => 'Asia/Krasnoyarsk',
            'Asia/Novokuznetsk' => 'Asia/Novokuznetsk',
            'Asia/Novosibirsk' => 'Asia/Novosibirsk',
            'Asia/Phnom_Penh' => 'Asia/Phnom_Penh',
            'Asia/Pontianak' => 'Asia/Pontianak',
            'Asia/Tomsk' => 'Asia/Tomsk',
            'Asia/Vientiane' => 'Asia/Vientiane',
            'Indian/Christmas' => 'Indian/Christmas',
            'Asia/Brunei' => 'Asia/Brunei',
            'Asia/Choibalsan' => 'Asia/Choibalsan',
            'Asia/Hong_Kong' => 'Asia/Hong_Kong',
            'Asia/Irkutsk' => 'Asia/Irkutsk',
            'Asia/Kuala_Lumpur' => 'Asia/Kuala_Lumpur',
            'Asia/Kuching' => 'Asia/Kuching',
            'Asia/Macau' => 'Asia/Macau',
            'Asia/Makassar' => 'Asia/Makassar',
            'Asia/Manila' => 'Asia/Manila',
            'Asia/Shanghai' => 'Asia/Shanghai',
            'Asia/Singapore' => 'Asia/Singapore',
            'Asia/Taipei' => 'Asia/Taipei',
            'Asia/Ulaanbaatar' => 'Asia/Ulaanbaatar',
            'Australia/Perth' => 'Australia/Perth',
            'Australia/Eucla' => 'Australia/Eucla',
            'Asia/Chita' => 'Asia/Chita',
            'Asia/Dili' => 'Asia/Dili',
            'Asia/Jayapura' => 'Asia/Jayapura',
            'Asia/Khandyga' => 'Asia/Khandyga',
            'Asia/Pyongyang' => 'Asia/Pyongyang',
            'Asia/Seoul' => 'Asia/Seoul',
            'Asia/Tokyo' => 'Asia/Tokyo',
            'Asia/Yakutsk' => 'Asia/Yakutsk',
            'Pacific/Palau' => 'Pacific/Palau',
            'Australia/Adelaide' => 'Australia/Adelaide',
            'Australia/Broken_Hill' => 'Australia/Broken_Hill',
            'Australia/Darwin' => 'Australia/Darwin',
            'Antarctica/DumontDUrville' => 'Antarctica/DumontDUrville',
            'Antarctica/Macquarie' => 'Antarctica/Macquarie',
            'Asia/Ust-Nera' => 'Asia/Ust-Nera',
            'Asia/Vladivostok' => 'Asia/Vladivostok',
            'Australia/Brisbane' => 'Australia/Brisbane',
            'Australia/Hobart' => 'Australia/Hobart',
            'Australia/Lindeman' => 'Australia/Lindeman',
            'Australia/Melbourne' => 'Australia/Melbourne',
            'Australia/Sydney' => 'Australia/Sydney',
            'Pacific/Chuuk' => 'Pacific/Chuuk',
            'Pacific/Guam' => 'Pacific/Guam',
            'Pacific/Port_Moresby' => 'Pacific/Port_Moresby',
            'Pacific/Saipan' => 'Pacific/Saipan',
            'Australia/Lord_Howe' => 'Australia/Lord_Howe',
            'Antarctica/Casey' => 'Antarctica/Casey',
            'Asia/Magadan' => 'Asia/Magadan',
            'Asia/Sakhalin' => 'Asia/Sakhalin',
            'Asia/Srednekolymsk' => 'Asia/Srednekolymsk',
            'Pacific/Bougainville' => 'Pacific/Bougainville',
            'Pacific/Efate' => 'Pacific/Efate',
            'Pacific/Guadalcanal' => 'Pacific/Guadalcanal',
            'Pacific/Kosrae' => 'Pacific/Kosrae',
            'Pacific/Norfolk' => 'Pacific/Norfolk',
            'Pacific/Noumea' => 'Pacific/Noumea',
            'Pacific/Pohnpei' => 'Pacific/Pohnpei',
            'Asia/Anadyr' => 'Asia/Anadyr',
            'Asia/Kamchatka' => 'Asia/Kamchatka',
            'Pacific/Fiji' => 'Pacific/Fiji',
            'Pacific/Funafuti' => 'Pacific/Funafuti',
            'Pacific/Kwajalein' => 'Pacific/Kwajalein',
            'Pacific/Majuro' => 'Pacific/Majuro',
            'Pacific/Nauru' => 'Pacific/Nauru',
            'Pacific/Tarawa' => 'Pacific/Tarawa',
            'Pacific/Wake' => 'Pacific/Wake',
            'Pacific/Wallis' => 'Pacific/Wallis',
            'Antarctica/McMurdo' => 'Antarctica/McMurdo',
            'Pacific/Apia' => 'Pacific/Apia',
            'Pacific/Auckland' => 'Pacific/Auckland',
            'Pacific/Fakaofo' => 'Pacific/Fakaofo',
            'Pacific/Kanton' => 'Pacific/Kanton',
            'Pacific/Tongatapu' => 'Pacific/Tongatapu',
            'Pacific/Chatham' => 'Pacific/Chatham',
            'Pacific/Kiritimati' => 'Pacific/Kiritimati',
        ];
    }
}
*/

if (! function_exists('formatBytes')) {
    function formatBytes($bytes = '', $force_unit = null, $format = null, $si = true)
    {
        $bytes = ($bytes) ? $bytes : config('image-max-size', '123344');
        // Format string
        $format = ($format === null) ? '%01.2f %s' : (string) $format;

        // IEC prefixes (binary)
        if ($si == false or strpos($force_unit, 'i') !== false) {
            $units = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB'];
            $mod = 1024;
        }
        // SI prefixes (decimal)
        else {
            $units = ['B', 'kB', 'MB', 'GB', 'TB', 'PB'];
            $mod = 1024;
        }

        // Determine unit to use
        if (($power = array_search((string) $force_unit, $units)) === false) {
            $power = ($bytes > 0) ? floor(log($bytes, $mod)) : 0;
        }

        return sprintf($format, $bytes / pow($mod, $power), $units[$power]);
    }
}

if (! function_exists('generatePassword')) {
    function generatePassword($length)
    {
        $token = '';
        $codeAlphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $codeAlphabet .= 'abcdefghijklmnopqrstuvwxyz';
        $codeAlphabet .= '0123456789';
        $max = strlen($codeAlphabet); // edited

        for ($i = 0; $i < $length; $i++) {
            $token .= $codeAlphabet[mt_rand(0, $max - 1)];
        }

        return $token;
    }
}

function AutoLinkUrls($text, $popup = true)
{
   // $regexB = '(?:[^-\\/"\':!=a-z0-9_@＠]|^|\\:)';
    $regexB = '(?:[^-\\/"\':!=a-z0-9_@＠]|^|\\:)';
    $regexUrl = '(?:[^\\p{P}\\p{Lo}\\s][\\.-](?=[^\\p{P}\\p{Lo}\\s])|[^\\p{P}\\p{Lo}\\s])+\\.[a-z]{2,}(?::[0-9]+)?';
    $regexUrlChars = '(?:(?:\\([a-z0-9!\\*\';:=\\+\\$\\/%#\\[\\]\\-_,~]+\\))|@[a-z0-9!\\*\';:=\\+\\$\\/%#\\[\\]\\-_,~]+\\/|[\\.\\,]?(?:[a-z0-9!\\*\';:=\\+\\$\\/%#\\[\\]\\-_~]|,(?!\s)))';
    $regexURLPath = '[a-z0-9=#\\/]';
    $regexQuery = '[a-z0-9!\\*\'\\(\\);:&=\\+\\$\\/%#\\[\\]\\-_\\.,~]';
    $regexQueryEnd = '[a-z0-9_&=#\\/]';

    $regex = '/(?:'             // $1 Complete match (preg_match already matches everything.)
        .'('.$regexB.')'    // $2 Preceding character
        .'('                                     // $3 Complete URL
        .'((?:https?:\\/\\/|www\\.)?)'           // $4 Protocol (or www)
        .'('.$regexUrl.')'          // $5 Domain(s) (and port)
        .'(\\/'.$regexUrlChars.'*'   // $6 URL Path
        .$regexURLPath.'?)?'
        .'(\\?'.$regexQuery.'*'  // $7 Query String
        .$regexQueryEnd.')?'
        .')'
        .')/iux';

    return preg_replace_callback($regex, function ($matches) {

        list($all, $before, $url, $protocol, $domain, $path, $query) = array_pad($matches, 7, '');
        $href = ((! $protocol || strtolower($protocol) === 'www.') ? 'http://'.$url : $url);
        $hrefWhole = $href;
        $href = getShortUrl($href);
        if (! $protocol && ! preg_match('/\\.(?:com|net|org|gov|edu)$/iu', $domain)) {
            return $all;
        }

        // $newUrl=\URL::to('postarticle')."?url=".$url;
        // $newUrl=\URL::to('postarticle')."?url=".$hrefWhole; //whole working url

        $newUrl = $hrefWhole;

        // return $before."<a nofollow='nofollow' href='".$newUrl."' >".$href."</a>"; // iframe call

        // return $before."<a onclick=\"return window.open('".$href."')\" nofollow='nofollow' href='javascript:void(0)' >".$url."</a>"; //existing one

        if (strlen($href) > 30) {
            $hrefShort = Str::limit($href, 30);
        } else {
            $hrefShort = $href;
        }

        // return $before."<a onclick=\"return window.open('".$url."')\" nofollow='nofollow' href='javascript:void(0)' >".$hrefShort."</a>"; //new with new window
        // return $before."<a nofollow='nofollow' href='".$newUrl."'>".$hrefShort."</a>";

        return $before."<a target='_blank' href='".$newUrl."'>".$hrefShort.'</a>';

        /*$domain=get_domain($newUrl);
        $ownUrls=array('vmeetsnew.devs','vmeets.wakhal.com');
        if(in_array($domain,$ownUrls))
        {
                $postRedirectUrlMeeting=\URL::to('postarticle')."?url=".$newUrl;
             $postRedirectUrl=$before."<a target='_blank' href='".$postRedirectUrlMeeting."'>".$hrefShort."</a>";
        }else{
            $postRedirectUrl=$before."<a target='_blank' href='".$newUrl."'>".$hrefShort."</a>";
        }
        return $postRedirectUrl;*/

    }, $text);

}// end AutoLinkUrls

function get_domain($url)
{
    $pieces = parse_url($url);
    $domain = isset($pieces['host']) ? $pieces['host'] : $pieces['path'];
    if (preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)) {
        return $regs['domain'];
    }

    return false;
}

function getMonthName($n)
{
    $months = config('months.list');

    if (isset($months[$n])) {
        return trans($months[$n]);
    }

    return '';
}

function lawedContent($t, $C = 1, $S = [])
{
    /*  if (file_exists('library/htmlawed/htmLawed.php')) {
          require_once 'library/htmlawed/htmLawed.php';

          return htmLawed($t, $C, $S);
      }*/

    app('App\\Repositories\\PostRepository')->htLawedContent($t, $C, $S);

    return $t;
}

function getProperAge($y, $d, $m)
{
    $thisYear = (int) date('Y');
    $diff = $thisYear - $y;
    $aDiff = $diff - 1;
    $thisMonth = (int) date('n');
    $thisDay = (int) date('j');

    if ($m > $thisMonth) {
        return $aDiff;
    }

    if ($thisMonth == $m) {
        // let check for the day
        if ($d > $thisDay) {
            return $aDiff;
        }
    }

    return $diff;
}

function formatDTime($time)
{
    $dateTime = date_create($time);

    return date_format($dateTime, 'D, M j, Y');
}

function formatDTimePost($time, $type)
{

    $currentDate = strtotime(date('Y-m-d H:i:s'));
    $dateCreated = strtotime($time);
    $dateTime = date_create($time);
    if ($type == 1) {
        if ($dateCreated > $currentDate) {
            return 'Scheduled for '.date('Y-m-d', strtotime($time)).' at '.date('H:i', strtotime($time)).' hrs';
        } else {
            // return date_format($dateTime, 'l, F j, Y');
            return date_format($dateTime, 'D, M j, Y');
        }
    } else {
        // return date_format($dateTime, 'l, F j, Y');
        return date_format($dateTime, 'D, M j, Y');
    }
}

function curl_get_file_size($url)
{
    $ch = curl_init($url);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_NOBODY, true);

    $data = curl_exec($ch);
    $size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);

    curl_close($ch);

    return $size;
}

function parseVimeo($link)
{
    $link = str_replace('http://www.', '', $link);
    $link = str_replace('http://', '', $link);
    $link = str_replace('https://', '', $link);
    $link = str_replace('www.', '', $link);
    // $link = str_replace('https://wwww.','', $link);

    // echo $link;

    if (preg_match('#vimeo.com\/[a-zA-Z0-9\-\_]#', $link)) {
        if (preg_match('#player.vimeo#', $link)) {
            return 'http://'.$link;
        }

        // return true;
        $link = str_replace('vimeo.com/', 'vimeo.com/video/', $link);
        $link = 'http://player.'.$link;

        return $link;
    }

    return false;
}

function parseYouTube($link)
{
    if (preg_match('#embed#', $link)) {
        return $link;
    }

    // this take care of youtube link like this http://youtu.be/awerqwouioqw
    if (preg_match('#http://#', $link)) {
        if (preg_match('#http://youtu.be#', $link)) {
            $link = str_replace('http://youtu.be', 'http://www.youtu.be', $link);

        } elseif (preg_match('#http://youtube.com#', $link)) {
            $link = str_replace('http://youtube.com', 'http://www.youtube.com', $link);
        }

        if (preg_match("#http:\/\/youtu.be\/[a-zA-Z0-9\-\_\.]+#", $link, $matchs)) {
            return 'http://www.youtube.com/embed/'.str_replace('http://youtu.be/', '', $link);
        }

        // this take care of youtube http://youtube.com/watch?v=dfkjsdfhsdjk
        if (preg_match("#http:\/\/www.youtube.com\/watch\?v\=[a-zA-Z0-9\-\_\.]+#", $link, $matchs)) {
            return 'http://www.youtube.com/embed/'.str_replace('http://www.youtube.com/watch?v=', '', $link);
        }

    } elseif (preg_match('#https://#', $link)) {
        if (preg_match('#https://youtu.be#', $link)) {
            $link = str_replace('https://youtu.be', 'https://www.youtu.be', $link);

        } elseif (preg_match('#https://youtube.com#', $link)) {
            $link = str_replace('https://youtube.com', 'https://www.youtube.com', $link);
        }

        if (preg_match("#https:\/\/www.youtu.be\/[a-zA-Z0-9\-\_\.]+#", $link, $matchs)) {
            return 'https://www.youtube.com/embed/'.str_replace('https://www.youtu.be/', '', $link);
        }

        // this take care of youtube http://youtube.com/watch?v=dfkjsdfhsdjk
        if (preg_match("#https:\/\/www.youtube.com\/watch\?v\=[a-zA-Z0-9\-\_\.]+#", $link, $matchs)) {

            return 'https://www.youtube.com/embed/'.str_replace('https://www.youtube.com/watch?v=', '', $link);
        }
    }

    return false;
}

function parseAmazonLink($link)
{
    /* amazon/uploads/videos */
    if (preg_match('#http://medias.wakhal.com/(uploads/videos.*)#', $link, $matches)) { // amazon server path
        return $matches[1];
    }
    if (preg_match('#https://medias.wakhal.com/(uploads/videos.*)#', $link, $matches)) { // amazon server path
        return $matches[1];
    }

    return false;
}

function parseVideoLink($link)
{
    $url = $link;
    $file_path = '';
    if ($url != '') {

        if (strpos($url, 'dropbox.com/') !== false) {
            $url = str_replace('dropbox.com/', 'dl.dropboxusercontent.com/', $url);
            $url = str_replace('?dl=0', '', $url);
            $url = str_replace('?dl=1', '', $url);
            $link = $url;
        }

        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FAILONERROR, true);

        $response = curl_exec($ch);
        $contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
        $pathinfo = pathinfo($url);

        // avi, wmv
        if (isset($pathinfo['extension'])) {
            $extension = strtolower($pathinfo['extension']);
            if ($extension == 'mp4' || $extension == 'mov' || $extension == 'ogg') {
                return $file_path = $link;
            }
        }
    }

    return false;
}

function parseEmbedVideoLink($link)
{
    $url = $link;
    $file_path = '';
    if ($url != '') {
        if (strpos($url, 'https://drive.google.com/file/') !== false) {
            $url = str_replace('?usp=sharing', '', $url);
            $url = str_replace('/view', '/preview', $url);

            return $url;
        }
    }

    return false;
}

function parsePDFLink($pdf_file_url)
{
    $url = $pdf_file_url;
    $file_path = '';
    if ($pdf_file_url != '') {
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FAILONERROR, true);

        $response = curl_exec($ch);
        $contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
        $pathinfo = pathinfo($url);
        if (isset($pathinfo['extension'])) {
            $extension = strtolower($pathinfo['extension']);
            if ($extension == 'pdf') {
                $file_path = $pdf_file_url;
            }
        }
    }

    return $file_path;
}

if (! function_exists('createUsernameFromEmail')) {
    function createUsernameFromEmail($email)
    {
        $username = preg_replace('/[^A-Za-z0-9]/', '', $email);

        return $username;
    }
}

function getShortUrl($longUrl)
{
    // Get API key from : http://code.google.com/apis/console/
    /* $apiKey = 'AIzaSyDQeLPsboPHdfWzHwWy7IyVC3Z4Sxc4J_0';//'AIzaSyAL9wh0-o8jEncPhKB630HbnNaqLnKotzo';
     $postData = array('longUrl' => $longUrl);
     $jsonData = json_encode($postData);
     $curlObj = curl_init();
     curl_setopt($curlObj, CURLOPT_URL, 'https://www.googleapis.com/urlshortener/v1/url?key='.$apiKey);
     curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);
     curl_setopt($curlObj, CURLOPT_HEADER, 0);
     curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
     curl_setopt($curlObj, CURLOPT_POST, 1);
     curl_setopt($curlObj, CURLOPT_POSTFIELDS, $jsonData);

     $response = curl_exec($curlObj);
     $json = json_decode($response);
     if(isset($json->error)){
         return $longUrl;
     }else{
         return $json->id;
     }*/

    // ----------------------------------Tinyurl start
    /*
     $ch = curl_init();
     $timeout = 5;
     curl_setopt($ch,CURLOPT_URL,'http://tinyurl.com/api-create.php?url='.$longUrl);
     curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
     curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
     $response = curl_exec($ch);
     curl_close($ch);
     return $response;
     */
    // -------------------------------Tinyurl end

    $paresedUrl = parse_url($longUrl);
    if (isset($paresedUrl['scheme']) and isset($paresedUrl['host'])) {
        return $newUrl = $paresedUrl['scheme'].'://'.$paresedUrl['host'];
    } else {
        return $longUrl;
    }
}

function getShortUrlLink($text, $popup = true)
{
    $regexB = '(?:[^-\\/"\':!=a-z0-9_@＠]|^|\\:)';
    $regexUrl = '(?:[^\\p{P}\\p{Lo}\\s][\\.-](?=[^\\p{P}\\p{Lo}\\s])|[^\\p{P}\\p{Lo}\\s])+\\.[a-z]{2,}(?::[0-9]+)?';
    $regexUrlChars = '(?:(?:\\([a-z0-9!\\*\';:=\\+\\$\\/%#\\[\\]\\-_,~]+\\))|@[a-z0-9!\\*\';:=\\+\\$\\/%#\\[\\]\\-_,~]+\\/|[\\.\\,]?(?:[a-z0-9!\\*\';:=\\+\\$\\/%#\\[\\]\\-_~]|,(?!\s)))';
    $regexURLPath = '[a-z0-9=#\\/]';
    $regexQuery = '[a-z0-9!\\*\'\\(\\);:&=\\+\\$\\/%#\\[\\]\\-_\\.,~]';
    $regexQueryEnd = '[a-z0-9_&=#\\/]';

    $regex = '/(?:'             // $1 Complete match (preg_match already matches everything.)
        .'('.$regexB.')'    // $2 Preceding character
        .'('                                     // $3 Complete URL
        .'((?:https?:\\/\\/|www\\.)?)'           // $4 Protocol (or www)
        .'('.$regexUrl.')'          // $5 Domain(s) (and port)
        .'(\\/'.$regexUrlChars.'*'   // $6 URL Path
        .$regexURLPath.'?)?'
        .'(\\?'.$regexQuery.'*'  // $7 Query String
        .$regexQueryEnd.')?'
        .')'
        .')/iux';

    return preg_replace_callback($regex, function ($matches) {

        list($all, $before, $url, $protocol, $domain, $path, $query) = array_pad($matches, 7, '');
        $href = ((! $protocol || strtolower($protocol) === 'www.') ? 'http://'.$url : $url);

        $href = getShortUrl($href);
        if (! $protocol && ! preg_match('/\\.(?:com|net|org|gov|edu)$/iu', $domain)) {
            return $all;
        }

        return $before.$href;

    }, $text);
}// end getShortUrlLink

// Compress Image
function compressImage($source, $destination, $quality)
{

    $info = getimagesize($source);

    if ($info['mime'] == 'image/jpeg') {
        $image = imagecreatefromjpeg($source);
    } elseif ($info['mime'] == 'image/gif') {
        $image = imagecreatefromgif($source);
    } elseif ($info['mime'] == 'image/png') {
        $image = imagecreatefrompng($source);
    }

    imagejpeg($image, $destination, $quality);

    return $destination;
}

if (! function_exists('sanitizeRevertText')) {
    function sanitizeRevertText($string, $limit = false)
    {
        if (! is_string($string)) {
            return $string;
        }
        $string = lawedContent($string); // great one
        $string = trim($string);
        $string = str_replace('&#60;', '<', $string);
        $string = str_replace('&#62;', '>', $string);
        $string = str_replace('&#39;', "'", $string);
        $string = htmlspecialchars($string);
        $string = str_replace('<br>', '\\r\\n', $string);
        $string = str_replace('<br>', '\\n\\n', $string);
        // $string = stripslashes($string);
        $string = str_replace('&#', '&amp;#', $string);

        if ($limit) {
            $string = substr($string, 0, $limit);
        }

        return $string;
    }
}

function formatSizeUnits($bytes)
{
    if ($bytes >= 1073741824) {
        $bytes = number_format($bytes / 1073741824, 2).' GB';
    } elseif ($bytes >= 1048576) {
        $bytes = number_format($bytes / 1048576, 2).' MB';
    } elseif ($bytes >= 1024) {
        $bytes = number_format($bytes / 1024, 2).' KB';
    } elseif ($bytes > 1) {
        $bytes = $bytes.' bytes';
    } elseif ($bytes == 1) {
        $bytes = $bytes.' byte';
    } else {
        $bytes = '0 bytes';
    }

    return $bytes;
}

function getTimeAgo($timeZone)
{
    $timeSet = '+05:30';
    if ($timeZone == 'UTC') {
        $timeSet = '-00:00';
    } elseif ($timeZone == 'Pacific/Midway') {
        $timeSet = '-11:00';
    } elseif ($timeZone == 'Pacific/Niue') {
        $timeSet = '-11:00';
    } elseif ($timeZone == 'Pacific/Pago_Pago') {
        $timeSet = '-11:00';
    } elseif ($timeZone == 'Pacific/Honolulu') {
        $timeSet = '-10:00';
    } elseif ($timeZone == 'Pacific/Johnston') {
        $timeSet = '-10:00';
    } elseif ($timeZone == 'Pacific/Rarotonga') {
        $timeSet = '-10:00';
    } elseif ($timeZone == 'Pacific/Tahiti') {
        $timeSet = '-10:00';
    } elseif ($timeZone == 'Pacific/Marquesas') {
        $timeSet = '-09:30';
    } elseif ($timeZone == 'America/Ciudad_Juarez') { // new added start
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-07:00';
        } else {
            $timeSet = '-08:00';
        }
    } elseif ($timeZone == 'America/Punta_Arenas') { // new added start
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-03:00';
        } else {
            $timeSet = '-04:00';
        }
    } elseif ($timeZone == 'America/Nuuk') { // new added start
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-02:00';
        } else {
            $timeSet = '-03:00';
        }
    } elseif ($timeZone == 'Europe/Kyiv') { // new added start
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'America/Adak') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-9:00';
        } else {
            $timeSet = '-10:00';
        }
    } elseif ($timeZone == 'Pacific/Gambier') {
        $timeSet = '-09:00';
    } elseif ($timeZone == 'America/Anchorage') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-08:00';
        } else {
            $timeSet = '-09:00';
        }
    } elseif ($timeZone == 'America/Juneau') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-08:00';
        } else {
            $timeSet = '-09:00';
        }
    } elseif ($timeZone == 'America/Metlakatla') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-08:00';
        } else {
            $timeSet = '-09:00';
        }
    } elseif ($timeZone == 'America/Nome') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-08:00';
        } else {
            $timeSet = '-09:00';
        }
    } elseif ($timeZone == 'America/Sitka') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-08:00';
        } else {
            $timeSet = '-09:00';
        }
    } elseif ($timeZone == 'America/Yakutat') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-08:00';
        } else {
            $timeSet = '-09:00';
        }
    } elseif ($timeZone == 'Pacific/Pitcairn') {
        $timeSet = '-08:00';
    } elseif ($timeZone == 'America/Creston') {
        $timeSet = '-07:00';
    } elseif ($timeZone == 'America/Dawson') {
        $timeSet = '-07:00';
    } elseif ($timeZone == 'America/Dawson_Creek') {
        $timeSet = '-07:00';
    } elseif ($timeZone == 'America/Fort_Nelson') {
        $timeSet = '-07:00';
    } elseif ($timeZone == 'America/Hermosillo') {
        $timeSet = '-07:00';
    } elseif ($timeZone == 'America/Los_Angeles') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-07:00';
        } else {
            $timeSet = '-08:00';
        }
    } elseif ($timeZone == 'America/Phoenix') {
        $timeSet = '-07:00';
    } elseif ($timeZone == 'America/Tijuana') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-07:00';
        } else {
            $timeSet = '-08:00';
        }
    } elseif ($timeZone == 'America/Vancouver') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-07:00';
        } else {
            $timeSet = '-08:00';
        }
    } elseif ($timeZone == 'America/Whitehorse') { // difference
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-07:00';
        } else {
            $timeSet = '-08:00';
        }
    } elseif ($timeZone == 'America/Belize') {
        $timeSet = '-06:00';
    } elseif ($timeZone == 'America/Boise') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-06:00';
        } else {
            $timeSet = '-07:00';
        }
    } elseif ($timeZone == 'America/Cambridge_Bay') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-06:00';
        } else {
            $timeSet = '-07:00';
        }
    } elseif ($timeZone == 'America/Chihuahua') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-06:00';
        } else {
            $timeSet = '-07:00';
        }
    } elseif ($timeZone == 'America/Costa_Rica') {
        $timeSet = '-06:00';
    } elseif ($timeZone == 'America/Denver') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-06:00';
        } else {
            $timeSet = '-07:00';
        }
    } elseif ($timeZone == 'America/Edmonton') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-06:00';
        } else {
            $timeSet = '-07:00';
        }
    } elseif ($timeZone == 'America/El_Salvador') {
        $timeSet = '-06:00';
    } elseif ($timeZone == 'America/Guatemala') {
        $timeSet = '-06:00';
    } elseif ($timeZone == 'America/Inuvik') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-06:00';
        } else {
            $timeSet = '-07:00';
        }
    } elseif ($timeZone == 'America/Managua') {
        $timeSet = '-06:00';
    } elseif ($timeZone == 'America/Mazatlan') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-06:00';
        } else {
            $timeSet = '-07:00';
        }
    } elseif ($timeZone == 'America/Ojinaga') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-06:00';
        } else {
            $timeSet = '-07:00';
        }
    } elseif ($timeZone == 'America/Regina') {
        $timeSet = '-06:00';
    } elseif ($timeZone == 'America/Swift_Current') {
        $timeSet = '-06:00';
    } elseif ($timeZone == 'America/Tegucigalpa') {
        $timeSet = '-06:00';
    } elseif ($timeZone == 'America/Yellowknife') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-06:00';
        } else {
            $timeSet = '-07:00';
        }
    } elseif ($timeZone == 'Pacific/Galapagos') {
        $timeSet = '-06:00';
    } elseif ($timeZone == 'America/Atikokan') {
        $timeSet = '-05:00';
    } elseif ($timeZone == 'America/Bahia_Banderas') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-05:00';
        } else {
            $timeSet = '-06:00';
        }
    } elseif ($timeZone == 'America/Bogota') {
        $timeSet = '-05:00';
    } elseif ($timeZone == 'America/Cancun') {
        $timeSet = '-05:00';
    } elseif ($timeZone == 'America/Cayman') {
        $timeSet = '-05:00';
    } elseif ($timeZone == 'America/Chicago') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-05:00';
        } else {
            $timeSet = '-06:00';
        }
    } elseif ($timeZone == 'America/Eirunepe') {
        $timeSet = '-05:00';
    } elseif ($timeZone == 'America/Guayaquil') {
        $timeSet = '-05:00';
    } elseif ($timeZone == 'America/Indiana/Knox') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-05:00';
        } else {
            $timeSet = '-06:00';
        }
    } elseif ($timeZone == 'America/Indiana/Tell_City') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-05:00';
        } else {
            $timeSet = '-06:00';
        }
    } elseif ($timeZone == 'America/Jamaica') {
        $timeSet = '-05:00';
    } elseif ($timeZone == 'America/Lima') {
        $timeSet = '-05:00';
    } elseif ($timeZone == 'America/Matamoros') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-05:00';
        } else {
            $timeSet = '-06:00';
        }
    } elseif ($timeZone == 'America/Menominee') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-05:00';
        } else {
            $timeSet = '-06:00';
        }
    } elseif ($timeZone == 'America/Merida') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-05:00';
        } else {
            $timeSet = '-06:00';
        }
    } elseif ($timeZone == 'America/Mexico_City') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-05:00';
        } else {
            $timeSet = '-06:00';
        }
    } elseif ($timeZone == 'America/Monterrey') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-05:00';
        } else {
            $timeSet = '-06:00';
        }
    } elseif ($timeZone == 'America/North_Dakota/Beulah') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-05:00';
        } else {
            $timeSet = '-06:00';
        }
    } elseif ($timeZone == 'America/North_Dakota/Center') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-05:00';
        } else {
            $timeSet = '-06:00';
        }
    } elseif ($timeZone == 'America/North_Dakota/New_Salem') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-05:00';
        } else {
            $timeSet = '-06:00';
        }
    } elseif ($timeZone == 'America/Panama') {
        $timeSet = '-05:00';
    } elseif ($timeZone == 'America/Port-au-Prince') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-04:00';
        } else {
            $timeSet = '-05:00';
        }
    } elseif ($timeZone == 'America/Rainy_River') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-05:00';
        } else {
            $timeSet = '-06:00';
        }
    } elseif ($timeZone == 'America/Rankin_Inlet') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-05:00';
        } else {
            $timeSet = '-06:00';
        }
    } elseif ($timeZone == 'America/Resolute') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-05:00';
        } else {
            $timeSet = '-06:00';
        }
    } elseif ($timeZone == 'America/Rio_Branco') {
        $timeSet = '-05:00';
    } elseif ($timeZone == 'America/Winnipeg') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-05:00';
        } else {
            $timeSet = '-06:00';
        }
    } elseif ($timeZone == 'Pacific/Easter') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-05:00';
        } else {
            $timeSet = '-06:00';
        }
    } elseif ($timeZone == 'America/Anguilla') {
        $timeSet = '-05:00';
    } elseif ($timeZone == 'America/Antigua') {
        $timeSet = '-04:00';
    } elseif ($timeZone == 'America/Aruba') {
        $timeSet = '-04:00';
    } elseif ($timeZone == 'America/Asuncion') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-03:00';
        } else {
            $timeSet = '-04:00';
        }
    } elseif ($timeZone == 'America/Barbados') {
        $timeSet = '-04:00';
    } elseif ($timeZone == 'America/Blanc-Sablon') {
        $timeSet = '-04:00';
    } elseif ($timeZone == 'America/Boa_Vista') {
        $timeSet = '-04:00';
    } elseif ($timeZone == 'America/Campo_Grande') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-03:00';
        } else {
            $timeSet = '-04:00';
        }
    } elseif ($timeZone == 'America/Caracas') {
        $timeSet = '-04:00';
    } elseif ($timeZone == 'America/Cuiaba') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-03:00';
        } else {
            $timeSet = '-04:00';
        }
    } elseif ($timeZone == 'America/Curacao') {
        $timeSet = '-04:00';
    } elseif ($timeZone == 'America/Detroit') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-04:00';
        } else {
            $timeSet = '-05:00';
        }
    } elseif ($timeZone == 'America/Dominica') {
        $timeSet = '-04:00';
    } elseif ($timeZone == 'America/Grand_Turk') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-04:00';
        } else {
            $timeSet = '-05:00';
        }
    } elseif ($timeZone == 'America/Grenada') {
        $timeSet = '-04:00';
    } elseif ($timeZone == 'America/Guadeloupe') {
        $timeSet = '-04:00';
    } elseif ($timeZone == 'America/Guyana') {
        $timeSet = '-04:00';
    } elseif ($timeZone == 'America/Havana') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-04:00';
        } else {
            $timeSet = '-05:00';
        }
    } elseif ($timeZone == 'America/Indiana/Indianapolis') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-04:00';
        } else {
            $timeSet = '-05:00';
        }
    } elseif ($timeZone == 'America/Indiana/Marengo') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-04:00';
        } else {
            $timeSet = '-05:00';
        }
    } elseif ($timeZone == 'America/Indiana/Petersburg') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-04:00';
        } else {
            $timeSet = '-05:00';
        }
    } elseif ($timeZone == 'America/Indiana/Vevay') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-04:00';
        } else {
            $timeSet = '-05:00';
        }
    } elseif ($timeZone == 'America/Indiana/Vincennes') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-04:00';
        } else {
            $timeSet = '-05:00';
        }
    } elseif ($timeZone == 'America/Indiana/Winamac') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-04:00';
        } else {
            $timeSet = '-05:00';
        }
    } elseif ($timeZone == 'America/Iqaluit') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-04:00';
        } else {
            $timeSet = '-05:00';
        }
    } elseif ($timeZone == 'America/Kentucky/Louisville') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-04:00';
        } else {
            $timeSet = '-05:00';
        }
    } elseif ($timeZone == 'America/Kentucky/Monticello') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-04:00';
        } else {
            $timeSet = '-05:00';
        }
    } elseif ($timeZone == 'America/Kralendijk') {
        $timeSet = '-04:00';
    } elseif ($timeZone == 'America/La_Paz') {
        $timeSet = '-04:00';
    } elseif ($timeZone == 'America/Lower_Princes') {
        $timeSet = '-04:00';
    } elseif ($timeZone == 'America/Manaus') {
        $timeSet = '-04:00';
    } elseif ($timeZone == 'America/Marigot') {
        $timeSet = '-04:00';
    } elseif ($timeZone == 'America/Martinique') {
        $timeSet = '-04:00';
    } elseif ($timeZone == 'America/Montserrat') {
        $timeSet = '-04:00';
    } elseif ($timeZone == 'America/Nassau') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-04:00';
        } else {
            $timeSet = '-05:00';
        }
    } elseif ($timeZone == 'America/New_York') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-04:00';
        } else {
            $timeSet = '-05:00';
        }
    } elseif ($timeZone == 'America/Nipigon') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-04:00';
        } else {
            $timeSet = '-05:00';
        }
    } elseif ($timeZone == 'America/Pangnirtung') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-04:00';
        } else {
            $timeSet = '-05:00';
        }
    } elseif ($timeZone == 'America/Port_of_Spain') {
        $timeSet = '-04:00';
    } elseif ($timeZone == 'America/Porto_Velho') {
        $timeSet = '-04:00';
    } elseif ($timeZone == 'America/Puerto_Rico') {
        $timeSet = '-04:00';
    } elseif ($timeZone == 'America/Santo_Domingo') {
        $timeSet = '-04:00';
    } elseif ($timeZone == 'America/St_Barthelemy') {
        $timeSet = '-04:00';
    } elseif ($timeZone == 'America/St_Kitts') {
        $timeSet = '-04:00';
    } elseif ($timeZone == 'America/St_Lucia') {
        $timeSet = '-04:00';
    } elseif ($timeZone == 'America/St_Thomas') {
        $timeSet = '-04:00';
    } elseif ($timeZone == 'America/St_Vincent') {
        $timeSet = '-04:00';
    } elseif ($timeZone == 'America/Thunder_Bay') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-04:00';
        } else {
            $timeSet = '-05:00';
        }
    } elseif ($timeZone == 'America/Toronto') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-04:00';
        } else {
            $timeSet = '-05:00';
        }
    } elseif ($timeZone == 'America/Tortola') {
        $timeSet = '-04:00';
    } elseif ($timeZone == 'America/Araguaina') {
        $timeSet = '-03:00';
    } elseif ($timeZone == 'America/Argentina/Buenos_Aires') {
        $timeSet = '-03:00';
    } elseif ($timeZone == 'America/Argentina/Catamarca') {
        $timeSet = '-03:00';
    } elseif ($timeZone == 'America/Argentina/Cordoba') {
        $timeSet = '-03:00';
    } elseif ($timeZone == 'America/Argentina/Jujuy') {
        $timeSet = '-03:00';
    } elseif ($timeZone == 'America/Argentina/La_Rioja') {
        $timeSet = '-03:00';
    } elseif ($timeZone == 'America/Argentina/Mendoza') {
        $timeSet = '-03:00';
    } elseif ($timeZone == 'America/Argentina/Rio_Gallegos') {
        $timeSet = '-03:00';
    } elseif ($timeZone == 'America/Argentina/Salta') {
        $timeSet = '-03:00';
    } elseif ($timeZone == 'America/Argentina/San_Juan') {
        $timeSet = '-03:00';
    } elseif ($timeZone == 'America/Argentina/San_Luis') {
        $timeSet = '-03:00';
    } elseif ($timeZone == 'America/Argentina/Tucuman') {
        $timeSet = '-03:00';
    } elseif ($timeZone == 'America/Argentina/Ushuaia') {
        $timeSet = '-03:00';
    } elseif ($timeZone == 'America/Bahia') {
        $timeSet = '-03:00';
    } elseif ($timeZone == 'America/Belem') {
        $timeSet = '-03:00';
    } elseif ($timeZone == 'America/Cayenne') {
        $timeSet = '-03:00';
    } elseif ($timeZone == 'America/Fortaleza') {
        $timeSet = '-03:00';
    } elseif ($timeZone == 'America/Glace_Bay') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-03:00';
        } else {
            $timeSet = '-04:00';
        }
    } elseif ($timeZone == 'America/Goose_Bay') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-03:00';
        } else {
            $timeSet = '-04:00';
        }
    } elseif ($timeZone == 'America/Halifax') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-03:00';
        } else {
            $timeSet = '-04:00';
        }
    } elseif ($timeZone == 'America/Maceio') {
        $timeSet = '-03:00';
    } elseif ($timeZone == 'America/Moncton') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-03:00';
        } else {
            $timeSet = '-04:00';
        }
    } elseif ($timeZone == 'America/Montevideo') {
        $timeSet = '-03:00';
    } elseif ($timeZone == 'America/Paramaribo') {
        $timeSet = '-03:00';
    } elseif ($timeZone == 'America/Recife') {
        $timeSet = '-03:00';
    } elseif ($timeZone == 'America/Santarem') {
        $timeSet = '-03:00';
    } elseif ($timeZone == 'America/Santiago') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-03:00';
        } else {
            $timeSet = '-04:00';
        }
    } elseif ($timeZone == 'America/Sao_Paulo') {
        $timeSet = '-03:00';
    } elseif ($timeZone == 'America/Thule') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-03:00';
        } else {
            $timeSet = '-04:00';
        }
    } elseif ($timeZone == 'Antarctica/Palmer') {
        $timeSet = '-03:00';
    } elseif ($timeZone == 'Antarctica/Rothera') {
        $timeSet = '-03:00';
    } elseif ($timeZone == 'Atlantic/Bermuda') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-03:00';
        } else {
            $timeSet = '-04:00';
        }
    } elseif ($timeZone == 'Atlantic/Stanley') {
        $timeSet = '-03:00';
    } elseif ($timeZone == 'America/St_Johns') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-02:30';
        } else {
            $timeSet = '-03:30';
        }
    } elseif ($timeZone == 'America/Godthab') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-02:00';
        } else {
            $timeSet = '-03:00';
        }
    } elseif ($timeZone == 'America/Miquelon') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-02:00';
        } else {
            $timeSet = '-03:00';
        }
    } elseif ($timeZone == 'America/Noronha') {
        $timeSet = '-02:00';
    } elseif ($timeZone == 'Atlantic/South_Georgia') {
        $timeSet = '-02:00';
    } elseif ($timeZone == 'Atlantic/Cape_Verde') {
        $timeSet = '-01:00';
    } elseif ($timeZone == 'Africa/Abidjan') {
        $timeSet = '+00:00';
    } elseif ($timeZone == 'Africa/Accra') {
        $timeSet = '+00:00';
    } elseif ($timeZone == 'Africa/Bamako') {
        $timeSet = '+00:00';
    } elseif ($timeZone == 'Africa/Banjul') {
        $timeSet = '+00:00';
    } elseif ($timeZone == 'Africa/Bissau') {
        $timeSet = '+00:00';
    } elseif ($timeZone == 'Africa/Conakry') {
        $timeSet = '+00:00';
    } elseif ($timeZone == 'Africa/Dakar') {
        $timeSet = '+00:00';
    } elseif ($timeZone == 'Africa/Freetown') {
        $timeSet = '+00:00';
    } elseif ($timeZone == 'Africa/Lome') {
        $timeSet = '+00:00';
    } elseif ($timeZone == 'Africa/Monrovia') {
        $timeSet = '+00:00';
    } elseif ($timeZone == 'Africa/Nouakchott') {
        $timeSet = '+00:00';
    } elseif ($timeZone == 'Africa/Ouagadougou') {
        $timeSet = '+00:00';
    } elseif ($timeZone == 'Africa/Sao_Tome') {
        $timeSet = '+00:00';
    } elseif ($timeZone == 'America/Danmarkshavn') {
        $timeSet = '+00:00';
    } elseif ($timeZone == 'America/Scoresbysund') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-01:00';
        } else {
            $timeSet = '+00:00';
        }
    } elseif ($timeZone == 'Atlantic/Azores') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '-01:00';
        } else {
            $timeSet = '+00:00';
        }
    } elseif ($timeZone == 'Atlantic/Reykjavik') {
        $timeSet = '+00:00';
    } elseif ($timeZone == 'Atlantic/St_Helena') {
        $timeSet = '+00:00';
    } elseif ($timeZone == 'Africa/Algiers') {
        $timeSet = '+01:00';
    } elseif ($timeZone == 'Africa/Bangui') {
        $timeSet = '+01:00';
    } elseif ($timeZone == 'Africa/Brazzaville') {
        $timeSet = '+01:00';
    } elseif ($timeZone == 'Africa/Casablanca') {
        $timeSet = '+01:00';
    } elseif ($timeZone == 'Africa/Douala') {
        $timeSet = '+01:00';
    } elseif ($timeZone == 'Africa/El_Aaiun') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+00:00';
        } else {
            $timeSet = '+01:00';
        }
    } elseif ($timeZone == 'Africa/Kinshasa') {
        $timeSet = '+01:00';
    } elseif ($timeZone == 'Africa/Lagos') {
        $timeSet = '+01:00';
    } elseif ($timeZone == 'Africa/Libreville') {
        $timeSet = '+01:00';
    } elseif ($timeZone == 'Africa/Luanda') {
        $timeSet = '+01:00';
    } elseif ($timeZone == 'Africa/Malabo') {
        $timeSet = '+01:00';
    } elseif ($timeZone == 'Africa/Ndjamena') {
        $timeSet = '+01:00';
    } elseif ($timeZone == 'Africa/Niamey') {
        $timeSet = '+01:00';
    } elseif ($timeZone == 'Africa/Porto-Novo') {
        $timeSet = '+01:00';
    } elseif ($timeZone == 'Africa/Tunis') {
        $timeSet = '+01:00';

    } elseif ($timeZone == 'Africa/Windhoek') {
        $timeSet = '+01:00';
    } elseif ($timeZone == 'Atlantic/Canary') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+00:00';
        } else {
            $timeSet = '+01:00';
        }
    } elseif ($timeZone == 'Atlantic/Faroe') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+00:00';
        } else {
            $timeSet = '+01:00';
        }
    } elseif ($timeZone == 'Atlantic/Madeira') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+00:00';
        } else {
            $timeSet = '+01:00';
        }
    } elseif ($timeZone == 'Europe/Dublin') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+00:00';
        } else {
            $timeSet = '+01:00';
        }
    } elseif ($timeZone == 'Europe/Guernsey') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+00:00';
        } else {
            $timeSet = '+01:00';
        }
    } elseif ($timeZone == 'Europe/Isle_of_Man') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+00:00';
        } else {
            $timeSet = '+01:00';
        }
    } elseif ($timeZone == 'Europe/Jersey') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+00:00';
        } else {
            $timeSet = '+01:00';
        }
    } elseif ($timeZone == 'Europe/Lisbon') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+00:00';
        } else {
            $timeSet = '+01:00';
        }
    } elseif ($timeZone == 'Europe/London') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+00:00';
        } else {
            $timeSet = '+01:00';
        }
    } elseif ($timeZone == 'Africa/Blantyre') {
        $timeSet = '+02:00';
    } elseif ($timeZone == 'Africa/Bujumbura') {
        $timeSet = '+02:00';
    } elseif ($timeZone == 'Africa/Cairo') {
        $timeSet = '+02:00';
    } elseif ($timeZone == 'Africa/Ceuta') {
        $timeSet = '+01:00';
    } elseif ($timeZone == 'Africa/Gaborone') {
        $timeSet = '+02:00';
    } elseif ($timeZone == 'Africa/Harare') {
        $timeSet = '+02:00';
    } elseif ($timeZone == 'Africa/Johannesburg') {
        $timeSet = '+02:00';
    } elseif ($timeZone == 'Africa/Kigali') {
        $timeSet = '+02:00';
    } elseif ($timeZone == 'Africa/Lubumbashi') {
        $timeSet = '+02:00';
    } elseif ($timeZone == 'Africa/Lusaka') {
        $timeSet = '+02:00';
    } elseif ($timeZone == 'Africa/Maputo') {
        $timeSet = '+02:00';
    } elseif ($timeZone == 'Africa/Maseru') {
        $timeSet = '+02:00';
    } elseif ($timeZone == 'Africa/Mbabane') {
        $timeSet = '+02:00';
    } elseif ($timeZone == 'Africa/Tripoli') {
        $timeSet = '+02:00';
    } elseif ($timeZone == 'Antarctica/Troll') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+00:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Arctic/Longyearbyen') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Europe/Amsterdam') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Europe/Andorra') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Europe/Belgrade') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Europe/Berlin') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Europe/Bratislava') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Europe/Brussels') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Europe/Budapest') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Europe/Busingen') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Europe/Copenhagen') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Europe/Gibraltar') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Europe/Kaliningrad') {
        $timeSet = '+02:00';
    } elseif ($timeZone == 'Europe/Ljubljana') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Europe/Luxembourg') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Europe/Madrid') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Europe/Malta') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Europe/Monaco') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Europe/Oslo') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Europe/Paris') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Europe/Podgorica') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Europe/Prague') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Europe/Rome') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Europe/San_Marino') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Europe/Sarajevo') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Europe/Skopje') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Europe/Stockholm') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Europe/Tirane') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Europe/Vaduz') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Europe/Vatican') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Europe/Vienna') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Europe/Warsaw') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Europe/Zagreb') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Europe/Zurich') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+01:00';
        } else {
            $timeSet = '+02:00';
        }
    } elseif ($timeZone == 'Africa/Addis_Ababa') {
        $timeSet = '+03:00';
    } elseif ($timeZone == 'Africa/Asmara') {
        $timeSet = '+03:00';
    } elseif ($timeZone == 'Africa/Dar_es_Salaam') {
        $timeSet = '+03:00';
    } elseif ($timeZone == 'Africa/Djibouti') {
        $timeSet = '+03:00';
    } elseif ($timeZone == 'Africa/Juba') {
        $timeSet = '+03:00';
    } elseif ($timeZone == 'Africa/Kampala') {
        $timeSet = '+03:00';
    } elseif ($timeZone == 'Africa/Khartoum') {
        $timeSet = '+02:00';

    } elseif ($timeZone == 'Africa/Mogadishu') {
        $timeSet = '+03:00';
    } elseif ($timeZone == 'Africa/Nairobi') {
        $timeSet = '+03:00';
    } elseif ($timeZone == 'Antarctica/Syowa') {
        $timeSet = '+03:00';
    } elseif ($timeZone == 'Asia/Aden') {
        $timeSet = '+03:00';
    } elseif ($timeZone == 'Asia/Amman') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+02:00';
        } else {
            $timeSet = '+03:00';
        }
    } elseif ($timeZone == 'Asia/Baghdad') {
        $timeSet = '+03:00';
    } elseif ($timeZone == 'Asia/Bahrain') {
        $timeSet = '+03:00';
    } elseif ($timeZone == 'Asia/Beirut') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+02:00';
        } else {
            $timeSet = '+03:00';
        }
    } elseif ($timeZone == 'Asia/Damascus') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+02:00';
        } else {
            $timeSet = '+03:00';
        }
    } elseif ($timeZone == 'Asia/Famagusta') {
        $timeSet = '+02:00';
    } elseif ($timeZone == 'Asia/Gaza') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+02:00';
        } else {
            $timeSet = '+03:00';
        }
    } elseif ($timeZone == 'Asia/Hebron') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+02:00';
        } else {
            $timeSet = '+03:00';
        }
    } elseif ($timeZone == 'Asia/Jerusalem') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+02:00';
        } else {
            $timeSet = '+03:00';
        }
    } elseif ($timeZone == 'Asia/Kuwait') {
        $timeSet = '+03:00';
    } elseif ($timeZone == 'Asia/Nicosia') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+02:00';
        } else {
            $timeSet = '+03:00';
        }
    } elseif ($timeZone == 'Asia/Qatar') {
        $timeSet = '+03:00';
    } elseif ($timeZone == 'Asia/Riyadh') {
        $timeSet = '+03:00';
    } elseif ($timeZone == 'Europe/Athens') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+02:00';
        } else {
            $timeSet = '+03:00';
        }
    } elseif ($timeZone == 'Europe/Bucharest') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+02:00';
        } else {
            $timeSet = '+03:00';
        }
    } elseif ($timeZone == 'Europe/Chisinau') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+02:00';
        } else {
            $timeSet = '+03:00';
        }
    } elseif ($timeZone == 'Europe/Helsinki') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+02:00';
        } else {
            $timeSet = '+03:00';
        }
    } elseif ($timeZone == 'Europe/Istanbul') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+02:00';
        } else {
            $timeSet = '+03:00';
        }
    } elseif ($timeZone == 'Europe/Kiev') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+02:00';
        } else {
            $timeSet = '+03:00';
        }
    } elseif ($timeZone == 'Europe/Kirov') {
        $timeSet = '+03:00';
    } elseif ($timeZone == 'Europe/Mariehamn') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+02:00';
        } else {
            $timeSet = '+03:00';
        }
    } elseif ($timeZone == 'Europe/Minsk') {
        $timeSet = '+03:00';
    } elseif ($timeZone == 'Europe/Moscow') {
        $timeSet = '+03:00';
    } elseif ($timeZone == 'Europe/Riga') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+02:00';
        } else {
            $timeSet = '+03:00';
        }
    } elseif ($timeZone == 'Europe/Simferopol') {
        $timeSet = '+03:00';
    } elseif ($timeZone == 'Europe/Sofia') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+02:00';
        } else {
            $timeSet = '+03:00';
        }
    } elseif ($timeZone == 'Europe/Tallinn') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+02:00';
        } else {
            $timeSet = '+03:00';
        }
    } elseif ($timeZone == 'Europe/Uzhgorod') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+02:00';
        } else {
            $timeSet = '+03:00';
        }
    } elseif ($timeZone == 'Europe/Vilnius') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+02:00';
        } else {
            $timeSet = '+03:00';
        }
    } elseif ($timeZone == 'Europe/Volgograd') {
        $timeSet = '+04:00';
    } elseif ($timeZone == 'Europe/Zaporozhye') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+02:00';
        } else {
            $timeSet = '+03:00';
        }
    } elseif ($timeZone == 'Indian/Antananarivo') {
        $timeSet = '+03:00';
    } elseif ($timeZone == 'Indian/Comoro') {
        $timeSet = '+03:00';
    } elseif ($timeZone == 'Indian/Mayotte') {
        $timeSet = '+03:00';
    } elseif ($timeZone == 'Asia/Baku') {
        $timeSet = '+04:00';
    } elseif ($timeZone == 'Asia/Dubai') {
        $timeSet = '+04:00';
    } elseif ($timeZone == 'Asia/Muscat') {
        $timeSet = '+04:00';
    } elseif ($timeZone == 'Asia/Tbilisi') {
        $timeSet = '+04:00';
    } elseif ($timeZone == 'Asia/Yerevan') {
        $timeSet = '+04:00';
    } elseif ($timeZone == 'Europe/Astrakhan') {
        $timeSet = '+04:00';
    } elseif ($timeZone == 'Europe/Samara') {
        $timeSet = '+04:00';
    } elseif ($timeZone == 'Europe/Saratov') {
        $timeSet = '+04:00';
    } elseif ($timeZone == 'Europe/Ulyanovsk') {
        $timeSet = '+04:00';
    } elseif ($timeZone == 'Indian/Mahe') {
        $timeSet = '+04:00';
    } elseif ($timeZone == 'Indian/Mauritius') {
        $timeSet = '+04:00';
    } elseif ($timeZone == 'Indian/Reunion') {
        $timeSet = '+04:00';
    } elseif ($timeZone == 'Asia/Kabul') {
        $timeSet = '+04:30';
    } elseif ($timeZone == 'Asia/Tehran') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+03:30';
        } else {
            $timeSet = '+04:30';
        }
    } elseif ($timeZone == 'Antarctica/Mawson') {
        $timeSet = '+05:00';
    } elseif ($timeZone == 'Asia/Aqtau') {
        $timeSet = '+05:00';
    } elseif ($timeZone == 'Asia/Aqtobe') {
        $timeSet = '+05:00';
    } elseif ($timeZone == 'Asia/Ashgabat') {
        $timeSet = '+05:00';
    } elseif ($timeZone == 'Asia/Atyrau') {
        $timeSet = '+05:00';
    } elseif ($timeZone == 'Asia/Dushanbe') {
        $timeSet = '+05:00';
    } elseif ($timeZone == 'Asia/Karachi') {
        $timeSet = '+05:00';
    } elseif ($timeZone == 'Asia/Oral') {
        $timeSet = '+05:00';
    } elseif ($timeZone == 'Asia/Samarkand') {
        $timeSet = '+05:00';
    } elseif ($timeZone == 'Asia/Tashkent') {
        $timeSet = '+05:00';
    } elseif ($timeZone == 'Asia/Yekaterinburg') {
        $timeSet = '+05:00';
    } elseif ($timeZone == 'Indian/Kerguelen') {
        $timeSet = '+05:00';
    } elseif ($timeZone == 'Indian/Maldives') {
        $timeSet = '+05:00';
    } elseif ($timeZone == 'Asia/Colombo') {
        $timeSet = '+05:30';
    } elseif ($timeZone == 'Asia/Kolkata') {
        $timeSet = '+05:30';
    } elseif ($timeZone == 'Asia/Kathmandu') {
        $timeSet = '+05:45';
    } elseif ($timeZone == 'Antarctica/Vostok') {
        $timeSet = '+06:00';
    } elseif ($timeZone == 'Asia/Almaty') {
        $timeSet = '+06:00';
    } elseif ($timeZone == 'Asia/Bishkek') {
        $timeSet = '+06:00';
    } elseif ($timeZone == 'Asia/Dhaka') {
        $timeSet = '+06:00';
    } elseif ($timeZone == 'Asia/Omsk') {
        $timeSet = '+06:00';
    } elseif ($timeZone == 'Asia/Qyzylorda') {
        $timeSet = '+05:00';
    } elseif ($timeZone == 'Asia/Thimphu') {
        $timeSet = '+06:00';
    } elseif ($timeZone == 'Asia/Urumqi') {
        $timeSet = '+06:00';
    } elseif ($timeZone == 'Indian/Chagos') {
        $timeSet = '+06:00';
    } elseif ($timeZone == 'Asia/Yangon') {
        $timeSet = '+06:30';
    } elseif ($timeZone == 'Indian/Cocos') {
        $timeSet = '+06:30';
    } elseif ($timeZone == 'Antarctica/Davis') {
        $timeSet = '+07:00';
    } elseif ($timeZone == 'Asia/Bangkok') {
        $timeSet = '+07:00';
    } elseif ($timeZone == 'Asia/Barnaul') {
        $timeSet = '+07:00';
    } elseif ($timeZone == 'Asia/Ho_Chi_Minh') {
        $timeSet = '+07:00';
    } elseif ($timeZone == 'Asia/Jakarta') {
        $timeSet = '+07:00';
    } elseif ($timeZone == 'Asia/Krasnoyarsk') {
        $timeSet = '+07:00';
    } elseif ($timeZone == 'Asia/Novokuznetsk') {
        $timeSet = '+07:00';
    } elseif ($timeZone == 'Asia/Novosibirsk') {
        $timeSet = '+07:00';
    } elseif ($timeZone == 'Asia/Phnom_Penh') {
        $timeSet = '+07:00';
    } elseif ($timeZone == 'Asia/Pontianak') {
        $timeSet = '+07:00';
    } elseif ($timeZone == 'Asia/Tomsk') {
        $timeSet = '+07:00';
    } elseif ($timeZone == 'Asia/Vientiane') {
        $timeSet = '+07:00';
    } elseif ($timeZone == 'Indian/Christmas') {
        $timeSet = '+07:00';
    } elseif ($timeZone == 'Asia/Brunei') {
        $timeSet = '+08:00';
    } elseif ($timeZone == 'Asia/Hong_Kong') {
        $timeSet = '+08:00';
    } elseif ($timeZone == 'Asia/Hovd') {
        $timeSet = '+07:00';
    } elseif ($timeZone == 'Asia/Irkutsk') {
        $timeSet = '+08:00';
    } elseif ($timeZone == 'Asia/Kuala_Lumpur') {
        $timeSet = '+08:00';
    } elseif ($timeZone == 'Asia/Kuching') {
        $timeSet = '+08:00';
    } elseif ($timeZone == 'Asia/Macau') {
        $timeSet = '+08:00';
    } elseif ($timeZone == 'Asia/Makassar') {
        $timeSet = '+08:00';
    } elseif ($timeZone == 'Asia/Manila') {
        $timeSet = '+08:00';
    } elseif ($timeZone == 'Asia/Shanghai') {
        $timeSet = '+08:00';
    } elseif ($timeZone == 'Asia/Singapore') {
        $timeSet = '+08:00';
    } elseif ($timeZone == 'Asia/Taipei') {
        $timeSet = '+08:00';
    } elseif ($timeZone == 'Australia/Perth') {
        $timeSet = '+08:00';
    } elseif ($timeZone == 'Asia/Pyongyang') {
        $timeSet = '+09:00';
    } elseif ($timeZone == 'Australia/Eucla') {
        $timeSet = '+08:45';
    } elseif ($timeZone == 'Asia/Chita') {
        $timeSet = '+09:00';
    } elseif ($timeZone == 'Asia/Choibalsan') {
        $timeSet = '+09:00';
    } elseif ($timeZone == 'Asia/Dili') {
        $timeSet = '+09:00';
    } elseif ($timeZone == 'Asia/Jayapura') {
        $timeSet = '+09:00';
    } elseif ($timeZone == 'Asia/Khandyga') {
        $timeSet = '+09:00';
    } elseif ($timeZone == 'Asia/Seoul') {
        $timeSet = '+09:00';
    } elseif ($timeZone == 'Asia/Tokyo') {
        $timeSet = '+09:00';
    } elseif ($timeZone == 'Asia/Ulaanbaatar') {
        $timeSet = '+08:00';
    } elseif ($timeZone == 'Asia/Yakutsk') {
        $timeSet = '+09:00';
    } elseif ($timeZone == 'Pacific/Palau') {
        $timeSet = '+09:00';
    } elseif ($timeZone == 'Australia/Adelaide') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+09:30';
        } else {
            $timeSet = '+10:30';
        }
    } elseif ($timeZone == 'Australia/Broken_Hill') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+09:30';
        } else {
            $timeSet = '+10:30';
        }
    } elseif ($timeZone == 'Australia/Darwin') {
        $timeSet = '+09:30';
    } elseif ($timeZone == 'Antarctica/DumontDUrville') {
        $timeSet = '+10:00';
    } elseif ($timeZone == 'Asia/Ust-Nera') {
        $timeSet = '+10:00';
    } elseif ($timeZone == 'Asia/Vladivostok') {
        $timeSet = '+10:00';
    } elseif ($timeZone == 'Australia/Brisbane') {
        $timeSet = '+10:00';
    } elseif ($timeZone == 'Australia/Currie') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+10:00';
        } else {
            $timeSet = '+11:00';
        }
    } elseif ($timeZone == 'Australia/Hobart') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+10:00';
        } else {
            $timeSet = '+11:00';
        }
    } elseif ($timeZone == 'Australia/Lindeman') {
        $timeSet = '+10:00';
    } elseif ($timeZone == 'Australia/Melbourne') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+10:00';
        } else {
            $timeSet = '+11:00';
        }
    } elseif ($timeZone == 'Australia/Sydney') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+10:00';
        } else {
            $timeSet = '+11:00';
        }
    } elseif ($timeZone == 'Pacific/Chuuk') {
        $timeSet = '+10:00';
    } elseif ($timeZone == 'Pacific/Guam') {
        $timeSet = '+10:00';
    } elseif ($timeZone == 'Pacific/Port_Moresby') {
        $timeSet = '+10:00';
    } elseif ($timeZone == 'Pacific/Saipan') {
        $timeSet = '+10:00';
    } elseif ($timeZone == 'Australia/Lord_Howe') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+10:30';
        } else {
            $timeSet = '+11:30';
        }
    } elseif ($timeZone == 'Antarctica/Casey') {
        $timeSet = '+11:00';
    } elseif ($timeZone == 'Antarctica/Macquarie') {
        $timeSet = '+11:00';
    } elseif ($timeZone == 'Asia/Magadan') {
        $timeSet = '+11:00';
    } elseif ($timeZone == 'Asia/Sakhalin') {
        $timeSet = '+11:00';
    } elseif ($timeZone == 'Asia/Srednekolymsk') {
        $timeSet = '+11:00';
    } elseif ($timeZone == 'Pacific/Bougainville') {
        $timeSet = '+11:00';
    } elseif ($timeZone == 'Pacific/Efate') {
        $timeSet = '+11:00';
    } elseif ($timeZone == 'Pacific/Guadalcanal') {
        $timeSet = '+11:00';
    } elseif ($timeZone == 'Pacific/Kosrae') {
        $timeSet = '+11:00';
    } elseif ($timeZone == 'Pacific/Norfolk') {
        $timeSet = '+11:00';
    } elseif ($timeZone == 'Pacific/Noumea') {
        $timeSet = '+11:00';
    } elseif ($timeZone == 'Pacific/Pohnpei') {
        $timeSet = '+11:00';
    } elseif ($timeZone == 'Antarctica/McMurdo') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+12:00';
        } else {
            $timeSet = '+13:00';
        }
    } elseif ($timeZone == 'Asia/Anadyr') {
        $timeSet = '+12:00';
    } elseif ($timeZone == 'Asia/Kamchatka') {
        $timeSet = '+12:00';
    } elseif ($timeZone == 'Pacific/Auckland') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+12:00';
        } else {
            $timeSet = '+13:00';
        }
    } elseif ($timeZone == 'Pacific/Fiji') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+12:00';
        } else {
            $timeSet = '+13:00';
        }
    } elseif ($timeZone == 'Pacific/Funafuti') {
        $timeSet = '+12:00';
    } elseif ($timeZone == 'Pacific/Kwajalein') {
        $timeSet = '+12:00';
    } elseif ($timeZone == 'Pacific/Majuro') {
        $timeSet = '+12:00';
    } elseif ($timeZone == 'Pacific/Nauru') {
        $timeSet = '+12:00';
    } elseif ($timeZone == 'Pacific/Tarawa') {
        $timeSet = '+12:00';
    } elseif ($timeZone == 'Pacific/Wake') {
        $timeSet = '+12:00';
    } elseif ($timeZone == 'Pacific/Wallis') {
        $timeSet = '+12:00';
    } elseif ($timeZone == 'Pacific/Chatham') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+12:45';
        } else {
            $timeSet = '+13:45';
        }
    } elseif ($timeZone == 'Pacific/Apia') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+13:00';
        } else {
            $timeSet = '+14:00';
        }
    } elseif ($timeZone == 'Pacific/Enderbury') {
        $timeSet = '+13:00';
    } elseif ($timeZone == 'Pacific/Fakaofo') {
        $timeSet = '+13:00';
    } elseif ($timeZone == 'Pacific/Tongatapu') {
        if (timezoneIsDST($timeZone)) {
            $timeSet = '+13:00';
        } else {
            $timeSet = '+14:00';
        }
    } elseif ($timeZone == 'Pacific/Kiritimati') {
        $timeSet = '+14:00';
    }

    return $timeSet;
}

function get_starred_contact($str)
{
    if ($str != '') {
        $str = str_replace(' ', '', $str);
        $len = strlen($str);

        return substr($str, 0, 1).str_repeat('X', $len - 2).substr($str, $len - 1, 1);
    }
}

function nonReadTexts($str)
{
    if ($str != '') {
        $str = str_replace(' ', '', $str);
        $len = strlen($str);

        return substr($str, 0, 1).str_repeat('X', $len - 2).substr($str, $len - 1, 1);
    }
}

function get_starred_email($str)
{
    if ($str != '') {

        $email = explode('@', $str);

        $completeString = '';
        if (isset($email[0])) {
            $completeString = get_starred_email_format($email[0]);
        }

        if (isset($email[1])) {
            $completeString .= '@';
            $emailDomain = explode('.', $email[1]);
            if (isset($emailDomain[0])) {
                $completeString .= get_starred_email_format($emailDomain[0]);
            }

            if (isset($emailDomain[1])) {
                $completeString .= '.'.$emailDomain[1];
            }
        }

        return $completeString;
    }
}

function passwordTexts($str)
{
    if ($str != '') {
        $str = str_replace(' ', '', $str);
        $len = strlen($str);

        return 'x'.str_repeat('x', $len - 2).'x';
    }
}

function get_starred_email_format($str)
{
    if ($str != '') {
        $len = strlen($str);

        return substr($str, 0, 1).str_repeat('x', $len - 2).substr($str, $len - 1, 1);
    }
}

function getStarredString($str)
{
    if ($str != '') {
        $len = strlen($str);

        return substr($str, 0, 1).str_repeat('X', $len - 2).substr($str, $len - 1, 1);
    }
}

function getUserClientIpAddr()
{
    $ip = '';
    /* if(isset($_SERVER['HTTP_CLIENT_IP']) and !empty($_SERVER['HTTP_CLIENT_IP'])){
         //ip from share internet
         $ip = $_SERVER['HTTP_CLIENT_IP'];
     }elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR']) and !empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
         //ip pass from proxy
         $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
     }elseif(isset($_SERVER['REMOTE_ADDR'])){
         $ip = $_SERVER['REMOTE_ADDR'];
     }*/

    if (isset($_SERVER['HTTP_CLIENT_IP']) and ! empty($_SERVER['HTTP_CLIENT_IP']) && validate_ip($_SERVER['HTTP_CLIENT_IP'])) {
        return $_SERVER['HTTP_CLIENT_IP'];
    }

    // check for IPs passing through proxies
    if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) and ! empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        // check if multiple ips exist in var
        if (strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ',') !== false) {
            $iplist = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
            foreach ($iplist as $ip) {
                if (validate_ip($ip)) {
                    return $ip;
                }
            }
        } else {
            if (validate_ip($_SERVER['HTTP_X_FORWARDED_FOR'])) {
                return $_SERVER['HTTP_X_FORWARDED_FOR'];
            }
        }
    }
    if (isset($_SERVER['HTTP_X_FORWARDED']) and ! empty($_SERVER['HTTP_X_FORWARDED']) && validate_ip($_SERVER['HTTP_X_FORWARDED'])) {
        return $_SERVER['HTTP_X_FORWARDED'];
    }
    if (isset($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) and ! empty($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && validate_ip($_SERVER['HTTP_X_CLUSTER_CLIENT_IP'])) {
        return $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'];
    }
    if (isset($_SERVER['HTTP_FORWARDED_FOR']) and ! empty($_SERVER['HTTP_FORWARDED_FOR']) && validate_ip($_SERVER['HTTP_FORWARDED_FOR'])) {
        return $_SERVER['HTTP_FORWARDED_FOR'];
    }
    if (isset($_SERVER['HTTP_FORWARDED']) and ! empty($_SERVER['HTTP_FORWARDED']) && validate_ip($_SERVER['HTTP_FORWARDED'])) {
        return $_SERVER['HTTP_FORWARDED'];
    }

    // return unreliable ip since all else failed
    if (isset($_SERVER['REMOTE_ADDR'])) {
        return $_SERVER['REMOTE_ADDR'];
    }

    return $ip;
}

function getUserIpAddr()
{
    // check for shared internet/ISP IP
    if (! empty($_SERVER['HTTP_CLIENT_IP']) && validate_ip($_SERVER['HTTP_CLIENT_IP'])) {
        return $_SERVER['HTTP_CLIENT_IP'];
    }

    // check for IPs passing through proxies
    if (! empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        // check if multiple ips exist in var
        if (strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ',') !== false) {
            $iplist = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
            foreach ($iplist as $ip) {
                if (validate_ip($ip)) {
                    return $ip;
                }
            }
        } else {
            if (validate_ip($_SERVER['HTTP_X_FORWARDED_FOR'])) {
                return $_SERVER['HTTP_X_FORWARDED_FOR'];
            }
        }
    }
    if (! empty($_SERVER['HTTP_X_FORWARDED']) && validate_ip($_SERVER['HTTP_X_FORWARDED'])) {
        return $_SERVER['HTTP_X_FORWARDED'];
    }
    if (! empty($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && validate_ip($_SERVER['HTTP_X_CLUSTER_CLIENT_IP'])) {
        return $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'];
    }
    if (! empty($_SERVER['HTTP_FORWARDED_FOR']) && validate_ip($_SERVER['HTTP_FORWARDED_FOR'])) {
        return $_SERVER['HTTP_FORWARDED_FOR'];
    }
    if (! empty($_SERVER['HTTP_FORWARDED']) && validate_ip($_SERVER['HTTP_FORWARDED'])) {
        return $_SERVER['HTTP_FORWARDED'];
    }

    // return unreliable ip since all else failed
    return $_SERVER['REMOTE_ADDR'];
}

/**
 * Ensures an ip address is both a valid IP and does not fall within
 * a private network range.
 */
function validate_ip($ip)
{
    if (strtolower($ip) === 'unknown') {
        return false;
    }

    // generate ipv4 network address
    $ip = ip2long($ip);

    // if the ip is set and not equivalent to 255.255.255.255
    if ($ip !== false && $ip !== -1) {
        // make sure to get unsigned long representation of ip
        // due to discrepancies between 32 and 64 bit OSes and
        // signed numbers (ints default to signed in PHP)
        $ip = sprintf('%u', $ip);
        // do private network range checking
        if ($ip >= 0 && $ip <= 50331647) {
            return false;
        }
        if ($ip >= 167772160 && $ip <= 184549375) {
            return false;
        }
        if ($ip >= 2130706432 && $ip <= 2147483647) {
            return false;
        }
        if ($ip >= 2851995648 && $ip <= 2852061183) {
            return false;
        }
        if ($ip >= 2886729728 && $ip <= 2887778303) {
            return false;
        }
        if ($ip >= 3221225984 && $ip <= 3221226239) {
            return false;
        }
        if ($ip >= 3232235520 && $ip <= 3232301055) {
            return false;
        }
        if ($ip >= 4294967040) {
            return false;
        }
    }

    return true;
}

function convertPdfToJpg($pdfFilePath, $folder)
{
    $uploadfile = $pdfFilePath;
    $filePath = $folder;
    $im = new imagick($uploadfile);
    $pages = $im->getNumberImages();
    $im->clear();
    $im->destroy();

    $resolution = '300';
    $imagick = new imagick;
    $imagick->setResolution($resolution, $resolution);
    $imagick->readImage($uploadfile);
    $imagick->setImageFormat('jpg');
    $page = 1;

    $fileNameArray = '';
    foreach ($imagick as $i => $imagick) {
        $newname = hash('crc32', time());
        $fileImage = $filePath.$newname.'_'.$page.'.jpg';
        $imagick->writeImage($fileImage);
        if ($fileNameArray) {
            $fileNameArray = $fileNameArray.','.$fileImage;
        } else {
            $fileNameArray = $fileImage;
        }
        $page++;
    }
    $imagick->clear();
    $imagick->destroy();

    return $fileNameArray;
}

function sendPushNotifiation($headings, $content, $url, $notificationKeys)
{
    $headings = [
        'en' => $headings,
    ];

    $content = [
        'en' => $content,
    ];

    $fields = [
        'app_id' => '70f75ce6-0e6e-48ca-95b5-bca47c85737e',
        // 'included_segments' => array('Active Users'),
        // 'include_player_ids' => array("6900fbfc-4566-4281-a90c-2c2b04e85dfa"),
        'include_player_ids' => $notificationKeys,
        'data' => ['foo' => 'bar'],
        'headings' => $headings, // Title of your website
        'contents' => $content, // the message
        'url' => $url,
    ];

    $fields = json_encode($fields);

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://onesignal.com/api/v1/notifications');
    curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json; charset=utf-8',
        'Authorization: Basic ZDg1NTZlZGMtMDYwNi00YjUzLTkyODItYTJmMTA1ZjQ4YzZm']);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    $response = curl_exec($ch);
    curl_close($ch);

    return $response;
}

function get_words($sentence, $count = 10)
{
    $sentence = trim($sentence);
    preg_match("/(?:\w+(?:\W+|$)){0,$count}/", $sentence, $matches);

    return $matches[0];
}

function DownloadAnything($file, $newfilename = '', $mimetype = '', $isremotefile = false)
{

    $formattedhpath = '';
    $filesize = '';

    if (empty($file)) {
        exit('Please enter file url to download...!');
        exit;
    }
    // Removing spaces and replacing with %20 ascii code
    $file = RemoveUrlSpaces($file);

    if (preg_match('#https://#', $file) || preg_match('#http://#', $file)) {
        $formattedhpath = 'url';
    } else {
        $formattedhpath = 'filepath';
    }

    if ($formattedhpath == 'url') {
        $file_headers = @get_headers($file);
        if ($file_headers[0] == 'HTTP/1.1 404 Not Found') {
            exit('File is not readable or not found...!');
            exit;
        }
    } elseif ($formattedhpath == 'filepath') {
        if (!@is_readable($file)) {
            exit('File is not readable or not found...!');
            exit;
        }
    }

    // Fetching File Size Located in Remote Server
    if ($isremotefile && $formattedhpath == 'url') {

        $data = @get_headers($file, true);

        if (! empty($data['Content-Length'])) {
            $filesize = (int) $data['Content-Length'];

        } else {
            // /If get_headers fails then try to fetch filesize with curl
            $ch = @curl_init();

            if (!$ch || !@curl_setopt($ch, CURLOPT_URL, $file)) {
                if ($ch) @curl_close($ch);
                exit('Unable to initialize curl for file download...!');
            }

            @curl_setopt($ch, CURLOPT_NOBODY, true);
            @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            @curl_setopt($ch, CURLOPT_HEADER, true);
            @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
            @curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
            @curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
            @curl_exec($ch);

            if (! @curl_errno($ch)) {

                $http_status = (int) @curl_getinfo($ch, CURLINFO_HTTP_CODE);
                if ($http_status >= 200 && $http_status <= 300) {
                    $filesize = (int) @curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
                }

            }
            @curl_close($ch);
        }

    } elseif ($isremotefile && $formattedhpath == 'filepath') {

        exit('Error : Need complete URL of remote file...!');
        exit;
    } else {
        if ($formattedhpath == 'url') {
            $data = @get_headers($file, true);
            $filesize = (int) $data['Content-Length'];

        } elseif ($formattedhpath == 'filepath') {
            $filesize = (int) @filesize($file);
        }
    }

    if (empty($newfilename)) {
        $newfilename = @basename($file);
    } else {
        // Replacing any spaces with (-) hypen
        $newfilename = RemoveSpaces($newfilename);
    }

    if (empty($mimetype)) {

        // /Get the extension of the file
        $path_parts = @pathinfo($file);
        $myfileextension = $path_parts['extension'];

        switch ($myfileextension) {

            // /Image Mime Types
            case 'jpg':
                $mimetype = 'image/jpg';
                break;
            case 'jpeg':
                $mimetype = 'image/jpeg';
                break;
            case 'gif':
                $mimetype = 'image/gif';
                break;
            case 'png':
                $mimetype = 'image/png';
                break;
            case 'bm':
                $mimetype = 'image/bmp';
                break;
            case 'bmp':
                $mimetype = 'image/bmp';
                break;
            case 'art':
                $mimetype = 'image/x-jg';
                break;
            case 'dwg':
                $mimetype = 'image/x-dwg';
                break;
            case 'dxf':
                $mimetype = 'image/x-dwg';
                break;
            case 'flo':
                $mimetype = 'image/florian';
                break;
            case 'fpx':
                $mimetype = 'image/vnd.fpx';
                break;
            case 'g3':
                $mimetype = 'image/g3fax';
                break;
            case 'ief':
                $mimetype = 'image/ief';
                break;
            case 'jfif':
                $mimetype = 'image/pjpeg';
                break;
            case 'jfif-tbnl':
                $mimetype = 'image/jpeg';
                break;
            case 'jpe':
                $mimetype = 'image/pjpeg';
                break;
            case 'jps':
                $mimetype = 'image/x-jps';
                break;
            case 'jut':
                $mimetype = 'image/jutvision';
                break;
            case 'mcf':
                $mimetype = 'image/vasa';
                break;
            case 'nap':
                $mimetype = 'image/naplps';
                break;
            case 'naplps':
                $mimetype = 'image/naplps';
                break;
            case 'nif':
                $mimetype = 'image/x-niff';
                break;
            case 'niff':
                $mimetype = 'image/x-niff';
                break;
            case 'cod':
                $mimetype = 'image/cis-cod';
                break;
            case 'ief':
                $mimetype = 'image/ief';
                break;
            case 'svg':
                $mimetype = 'image/svg+xml';
                break;
            case 'tif':
                $mimetype = 'image/tiff';
                break;
            case 'tiff':
                $mimetype = 'image/tiff';
                break;
            case 'ras':
                $mimetype = 'image/x-cmu-raster';
                break;
            case 'cmx':
                $mimetype = 'image/x-cmx';
                break;
            case 'ico':
                $mimetype = 'image/x-icon';
                break;
            case 'pnm':
                $mimetype = 'image/x-portable-anymap';
                break;
            case 'pbm':
                $mimetype = 'image/x-portable-bitmap';
                break;
            case 'pgm':
                $mimetype = 'image/x-portable-graymap';
                break;
            case 'ppm':
                $mimetype = 'image/x-portable-pixmap';
                break;
            case 'rgb':
                $mimetype = 'image/x-rgb';
                break;
            case 'xbm':
                $mimetype = 'image/x-xbitmap';
                break;
            case 'xpm':
                $mimetype = 'image/x-xpixmap';
                break;
            case 'xwd':
                $mimetype = 'image/x-xwindowdump';
                break;
            case 'rgb':
                $mimetype = 'image/x-rgb';
                break;
            case 'xbm':
                $mimetype = 'image/x-xbitmap';
                break;
            case 'wbmp':
                $mimetype = 'image/vnd.wap.wbmp';
                break;

                // Files MIME Types

            case 'css':
                $mimetype = 'text/css';
                break;
            case 'htm':
                $mimetype = 'text/html';
                break;
            case 'html':
                $mimetype = 'text/html';
                break;
            case 'stm':
                $mimetype = 'text/html';
                break;
            case 'c':
                $mimetype = 'text/plain';
                break;
            case 'h':
                $mimetype = 'text/plain';
                break;
            case 'txt':
                $mimetype = 'text/plain';
                break;
            case 'rtx':
                $mimetype = 'text/richtext';
                break;
            case 'htc':
                $mimetype = 'text/x-component';
                break;
            case 'vcf':
                $mimetype = 'text/x-vcard';
                break;

                // Applications MIME Types

            case 'doc':
                $mimetype = 'application/msword';
                break;
            case 'xls':
                $mimetype = 'application/vnd.ms-excel';
                break;
            case 'ppt':
                $mimetype = 'application/vnd.ms-powerpoint';
                break;
            case 'pps':
                $mimetype = 'application/vnd.ms-powerpoint';
                break;
            case 'pot':
                $mimetype = 'application/vnd.ms-powerpoint';
                break;

            case 'ogg':
                $mimetype = 'application/ogg';
                break;
            case 'pls':
                $mimetype = 'application/pls+xml';
                break;
            case 'asf':
                $mimetype = 'application/vnd.ms-asf';
                break;
            case 'wmlc':
                $mimetype = 'application/vnd.wap.wmlc';
                break;
            case 'dot':
                $mimetype = 'application/msword';
                break;
            case 'class':
                $mimetype = 'application/octet-stream';
                break;
            case 'exe':
                $mimetype = 'application/octet-stream';
                break;
            case 'pdf':
                $mimetype = 'application/pdf';
                break;
            case 'rtf':
                $mimetype = 'application/rtf';
                break;
            case 'xla':
                $mimetype = 'application/vnd.ms-excel';
                break;
            case 'xlc':
                $mimetype = 'application/vnd.ms-excel';
                break;
            case 'xlm':
                $mimetype = 'application/vnd.ms-excel';
                break;

            case 'msg':
                $mimetype = 'application/vnd.ms-outlook';
                break;
            case 'mpp':
                $mimetype = 'application/vnd.ms-project';
                break;
            case 'cdf':
                $mimetype = 'application/x-cdf';
                break;
            case 'tgz':
                $mimetype = 'application/x-compressed';
                break;
            case 'dir':
                $mimetype = 'application/x-director';
                break;
            case 'dvi':
                $mimetype = 'application/x-dvi';
                break;
            case 'gz':
                $mimetype = 'application/x-gzip';
                break;
            case 'js':
                $mimetype = 'application/x-javascript';
                break;
            case 'mdb':
                $mimetype = 'application/x-msaccess';
                break;
            case 'dll':
                $mimetype = 'application/x-msdownload';
                break;
            case 'wri':
                $mimetype = 'application/x-mswrite';
                break;
            case 'cdf':
                $mimetype = 'application/x-netcdf';
                break;
            case 'swf':
                $mimetype = 'application/x-shockwave-flash';
                break;
            case 'tar':
                $mimetype = 'application/x-tar';
                break;
            case 'man':
                $mimetype = 'application/x-troff-man';
                break;
            case 'zip':
                $mimetype = 'application/zip';
                break;
            case 'xlsx':
                $mimetype = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
                break;
            case 'pptx':
                $mimetype = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
                break;
            case 'docx':
                $mimetype = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
                break;
            case 'xltx':
                $mimetype = 'application/vnd.openxmlformats-officedocument.spreadsheetml.template';
                break;
            case 'potx':
                $mimetype = 'application/vnd.openxmlformats-officedocument.presentationml.template';
                break;
            case 'ppsx':
                $mimetype = 'application/vnd.openxmlformats-officedocument.presentationml.slideshow';
                break;
            case 'sldx':
                $mimetype = 'application/vnd.openxmlformats-officedocument.presentationml.slide';
                break;

                // /Audio and Video Files

            case 'mp3':
                $mimetype = 'audio/mpeg';
                break;
            case 'wav':
                $mimetype = 'audio/x-wav';
                break;
            case 'au':
                $mimetype = 'audio/basic';
                break;
            case 'snd':
                $mimetype = 'audio/basic';
                break;
            case 'm3u':
                $mimetype = 'audio/x-mpegurl';
                break;
            case 'ra':
                $mimetype = 'audio/x-pn-realaudio';
                break;
            case 'mp2':
                $mimetype = 'video/mpeg';
                break;
            case 'mov':
                $mimetype = 'video/quicktime';
                break;
            case 'qt':
                $mimetype = 'video/quicktime';
                break;
            case 'mp4':
                $mimetype = 'video/mp4';
                break;
            case 'm4a':
                $mimetype = 'audio/mp4';
                break;
            case 'mp4a':
                $mimetype = 'audio/mp4';
                break;
            case 'm4p':
                $mimetype = 'audio/mp4';
                break;
            case 'm3a':
                $mimetype = 'audio/mpeg';
                break;
            case 'm2a':
                $mimetype = 'audio/mpeg';
                break;
            case 'mp2a':
                $mimetype = 'audio/mpeg';
                break;
            case 'mp2':
                $mimetype = 'audio/mpeg';
                break;
            case 'mpga':
                $mimetype = 'audio/mpeg';
                break;
            case '3gp':
                $mimetype = 'video/3gpp';
                break;
            case '3g2':
                $mimetype = 'video/3gpp2';
                break;
            case 'mp4v':
                $mimetype = 'video/mp4';
                break;
            case 'mpg4':
                $mimetype = 'video/mp4';
                break;
            case 'm2v':
                $mimetype = 'video/mpeg';
                break;
            case 'm1v':
                $mimetype = 'video/mpeg';
                break;
            case 'mpe':
                $mimetype = 'video/mpeg';
                break;
            case 'avi':
                $mimetype = 'video/x-msvideo';
                break;
            case 'midi':
                $mimetype = 'audio/midi';
                break;
            case 'mid':
                $mimetype = 'audio/mid';
                break;
            case 'amr':
                $mimetype = 'audio/amr';
                break;
            default:
                $mimetype = 'application/octet-stream';
        }
    }

    // off output buffering to decrease Server usage
    @ob_end_clean();

    if (ini_get('zlib.output_compression')) {
        ini_set('zlib.output_compression', 'Off');
    }

    header('Content-Description: File Transfer');
    header('Content-Type: '.$mimetype);
    header('Content-Disposition: attachment; filename='.$newfilename.'');
    header('Content-Transfer-Encoding: binary');
    header('Expires: Wed, 07 May 2013 09:09:09 GMT');
    header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
    header('Cache-Control: post-check=0, pre-check=0', false);
    header('Cache-Control: no-store, no-cache, must-revalidate');
    header('Pragma: no-cache');
    header('Content-Length: '.$filesize);

    // /Will Download 1 MB in chunkwise
    $chunk = 1 * (1024 * 1024);
    $nfile = @fopen($file, 'rb');
    
    // Check if file opened successfully
    if ($nfile === false || $nfile === null) {
        exit('Unable to open file for download...!');
    }
    
    while (! feof($nfile)) {
        echo @fread($nfile, $chunk);
        @ob_flush();
        @flush();
    }
    @fclose($nfile);
}

function RemoveUrlSpaces($url)
{
    $url = preg_replace('/\s+/', '%20', trim($url));
    $url = str_replace('         ', '%20', $url);
    $url = str_replace('        ', '%20', $url);
    $url = str_replace('       ', '%20', $url);
    $url = str_replace('      ', '%20', $url);
    $url = str_replace('     ', '%20', $url);
    $url = str_replace('    ', '%20', $url);
    $url = str_replace('   ', '%20', $url);
    $url = str_replace('  ', '%20', $url);
    $url = str_replace(' ', '%20', $url);

    return $url;
}

function RemoveSpaces($url)
{
    $url = preg_replace('/\s+/', '-', trim($url));
    $url = str_replace('         ', '-', $url);
    $url = str_replace('        ', '-', $url);
    $url = str_replace('       ', '-', $url);
    $url = str_replace('      ', '-', $url);
    $url = str_replace('     ', '-', $url);
    $url = str_replace('    ', '-', $url);
    $url = str_replace('   ', '-', $url);
    $url = str_replace('  ', '-', $url);
    $url = str_replace(' ', '-', $url);

    return $url;
}

function getStateFullName($code)
{
    $state = $code;
    if ($code == 'AL') {
        $state = 'Alabama';
    } elseif ($code == 'AK') {
        $state = 'Alaska';
    } elseif ($code == 'AZ') {
        $state = 'Arizona';
    } elseif ($code == 'AR') {
        $state = 'Arkansas';
    } elseif ($code == 'AA') {
        $state = 'Armed Forces America';
    } elseif ($code == 'AE') {
        $state = 'Armed Forces Europe';
    } elseif ($code == 'AP') {
        $state = 'Armed Forces Pacific';
    } elseif ($code == 'CA') {
        $state = 'California';
    } elseif ($code == 'CO') {
        $state = 'Colorado';
    } elseif ($code == 'CT') {
        $state = 'Connecticut';
    } elseif ($code == 'DE') {
        $state = 'Delaware';
    } elseif ($code == 'DC') {
        $state = 'District of Columbia';
    } elseif ($code == 'FL') {
        $state = 'Florida';
    } elseif ($code == 'GA') {
        $state = 'Georgia';
    } elseif ($code == 'HI') {
        $state = 'Hawaii';
    } elseif ($code == 'ID') {
        $state = 'Idaho';
    } elseif ($code == 'IL') {
        $state = 'Illinois';
    } elseif ($code == 'IN') {
        $state = 'Indiana';
    } elseif ($code == 'IA') {
        $state = 'Iowa';
    } elseif ($code == 'KS') {
        $state = 'Kansas';
    } elseif ($code == 'KY') {
        $state = 'Kentucky';
    } elseif ($code == 'LA') {
        $state = 'Louisiana';
    } elseif ($code == 'ME') {
        $state = 'Maine';
    } elseif ($code == 'MD') {
        $state = 'Maryland';
    } elseif ($code == 'MA') {
        $state = 'Massachusetts';
    } elseif ($code == 'MI') {
        $state = 'Michigan';
    } elseif ($code == 'MN') {
        $state = 'Minnesota';
    } elseif ($code == 'MS') {
        $state = 'Mississippi';
    } elseif ($code == 'MO') {
        $state = 'Missouri';
    } elseif ($code == 'MT') {
        $state = 'Montana';
    } elseif ($code == 'NE') {
        $state = 'Nebraska';
    } elseif ($code == 'NV') {
        $state = 'Nevada';
    } elseif ($code == 'NH') {
        $state = 'New Hampshire';
    } elseif ($code == 'NJ') {
        $state = 'New Jersey';
    } elseif ($code == 'NM') {
        $state = 'New Mexico';
    } elseif ($code == 'NY') {
        $state = 'New York';
    } elseif ($code == 'NC') {
        $state = 'North Carolina';
    } elseif ($code == 'ND') {
        $state = 'North Dakota';
    } elseif ($code == 'Ohio') {
        $state = 'OH';
    } elseif ($code == 'OK') {
        $state = 'Oklahoma';
    } elseif ($code == 'OR') {
        $state = 'Oregon';
    } elseif ($code == 'PA') {
        $state = 'Pennsylvania';
    } elseif ($code == 'RI') {
        $state = 'Rhode Island';
    } elseif ($code == 'SC') {
        $state = 'South Carolina';
    } elseif ($code == 'SD') {
        $state = 'South Dakota';
    } elseif ($code == 'TN') {
        $state = 'Tennessee';
    } elseif ($code == 'TX') {
        $state = 'Texas';
    } elseif ($code == 'UT') {
        $state = 'Utah';
    } elseif ($code == 'VT') {
        $state = 'Vermont';
    } elseif ($code == 'VA') {
        $state = 'Virginia';
    } elseif ($code == 'WA') {
        $state = 'Washington';
    } elseif ($code == 'WV') {
        $state = 'West Virginia';
    } elseif ($code == 'WI') {
        $state = 'Wisconsin';
    } elseif ($code == 'WY') {
        $state = 'Wyoming';
    } elseif ($code == 'AB') {
        $state = 'Alberta';
    } elseif ($code == 'BC') {
        $state = 'British Columbia';
    } elseif ($code == 'MB') {
        $state = 'Manitoba';
    } elseif ($code == 'NB') {
        $state = 'New Brunswick';
    } elseif ($code == 'NL') {
        $state = 'Newfoundland and Labrador';
    } elseif ($code == 'NT') {
        $state = 'Northwest Territories';
    } elseif ($code == 'NS') {
        $state = 'Nova Scotia';
    } elseif ($code == 'NU') {
        $state = 'Nunavut';
    } elseif ($code == 'ON') {
        $state = 'Ontario';
    } elseif ($code == 'PE') {
        $state = 'Prince Edward Island';
    } elseif ($code == 'QC') {
        $state = 'Quebec';
    } elseif ($code == 'SK') {
        $state = 'Saskatchewan';
    } elseif ($code == 'YT') {
        $state = 'Yukon';
    }

    return $state;
}

function getDocumentUrl($path)
{
    $file = URL::to($path);
    $CDNRepository = app('App\\Repositories\\CDNRepository');
    if ($CDNRepository->has($path)) {
        $file = $CDNRepository->getLink($path);
    }

    return $file;
}

function convertToNewTimeZone($time, $master_timezone, $user_timezone)
{
    date_default_timezone_set($master_timezone);
    $datetime = new DateTime($time);
    $datetime->format('H:i');
    $la_time = new DateTimeZone($user_timezone);
    $datetime->setTimezone($la_time);

    return $datetime->format('H:i');
}

function convertToNewTimeZoneMaster($time, $master_timezone, $user_timezone)
{
    date_default_timezone_set($master_timezone);
    $datetime = new DateTime($time);
    $datetime->format('h:i A');
    $la_time = new DateTimeZone($user_timezone);
    $datetime->setTimezone($la_time);

    return $datetime->format('h:i A');
}

function convertToNewTimeDateZone($time, $master_timezone, $user_timezone)
{
    date_default_timezone_set($master_timezone);
    $datetime = new DateTime($time);
    $datetime->format('Y-m-d H:i');
    $la_time = new DateTimeZone($user_timezone);
    $datetime->setTimezone($la_time);

    return $datetime->format('Y-m-d H:i');
}

function convertToNewTimeDateZoneMaster($time, $master_timezone, $user_timezone)
{
    date_default_timezone_set($master_timezone);
    $datetime = new DateTime($time);
    $datetime->format('Y-m-d h:i A');
    $la_time = new DateTimeZone($user_timezone);
    $datetime->setTimezone($la_time);

    return $datetime->format('Y-m-d h:i A');
}

function appointmentTimeConvert($time, $master_timezone, $user_timezone)
{
    if ($master_timezone == $user_timezone) {
        return $time;
    } else {
        date_default_timezone_set($master_timezone);
        $time = date('Y-m-d h:i A', strtotime($time));

        $datetime = new DateTime($time);
        $datetime->format('Y-m-d h:i A');
        $la_time = new DateTimeZone($user_timezone);
        $datetime->setTimezone($la_time);

        return $datetime->format('Y-m-d h:i A');
    }
}

function getConvrtedTime($time, $master_timezone)
{
    date_default_timezone_set($master_timezone);
    $datetime = new DateTime($time);

    return $datetime->format('Y-m-d h:i A');
}

function getConvrtedTimeAmPm($time, $master_timezone)
{
    date_default_timezone_set($master_timezone);
    $datetime = new DateTime($time);

    return $datetime->format('Y-m-d H:i A');
}

function convertToNewTimeDateZoneClient($time, $master_timezone, $user_timezone)
{
    date_default_timezone_set($master_timezone);
    $datetime = new DateTime($time);
    $datetime->format('Y-m-d H:i:s');
    $la_time = new DateTimeZone($user_timezone);
    $datetime->setTimezone($la_time);

    return $datetime->format('Y-m-d H:i:s');
}

function getDomain($url)
{
    $pieces = parse_url($url);
    $domain = isset($pieces['host']) ? $pieces['host'] : '';
    if (preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)) {
        return $regs['domain'];
    }

    return false;
}

function eventHtmlBody($htmlMsg)
{
    $temp = str_replace(["\r\n"], "\n", $htmlMsg);
    $lines = explode("\n", $temp);
    $new_lines = [];
    foreach ($lines as $i => $line) {
        if (! empty($line)) {
            $new_lines[] = trim($line);
        }
    }
    $desc = implode("\r\n ", $new_lines);

    return $desc;
}

function generateResumeFullUrl($resume)
{
    if (\Auth::check()) {
        $url = url('/ip/'.$resume->slug);
    } else {
        if ($resume->domain_activated == 1 and $resume->domain_blocked == 0) {
            $result = parse_url(config('app.url'));
            $scheme = 'https://';
            if (isset($result['scheme'])) {
                $scheme = $result['scheme'].'://';
            }
            $url = $scheme.$resume->domain_name.'/ip/'.$resume->slug;
        } else {
            $url = config('app.url').'/ip/'.$resume->slug;
        }
    }

    return $url;
}

function generateResumeUrl($slug)
{
    if (\Auth::check()) {
        $url = url('/ip/'.$slug);
    } else {
        $url = generateResumeProfileUrl($slug);
    }

    return $url;
}

function generateResumeProfileOwnUrl($resume)
{
    if ($resume->domain_activated == 1 and $resume->domain_blocked == 0) {
        $result = parse_url(config('app.url'));
        $scheme = 'https://';
        if (isset($result['scheme'])) {
            $scheme = $result['scheme'].'://';
        }
        $url = $scheme.$resume->domain_name.'/ip/'.$resume->slug;
    } else {
        $url = config('app.url').'/ip/'.$resume->slug;
    }

    return $url;
}

function generateResumeProfileUrl($slug)
{
    $community = app('App\\Repositories\\CommunityRepository')->getResumeCommunity();
    if ($community) {
        $url = $community->present()->getCommunityDomain();
        $url = $url.'/ip/'.$slug;

        return $url;
    }

    // $url=\URL()."/ip/".$slug;
    $url = config('app.url').'/ip/'.$slug;

    return $url;
}

function convertToBold($string)
{

    $string = str_replace('/*', '<b>', $string);
    $stingNew = str_replace('*/', '</b>', $string);
    $startCount = substr_count($stingNew, '<b>');

    $boldEnding = '';
    if ($startCount > 0) {
        for ($i = 0; $i < $startCount; $i++) {
            $boldEnding = $boldEnding.'</b>';
        }
    }
    $boldString = $stingNew.$boldEnding; // -------------Bold ending

    $boldString = str_replace('/$', '<strike>', $boldString);
    $stingNewStrike = str_replace('$/', '</strike>', $boldString);
    $strikeStartCount = substr_count($stingNewStrike, '<strike>');

    $strikeEnding = '';
    if ($strikeStartCount > 0) {
        for ($i = 0; $i < $strikeStartCount; $i++) {
            $strikeEnding = $strikeEnding.'</strike>';
        }
    }
    $strikeString = $stingNewStrike.$strikeEnding; // --------------Strike ending

    $strikeString = str_replace('/!', '<i>', $strikeString);
    $stringNewItalic = str_replace('!/', '</i>', $strikeString);
    $italicStartCount = substr_count($stringNewItalic, '<i>');

    $italicEnding = '';
    if ($italicStartCount > 0) {
        for ($i = 0; $i < $italicStartCount; $i++) {
            $italicEnding = $italicEnding.'</i>';
        }
    }
    $italicString = $stringNewItalic.$italicEnding; // --------------Italic ending

    $italicString = str_replace('/@', '<u>', $italicString);
    $stringNewUnderline = str_replace('@/', '</u>', $italicString);
    $underlineStartCount = substr_count($stringNewUnderline, '<u>');

    $underlineEnding = '';
    if ($underlineStartCount > 0) {
        for ($i = 0; $i < $underlineStartCount; $i++) {
            $underlineEnding = $underlineEnding.'</u>';
        }
    }
    $underlineString = $stringNewUnderline.$underlineEnding; // -----------Underline ending

    $underlineString = str_replace('/#', "<p class='posttextshighlight'>", $underlineString);
    $stringNewHighlight = str_replace('#/', '</p>', $underlineString);
    $highlightStartCount = substr_count($stringNewHighlight, "<p class='posttextshighlight'>");

    $highlightEnding = '';
    if ($highlightStartCount > 0) {
        for ($i = 0; $i < $highlightStartCount; $i++) {
            $highlightEnding = $highlightEnding.'</p>';
        }
    }
    $highlightString = $stringNewHighlight.$highlightEnding;

    $highlightString = str_replace('/~', "<p class='posttextshighlightplane'>", $highlightString);
    $stringNewHighlightPlane = str_replace('~/', '</p>', $highlightString);
    $highlightPlaneStartCount = substr_count($stringNewHighlightPlane, "<p class='posttextshighlightplane'>");

    $highlightPlaneEnding = '';
    if ($highlightPlaneStartCount > 0) {
        for ($i = 0; $i < $highlightPlaneStartCount; $i++) {
            $highlightPlaneEnding = $highlightPlaneEnding.'</p>';
        }
    }
    $highlightPlaneString = $stringNewHighlightPlane.$highlightPlaneEnding;

    return $highlightPlaneString; // --------------Highlight ending
}

function closeAllOpenTags($html)
{
    // $newHtml=strip_tags($html);
    // return $newHtml;

    $newHtml = strip_tags($html, '<code><br></br><ul><ol><li>');

    // $newConvertedHtml=closetags($newHtml);

    return $newHtml;

    /*preg_match_all('#<([a-z]+)(?: .*)?(?<![/|/ ])>#iU', $html, $result);
    $openedtags = $result[1];

    preg_match_all('#</([a-z]+)>#iU', $html, $result);
    $closedtags = $result[1];
    $len_opened = count($openedtags);

    $htmlEnding=$html;

    $paraCount=substr_count($html,"<p");
    if($paraCount > 0){
        for($i=0; $i<$paraCount; $i++){
            $htmlEnding=$htmlEnding."</p>";
        }
    }

    $anchorCount=substr_count($htmlEnding,"<a");
    if($anchorCount > 0){
        for($i=0; $i<$anchorCount; $i++){
            $htmlEnding=$htmlEnding."</a>";
        }
    }

    $html=$htmlEnding;

    if (count($closedtags) == $len_opened) {
        $html;
    }

    $openedtags = array_reverse($openedtags);
    for ($i=0; $i < $len_opened; $i++) {
        if (!in_array($openedtags[$i], $closedtags)){
            $html .= '</'.$openedtags[$i].'>';
        } else {
            unset($closedtags[array_search($openedtags[$i], $closedtags)]);
        }
    }

    return $html;*/
}

function closetags($html)
{
    preg_match_all('#<([a-z]+)(?: .*)?(?<![/|/ ])>#iU', $html, $result);
    $openedtags = $result[1];

    preg_match_all('#</([a-z]+)>#iU', $html, $result);
    $closedtags = $result[1];
    $len_opened = count($openedtags);
    if (count($closedtags) == $len_opened) {
        return $html;
    }
    $openedtags = array_reverse($openedtags);
    for ($i = 0; $i < $len_opened; $i++) {
        if (! in_array($openedtags[$i], $closedtags)) {
            $html .= '</'.$openedtags[$i].'>';
        } else {
            unset($closedtags[array_search($openedtags[$i], $closedtags)]);
        }
    }

    return $html;
}

function removeConvertedTexts($texts)
{
    $texts = html_entity_decode($texts);

    $res = str_replace(['/*',  '*/', '/$', '$/', '/!', '!/', '/@', '@/', '/#', '#/', '/~', '~/'], ' ', $texts);

    $res = strip_tags($res);

    return $res;
}

function addVisitorInfo($community_id = 0)
{
    /*$referrer_url="";
    if(isset($_SERVER['HTTP_REFERER'])){
        $referrer_url=$_SERVER['HTTP_REFERER'];
    }
    $visitor_ip=getUserIpAddr();

    $siteVisitorsRepository = app('App\\Repositories\\SiteVisitorsRepository');

    $siteVisitorsRepository->addVisitor($community_id,$visitor_ip,$referrer_url);*/
}

function sendAlertNotification($headings, $content, $url, $notificationKeys, $data)
{
    $headings = [
        'en' => $headings,
    ];

    $content = [
        'en' => $content,
    ];

    $fields = [
        'app_id' => '329205a1-9487-4e5d-a2bd-469a6a2f2295',
        'include_player_ids' => $notificationKeys,
        'data' => $data,
        'headings' => $headings, // Title of your website
        'contents' => $content, // the message
        // 'url' => $url,
    ];

    $fields = json_encode($fields);

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://onesignal.com/api/v1/notifications');
    curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json; charset=utf-8',
        'Authorization: Basic MjU3Y2ZmNGItYmRkZC00NWZkLWEwMWEtMThkN2U0MWQzNDMy']);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    $response = curl_exec($ch);
    curl_close($ch);

    return $response;
}

function userLocalTimeForZoom()
{
    $timezone = \Session::get('user_client_timezone');
    if ($timezone != 'America/New_York' and $timezone != '') {
        date_default_timezone_set($timezone);

        return date('Y-m-d').'T'.date('H:i:s');
    } else {
        date_default_timezone_set('America/New_York');

        return date('Y-m-d').'T'.date('H:i:s');
    }
}

function userLocalTimeZone()
{
    $timezone = \Session::get('user_client_timezone');
    if ($timezone != 'America/New_York' and $timezone != '') {
        return $timezone;
    } else {
        return 'America/New_York';
    }
}

function timezoneIsDST($timezone = 'America/New_York')
{

    /*$tz = new DateTimeZone($timezone);
    $transitions = $tz->getTransitions();
    if (is_array($transitions)){
        foreach ($transitions as $k => $t){
            // look for current year
            if (substr($t['time'],0,4) == date('Y')){
               $trans = $t;
               break;
            }
        }
    }

    if(isset($trans)){
         if($trans['isdst']==1){
             return true;
         }
    }
    return false;*/

    date_default_timezone_set($timezone);

    return date('I');

    if (date('I')) {
        return true;
    }

    return false;
}

function getVisitingCommunityId()
{
    if (\Auth::check()) {
        return \Auth::user()->visiting_community;
    }

    return 0;
}

function translateLanguage($target, $source, $string)
{
    // $value1 = str_replace(array('‘', "’",'“', "”","'",'"'), '', $string);
    // $value2 = trim(preg_replace('/\s+/',' ', $value1));

    // $string='According to McKinzie\'s research, \"the benefits from using social technologies within and across enterprises - to communicate, share knowledge, and collaborate - are larger than the (also enormous) value in product development, marketing, customer service and so forth. Overall, we estimate that social technologies could, when properly implemented, raise overall knowledge worker productivity by 20 to 25 percent.\"';

    $curl = curl_init();

    $payload = json_encode([
        'text' => (string) $string,
        'source' => (string) $source,
        'target' => (string) $target,
    ], JSON_UNESCAPED_UNICODE);

    curl_setopt_array($curl, [
        CURLOPT_URL => 'https://heziehxaoa.execute-api.us-east-1.amazonaws.com/pro-translate',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        // Avoid hanging requests during bulk language generation
        CURLOPT_CONNECTTIMEOUT => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_POSTFIELDS => $payload,
        CURLOPT_HTTPHEADER => [
            'Content-Type: application/json',
        ],
    ]);

    $response = curl_exec($curl);
    curl_close($curl);

    if (!is_string($response) || $response === '') {
        return $string;
    }

    $result = json_decode($response, true);
    if (!is_array($result)) {
        return $string;
    }

    if (($result['message'] ?? null) === 'success' && isset($result['TranslatedText'])) {
        return (string) $result['TranslatedText'];
    }

    return $string;
}

/**
 * Translate many strings faster by running translation API requests concurrently.
 *
 * Returns an array of translated strings in the same order as $strings.
 * Falls back to original strings on any failure.
 */
function translateLanguageBulk($target, $source, array $strings, int $concurrency = 8): array
{
    $concurrency = max(1, min(20, $concurrency));

    $results = [];
    $indexMapByText = [];
    $uniqueTexts = [];

    // Cache translations (persistent) to reduce calls across runs.
    $cache = null;
    try {
        $cache = app('cache.store');
    } catch (\Throwable $e) {
        $cache = null;
    }

    foreach ($strings as $i => $text) {
        if (!is_string($text) || $text === '') {
            $results[$i] = $text;
            continue;
        }

        $cacheKey = 'translate.v1.' . sha1($source . '|' . $target . '|' . $text);
        if ($cache) {
            try {
                $cached = $cache->get($cacheKey);
                if (is_string($cached) && $cached !== '') {
                    $results[$i] = $cached;
                    continue;
                }
            } catch (\Throwable $e) {
                // ignore cache failures
            }
        }

        $indexMapByText[$text][] = $i;
        if (!isset($uniqueTexts[$text])) {
            $uniqueTexts[$text] = true;
        }
    }

    $queue = array_keys($uniqueTexts);
    if (empty($queue)) {
        ksort($results);
        return array_values($results);
    }

    $multi = curl_multi_init();
    $handles = [];
    $handleText = [];

    $addHandle = function (string $text) use (&$handles, &$handleText, $multi, $target, $source) {
        $ch = curl_init();
        $payload = json_encode([
            'text' => $text,
            'source' => (string) $source,
            'target' => (string) $target,
        ], JSON_UNESCAPED_UNICODE);

        curl_setopt_array($ch, [
            CURLOPT_URL => 'https://heziehxaoa.execute-api.us-east-1.amazonaws.com/pro-translate',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 5,
            CURLOPT_CONNECTTIMEOUT => 10,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_POSTFIELDS => $payload,
            CURLOPT_HTTPHEADER => [
                'Content-Type: application/json',
            ],
        ]);

        $id = is_object($ch) ? spl_object_id($ch) : (int) $ch;
        $handles[$id] = $ch;
        $handleText[$id] = $text;

        curl_multi_add_handle($multi, $ch);
    };

    $inFlight = 0;
    $cursor = 0;
    $active = null;

    while ($cursor < count($queue) || $inFlight > 0) {
        while ($inFlight < $concurrency && $cursor < count($queue)) {
            $addHandle($queue[$cursor]);
            $cursor++;
            $inFlight++;
        }

        do {
            $status = curl_multi_exec($multi, $active);
        } while ($status === CURLM_CALL_MULTI_PERFORM);

        while ($info = curl_multi_info_read($multi)) {
            $ch = $info['handle'];
            $id = is_object($ch) ? spl_object_id($ch) : (int) $ch;
            $text = $handleText[$id] ?? '';

            $response = curl_multi_getcontent($ch);
            $translated = $text;
            if (is_string($response) && $response !== '') {
                $decoded = json_decode($response, true);
                if (is_array($decoded) && ($decoded['message'] ?? null) === 'success' && isset($decoded['TranslatedText'])) {
                    $translated = (string) $decoded['TranslatedText'];
                }
            }

            // Fill all indexes that share the same source text.
            foreach (($indexMapByText[$text] ?? []) as $i) {
                $results[$i] = $translated;
            }

            // Persist cache (30 days) to avoid re-translation across runs.
            if ($cache) {
                try {
                    $cacheKey = 'translate.v1.' . sha1($source . '|' . $target . '|' . $text);
                    $cache->put($cacheKey, $translated, 60 * 60 * 24 * 30);
                } catch (\Throwable $e) {
                    // ignore
                }
            }

            curl_multi_remove_handle($multi, $ch);
            curl_close($ch);
            unset($handles[$id], $handleText[$id]);
            $inFlight--;
        }

        if ($active) {
            $selected = curl_multi_select($multi, 1.0);
            if ($selected === -1) {
                usleep(10_000);
            }
        }
    }

    curl_multi_close($multi);

    // Ensure all outputs are set (fallback to original).
    foreach ($strings as $i => $text) {
        if (!array_key_exists($i, $results)) {
            $results[$i] = $text;
        }
    }

    ksort($results);
    return array_values($results);
}

/**
 * Recursively translate all string leaf values in a translation array.
 */
function translateArrayLanguageBulk($target, $source, $data, int $concurrency = 8)
{
    if (!is_array($data)) {
        return $data;
    }

    $paths = [];
    $strings = [];

    $walk = function ($value, array $path) use (&$walk, &$paths, &$strings) {
        if (is_array($value)) {
            foreach ($value as $k => $v) {
                $walk($v, array_merge($path, [$k]));
            }
            return;
        }

        if (is_string($value)) {
            $paths[] = $path;
            $strings[] = $value;
        }
    };

    $walk($data, []);
    if (empty($strings)) {
        return $data;
    }

    $translated = translateLanguageBulk($target, $source, $strings, $concurrency);

    $setByPath = function (&$arr, array $path, $value) {
        $ref = &$arr;
        $lastKey = array_pop($path);
        foreach ($path as $k) {
            if (!isset($ref[$k]) || !is_array($ref[$k])) {
                $ref[$k] = [];
            }
            $ref = &$ref[$k];
        }
        if ($lastKey !== null) {
            $ref[$lastKey] = $value;
        }
    };

    foreach ($paths as $i => $path) {
        $setByPath($data, $path, $translated[$i] ?? $strings[$i]);
    }

    return $data;
}

function translatePageLanguage($target, $source, $string)
{
    $html = $string;
    @$dom = new DomDocument;
    @$dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
    $xpath = new DOMXPath($dom);

    foreach ($xpath->query('//text()') as $text) {
        if (trim($text->nodeValue)) {

            $value1 = trim($text->nodeValue);

            if ($value1 == '»') {
                return $value1;
            } else {
                /*$value1 = str_replace('‘', "\‘", $value1);
                $value1 = str_replace('’', '\’', $value1);
                $value1 = str_replace('“', '\“', $value1);
                $value1 = str_replace('”', '\”', $value1);
                $value1 = str_replace("'", "\'", $value1);
                $value1 = str_replace('"', '\"', $value1);*/

                $value1 = str_replace("'", '', $value1);

                $value1 = str_replace('‘', "\‘", $value1);
                $value1 = str_replace('’', '\’', $value1);
                $value1 = str_replace('“', '\“', $value1);
                $value1 = str_replace('”', '\”', $value1);
                $value1 = str_replace("'", "\'", $value1);
                $value1 = str_replace('"', '\"', $value1);

                $value1 = trim(preg_replace('/\s+/', ' ', $value1));

                $text->nodeValue = translateLanguage($target, $source, $value1);
            }
        }
    }

    return $dom->saveHTML();
}

function communityTranslate($communityId, $phrase, $texts)
{
    $lang = \session::get('lang');

    if (! $lang or $lang == 'en') {
        return $texts;
    }
    $translation = app('App\\Repositories\\CommunityLanguagesTranslationRepository')->findByVar($communityId, $lang, $phrase);

    if ($translation) {
        $value = $translation->value;
        $value1 = stripslashes($value);

        return $value1;
    }

    return $texts;
}

/**
 * Replaces dynamic header tokens with runtime-rendered HTML.
 *
 * Currently supported tokens:
 * - [[COMMUNITY_DYNAMIC_MENUBAR]]
 * - [[CHAMBER_COMMON_HEADER]]
 */
function replaceCommunityHeaderTokens($html, $community = null, $homecontents = null, $pages = null)
{
    if (! $html || ! is_string($html)) {
        return $html;
    }

    if (! $community) {
        // No community context to resolve dynamic tokens.
        return str_replace(['[[COMMUNITY_DYNAMIC_MENUBAR]]', '[[CHAMBER_COMMON_HEADER]]'], '', $html);
    }

    // Ensure homecontents is available for Chamber menu/header configuration.
    if (! $homecontents) {
        try {
            $homecontents = $community->present()->getHomeContents();
        } catch (\Throwable $e) {
            $homecontents = null;
        }
    }

    $chamberToken = '[[CHAMBER_COMMON_HEADER]]';
    $hasChamberToken = (strpos($html, $chamberToken) !== false);

    // If a DB-backed common header exists, inject it either via token or by
    // replacing the existing Chamber8 topbar+nav segment (backward compatible).
    $commonHeaderHtml = '';
    if ($homecontents && ! empty($homecontents->chamber_common_header_html)) {
        $commonHeaderHtml = (string) $homecontents->chamber_common_header_html;
    } elseif ($homecontents && ! empty($homecontents->html_edit_code_chamber)) {
        // Fallback for older communities: derive the common header from the saved
        // homepage Chamber HTML until the column gets populated.
        $commonHeaderHtml = (string) extractChamberCommonHeaderSection($homecontents->html_edit_code_chamber);
    }

    $isChamberCommunity = false;
    try {
        $isChamberCommunity = (bool) $community->present()->isChamberCommunity();
    } catch (\Throwable $e) {
        $isChamberCommunity = false;
    }

    if ($commonHeaderHtml !== '') {
        if ($hasChamberToken) {
            $html = str_replace($chamberToken, $commonHeaderHtml, $html);
        } else {
            $before = $html;
            $html = replaceChamberCommonHeaderSegment($html, $commonHeaderHtml);

            // If the saved header doesn't contain the Chamber segment at all,
            // ensure the common header is still displayed for Chamber communities.
            if ($html === $before && $isChamberCommunity) {
                // Never prepend if the page already contains a Chamber8 header.
                // (Fallback is only for pages that truly have no header markup.)
                $alreadyHasChamberHeader = (stripos($before, 'chamber8-topbar') !== false) || (stripos($before, 'chamber8-nav') !== false);
                if (! $alreadyHasChamberHeader) {
                    $html = $commonHeaderHtml . $html;
                }
            }
        }
    } elseif ($hasChamberToken) {
        // Token present but no configured header.
        $html = str_replace($chamberToken, '', $html);
    }

    $token = '[[COMMUNITY_DYNAMIC_MENUBAR]]';
    if (strpos($html, $token) === false) {
        return $html;
    }

    try {
        if (! $pages) {
            $pages = $community->present()->getPages();
        }
        $menuHtml = view('themes.frontend.default.views.community-layouts.chamber8-dynamic-menubar', [
            'community' => $community,
            'homecontents' => $homecontents,
            'pages' => $pages,
        ])->render();
    } catch (\Throwable $e) {
        $menuHtml = '';
    }

    return str_replace($token, $menuHtml, $html);
}

/**
 * Extracts the Chamber8 common header segment (topbar + nav) from a Chamber HTML snippet.
 * Returns empty string if the segment can't be located.
 */
function extractChamberCommonHeaderSection($html)
{
    if (! $html || ! is_string($html)) {
        return '';
    }

    // Match regardless of quote style in attributes.
    if (! preg_match('/<div\b[^>]*\bchamber8-topbar\b[^>]*>/i', $html, $m1, PREG_OFFSET_CAPTURE)) {
        return '';
    }

    $start = (int) ($m1[0][1] ?? 0);

    if (! preg_match('/<nav\b[^>]*\bchamber8-nav\b[^>]*>/i', $html, $m2, PREG_OFFSET_CAPTURE, $start)) {
        return '';
    }
    $navOffset = (int) ($m2[0][1] ?? 0);

    $end = stripos($html, '</nav>', $navOffset);
    if ($end === false) {
        return '';
    }
    $end += strlen('</nav>');

    $segment = substr($html, $start, $end - $start);
    return is_string($segment) ? trim($segment) : '';
}

/**
 * Replaces the Chamber8 topbar+nav section in an HTML snippet with the given common header.
 * Used for backward compatibility when saved headers don't contain a token.
 */
function replaceChamberCommonHeaderSegment($html, $commonHeaderHtml)
{
    if (! $html || ! is_string($html) || ! $commonHeaderHtml) {
        return $html;
    }

    $segment = extractChamberCommonHeaderSection($html);
    if ($segment === '') {
        return $html;
    }

    return str_replace($segment, $commonHeaderHtml, $html);
}

function generateVideoUrl($link)
{
    if ($link) {
        $youTube = parseYouTube($link);
        if (config('enable-https', false)) {
            $youTube = str_replace('http://', 'https://', $youTube);
        }
        if (! empty($youTube)) {
            return $youTube;
        }

        $vimeoURL = parseVimeo($link);
        if (config('enable-https', false)) {
            $vimeoURL = str_replace('http://', 'https://', $vimeoURL);
        }
        if (! empty($vimeoURL)) {
            return $vimeoURL;
        }
    }

    return false;
}

function saveUserSession()
{
    $userSessionsRepository = app('App\\Repositories\\UserSessionsRepository');
    $userSessionsRepository->saveSession();
}

function sessionVerification($value)
{
    $userSessionsRepository = app('App\\Repositories\\UserSessionsRepository');
    $sessionVerification = $userSessionsRepository->sessionVerification($value);
}

function clearUserCookie()
{
    $userSessionsRepository = app('App\\Repositories\\UserSessionsRepository');

    return $userSessionsRepository->clearUserCookie();
}

function userLoginVerification()
{
    // Enhanced CLI detection to prevent any operations during artisan commands
    if (app()->runningInConsole() || php_sapi_name() === 'cli') {
        return;
    }
    
    // Cache the verification result to avoid repeated processing
    static $verificationDone = false;
    if ($verificationDone) {
        return;
    }
    $verificationDone = true;
    
    if (\Session::has('redirectlogincookie') and \Session::get('redirectlogincookie') != '') {
        saveUserSession();
    } else {
        if (isset($_COOKIE[config('community-domain.cookie-name')])) {
            if (! \Auth::check()) {
                sessionVerification($_COOKIE[config('community-domain.cookie-name')]);
                $cookie_name = config('community-domain.cookie-name');
                \Session::put('single-signon-key', $cookie_name);
            }
        } else {
            // REMOVED: Automatic logout redirect that was causing infinite loops
            // This was a major performance bottleneck
			
			if (Auth::check()) {
				\Auth::logout();
                //redirect('logout')->send();
             }
        }
    }
}

function isMobile()
{

    /*if(isset($_SERVER["HTTP_USER_AGENT"])){
        return preg_match("/(android|webos|avantgo|iphone|ipad|ipod|blackberry|iemobile|bolt|boost|cricket|docomo|fone|hiptop|mini|opera mini|kitkat|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"]);
    }
    return false;*/

    if (\Session::has('loginFromApp') and \Session::get('loginFromApp') == 'loginFromApp') {
        return true;
    } else {
        return false;
    }
}

function getUrlHostname($url)
{
    $result = parse_url($url);
    if (isset($result['host'])) {
        return $result['host'];
    }

    return \Request::getHost();
}

function getUrlHostnameScheme($url)
{
    $result = parse_url($url);
    if (isset($result['scheme']) and isset($result['host'])) {
        return $result['scheme'].'://'.$result['host'];
    }

    return $url;
}

function siteEstimatedReadingTime($postContent = '')
{
    $text = (string) $postContent;
    $text = strip_tags($text);
    $text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');

    $word = 0;
    if ($text !== '') {
        // Unicode-safe word counting (supports Hindi/Marathi and other non-Latin scripts)
        if (preg_match_all("/[\\p{L}\\p{N}]+(?:[\'’][\\p{L}\\p{N}]+)*/u", $text, $matches)) {
            $word = count($matches[0]);
        }
    }
    $m = floor($word / 180);
    $s = floor($word % 180 / (180 / 60));
    if ($m > 0) {
        $plus = ($s > 0) ? '+' : '';
        $est = trans_choice('post.reading-time', $m, [
            'minutes' => $m,
            'plus' => $plus,
        ]);

    } else {
        // $est = $s . ' second' . ($s == 1 || $s == 0 ? '' : 's');
        $est = '';
    }

    return $est;
}

function generateUUID()
{
    if (function_exists('com_create_guid') === true) {
        return trim(com_create_guid(), '{}');
    }

    $string = sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));

    return strtolower($string);
}

function getSharingCommunityName($posted_in_community = 0)
{
    if (! $posted_in_community) {
        $posted_in_community = getVisitingCommunityId();
    }

    if ($posted_in_community > 0) {
        $visitingCm = app('App\\Repositories\\CommunityRepository')->getById($posted_in_community);
        if ($visitingCm) {
            return trans('global.you-are-sharing-at-community', ['community' => $visitingCm->title]);
        }
    } else {
        return trans('global.you-are-sharing-at-idhubs');
    }
}

function id4MartCommunityId()
{
    $publicBusinessCommunity = app('App\\Repositories\\CommunityRepository')->publicBusinessCommunity();
    if ($publicBusinessCommunity) {
        return $publicBusinessCommunity->id;
    }

    return 146;
}

function postShowTime($post)
{
    $originalDate = config('show-post-original-date-time', 1);

    if (! $originalDate) {
        if (\Auth::check()) {
            if ($post->community and $post->community->user_id == \Auth::user()->id) {
                return true;
            } elseif ($post->postedIncommunity and $post->postedIncommunity->user_id == \Auth::user()->id) {
                return true;
            }
        }

        return false;
    }

    return true;
}

function checkAvailableSpace($community_id, $selectedFileSize)
{
    if ($community_id) {
        $community = app('App\\Repositories\\CommunityRepository')->getById($community_id);
        if ($community) {
            $requiredSpace = $community->space_used + $selectedFileSize;
            if ($community->allocated_space >= $requiredSpace) {
                return 1;
            } else {
                return 0;
            }
        }

        return 1;
    }

    return 1;
}

function getConvrtedTime24Hrs($time)
{
    $datetime = new DateTime($time);

    return $datetime->format('His');
}

function articleViewName($type, $typeId, $community_id, $page_id, $posted_in_community)
{
    if ($type == 'user-timeline' and $community_id == 0 and $posted_in_community == 0) {
        return 'Idhubs social media -';
    } elseif ($type == 'community' and $community_id != 0 and $typeId != 0) {
        $category = app('App\\Repositories\\CommunityCategoryRepository')->getById($typeId);
        if ($category) {
            return $category->title.' - ';
        }
    } elseif ($type == 'resume') {
        return 'Interactive Resume - ';
    } elseif ($posted_in_community) {
        $community = app('App\\Repositories\\CommunityRepository')->getById($posted_in_community);
        if ($community) {
            return $community->title.' social media - ';
        }
    } elseif ($type == 'page' and $page_id != 0) {
        $page = app('App\\Repositories\\PageRepository')->findById($page_id);
        if ($page) {
            return $page->title.' - ';
        }
    }
}

function articleViewNameLink($type, $typeId, $community_id, $page_id, $posted_in_community)
{
    if ($type == 'user-timeline' and $community_id == 0 and $posted_in_community == 0) {
        return '<a href="'.config('app.url').'" class="brand-colored-texts">Idhubs social media - </a>';
    } elseif ($type == 'community' and $community_id != 0 and $typeId != 0) {
        $community = app('App\\Repositories\\CommunityRepository')->getById($community_id);
        if ($community) {
            $category = app('App\\Repositories\\CommunityCategoryRepository')->getById($typeId);
            if ($category) {
                return '<a href="'.$community->present()->url('category/'.$category->slug).'" class="brand-colored-texts">'.$category->title.' - </a>';
            }
        }
    } elseif ($type == 'resume') {

        $resumeData = \Auth::user()->present()->isResumeCreated();
        if ($resumeData) {
            $ipUrl = \URL::to('ip/').'/'.$resumeData->slug.'/manage';

            return '<a href="'.$ipUrl.'" class="brand-colored-texts">Interactive Resume - </a>';
        }
    } elseif ($posted_in_community) {
        $community = app('App\\Repositories\\CommunityRepository')->getById($posted_in_community);
        if ($community) {
            $communitySocialUrl = URL::route('community-home', ['slug' => $posted_in_community]);

            return '<a href="'.$communitySocialUrl.'" class="brand-colored-texts">'.$community->title.' social media - </a>';
        }
    } elseif ($type == 'page' and $page_id != 0) {
        $page = app('App\\Repositories\\PageRepository')->findById($page_id);
        if ($page) {
            return '<a href="'.$page->present()->url().'" class="brand-colored-texts">'.$page->title.' - </a>';
        }
    }
}

function articleViewNameLinkBack($type, $typeId, $community_id, $page_id, $posted_in_community)
{
    if ($type == 'user-timeline' and $community_id == 0 and $posted_in_community == 0) {
        return config('app.url');
    } elseif ($type == 'community' and $community_id != 0 and $typeId != 0) {
        $community = app('App\\Repositories\\CommunityRepository')->getById($community_id);
        if ($community) {
            $category = app('App\\Repositories\\CommunityCategoryRepository')->getById($typeId);
            if ($category) {
                return $community->present()->url('category/'.$category->slug);
            }
        }
    } elseif ($type == 'resume') {

        $resumeData = \Auth::user()->present()->isResumeCreated();
        if ($resumeData) {
            $ipUrl = \URL::to('ip/').'/'.$resumeData->slug.'/manage';

            return $ipUrl;
        }
    } elseif ($posted_in_community) {
        $community = app('App\\Repositories\\CommunityRepository')->getById($posted_in_community);
        if ($community) {
            $communitySocialUrl = URL::route('community-home', ['slug' => $posted_in_community]);

            return $communitySocialUrl;
        }
    } elseif ($type == 'page' and $page_id != 0) {
        $page = app('App\\Repositories\\PageRepository')->findById($page_id);
        if ($page) {
            return $page->present()->url();
        }
    }
}

function getPricingPlanName($id)
{
    $plan = app('App\\Repositories\\PricingPlansRepository')->getPlanByPlanId($id);
    $plan_name = '';
    if ($plan) {
        $plan_name = $plan->plan_name;
    }

    return $plan_name;
}

function getPricingPlanUserLimit($id)
{
    $plan = app('App\\Repositories\\PricingPlansRepository')->getPlanByPlanId($id);
    $user_limit = '';
    if ($plan) {
        $user_limit = $plan->user_limit;
    }

    return $user_limit;
}

function loginDisabledMsgCm()
{
    return 'Login has been disabled for this organization.';
}

function time_elapsed_string($datetime, $full = false)
{
    $now = new DateTime;
    $ago = new DateTime($datetime);
    $diff = $now->diff($ago);

    $diff->w = floor($diff->d / 7);
    $diff->d -= $diff->w * 7;

    $string = [
        'y' => 'year',
        'm' => 'month',
        'w' => 'week',
        'd' => 'day',
        'h' => 'hr',
        'i' => 'min',
        's' => 'second',
    ];
    foreach ($string as $k => &$v) {
        if ($diff->$k) {
            $v = $diff->$k.' '.$v.($diff->$k > 1 ? 's' : '');
        } else {
            unset($string[$k]);
        }
    }

    if (! $full) {
        $string = array_slice($string, 0, 1);
    }

    // return $string ? implode(', ', $string) . ' ago' : 'just now';
    return $string ? implode(', ', $string).' ' : 'just now';
}

function replaceStringWithStar($num)
{
    $chars = 'XXXXXXXXXX';

    return substr((string) $num, 0, -strlen($chars)).$chars;
}

function timeZoneShortName($timezone_id)
{
    if ($timezone_id) {
        /*$abb_list = timezone_abbreviations_list();

        $abb_array = array();
        foreach ($abb_list as $abb_key => $abb_val) {
            foreach ($abb_val as $key => $value) {
                $value['abb'] = $abb_key;
                array_push($abb_array, $value);
            }
        }

        foreach ($abb_array as $key => $value) {
            if($value['timezone_id'] == $timezone_id){
                return strtoupper($value['abb']);
            }
        }*/

        $dateTime = new \DateTime;
        $dateTime->setTimeZone(new \DateTimeZone($timezone_id));

        return $dateTime->format('T');
    }

    return '';
}

function makeFirstCharacterBig($texts)
{
    // $string=strtolower($texts);
    // return ucwords($string);
    return $texts;
}

function getFullPath($path)
{
    $file = \URL::to($path);
    $CDNRepository = app('App\\Repositories\\CDNRepository');
    if ($CDNRepository->has($path)) {
        if (strpos($path, 'media/appvideo/') !== false) {
            $file = $CDNRepository->getVideoOutpuLinkMp4($path);
        } else {
            $file = $CDNRepository->getLink($path);
        }
    }

    return $file;
}

function generate_random_string($strength = 10)
{
    $input = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $input_length = strlen($input);
    $random_string = '';
    for ($i = 0; $i < $strength; $i++) {
        $random_character = $input[mt_rand(0, $input_length - 1)];
        $random_string .= $random_character;
    }

    return $random_string;
}

function replaceCardWithStar($card_number)
{
    $str = $card_number;
    $str = str_replace(' ', '', $str);
    $len = strlen($str);

    return str_repeat('*', $len - 4).substr($str, $len - 4);
}

function getMonthsDifferenceFromToday($date2)
{
    $date1 = date('Y-m-d');
    $d1 = new DateTime($date2);
    $d2 = new DateTime($date1);
    $Months = $d2->diff($d1);
    $howeverManyMonths = (($Months->y) * 12) + ($Months->m) + $Months->d / 30;

    // return $howeverManyMonths;
    return (int) round($howeverManyMonths);
}

function getRecurringMonthDate($date)
{
   /* $currentMonth = date('m', strtotime($date));
    $nextMonth = date('m', strtotime($date.'+1 month'));
    if ($currentMonth == $nextMonth - 1 && (date('j', strtotime($date)) != date('t', strtotime($date)))) {
        $nextDate = date('Y-m-d', strtotime($date.' +1 month'));
    } else {
        $nextDate = date('Y-m-d', strtotime('last day of next month', strtotime($date)));
    }

    return $nextDate;*/
	
	$dt = new DateTime($date);

    $day = (int) $dt->format('d');

    // Move to first day of next month
    $dt->modify('first day of next month');

    // Get total days in next month
    $daysInMonth = (int) $dt->format('t');

    // Use same day if exists, else last day
    $day = min($day, $daysInMonth);

    return $dt->format('Y-m-') . str_pad($day, 2, '0', STR_PAD_LEFT);
}

function getRssFeed($feed_url, $title)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $feed_url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $content = curl_exec($ch);
    curl_close($ch);

    libxml_use_internal_errors(true);

    $news = '';
    if (substr($content, 0, 5) == '<?xml') {

        $x = simplexml_load_string($content);
        $i = 1;
        if (isset($x->channel->item)) {
            foreach ($x->channel->item as $entry) {
                $news = 'found';

                $imageBox = '';
                $imageUrl = '';
                if (isset($entry->enclosure['url'])) {
                    $imageUrl = $entry->enclosure['url'];
                    $imageBox = '<div class="rss-img-outer-box"><img class="rss-img-preview lazy" data-original="'.$imageUrl.'"/></div>';
                }

                echo '<div class="rss_content">
							<div class="rss_panel rss_panel'.$i.'">'.$imageBox.'
								<div class="blog_title">
										<a class="blog_title_'.$i.'" data-img="'.$imageUrl.'" target="_blank" href="'.$entry->link.'" title="'.$entry->title.'">"'.$entry->title.'"</a> 
								</div>
								<div class="blog_description blog_description_'.$i.' ">'.strip_tags($entry->description).'</div>
							</div>
							
							<div class="edit_rss_form edit_rss_form_'.$i.'">
								
							</div>
							
							<div class="rss_action_items rss_action_items_'.$i.'">
								<span data-id="'.$i.'" class="editRSSBtn btn btn-success">Edit</span>		

								<span data-id="'.$i.'" class="shareRSS postRSSBtn red-color-button btn">Post</span>	
							</div>
						</div>';
                $i++;

                // <span data-id="'.$i.'" class="viewRSSBtn"><i class="fa fa-eye" aria-hidden="true"></i></span>
            }
        }
    }

    if ($news == '') {
        echo '<div>No feeds found</div>';
    }
}

function getRssFeedData($feed_url)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $feed_url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $content = curl_exec($ch);
    curl_close($ch);

    libxml_use_internal_errors(true);

    $news = '';
    if (substr($content, 0, 5) == '<?xml') {

        $x = simplexml_load_string($content);
        $i = 1;
        if (isset($x->channel->item)) {
            foreach ($x->channel->item as $entry) {
                $news = 'found';

                $imageBox = '';
                $imageUrl = '';
                if (isset($entry->enclosure['url'])) {
                    $imageUrl = $entry->enclosure['url'];
                    $imageBox = '<div class="rss-img-outer-box"><img class="rss-img-preview lazy" data-original="'.$imageUrl.'"/></div>';
                }

                echo '<div class="rss_content">
							<div class="rss_panel rss_panel'.$i.'">'.$imageBox.'
								<div class="blog_title">
										<a class="blog_title_'.$i.'" data-img="'.$imageUrl.'" target="_blank" href="'.$entry->link.'" title="'.$entry->title.'">"'.$entry->title.'"</a> 
								</div>
								<div class="blog_description blog_description_'.$i.' ">'.strip_tags($entry->description).'</div>
							</div>
							
						</div>';
                $i++;
            }
        }
    }

    if ($news == '') {
        echo "<div style='margin-top:20px'>No feeds found</div>";
    }
}

function getFolderSize($dir)
{
    $size = 0;

    foreach (glob(rtrim($dir, '/').'/*', GLOB_NOSORT) as $each) {
        $size += is_file($each) ? filesize($each) : getFolderSize($each);
    }

    return $size;
}

function isIdentityVerified($user_id)
{
	static $requestCache = [];
	$user_id = (int) $user_id;

	if ($user_id <= 0) {
		return false;
	}

	if (array_key_exists($user_id, $requestCache)) {
		return $requestCache[$user_id];
	}

	return $requestCache[$user_id] = Cache::remember('user_identity_verified_' . $user_id, 60, function() use ($user_id) {
		$identity = app('App\\Repositories\\UserIdentificationRepository')->getByUserId($user_id);

		if ($identity && (int) ($identity->is_verified ?? 0) === 1) {
			return true;
		}

		return false;
	});
}
