]> source.dussan.org Git - nextcloud-server.git/commitdiff
add themeing support and support for autoselection of mobile/tablet and standalone...
authorFrank Karlitschek <karlitschek@kde.org>
Sat, 11 Feb 2012 22:25:35 +0000 (23:25 +0100)
committerFrank Karlitschek <karlitschek@kde.org>
Sat, 11 Feb 2012 22:25:35 +0000 (23:25 +0100)
config/config.sample.php [changed mode: 0644->0755]
lib/template.php

old mode 100644 (file)
new mode 100755 (executable)
index a40ce07..cd52535
@@ -12,6 +12,7 @@ $CONFIG = array(
 "dbtableprefix" => "",
 "forcessl" => false,
 "enablebackup" => false,
+"theme" => "",
 // "datadirectory" => ""
 );
 ?>
index 881d2a27b1e3e96becb53235a3794d0f50743962..84302fd138513a1168aa9b211583b00f2f2891f7 100644 (file)
@@ -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" );
+
+                       // 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 css and js files
+                       // 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){