diff options
Diffstat (limited to 'ajax')
-rw-r--r-- | ajax/importopml.php | 39 | ||||
-rw-r--r-- | ajax/selectfromcloud.php | 2 | ||||
-rw-r--r-- | ajax/uploadopml.php | 42 |
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'); +} |