ACC SHELL

Path : /srv/www/vhosts/marevva/nadacekrizovatka/
File Upload :
Current File : /srv/www/vhosts/marevva/nadacekrizovatka/functions.php

<?php

	
	// --------------------------------------------------------------------------------
	// javascript redirect
	function js_redirect( $url )
	{
		echo '	<script language="javascript" type="text/javascript">
					<!--
						window.location.href = \'' . $url . '\';
					-->
				</script>';
	}
	
	// --------------------------------------------------------------------------------
	// javascript redirect
	function js_redirectEx( $url )
	{
		echo '<html><head>	<script language="javascript" type="text/javascript">
					
						window.location.href = \'' . $url . '\';
					
				</script></head></body></html>';
	}

	// --------------------------------------------------------------------------------
	// check user info text field
	function checkField( $field, $regex, $bad=' ! ', $good=' OK ', $echo=true )
	{
		if ( !empty( $field ) && ( preg_match( $regex, $field ) > 0 ) )
		{
			if ( $echo )
			{
				echo '<div class="register-check-good">' . $good . '</div>';
			}

			return true;
		}
		else
		{
			if ( $echo )
			{
				echo '<div class="register-check-bad">' . $bad . '</div>';
			}

			return false;
		}
	}
	
	// --------------------------------------------------------------------------------
	// check user info text field
	function checkFieldR( $field, $regex, $bad=' ! ', $good=' OK ', $echo=false )
	{
		if ( !empty( $field ) && ( preg_match( $regex, $field ) > 0 ) )
		{
			if ( $echo )
				return '<div class="register-check-good">' . $good . '</div>';
		}
		else
		{
			if ( $echo )
				return '<div class="register-check-bad">' . $bad . '</div>';
		}
	}
	
	// --------------------------------------------------------------------------------
	function urlLang( $_lang, $languages=array('cz', 'en'), $default='cz' )
	{
		if ( count() > 0 )
		{
			foreach ( $languages as $language )
			{
				if ( $_lang == $language )
				{
					if ( $_lang == $default ) 
						return '';
					else
						return '.' . $language;
				}
			}
		}
		
		return '';	
	}
	
	// --------------------------------------------------------------------------------
	function removeOutdatedItems( $itemsArray, $currentDate, $sort=true )
	{
		$itemsArray_ = array();
		
		$count = count( $itemsArray );
		if ( $count > 0 )
		{
			for ( $i = 0; $i < $count; $i++ )
			{
				$item = $itemsArray[$i];
				
				if ( ( strcmp( $item['visibilityStartDate'], $currentDate ) <= 0 ) && 
					 (( $item['visibilityEndDate'] == '0000-00-00' ) || ( strcmp( $item['visibilityEndDate'], $currentDate ) >= 0 )) )
				{
					$itemsArray_[] = $itemsArray[ $i ];
				}
			}
			$count = count( $itemsArray_ );
			
			if ( $sort )
			{
				if ( $count > 0 )
				{
					for ( $i = 0; $i < $count; $i++ )
					{
						$item = $itemsArray_[$i];
						if ( $item['visibilityStartDate'] != '0000-00-00' )
						{
							$item['createdDateTime'] = $item['visibilityStartDate'];
							$itemsArray_[$i] = $item;
						}
					}
				}
				$itemsArray_ = array_sort( $itemsArray_, 'createdDateTime' );
			}
		}
		
		return $itemsArray_;
	}

	// --------------------------------------------------------------------------------
	// Files
	// --------------------------------------------------------------------------------
	
	// --------------------------------------------------------------------------------
	function deleteDirectory( $dir )
	{
        if ( !file_exists( $dir ) ) 
			return false;
			
        if ( !is_dir( $dir ) )
			return unlink( $dir );

        foreach ( scandir( $dir ) as $item )
		{
            if ( ($item == '.') || ($item == '..') ) 
				continue;

            if ( !deleteDirectory( $dir.DIRECTORY_SEPARATOR.$item ) )
				return false;
        }

        return rmdir( $dir );
    }
	
	// --------------------------------------------------------------------------------
	// check if file is PHP
	function isFilePHP( $fileName )
	{
		if ( !file_exists( $fileName ) )
		{
			return false;
		}
		
		$finfo = finfo_open( FILEINFO_MIME_TYPE );
		$fileMIMEtype = finfo_file( $finfo, $fileName );
		finfo_close( $finfo );
		
		$fileExtension = '';
		$path_parts = pathinfo( $fileName );
		if ( isset($path_parts['extension']) )
		{
			$fileExtension = strtolower( $path_parts['extension'] );
		}
		
		if (
				( $fileMIMEtype == 'text/php' ) || 
				( $fileMIMEtype == 'text/x-php' ) || 
				( $fileMIMEtype == 'application/php' ) || 
				( $fileMIMEtype == 'application/x-php' ) || 
				( $fileMIMEtype == 'application/x-httpd-php' ) || 
				( $fileMIMEtype == 'application/x-httpd-php-source' ) || 
				( $fileMIMEtype == 'text/c++' ) || 
				( $fileMIMEtype == 'text/x-c++' ) || 
				( $fileMIMEtype == 'application/c++' ) || 
				( $fileMIMEtype == 'application/x-c++' ) ||
				( $fileExtension == 'php' ) || 
				( $fileExtension == 'php4' ) || 
				( $fileExtension == 'php5' )
			)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	// --------------------------------------------------------------------------------
	// file size
	function human_filesize($bytes, $decimals = 2)
	{
	  $sz = 'BkMGTP';
	  $factor = floor((strlen($bytes) - 1) / 3);
	  return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . ' ' . @$sz[$factor];
	}

	// --------------------------------------------------------------------------------
	// Images & Video
	// --------------------------------------------------------------------------------
	
	function createThumbnailMin( $sourceImageFileName, $targetImageFileName, $minWidth, $minHeight )
	{
		if ( ( $minWidth != 0 ) && ( $minHeight != 0 ) )
		{
			// get image size info
			$imgInfo = getimagesize( $sourceImageFileName );
			switch ( $imgInfo[2] )
			{
				case 1: $srcImg = imagecreatefromgif( $sourceImageFileName ); break;
				case 2: $srcImg = imagecreatefromjpeg( $sourceImageFileName ); break;
				case 3: $srcImg = imagecreatefrompng( $sourceImageFileName ); break;
			}

			list( $widthImg, $heightImg ) = getimagesize( $sourceImageFileName );
	
			///
			$MinWidth = $minWidth;
			$MinHeight = $minHeight;
	
			$ratioWidth = $widthImg / $MinWidth;
			$ratioHeight = $heightImg / $MinHeight;
	
			if ( $ratioWidth < $ratioHeight )
				$ratio = $ratioWidth;						
			else						
				$ratio = $ratioHeight;						
			
			if ( $ratio < 1 )						
				$ratio = 1;
	
			$NewWidth = (int)$widthImg / $ratio;
			$NewHeight = (int)$heightImg / $ratio;
			///

			// thumb
			$tmpImg = imagecreatetruecolor( $NewWidth, $NewHeight );
			
			// Check if this image is PNG or GIF, then set if Transparent 
			if ( ($imgInfo[2] == 1) || ($imgInfo[2] == 3) )
			{
				imagealphablending( $tmpImg, false );
				imagesavealpha( $tmpImg, true );
				
				$transparent = imagecolorallocatealpha( $tmpImg, 255, 255, 255, 127 );
				
				imagefilledrectangle( $tmpImg, 0, 0, $NewWidth, $NewHeight, $transparent );
			}
			
			imagecopyresampled( $tmpImg, $srcImg, 0, 0, 0, 0, $NewWidth, $NewHeight, $widthImg, $heightImg );
			
			switch ( $imgInfo[2] )
			{
				case 1: $srcImg = imagegif( $tmpImg, $targetImageFileName ); break;
				case 2: $srcImg = imagejpeg( $tmpImg, $targetImageFileName, 100 ); break;
				case 3: $srcImg = imagepng( $tmpImg, $targetImageFileName, 5 ); break;
			}
			
			imagedestroy( $tmpImg );
			
			return true;
		}
		return false;
	}
	
	// --------------------------------------------------------------------------------
	function createThumbnailMax( $sourceImageFileName, $targetImageFileName, $MaxWidth, $MaxHeight )
	{
		if ( ( $MaxWidth != 0 ) && ( $MaxHeight != 0 ) )
		{
			// get image size info
			$imgInfo = getimagesize( $sourceImageFileName );
			switch ( $imgInfo[2] )
			{
				case 1: $srcImg = imagecreatefromgif( $sourceImageFileName ); break;
				case 2: $srcImg = imagecreatefromjpeg( $sourceImageFileName ); break;
				case 3: $srcImg = imagecreatefrompng( $sourceImageFileName ); break;
			}

			list( $widthImg, $heightImg ) = getimagesize( $sourceImageFileName );
	
			///
			$MaxWidth = $MaxWidth;
			$MaxHeight = $MaxHeight;
	
			$ratioWidth = $widthImg / $MaxWidth;
			$ratioHeight = $heightImg / $MaxHeight;
	
			if ( $ratioWidth > $ratioHeight )
				$ratio = $ratioWidth;						
			else						
				$ratio = $ratioHeight;						
			
			if ( $ratio < 1 )						
				$ratio = 1;
	
			$NewWidth = (int)$widthImg / $ratio;
			$NewHeight = (int)$heightImg / $ratio;
			///
	
			// thumb
			$tmpImg = imagecreatetruecolor( $NewWidth, $NewHeight );
			
			// Check if this image is PNG or GIF, then set if Transparent 
			if ( ($imgInfo[2] == 1) || ($imgInfo[2] == 3) )
			{
				imagealphablending( $tmpImg, false );
				imagesavealpha( $tmpImg, true );
				
				$transparent = imagecolorallocatealpha( $tmpImg, 255, 255, 255, 127 );
				
				imagefilledrectangle( $tmpImg, 0, 0, $NewWidth, $NewHeight, $transparent );
			}
			
			imagecopyresampled( $tmpImg, $srcImg, 0, 0, 0, 0, $NewWidth, $NewHeight, $widthImg, $heightImg );
			
			switch ( $imgInfo[2] )
			{
				case 1: $srcImg = imagegif( $tmpImg, $targetImageFileName ); break;
				case 2: $srcImg = imagejpeg( $tmpImg, $targetImageFileName, 100 ); break;
				case 3: $srcImg = imagepng( $tmpImg, $targetImageFileName, 5 ); break;
			}
			
			imagedestroy( $tmpImg );
			
			return true;
		}
		return false;
	}
	
	// --------------------------------------------------------------------------------
	/* Retrive Video Thumbnails
	Each YouTube video has 4 generated images. The first is a full size cover image and the rest are thumbnail images:
		480x360: http://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg
		120x90 : http://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg
		120x90 : http://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg
		120x90 : http://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg
	The default thumbnail image (ie. one of 0.jpg, 1.jpg, 2.jpg, 3.jpg) is:
		120x90 : http://img.youtube.com/vi/<insert-youtube-video-id-here>/default.jpg
	For the high quality version and medium quality version of the thumbnail:
		480x360: http://img.youtube.com/vi/<insert-youtube-video-id-here>/hqdefault.jpg
		320x180: http://img.youtube.com/vi/<insert-youtube-video-id-here>/mqdefault.jpg
	For the maximum resolution version of the thumbnail, the size depends on the video quality:
		http://img.youtube.com/vi/<insert-youtube-video-id-here>/maxresdefault.jpg
	*/
	function getVideoImage( $vurl, $quality = '0' /*YouTube: default, 0, 1, 2, 3 */ )
	{
		$image_url = parse_url( $vurl );
		
		if ( ( $vurl == '' ) || !isset( $image_url['host'] ) )
		{
			return '';
		}
		
		// Test if the link is for youtube
		if ($image_url['host'] == 'www.youtube.com' || $image_url['host'] == 'youtube.com' )
		{
			$array = explode("&", $image_url['query']);
			return "http://img.youtube.com/vi/".substr($array[0], 2)."/".$quality.".jpg"; // Returns the largest Thumbnail
		// Test if the link is for the shortened youtube share link
		}
		else if ( $image_url['host'] == 'www.youtu.be' || $image_url['host'] == 'youtu.be' ) 
		{
			$array = ltrim($image_url['path'],'/');
			return "http://img.youtube.com/vi/". $array ."/".$quality.".jpg"; // Returns the largest Thumbnail
		// Test if the link is for vimeo
		}
		else if ( $image_url['host'] == 'www.vimeo.com' || $image_url['host'] == 'vimeo.com' ) 
		{
			//$hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/".substr($image_url['path'], 1).".php"));
			//return $hash[0]["thumbnail_medium"]; // Returns the medium Thumbnail
			
			$url = parse_url($vurl);
			if($url['host'] !== 'vimeo.com' &&
					$url['host'] !== 'www.vimeo.com')
				return false;
		   if (preg_match('~^http://(?:www\.)?vimeo\.com/(?:clip:)?(\d+)~', $vurl, $match)) 
		   {
			   $id = $match[1];
		   }
		   else
		   {
			   $id = substr($link,10,strlen($link));
		   }
		
		   if (!function_exists('curl_init')) die('CURL is not installed!');
		   $ch = curl_init();
		   curl_setopt($ch, CURLOPT_URL, "http://vimeo.com/api/v2/video/$id.php");
		   curl_setopt($ch, CURLOPT_HEADER, 0);
		   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		   curl_setopt($ch, CURLOPT_TIMEOUT, 10);
		   $output = unserialize(curl_exec($ch));
		   $output = $output[0];
		   curl_close($ch);
		   return $output["thumbnail_large"];
		}
	}
	
	// --------------------------------------------------------------------------------
	// Retrieve Video Embed Code
	function getVideoEmbed( $vurl, $width='100%', $height='' )
	{
		if ( $vurl == '' )
			return '';

		$image_url = parse_url( $vurl );
		// Test if the link is for youtube
		if ( isset($image_url['host']) && ( $image_url['host'] == 'www.youtube.com' || $image_url['host'] == 'youtube.com' ) )
		{
			$array = explode("&", $image_url['query']);
			return '<iframe src="http://www.youtube.com/embed/' . substr($array[0], 2) . '?wmode=transparent" width="'.$width.'" height="'.$height.'" frameborder="0" allowfullscreen></iframe>'; // Returns the youtube iframe embed code
		// Test if the link is for the shortened youtube share link
		}
		else if ( isset($image_url['host']) && ( $image_url['host'] == 'www.youtu.be' || $image_url['host'] == 'www.youtu.be' ) )
		{
			$array = ltrim($image_url['path'],'/');
			return '<iframe src="http://www.youtube.com/embed/' . $array . '?wmode=transparent" width="'.$width.'" height="'.$height.'" frameborder="0" allowfullscreen></iframe>'; // Returns the youtube iframe embed code
		// Test if the link is for vimeo
		}
		else if ( isset($image_url['host']) && ( $image_url['host'] == 'www.vimeo.com' || $image_url['host'] == 'www.vimeo.com' ) )
		{
			$hash = substr($image_url['path'], 1);
			return '<iframe src="http://player.vimeo.com/video/' . $hash . '?title=0&byline=0&portrait=0" width="'.$width.'" height="'.$height.'" frameborder="0" webkitAllowFullScreen allowfullscreen></iframe>'; // Returns the vimeo iframe embed code
		}
	}
	
	// --------------------------------------------------------------------------------
	// Text
	// --------------------------------------------------------------------------------
	
	function clearUTF( $s )
	{
		setlocale(LC_ALL, 'en_US.UTF8');
		
		$r = '';
		$s1 = iconv('UTF-8', 'ASCII//TRANSLIT', $s);
		for ($i = 0; $i < strlen($s1); $i++)
		{
			$ch1 = $s1[$i];
			$ch2 = mb_substr($s, $i, 1);
	
			$r .= $ch1=='?'?$ch2:$ch1;
		}
		return $r;
	}

	// --------------------------------------------------------------------------------
	
	function friendly_url( $nadpis )
	{
		$url = $nadpis;
		$url = preg_replace("~[^\\pL0-9_\/]+~u", "-", $url);
		$url = trim($url, "-");
		$url = clearUTF($url);// iconv("utf-8", "us-ascii//TRANSLIT", $url);
		$url = strtolower($url);
		$url = str_replace("'", "", $url);
		$url = str_replace("/", "-", $url);
		//$url = preg_replace('~[^-a-z0-9_]+~', '', $url);

		return $url;
	}
	
	// --------------------------------------------------------------------------------
	
	function url_removeQueryString( $url )
	{
		$p = strpos( $url, '?' );
		
		if ( $p !== false )
			$url = substr( $url, 0, $p );
			
		return $url;
	}
	
	// --------------------------------------------------------------------------------
	function shortenText( $str, $len, $cut = false )
	{
		if ( strlen( $str ) <= $len ) return $str;
   
   		return ( $cut ? substr( $str, 0, $len ) : substr( $str, 0, strrpos( substr( $str, 0, $len ), ' ' ) ) ) . '&hellip;';	
	}
		
	// --------------------------------------------------------------------------------
	function fuckOffOrphans( $textWithOrphans )
	{
		$old_str = array(" s ", " z ", " a ", " o ", " v ", " i ", " k ", " u ", " e ");
		$new_str = array(" s&nbsp;", " z&nbsp;", " a&nbsp;", " o&nbsp;", " v&nbsp;", " i&nbsp;", " k&nbsp;", " u&nbsp;", " e&nbsp;");
		
		$textWithoutOrphans = str_replace( $old_str, $new_str, $textWithOrphans );
		
		return $textWithoutOrphans;
	}
	
	// --------------------------------------------------------------------------------
	function fuckOffHTMLspecialChars( $textWithHTMLspecialChars )
	{
		$new_str = array(
'Á', 
'á',
'À',
'Â',
'à',
'Â',
'â',
'Ä',
'ä',
'Ã',
'ã',
'Å',
'å',
'Æ',
'æ',
'Ç',
'ç',
'Ð',
'ð',
'É',
'é',
'È',
'è',
'Ê',
'ê',
'Ë',
'ë',
'Í',
'í',
'Ì',
'ì',
'Î',
'î',
'Ï',
'ï',
'Ñ',
'ñ',
'Ó',
'ó',
'Ò',
'ò',
'Ô',
'ô',
'Ö',
'ö',
'Õ',
'õ',
'Ø',
'ø',
'ß',
'Þ',
'þ',
'Ú',
'ú',
'Ù',
'ù',
'Û',
'û',
'Ü',
'ü',
'Ý',
'ý',
'ÿ',
'Š',
'š',
'"',
'"',
'°',
'–',
' ',
'·',
'×',
'•'
);
		$old_str = array(
'&Aacute;',
'&aacute;',
'&Agrave;',
'&Acirc;',
'&agrave;',
'&Acirc;',
'&acirc;',
'&Auml;',
'&auml;',
'&Atilde;',
'&atilde;',
'&Aring;',
'&aring;',
'&Aelig;',
'&aelig;',
'&Ccedil;',
'&ccedil;',
'&Eth;',
'&eth;',
'&Eacute;',
'&eacute;',
'&Egrave;',
'&egrave;',
'&Ecirc;',
'&ecirc;',
'&Euml;',
'&euml;',
'&Iacute;',
'&iacute;',
'&Igrave;',
'&igrave;',
'&Icirc;',
'&icirc;',
'&Iuml;',
'&iuml;',
'&Ntilde;',
'&ntilde;',
'&Oacute;',
'&oacute;',
'&Ograve;',
'&ograve;',
'&Ocirc;',
'&ocirc;',
'&Ouml;',
'&ouml;',
'&Otilde;',
'&otilde;',
'&Oslash;',
'&oslash;',
'&szlig;',
'&Thorn;',
'&thorn;',
'&Uacute;',
'&uacute;',
'&Ugrave;',
'&ugrave;',
'&Ucirc;',
'&ucirc;',
'&Uuml;',
'&uuml;',
'&Yacute;',
'&yacute;',
'&yuml;',
'&Scaron;',
'&scaron;',
'&bdquo;',
'&ldquo;',
'&deg;',
'&ndash;',
'&nbsp;',
'&middot;',
'&times;',
'&bull;'
);
		
		$textWithoutHTMLspecialChars = str_replace( $old_str, $new_str, $textWithHTMLspecialChars );
		
		return $textWithoutHTMLspecialChars;
	}
	
	// --------------------------------------------------------------------------------
	// generate random text
	function randomText( $length=10, $chrs = '1234567890qwertyuiopasdfghjklzxcvbnm' )
	{
		$text = '';
		
		for ( $i = 0; $i < $length; $i++ )
		{
			$text .= $chrs[ mt_rand(0, strlen($chrs)-1) ];
		}
		
		return $text;
	}
	
	// --------------------------------------------------------------------------------
	/**
     * ucfirst UTF-8 aware function
     *
     * @param string $string
     * @return string
     * @see http://ca.php.net/ucfirst
     */
    function my_ucfirst($string, $e ='utf-8')
	{
        if (function_exists('mb_strtoupper') && function_exists('mb_substr') && !empty($string)) {
            $string = mb_strtolower($string, $e);
            $upper = mb_strtoupper($string, $e);
            preg_match('#(.)#us', $upper, $matches);
            $string = $matches[1] . mb_substr($string, 1, mb_strlen($string, $e), $e);
        } else {
            $string = ucfirst($string);
        }
        return $string;
    } 
	
	// --------------------------------------------------------------------------------
	function positive($var)
	{
		return ($var > 0);
	}
	
	
	// --------------------------------------------------------------------------------
	// Arrays
	// --------------------------------------------------------------------------------
	
	function array_sort($array, $on, $order='SORT_DESC')
    {
      $new_array = array();
      $sortable_array = array();
 
      if (count($array) > 0) {
          foreach ($array as $k => $v) {
              if (is_array($v)) {
                  foreach ($v as $k2 => $v2) {
                      if ($k2 == $on) {
                          $sortable_array[$k] = $v2;
                      }
                  }
              } else {
                  $sortable_array[$k] = $v;
              }
          }
 
          switch($order)
          {
              case 'SORT_ASC':   
                  //echo "ASC";
                  asort($sortable_array);
              break;
              case 'SORT_DESC':
                  //echo "DESC";
                  arsort($sortable_array);
              break;
          }
 
          foreach($sortable_array as $k => $v) {
              $new_array[] = $array[$k];
          }
      }
      return $new_array;
    }
	
	// --------------------------------------------------------------------------------
	// a foreach friendly version of array_rand
	function selectRandomIndices($source_array, $count = 1)
	{
		//mt_srand((double) microtime() * 10000000);
		
		if($count > 0)
		{
			if($count == 1)
			{
				$result = array(array_rand($source_array, $count));
			}
			else
			{
				$result = array_rand($source_array, $count);
			}
		}
		else
		{
			$result = array();
		}
	
		return $result;
	}
	
	// --------------------------------------------------------------------------------
	// using the above function to pick random values instead of entries
	function selectRandomEntries($source_array, $count = 1)
	{
		if ( $count > count($source_array) )
			$count = count($source_array);//-1;
		
		$result = array();
		$index_array = selectRandomIndices($source_array, $count);
	
		//echo '<!-- ' . print_r( $index_array , true ) . '-->';
		
		foreach($index_array as $index)
		{
			$result[$index] = $source_array[$index];
		}
	
		return $result;
	}
	
	// --------------------------------------------------------------------------------
	function inObjectArray( $objectArray, $objectProperty, $value )
	{
		if ( count( $objectArray ) > 0 )
		{
			foreach ( $objectArray as $item )
			{
				if ( $item->{$objectProperty} == $value )
				{
					return true;
				}
			}
		}

		return false;
  	}
	
	// --------------------------------------------------------------------------------
	// converts pure string into a trimmed keyed array
	// 'a=>1, b=>23   , $a, c=> 45% , true,d => ab c '
	function stringToKeyedArray( $string, $delimiter = ',', $kv = '=>' )
	{
		if ( $a = explode( $delimiter, $string ) ) 
		{ // create parts
			foreach ( $a as $s ) 
			{ // each part
				if ($s)
				{
					if ( $pos = strpos($s, $kv) )
					{ // key/value delimiter
		  				$ka[ trim( substr($s, 0, $pos) ) ] = trim( substr($s, $pos + strlen($kv)) );
					} 
					else 
					{ // key delimiter not found
						$ka[] = trim( $s );
					}
				}
			}

			return $ka;
		}
	}
	
	// --------------------------------------------------------------------------------
	// remove duplicated items from multidimensional array
	function arrayUnique( $array )
	{
		$results_ = array(); 
		
		foreach ($array as $r)
		{
			$results_[md5(serialize($r))] = $r;
		}
		
		$results_ =  array_values( $results_ );
		
		return $results_;
	}
	
	// --------------------------------------------------------------------------------
	// Date
	// --------------------------------------------------------------------------------
	
	// --------------------------------------------------------------------------------
	// Vrácení českého názvu měsíce
	function cesky_mesic($mesic) {
		static $nazvy = array(1 => 'leden', 'únor', 'březen', 'duben', 'květen', 'červen', 'červenec', 'srpen', 'září', 'říjen', 'listopad', 'prosinec');
		return $nazvy[$mesic];
	}
	
	// --------------------------------------------------------------------------------
	// Vrácení českého názvu dne v týdnu
	
	function cesky_den($den) {
		static $nazvy = array( 1 => 'pondělí', 'úterý', 'středa', 'čtvrtek', 'pátek', 'sobota', 'neděle');
		return $nazvy[$den];
	}
  	function cesky_den_zkratka($den) {
		static $nazvy = array( 1 => 'po', 'út', 'st', 'čt', 'pá', 'so', 'ne');
		return $nazvy[$den];
	}
	
	// --------------------------------------------------------------------------------
	if ( !function_exists('cal_days_in_month') )
	{
		function cal_days_in_month($month, $year)
		{
			if(checkdate((int)$month, 31, $year)) return 31;
			if(checkdate((int)$month, 30, $year)) return 30;
			if(checkdate((int)$month, 29, $year)) return 29;
			if(checkdate((int)$month, 28, $year)) return 28;
			return 0; // error
		}
	}
	
	// --------------------------------------------------------------------------------
	// send mail via SMTP
	function SendMail( $strTo, 
											$strFrom, $strFromName, 
											$strSubject, $strBody,
									 	 	$smtp_server = 'smtp.onebit.cz', $smtp_user = 'admin-sender@321web.cz', $smtp_password = '321MailFromWeb-123', $smtp_port = 587 )
                      //$smtp_server = 'exchange.marevva.cz', $smtp_user = 'web@nadacekrizovatka.cz', $smtp_password = '794Policka-358', $smtp_port = 587 )
	{
		require_once (__DIR__).'/PHPMailer/PHPMailerAutoload.php';
		
		$mail = new PHPMailer;
		
		$strBody = utf8_decode( $strBody );
		
		$mail->CharSet = "UTF-8";//'iso-8859-1';
		$mail->isSMTP();  											// tell the class to use SMTP
		$mail->SMTPAuth = true;                	// enable SMTP authentication
		$mail->SMTPSecure = 'tls';
		$mail->Port = $smtp_port;               // set the SMTP port
		$mail->Host = $smtp_server; 						// SMTP server
		$mail->Username = $smtp_user; 					// SMTP account username
		$mail->Password = $smtp_password;     	// SMTP account password
	
		$mail->setFrom( /*$strFrom*/$mail->Username, $strFromName );
		//$mail->addReplyTo( $strFrom, $strFromName );
		
		$strToEmailArray = explode( ',', $strTo );
		if ( count( $strToEmailArray ) > 0 )
		{
			foreach ( $strToEmailArray as $strToEmailArrayItem )
			{
				$mail->addAddress( trim( $strToEmailArrayItem ) );
			}
		}
		else
		{
			$mail->addAddress( $strTo );
		}
		
		$mail->isHTML( true );
		$mail->Subject = $strSubject;
		$mail->Body = mb_convert_encoding( $strBody, "UTF-8" );
		$mail->AltBody = strip_tags( $strBody );
		
		if ( ( $smtp_server == '' ) || !$mail->send() )
		{
			// keby sa to neodoslalo cez SMTP, tak skúsime starú dobrú php funkciu email()
			$headers  = 'MIME-Version: 1.0' . "\r\n";
			$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
			$headers .= 'From: ' . mb_encode_mimeheader( $strFromName ) . '. <' . $strFrom . "> \r\n";
		  
			return mb_send_mail( $strTo, $strSubject, $strBody, $headers );
		}
		else
		{
			return true;
		}
	}
	
	// --------------------------------------------------------------------------------

?>

ACC SHELL 2018