aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/calendar/ajax/editevent.php2
-rw-r--r--apps/calendar/ajax/editeventform.php16
-rw-r--r--apps/calendar/ajax/events.php2
-rw-r--r--apps/calendar/ajax/moveevent.php12
-rw-r--r--apps/calendar/js/calendar.js5
-rw-r--r--apps/calendar/lib/object.php92
-rw-r--r--apps/contacts/ajax/addcard.php32
-rw-r--r--apps/contacts/ajax/addproperty.php28
-rw-r--r--apps/contacts/ajax/deletebook.php11
-rw-r--r--apps/contacts/ajax/deletecard.php17
-rw-r--r--apps/contacts/ajax/deleteproperty.php38
-rw-r--r--apps/contacts/ajax/getdetails.php45
-rw-r--r--apps/contacts/ajax/setproperty.php42
-rw-r--r--apps/contacts/ajax/showaddcard.php6
-rw-r--r--apps/contacts/ajax/showaddproperty.php16
-rw-r--r--apps/contacts/ajax/showsetproperty.php39
-rw-r--r--apps/contacts/appinfo/app.php1
-rw-r--r--apps/contacts/index.php12
-rw-r--r--apps/contacts/lib/app.php122
-rw-r--r--apps/contacts/lib/vcard.php135
-rw-r--r--apps/contacts/photo.php2
-rw-r--r--apps/contacts/templates/index.php9
-rw-r--r--apps/contacts/templates/part.property.php2
-rw-r--r--apps/files_imageviewer/css/jquery.fancybox-1.3.4.css42
-rw-r--r--apps/files_sharing/appinfo/app.php1
-rw-r--r--apps/files_sharing/lib_share.php4
-rw-r--r--apps/files_sharing/sharedstorage.php77
-rw-r--r--apps/files_texteditor/ajax/savefile.php2
-rw-r--r--apps/gallery/ajax/createAlbum.php3
-rw-r--r--apps/gallery/ajax/getAlbums.php6
-rw-r--r--apps/gallery/ajax/getCovers.php16
-rw-r--r--apps/gallery/ajax/scanForAlbums.php3
-rw-r--r--apps/gallery/ajax/thumbnail.php17
-rw-r--r--apps/gallery/appinfo/app.php4
-rw-r--r--apps/gallery/css/styles.css14
-rw-r--r--apps/gallery/index.php7
-rw-r--r--apps/gallery/lib/album.php18
-rw-r--r--apps/gallery/lib/photo.php28
-rw-r--r--apps/gallery/lib/scanner.php (renamed from apps/gallery/lib_scanner.php)22
-rw-r--r--apps/gallery/templates/view_album.php10
-rw-r--r--apps/remoteStorage/WebDAV.php (renamed from apps/remoteStorage/compat.php)52
-rw-r--r--apps/remoteStorage/appinfo/database.xml9
-rw-r--r--apps/remoteStorage/appinfo/info.xml2
-rw-r--r--apps/remoteStorage/auth.php100
-rw-r--r--apps/remoteStorage/lib_remoteStorage.php30
-rw-r--r--apps/remoteStorage/oauth_ro_auth.php3
-rw-r--r--apps/user_webfinger/webfinger.php12
-rw-r--r--db_structure.xml102
-rw-r--r--files/ajax/scan.php16
-rw-r--r--files/ajax/upload.php2
-rw-r--r--files/css/files.css4
-rw-r--r--files/js/files.js19
-rw-r--r--files/templates/index.php5
-rw-r--r--files/templates/part.list.php4
-rw-r--r--lib/app.php2
-rw-r--r--lib/base.php3
-rw-r--r--lib/db.php2
-rw-r--r--lib/filecache.php353
-rw-r--r--lib/fileproxy.php2
-rw-r--r--lib/files.php41
-rw-r--r--lib/filestorage.php2
-rw-r--r--lib/filestorage/local.php97
-rw-r--r--lib/filestorage/remote.php350
-rw-r--r--lib/filesystem.php103
-rw-r--r--lib/helper.php25
-rw-r--r--lib/updater.php10
-rw-r--r--lib/util.php4
-rw-r--r--lib/vobject.php207
-rw-r--r--owncloud.db.filesystembin0 -> 2348032 bytes
-rw-r--r--settings/ajax/setquota.php2
-rw-r--r--settings/apps.php8
-rw-r--r--settings/js/users.js7
72 files changed, 1277 insertions, 1261 deletions
diff --git a/apps/calendar/ajax/editevent.php b/apps/calendar/ajax/editevent.php
index 46feb068499..e3c84520481 100644
--- a/apps/calendar/ajax/editevent.php
+++ b/apps/calendar/ajax/editevent.php
@@ -34,7 +34,7 @@ if($errarr){
OC_JSON::error();
exit;
}
- $vcalendar = OC_Calendar_Object::parse($data['calendardata']);
+ $vcalendar = OC_VObject::parse($data['calendardata']);
$last_modified = $vcalendar->VEVENT->__get('LAST-MODIFIED');
if($last_modified && $_POST['lastmodified'] != $last_modified->getDateTime()->format('U')){
diff --git a/apps/calendar/ajax/editeventform.php b/apps/calendar/ajax/editeventform.php
index 63c72934079..c91f136e898 100644
--- a/apps/calendar/ajax/editeventform.php
+++ b/apps/calendar/ajax/editeventform.php
@@ -26,7 +26,7 @@ if($calendar['userid'] != OC_User::getUser()){
echo $l10n->t('Wrong calendar');
exit;
}
-$object = OC_Calendar_Object::parse($data['calendardata']);
+$object = OC_VObject::parse($data['calendardata']);
$vevent = $object->VEVENT;
$dtstart = $vevent->DTSTART;
$dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent);
@@ -49,20 +49,16 @@ switch($dtstart->getDateType()) {
break;
}
-$summary = isset($vevent->SUMMARY) ? $vevent->SUMMARY->value : '';
-$location = isset($vevent->LOCATION) ? $vevent->LOCATION->value : '';
-$categories = array();
-if (isset($vevent->CATEGORIES)){
- $categories = explode(',', $vevent->CATEGORIES->value);
- $categories = array_map('trim', $categories);
-}
+$summary = $vevent->getAsString('SUMMARY');
+$location = $vevent->getAsString('LOCATION');
+$categories = $vevent->getAsArray('CATEGORIES');
+$repeat = $vevent->getAsString('CATEGORY');
+$description = $vevent->getAsString('DESCRIPTION');
foreach($categories as $category){
if (!in_array($category, $category_options)){
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');
if ($last_modified){
$lastmodified = $last_modified->getDateTime()->format('U');
diff --git a/apps/calendar/ajax/events.php b/apps/calendar/ajax/events.php
index 1ef6bd30594..1430432b8a3 100644
--- a/apps/calendar/ajax/events.php
+++ b/apps/calendar/ajax/events.php
@@ -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());
$return = array();
foreach($events as $event){
- $object = OC_Calendar_Object::parse($event['calendardata']);
+ $object = OC_VObject::parse($event['calendardata']);
$vevent = $object->VEVENT;
$dtstart = $vevent->DTSTART;
$dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent);
diff --git a/apps/calendar/ajax/moveevent.php b/apps/calendar/ajax/moveevent.php
index 6b315a39213..51fafdfeb97 100644
--- a/apps/calendar/ajax/moveevent.php
+++ b/apps/calendar/ajax/moveevent.php
@@ -22,7 +22,7 @@ $delta = new DateInterval('P0D');
$delta->d = $_POST['dayDelta'];
$delta->i = $_POST['minuteDelta'];
-$vcalendar = OC_Calendar_Object::parse($data['calendardata']);
+$vcalendar = OC_VObject::parse($data['calendardata']);
$vevent = $vcalendar->VEVENT;
$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);
unset($vevent->DURATION);
-$now = new DateTime();
-$last_modified = new Sabre_VObject_Element_DateTime('LAST-MODIFIED');
-$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;
+$vevent->setDateTime('LAST-MODIFIED', 'now', Sabre_VObject_Element_DateTime::UTC);
+$vevent->setDateTime('DTSTAMP', 'now', Sabre_VObject_Element_DateTime::UTC);
$result = OC_Calendar_Object::edit($id, $vcalendar->serialize());
OC_JSON::success(array('lastmodified'=>(int)$now->format('U')));
diff --git a/apps/calendar/js/calendar.js b/apps/calendar/js/calendar.js
index 005e359f8eb..c3644b53704 100644
--- a/apps/calendar/js/calendar.js
+++ b/apps/calendar/js/calendar.js
@@ -7,7 +7,6 @@
*/
Calendar={
- space:' ',
UI:{
startEventDialog:function(){
$('.tipsy').remove();
@@ -271,9 +270,9 @@ Calendar={
var url;
if (calendarid == 'new'){
- url = "ajax/createcalendar.php";
+ url = OC.filePath('calendar', 'ajax', 'createcalendar.php');
}else{
- url = "ajax/updatecalendar.php";
+ url = OC.filePath('calendar', 'ajax', 'updatecalendar.php');
}
$.post(url, { id: calendarid, name: displayname, active: active, description: description, color: calendarcolor },
function(data){
diff --git a/apps/calendar/lib/object.php b/apps/calendar/lib/object.php
index b0164690429..1c145003511 100644
--- a/apps/calendar/lib/object.php
+++ b/apps/calendar/lib/object.php
@@ -92,7 +92,7 @@ class OC_Calendar_Object{
* @return insertid
*/
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);
if(is_null($uid)){
@@ -119,7 +119,7 @@ class OC_Calendar_Object{
* @return insertid
*/
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);
$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){
$oldobject = self::find($id);
- $object = self::parse($data);
+ $object = OC_VObject::parse($data);
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 = ?' );
@@ -160,7 +160,7 @@ class OC_Calendar_Object{
public static function editFromDAVData($cid,$uri,$data){
$oldobject = self::findWhereDAVDataIs($cid,$uri);
- $object = self::parse($data);
+ $object = OC_VObject::parse($data);
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 = ?' );
@@ -228,7 +228,7 @@ class OC_Calendar_Object{
// Child to use
$children = 0;
$use = null;
- foreach($object->children as &$property){
+ foreach($object->children as $property){
if($property->name == 'VEVENT'){
$children++;
$thisone = true;
@@ -259,12 +259,12 @@ class OC_Calendar_Object{
// one VTODO per object)
break;
}
- } unset($property);
+ }
// find the data
if(!is_null($use)){
$return[0] = $use->name;
- foreach($use->children as &$property){
+ foreach($use->children as $property){
if($property->name == 'DTSTART'){
$return[1] = self::getUTCforMDB($property->getDateTime());
}
@@ -280,7 +280,7 @@ class OC_Calendar_Object{
elseif($property->name == 'UID'){
$return[5] = $property->value;
}
- } unset($property);
+ }
}
// 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());
}
- /**
- * @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)
{
if ($vevent->DTEND) {
@@ -458,22 +443,16 @@ class OC_Calendar_Object{
public static function createVCalendarFromRequest($request)
{
- $vcalendar = new Sabre_VObject_Component('VCALENDAR');
+ $vcalendar = new OC_VObject('VCALENDAR');
$vcalendar->add('PRODID', 'ownCloud Calendar');
$vcalendar->add('VERSION', '2.0');
- $now = new DateTime();
-
- $vevent = new Sabre_VObject_Component('VEVENT');
+ $vevent = new OC_VObject('VEVENT');
$vcalendar->add($vevent);
- $created = new Sabre_VObject_Element_DateTime('CREATED');
- $created->setDateTime($now, Sabre_VObject_Element_DateTime::UTC);
- $vevent->add($created);
-
- $uid = self::createUID();
- $vevent->add('UID',$uid);
+ $vevent->setDateTime('CREATED', 'now', Sabre_VObject_Element_DateTime::UTC);
+ $vevent->setUID();
return self::updateVCalendarFromRequest($request, $vcalendar);
}
@@ -481,7 +460,7 @@ class OC_Calendar_Object{
{
$title = $request["title"];
$location = $request["location"];
- $categories = isset($request["categories"]) ? $request["categories"] : null;
+ $categories = isset($request["categories"]) ? $request["categories"] : array();
$allday = isset($request["allday"]);
$from = $request["from"];
$to = $request["to"];
@@ -509,55 +488,32 @@ class OC_Calendar_Object{
}*/
$repeat = "false";
- $now = new DateTime();
- $vevent = $vcalendar->VEVENT[0];
-
- $last_modified = new Sabre_VObject_Element_DateTime('LAST-MODIFIED');
- $last_modified->setDateTime($now, Sabre_VObject_Element_DateTime::UTC);
- $vevent->__set('LAST-MODIFIED', $last_modified);
+ $vevent = $vcalendar->VEVENT;
- $dtstamp = new Sabre_VObject_Element_DateTime('DTSTAMP');
- $dtstamp->setDateTime($now, Sabre_VObject_Element_DateTime::UTC);
- $vevent->DTSTAMP = $dtstamp;
-
- $vevent->SUMMARY = $title;
+ $vevent->setDateTime('LAST-MODIFIED', 'now', Sabre_VObject_Element_DateTime::UTC);
+ $vevent->setDateTime('DTSTAMP', 'now', Sabre_VObject_Element_DateTime::UTC);
+ $vevent->setString('SUMMARY', $title);
$dtstart = new Sabre_VObject_Element_DateTime('DTSTART');
$dtend = new Sabre_VObject_Element_DateTime('DTEND');
if($allday){
$start = new DateTime($from);
$end = new DateTime($to.' +1 day');
- $dtstart->setDateTime($start, Sabre_VObject_Element_DateTime::DATE);
- $dtend->setDateTime($end, Sabre_VObject_Element_DateTime::DATE);
+ $vevent->setDateTime('DTSTART', $start, Sabre_VObject_Element_DateTime::DATE);
+ $vevent->setDateTime('DTEND', $end, Sabre_VObject_Element_DateTime::DATE);
}else{
$timezone = OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezone', date_default_timezone_get());
$timezone = new DateTimeZone($timezone);
$start = new DateTime($from.' '.$fromtime, $timezone);
$end = new DateTime($to.' '.$totime, $timezone);
- $dtstart->setDateTime($start, Sabre_VObject_Element_DateTime::LOCALTZ);
- $dtend->setDateTime($end, Sabre_VObject_Element_DateTime::LOCALTZ);
+ $vevent->setDateTime('DTSTART', $start, Sabre_VObject_Element_DateTime::LOCALTZ);
+ $vevent->setDateTime('DTEND', $end, Sabre_VObject_Element_DateTime::LOCALTZ);
}
- $vevent->DTSTART = $dtstart;
- $vevent->DTEND = $dtend;
unset($vevent->DURATION);
- if($location != ""){
- $vevent->LOCATION = $location;
- }else{
- unset($vevent->LOCATION);
- }
-
- if($description != ""){
- $vevent->DESCRIPTION = $description;
- }else{
- unset($vevent->DESCRIPTION);
- }
-
- if(!empty($categories)){
- $vevent->CATEGORIES = join(',', $categories);
- }else{
- unset($vevent->CATEGORIES);
- }
+ $vevent->setString('LOCATION', $location);
+ $vevent->setString('DESCRIPTION', $description);
+ $vevent->setString('CATEGORIES', join(',', $categories));
/*if($repeat == "true"){
$vevent->RRULE = $repeat;
diff --git a/apps/contacts/ajax/addcard.php b/apps/contacts/ajax/addcard.php
index dd5b90651f5..9d782246a0a 100644
--- a/apps/contacts/ajax/addcard.php
+++ b/apps/contacts/ajax/addcard.php
@@ -23,26 +23,20 @@
// Init owncloud
require_once('../../../lib/base.php');
-$aid = $_POST['id'];
-$l10n = new OC_L10N('contacts');
-
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
-$addressbook = OC_Contacts_Addressbook::find( $aid );
-if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
- 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();
-}
+$aid = $_POST['id'];
+$addressbook = OC_Contacts_App::getAddressbook( $aid );
$fn = $_POST['fn'];
$values = $_POST['value'];
$parameters = $_POST['parameters'];
-$vcard = new Sabre_VObject_Component('VCARD');
-$vcard->add(new Sabre_VObject_Property('FN',$fn));
-$vcard->add(new Sabre_VObject_Property('UID',OC_Contacts_VCard::createUID()));
+$vcard = new OC_VObject('VCARD');
+$vcard->setUID();
+$vcard->setString('FN',$fn);
// Data to add ...
$add = array('TEL', 'EMAIL', 'ORG');
@@ -64,20 +58,8 @@ foreach( $add as $propname){
else{
$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());
-$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR');
-$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 )));
+OC_Contacts_App::renderDetails($id, $vcard);
diff --git a/apps/contacts/ajax/addproperty.php b/apps/contacts/ajax/addproperty.php
index 101cfabbe84..98877805b46 100644
--- a/apps/contacts/ajax/addproperty.php
+++ b/apps/contacts/ajax/addproperty.php
@@ -23,40 +23,20 @@
// Init owncloud
require_once('../../../lib/base.php');
-$id = $_POST['id'];
-$l10n = new OC_L10N('contacts');
-
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
-$card = OC_Contacts_VCard::find( $id );
-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();
-}
+$id = $_POST['id'];
+$vcard = OC_Contacts_App::getContactVCard( $id );
$name = $_POST['name'];
$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;
-$checksum = md5($property->serialize());
OC_Contacts_VCard::edit($id,$vcard->serialize());
diff --git a/apps/contacts/ajax/deletebook.php b/apps/contacts/ajax/deletebook.php
index c13217ef2e2..3ede17ab886 100644
--- a/apps/contacts/ajax/deletebook.php
+++ b/apps/contacts/ajax/deletebook.php
@@ -23,19 +23,12 @@
// Init owncloud
require_once('../../../lib/base.php');
-$id = $_GET['id'];
-
-$l10n = new OC_L10N('contacts');
-
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
-$addressbook = OC_Contacts_Addressbook::find( $id );
-if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.'))));
- exit();
-}
+$id = $_GET['id'];
+$addressbook = OC_Contacts_App::getAddressbook( $id );
OC_Contacts_Addressbook::delete($id);
OC_JSON::success(array('data' => array( 'id' => $id )));
diff --git a/apps/contacts/ajax/deletecard.php b/apps/contacts/ajax/deletecard.php
index a0a6b8c3ea8..e26dfd6ebfe 100644
--- a/apps/contacts/ajax/deletecard.php
+++ b/apps/contacts/ajax/deletecard.php
@@ -23,25 +23,12 @@
// Init owncloud
require_once('../../../lib/base.php');
-$id = $_GET['id'];
-
-$l10n = new OC_L10N('contacts');
-
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
-$card = OC_Contacts_VCard::find( $id );
-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();
-}
+$id = $_GET['id'];
+$card = OC_Contacts_App::getContactObject( $id );
OC_Contacts_VCard::delete($id);
OC_JSON::success(array('data' => array( 'id' => $id )));
diff --git a/apps/contacts/ajax/deleteproperty.php b/apps/contacts/ajax/deleteproperty.php
index 0a3a3c293a0..f69735e61c6 100644
--- a/apps/contacts/ajax/deleteproperty.php
+++ b/apps/contacts/ajax/deleteproperty.php
@@ -23,45 +23,15 @@
// Init owncloud
require_once('../../../lib/base.php');
-$id = $_GET['id'];
-$checksum = $_GET['checksum'];
-
-
-$l10n = new OC_L10N('contacts');
-
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
-$card = OC_Contacts_VCard::find( $id );
-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();
-}
+$id = $_GET['id'];
+$checksum = $_GET['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' => $l10n->t('Information about vCard is incorrect. Please reload the page.'))));
- exit();
-}
+$vcard = OC_Contacts_App::getContactVCard( $id );
+$line = OC_Contacts_App::getPropertyLineByChecksum($vcard, $checksum);
unset($vcard->children[$line]);
diff --git a/apps/contacts/ajax/getdetails.php b/apps/contacts/ajax/getdetails.php
index 260fb53a686..8cc0f9cbb0f 100644
--- a/apps/contacts/ajax/getdetails.php
+++ b/apps/contacts/ajax/getdetails.php
@@ -23,50 +23,11 @@
// Init owncloud
require_once('../../../lib/base.php');
-$id = $_GET['id'];
-
-$l10n = new OC_L10N('contacts');
-
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
+$id = $_GET['id'];
+$vcard = OC_Contacts_App::getContactVCard( $id );
-$card = OC_Contacts_VCard::find( $id );
-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 )));
+OC_Contacts_App::renderDetails($id, $vcard);
diff --git a/apps/contacts/ajax/setproperty.php b/apps/contacts/ajax/setproperty.php
index 22f228cbf43..bcc4c161cc0 100644
--- a/apps/contacts/ajax/setproperty.php
+++ b/apps/contacts/ajax/setproperty.php
@@ -23,48 +23,20 @@
// Init owncloud
require_once('../../../lib/base.php');
-$id = $_POST['id'];
-$checksum = $_POST['checksum'];
-$l10n = new OC_L10N('contacts');
-
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
-$card = OC_Contacts_VCard::find( $id );
-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();
-}
+$id = $_POST['id'];
+$checksum = $_POST['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' => $l10n->t('Information about vCard is incorrect. Please reload the page.'))));
- exit();
-}
+$vcard = OC_Contacts_App::getContactVCard( $id );
+$line = OC_Contacts_App::getPropertyLineByChecksum($vcard, $checksum);
// Set the value
$value = $_POST['value'];
if(is_array($value)){
- $value = OC_Contacts_VCard::escapeSemicolons($value);
+ $value = OC_VObject::escapeSemicolons($value);
}
$vcard->children[$line]->setValue($value);
@@ -104,8 +76,8 @@ $checksum = md5($vcard->children[$line]->serialize());
OC_Contacts_VCard::edit($id,$vcard->serialize());
-$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR');
-$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL');
+$adr_types = OC_Contacts_App::getTypesOfProperty('ADR');
+$phone_types = OC_Contacts_App::getTypesOfProperty('TEL');
if ($vcard->children[$line]->name == 'FN'){
$tmpl = new OC_Template('contacts','part.property.FN');
diff --git a/apps/contacts/ajax/showaddcard.php b/apps/contacts/ajax/showaddcard.php
index 98367758fd4..54592c89c0d 100644
--- a/apps/contacts/ajax/showaddcard.php
+++ b/apps/contacts/ajax/showaddcard.php
@@ -23,14 +23,12 @@
// Init owncloud
require_once('../../../lib/base.php');
-$l10n = new OC_L10N('contacts');
-
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
-$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR');
-$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL');
+$adr_types = OC_Contacts_App::getTypesOfProperty('ADR');
+$phone_types = OC_Contacts_App::getTypesOfProperty('TEL');
$addressbooks = OC_Contacts_Addressbook::all(OC_USER::getUser());
$tmpl = new OC_Template('contacts','part.addcardform');
diff --git a/apps/contacts/ajax/showaddproperty.php b/apps/contacts/ajax/showaddproperty.php
index f87cd05359b..30eb7634f80 100644
--- a/apps/contacts/ajax/showaddproperty.php
+++ b/apps/contacts/ajax/showaddproperty.php
@@ -23,24 +23,12 @@
// Init owncloud
require_once('../../../lib/base.php');
-$id = $_GET['id'];
-$l10n = new OC_L10N('contacts');
-
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
-$card = OC_Contacts_VCard::find( $id );
-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();
-}
+$id = $_GET['id'];
+$card = OC_Contacts_App::getContactObject( $id );
$tmpl = new OC_Template('contacts','part.addpropertyform');
$tmpl->assign('id',$id);
diff --git a/apps/contacts/ajax/showsetproperty.php b/apps/contacts/ajax/showsetproperty.php
index 2ec4b89b824..e23fa21c56b 100644
--- a/apps/contacts/ajax/showsetproperty.php
+++ b/apps/contacts/ajax/showsetproperty.php
@@ -23,46 +23,19 @@
// Init owncloud
require_once('../../../lib/base.php');
-$id = $_GET['id'];
-$checksum = $_GET['checksum'];
-$l10n = new OC_L10N('contacts');
-
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
-$card = OC_Contacts_VCard::find( $id );
-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();
-}
+$id = $_GET['id'];
+$checksum = $_GET['checksum'];
-$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();
-}
+$vcard = OC_Contacts_App::getContactVCard( $id );
-$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();
-}
+$line = OC_Contacts_App::getPropertyLineByChecksum($vcard, $checksum);
-$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR');
-$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL');
+$adr_types = OC_Contacts_App::getTypesOfProperty('ADR');
+$phone_types = OC_Contacts_App::getTypesOfProperty('TEL');
$tmpl = new OC_Template('contacts','part.setpropertyform');
$tmpl->assign('id',$id);
diff --git a/apps/contacts/appinfo/app.php b/apps/contacts/appinfo/app.php
index fc7b3769c53..524cc640bc9 100644
--- a/apps/contacts/appinfo/app.php
+++ b/apps/contacts/appinfo/app.php
@@ -1,5 +1,6 @@
<?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_VCard'] = 'apps/contacts/lib/vcard.php';
OC::$CLASSPATH['OC_Contacts_Hooks'] = 'apps/contacts/lib/hooks.php';
diff --git a/apps/contacts/index.php b/apps/contacts/index.php
index 29d41d3c4c4..de7b56dd1ae 100644
--- a/apps/contacts/index.php
+++ b/apps/contacts/index.php
@@ -66,18 +66,16 @@ foreach( $openaddressbooks as $addressbook ){
}
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'];
- $contact = OC_Contacts_VCard::find($id);
- $vcard = OC_Contacts_VCard::parse($contact['carddata']);
+ $vcard = OC_Contacts_App::getContactVCard($id);
$details = OC_Contacts_VCard::structureContact($vcard);
}
-$l10n = new OC_L10N('contacts');
-$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR');
-$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL');
+$adr_types = OC_Contacts_App::getTypesOfProperty('ADR');
+$phone_types = OC_Contacts_App::getTypesOfProperty('TEL');
// Process the template
$tmpl = new OC_Template( 'contacts', 'index', 'user' );
diff --git a/apps/contacts/lib/app.php b/apps/contacts/lib/app.php
new file mode 100644
index 00000000000..ba086e4aca8
--- /dev/null
+++ b/apps/contacts/lib/app.php
@@ -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'),
+ );
+ }
+ }
+}
diff --git a/apps/contacts/lib/vcard.php b/apps/contacts/lib/vcard.php
index 4865fae7642..a573f40f7d9 100644
--- a/apps/contacts/lib/vcard.php
+++ b/apps/contacts/lib/vcard.php
@@ -91,31 +91,21 @@ class OC_Contacts_VCard{
*/
public static function add($id,$data){
$fn = null;
- $uri = null;
- $card = self::parse($data);
+ $card = OC_VObject::parse($data);
if(!is_null($card)){
- // VCARD must have a version
- $hasversion = false;
- foreach($card->children as $property){
- if($property->name == 'FN'){
- $fn = $property->value;
- }
- 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));
+ $fn = $card->getAsString('FN');
+ $uid = $card->getAsString('UID');
+ if(is_null($uid)){
+ $card->setUID();
+ $uid = $card->getAsString('UID');
$data = $card->serialize();
};
+ $uri = $uid.'.vcf';
+ // VCARD must have a version
+ $version = $card->getAsString('VERSION');
// Add version if needed
- if(!$hasversion){
+ if(is_null($version)){
$card->add(new Sabre_VObject_Property('VERSION','3.0'));
$data = $card->serialize();
}
@@ -143,7 +133,7 @@ class OC_Contacts_VCard{
*/
public static function addFromDAVData($id,$uri,$data){
$fn = null;
- $card = self::parse($data);
+ $card = OC_VObject::parse($data);
if(!is_null($card)){
foreach($card->children as $property){
if($property->name == 'FN'){
@@ -170,7 +160,7 @@ class OC_Contacts_VCard{
$oldcard = self::find($id);
$fn = null;
- $card = self::parse($data);
+ $card = OC_VObject::parse($data);
if(!is_null($card)){
foreach($card->children as $property){
if($property->name == 'FN'){
@@ -198,7 +188,7 @@ class OC_Contacts_VCard{
$oldcard = self::findWhereDAVDataIs($aid,$uri);
$fn = null;
- $card = self::parse($data);
+ $card = OC_VObject::parse($data);
if(!is_null($card)){
foreach($card->children as $property){
if($property->name == 'FN'){
@@ -249,67 +239,6 @@ class OC_Contacts_VCard{
}
/**
- * @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
* @param object $property
* @return associative array
@@ -345,7 +274,7 @@ class OC_Contacts_VCard{
$value = $property->value;
$value = htmlspecialchars($value);
if($property->name == 'ADR' || $property->name == 'N'){
- $value = self::unescapeSemicolons($value);
+ $value = OC_VObject::unescapeSemicolons($value);
}
$temp = array(
'name' => $property->name,
@@ -372,40 +301,4 @@ class OC_Contacts_VCard{
}
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'),
- );
- }
- }
}
diff --git a/apps/contacts/photo.php b/apps/contacts/photo.php
index 5178fe7a078..60dd81140bf 100644
--- a/apps/contacts/photo.php
+++ b/apps/contacts/photo.php
@@ -41,7 +41,7 @@ if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
exit();
}
-$content = OC_Contacts_VCard::parse($card['carddata']);
+$content = OC_VObject::parse($card['carddata']);
// invalid vcard
if( is_null($content)){
diff --git a/apps/contacts/templates/index.php b/apps/contacts/templates/index.php
index 630dca41b2e..649c4807dd5 100644
--- a/apps/contacts/templates/index.php
+++ b/apps/contacts/templates/index.php
@@ -15,5 +15,12 @@ OC_Util::addStyle('contacts','formtastic');
</ul>
</div>
<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>
diff --git a/apps/contacts/templates/part.property.php b/apps/contacts/templates/part.property.php
index afef4311260..6264f296743 100644
--- a/apps/contacts/templates/part.property.php
+++ b/apps/contacts/templates/part.property.php
@@ -20,7 +20,7 @@
<span style="display:none;" data-use="delete"><img class="svg action" src="<?php echo image_path('', 'actions/delete.svg'); ?>" /></span>
</p>
<?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">
<?php echo $_['property']['value']; ?>
<?php if(isset($_['property']['parameters']['TYPE']) && !empty($_['property']['parameters']['TYPE'])): ?>
diff --git a/apps/files_imageviewer/css/jquery.fancybox-1.3.4.css b/apps/files_imageviewer/css/jquery.fancybox-1.3.4.css
index 030497750b2..1dfd9b95d35 100644
--- a/apps/files_imageviewer/css/jquery.fancybox-1.3.4.css
+++ b/apps/files_imageviewer/css/jquery.fancybox-1.3.4.css
@@ -35,7 +35,7 @@
left: 0;
width: 40px;
height: 480px;
- background-image: url('../img/fancybox/fancybox.png');
+ background-image: url('../img/fancybox.png');
}
#fancybox-overlay {
@@ -282,7 +282,7 @@
#fancybox-title-over {
padding: 10px;
- background-image: url('../img/fancybox/fancy_title_over.png');
+ background-image: url('../img/fancy_title_over.png');
display: block;
}
@@ -306,7 +306,7 @@
#fancybox-title-float-left {
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 {
@@ -314,25 +314,25 @@
line-height: 29px;
font-weight: bold;
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 {
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 */
-.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-right-ico { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_nav_right.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='../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-float-left { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/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-right { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_title_right.png', sizingMethod='scale'); }
+.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='../img/fancy_title_left.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='../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 {
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');
}
-#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 */
.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-ne { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/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-se { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/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-sw { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/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-nw { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_nw.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='../img/fancy_shadow_ne.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='../img/fancy_shadow_se.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='../img/fancy_shadow_sw.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='../img/fancy_shadow_nw.png', sizingMethod='scale'); }
diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php
index c175142319f..a675175a8be 100644
--- a/apps/files_sharing/appinfo/app.php
+++ b/apps/files_sharing/appinfo/app.php
@@ -5,7 +5,6 @@ require_once('apps/files_sharing/sharedstorage.php');
OC::$CLASSPATH['OC_Share'] = "apps/files_sharing/lib_share.php";
OC_Hook::connect("OC_Filesystem", "post_delete", "OC_Share", "deleteItem");
OC_Hook::connect("OC_Filesystem", "post_rename", "OC_Share", "renameItem");
-OC_Filesystem::registerStorageType("shared", "OC_Filestorage_Shared", array("datadir" => "string"));
OC_Util::addScript("files_sharing", "share");
OC_Util::addScript("3rdparty", "chosen/chosen.jquery.min");
OC_Util::addStyle( 'files_sharing', 'sharing' );
diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php
index cde33fd1dc5..c1957d7b6c4 100644
--- a/apps/files_sharing/lib_share.php
+++ b/apps/files_sharing/lib_share.php
@@ -89,8 +89,8 @@ class OC_Share {
}
$query->execute(array($uid_owner, $uid, $source, $target, $permissions));
// Clear the folder size cache for the 'Shared' folder
- $clearFolderSize = OC_DB::prepare("DELETE FROM *PREFIX*foldersize WHERE path = ?");
- $clearFolderSize->execute(array($sharedFolder));
+// $clearFolderSize = OC_DB::prepare("DELETE FROM *PREFIX*foldersize WHERE path = ?");
+// $clearFolderSize->execute(array($sharedFolder));
}
}
}
diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php
index faf4e68d9b1..f7849d499f0 100644
--- a/apps/files_sharing/sharedstorage.php
+++ b/apps/files_sharing/sharedstorage.php
@@ -25,7 +25,7 @@ require_once( 'lib_share.php' );
if (!OC_Filesystem::is_dir('/Shared')) {
OC_Filesystem::mkdir('/Shared');
}
-OC_Filesystem::mount('shared',array('datadir'=>'/'.OC_User::getUser().'/files/Shared'),'/'.OC_User::getUser().'/files/Shared/');
+OC_Filesystem::mount('OC_Filestorage_Shared',array('datadir'=>'/'.OC_User::getUser().'/files/Shared'),'/'.OC_User::getUser().'/files/Shared/');
/**
* Convert target path to source path and pass the function call to the correct storage provider
@@ -172,19 +172,9 @@ class OC_Filestorage_Shared extends OC_Filestorage {
// TODO fill in other components of array
public function stat($path) {
if ($path == "" || $path == "/") {
- $stat["dev"] = "";
- $stat["ino"] = "";
- $stat["mode"] = "";
- $stat["nlink"] = "";
- $stat["uid"] = "";
- $stat["gid"] = "";
- $stat["rdev"] = "";
$stat["size"] = $this->filesize($path);
- $stat["atime"] = $this->fileatime($path);
$stat["mtime"] = $this->filemtime($path);
$stat["ctime"] = $this->filectime($path);
- $stat["blksize"] = "";
- $stat["blocks"] = "";
return $stat;
} else {
$source = $this->getSource($path);
@@ -221,18 +211,7 @@ class OC_Filestorage_Shared extends OC_Filestorage {
}
public function getFolderSize($path) {
- // Shared folder sizes are cached separately from the source folder sizes because folders can have different names
- $path = rtrim($path, "/");
- $path = ltrim($path, "/");
- $path = preg_replace('{(/)\1+}', "/", $path);
- $dbpath = rtrim($this->datadir.$path, "/");
- $query = OC_DB::prepare("SELECT size FROM *PREFIX*foldersize WHERE path = ?");
- $size = $query->execute(array($dbpath))->fetchAll();
- if (count($size) > 0) {
- return $size[0]['size'];
- } else {
- return $this->calculateFolderSize($path);
- }
+ return 0; //depricated
}
private function calculateFolderSize($path) {
@@ -253,8 +232,8 @@ class OC_Filestorage_Shared extends OC_Filestorage {
}
if ($size > 0) {
$dbpath = rtrim($this->datadir.$path, "/");
- $query = OC_DB::prepare("INSERT INTO *PREFIX*foldersize VALUES(?,?)");
- $result = $query->execute(array($dbpath, $size));
+// $query = OC_DB::prepare("INSERT INTO *PREFIX*foldersize VALUES(?,?)");
+// $result = $query->execute(array($dbpath, $size));
}
}
return $size;
@@ -267,8 +246,8 @@ class OC_Filestorage_Shared extends OC_Filestorage {
$path = dirname($path);
}
$dbpath = rtrim($this->datadir.$path, "/");
- $query = OC_DB::prepare("DELETE FROM *PREFIX*foldersize WHERE path = ?");
- $result = $query->execute(array($dbpath));
+// $query = OC_DB::prepare("DELETE FROM *PREFIX*/*foldersize*/ WHERE path = ?");
+// $result = $query->execute(array($dbpath));
if ($path != "/" && $path != "") {
$parts = explode("/", $path);
$part = array_pop($parts);
@@ -322,8 +301,8 @@ class OC_Filestorage_Shared extends OC_Filestorage {
$ctime = $tempctime;
}
}
- return $ctime;
}
+ return $ctime;
} else {
$source = $this->getSource($path);
if ($source) {
@@ -343,8 +322,8 @@ class OC_Filestorage_Shared extends OC_Filestorage {
$mtime = $tempmtime;
}
}
- return $mtime;
}
+ return $mtime;
} else {
$source = $this->getSource($path);
if ($source) {
@@ -354,27 +333,6 @@ class OC_Filestorage_Shared extends OC_Filestorage {
}
}
- public function fileatime($path) {
- if ($path == "" || $path == "/") {
- $atime = 0;
- if ($dh = $this->opendir($path)) {
- while (($filename = readdir($dh)) !== false) {
- $tempatime = $this->fileatime($filename);
- if ($tempatime > $atime) {
- $atime = $tempatime;
- }
- }
- return $atime;
- }
- } else {
- $source = $this->getSource($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->fileatime($this->getInternalPath($source));
- }
- }
- }
-
public function file_get_contents($path) {
$source = $this->getSource($path);
if ($source) {
@@ -503,23 +461,10 @@ class OC_Filestorage_Shared extends OC_Filestorage {
}
}
- public function fromUploadedFile($tmpFile, $path) {
- if ($this->is_writeable($path)) {
- $source = $this->getSource($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- $result = $storage->fromUploadedFile($tmpFile, $this->getInternalPath($source));
- if ($result) {
- $this->clearFolderSizeCache($path);
- }
- return $result;
- }
- } else {
- return false;
- }
- }
-
public function getMimeType($path) {
+ if ($path2 == "" || $path2 == "/") {
+ return 'httpd/unix-directory';
+ }
$source = $this->getSource($path);
if ($source) {
$storage = OC_Filesystem::getStorage($source);
diff --git a/apps/files_texteditor/ajax/savefile.php b/apps/files_texteditor/ajax/savefile.php
index f1a2bafc12b..a9777eb4133 100644
--- a/apps/files_texteditor/ajax/savefile.php
+++ b/apps/files_texteditor/ajax/savefile.php
@@ -37,7 +37,7 @@ $sessionname = sha1('oc_file_hash_'.$path);
function do_save($path,$filecontents){
$sessionname = md5('oc_file_hash_'.$path);
- OC_Filesystem::update_session_file_hash($sessionname,sha1(htmlspecialchars($filecontents)));
+ $_SESSION[$sessionname] = sha1(htmlspecialchars($filecontents));
OC_Filesystem::file_put_contents($path, $filecontents);
}
diff --git a/apps/gallery/ajax/createAlbum.php b/apps/gallery/ajax/createAlbum.php
index 610f761b72a..9413b54718a 100644
--- a/apps/gallery/ajax/createAlbum.php
+++ b/apps/gallery/ajax/createAlbum.php
@@ -3,8 +3,7 @@ require_once('../../../lib/base.php');
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('gallery');
-$stmt = OC_DB::prepare('INSERT INTO *PREFIX*gallery_albums ("uid_owner", "album_name") VALUES ("'.OC_User::getUser().'", "'.$_GET['album_name'].'")');
-$stmt->execute(array());
+OC_Gallery_Album::create(OC_User::getUser(), $_GET['album_name']);
OC_JSON::success(array('name' => $_GET['album_name']));
diff --git a/apps/gallery/ajax/getAlbums.php b/apps/gallery/ajax/getAlbums.php
index 38bea74636f..856f29344d7 100644
--- a/apps/gallery/ajax/getAlbums.php
+++ b/apps/gallery/ajax/getAlbums.php
@@ -4,13 +4,11 @@ OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('gallery');
$a = array();
-$stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_albums WHERE `uid_owner` = ?');
-$result = $stmt->execute(array(OC_User::getUser()));
+$result = OC_Gallery_Album::find(OC_User::getUser());
while ($r = $result->fetchRow()) {
$album_name = $r['album_name'];
- $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_photos WHERE `album_id` = ?');
- $tmp_res = $stmt->execute(array($r['album_id']));
+ $tmp_res = OC_Gallery_Photo::find($r['album_id']);
$a[] = array('name' => $album_name, 'numOfItems' => min($tmp_res->numRows(), 10));
}
diff --git a/apps/gallery/ajax/getCovers.php b/apps/gallery/ajax/getCovers.php
index b9c7558a53c..db7c8e9fcde 100644
--- a/apps/gallery/ajax/getCovers.php
+++ b/apps/gallery/ajax/getCovers.php
@@ -18,7 +18,7 @@ function CroppedThumbnail($imgSrc,$thumbnail_width,$thumbnail_height, $tgtImg, $
default:
exit();
}
- if(!$myImage) exit();
+ if(!$myImage) exit();
$ratio_orig = $width_orig/$height_orig;
if ($thumbnail_width/$thumbnail_height > $ratio_orig) {
@@ -44,15 +44,19 @@ function CroppedThumbnail($imgSrc,$thumbnail_width,$thumbnail_height, $tgtImg, $
$box_size = 200;
$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 = $stmt->execute(array(OC_User::getUser(), $album_name));
+$result = OC_Gallery_Photo::findForAlbum(OC_User::getUser(), $album_name);
$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;
while (($i = $result->fetchRow()) && $counter < $numOfItems) {
- $imagePath = OC::$CONFIG_DATADIRECTORY . $i['file_path'];
+ $imagePath = OC_Filesystem::getLocalFile($i['file_path']);
if(file_exists($imagePath))
{
CroppedThumbnail($imagePath, $box_size, $box_size, $targetImg, $counter*$box_size);
@@ -65,7 +69,7 @@ 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=3600, must-revalidate');
+header('Cache-Control: max-age='.$offset.', must-revalidate');
header('Pragma: public');
imagepng($targetImg);
diff --git a/apps/gallery/ajax/scanForAlbums.php b/apps/gallery/ajax/scanForAlbums.php
index de0b141a367..ff696804b00 100644
--- a/apps/gallery/ajax/scanForAlbums.php
+++ b/apps/gallery/ajax/scanForAlbums.php
@@ -3,9 +3,8 @@
require_once('../../../lib/base.php');
OC_JSON::checkLoggedIn();
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')))));
?>
diff --git a/apps/gallery/ajax/thumbnail.php b/apps/gallery/ajax/thumbnail.php
index a1416452932..d937691fa03 100644
--- a/apps/gallery/ajax/thumbnail.php
+++ b/apps/gallery/ajax/thumbnail.php
@@ -49,12 +49,19 @@ function CroppedThumbnail($imgSrc,$thumbnail_width,$thumbnail_height) { //$imgSr
$box_size = 200;
$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($tmp, $box_size, $box_size);
+ $image = CroppedThumbnail($imagePath, $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);
imagedestroy($image);
-} \ No newline at end of file
+}
diff --git a/apps/gallery/appinfo/app.php b/apps/gallery/appinfo/app.php
index 8f855c470e5..2b1ab857afc 100644
--- a/apps/gallery/appinfo/app.php
+++ b/apps/gallery/appinfo/app.php
@@ -1,4 +1,8 @@
<?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(
'order' => 20,
'id' => 'gallery',
diff --git a/apps/gallery/css/styles.css b/apps/gallery/css/styles.css
index 03b179138e6..e23d822fec7 100644
--- a/apps/gallery/css/styles.css
+++ b/apps/gallery/css/styles.css
@@ -1,13 +1,22 @@
div#gallery_list {
margin: 90pt 20pt;
}
+div#gallery_list.leftcontent {
+ padding-top: 15px;
+ margin: 0;
+ text-align: center;
+}
div#gallery_album_box {
width: 200px;
text-align: center;
border: 0;
- float: left;
+ display: inline-block;
margin: 5pt;
+ vertical-align: top;
+}
+.leftcontent div#gallery_album_box {
+ margin: 5px;
}
div#gallery_album_box h1 {
@@ -21,3 +30,6 @@ div#gallery_album_cover {
border: solid 1px black;
}
+#gallery_images {
+padding:10px 5px;
+}
diff --git a/apps/gallery/index.php b/apps/gallery/index.php
index 87fdafcf13c..2c409089ebe 100644
--- a/apps/gallery/index.php
+++ b/apps/gallery/index.php
@@ -7,8 +7,7 @@ OC_App::setActiveNavigationEntry( 'gallery_index' );
if (!isset($_GET['view'])) {
- $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_albums WHERE uid_owner = ?');
- $result = $stmt->execute(array(OC_User::getUser()));
+ $result = OC_Gallery_Album::find(OC_User::getUser());
$r = array();
while ($row = $result->fetchRow())
@@ -18,9 +17,7 @@ if (!isset($_GET['view'])) {
$tmpl->assign('r', $r);
$tmpl->printPage();
} 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 = $stmt->execute(array(OC_User::getUser(), $_GET['view']));
+ $result = OC_Gallery_Photo::findForAlbum(OC_User::getUser(), $_GET['view']);
$photos = array();
while ($p = $result->fetchRow())
diff --git a/apps/gallery/lib/album.php b/apps/gallery/lib/album.php
new file mode 100644
index 00000000000..6ddfe46de3d
--- /dev/null
+++ b/apps/gallery/lib/album.php
@@ -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);
+ }
+}
diff --git a/apps/gallery/lib/photo.php b/apps/gallery/lib/photo.php
new file mode 100644
index 00000000000..97d159935f5
--- /dev/null
+++ b/apps/gallery/lib/photo.php
@@ -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));
+ }
+}
diff --git a/apps/gallery/lib_scanner.php b/apps/gallery/lib/scanner.php
index 1231de3f3c4..1590051c48d 100644
--- a/apps/gallery/lib_scanner.php
+++ b/apps/gallery/lib/scanner.php
@@ -1,9 +1,6 @@
<?php
-require_once('base.php'); // base lib
-
-class OC_GALLERY_SCANNER {
-
+class OC_Gallery_Scanner {
public static function scan($root) {
$albums = array();
self::scanDir($root, $albums);
@@ -24,26 +21,21 @@ class OC_GALLERY_SCANNER {
} elseif (self::isPhoto($path.'/'.$filename)) {
$current_album['images'][] = $filepath;
}
- }
+ }
}
$current_album['imagesCount'] = count($current_album['images']);
$albums[] = $current_album;
- $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']));
+ $result = OC_Gallery_Album::find(OC_User::getUser(), $current_album['name']);
if ($result->numRows() == 0 && count($current_album['images'])) {
- $stmt = OC_DB::prepare('INSERT INTO *PREFIX*gallery_albums (`uid_owner`, `album_name`) VALUES (?, ?)');
- $stmt->execute(array(OC_User::getUser(), $current_album['name']));
+ OC_Gallery_Album::create(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 = $albumId['album_id'];
foreach ($current_album['images'] as $img) {
- $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_photos WHERE `album_id` = ? AND `file_path` = ?');
- $result = $stmt->execute(array($albumId, $img));
+ $result = OC_Gallery_Photo::find($albumId, $img);
if ($result->numRows() == 0) {
- $stmt = OC_DB::prepare('INSERT INTO *PREFIX*gallery_photos (`album_id`, `file_path`) VALUES (?, ?)');
- $stmt->execute(array($albumId, $img));
+ OC_Gallery_Photo::create($albumId, $img);
}
}
}
diff --git a/apps/gallery/templates/view_album.php b/apps/gallery/templates/view_album.php
index 230e2a5c21d..ae43e2fc557 100644
--- a/apps/gallery/templates/view_album.php
+++ b/apps/gallery/templates/view_album.php
@@ -1,5 +1,6 @@
<?php
OC_Util::addStyle('gallery', 'styles');
+OC_Util::addScript('gallery', 'albums');
OC_Util::addScript('gallery', 'album_cover');
OC_Util::addScript('files_imageviewer', 'jquery.mousewheel-3.0.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">
<a href="?"><input type="button" value="Back" /></a><br/>
</div>
-<div id="gallery_list">
+
+<div id="gallery_list" class="leftcontent">
+</div>
+
+<div id="gallery_images" class="rightcontent">
<?php
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
}
?>
-
</div>
diff --git a/apps/remoteStorage/compat.php b/apps/remoteStorage/WebDAV.php
index 445257320c6..e048d19e8f2 100644
--- a/apps/remoteStorage/compat.php
+++ b/apps/remoteStorage/WebDAV.php
@@ -52,14 +52,11 @@ if(isset($_SERVER['HTTP_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
+// 0/ 1 / 2 / 3...
+// /$ownCloudUser/remoteStorage/$category/
-if(count($pathParts) >= 8 && $pathParts[0] == '' && $pathParts[2] == 'remoteStorage' && $pathParts[3] == 'webdav') {
- list($dummy0, $ownCloudUser, $dummy2, $dummy3, $userHost, $userName, $dataScope) = $pathParts;
+if(count($pathParts) >= 3 && $pathParts[0] == '') {
+ list($dummy, $ownCloudUser, $dummy2, $category) = $pathParts;
OC_Util::setupFS($ownCloudUser);
@@ -68,10 +65,10 @@ if(count($pathParts) >= 8 && $pathParts[0] == '' && $pathParts[2] == 'remoteStor
$server = new Sabre_DAV_Server($publicDir);
// Path to our script
- $server->setBaseUri(OC::$WEBROOT."/apps/remoteStorage/compat.php/$ownCloudUser");
+ $server->setBaseUri(OC::$WEBROOT."/apps/remoteStorage/WebDAV.php/$ownCloudUser");
// 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
$server->addPlugin($authPlugin);
@@ -83,41 +80,6 @@ if(count($pathParts) >= 8 && $pathParts[0] == '' && $pathParts[2] == 'remoteStor
// And off we go!
$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 {
- 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));
}
diff --git a/apps/remoteStorage/appinfo/database.xml b/apps/remoteStorage/appinfo/database.xml
index b4e1ac7d8af..00ee4942744 100644
--- a/apps/remoteStorage/appinfo/database.xml
+++ b/apps/remoteStorage/appinfo/database.xml
@@ -29,14 +29,7 @@
<length>64</length>
</field>
<field>
- <name>dataScope</name>
- <type>text</type>
- <default></default>
- <notnull>true</notnull>
- <length>64</length>
- </field>
- <field>
- <name>userAddress</name>
+ <name>category</name>
<type>text</type>
<default></default>
<notnull>true</notnull>
diff --git a/apps/remoteStorage/appinfo/info.xml b/apps/remoteStorage/appinfo/info.xml
index a20c6ff4cd4..8179ca99112 100644
--- a/apps/remoteStorage/appinfo/info.xml
+++ b/apps/remoteStorage/appinfo/info.xml
@@ -3,7 +3,7 @@
<id>remoteStorage</id>
<name>remoteStorage compatibility</name>
<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>
<author>Michiel de Jong</author>
<require>2</require>
diff --git a/apps/remoteStorage/auth.php b/apps/remoteStorage/auth.php
new file mode 100644
index 00000000000..85421ba3d88
--- /dev/null
+++ b/apps/remoteStorage/auth.php
@@ -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));
+}
diff --git a/apps/remoteStorage/lib_remoteStorage.php b/apps/remoteStorage/lib_remoteStorage.php
index 4bbadafe7d2..4f19310904e 100644
--- a/apps/remoteStorage/lib_remoteStorage.php
+++ b/apps/remoteStorage/lib_remoteStorage.php
@@ -1,26 +1,25 @@
<?php
class OC_remoteStorage {
- public static function getValidTokens($ownCloudUser, $userAddress, $dataScope) {
- $query=OC_DB::prepare("SELECT token,appUrl FROM *PREFIX*authtoken WHERE user=? AND userAddress=? AND dataScope=? LIMIT 100");
- $result=$query->execute(array($ownCloudUser,$userAddress,$dataScope));
+ public static function getValidTokens($ownCloudUser, $category) {
+ $query=OC_DB::prepare("SELECT token,appUrl FROM *PREFIX*authtoken WHERE user=? AND category=? LIMIT 100");
+ $result=$query->execute(array($ownCloudUser,$category));
$ret = array();
while($row=$result->fetchRow()){
- $ret[$row['token']]=$userAddress;
+ $ret[$row['token']]=true;
}
return $ret;
}
public static function getAllTokens() {
$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));
$ret = array();
while($row=$result->fetchRow()){
$ret[$row['token']] = array(
'appUrl' => $row['appurl'],
- 'userAddress' => $row['useraddress'],
- 'dataScope' => $row['datascope'],
+ 'category' => $row['category'],
);
}
return $ret;
@@ -31,24 +30,23 @@ class OC_remoteStorage {
$query=OC_DB::prepare("DELETE FROM *PREFIX*authtoken WHERE token=? AND 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();
- $query=OC_DB::prepare("INSERT INTO *PREFIX*authtoken (`token`,`appUrl`,`user`,`userAddress`,`dataScope`) VALUES(?,?,?,?,?)");
- $result=$query->execute(array($token,$appUrl,$user,$userAddress,$dataScope));
+ $query=OC_DB::prepare("INSERT INTO *PREFIX*authtoken (`token`,`appUrl`,`user`,`category`) VALUES(?,?,?,?)");
+ $result=$query->execute(array($token,$appUrl,$user,$category));
}
- public static function createDataScope($appUrl, $userAddress, $dataScope){
+ public static function createCategory($appUrl, $category) {
$token=uniqid();
- self::addToken($token, $appUrl, $userAddress, $dataScope);
- //TODO: input checking on $userAddress and $dataScope
- list($userName, $userHost) = explode('@', $userAddress);
+ self::addToken($token, $appUrl, $category);
+ //TODO: input checking on $category
OC_Util::setupFS(OC_User::getUser());
- $scopePathParts = array('remoteStorage', 'webdav', $userHost, $userName, $dataScope);
+ $scopePathParts = array('remoteStorage', $category);
for($i=0;$i<=count($scopePathParts);$i++){
$thisPath = '/'.implode('/', array_slice($scopePathParts, 0, $i));
if(!OC_Filesystem::file_exists($thisPath)) {
OC_Filesystem::mkdir($thisPath);
}
}
- return $token;
+ return base64_encode('remoteStorage:'.$token);
}
}
diff --git a/apps/remoteStorage/oauth_ro_auth.php b/apps/remoteStorage/oauth_ro_auth.php
index b785d85fead..5403fbe20c9 100644
--- a/apps/remoteStorage/oauth_ro_auth.php
+++ b/apps/remoteStorage/oauth_ro_auth.php
@@ -13,6 +13,7 @@
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @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 {
private $validTokens;
@@ -52,7 +53,7 @@ die('not getting in with "'.$username.'"/"'.$password.'"!');
$auth->setRealm($realm);
$userpass = $auth->getUserPass();
if (!$userpass) {
- if(in_array($_SERVER['REQUEST_METHOD'], array('GET', 'HEAD', 'OPTIONS'))) {
+ if(in_array($_SERVER['REQUEST_METHOD'], array('OPTIONS'))) {
$userpass = array('', '');
} else {
$auth->requireLogin();
diff --git a/apps/user_webfinger/webfinger.php b/apps/user_webfinger/webfinger.php
index 349afaba507..d695a833f31 100644
--- a/apps/user_webfinger/webfinger.php
+++ b/apps/user_webfinger/webfinger.php
@@ -22,10 +22,20 @@ if($_GET['q']) {
if(substr($userName, 0, 5) == 'acct:') {
$userName = substr($userName, 5);
}
+if($_SERVER['HTTPS']) {
+ $baseAddress = 'https://'.$_SERVER['SERVER_NAME'].'/apps/remoteStorage/';
+} else {
+ $baseAddress = 'http://'.$_SERVER['SERVER_NAME'].'/apps/remoteStorage/';
+}
echo "<";
?>
?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">
<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>
diff --git a/db_structure.xml b/db_structure.xml
index ddb8c44d19d..39dea564b0f 100644
--- a/db_structure.xml
+++ b/db_structure.xml
@@ -43,11 +43,20 @@
<table>
- <name>*dbprefix*foldersize</name>
+ <name>*dbprefix*fscache</name>
<declaration>
<field>
+ <name>id</name>
+ <autoincrement>1</autoincrement>
+ <type>integer</type>
+ <default>0</default>
+ <notnull>true</notnull>
+ <length>4</length>
+ </field>
+
+ <field>
<name>path</name>
<type>text</type>
<default></default>
@@ -56,6 +65,24 @@
</field>
<field>
+ <name>parent</name>
+ <type>integer</type>
+ <default>
+ </default>
+ <notnull>true</notnull>
+ <length>4</length>
+ </field>
+
+ <field>
+ <name>name</name>
+ <type>text</type>
+ <default>
+ </default>
+ <notnull>true</notnull>
+ <length>512</length>
+ </field>
+
+ <field>
<name>size</name>
<type>integer</type>
<default></default>
@@ -63,14 +90,87 @@
<length>4</length>
</field>
+ <field>
+ <name>ctime</name>
+ <type>integer</type>
+ <default>
+ </default>
+ <notnull>true</notnull>
+ <length>4</length>
+ </field>
+
+ <field>
+ <name>mtime</name>
+ <type>integer</type>
+ <default>
+ </default>
+ <notnull>true</notnull>
+ <length>4</length>
+ </field>
+
+ <field>
+ <name>mimetype</name>
+ <type>text</type>
+ <default>
+ </default>
+ <notnull>true</notnull>
+ <length>32</length>
+ </field>
+
+ <field>
+ <name>mimepart</name>
+ <type>text</type>
+ <default>
+ </default>
+ <notnull>true</notnull>
+ <length>32</length>
+ </field>
+
+ <field>
+ <name>encrypted</name>
+ <type>integer</type>
+ <default>0</default>
+ <notnull>true</notnull>
+ <length>1</length>
+ </field>
+
+ <field>
+ <name>versioned</name>
+ <type>integer</type>
+ <default>0</default>
+ <notnull>true</notnull>
+ <length>1</length>
+ </field>
+
<index>
<name>path_index</name>
+ <unique>true</unique>
<field>
<name>path</name>
<sorting>ascending</sorting>
</field>
</index>
+ <index>
+ <name>parent_index</name>
+ <field>
+ <name>parent</name>
+ <sorting>ascending</sorting>
+ </field>
+ </index>
+
+ <index>
+ <name>parent_name_index</name>
+ <field>
+ <name>parent</name>
+ <sorting>ascending</sorting>
+ </field>
+ <field>
+ <name>name</name>
+ <sorting>ascending</sorting>
+ </field>
+ </index>
+
</declaration>
</table>
diff --git a/files/ajax/scan.php b/files/ajax/scan.php
new file mode 100644
index 00000000000..dec949a819b
--- /dev/null
+++ b/files/ajax/scan.php
@@ -0,0 +1,16 @@
+<?php
+
+require_once '../../lib/base.php';
+
+$force=isset($_GET['force']) and $_GET['force']=='true';
+$checkOnly=isset($_GET['checkonly']) and $_GET['checkonly']=='true';
+
+//create the file cache if necesary
+if($force or !OC_FileCache::inCache('')){
+ if(!$checkOnly){
+ OC_FileCache::scan('');
+ }
+ OC_JSON::success(array("data" => array( "done" => true)));
+}else{
+ OC_JSON::success(array("data" => array( "done" => false)));
+} \ No newline at end of file
diff --git a/files/ajax/upload.php b/files/ajax/upload.php
index 041ec0c92e3..d9dafde7779 100644
--- a/files/ajax/upload.php
+++ b/files/ajax/upload.php
@@ -46,7 +46,7 @@ if(strpos($dir,'..') === false){
$fileCount=count($files['name']);
for($i=0;$i<$fileCount;$i++){
$target=stripslashes($dir) . $files['name'][$i];
- if(OC_Filesystem::fromUploadedFile($files['tmp_name'][$i],$target)){
+ if(is_uploaded_file($files['tmp_name'][$i]) and OC_Filesystem::fromTmpFile($files['tmp_name'][$i],$target)){
$result[]=array( "status" => "success", 'mime'=>OC_Filesystem::getMimeType($target),'size'=>OC_Filesystem::filesize($target),'name'=>$files['name'][$i]);
}
}
diff --git a/files/css/files.css b/files/css/files.css
index 22f4810d0a6..39f0b9fe780 100644
--- a/files/css/files.css
+++ b/files/css/files.css
@@ -73,4 +73,6 @@ table thead.fixed { height:2em; }
/* add breadcrumb divider to the File item in navigation panel */
#navigation>ul>li:first-child { background:url('../../core/img/breadcrumb-start.svg') no-repeat 12.5em 0px; width:12.5em; padding-right:1em; position:fixed; }
-#navigation>ul>li:first-child+li { padding-top:2.9em; } \ No newline at end of file
+#navigation>ul>li:first-child+li { padding-top:2.9em; }
+
+#scanning-message{ top:40%; left:40%; position:absolute; display:none } \ No newline at end of file
diff --git a/files/js/files.js b/files/js/files.js
index 5a528f5122c..b500ecfed70 100644
--- a/files/js/files.js
+++ b/files/js/files.js
@@ -336,8 +336,27 @@ $(document).ready(function() {
$('#new>a').click();
});
});
+
+ //check if we need to scan the filesystem
+ $.get(OC.filePath('files','ajax','scan.php'),{checkonly:'true'}, function(response) {
+ if(response.data.done){
+ scanFiles();
+ }
+ }, "json");
});
+function scanFiles(force){
+ force=!!force; //cast to bool
+ $('#scanning-message').show();
+ $.get(OC.filePath('files','ajax','scan.php'),{force:force}, function(response) {
+ if(response && response.data && response.data.done){
+ window.location.reload();
+ }else{
+ alert('error')
+ }
+ }, "json");
+}
+
function boolOperationFinished(data, callback) {
result = jQuery.parseJSON(data.responseText);
if(result.status == 'success'){
diff --git a/files/templates/index.php b/files/templates/index.php
index 722c38e4776..21a4e2df010 100644
--- a/files/templates/index.php
+++ b/files/templates/index.php
@@ -63,3 +63,8 @@ if (isset($_['files'])) {
<?php echo $l->t('The files you are trying to upload exceed the maximum size for file uploads on this server.');?>
</p>
</div>
+<div id="scanning-message">
+ <p>
+ <?php echo $l->t('Files are being scanned, please wait.');?>
+ </p>
+</div>
diff --git a/files/templates/part.list.php b/files/templates/part.list.php
index 46830ba3a37..7ae5756c22e 100644
--- a/files/templates/part.list.php
+++ b/files/templates/part.list.php
@@ -5,8 +5,8 @@
$relative_modified_date = relative_modified_date($file['mtime']);
$relative_date_color = round((time()-$file['mtime'])/60/60/24*14); // the older the file, the brighter the shade of grey; days*14
if($relative_date_color>200) $relative_date_color = 200; ?>
- <tr data-file="<?php echo str_replace('+','%20',urlencode($file['name']));?>" data-type="<?php echo ($file['type'] == 'dir')?'dir':'file'?>" data-mime="<?php echo $file['mime']?>" data-size='<?php echo $file['size'];?>'>
- <td class="filename svg" style="background-image:url(<?php if($file['type'] == 'dir') echo mimetype_icon('dir'); else echo mimetype_icon($file['mime']); ?>)">
+ <tr data-file="<?php echo str_replace('+','%20',urlencode($file['name']));?>" data-type="<?php echo ($file['type'] == 'dir')?'dir':'file'?>" data-mime="<?php echo $file['mimetype']?>" data-size='<?php echo $file['size'];?>'>
+ <td class="filename svg" style="background-image:url(<?php if($file['type'] == 'dir') echo mimetype_icon('dir'); else echo mimetype_icon($file['mimetype']); ?>)">
<?php if(!isset($_['readonly']) || !$_['readonly']) { ?><input type="checkbox" /><?php } ?>
<a class="name" href="<?php if($file['type'] == 'dir') echo $_['baseURL'].$file['directory'].'/'.$file['name']; else echo $_['downloadURL'].urlencode($file['directory']).'/'.urlencode($file['name']); ?>" title="">
<span class="nametext">
diff --git a/lib/app.php b/lib/app.php
index b017ca7532f..2e03db6c8d2 100644
--- a/lib/app.php
+++ b/lib/app.php
@@ -223,7 +223,7 @@ class OC_App{
// 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" ));
// 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" ));
}
diff --git a/lib/base.php b/lib/base.php
index 548cc09823d..f1303c298e0 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -174,9 +174,6 @@ class OC{
OC_User::useBackend( OC_Config::getValue( "userbackend", "database" ));
OC_Group::setBackend( OC_Config::getValue( "groupbackend", "database" ));
- // Was in required file ... put it here
- OC_Filesystem::registerStorageType('local','OC_Filestorage_Local',array('datadir'=>'string'));
-
// Set up file system unless forbidden
global $RUNTIME_NOSETUPFS;
if(!$RUNTIME_NOSETUPFS ){
diff --git a/lib/db.php b/lib/db.php
index 0fee5e03816..16d477d1b86 100644
--- a/lib/db.php
+++ b/lib/db.php
@@ -491,7 +491,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()){
$this->lastArguments=$input;
diff --git a/lib/filecache.php b/lib/filecache.php
new file mode 100644
index 00000000000..928fc02e669
--- /dev/null
+++ b/lib/filecache.php
@@ -0,0 +1,353 @@
+<?php
+
+/**
+* @author Robin Appelman
+* @copyright 2011 Robin Appelman icewind1991@gmail.com
+*
+* 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/>.
+*
+*/
+
+/**
+ * provide caching for filesystem info in the database
+ *
+ * not used by OC_Filesystem for reading filesystem info,
+ * instread apps should use OC_FileCache::get where possible
+ *
+ * It will try to keep the data up to date but changes from outside ownCloud can invalidate the cache
+ */
+class OC_FileCache{
+ /**
+ * get the filesystem info from the cache
+ * @param string path
+ * @return array
+ *
+ * returns an assiciative array with the following keys:
+ * - size
+ * - mtime
+ * - ctime
+ * - mimetype
+ * - encrypted
+ * - versioned
+ */
+ public static function get($path){
+ $path=OC_Filesystem::getRoot().$path;
+ $query=OC_DB::prepare('SELECT ctime,mtime,mimetype,size,encrypted,versioned FROM *PREFIX*fscache WHERE path=?');
+ $result=$query->execute(array($path))->fetchRow();
+ if(is_array($result)){
+ return $result;
+ }else{
+ OC_Log::write('file not found in cache ('.$path.')','core',OC_Log::DEBUG);
+ return false;
+ }
+ }
+
+ /**
+ * put filesystem info in the cache
+ * @param string $path
+ * @param array data
+ *
+ * $data is an assiciative array in the same format as returned by get
+ */
+ public static function put($path,$data){
+ $path=OC_Filesystem::getRoot().$path;
+ if($path=='/'){
+ $parent=-1;
+ }else{
+ $parent=self::getFileId(dirname($path));
+ }
+ $id=self::getFileId($path);
+ if($id!=-1){
+ self::update($id,$data);
+ return;
+ }
+ if(!isset($data['encrypted'])){
+ $data['encrypted']=false;
+ }
+ if(!isset($data['versioned'])){
+ $data['versioned']=false;
+ }
+ $mimePart=dirname($data['mimetype']);
+ $query=OC_DB::prepare('INSERT INTO *PREFIX*fscache(parent, name, path, size, mtime, ctime, mimetype, mimepart) VALUES(?,?,?,?,?,?,?,?)');
+ $query->execute(array($parent,basename($path),$path,$data['size'],$data['mtime'],$data['ctime'],$data['mimetype'],$mimePart));
+
+ }
+
+ /**
+ * update filesystem info of a file
+ * @param int $id
+ * @param array $data
+ */
+ private static function update($id,$data){
+ $arguments=array();
+ $queryParts=array();
+ foreach(array('size','mtime','ctime','mimetype','encrypted','versioned') as $attribute){
+ if(isset($data[$attribute])){
+ $arguments[]=$data[$attribute];
+ $queryParts[]=$attribute.'=?';
+ }
+ }
+ if(isset($data['mimetype'])){
+ $arguments[]=dirname($data['mimetype']);
+ $queryParts[]='mimepart=?';
+ }
+ $arguments[]=$id;
+ $query=OC_DB::prepare('UPDATE *PREFIX*fscache SET '.implode(' , ',$queryParts).' WHERE id=?');
+ $query->execute($arguments);
+ }
+
+ /**
+ * register a file move in the cache
+ * @param string oldPath
+ * @param string newPath
+ */
+ public static function move($oldPath,$newPath){
+ $oldPath=OC_Filesystem::getRoot().$oldPath;
+ $newPath=OC_Filesystem::getRoot().$newPath;
+ $newParent=self::getParentId($newPath);
+ $query=OC_DB::prepare('UPDATE *PREFIX*fscache SET parent=? ,name=?, path=? WHERE path=?');
+ $query->execute(array($newParent,basename($newPath),$newPath,$oldPath));
+ }
+
+ /**
+ * delete info from the cache
+ * @param string $path
+ */
+ public static function delete($path){
+ $path=OC_Filesystem::getRoot().$path;
+ $query=OC_DB::prepare('DELETE FROM *PREFIX*fscache WHERE path=?');
+ $query->execute(array($path));
+ }
+
+ /**
+ * return array of filenames matching the querty
+ * @param string $query
+ * @return array of filepaths
+ */
+ public static function search($search){
+ $query=OC_DB::prepare('SELECT path FROM *PREFIX*fscache WHERE name LIKE ?');
+ $result=$query->execute(array("%$search%"));
+ $names=array();
+ while($row=$result->fetchRow()){
+ $names[]=$row['path'];
+ }
+ return $names;
+ }
+
+ /**
+ * get all files and folders in a folder
+ * @param string path
+ * @return array
+ *
+ * returns an array of assiciative arrays with the following keys:
+ * - name
+ * - size
+ * - mtime
+ * - ctime
+ * - mimetype
+ * - encrypted
+ * - versioned
+ */
+ public static function getFolderContent($path){
+ $path=OC_Filesystem::getRoot().$path;
+ $parent=self::getFileId($path);
+ $query=OC_DB::prepare('SELECT name,ctime,mtime,mimetype,size,encrypted,versioned FROM *PREFIX*fscache WHERE parent=?');
+ $result=$query->execute(array($parent))->fetchAll();
+ if(is_array($result)){
+ return $result;
+ }else{
+ OC_Log::write('file not found in cache ('.$path.')','core',OC_Log::DEBUG);
+ return false;
+ }
+ }
+
+ /**
+ * check if a file or folder is in the cache
+ * @param string $path
+ * @return bool
+ */
+ public static function inCache($path){
+ $path=OC_Filesystem::getRoot().$path;
+ $inCache=self::getFileId($path)!=-1;
+ return $inCache;
+ }
+
+ /**
+ * get the file id as used in the cache
+ * @param string $path
+ * @return int
+ */
+ private static function getFileId($path){
+ $query=OC_DB::prepare('SELECT id FROM *PREFIX*fscache WHERE path=?');
+ $result=$query->execute(array($path))->fetchRow();
+ if(is_array($result)){
+ return $result['id'];
+ }else{
+ OC_Log::write('file not found in cache ('.$path.')','core',OC_Log::DEBUG);
+ return -1;
+ }
+ }
+
+ /**
+ * get the file id of the parent folder, taking into account '/' has no parent
+ * @param string $path
+ * @return int
+ */
+ private static function getParentId($path){
+ if($path=='/'){
+ return -1;
+ }else{
+ return self::getFileId(dirname($path));
+ }
+ }
+
+ /**
+ * called when changes are made to files
+ */
+ public static function fileSystemWatcherWrite($params){
+ $path=$params['path'];
+ $fullPath=OC_Filesystem::getRoot().$path;
+ $mimetype=OC_Filesystem::getMimeType($path);
+ if($mimetype=='httpd/unix-directory'){
+ $size=0;
+ }else{
+ $id=self::getFileId($fullPath);
+ if($id!=-1){
+ $oldInfo=self::get($path);
+ $oldSize=$oldInfo['size'];
+ }else{
+ $oldSize=0;
+ }
+ $size=OC_Filesystem::filesize($path);
+ self::increaseSize(dirname($fullPath),$size-$oldSize);
+ }
+ $mtime=OC_Filesystem::filemtime($path);
+ $ctime=OC_Filesystem::filectime($path);
+ self::put($path,array('size'=>$size,'mtime'=>$mtime,'ctime'=>$ctime,'mimetype'=>$mimetype));
+ }
+
+ /**
+ * called when files are deleted
+ */
+ public static function fileSystemWatcherDelete($params){
+ $path=$params['path'];
+ $fullPath=OC_Filesystem::getRoot().$path;
+ if(self::getFileId($fullPath)==-1){
+ return;
+ }
+ $size=OC_Filesystem::filesize($path);
+ self::increaseSize(dirname($fullPath),-$size);
+ self::delete($path);
+ }
+
+ /**
+ * called when files are deleted
+ */
+ public static function fileSystemWatcherRename($params){
+ $oldPath=$params['oldpath'];
+ $newPath=$params['newpath'];
+ $fullOldPath=OC_Filesystem::getRoot().$oldPath;
+ $fullNewPath=OC_Filesystem::getRoot().$newPath;
+ if(($id=self::getFileId($fullOldPath))!=-1){
+ $oldInfo=self::get($fullOldPath);
+ $oldSize=$oldInfo['size'];
+ }else{
+ return;
+ }
+ $size=OC_Filesystem::filesize($oldPath);
+ self::increaseSize(dirname($fullOldPath),-$oldSize);
+ self::increaseSize(dirname($fullNewPath),$oldSize);
+ self::move($oldPath,$newPath);
+ }
+
+ /**
+ * adjust the size of the parent folders
+ * @param string $path
+ * @param int $sizeDiff
+ */
+ private static function increaseSize($path,$sizeDiff){
+ while(($id=self::getFileId($path))!=-1){
+ $query=OC_DB::prepare('UPDATE *PREFIX*fscache SET size=size+? WHERE id=?');
+ $query->execute(array($sizeDiff,$id));
+ $path=dirname($path);
+ }
+ }
+
+ /**
+ * recursively scan the filesystem and fill the cache
+ * @param string $path
+ * @param bool $onlyChilds
+ */
+ public static function scan($path,$onlyChilds=false){//PROBLEM due to the order things are added, all parents are -1
+ $dh=OC_Filesystem::opendir($path);
+ $stat=OC_Filesystem::stat($path);
+ $mimetype=OC_Filesystem::getMimeType($path);
+ $stat['mimetype']=$mimetype;
+ if($path=='/'){
+ $path='';
+ }
+ self::put($path,$stat);
+ $fullPath=OC_Filesystem::getRoot().$path;
+ $totalSize=0;
+ if($dh){
+ while (($filename = readdir($dh)) !== false) {
+ if($filename != '.' and $filename != '..'){
+ $file=$path.'/'.$filename;
+ if(OC_Filesystem::is_dir($file)){
+ self::scan($file,true);
+ }else{
+ $stat=OC_Filesystem::stat($file);
+ $mimetype=OC_Filesystem::getMimeType($file);
+ $stat['mimetype']=$mimetype;
+ self::put($file,$stat);
+ $totalSize+=$stat['size'];
+ }
+ }
+ }
+ }
+ self::increaseSize($fullPath,$totalSize);
+ }
+
+ /**
+ * fine files by mimetype
+ * @param string $part1
+ * @param string $part2 (optional)
+ * @return array of file paths
+ *
+ * $part1 and $part2 together form the complete mimetype.
+ * e.g. searchByMime('text','plain')
+ *
+ * seccond mimetype part can be ommited
+ * e.g. searchByMime('audio')
+ */
+ public static function searchByMime($part1,$part2=''){
+ if($part2){
+ $query=OC_DB::prepare('SELECT path FROM *PREFIX*fscache WHERE mimepart=?');
+ $result=$query->execute(array($part1));
+ }else{
+ $query=OC_DB::prepare('SELECT path FROM *PREFIX*fscache WHERE mimetype=?');
+ $result=$query->execute(array($part1.'/'.$part2));
+ }
+ $names=array();
+ while($row=$result->fetchRow()){
+ $names[]=$row['path'];
+ }
+ return $names;
+ }
+}
+
+//watch for changes and try to keep the cache up to date
+OC_Hook::connect('OC_Filesystem','post_write','OC_FileCache','fileSystemWatcherWrite');
+OC_Hook::connect('OC_Filesystem','delete','OC_FileCache','fileSystemWatcherDelete');
+OC_Hook::connect('OC_Filesystem','rename','OC_FileCache','fileSystemWatcherRename');
diff --git a/lib/fileproxy.php b/lib/fileproxy.php
index 549b7015a6a..235fc8bf284 100644
--- a/lib/fileproxy.php
+++ b/lib/fileproxy.php
@@ -34,7 +34,7 @@
* A post-proxy recieves 2 arguments, the filepath and the result of the operation.
* The return calue of the post-proxy will be used as the new result of the operation
* The operations that have a post-proxy are
- * file_get_contents, is_file, is_dir, file_exists, stat, is_readable, is_writable, fileatime, filemtime, filectime, file_get_contents, getMimeType, hash, free_space and search
+ * file_get_contents, is_file, is_dir, file_exists, stat, is_readable, is_writable, filemtime, filectime, file_get_contents, getMimeType, hash, free_space and search
*/
class OC_FileProxy{
diff --git a/lib/files.php b/lib/files.php
index 88b559059f0..143aab5c72d 100644
--- a/lib/files.php
+++ b/lib/files.php
@@ -36,44 +36,13 @@ class OC_Files {
if(strpos($directory,OC::$CONFIG_DATADIRECTORY)===0){
$directory=substr($directory,strlen(OC::$CONFIG_DATADIRECTORY));
}
- $filesfound=true;
- $content=array();
- $dirs=array();
- $file=array();
- $files=array();
- if(OC_Filesystem::is_dir($directory)) {
- if ($dh = OC_Filesystem::opendir($directory)) {
- while (($filename = readdir($dh)) !== false) {
- if($filename<>'.' and $filename<>'..' and substr($filename,0,1)!='.'){
- $file=array();
- $filesfound=true;
- $file['name']=$filename;
- $file['directory']=$directory;
- $stat=OC_Filesystem::stat($directory.'/'.$filename);
- $file=array_merge($file,$stat);
- $file['size']=OC_Filesystem::filesize($directory.'/'.$filename);
- $file['mime']=OC_Files::getMimeType($directory .'/'. $filename);
- $file['readable']=OC_Filesystem::is_readable($directory .'/'. $filename);
- $file['writeable']=OC_Filesystem::is_writeable($directory .'/'. $filename);
- $file['type']=OC_Filesystem::filetype($directory .'/'. $filename);
- if($file['type']=='dir'){
- $dirs[$file['name']]=$file;
- }else{
- $files[$file['name']]=$file;
- }
- }
- }
- closedir($dh);
- }
+ $files=OC_FileCache::getFolderContent($directory);
+ foreach($files as &$file){
+ $file['directory']=$directory;
+ $file['type']=($file['mimetype']=='httpd/unix-directory')?'dir':'file';
}
- uksort($dirs, "strnatcasecmp");
uksort($files, "strnatcasecmp");
- $content=array_merge($dirs,$files);
- if($filesfound){
- return $content;
- }else{
- return false;
- }
+ return $files;
}
diff --git a/lib/filestorage.php b/lib/filestorage.php
index 34fa6457fd2..70aaf985b8b 100644
--- a/lib/filestorage.php
+++ b/lib/filestorage.php
@@ -39,7 +39,6 @@ class OC_Filestorage{
public function readfile($path){}
public function filectime($path){}
public function filemtime($path){}
- public function fileatime($path){}
public function file_get_contents($path){}
public function file_put_contents($path,$data){}
public function unlink($path){}
@@ -48,7 +47,6 @@ class OC_Filestorage{
public function fopen($path,$mode){}
public function toTmpFile($path){}//copy the file to a temporary file, used for cross-storage file actions
public function fromTmpFile($tmpPath,$path){}//copy a file from a temporary file, used for cross-storage file actions
- public function fromUploadedFile($tmpPath,$path){}//copy a file from a temporary file, used for cross-storage file actions
public function getMimeType($path){}
public function hash($type,$path,$raw){}
public function free_space($path){}
diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php
index 9e29f85071a..87efdb15ad2 100644
--- a/lib/filestorage/local.php
+++ b/lib/filestorage/local.php
@@ -13,13 +13,11 @@ class OC_Filestorage_Local extends OC_Filestorage{
}
public function mkdir($path){
if($return=mkdir($this->datadir.$path)){
- $this->clearFolderSizeCache($path);
}
return $return;
}
public function rmdir($path){
if($return=rmdir($this->datadir.$path)){
- $this->clearFolderSizeCache($path);
}
return $return;
}
@@ -67,20 +65,15 @@ class OC_Filestorage_Local extends OC_Filestorage{
public function filemtime($path){
return filemtime($this->datadir.$path);
}
- public function fileatime($path){
- return fileatime($this->datadir.$path);
- }
public function file_get_contents($path){
return file_get_contents($this->datadir.$path);
}
public function file_put_contents($path,$data){
if($return=file_put_contents($this->datadir.$path,$data)){
- $this->clearFolderSizeCache($path);
}
}
public function unlink($path){
$return=$this->delTree($path);
- $this->clearFolderSizeCache($path);
return $return;
}
public function rename($path1,$path2){
@@ -90,8 +83,6 @@ class OC_Filestorage_Local extends OC_Filestorage{
}
if($return=rename($this->datadir.$path1,$this->datadir.$path2)){
- $this->clearFolderSizeCache($path1);
- $this->clearFolderSizeCache($path2);
}
return $return;
}
@@ -104,7 +95,6 @@ class OC_Filestorage_Local extends OC_Filestorage{
$path2.=$source;
}
if($return=copy($this->datadir.$path1,$this->datadir.$path2)){
- $this->clearFolderSizeCache($path2);
}
return $return;
}
@@ -117,12 +107,10 @@ class OC_Filestorage_Local extends OC_Filestorage{
case 'w+':
case 'x+':
case 'a+':
- $this->clearFolderSizeCache($path);
break;
case 'w':
case 'x':
case 'a':
- $this->clearFolderSizeCache($path);
break;
}
}
@@ -185,18 +173,6 @@ class OC_Filestorage_Local extends OC_Filestorage{
$fileStats = stat($tmpFile);
if(rename($tmpFile,$this->datadir.$path)){
touch($this->datadir.$path, $fileStats['mtime'], $fileStats['atime']);
- $this->clearFolderSizeCache($path);
- return true;
- }else{
- return false;
- }
- }
-
- public function fromUploadedFile($tmpFile,$path){
- $fileStats = stat($tmpFile);
- if(move_uploaded_file($tmpFile,$this->datadir.$path)){
- touch($this->datadir.$path, $fileStats['mtime'], $fileStats['atime']);
- $this->clearFolderSizeCache($path);
return true;
}else{
return false;
@@ -212,7 +188,6 @@ class OC_Filestorage_Local extends OC_Filestorage{
if ($item == '.' || $item == '..') continue;
if(is_file($dir.'/'.$item)){
if(unlink($dir.'/'.$item)){
- $this->clearFolderSizeCache($dir);
}
}elseif(is_dir($dir.'/'.$item)){
if (!$this->delTree($dirRelative. "/" . $item)){
@@ -221,7 +196,6 @@ class OC_Filestorage_Local extends OC_Filestorage{
}
}
if($return=rmdir($dir)){
- $this->clearFolderSizeCache($dir);
}
return $return;
}
@@ -261,75 +235,6 @@ class OC_Filestorage_Local extends OC_Filestorage{
* @return int size of folder and it's content
*/
public function getFolderSize($path){
- $path=str_replace('//','/',$path);
- if($this->is_dir($path) and substr($path,-1)!='/'){
- $path.='/';
- }
- $query=OC_DB::prepare("SELECT size FROM *PREFIX*foldersize WHERE path=?");
- $size=$query->execute(array($path))->fetchAll();
- if(count($size)>0){// we already the size, just return it
- return $size[0]['size'];
- }else{//the size of the folder isn't know, calulate it
- return $this->calculateFolderSize($path);
- }
- }
-
- /**
- * @brief calulate the size of folder and it's content and cache it
- * @param string $path file path
- * @return int size of folder and it's content
- */
- public function calculateFolderSize($path){
- if($this->is_file($path)){
- $path=dirname($path);
- }
- $path=str_replace('//','/',$path);
- if($this->is_dir($path) and substr($path,-1)!='/'){
- $path.='/';
- }
- $size=0;
- if ($dh = $this->opendir($path)) {
- while (($filename = readdir($dh)) !== false) {
- if($filename!='.' and $filename!='..'){
- $subFile=$path.'/'.$filename;
- if($this->is_file($subFile)){
- $size+=$this->filesize($subFile);
- }else{
- $size+=$this->getFolderSize($subFile);
- }
- }
- }
- if($size>0){
- $query=OC_DB::prepare("INSERT INTO *PREFIX*foldersize VALUES(?,?)");
- $result=$query->execute(array($path,$size));
- }
- }
- return $size;
- }
-
- /**
- * @brief clear the folder size cache of folders containing a file
- * @param string $path
- */
- public function clearFolderSizeCache($path){
- if($this->is_file($path)){
- $path=dirname($path);
- }
- $path=str_replace('//','/',$path);
- if($this->is_dir($path) and substr($path,-1)!='/'){
- $path.='/';
- }
- $query=OC_DB::prepare("DELETE FROM *PREFIX*foldersize WHERE path = ?");
- $result=$query->execute(array($path));
- if($path!='/' and $path!=''){
- $parts=explode('/',$path);
- //pop empty part
- $part=array_pop($parts);
- if(empty($part)){
- array_pop($parts);
- }
- $parent=implode('/',$parts);
- $this->clearFolderSizeCache($parent);
- }
+ return 0;//depricated, use OC_FileCach instead
}
}
diff --git a/lib/filestorage/remote.php b/lib/filestorage/remote.php
deleted file mode 100644
index 88bdbca481c..00000000000
--- a/lib/filestorage/remote.php
+++ /dev/null
@@ -1,350 +0,0 @@
-<?php
-
-/**
-* ownCloud
-*
-* @author Frank Karlitschek
-* @copyright 2010 Frank Karlitschek karlitschek@kde.org
-*
-* 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/>.
-*
-*/
-
-class OC_Filestorage_Remote extends OC_Filestorage{
- private $url;
- private $username;
- private $password;
- private $remote=false;
- private $statCache;
- private $statCacheDir=false;
- private $changed=array();
-
- private function cacheDir($dir){
- if($this->statCacheDir!=$dir or $this->statCacheDir===false){
- $this->statCache=$this->remote->getFiles($dir);
- $keys=array_keys($this->statCache);
- $this->statCacheDir=$dir;
- }
- }
-
- public function __construct($arguments){
- $this->url=$arguments['url'];
- $this->username=$arguments['username'];
- $this->password=$arguments['password'];
- }
- private function connect(){
- if($this->remote===false){
- $this->remote=OC_Connect::connect($this->url,$this->username,$this->password);
- }
- }
- public function mkdir($path){
- $this->connect();
- $parent=dirname($path);
- $name=substr($path,strlen($parent)+1);
- $return=$this->remote->newFile($parent,$name,'dir');
- if($return){
- $this->notifyObservers($path,OC_FILEACTION_CREATE);
- }
- return $return;
- }
- public function rmdir($path){
- $this->connect();
- $parent=dirname($path);
- $name=substr($path,strlen($parent)+1);
- $return=$this->remote->delete($parent,$name);
- if($return){
- $this->notifyObservers($path,OC_FILEACTION_DELETE);
- }
- return $return;
- }
- public function opendir($path){
- $this->connect();
- $this->cacheDir($path);
- $dirs=array_keys($this->statCache);
- $id=uniqid();
- global $FAKEDIRS;
- $FAKEDIRS[$id]=$dirs;
- if($return=opendir("fakedir://$id")){
- $this->notifyObservers($path,OC_FILEACTION_READ);
- }
- return $return;
- }
- public function is_dir($path){
- $this->connect();
- $parent=dirname($path);
- $name=substr($path,strlen($parent)+1);
- $this->cacheDir($path);
- if($path=='' or $path=='/'){
- return true;
- }
- if(!isset($this->statCache[$name])){
- return false;
- }
- return ($this->statCache[$name]['type'=='dir']);
- }
- public function is_file($path){
- $this->connect();
- $parent=dirname($path);
- $name=substr($path,strlen($parent)+1);
- $this->cacheDir($parent);
- if(!isset($this->statCache[$name])){
- return false;
- }
- return ($this->statCache[$name]['type'!='dir']);
- }
- public function stat($path){
- $this->connect();
- $parent=dirname($path);
- $name=substr($path,strlen($parent)+1);
- $this->cacheDir($parent);
- if(!isset($this->statCache[$name])){
- return $false;
- }
- return $this->statCache[$name];
- }
- public function filetype($path){
- $this->connect();
- $parent=dirname($path);
- $name=substr($path,strlen($parent)+1);
- $this->cacheDir($parent);
- if(!isset($this->statCache[$name])){
- return false;
- }
- return $this->statCache[$name]['type'];
- }
- public function filesize($path){
- $this->connect();
- $parent=dirname($path);
- $name=substr($path,strlen($parent)+1);
- $this->cacheDir($parent);
- if(!isset($this->statCache[$name])){
- return $false;
- }
- return $this->statCache[$name]['size'];
- }
- public function is_readable($path){
- $this->connect();
- $parent=dirname($path);
- $name=substr($path,strlen($parent)+1);
- $this->cacheDir($parent);
- if(!isset($this->statCache[$name])){
- return false;
- }
- return $this->statCache[$name]['readable'];
- }
- public function is_writeable($path){
- $this->connect();
- $parent=dirname($path);
- $name=substr($path,strlen($parent)+1);
- $this->cacheDir($parent);
- if(!isset($this->statCache[$name])){
- return false;
- }
- return $this->statCache[$name]['writeable'];
- }
- public function file_exists($path){
- $this->connect();
- $parent=dirname($path);
- $name=substr($path,strlen($parent)+1);
- $this->cacheDir($parent);
- return isset($this->statCache[$name]);
- }
- public function readfile($path){
- $this->connect();
- $parent=dirname($path);
- $name=substr($path,strlen($parent)+1);
- $file=$this->remote->getFile($parent,$name);
- readfile($file);
- unlink($file);
- }
- public function filectime($path){
- $this->connect();
- $parent=dirname($path);
- $name=substr($path,strlen($parent)+1);
- $this->cacheDir($parent);
- if(!isset($this->statCache[$name])){
- return false;
- }
- return $this->statCache[$name]['ctime'];
- }
- public function filemtime($path){
- $this->connect();
- $parent=dirname($path);
- $name=substr($path,strlen($parent)+1);
- $this->cacheDir($parent);
- if(!isset($this->statCache[$name])){
- return false;
- }
- return $this->statCache[$name]['mtime'];
- }
- public function fileatime($path){
- $this->connect();
- $parent=dirname($path);
- $name=substr($path,strlen($parent)+1);
- $this->cacheDir($parent);
- if(!isset($this->statCache[$name])){
- return false;
- }
- return $this->statCache[$name]['atime'];
- }
- public function file_get_contents($path){
- $this->connect();
- $parent=dirname($path);
- $name=substr($path,strlen($parent)+1);
- $file=$this->remote->getFile($parent,$name);
- file_get_contents($file);
- unlink($file);
- }
- public function file_put_contents($path,$data){
- $this->connect();
- $parent=dirname($path);
- $name=substr($path,strlen($parent)+1);
- $file=$this->remote->getFile($parent,$name);
- $file=tempnam(get_temp_dir(),'oc_');
- file_put_contents($file,$data);
- if($return=$this->remote->sendTmpFile($file,$parent,$name)){
- $this->notifyObservers($path,OC_FILEACTION_WRITE);
- }
- }
- public function unlink($path){
- $this->connect();
- $parent=dirname($path);
- $name=substr($path,strlen($parent)+1);
- if($return=$this->remote->delete($paren,$name)){
- $this->notifyObservers($path,OC_FILEACTION_DELETE);
- }
- return $return;
- }
- public function rename($path1,$path2){
- $this->connect();
- $parent1=dirname($path1);
- $name1=substr($path1,strlen($parent1)+1);
- $parent2=dirname($path2);
- $name2=substr($path2,strlen($parent2)+1);
- if($return=$this->remote->move($parent1,$name1,$parent2,$name2)){
- $this->notifyObservers($path1.'->'.$path2,OC_FILEACTION_RENAME);
- }
- return $return;
- }
- public function copy($path1,$path2){
- $this->connect();
- $parent1=dirname($path1);
- $name1=substr($path1,strlen($parent1)+1);
- $parent2=dirname($path2);
- $name2=substr($path2,strlen($parent2)+1);
- if($return=$this->copy->rename($parent1,$name1,$parent2,$name2)){
- $this->notifyObservers($path1.'->'.$path2,OC_FILEACTION_RENAME);
- }
- return $return;
- }
- public function fopen($path,$mode){
- $this->connect();
- $changed=false;
- $parent=dirname($path);
- $name=substr($path,strlen($parent)+1);
- $file=$this->remote->getFile($parent,$name);
- if($return=fopen($file,$mode)){
- switch($mode){
- case 'r':
- $this->notifyObservers($path,OC_FILEACTION_READ);
- break;
- case 'r+':
- case 'w+':
- case 'x+':
- case 'a+':
- $this->notifyObservers($path,OC_FILEACTION_READ | OC_FILEACTION_WRITE);
- $this->changed[]=array('dir'=>$parent,'file'=>$name,'tmp'=>$file);
- break;
- case 'w':
- case 'x':
- case 'a':
- $this->notifyObservers($path,OC_FILEACTION_WRITE);
- $this->changed[]=array('dir'=>$parent,'file'=>$name,'tmp'=>$file);
- break;
- }
- }
- return $return;
- }
-
- public function getMimeType($path){
- $this->connect();
- $parent=dirname($path);
- $name=substr($path,strlen($parent)+1);
- if(substr($name,0,1)=='/'){
- $name=substr($name,1);
- }
- $this->cacheDir($parent);
- if(!isset($this->statCache[$name])){
- return false;
- }
- return $this->statCache[$name]['mime'];
- }
-
- public function toTmpFile($path){
- $this->connect();
- $parent=dirname($path);
- $name=substr($path,strlen($parent)+1);
- if(substr($name,0,1)=='/'){
- $name=substr($name,1);
- }
- $filename=$this->remote->getFile($parent,$name);
- if($filename){
- $this->notifyObservers($path,OC_FILEACTION_READ);
- return $filename;
- }else{
- return false;
- }
- }
-
- public function fromTmpFile($tmpFile,$path){
- $this->connect();
- $parent=dirname($path);
- $name=substr($path,strlen($parent)+1);
- if($this->remote->sendTmpFile($tmpFile,$parent,$name)){
- $this->notifyObservers($path,OC_FILEACTION_CREATE);
- return true;
- }else{
- return false;
- }
- }
-
- public function delTree($dir) {
- $this->connect();
- $parent=dirname($dir);
- $name=substr($dir,strlen($parent)+1);
- $return=$this->remote->delete($parent,$name);
- if($return=rmdir($dir)){
- $this->notifyObservers($dir,OC_FILEACTION_DELETE);
- }
- return $return;
- }
-
- public function find($path){
- return $this->getTree($path);
- }
-
- public function getTree($dir) {
- $this->connect();
- if($return=$this->remote->getTree($dir)){
- $this->notifyObservers($dir,OC_FILEACTION_READ);
- }
- return $return;
- }
-
- public function __destruct(){
- foreach($this->changed as $changed){
- $this->remote->sendTmpFile($changed['tmp'],$changed['dir'],$changed['file']);
- }
- }
-}
diff --git a/lib/filesystem.php b/lib/filesystem.php
index cae8ead5b16..c3830b34168 100644
--- a/lib/filesystem.php
+++ b/lib/filesystem.php
@@ -42,39 +42,11 @@
*
* the &run parameter can be set to false to prevent the operation from occuring
*/
+
class OC_Filesystem{
static private $storages=array();
static private $mounts=array();
static private $fakeRoot='';
- static private $storageTypes=array();
-
-
- /**
- * register a storage type
- * @param string type
- * @param string classname
- * @param array arguments an associative array in the form of name=>type (eg array('datadir'=>'string'))
- */
- static public function registerStorageType($type,$classname,$arguments){
- self::$storageTypes[$type]=array('type'=>$type,'classname'=>$classname,'arguments'=>$arguments);
- }
-
- /**
- * check if the filesystem supports a specific storagetype
- * @param string type
- * @return bool
- */
- static public function hasStorageType($type){
- return isset(self::$storageTypes[$type]);
- }
-
- /**
- * get the list of names of storagetypes that the filesystem supports
- * @return array
- */
- static public function getStorageTypeNames(){
- return array_keys(self::$storageTypes);
- }
/**
* tear down the filesystem, removing all storage providers
@@ -92,13 +64,9 @@ class OC_Filesystem{
* @param array arguments
* @return OC_Filestorage
*/
- static private function createStorage($type,$arguments){
- if(!self::hasStorageType($type)){
- return false;
- }
- $className=self::$storageTypes[$type]['classname'];
- if(class_exists($className)){
- return new $className($arguments);
+ static private function createStorage($class,$arguments){
+ if(class_exists($class)){
+ return new $class($arguments);
}else{
return false;
}
@@ -117,6 +85,14 @@ class OC_Filesystem{
}
self::$fakeRoot=$fakeRoot;
}
+
+ /**
+ * get the fake root
+ * @return string
+ */
+ static public function getRoot(){
+ return self::$fakeRoot;
+ }
/**
* get the part of the path relative to the mountpoint of the storage it's stored in
@@ -164,11 +140,11 @@ class OC_Filesystem{
* @param OC_Filestorage storage
* @param string mountpoint
*/
- static public function mount($type,$arguments,$mountpoint){
+ static public function mount($class,$arguments,$mountpoint){
if(substr($mountpoint,0,1)!=='/'){
$mountpoint='/'.$mountpoint;
}
- self::$mounts[$mountpoint]=array('type'=>$type,'arguments'=>$arguments);
+ self::$mounts[$mountpoint]=array('class'=>$class,'arguments'=>$arguments);
}
/**
@@ -181,7 +157,7 @@ class OC_Filesystem{
if($mountpoint){
if(!isset(self::$storages[$mountpoint])){
$mount=self::$mounts[$mountpoint];
- self::$storages[$mountpoint]=self::createStorage($mount['type'],$mount['arguments']);
+ self::$storages[$mountpoint]=self::createStorage($mount['class'],$mount['arguments']);
}
return self::$storages[$mountpoint];
}
@@ -233,6 +209,10 @@ class OC_Filesystem{
}
}
+ /**
+ * following functions are equivilent to their php buildin equivilents for arguments/return values.
+ */
+
static public function mkdir($path){
return self::basicOperation('mkdir',$path,array('create','write'));
}
@@ -284,9 +264,6 @@ class OC_Filesystem{
static public function filemtime($path){
return self::basicOperation('filemtime',$path);
}
- static public function fileatime($path){
- return self::basicOperation('fileatime',$path);
- }
static public function file_get_contents($path){
return self::basicOperation('file_get_contents',$path,array('read'));
}
@@ -398,26 +375,6 @@ class OC_Filesystem{
}
}
}
- static public function fromUploadedFile($tmpFile,$path){
- if(OC_FileProxy::runPreProxies('fromUploadedFile',$tmpFile,$path) and self::canWrite($path) and $storage=self::getStorage($path)){
- $run=true;
- $exists=self::file_exists($path);
- if(!$exists){
- OC_Hook::emit( 'OC_Filesystem', 'create', array( 'path' => $path, 'run' => &$run));
- }
- if($run){
- OC_Hook::emit( 'OC_Filesystem', 'write', array( 'path' => $path, 'run' => &$run));
- }
- if($run){
- $result=$storage->fromUploadedFile($tmpFile,self::getInternalPath($path));
- if(!$exists){
- OC_Hook::emit( 'OC_Filesystem', 'post_create', array( 'path' => $path));
- }
- OC_Hook::emit( 'OC_Filesystem', 'post_write', array( 'path' => $path));
- return $result;
- }
- }
- }
static public function getMimeType($path){
return self::basicOperation('getMimeType',$path);
}
@@ -433,15 +390,13 @@ class OC_Filesystem{
$files=array();
$fakeRoot=self::$fakeRoot;
$fakeRootLength=strlen($fakeRoot);
- foreach(self::$storages as $mountpoint=>$storage){
- $results=$storage->search($query);
- if(is_array($results)){
- foreach($results as $result){
- $file=str_replace('//','/',$mountpoint.$result);
- if(substr($file,0,$fakeRootLength)==$fakeRoot){
- $file=substr($file,$fakeRootLength);
- $files[]=$file;
- }
+ $results=OC_FileCache::search($query);
+ if(is_array($results)){
+ foreach($results as $result){
+ $file=str_replace('//','/',$mountpoint.$result);
+ if(substr($file,0,$fakeRootLength)==$fakeRoot){
+ $file=substr($file,$fakeRootLength);
+ $files[]=$file;
}
}
}
@@ -449,10 +404,6 @@ class OC_Filesystem{
}
- static public function update_session_file_hash($sessionname,$sessionvalue){
- $_SESSION[$sessionname] = $sessionvalue;
- }
-
/**
* abstraction for running most basic operations
* @param string $operation
@@ -490,3 +441,5 @@ class OC_Filesystem{
return null;
}
}
+
+require_once('filecache.php');
diff --git a/lib/helper.php b/lib/helper.php
index 5b3e394cafd..24d436225b7 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -160,24 +160,25 @@ class OC_Helper {
*/
public static function computerFileSize( $str ){
$bytes = 0;
+ $str=strtolower($str);
$bytes_array = array(
- 'B' => 1,
- 'K' => 1024,
- 'KB' => 1024,
- 'MB' => 1024 * 1024,
- 'M' => 1024 * 1024,
- 'GB' => 1024 * 1024 * 1024,
- 'G' => 1024 * 1024 * 1024,
- 'TB' => 1024 * 1024 * 1024 * 1024,
- 'T' => 1024 * 1024 * 1024 * 1024,
- 'PB' => 1024 * 1024 * 1024 * 1024 * 1024,
- 'P' => 1024 * 1024 * 1024 * 1024 * 1024,
+ 'b' => 1,
+ 'k' => 1024,
+ 'kb' => 1024,
+ 'mb' => 1024 * 1024,
+ 'm' => 1024 * 1024,
+ 'gb' => 1024 * 1024 * 1024,
+ 'g' => 1024 * 1024 * 1024,
+ 'tb' => 1024 * 1024 * 1024 * 1024,
+ 't' => 1024 * 1024 * 1024 * 1024,
+ 'pb' => 1024 * 1024 * 1024 * 1024 * 1024,
+ 'p' => 1024 * 1024 * 1024 * 1024 * 1024,
);
$bytes = floatval($str);
- if (preg_match('#([KMGTP]?B?)$#si', $str, $matches) && !empty($bytes_array[$matches[1]])) {
+ if (preg_match('#([kmgtp]?b?)$#si', $str, $matches) && !empty($bytes_array[$matches[1]])) {
$bytes *= $bytes_array[$matches[1]];
}
diff --git a/lib/updater.php b/lib/updater.php
index e4db719a62c..cc4a4602539 100644
--- a/lib/updater.php
+++ b/lib/updater.php
@@ -52,13 +52,9 @@ class OC_Updater{
$tmp['url'] = $data->url;
$tmp['web'] = $data->web;
-
return $tmp;
-
}
-
-
public static function ShowUpdatingHint(){
$data=OC_Updater::check();
if(isset($data['version']) and $data['version']<>'') {
@@ -67,10 +63,8 @@ class OC_Updater{
$txt='Your ownCloud is up to date';
}
return($txt);
-
}
-
/**
* do ownCloud update
*/
@@ -83,9 +77,5 @@ class OC_Updater{
//update version in config
}
-
}
-
-
-
?>
diff --git a/lib/util.php b/lib/util.php
index 0f79948bc24..466b58078ca 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -37,7 +37,7 @@ class OC_Util {
if( $user != "" ){ //if we aren't logged in, there is no use to set up the filesystem
//first set up the local "root" storage
- OC_Filesystem::mount('local',array('datadir'=>$CONFIG_DATADIRECTORY_ROOT),'/');
+ OC_Filesystem::mount('OC_Filestorage_Local',array('datadir'=>$CONFIG_DATADIRECTORY_ROOT),'/');
OC::$CONFIG_DATADIRECTORY = $CONFIG_DATADIRECTORY_ROOT."/$user/$root";
if( !is_dir( OC::$CONFIG_DATADIRECTORY )){
@@ -62,7 +62,7 @@ class OC_Util {
* @return array
*/
public static function getVersion(){
- return array(2,90,0);
+ return array(2,90,1);
}
/**
diff --git a/lib/vobject.php b/lib/vobject.php
new file mode 100644
index 00000000000..e3479fc6d36
--- /dev/null
+++ b/lib/vobject.php
@@ -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);
+ }
+}
diff --git a/owncloud.db.filesystem b/owncloud.db.filesystem
new file mode 100644
index 00000000000..082977a37ef
--- /dev/null
+++ b/owncloud.db.filesystem
Binary files differ
diff --git a/settings/ajax/setquota.php b/settings/ajax/setquota.php
index edbf5b74516..5c07285cfca 100644
--- a/settings/ajax/setquota.php
+++ b/settings/ajax/setquota.php
@@ -10,6 +10,6 @@ $quota= OC_Helper::computerFileSize($_POST["quota"]);
// Return Success story
OC_Preferences::setValue($username,'files','quota',$quota);
-OC_JSON::success(array("data" => array( "username" => $username ,'quota'=>$quota)));
+OC_JSON::success(array("data" => array( "username" => $username ,'quota'=>OC_Helper::humanFileSize($quota))));
?>
diff --git a/settings/apps.php b/settings/apps.php
index 27b4c17f9e6..12a7bf77202 100644
--- a/settings/apps.php
+++ b/settings/apps.php
@@ -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
// $catagoryNames=OC_OCSClient::getCategories();
// if(is_array($catagoryNames)){
diff --git a/settings/js/users.js b/settings/js/users.js
index 684fee21c64..4fea52e4a1f 100644
--- a/settings/js/users.js
+++ b/settings/js/users.js
@@ -101,8 +101,11 @@ $(document).ready(function(){
if($(this).val().length>0){
$.post(
OC.filePath('settings','ajax','setquota.php'),
- {username:uid,quota:$(this).val()},
- function(result){}
+ {username:uid,quota:$(this).val()},
+ function(result){
+ img.parent().children('span').text(result.data.quota)
+ $(this).parent().attr('data-quota',result.data.quota);
+ }
);
input.blur();
}else{