diff options
author | nashe <thomas@chauchefoin.fr> | 2017-10-21 13:30:15 +0200 |
---|---|---|
committer | nashe <thomas@chauchefoin.fr> | 2017-10-21 13:30:15 +0200 |
commit | 351009241bbe0864670c79fd78b5e95271cc6c2f (patch) | |
tree | 1fe11d960daa3da772971386b87480a9854962bc /app/classes/OpmlManager.php | |
parent | 1b341502ba68092b444a7870d601537eec68b344 (diff) | |
download | planet-3510092.tar planet-3510092.tar.gz planet-3510092.tar.bz2 planet-3510092.tar.xz planet-3510092.zip |
Improve project structure
Diffstat (limited to 'app/classes/OpmlManager.php')
-rw-r--r-- | app/classes/OpmlManager.php | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/app/classes/OpmlManager.php b/app/classes/OpmlManager.php new file mode 100644 index 0000000..02491a2 --- /dev/null +++ b/app/classes/OpmlManager.php @@ -0,0 +1,50 @@ +<?php + + +class OpmlManager +{ + public static function load($file) + { + if (!file_exists($file)) { + throw new Exception('OPML file not found!'); + } + + $opml = new opml(); + + //Remove BOM if needed + $BOM = '/^/'; + $fileContent = file_get_contents($file); + $fileContent = preg_replace($BOM, '', $fileContent, 1); + + //Parse + $opml->parse($fileContent); + + return $opml; + } + + /** + * @param Opml $opml + * @param string $file + */ + public static function save($opml, $file){ + $out = '<?xml version="1.0"?>'."\n"; + $out.= '<opml version="1.1">'."\n"; + $out.= '<head>'."\n"; + $out.= '<title>'.htmlspecialchars($opml->getTitle()).'</title>'."\n"; + $out.= '<dateCreated>'.date('c').'</dateCreated>'."\n"; + $out.= '<dateModified>'.date('c').'</dateModified>'."\n"; + $out.= '</head>'."\n"; + $out.= '<body>'."\n"; + foreach ($opml->entries as $person) { + $out.= '<outline text="' . htmlspecialchars($person['name'], ENT_QUOTES) . '" htmlUrl="' . htmlspecialchars($person['website'], ENT_QUOTES) . '" xmlUrl="' . htmlspecialchars($person['feed'], ENT_QUOTES) . '" isDown="' . htmlspecialchars($person['isDown'], ENT_QUOTES) . '"/>'."\n"; + } + $out.= '</body>'."\n"; + $out.= '</opml>'; + + file_put_contents($file, $out); + } + + public static function backup($file){ + copy($file, $file.'.bak'); + } +} |