Skip to content

Instantly share code, notes, and snippets.

@andyjones
Created January 22, 2018 14:09
Show Gist options
  • Save andyjones/d0b03cd85ad7b70e84f357bb8f320d65 to your computer and use it in GitHub Desktop.
Save andyjones/d0b03cd85ad7b70e84f357bb8f320d65 to your computer and use it in GitHub Desktop.

Revisions

  1. andyjones created this gist Jan 22, 2018.
    103 changes: 103 additions & 0 deletions display-entry.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,103 @@
    <?php
    function initialiseSymphony() {
    // Config hacks (not required in symphony 2.7)
    date_default_timezone_set('UTC');

    // Find out where we are:
    define('DOCROOT', __DIR__);

    // Propagate this change to all executables:
    chdir(DOCROOT);

    // Include autoloader if present
    $autoloader = DOCROOT . '/vendor/autoload.php';
    if ( file_exists($autoloader) ) {
    require_once $autoloader;
    }

    // Include the boot script:
    require_once DOCROOT . '/symphony/lib/boot/bundle.php';

    // Set some globals
    require_once CORE . "/class.frontend.php";
    Frontend::instance();
    Lang::initialize();
    Lang::set("en", false);
    }

    // Returns the debug xml for a given entry id
    function buildEntryXML($entry_id) {
    $entries = EntryManager::fetch($entry_id);
    $xml = new XMLElement('root');

    foreach ($entries as $entry) {
    $xEntry = new XMLElement('entry');
    $xEntry->setAttribute('id', $entry->get('id'));

    foreach ($entry->getData() as $field_id => $data) {
    $field = FieldManager::fetch($field_id);
    $field->appendFormattedElement($xEntry, $data, false, '*', $entry->get('id'));
    }

    $xml->appendChild($xEntry);
    }

    return $xml->generate(true, 0);
    }

    // takes a CSV like string (comma or white space separated)
    // and returns an array of fields
    function splitCSV($string) {
    return preg_split("/[\s,]+/", $string, null, PREG_SPLIT_NO_EMPTY);
    }

    initialiseSymphony();

    ?>
    <html>
    <head>
    <title>Symphony debug page</title>
    <style type="text/css">
    body {
    font: 'Grande',Leelawadee,Tahoma,Verdana,sans-serif;
    color: #222;
    font-size: 10px;
    }

    code {
    font: 100%/1.5 Monaco,Consolas,'Andale Mono',monospace;
    white-space: pre;
    }

    .log-list {
    font: 100%/1.5 Monaco,Consolas,'Andale Mono',monospace;
    }
    </style>
    </head>
    <body>

    <h3>Entry</h3>

    <form method="GET">
    <input name="entry_ids" value="<?= htmlspecialchars($_REQUEST['entry_ids']) ?>">
    <input type="submit">
    </form>

    <?php foreach (splitCSV($_REQUEST['entry_ids']) as $entry_id) { ?>

    <h3>Entry <?= htmlspecialchars($entry_id) ?></h3>

    <code><?= htmlspecialchars(buildEntryXML($entry_id)) ?></code>

    <?php } ?>

    <h3>DB queries</h3>

    <ol class="log-list">
    <?php foreach (Symphony::Database()->debug() as $entry) { ?>
    <li><?= htmlspecialchars($entry['query']) ?></li>

    <?php } ?>
    </ol>

    </body>