SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/Helpers/DocImport/DocImportPlaintext.php

  1. <?php
  2. /*
  3.  * Copyright (C) 2017 Karmabunny Pty Ltd.
  4.  *
  5.  * This file is a part of SproutCMS.
  6.  *
  7.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation, either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * For more information, visit <http://getsproutcms.com>.
  12.  */
  13.  
  14. namespace Sprout\Helpers\DocImport;
  15.  
  16. use Sprout\Helpers\Enc;
  17. use Sprout\Helpers\Text;
  18.  
  19.  
  20. class DocImportPlaintext extends DocImport {
  21.  
  22. /**
  23.   * The main load function for a document.
  24.   * Throw an exception on error.
  25.   *
  26.   * @param string $filename The file. The file will exist, but may not be valid
  27.   * @return string|DOMDocument $data Resultant XML data as a string or DOMDocument element
  28.   **/
  29. public function load($filename) {
  30. $text = trim(file_get_contents($filename));
  31.  
  32. $text = Enc::cleanfunky($text);
  33. $text = Text::richtext($text);
  34.  
  35. // The below is an XML file, so convert BRs to valid XML
  36. $text = str_replace('<br>', '<br/>', $text);
  37.  
  38. $out = '<?xml version="1.0" encoding="UTF-8" ?>' . PHP_EOL;
  39. $out .= '<doc><body>';
  40. $out .= $text;
  41. $out .= '</body></doc>';
  42.  
  43. return $out;
  44. }
  45.  
  46. }
  47.