With my new knowledge about parsing chunks in revolution from
http://modxcms.com/forums/index.php/topic,31214.0.html I made a quick fix in Ditto for using the new included PHx-processing of revolution:
In ditto.class.php:
<?php
function render($resource, $template, $removeChunk,$dateSource,$dateFormat,$ph=array(),$phx=0,$x=0) {
if (!is_array($resource)) {
return $this->modx->lexicon('resource_array_error');
}
$placeholders = array();
$contentVars = array();
foreach ($resource as $name=>$value) {
$placeholders["$name"] = $value;
//$contentVars["[[*$name]]"] = $value;
}
/* set author placeholder */
if (in_array("author",$this->fields["display"]["custom"])) {
$placeholders['author'] = $this->getAuthor($resource['createdby']);
}
/* set title placeholder */
if (in_array("title",$this->fields["display"]["custom"])) {
$placeholders['title'] = $resource['pagetitle'];
}
/* set sequence placeholder */
if (in_array("ditto_iteration",$this->fields["display"]["custom"])) {
$placeholders['ditto_iteration'] = $x;
}
/* set url placeholder */
if (in_array("url",$this->fields["display"]["custom"])) {
$placeholders['url'] = $this->modx->makeUrl($resource['id'],'','','full');
}
if (in_array("date",$this->fields["display"]["custom"])) {
$timestamp = ($resource[$dateSource] != "0") ? $resource[$dateSource] : $resource["createdon"];
$placeholders['date'] = strftime($dateFormat,$timestamp);
}
if (in_array("content",$this->fields["display"]["db"]) && $this->format != "html") {
$resource['content'] = $this->relToAbs($resource['content'], $this->modx->config['site_url']);
}
if (in_array("introtext",$this->fields["display"]["db"]) && $this->format != "html") {
$resource['introtext'] = $this->relToAbs($resource['introtext'], $this->modx->config['site_url']);
}
$customPlaceholders = $ph;
/* set custom placeholder */
foreach ($ph as $name=>$value) {
if ($name != "*") {
$placeholders[$name] = call_user_func($value[1],$resource, $this);
unset($customPlaceholders[$name]);
}
}
foreach ($customPlaceholders as $name=>$value) {
$placeholders = call_user_func($value,$placeholders);
}
if (count($this->fields["display"]['qe']) > 0) {
$placeholders = $this->renderQELinks($this->template->fields['qe'],$resource,$this->modx->lexicon('edit').' : '.$resource['pagetitle'].' : ',$placeholders);
/* set QE Placeholders */
}
//print_r($placeholders);
/*
if ($phx == 1) {
$PHs = $placeholders;
foreach($PHs as $key=>$output) {
$placeholders[$key] = str_replace( array_keys( $contentVars ), array_values( $contentVars ), $output );
}
unset($PHs);
$phx = new prePHx($template);
$phx->setPlaceholders($placeholders);
$output = $phx->output();
} else {
$output = $this->template->replace($placeholders,$template);
$output = $this->template->replace($contentVars,$output);
}
*/
$output = $this->template->replace($placeholders,$template);
//$output = $this->template->replace($contentVars,$output);
//I think here is something Todo:
if ($removeChunk) {
foreach ($removeChunk as $chunk) {
$output = str_replace('[[$'.$chunk.']]',"",$output);
$output = str_replace($this->modx->getChunk($chunk),"",$output);
/* remove chunk that is not wanted */
}
}
return $output;
}
?>
in template.class.php:
<?php
function replace( $placeholders, $tpl ) {
/*
$keys = array();
$values = array();
foreach ($placeholders as $key=>$value) {
$keys[] = '[[+'.$key.']]';
$values[] = $value;
}
return str_replace($keys,$values,$tpl);
*/
$chunk = $this->modx->newObject('modChunk');
$chunk->setCacheable(false);
$output = $chunk->process($placeholders, $tpl);
return $output;
}
function fetch($tpl){
$template = "";
//if ($this->modx->getChunk($tpl) != "") {
// $template = $this->modx->getChunk($tpl);
if ($chunk= $this->modx->getObject('modChunk', array ('name' => $tpl), true)) {
$template = $chunk->getContent();
} else if(substr($tpl, 0, 6) == "@FILE:") {
$template = $this->get_file_contents(substr($tpl, 6));
} else if(substr($tpl, 0, 6) == "@CODE:") {
$template = substr($tpl, 6);
} else if(substr($tpl, 0, 5) == "@FILE") {
$template = $this->get_file_contents(trim(substr($tpl, 5)));
} else if(substr($tpl, 0, 5) == "@CODE") {
$template = trim(substr($tpl, 5));
} else {
$template = $this->modx->lexicon('missing_placeholders_tpl');
}
return $template;
}
?<
Is that now the way we can do this things?
Bruno