]> source.dussan.org Git - nextcloud-server.git/commitdiff
Contacts: In app import (for Chrome and Firefox only)
authorThomas Tanghus <thomas@tanghus.net>
Mon, 23 Apr 2012 23:43:21 +0000 (01:43 +0200)
committerThomas Tanghus <thomas@tanghus.net>
Mon, 23 Apr 2012 23:44:07 +0000 (01:44 +0200)
apps/contacts/ajax/uploadimport.php
apps/contacts/import.php
apps/contacts/js/contacts.js

index 08bc436bc58178dec2a9801a5f86259eff726b38..ab680c8823f7744d1a3b5aa5af983bfd687f044b 100644 (file)
@@ -37,16 +37,9 @@ function debug($msg) {
 // If it is a Drag'n'Drop transfer it's handled here.
 $fn = (isset($_SERVER['HTTP_X_FILE_NAME']) ? $_SERVER['HTTP_X_FILE_NAME'] : false);
 if($fn) {
-       /*$dir = OC_App::getStorage('contacts');
-       $handle = $dir->touch(''.$fn);
-       if(!$handle) {
-               bailOut('Bugger!');
-       } else {
-               bailOut('Yippie!');
-       }
-       debug('Internal path: '.$dir->getInternalPath());*/
+       $view = OC_App::getStorage('contacts');
        $tmpfile = md5(rand());
-       if(OC_Filesystem::file_put_contents('/'.$tmpfile, file_get_contents('php://input'))) {
+       if($view->file_put_contents('/'.$tmpfile, file_get_contents('php://input'))) {
                debug($fn.' uploaded');
                OC_JSON::success(array('data' => array('path'=>'', 'file'=>$tmpfile)));
        } else {
index c98e46995ff5416181eaf969b40d46d3a91687d3..93af7e628140dca7d2d7eae260442e4f80b0e716 100644 (file)
@@ -17,8 +17,14 @@ if(is_writable('import_tmp/')){
        fwrite($progressfopen, '10');
        fclose($progressfopen);
 }
-$file = OC_Filesystem::file_get_contents($_POST['path'] . '/' . $_POST['file']);
-if($_POST['method'] == 'new'){
+$view = $file = null;
+if(isset($_POST['fstype']) && $_POST['fstype'] == 'OC_FilesystemView') {
+       $view = OC_App::getStorage('contacts');
+       $file = $view->file_get_contents('/' . $_POST['file']);
+} else {
+       $file = OC_Filesystem::file_get_contents($_POST['path'] . '/' . $_POST['file']);
+}
+if(isset($_POST['method']) && $_POST['method'] == 'new'){
        $id = OC_Contacts_Addressbook::add(OC_User::getUser(), $_POST['addressbookname']);
        OC_Contacts_Addressbook::setActive($id, 1);
 }else{
@@ -121,10 +127,9 @@ sleep(3);
 if(is_writable('import_tmp/')){
        unlink($progressfile);
 }
-if(isset($_POST['istmpfile'])) {
-       OC_Log::write('contacts','Import: Unlinking '.$_POST['path'] . '/' . $_POST['file'], OC_Log::ERROR);
-       if(!OC_Filesystem::unlink($_POST['path'] . '/' . $_POST['file'])) {
-               OC_Log::write('contacts','Import: Error unlinking '.$_POST['path'] . '/' . $_POST['file'], OC_Log::ERROR);
+if(isset($_POST['fstype']) && $_POST['fstype'] == 'OC_FilesystemView') {
+       if(!$view->unlink('/' . $_POST['file'])) {
+               OC_Log::write('contacts','Import: Error unlinking OC_FilesystemView ' . '/' . $_POST['file'], OC_Log::ERROR);
        }
 }
 OC_JSON::success(array('data' => array('imported'=>$imported, 'failed'=>$failed)));
index f471a7f25aab72da1d3cd3cbcf500c7a357f2291..a3e1a1361dfa0c4cc8d00ca68fbbbd932d821081 100644 (file)
@@ -1348,16 +1348,12 @@ Contacts={
                                this.droptarget = $('#import_drop_target');
                                console.log($('#import_drop_target').html());
                                $(this.droptarget).bind('dragover',function(event){
-                                       //console.log('dragover');
                                        $(event.target).addClass('droppable');
                                        event.stopPropagation();
                                        event.preventDefault();  
                                });
                                $(this.droptarget).bind('dragleave',function(event){
-                                       //console.log('dragleave');
                                        $(event.target).removeClass('droppable');
-                                       //event.stopPropagation();
-                                       //event.preventDefault();  
                                });
                                $(this.droptarget).bind('drop',function(event){
                                        event.stopPropagation();
@@ -1421,12 +1417,11 @@ Contacts={
                                var tr = $(document.createElement('tr'))
                                        .load(OC.filePath('contacts', 'ajax', 'importaddressbook.php'));
                                $(object).closest('tr').after(tr).hide();
-                               //this.loadImportHandlers();
                        },
                        doImport:function(path, file){
                                var id = $('#importaddressbook_dialog').find('#book').val();
                                console.log('Selected book: ' + id);
-                               $.post(OC.filePath('contacts', '', 'import.php'), { id: id, path: path, file: file, istmpfile: true },
+                               $.post(OC.filePath('contacts', '', 'import.php'), { id: id, path: path, file: file, fstype: 'OC_FilesystemView' },
                                        function(jsondata){
                                                if(jsondata.status == 'success'){
                                                        Contacts.UI.Addressbooks.droptarget.html(t('contacts', 'Import done. Success/Failure: ')+jsondata.data.imported+'/'+jsondata.data.failed);
@@ -1478,7 +1473,6 @@ Contacts={
                                        }
                                        else{
                                                OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
-                                               //alert(jsondata.data.message);
                                        }
                                });
                                setTimeout(Contacts.UI.Contacts.lazyupdate, 500);