summaryrefslogtreecommitdiffstats
path: root/app/classes/OpmlManager.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/classes/OpmlManager.php')
-rw-r--r--app/classes/OpmlManager.php50
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');
+ }
+}