Merge branch 'master' of gitorious.org:owncloud/owncloud into ace-editor

This commit is contained in:
Tom Needham 2011-12-11 18:16:14 +00:00
commit 3f44a28e28
48 changed files with 707 additions and 606 deletions

View File

@ -34,7 +34,7 @@ if($errarr){
OC_JSON::error(); OC_JSON::error();
exit; exit;
} }
$vcalendar = OC_Calendar_Object::parse($data['calendardata']); $vcalendar = OC_VObject::parse($data['calendardata']);
$last_modified = $vcalendar->VEVENT->__get('LAST-MODIFIED'); $last_modified = $vcalendar->VEVENT->__get('LAST-MODIFIED');
if($last_modified && $_POST['lastmodified'] != $last_modified->getDateTime()->format('U')){ if($last_modified && $_POST['lastmodified'] != $last_modified->getDateTime()->format('U')){

View File

@ -26,7 +26,7 @@ if($calendar['userid'] != OC_User::getUser()){
echo $l10n->t('Wrong calendar'); echo $l10n->t('Wrong calendar');
exit; exit;
} }
$object = OC_Calendar_Object::parse($data['calendardata']); $object = OC_VObject::parse($data['calendardata']);
$vevent = $object->VEVENT; $vevent = $object->VEVENT;
$dtstart = $vevent->DTSTART; $dtstart = $vevent->DTSTART;
$dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent); $dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent);
@ -49,20 +49,16 @@ switch($dtstart->getDateType()) {
break; break;
} }
$summary = isset($vevent->SUMMARY) ? $vevent->SUMMARY->value : ''; $summary = $vevent->getAsString('SUMMARY');
$location = isset($vevent->LOCATION) ? $vevent->LOCATION->value : ''; $location = $vevent->getAsString('LOCATION');
$categories = array(); $categories = $vevent->getAsArray('CATEGORIES');
if (isset($vevent->CATEGORIES)){ $repeat = $vevent->getAsString('CATEGORY');
$categories = explode(',', $vevent->CATEGORIES->value); $description = $vevent->getAsString('DESCRIPTION');
$categories = array_map('trim', $categories);
}
foreach($categories as $category){ foreach($categories as $category){
if (!in_array($category, $category_options)){ if (!in_array($category, $category_options)){
array_unshift($category_options, $category); array_unshift($category_options, $category);
} }
} }
$repeat = isset($vevent->CATEGORY) ? $vevent->CATEGORY->value : '';
$description = isset($vevent->DESCRIPTION) ? $vevent->DESCRIPTION->value : '';
$last_modified = $vevent->__get('LAST-MODIFIED'); $last_modified = $vevent->__get('LAST-MODIFIED');
if ($last_modified){ if ($last_modified){
$lastmodified = $last_modified->getDateTime()->format('U'); $lastmodified = $last_modified->getDateTime()->format('U');

View File

@ -33,7 +33,7 @@ $events = OC_Calendar_Object::allInPeriod($_GET['calendar_id'], $start, $end);
$user_timezone = OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezone', date_default_timezone_get()); $user_timezone = OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezone', date_default_timezone_get());
$return = array(); $return = array();
foreach($events as $event){ foreach($events as $event){
$object = OC_Calendar_Object::parse($event['calendardata']); $object = OC_VObject::parse($event['calendardata']);
$vevent = $object->VEVENT; $vevent = $object->VEVENT;
$dtstart = $vevent->DTSTART; $dtstart = $vevent->DTSTART;
$dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent); $dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent);

View File

@ -22,7 +22,7 @@ $delta = new DateInterval('P0D');
$delta->d = $_POST['dayDelta']; $delta->d = $_POST['dayDelta'];
$delta->i = $_POST['minuteDelta']; $delta->i = $_POST['minuteDelta'];
$vcalendar = OC_Calendar_Object::parse($data['calendardata']); $vcalendar = OC_VObject::parse($data['calendardata']);
$vevent = $vcalendar->VEVENT; $vevent = $vcalendar->VEVENT;
$last_modified = $vevent->__get('LAST-MODIFIED'); $last_modified = $vevent->__get('LAST-MODIFIED');
@ -46,14 +46,8 @@ $dtstart->setDateTime($dtstart->getDateTime()->add($delta), $start_type);
$dtend->setDateTime($dtend->getDateTime()->add($delta), $end_type); $dtend->setDateTime($dtend->getDateTime()->add($delta), $end_type);
unset($vevent->DURATION); unset($vevent->DURATION);
$now = new DateTime(); $vevent->setDateTime('LAST-MODIFIED', 'now', Sabre_VObject_Element_DateTime::UTC);
$last_modified = new Sabre_VObject_Element_DateTime('LAST-MODIFIED'); $vevent->setDateTime('DTSTAMP', 'now', Sabre_VObject_Element_DateTime::UTC);
$last_modified->setDateTime($now, Sabre_VObject_Element_DateTime::UTC);
$vevent->__set('LAST-MODIFIED', $last_modified);
$dtstamp = new Sabre_VObject_Element_DateTime('DTSTAMP');
$dtstamp->setDateTime($now, Sabre_VObject_Element_DateTime::UTC);
$vevent->DTSTAMP = $dtstamp;
$result = OC_Calendar_Object::edit($id, $vcalendar->serialize()); $result = OC_Calendar_Object::edit($id, $vcalendar->serialize());
OC_JSON::success(array('lastmodified'=>(int)$now->format('U'))); OC_JSON::success(array('lastmodified'=>(int)$now->format('U')));

View File

@ -7,7 +7,6 @@
*/ */
Calendar={ Calendar={
space:' ',
UI:{ UI:{
startEventDialog:function(){ startEventDialog:function(){
$('.tipsy').remove(); $('.tipsy').remove();
@ -271,9 +270,9 @@ Calendar={
var url; var url;
if (calendarid == 'new'){ if (calendarid == 'new'){
url = "ajax/createcalendar.php"; url = OC.filePath('calendar', 'ajax', 'createcalendar.php');
}else{ }else{
url = "ajax/updatecalendar.php"; url = OC.filePath('calendar', 'ajax', 'updatecalendar.php');
} }
$.post(url, { id: calendarid, name: displayname, active: active, description: description, color: calendarcolor }, $.post(url, { id: calendarid, name: displayname, active: active, description: description, color: calendarcolor },
function(data){ function(data){

View File

@ -92,7 +92,7 @@ class OC_Calendar_Object{
* @return insertid * @return insertid
*/ */
public static function add($id,$data){ public static function add($id,$data){
$object = self::parse($data); $object = OC_VObject::parse($data);
list($type,$startdate,$enddate,$summary,$repeating,$uid) = self::extractData($object); list($type,$startdate,$enddate,$summary,$repeating,$uid) = self::extractData($object);
if(is_null($uid)){ if(is_null($uid)){
@ -119,7 +119,7 @@ class OC_Calendar_Object{
* @return insertid * @return insertid
*/ */
public static function addFromDAVData($id,$uri,$data){ public static function addFromDAVData($id,$uri,$data){
$object = self::parse($data); $object = OC_VObject::parse($data);
list($type,$startdate,$enddate,$summary,$repeating,$uid) = self::extractData($object); list($type,$startdate,$enddate,$summary,$repeating,$uid) = self::extractData($object);
$stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*calendar_objects (calendarid,objecttype,startdate,enddate,repeating,summary,calendardata,uri,lastmodified) VALUES(?,?,?,?,?,?,?,?,?)' ); $stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*calendar_objects (calendarid,objecttype,startdate,enddate,repeating,summary,calendardata,uri,lastmodified) VALUES(?,?,?,?,?,?,?,?,?)' );
@ -139,7 +139,7 @@ class OC_Calendar_Object{
public static function edit($id, $data){ public static function edit($id, $data){
$oldobject = self::find($id); $oldobject = self::find($id);
$object = self::parse($data); $object = OC_VObject::parse($data);
list($type,$startdate,$enddate,$summary,$repeating,$uid) = self::extractData($object); list($type,$startdate,$enddate,$summary,$repeating,$uid) = self::extractData($object);
$stmt = OC_DB::prepare( 'UPDATE *PREFIX*calendar_objects SET objecttype=?,startdate=?,enddate=?,repeating=?,summary=?,calendardata=?, lastmodified = ? WHERE id = ?' ); $stmt = OC_DB::prepare( 'UPDATE *PREFIX*calendar_objects SET objecttype=?,startdate=?,enddate=?,repeating=?,summary=?,calendardata=?, lastmodified = ? WHERE id = ?' );
@ -160,7 +160,7 @@ class OC_Calendar_Object{
public static function editFromDAVData($cid,$uri,$data){ public static function editFromDAVData($cid,$uri,$data){
$oldobject = self::findWhereDAVDataIs($cid,$uri); $oldobject = self::findWhereDAVDataIs($cid,$uri);
$object = self::parse($data); $object = OC_VObject::parse($data);
list($type,$startdate,$enddate,$summary,$repeating,$uid) = self::extractData($object); list($type,$startdate,$enddate,$summary,$repeating,$uid) = self::extractData($object);
$stmt = OC_DB::prepare( 'UPDATE *PREFIX*calendar_objects SET objecttype=?,startdate=?,enddate=?,repeating=?,summary=?,calendardata=?, lastmodified = ? WHERE id = ?' ); $stmt = OC_DB::prepare( 'UPDATE *PREFIX*calendar_objects SET objecttype=?,startdate=?,enddate=?,repeating=?,summary=?,calendardata=?, lastmodified = ? WHERE id = ?' );
@ -228,7 +228,7 @@ class OC_Calendar_Object{
// Child to use // Child to use
$children = 0; $children = 0;
$use = null; $use = null;
foreach($object->children as &$property){ foreach($object->children as $property){
if($property->name == 'VEVENT'){ if($property->name == 'VEVENT'){
$children++; $children++;
$thisone = true; $thisone = true;
@ -259,12 +259,12 @@ class OC_Calendar_Object{
// one VTODO per object) // one VTODO per object)
break; break;
} }
} unset($property); }
// find the data // find the data
if(!is_null($use)){ if(!is_null($use)){
$return[0] = $use->name; $return[0] = $use->name;
foreach($use->children as &$property){ foreach($use->children as $property){
if($property->name == 'DTSTART'){ if($property->name == 'DTSTART'){
$return[1] = self::getUTCforMDB($property->getDateTime()); $return[1] = self::getUTCforMDB($property->getDateTime());
} }
@ -280,7 +280,7 @@ class OC_Calendar_Object{
elseif($property->name == 'UID'){ elseif($property->name == 'UID'){
$return[5] = $property->value; $return[5] = $property->value;
} }
} unset($property); }
} }
// More than one child means reoccuring! // More than one child means reoccuring!
@ -302,21 +302,6 @@ class OC_Calendar_Object{
return date('Y-m-d H:i', $datetime->format('U') - $datetime->getOffset()); return date('Y-m-d H:i', $datetime->format('U') - $datetime->getOffset());
} }
/**
* @brief Parses the VObject
* @param string VObject as string
* @returns Sabre_VObject or null
*/
public static function parse($data){
try {
Sabre_VObject_Reader::$elementMap['LAST-MODIFIED'] = 'Sabre_VObject_Element_DateTime';
$calendar = Sabre_VObject_Reader::read($data);
return $calendar;
} catch (Exception $e) {
return null;
}
}
public static function getDTEndFromVEvent($vevent) public static function getDTEndFromVEvent($vevent)
{ {
if ($vevent->DTEND) { if ($vevent->DTEND) {
@ -458,22 +443,16 @@ class OC_Calendar_Object{
public static function createVCalendarFromRequest($request) public static function createVCalendarFromRequest($request)
{ {
$vcalendar = new Sabre_VObject_Component('VCALENDAR'); $vcalendar = new OC_VObject('VCALENDAR');
$vcalendar->add('PRODID', 'ownCloud Calendar'); $vcalendar->add('PRODID', 'ownCloud Calendar');
$vcalendar->add('VERSION', '2.0'); $vcalendar->add('VERSION', '2.0');
$now = new DateTime(); $vevent = new OC_VObject('VEVENT');
$vevent = new Sabre_VObject_Component('VEVENT');
$vcalendar->add($vevent); $vcalendar->add($vevent);
$created = new Sabre_VObject_Element_DateTime('CREATED'); $vevent->setDateTime('CREATED', 'now', Sabre_VObject_Element_DateTime::UTC);
$created->setDateTime($now, Sabre_VObject_Element_DateTime::UTC);
$vevent->add($created);
$uid = self::createUID();
$vevent->add('UID',$uid);
$vevent->setUID();
return self::updateVCalendarFromRequest($request, $vcalendar); return self::updateVCalendarFromRequest($request, $vcalendar);
} }
@ -481,7 +460,7 @@ class OC_Calendar_Object{
{ {
$title = $request["title"]; $title = $request["title"];
$location = $request["location"]; $location = $request["location"];
$categories = isset($request["categories"]) ? $request["categories"] : null; $categories = isset($request["categories"]) ? $request["categories"] : array();
$allday = isset($request["allday"]); $allday = isset($request["allday"]);
$from = $request["from"]; $from = $request["from"];
$to = $request["to"]; $to = $request["to"];
@ -509,55 +488,32 @@ class OC_Calendar_Object{
}*/ }*/
$repeat = "false"; $repeat = "false";
$now = new DateTime(); $vevent = $vcalendar->VEVENT;
$vevent = $vcalendar->VEVENT[0];
$last_modified = new Sabre_VObject_Element_DateTime('LAST-MODIFIED'); $vevent->setDateTime('LAST-MODIFIED', 'now', Sabre_VObject_Element_DateTime::UTC);
$last_modified->setDateTime($now, Sabre_VObject_Element_DateTime::UTC); $vevent->setDateTime('DTSTAMP', 'now', Sabre_VObject_Element_DateTime::UTC);
$vevent->__set('LAST-MODIFIED', $last_modified); $vevent->setString('SUMMARY', $title);
$dtstamp = new Sabre_VObject_Element_DateTime('DTSTAMP');
$dtstamp->setDateTime($now, Sabre_VObject_Element_DateTime::UTC);
$vevent->DTSTAMP = $dtstamp;
$vevent->SUMMARY = $title;
$dtstart = new Sabre_VObject_Element_DateTime('DTSTART'); $dtstart = new Sabre_VObject_Element_DateTime('DTSTART');
$dtend = new Sabre_VObject_Element_DateTime('DTEND'); $dtend = new Sabre_VObject_Element_DateTime('DTEND');
if($allday){ if($allday){
$start = new DateTime($from); $start = new DateTime($from);
$end = new DateTime($to.' +1 day'); $end = new DateTime($to.' +1 day');
$dtstart->setDateTime($start, Sabre_VObject_Element_DateTime::DATE); $vevent->setDateTime('DTSTART', $start, Sabre_VObject_Element_DateTime::DATE);
$dtend->setDateTime($end, Sabre_VObject_Element_DateTime::DATE); $vevent->setDateTime('DTEND', $end, Sabre_VObject_Element_DateTime::DATE);
}else{ }else{
$timezone = OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezone', date_default_timezone_get()); $timezone = OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezone', date_default_timezone_get());
$timezone = new DateTimeZone($timezone); $timezone = new DateTimeZone($timezone);
$start = new DateTime($from.' '.$fromtime, $timezone); $start = new DateTime($from.' '.$fromtime, $timezone);
$end = new DateTime($to.' '.$totime, $timezone); $end = new DateTime($to.' '.$totime, $timezone);
$dtstart->setDateTime($start, Sabre_VObject_Element_DateTime::LOCALTZ); $vevent->setDateTime('DTSTART', $start, Sabre_VObject_Element_DateTime::LOCALTZ);
$dtend->setDateTime($end, Sabre_VObject_Element_DateTime::LOCALTZ); $vevent->setDateTime('DTEND', $end, Sabre_VObject_Element_DateTime::LOCALTZ);
} }
$vevent->DTSTART = $dtstart;
$vevent->DTEND = $dtend;
unset($vevent->DURATION); unset($vevent->DURATION);
if($location != ""){ $vevent->setString('LOCATION', $location);
$vevent->LOCATION = $location; $vevent->setString('DESCRIPTION', $description);
}else{ $vevent->setString('CATEGORIES', join(',', $categories));
unset($vevent->LOCATION);
}
if($description != ""){
$vevent->DESCRIPTION = $description;
}else{
unset($vevent->DESCRIPTION);
}
if(!empty($categories)){
$vevent->CATEGORIES = join(',', $categories);
}else{
unset($vevent->CATEGORIES);
}
/*if($repeat == "true"){ /*if($repeat == "true"){
$vevent->RRULE = $repeat; $vevent->RRULE = $repeat;

View File

@ -23,26 +23,20 @@
// Init owncloud // Init owncloud
require_once('../../../lib/base.php'); require_once('../../../lib/base.php');
$aid = $_POST['id'];
$l10n = new OC_L10N('contacts');
// Check if we are a user // Check if we are a user
OC_JSON::checkLoggedIn(); OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts'); OC_JSON::checkAppEnabled('contacts');
$addressbook = OC_Contacts_Addressbook::find( $aid ); $aid = $_POST['id'];
if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){ $addressbook = OC_Contacts_App::getAddressbook( $aid );
OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your addressbook.')))); // Same here (as with the contact error). Could this error be improved?
exit();
}
$fn = $_POST['fn']; $fn = $_POST['fn'];
$values = $_POST['value']; $values = $_POST['value'];
$parameters = $_POST['parameters']; $parameters = $_POST['parameters'];
$vcard = new Sabre_VObject_Component('VCARD'); $vcard = new OC_VObject('VCARD');
$vcard->add(new Sabre_VObject_Property('FN',$fn)); $vcard->setUID();
$vcard->add(new Sabre_VObject_Property('UID',OC_Contacts_VCard::createUID())); $vcard->setString('FN',$fn);
// Data to add ... // Data to add ...
$add = array('TEL', 'EMAIL', 'ORG'); $add = array('TEL', 'EMAIL', 'ORG');
@ -64,20 +58,8 @@ foreach( $add as $propname){
else{ else{
$prop_parameters = array(); $prop_parameters = array();
} }
OC_Contacts_VCard::addVCardProperty($vcard, $propname, $value, $prop_parameters); $vcard->addProperty($propname, $value, $prop_parameters);
} }
$id = OC_Contacts_VCard::add($aid,$vcard->serialize()); $id = OC_Contacts_VCard::add($aid,$vcard->serialize());
$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR'); OC_Contacts_App::renderDetails($id, $vcard);
$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL');
$details = OC_Contacts_VCard::structureContact($vcard);
$name = $details['FN'][0]['value'];
$tmpl = new OC_Template('contacts','part.details');
$tmpl->assign('details',$details);
$tmpl->assign('id',$id);
$tmpl->assign('adr_types',$adr_types);
$tmpl->assign('phone_types',$phone_types);
$page = $tmpl->fetchPage();
OC_JSON::success(array('data' => array( 'id' => $id, 'name' => $name, 'page' => $page )));

View File

@ -23,40 +23,20 @@
// Init owncloud // Init owncloud
require_once('../../../lib/base.php'); require_once('../../../lib/base.php');
$id = $_POST['id'];
$l10n = new OC_L10N('contacts');
// Check if we are a user // Check if we are a user
OC_JSON::checkLoggedIn(); OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts'); OC_JSON::checkAppEnabled('contacts');
$card = OC_Contacts_VCard::find( $id ); $id = $_POST['id'];
if( $card === false ){ $vcard = OC_Contacts_App::getContactVCard( $id );
OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.'))));
exit();
}
$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] );
if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.'))));
exit();
}
$vcard = OC_Contacts_VCard::parse($card['carddata']);
// Check if the card is valid
if(is_null($vcard)){
OC_JSON::error(array('data' => array( 'message' => $l10n->t('vCard could not be read.'))));
exit();
}
$name = $_POST['name']; $name = $_POST['name'];
$value = $_POST['value']; $value = $_POST['value'];
$parameters = isset($_POST['parameteres'])?$_POST['parameters']:array(); $parameters = isset($_POST['parameters'])?$_POST['parameters']:array();
$property = OC_Contacts_VCard::addVCardProperty($vcard, $name, $value, $parameters); $property = $vcard->addProperty($name, $value, $parameters);
$line = count($vcard->children) - 1; $line = count($vcard->children) - 1;
$checksum = md5($property->serialize());
OC_Contacts_VCard::edit($id,$vcard->serialize()); OC_Contacts_VCard::edit($id,$vcard->serialize());

View File

@ -23,19 +23,12 @@
// Init owncloud // Init owncloud
require_once('../../../lib/base.php'); require_once('../../../lib/base.php');
$id = $_GET['id'];
$l10n = new OC_L10N('contacts');
// Check if we are a user // Check if we are a user
OC_JSON::checkLoggedIn(); OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts'); OC_JSON::checkAppEnabled('contacts');
$addressbook = OC_Contacts_Addressbook::find( $id ); $id = $_GET['id'];
if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){ $addressbook = OC_Contacts_App::getAddressbook( $id );
OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.'))));
exit();
}
OC_Contacts_Addressbook::delete($id); OC_Contacts_Addressbook::delete($id);
OC_JSON::success(array('data' => array( 'id' => $id ))); OC_JSON::success(array('data' => array( 'id' => $id )));

View File

@ -23,25 +23,12 @@
// Init owncloud // Init owncloud
require_once('../../../lib/base.php'); require_once('../../../lib/base.php');
$id = $_GET['id'];
$l10n = new OC_L10N('contacts');
// Check if we are a user // Check if we are a user
OC_JSON::checkLoggedIn(); OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts'); OC_JSON::checkAppEnabled('contacts');
$card = OC_Contacts_VCard::find( $id ); $id = $_GET['id'];
if( $card === false ){ $card = OC_Contacts_App::getContactObject( $id );
OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.'))));
exit();
}
$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] );
if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.'))));
exit();
}
OC_Contacts_VCard::delete($id); OC_Contacts_VCard::delete($id);
OC_JSON::success(array('data' => array( 'id' => $id ))); OC_JSON::success(array('data' => array( 'id' => $id )));

View File

@ -23,45 +23,15 @@
// Init owncloud // Init owncloud
require_once('../../../lib/base.php'); require_once('../../../lib/base.php');
$id = $_GET['id'];
$checksum = $_GET['checksum'];
$l10n = new OC_L10N('contacts');
// Check if we are a user // Check if we are a user
OC_JSON::checkLoggedIn(); OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts'); OC_JSON::checkAppEnabled('contacts');
$card = OC_Contacts_VCard::find( $id ); $id = $_GET['id'];
if( $card === false ){ $checksum = $_GET['checksum'];
OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.'))));
exit();
}
$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] ); $vcard = OC_Contacts_App::getContactVCard( $id );
if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){ $line = OC_Contacts_App::getPropertyLineByChecksum($vcard, $checksum);
OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.'))));
exit();
}
$vcard = OC_Contacts_VCard::parse($card['carddata']);
// Check if the card is valid
if(is_null($vcard)){
OC_JSON::error(array('data' => array( 'message' => $l10n->t('vCard could not be read.'))));
exit();
}
$line = null;
for($i=0;$i<count($vcard->children);$i++){
if(md5($vcard->children[$i]->serialize()) == $checksum ){
$line = $i;
}
}
if(is_null($line)){
OC_JSON::error(array('data' => array( 'message' => $l10n->t('Information about vCard is incorrect. Please reload the page.'))));
exit();
}
unset($vcard->children[$line]); unset($vcard->children[$line]);

View File

@ -23,50 +23,11 @@
// Init owncloud // Init owncloud
require_once('../../../lib/base.php'); require_once('../../../lib/base.php');
$id = $_GET['id'];
$l10n = new OC_L10N('contacts');
// Check if we are a user // Check if we are a user
OC_JSON::checkLoggedIn(); OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts'); OC_JSON::checkAppEnabled('contacts');
$id = $_GET['id'];
$vcard = OC_Contacts_App::getContactVCard( $id );
$card = OC_Contacts_VCard::find( $id ); OC_Contacts_App::renderDetails($id, $vcard);
if( $card === false ){
OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.'))));
exit();
}
$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] );
if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.'))));
exit();
}
$vcard = OC_Contacts_VCard::parse($card['carddata']);
// Check if the card is valid
if(is_null($vcard)){
OC_JSON::error(array('data' => array( 'message' => $l10n->t('vCard could not be read.'))));
exit();
}
$property_types = array(
'ADR' => $l10n->t('Address'),
'TEL' => $l10n->t('Telephone'),
'EMAIL' => $l10n->t('Email'),
'ORG' => $l10n->t('Organization'),
);
$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR');
$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL');
$details = OC_Contacts_VCard::structureContact($vcard);
$tmpl = new OC_Template('contacts','part.details');
$tmpl->assign('details',$details);
$tmpl->assign('id',$id);
$tmpl->assign('property_types',$property_types);
$tmpl->assign('adr_types',$adr_types);
$tmpl->assign('phone_types',$phone_types);
$page = $tmpl->fetchPage();
OC_JSON::success(array('data' => array( 'id' => $id, 'page' => $page )));

View File

@ -23,48 +23,20 @@
// Init owncloud // Init owncloud
require_once('../../../lib/base.php'); require_once('../../../lib/base.php');
$id = $_POST['id'];
$checksum = $_POST['checksum'];
$l10n = new OC_L10N('contacts');
// Check if we are a user // Check if we are a user
OC_JSON::checkLoggedIn(); OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts'); OC_JSON::checkAppEnabled('contacts');
$card = OC_Contacts_VCard::find( $id ); $id = $_POST['id'];
if( $card === false ){ $checksum = $_POST['checksum'];
OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.'))));
exit();
}
$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] ); $vcard = OC_Contacts_App::getContactVCard( $id );
if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){ $line = OC_Contacts_App::getPropertyLineByChecksum($vcard, $checksum);
OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.'))));
exit();
}
$vcard = OC_Contacts_VCard::parse($card['carddata']);
// Check if the card is valid
if(is_null($vcard)){
OC_JSON::error(array('data' => array( 'message' => $l10n->t('vCard could not be read.'))));
exit();
}
$line = null;
for($i=0;$i<count($vcard->children);$i++){
if(md5($vcard->children[$i]->serialize()) == $checksum ){
$line = $i;
}
}
if(is_null($line)){
OC_JSON::error(array('data' => array( 'message' => $l10n->t('Information about vCard is incorrect. Please reload the page.'))));
exit();
}
// Set the value // Set the value
$value = $_POST['value']; $value = $_POST['value'];
if(is_array($value)){ if(is_array($value)){
$value = OC_Contacts_VCard::escapeSemicolons($value); $value = OC_VObject::escapeSemicolons($value);
} }
$vcard->children[$line]->setValue($value); $vcard->children[$line]->setValue($value);
@ -104,8 +76,8 @@ $checksum = md5($vcard->children[$line]->serialize());
OC_Contacts_VCard::edit($id,$vcard->serialize()); OC_Contacts_VCard::edit($id,$vcard->serialize());
$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR'); $adr_types = OC_Contacts_App::getTypesOfProperty('ADR');
$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL'); $phone_types = OC_Contacts_App::getTypesOfProperty('TEL');
if ($vcard->children[$line]->name == 'FN'){ if ($vcard->children[$line]->name == 'FN'){
$tmpl = new OC_Template('contacts','part.property.FN'); $tmpl = new OC_Template('contacts','part.property.FN');

View File

@ -23,14 +23,12 @@
// Init owncloud // Init owncloud
require_once('../../../lib/base.php'); require_once('../../../lib/base.php');
$l10n = new OC_L10N('contacts');
// Check if we are a user // Check if we are a user
OC_JSON::checkLoggedIn(); OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts'); OC_JSON::checkAppEnabled('contacts');
$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR'); $adr_types = OC_Contacts_App::getTypesOfProperty('ADR');
$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL'); $phone_types = OC_Contacts_App::getTypesOfProperty('TEL');
$addressbooks = OC_Contacts_Addressbook::all(OC_USER::getUser()); $addressbooks = OC_Contacts_Addressbook::all(OC_USER::getUser());
$tmpl = new OC_Template('contacts','part.addcardform'); $tmpl = new OC_Template('contacts','part.addcardform');

View File

@ -23,24 +23,12 @@
// Init owncloud // Init owncloud
require_once('../../../lib/base.php'); require_once('../../../lib/base.php');
$id = $_GET['id'];
$l10n = new OC_L10N('contacts');
// Check if we are a user // Check if we are a user
OC_JSON::checkLoggedIn(); OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts'); OC_JSON::checkAppEnabled('contacts');
$card = OC_Contacts_VCard::find( $id ); $id = $_GET['id'];
if( $card === false ){ $card = OC_Contacts_App::getContactObject( $id );
OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.'))));
exit();
}
$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] );
if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.'))));
exit();
}
$tmpl = new OC_Template('contacts','part.addpropertyform'); $tmpl = new OC_Template('contacts','part.addpropertyform');
$tmpl->assign('id',$id); $tmpl->assign('id',$id);

View File

@ -23,46 +23,19 @@
// Init owncloud // Init owncloud
require_once('../../../lib/base.php'); require_once('../../../lib/base.php');
$id = $_GET['id'];
$checksum = $_GET['checksum'];
$l10n = new OC_L10N('contacts');
// Check if we are a user // Check if we are a user
OC_JSON::checkLoggedIn(); OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts'); OC_JSON::checkAppEnabled('contacts');
$card = OC_Contacts_VCard::find( $id ); $id = $_GET['id'];
if( $card === false ){ $checksum = $_GET['checksum'];
OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.'))));
exit();
}
$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] ); $vcard = OC_Contacts_App::getContactVCard( $id );
if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.'))));
exit();
}
$vcard = OC_Contacts_VCard::parse($card['carddata']); $line = OC_Contacts_App::getPropertyLineByChecksum($vcard, $checksum);
// Check if the card is valid
if(is_null($vcard)){
OC_JSON::error(array('data' => array( 'message' => $l10n->t('vCard could not be read.'))));
exit();
}
$line = null; $adr_types = OC_Contacts_App::getTypesOfProperty('ADR');
for($i=0;$i<count($vcard->children);$i++){ $phone_types = OC_Contacts_App::getTypesOfProperty('TEL');
if(md5($vcard->children[$i]->serialize()) == $checksum ){
$line = $i;
}
}
if(is_null($line)){
OC_JSON::error(array('data' => array( 'message' => $l10n->t('Information about vCard is incorrect. Please reload the page.'))));
exit();
}
$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR');
$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL');
$tmpl = new OC_Template('contacts','part.setpropertyform'); $tmpl = new OC_Template('contacts','part.setpropertyform');
$tmpl->assign('id',$id); $tmpl->assign('id',$id);

View File

@ -1,5 +1,6 @@
<?php <?php
OC::$CLASSPATH['OC_Contacts_App'] = 'apps/contacts/lib/app.php';
OC::$CLASSPATH['OC_Contacts_Addressbook'] = 'apps/contacts/lib/addressbook.php'; OC::$CLASSPATH['OC_Contacts_Addressbook'] = 'apps/contacts/lib/addressbook.php';
OC::$CLASSPATH['OC_Contacts_VCard'] = 'apps/contacts/lib/vcard.php'; OC::$CLASSPATH['OC_Contacts_VCard'] = 'apps/contacts/lib/vcard.php';
OC::$CLASSPATH['OC_Contacts_Hooks'] = 'apps/contacts/lib/hooks.php'; OC::$CLASSPATH['OC_Contacts_Hooks'] = 'apps/contacts/lib/hooks.php';

View File

@ -66,18 +66,16 @@ foreach( $openaddressbooks as $addressbook ){
} }
usort($contacts,'contacts_namesort'); usort($contacts,'contacts_namesort');
$details = array();
if( !is_null($id) || count($contacts)){ $details = array();
if( !is_null($id)/* || count($contacts)*/){
if(is_null($id)) $id = $contacts[0]['id']; if(is_null($id)) $id = $contacts[0]['id'];
$contact = OC_Contacts_VCard::find($id); $vcard = OC_Contacts_App::getContactVCard($id);
$vcard = OC_Contacts_VCard::parse($contact['carddata']);
$details = OC_Contacts_VCard::structureContact($vcard); $details = OC_Contacts_VCard::structureContact($vcard);
} }
$l10n = new OC_L10N('contacts'); $adr_types = OC_Contacts_App::getTypesOfProperty('ADR');
$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR'); $phone_types = OC_Contacts_App::getTypesOfProperty('TEL');
$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL');
// Process the template // Process the template
$tmpl = new OC_Template( 'contacts', 'index', 'user' ); $tmpl = new OC_Template( 'contacts', 'index', 'user' );

122
apps/contacts/lib/app.php Normal file
View File

@ -0,0 +1,122 @@
<?php
/**
* Copyright (c) 2011 Bart Visscher bartv@thisnet.nl
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
/**
* This class manages our app actions
*/
OC_Contacts_App::$l10n = new OC_L10N('contacts');
class OC_Contacts_App{
public static $l10n;
/**
* Render templates/part.details to json output
* @param int $id of contact
* @param Sabre_VObject_Component $vcard to render
*/
public static function renderDetails($id, $vcard){
$property_types = self::getAddPropertyOptions();
$adr_types = self::getTypesOfProperty('ADR');
$phone_types = self::getTypesOfProperty('TEL');
$details = OC_Contacts_VCard::structureContact($vcard);
$name = $details['FN'][0]['value'];
$tmpl = new OC_Template('contacts','part.details');
$tmpl->assign('details',$details);
$tmpl->assign('id',$id);
$tmpl->assign('property_types',$property_types);
$tmpl->assign('adr_types',$adr_types);
$tmpl->assign('phone_types',$phone_types);
$page = $tmpl->fetchPage();
OC_JSON::success(array('data' => array( 'id' => $id, 'name' => $name, 'page' => $page )));
}
public static function getAddressbook($id){
$addressbook = OC_Contacts_Addressbook::find( $id );
if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
OC_JSON::error(array('data' => array( 'message' => self::$l10n->t('This is not your addressbook.')))); // Same here (as with the contact error). Could this error be improved?
exit();
}
return $addressbook;
}
public static function getContactObject($id){
$card = OC_Contacts_VCard::find( $id );
if( $card === false ){
OC_JSON::error(array('data' => array( 'message' => self::$l10n->t('Contact could not be found.'))));
exit();
}
self::getAddressbook( $card['addressbookid'] );
return $card;
}
public static function getContactVCard($id){
$card = self::getContactObject( $id );
$vcard = OC_VObject::parse($card['carddata']);
// Check if the card is valid
if(is_null($vcard)){
OC_JSON::error(array('data' => array( 'message' => self::$l10n->t('vCard could not be read.'))));
exit();
}
return $vcard;
}
public static function getPropertyLineByChecksum($vcard, $checksum){
$line = null;
for($i=0;$i<count($vcard->children);$i++){
if(md5($vcard->children[$i]->serialize()) == $checksum ){
$line = $i;
}
}
if(is_null($line)){
OC_JSON::error(array('data' => array( 'message' => self::$l10n->t('Information about vCard is incorrect. Please reload the page.'))));
exit();
}
return $line;
}
/**
* @return array of vcard prop => label
*/
public static function getAddPropertyOptions(){
$l10n = self::$l10n;
return array(
'ADR' => $l10n->t('Address'),
'TEL' => $l10n->t('Telephone'),
'EMAIL' => $l10n->t('Email'),
'ORG' => $l10n->t('Organization'),
);
}
/**
* @return types for property $prop
*/
public static function getTypesOfProperty($prop){
$l = self::$l10n;
switch($prop){
case 'ADR':
return array(
'WORK' => $l->t('Work'),
'HOME' => $l->t('Home'),
);
case 'TEL':
return array(
'HOME' => $l->t('Home'),
'CELL' => $l->t('Mobile'),
'WORK' => $l->t('Work'),
'TEXT' => $l->t('Text'),
'VOICE' => $l->t('Voice'),
'FAX' => $l->t('Fax'),
'VIDEO' => $l->t('Video'),
'PAGER' => $l->t('Pager'),
);
}
}
}

View File

@ -91,31 +91,21 @@ class OC_Contacts_VCard{
*/ */
public static function add($id,$data){ public static function add($id,$data){
$fn = null; $fn = null;
$uri = null;
$card = self::parse($data); $card = OC_VObject::parse($data);
if(!is_null($card)){ if(!is_null($card)){
// VCARD must have a version $fn = $card->getAsString('FN');
$hasversion = false; $uid = $card->getAsString('UID');
foreach($card->children as $property){ if(is_null($uid)){
if($property->name == 'FN'){ $card->setUID();
$fn = $property->value; $uid = $card->getAsString('UID');
}
elseif($property->name == 'VERSION'){
$hasversion = true;
}
elseif(is_null($uri) && $property->name == 'UID' ){
$uri = $property->value.'.vcf';
}
}
if(is_null($uri)){
$uid = self::createUID();
$uri = $uid.'.vcf';
$card->add(new Sabre_VObject_Property('UID',$uid));
$data = $card->serialize(); $data = $card->serialize();
}; };
$uri = $uid.'.vcf';
// VCARD must have a version
$version = $card->getAsString('VERSION');
// Add version if needed // Add version if needed
if(!$hasversion){ if(is_null($version)){
$card->add(new Sabre_VObject_Property('VERSION','3.0')); $card->add(new Sabre_VObject_Property('VERSION','3.0'));
$data = $card->serialize(); $data = $card->serialize();
} }
@ -143,7 +133,7 @@ class OC_Contacts_VCard{
*/ */
public static function addFromDAVData($id,$uri,$data){ public static function addFromDAVData($id,$uri,$data){
$fn = null; $fn = null;
$card = self::parse($data); $card = OC_VObject::parse($data);
if(!is_null($card)){ if(!is_null($card)){
foreach($card->children as $property){ foreach($card->children as $property){
if($property->name == 'FN'){ if($property->name == 'FN'){
@ -170,7 +160,7 @@ class OC_Contacts_VCard{
$oldcard = self::find($id); $oldcard = self::find($id);
$fn = null; $fn = null;
$card = self::parse($data); $card = OC_VObject::parse($data);
if(!is_null($card)){ if(!is_null($card)){
foreach($card->children as $property){ foreach($card->children as $property){
if($property->name == 'FN'){ if($property->name == 'FN'){
@ -198,7 +188,7 @@ class OC_Contacts_VCard{
$oldcard = self::findWhereDAVDataIs($aid,$uri); $oldcard = self::findWhereDAVDataIs($aid,$uri);
$fn = null; $fn = null;
$card = self::parse($data); $card = OC_VObject::parse($data);
if(!is_null($card)){ if(!is_null($card)){
foreach($card->children as $property){ foreach($card->children as $property){
if($property->name == 'FN'){ if($property->name == 'FN'){
@ -248,67 +238,6 @@ class OC_Contacts_VCard{
return true; return true;
} }
/**
* @brief Escapes semicolons
* @param string $value
* @return string
*/
public static function escapeSemicolons($value){
foreach($value as &$i ){
$i = implode("\\\\;", explode(';', $i));
}
return implode(';',$value);
}
/**
* @brief Creates an array out of a multivalue property
* @param string $value
* @return array
*/
public static function unescapeSemicolons($value){
$array = explode(';',$value);
for($i=0;$i<count($array);$i++){
if(substr($array[$i],-2,2)=="\\\\"){
if(isset($array[$i+1])){
$array[$i] = substr($array[$i],0,count($array[$i])-2).';'.$array[$i+1];
unset($array[$i+1]);
}
else{
$array[$i] = substr($array[$i],0,count($array[$i])-2).';';
}
$i = $i - 1;
}
}
return $array;
}
/**
* @brief Add property to vcard object
* @param object $vcard
* @param object $name of property
* @param object $value of property
* @param object $paramerters of property
*/
public static function addVCardProperty($vcard, $name, $value, $parameters=array()){
if(is_array($value)){
$value = OC_Contacts_VCard::escapeSemicolons($value);
}
$property = new Sabre_VObject_Property( $name, $value );
$parameternames = array_keys($parameters);
foreach($parameternames as $i){
$values = $parameters[$i];
if (!is_array($values)){
$values = array($values);
}
foreach($values as $value){
$property->add($i, $value);
}
}
$vcard->add($property);
return $property;
}
/** /**
* @brief Data structure of vCard * @brief Data structure of vCard
* @param object $property * @param object $property
@ -345,7 +274,7 @@ class OC_Contacts_VCard{
$value = $property->value; $value = $property->value;
$value = htmlspecialchars($value); $value = htmlspecialchars($value);
if($property->name == 'ADR' || $property->name == 'N'){ if($property->name == 'ADR' || $property->name == 'N'){
$value = self::unescapeSemicolons($value); $value = OC_VObject::unescapeSemicolons($value);
} }
$temp = array( $temp = array(
'name' => $property->name, 'name' => $property->name,
@ -372,40 +301,4 @@ class OC_Contacts_VCard{
} }
return $temp; return $temp;
} }
/**
* @brief Parses a vcard file
* @param string vCard
* @return Sabre_VObject or null
*
* Will retun the vobject if sabre DAV is able to parse the file.
*/
public static function parse($data){
try {
$card = Sabre_VObject_Reader::read($data);
return $card;
} catch (Exception $e) {
return null;
}
}
public static function getTypesOfProperty($l, $prop){
switch($prop){
case 'ADR':
return array(
'WORK' => $l->t('Work'),
'HOME' => $l->t('Home'),
);
case 'TEL':
return array(
'HOME' => $l->t('Home'),
'CELL' => $l->t('Mobile'),
'WORK' => $l->t('Work'),
'TEXT' => $l->t('Text'),
'VOICE' => $l->t('Voice'),
'FAX' => $l->t('Fax'),
'VIDEO' => $l->t('Video'),
'PAGER' => $l->t('Pager'),
);
}
}
} }

View File

@ -41,7 +41,7 @@ if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
exit(); exit();
} }
$content = OC_Contacts_VCard::parse($card['carddata']); $content = OC_VObject::parse($card['carddata']);
// invalid vcard // invalid vcard
if( is_null($content)){ if( is_null($content)){

View File

@ -15,5 +15,12 @@ OC_Util::addStyle('contacts','formtastic');
</ul> </ul>
</div> </div>
<div id="rightcontent" class="rightcontent" data-id="<?php echo $_['id']; ?>"> <div id="rightcontent" class="rightcontent" data-id="<?php echo $_['id']; ?>">
<?php echo $this->inc("part.addcardform"); ?> <?php
if ($_['id']){
echo $this->inc("part.details");
}
else{
echo $this->inc("part.addcardform");
}
?>
</div> </div>

View File

@ -20,7 +20,7 @@
<span style="display:none;" data-use="delete"><img class="svg action" src="<?php echo image_path('', 'actions/delete.svg'); ?>" /></span> <span style="display:none;" data-use="delete"><img class="svg action" src="<?php echo image_path('', 'actions/delete.svg'); ?>" /></span>
</p> </p>
<?php elseif($_['property']['name'] == 'TEL'): ?> <?php elseif($_['property']['name'] == 'TEL'): ?>
<p class="contacts_property_name"><?php echo $l->t('Phone'); ?></p> <p class="contacts_property_name"><?php echo $_['property']['parameters']['PREF'] ? $l->t('Preferred').' ' : '' ?><?php echo $l->t('Phone'); ?></p>
<p class="contacts_property_data"> <p class="contacts_property_data">
<?php echo $_['property']['value']; ?> <?php echo $_['property']['value']; ?>
<?php if(isset($_['property']['parameters']['TYPE']) && !empty($_['property']['parameters']['TYPE'])): ?> <?php if(isset($_['property']['parameters']['TYPE']) && !empty($_['property']['parameters']['TYPE'])): ?>

View File

@ -35,7 +35,7 @@
left: 0; left: 0;
width: 40px; width: 40px;
height: 480px; height: 480px;
background-image: url('../img/fancybox/fancybox.png'); background-image: url('../img/fancybox.png');
} }
#fancybox-overlay { #fancybox-overlay {
@ -282,7 +282,7 @@
#fancybox-title-over { #fancybox-title-over {
padding: 10px; padding: 10px;
background-image: url('../img/fancybox/fancy_title_over.png'); background-image: url('../img/fancy_title_over.png');
display: block; display: block;
} }
@ -306,7 +306,7 @@
#fancybox-title-float-left { #fancybox-title-float-left {
padding: 0 0 0 15px; padding: 0 0 0 15px;
background: url('../img/fancybox/fancybox.png') -40px -90px no-repeat; background: url('../img/fancybox.png') -40px -90px no-repeat;
} }
#fancybox-title-float-main { #fancybox-title-float-main {
@ -314,25 +314,25 @@
line-height: 29px; line-height: 29px;
font-weight: bold; font-weight: bold;
padding: 0 0 3px 0; padding: 0 0 3px 0;
background: url('../img/fancybox/fancybox-x.png') 0px -40px; background: url('../img/fancybox-x.png') 0px -40px;
} }
#fancybox-title-float-right { #fancybox-title-float-right {
padding: 0 0 0 15px; padding: 0 0 0 15px;
background: url('../img/fancybox/fancybox.png') -55px -90px no-repeat; background: url('../img/fancybox.png') -55px -90px no-repeat;
} }
/* IE6 */ /* IE6 */
.fancybox-ie6 #fancybox-close { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_close.png', sizingMethod='scale'); } .fancybox-ie6 #fancybox-close { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/fancy_close.png', sizingMethod='scale'); }
.fancybox-ie6 #fancybox-left-ico { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_nav_left.png', sizingMethod='scale'); } .fancybox-ie6 #fancybox-left-ico { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/fancy_nav_left.png', sizingMethod='scale'); }
.fancybox-ie6 #fancybox-right-ico { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_nav_right.png', sizingMethod='scale'); } .fancybox-ie6 #fancybox-right-ico { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/fancy_nav_right.png', sizingMethod='scale'); }
.fancybox-ie6 #fancybox-title-over { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_title_over.png', sizingMethod='scale'); zoom: 1; } .fancybox-ie6 #fancybox-title-over { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/fancy_title_over.png', sizingMethod='scale'); zoom: 1; }
.fancybox-ie6 #fancybox-title-float-left { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_title_left.png', sizingMethod='scale'); } .fancybox-ie6 #fancybox-title-float-left { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/fancy_title_left.png', sizingMethod='scale'); }
.fancybox-ie6 #fancybox-title-float-main { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_title_main.png', sizingMethod='scale'); } .fancybox-ie6 #fancybox-title-float-main { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/fancy_title_main.png', sizingMethod='scale'); }
.fancybox-ie6 #fancybox-title-float-right { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_title_right.png', sizingMethod='scale'); } .fancybox-ie6 #fancybox-title-float-right { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/fancy_title_right.png', sizingMethod='scale'); }
.fancybox-ie6 #fancybox-bg-w, .fancybox-ie6 #fancybox-bg-e, .fancybox-ie6 #fancybox-left, .fancybox-ie6 #fancybox-right, #fancybox-hide-sel-frame { .fancybox-ie6 #fancybox-bg-w, .fancybox-ie6 #fancybox-bg-e, .fancybox-ie6 #fancybox-left, .fancybox-ie6 #fancybox-right, #fancybox-hide-sel-frame {
height: expression(this.parentNode.clientHeight + "px"); height: expression(this.parentNode.clientHeight + "px");
@ -343,17 +343,17 @@
top: expression( (-20 + (document.documentElement.clientHeight ? document.documentElement.clientHeight/2 : document.body.clientHeight/2 ) + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop )) + 'px'); top: expression( (-20 + (document.documentElement.clientHeight ? document.documentElement.clientHeight/2 : document.body.clientHeight/2 ) + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop )) + 'px');
} }
#fancybox-loading.fancybox-ie6 div { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_loading.png', sizingMethod='scale'); } #fancybox-loading.fancybox-ie6 div { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/fancy_loading.png', sizingMethod='scale'); }
/* IE6, IE7, IE8 */ /* IE6, IE7, IE8 */
.fancybox-ie .fancybox-bg { background: transparent !important; } .fancybox-ie .fancybox-bg { background: transparent !important; }
.fancybox-ie #fancybox-bg-n { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_n.png', sizingMethod='scale'); } .fancybox-ie #fancybox-bg-n { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/fancy_shadow_n.png', sizingMethod='scale'); }
.fancybox-ie #fancybox-bg-ne { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_ne.png', sizingMethod='scale'); } .fancybox-ie #fancybox-bg-ne { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/fancy_shadow_ne.png', sizingMethod='scale'); }
.fancybox-ie #fancybox-bg-e { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_e.png', sizingMethod='scale'); } .fancybox-ie #fancybox-bg-e { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/fancy_shadow_e.png', sizingMethod='scale'); }
.fancybox-ie #fancybox-bg-se { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_se.png', sizingMethod='scale'); } .fancybox-ie #fancybox-bg-se { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/fancy_shadow_se.png', sizingMethod='scale'); }
.fancybox-ie #fancybox-bg-s { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_s.png', sizingMethod='scale'); } .fancybox-ie #fancybox-bg-s { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/fancy_shadow_s.png', sizingMethod='scale'); }
.fancybox-ie #fancybox-bg-sw { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_sw.png', sizingMethod='scale'); } .fancybox-ie #fancybox-bg-sw { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/fancy_shadow_sw.png', sizingMethod='scale'); }
.fancybox-ie #fancybox-bg-w { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_w.png', sizingMethod='scale'); } .fancybox-ie #fancybox-bg-w { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/fancy_shadow_w.png', sizingMethod='scale'); }
.fancybox-ie #fancybox-bg-nw { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_nw.png', sizingMethod='scale'); } .fancybox-ie #fancybox-bg-nw { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/fancy_shadow_nw.png', sizingMethod='scale'); }

View File

@ -3,8 +3,7 @@ require_once('../../../lib/base.php');
OC_JSON::checkLoggedIn(); OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('gallery'); OC_JSON::checkAppEnabled('gallery');
$stmt = OC_DB::prepare('INSERT INTO *PREFIX*gallery_albums ("uid_owner", "album_name") VALUES ("'.OC_User::getUser().'", "'.$_GET['album_name'].'")'); OC_Gallery_Album::create(OC_User::getUser(), $_GET['album_name']);
$stmt->execute(array());
OC_JSON::success(array('name' => $_GET['album_name'])); OC_JSON::success(array('name' => $_GET['album_name']));

View File

@ -4,13 +4,11 @@ OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('gallery'); OC_JSON::checkAppEnabled('gallery');
$a = array(); $a = array();
$stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_albums WHERE `uid_owner` = ?'); $result = OC_Gallery_Album::find(OC_User::getUser());
$result = $stmt->execute(array(OC_User::getUser()));
while ($r = $result->fetchRow()) { while ($r = $result->fetchRow()) {
$album_name = $r['album_name']; $album_name = $r['album_name'];
$stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_photos WHERE `album_id` = ?'); $tmp_res = OC_Gallery_Photo::find($r['album_id']);
$tmp_res = $stmt->execute(array($r['album_id']));
$a[] = array('name' => $album_name, 'numOfItems' => min($tmp_res->numRows(), 10)); $a[] = array('name' => $album_name, 'numOfItems' => min($tmp_res->numRows(), 10));
} }

View File

@ -18,7 +18,7 @@ function CroppedThumbnail($imgSrc,$thumbnail_width,$thumbnail_height, $tgtImg, $
default: default:
exit(); exit();
} }
if(!$myImage) exit(); if(!$myImage) exit();
$ratio_orig = $width_orig/$height_orig; $ratio_orig = $width_orig/$height_orig;
if ($thumbnail_width/$thumbnail_height > $ratio_orig) { if ($thumbnail_width/$thumbnail_height > $ratio_orig) {
@ -44,15 +44,19 @@ function CroppedThumbnail($imgSrc,$thumbnail_width,$thumbnail_height, $tgtImg, $
$box_size = 200; $box_size = 200;
$album_name= $_GET['album_name']; $album_name= $_GET['album_name'];
$stmt = OC_DB::prepare('SELECT `file_path` FROM *PREFIX*gallery_photos,*PREFIX*gallery_albums WHERE *PREFIX*gallery_albums.`uid_owner` = ? AND `album_name` = ? AND *PREFIX*gallery_photos.`album_id` = *PREFIX*gallery_albums.`album_id`'); $result = OC_Gallery_Photo::findForAlbum(OC_User::getUser(), $album_name);
$result = $stmt->execute(array(OC_User::getUser(), $album_name));
$numOfItems = min($result->numRows(),10); $numOfItems = min($result->numRows(),10);
$targetImg = imagecreatetruecolor($numOfItems*$box_size, $box_size); if ($numOfItems){
$targetImg = imagecreatetruecolor($numOfItems*$box_size, $box_size);
}
else{
$targetImg = imagecreatetruecolor($box_size, $box_size);
}
$counter = 0; $counter = 0;
while (($i = $result->fetchRow()) && $counter < $numOfItems) { while (($i = $result->fetchRow()) && $counter < $numOfItems) {
$imagePath = OC::$CONFIG_DATADIRECTORY . $i['file_path']; $imagePath = OC_Filesystem::getLocalFile($i['file_path']);
if(file_exists($imagePath)) if(file_exists($imagePath))
{ {
CroppedThumbnail($imagePath, $box_size, $box_size, $targetImg, $counter*$box_size); CroppedThumbnail($imagePath, $box_size, $box_size, $targetImg, $counter*$box_size);
@ -65,7 +69,7 @@ header('Content-Type: image/png');
$offset = 3600 * 24; $offset = 3600 * 24;
// calc the string in GMT not localtime and add the offset // calc the string in GMT not localtime and add the offset
header("Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT"); header("Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT");
header('Cache-Control: max-age=3600, must-revalidate'); header('Cache-Control: max-age='.$offset.', must-revalidate');
header('Pragma: public'); header('Pragma: public');
imagepng($targetImg); imagepng($targetImg);

View File

@ -3,9 +3,8 @@
require_once('../../../lib/base.php'); require_once('../../../lib/base.php');
OC_JSON::checkLoggedIn(); OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('gallery'); OC_JSON::checkAppEnabled('gallery');
require_once('../lib_scanner.php');
OC_JSON::success(array('albums' => OC_GALLERY_SCANNER::scan(''))); OC_JSON::success(array('albums' => OC_Gallery_Scanner::scan('')));
//OC_JSON::success(array('albums' => array(array('name' => 'test', 'imagesCount' => 1, 'images' => array('dupa'))))); //OC_JSON::success(array('albums' => array(array('name' => 'test', 'imagesCount' => 1, 'images' => array('dupa')))));
?> ?>

View File

@ -49,12 +49,19 @@ function CroppedThumbnail($imgSrc,$thumbnail_width,$thumbnail_height) { //$imgSr
$box_size = 200; $box_size = 200;
$img = $_GET['img']; $img = $_GET['img'];
$tmp = OC::$CONFIG_DATADIRECTORY . $img; $imagePath = OC_Filesystem::getLocalFile($img);
if(file_exists($tmp)) if(file_exists($imagePath))
{ {
header('Content-Type: image/png'); $image = CroppedThumbnail($imagePath, $box_size, $box_size);
$image = CroppedThumbnail($tmp, $box_size, $box_size);
header('Content-Type: image/png');
$offset = 3600 * 24;
// calc the string in GMT not localtime and add the offset
header("Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT");
header('Cache-Control: max-age='.$offset.', must-revalidate');
header('Pragma: public');
imagepng($image); imagepng($image);
imagedestroy($image); imagedestroy($image);
} }

View File

@ -1,4 +1,8 @@
<?php <?php
OC::$CLASSPATH['OC_Gallery_Album'] = 'apps/gallery/lib/album.php';
OC::$CLASSPATH['OC_Gallery_Photo'] = 'apps/gallery/lib/photo.php';
OC::$CLASSPATH['OC_Gallery_Scanner'] = 'apps/gallery/lib/scanner.php';
OC_App::register(array( OC_App::register(array(
'order' => 20, 'order' => 20,
'id' => 'gallery', 'id' => 'gallery',

View File

@ -1,13 +1,22 @@
div#gallery_list { div#gallery_list {
margin: 90pt 20pt; margin: 90pt 20pt;
} }
div#gallery_list.leftcontent {
padding-top: 15px;
margin: 0;
text-align: center;
}
div#gallery_album_box { div#gallery_album_box {
width: 200px; width: 200px;
text-align: center; text-align: center;
border: 0; border: 0;
float: left; display: inline-block;
margin: 5pt; margin: 5pt;
vertical-align: top;
}
.leftcontent div#gallery_album_box {
margin: 5px;
} }
div#gallery_album_box h1 { div#gallery_album_box h1 {
@ -21,3 +30,6 @@ div#gallery_album_cover {
border: solid 1px black; border: solid 1px black;
} }
#gallery_images {
padding:10px 5px;
}

View File

@ -7,8 +7,7 @@ OC_App::setActiveNavigationEntry( 'gallery_index' );
if (!isset($_GET['view'])) { if (!isset($_GET['view'])) {
$stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_albums WHERE uid_owner = ?'); $result = OC_Gallery_Album::find(OC_User::getUser());
$result = $stmt->execute(array(OC_User::getUser()));
$r = array(); $r = array();
while ($row = $result->fetchRow()) while ($row = $result->fetchRow())
@ -18,9 +17,7 @@ if (!isset($_GET['view'])) {
$tmpl->assign('r', $r); $tmpl->assign('r', $r);
$tmpl->printPage(); $tmpl->printPage();
} else { } else {
$stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_photos, *PREFIX*gallery_albums WHERE uid_owner = ? AND album_name = ? AND *PREFIX*gallery_albums.album_id = *PREFIX*gallery_photos.album_id'); $result = OC_Gallery_Photo::findForAlbum(OC_User::getUser(), $_GET['view']);
$result = $stmt->execute(array(OC_User::getUser(), $_GET['view']));
$photos = array(); $photos = array();
while ($p = $result->fetchRow()) while ($p = $result->fetchRow())

View File

@ -0,0 +1,18 @@
<?php
class OC_Gallery_Album{
public static function create($owner, $name){
$stmt = OC_DB::prepare('INSERT INTO *PREFIX*gallery_albums (uid_owner, album_name) VALUES (?, ?)');
$stmt->execute(array($owner, $name));
}
public static function find($owner, $name=null){
$sql = 'SELECT * FROM *PREFIX*gallery_albums WHERE uid_owner = ?';
$args = array($owner);
if (!is_null($name)){
$sql .= ' AND album_name = ?';
$args[] = $name;
}
$stmt = OC_DB::prepare($sql);
return $stmt->execute($args);
}
}

View File

@ -0,0 +1,28 @@
<?php
class OC_Gallery_Photo{
public static function create($albumId, $img){
$stmt = OC_DB::prepare('INSERT INTO *PREFIX*gallery_photos (album_id, file_path) VALUES (?, ?)');
$stmt->execute(array($albumId, $img));
}
public static function find($albumId, $img=null){
$sql = 'SELECT * FROM *PREFIX*gallery_photos WHERE album_id = ?';
$args = array($albumId);
$args = array($albumId);
if (!is_null($img)){
$sql .= ' AND file_path = ?';
$args[] = $img;
}
$stmt = OC_DB::prepare($sql);
return $stmt->execute($args);
}
public static function findForAlbum($owner, $album_name){
$stmt = OC_DB::prepare('SELECT *'
.' FROM *PREFIX*gallery_photos photos,'
.' *PREFIX*gallery_albums albums'
.' WHERE albums.uid_owner = ?'
.' AND albums.album_name = ?'
.' AND photos.album_id = albums.album_id');
return $stmt->execute(array($owner, $album_name));
}
}

View File

@ -1,9 +1,6 @@
<?php <?php
require_once('base.php'); // base lib class OC_Gallery_Scanner {
class OC_GALLERY_SCANNER {
public static function scan($root) { public static function scan($root) {
$albums = array(); $albums = array();
self::scanDir($root, $albums); self::scanDir($root, $albums);
@ -24,26 +21,21 @@ class OC_GALLERY_SCANNER {
} elseif (self::isPhoto($path.'/'.$filename)) { } elseif (self::isPhoto($path.'/'.$filename)) {
$current_album['images'][] = $filepath; $current_album['images'][] = $filepath;
} }
} }
} }
$current_album['imagesCount'] = count($current_album['images']); $current_album['imagesCount'] = count($current_album['images']);
$albums[] = $current_album; $albums[] = $current_album;
$stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_albums WHERE `uid_owner` = ? AND `album_name` = ?'); $result = OC_Gallery_Album::find(OC_User::getUser(), $current_album['name']);
$result = $stmt->execute(array(OC_User::getUser(), $current_album['name']));
if ($result->numRows() == 0 && count($current_album['images'])) { if ($result->numRows() == 0 && count($current_album['images'])) {
$stmt = OC_DB::prepare('INSERT INTO *PREFIX*gallery_albums (`uid_owner`, `album_name`) VALUES (?, ?)'); OC_Gallery_Album::create(OC_User::getUser(), $current_album['name']);
$stmt->execute(array(OC_User::getUser(), $current_album['name'])); $result = OC_Gallery_Album::find(OC_User::getUser(), $current_album['name']);
} }
$stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_albums WHERE `uid_owner` = ? AND `album_name` = ?');
$result = $stmt->execute(array(OC_User::getUser(), $current_album['name']));
$albumId = $result->fetchRow(); $albumId = $result->fetchRow();
$albumId = $albumId['album_id']; $albumId = $albumId['album_id'];
foreach ($current_album['images'] as $img) { foreach ($current_album['images'] as $img) {
$stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_photos WHERE `album_id` = ? AND `file_path` = ?'); $result = OC_Gallery_Photo::find($albumId, $img);
$result = $stmt->execute(array($albumId, $img));
if ($result->numRows() == 0) { if ($result->numRows() == 0) {
$stmt = OC_DB::prepare('INSERT INTO *PREFIX*gallery_photos (`album_id`, `file_path`) VALUES (?, ?)'); OC_Gallery_Photo::create($albumId, $img);
$stmt->execute(array($albumId, $img));
} }
} }
} }

View File

@ -1,5 +1,6 @@
<?php <?php
OC_Util::addStyle('gallery', 'styles'); OC_Util::addStyle('gallery', 'styles');
OC_Util::addScript('gallery', 'albums');
OC_Util::addScript('gallery', 'album_cover'); OC_Util::addScript('gallery', 'album_cover');
OC_Util::addScript('files_imageviewer', 'jquery.mousewheel-3.0.4.pack'); OC_Util::addScript('files_imageviewer', 'jquery.mousewheel-3.0.4.pack');
OC_Util::addScript('files_imageviewer', 'jquery.fancybox-1.3.4.pack'); OC_Util::addScript('files_imageviewer', 'jquery.fancybox-1.3.4.pack');
@ -16,13 +17,16 @@ OC_Util::addStyle( 'files_imageviewer', 'jquery.fancybox-1.3.4' );
<div id="controls"> <div id="controls">
<a href="?"><input type="button" value="Back" /></a><br/> <a href="?"><input type="button" value="Back" /></a><br/>
</div> </div>
<div id="gallery_list">
<div id="gallery_list" class="leftcontent">
</div>
<div id="gallery_images" class="rightcontent">
<?php <?php
foreach ($_['photos'] as $a) { foreach ($_['photos'] as $a) {
?> ?>
<a rel="images" href="../../files/ajax/download.php?files=<?php echo $a; ?>"><img src="ajax/thumbnail.php?img=<?php echo $a ?>"></a> <a rel="images" href="../../files/download.php?file=<?php echo urlencode($a); ?>"><img src="ajax/thumbnail.php?img=<?php echo urlencode($a) ?>"></a>
<?php <?php
} }
?> ?>
</div> </div>

View File

@ -52,14 +52,11 @@ if(isset($_SERVER['HTTP_ORIGIN'])) {
$path = substr($_SERVER["REQUEST_URI"], strlen($_SERVER["SCRIPT_NAME"])); $path = substr($_SERVER["REQUEST_URI"], strlen($_SERVER["SCRIPT_NAME"]));
$pathParts = explode('/', $path); $pathParts = explode('/', $path);
// for webdav: // for webdav:
// 0/ 1 / 2 / 3 / 4 / 5 / 6 / 7 // 0/ 1 / 2 / 3...
// /$ownCloudUser/remoteStorage/webdav/$userHost/$userName/$dataScope/$key // /$ownCloudUser/remoteStorage/$category/
// for oauth:
// 0/ 1 / 2 / 3 / 4
// /$ownCloudUser/remoteStorage/oauth/auth
if(count($pathParts) >= 8 && $pathParts[0] == '' && $pathParts[2] == 'remoteStorage' && $pathParts[3] == 'webdav') { if(count($pathParts) >= 3 && $pathParts[0] == '') {
list($dummy0, $ownCloudUser, $dummy2, $dummy3, $userHost, $userName, $dataScope) = $pathParts; list($dummy, $ownCloudUser, $dummy2, $category) = $pathParts;
OC_Util::setupFS($ownCloudUser); OC_Util::setupFS($ownCloudUser);
@ -68,10 +65,10 @@ if(count($pathParts) >= 8 && $pathParts[0] == '' && $pathParts[2] == 'remoteStor
$server = new Sabre_DAV_Server($publicDir); $server = new Sabre_DAV_Server($publicDir);
// Path to our script // Path to our script
$server->setBaseUri(OC::$WEBROOT."/apps/remoteStorage/compat.php/$ownCloudUser"); $server->setBaseUri(OC::$WEBROOT."/apps/remoteStorage/WebDAV.php/$ownCloudUser");
// Auth backend // Auth backend
$authBackend = new OC_Connector_Sabre_Auth_ro_oauth(OC_remoteStorage::getValidTokens($ownCloudUser, $userName.'@'.$userHost, $dataScope)); $authBackend = new OC_Connector_Sabre_Auth_ro_oauth(OC_remoteStorage::getValidTokens($ownCloudUser, $category));
$authPlugin = new Sabre_DAV_Auth_Plugin($authBackend,'ownCloud');//should use $validTokens here $authPlugin = new Sabre_DAV_Auth_Plugin($authBackend,'ownCloud');//should use $validTokens here
$server->addPlugin($authPlugin); $server->addPlugin($authPlugin);
@ -83,41 +80,6 @@ if(count($pathParts) >= 8 && $pathParts[0] == '' && $pathParts[2] == 'remoteStor
// And off we go! // And off we go!
$server->exec(); $server->exec();
} else if(count($pathParts) >= 4 && $pathParts[0] == '' && $pathParts[2] == 'remoteStorage' && $pathParts[3] == 'oauth2' && $pathParts[4] = 'auth') {
if(isset($_POST['allow'])) {
//TODO: input checking. these explodes may fail to produces the desired arrays:
$ownCloudUser = $pathParts[1];
foreach($_GET as $k => $v) {
if($k=='user_address'){
$userAddress=$v;
} else if($k=='redirect_uri'){
$appUrl=$v;
} else if($k=='scope'){
$dataScope=$v;
}
}
if(OC_User::getUser() == $ownCloudUser) {
//TODO: check if this can be faked by editing the cookie in firebug!
$token=OC_remoteStorage::createDataScope($appUrl, $userAddress, $dataScope);
header('Location: '.$_GET['redirect_uri'].'#access_token='.$token.'&token_type=remoteStorage');
} else {
if((isset($_SERVER['HTTPS'])) && ($_SERVER['HTTPS'])) {
$url = "https://";
} else {
$url = "http://";
}
$url .= $_SERVER['SERVER_NAME'];
$url .= substr($_SERVER['SCRIPT_NAME'], 0, -strlen('apps/remoteStorage/compat.php'));
die('Please '
.'<input type="submit" onclick="'
."window.open('$url','Close me!','height=600,width=300');"
.'" value="log in">'
.', close the pop-up, and '
.'<form method="POST"><input name="allow" type="submit" value="Try again"></form>');
}
} else {
echo '<form method="POST"><input name="allow" type="submit" value="Allow this web app to store stuff on your owncloud."></form>';
}
} else { } else {
die('not webdav and not oauth. dont know what to do '.var_export($pathParts, true)); die('not the right address format '.var_export($pathParts, true));
} }

View File

@ -29,14 +29,7 @@
<length>64</length> <length>64</length>
</field> </field>
<field> <field>
<name>dataScope</name> <name>category</name>
<type>text</type>
<default></default>
<notnull>true</notnull>
<length>64</length>
</field>
<field>
<name>userAddress</name>
<type>text</type> <type>text</type>
<default></default> <default></default>
<notnull>true</notnull> <notnull>true</notnull>

View File

@ -3,7 +3,7 @@
<id>remoteStorage</id> <id>remoteStorage</id>
<name>remoteStorage compatibility</name> <name>remoteStorage compatibility</name>
<description>Enables your users to use ownCloud as their remote storage for unhosted applications.</description> <description>Enables your users to use ownCloud as their remote storage for unhosted applications.</description>
<version>0.1</version> <version>0.2</version>
<licence>AGPL</licence> <licence>AGPL</licence>
<author>Michiel de Jong</author> <author>Michiel de Jong</author>
<require>2</require> <require>2</require>

100
apps/remoteStorage/auth.php Normal file
View File

@ -0,0 +1,100 @@
<?php
/**
* ownCloud
*
* Original:
* @author Frank Karlitschek
* @copyright 2010 Frank Karlitschek karlitschek@kde.org
*
* Adapted:
* @author Michiel de Jong, 2011
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
// Do not load FS ...
$RUNTIME_NOSETUPFS = true;
require_once('../../lib/base.php');
OC_Util::checkAppEnabled('remoteStorage');
require_once('Sabre/autoload.php');
require_once('lib_remoteStorage.php');
require_once('oauth_ro_auth.php');
ini_set('default_charset', 'UTF-8');
#ini_set('error_reporting', '');
@ob_clean();
//allow use as remote storage for other websites
if(isset($_SERVER['HTTP_ORIGIN'])) {
header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
header('Access-Control-Max-Age: 3600');
header('Access-Control-Allow-Methods: OPTIONS, GET, PUT, DELETE, PROPFIND');
header('Access-Control-Allow-Headers: Authorization, Content-Type');
} else {
header('Access-Control-Allow-Origin: *');
}
$path = substr($_SERVER["REQUEST_URI"], strlen($_SERVER["SCRIPT_NAME"]));
$pathParts = explode('/', $path);
// for webdav:
// 0/ 1 / 2 / 3 / 4 / 5 / 6 / 7
// /$ownCloudUser/remoteStorage/webdav/$userHost/$userName/$dataScope/$key
// for oauth:
// 0/ 1 / 2 / 3 / 4
// /$ownCloudUser/remoteStorage/oauth/auth
if(count($pathParts) == 2 && $pathParts[0] == '') {
//TODO: input checking. these explodes may fail to produces the desired arrays:
$subPathParts = explode('?', $pathParts[1]);
$ownCloudUser = $subPathParts[0];
foreach($_GET as $k => $v) {
if($k=='user_address'){
$userAddress=$v;
} else if($k=='redirect_uri'){
$appUrl=$v;
} else if($k=='scope'){
$category=$v;
}
}
$currUser = OC_User::getUser();
if($currUser == $ownCloudUser) {
if(isset($_POST['allow'])) {
//TODO: check if this can be faked by editing the cookie in firebug!
$token=OC_remoteStorage::createCategory($appUrl, $category);
header('Location: '.$_GET['redirect_uri'].'#access_token='.$token.'&token_type=bearer');
} else {
echo '<form method="POST"><input name="allow" type="submit" value="Allow this web app to store stuff on your owncloud."></form>';
}
} else {
if((isset($_SERVER['HTTPS'])) && ($_SERVER['HTTPS'])) {
$url = "https://";
} else {
$url = "http://";
}
$url .= $_SERVER['SERVER_NAME'];
$url .= substr($_SERVER['SCRIPT_NAME'], 0, -strlen('apps/remoteStorage/compat.php'));
die('You are '.($currUser?'logged in as '.$currUser.' instead of '.$ownCloudUser:'not logged in').'. Please '
.'<input type="submit" onclick="'
."window.open('$url','Close me!','height=600,width=300');"
.'" value="log in">'
.', close the pop-up, and '
.'<form method="POST"><input name="allow" type="submit" value="Click here"></form>');
}
} else {
die('please use auth.php/username?params. '.var_export($pathParts, true));
}

View File

@ -1,26 +1,25 @@
<?php <?php
class OC_remoteStorage { class OC_remoteStorage {
public static function getValidTokens($ownCloudUser, $userAddress, $dataScope) { public static function getValidTokens($ownCloudUser, $category) {
$query=OC_DB::prepare("SELECT token,appUrl FROM *PREFIX*authtoken WHERE user=? AND userAddress=? AND dataScope=? LIMIT 100"); $query=OC_DB::prepare("SELECT token,appUrl FROM *PREFIX*authtoken WHERE user=? AND category=? LIMIT 100");
$result=$query->execute(array($ownCloudUser,$userAddress,$dataScope)); $result=$query->execute(array($ownCloudUser,$category));
$ret = array(); $ret = array();
while($row=$result->fetchRow()){ while($row=$result->fetchRow()){
$ret[$row['token']]=$userAddress; $ret[$row['token']]=true;
} }
return $ret; return $ret;
} }
public static function getAllTokens() { public static function getAllTokens() {
$user=OC_User::getUser(); $user=OC_User::getUser();
$query=OC_DB::prepare("SELECT token,appUrl,userAddress,dataScope FROM *PREFIX*authtoken WHERE user=? LIMIT 100"); $query=OC_DB::prepare("SELECT token,appUrl,category FROM *PREFIX*authtoken WHERE user=? LIMIT 100");
$result=$query->execute(array($user)); $result=$query->execute(array($user));
$ret = array(); $ret = array();
while($row=$result->fetchRow()){ while($row=$result->fetchRow()){
$ret[$row['token']] = array( $ret[$row['token']] = array(
'appUrl' => $row['appurl'], 'appUrl' => $row['appurl'],
'userAddress' => $row['useraddress'], 'category' => $row['category'],
'dataScope' => $row['datascope'],
); );
} }
return $ret; return $ret;
@ -31,24 +30,23 @@ class OC_remoteStorage {
$query=OC_DB::prepare("DELETE FROM *PREFIX*authtoken WHERE token=? AND user=?"); $query=OC_DB::prepare("DELETE FROM *PREFIX*authtoken WHERE token=? AND user=?");
$result=$query->execute(array($token,$user)); $result=$query->execute(array($token,$user));
} }
private static function addToken($token, $appUrl, $userAddress, $dataScope){ private static function addToken($token, $appUrl, $category){
$user=OC_User::getUser(); $user=OC_User::getUser();
$query=OC_DB::prepare("INSERT INTO *PREFIX*authtoken (`token`,`appUrl`,`user`,`userAddress`,`dataScope`) VALUES(?,?,?,?,?)"); $query=OC_DB::prepare("INSERT INTO *PREFIX*authtoken (`token`,`appUrl`,`user`,`category`) VALUES(?,?,?,?)");
$result=$query->execute(array($token,$appUrl,$user,$userAddress,$dataScope)); $result=$query->execute(array($token,$appUrl,$user,$category));
} }
public static function createDataScope($appUrl, $userAddress, $dataScope){ public static function createCategory($appUrl, $category) {
$token=uniqid(); $token=uniqid();
self::addToken($token, $appUrl, $userAddress, $dataScope); self::addToken($token, $appUrl, $category);
//TODO: input checking on $userAddress and $dataScope //TODO: input checking on $category
list($userName, $userHost) = explode('@', $userAddress);
OC_Util::setupFS(OC_User::getUser()); OC_Util::setupFS(OC_User::getUser());
$scopePathParts = array('remoteStorage', 'webdav', $userHost, $userName, $dataScope); $scopePathParts = array('remoteStorage', $category);
for($i=0;$i<=count($scopePathParts);$i++){ for($i=0;$i<=count($scopePathParts);$i++){
$thisPath = '/'.implode('/', array_slice($scopePathParts, 0, $i)); $thisPath = '/'.implode('/', array_slice($scopePathParts, 0, $i));
if(!OC_Filesystem::file_exists($thisPath)) { if(!OC_Filesystem::file_exists($thisPath)) {
OC_Filesystem::mkdir($thisPath); OC_Filesystem::mkdir($thisPath);
} }
} }
return $token; return base64_encode('remoteStorage:'.$token);
} }
} }

View File

@ -13,6 +13,7 @@
* @author Evert Pot (http://www.rooftopsolutions.nl/) * @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/ */
class OC_Connector_Sabre_Auth_ro_oauth extends Sabre_DAV_Auth_Backend_AbstractBasic { class OC_Connector_Sabre_Auth_ro_oauth extends Sabre_DAV_Auth_Backend_AbstractBasic {
private $validTokens; private $validTokens;
@ -52,7 +53,7 @@ die('not getting in with "'.$username.'"/"'.$password.'"!');
$auth->setRealm($realm); $auth->setRealm($realm);
$userpass = $auth->getUserPass(); $userpass = $auth->getUserPass();
if (!$userpass) { if (!$userpass) {
if(in_array($_SERVER['REQUEST_METHOD'], array('GET', 'HEAD', 'OPTIONS'))) { if(in_array($_SERVER['REQUEST_METHOD'], array('OPTIONS'))) {
$userpass = array('', ''); $userpass = array('', '');
} else { } else {
$auth->requireLogin(); $auth->requireLogin();

View File

@ -22,10 +22,20 @@ if($_GET['q']) {
if(substr($userName, 0, 5) == 'acct:') { if(substr($userName, 0, 5) == 'acct:') {
$userName = substr($userName, 5); $userName = substr($userName, 5);
} }
if($_SERVER['HTTPS']) {
$baseAddress = 'https://'.$_SERVER['SERVER_NAME'].'/apps/remoteStorage/';
} else {
$baseAddress = 'http://'.$_SERVER['SERVER_NAME'].'/apps/remoteStorage/';
}
echo "<"; echo "<";
?> ?>
?xml version="1.0" encoding="UTF-8"?> ?xml version="1.0" encoding="UTF-8"?>
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0" xmlns:hm="http://host-meta.net/xrd/1.0"> <XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0" xmlns:hm="http://host-meta.net/xrd/1.0">
<hm:Host xmlns="http://host-meta.net/xrd/1.0"><?php echo $_SERVER['SERVER_NAME'] ?></hm:Host> <hm:Host xmlns="http://host-meta.net/xrd/1.0"><?php echo $_SERVER['SERVER_NAME'] ?></hm:Host>
<Link rel="http://unhosted.org/spec/dav/0.1" href="http<?php echo ($_SERVER['HTTPS']?'s':''); ?>://<?php echo $_SERVER['SERVER_NAME'].$WEBROOT ?>/apps/remoteStorage/compat.php/<?php echo $userName ?>/remoteStorage/" /> <Link
rel="remoteStorage"
template="<?php echo $baseAddress ?>WebDAV.php/<?php echo $userName ?>/remoteStorage/{category}/"
api="WebDAV"
auth="<?php echo $baseAddress; ?>auth.php/<?php echo $userName ?>"
></Link>
</XRD> </XRD>

View File

@ -223,7 +223,7 @@ class OC_App{
// admin apps menu // admin apps menu
$settings[] = array( "id" => "core_apps", "order" => 3, "href" => OC_Helper::linkTo( "settings", "apps.php?installed" ), "name" => $l->t("Apps"), "icon" => OC_Helper::imagePath( "settings", "apps.svg" )); $settings[] = array( "id" => "core_apps", "order" => 3, "href" => OC_Helper::linkTo( "settings", "apps.php?installed" ), "name" => $l->t("Apps"), "icon" => OC_Helper::imagePath( "settings", "apps.svg" ));
// admin log menu // admin log menu
$settings[] = array( "id" => "core_log", "order" => 4, "href" => OC_Helper::linkTo( "settings", "log.php" ), "name" => $l->t("Log"), "icon" => OC_Helper::imagePath( "log", "apps.svg" )); $settings[] = array( "id" => "core_log", "order" => 4, "href" => OC_Helper::linkTo( "settings", "log.php" ), "name" => $l->t("Log"), "icon" => OC_Helper::imagePath( "settings", "log.svg" ));
$settings[]=array( "id" => "admin", "order" => 1000, "href" => OC_Helper::linkTo( "settings", "admin.php" ), "name" => $l->t("Admin"), "icon" => OC_Helper::imagePath( "settings", "admin.svg" )); $settings[]=array( "id" => "admin", "order" => 1000, "href" => OC_Helper::linkTo( "settings", "admin.php" ), "name" => $l->t("Admin"), "icon" => OC_Helper::imagePath( "settings", "admin.svg" ));
} }

View File

@ -492,7 +492,7 @@ class PDOStatementWrapper{
} }
/** /**
* make exucute return the result instead of a bool * make execute return the result instead of a bool
*/ */
public function execute($input=array()){ public function execute($input=array()){
$this->lastArguments=$input; $this->lastArguments=$input;

View File

@ -52,13 +52,9 @@ class OC_Updater{
$tmp['url'] = $data->url; $tmp['url'] = $data->url;
$tmp['web'] = $data->web; $tmp['web'] = $data->web;
return $tmp; return $tmp;
} }
public static function ShowUpdatingHint(){ public static function ShowUpdatingHint(){
$data=OC_Updater::check(); $data=OC_Updater::check();
if(isset($data['version']) and $data['version']<>'') { if(isset($data['version']) and $data['version']<>'') {
@ -67,10 +63,8 @@ class OC_Updater{
$txt='Your ownCloud is up to date'; $txt='Your ownCloud is up to date';
} }
return($txt); return($txt);
} }
/** /**
* do ownCloud update * do ownCloud update
*/ */
@ -83,9 +77,5 @@ class OC_Updater{
//update version in config //update version in config
} }
} }
?> ?>

207
lib/vobject.php Normal file
View File

@ -0,0 +1,207 @@
<?php
/**
* ownCloud
*
* @author Bart Visscher
* @copyright 2011 Bart Visscher bartv@thisnet.nl
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
* This class provides a streamlined interface to the Sabre VObject classes
*/
class OC_VObject{
/** @var Sabre_VObject_Component */
protected $vobject;
/**
* @returns Sabre_VObject_Component
*/
public function getVObject(){
return $this->vobject;
}
/**
* @brief Parses the VObject
* @param string VObject as string
* @returns Sabre_VObject or null
*/
public static function parse($data){
try {
Sabre_VObject_Reader::$elementMap['LAST-MODIFIED'] = 'Sabre_VObject_Element_DateTime';
$vobject = Sabre_VObject_Reader::read($data);
if ($vobject instanceof Sabre_VObject_Component){
$vobject = new OC_VObject($vobject);
}
return $vobject;
} catch (Exception $e) {
OC_Log::write('vobject', $e->getMessage(), OC_Log::ERROR);
return null;
}
}
/**
* @brief Escapes semicolons
* @param string $value
* @return string
*/
public static function escapeSemicolons($value){
foreach($value as &$i ){
$i = implode("\\\\;", explode(';', $i));
}
return implode(';',$value);
}
/**
* @brief Creates an array out of a multivalue property
* @param string $value
* @return array
*/
public static function unescapeSemicolons($value){
$array = explode(';',$value);
for($i=0;$i<count($array);$i++){
if(substr($array[$i],-2,2)=="\\\\"){
if(isset($array[$i+1])){
$array[$i] = substr($array[$i],0,count($array[$i])-2).';'.$array[$i+1];
unset($array[$i+1]);
}
else{
$array[$i] = substr($array[$i],0,count($array[$i])-2).';';
}
$i = $i - 1;
}
}
return $array;
}
/**
* Constuctor
* @param Sabre_VObject_Component or string
*/
public function __construct($vobject_or_name){
if (is_object($vobject_or_name)){
$this->vobject = $vobject_or_name;
} else {
$this->vobject = new Sabre_VObject_Component($vobject_or_name);
}
}
public function add($item, $itemValue = null){
if ($item instanceof OC_VObject){
$item = $item->getVObject();
}
$this->vobject->add($item, $itemValue);
}
/**
* @brief Add property to vobject
* @param object $name of property
* @param object $value of property
* @param object $parameters of property
* @returns Sabre_VObject_Property newly created
*/
public function addProperty($name, $value, $parameters=array()){
if(is_array($value)){
$value = OC_VObject::escapeSemicolons($value);
}
$property = new Sabre_VObject_Property( $name, $value );
foreach($parameters as $name => $value){
$property->parameters[] = new Sabre_VObject_Parameter($name, $value);
}
$this->vobject->add($property);
return $property;
}
public function setUID(){
$uid = substr(md5(rand().time()),0,10);
$this->vobject->add('UID',$uid);
}
public function setString($name, $string){
if ($string != ''){
$string = strtr($string, array("\r\n"=>"\n"));
$this->vobject->__set($name, $string);
}else{
$this->vobject->__unset($name);
}
}
/**
* Sets or unsets the Date and Time for a property.
* When $datetime is set to 'now', use the current time
* When $datetime is null, unset the property
*
* @param string property name
* @param DateTime $datetime
* @param int $dateType
* @return void
*/
public function setDateTime($name, $datetime, $dateType=Sabre_VObject_Element_DateTime::LOCALTZ){
if ($datetime == 'now'){
$datetime = new DateTime();
}
if ($datetime instanceof DateTime){
$datetime_element = new Sabre_VObject_Element_DateTime($name);
$datetime_element->setDateTime($datetime, $dateType);
$this->vobject->__set($name, $datetime_element);
}else{
$this->vobject->__unset($name);
}
}
public function getAsString($name){
return $this->vobject->__isset($name) ?
$this->vobject->__get($name)->value :
'';
}
public function getAsArray($name){
$values = array();
if ($this->vobject->__isset($name)){
$values = explode(',', $this->getAsString($name));
$values = array_map('trim', $values);
}
return $values;
}
public function &__get($name){
if ($name == 'children'){
return $this->vobject->children;
}
$return = $this->vobject->__get($name);
if ($return instanceof Sabre_VObject_Component){
$return = new OC_VObject($return);
}
return $return;
}
public function __set($name, $value){
return $this->vobject->__set($name, $value);
}
public function __unset($name){
return $this->vobject->__unset($name);
}
public function __isset($name){
return $this->vobject->__isset($name);
}
public function __call($function,$arguments){
return call_user_func_array(array($this->vobject, $function), $arguments);
}
}

View File

@ -43,6 +43,14 @@ foreach($registeredApps as $app){
} }
} }
function app_sort($a, $b){
if ($a['active'] != $b['active']){
return $b['active'] - $a['active'];
}
return strcmp($a['name'], $b['name']);
}
usort($apps, 'app_sort');
// dissabled for now // dissabled for now
// $catagoryNames=OC_OCSClient::getCategories(); // $catagoryNames=OC_OCSClient::getCategories();
// if(is_array($catagoryNames)){ // if(is_array($catagoryNames)){