diff options
author | Nicolas Lécureuil <neoclust@mageia.org> | 2020-05-17 14:46:00 +0200 |
---|---|---|
committer | Nicolas Lécureuil <neoclust@mageia.org> | 2020-05-17 14:46:00 +0200 |
commit | e3de9d7dd1331f9718e04cc98e9ca7cfa27cf4aa (patch) | |
tree | 336981502f93ceb9fa5ed33ea3b47dcefc5a8402 /common/app/classes/OpmlManager.php | |
parent | ff32e499745367b816d10f25e63ff3328214c32f (diff) | |
download | planet-user/wally/upstream-10-dev.tar planet-user/wally/upstream-10-dev.tar.gz planet-user/wally/upstream-10-dev.tar.bz2 planet-user/wally/upstream-10-dev.tar.xz planet-user/wally/upstream-10-dev.zip |
Sync with master of moonmoon ( version 9.0.0-rc)HEADuser/wally/upstream-10-devmaster
Source from https://github.com/Emmafrs/moonmoon/
Diffstat (limited to 'common/app/classes/OpmlManager.php')
-rw-r--r-- | common/app/classes/OpmlManager.php | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/common/app/classes/OpmlManager.php b/common/app/classes/OpmlManager.php new file mode 100644 index 0000000..d3940b2 --- /dev/null +++ b/common/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'); + } +} |