diff --git a/apps/calendar/ajax/updatecalendar.php b/apps/calendar/ajax/updatecalendar.php index 5add6d92bfa..20c225d8a29 100644 --- a/apps/calendar/ajax/updatecalendar.php +++ b/apps/calendar/ajax/updatecalendar.php @@ -25,8 +25,16 @@ foreach($calendars as $cal){ } $calendarid = $_POST['id']; +$calendarcolor = $_POST['color']; +if (preg_match('/^#?([0-9a-f]{6})/', $calendarcolor, $matches)) { + $calendarcolor = '#'.$matches[1]; +} +else { + $calendarcolor = null; +} + $calendar = OC_Calendar_App::getCalendar($calendarid);//access check -OC_Calendar_Calendar::editCalendar($calendarid, strip_tags($_POST['name']), null, null, null, $_POST['color']); +OC_Calendar_Calendar::editCalendar($calendarid, strip_tags($_POST['name']), null, null, null, $calendarcolor); OC_Calendar_Calendar::setCalendarActive($calendarid, $_POST['active']); $calendar = OC_Calendar_App::getCalendar($calendarid); diff --git a/apps/calendar/appinfo/info.xml b/apps/calendar/appinfo/info.xml index 46292af3db1..4ac3c5bf099 100644 --- a/apps/calendar/appinfo/info.xml +++ b/apps/calendar/appinfo/info.xml @@ -2,7 +2,7 @@ calendar Calendar - 0.2 + 0.2.1 AGPL Georg Ehrke, Bart Visscher, Jakob Sack 2 diff --git a/apps/calendar/appinfo/update.php b/apps/calendar/appinfo/update.php new file mode 100644 index 00000000000..375816a403e --- /dev/null +++ b/apps/calendar/appinfo/update.php @@ -0,0 +1,17 @@ +execute(); + while( $row = $result->fetchRow()) { + $id = $row['id']; + $color = $row['calendarcolor']; + if ($color[0] == '#' || strlen($color) < 6) { + continue; + } + $color = '#' .$color; + $stmt = OC_DB::prepare( 'UPDATE *PREFIX*calendar_calendars SET calendarcolor=? WHERE id=?' ); + $r = $stmt->execute(array($color,$id)); + } +} diff --git a/apps/calendar/js/calendar.js b/apps/calendar/js/calendar.js index 517d2ce128b..ba8e293819a 100644 --- a/apps/calendar/js/calendar.js +++ b/apps/calendar/js/calendar.js @@ -478,7 +478,7 @@ Calendar={ colors[i].label = $(elm).text(); }); for (var i in colors) { - picker.append(''); + picker.append(''); } picker.delegate(".calendar-colorpicker-color", "click", function() { $(obj).val($(this).attr('rel')); diff --git a/apps/calendar/lib/calendar.php b/apps/calendar/lib/calendar.php index 679649582d8..277539af97d 100644 --- a/apps/calendar/lib/calendar.php +++ b/apps/calendar/lib/calendar.php @@ -96,7 +96,7 @@ class OC_Calendar_Calendar{ * @param string $components Default: "VEVENT,VTODO,VJOURNAL" * @param string $timezone Default: null * @param integer $order Default: 1 - * @param string $color Default: null + * @param string $color Default: null, format: '#RRGGBB(AA)' * @return insertid */ public static function addCalendar($userid,$name,$components='VEVENT,VTODO,VJOURNAL',$timezone=null,$order=0,$color=null){ @@ -122,7 +122,7 @@ class OC_Calendar_Calendar{ * @param string $components * @param string $timezone * @param integer $order - * @param string $color + * @param string $color format: '#RRGGBB(AA)' * @return insertid */ public static function addCalendarFromDAVData($principaluri,$uri,$name,$components,$timezone,$order,$color){ @@ -141,7 +141,7 @@ class OC_Calendar_Calendar{ * @param string $components Default: null * @param string $timezone Default: null * @param integer $order Default: null - * @param string $color Default: null + * @param string $color Default: null, format: '#RRGGBB(AA)' * @return boolean * * Values not null will be set @@ -230,20 +230,20 @@ class OC_Calendar_Calendar{ } public static function getCalendarColorOptions(){ return array( - 'ff0000', // "Red" - 'b3dc6c', // "Green" - 'ffff00', // "Yellow" - '808000', // "Olive" - 'ffa500', // "Orange" - 'ff7f50', // "Coral" - 'ee82ee', // "Violet" - '9fc6e7', // "light blue" + '#ff0000', // "Red" + '#b3dc6c', // "Green" + '#ffff00', // "Yellow" + '#808000', // "Olive" + '#ffa500', // "Orange" + '#ff7f50', // "Coral" + '#ee82ee', // "Violet" + '#9fc6e7', // "light blue" ); } public static function getEventSourceInfo($calendar){ return array( 'url' => 'ajax/events.php?calendar_id='.$calendar['id'], - 'backgroundColor' => '#'.$calendar['calendarcolor'], + 'backgroundColor' => $calendar['calendarcolor'], 'borderColor' => '#888', 'textColor' => 'black', 'cache' => true, diff --git a/apps/contacts/ajax/saveproperty.php b/apps/contacts/ajax/saveproperty.php index 0c9e0cc7836..6f8366243fe 100644 --- a/apps/contacts/ajax/saveproperty.php +++ b/apps/contacts/ajax/saveproperty.php @@ -51,7 +51,7 @@ $checksum = isset($_POST['checksum'])?$_POST['checksum']:null; // } // } -if(is_array($value)){ // FIXME: How to strip_tags for compound values? +if(is_array($value)){ $value = array_map('strip_tags', $value); ksort($value); // NOTE: Important, otherwise the compound value will be set in the order the fields appear in the form! $value = OC_VObject::escapeSemicolons($value); diff --git a/apps/contacts/js/contacts.js b/apps/contacts/js/contacts.js index 0e06b650a18..11661320c59 100644 --- a/apps/contacts/js/contacts.js +++ b/apps/contacts/js/contacts.js @@ -1076,7 +1076,7 @@ Contacts={ $.post(url, { id: bookid, name: displayname, active: active, description: description }, function(jsondata){ if(jsondata.status == 'success'){ - $(button).closest('tr').prev().html(data.page).show().next().remove(); + $(button).closest('tr').prev().html(jsondata.page).show().next().remove(); Contacts.UI.Contacts.update(); } else { Contacts.UI.messageBox(t('contacts', 'Error'), jsondata.data.message); diff --git a/apps/contacts/lib/vcard.php b/apps/contacts/lib/vcard.php index a10d052a2d1..99b1edd656f 100644 --- a/apps/contacts/lib/vcard.php +++ b/apps/contacts/lib/vcard.php @@ -103,6 +103,118 @@ class OC_Contacts_VCard{ return $result->fetchRow(); } + /** + * @brief Format property TYPE parameters for upgrading from v. 2.1 + * @param $property Reference to a Sabre_VObject_Property. + * In version 2.1 e.g. a phone can be formatted like: TEL;HOME;CELL:123456789 + * This has to be changed to either TEL;TYPE=HOME,CELL:123456789 or TEL;TYPE=HOME;TYPE=CELL:123456789 - both are valid. + */ + public static function formatPropertyTypes(&$property) { + foreach($property->parameters as $key=>&$parameter){ + $types = OC_Contacts_App::getTypesOfProperty($property->name); + if(is_array($types) && in_array(strtoupper($parameter->name), array_keys($types)) || strtoupper($parameter->name) == 'PREF') { + $property->parameters[] = new Sabre_VObject_Parameter('TYPE', $parameter->name); + } + unset($property->parameters[$key]); + } + } + + /** + * @brief Decode properties for upgrading from v. 2.1 + * @param $property Reference to a Sabre_VObject_Property. + * The only encoding allowed in version 3.0 is 'b' for binary. All encoded strings + * must therefor be decoded and the parameters removed. + */ + public static function decodeProperty(&$property) { + // Check out for encoded string and decode them :-[ + foreach($property->parameters as $key=>&$parameter){ + if(strtoupper($parameter->name) == 'ENCODING') { + if(strtoupper($parameter->value) == 'QUOTED-PRINTABLE') { // what kind of other encodings could be used? + $property->value = quoted_printable_decode($property->value); + unset($property->parameters[$key]); + } + } elseif(strtoupper($parameter->name) == 'CHARSET') { + unset($property->parameters[$key]); + } + } + } + + /** + * @brief Tries to update imported VCards to adhere to rfc2426 (VERSION: 3.0) + * @param vcard An OC_VObject of type VCARD (passed by reference). + */ + protected static function updateValuesFromAdd(&$vcard) { // any suggestions for a better method name? ;-) + $stringprops = array('N', 'FN', 'ORG', 'NICK', 'ADR', 'NOTE'); + $typeprops = array('ADR', 'TEL', 'EMAIL'); + $upgrade = false; + $fn = $n = $uid = $email = null; + $version = $vcard->getAsString('VERSION'); + // Add version if needed + if($version && $version < '3.0') { + $upgrade = true; + OC_Log::write('contacts','OC_Contacts_VCard::updateValuesFromAdd. Updating from version: '.$version,OC_Log::DEBUG); + } + foreach($vcard->children as &$property){ + // Decode string properties and remove obsolete properties. + if($upgrade && in_array($property->name, $stringprops)) { + self::decodeProperty($property); + } + // Fix format of type parameters. + if($upgrade && in_array($property->name, $typeprops)) { + OC_Log::write('contacts','OC_Contacts_VCard::updateValuesFromAdd. before: '.$property->serialize(),OC_Log::DEBUG); + self::formatPropertyTypes($property); + OC_Log::write('contacts','OC_Contacts_VCard::updateValuesFromAdd. after: '.$property->serialize(),OC_Log::DEBUG); + } + if($property->name == 'FN'){ + $fn = $property->value; + } + if($property->name == 'N'){ + $n = $property->value; + } + if($property->name == 'UID'){ + $uid = $property->value; + } + if($property->name == 'EMAIL' && is_null($email)){ // only use the first email as substitute for missing N or FN. + $email = $property->value; + } + } + // Check for missing 'N', 'FN' and 'UID' properties + if(!$fn) { + if($n && $n != ';;;;'){ + $fn = join(' ', array_reverse(array_slice(explode(';', $n), 0, 2))); + } elseif($email) { + $fn = $email; + } else { + $fn = 'Unknown Name'; + } + $vcard->setString('FN', $fn); + OC_Log::write('contacts','OC_Contacts_VCard::updateValuesFromAdd. Added missing \'FN\' field: '.$fn,OC_Log::DEBUG); + } + if(!$n || $n = ';;;;'){ // Fix missing 'N' field. Ugly hack ahead ;-) + $slice = array_reverse(array_slice(explode(' ', $fn), 0, 2)); // Take 2 first name parts of 'FN' and reverse. + if(count($slice) < 2) { // If not enought, add one more... + $slice[] = ""; + } + $n = implode(';', $slice).';;;'; + $vcard->setString('N', $n); + OC_Log::write('contacts','OC_Contacts_VCard::updateValuesFromAdd. Added missing \'N\' field: '.$n,OC_Log::DEBUG); + } + if(!$uid) { + $vcard->setUID(); + OC_Log::write('contacts','OC_Contacts_VCard::updateValuesFromAdd. Added missing \'UID\' field: '.$uid,OC_Log::DEBUG); + } + $vcard->setString('VERSION','3.0'); + // Add product ID is missing. + $prodid = trim($vcard->getAsString('PRODID')); + if(!$prodid) { + $appinfo = OC_App::getAppInfo('contacts'); + $prodid = '-//ownCloud//NONSGML '.$appinfo['name'].' '.$appinfo['version'].'//EN'; + $vcard->setString('PRODID', $prodid); + } + $now = new DateTime; + $vcard->setString('REV', $now->format(DateTime::W3C)); + } + /** * @brief Adds a card * @param integer $id Addressbook id @@ -115,59 +227,17 @@ class OC_Contacts_VCard{ $card = OC_VObject::parse($data); if(!is_null($card)){ OC_Contacts_App::$categories->loadFromVObject($card); - - $fn = $card->getAsString('FN'); - if(!$fn){ // Fix missing 'FN' field. - $n = $card->getAsString('N'); - if(!is_null($n)){ - $fn = join(' ', array_reverse(array_slice(explode(';', $n), 0, 2))); - $card->setString('FN', $fn); - OC_Log::write('contacts','OC_Contacts_VCard::add. Added missing \'FN\' field: '.$fn,OC_Log::DEBUG); - } else { - $fn = 'Unknown Name'; - } - } - $n = $card->getAsString('N'); - if(!$n){ // Fix missing 'N' field. - $n = implode(';', array_reverse(array_slice(explode(' ', $fn), 0, 2))).';;;'; - $card->setString('N', $n); - OC_Log::write('contacts','OC_Contacts_VCard::add. Added missing \'N\' field: '.$n,OC_Log::DEBUG); - } - $uid = $card->getAsString('UID'); - if(!$uid){ - $card->setUID(); - $uid = $card->getAsString('UID'); - }; - $uri = $uid.'.vcf'; - - // Add product ID. - $prodid = trim($card->getAsString('PRODID')); - if(!$prodid) { - $appinfo = OC_App::getAppInfo('contacts'); - $prodid = '//ownCloud//NONSGML '.$appinfo['name'].' '.$appinfo['version'].'//EN'; - $card->setString('PRODID', $prodid); - } - // VCARD must have a version - $version = $card->getAsString('VERSION'); - // Add version if needed - if(!$version){ - $card->add(new Sabre_VObject_Property('VERSION','3.0')); - //$data = $card->serialize(); - }/* else { - OC_Log::write('contacts','OC_Contacts_VCard::add. Version already set as: '.$version,OC_Log::DEBUG); - }*/ - $now = new DateTime; - $card->setString('REV', $now->format(DateTime::W3C)); + self::updateValuesFromAdd($card); $data = $card->serialize(); } else{ - // that's hard. Creating a UID and not saving it OC_Log::write('contacts','OC_Contacts_VCard::add. Error parsing VCard: '.$data,OC_Log::ERROR); return null; // Ditch cards that can't be parsed by Sabre. - //$uid = self::createUID(); - //$uri = $uid.'.vcf'; }; + $fn = $card->getAsString('FN'); + $uid = $card->getAsString('UID'); + $uri = $uid.'.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())); $newid = OC_DB::insertid('*PREFIX*contacts_cards'); @@ -185,55 +255,24 @@ class OC_Contacts_VCard{ * @return insertid */ public static function addFromDAVData($id,$uri,$data){ - $fn = $n = $uid = null; - $email = null; $card = OC_VObject::parse($data); if(!is_null($card)){ OC_Contacts_App::$categories->loadFromVObject($card); - foreach($card->children as $property){ - if($property->name == 'FN'){ - $fn = $property->value; - } - if($property->name == 'N'){ - $n = $property->value; - } - if($property->name == 'UID'){ - $uid = $property->value; - } - if($property->name == 'EMAIL' && is_null($email)){ - $email = $property->value; - } - } - } - if(!$fn) { - if($n){ - $fn = join(' ', array_reverse(array_slice(explode(';', $n), 0, 2))); - } elseif($email) { - $fn = $email; - } else { - $fn = 'Unknown Name'; - } - $card->addProperty('FN', $fn); - $data = $card->serialize(); - OC_Log::write('contacts','OC_Contacts_VCard::add. Added missing \'FN\' field: '.$n,OC_Log::DEBUG); - } - if(!$n){ // Fix missing 'N' field. - $n = implode(';', array_reverse(array_slice(explode(' ', $fn), 0, 2))).';;;'; - $card->setString('N', $n); - $data = $card->serialize(); - OC_Log::write('contacts','OC_Contacts_VCard::add. Added missing \'N\' field: '.$n,OC_Log::DEBUG); - } - if(!$uid) { - $card->setUID(); + self::updateValuesFromAdd($card); $data = $card->serialize(); - } + } else { + OC_Log::write('contacts','OC_Contacts_VCard::addFromDAVData. Error parsing VCard: '.$data, OC_Log::ERROR); + return null; // Ditch cards that can't be parsed by Sabre. + }; + $fn = $card->getAsString('FN'); $stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*contacts_cards (addressbookid,fullname,carddata,uri,lastmodified) VALUES(?,?,?,?,?)' ); $result = $stmt->execute(array($id,$fn,$data,$uri,time())); + $newid = OC_DB::insertid('*PREFIX*contacts_cards'); OC_Contacts_Addressbook::touch($id); - return OC_DB::insertid('*PREFIX*contacts_cards'); + return $newid; } /** @@ -309,7 +348,7 @@ class OC_Contacts_VCard{ * @return boolean */ public static function delete($id){ - // FIXME: Add error checking. Touch addressbook. + // FIXME: Add error checking. $stmt = OC_DB::prepare( 'DELETE FROM *PREFIX*contacts_cards WHERE id = ?' ); $stmt->execute(array($id)); @@ -386,10 +425,14 @@ class OC_Contacts_VCard{ 'checksum' => md5($property->serialize())); foreach($property->parameters as $parameter){ // Faulty entries by kaddressbook + // Actually TYPE=PREF is correct according to RFC 2426 + // but this way is more handy in the UI. Tanghus. if($parameter->name == 'TYPE' && $parameter->value == 'PREF'){ $parameter->name = 'PREF'; $parameter->value = '1'; } + // NOTE: Apparently Sabre_VObject_Reader can't always deal with value list parameters + // like TYPE=HOME,CELL,VOICE. Tanghus. if ($property->name == 'TEL' && $parameter->name == 'TYPE'){ if (isset($temp['parameters'][$parameter->name])){ $temp['parameters'][$parameter->name][] = $parameter->value; diff --git a/apps/media/css/music.css b/apps/media/css/music.css index 91da9ec40e7..07173624018 100644 --- a/apps/media/css/music.css +++ b/apps/media/css/music.css @@ -17,7 +17,7 @@ a.jp-mute,a.jp-unmute { left:24em; } div.jp-volume-bar { position:absolute; overflow:hidden; background:#eee; width:4em; height:0.4em; cursor:pointer; top:1.3em; left:27em; } div.jp-volume-bar-value { background:#ccc; width:0; height:0.4em; } -#collection { padding-top:1em; position:relative; width:100%; float:left; table-layout:fixed; } +#collection { position:relative; width:100%; float:left; table-layout:fixed; } #collection td { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; } #leftcontent img.remove { display:none; float:right; cursor:pointer; opacity: 0; } #leftcontent li:hover img.remove { display:inline; opacity: .3; } @@ -31,7 +31,7 @@ div.jp-volume-bar-value { background:#ccc; width:0; height:0.4em; } #collection td.artist-expander, #collection td.album-expander { width:2em; text-align:center; } td.artist a.expander, td.album a.expander { float:right; padding:0 1em; } tr.active td { background-color:#eee; font-weight:bold; } -tr td { border-top:1px solid #eee; height:2.2em; } +tr td { border-bottom:1px solid #eee; height:2.2em; } tr .artist img { vertical-align:middle; } tr.album td.artist { padding-left:1em; } tr.song td.artist { padding-left:2em; } diff --git a/lib/helper.php b/lib/helper.php index b1e6d053a19..2f71bdad2dc 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -29,12 +29,11 @@ class OC_Helper { * @brief Creates an url * @param $app app * @param $file file - * @param $redirect_url redirect_url variable is appended to the URL * @returns the url * * Returns a url to the given app and file. */ - public static function linkTo( $app, $file, $redirect_url=NULL, $absolute=false ){ + public static function linkTo( $app, $file ){ if( $app != '' ){ $app .= '/'; // Check if the app is in the app folder @@ -54,24 +53,19 @@ class OC_Helper { } } - if($redirect_url) - return $urlLinkTo.'?redirect_url='.urlencode($_SERVER["REQUEST_URI"]); - else - return $urlLinkTo; - + return $urlLinkTo; } /** * @brief Creates an absolute url * @param $app app * @param $file file - * @param $redirect_url redirect_url variable is appended to the URL * @returns the url * * Returns a absolute url to the given app and file. */ - public static function linkToAbsolute( $app, $file, $redirect_url=NULL ) { - $urlLinkTo = self::linkTo( $app, $file, $redirect_url ); + public static function linkToAbsolute( $app, $file ) { + $urlLinkTo = self::linkTo( $app, $file ); // Checking if the request was made through HTTPS. The last in line is for IIS $protocol = isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && ($_SERVER['HTTPS']!='off'); $urlLinkTo = ($protocol?'https':'http') . '://' . $_SERVER['HTTP_HOST'] . $urlLinkTo; diff --git a/lib/util.php b/lib/util.php index ee32d31bfd0..1b1e29b6749 100644 --- a/lib/util.php +++ b/lib/util.php @@ -240,7 +240,7 @@ class OC_Util { /** - * Check if the app is enabled, send json error msg if not + * Check if the app is enabled, redirects to home if not */ public static function checkAppEnabled($app){ if( !OC_App::isEnabled($app)){ @@ -250,12 +250,13 @@ class OC_Util { } /** - * Check if the user is logged in, redirects to home if not + * Check if the user is logged in, redirects to home if not. With + * redirect URL parameter to the request URI. */ public static function checkLoggedIn(){ // Check if we are a user if( !OC_User::isLoggedIn()){ - header( 'Location: '.OC_Helper::linkToAbsolute( '', 'index.php' )); + header( 'Location: '.OC_Helper::linkToAbsolute( '', 'index.php' ).'?redirect_url='.urlencode($_SERVER["REQUEST_URI"])); exit(); } }