From 000f77224c3c5b1b119cb59717a0deaf58051511 Mon Sep 17 00:00:00 2001 From: Garvin Hicking Date: Thu, 24 Nov 2011 12:21:40 +0100 Subject: [PATCH] nl2br plugin by ophian --- docs/NEWS | 2 + .../UTF-8/lang_bg.inc.php | 22 +- .../UTF-8/lang_cs.inc.php | 24 +- .../UTF-8/lang_cz.inc.php | 24 +- .../UTF-8/lang_de.inc.php | 11 +- .../UTF-8/lang_tn.inc.php | 32 +-- .../serendipity_event_nl2br/lang_bg.inc.php | 22 +- .../serendipity_event_nl2br/lang_cs.inc.php | 24 +- .../serendipity_event_nl2br/lang_cz.inc.php | 24 +- .../serendipity_event_nl2br/lang_de.inc.php | 11 +- .../serendipity_event_nl2br/lang_en.inc.php | 17 +- .../serendipity_event_nl2br/lang_tn.inc.php | 32 +-- .../serendipity_event_nl2br.php | 208 ++++++++++++++---- 13 files changed, 301 insertions(+), 152 deletions(-) diff --git a/docs/NEWS b/docs/NEWS index 9004ffe8..047e61a4 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -4,6 +4,8 @@ Version 1.7 () ------------------------------------------------------------------------ + * Updated nl2br plugin (ophian) + * EXPERIMENTAL: Smarty3 support (ophian) * Added new serendipity['defaultBaseURL'] variable that makes sure diff --git a/plugins/serendipity_event_nl2br/UTF-8/lang_bg.inc.php b/plugins/serendipity_event_nl2br/UTF-8/lang_bg.inc.php index 390d3ce5..981981bc 100644 --- a/plugins/serendipity_event_nl2br/UTF-8/lang_bg.inc.php +++ b/plugins/serendipity_event_nl2br/UTF-8/lang_bg.inc.php @@ -1,11 +1,11 @@ - - * EN-Revision: Revision of lang_en.inc.php - * Translated on 2007/11/30 - * @author Vladimír Ajgl - * @revisionDate 2009/05/06 - * @author Vladimír Ajgl - * @revisionDate 2009/08/15 + + * EN-Revision: Revision of lang_en.inc.php + * Translated on 2007/11/30 + * @author Vladimír Ajgl + * @revisionDate 2009/05/06 + * @author Vladimír Ajgl + * @revisionDate 2009/08/15 */ @define('PLUGIN_EVENT_NL2BR_NAME', 'Markup: NL2BR'); @define('PLUGIN_EVENT_NL2BR_DESC', 'Mění znaky konce řádku na tagy
'); @define('PLUGIN_EVENT_NL2BR_ISOLATE_TAGS', 'Seznam html tagů, uvnitř kterých nemají být konce řádků nahrazovány.'); @define('PLUGIN_EVENT_NL2BR_ISOLATE_TAGS_DESC', 'Návrhy: "code,pre,geshi,textarea". Názvy tagů oddělujte čárkou. Tip: Zadávané tagy jsou vyhodnocovány jako regulární výraz.'); -@define('PLUGIN_EVENT_NL2BR_PTAGS', 'Použít tagy <p>'); +@define('PLUGIN_EVENT_NL2BR_PTAGS', 'Použít tagy <p>'); @define('PLUGIN_EVENT_NL2BR_PTAGS_DESC', 'Vkládat tagy <p> místo tagů <br />'); \ No newline at end of file diff --git a/plugins/serendipity_event_nl2br/UTF-8/lang_cz.inc.php b/plugins/serendipity_event_nl2br/UTF-8/lang_cz.inc.php index c2d1ce8f..58df5121 100644 --- a/plugins/serendipity_event_nl2br/UTF-8/lang_cz.inc.php +++ b/plugins/serendipity_event_nl2br/UTF-8/lang_cz.inc.php @@ -1,19 +1,19 @@ - - * EN-Revision: Revision of lang_en.inc.php - * Translated on 2007/11/30 - * @author Vladimír Ajgl - * @revisionDate 2009/05/06 - * @author Vladimír Ajgl - * @revisionDate 2009/08/15 + + * EN-Revision: Revision of lang_en.inc.php + * Translated on 2007/11/30 + * @author Vladimír Ajgl + * @revisionDate 2009/05/06 + * @author Vladimír Ajgl + * @revisionDate 2009/08/15 */ @define('PLUGIN_EVENT_NL2BR_NAME', 'Markup: NL2BR'); @define('PLUGIN_EVENT_NL2BR_DESC', 'Mění znaky konce řádku na tagy
'); @define('PLUGIN_EVENT_NL2BR_ISOLATE_TAGS', 'Seznam html tagů, uvnitř kterých nemají být konce řádků nahrazovány.'); @define('PLUGIN_EVENT_NL2BR_ISOLATE_TAGS_DESC', 'Návrhy: "code,pre,geshi,textarea". Názvy tagů oddělujte čárkou. Tip: Zadávané tagy jsou vyhodnocovány jako regulární výraz.'); -@define('PLUGIN_EVENT_NL2BR_PTAGS', 'Použít tagy <p>'); +@define('PLUGIN_EVENT_NL2BR_PTAGS', 'Použít tagy <p>'); @define('PLUGIN_EVENT_NL2BR_PTAGS_DESC', 'Vkládat tagy <p> místo tagů <br />'); \ No newline at end of file diff --git a/plugins/serendipity_event_nl2br/UTF-8/lang_de.inc.php b/plugins/serendipity_event_nl2br/UTF-8/lang_de.inc.php index d33127f6..5aa89a57 100644 --- a/plugins/serendipity_event_nl2br/UTF-8/lang_de.inc.php +++ b/plugins/serendipity_event_nl2br/UTF-8/lang_de.inc.php @@ -1,8 +1,15 @@ - als NL2BR Isolations-Default Einstellung, kann die NL2BR Funktion nun so genutzt werden, dass alles innerhalb dieses Tags nicht von NL2BR geparst wird. Auch nicht verschachtelte mehrfach Vorkommen im Text werden unterstützt! Beispiel: do not parse newline to br inside'); +@define('PLUGIN_EVENT_NL2BR_CLEANTAGS', 'Nutze BR-Clean-Tags fallback, wenn ISOBR false'); +@define('PLUGIN_EVENT_NL2BR_CLEANTAGS_DESC', 'Bei Benutzung von in den Einträgen, die nicht zufriedenstellend mit der ISOBR Config-Option gelöst werden können, lösche nl2br Umbruch nach . Dies gilt für alle , die mit > oder >\n enden! Default (table|thead|tbody|tfoot|th|tr|td|caption|colgroup|col|ol|ul|li|dl|dt|dd)'); +@define('PLUGIN_EVENT_NL2BR_CONFIG_ERROR', 'Konfigurations Fehler! Die Option: "clean_tags" wurde zurückgesetzt, weil die Option \'isobr\' aktiv geschaltet war! Benutzen sie bitte nur eine dieser Optionen.'); diff --git a/plugins/serendipity_event_nl2br/UTF-8/lang_tn.inc.php b/plugins/serendipity_event_nl2br/UTF-8/lang_tn.inc.php index 67bfae49..0e396ddb 100644 --- a/plugins/serendipity_event_nl2br/UTF-8/lang_tn.inc.php +++ b/plugins/serendipity_event_nl2br/UTF-8/lang_tn.inc.php @@ -1,17 +1,17 @@ - # -# http://www.jannis.to/programming/serendipity.html # -# # -# Translated by # -# (c) 2004-2005 CapriSkye # -# http://open.38.com # -########################################################################## - - @define('PLUGIN_EVENT_NL2BR_NAME', '標記語言: NL2BR'); - @define('PLUGIN_EVENT_NL2BR_DESC', '轉換新行成 BR 標籤'); + # +# http://www.jannis.to/programming/serendipity.html # +# # +# Translated by # +# (c) 2004-2005 CapriSkye # +# http://open.38.com # +########################################################################## + + @define('PLUGIN_EVENT_NL2BR_NAME', '標記語言: NL2BR'); + @define('PLUGIN_EVENT_NL2BR_DESC', '轉換新行成 BR 標籤'); ?> \ No newline at end of file diff --git a/plugins/serendipity_event_nl2br/lang_bg.inc.php b/plugins/serendipity_event_nl2br/lang_bg.inc.php index 649b8baf..d87ce1ea 100644 --- a/plugins/serendipity_event_nl2br/lang_bg.inc.php +++ b/plugins/serendipity_event_nl2br/lang_bg.inc.php @@ -1,11 +1,11 @@ - - * EN-Revision: Revision of lang_en.inc.php - * Translated on 2007/11/30 - * @author Vladimr Ajgl - * @revisionDate 2009/05/06 - * @author Vladimr Ajgl - * @revisionDate 2009/08/15 + + * EN-Revision: Revision of lang_en.inc.php + * Translated on 2007/11/30 + * @author Vladimr Ajgl + * @revisionDate 2009/05/06 + * @author Vladimr Ajgl + * @revisionDate 2009/08/15 */ @define('PLUGIN_EVENT_NL2BR_NAME', 'Markup: NL2BR'); @define('PLUGIN_EVENT_NL2BR_DESC', 'Mn znaky konce dku na tagy
'); @define('PLUGIN_EVENT_NL2BR_ISOLATE_TAGS', 'Seznam html tag, uvnit kterch nemaj bt konce dk nahrazovny.'); @define('PLUGIN_EVENT_NL2BR_ISOLATE_TAGS_DESC', 'Nvrhy: "code,pre,geshi,textarea". Nzvy tag oddlujte rkou. Tip: Zadvan tagy jsou vyhodnocovny jako regulrn vraz.'); -@define('PLUGIN_EVENT_NL2BR_PTAGS', 'Pout tagy <p>'); +@define('PLUGIN_EVENT_NL2BR_PTAGS', 'Pout tagy <p>'); @define('PLUGIN_EVENT_NL2BR_PTAGS_DESC', 'Vkldat tagy <p> msto tag <br />'); \ No newline at end of file diff --git a/plugins/serendipity_event_nl2br/lang_cz.inc.php b/plugins/serendipity_event_nl2br/lang_cz.inc.php index 4b8b6a57..56b1dfd7 100644 --- a/plugins/serendipity_event_nl2br/lang_cz.inc.php +++ b/plugins/serendipity_event_nl2br/lang_cz.inc.php @@ -1,19 +1,19 @@ - - * EN-Revision: Revision of lang_en.inc.php - * Translated on 2007/11/30 - * @author Vladimr Ajgl - * @revisionDate 2009/05/06 - * @author Vladimr Ajgl - * @revisionDate 2009/08/15 + + * EN-Revision: Revision of lang_en.inc.php + * Translated on 2007/11/30 + * @author Vladimr Ajgl + * @revisionDate 2009/05/06 + * @author Vladimr Ajgl + * @revisionDate 2009/08/15 */ @define('PLUGIN_EVENT_NL2BR_NAME', 'Markup: NL2BR'); @define('PLUGIN_EVENT_NL2BR_DESC', 'Mn znaky konce dku na tagy
'); @define('PLUGIN_EVENT_NL2BR_ISOLATE_TAGS', 'Seznam html tag, uvnit kterch nemaj bt konce dk nahrazovny.'); @define('PLUGIN_EVENT_NL2BR_ISOLATE_TAGS_DESC', 'Nvrhy: "code,pre,geshi,textarea". Nzvy tag oddlujte rkou. Tip: Zadvan tagy jsou vyhodnocovny jako regulrn vraz.'); -@define('PLUGIN_EVENT_NL2BR_PTAGS', 'Pout tagy <p>'); +@define('PLUGIN_EVENT_NL2BR_PTAGS', 'Pout tagy <p>'); @define('PLUGIN_EVENT_NL2BR_PTAGS_DESC', 'Vkldat tagy <p> msto tag <br />'); \ No newline at end of file diff --git a/plugins/serendipity_event_nl2br/lang_de.inc.php b/plugins/serendipity_event_nl2br/lang_de.inc.php index 630a5f6e..19f0380c 100644 --- a/plugins/serendipity_event_nl2br/lang_de.inc.php +++ b/plugins/serendipity_event_nl2br/lang_de.inc.php @@ -1,8 +1,15 @@ - als NL2BR Isolations-Default Einstellung, kann die NL2BR Funktion nun so genutzt werden, dass alles innerhalb dieses Tags nicht von NL2BR geparst wird. Auch nicht verschachtelte mehrfach Vorkommen im Text werden untersttzt! Beispiel: do not parse newline to br inside'); +@define('PLUGIN_EVENT_NL2BR_CLEANTAGS', 'Nutze BR-Clean-Tags fallback, wenn ISOBR false'); +@define('PLUGIN_EVENT_NL2BR_CLEANTAGS_DESC', 'Bei Benutzung von in den Eintrgen, die nicht zufriedenstellend mit der ISOBR Config-Option gelst werden knnen, lsche nl2br Umbruch nach . Dies gilt fr alle , die mit > oder >\n enden! Default (table|thead|tbody|tfoot|th|tr|td|caption|colgroup|col|ol|ul|li|dl|dt|dd)'); +@define('PLUGIN_EVENT_NL2BR_CONFIG_ERROR', 'Konfigurations Fehler! Die Option: "clean_tags" wurde zurckgesetzt, weil die Option \'isobr\' aktiv geschaltet war! Benutzen sie bitte nur eine dieser Optionen.'); diff --git a/plugins/serendipity_event_nl2br/lang_en.inc.php b/plugins/serendipity_event_nl2br/lang_en.inc.php index feead715..c2dfdec5 100644 --- a/plugins/serendipity_event_nl2br/lang_en.inc.php +++ b/plugins/serendipity_event_nl2br/lang_en.inc.php @@ -1,15 +1,22 @@ - * EN-Revision: Revision of lang_en.inc.php */ -@define('PLUGIN_EVENT_NL2BR_NAME', 'Markup: NL2BR'); -@define('PLUGIN_EVENT_NL2BR_DESC', 'Convert newlines to BR tags'); -@define('PLUGIN_EVENT_NL2BR_ISOLATE_TAGS', 'A list of HTML-tags where no breaks shall be converted'); +@define('PLUGIN_EVENT_NL2BR_NAME', 'Markup: NL2BR'); +@define('PLUGIN_EVENT_NL2BR_DESC', 'Convert newlines to BR tags'); +@define('PLUGIN_EVENT_NL2BR_CHECK_MARKUP', 'Check other markup plugins?'); +@define('PLUGIN_EVENT_NL2BR_CHECK_MARKUP_DESC', 'Automaticly check existing markup plugins to disable the use of NL2BR plugin. This is true, when WYSIWYG or specific markup plugins are detected.'); +@define('PLUGIN_EVENT_NL2BR_ISOLATE_TAGS', 'A list of HTML-tags where no breaks shall be converted, if using P-Tags'); @define('PLUGIN_EVENT_NL2BR_ISOLATE_TAGS_DESC', 'Suggestion: "code,pre,geshi,textarea". Seperate multiple tags with a comma. Hint: The entered tags are evaluated as regular expressions.'); @define('PLUGIN_EVENT_NL2BR_PTAGS', 'Use P-Tags'); @define('PLUGIN_EVENT_NL2BR_PTAGS_DESC', 'Insert p-tags instead of br.'); +@define('PLUGIN_EVENT_NL2BR_ISOBR_TAG', 'ISOBR isolations-default BR setting'); +@define('PLUGIN_EVENT_NL2BR_ISOBR_TAG_DESC', 'With this newly added NON-HTML-Tag , as a NL2BR Isolations-Default setting, you can use the NL2BR function now by shutting down the parsing inside this tag. You can use it multiple times inside your entry, but not nested! Example: do not parse newline to br inside'); +@define('PLUGIN_EVENT_NL2BR_CLEANTAGS', 'Use BR-Clean-Tags as fallback, when ISOBR false'); +@define('PLUGIN_EVENT_NL2BR_CLEANTAGS_DESC', 'If using in you entries, which can\'t be solved satisfiable with the ISOBR Config-Option, remove nl2br after . This applies to all ending with > or >\n! Default (table|thead|tbody|tfoot|th|tr|td|caption|colgroup|col|ol|ul|li|dl|dt|dd)'); +@define('PLUGIN_EVENT_NL2BR_CONFIG_ERROR', 'Config missmatch alert! The Option: "clean_tags" is set back to false, while \'isobr\' is active! Just use one of them, please.'); ?> diff --git a/plugins/serendipity_event_nl2br/lang_tn.inc.php b/plugins/serendipity_event_nl2br/lang_tn.inc.php index 67bfae49..0e396ddb 100644 --- a/plugins/serendipity_event_nl2br/lang_tn.inc.php +++ b/plugins/serendipity_event_nl2br/lang_tn.inc.php @@ -1,17 +1,17 @@ - # -# http://www.jannis.to/programming/serendipity.html # -# # -# Translated by # -# (c) 2004-2005 CapriSkye # -# http://open.38.com # -########################################################################## - - @define('PLUGIN_EVENT_NL2BR_NAME', '標記語言: NL2BR'); - @define('PLUGIN_EVENT_NL2BR_DESC', '轉換新行成 BR 標籤'); + # +# http://www.jannis.to/programming/serendipity.html # +# # +# Translated by # +# (c) 2004-2005 CapriSkye # +# http://open.38.com # +########################################################################## + + @define('PLUGIN_EVENT_NL2BR_NAME', '標記語言: NL2BR'); + @define('PLUGIN_EVENT_NL2BR_DESC', '轉換新行成 BR 標籤'); ?> \ No newline at end of file diff --git a/plugins/serendipity_event_nl2br/serendipity_event_nl2br.php b/plugins/serendipity_event_nl2br/serendipity_event_nl2br.php index 680d689f..299cf9ae 100644 --- a/plugins/serendipity_event_nl2br/serendipity_event_nl2br.php +++ b/plugins/serendipity_event_nl2br/serendipity_event_nl2br.php @@ -1,4 +1,4 @@ -add('description', PLUGIN_EVENT_NL2BR_DESC); $propbag->add('stackable', false); $propbag->add('author', 'Serendipity Team'); - $propbag->add('version', '2.0'); + $propbag->add('version', '2.12'); $propbag->add('requirements', array( 'serendipity' => '0.8', 'smarty' => '2.6.7', 'php' => '4.1.0' )); $propbag->add('cachable_events', array('frontend_display' => true)); - $propbag->add('event_hooks', array('frontend_display' => true, - 'css' => true) - ); + + $propbag->add('event_hooks', array('frontend_display' => true, + 'backend_display' => true, + 'css' => true) + ); $propbag->add('groups', array('MARKUP')); $this->markup_elements = array( @@ -45,13 +47,27 @@ class serendipity_event_nl2br extends serendipity_event ) ); - $conf_array = array('isolate', 'p_tags'); + + $conf_array = array('check_markup', 'isolate', 'p_tags', 'isobr', 'clean_tags'); foreach($this->markup_elements as $element) { $conf_array[] = $element['name']; } $propbag->add('configuration', $conf_array); } + function cleanup() { + global $serendipity; + + /* check possible config mismatch setting */ + if ( serendipity_db_bool($this->get_config('isobr')) === true && serendipity_db_bool($this->get_config('clean_tags')) === true ) { + $this->set_config('clean_tags', false); + echo '
'; + echo PLUGIN_EVENT_NL2BR_CONFIG_ERROR . '
'; + return false; + } + return true; + } + function install() { serendipity_plugin_api::hook_event('backend_cache_entries', $this->title); } @@ -68,6 +84,13 @@ class serendipity_event_nl2br extends serendipity_event function introspect_config_item($name, &$propbag) { switch($name) { + case 'check_markup': + $propbag->add('type', 'boolean'); + $propbag->add('name', PLUGIN_EVENT_NL2BR_CHECK_MARKUP); + $propbag->add('description', PLUGIN_EVENT_NL2BR_CHECK_MARKUP_DESC); + $propbag->add('default', 'true'); + break; + case 'isolate': $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_EVENT_NL2BR_ISOLATE_TAGS); @@ -79,7 +102,21 @@ class serendipity_event_nl2br extends serendipity_event $propbag->add('type', 'boolean'); $propbag->add('name', PLUGIN_EVENT_NL2BR_PTAGS); $propbag->add('description', PLUGIN_EVENT_NL2BR_PTAGS_DESC); - $propbag->add('default', 'false'); + $propbag->add('default', 'false'); + break; + + case 'isobr': + $propbag->add('type', 'boolean'); + $propbag->add('name', PLUGIN_EVENT_NL2BR_ISOBR_TAG); + $propbag->add('description', PLUGIN_EVENT_NL2BR_ISOBR_TAG_DESC); + $propbag->add('default', 'true'); + break; + + case 'clean_tags': + $propbag->add('type', 'boolean'); + $propbag->add('name', PLUGIN_EVENT_NL2BR_CLEANTAGS); + $propbag->add('description', PLUGIN_EVENT_NL2BR_CLEANTAGS_DESC); + $propbag->add('default', 'false'); break; default: @@ -105,57 +142,120 @@ class serendipity_event_nl2br extends serendipity_event function event_hook($event, &$bag, &$eventData) { global $serendipity; + static $markup = null; static $isolate = null; static $p_tags = null; + static $isobr = null; + static $clean_tags = null; global $_buf; $hooks = &$bag->get('event_hooks'); + if ($markup === null) { + $markup = serendipity_db_bool($this->get_config('check_markup')); + } + if ($p_tags === null) { $p_tags = serendipity_db_bool($this->get_config('p_tags')); } + if ($isobr === null) { + $isobr = serendipity_db_bool($this->get_config('isobr')); + } + + if ($clean_tags === null) { + $clean_tags = serendipity_db_bool($this->get_config('clean_tags')); + } + if (isset($hooks[$event])) { switch($event) { - case 'frontend_display': - if ($isolate === null) { - $isolate = $this->get_config('isolate'); - $tags = (array)explode(',', $isolate); - $isolate = array(); - foreach($tags AS $tag) { - $tag = trim($tag); - if (!empty($tag)) { - $isolate[] = $tag; + case 'frontend_display': + + // check single entry for temporary disabled markups + if ( !$eventData['properties']['ep_disable_markup_' . $this->instance] && + !in_array($this->instance, (array)$serendipity['POST']['properties']['disable_markups']) && + !$eventData['properties']['ep_no_textile'] && !isset($serendipity['POST']['properties']['ep_no_textile']) && + !$eventData['properties']['ep_no_markdown'] && !isset($serendipity['POST']['properties']['ep_no_markdown'])) { + // yes, this markup shall be applied + $serendipity['nl2br']['entry_disabled_markup'] = false; + } else { + // no, do not apply markup + $serendipity['nl2br']['entry_disabled_markup'] = true; + } + + // don't add additional br or p tags, if the wysiwyg-editor, the textile, or markdown plugin already took care about markup + if($markup) { + if ( ($serendipity['wysiwyg'] && serendipity_userLoggedIn()) || + ($serendipity['nl2br']['entry_disabled_markup'] === false && (class_exists('serendipity_event_textile') || class_exists('serendipity_event_markdown'))) ) { + return true; } } - if (count($isolate) < 1) { - $isolate = false; - } - } - - foreach ($this->markup_elements as $temp) { - if (serendipity_db_bool($this->get_config($temp['name'], true)) && isset($eventData[$temp['element']]) && - !$eventData['properties']['ep_disable_markup_' . $this->instance] && - !in_array($this->instance, (array)$serendipity['POST']['properties']['disable_markups']) && - !$eventData['properties']['ep_no_nl2br'] && - !isset($serendipity['POST']['properties']['ep_no_nl2br'])) { - - $element = $temp['element']; - if ($p_tags) { - $eventData[$element] = $this->nl2p($eventData[$element]); - } else if ($isolate) { - $eventData[$element] = $this->isolate($eventData[$element], '~[<\[](' . implode('|', $isolate) . ').*?[>\]].*?[<\[]/\1[>\]]~si'); - $eventData[$element] = nl2br($eventData[$element]); - $eventData[$element] = $this->restore($eventData[$element]); - } else { - $eventData[$element] = nl2br($eventData[$element]); + // check for users isolation tags + if ($isolate === null) { + $isolate = $this->get_config('isolate'); + $tags = (array)explode(',', $isolate); + $isolate = array(); + foreach($tags AS $tag) { + $tag = trim($tag); + if (!empty($tag)) { + $isolate[] = $tag; + } + } + if (count($isolate) < 1) { + $isolate = false; + } + } + + foreach ($this->markup_elements as $temp) { + if (serendipity_db_bool($this->get_config($temp['name'], true)) && isset($eventData[$temp['element']]) && + !$eventData['properties']['ep_disable_markup_' . $this->instance] && + !in_array($this->instance, (array)$serendipity['POST']['properties']['disable_markups']) && + !$eventData['properties']['ep_no_nl2br'] && + !isset($serendipity['POST']['properties']['ep_no_nl2br'])) { + + $element = $temp['element']; + if ($p_tags) { + $eventData[$element] = $this->nl2p($eventData[$element]); + } else if ($isolate) { + $eventData[$element] = $this->isolate($eventData[$element], '~[<\[](' . implode('|', $isolate) . ').*?[>\]].*?[<\[]/\1[>\]]~si'); + $eventData[$element] = nl2br($eventData[$element]); + $eventData[$element] = $this->restore($eventData[$element]); + } else { + if($isobr) { + $eventData[$element] = $this->isolate($eventData[$element], '~[<\[](nl).*?[>\]].*?[<\[]/\1[>\]]~si'); + $eventData[$element] = nl2br($eventData[$element]); + $eventData[$element] = $this->restore($eventData[$element]); + // unset nl tagline, if is + $eventData[$element] = str_replace(array("", "
", "
", ""), "", $eventData[$element]); + } else { + $eventData[$element] = nl2br($eventData[$element]); + } + } + /* this is an option if not using new isobr default config setting */ + if (!$p_tags && $isobr === false && $clean_tags === true) { + // convert line endings to Unix style, if not already done + $eventData[$element] = str_replace(array("\r\n", "\r"), "\n", $eventData[$element]); + // clean special tags from nl2br + $eventData[$element] = $this->clean_nl2brtags($eventData[$element]); + } } } - } return true; break; - case 'css': + case 'backend_display': + /* + // create some buttons + if( $isobr ) { + // ToDo: hook into default/admin/entries.tpl somehow via the Heart Of Gold = serendipity_printEntryForm() before! it is loaded + $serendipity['smarty']->assign('iso2br', true); + } + */ + + return true; + break; + + case 'css': ?> p.whiteline { @@ -172,7 +272,7 @@ p.break { return true; break; - default: + default: return false; } @@ -181,6 +281,32 @@ p.break { } } + /* clean nl2br from markup where it is invalid and/or breaks html output + * @param string entrytext + * @return string + * */ + function clean_nl2brtags(&$entry) { + $allTags = explode('|', 'table|thead|tbody|tfoot|th|tr|td|caption|colgroup|col|ol|ul|li|dl|dt|dd'); + + $br2nl = array(); + + foreach($allTags as $tag){ + /* for \\1 ( start with : < followed by any number of white spaces : \s* optionally a slash : /? and the tag itself ) + * for \\2 ( anything with spaces and characters following until ) + * for \\3 ( finally the > ) + * for \\4 (
) + * regex modifier : i - using a case-insensitive match, as upper are valid in HTML + * regex modifier : s - using the dot metacharacter in the pattern to match all characters, including newlines */ + $br2nl[] = "%(<\s*/?$tag)(.*?)([^>]*>)()%is"; + } + + if(sizeof($br2nl)) $entry = preg_replace($br2nl, '\\1\\2\\3', $entry); + + return $entry; + } + + + /* Insert