зеркало из https://github.com/nextcloud/news.git
select opml dialog improved
This commit is contained in:
Родитель
42458fad2f
Коммит
1c006551e8
|
@ -0,0 +1,48 @@
|
|||
<?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/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();
|
||||
/*
|
||||
$localpath = OC_Filesystem::getLocalFile($_GET['path']);
|
||||
$tmpfname = tempnam(get_temp_dir(), "occOrig");
|
||||
|
||||
if(!file_exists($localpath)) {
|
||||
bailOut($l->t('File doesn\'t exist:').$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));
|
||||
}*/
|
|
@ -36,26 +36,9 @@ $tmpfname = tempnam(get_temp_dir(), "occOrig");
|
|||
if(!file_exists($localpath)) {
|
||||
bailOut($l->t('File doesn\'t exist:').$localpath);
|
||||
}
|
||||
file_put_contents($tmpfname, file_get_contents($localpath));
|
||||
|
||||
OCP\JSON::success(array('data' => array('tmp'=>$tmpfname)));
|
||||
|
||||
// $image = new OC_Image();
|
||||
// if(!$image) {
|
||||
// bailOut(OC_Contacts_App::$l10n->t('Error loading image.'));
|
||||
// }
|
||||
// if(!$image->loadFromFile($tmpfname)) {
|
||||
// bailOut(OC_Contacts_App::$l10n->t('Error loading image.'));
|
||||
// }
|
||||
// if($image->width() > 400 || $image->height() > 400) {
|
||||
// $image->resize(400); // Prettier resizing than with browser and saves bandwidth.
|
||||
// }
|
||||
// if(!$image->fixOrientation()) { // No fatal error so we don't bail out.
|
||||
// debug('Couldn\'t save correct image orientation: '.$tmpfname);
|
||||
// }
|
||||
// if($image->save($tmpfname)) {
|
||||
// OCP\JSON::success(array('data' => array('tmp'=>$tmpfname)));
|
||||
// exit();
|
||||
// } else {
|
||||
// bailOut('Couldn\'t save temporary image: '.$tmpfname);
|
||||
// }
|
||||
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));
|
||||
}
|
||||
|
|
43
js/news.js
43
js/news.js
|
@ -28,18 +28,23 @@ News={
|
|||
$('#dialog_holder').load(OC.filePath('news', 'ajax', dialogfile), function(jsondata){
|
||||
if(jsondata.status != 'error'){
|
||||
if(dialogtype == '#import_dialog') {
|
||||
$('#cloudbtn').click(function() {
|
||||
//TODO: group all the following calls in a method
|
||||
$('#browsebtn, #cloudbtn, #importbtn').hide();
|
||||
$('#cloudbtn, #cloudlink').click(function() {
|
||||
/*
|
||||
* it needs to be filtered by MIME type, but there are too many MIME types corresponding to opml
|
||||
* and filepicker doesn't support multiple MIME types filter.
|
||||
*/
|
||||
OC.dialogs.filepicker(t('news', 'Select file'), News.UI.cloudFileSelected, false, '', true);
|
||||
OC.dialogs.filepicker(t('news', 'Select file'), News.Opml.cloudFileSelected, false, '', true);
|
||||
});
|
||||
$('#browsebtn,#opml_file').click(function() {
|
||||
$('#browsebtn, #browselink').click(function() {
|
||||
$('#file_upload_start').trigger('click');
|
||||
});
|
||||
$('#file_upload_start').change(function() {
|
||||
News.UI.browseFile(this.files);
|
||||
News.Opml.browseFile(this.files);
|
||||
});
|
||||
$('#importbtn').click(function() {
|
||||
News.Opml.import(this);
|
||||
});
|
||||
}
|
||||
$(dialogtype).dialog({
|
||||
|
@ -55,12 +60,18 @@ News={
|
|||
});
|
||||
}
|
||||
return false;
|
||||
},
|
||||
}
|
||||
},
|
||||
Opml: {
|
||||
importpath:'',
|
||||
importkind:'',
|
||||
cloudFileSelected:function(path){
|
||||
$.getJSON(OC.filePath('news', 'ajax', 'selectfromcloud.php'),{'path':path},function(jsondata){
|
||||
if(jsondata.status == 'success'){
|
||||
$("#opml_file").prop('value', jsondata.data.tmp);
|
||||
|
||||
$('#browsebtn, #cloudbtn, #importbtn').show();
|
||||
$("#opml_file").text(t('news', 'File ') + path + t('news', ' loaded from cloud.'));
|
||||
News.Opml.importkind = 'cloud';
|
||||
News.Opml.importpath = jsondata.data.tmp;
|
||||
}
|
||||
else{
|
||||
OC.dialogs.alert(jsondata.data.message, t('news', 'Error'));
|
||||
|
@ -73,7 +84,25 @@ News={
|
|||
return;
|
||||
}
|
||||
var file = filelist[0];
|
||||
$("#browsebtn, #cloudbtn, #importbtn").show();
|
||||
$("#opml_file").text(t('news', 'File ') + file.name + t('news', ' loaded from local filesystem.'));
|
||||
$("#opml_file").prop('value', file.name);
|
||||
},
|
||||
import:function(button){
|
||||
$(button).attr("disabled", true);
|
||||
$(button).prop('value', t('news', 'Importing...'));
|
||||
|
||||
var path = '';
|
||||
if (News.Opml.importkind == 'cloud') {
|
||||
path = News.Opml.importpath;
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
$.post(OC.filePath('news', 'ajax', 'importopml.php'), { path: path}, function(jsondata){
|
||||
OC.dialogs.alert(jsondata.data.message, t('news', 'Success!'));
|
||||
});
|
||||
|
||||
}
|
||||
},
|
||||
Folder: {
|
||||
|
|
|
@ -10,6 +10,13 @@ class OPMLParser {
|
|||
$this->data = array();
|
||||
}
|
||||
|
||||
public function parse(){
|
||||
|
||||
}
|
||||
|
||||
//TODO: implement an iterator to get data in a fancier way
|
||||
public function getData() {
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
}
|
|
@ -3,9 +3,12 @@
|
|||
<dt><?php echo $l->t('Import'); ?></dt>
|
||||
<dd><button class="svg" id="browsebtn" title="<?php echo $l->t('Upload file from desktop'); ?>" onclick="News.DropDownMenu.fade('ul#feedfoldermenu')"><img class="svg" src="<?php echo OCP\Util::imagePath('core','actions/upload.svg'); ?>" alt="<?php echo $l->t('Upload'); ?>" /></button>
|
||||
<button class="svg" id="cloudbtn" title="<?php echo $l->t('Select file from ownCloud'); ?>"><img class="svg" src="<?php echo OCP\Util::imagePath('core','actions/upload.svg'); ?>" alt="<?php echo $l->t('Select'); ?>" /></button>
|
||||
<input type="text" name="opml_file" id="opml_file" placeholder="<?php echo $l->t('.opml file');?>" />
|
||||
<span id="opml_file">
|
||||
<?php echo $l->t('No file selected. Select file from '); ?><a href='#' id="browselink"><?php echo $l->t('local filesystem');?></a>
|
||||
<?php echo $l->t(' or '); ?><a href='#' id="cloudlink"><?php echo $l->t('cloud');?></a>.
|
||||
</span>
|
||||
<input type="file" id="file_upload_start" name="files[]" />
|
||||
<input type="submit" value="<?php echo $l->t('Import feeds');?>" /></dd>
|
||||
<input style="float: right" id="importbtn" type="submit" value="<?php echo $l->t('Import');?>" /></dd>
|
||||
<dt><?php echo $l->t('Export'); ?></dt>
|
||||
<dd></dd>
|
||||
</dl>
|
Загрузка…
Ссылка в новой задаче