summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrank Karlitschek <karlitschek@kde.org>2011-08-06 23:19:40 +0200
committerFrank Karlitschek <karlitschek@kde.org>2011-08-06 23:19:40 +0200
commita689fa18dfb66226527499ea707b2ff517561851 (patch)
tree4c47cbcfbdb46b4f00d50893fc07794670b864e6
parentb513a6054036455605d96f1d1827e156b2127ce3 (diff)
parent6d5402247c9a2d6cf5f8e716d9ab99d688e07038 (diff)
downloadnextcloud-server-a689fa18dfb66226527499ea707b2ff517561851.tar.gz
nextcloud-server-a689fa18dfb66226527499ea707b2ff517561851.zip
Merge branch 'master' of git.kde.org:owncloud
-rw-r--r--apps/contacts/appinfo/app.php18
-rw-r--r--apps/contacts/appinfo/database.xml129
-rw-r--r--apps/contacts/appinfo/info.xml9
-rw-r--r--apps/contacts/carddav.php28
-rw-r--r--apps/contacts/css/styles.css1
-rw-r--r--apps/contacts/details.php57
-rw-r--r--apps/contacts/img/icon.pngbin0 -> 741 bytes
-rw-r--r--apps/contacts/index.php68
-rw-r--r--apps/contacts/js/interface.js14
-rw-r--r--apps/contacts/lib/addressbook.php287
-rw-r--r--apps/contacts/lib/connector_sabre.php186
-rw-r--r--apps/contacts/photo.php85
-rw-r--r--apps/contacts/templates/_contacts.php3
-rw-r--r--apps/contacts/templates/_details.php4
-rw-r--r--apps/contacts/templates/index.php13
-rw-r--r--apps/contacts/temporaryupdate.php13
-rw-r--r--core/js/js.js65
-rw-r--r--lib/base.php10
-rw-r--r--lib/connector/sabre/principal.php4
19 files changed, 987 insertions, 7 deletions
diff --git a/apps/contacts/appinfo/app.php b/apps/contacts/appinfo/app.php
new file mode 100644
index 00000000000..f38a45f2790
--- /dev/null
+++ b/apps/contacts/appinfo/app.php
@@ -0,0 +1,18 @@
+<?php
+
+OC::$CLASSPATH['OC_Contacts_Addressbook'] = 'apps/contacts/lib/addressbook.php';
+OC::$CLASSPATH['OC_Connector_Sabre_CardDAV'] = 'apps/contacts/lib/connector_sabre.php';
+
+OC_App::register( array(
+ 'order' => 10,
+ 'id' => 'contacts',
+ 'name' => 'Contacts' ));
+
+OC_App::addNavigationEntry( array(
+ 'id' => 'contacts_index',
+ 'order' => 10,
+ 'href' => OC_Helper::linkTo( 'contacts', 'index.php' ),
+ 'icon' => OC_Helper::imagePath( 'contacts', 'icon.png' ),
+ 'name' => 'Addressbook' ));
+
+?>
diff --git a/apps/contacts/appinfo/database.xml b/apps/contacts/appinfo/database.xml
new file mode 100644
index 00000000000..7c8268d71f5
--- /dev/null
+++ b/apps/contacts/appinfo/database.xml
@@ -0,0 +1,129 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<database>
+
+ <name>*dbname*</name>
+ <create>true</create>
+ <overwrite>false</overwrite>
+
+ <charset>utf8</charset>
+
+ <table>
+
+ <name>*dbprefix*contacts_addressbooks</name>
+
+ <declaration>
+
+ <field>
+ <name>id</name>
+ <type>integer</type>
+ <default>0</default>
+ <notnull>true</notnull>
+ <autoincrement>1</autoincrement>
+ <unsigned>true</unsigned>
+ <length>4</length>
+ </field>
+
+ <field>
+ <name>userid</name>
+ <type>text</type>
+ <default></default>
+ <notnull>true</notnull>
+ <length>255</length>
+ </field>
+
+ <field>
+ <name>displayname</name>
+ <type>text</type>
+ <default></default>
+ <notnull>false</notnull>
+ <length>255</length>
+ </field>
+
+ <field>
+ <name>uri</name>
+ <type>text</type>
+ <default></default>
+ <notnull>false</notnull>
+ <length>100</length>
+ </field>
+
+ <field>
+ <name>description</name>
+ <type>clob</type>
+ <notnull>false</notnull>
+ </field>
+
+ <field>
+ <name>ctag</name>
+ <type>integer</type>
+ <default>1</default>
+ <notnull>true</notnull>
+ <unsigned>true</unsigned>
+ <length>4</length>
+ </field>
+
+ </declaration>
+
+ </table>
+
+ <table>
+
+ <name>*dbprefix*contacts_cards</name>
+
+ <declaration>
+
+ <field>
+ <name>id</name>
+ <type>integer</type>
+ <default>0</default>
+ <notnull>true</notnull>
+ <autoincrement>1</autoincrement>
+ <unsigned>true</unsigned>
+ <length>4</length>
+ </field>
+
+ <field>
+ <name>addressbookid</name>
+ <type>integer</type>
+ <default></default>
+ <notnull>true</notnull>
+ <unsigned>true</unsigned>
+ <length>4</length>
+ </field>
+
+ <field>
+ <name>fullname</name>
+ <type>text</type>
+ <default></default>
+ <notnull>false</notnull>
+ <length>255</length>
+ </field>
+
+ <field>
+ <name>carddata</name>
+ <type>clob</type>
+ <notnull>false</notnull>
+ </field>
+
+ <field>
+ <name>uri</name>
+ <type>text</type>
+ <default></default>
+ <notnull>false</notnull>
+ <length>100</length>
+ </field>
+
+ <field>
+ <name>lastmodified</name>
+ <type>integer</type>
+ <default></default>
+ <notnull>false</notnull>
+ <unsigned>true</unsigned>
+ <length>4</length>
+ </field>
+
+ </declaration>
+
+ </table>
+
+</database>
diff --git a/apps/contacts/appinfo/info.xml b/apps/contacts/appinfo/info.xml
new file mode 100644
index 00000000000..93463b9cf09
--- /dev/null
+++ b/apps/contacts/appinfo/info.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0"?>
+<info>
+ <id>contacts</id>
+ <name>Contacts</name>
+ <version>0.1</version>
+ <licence>AGPL</licence>
+ <author>Jakob Sack</author>
+ <require>2</require>
+</info>
diff --git a/apps/contacts/carddav.php b/apps/contacts/carddav.php
new file mode 100644
index 00000000000..ae2c5b97363
--- /dev/null
+++ b/apps/contacts/carddav.php
@@ -0,0 +1,28 @@
+<?php
+
+// Do not load FS ...
+$RUNTIME_NOSETUPFS = true;
+
+require_once('../../lib/base.php');
+
+// Backends
+$authBackend = new OC_Connector_Sabre_Auth();
+$principalBackend = new OC_Connector_Sabre_Principal();
+$carddavBackend = new OC_Connector_Sabre_CardDAV();
+
+// Root nodes
+$nodes = array(
+ new Sabre_DAVACL_PrincipalCollection($principalBackend),
+ new Sabre_CardDAV_AddressBookRoot($principalBackend, $carddavBackend),
+);
+
+// Fire up server
+$server = new Sabre_DAV_Server($nodes);
+$server->setBaseUri($WEBROOT.'/apps/contacts/carddav.php');
+// Add plugins
+$server->addPlugin(new Sabre_DAV_Auth_Plugin($authBackend,'ownCloud'));
+$server->addPlugin(new Sabre_CardDAV_Plugin());
+$server->addPlugin(new Sabre_DAVACL_Plugin());
+
+// And off we go!
+$server->exec();
diff --git a/apps/contacts/css/styles.css b/apps/contacts/css/styles.css
new file mode 100644
index 00000000000..8d1c8b69c3f
--- /dev/null
+++ b/apps/contacts/css/styles.css
@@ -0,0 +1 @@
+
diff --git a/apps/contacts/details.php b/apps/contacts/details.php
new file mode 100644
index 00000000000..7ab1b64de24
--- /dev/null
+++ b/apps/contacts/details.php
@@ -0,0 +1,57 @@
+<?php
+/**
+ * ownCloud - Addressbook
+ *
+ * @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
+if( !OC_User::isLoggedIn()){
+ echo $l10n->t('You need to log in!');
+ exit();
+}
+
+
+$card = OC_Contacts_Addressbook::findCard( $id );
+if( $card === false ){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('Can not find Contact!'))));
+ exit();
+}
+
+$addressbook = OC_Contacts_Addressbook::findAddressbook( $card['addressbookid'] );
+if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('This is not your contact!'))));
+ exit();
+}
+
+$vcard = Sabre_VObject_Reader::read($card['carddata']);
+$details = OC_Contacts_Addressbook::structureContact($vcard);
+
+$tmpl = new OC_Template('contacts','_details');
+$tmpl->assign('details',$details);
+$tmpl->assign('id',$id);
+$page = $tmpl->fetchPage();
+
+echo json_encode( array( 'status' => 'success', 'data' => array( 'page' => $page )));
diff --git a/apps/contacts/img/icon.png b/apps/contacts/img/icon.png
new file mode 100644
index 00000000000..ea2ed9e3335
--- /dev/null
+++ b/apps/contacts/img/icon.png
Binary files differ
diff --git a/apps/contacts/index.php b/apps/contacts/index.php
new file mode 100644
index 00000000000..2d5bcefd875
--- /dev/null
+++ b/apps/contacts/index.php
@@ -0,0 +1,68 @@
+<?php
+/**
+ * ownCloud - Addressbook
+ *
+ * @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/>.
+ *
+ */
+
+function contactsort($a,$b){
+ return strcmp($a['name'],$b['name']);
+}
+
+// Init owncloud
+require_once('../../lib/base.php');
+
+// Check if we are a user
+if( !OC_User::isLoggedIn()){
+ header( 'Location: '.OC_Helper::linkTo( '', 'index.php' ));
+ exit();
+}
+
+// Load the files we need
+OC_App::setActiveNavigationEntry( 'contacts_index' );
+
+// Load a specific user?
+$id = isset( $_GET['id'] ) ? $_GET['id'] : null;
+
+// Addressbooks to load
+$openaddressbooks = explode(';',OC_Preferences::getValue(OC_User::getUser(),'contacts','openaddressbooks',null));
+
+$contacts = array();
+foreach( $openaddressbooks as $addressbook ){
+ $addressbookcontacts = OC_Contacts_Addressbook::allCards($addressbook);
+ foreach( $addressbookcontacts as $contact ){
+ $contacts[] = array( 'name' => $contact['fullname'], 'id' => $contact['id'] );
+ }
+}
+
+
+usort($contacts,'contactsort');
+$details = array();
+
+if( !is_null($id) || count($contacts)){
+ $contact = OC_Contacts_Addressbook::findCard(is_null($id)?$contacts[0]['id']:$id);
+ $vcard = Sabre_VObject_Reader::read($contact['carddata']);
+ $details = OC_Contacts_Addressbook::structureContact($vcard);
+}
+
+// Process the template
+$tmpl = new OC_Template( 'contacts', 'index', 'user' );
+$tmpl->assign('contacts', $contacts);
+$tmpl->assign('details', $details );
+$tmpl->assign('id',$id);
+$tmpl->printPage();
diff --git a/apps/contacts/js/interface.js b/apps/contacts/js/interface.js
new file mode 100644
index 00000000000..045562b496f
--- /dev/null
+++ b/apps/contacts/js/interface.js
@@ -0,0 +1,14 @@
+$(document).ready(function(){
+ $('.contacts_contacts').find('li').live('click',function(){
+ var id = $(this).attr('x-id');
+ $.getJSON('details.php',{'id':id},function(jsondata){
+ if(jsondata.status == 'success'){
+ $('.contacts_details').html(jsondata.data.page);
+ }
+ else{
+ alert(jsondata.data.message);
+ }
+ });
+ return false;
+ });
+});
diff --git a/apps/contacts/lib/addressbook.php b/apps/contacts/lib/addressbook.php
new file mode 100644
index 00000000000..c0f26c7df55
--- /dev/null
+++ b/apps/contacts/lib/addressbook.php
@@ -0,0 +1,287 @@
+<?php
+/**
+ * ownCloud - Addressbook
+ *
+ * @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/>.
+ *
+ */
+/*
+ *
+ * The following SQL statement is just a help for developers and will not be
+ * executed!
+ *
+ * CREATE TABLE contacts_addressbooks (
+ * id INT(11) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
+ * userid VARCHAR(255) NOT NULL,
+ * displayname VARCHAR(255),
+ * uri VARCHAR(100),
+ * description TEXT,
+ * ctag INT(11) UNSIGNED NOT NULL DEFAULT '1'
+ * );
+ *
+ * CREATE TABLE contacts_cards (
+ * id INT(11) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
+ * addressbookid INT(11) UNSIGNED NOT NULL,
+ * fullname VARCHAR(255),
+ * carddata TEXT,
+ * uri VARCHAR(100),
+ * lastmodified INT(11) UNSIGNED
+ * );
+ */
+
+/**
+ * This class manages our addressbooks.
+ */
+class OC_Contacts_Addressbook{
+ public static function allAddressbooks($uid){
+ $stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*contacts_addressbooks WHERE userid = ?' );
+ $result = $stmt->execute(array($uid));
+
+ $addressbooks = array();
+ while( $row = $result->fetchRow()){
+ $addressbooks[] = $row;
+ }
+
+ return $addressbooks;
+ }
+
+ public static function allAddressbooksWherePrincipalURIIs($principaluri){
+ $uid = self::extractUserID($principaluri);
+ return self::allAddressbooks($uid);
+ }
+
+ public static function findAddressbook($id){
+ $stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*contacts_addressbooks WHERE id = ?' );
+ $result = $stmt->execute(array($id));
+
+ return $result->fetchRow();
+ }
+
+ public static function addAddressbook($userid,$name,$description){
+ $all = self::allAddressbooks($userid);
+ $uris = array();
+ foreach($all as $i){
+ $uris[] = $i['uri'];
+ }
+
+ $uri = self::createURI('name', $uris );
+
+ $stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*contacts_addressbooks (userid,displayname,uri,description,ctag) VALUES(?,?,?,?,?)' );
+ $result = $stmt->execute(array($userid,$name,$uri,$description,1));
+
+ return OC_DB::insertid();
+ }
+
+ public static function addAddressbookFromDAVData($principaluri,$uri,$name,$description){
+ $userid = self::extractUserID($principaluri);
+
+ $stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*contacts_addressbooks (userid,displayname,uri,description,ctag) VALUES(?,?,?,?,?)' );
+ $result = $stmt->execute(array($userid,$name,$uri,$description,1));
+
+ return OC_DB::insertid();
+ }
+
+ public static function editAddressbook($id,$name,$description){
+ // Need these ones for checking uri
+ $addressbook = self::find($id);
+
+ if(is_null($name)){
+ $name = $addressbook['name'];
+ }
+ if(is_null($description)){
+ $description = $addressbook['description'];
+ }
+
+ $stmt = OC_DB::prepare( 'UPDATE *PREFIX*contacts_addressbooks SET displayname=?,description=?, ctag=ctag+1 WHERE id=?' );
+ $result = $stmt->execute(array($name,$description,$id));
+
+ return true;
+ }
+
+ public static function touchAddressbook($id){
+ $stmt = OC_DB::prepare( 'UPDATE *PREFIX*contacts_addressbooks SET ctag = ctag + 1 WHERE id = ?' );
+ $stmt->execute(array($id));
+
+ return true;
+ }
+
+ public static function deleteAddressbook($id){
+ $stmt = OC_DB::prepare( 'DELETE FROM *PREFIX*contacts_cards WHERE id = ?' );
+ $stmt->execute(array($id));
+
+ $stmt = OC_DB::prepare( 'DELETE FROM *PREFIX*contacts_addressbooks WHERE addressbookid = ?' );
+ $stmt->execute(array($id));
+
+ return true;
+ }
+
+ public static function allCards($id){
+ $stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*contacts_cards WHERE addressbookid = ?' );
+ $result = $stmt->execute(array($id));
+
+ $addressbooks = array();
+ while( $row = $result->fetchRow()){
+ $addressbooks[] = $row;
+ }
+
+ return $addressbooks;
+ }
+
+ public static function findCard($id){
+ $stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*contacts_cards WHERE id = ?' );
+ $result = $stmt->execute(array($id));
+
+ return $result->fetchRow();
+ }
+
+ public static function findCardWhereDAVDataIs($aid,$uri){
+ $stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*contacts_cards WHERE addressbookid = ? AND uri = ?' );
+ $result = $stmt->execute(array($aid,$uri));
+
+ return $result->fetchRow();
+ }
+
+ public static function addCard($id,$data){
+ $fn = null;
+ $uri = null;
+ $card = Sabre_VObject_Reader::read($data);
+ foreach($card->children as $property){
+ if($property->name == 'FN'){
+ $fn = $property->value;
+ }
+ elseif(is_null($uri) && $property->name == 'UID' ){
+ $uri = $property->value.'.vcf';
+ }
+ }
+ $uri = self::createUID().'.vcf';
+
+ $stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*contacts_cards (addressbookid,fullname,carddata,uri,lastmodified) VALUES(?,?,?,?,?)' );
+ $result = $stmt->execute(array($id,$fn,$data,$uri,time()));
+
+ self::touch($id);
+
+ return OC_DB::insertid;
+ }
+
+ public static function addCardFromDAVData($id,$uri,$data){
+ $fn = null;
+ $card = Sabre_VObject_Reader::read($data);
+ foreach($card->children as $property){
+ if($property->name == 'FN'){
+ $fn = $property->value;
+ }
+ }
+
+ $stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*contacts_cards (addressbookid,fullname,carddata,uri,lastmodified) VALUES(?,?,?,?,?)' );
+ $result = $stmt->execute(array($id,$fn,$data,$uri,time()));
+
+ self::touch($id);
+
+ return OC_DB::insertid;
+ }
+
+ public static function editCard($id, $data){
+ $oldcard = self::findCard($id,$aid,$uri);
+ $fn = null;
+ $card = Sabre_VObject_Reader::read($data);
+ foreach($card->children as $property){
+ if($property->name == 'FN'){
+ $fn = $property->value;
+ }
+ }
+
+ $stmt = OC_DB::prepare( 'UPDATE *PREFIX*contacts_cards SET fullname = ?,carddata = ?, lastmodified = ? WHERE id = ?' );
+ $result = $stmt->execute(array($fn,$data,time(),$id));
+
+ self::touch($oldcard['addressbookid']);
+
+ return true;
+ }
+
+ public static function editCardFromDAVData($aid,$uri,$data){
+ $oldcard = self::findCardWhereDAVDataIs($aid,$uri);
+
+ $fn = null;
+ $card = Sabre_VObject_Reader::read($data);
+ foreach($card->children as $property){
+ if($property->name == 'FN'){
+ $fn = $property->value;
+ }
+ }
+
+ $stmt = OC_DB::prepare( 'UPDATE *PREFIX*contacts_cards SET fullname = ?,carddata = ?, lastmodified = ? WHERE id = ?' );
+ $result = $stmt->execute(array($fn,$data,time(),$oldcard['id']));
+
+ self::touch($oldcard['addressbookid']);
+
+ return true;
+ }
+
+ public static function deleteCard($id){
+ $stmt = OC_DB::prepare( 'DELETE FROM *PREFIX*contacts_addressbooks WHERE id = ?' );
+ $stmt->execute(array($id));
+
+ return true;
+ }
+
+ public static function deleteCardFromDAVData($aid,$uri){
+ $stmt = OC_DB::prepare( 'DELETE FROM *PREFIX*contacts_addressbooks WHERE addressbookid = ? AND uri=?' );
+ $stmt->execute(array($aid,$uri));
+
+ return true;
+ }
+
+ public static function createURI($name,$existing){
+ $name = strtolower($name);
+ $newname = $name;
+ $i = 1;
+ while(in_array($newname,$existing)){
+ $newname = $name.$i;
+ $i = $i + 1;
+ }
+ return $newname;
+ }
+
+ public static function createUID(){
+ return substr(md5(rand().time()),0,10);
+ }
+
+ public static function extractUserID($principaluri){
+ list($prefix,$userid) = Sabre_DAV_URLUtil::splitPath($principaluri);
+ return $userid;
+ }
+
+ public static function structureContact($object){
+ $details = array();
+ foreach($object->children as $property){
+ $temp = array(
+ 'name' => $property->name,
+ 'value' => ($property->name == 'PHOTO' || $property->name == 'LOGO' ? null : $property->value ),
+ 'parameters' => array());
+ foreach($property->parameters as $parameter){
+ $temp['parameters'][] = array( 'name' => $parameter->name, 'value' => $parameter->value);
+ }
+ if(array_key_exists($property->name,$details)){
+ $details[$property->name][] = $temp;
+ }
+ else{
+ $details[$property->name] = array($temp);
+ }
+ }
+ return $details;
+ }
+}
diff --git a/apps/contacts/lib/connector_sabre.php b/apps/contacts/lib/connector_sabre.php
new file mode 100644
index 00000000000..98e2598b3a7
--- /dev/null
+++ b/apps/contacts/lib/connector_sabre.php
@@ -0,0 +1,186 @@
+<?php
+
+/**
+ * PDO CardDAV backend
+ *
+ * @package Sabre
+ * @subpackage CardDAV
+ * @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
+ * @author Evert Pot (http://www.rooftopsolutions.nl/)
+ * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
+ */
+
+/**
+ * This CardDAV backend uses PDO to store addressbooks
+ */
+class OC_Connector_Sabre_CardDAV extends Sabre_CardDAV_Backend_Abstract {
+ /**
+ * Returns the list of addressbooks for a specific user.
+ *
+ * @param string $principaluri
+ * @return array
+ */
+ public function getAddressBooksForUser($principaluri) {
+ $data = OC_Contacts_Addressbook::allAddressbooksWherePrincipalURIIs($principaluri);
+ $addressbooks = array();
+
+ foreach($data as $i) {
+ $addressbooks[] = array(
+ 'id' => $i['id'],
+ 'uri' => $i['uri'],
+ 'principaluri' => 'principals/'.$i['userid'],
+ '{DAV:}displayname' => $i['displayname'],
+ '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => $i['description'],
+ '{http://calendarserver.org/ns/}getctag' => $i['ctag'],
+ );
+ }
+
+ return $addressbooks;
+ }
+
+
+ /**
+ * Updates an addressbook's properties
+ *
+ * See Sabre_DAV_IProperties for a description of the mutations array, as
+ * well as the return value.
+ *
+ * @param mixed $addressbookid
+ * @param array $mutations
+ * @see Sabre_DAV_IProperties::updateProperties
+ * @return bool|array
+ */
+ public function updateAddressBook($addressbookid, array $mutations) {
+ $name = null;
+ $description = null;
+
+ foreach($mutations as $property=>$newvalue) {
+ switch($property) {
+ case '{DAV:}displayname' :
+ $name = $newvalue;
+ break;
+ case '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' :
+ $description = $newvalue;
+ break;
+ default :
+ // If any unsupported values were being updated, we must
+ // let the entire request fail.
+ return false;
+ }
+ }
+
+ OC_Contacts_Addressbook::editAddressbook($addressbookid,$name,$description);
+
+ return true;
+
+ }
+
+ /**
+ * Creates a new address book
+ *
+ * @param string $principaluri
+ * @param string $url Just the 'basename' of the url.
+ * @param array $properties
+ * @return void
+ */
+ public function createAddressBook($principaluri, $url, array $properties) {
+
+ $displayname = null;
+ $description = null;
+
+ foreach($properties as $property=>$newvalue) {
+
+ switch($property) {
+ case '{DAV:}displayname' :
+ $displayname = $newvalue;
+ break;
+ case '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' :
+ $description = $newvalue;
+ break;
+ default :
+ throw new Sabre_DAV_Exception_BadRequest('Unknown property: ' . $property);
+ }
+
+ }
+
+ OC_Contacts_Addressbook::addAddressbookFromDAVData($principaluri,$url,$name,$description);
+ }
+
+ /**
+ * Deletes an entire addressbook and all its contents
+ *
+ * @param int $addressbookid
+ * @return void
+ */
+ public function deleteAddressBook($addressbookid) {
+ OC_Contacts_Addressbook::deleteAddressbook($addressbookid);
+ }
+
+ /**
+ * Returns all cards for a specific addressbook id.
+ *
+ * @param mixed $addressbookid
+ * @return array
+ */
+ public function getCards($addressbookid) {
+ $data = OC_Contacts_Addressbook::allCards($addressbookid);
+ $cards = array();
+ foreach($data as $i){
+ $cards[] = array(
+ 'id' => $i['id'],
+ 'carddata' => $i['carddata'],
+ 'uri' => $i['uri'],
+ 'lastmodified' => $i['lastmodified'] );
+ }
+
+ return $cards;
+ }
+
+ /**
+ * Returns a specfic card
+ *
+ * @param mixed $addressbookid
+ * @param string $carduri
+ * @return array
+ */
+ public function getCard($addressbookid, $carduri) {
+ return OC_Contacts_Addressbook::findCardWhereDAVDataIs($addressbookid,$carduri);
+
+ }
+
+ /**
+ * Creates a new card
+ *
+ * @param mixed $addressbookid
+ * @param string $carduri
+ * @param string $carddata
+ * @return bool
+ */
+ public function createCard($addressbookid, $carduri, $carddata) {
+ OC_Contacts_Addressbook::addCardFromDAVData($addressbookid, $carduri, $carddata);
+ return true;
+ }
+
+ /**
+ * Updates a card
+ *
+ * @param mixed $addressbookid
+ * @param string $carduri
+ * @param string $carddata
+ * @return bool
+ */
+ public function updateCard($addressbookid, $carduri, $carddata) {
+ return OC_Contacts_Addressbook::editCardFromDAVData($addressbookid, $carduri, $carddata);
+ }
+
+ /**
+ * Deletes a card
+ *
+ * @param mixed $addressbookid
+ * @param string $carduri
+ * @return bool
+ */
+ public function deleteCard($addressbookid, $carduri) {
+ return OC_Contacts_Addressbook::deleteCardFromDAVData($addressbookid, $carduri);
+ }
+}
diff --git a/apps/contacts/photo.php b/apps/contacts/photo.php
new file mode 100644
index 00000000000..62386421cdc
--- /dev/null
+++ b/apps/contacts/photo.php
@@ -0,0 +1,85 @@
+<?php
+/**
+ * ownCloud - Addressbook
+ *
+ * @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
+if( !OC_User::isLoggedIn()){
+ echo $l10n->t('You need to log in!');
+ exit();
+}
+
+
+$card = OC_Contacts_Addressbook::findCard( $id );
+if( $card === false ){
+ echo $l10n->t('Can not find Contact!');
+ exit();
+}
+
+$addressbook = OC_Contacts_Addressbook::findAddressbook( $card['addressbookid'] );
+if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
+ echo $l10n->t('This is not your contact!');
+ exit();
+}
+
+$content = Sabre_VObject_Reader::read($card['carddata']);
+
+// Photo :-)
+foreach($content->children as $child){
+ if($child->name == 'PHOTO'){
+ $mime = 'image/jpeg';
+ foreach($child->parameters as $parameter){
+ if( $parameter->name == 'TYPE' ){
+ $mime = $parameter->value;
+ }
+ }
+ $photo = base64_decode($child->value);
+ header('Content-Type: '.$mime);
+ header('Content-Length: ' . strlen($photo));
+ echo $photo;
+ exit();
+ }
+}
+// Logo :-/
+foreach($content->children as $child){
+ if($child->name == 'PHOTO'){
+ $mime = 'image/jpeg';
+ foreach($child->parameters as $parameter){
+ if($parameter->name == 'TYPE'){
+ $mime = $parameter->value;
+ }
+ }
+ $photo = base64_decode($child->value());
+ header('Content-Type: '.$mime);
+ header('Content-Length: ' . strlen($photo));
+ echo $photo;
+ exit();
+ }
+}
+
+// Not found :-(
+echo $l10n->t('This card does not contain photo data!');
diff --git a/apps/contacts/templates/_contacts.php b/apps/contacts/templates/_contacts.php
new file mode 100644
index 00000000000..bf633b79b04
--- /dev/null
+++ b/apps/contacts/templates/_contacts.php
@@ -0,0 +1,3 @@
+<?php foreach( $_['contacts'] as $contact ): ?>
+ <li x-id="<?php echo $contact['id']; ?>"><a href="index.php?id=<?php echo $contact['id']; ?>"><?php echo $contact['name']; ?></a></li>
+<?php endforeach; ?>
diff --git a/apps/contacts/templates/_details.php b/apps/contacts/templates/_details.php
new file mode 100644
index 00000000000..e27b17ef2eb
--- /dev/null
+++ b/apps/contacts/templates/_details.php
@@ -0,0 +1,4 @@
+Name <?php echo $_['details']['FN'][0]['value']; ?>
+<?php if(array_key_exists('PHOTO',$_['details'])): ?>
+ <img src="photo.php?id=<?php echo $_['id']; ?>">
+<?php endif; ?> \ No newline at end of file
diff --git a/apps/contacts/templates/index.php b/apps/contacts/templates/index.php
new file mode 100644
index 00000000000..0cd214bfb18
--- /dev/null
+++ b/apps/contacts/templates/index.php
@@ -0,0 +1,13 @@
+<?php // Include Style and Script
+OC_Util::addScript('contacts','interface');
+OC_Util::addStyle('contacts','styles');
+?>
+
+<div class="contacts_contacts leftcontent">
+ <ul>
+ <?php echo $this->inc("_contacts"); ?>
+ </ul>
+</div>
+<div class="contacts_details rightcontent">
+ <?php echo $this->inc("_details"); ?>
+</div>
diff --git a/apps/contacts/temporaryupdate.php b/apps/contacts/temporaryupdate.php
new file mode 100644
index 00000000000..bb5ff7604f3
--- /dev/null
+++ b/apps/contacts/temporaryupdate.php
@@ -0,0 +1,13 @@
+<?php
+// Init owncloud
+require_once('../../lib/base.php');
+$connector = new OC_Connector_Sabre_Principal;
+$users = OC_User::getUsers();
+
+foreach($users as $user){
+ $foo = $connector->getPrincipalByPath('principals/'.$user);
+ if(!isset($foo)){
+ OC_Connector_Sabre_Principal::addPrincipal(array('uid'=>$user));
+ }
+}
+echo "done"; \ No newline at end of file
diff --git a/core/js/js.js b/core/js/js.js
index a83d6abb6a5..00618cb30cf 100644
--- a/core/js/js.js
+++ b/core/js/js.js
@@ -1,3 +1,9 @@
+/**
+ * translate a string
+ * @param app the id of the app for which to translate the string
+ * @param text the string to translate
+ * @return string
+ */
function t(app,text){
if( !( app in t.cache )){
@@ -22,9 +28,22 @@ t.cache={};
OC={
webroot:oc_webroot,
coreApps:['files','admin','log','search','settings','core'],
+ /**
+ * get an absolute url to a file in an appen
+ * @param app the id of the app the file belongs to
+ * @param file the file path relative to the app folder
+ * @return string
+ */
linkTo:function(app,file){
return OC.filePath(app,'',file);
},
+ /**
+ * get the absolute url for a file in an app
+ * @param app the id of the app
+ * @param type the type of the file to link to (e.g. css,img,ajax.template)
+ * @param file the filename
+ * @return string
+ */
filePath:function(app,type,file){
var isCore=OC.coreApps.indexOf(app)!=-1;
app+='/';
@@ -39,12 +58,28 @@ OC={
link+=file;
return link;
},
+ /**
+ * get the absolute path to an image file
+ * @param app the app id to which the image belongs
+ * @param file the name of the image file
+ * @return string
+ *
+ * if no extention is given for the image, it will automatically decide between .png and .svg based on what the browser supports
+ */
imagePath:function(app,file){
if(file.indexOf('.')==-1){//if no extention is given, use png or svg depending on browser support
file+=(SVGSupport())?'.svg':'.png'
}
return OC.filePath(app,'img',file);
},
+ /**
+ * load a script for the server and load it
+ * @param app the app id to which the script belongs
+ * @param script the filename of the script
+ * @param ready event handeler to be called when the script is loaded
+ *
+ * if the script is already loaded, the event handeler will be called directly
+ */
addScript:function(app,script,ready){
var path=OC.filePath(app,'js',script+'.js');
if(OC.addStyle.loaded.indexOf(path)==-1){
@@ -60,6 +95,11 @@ OC={
}
}
},
+ /**
+ * load a css file and load it
+ * @param app the app id to which the css style belongs
+ * @param style the filename of the css file
+ */
addStyle:function(app,style){
var path=OC.filePath(app,'css',style+'.css');
if(OC.addScript.loaded.indexOf(path)==-1){
@@ -68,6 +108,10 @@ OC={
$('head').append(style);
}
},
+ /**
+ * do a search query and display the results
+ * @param query the search query
+ */
search:function(query){
if(query){
OC.addStyle('search','results');
@@ -85,6 +129,9 @@ OC.search.lastResults={};
OC.addStyle.loaded=[];
OC.addScript.loaded=[];
+/**
+ * implement Array.filter for browsers without native support
+ */
if (!Array.prototype.filter) {
Array.prototype.filter = function(fun /*, thisp*/) {
var len = this.length >>> 0;
@@ -103,6 +150,9 @@ if (!Array.prototype.filter) {
return res;
}
}
+/**
+ * implement Array.indexOf for browsers without native support
+ */
if (!Array.prototype.indexOf){
Array.prototype.indexOf = function(elt /*, from*/)
{
@@ -125,10 +175,25 @@ if (!Array.prototype.indexOf){
};
}
+/**
+ * check if the browser support svg images
+ */
function SVGSupport() {
return document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") || document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Shape", "1.0");
}
+/**
+ * prototypal inharitence functions
+ *
+ * usage:
+ * MySubObject=object(MyObject)
+ */
+function object(o) {
+ function F() {}
+ F.prototype = o;
+ return new F();
+}
+
$(document).ready(function(){
if(!SVGSupport()){//replace all svg images with png images for browser that dont support svg
$('img.svg').each(function(index,element){
diff --git a/lib/base.php b/lib/base.php
index 520c12d4df1..d02f63a2766 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -35,23 +35,23 @@ class OC{
*/
public static $DOCUMENTROOT = '';
/**
- * TODO: What's this for?
+ * The installation path for owncloud on the server (e.g. /srv/http/owncloud)
*/
public static $SERVERROOT = '';
/**
- * TODO: What's this for?
+ * the current request path relative to the owncloud root (e.g. files/index.php)
*/
public static $SUBURI = '';
/**
- * TODO: What's this for?
+ * the owncloud root path for http requests (e.g. owncloud/)
*/
public static $WEBROOT = '';
/**
- * TODO: What's this for?
+ * the folder that stores that data files for the filesystem of the user (e.g. /srv/http/owncloud/data/myusername/files)
*/
public static $CONFIG_DATADIRECTORY = '';
/**
- * TODO: What's this for?
+ * the folder that stores the data for the root filesystem (e.g. /srv/http/owncloud/data)
*/
public static $CONFIG_DATADIRECTORY_ROOT = '';
diff --git a/lib/connector/sabre/principal.php b/lib/connector/sabre/principal.php
index b3070087fd7..9c386f85e15 100644
--- a/lib/connector/sabre/principal.php
+++ b/lib/connector/sabre/principal.php
@@ -37,8 +37,8 @@ class OC_Connector_Sabre_Principal implements Sabre_DAVACL_IPrincipalBackend {
// We have to delete the principals and relations! Principals include
while($row = $result->fetchRow()){
// Checking if the principal is in the prefix
- list($rowPrefix,$rowUser) = Sabre_DAV_URLUtil::splitPath($row['uri']);
- if ($rowUser !== $params['uid']) continue;
+ $array = explode('/',$row['uri']);
+ if ($array[1] != $params['uid']) continue;
$deleteprincipal->execute(array($row['id']));
$deletegroup->execute(array($row['id'],$row['id']));
}