Ejemplo n.º 1
0
/**
* @author  Victor Dubiniuk
* Copyright (c) 2012 Victor Dubiniuk <*****@*****.**>
* Copyright (c) 2012 Thomas Tanghus <*****@*****.**>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
OCP\JSON::callCheck();
$id = intval($_POST['id']);
$aid = intval($_POST['aid']);
$isaddressbook = isset($_POST['isaddressbook']) ? true : false;
// Ownership checking
try {
    OCA\Contacts\Addressbook::find($id);
    // is owner access check
} catch (Exception $e) {
    OCP\JSON::error(array('data' => array('message' => $e->getMessage())));
    exit;
}
try {
    OCA\Contacts\VCard::moveToAddressBook($aid, $id, $isaddressbook);
} catch (Exception $e) {
    $msg = $e->getMessage();
    OCP\Util::writeLog('contacts', 'Error moving contacts "' . implode(',', $id) . '" to addressbook "' . $aid . '"' . $msg, OCP\Util::ERROR);
    OC_JSON::error(array('data' => array('message' => $msg)));
    exit;
}
OC_JSON::success(array('data' => array('ids' => $id)));
Ejemplo n.º 2
0
    $batchsize = OCP\Config::getUserValue(OCP\User::getUser(), 'contacts', 'export_batch_size', 20);
    while ($cardobjects = OCA\Contacts\VCard::all($bookid, $start, $batchsize, array('carddata'))) {
        foreach ($cardobjects as $card) {
            echo $card['carddata'] . $nl;
        }
        $start += $batchsize;
    }
} elseif (!is_null($contactid)) {
    try {
        $data = OCA\Contacts\VCard::find($contactid);
    } catch (Exception $e) {
        OCP\JSON::error(array('data' => array('message' => $e->getMessage())));
        exit;
    }
    header('Content-Type: text/vcard');
    header('Content-Disposition: inline; filename=' . str_replace(' ', '_', $data['fullname']) . '.vcf');
    echo $data['carddata'];
} elseif (!is_null($selectedids)) {
    $selectedids = explode(',', $selectedids);
    $l10n = \OC_L10N::get('contacts');
    header('Content-Type: text/directory');
    header('Content-Disposition: inline; filename=' . $l10n->t('%d_selected_contacts', array(count($selectedids))) . '.vcf');
    foreach ($selectedids as $id) {
        try {
            $data = OCA\Contacts\VCard::find($id);
            echo $data['carddata'] . $nl;
        } catch (Exception $e) {
            continue;
        }
    }
}
Ejemplo n.º 3
0
require_once __DIR__ . '/../loghandler.php';
$categories = isset($_POST['categories']) ? $_POST['categories'] : null;
$fromobjects = isset($_POST['fromobjects']) && ($_POST['fromobjects'] === 'true' || $_POST['fromobjects'] === '1') ? true : false;
if (is_null($categories)) {
    bailOut(OCA\Contacts\App::$l10n->t('No categories selected for deletion.'));
}
debug(print_r($categories, true));
if ($fromobjects) {
    $addressbooks = OCA\Contacts\Addressbook::all(OCP\USER::getUser());
    if (count($addressbooks) == 0) {
        bailOut(OCA\Contacts\App::$l10n->t('No address books found.'));
    }
    $addressbookids = array();
    foreach ($addressbooks as $addressbook) {
        $addressbookids[] = $addressbook['id'];
    }
    $contacts = OCA\Contacts\VCard::all($addressbookids);
    if (count($contacts) == 0) {
        bailOut(OCA\Contacts\App::$l10n->t('No contacts found.'));
    }
    $cards = array();
    foreach ($contacts as $contact) {
        $cards[] = array($contact['id'], $contact['carddata']);
    }
}
$catman = new OC_VCategories('contact');
$catman->delete($categories, $cards);
if ($fromobjects) {
    OCA\Contacts\VCard::updateDataByID($cards);
}
OCP\JSON::success();
Ejemplo n.º 4
0
 /**
  * Deletes a card
  *
  * @param mixed $addressbookid
  * @param string $carduri
  * @return bool
  */
 public function deleteCard($addressbookid, $carduri)
 {
     return OCA\Contacts\VCard::deleteFromDAVData($addressbookid, $carduri);
 }
Ejemplo n.º 5
0
/*foreach($ids as $id) {
	if($id) {
		$contacts_alphabet = array_merge(
				$contacts_alphabet,
				OCA\Contacts\VCard::all($id, $offset, 50)
		);
	}
}*/
uasort($contacts_alphabet, 'cmp');
$contacts = array();
// Our new array for the contacts sorted by addressbook
if ($contacts_alphabet) {
    foreach ($contacts_alphabet as $contact) {
        try {
            $vcard = Sabre\VObject\Reader::read($contact['carddata']);
            $details = OCA\Contacts\VCard::structureContact($vcard);
            $contacts[] = array('id' => $contact['id'], 'aid' => $contact['addressbookid'], 'data' => $details);
        } catch (Exception $e) {
            continue;
        }
        // This should never execute.
        /*if(!isset($contacts_addressbook[$contact['addressbookid']])) {
        			$contacts_addressbook[$contact['addressbookid']] = array(
        				'contacts' => array('type' => 'book',)
        			);
        		}
        		$display = trim($contact['fullname']);
        		if(!$display) {
        			$vcard = OCA\Contacts\App::getContactVCard($contact['id']);
        			if(!is_null($vcard)) {
        				$struct = OCA\Contacts\VCard::structureContact($vcard);
Ejemplo n.º 6
0
            OCP\Util::writeLog('contacts', 'Import: Error unlinking OC_FilesystemView ' . '/' . $_POST['file'], OCP\Util::ERROR);
        }
    }
    exit;
}
foreach ($parts as $part) {
    try {
        $vcard = Sabre\VObject\Reader::read($part);
    } catch (Exception $e) {
        $failed += 1;
        OCP\Util::writeLog('contacts', 'Import: skipping card. Error parsing VCard: ' . $e->getMessage(), OCP\Util::ERROR);
        continue;
        // Ditch cards that can't be parsed by Sabre.
    }
    try {
        OCA\Contacts\VCard::add($id, $vcard);
        $imported += 1;
    } catch (Exception $e) {
        OCP\Util::writeLog('contacts', 'Error importing vcard: ' . $e->getMessage() . $nl . $vcard, OCP\Util::ERROR);
        $failed += 1;
    }
}
//done the import
writeProgress('100');
sleep(3);
OC_Cache::remove($progresskey);
if (isset($_POST['fstype']) && $_POST['fstype'] == 'OC_FilesystemView') {
    if (!$view->unlink('/imports/' . $_POST['file'])) {
        OCP\Util::writeLog('contacts', 'Import: Error unlinking OC_FilesystemView ' . '/' . $_POST['file'], OCP\Util::ERROR);
    }
}
Ejemplo n.º 7
0
 * Copyright (c) 2011 Thomas Tanghus <*****@*****.**>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
$id = $_GET['id'];
$checksum = isset($_GET['checksum']) ? $_GET['checksum'] : '';
$vcard = OCA\Contacts\App::getContactVCard($id);
$adr_types = OCA\Contacts\App::getTypesOfProperty('ADR');
$tmpl = new OCP\Template("contacts", "part.edit_address_dialog");
if ($checksum) {
    $line = OCA\Contacts\App::getPropertyLineByChecksum($vcard, $checksum);
    $element = $vcard->children[$line];
    $adr = OCA\Contacts\VCard::structureProperty($element);
    $types = array();
    if (isset($adr['parameters']['TYPE'])) {
        if (is_array($adr['parameters']['TYPE'])) {
            $types = array_map('htmlspecialchars', $adr['parameters']['TYPE']);
            $types = array_map('strtoupper', $types);
        } else {
            $types = array(strtoupper(htmlspecialchars($adr['parameters']['TYPE'])));
        }
    }
    $tmpl->assign('types', $types, false);
    $adr = array_map('htmlspecialchars', $adr['value']);
    $tmpl->assign('adr', $adr, false);
}
$tmpl->assign('id', $id);
$tmpl->assign('adr_types', $adr_types);
Ejemplo n.º 8
0
 * 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/>.
 *
 */
/**
 * @brief Index vCard properties for easier searching
 */
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
OCP\JSON::callCheck();
require_once 'loghandler.php';
$addressbooks = OCA\Contacts\Addressbook::all(OCP\USER::getUser());
$ids = array();
foreach ($addressbooks as $addressbook) {
    $ids[] = $addressbook['id'];
}
$user = OCP\User::getUser();
session_write_close();
$start = 0;
$batchsize = 10;
while ($contacts = OCA\Contacts\VCard::all($ids, $start, $batchsize)) {
    OCP\Util::writeLog('contacts', 'Indexing contacts: ' . $batchsize . ' starting from ' . $start, OCP\Util::DEBUG);
    foreach ($contacts as $contact) {
        $vcard = OC_VObject::parse($contact['carddata']);
        OCA\Contacts\App::updateDBProperties($contact['id'], $vcard);
    }
    $start += $batchsize;
}
OCP\Config::setUserValue($user, 'contacts', 'contacts_indexed', 'yes');
Ejemplo n.º 9
0
                    }
                    $property->setValue($image->__toString());
                    $property->parameters[] = new Sabre\VObject\Parameter('ENCODING', 'b');
                    $property->parameters[] = new Sabre\VObject\Parameter('TYPE', $image->mimeType());
                    $vcard->__set('PHOTO', $property);
                } else {
                    OCP\Util::writeLog('contacts', 'savecrop.php: files: Adding PHOTO property.', OCP\Util::DEBUG);
                    // For vCard 3.0 the type must be e.g. JPEG or PNG
                    // For version 4.0 the full mimetype should be used.
                    // https://tools.ietf.org/html/rfc2426#section-3.1.4
                    $type = $vcard->VERSION == '4.0' ? $image->mimeType() : strtoupper(array_pop(explode('/', $image->mimeType())));
                    $vcard->add('PHOTO', $image->__toString(), array('ENCODING' => 'b', 'TYPE' => $type));
                }
                $now = new DateTime();
                $vcard->{'REV'} = $now->format(DateTime::W3C);
                if (!OCA\Contacts\VCard::edit($id, $vcard)) {
                    bailOut(OCA\Contacts\App::$l10n->t('Error saving contact.'));
                }
                OCA\Contacts\App::cacheThumbnail($id, $image);
                OCP\JSON::success(array('data' => array('id' => $id, 'width' => $image->width(), 'height' => $image->height(), 'lastmodified' => OCA\Contacts\App::lastModified($vcard)->format('U'))));
            } else {
                bailOut(OCA\Contacts\App::$l10n->t('Error resizing image'));
            }
        } else {
            bailOut(OCA\Contacts\App::$l10n->t('Error cropping image'));
        }
    } else {
        bailOut(OCA\Contacts\App::$l10n->t('Error creating temporary image'));
    }
} else {
    bailOut(OCA\Contacts\App::$l10n->t('Error finding image: ') . $tmpkey);
Ejemplo n.º 10
0
<?php

/**
 * Copyright (c) 2012 Thomas Tanghus <*****@*****.**>
 * Copyright (c) 2011 Jakob Sack mail@jakobsack.de
 * 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\User::checkLoggedIn();
OCP\App::checkAppEnabled('contacts');
// Get active address books. This creates a default one if none exists.
$ids = OCA\Contacts\Addressbook::activeIds(OCP\USER::getUser());
$has_contacts = count(OCA\Contacts\VCard::all($ids, 0, 1)) > 0 ? true : false;
// just to check if there are any contacts.
if ($has_contacts === false) {
    OCP\Util::writeLog('contacts', 'index.html: No contacts found.', OCP\Util::DEBUG);
}
// Load the files we need
OCP\App::setActiveNavigationEntry('contacts_index');
// Load a specific user?
$id = isset($_GET['id']) ? $_GET['id'] : null;
$impp_types = OCA\Contacts\App::getTypesOfProperty('IMPP');
$adr_types = OCA\Contacts\App::getTypesOfProperty('ADR');
$phone_types = OCA\Contacts\App::getTypesOfProperty('TEL');
$email_types = OCA\Contacts\App::getTypesOfProperty('EMAIL');
$ims = OCA\Contacts\App::getIMOptions();
$im_protocols = array();
foreach ($ims as $name => $values) {
    $im_protocols[$name] = $values['displayname'];
Ejemplo n.º 11
0
OCP\JSON::checkAppEnabled('contacts');
OCP\JSON::callCheck();
require_once __DIR__ . '/../loghandler.php';
$aid = isset($_POST['aid']) ? $_POST['aid'] : null;
if (!$aid) {
    $addressbooks = OCA\Contacts\Addressbook::all(OCP\User::getUser(), true, false);
    if (count($addressbooks) === 0) {
        bailOut(OCA\Contacts\App::$l10n->t('You have no addressbooks.'));
    } else {
        $aid = $addressbooks[0]['id'];
    }
}
$isnew = isset($_POST['isnew']) ? $_POST['isnew'] : false;
$vcard = Sabre\VObject\Component::create('VCARD');
$uid = substr(md5(rand() . time()), 0, 10);
$vcard->add('UID', $uid);
$id = null;
try {
    $id = OCA\Contacts\VCard::add($aid, $vcard, null, $isnew);
} catch (Exception $e) {
    bailOut($e->getMessage());
}
if (!$id) {
    bailOut('There was an error adding the contact.');
}
$lastmodified = OCA\Contacts\App::lastModified($vcard);
if (!$lastmodified) {
    $lastmodified = new DateTime();
}
OCP\JSON::success(array('data' => array('id' => $id, 'aid' => $aid, 'details' => OCA\Contacts\VCard::structureContact($vcard), 'lastmodified' => $lastmodified->format('U'))));
Ejemplo n.º 12
0
<?php

/**
 * Copyright (c) 2011 Thomas Tanghus <*****@*****.**>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
require_once 'loghandler.php';
$tmpl = new OCP\Template("contacts", "part.edit_name_dialog");
$id = isset($_GET['id']) ? $_GET['id'] : '';
if ($id) {
    $vcard = OCA\Contacts\App::getContactVCard($id);
    $name = array('', '', '', '', '');
    if ($vcard->__isset('N')) {
        $property = $vcard->__get('N');
        if ($property) {
            $name = OCA\Contacts\VCard::structureProperty($property);
        }
    }
    $name = array_map('htmlspecialchars', $name['value']);
    $tmpl->assign('name', $name, false);
    $tmpl->assign('id', $id, false);
} else {
    bailOut(OCA\Contacts\App::$l10n->t('Contact ID is missing.'));
}
$page = $tmpl->fetchPage();
OCP\JSON::success(array('data' => array('page' => $page)));
Ejemplo n.º 13
0
 * @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/>.
 *
 */
// Check if we are a user
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
OCP\JSON::callCheck();
require_once __DIR__ . '/../loghandler.php';
$id = isset($_POST['id']) ? $_POST['id'] : null;
if (!$id) {
    bailOut(OCA\Contacts\App::$l10n->t('id is not set.'));
}
try {
    OCA\Contacts\VCard::delete($id);
} catch (Exception $e) {
    bailOut($e->getMessage());
}
OCP\JSON::success(array('data' => array('id' => $id)));