diff --git a/apps/calendar/lib/object.php b/apps/calendar/lib/object.php index 7f3322b1ab..0531a56fc5 100644 --- a/apps/calendar/lib/object.php +++ b/apps/calendar/lib/object.php @@ -216,6 +216,14 @@ class OC_Calendar_Object{ return true; } + + /** + * @brief Creates a UID + * @return string + */ + protected static function createUID(){ + return substr(md5(rand().time()),0,10); + } /** * @brief Extracts data from a vObject-Object diff --git a/apps/contacts/ajax/contacts.php b/apps/contacts/ajax/contacts.php index 4bb7801cb2..07b442159c 100644 --- a/apps/contacts/ajax/contacts.php +++ b/apps/contacts/ajax/contacts.php @@ -31,19 +31,21 @@ foreach($active_addressbooks as $addressbook) { $contacts_alphabet = OC_Contacts_VCard::all($ids); // Our new array for the contacts sorted by addressbook -foreach($contacts_alphabet as $contact) { - if(!isset($contacts_addressbook[$contact['addressbookid']])) { // It should never execute. - $contacts_addressbook[$contact['addressbookid']] = array('contacts' => array()); - } - $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]'; +if($contacts_alphabet) { + foreach($contacts_alphabet as $contact) { + if(!isset($contacts_addressbook[$contact['addressbookid']])) { // It should never execute. + $contacts_addressbook[$contact['addressbookid']] = array('contacts' => array()); } + $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]'; + } + } + $contacts_addressbook[$contact['addressbookid']]['contacts'][] = array('id' => $contact['id'], 'addressbookid' => $contact['addressbookid'], 'displayname' => htmlspecialchars($display)); } - $contacts_addressbook[$contact['addressbookid']]['contacts'][] = array('id' => $contact['id'], 'addressbookid' => $contact['addressbookid'], 'displayname' => htmlspecialchars($display)); } unset($contacts_alphabet); uasort($contacts_addressbook, 'cmp'); diff --git a/apps/contacts/ajax/loadcard.php b/apps/contacts/ajax/loadcard.php index fbb831f4a1..1309faaa7a 100644 --- a/apps/contacts/ajax/loadcard.php +++ b/apps/contacts/ajax/loadcard.php @@ -27,6 +27,7 @@ OCP\JSON::checkAppEnabled('contacts'); $upload_max_filesize = OCP\Util::computerFileSize(ini_get('upload_max_filesize')); $post_max_size = OCP\Util::computerFileSize(ini_get('post_max_size')); $maxUploadFilesize = min($upload_max_filesize, $post_max_size); +$requesttoken = $_GET['requesttoken']; $freeSpace=OC_Filesystem::free_space('/'); $freeSpace=max($freeSpace,0); @@ -41,6 +42,7 @@ $tmpl->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesi $tmpl->assign('adr_types',$adr_types); $tmpl->assign('phone_types',$phone_types); $tmpl->assign('email_types',$email_types); +$tmpl->assign('requesttoken', $requesttoken); $tmpl->assign('id',''); $page = $tmpl->fetchPage(); diff --git a/apps/contacts/appinfo/app.php b/apps/contacts/appinfo/app.php index 7a04ec7ff5..64fe00eef1 100644 --- a/apps/contacts/appinfo/app.php +++ b/apps/contacts/appinfo/app.php @@ -5,6 +5,7 @@ OC::$CLASSPATH['OC_Contacts_VCard'] = 'apps/contacts/lib/vcard.php'; OC::$CLASSPATH['OC_Contacts_Hooks'] = 'apps/contacts/lib/hooks.php'; OC::$CLASSPATH['OC_Connector_Sabre_CardDAV'] = 'apps/contacts/lib/connector_sabre.php'; OC::$CLASSPATH['OC_Search_Provider_Contacts'] = 'apps/contacts/lib/search.php'; +OCP\Util::connectHook('OC_User', 'post_createUser', 'OC_Contacts_Hooks', 'createUser'); OCP\Util::connectHook('OC_User', 'post_deleteUser', 'OC_Contacts_Hooks', 'deleteUser'); OCP\Util::connectHook('OC_Calendar', 'getEvents', 'OC_Contacts_Hooks', 'getBirthdayEvents'); OCP\Util::connectHook('OC_Calendar', 'getSources', 'OC_Contacts_Hooks', 'getCalenderSources'); diff --git a/apps/contacts/index.php b/apps/contacts/index.php index f6b37409ea..0b4f89b30c 100644 --- a/apps/contacts/index.php +++ b/apps/contacts/index.php @@ -15,6 +15,9 @@ OCP\App::checkAppEnabled('contacts'); // Get active address books. This creates a default one if none exists. $ids = OC_Contacts_Addressbook::activeIds(OCP\USER::getUser()); $contacts = OC_Contacts_VCard::all($ids); +if($contacts === false) { + OCP\Util::writeLog('contacts','index.html: No contacts found.',OCP\Util::DEBUG); +} $addressbooks = OC_Contacts_Addressbook::active(OCP\USER::getUser()); diff --git a/apps/contacts/js/contacts.js b/apps/contacts/js/contacts.js index 036734049b..e5326ad880 100644 --- a/apps/contacts/js/contacts.js +++ b/apps/contacts/js/contacts.js @@ -48,7 +48,7 @@ Contacts={ adrstr = adrstr + adrarr[6].trim(); } adrstr = encodeURIComponent(adrstr); - var uri = 'http://open.mapquestapi.com/nominatim/v1/search.php?q=' + adrstr + '&limit=10&addressdetails=1&zoom='; + var uri = 'http://open.mapquestapi.com/nominatim/v1/search.php?q=' + adrstr + '&limit=10&addressdetails=1&polygon=1&zoom='; var newWindow = window.open(uri,'_blank'); newWindow.focus(); }, @@ -234,6 +234,30 @@ Contacts={ $('#contacts_downloadcard').tipsy({gravity: 'ne'}); $('#contacts_propertymenu_button').tipsy(); $('#contacts_newcontact, #chooseaddressbook').tipsy({gravity: 'sw'}); + + $('body').click(function(e){ + if(!$(e.target).is('#contacts_propertymenu_button')) { + $('#contacts_propertymenu_dropdown').hide(); + } + }); + function propertyMenu(){ + var menu = $('#contacts_propertymenu_dropdown'); + if(menu.is(':hidden')) { + menu.show(); + menu.find('li').first().focus(); + } else { + menu.hide(); + } + } + $('#contacts_propertymenu_button').click(propertyMenu); + $('#contacts_propertymenu_button').keydown(propertyMenu); + function propertyMenuItem(){ + var type = $(this).data('type'); + Contacts.UI.Card.addProperty(type); + $('#contacts_propertymenu_dropdown').hide(); + } + $('#contacts_propertymenu_dropdown a').click(propertyMenuItem); + $('#contacts_propertymenu_dropdown a').keydown(propertyMenuItem); }, Card:{ id:'', @@ -258,6 +282,9 @@ Contacts={ newid = id; bookid = bookid?bookid:$('#contacts li[data-id="'+newid+'"]').data('bookid'); } + if(!bookid) { + bookid = $('#contacts h3').first().data('id'); + } var localLoadContact = function(newid, bookid) { if($('.contacts li').length > 0) { $('#contacts li[data-id="'+newid+'"]').addClass('active'); @@ -359,7 +386,7 @@ Contacts={ var card = $('#card')[0]; if(!card) { - $.getJSON(OC.filePath('contacts', 'ajax', 'loadcard.php'),{},function(jsondata){ + $.getJSON(OC.filePath('contacts', 'ajax', 'loadcard.php'),{'requesttoken': requesttoken},function(jsondata){ if(jsondata.status == 'success'){ $('#rightcontent').html(jsondata.data.page).ready(function() { Contacts.UI.loadHandlers(); @@ -1566,6 +1593,8 @@ Contacts={ scroll: true, scrollSensitivity: 100, opacity: 0.7, helper: 'clone' }); + } else { + $('#contacts h3').first().addClass('active'); } }); Contacts.UI.Card.update(id); @@ -1734,30 +1763,6 @@ $(document).ready(function(){ xhr.send(file); } - $('body').click(function(e){ - if(!$(e.target).is('#contacts_propertymenu_button')) { - $('#contacts_propertymenu_dropdown').hide(); - } - }); - function propertyMenu(){ - var menu = $('#contacts_propertymenu_dropdown'); - if(menu.is(':hidden')) { - menu.show(); - menu.find('li').first().focus(); - } else { - menu.hide(); - } - } - $('#contacts_propertymenu_button').click(propertyMenu); - $('#contacts_propertymenu_button').keydown(propertyMenu); - function propertyMenuItem(){ - var type = $(this).data('type'); - Contacts.UI.Card.addProperty(type); - $('#contacts_propertymenu_dropdown').hide(); - } - $('#contacts_propertymenu_dropdown a').click(propertyMenuItem); - $('#contacts_propertymenu_dropdown a').keydown(propertyMenuItem); - Contacts.UI.loadHandlers(); Contacts.UI.Contacts.update(id); }); diff --git a/apps/contacts/lib/addressbook.php b/apps/contacts/lib/addressbook.php index 878d8835f9..86a41b18cf 100644 --- a/apps/contacts/lib/addressbook.php +++ b/apps/contacts/lib/addressbook.php @@ -41,11 +41,18 @@ class OC_Contacts_Addressbook{ /** * @brief Returns the list of addressbooks for a specific user. * @param string $uid - * @return array + * @return array or false. */ public static function all($uid){ - $stmt = OCP\DB::prepare( 'SELECT * FROM *PREFIX*contacts_addressbooks WHERE userid = ? ORDER BY displayname' ); - $result = $stmt->execute(array($uid)); + try { + $stmt = OCP\DB::prepare( 'SELECT * FROM *PREFIX*contacts_addressbooks WHERE userid = ? ORDER BY displayname' ); + $result = $stmt->execute(array($uid)); + } catch(Exception $e) { + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.' exception: '.$e->getMessage(),OCP\Util::ERROR); + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.' uid: '.$uid,OCP\Util::DEBUG); + return false; + } + $addressbooks = array(); while( $row = $result->fetchRow()){ @@ -68,15 +75,36 @@ class OC_Contacts_Addressbook{ /** * @brief Gets the data of one address book * @param integer $id - * @return associative array + * @return associative array or false. */ public static function find($id){ - $stmt = OCP\DB::prepare( 'SELECT * FROM *PREFIX*contacts_addressbooks WHERE id = ?' ); - $result = $stmt->execute(array($id)); + try { + $stmt = OCP\DB::prepare( 'SELECT * FROM *PREFIX*contacts_addressbooks WHERE id = ?' ); + $result = $stmt->execute(array($id)); + } catch(Exception $e) { + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', exception: '.$e->getMessage(),OCP\Util::ERROR); + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', id: '.$id,OCP\Util::DEBUG); + return false; + } return $result->fetchRow(); } + /** + * @brief Adds default address book + * @return $id ID of the newly created addressbook or false on error. + */ + public static function addDefault($uid = null){ + if(is_null($uid)) { + $uid = OCP\USER::getUser(); + } + $id = self::add($uid,'default','Default Address Book'); + if($id !== false) { + self::setActive($id, true); + } + return $id; + } + /** * @brief Creates a new address book * @param string $userid @@ -84,17 +112,22 @@ class OC_Contacts_Addressbook{ * @param string $description * @return insertid */ - public static function add($userid,$name,$description=''){ - $all = self::all($userid); + public static function add($uid,$name,$description=''){ + $all = self::all($uid); $uris = array(); foreach($all as $i){ $uris[] = $i['uri']; } $uri = self::createURI($name, $uris ); - - $stmt = OCP\DB::prepare( 'INSERT INTO *PREFIX*contacts_addressbooks (userid,displayname,uri,description,ctag) VALUES(?,?,?,?,?)' ); - $result = $stmt->execute(array($userid,$name,$uri,$description,1)); + try { + $stmt = OCP\DB::prepare( 'INSERT INTO *PREFIX*contacts_addressbooks (userid,displayname,uri,description,ctag) VALUES(?,?,?,?,?)' ); + $result = $stmt->execute(array($uid,$name,$uri,$description,1)); + } catch(Exception $e) { + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', exception: '.$e->getMessage(),OCP\Util::ERROR); + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', uid: '.$uid,OCP\Util::DEBUG); + return false; + } return OCP\DB::insertid('*PREFIX*contacts_addressbooks'); } @@ -105,13 +138,20 @@ class OC_Contacts_Addressbook{ * @param string $uri * @param string $name * @param string $description - * @return insertid + * @return insertid or false */ public static function addFromDAVData($principaluri,$uri,$name,$description){ - $userid = self::extractUserID($principaluri); + $uid = self::extractUserID($principaluri); - $stmt = OCP\DB::prepare( 'INSERT INTO *PREFIX*contacts_addressbooks (userid,displayname,uri,description,ctag) VALUES(?,?,?,?,?)' ); - $result = $stmt->execute(array($userid,$name,$uri,$description,1)); + try { + $stmt = OCP\DB::prepare('INSERT INTO *PREFIX*contacts_addressbooks (userid,displayname,uri,description,ctag) VALUES(?,?,?,?,?)'); + $result = $stmt->execute(array($uid,$name,$uri,$description,1)); + } catch(Exception $e) { + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', exception: '.$e->getMessage(),OCP\Util::ERROR); + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', uid: '.$uid,OCP\Util::DEBUG); + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', uri: '.$uri,OCP\Util::DEBUG); + return false; + } return OCP\DB::insertid('*PREFIX*contacts_addressbooks'); } @@ -134,8 +174,14 @@ class OC_Contacts_Addressbook{ $description = $addressbook['description']; } - $stmt = OCP\DB::prepare( 'UPDATE *PREFIX*contacts_addressbooks SET displayname=?,description=?, ctag=ctag+1 WHERE id=?' ); - $result = $stmt->execute(array($name,$description,$id)); + try { + $stmt = OCP\DB::prepare('UPDATE *PREFIX*contacts_addressbooks SET displayname=?,description=?, ctag=ctag+1 WHERE id=?'); + $result = $stmt->execute(array($name,$description,$id)); + } catch(Exception $e) { + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', exception: '.$e->getMessage(),OCP\Util::ERROR); + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', id: '.$id,OCP\Util::DEBUG); + return false; + } return true; } @@ -172,8 +218,7 @@ class OC_Contacts_Addressbook{ if(!$prefbooks){ $addressbooks = OC_Contacts_Addressbook::all($uid); if(count($addressbooks) == 0){ - $id = OC_Contacts_Addressbook::add($uid,'default','Default Address Book'); - self::setActive($id, true); + self::addDefault($uid); } } $prefbooks = OCP\Config::getUserValue($uid,'contacts','openaddressbooks',null); @@ -186,6 +231,9 @@ class OC_Contacts_Addressbook{ * @return array */ public static function active($uid){ + if(is_null($uid)){ + $uid = OCP\USER::getUser(); + } $active = self::activeIds($uid); $addressbooks = array(); $ids_sql = join(',', array_fill(0, count($active), '?')); @@ -194,15 +242,18 @@ class OC_Contacts_Addressbook{ $stmt = OCP\DB::prepare( $prep ); $result = $stmt->execute($active); } catch(Exception $e) { - OCP\Util::writeLog('contacts','OC_Contacts_Addressbook:active:, exception: '.$e->getMessage(),OCP\Util::ERROR); - OCP\Util::writeLog('contacts','OC_Contacts_Addressbook:active, ids: '.join(',', $active),OCP\Util::DEBUG); - OCP\Util::writeLog('contacts','OC_Contacts_Addressbook::active, SQL:'.$prep,OCP\Util::DEBUG); + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', exception: '.$e->getMessage(),OCP\Util::ERROR); + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', uid: '.$uid,OCP\Util::DEBUG); + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', ids: '.join(',', $active),OCP\Util::DEBUG); + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', SQL:'.$prep,OCP\Util::DEBUG); } while( $row = $result->fetchRow()){ $addressbooks[] = $row; } - + if(!count($addressbooks)) { + self::addDefault($uid); + } return $addressbooks; } @@ -260,7 +311,7 @@ class OC_Contacts_Addressbook{ $stmt = OCP\DB::prepare( 'DELETE FROM *PREFIX*contacts_addressbooks WHERE id = ?' ); $stmt->execute(array($id)); } catch(Exception $e) { - OCP\Util::writeLog('contacts','OC_Contacts_Addressbook:delete:, exception for '.$id.': '.$e->getMessage(),OCP\Util::ERROR); + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', exception for '.$id.': '.$e->getMessage(),OCP\Util::ERROR); return false; } diff --git a/apps/contacts/lib/app.php b/apps/contacts/lib/app.php index 29428763d6..b3a7abd28b 100644 --- a/apps/contacts/lib/app.php +++ b/apps/contacts/lib/app.php @@ -10,7 +10,6 @@ * This class manages our app actions */ OC_Contacts_App::$l10n = OC_L10N::get('contacts'); -OC_Contacts_App::$categories = new OC_VCategories('contacts'); class OC_Contacts_App { /* * @brief language object for calendar app @@ -137,30 +136,54 @@ class OC_Contacts_App { } } - /* + /** * @brief returns the vcategories object of the user * @return (object) $vcategories */ protected static function getVCategories() { if (is_null(self::$categories)) { - self::$categories = new OC_VCategories('contacts'); + self::$categories = new OC_VCategories('contacts', null, self::getDefaultCategories()); } return self::$categories; } - /* + /** * @brief returns the categories for the user * @return (Array) $categories */ public static function getCategories() { - $categories = self::$categories->categories(); + $categories = self::getVCategories()->categories(); if(count($categories) == 0) { self::scanCategories(); $categories = self::$categories->categories(); } - return $categories; + return ($categories ? $categories : self::getDefaultCategories()); } + /** + * @brief returns the default categories of ownCloud + * @return (array) $categories + */ + protected static function getDefaultCategories(){ + return array( + (string)self::$l10n->t('Birthday'), + (string)self::$l10n->t('Business'), + (string)self::$l10n->t('Call'), + (string)self::$l10n->t('Clients'), + (string)self::$l10n->t('Deliverer'), + (string)self::$l10n->t('Holidays'), + (string)self::$l10n->t('Ideas'), + (string)self::$l10n->t('Journey'), + (string)self::$l10n->t('Jubilee'), + (string)self::$l10n->t('Meeting'), + (string)self::$l10n->t('Other'), + (string)self::$l10n->t('Personal'), + (string)self::$l10n->t('Projects'), + (string)self::$l10n->t('Questions'), + (string)self::$l10n->t('Work'), + ); + } + /** * scan vcards for categories. * @param $vccontacts VCards to scan. null to check all vcards for the current user. diff --git a/apps/contacts/lib/hooks.php b/apps/contacts/lib/hooks.php index 0a920fc519..9794a9c9b9 100644 --- a/apps/contacts/lib/hooks.php +++ b/apps/contacts/lib/hooks.php @@ -33,6 +33,16 @@ * This class contains all hooks. */ class OC_Contacts_Hooks{ + /** + * @brief Add default Addressbooks of a certain user + * @param paramters parameters from postDeleteUser-Hook + * @return array + */ + static public function createUser($parameters) { + OC_Contacts_Addressbook::addDefault($parameters['uid'],'default','Default Address Book'); + return true; + } + /** * @brief Deletes all Addressbooks of a certain user * @param paramters parameters from postDeleteUser-Hook diff --git a/apps/contacts/lib/vcard.php b/apps/contacts/lib/vcard.php index 0f3a08844b..bf22be0de7 100644 --- a/apps/contacts/lib/vcard.php +++ b/apps/contacts/lib/vcard.php @@ -42,32 +42,37 @@ class OC_Contacts_VCard{ /** * @brief Returns all cards of an address book * @param integer $id - * @return array + * @return array|false * * The cards are associative arrays. You'll find the original vCard in * ['carddata'] */ public static function all($id){ $result = null; - if(is_array($id)) { + if(is_array($id) && count($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 = OCP\DB::prepare( $prep ); $result = $stmt->execute($id); } catch(Exception $e) { - OCP\Util::writeLog('contacts','OC_Contacts_VCard:all:, exception: '.$e->getMessage(),OCP\Util::ERROR); - OCP\Util::writeLog('contacts','OC_Contacts_VCard:all, ids: '.join(',', $id),OCP\Util::DEBUG); - OCP\Util::writeLog('contacts','SQL:'.$prep,OCP\Util::DEBUG); + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', exception: '.$e->getMessage(),OCP\Util::ERROR); + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', ids: '.join(',', $id),OCP\Util::DEBUG); + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.'SQL:'.$prep,OCP\Util::DEBUG); + return false; } - } elseif($id) { + } elseif(is_int($id) || is_string($id)) { try { $stmt = OCP\DB::prepare( 'SELECT * FROM *PREFIX*contacts_cards WHERE addressbookid = ? ORDER BY fullname' ); $result = $stmt->execute(array($id)); } catch(Exception $e) { - OCP\Util::writeLog('contacts','OC_Contacts_VCard:all:, exception: '.$e->getMessage(),OCP\Util::DEBUG); - OCP\Util::writeLog('contacts','OC_Contacts_VCard:all, ids: '. $id,OCP\Util::DEBUG); + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', exception: '.$e->getMessage(),OCP\Util::ERROR); + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', ids: '. $id,OCP\Util::DEBUG); + return false; } + } else { + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.'. Addressbook id(s) argument is empty: '. $id,OCP\Util::DEBUG); + return false; } $cards = array(); if(!is_null($result)) { @@ -82,11 +87,17 @@ class OC_Contacts_VCard{ /** * @brief Returns a card * @param integer $id - * @return associative array + * @return associative array or false. */ public static function find($id){ - $stmt = OCP\DB::prepare( 'SELECT * FROM *PREFIX*contacts_cards WHERE id = ?' ); - $result = $stmt->execute(array($id)); + try { + $stmt = OCP\DB::prepare( 'SELECT * FROM *PREFIX*contacts_cards WHERE id = ?' ); + $result = $stmt->execute(array($id)); + } catch(Exception $e) { + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', exception: '.$e->getMessage(),OCP\Util::ERROR); + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', id: '. $id,OCP\Util::DEBUG); + return false; + } return $result->fetchRow(); } @@ -95,11 +106,17 @@ class OC_Contacts_VCard{ * @brief finds a card by its DAV Data * @param integer $aid Addressbook id * @param string $uri the uri ('filename') - * @return associative array + * @return associative array or false. */ public static function findWhereDAVDataIs($aid,$uri){ - $stmt = OCP\DB::prepare( 'SELECT * FROM *PREFIX*contacts_cards WHERE addressbookid = ? AND uri = ?' ); - $result = $stmt->execute(array($aid,$uri)); + try { + $stmt = OCP\DB::prepare( 'SELECT * FROM *PREFIX*contacts_cards WHERE addressbookid = ? AND uri = ?' ); + $result = $stmt->execute(array($aid,$uri)); + } catch(Exception $e) { + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', exception: '.$e->getMessage(), OCP\Util::ERROR); + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', aid: '.$aid.' uri'.$uri, OCP\Util::DEBUG); + return false; + } return $result->fetchRow(); } @@ -149,7 +166,13 @@ class OC_Contacts_VCard{ protected static function trueUID($aid, &$uid) { $stmt = OCP\DB::prepare( 'SELECT * FROM *PREFIX*contacts_cards WHERE addressbookid = ? AND uri = ?' ); $uri = $uid.'.vcf'; - $result = $stmt->execute(array($aid,$uri)); + try { + $result = $stmt->execute(array($aid,$uri)); + } catch(Exception $e) { + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', exception: '.$e->getMessage(), OCP\Util::ERROR); + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', aid: '.$aid.' uid'.$uid, OCP\Util::DEBUG); + return false; + } if($result->numRows() > 0){ while(true) { $tmpuid = substr(md5(rand().time()),0,10); @@ -254,7 +277,7 @@ class OC_Contacts_VCard{ * @param integer $aid Addressbook id * @param OC_VObject $card vCard file * @param string $uri the uri of the card, default based on the UID - * @return insertid on success or null if no card. + * @return insertid on success or false. */ public static function add($aid, OC_VObject $card, $uri=null, $isnew=false){ if(is_null($card)){ @@ -289,7 +312,13 @@ class OC_Contacts_VCard{ $data = $card->serialize(); $stmt = OCP\DB::prepare( 'INSERT INTO *PREFIX*contacts_cards (addressbookid,fullname,carddata,uri,lastmodified) VALUES(?,?,?,?,?)' ); - $result = $stmt->execute(array($aid,$fn,$data,$uri,time())); + try { + $result = $stmt->execute(array($aid,$fn,$data,$uri,time())); + } catch(Exception $e) { + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', exception: '.$e->getMessage(), OCP\Util::ERROR); + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', aid: '.$aid.' uri'.$uri, OCP\Util::DEBUG); + return false; + } $newid = OCP\DB::insertid('*PREFIX*contacts_cards'); OC_Contacts_Addressbook::touch($aid); @@ -325,8 +354,8 @@ class OC_Contacts_VCard{ $result = $stmt->execute(array($data,time(),$object[0])); //OCP\Util::writeLog('contacts','OC_Contacts_VCard::updateDataByID, id: '.$object[0].': '.$object[1],OCP\Util::DEBUG); } catch(Exception $e) { - OCP\Util::writeLog('contacts','OC_Contacts_VCard::updateDataByID:, exception: '.$e->getMessage(),OCP\Util::DEBUG); - OCP\Util::writeLog('contacts','OC_Contacts_VCard::updateDataByID, id: '.$object[0],OCP\Util::DEBUG); + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', exception: '.$e->getMessage(),OCP\Util::ERROR); + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', id: '.$object[0],OCP\Util::DEBUG); } } } @@ -357,7 +386,13 @@ class OC_Contacts_VCard{ $data = $card->serialize(); $stmt = OCP\DB::prepare( 'UPDATE *PREFIX*contacts_cards SET fullname = ?,carddata = ?, lastmodified = ? WHERE id = ?' ); - $result = $stmt->execute(array($fn,$data,time(),$id)); + try { + $result = $stmt->execute(array($fn,$data,time(),$id)); + } catch(Exception $e) { + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', exception: '.$e->getMessage(), OCP\Util::ERROR); + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', id'.$id, OCP\Util::DEBUG); + return false; + } OC_Contacts_Addressbook::touch($oldcard['addressbookid']); OC_Hook::emit('OC_Contacts_VCard', 'post_updateVCard', $id); @@ -390,7 +425,13 @@ class OC_Contacts_VCard{ // FIXME: Add error checking. OC_Hook::emit('OC_Contacts_VCard', 'pre_deleteVCard', array('aid' => null, 'id' => $id, 'uri' => null)); $stmt = OCP\DB::prepare( 'DELETE FROM *PREFIX*contacts_cards WHERE id = ?' ); - $stmt->execute(array($id)); + try { + $stmt->execute(array($id)); + } catch(Exception $e) { + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', exception: '.$e->getMessage(), OCP\Util::ERROR); + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', id: '.$id, OCP\Util::DEBUG); + return false; + } return true; } @@ -403,9 +444,15 @@ class OC_Contacts_VCard{ */ public static function deleteFromDAVData($aid,$uri){ // FIXME: Add error checking. Deleting a card gives an Kontact/Akonadi error. - OC_Hook::emit('OC_Contacts_VCard', 'pre_deleteVCard', array('aid' => $aid, 'id' => null, 'uri' => $uid)); + OC_Hook::emit('OC_Contacts_VCard', 'pre_deleteVCard', array('aid' => $aid, 'id' => null, 'uri' => $uri)); $stmt = OCP\DB::prepare( 'DELETE FROM *PREFIX*contacts_cards WHERE addressbookid = ? AND uri=?' ); - $stmt->execute(array($aid,$uri)); + try { + $stmt->execute(array($aid,$uri)); + } catch(Exception $e) { + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', exception: '.$e->getMessage(), OCP\Util::ERROR); + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', aid: '.$aid.' uri: '.$uri, OCP\Util::DEBUG); + return false; + } OC_Contacts_Addressbook::touch($aid); return true; @@ -546,9 +593,9 @@ class OC_Contacts_VCard{ $vals = array_merge((array)$aid, $id); $result = $stmt->execute($vals); } catch(Exception $e) { - OCP\Util::writeLog('contacts','OC_Contacts_VCard::moveToAddressBook:, exception: '.$e->getMessage(),OCP\Util::DEBUG); - OCP\Util::writeLog('contacts','OC_Contacts_VCard::moveToAddressBook, ids: '.join(',', $vals),OCP\Util::DEBUG); - OCP\Util::writeLog('contacts','SQL:'.$prep,OCP\Util::DEBUG); + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', exception: '.$e->getMessage(),OCP\Util::ERROR); + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', ids: '.join(',', $vals),OCP\Util::DEBUG); + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', SQL:'.$prep,OCP\Util::DEBUG); return false; } } else { @@ -556,8 +603,8 @@ class OC_Contacts_VCard{ $stmt = OCP\DB::prepare( 'UPDATE *PREFIX*contacts_cards SET addressbookid = ? WHERE id = ?' ); $result = $stmt->execute(array($aid, $id)); } catch(Exception $e) { - OCP\Util::writeLog('contacts','OC_Contacts_VCard::moveToAddressBook:, exception: '.$e->getMessage(),OCP\Util::DEBUG); - OCP\Util::writeLog('contacts','OC_Contacts_VCard::moveToAddressBook, id: '.$id,OCP\Util::DEBUG); + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', exception: '.$e->getMessage(),OCP\Util::DEBUG); + OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.' id: '.$id,OCP\Util::DEBUG); return false; } } diff --git a/apps/files_external/lib/dropbox.php b/apps/files_external/lib/dropbox.php index 5e94277c6d..6f1a154a12 100755 --- a/apps/files_external/lib/dropbox.php +++ b/apps/files_external/lib/dropbox.php @@ -41,7 +41,11 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common { return $this->metaData[$path]; } else { if ($list) { - $response = $this->dropbox->getMetaData($path); + try { + $response = $this->dropbox->getMetaData($path); + } catch (Exception $exception) { + return false; + } if ($response && isset($response['contents'])) { $contents = $response['contents']; // Cache folder's contents @@ -90,7 +94,7 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common { if ($metaData = $this->getMetaData($path)) { $stat['size'] = $metaData['bytes']; $stat['atime'] = time(); - $stat['mtime'] = strtotime($metaData['modified']); + $stat['mtime'] = (isset($metaData['modified'])) ? strtotime($metaData['modified']) : time(); $stat['ctime'] = $stat['mtime']; return $stat; } @@ -111,11 +115,11 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common { } public function is_readable($path) { - return true; + return self::file_exists($path); } public function is_writable($path) { - return true; + return self::file_exists($path); } public function file_exists($path) { diff --git a/apps/files_texteditor/js/editor.js b/apps/files_texteditor/js/editor.js index 9d168c1c4f..70bb74a910 100644 --- a/apps/files_texteditor/js/editor.js +++ b/apps/files_texteditor/js/editor.js @@ -67,7 +67,7 @@ function setSyntaxMode(ext){ function showControls(filename,writeperms){ // Loads the control bar at the top. // Load the new toolbar. - var editorbarhtml = '