From e58df3adc9b4182c232c94178d024bb4a89c2290 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Sun, 15 Jun 2008 05:19:47 -0400
Subject: [PATCH] - Added option to select skin in user preferences (#1485031) - template_exists() moved to rcube_template class

---
 CHANGELOG                                |    5 ++
 program/steps/error.inc                  |    2 
 installer/config.php                     |    8 ++--
 program/steps/addressbook/edit.inc       |    2 
 program/include/main.inc                 |   16 --------
 program/steps/mail/show.inc              |    6 +-
 config/main.inc.php.dist                 |   11 +++--
 program/include/rcube_template.php       |   27 +++++++++++++
 program/include/rcube_config.php         |    2 
 program/steps/settings/edit_identity.inc |    2 
 10 files changed, 50 insertions(+), 31 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index e25081e..727d93c 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,11 @@
 CHANGELOG RoundCube Webmail
 ---------------------------
 
+2008/06/15 (alec)
+----------
+- Added option to select skin in user preferences
+  WARNING: option 'skin_path' replaced by 'default_skin'!
+
 2008/06/14 (alec)
 ----------
 - Added option to disable displaying of attached images below the message body
diff --git a/config/main.inc.php.dist b/config/main.inc.php.dist
index 17ba0a0..ac921a0 100644
--- a/config/main.inc.php.dist
+++ b/config/main.inc.php.dist
@@ -94,16 +94,16 @@
 // available cols are: subject, from, to, cc, replyto, date, size, encoding
 $rcmail_config['list_cols'] = array('subject', 'from', 'date', 'size');
 
-// relative path to the skin folder
-$rcmail_config['skin_path'] = 'skins/default/';
+// skin name: folder from skins/
+$rcmail_config['default_skin'] = 'default';
 
 // includes should be interpreted as PHP files
 $rcmail_config['skin_include_php'] = FALSE;
 
-// use this folder to store temp files (must be writebale for apache user)
+// use this folder to store temp files (must be writeable for apache user)
 $rcmail_config['temp_dir'] = 'temp/';
 
-// use this folder to store log files (must be writebale for apache user)
+// use this folder to store log files (must be writeable for apache user)
 $rcmail_config['log_dir'] = 'logs/';
 
 // session lifetime in minutes
@@ -315,6 +315,9 @@
 
 /***** these settings can be overwritten by user's preferences *****/
 
+// skin name (see 'default_skin' option)
+$rcmail_config['skin'] = $rcmail_config['default_skin'];
+
 // show up to X items in list view
 $rcmail_config['pagesize'] = 40;
 
diff --git a/installer/config.php b/installer/config.php
index 04683b9..bf1ae61 100644
--- a/installer/config.php
+++ b/installer/config.php
@@ -78,15 +78,15 @@
 <div>The name of your service (used to compose page titles)</div>
 </dd>
 
-<dt class="propname">skin_path</dt>
+<dt class="propname">default_skin</dt>
 <dd>
 <?php
 
-$input_skinpath = new html_inputfield(array('name' => '_skin_path', 'size' => 30, 'id' => "cfgskinpath"));
-echo $input_skinpath->show($RCI->getprop('skin_path'));
+$input_skin = new html_inputfield(array('name' => '_default_skin', 'size' => 30, 'id' => "cfgdefaultskin"));
+echo $input_skin->show($RCI->getprop('default_skin'));
 
 ?>
-<div>Relative path to the skin folder</div>
+<div>Name of the skin folder</div>
 </dd>
 
 <dt class="propname">temp_dir</dt>
diff --git a/program/include/main.inc b/program/include/main.inc
index 73b9c41..2740ee3 100644
--- a/program/include/main.inc
+++ b/program/include/main.inc
@@ -503,22 +503,6 @@
 
 
 /**
- * Check if a specific template exists
- *
- * @param string Template name
- * @return boolean True if template exists
- */
-function template_exists($name)
-  {
-  global $CONFIG;
-  $skin_path = $CONFIG['skin_path'];
-
-  // check template file
-  return is_file("$skin_path/templates/$name.html");
-  }
-
-
-/**
  * Create a HTML table based on the given data
  *
  * @param  array  Named table attributes
diff --git a/program/include/rcube_config.php b/program/include/rcube_config.php
index 5c744ba..b862bf7 100644
--- a/program/include/rcube_config.php
+++ b/program/include/rcube_config.php
@@ -61,7 +61,7 @@
     $this->load_host_config();
 
     // fix paths
-    $this->prop['skin_path'] = $this->prop['skin_path'] ? unslashify($this->prop['skin_path']) : 'skins/default';
+    $this->prop['default_skin'] = $this->prop['default_skin'] ? unslashify($this->prop['default_skin']) : 'default';
     $this->prop['log_dir'] = $this->prop['log_dir'] ? unslashify($this->prop['log_dir']) : INSTALL_PATH . 'logs';
     
     // handle aliases
diff --git a/program/include/rcube_template.php b/program/include/rcube_template.php
index 5834e42..9bc918e 100755
--- a/program/include/rcube_template.php
+++ b/program/include/rcube_template.php
@@ -57,6 +57,12 @@
         //$this->framed = $framed;
         $this->set_env('task', $task);
 
+	// load the correct skin (in case user-defined)
+	if (empty($this->config['skin']) || !is_readable('skins/'.$this->config['skin']))
+	    $this->config['skin'] = $this->config['default_skin'];
+
+	$this->config['skin_path'] = 'skins/'.$this->config['skin'];
+
         // add common javascripts
         $javascript = 'var '.JS_OBJECT_NAME.' = new rcube_webmail();';
 
@@ -102,6 +108,27 @@
         $this->pagetitle = $title;
     }
 
+    /**
+     * Set skin
+     */
+    public function set_skin($skin)
+    {
+	if (!empty($skin) && is_dir('skins/'.$skin) && is_readable('skins/'.$skin))
+	    $this->config['skin_path'] = 'skins/'.$skin;
+    }
+
+    /**
+     * Check if a specific template exists
+     *
+     * @param string Template name
+     * @return boolean True if template exists
+     */
+    public function template_exists($name)
+    {
+	$filename = $this->config['skin_path'] . '/templates/' . $name . '.html';
+
+	return (is_file($filename) && is_readable($filename));
+    }
 
     /**
      * Register a template object handler
diff --git a/program/steps/addressbook/edit.inc b/program/steps/addressbook/edit.inc
index 9cda22b..4b50fa2 100644
--- a/program/steps/addressbook/edit.inc
+++ b/program/steps/addressbook/edit.inc
@@ -113,7 +113,7 @@
 
 
 
-if (!$CONTACTS->get_result() && template_exists('addcontact'))
+if (!$CONTACTS->get_result() && $OUTPUT->template_exists('addcontact'))
   $OUTPUT->send('addcontact');
 
 // this will be executed if no template for addcontact exists
diff --git a/program/steps/error.inc b/program/steps/error.inc
index 5cde93c..bd6fa28 100644
--- a/program/steps/error.inc
+++ b/program/steps/error.inc
@@ -97,7 +97,7 @@
 
 
 
-if (template_exists('error'))
+if ($OUTPUT->template_exists('error'))
   {
   $OUTPUT->reset();
   $OUTPUT->send('error');
diff --git a/program/steps/mail/show.inc b/program/steps/mail/show.inc
index 3cdf2c9..bff4e68 100644
--- a/program/steps/mail/show.inc
+++ b/program/steps/mail/show.inc
@@ -32,7 +32,7 @@
   // go back to list if message not found (wrong UID)
   if (empty($MESSAGE->headers)) {
     $OUTPUT->show_message('messageopenerror', 'error');
-    if ($RCMAIL->action=='preview' && template_exists('messagepreview'))
+    if ($RCMAIL->action=='preview' && $OUTPUT->template_exists('messagepreview'))
         $OUTPUT->send('messagepreview');
     else {
       $RCMAIL->action = 'list';
@@ -194,9 +194,9 @@
   'blockedobjects' => 'rcmail_remote_objects_msg'));
 
 
-if ($RCMAIL->action=='print' && template_exists('printmessage'))
+if ($RCMAIL->action=='print' && $OUTPUT->template_exists('printmessage'))
   $OUTPUT->send('printmessage');
-else if ($RCMAIL->action=='preview' && template_exists('messagepreview'))
+else if ($RCMAIL->action=='preview' && $OUTPUT->template_exists('messagepreview'))
     $OUTPUT->send('messagepreview');
 else
   $OUTPUT->send('message');
diff --git a/program/steps/settings/edit_identity.inc b/program/steps/settings/edit_identity.inc
index 43cbf3d..cc541a6 100644
--- a/program/steps/settings/edit_identity.inc
+++ b/program/steps/settings/edit_identity.inc
@@ -136,7 +136,7 @@
 
 $OUTPUT->add_handler('identityform', 'rcube_identity_form');
 
-if ($RCMAIL->action=='add-identity' && template_exists('addidentity'))
+if ($RCMAIL->action=='add-identity' && $OUTPUT->template_exists('addidentity'))
   $OUTPUT->send('addidentity');
 
 $OUTPUT->send('editidentity');

--
Gitblit v1.9.1