9 * @author Christian Weiske <cweiske@cweiske.de>
10 * @copyright 2014 Christian Weiske
11 * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3
12 * @link http://cweiske.de/grauphel.htm
14 namespace OCA\Grauphel\Converter;
17 * Base class to convert tomboy XML to some other format.
21 * @author Christian Weiske <cweiske@cweiske.de>
22 * @copyright 2014 Christian Weiske
23 * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3
24 * @version Release: @package_version@
25 * @link http://cweiske.de/grauphel.htm
30 * Re-arranges the XML of formatted links to that clean link tags can
33 * Tomboy 1.15.2 allows link formatting, and the resulting XML is a
34 * mess of multiple(!) link tags that are within or around other formatting
37 * This method tries to re-arrange the links so that only a single link tag
38 * appears with all the formatting inside.
40 * @param string $xmlContent Tomboy note content
42 * @return string XML content, with re-arranged link tags.
44 protected function fixNastyLinks($xmlContent)
47 '#(?:<.*>)?<link:internal>.+</link:internal><link:internal>.+</link:internal>#U',
52 foreach ($matches[0] as $nastyLink) {
53 $cleaner = str_replace('</link:internal><link:internal>', '', $nastyLink);
54 $cleaner = preg_replace('#<([a-z]+)><(link:internal)>#U', '<\2><\1>', $cleaner);
55 $cleaner = preg_replace('#</(link:internal)></([a-z]+)>#U', '</\2></\1>', $cleaner);
56 $cleaner = str_replace('</link:internal><link:internal>', '', $cleaner);
57 $xmlContent = str_replace($nastyLink, $cleaner, $xmlContent);