aboutsummaryrefslogtreecommitdiff
path: root/lib/converter/base.php
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2015-03-17 22:03:39 +0100
committerChristian Weiske <cweiske@cweiske.de>2015-03-17 22:03:39 +0100
commita375467d42cb53599ffddbd1d7ce8fae028972f8 (patch)
tree806da86795775a9e889c70fc4283dc5d7b76ab78 /lib/converter/base.php
parent81554f1309cc6a80578100b9583a591012df0d43 (diff)
downloadgrauphel-a375467d42cb53599ffddbd1d7ce8fae028972f8.tar.gz
grauphel-a375467d42cb53599ffddbd1d7ce8fae028972f8.zip
reStructuredText output
Diffstat (limited to 'lib/converter/base.php')
-rw-r--r--lib/converter/base.php63
1 files changed, 63 insertions, 0 deletions
diff --git a/lib/converter/base.php b/lib/converter/base.php
new file mode 100644
index 0000000..2694374
--- /dev/null
+++ b/lib/converter/base.php
@@ -0,0 +1,63 @@
+<?php
+/**
+ * Part of grauphel
+ *
+ * PHP version 5
+ *
+ * @category Tools
+ * @package Grauphel
+ * @author Christian Weiske <cweiske@cweiske.de>
+ * @copyright 2014 Christian Weiske
+ * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3
+ * @link http://cweiske.de/grauphel.htm
+ */
+namespace OCA\Grauphel\Converter;
+
+/**
+ * Base class to convert tomboy XML to some other format.
+ *
+ * @category Tools
+ * @package Grauphel
+ * @author Christian Weiske <cweiske@cweiske.de>
+ * @copyright 2014 Christian Weiske
+ * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3
+ * @version Release: @package_version@
+ * @link http://cweiske.de/grauphel.htm
+ */
+class Base
+{
+ /**
+ * Re-arranges the XML of formatted links to that clean link tags can
+ * be generated.
+ *
+ * Tomboy 1.15.2 allows link formatting, and the resulting XML is a
+ * mess of multiple(!) link tags that are within or around other formatting
+ * tags.
+ *
+ * This method tries to re-arrange the links so that only a single link tag
+ * appears with all the formatting inside.
+ *
+ * @param string $xmlContent Tomboy note content
+ *
+ * @return string XML content, with re-arranged link tags.
+ */
+ protected function fixNastyLinks($xmlContent)
+ {
+ preg_match_all(
+ '#(?:<.*>)?<link:internal>.+</link:internal><link:internal>.+</link:internal>#U',
+ $xmlContent,
+ $matches
+ );
+
+ foreach ($matches[0] as $nastyLink) {
+ $cleaner = str_replace('</link:internal><link:internal>', '', $nastyLink);
+ $cleaner = preg_replace('#<([a-z]+)><(link:internal)>#U', '<\2><\1>', $cleaner);
+ $cleaner = preg_replace('#</(link:internal)></([a-z]+)>#U', '</\2></\1>', $cleaner);
+ $cleaner = str_replace('</link:internal><link:internal>', '', $cleaner);
+ $xmlContent = str_replace($nastyLink, $cleaner, $xmlContent);
+ }
+
+ return $xmlContent;
+ }
+}
+?>