diff --git a/apps/calendar/caldav.php b/apps/calendar/caldav.php index b581274398..db0b35da11 100644 --- a/apps/calendar/caldav.php +++ b/apps/calendar/caldav.php @@ -19,7 +19,7 @@ $caldavBackend = new OC_Connector_Sabre_CalDAV(); // Root nodes $nodes = array( - new Sabre_DAVACL_PrincipalCollection($principalBackend), + new Sabre_CalDAV_Principal_Collection($principalBackend), new Sabre_CalDAV_CalendarRootNode($principalBackend, $caldavBackend), ); diff --git a/apps/contacts/carddav.php b/apps/contacts/carddav.php index df7c858b1a..a2bf492e20 100644 --- a/apps/contacts/carddav.php +++ b/apps/contacts/carddav.php @@ -33,7 +33,7 @@ $carddavBackend = new OC_Connector_Sabre_CardDAV(); // Root nodes $nodes = array( - new Sabre_DAVACL_PrincipalCollection($principalBackend), + new Sabre_CalDAV_Principal_Collection($principalBackend), new Sabre_CardDAV_AddressBookRoot($principalBackend, $carddavBackend), ); diff --git a/config/config.sample.php b/config/config.sample.php old mode 100644 new mode 100755 index a40ce073bf..cd52535871 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -12,6 +12,7 @@ $CONFIG = array( "dbtableprefix" => "", "forcessl" => false, "enablebackup" => false, +"theme" => "", // "datadirectory" => "" ); ?> diff --git a/lib/base.php b/lib/base.php index 5b8eeb746b..31133b7262 100644 --- a/lib/base.php +++ b/lib/base.php @@ -142,6 +142,13 @@ class OC{ // set the right include path set_include_path(OC::$SERVERROOT.'/lib'.PATH_SEPARATOR.OC::$SERVERROOT.'/config'.PATH_SEPARATOR.OC::$SERVERROOT.'/3rdparty'.PATH_SEPARATOR.get_include_path().PATH_SEPARATOR.OC::$SERVERROOT); + // Redirect to installer if not installed + if (!OC_Config::getValue('installed', false) && OC::$SUBURI != '/index.php') { + $url = 'http://'.$_SERVER['SERVER_NAME'].OC::$WEBROOT.'/index.php'; + header("Location: $url"); + exit(); + } + // redirect to https site if configured if( OC_Config::getValue( "forcessl", false )){ ini_set("session.cookie_secure", "on"); diff --git a/lib/connector/sabre/principal.php b/lib/connector/sabre/principal.php index 9c386f85e1..0f3d5feb79 100644 --- a/lib/connector/sabre/principal.php +++ b/lib/connector/sabre/principal.php @@ -44,6 +44,7 @@ class OC_Connector_Sabre_Principal implements Sabre_DAVACL_IPrincipalBackend { } return true; } + /** * Returns a list of principals based on a prefix. * @@ -57,22 +58,17 @@ class OC_Connector_Sabre_Principal implements Sabre_DAVACL_IPrincipalBackend { * @param string $prefixPath * @return array */ - public function getPrincipalsByPrefix( $prefixPath ){ - $query = OC_DB::prepare('SELECT * FROM *PREFIX*principals'); - $result = $query->execute(); - + public function getPrincipalsByPrefix( $prefixPath ) { $principals = array(); - while($row = $result->fetchRow()){ - // Checking if the principal is in the prefix - list($rowPrefix) = Sabre_DAV_URLUtil::splitPath($row['uri']); - if ($rowPrefix !== $prefixPath) continue; - - $principals[] = array( - 'uri' => $row['uri'], - '{DAV:}displayname' => $row['displayname']?$row['displayname']:basename($row['uri']) - ); - + if ($prefixPath == 'principals') { + foreach(OC_User::getUsers() as $user) { + $user_uri = 'principals/'.$user; + $principals[] = array( + 'uri' => $user_uri, + '{DAV:}displayname' => $user, + ); + } } return $principals; @@ -87,20 +83,16 @@ class OC_Connector_Sabre_Principal implements Sabre_DAVACL_IPrincipalBackend { * @return array */ public function getPrincipalByPath($path) { - $query = OC_DB::prepare('SELECT * FROM *PREFIX*principals WHERE uri=?'); - $result = $query->execute(array($path)); + list($prefix,$name) = Sabre_DAV_URLUtil::splitPath($path); - $users = array(); - - $row = $result->fetchRow(); - if (!$row) return; - - return array( - 'id' => $row['id'], - 'uri' => $row['uri'], - '{DAV:}displayname' => $row['displayname']?$row['displayname']:basename($row['uri']) - ); + if ($prefix == 'principals' && OC_User::userExists($name)) { + return array( + 'uri' => 'principals/'.$name, + '{DAV:}displayname' => $name, + ); + } + return null; } /** @@ -110,17 +102,15 @@ class OC_Connector_Sabre_Principal implements Sabre_DAVACL_IPrincipalBackend { * @return array */ public function getGroupMemberSet($principal) { - $principal = $this->getPrincipalByPath($principal); + // TODO: for now the group principal has only one member, the user itself + list($prefix,$name) = Sabre_DAV_URLUtil::splitPath($principal); + + $principal = $this->getPrincipalByPath($prefix); if (!$principal) throw new Sabre_DAV_Exception('Principal not found'); - $query = OC_DB::prepare('SELECT principals.uri as uri FROM *PREFIX*principalgroups AS groupmembers LEFT JOIN *PREFIX*principals AS principals ON groupmembers.member_id = principals.id WHERE groupmembers.principal_id = ?'); - $result = $query->execute(array($principal['id'])); - - $return = array(); - while ($row = $result->fetchRow()){ - $return[] = $row['uri']; - } - return $return; + return array( + $prefix + ); } /** @@ -130,17 +120,24 @@ class OC_Connector_Sabre_Principal implements Sabre_DAVACL_IPrincipalBackend { * @return array */ public function getGroupMembership($principal) { - $principal = $this->getPrincipalByPath($principal); - if (!$principal) throw new Sabre_DAV_Exception('Principal not found'); + list($prefix,$name) = Sabre_DAV_URLUtil::splitPath($principal); - $query = OC_DB::prepare('SELECT principals.uri as uri FROM *PREFIX*principalgroups AS groupmembers LEFT JOIN *PREFIX*principals AS principals ON groupmembers.member_id = principals.id WHERE groupmembers.member_id = ?'); - $result = $query->execute(array($principal['id'])); + $group_membership = array(); + if ($prefix == 'principals') { + $principal = $this->getPrincipalByPath($principal); + if (!$principal) throw new Sabre_DAV_Exception('Principal not found'); - $return = array(); - while ($row = $result->fetchRow()){ - $return[] = $row['uri']; + // TODO: for now the user principal has only its own groups + return array( + 'principals/'.$name.'/calendar-proxy-read', + 'principals/'.$name.'/calendar-proxy-write', + // The addressbook groups are not supported in Sabre, + // see http://groups.google.com/group/sabredav-discuss/browse_thread/thread/ef2fa9759d55f8c#msg_5720afc11602e753 + //'principals/'.$name.'/addressbook-proxy-read', + //'principals/'.$name.'/addressbook-proxy-write', + ); } - return $return; + return $group_membership; } /** @@ -153,29 +150,6 @@ class OC_Connector_Sabre_Principal implements Sabre_DAVACL_IPrincipalBackend { * @return void */ public function setGroupMemberSet($principal, array $members) { - $query = OC_DB::prepare('SELECT id, uri FROM *PREFIX*principals WHERE uri IN (? '.str_repeat(', ?', count($members)).')'); - $result = $query->execute(array_merge(array($principal), $members)); - - $memberIds = array(); - $principalId = null; - - while($row = $$result->fetchRow()) { - if ($row['uri'] == $principal) { - $principalId = $row['id']; - } - else{ - $memberIds[] = $row['id']; - } - } - if (!$principalId) throw new Sabre_DAV_Exception('Principal not found'); - - // Wiping out old members - $query = OC_DB::prepare('DELETE FROM *PREFIX*principalgroups WHERE principal_id = ?'); - $query->execute(array($principalID)); - - $query = OC_DB::prepare('INSERT INTO *PREFIX*principalgroups (principal_id, member_id) VALUES (?, ?);'); - foreach($memberIds as $memberId) { - $query->execute(array($principalId, $memberId)); - } + throw new Sabre_DAV_Exception('Setting members of the group is not supported yet'); } } diff --git a/lib/template.php b/lib/template.php index 881d2a27b1..84302fd138 100644 --- a/lib/template.php +++ b/lib/template.php @@ -151,21 +151,75 @@ class OC_Template{ * "admin". */ public function __construct( $app, $name, $renderas = "" ){ - // Get the right template folder - $template = OC::$SERVERROOT."/core/templates/"; + // Read the selected theme from the config file + $theme=OC_Config::getValue( "theme" ); + + // Read the detected formfactor and use the right file name. + $formfactor=$_SESSION['formfactor']; + if($formfactor=='default') { + $fext=''; + }elseif($formfactor=='mobile') { + $fext='.mobile'; + }elseif($formfactor=='tablet') { + $fext='.tablet'; + }elseif($formfactor=='standalone') { + $fext='.standalone'; + }else{ + $fext=''; + } + + // Check if it is a app template or not. if( $app != "" ){ - // Check if the app is in the app folder + // Check if the app is in the app folder or in the root if( file_exists( OC::$SERVERROOT."/apps/$app/templates/" )){ - $template = OC::$SERVERROOT."/apps/$app/templates/"; + // Check if the template is overwritten by the selected theme + if( file_exists( OC::$SERVERROOT."/themes/$theme/apps/$app/templates/"."$name$fext.php" )){ + $template = OC::$SERVERROOT."/themes/$theme/apps/$app/templates/"."$name$fext.php"; + $path = OC::$SERVERROOT."/themes/$theme/apps/$app/templates/"; + }elseif( file_exists( OC::$SERVERROOT."/themes/$theme/apps/$app/templates/"."$name.php" )){ + $template = OC::$SERVERROOT."/themes/$theme/apps/$app/templates/"."$name.php"; + $path = OC::$SERVERROOT."/themes/$theme/apps/$app/templates/"; + }elseif( OC::$SERVERROOT."/apps/$app/templates/"."$name$fext.php" ){ + $template = OC::$SERVERROOT."/apps/$app/templates/"."$name$fext.php"; + $path = OC::$SERVERROOT."/apps/$app/templates/"; + }else{ + $template = OC::$SERVERROOT."/apps/$app/templates/"."$name.php"; + $path = OC::$SERVERROOT."/apps/$app/templates/"; + } + }else{ + // Check if the template is overwritten by the selected theme + if( file_exists( OC::$SERVERROOT."/themes/$theme/$app/templates/"."$name$fext.php" )){ + $template = OC::$SERVERROOT."/themes/$theme/$app/templates/"."$name$fext.php"; + $path = OC::$SERVERROOT."/themes/$theme/$app/templates/"; + }elseif( file_exists( OC::$SERVERROOT."/themes/$theme/$app/templates/"."$name.php" )){ + $template = OC::$SERVERROOT."/themes/$theme/$app/templates/"."$name.php"; + $path = OC::$SERVERROOT."/themes/$theme/$app/templates/"; + }elseif( file_exists( OC::$SERVERROOT."/$app/templates/"."$name$fext.php" )){ + $template = OC::$SERVERROOT."/$app/templates/"."$name$fext.php"; + $path = OC::$SERVERROOT."/$app/templates/"; + }else{ + $template = OC::$SERVERROOT."/$app/templates/"."$name.php"; + $path = OC::$SERVERROOT."/$app/templates/"; + } + } - else{ - $template = OC::$SERVERROOT."/$app/templates/"; + }else{ + // Check if the template is overwritten by the selected theme + if( file_exists( OC::$SERVERROOT."/themes/$theme/core/templates/"."$name$fext.php" )){ + $template = OC::$SERVERROOT."/themes/$theme/core/templates/"."$name$fext.php"; + $path = OC::$SERVERROOT."/themes/$theme/core/templates/"; + }elseif( file_exists( OC::$SERVERROOT."/themes/$theme/core/templates/"."$name.php" )){ + $template = OC::$SERVERROOT."/themes/$theme/core/templates/"."$name.php"; + $path = OC::$SERVERROOT."/themes/$theme/core/templates/"; + }elseif( file_exists( OC::$SERVERROOT."/core/templates/"."$name$fext.php" )){ + $template = OC::$SERVERROOT."/core/templates/"."$name$fext.php"; + $path = OC::$SERVERROOT."/core/templates/"; + }else{ + $template = OC::$SERVERROOT."/core/templates/"."$name.php"; + $path = OC::$SERVERROOT."/core/templates/"; } } - // Templates have the ending .php - $path = $template; - $template .= "$name.php"; // Set the private data $this->renderas = $renderas; @@ -265,31 +319,93 @@ class OC_Template{ }else{ $page = new OC_Template( "core", "layout.guest" ); } + + // Read the selected theme from the config file + $theme=OC_Config::getValue( "theme" ); - // Add the css and js files + // Read the detected formfactor and use the right file name. + $formfactor=$_SESSION['formfactor']; + if($formfactor=='default') { + $fext=''; + }elseif($formfactor=='mobile') { + $fext='.mobile'; + }elseif($formfactor=='tablet') { + $fext='.tablet'; + }elseif($formfactor=='standalone') { + $fext='.standalone'; + }else{ + $fext=''; + } + + // Add the core js files or the js files provided by the selected theme foreach(OC_Util::$scripts as $script){ - if(is_file(OC::$SERVERROOT."/apps/$script.js" )){ + if(is_file(OC::$SERVERROOT."/themes/$theme/apps/$script$fext.js" )){ + $page->append( "jsfiles", OC::$WEBROOT."/themes/$theme/apps/$script$fext.js" ); + }elseif(is_file(OC::$SERVERROOT."/themes/$theme/apps/$script.js" )){ + $page->append( "jsfiles", OC::$WEBROOT."/themes/$theme/apps/$script.js" ); + + }elseif(is_file(OC::$SERVERROOT."/apps/$script$fext.js" )){ + $page->append( "jsfiles", OC::$WEBROOT."/apps/$script$fext.js" ); + }elseif(is_file(OC::$SERVERROOT."/apps/$script.js" )){ $page->append( "jsfiles", OC::$WEBROOT."/apps/$script.js" ); - } - elseif(is_file(OC::$SERVERROOT."/$script.js" )){ + + }elseif(is_file(OC::$SERVERROOT."/themes/$theme/$script$fext.js" )){ + $page->append( "jsfiles", OC::$WEBROOT."/themes/$theme/$script$fext.js" ); + }elseif(is_file(OC::$SERVERROOT."/themes/$theme/$script.js" )){ + $page->append( "jsfiles", OC::$WEBROOT."/themes/$theme/$script.js" ); + + }elseif(is_file(OC::$SERVERROOT."/$script$fext.js" )){ + $page->append( "jsfiles", OC::$WEBROOT."/$script$fext.js" ); + }elseif(is_file(OC::$SERVERROOT."/$script.js" )){ $page->append( "jsfiles", OC::$WEBROOT."/$script.js" ); - } - else{ + + }elseif(is_file(OC::$SERVERROOT."/themes/$theme/core/$script$fext.js" )){ + $page->append( "jsfiles", OC::$WEBROOT."/themes/$theme/core/$script$fext.js" ); + }elseif(is_file(OC::$SERVERROOT."/themes/$theme/core/$script.js" )){ + $page->append( "jsfiles", OC::$WEBROOT."/themes/$theme/core/$script.js" ); + + }elseif(is_file(OC::$SERVERROOT."/core/$script$fext.js" )){ + $page->append( "jsfiles", OC::$WEBROOT."/core/$script$fext.js" ); + }else{ $page->append( "jsfiles", OC::$WEBROOT."/core/$script.js" ); + } } + // Add the css files foreach(OC_Util::$styles as $style){ - if(is_file(OC::$SERVERROOT."/apps/$style.css" )){ + if(is_file(OC::$SERVERROOT."/apps/$style$fext.css" )){ + $page->append( "cssfiles", OC::$WEBROOT."/apps/$style$fext.css" ); + }elseif(is_file(OC::$SERVERROOT."/apps/$style.css" )){ $page->append( "cssfiles", OC::$WEBROOT."/apps/$style.css" ); - } - elseif(is_file(OC::$SERVERROOT."/$style.css" )){ + }elseif(is_file(OC::$SERVERROOT."/$style$fext.css" )){ + $page->append( "cssfiles", OC::$WEBROOT."/$style$fext.css" ); + }elseif(is_file(OC::$SERVERROOT."/$style.css" )){ $page->append( "cssfiles", OC::$WEBROOT."/$style.css" ); - } - else{ + }elseif(is_file(OC::$SERVERROOT."/core/$style$fext.css" )){ + $page->append( "cssfiles", OC::$WEBROOT."/core/$style$fext.css" ); + }else{ $page->append( "cssfiles", OC::$WEBROOT."/core/$style.css" ); } } - + // Add the theme css files. you can override the default values here + if(!empty($theme)) { + foreach(OC_Util::$styles as $style){ + if(is_file(OC::$SERVERROOT."/themes/$theme/apps/$style$fext.css" )){ + $page->append( "cssfiles", OC::$WEBROOT."/themes/$theme/apps/$style$fext.css" ); + }elseif(is_file(OC::$SERVERROOT."/themes/$theme/apps/$style.css" )){ + $page->append( "cssfiles", OC::$WEBROOT."/themes/$theme/apps/$style.css" ); + }elseif(is_file(OC::$SERVERROOT."/themes/$theme/$style$fext.css" )){ + $page->append( "cssfiles", OC::$WEBROOT."/themes/$theme/$style$fext.css" ); + }elseif(is_file(OC::$SERVERROOT."/themes/$theme/$style.css" )){ + $page->append( "cssfiles", OC::$WEBROOT."/themes/$theme/$style.css" ); + }elseif(is_file(OC::$SERVERROOT."/themes/$theme/core/$style$fext.css" )){ + $page->append( "cssfiles", OC::$WEBROOT."/themes/$theme/core/$style$fext.css" ); + }elseif(is_file(OC::$SERVERROOT."/themes/$theme/core/$style.css" )){ + $page->append( "cssfiles", OC::$WEBROOT."/themes/$theme/core/$style.css" ); + } + } + } + // Add custom headers $page->assign('headers',$this->headers); foreach(OC_Util::$headers as $header){ diff --git a/themes/README b/themes/README new file mode 100644 index 0000000000..e348f86a12 --- /dev/null +++ b/themes/README @@ -0,0 +1,7 @@ +This is the themes folder. Themes can be used to customize the look and feel of ownCloud without the need to patch the source code. +Themes can be placed in this folder with the name of the theme as foldername. The theme can be activated by putting +"theme" => 'themename', into the config.php file. +The folder structure of a theme is exactly the same as the main ownCloud structure. You can override js files and templates with own versions. css files are loaded additionaly to the default files so you can override css properties. +Themes should be developed here: https://gitorious.org/owncloud/themes +You can also find a super simple example there +