This is a mockup of how I would like the Ditto 2.0 snippet source code to look like. Please give feedback as to function names and architecture.
<?php
// Ditto 2.0
// PARAMETERS WILL GO HERE
$ditto = new ditto($format,$language,$debug);
// create a new Ditto instance in the specified format and language with the requested debug level
$ditto->loadExtenders($extenders);
// load the requested extenders into the class
$ditto->parseTemplates($templates);
// parse the templates for TV's and store them for later use
$filter = $ditto->parseFilters($textFilter,$dateFilter,$tagFilter);
$documentIDs = $ditto->getDocumentIDs($IDs, $IDType, $ditto->TVs, $sortBy, $sortDir, $depth, $showPublishedOnly, $seeThruUnpub, $hideFolders, $showInMenuOnly, $where, $keywords, $limit, $filter);
// retrieves a list of document IDs that meet the criteria and populates the $resources array with them
$sortOrder = $ditto->setSortOrder($documentIDs);
// saves the order of the documents for use later
if($paginate == 1) {
$documentIDs = $ditto->paginate($documentIDs, $start, $stop, $perPage);
// paginates the documents array so that it only contains a single page worth of documents
$stop = $ditto->stop;
}
$documents = $ditto->getDocuments($documentIDs);
// executes the SQL query but DOES NOT retrieve the row
$output = $ditto->header;
// initialize the output variable and send the header
for ($x=0; $x<$stop; $x++) {
$resource = $ditto->getDocument($document);
// retrieves the row into an associative array
$template = $ditto->determineTPL($templates,$x,$start,$stop,$modx->documentIdentifier);
// choose the template to use and set the code of that template to the template variable
$output .= $ditto->render($resource, $template, $targetIDs, $removeChunk);
// render the output using the correct template, in the correct format and language, with the right target IDs and the correct chunk removed
}
$output .= $ditto->footer;
// send the footer
return $output;
?>