summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlessandro Cosentino <cosenal@gmail.com>2012-07-30 02:24:38 -0400
committerAlessandro Cosentino <cosenal@gmail.com>2012-07-30 02:24:38 -0400
commita5438863a4e88fb5c9e166e8810f493a1feb2cf0 (patch)
tree5239bdede220fdd4a74f988fa3493cc86b0f33c7
parent0812aadc7b1eaf45afd8a56640cc5de84d0e3dd7 (diff)
parses opml file to get the title
-rw-r--r--ajax/importopml.php12
-rw-r--r--js/news.js8
-rw-r--r--opmlparser.php34
3 files changed, 47 insertions, 7 deletions
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 @@
<?php
+/**
+* ownCloud - News app
+*
+* @author Alessandro Cosentino
+* Copyright (c) 2012 - Alessandro Cosentino <cosenal@gmail.com>
+*
+* 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