<?php


     /**
      * Div printer
      * @param string $string
      * @return string - HTML <div>{$string}</div>
      */     
     function print_div( $string ){
        print( "<div>" . $string . "</div>" );
     }
     
    /**
     * String Escape
     * @deprecated 
     */
    //function esc( $string , $strip_tags = false  , $allowed_tags = null ){
    
    	//if( $strip_tags ) $string = strip_tags( $string , $allowed_tags );
    
        //if(version_compare(phpversion(),"4.3.0")=="-1") return  mysql_escape_string( $string );
        //else return mysql_real_escape_string( $string );

    //}

    /**
     * @param $string
     * @param bool $strip_tags
     * @param null $allowed_tags
     * @return string
     */
    function esc( $string , $strip_tags = false  , $allowed_tags = null ){

        if( $strip_tags ) $string = strip_tags( $string , $allowed_tags );

            //return db::$i->connection->escape_string( $string );
        return  mysqli_real_escape_string( db::$i->connection , $string );

    }

    function display_memory_unit( $bytes ){
        
    	$units = array('B' => 0, 'KB' => 1, 'MB' => 2, 'GB' => 3, 'TB' => 4, 
    			'PB' => 5, 'EB' => 6, 'ZB' => 7, 'YB' => 8);
     
    	$value = 0;
    	if ($bytes > 0) {
    		// Generate automatic prefix by bytes 
    		// If wrong prefix given
    		if (!array_key_exists($unit, $units)) {
    			$pow = floor(log($bytes)/log(1024));
    			$unit = array_search($pow, $units);
    		}
     
    		// Calculate byte value by prefix
    		$value = ($bytes/pow(1024,floor($units[$unit])));
    	}
     
    	// If decimals is not numeric or decimals is less than 0 
    	// then set default value
    	if (!is_numeric($decimals) || $decimals < 0) {
    		$decimals = 2;
    	}
     
        if( $value <= 0 ) return '0 MB';
     
    	// Format output
    	return sprintf('%.' . $decimals . 'f '.$unit, $value);
    }

    /**
     * Language short
     */
    function l( $text ){

        if( !empty( l::$i->t[md5( $text )] ) ){
            
            return l::$i->t[md5( $text )];
            
        } elseif( !empty( l::$i->t[$text] ) ) {
            
            return l::$i->t[$text];
            
        } else {
            
            l::$i->CreateTranslateFile( $text );
            
                return $text;
        
        }
    }

    /**
     * Zwraca identyfikator uzytkownika
     * @param void
     * @return int user::$i->id - offline = false
     */
    function uid()
    {
        return user::$i->id;
    }
    
    /**
     * URL
     */
    function url(){
        
        global $_cfg;
        
        
    }
    
    /**
     * Short date("Y-m-d H:i:s")
     * @param string $format - Default: Y-m-d H:i:s
     * @return string datetime
     */
    function crt( $format = "Y-m-d H:i:s" ){
        return date( $format );
    }
    
    /**
     * Usuwanie pustych elementów tablicy
     */
    function ArrayClear( $array ){
        $newarray = array();
        foreach( $array as $element ){
            if(!empty($element)) array_push( $newarray , $element );
        }
        
            return $newarray;
    }
    
    
?>