summaryrefslogtreecommitdiffstats
path: root/lib/template.php
diff options
context:
space:
mode:
authorFrank Karlitschek <karlitschek@kde.org>2012-02-11 23:25:35 +0100
committerFrank Karlitschek <karlitschek@kde.org>2012-02-11 23:25:35 +0100
commit340b6bf3ad6400aa4996114046c5ad7070cac9e4 (patch)
tree2dd86dcac63fb8b9e2cf236dfd5e6465efd3cc10 /lib/template.php
parent1d6b4f8f3c2872b25ded28553925dd35ebd82997 (diff)
downloadnextcloud-server-340b6bf3ad6400aa4996114046c5ad7070cac9e4.tar.gz
nextcloud-server-340b6bf3ad6400aa4996114046c5ad7070cac9e4.zip
add themeing support and support for autoselection of mobile/tablet and standalone css/jss files and templates
Diffstat (limited to 'lib/template.php')
-rw-r--r--lib/template.php158
1 files changed, 137 insertions, 21 deletions
diff --git a/lib/template.php b/lib/template.php
index 881d2a27b1e..84302fd1385 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" );
+
+ // 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){