FCK Editor und Diff

am 08.04.2009 - 01:02 Uhr in
Wer das Diff Modul und den FCK Editor verwendet wird eintäuscht sein. HTML Tags und Entities werden unübersichtlich in eine Zeile geschrieben.
Lösung Bearbeitung der node.inc im diff Modul Ordner:
- Html Tags weg: strip_tags
- Entities weg: html_entity_decode
- Zeilen einfügen: str_replace p-Tags
Die Diffs sehen so aus: http://de.consenser.org/node/1778/revisions/view/2780/2911
Links ist alles in Ordnung, rechts wird die Entities nicht umgewandelt, da im folgenden Code, die Zeile für html_entity_decode für new_node fehlt. Würde ich diese Zeile einsetzen wird der diff nicht mehr vollständig angezeigt. Warum? Was ist die Lösung?
Mein aktueller Code sieht so aus:
<?php
/**
* Implementation of hook_diff() for node.module (body and title).
*/
function node_diff(&$old_node, &$new_node) {
$result = array();
$result[] = array(
'name' => t('Title'),
'old' => array($old_node->title),
'new' => array($new_node->title),
'format' => array(
'show_header' => false,
)
);
// Make a diff depending on the diff type of the node.
$body = $old_node->body;
$body = str_replace('<p>',"\n",$body);
$body = str_replace('</p>',' ',$body);
$body = strip_tags($body);
$body = html_entity_decode($body);
$old_node->body = $body;
$body = $new_node->body;
$body = str_replace('<p>',"\n",$body);
$body = str_replace('</p>',' ',$body);
$body = strip_tags($body);
$new_node->body = $body;
$result[] = array(
'name' => t('Body'),
'old' => explode("\n", $old_node->body),
'new' => explode("\n", $new_node->body),
);
return $result;
}
- Anmelden oder Registrieren um Kommentare zu schreiben
Wenn Dein Post eine Frage sein sollte ...
am 08.04.2009 - 01:35 Uhr
HTML Tags und Entities werden unübersichtlich in eine Zeile geschrieben
Das ist selbst organisiert:
<?php
$body = str_replace('<p>',"\n",$body);
$body = str_replace('</p>',' ',$body);
?>
------------------------
Quiptime Group
Hallo quiptime
am 08.04.2009 - 08:13 Uhr
schön von Dir ein Lebenszeichen zu bekommen. Wir vermissen Dich Dienstag im DVC.
Ich habe die ursprüngliche node.inc wieder aktiviert, damit man das Problem sieht.
Wenn ich $old_node aufbereite, sieht es vielversprechend aus (linke Seite -), jedoch wenn ich das selbe für $new_node mache (rechte Seite +), kommt irgendwie Mist raus und ich stehe im Wald. Ich vermute das Problem liegt in meiner nachträglichen Codeaufbereitung, die auch Einfluss auf die Diff Erstellung nimmt. Wie würdest Du weiter vorgehen?
Super neue Webpage! Der Name Quiptime Group klinkt super!
Saludos,
Schnittmenge
Problem gelöst
am 10.04.2009 - 21:56 Uhr
Nach dem die Benutzung von html_entity_decode zu unerwünschte Ergebnisse geführt hat, habe ich jetzt die wichtigsten Entity einfach einzel ersetzt. Jetzt funktioniert es! Beispiel Diff: http://de.consenser.org/node/1854/revisions/view/2985/3002
Der Code:
<?php
// $Id: node.inc,v 1.3 2008/03/05 21:03:17 weitzman Exp $
// ^don't know what to do here^
/*
* Implementation of hook_diff() for node.module (body and title).
modified 2009.04.10 by schnittmenge
*/
function node_diff(&$old_node, &$new_node) {
$result = array();
$type = node_get_types('type', $new_node);
$result['title'] = array(
'name' => $type->title_label,
'old' => array($old_node->title),
'new' => array($new_node->title),
'format' => array(
'show_header' => false,
)
);
// Make a diff depending on the diff type of the node.
if ($type->has_body) {
$result['body'] = array(
'name' => t('Body'),
'old' => explode("\n", node_diff_strip_html($old_node->body)),
'new' => explode("\n", node_diff_strip_html($new_node->body)),
);
}
return $result;
}
/**
* Insert newlines in HTML, replace special characters and remove all tags.
*/
function node_diff_strip_html($text) {
// Replace
$text = str_replace(" ", " ", $text);
// Replace entity
$uml_ersatz = array("ä"=>"ä",
"ö"=>"ö",
"ü"=>"ü",
"Á"=>"Á",
"É"=>"É",
"Í"=>"Í",
"Ñ"=>"Ñ",
"Ó"=>"Ó",
"Ú"=>"Ú",
"á"=>"á",
"é"=>"é",
"í"=>"í",
"ñ"=>"ñ",
"ó"=>"ó",
"ú"=>"ú",
"«"=>"«",
"»"=>"»",
"¿"=>"¿",
"€"=>"€",
"&"=>"&",
"""=>"''",
"§"=>"§",
"ß"=>"ß",
"Ä"=>"Ä",
"Ö"=>"Ö",
"Ü"=>"Ü");
$text = strtr($text,$uml_ersatz);
// Todo: maybe implement a generic solution for encoded symbols using html_entity_decode() - unfortunly does not work!!!
// Replace HTML breaks with newlines
$text = str_replace("<br/>", "\n", $text);
//EFD ADDDED - replace more BR's
//(maybe would work better as an array of tags or module setting)
$text = str_replace("<br />", "\n", $text);
$text = str_replace("<br>", "\n", $text);
// Replace list elements with newlies
$text = str_replace("</li>", "\n", $text);
// Replace paragraphs with newlies
$text = str_replace("</p>", "\n", $text);
// Replace table cells with newlines
$text = str_replace("</td>", "\n", $text);
// Replace divs with newlines
$text = str_replace("</div>", "\n", $text);
$text = str_replace("</h3>", "\n", $text);
$text = str_replace("</h4>", "\n", $text);
// Replace image tags with the image location
// Todo: maybe alt and title attribute can also be displayed
$text = preg_replace('#<img(.*)(src="([^"]+)")([^/]*)/>#', '[image:$3]', $text);
// Replace link tags with the link location
// Todo: maybe title attribute can also be displayed
$text = preg_replace('#<a(.*)(href="([^"]+)")([^>]*)>#', '[link:$3]', $text);
// Replace link endings
$text = str_replace("</a>", "[link]", $text);
// Todo: check if other tags need special treatment as well
// Strip all remaining tags
$text = preg_replace("#</?[a-zA-Z]+(\s[^>]*)?>#", "", $text);
$text = strip_tags($text);
return $text;
}