<?php
function dacdb_debug($function_name, $atts, $options, $additional_vars, $xml)
{
    if (!$GLOBALS['fDebug']) {
        return; // Exit if debugging is not enabled
    }

    echo "<h5>function <em><strong>$function_name</strong></em> called:</h5>";

    // Display options
    echo '<h4 class="drawer">Options</h4><pre class="panel">';
    foreach ($options as $key => $value) {
        echo "<dt>\$options['$key']</dt><dd>$value</dd>";
    }
    echo '</pre>';

    // Display shortcode attributes
    if (count($atts) > 0) {
        echo '<h4 class="drawer">Shortcode Attributes</h4><pre class="panel">';
        foreach ($atts as $key => $value) {
            echo "<dt>[\$atts] $key</dt><dd>$value</dd>";
        }
        echo '</pre>';
    }

    // Display additional variables
    if (count($additional_vars) > 0) {
        echo '<h4 class="drawer">Named Variables</h4><pre class="panel">';
        foreach ($additional_vars as $key => $value) {
            // Special handling for XML to format it nicely
            if ($key == 'xml') {
                echo "<dt>\$xml</dt><dd>";
                // Format and display XML
                // ... Add XML formatting and displaying code here ...
                echo "</dd>";
            } else {
                echo "<dt>\$$key</dt><dd>$value</dd>";
            }
        }
        echo '</pre>';
    }    // Display additional variables

    if (count($xml) > 0) {
        echo '<h4 class="drawer">XML Output</h4><div class="panel">';
        foreach ($xml->element as $content) {
            $dom = new DOMDocument();
            $dom->preserveWhiteSpace = false; // Don't preserve whitespaces
            $dom->formatOutput = true; // Format output with indentation and line breaks
            $dom->loadXML($content->asXML()); // Load the XML string from SimpleXMLElement
            $formattedXml = $dom->saveXML(); // Save the formatted XML to a string
            echo '<pre>' . htmlspecialchars($formattedXml) . '</pre>';
        }
        echo '</div>';
    }
}
function dacdb_debug_shortcode($post, $atts)
{
    $pagedata = ''; // Initialize the variable to store debugging information

    // Check if the shortcode exists on the page
    if (has_shortcode($post->post_content, 'dacdb_plus')) {
        // Iterate through the provided parameters
        foreach ($atts as $param => $value) {
            if ($param !== 'show') {
                // $pagedata .= "Parameter: $param with value: $value<br>";
            }
        }

        // Display the shortcode name and its attributes
        $shortcode_name = 'dacdb_plus';
        $pagedata .= "<code>[$shortcode_name";
        foreach ($atts as $param => $value) {
            $pagedata .= " $param=\"$value\"";
        }
        $pagedata .= "]</code>";
    } else {
        // Shortcode not found on the page
        $pagedata .= "<code>[dacdb_plus]</code> shortcode not found on the page";
    }

    return $pagedata;
}