diff --git a/ajax/importopml.php b/ajax/importopml.php index 3b66bb8e7..5a93567f9 100644 --- a/ajax/importopml.php +++ b/ajax/importopml.php @@ -22,17 +22,25 @@ function bailOut($msg) { OCP\Util::writeLog('news','ajax/importopml.php: '.$msg, OCP\Util::ERROR); exit(); } + function debug($msg) { OCP\Util::writeLog('news','ajax/importopml.php: '.$msg, OCP\Util::DEBUG); } if(!isset($_GET['path'])) { bailOut($l->t('No file path was submitted.')); -} +} require_once('news/opmlparser.php'); -$parser = new OPMLParser(); +$raw = file_get_contents($_GET['path']); + +$parser = new OPMLParser($raw); +$title = $parser->getTitle(); +$count = 0; //number of feeds imported + +OCP\JSON::success(array('data' => array('title'=>$title, 'count'=>$count))); + /* $localpath = OC_Filesystem::getLocalFile($_GET['path']); $tmpfname = tempnam(get_temp_dir(), "occOrig"); diff --git a/js/news.js b/js/news.js index 4bbbc8312..0b5f792ff 100644 --- a/js/news.js +++ b/js/news.js @@ -98,9 +98,11 @@ News={ } else { } - - $.post(OC.filePath('news', 'ajax', 'importopml.php'), { path: path}, function(jsondata){ - OC.dialogs.alert(jsondata.data.message, t('news', 'Success!')); + + $.getJSON(OC.filePath('news', 'ajax', 'importopml.php'), { path: path }, function(jsondata){ + if (jsondata.status == 'success') { + alert(jsondata.data.title); + } }); } diff --git a/opmlparser.php b/opmlparser.php index 0407e0f7e..4918b87b1 100644 --- a/opmlparser.php +++ b/opmlparser.php @@ -1,13 +1,36 @@ +* +* This file is licensed under the Affero General Public License version 3 or later. +* See the COPYING-README file +* +*/ + class OPMLParser { - public $raw; - public $data; + private $raw; + private $body; + private $data; + private $title; + private $error; public function __construct($raw) { $this->raw = $raw; $this->data = array(); + try { + $xml_parser = new SimpleXMLElement($this->raw, LIBXML_NOERROR); + $this->title = (string)$xml_parser->head->title; + $this->body = $xml_parser->body; + } + catch (Exception $e) { + $this->error = $e->getMessage(); + return; + } } public function parse(){ @@ -19,4 +42,11 @@ class OPMLParser { return $this->data; } + public function getTitle() { + return $this->title; + } + + public function getError() { + return $this->error; + } } \ No newline at end of file