Display post formats differently on index.php (loop in function)

The best way to do this is get the post format and then use the switch statement, like this:

$my_format = get_post_format ();
switch ($my_format) {
    case 'quote': $htmlcontent = ... ; break;
    case 'aside': $htmlcontent = ... ; break;
    and so on
    }

The function that builds up $htmlcontent starts with declaring some building blocks that are used later on (from $timeformat to $firsttext). You can improve on this by setting up larger blocks. The code as it is now, for instance, would already be better if it had blocks like this:

$post-title="<header class="content">
                       <h2 class="post-title"><a href="". get_permalink(get_the_ID()) .'">'. get_the_title() .'</a></h2>
                   </header>';

This code is now duplicated, which is never a good idea.