Merge branch 'master' into calendar_import

This commit is contained in:
Georg Ehrke 2012-06-27 14:02:05 +02:00
commit 153ce2f9ab
20 changed files with 316 additions and 132 deletions

View file

@ -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

View file

@ -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');

View file

@ -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();

View file

@ -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');

View file

@ -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());

View file

@ -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);
});

View file

@ -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;
}

View file

@ -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.

View file

@ -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

View file

@ -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;
}
}

View file

@ -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) {

View file

@ -67,7 +67,7 @@ function setSyntaxMode(ext){
function showControls(filename,writeperms){
// Loads the control bar at the top.
// Load the new toolbar.
var editorbarhtml = '<div id="editorcontrols" style="display: none;"><div class="crumb svg last" id="breadcrumb_file" style="background-image:url(&quot;'+OC.imagePath('core','breadcrumb.png')+'&quot;)"><p>'+filename+'</p></div>';
var editorbarhtml = '<div id="editorcontrols" style="display: none;"><div class="crumb svg last" id="breadcrumb_file" style="background-image:url(&quot;'+OC.imagePath('core','breadcrumb.png')+'&quot;)"><p>'+filename.replace(/</, "&lt;").replace(/>/, "&gt;")+'</p></div>';
if(writeperms=="true"){
editorbarhtml += '<button id="editor_save">'+t('files_texteditor','Save')+'</button><div class="separator"></div>';
}

View file

@ -61,7 +61,6 @@ class OC_MEDIA_SCANNER{
* @return boolean
*/
public static function scanFile($path){
$file=OC_Filesystem::getLocalFile($path);
if(!self::isMusic($path)){
return;
}
@ -69,6 +68,7 @@ class OC_MEDIA_SCANNER{
self::$getID3=@new getID3();
self::$getID3->encoding='UTF-8';
}
$file=OC_Filesystem::getLocalFile($path);
$data=@self::$getID3->analyze($file);
getid3_lib::CopyTagsToComments($data);
if(!isset($data['comments'])){

View file

@ -84,6 +84,7 @@ class OC_App{
*/
public static function loadApp($app){
if(is_file(self::getAppPath($app).'/appinfo/app.php')){
self::checkUpgrade($app);
require_once( $app.'/appinfo/app.php' );
}
}
@ -526,22 +527,17 @@ class OC_App{
}
/**
* check if any apps need updating and update those
* check if the app need updating and update when needed
*/
public static function updateApps(){
public static function checkUpgrade($app) {
$versions = self::getAppVersions();
//ensure files app is installed for upgrades
if(!isset($versions['files'])){
$versions['files']='0';
}
foreach( $versions as $app=>$installedVersion ){
$currentVersion=OC_App::getAppVersion($app);
if ($currentVersion) {
if (version_compare($currentVersion, $installedVersion, '>')) {
OC_Log::write($app, 'starting app upgrade from '.$installedVersion.' to '.$currentVersion,OC_Log::DEBUG);
OC_App::updateApp($app);
OC_Appconfig::setValue($app, 'installed_version', OC_App::getAppVersion($app));
}
$currentVersion=OC_App::getAppVersion($app);
if ($currentVersion) {
$installedVersion = $versions[$app];
if (version_compare($currentVersion, $installedVersion, '>')) {
OC_Log::write($app, 'starting app upgrade from '.$installedVersion.' to '.$currentVersion,OC_Log::DEBUG);
OC_App::updateApp($app);
OC_Appconfig::setValue($app, 'installed_version', OC_App::getAppVersion($app));
}
}
}
@ -571,6 +567,10 @@ class OC_App{
* get the installed version of all papps
*/
public static function getAppVersions(){
static $versions;
if (isset($versions)) { // simple cache, needs to be fixed
return $versions; // when function is used besides in checkUpgrade
}
$versions=array();
$query = OC_DB::prepare( 'SELECT appid, configvalue FROM *PREFIX*appconfig WHERE configkey = \'installed_version\'' );
$result = $query->execute();

View file

@ -170,8 +170,10 @@ class OC{
public static function checkInstalled() {
// Redirect to installer if not installed
if (!OC_Config::getValue('installed', false) && OC::$SUBURI != '/index.php') {
$url = 'http://'.$_SERVER['SERVER_NAME'].OC::$WEBROOT.'/index.php';
header("Location: $url");
if(!OC::$CLI){
$url = 'http://'.$_SERVER['SERVER_NAME'].OC::$WEBROOT.'/index.php';
header("Location: $url");
}
exit();
}
}
@ -180,7 +182,7 @@ class OC{
// redirect to https site if configured
if( OC_Config::getValue( "forcessl", false )){
ini_set("session.cookie_secure", "on");
if(OC_Helper::serverProtocol()<>'https') {
if(OC_Helper::serverProtocol()<>'https' and !OC::$CLI) {
$url = "https://". OC_Helper::serverHost() . $_SERVER['REQUEST_URI'];
header("Location: $url");
exit();
@ -208,9 +210,9 @@ class OC{
OC_Config::setValue('version',implode('.',OC_Util::getVersion()));
OC_App::checkAppsRequirements();
// load all apps to also upgrade enabled apps
OC_App::loadApps();
}
OC_App::updateApps();
}
}

View file

@ -90,16 +90,18 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
foreach($folder_content as $info) {
$paths[] = $this->path.'/'.$info['name'];
}
$placeholders = join(',', array_fill(0, count($paths), '?'));
$query = OC_DB::prepare( 'SELECT * FROM *PREFIX*properties WHERE userid = ?' . ' AND propertypath IN ('.$placeholders.')' );
array_unshift($paths, OC_User::getUser()); // prepend userid
$result = $query->execute( $paths );
$properties = array_fill_keys($paths, array());
while($row = $result->fetchRow()) {
$propertypath = $row['propertypath'];
$propertyname = $row['propertyname'];
$propertyvalue = $row['propertyvalue'];
$properties[$propertypath][$propertyname] = $propertyvalue;
if(count($paths)>0){
$placeholders = join(',', array_fill(0, count($paths), '?'));
$query = OC_DB::prepare( 'SELECT * FROM *PREFIX*properties WHERE userid = ?' . ' AND propertypath IN ('.$placeholders.')' );
array_unshift($paths, OC_User::getUser()); // prepend userid
$result = $query->execute( $paths );
while($row = $result->fetchRow()) {
$propertypath = $row['propertypath'];
$propertyname = $row['propertyname'];
$propertyvalue = $row['propertyvalue'];
$properties[$propertypath][$propertyname] = $propertyvalue;
}
}
$nodes = array();

View file

@ -75,6 +75,9 @@ class OC_Helper {
* reverse proxies
*/
public static function serverHost() {
if(OC::$CLI){
return 'localhost';
}
if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
if (strpos($_SERVER['HTTP_X_FORWARDED_HOST'], ",") !== false) {
$host = trim(array_pop(explode(",", $_SERVER['HTTP_X_FORWARDED_HOST'])));

View file

@ -55,7 +55,7 @@ class OC_VCategories {
$this->app = $app;
$this->user = is_null($user) ? OC_User::getUser() : $user;
$categories = trim(OC_Preferences::getValue($this->user, $app, self::PREF_CATEGORIES_LABEL, ''));
$this->categories = $categories != '' ? unserialize($categories) : $defcategories;
$this->categories = $categories != '' ? @unserialize($categories) : $defcategories;
}
/**
@ -64,6 +64,9 @@ class OC_VCategories {
*/
public function categories() {
//OC_Log::write('core','OC_VCategories::categories: '.print_r($this->categories, true), OC_Log::DEBUG);
if(!$this->categories) {
return array();
}
usort($this->categories, 'strnatcasecmp'); // usort to also renumber the keys
return $this->categories;
}
@ -203,11 +206,17 @@ class OC_VCategories {
// case-insensitive in_array
private function in_arrayi($needle, $haystack) {
if(!is_array($haystack)) {
return false;
}
return in_array(strtolower($needle), array_map('strtolower', $haystack));
}
// case-insensitive array_search
private function array_searchi($needle, $haystack) {
if(!is_array($haystack)) {
return false;
}
return array_search(strtolower($needle),array_map('strtolower',$haystack));
}

View file

@ -10,6 +10,7 @@ if(is_null($file)){
$parts=explode('/',$file,2);
$app=$parts[0];
OC_Util::checkAppEnabled($app);
OC_App::loadApp($app);
require_once(OC_App::getAppPath($app) .'/'. $parts[1]);

View file

@ -27,13 +27,24 @@ $file = ltrim ($file, '/');
if(count(explode('/',$file)) == 2) {
$parts=explode('/',$file);
$app=$parts[1];
OC_App::loadApp($app);
$app=$parts[0];
switch ($app) {
case 'files':
OC_Util::checkAppEnabled($app);
OC_App::loadApp($app);
break;
case 'core':
break;
default:
OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND);
exit;
}
$baseuri = OC::$WEBROOT . '/remote.php/'.$service.'/';
require_once( OC::$SERVERROOT.'/'.$file);
} else {
$parts=explode('/', $file, 2);
$app=$parts[0];
OC_Util::checkAppEnabled($app);
OC_App::loadApp($app);
$baseuri = OC::$WEBROOT . '/remote.php/'.$service.'/';
require_once(OC_App::getAppPath($app) .'/'. $parts[1]);