Merge branch 'master' into calendar_sharing

This commit is contained in:
Georg Ehrke 2012-02-12 10:46:34 +01:00
commit c9db88aa3b
7 changed files with 195 additions and 90 deletions

View File

@ -19,7 +19,7 @@ $caldavBackend = new OC_Connector_Sabre_CalDAV();
// Root nodes // Root nodes
$nodes = array( $nodes = array(
new Sabre_DAVACL_PrincipalCollection($principalBackend), new Sabre_CalDAV_Principal_Collection($principalBackend),
new Sabre_CalDAV_CalendarRootNode($principalBackend, $caldavBackend), new Sabre_CalDAV_CalendarRootNode($principalBackend, $caldavBackend),
); );

View File

@ -33,7 +33,7 @@ $carddavBackend = new OC_Connector_Sabre_CardDAV();
// Root nodes // Root nodes
$nodes = array( $nodes = array(
new Sabre_DAVACL_PrincipalCollection($principalBackend), new Sabre_CalDAV_Principal_Collection($principalBackend),
new Sabre_CardDAV_AddressBookRoot($principalBackend, $carddavBackend), new Sabre_CardDAV_AddressBookRoot($principalBackend, $carddavBackend),
); );

1
config/config.sample.php Normal file → Executable file
View File

@ -12,6 +12,7 @@ $CONFIG = array(
"dbtableprefix" => "", "dbtableprefix" => "",
"forcessl" => false, "forcessl" => false,
"enablebackup" => false, "enablebackup" => false,
"theme" => "",
// "datadirectory" => "" // "datadirectory" => ""
); );
?> ?>

View File

@ -142,6 +142,13 @@ class OC{
// set the right include path // 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); 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 // redirect to https site if configured
if( OC_Config::getValue( "forcessl", false )){ if( OC_Config::getValue( "forcessl", false )){
ini_set("session.cookie_secure", "on"); ini_set("session.cookie_secure", "on");

View File

@ -44,6 +44,7 @@ class OC_Connector_Sabre_Principal implements Sabre_DAVACL_IPrincipalBackend {
} }
return true; return true;
} }
/** /**
* Returns a list of principals based on a prefix. * 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 * @param string $prefixPath
* @return array * @return array
*/ */
public function getPrincipalsByPrefix( $prefixPath ){ public function getPrincipalsByPrefix( $prefixPath ) {
$query = OC_DB::prepare('SELECT * FROM *PREFIX*principals');
$result = $query->execute();
$principals = array(); $principals = array();
while($row = $result->fetchRow()){ if ($prefixPath == 'principals') {
// Checking if the principal is in the prefix foreach(OC_User::getUsers() as $user) {
list($rowPrefix) = Sabre_DAV_URLUtil::splitPath($row['uri']); $user_uri = 'principals/'.$user;
if ($rowPrefix !== $prefixPath) continue; $principals[] = array(
'uri' => $user_uri,
$principals[] = array( '{DAV:}displayname' => $user,
'uri' => $row['uri'], );
'{DAV:}displayname' => $row['displayname']?$row['displayname']:basename($row['uri']) }
);
} }
return $principals; return $principals;
@ -87,20 +83,16 @@ class OC_Connector_Sabre_Principal implements Sabre_DAVACL_IPrincipalBackend {
* @return array * @return array
*/ */
public function getPrincipalByPath($path) { public function getPrincipalByPath($path) {
$query = OC_DB::prepare('SELECT * FROM *PREFIX*principals WHERE uri=?'); list($prefix,$name) = Sabre_DAV_URLUtil::splitPath($path);
$result = $query->execute(array($path));
$users = array(); if ($prefix == 'principals' && OC_User::userExists($name)) {
return array(
$row = $result->fetchRow(); 'uri' => 'principals/'.$name,
if (!$row) return; '{DAV:}displayname' => $name,
);
return array( }
'id' => $row['id'],
'uri' => $row['uri'],
'{DAV:}displayname' => $row['displayname']?$row['displayname']:basename($row['uri'])
);
return null;
} }
/** /**
@ -110,17 +102,15 @@ class OC_Connector_Sabre_Principal implements Sabre_DAVACL_IPrincipalBackend {
* @return array * @return array
*/ */
public function getGroupMemberSet($principal) { 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'); 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 = ?'); return array(
$result = $query->execute(array($principal['id'])); $prefix
);
$return = array();
while ($row = $result->fetchRow()){
$return[] = $row['uri'];
}
return $return;
} }
/** /**
@ -130,17 +120,24 @@ class OC_Connector_Sabre_Principal implements Sabre_DAVACL_IPrincipalBackend {
* @return array * @return array
*/ */
public function getGroupMembership($principal) { public function getGroupMembership($principal) {
$principal = $this->getPrincipalByPath($principal); list($prefix,$name) = Sabre_DAV_URLUtil::splitPath($principal);
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.member_id = ?'); $group_membership = array();
$result = $query->execute(array($principal['id'])); if ($prefix == 'principals') {
$principal = $this->getPrincipalByPath($principal);
if (!$principal) throw new Sabre_DAV_Exception('Principal not found');
$return = array(); // TODO: for now the user principal has only its own groups
while ($row = $result->fetchRow()){ return array(
$return[] = $row['uri']; '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 * @return void
*/ */
public function setGroupMemberSet($principal, array $members) { public function setGroupMemberSet($principal, array $members) {
$query = OC_DB::prepare('SELECT id, uri FROM *PREFIX*principals WHERE uri IN (? '.str_repeat(', ?', count($members)).')'); throw new Sabre_DAV_Exception('Setting members of the group is not supported yet');
$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));
}
} }
} }

View File

@ -151,21 +151,75 @@ class OC_Template{
* "admin". * "admin".
*/ */
public function __construct( $app, $name, $renderas = "" ){ public function __construct( $app, $name, $renderas = "" ){
// Get the right template folder // Read the selected theme from the config file
$template = OC::$SERVERROOT."/core/templates/"; $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 != "" ){ 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/" )){ 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{ }else{
$template = OC::$SERVERROOT."/$app/templates/"; // 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 // Set the private data
$this->renderas = $renderas; $this->renderas = $renderas;
@ -266,29 +320,91 @@ class OC_Template{
$page = new OC_Template( "core", "layout.guest" ); $page = new OC_Template( "core", "layout.guest" );
} }
// Add the css and js files // 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='';
}
// Add the core js files or the js files provided by the selected theme
foreach(OC_Util::$scripts as $script){ 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" ); $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" ); $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" ); $page->append( "jsfiles", OC::$WEBROOT."/core/$script.js" );
} }
} }
// Add the css files
foreach(OC_Util::$styles as $style){ 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" ); $page->append( "cssfiles", OC::$WEBROOT."/apps/$style.css" );
} }elseif(is_file(OC::$SERVERROOT."/$style$fext.css" )){
elseif(is_file(OC::$SERVERROOT."/$style.css" )){ $page->append( "cssfiles", OC::$WEBROOT."/$style$fext.css" );
}elseif(is_file(OC::$SERVERROOT."/$style.css" )){
$page->append( "cssfiles", OC::$WEBROOT."/$style.css" ); $page->append( "cssfiles", OC::$WEBROOT."/$style.css" );
} }elseif(is_file(OC::$SERVERROOT."/core/$style$fext.css" )){
else{ $page->append( "cssfiles", OC::$WEBROOT."/core/$style$fext.css" );
}else{
$page->append( "cssfiles", OC::$WEBROOT."/core/$style.css" ); $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 // Add custom headers
$page->assign('headers',$this->headers); $page->assign('headers',$this->headers);

7
themes/README Normal file
View File

@ -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