예제 #1
0
파일: hooks.php 프로젝트: noci2012/owncloud
 public static function getBirthdayEvents($parameters)
 {
     $name = $parameters['calendar_id'];
     if (strpos('birthday_', $name) != 0) {
         return;
     }
     $info = explode('_', $name);
     $aid = $info[1];
     OC_Contacts_App::getAddressbook($aid);
     foreach (OC_Contacts_VCard::all($aid) as $card) {
         $vcard = OC_VObject::parse($card['carddata']);
         if (!$vcard) {
             continue;
         }
         $birthday = $vcard->BDAY;
         if ($birthday) {
             $date = new DateTime($birthday);
             $vevent = new OC_VObject('VEVENT');
             $vevent->setDateTime('LAST-MODIFIED', new DateTime($vcard->REV));
             $vevent->setDateTime('DTSTART', $date, Sabre_VObject_Element_DateTime::DATE);
             $vevent->setString('DURATION', 'P1D');
             // DESCRIPTION?
             $vevent->setString('RRULE', 'FREQ=YEARLY');
             $title = str_replace('{name}', $vcard->getAsString('FN'), OC_Contacts_App::$l10n->t('{name}\'s Birthday'));
             $parameters['events'][] = array('id' => 0, 'vevent' => $vevent, 'repeating' => true, 'summary' => $title);
         }
     }
 }
예제 #2
0
 public static function getBirthdayEvents($parameters)
 {
     $name = $parameters['calendar_id'];
     if (strpos($name, 'birthday_') != 0) {
         return;
     }
     $info = explode('_', $name);
     $aid = $info[1];
     OC_Contacts_App::getAddressbook($aid);
     foreach (OC_Contacts_VCard::all($aid) as $card) {
         $vcard = OC_VObject::parse($card['carddata']);
         if (!$vcard) {
             continue;
         }
         $birthday = $vcard->BDAY;
         if ($birthday) {
             $date = new DateTime($birthday);
             $vevent = new OC_VObject('VEVENT');
             //$vevent->setDateTime('LAST-MODIFIED', new DateTime($vcard->REV));
             $vevent->setDateTime('DTSTART', $date, Sabre_VObject_Element_DateTime::DATE);
             $vevent->setString('DURATION', 'P1D');
             $vevent->setString('UID', substr(md5(rand() . time()), 0, 10));
             // DESCRIPTION?
             $vevent->setString('RRULE', 'FREQ=YEARLY');
             $title = str_replace('{name}', $vcard->getAsString('FN'), OC_Contacts_App::$l10n->t('{name}\'s Birthday'));
             $parameters['events'][] = array('id' => 0, 'vevent' => $vevent, 'repeating' => true, 'summary' => $title, 'calendardata' => "BEGIN:VCALENDAR\nVERSION:2.0\n" . "PRODID:ownCloud Contacts " . OCP\App::getAppVersion('contacts') . "\n" . $vevent->serialize() . "END:VCALENDAR");
         }
     }
 }
예제 #3
0
 function search($query)
 {
     $addressbooks = OC_Contacts_Addressbook::all(OCP\USER::getUser(), 1);
     // 		if(count($calendars)==0 || !OCP\App::isEnabled('contacts')){
     // 			//return false;
     // 		}
     // NOTE: Does the following do anything
     $results = array();
     $searchquery = array();
     if (substr_count($query, ' ') > 0) {
         $searchquery = explode(' ', $query);
     } else {
         $searchquery[] = $query;
     }
     $l = new OC_l10n('contacts');
     foreach ($addressbooks as $addressbook) {
         $vcards = OC_Contacts_VCard::all($addressbook['id']);
         foreach ($vcards as $vcard) {
             if (substr_count(strtolower($vcard['fullname']), strtolower($query)) > 0) {
                 $link = OCP\Util::linkTo('contacts', 'index.php') . '?id=' . urlencode($vcard['id']);
                 $results[] = new OC_Search_Result($vcard['fullname'], '', $link, $l->t('Contact'));
                 //$name,$text,$link,$type
             }
         }
     }
     return $results;
 }
예제 #4
0
 function search($query)
 {
     $addressbooks = OC_Contacts_Addressbook::all(OCP\USER::getUser(), 1);
     if (count($addressbooks) == 0 || !OCP\App::isEnabled('contacts')) {
         return array();
     }
     $results = array();
     $l = new OC_l10n('contacts');
     foreach ($addressbooks as $addressbook) {
         $vcards = OC_Contacts_VCard::all($addressbook['id']);
         foreach ($vcards as $vcard) {
             if (substr_count(strtolower($vcard['fullname']), strtolower($query)) > 0) {
                 $link = OCP\Util::linkTo('contacts', 'index.php') . '&id=' . urlencode($vcard['id']);
                 $results[] = new OC_Search_Result($vcard['fullname'], '', $link, (string) $l->t('Contact'));
                 //$name,$text,$link,$type
             }
         }
     }
     return $results;
 }
예제 #5
0
function debug($msg)
{
    OCP\Util::writeLog('contacts', 'ajax/categories/delete.php: ' . $msg, OCP\Util::DEBUG);
}
$categories = isset($_POST['categories']) ? $_POST['categories'] : null;
if (is_null($categories)) {
    bailOut(OC_Contacts_App::$l10n->t('No categories selected for deletion.'));
}
debug(print_r($categories, true));
$addressbooks = OC_Contacts_Addressbook::all(OCP\USER::getUser());
if (count($addressbooks) == 0) {
    bailOut(OC_Contacts_App::$l10n->t('No address books found.'));
}
$addressbookids = array();
foreach ($addressbooks as $addressbook) {
    $addressbookids[] = $addressbook['id'];
}
$contacts = OC_Contacts_VCard::all($addressbookids);
if (count($contacts) == 0) {
    bailOut(OC_Contacts_App::$l10n->t('No contacts found.'));
}
$cards = array();
foreach ($contacts as $contact) {
    $cards[] = array($contact['id'], $contact['carddata']);
}
debug('Before delete: ' . print_r($categories, true));
$catman = new OC_VCategories('contacts');
$catman->delete($categories, $cards);
debug('After delete: ' . print_r($catman->categories(), true));
OC_Contacts_VCard::updateDataByID($cards);
OCP\JSON::success(array('data' => array('categories' => $catman->categories())));
예제 #6
0
 /**
  * Returns all cards for a specific addressbook id.
  *
  * @param mixed $addressbookid
  * @return array
  */
 public function getCards($addressbookid)
 {
     $data = OC_Contacts_VCard::all($addressbookid);
     $cards = array();
     foreach ($data as $i) {
         //OCP\Util::writeLog('contacts', __METHOD__.', uri: ' . $i['uri'], OCP\Util::DEBUG);
         $cards[] = array('id' => $i['id'], 'size' => strlen($i['carddata']), 'etag' => md5($i['carddata']), 'uri' => $i['uri'], 'lastmodified' => $i['lastmodified']);
     }
     return $cards;
 }
예제 #7
0
 /**
  * scan vcards for categories.
  * @param $vccontacts VCards to scan. null to check all vcards for the current user.
  */
 public static function scanCategories($vccontacts = null)
 {
     if (is_null($vccontacts)) {
         $vcaddressbooks = OC_Contacts_Addressbook::all(OCP\USER::getUser());
         if (count($vcaddressbooks) > 0) {
             $vcaddressbookids = array();
             foreach ($vcaddressbooks as $vcaddressbook) {
                 $vcaddressbookids[] = $vcaddressbook['id'];
             }
             $vccontacts = OC_Contacts_VCard::all($vcaddressbookids);
         }
     }
     if (is_array($vccontacts) && count($vccontacts) > 0) {
         $cards = array();
         foreach ($vccontacts as $vccontact) {
             $cards[] = $vccontact['carddata'];
         }
         self::$categories->rescan($cards);
     }
 }
예제 #8
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');
$ids = OC_Contacts_Addressbook::activeIds(OCP\USER::getUser());
$allcontacts = OC_Contacts_VCard::all($ids);
$contacts = array();
foreach ($allcontacts as $contact) {
    // try to conserve some memory
    $contacts[] = array('id' => $contact['id'], 'addressbookid' => $contact['addressbookid'], 'fullname' => $contact['fullname']);
}
unset($allcontacts);
$addressbooks = OC_Contacts_Addressbook::active(OCP\USER::getUser());
$tmpl = new OCP\Template("contacts", "part.contacts");
$tmpl->assign('contacts', $contacts);
$page = $tmpl->fetchPage();
OCP\JSON::success(array('data' => array('page' => $page)));
예제 #9
0
/**
 * Copyright (c) 2011-2012 Thomas Tanghus <*****@*****.**>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */
OCP\User::checkLoggedIn();
OCP\App::checkAppEnabled('contacts');
$bookid = isset($_GET['bookid']) ? $_GET['bookid'] : null;
$contactid = isset($_GET['contactid']) ? $_GET['contactid'] : null;
$nl = "\n";
if (isset($bookid)) {
    $addressbook = OC_Contacts_App::getAddressbook($bookid);
    //$cardobjects = OC_Contacts_VCard::all($bookid);
    header('Content-Type: text/directory');
    header('Content-Disposition: inline; filename=' . str_replace(' ', '_', $addressbook['displayname']) . '.vcf');
    $start = 0;
    $batchsize = OCP\Config::getUserValue(OCP\User::getUser(), 'contacts', 'export_batch_size', 20);
    while ($cardobjects = OC_Contacts_VCard::all($bookid, $start, $batchsize)) {
        foreach ($cardobjects as $card) {
            echo $card['carddata'] . $nl;
        }
        $start += $batchsize;
    }
} elseif (isset($contactid)) {
    $data = OC_Contacts_App::getContactObject($contactid);
    header('Content-Type: text/vcard');
    header('Content-Disposition: inline; filename=' . str_replace(' ', '_', $data['fullname']) . '.vcf');
    echo $data['carddata'];
}
예제 #10
0
파일: index.php 프로젝트: noci2012/owncloud
<?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 = 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.
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 = OC_Contacts_App::getTypesOfProperty('IMPP');
$phone_types = OC_Contacts_App::getTypesOfProperty('TEL');
$email_types = OC_Contacts_App::getTypesOfProperty('EMAIL');
$ims = OC_Contacts_App::getIMOptions();
$im_protocols = array();
foreach ($ims as $name => $values) {
    $im_protocols[$name] = $values['displayname'];
}
 /**
  * Returns all cards for a specific addressbook id.
  *
  * @param mixed $addressbookid
  * @return array
  */
 public function getCards($addressbookid)
 {
     $data = OC_Contacts_VCard::all($addressbookid);
     $cards = array();
     foreach ($data as $i) {
         $cards[] = array('id' => $i['id'], 'carddata' => $i['carddata'], 'uri' => $i['uri'], 'lastmodified' => $i['lastmodified']);
     }
     return $cards;
 }
예제 #12
0
$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();
// get next 50 for each addressbook.
foreach ($ids as $id) {
    if ($id) {
        $contacts_alphabet = array_merge($contacts_alphabet, OC_Contacts_VCard::all($id, $start, 50));
    }
}
// Our new array for the contacts sorted by addressbook
if ($contacts_alphabet) {
    foreach ($contacts_alphabet as $contact) {
        // 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 = OC_Contacts_App::getContactVCard($contact['id']);
            if (!is_null($vcard)) {
                $struct = OC_Contacts_VCard::structureContact($vcard);
                $display = isset($struct['EMAIL'][0]) ? $struct['EMAIL'][0]['value'] : '[UNKNOWN]';
예제 #13
0
<?php

/**
 * Copyright (c) 2011-2012 Thomas Tanghus <*****@*****.**>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */
OCP\User::checkLoggedIn();
OCP\App::checkAppEnabled('contacts');
$bookid = isset($_GET['bookid']) ? $_GET['bookid'] : NULL;
$contactid = isset($_GET['contactid']) ? $_GET['contactid'] : NULL;
$nl = "\n";
if (isset($bookid)) {
    $addressbook = OC_Contacts_App::getAddressbook($bookid);
    $cardobjects = OC_Contacts_VCard::all($bookid);
    header('Content-Type: text/directory');
    header('Content-Disposition: inline; filename=' . str_replace(' ', '_', $addressbook['displayname']) . '.vcf');
    foreach ($cardobjects as $card) {
        echo $card['carddata'] . $nl;
    }
} elseif (isset($contactid)) {
    $data = OC_Contacts_App::getContactObject($contactid);
    header('Content-Type: text/directory');
    header('Content-Disposition: inline; filename=' . str_replace(' ', '_', $data['fullname']) . '.vcf');
    echo $data['carddata'];
}
 /**
  * @brief removes an address book
  * @param integer $id
  * @return boolean
  */
 public static function delete($id)
 {
     $stmt = OC_DB::prepare('DELETE FROM *PREFIX*contacts_addressbooks WHERE id = ?');
     $stmt->execute(array($id));
     $cards = OC_Contacts_VCard::all($id);
     foreach ($cards as $card) {
         OC_Contacts_VCard::delete($card['id']);
     }
     return true;
 }
예제 #15
0
 /**
  * @brief removes an address book
  * @param integer $id
  * @return boolean
  */
 public static function delete($id)
 {
     // FIXME: There's no error checking at all.
     self::setActive($id, false);
     $stmt = OCP\DB::prepare('DELETE FROM *PREFIX*contacts_addressbooks WHERE id = ?');
     $stmt->execute(array($id));
     $cards = OC_Contacts_VCard::all($id);
     foreach ($cards as $card) {
         OC_Contacts_VCard::delete($card['id']);
     }
     return true;
 }
예제 #16
0
 /**
  * scan vcards for categories.
  * @param $vccontacts VCards to scan. null to check all vcards for the current user.
  */
 public static function scanCategories($vccontacts = null)
 {
     if (is_null($vccontacts)) {
         $vcaddressbooks = OC_Contacts_Addressbook::all(OCP\USER::getUser());
         if (count($vcaddressbooks) > 0) {
             $vcaddressbookids = array();
             foreach ($vcaddressbooks as $vcaddressbook) {
                 $vcaddressbookids[] = $vcaddressbook['id'];
             }
             $start = 0;
             $batchsize = 10;
             while ($vccontacts = OC_Contacts_VCard::all($vcaddressbookids, $start, $batchsize)) {
                 $cards = array();
                 foreach ($vccontacts as $vccontact) {
                     $cards[] = $vccontact['carddata'];
                 }
                 OCP\Util::writeLog('contacts', __CLASS__ . '::' . __METHOD__ . ', scanning: ' . $batchsize . ' starting from ' . $start, OCP\Util::DEBUG);
                 // only reset on first batch.
                 self::getVCategories()->rescan($cards, true, $start == 0 ? true : false);
                 $start += $batchsize;
             }
         }
     }
 }
예제 #17
0
 /**
  * @brief removes an address book
  * @param integer $id
  * @return boolean true on success, otherwise an exception will be thrown
  */
 public static function delete($id)
 {
     $addressbook = self::find($id);
     if ($addressbook['userid'] != OCP\User::getUser()) {
         $sharedAddressbook = OCP\Share::getItemSharedWithBySource('addressbook', $id);
         if (!$sharedAddressbook || !($sharedAddressbook['permissions'] & OCP\Share::PERMISSION_DELETE)) {
             throw new Exception(OC_Contacts_App::$l10n->t('You do not have the permissions to delete this addressbook.'));
         }
     }
     // First delete cards belonging to this addressbook.
     $cards = OC_Contacts_VCard::all($id);
     foreach ($cards as $card) {
         try {
             OC_Contacts_VCard::delete($card['id']);
         } catch (Exception $e) {
             OCP\Util::writeLog('contacts', __METHOD__ . ', exception deleting vCard ' . $card['id'] . ': ' . $e->getMessage(), OCP\Util::ERROR);
         }
     }
     try {
         $stmt = OCP\DB::prepare('DELETE FROM `*PREFIX*contacts_addressbooks` WHERE `id` = ?');
         $stmt->execute(array($id));
     } catch (Exception $e) {
         OCP\Util::writeLog('contacts', __METHOD__ . ', exception for ' . $id . ': ' . $e->getMessage(), OCP\Util::ERROR);
         throw new Exception(OC_Contacts_App::$l10n->t('There was an error deleting this addressbook.'));
     }
     // TODO: Unshare all when that method is created
     //OCP\Share::unshare('addressbook', $id);
     if (count(self::all(OCP\User::getUser())) == 0) {
         self::addDefault();
     }
     return true;
 }
$prefbooks = OC_Preferences::getValue(OC_User::getUser(), 'contacts', 'openaddressbooks', null);
if (is_null($prefbooks)) {
    $prefbooks = $addressbooks[0]['id'];
    OC_Preferences::setValue(OC_User::getUser(), 'contacts', 'openaddressbooks', $prefbooks);
}
// Load the files we need
OC_App::setActiveNavigationEntry('contacts_index');
// Load a specific user?
$id = isset($_GET['id']) ? $_GET['id'] : null;
// sort addressbooks  (use contactsort)
usort($addressbooks, 'contacts_namesort');
// Addressbooks to load
$openaddressbooks = explode(';', $prefbooks);
$contacts = array();
foreach ($openaddressbooks as $addressbook) {
    $addressbookcontacts = OC_Contacts_VCard::all($addressbook);
    foreach ($addressbookcontacts as $contact) {
        if (is_null($contact['fullname'])) {
            continue;
        }
        $contacts[] = array('name' => $contact['fullname'], 'id' => $contact['id']);
    }
}
usort($contacts, 'contacts_namesort');
$details = array();
if (!is_null($id) || count($contacts)) {
    if (is_null($id)) {
        $id = $contacts[0]['id'];
    }
    $contact = OC_Contacts_VCard::find($id);
    $vcard = OC_Contacts_VCard::parse($contact['carddata']);