From 4793d25c577dcad3516853d05d62cf264fc54448 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Fri, 30 Dec 2011 21:07:16 +0100 Subject: [PATCH] Added license and waiver of conditions for jquery.inview. CSS fix on contact list. Query contacts from multiple address books. --- apps/contacts/ajax/addcard.php | 1 + apps/contacts/ajax/contacts.php | 9 +++--- apps/contacts/css/styles.css | 1 + apps/contacts/index.php | 9 ++++-- apps/contacts/js/LICENSE.jquery.inview | 41 ++++++++++++++++++++++++++ apps/contacts/js/jquery.inview.txt | 15 ++++++++++ apps/contacts/lib/addressbook.php | 25 ++++++++++++++-- apps/contacts/lib/vcard.php | 21 +++++++++++-- 8 files changed, 111 insertions(+), 11 deletions(-) create mode 100644 apps/contacts/js/LICENSE.jquery.inview create mode 100644 apps/contacts/js/jquery.inview.txt diff --git a/apps/contacts/ajax/addcard.php b/apps/contacts/ajax/addcard.php index 9d782246a0a..54c455e515f 100644 --- a/apps/contacts/ajax/addcard.php +++ b/apps/contacts/ajax/addcard.php @@ -61,5 +61,6 @@ foreach( $add as $propname){ $vcard->addProperty($propname, $value, $prop_parameters); } $id = OC_Contacts_VCard::add($aid,$vcard->serialize()); +OC_Log::write('contacts','ajax/addcard.php - adding id: '.$id,OC_Log::DEBUG); OC_Contacts_App::renderDetails($id, $vcard); diff --git a/apps/contacts/ajax/contacts.php b/apps/contacts/ajax/contacts.php index b34cf414249..54ad3e4c103 100644 --- a/apps/contacts/ajax/contacts.php +++ b/apps/contacts/ajax/contacts.php @@ -6,14 +6,14 @@ * See the COPYING-README file. */ -function contacts_namesort($a,$b){ - return strcasecmp($a['fullname'],$b['fullname']); -} - require_once('../../../lib/base.php'); OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('contacts'); +$ids = OC_Contacts_Addressbook::activeIds(OC_User::getUser()); +$contacts = OC_Contacts_VCard::all($ids); +//OC_Log::write('contacts','contacts.php: '.count($contacts).' contacts.',OC_Log::DEBUG); +/* $addressbooks = OC_Contacts_Addressbook::active(OC_User::getUser()); $contacts = array(); foreach( $addressbooks as $addressbook ){ @@ -26,6 +26,7 @@ foreach( $addressbooks as $addressbook ){ } } usort($contacts,'contacts_namesort'); +*/ $tmpl = new OC_TEMPLATE("contacts", "part.contacts"); $tmpl->assign('contacts', $contacts); $page = $tmpl->fetchPage(); diff --git a/apps/contacts/css/styles.css b/apps/contacts/css/styles.css index b6709c5a791..53b469e6eed 100644 --- a/apps/contacts/css/styles.css +++ b/apps/contacts/css/styles.css @@ -1,3 +1,4 @@ +#contacts { padding-left:5px; padding-top: 5px; background: #fff; } #contacts li { padding-left:25px;background:url('../img/person.svg') no-repeat; } #chooseaddressbook {margin-right: 170px; float: right;} #contacts_details_name { font-weight:bold;font-size:1.1em;margin-left:25%;} diff --git a/apps/contacts/index.php b/apps/contacts/index.php index a6af54c8789..5ab6f293ab4 100644 --- a/apps/contacts/index.php +++ b/apps/contacts/index.php @@ -32,6 +32,9 @@ OC_Util::checkLoggedIn(); OC_Util::checkAppEnabled('contacts'); // Get active address books. This creates a default one if none exists. +$ids = OC_Contacts_Addressbook::activeIds(OC_User::getUser()); +$contacts = OC_Contacts_VCard::all($ids); + $addressbooks = OC_Contacts_Addressbook::active(OC_User::getUser()); // Load the files we need @@ -39,7 +42,7 @@ OC_App::setActiveNavigationEntry( 'contacts_index' ); // Load a specific user? $id = isset( $_GET['id'] ) ? $_GET['id'] : null; - +/* // sort addressbooks (use contactsort) usort($addressbooks,'contacts_namesort'); @@ -55,8 +58,10 @@ foreach( $addressbooks as $addressbook ){ } usort($contacts,'contacts_namesort'); - +*/ $details = array(); + +// FIXME: This cannot work..? if( !is_null($id)/* || count($contacts)*/){ if(is_null($id)) $id = $contacts[0]['id']; $vcard = OC_Contacts_App::getContactVCard($id); diff --git a/apps/contacts/js/LICENSE.jquery.inview b/apps/contacts/js/LICENSE.jquery.inview new file mode 100644 index 00000000000..1ed340edbe5 --- /dev/null +++ b/apps/contacts/js/LICENSE.jquery.inview @@ -0,0 +1,41 @@ +Attribution-Non-Commercial-Share Alike 2.0 UK: England & Wales + +http://creativecommons.org/licenses/by-nc-sa/2.0/uk/ + +You are free: + + * to copy, distribute, display, and perform the work + * to make derivative works + + +Under the following conditions: + + * Attribution — You must give the original author credit. + Attribute this work: + Information + What does "Attribute this work" mean? + The page you came from contained embedded licensing metadata, + including how the creator wishes to be attributed for re-use. + You can use the HTML here to cite the work. Doing so will + also include metadata on your page so that others can find the + original work as well. + + * Non-Commercial — You may not use this work for commercial + purposes. + * Share Alike — If you alter, transform, or build upon this + work, you may distribute the resulting work only under a + licence identical to this one. + +With the understanding that: + + * Waiver — Any of the above conditions can be waived if you get + permission from the copyright holder. + * Other Rights — In no way are any of the following rights + affected by the license: + o Your fair dealing or fair use rights; + o The author's moral rights; + o Rights other persons may have either in the work itself + or in how the work is used, such as publicity or privacy rights. + * Notice — For any reuse or distribution, you must make clear to + others the licence terms of this work. + diff --git a/apps/contacts/js/jquery.inview.txt b/apps/contacts/js/jquery.inview.txt new file mode 100644 index 00000000000..c53dbd1d97c --- /dev/null +++ b/apps/contacts/js/jquery.inview.txt @@ -0,0 +1,15 @@ +jQuery.inview is licensed Attribution-Non-Commercial-Share Alike 2.0 but the +conditions has been waived by the author in the following tweet: + +https://twitter.com/#!/ChristopherBlum/status/148382899887013888 + +Saying: + +Thomas Tanghus @tanghus 18 Dec. 2011 + +@ChristopherBlum Hi. Is it OK if I use https://github.com/protonet/jquery.inview in ownCloud? Preferably under an AGPL license ;-) owncloud.org + + +Christopher Blum Christopher Blum @ChristopherBlum 18 Dec. 2011 + +@tanghus Feel free to! :) diff --git a/apps/contacts/lib/addressbook.php b/apps/contacts/lib/addressbook.php index 6f2f34225de..b3c981a541e 100644 --- a/apps/contacts/lib/addressbook.php +++ b/apps/contacts/lib/addressbook.php @@ -140,6 +140,25 @@ class OC_Contacts_Addressbook{ return true; } + public static function cleanArray($array, $remove_null_number = true){ + $new_array = array(); + + $null_exceptions = array(); + + foreach ($array as $key => $value){ + $value = trim($value); + + if($remove_null_number){ + $null_exceptions[] = '0'; + } + + if(!in_array($value, $null_exceptions) && $value != "") { + $new_array[] = $value; + } + } + return $new_array; + } + /** * @brief Get active addressbooks for a user. * @param integer $uid User id. If null current user will be used. @@ -170,7 +189,8 @@ class OC_Contacts_Addressbook{ public static function active($uid){ $active = self::activeIds($uid); $addressbooks = array(); - /** FIXME: Is there a way to prepare a statement 'WHERE id IN ([range])'? + /* FIXME: Is there a way to prepare a statement 'WHERE id IN ([range])'? + * See OC_Contacts_VCard:all. */ foreach( $active as $aid ){ $stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*contacts_addressbooks WHERE id = ? ORDER BY displayname' ); @@ -208,6 +228,7 @@ class OC_Contacts_Addressbook{ unset($openaddressbooks[array_search($id, $openaddressbooks)]); } } + $openaddressbooks = self::cleanArray($openaddressbooks, false); sort($openaddressbooks, SORT_NUMERIC); // FIXME: I alway end up with a ';' prepending when imploding the array..? OC_Preferences::setValue(OC_User::getUser(),'contacts','openaddressbooks',implode(';', $openaddressbooks)); @@ -221,7 +242,7 @@ class OC_Contacts_Addressbook{ * @return boolean */ public static function isActive($id){ - OC_Log::write('contacts','OC_Contacts_Addressbook::isActive('.$id.'):'.in_array($id, self::activeIds()), OC_Log::DEBUG); + //OC_Log::write('contacts','OC_Contacts_Addressbook::isActive('.$id.'):'.in_array($id, self::activeIds()), OC_Log::DEBUG); return in_array($id, self::activeIds()); } diff --git a/apps/contacts/lib/vcard.php b/apps/contacts/lib/vcard.php index 7285761fd58..81519b3d051 100644 --- a/apps/contacts/lib/vcard.php +++ b/apps/contacts/lib/vcard.php @@ -47,9 +47,24 @@ class OC_Contacts_VCard{ * ['carddata'] */ public static function all($id){ - $stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*contacts_cards WHERE addressbookid = ? ORDER BY fullname' ); - $result = $stmt->execute(array($id)); - + //$stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*contacts_cards WHERE addressbookid = ? ORDER BY fullname' ); + //$result = $stmt->execute(array($id)); + + if(is_array($id)) { + $id_sql = join(',', array_fill(0, count($id), '?')); + $prep = 'SELECT * FROM *PREFIX*contacts_cards WHERE addressbookid IN ('.$id_sql.') ORDER BY fullname'; + try { + $stmt = OC_DB::prepare( $prep ); + $result = $stmt->execute($id); + } catch(Exception $e) { + OC_Log::write('contacts','OC_Contacts_VCard:all:, exception: '.$e->getMessage(),OC_Log::DEBUG); + OC_Log::write('contacts','OC_Contacts_VCard:all, ids: '.join(',', $id),OC_Log::DEBUG); + OC_Log::write('contacts','SQL:'.$prep,OC_Log::DEBUG); + } + } else { + $stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*contacts_cards WHERE addressbookid = ? ORDER BY fullname' ); + $result = $stmt->execute(array($id)); + } $cards = array(); while( $row = $result->fetchRow()){ $cards[] = $row; -- 2.39.5