예제 #1
0
 public static function getAddressbook($id)
 {
     $addressbook = OC_Contacts_Addressbook::find($id);
     if ($addressbook === false || $addressbook['userid'] != OCP\USER::getUser()) {
         if ($addressbook === false) {
             OCP\Util::writeLog('contacts', 'Addressbook not found: ' . $id, OCP\Util::ERROR);
             OCP\JSON::error(array('data' => array('message' => self::$l10n->t('Addressbook not found.'))));
         } else {
             OCP\Util::writeLog('contacts', 'Addressbook(' . $id . ') is not from ' . OCP\USER::getUser(), OCP\Util::ERROR);
             OCP\JSON::error(array('data' => array('message' => self::$l10n->t('This is not your addressbook.'))));
         }
         exit;
     }
     return $addressbook;
 }
예제 #2
0
 public static function getAddressbook($id)
 {
     // TODO: Throw an exception instead of returning json.
     $addressbook = OC_Contacts_Addressbook::find($id);
     if ($addressbook === false || $addressbook['userid'] != OCP\USER::getUser()) {
         if ($addressbook === false) {
             OCP\Util::writeLog('contacts', 'Addressbook not found: ' . $id, OCP\Util::ERROR);
             //throw new Exception('Addressbook not found: '. $id);
             OCP\JSON::error(array('data' => array('message' => self::$l10n->t('Addressbook not found: ' . $id))));
         } else {
             $sharedAddressbook = OCP\Share::getItemSharedWithBySource('addressbook', $id, OC_Share_Backend_Addressbook::FORMAT_ADDRESSBOOKS);
             if ($sharedAddressbook) {
                 return $sharedAddressbook[0];
             } else {
                 OCP\Util::writeLog('contacts', 'Addressbook(' . $id . ') is not from ' . OCP\USER::getUser(), OCP\Util::ERROR);
                 //throw new Exception('This is not your addressbook.');
                 OCP\JSON::error(array('data' => array('message' => self::$l10n->t('This is not your addressbook.'))));
             }
         }
     }
     return $addressbook;
 }
 * 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';
OC_Util::checkLoggedIn();
OC_Util::checkAppEnabled('contacts');
$id = $_GET['id'];
$l10n = new OC_L10N('contacts');
$card = OC_Contacts_VCard::find($id);
if ($card === false) {
    echo $l10n->t('Contact could not be found.');
    exit;
}
$addressbook = OC_Contacts_Addressbook::find($card['addressbookid']);
if ($addressbook === false || $addressbook['userid'] != OC_USER::getUser()) {
    echo $l10n->t('This is not your contact.');
    // This is a weird error, why would it come up? (Better feedback for users?)
    exit;
}
$content = OC_Contacts_VCard::parse($card['carddata']);
// invalid vcard
if (is_null($content)) {
    echo $l10n->t('This card is not RFC compatible.');
    exit;
}
// Photo :-)
foreach ($content->children as $child) {
    if ($child->name == 'PHOTO') {
        $mime = 'image/jpeg';
예제 #4
0
파일: vcard.php 프로젝트: noci2012/owncloud
 /**
  * @brief Move card(s) to an address book
  * @param integer $aid Address book id
  * @param $id Array or integer of cards to be moved.
  * @return boolean
  *
  */
 public static function moveToAddressBook($aid, $id, $isAddressbook = false)
 {
     OC_Contacts_App::getAddressbook($aid);
     // check for user ownership.
     $addressbook = OC_Contacts_Addressbook::find($aid);
     if ($addressbook['userid'] != OCP\User::getUser()) {
         $sharedAddressbook = OCP\Share::getItemSharedWithBySource('addressbook', $aid);
         if (!$sharedAddressbook || !($sharedAddressbook['permissions'] & OCP\Share::PERMISSION_CREATE)) {
             return false;
         }
     }
     if (is_array($id)) {
         foreach ($id as $index => $cardId) {
             $card = self::find($cardId);
             if (!$card) {
                 unset($id[$index]);
             }
             $oldAddressbook = OC_Contacts_Addressbook::find($card['addressbookid']);
             if ($oldAddressbook['userid'] != OCP\User::getUser()) {
                 $sharedContact = OCP\Share::getItemSharedWithBySource('contact', $cardId, OCP\Share::FORMAT_NONE, null, true);
                 if (!$sharedContact || !($sharedContact['permissions'] & OCP\Share::PERMISSION_DELETE)) {
                     unset($id[$index]);
                 }
             }
         }
         $id_sql = join(',', array_fill(0, count($id), '?'));
         $prep = 'UPDATE `*PREFIX*contacts_cards` SET `addressbookid` = ? WHERE `id` IN (' . $id_sql . ')';
         try {
             $stmt = OCP\DB::prepare($prep);
             //$aid = array($aid);
             $vals = array_merge((array) $aid, $id);
             $result = $stmt->execute($vals);
         } catch (Exception $e) {
             OCP\Util::writeLog('contacts', __METHOD__ . ', exception: ' . $e->getMessage(), OCP\Util::ERROR);
             OCP\Util::writeLog('contacts', __METHOD__ . ', ids: ' . join(',', $vals), OCP\Util::DEBUG);
             OCP\Util::writeLog('contacts', __METHOD__ . ', SQL:' . $prep, OCP\Util::DEBUG);
             return false;
         }
     } else {
         $stmt = null;
         if ($isAddressbook) {
             $stmt = OCP\DB::prepare('UPDATE `*PREFIX*contacts_cards` SET `addressbookid` = ? WHERE `addressbookid` = ?');
         } else {
             $card = self::find($id);
             if (!$card) {
                 return false;
             }
             $oldAddressbook = OC_Contacts_Addressbook::find($card['addressbookid']);
             if ($oldAddressbook['userid'] != OCP\User::getUser()) {
                 $sharedContact = OCP\Share::getItemSharedWithBySource('contact', $id, OCP\Share::FORMAT_NONE, null, true);
                 if (!$sharedContact || !($sharedContact['permissions'] & OCP\Share::PERMISSION_DELETE)) {
                     return false;
                 }
             }
             $stmt = OCP\DB::prepare('UPDATE `*PREFIX*contacts_cards` SET `addressbookid` = ? WHERE `id` = ?');
         }
         try {
             $result = $stmt->execute(array($aid, $id));
         } catch (Exception $e) {
             OCP\Util::writeLog('contacts', __METHOD__ . ', exception: ' . $e->getMessage(), OCP\Util::DEBUG);
             OCP\Util::writeLog('contacts', __METHOD__ . ' id: ' . $id, OCP\Util::DEBUG);
             return false;
         }
     }
     OC_Hook::emit('OC_Contacts_VCard', 'post_moveToAddressbook', array('aid' => $aid, 'id' => $id));
     OC_Contacts_Addressbook::touch($aid);
     return true;
 }
 * @author Jakob Sack
 * @copyright 2011 Jakob Sack mail@jakobsack.de
 *
 * 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';
$id = $_GET['id'];
$l10n = new OC_L10N('contacts');
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
$addressbook = OC_Contacts_Addressbook::find($id);
if ($addressbook === false || $addressbook['userid'] != OC_USER::getUser()) {
    OC_JSON::error(array('data' => array('message' => $l10n->t('This is not your contact.'))));
    exit;
}
OC_Contacts_Addressbook::delete($id);
OC_JSON::success(array('data' => array('id' => $id)));
예제 #6
0
{
    if ($a['displayname'] == $b['displayname']) {
        return 0;
    }
    return $a['displayname'] < $b['displayname'] ? -1 : 1;
}
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
$start = isset($_GET['startat']) ? $_GET['startat'] : 0;
$aid = isset($_GET['aid']) ? $_GET['aid'] : null;
if (is_null($aid)) {
    // Called initially to get the active addressbooks.
    $active_addressbooks = OC_Contacts_Addressbook::active(OCP\USER::getUser());
} else {
    // called each time more contacts has to be shown.
    $active_addressbooks = array(OC_Contacts_Addressbook::find($aid));
}
session_write_close();
// create the addressbook associate array
$contacts_addressbook = array();
$ids = array();
foreach ($active_addressbooks as $addressbook) {
    $ids[] = $addressbook['id'];
    if (!isset($contacts_addressbook[$addressbook['id']])) {
        $contacts_addressbook[$addressbook['id']] = array('contacts' => array('type' => 'book'));
        $contacts_addressbook[$addressbook['id']]['displayname'] = $addressbook['displayname'];
        $contacts_addressbook[$addressbook['id']]['permissions'] = $addressbook['permissions'];
        $contacts_addressbook[$addressbook['id']]['owner'] = $addressbook['userid'];
    }
}
$contacts_alphabet = array();