<?php

global $options;
$output = '';
$title = get_post_meta($post->ID, 'sidebar_title_below', true);
if (strlen(trim($title)) > 1) {
    $output .= '<h2>' . $title . '</h2>' . "\n";
}
$text = get_post_meta($post->ID, 'sidebar_text_below', true);
if (!empty($text)) {
    if ($options['advanced_page_sidebar_useeditor_textbelow'] == false) {
        $text = wpautop($text);
    }
    $text = do_shortcode($text);
    if (function_exists('mimetypes_to_icons')) {
        $output .= mimetypes_to_icons($text);
    } else {
        $output .= $text;
    }
}
if (!empty($output)) {
    echo '<aside class="widget">' . "\n";
    echo $output;
    echo "</aside>\n";
}
if (strlen(trim($list1)) > 0 || strlen(trim($list2)) > 0) {
    // Es gibt eine Liste
    $output .= '<aside class="widget quicklinks">' . "\n";
    if (strlen(trim($titleblock2)) > 0 || strlen(trim($titleblock1) > 0)) {
        // Zwei Listen mit zwei Überschriften
        $output .= $titleblock1;
        $output .= '<ul class="tagcloud">' . "\n";
        $output .= $list1;
        $output .= '</ul>' . "\n";
        $output .= $titleblock2;
        $output .= '<ul class="tagcloud">' . "\n";
        $output .= $list2;
        $output .= '</ul>' . "\n";
    } else {
        if (strlen(trim($titleblock1)) > 0) {
            $output .= $titleblock1;
        } else {
            $output .= $titleblock2;
        }
        // Eine Liste mit einer Überschrift
        $output .= '<ul class="tagcloud">' . "\n";
        $output .= $list1;
        $output .= $list2;
        $output .= '</ul>' . "\n";
    }
    $output .= '</aside>' . "\n";
}
if (function_exists('mimetypes_to_icons')) {
    $output = mimetypes_to_icons($output);
}
echo $output;