From b9e6f5e42d54fc91205f03f4b19bbf313278f476 Mon Sep 17 00:00:00 2001 From: Michiel de Jong Date: Wed, 7 Dec 2011 21:51:47 +0700 Subject: [PATCH 01/15] compliance with http://www.w3.org/community/unhosted/wiki/remoteStorage --- apps/remoteStorage/{compat.php => WebDAV.php} | 52 ++------- apps/remoteStorage/appinfo/database.xml | 9 +- apps/remoteStorage/auth.php | 100 ++++++++++++++++++ apps/remoteStorage/lib_remoteStorage.php | 30 +++--- apps/remoteStorage/oauth_ro_auth.php | 3 +- apps/user_webfinger/webfinger.php | 12 ++- 6 files changed, 135 insertions(+), 71 deletions(-) rename apps/remoteStorage/{compat.php => WebDAV.php} (53%) create mode 100644 apps/remoteStorage/auth.php diff --git a/apps/remoteStorage/compat.php b/apps/remoteStorage/WebDAV.php similarity index 53% rename from apps/remoteStorage/compat.php rename to apps/remoteStorage/WebDAV.php index 445257320c..e048d19e8f 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 ' - .'' - .', close the pop-up, and ' - .'
'); - } - } else { - echo '
'; - } } 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 b4e1ac7d8a..00ee494274 100644 --- a/apps/remoteStorage/appinfo/database.xml +++ b/apps/remoteStorage/appinfo/database.xml @@ -29,14 +29,7 @@ 64 - dataScope - text - - true - 64 - - - userAddress + category text true diff --git a/apps/remoteStorage/auth.php b/apps/remoteStorage/auth.php new file mode 100644 index 0000000000..85421ba3d8 --- /dev/null +++ b/apps/remoteStorage/auth.php @@ -0,0 +1,100 @@ +. +* +*/ + + +// 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 '
'; + } + } 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 ' + .'' + .', close the pop-up, and ' + .'
'); + } +} 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 4bbadafe7d..4f19310904 100644 --- a/apps/remoteStorage/lib_remoteStorage.php +++ b/apps/remoteStorage/lib_remoteStorage.php @@ -1,26 +1,25 @@ 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 b785d85fea..5403fbe20c 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 349afaba50..d695a833f3 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"?> - + From c67ac46b6c3b333c7f16cbdc8df7b9a6b4f3fb1b Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Tue, 20 Sep 2011 14:41:17 +0200 Subject: [PATCH 02/15] Use a proxy class to interface with Sabre_VObject classes --- apps/calendar/ajax/editevent.php | 2 +- apps/calendar/ajax/editeventform.php | 16 +- apps/calendar/ajax/events.php | 2 +- apps/calendar/ajax/moveevent.php | 12 +- apps/calendar/lib/object.php | 77 +++------- apps/contacts/ajax/addcard.php | 8 +- apps/contacts/ajax/addproperty.php | 4 +- apps/contacts/ajax/deleteproperty.php | 2 +- apps/contacts/ajax/getdetails.php | 2 +- apps/contacts/ajax/setproperty.php | 4 +- apps/contacts/ajax/showsetproperty.php | 2 +- apps/contacts/index.php | 2 +- apps/contacts/lib/vcard.php | 114 ++------------ apps/contacts/photo.php | 2 +- lib/vobject.php | 201 +++++++++++++++++++++++++ 15 files changed, 261 insertions(+), 189 deletions(-) create mode 100644 lib/vobject.php diff --git a/apps/calendar/ajax/editevent.php b/apps/calendar/ajax/editevent.php index 46feb06849..e3c8452048 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 63c7293407..c91f136e89 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 1ef6bd3059..1430432b8a 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 6b315a3921..51fafdfeb9 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/lib/object.php b/apps/calendar/lib/object.php index b016469042..1e834241f6 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); } @@ -509,43 +488,31 @@ class OC_Calendar_Object{ }*/ $repeat = "false"; - $now = new DateTime(); - $vevent = $vcalendar->VEVENT[0]; + $vevent = $vcalendar->VEVENT; - $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->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); - } + + $vevent->setString('LOCATION', $location); if($description != ""){ $vevent->DESCRIPTION = $description; diff --git a/apps/contacts/ajax/addcard.php b/apps/contacts/ajax/addcard.php index dd5b90651f..8d192641db 100644 --- a/apps/contacts/ajax/addcard.php +++ b/apps/contacts/ajax/addcard.php @@ -40,9 +40,9 @@ $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,7 +64,7 @@ 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()); diff --git a/apps/contacts/ajax/addproperty.php b/apps/contacts/ajax/addproperty.php index 101cfabbe8..e59a91e4a5 100644 --- a/apps/contacts/ajax/addproperty.php +++ b/apps/contacts/ajax/addproperty.php @@ -42,7 +42,7 @@ if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){ exit(); } -$vcard = OC_Contacts_VCard::parse($card['carddata']); +$vcard = OC_VObject::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.')))); @@ -53,7 +53,7 @@ $name = $_POST['name']; $value = $_POST['value']; $parameters = isset($_POST['parameteres'])?$_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()); diff --git a/apps/contacts/ajax/deleteproperty.php b/apps/contacts/ajax/deleteproperty.php index 0a3a3c293a..be352cea61 100644 --- a/apps/contacts/ajax/deleteproperty.php +++ b/apps/contacts/ajax/deleteproperty.php @@ -45,7 +45,7 @@ if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){ exit(); } -$vcard = OC_Contacts_VCard::parse($card['carddata']); +$vcard = OC_VObject::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.')))); diff --git a/apps/contacts/ajax/getdetails.php b/apps/contacts/ajax/getdetails.php index 260fb53a68..eb1f20ee75 100644 --- a/apps/contacts/ajax/getdetails.php +++ b/apps/contacts/ajax/getdetails.php @@ -44,7 +44,7 @@ if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){ exit(); } -$vcard = OC_Contacts_VCard::parse($card['carddata']); +$vcard = OC_VObject::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.')))); diff --git a/apps/contacts/ajax/setproperty.php b/apps/contacts/ajax/setproperty.php index 22f228cbf4..2edfa5b452 100644 --- a/apps/contacts/ajax/setproperty.php +++ b/apps/contacts/ajax/setproperty.php @@ -43,7 +43,7 @@ if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){ exit(); } -$vcard = OC_Contacts_VCard::parse($card['carddata']); +$vcard = OC_VObject::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.')))); @@ -64,7 +64,7 @@ if(is_null($line)){ // 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); diff --git a/apps/contacts/ajax/showsetproperty.php b/apps/contacts/ajax/showsetproperty.php index 2ec4b89b82..1cf6541780 100644 --- a/apps/contacts/ajax/showsetproperty.php +++ b/apps/contacts/ajax/showsetproperty.php @@ -43,7 +43,7 @@ if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){ exit(); } -$vcard = OC_Contacts_VCard::parse($card['carddata']); +$vcard = OC_VObject::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.')))); diff --git a/apps/contacts/index.php b/apps/contacts/index.php index 29d41d3c4c..744b690233 100644 --- a/apps/contacts/index.php +++ b/apps/contacts/index.php @@ -71,7 +71,7 @@ $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_VObject::parse($contact['carddata']); $details = OC_Contacts_VCard::structureContact($vcard); } diff --git a/apps/contacts/lib/vcard.php b/apps/contacts/lib/vcard.php index 4865fae764..8836431ddb 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'){ @@ -248,67 +238,6 @@ class OC_Contacts_VCard{ return true; } - /** - * @brief Escapes semicolons - * @param string $value - * @return string - */ - public static function escapeSemicolons($value){ - foreach($value as &$i ){ - $i = implode("\\\\;", explode(';', $i)); - } - return implode(';',$value); - } - - /** - * @brief Creates an array out of a multivalue property - * @param string $value - * @return array - */ - public static function unescapeSemicolons($value){ - $array = explode(';',$value); - for($i=0;$iadd($i, $value); - } - } - - $vcard->add($property); - return $property; - } - /** * @brief Data structure of vCard * @param object $property @@ -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, @@ -373,21 +302,6 @@ 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': diff --git a/apps/contacts/photo.php b/apps/contacts/photo.php index 5178fe7a07..60dd81140b 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/lib/vobject.php b/lib/vobject.php new file mode 100644 index 0000000000..5a76cfd2d4 --- /dev/null +++ b/lib/vobject.php @@ -0,0 +1,201 @@ +. + * + */ + +/** + * 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) { + 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;$ivobject = $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 != ''){ + $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 __call($function,$arguments){ + return call_user_func_array(array($this->vobject, $function), $arguments); + } +} From 247146f7036984e0ae7a6719e8adfca6c2251079 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 5 Dec 2011 21:51:25 +0100 Subject: [PATCH 03/15] Contacts: refactor rendering of part.details template --- apps/contacts/ajax/addcard.php | 20 ++----- apps/contacts/ajax/getdetails.php | 26 +-------- apps/contacts/ajax/setproperty.php | 4 +- apps/contacts/ajax/showaddcard.php | 6 +-- apps/contacts/ajax/showsetproperty.php | 4 +- apps/contacts/appinfo/app.php | 1 + apps/contacts/index.php | 5 +- apps/contacts/lib/app.php | 74 ++++++++++++++++++++++++++ apps/contacts/lib/vcard.php | 21 -------- 9 files changed, 88 insertions(+), 73 deletions(-) create mode 100644 apps/contacts/lib/app.php diff --git a/apps/contacts/ajax/addcard.php b/apps/contacts/ajax/addcard.php index 8d192641db..9a52b26ed5 100644 --- a/apps/contacts/ajax/addcard.php +++ b/apps/contacts/ajax/addcard.php @@ -23,16 +23,14 @@ // 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'); +$aid = $_POST['id']; $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? + OC_JSON::error(array('data' => array( 'message' => OC_Contacts_App::$l10n->t('This is not your addressbook.')))); // Same here (as with the contact error). Could this error be improved? exit(); } @@ -68,16 +66,4 @@ foreach( $add as $propname){ } $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/getdetails.php b/apps/contacts/ajax/getdetails.php index eb1f20ee75..e480bce4cb 100644 --- a/apps/contacts/ajax/getdetails.php +++ b/apps/contacts/ajax/getdetails.php @@ -23,15 +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']; $card = OC_Contacts_VCard::find( $id ); if( $card === false ){ OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.')))); @@ -51,22 +47,4 @@ if(is_null($vcard)){ 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 2edfa5b452..e636cc5c1b 100644 --- a/apps/contacts/ajax/setproperty.php +++ b/apps/contacts/ajax/setproperty.php @@ -104,8 +104,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($l10n, 'ADR'); +$phone_types = OC_Contacts_App::getTypesOfProperty($l10n, '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 98367758fd..a2a9398bde 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(OC_Contacts_App::$l10n, 'ADR'); +$phone_types = OC_Contacts_App::getTypesOfProperty(OC_Contacts_App::$l10n, 'TEL'); $addressbooks = OC_Contacts_Addressbook::all(OC_USER::getUser()); $tmpl = new OC_Template('contacts','part.addcardform'); diff --git a/apps/contacts/ajax/showsetproperty.php b/apps/contacts/ajax/showsetproperty.php index 1cf6541780..30d0f5d817 100644 --- a/apps/contacts/ajax/showsetproperty.php +++ b/apps/contacts/ajax/showsetproperty.php @@ -61,8 +61,8 @@ if(is_null($line)){ exit(); } -$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR'); -$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL'); +$adr_types = OC_Contacts_App::getTypesOfProperty($l10n, 'ADR'); +$phone_types = OC_Contacts_App::getTypesOfProperty($l10n, '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 fc7b3769c5..524cc640bc 100644 --- a/apps/contacts/appinfo/app.php +++ b/apps/contacts/appinfo/app.php @@ -1,5 +1,6 @@ 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 ))); + } + + /** + * @return array of vcard prop => label + */ + public static function getAddPropertyOptions($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($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/lib/vcard.php b/apps/contacts/lib/vcard.php index 8836431ddb..a573f40f7d 100644 --- a/apps/contacts/lib/vcard.php +++ b/apps/contacts/lib/vcard.php @@ -301,25 +301,4 @@ class OC_Contacts_VCard{ } return $temp; } - - 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'), - ); - } - } } From 7e990a8e5c5bf266bd3fe36cd5bb99e49c6adb1e Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Tue, 6 Dec 2011 22:31:04 +0100 Subject: [PATCH 04/15] Contacts: refactor common ajax functions to OC_Contacts_App --- apps/contacts/ajax/addcard.php | 6 +-- apps/contacts/ajax/addproperty.php | 24 +---------- apps/contacts/ajax/deletebook.php | 11 +---- apps/contacts/ajax/deletecard.php | 17 +------- apps/contacts/ajax/deleteproperty.php | 38 ++--------------- apps/contacts/ajax/getdetails.php | 19 +-------- apps/contacts/ajax/setproperty.php | 40 +++--------------- apps/contacts/ajax/showaddcard.php | 4 +- apps/contacts/ajax/showaddproperty.php | 16 +------ apps/contacts/ajax/showsetproperty.php | 39 +++-------------- apps/contacts/index.php | 7 ++-- apps/contacts/lib/app.php | 58 +++++++++++++++++++++++--- 12 files changed, 84 insertions(+), 195 deletions(-) diff --git a/apps/contacts/ajax/addcard.php b/apps/contacts/ajax/addcard.php index 9a52b26ed5..9d782246a0 100644 --- a/apps/contacts/ajax/addcard.php +++ b/apps/contacts/ajax/addcard.php @@ -28,11 +28,7 @@ OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('contacts'); $aid = $_POST['id']; -$addressbook = OC_Contacts_Addressbook::find( $aid ); -if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){ - OC_JSON::error(array('data' => array( 'message' => OC_Contacts_App::$l10n->t('This is not your addressbook.')))); // Same here (as with the contact error). Could this error be improved? - exit(); -} +$addressbook = OC_Contacts_App::getAddressbook( $aid ); $fn = $_POST['fn']; $values = $_POST['value']; diff --git a/apps/contacts/ajax/addproperty.php b/apps/contacts/ajax/addproperty.php index e59a91e4a5..1ca4a85515 100644 --- a/apps/contacts/ajax/addproperty.php +++ b/apps/contacts/ajax/addproperty.php @@ -23,31 +23,12 @@ // 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_VObject::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']; @@ -56,7 +37,6 @@ $parameters = isset($_POST['parameteres'])?$_POST['parameters']:array(); $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 c13217ef2e..3ede17ab88 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 a0a6b8c3ea..e26dfd6ebf 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 be352cea61..f69735e61c 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(); -} +$id = $_GET['id']; +$checksum = $_GET['checksum']; -$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_VObject::parse($card['carddata']); -// Check if the card is valid -if(is_null($vcard)){ - OC_JSON::error(array('data' => array( 'message' => $l10n->t('vCard could not be read.')))); - exit(); -} - -$line = null; -for($i=0;$ichildren);$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 e480bce4cb..8cc0f9cbb0 100644 --- a/apps/contacts/ajax/getdetails.php +++ b/apps/contacts/ajax/getdetails.php @@ -28,23 +28,6 @@ OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('contacts'); $id = $_GET['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_VObject::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 ); OC_Contacts_App::renderDetails($id, $vcard); diff --git a/apps/contacts/ajax/setproperty.php b/apps/contacts/ajax/setproperty.php index e636cc5c1b..bcc4c161cc 100644 --- a/apps/contacts/ajax/setproperty.php +++ b/apps/contacts/ajax/setproperty.php @@ -23,43 +23,15 @@ // 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(); -} +$id = $_POST['id']; +$checksum = $_POST['checksum']; -$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_VObject::parse($card['carddata']); -// Check if the card is valid -if(is_null($vcard)){ - OC_JSON::error(array('data' => array( 'message' => $l10n->t('vCard could not be read.')))); - exit(); -} - -$line = null; -for($i=0;$ichildren);$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']; @@ -104,8 +76,8 @@ $checksum = md5($vcard->children[$line]->serialize()); OC_Contacts_VCard::edit($id,$vcard->serialize()); -$adr_types = OC_Contacts_App::getTypesOfProperty($l10n, 'ADR'); -$phone_types = OC_Contacts_App::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 a2a9398bde..54592c89c0 100644 --- a/apps/contacts/ajax/showaddcard.php +++ b/apps/contacts/ajax/showaddcard.php @@ -27,8 +27,8 @@ require_once('../../../lib/base.php'); OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('contacts'); -$adr_types = OC_Contacts_App::getTypesOfProperty(OC_Contacts_App::$l10n, 'ADR'); -$phone_types = OC_Contacts_App::getTypesOfProperty(OC_Contacts_App::$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 f87cd05359..30eb7634f8 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 30d0f5d817..e23fa21c56 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(); -} +$id = $_GET['id']; +$checksum = $_GET['checksum']; -$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_App::getContactVCard( $id ); -$vcard = OC_VObject::parse($card['carddata']); -// Check if the card is valid -if(is_null($vcard)){ - OC_JSON::error(array('data' => array( 'message' => $l10n->t('vCard could not be read.')))); - exit(); -} +$line = OC_Contacts_App::getPropertyLineByChecksum($vcard, $checksum); -$line = null; -for($i=0;$ichildren);$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(); -} - -$adr_types = OC_Contacts_App::getTypesOfProperty($l10n, 'ADR'); -$phone_types = OC_Contacts_App::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/index.php b/apps/contacts/index.php index 0a847f5a67..e5098bb7a8 100644 --- a/apps/contacts/index.php +++ b/apps/contacts/index.php @@ -70,13 +70,12 @@ $details = array(); if( !is_null($id) || count($contacts)){ if(is_null($id)) $id = $contacts[0]['id']; - $contact = OC_Contacts_VCard::find($id); - $vcard = OC_VObject::parse($contact['carddata']); + $vcard = OC_Contacts_App::getContactVCard($id); $details = OC_Contacts_VCard::structureContact($vcard); } -$adr_types = OC_Contacts_App::getTypesOfProperty(OC_Contacts_App::$l10n, 'ADR'); -$phone_types = OC_Contacts_App::getTypesOfProperty(OC_Contacts_App::$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 index 327ee6f1ca..ba086e4aca 100644 --- a/apps/contacts/lib/app.php +++ b/apps/contacts/lib/app.php @@ -19,9 +19,9 @@ class OC_Contacts_App{ * @param Sabre_VObject_Component $vcard to render */ public static function renderDetails($id, $vcard){ - $property_types = self::getAddPropertyOptions(self::$l10n); - $adr_types = self::getTypesOfProperty(self::$l10n, 'ADR'); - $phone_types = self::getTypesOfProperty(self::$l10n, 'TEL'); + $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']; @@ -36,10 +36,57 @@ class OC_Contacts_App{ 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;$ichildren);$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){ + public static function getAddPropertyOptions(){ + $l10n = self::$l10n; return array( 'ADR' => $l10n->t('Address'), 'TEL' => $l10n->t('Telephone'), @@ -51,7 +98,8 @@ class OC_Contacts_App{ /** * @return types for property $prop */ - public static function getTypesOfProperty($l, $prop){ + public static function getTypesOfProperty($prop){ + $l = self::$l10n; switch($prop){ case 'ADR': return array( From 36abf22a488b87096897a8748bbd2917321061c4 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Tue, 6 Dec 2011 22:32:16 +0100 Subject: [PATCH 05/15] Contacts: Fix postname var spelling --- apps/contacts/ajax/addproperty.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/contacts/ajax/addproperty.php b/apps/contacts/ajax/addproperty.php index 1ca4a85515..98877805b4 100644 --- a/apps/contacts/ajax/addproperty.php +++ b/apps/contacts/ajax/addproperty.php @@ -32,7 +32,7 @@ $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 = $vcard->addProperty($name, $value, $parameters); From 1220edd4dfdc76b80ee41a4ddc74756d572b009a Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Tue, 6 Dec 2011 22:33:20 +0100 Subject: [PATCH 06/15] Contacts: Add direct link to details of a contact --- apps/contacts/index.php | 4 ++-- apps/contacts/templates/index.php | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/apps/contacts/index.php b/apps/contacts/index.php index e5098bb7a8..de7b56dd1a 100644 --- a/apps/contacts/index.php +++ b/apps/contacts/index.php @@ -66,9 +66,9 @@ 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']; $vcard = OC_Contacts_App::getContactVCard($id); $details = OC_Contacts_VCard::structureContact($vcard); diff --git a/apps/contacts/templates/index.php b/apps/contacts/templates/index.php index 630dca41b2..649c4807dd 100644 --- a/apps/contacts/templates/index.php +++ b/apps/contacts/templates/index.php @@ -15,5 +15,12 @@ OC_Util::addStyle('contacts','formtastic');
- inc("part.addcardform"); ?> + inc("part.details"); + } + else{ + echo $this->inc("part.addcardform"); + } + ?>
From 546b7279a3488f242bc9f18d224ee9438915260e Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Wed, 7 Dec 2011 20:34:41 +0100 Subject: [PATCH 07/15] Contacts: Add "Preferred" before phone label for preferred numbers --- apps/contacts/templates/part.property.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/contacts/templates/part.property.php b/apps/contacts/templates/part.property.php index afef431126..6264f29674 100644 --- a/apps/contacts/templates/part.property.php +++ b/apps/contacts/templates/part.property.php @@ -20,7 +20,7 @@

-

t('Phone'); ?>

+

t('Preferred').' ' : '' ?>t('Phone'); ?>

From a389d94e2bf9b1288a13b002a17039cb6e87d969 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Wed, 7 Dec 2011 20:36:47 +0100 Subject: [PATCH 08/15] Imageviewer: fix fancybox.png image url in fancybox css --- .../css/jquery.fancybox-1.3.4.css | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) 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 030497750b..1dfd9b95d3 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'); } From 0342b5fc433da288f62b701bd77121d300ab30bc Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Wed, 7 Dec 2011 20:38:24 +0100 Subject: [PATCH 09/15] Fix filename of log icon --- lib/app.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/app.php b/lib/app.php index d3d9986576..b1aa8ba354 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" )); } From 9ba59aee3657dd67b8c0d575f1454fe50754f1f7 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Wed, 7 Dec 2011 20:38:58 +0100 Subject: [PATCH 10/15] Sort apps on name and enabled status --- settings/apps.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/settings/apps.php b/settings/apps.php index 27b4c17f9e..12a7bf7720 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)){ From d4546cdf37bced97d447b5170202cbd61c39d3be Mon Sep 17 00:00:00 2001 From: Michiel de Jong Date: Thu, 8 Dec 2011 17:18:22 +0700 Subject: [PATCH 11/15] bump version number to force db rebuild --- apps/remoteStorage/appinfo/info.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/remoteStorage/appinfo/info.xml b/apps/remoteStorage/appinfo/info.xml index a20c6ff4cd..8179ca9911 100644 --- a/apps/remoteStorage/appinfo/info.xml +++ b/apps/remoteStorage/appinfo/info.xml @@ -3,7 +3,7 @@ remoteStorage remoteStorage compatibility Enables your users to use ownCloud as their remote storage for unhosted applications. - 0.1 + 0.2 AGPL Michiel de Jong 2 From eeaf539a4414e3081b6f6652167363a3221a1973 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Thu, 8 Dec 2011 20:04:56 +0100 Subject: [PATCH 12/15] Gallery: splitout model code --- apps/gallery/ajax/createAlbum.php | 3 +- apps/gallery/ajax/getAlbums.php | 6 ++-- apps/gallery/ajax/getCovers.php | 16 +++++++---- apps/gallery/ajax/scanForAlbums.php | 3 +- apps/gallery/ajax/thumbnail.php | 17 +++++++---- apps/gallery/appinfo/app.php | 4 +++ apps/gallery/css/styles.css | 13 ++++++++- apps/gallery/index.php | 7 ++--- apps/gallery/lib/album.php | 18 ++++++++++++ apps/gallery/lib/photo.php | 28 +++++++++++++++++++ .../{lib_scanner.php => lib/scanner.php} | 22 +++++---------- apps/gallery/templates/view_album.php | 10 +++++-- lib/db.php | 2 +- 13 files changed, 105 insertions(+), 44 deletions(-) create mode 100644 apps/gallery/lib/album.php create mode 100644 apps/gallery/lib/photo.php rename apps/gallery/{lib_scanner.php => lib/scanner.php} (59%) diff --git a/apps/gallery/ajax/createAlbum.php b/apps/gallery/ajax/createAlbum.php index 610f761b72..9413b54718 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 38bea74636..856f29344d 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 b9c7558a53..db7c8e9fcd 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 de0b141a36..ff696804b0 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 a141645293..d937691fa0 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 8f855c470e..2b1ab857af 100644 --- a/apps/gallery/appinfo/app.php +++ b/apps/gallery/appinfo/app.php @@ -1,4 +1,8 @@ 20, 'id' => 'gallery', diff --git a/apps/gallery/css/styles.css b/apps/gallery/css/styles.css index 03b179138e..070effe3a9 100644 --- a/apps/gallery/css/styles.css +++ b/apps/gallery/css/styles.css @@ -1,14 +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; } +.leftcontent div#gallery_album_box { + margin: 5px; +} div#gallery_album_box h1 { font-size: 12pt; @@ -21,3 +29,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 87fdafcf13..2c409089eb 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 0000000000..6ddfe46de3 --- /dev/null +++ b/apps/gallery/lib/album.php @@ -0,0 +1,18 @@ +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 0000000000..97d159935f --- /dev/null +++ b/apps/gallery/lib/photo.php @@ -0,0 +1,28 @@ +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 similarity index 59% rename from apps/gallery/lib_scanner.php rename to apps/gallery/lib/scanner.php index 1231de3f3c..1590051c48 100644 --- a/apps/gallery/lib_scanner.php +++ b/apps/gallery/lib/scanner.php @@ -1,9 +1,6 @@ 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 230e2a5c21..ae43e2fc55 100644 --- a/apps/gallery/templates/view_album.php +++ b/apps/gallery/templates/view_album.php @@ -1,5 +1,6 @@
-