Code style.

This commit is contained in:
Thomas Tanghus 2012-07-20 17:09:03 +02:00
parent 3c2967074f
commit 7fff386679
18 changed files with 142 additions and 86 deletions

View File

@ -48,7 +48,8 @@ if(!$vcard) {
if(!is_array($value)) { if(!is_array($value)) {
$value = trim($value); $value = trim($value);
if(!$value && in_array( if(!$value
&& in_array(
$name, $name,
array('TEL', 'EMAIL', 'ORG', 'BDAY', 'URL', 'NICKNAME', 'NOTE')) array('TEL', 'EMAIL', 'ORG', 'BDAY', 'URL', 'NICKNAME', 'NOTE'))
) { ) {

View File

@ -21,8 +21,7 @@ class OC_Migration_Provider_Contacts extends OC_Migration_Provider{
$ids2 = $this->content->copyRows( $options ); $ids2 = $this->content->copyRows( $options );
// If both returned some ids then they worked // If both returned some ids then they worked
if( is_array( $ids ) && is_array( $ids2 ) ) if(is_array($ids) && is_array($ids2)) {
{
return true; return true;
} else { } else {
return false; return false;

View File

@ -2,5 +2,5 @@
if(!file_exists('../../lib/base.php')) { if(!file_exists('../../lib/base.php')) {
die('Please update the path to /lib/base.php in carddav.php or make use of /remote.php/carddav/'); die('Please update the path to /lib/base.php in carddav.php or make use of /remote.php/carddav/');
} }
require_once('../../lib/base.php'); require_once '../../lib/base.php';
require_once('appinfo/remote.php'); require_once 'appinfo/remote.php';

View File

@ -9,17 +9,20 @@
OCP\User::checkLoggedIn(); OCP\User::checkLoggedIn();
OCP\App::checkAppEnabled('contacts'); OCP\App::checkAppEnabled('contacts');
$bookid = isset($_GET['bookid']) ? $_GET['bookid'] : NULL; $bookid = isset($_GET['bookid']) ? $_GET['bookid'] : null;
$contactid = isset($_GET['contactid']) ? $_GET['contactid'] : NULL; $contactid = isset($_GET['contactid']) ? $_GET['contactid'] : null;
$nl = "\n"; $nl = "\n";
if(isset($bookid)) { if(isset($bookid)) {
$addressbook = OC_Contacts_App::getAddressbook($bookid); $addressbook = OC_Contacts_App::getAddressbook($bookid);
//$cardobjects = OC_Contacts_VCard::all($bookid); //$cardobjects = OC_Contacts_VCard::all($bookid);
header('Content-Type: text/directory'); header('Content-Type: text/directory');
header('Content-Disposition: inline; filename=' . str_replace(' ', '_', $addressbook['displayname']) . '.vcf'); header('Content-Disposition: inline; filename='
. str_replace(' ', '_', $addressbook['displayname']) . '.vcf');
$start = 0; $start = 0;
$batchsize = OCP\Config::getUserValue(OCP\User::getUser(), 'contacts', 'export_batch_size', 20); $batchsize = OCP\Config::getUserValue(OCP\User::getUser(),
'contacts',
'export_batch_size', 20);
while($cardobjects = OC_Contacts_VCard::all($bookid, $start, $batchsize)){ while($cardobjects = OC_Contacts_VCard::all($bookid, $start, $batchsize)){
foreach($cardobjects as $card) { foreach($cardobjects as $card) {
echo $card['carddata'] . $nl; echo $card['carddata'] . $nl;
@ -29,6 +32,7 @@ if(isset($bookid)){
}elseif(isset($contactid)) { }elseif(isset($contactid)) {
$data = OC_Contacts_App::getContactObject($contactid); $data = OC_Contacts_App::getContactObject($contactid);
header('Content-Type: text/vcard'); header('Content-Type: text/vcard');
header('Content-Disposition: inline; filename=' . str_replace(' ', '_', $data['fullname']) . '.vcf'); header('Content-Disposition: inline; filename='
. str_replace(' ', '_', $data['fullname']) . '.vcf');
echo $data['carddata']; echo $data['carddata'];
} }

View File

@ -39,16 +39,28 @@ if(!$file) {
exit(); exit();
} }
if(isset($_POST['method']) && $_POST['method'] == 'new') { if(isset($_POST['method']) && $_POST['method'] == 'new') {
$id = OC_Contacts_Addressbook::add(OCP\USER::getUser(), $_POST['addressbookname']); $id = OC_Contacts_Addressbook::add(OCP\USER::getUser(),
$_POST['addressbookname']);
if(!$id) { if(!$id) {
OCP\JSON::error(array('data' => array('message' => 'Error creating address book.'))); OCP\JSON::error(
array(
'data' => array('message' => 'Error creating address book.')
)
);
exit(); exit();
} }
OC_Contacts_Addressbook::setActive($id, 1); OC_Contacts_Addressbook::setActive($id, 1);
}else{ }else{
$id = $_POST['id']; $id = $_POST['id'];
if(!$id) { if(!$id) {
OCP\JSON::error(array('data' => array('message' => 'Error getting the ID of the address book.', 'file'=>$_POST['file']))); OCP\JSON::error(
array(
'data' => array(
'message' => 'Error getting the ID of the address book.',
'file'=>$_POST['file']
)
)
);
exit(); exit();
} }
OC_Contacts_App::getAddressbook($id); // is owner access check OC_Contacts_App::getAddressbook($id); // is owner access check
@ -79,10 +91,20 @@ writeProgress('70');
$imported = 0; $imported = 0;
$failed = 0; $failed = 0;
if(!count($parts) > 0) { if(!count($parts) > 0) {
OCP\JSON::error(array('data' => array('message' => 'No contacts to import in '.$_POST['file'].'. Please check if the file is corrupted.', 'file'=>$_POST['file']))); OCP\JSON::error(
array(
'data' => array(
'message' => 'No contacts to import in '
. $_POST['file'].'. Please check if the file is corrupted.',
'file'=>$_POST['file']
)
)
);
if(isset($_POST['fstype']) && $_POST['fstype'] == 'OC_FilesystemView') { if(isset($_POST['fstype']) && $_POST['fstype'] == 'OC_FilesystemView') {
if(!$view->unlink('/imports/' . $_POST['file'])) { if(!$view->unlink('/imports/' . $_POST['file'])) {
OCP\Util::writeLog('contacts','Import: Error unlinking OC_FilesystemView ' . '/' . $_POST['file'], OCP\Util::ERROR); OCP\Util::writeLog('contacts',
'Import: Error unlinking OC_FilesystemView ' . '/' . $_POST['file'],
OCP\Util::ERROR);
} }
} }
exit(); exit();
@ -91,14 +113,18 @@ foreach($parts as $part){
$card = OC_VObject::parse($part); $card = OC_VObject::parse($part);
if (!$card) { if (!$card) {
$failed += 1; $failed += 1;
OCP\Util::writeLog('contacts','Import: skipping card. Error parsing VCard: '.$part, OCP\Util::ERROR); OCP\Util::writeLog('contacts',
'Import: skipping card. Error parsing VCard: ' . $part,
OCP\Util::ERROR);
continue; // Ditch cards that can't be parsed by Sabre. continue; // Ditch cards that can't be parsed by Sabre.
} }
try { try {
OC_Contacts_VCard::add($id, $card); OC_Contacts_VCard::add($id, $card);
$imported += 1; $imported += 1;
} catch (Exception $e) { } catch (Exception $e) {
OCP\Util::writeLog('contacts', 'Error importing vcard: '.$e->getMessage().$nl.$card, OCP\Util::ERROR); OCP\Util::writeLog('contacts',
'Error importing vcard: ' . $e->getMessage() . $nl . $card,
OCP\Util::ERROR);
$failed += 1; $failed += 1;
} }
} }
@ -108,7 +134,17 @@ sleep(3);
OC_Cache::remove($progresskey); OC_Cache::remove($progresskey);
if(isset($_POST['fstype']) && $_POST['fstype'] == 'OC_FilesystemView') { if(isset($_POST['fstype']) && $_POST['fstype'] == 'OC_FilesystemView') {
if(!$view->unlink('/imports/' . $_POST['file'])) { if(!$view->unlink('/imports/' . $_POST['file'])) {
OCP\Util::writeLog('contacts','Import: Error unlinking OC_FilesystemView ' . '/' . $_POST['file'], OCP\Util::ERROR); OCP\Util::writeLog('contacts',
'Import: Error unlinking OC_FilesystemView ' . '/' . $_POST['file'],
OCP\Util::ERROR);
} }
} }
OCP\JSON::success(array('data' => array('imported'=>$imported, 'failed'=>$failed, 'file'=>$_POST['file']))); OCP\JSON::success(
array(
'data' => array(
'imported'=>$imported,
'failed'=>$failed,
'file'=>$_POST['file'],
)
)
);

View File

@ -14,9 +14,13 @@ OCP\App::checkAppEnabled('contacts');
// Get active address books. This creates a default one if none exists. // Get active address books. This creates a default one if none exists.
$ids = OC_Contacts_Addressbook::activeIds(OCP\USER::getUser()); $ids = OC_Contacts_Addressbook::activeIds(OCP\USER::getUser());
$has_contacts = (count(OC_Contacts_VCard::all($ids, 0, 1)) > 0 ? true : false); // just to check if there are any contacts. $has_contacts = (count(OC_Contacts_VCard::all($ids, 0, 1)) > 0
? true
: false); // just to check if there are any contacts.
if($has_contacts === false) { if($has_contacts === false) {
OCP\Util::writeLog('contacts','index.html: No contacts found.',OCP\Util::DEBUG); OCP\Util::writeLog('contacts',
'index.html: No contacts found.',
OCP\Util::DEBUG);
} }
// Load the files we need // Load the files we need
@ -53,7 +57,8 @@ OCP\Util::addStyle('contacts','contacts');
$tmpl = new OCP\Template( "contacts", "index", "user" ); $tmpl = new OCP\Template( "contacts", "index", "user" );
$tmpl->assign('uploadMaxFilesize', $maxUploadFilesize, false); $tmpl->assign('uploadMaxFilesize', $maxUploadFilesize, false);
$tmpl->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize), false); $tmpl->assign('uploadMaxHumanFilesize',
OCP\Util::humanFileSize($maxUploadFilesize), false);
$tmpl->assign('property_types', $property_types, false); $tmpl->assign('property_types', $property_types, false);
$tmpl->assign('phone_types', $phone_types, false); $tmpl->assign('phone_types', $phone_types, false);
$tmpl->assign('email_types', $email_types, false); $tmpl->assign('email_types', $email_types, false);

View File

@ -27,7 +27,8 @@ if(is_null($id)) {
} }
if(!extension_loaded('gd') || !function_exists('gd_info')) { if(!extension_loaded('gd') || !function_exists('gd_info')) {
OCP\Util::writeLog('contacts','photo.php. GD module not installed',OCP\Util::DEBUG); OCP\Util::writeLog('contacts',
'photo.php. GD module not installed', OCP\Util::DEBUG);
getStandardImage(); getStandardImage();
} }
@ -38,7 +39,9 @@ if(!$image) {
} }
// invalid vcard // invalid vcard
if (is_null($contact)) { if (is_null($contact)) {
OCP\Util::writeLog('contacts','photo.php. The VCard for ID '.$id.' is not RFC compatible',OCP\Util::ERROR); OCP\Util::writeLog('contacts',
'photo.php. The VCard for ID ' . $id . ' is not RFC compatible',
OCP\Util::ERROR);
} else { } else {
OCP\Response::enableCaching($caching); OCP\Response::enableCaching($caching);
OC_Contacts_App::setLastModifiedHeader($contact); OC_Contacts_App::setLastModifiedHeader($contact);
@ -56,8 +59,7 @@ if( is_null($contact)) {
} }
if ($image->valid()) { if ($image->valid()) {
$max_size = 200; $max_size = 200;
if($image->width() > $max_size || if ($image->width() > $max_size || $image->height() > $max_size) {
$image->height() > $max_size) {
$image->resize($max_size); $image->resize($max_size);
} }
} }
@ -65,8 +67,7 @@ if( is_null($contact)) {
if (!$image->valid()) { if (!$image->valid()) {
// Not found :-( // Not found :-(
getStandardImage(); getStandardImage();
//$image->loadFromFile('img/person_large.png');
} }
header('Content-Type: '.$image->mimeType()); header('Content-Type: '.$image->mimeType());
$image->show(); $image->show();
//echo OC_Contacts_App::$l10n->t('This card does not contain a photo.');

View File

@ -2,7 +2,6 @@
$id = $_['id']; $id = $_['id'];
$tmpkey = $_['tmpkey']; $tmpkey = $_['tmpkey'];
$requesttoken = $_['requesttoken']; $requesttoken = $_['requesttoken'];
OCP\Util::writeLog('contacts','templates/part.cropphoto.php: tmpkey: '.$tmpkey, OCP\Util::DEBUG);
?> ?>
<script type="text/javascript"> <script type="text/javascript">
jQuery(function($) { jQuery(function($) {

View File

@ -32,7 +32,8 @@ function getStandardImage(){
} }
if(!extension_loaded('gd') || !function_exists('gd_info')) { if(!extension_loaded('gd') || !function_exists('gd_info')) {
OCP\Util::writeLog('contacts','thumbnail.php. GD module not installed',OCP\Util::DEBUG); OCP\Util::writeLog('contacts',
'thumbnail.php. GD module not installed', OCP\Util::DEBUG);
getStandardImage(); getStandardImage();
exit(); exit();
} }
@ -44,7 +45,9 @@ $contact = OC_Contacts_App::getContactVCard($id);
// invalid vcard // invalid vcard
if(is_null($contact)) { if(is_null($contact)) {
OCP\Util::writeLog('contacts','thumbnail.php. The VCard for ID '.$id.' is not RFC compatible',OCP\Util::ERROR); OCP\Util::writeLog('contacts',
'thumbnail.php. The VCard for ID ' . $id . ' is not RFC compatible',
OCP\Util::ERROR);
getStandardImage(); getStandardImage();
exit(); exit();
} }
@ -64,16 +67,24 @@ if($photo) {
if($image->show()) { if($image->show()) {
exit(); exit();
} else { } else {
OCP\Util::writeLog('contacts','thumbnail.php. Couldn\'t display thumbnail for ID '.$id,OCP\Util::ERROR); OCP\Util::writeLog('contacts',
'thumbnail.php. Couldn\'t display thumbnail for ID ' . $id,
OCP\Util::ERROR);
} }
} else { } else {
OCP\Util::writeLog('contacts','thumbnail.php. Couldn\'t resize thumbnail for ID '.$id,OCP\Util::ERROR); OCP\Util::writeLog('contacts',
'thumbnail.php. Couldn\'t resize thumbnail for ID ' . $id,
OCP\Util::ERROR);
} }
}else{ }else{
OCP\Util::writeLog('contacts','thumbnail.php. Couldn\'t crop thumbnail for ID '.$id,OCP\Util::ERROR); OCP\Util::writeLog('contacts',
'thumbnail.php. Couldn\'t crop thumbnail for ID ' . $id,
OCP\Util::ERROR);
} }
} else { } else {
OCP\Util::writeLog('contacts','thumbnail.php. Couldn\'t load image string for ID '.$id,OCP\Util::ERROR); OCP\Util::writeLog('contacts',
'thumbnail.php. Couldn\'t load image string for ID ' . $id,
OCP\Util::ERROR);
} }
} }
getStandardImage(); getStandardImage();