Esempio n. 1
0
 public static function getContactObject($id)
 {
     $card = OC_Contacts_VCard::find($id);
     if ($card === false) {
         OCP\Util::writeLog('contacts', 'Contact could not be found: ' . $id, OCP\Util::ERROR);
         OCP\JSON::error(array('data' => array('message' => self::$l10n->t('Contact could not be found.') . ' ' . $id)));
         exit;
     }
     self::getAddressbook($card['addressbookid']);
     //access check
     return $card;
 }
Esempio n. 2
0
 public function formatItems($items, $format, $parameters = null)
 {
     $contacts = array();
     if ($format == self::FORMAT_CONTACT) {
         foreach ($items as $item) {
             $contact = OC_Contacts_VCard::find($item['item_source']);
             $contact['fullname'] = $item['item_target'];
             $contacts[] = $contact;
         }
     }
     return $contacts;
 }
 * 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';
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;
// 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']);
    $details = OC_Contacts_VCard::structureContact($vcard);
}
// Process the template
$tmpl = new OC_Template('contacts', 'index', 'user');
$tmpl->assign('addressbooks', $addressbooks);
$tmpl->assign('contacts', $contacts);
$tmpl->assign('details', $details);
$tmpl->assign('id', $id);
$tmpl->printPage();