summaryrefslogtreecommitdiffstats
path: root/ajax
diff options
context:
space:
mode:
authorAlessandro Cosentino <cosenal@gmail.com>2012-11-08 12:44:35 -0500
committerAlessandro Cosentino <cosenal@gmail.com>2012-11-08 12:45:16 -0500
commit0dddb38e93b0f2c67c1c611343255ffc5a4fd2e3 (patch)
tree17009908161e7b6110537026bb69be71aab4c423 /ajax
parentc2dfe049465a1e97ca643e54db6b0bbd67d22bf1 (diff)
[News] importopml implemented via eventsource for incremental notifications to client
Diffstat (limited to 'ajax')
-rw-r--r--ajax/importopml.php39
-rw-r--r--ajax/selectfromcloud.php2
-rw-r--r--ajax/uploadopml.php42
3 files changed, 71 insertions, 12 deletions
diff --git a/ajax/importopml.php b/ajax/importopml.php
index 478cc1369..e363254c3 100644
--- a/ajax/importopml.php
+++ b/ajax/importopml.php
@@ -10,31 +10,47 @@
*
*/
+global $eventSource;
+
// Check if we are a user
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('news');
OCP\JSON::callCheck();
-session_write_close();
$l = OC_L10N::get('news');
function bailOut($msg) {
- OCP\JSON::error(array('data' => array('message' => $msg)));
+ global $eventSource;
+ $eventSource->send('error', $msg);
+ $eventSource->close();
OCP\Util::writeLog('news','ajax/importopml.php: '.$msg, OCP\Util::ERROR);
exit();
}
-if (isset($_POST['path'])) {
- $raw = file_get_contents($_POST['path']);
+$eventSource=new OC_EventSource();
+
+require_once 'news/opmlparser.php';
+
+$source = isset( $_REQUEST['source'] ) ? $_REQUEST['source'] : '';
+$path = isset( $_REQUEST['path'] ) ? $_REQUEST['path'] : '';
+
+if($path == '') {
+ bailOut($l->t('Empty filename'));
+ exit();
}
-elseif (isset($_FILES['file'])) {
- $raw = file_get_contents($_FILES['file']['tmp_name']);
+
+if($source == 'cloud') {
+ $raw = file_get_contents($path);
+} elseif ($source == 'local') {
+ $storage = \OCP\Files::getStorage('news');
+ $raw = $storage->file_get_contents($path);
+} else {
+ bailOut($l->t('No source argument passed'));
}
-else {
- bailOut($l->t('No file was submitted.'));
+
+if ($raw == false) {
+ bailOut($l->t('Error while reading file'));
}
-
-require_once 'news/opmlparser.php';
try {
$parsed = OPMLParser::parse($raw);
@@ -119,5 +135,6 @@ function importList($data, $parentid) {
$countsuccess = importList($data, 0);
-OCP\JSON::success(array('data' => array('title'=>$parsed->getTitle(), 'count'=>$parsed->getCount(),
+$eventSource->send('success', array('data' => array('title'=>$parsed->getTitle(), 'count'=>$parsed->getCount(),
'countsuccess'=>$countsuccess)));
+$eventSource->close();
diff --git a/ajax/selectfromcloud.php b/ajax/selectfromcloud.php
index 37d8053cb..eae8f0a81 100644
--- a/ajax/selectfromcloud.php
+++ b/ajax/selectfromcloud.php
@@ -41,5 +41,5 @@ if(!file_exists($localpath)) {
if (file_put_contents($tmpfname, file_get_contents($localpath))) {
OCP\JSON::success(array('data' => array('tmp'=>$tmpfname, 'path'=>$localpath)));
} else {
- bailOut(bailOut('Couldn\'t save temporary image: '.$tmpfname));
+ bailOut($l->t('Couldn\'t save temporary image: ').$tmpfname);
}
diff --git a/ajax/uploadopml.php b/ajax/uploadopml.php
new file mode 100644
index 000000000..d982e0324
--- /dev/null
+++ b/ajax/uploadopml.php
@@ -0,0 +1,42 @@
+<?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
+*
+*/
+
+// Check if we are a user
+OCP\JSON::checkLoggedIn();
+OCP\JSON::checkAppEnabled('news');
+OCP\JSON::callCheck();
+
+$l = OC_L10N::get('news');
+
+function bailOut($msg) {
+ OCP\JSON::error(array('data' => array('message' => $msg)));
+ OCP\Util::writeLog('news','ajax/uploadopml.php: '.$msg, OCP\Util::ERROR);
+ exit();
+}
+
+if (isset($_POST['path'])) {
+ OCP\JSON::success(array('data' => array('source'=> 'cloud', 'path' => $_POST['path'])));
+
+}
+elseif (isset($_FILES['file'])) {
+ $storage = \OCP\Files::getStorage('news');
+ $filename = 'opmlfile.xml';
+ if ($storage->fromTmpFile($_FILES['file']['tmp_name'], $filename)) {
+ OCP\JSON::success(array('data' => array('source'=> 'local', 'path' => $filename)));
+ } else {
+ bailOut('Could not create the temporary file');
+ }
+
+}
+else {
+ bailOut('No file loaded');
+}