Merge branch 'master' of gitorious.org:owncloud/owncloud

This commit is contained in:
Frank Karlitschek 2012-04-24 15:38:36 +02:00
commit a3d0a74d03
11 changed files with 241 additions and 23 deletions

View File

@ -0,0 +1,24 @@
<?php
/**
* Copyright (c) 2012 Georg Ehrke <ownclouddev at georgswebsite dot de>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
require_once('../../../lib/base.php');
OC_JSON::checkLoggedIn();
OC_Util::checkAppEnabled('contacts');
$upload_max_filesize = OC_Helper::computerFileSize(ini_get('upload_max_filesize'));
$post_max_size = OC_Helper::computerFileSize(ini_get('post_max_size'));
$maxUploadFilesize = min($upload_max_filesize, $post_max_size);
$freeSpace=OC_Filesystem::free_space('/');
$freeSpace=max($freeSpace,0);
$maxUploadFilesize = min($maxUploadFilesize ,$freeSpace);
$tmpl = new OC_Template('contacts', 'part.importaddressbook');
$tmpl->assign('uploadMaxFilesize', $maxUploadFilesize);
$tmpl->assign('uploadMaxHumanFilesize', OC_Helper::humanFileSize($maxUploadFilesize));
$tmpl->printpage();
?>

View File

@ -0,0 +1,50 @@
<?php
/**
* ownCloud - Addressbook
*
* @author Thomas Tanghus
* @copyright 2012 Thomas Tanghus <thomas@tanghus.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
// Init owncloud
require_once('../../../lib/base.php');
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
function bailOut($msg) {
OC_JSON::error(array('data' => array('message' => $msg)));
OC_Log::write('contacts','ajax/uploadimport.php: '.$msg, OC_Log::ERROR);
exit();
}
function debug($msg) {
OC_Log::write('contacts','ajax/uploadimport.php: '.$msg, OC_Log::DEBUG);
}
// 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) {
$view = OC_App::getStorage('contacts');
$tmpfile = md5(rand());
if($view->file_put_contents('/'.$tmpfile, file_get_contents('php://input'))) {
debug($fn.' uploaded');
OC_JSON::success(array('data' => array('path'=>'', 'file'=>$tmpfile)));
} else {
bailOut(OC_Contacts_App::$l10n->t('Error uploading contacts to storage.'));
}
}
?>

View File

@ -33,7 +33,8 @@ dl.form { width: 100%; float: left; clear: right; margin: 0; padding: 0; }
.form dd { display: table-cell; clear: right; float: left; margin: 0; padding: 0px; white-space: nowrap; vertical-align: text-bottom; }
#address.form dt { min-width: 5em; }
#address.form dl { min-width: 10em; }
.droptarget { margin: 0.5em; padding: 0.5em; border: thin solid #ccc; -moz-border-radius:.3em; -webkit-border-radius:.3em; border-radius:.3em; }
.droppable { margin: 0.5em; padding: 0.5em; border: thin dashed #333; -moz-border-radius:.3em; -webkit-border-radius:.3em; border-radius:.3em; }
.loading { background: url('../../../core/img/loading.gif') no-repeat center !important; /*cursor: progress; */ cursor: wait; }
.ui-autocomplete-loading { background: url('../../../core/img/loading.gif') right center no-repeat; }
.float { float: left; }
@ -59,6 +60,7 @@ dl.form { width: 100%; float: left; clear: right; margin: 0; padding: 0; }
#identityprops { /*position: absolute; top: 2.5em; left: 0px;*/ }
/*#contact_photo { max-width: 250px; }*/
#contact_identity { min-width: 30em; }
#note { min-width: 200px; }
.contactsection { position: relative; float: left; /*max-width: 40em;*/ padding: 0.5em; height: auto: border: thin solid lightgray;/* -webkit-border-radius: 0.5em; -moz-border-radius: 0.5em; border-radius: 0.5em; background-color: #f8f8f8;*/ }
.contactpart legend { width:auto; padding:.3em; border:1px solid #ddd; font-weight:bold; cursor:pointer; background:#f8f8f8; color:#555; text-shadow:#fff 0 1px 0; -moz-box-shadow:0 1px 1px #fff, 0 1px 1px #fff inset; -webkit-box-shadow:0 1px 1px #fff, 0 1px 1px #fff inset; -moz-border-radius:.5em; -webkit-border-radius:.5em; border-radius:.5em; }

View 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{
@ -99,12 +105,16 @@ if(is_writable('import_tmp/')){
if(count($parts) == 1){
$importready = array($file);
}
$imported = 0;
$failed = 0;
foreach($importready as $import){
$card = OC_VObject::parse($import);
if (!$card) {
$failed += 1;
OC_Log::write('contacts','Import: skipping card. Error parsing VCard: '.$import, OC_Log::ERROR);
continue; // Ditch cards that can't be parsed by Sabre.
}
$imported += 1;
OC_Contacts_VCard::add($id, $card);
}
//done the import
@ -117,4 +127,9 @@ sleep(3);
if(is_writable('import_tmp/')){
unlink($progressfile);
}
OC_JSON::success();
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)));

View File

@ -1263,7 +1263,8 @@ Contacts={
for(ptype in this.data.TEL[phone]['parameters'][param]) {
var pt = this.data.TEL[phone]['parameters'][param][ptype];
$('#phonelist li:last-child').find('select option').each(function(){
if ($(this).val().toUpperCase() == pt.toUpperCase()) {
//if ($(this).val().toUpperCase() == pt.toUpperCase()) {
if ($.inArray($(this).val().toUpperCase(), pt.toUpperCase().split(',')) > -1) {
$(this).attr('selected', 'selected');
}
});
@ -1285,6 +1286,7 @@ Contacts={
},
},
Addressbooks:{
droptarget:undefined,
overview:function(){
if($('#chooseaddressbook_dialog').dialog('isOpen') == true){
$('#chooseaddressbook_dialog').dialog('moveToTop');
@ -1317,14 +1319,13 @@ Contacts={
var tr = $(document.createElement('tr'))
.load(OC.filePath('contacts', 'ajax', 'addbook.php'));
$(object).closest('tr').after(tr).hide();
/* TODO: Shouldn't there be some kinda error checking here? */
},
editAddressbook:function(object, bookid){
var tr = $(document.createElement('tr'))
.load(OC.filePath('contacts', 'ajax', 'editaddressbook.php') + "?bookid="+bookid);
$(object).closest('tr').after(tr).hide();
},
deleteAddressbook:function(bookid){
deleteAddressbook:function(obj, bookid){
var check = confirm("Do you really want to delete this address book?");
if(check == false){
return false;
@ -1332,9 +1333,10 @@ Contacts={
$.post(OC.filePath('contacts', 'ajax', 'deletebook.php'), { id: bookid},
function(jsondata) {
if (jsondata.status == 'success'){
$('#chooseaddressbook_dialog').dialog('destroy').remove();
$(obj).closest('tr').remove();
//$('#chooseaddressbook_dialog').dialog('destroy').remove();
Contacts.UI.Contacts.update();
Contacts.UI.Addressbooks.overview();
//Contacts.UI.Addressbooks.overview();
} else {
OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
//alert('Error: ' + data.message);
@ -1342,8 +1344,95 @@ Contacts={
});
}
},
doImport:function(){
Contacts.UI.notImplemented();
loadImportHandlers:function() {
this.droptarget = $('#import_drop_target');
console.log($('#import_drop_target').html());
$(this.droptarget).bind('dragover',function(event){
$(event.target).addClass('droppable');
event.stopPropagation();
event.preventDefault();
});
$(this.droptarget).bind('dragleave',function(event){
$(event.target).removeClass('droppable');
});
$(this.droptarget).bind('drop',function(event){
event.stopPropagation();
event.preventDefault();
console.log('drop');
$(event.target).removeClass('droppable');
$(event.target).html(t('contacts', 'Uploading...'));
Contacts.UI.loading(event.target, true);
$.fileUpload(event.originalEvent.dataTransfer.files);
});
$.fileUpload = function(files){
console.log(files + ', ' + files.length);
var file = files[0];
console.log('size: '+file.size+', type: '+file.type);
if(file.size > $('#max_upload').val()){
OC.dialogs.alert(t('contacts','The file you are trying to upload exceed the maximum size for file uploads on this server.'), t('contacts','Upload too large'));
$(Contacts.UI.Addressbooks.droptarget).html(t('contacts', 'Drop a VCF file to import contacts.'));
Contacts.UI.loading(Contacts.UI.Addressbooks.droptarget, false);
return;
}
if(file.type.indexOf('text') != 0) {
OC.dialogs.alert(t('contacts','You have dropped a file type that cannot be imported: ') + file.type, t('contacts','Wrong file type'));
$(Contacts.UI.Addressbooks.droptarget).html(t('contacts', 'Drop a VCF file to import contacts.'));
Contacts.UI.loading(Contacts.UI.Addressbooks.droptarget, false);
return;
}
var xhr = new XMLHttpRequest();
if (!xhr.upload) {
OC.dialogs.alert(t('contacts', 'Your browser doesn\'t support AJAX upload. Please upload the contacts file to ownCloud and import that way.'), t('contacts', 'Error'))
}
fileUpload = xhr.upload,
xhr.onreadystatechange = function() {
if (xhr.readyState == 4){
response = $.parseJSON(xhr.responseText);
if(response.status == 'success') {
if(xhr.status == 200) {
$(Contacts.UI.Addressbooks.droptarget).html(t('contacts', 'Importing...'));
Contacts.UI.loading(Contacts.UI.Addressbooks.droptarget, true);
Contacts.UI.Addressbooks.doImport(response.data.path, response.data.file);
} else {
$(Contacts.UI.Addressbooks.droptarget).html(t('contacts', 'Drop a VCF file to import contacts.'));
Contacts.UI.loading(Contacts.UI.Addressbooks.droptarget, false);
OC.dialogs.alert(xhr.status + ': ' + xhr.responseText, t('contacts', 'Error'));
}
} else {
OC.dialogs.alert(response.data.message, t('contacts', 'Error'));
}
}
};
xhr.open("POST", 'ajax/uploadimport.php?file='+encodeURIComponent(file.name), true);
xhr.setRequestHeader('Cache-Control', 'no-cache');
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.setRequestHeader('X_FILE_NAME', encodeURIComponent(file.name));
xhr.setRequestHeader('X-File-Size', file.size);
xhr.setRequestHeader('Content-Type', file.type);
xhr.send(file);
}
},
importAddressbook:function(object){
var tr = $(document.createElement('tr'))
.load(OC.filePath('contacts', 'ajax', 'importaddressbook.php'));
$(object).closest('tr').after(tr).hide();
},
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, 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);
$('#chooseaddressbook_dialog').find('#close_button').val(t('contacts', 'OK'));
Contacts.UI.Contacts.update();
} else {
OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
}
});
Contacts.UI.loading(Contacts.UI.Addressbooks.droptarget, false);
},
submit:function(button, bookid){
var displayname = $("#displayname_"+bookid).val().trim();
@ -1368,7 +1457,7 @@ Contacts={
} else {
OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
}
});
});
},
cancel:function(button, bookid){
$(button).closest('tr').prev().show().next().remove();
@ -1385,7 +1474,6 @@ Contacts={
}
else{
OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
//alert(jsondata.data.message);
}
});
setTimeout(Contacts.UI.Contacts.lazyupdate, 500);
@ -1507,13 +1595,13 @@ $(document).ready(function(){
});
$('#contacts_details_photo_wrapper').bind('dragover',function(event){
console.log('dragover');
$(event.target).css('background-color','red');
$(event.target).addClass('droppable');
event.stopPropagation();
event.preventDefault();
});
$('#contacts_details_photo_wrapper').bind('dragleave',function(event){
console.log('dragleave');
$(event.target).css('background-color','white');
$(event.target).removeClass('droppable');
//event.stopPropagation();
//event.preventDefault();
});
@ -1521,7 +1609,7 @@ $(document).ready(function(){
event.stopPropagation();
event.preventDefault();
console.log('drop');
$(event.target).css('background-color','white')
$(event.target).removeClass('droppable');
$.fileUpload(event.originalEvent.dataTransfer.files);
});

View File

@ -149,6 +149,7 @@ class OC_Contacts_App {
'WORK' => $l->t('Work'),
'TEXT' => $l->t('Text'),
'VOICE' => $l->t('Voice'),
'MSG' => $l->t('Message'),
'FAX' => $l->t('Fax'),
'VIDEO' => $l->t('Video'),
'PAGER' => $l->t('Pager'),

View File

@ -141,10 +141,38 @@ class OC_Contacts_VCard{
}
/**
* @brief Tries to update imported VCards to adhere to rfc2426 (VERSION: 3.0)
* @brief Checks if a contact with the same UID already exist in the address book.
* @param $aid Address book ID.
* @param $uid UID (passed by reference).
* @returns true if the UID has been changed.
*/
protected static function trueUID($aid, &$uid) {
$stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*contacts_cards WHERE addressbookid = ? AND uri = ?' );
$uri = $uid.'.vcf';
$result = $stmt->execute(array($aid,$uri));
if($result->numRows() > 0){
while(true) {
$tmpuid = substr(md5(rand().time()),0,10);
$uri = $tmpuid.'.vcf';
$result = $stmt->execute(array($aid,$uri));
if($result->numRows() > 0){
continue;
} else {
$uid = $tmpuid;
return true;
}
}
} else {
return false;
}
}
/**
* @brief Tries to update imported VCards to adhere to rfc2426 (VERSION: 3.0) and add mandatory fields if missing.
* @param aid Address book id.
* @param vcard An OC_VObject of type VCARD (passed by reference).
*/
protected static function updateValuesFromAdd(&$vcard) { // any suggestions for a better method name? ;-)
protected static function updateValuesFromAdd($aid, &$vcard) { // any suggestions for a better method name? ;-)
$stringprops = array('N', 'FN', 'ORG', 'NICK', 'ADR', 'NOTE');
$typeprops = array('ADR', 'TEL', 'EMAIL');
$upgrade = false;
@ -207,14 +235,19 @@ class OC_Contacts_VCard{
}
if(!$uid) {
$vcard->setUID();
$uid = $vcard->getAsString('UID');
OC_Log::write('contacts','OC_Contacts_VCard::updateValuesFromAdd. Added missing \'UID\' field: '.$uid,OC_Log::DEBUG);
}
if(self::trueUID($aid, $uid)) {
$vcard->setString('UID', $uid);
}
$vcard->setString('VERSION','3.0');
// Add product ID is missing.
$prodid = trim($vcard->getAsString('PRODID'));
if(!$prodid) {
$appinfo = OC_App::getAppInfo('contacts');
$prodid = '-//ownCloud//NONSGML '.$appinfo['name'].' '.$appinfo['version'].'//EN';
$appversion = OC_App::getAppVersion('contacts');
$prodid = '-//ownCloud//NONSGML '.$appinfo['name'].' '.$appversion.'//EN';
$vcard->setString('PRODID', $prodid);
}
$now = new DateTime;
@ -236,7 +269,7 @@ class OC_Contacts_VCard{
OC_Contacts_App::loadCategoriesFromVCard($card);
self::updateValuesFromAdd($card);
self::updateValuesFromAdd($aid, $card);
$fn = $card->getAsString('FN');
if (empty($fn)) {

View File

@ -1,4 +1,4 @@
<div id="chooseaddressbook_dialog" title="<?php echo $l->t("Choose active Address Books"); ?>">
<div id="chooseaddressbook_dialog" title="<?php echo $l->t("Configure Address Books"); ?>">
<table width="100%" style="border: 0;">
<?php
$option_addressbooks = OC_Contacts_Addressbook::all(OC_User::getUser());
@ -14,6 +14,7 @@ for($i = 0; $i < count($option_addressbooks); $i++){
<tr>
<td colspan="5" style="padding: 0.5em;">
<a class="button" href="#" onclick="Contacts.UI.Addressbooks.newAddressbook(this);"><?php echo $l->t('New Address Book') ?></a>
<a class="button" href="#" onclick="Contacts.UI.Addressbooks.importAddressbook(this);"><?php echo $l->t('Import from VCF') ?></a>
</td>
</tr>
<tr>

View File

@ -2,4 +2,4 @@
// FIXME: Make this readable.
echo "<td width=\"20px\"><input id=\"active_" . $_['addressbook']["id"] . "\" type=\"checkbox\" onClick=\"Contacts.UI.Addressbooks.activation(this, " . $_['addressbook']["id"] . ")\"" . (OC_Contacts_Addressbook::isActive($_['addressbook']["id"]) ? ' checked="checked"' : '') . "></td>";
echo "<td><label for=\"active_" . $_['addressbook']["id"] . "\">" . htmlspecialchars($_['addressbook']["displayname"]) . "</label></td>";
echo "<td width=\"20px\"><a href=\"#\" onclick=\"Contacts.UI.showCardDAVUrl('" . OC_User::getUser() . "', '" . rawurlencode($_['addressbook']["uri"]) . "');\" title=\"" . $l->t("CardDav Link") . "\" class=\"action\"><img class=\"svg action\" src=\"../../core/img/actions/public.svg\"></a></td><td width=\"20px\"><a href=\"export.php?bookid=" . $_['addressbook']["id"] . "\" title=\"" . $l->t("Download") . "\" class=\"action\"><img class=\"svg action\" src=\"../../core/img/actions/download.svg\"></a></td><td width=\"20px\"><a href=\"#\" title=\"" . $l->t("Edit") . "\" class=\"action\" onclick=\"Contacts.UI.Addressbooks.editAddressbook(this, " . $_['addressbook']["id"] . ");\"><img class=\"svg action\" src=\"../../core/img/actions/rename.svg\"></a></td><td width=\"20px\"><a href=\"#\" onclick=\"Contacts.UI.Addressbooks.deleteAddressbook('" . $_['addressbook']["id"] . "');\" title=\"" . $l->t("Delete") . "\" class=\"action\"><img class=\"svg action\" src=\"../../core/img/actions/delete.svg\"></a></td>";
echo "<td width=\"20px\"><a href=\"#\" onclick=\"Contacts.UI.showCardDAVUrl('" . OC_User::getUser() . "', '" . rawurlencode($_['addressbook']["uri"]) . "');\" title=\"" . $l->t("CardDav Link") . "\" class=\"action\"><img class=\"svg action\" src=\"../../core/img/actions/public.svg\"></a></td><td width=\"20px\"><a href=\"export.php?bookid=" . $_['addressbook']["id"] . "\" title=\"" . $l->t("Download") . "\" class=\"action\"><img class=\"svg action\" src=\"../../core/img/actions/download.svg\"></a></td><td width=\"20px\"><a href=\"#\" title=\"" . $l->t("Edit") . "\" class=\"action\" onclick=\"Contacts.UI.Addressbooks.editAddressbook(this, " . $_['addressbook']["id"] . ");\"><img class=\"svg action\" src=\"../../core/img/actions/rename.svg\"></a></td><td width=\"20px\"><a href=\"#\" onclick=\"Contacts.UI.Addressbooks.deleteAddressbook(this, '" . $_['addressbook']["id"] . "');\" title=\"" . $l->t("Delete") . "\" class=\"action\"><img class=\"svg action\" src=\"../../core/img/actions/delete.svg\"></a></td>";

View File

@ -112,7 +112,7 @@ $id = isset($_['id']) ? $_['id'] : '';
<div id="contact_note" class="contactsection">
<form class="float" method="post">
<fieldset id="note" class="formfloat propertycontainer contactpart" data-element="NOTE">
<textarea class="contacts_property note" name="value" cols="40" rows="10" required="required" placeholder="<?php echo $l->t('Add notes here.'); ?>"></textarea>
<textarea class="contacts_property note" name="value" cols="60" rows="15" required="required" placeholder="<?php echo $l->t('Add notes here.'); ?>"></textarea>
</fieldset>
</form>
</div> <!-- contact_note -->

View File

@ -519,6 +519,10 @@ class OC_App{
public static function getStorage($appid){
if(OC_App::isEnabled($appid)){//sanity check
if(OC_User::isLoggedIn()){
$view = new OC_FilesystemView('/'.OC_User::getUser());
if(!$view->file_exists($appid)) {
$view->mkdir($appid);
}
return new OC_FilesystemView('/'.OC_User::getUser().'/'.$appid);
}else{
OC_Log::write('core','Can\'t get app storage, app, user not logged in',OC_Log::ERROR);