Index: inc/admin/lib.themeconfig.php
===================================================================
--- inc/admin/lib.themeconfig.php	(revision 3340)
+++ inc/admin/lib.themeconfig.php	(revision 3730)
@@ -10,5 +10,5 @@
 #
 # -- END LICENSE BLOCK -----------------------------------------
-if (!defined('DC_ADMIN_CONTEXT')) { return; }
+if (!defined('DC_ADMIN_CONTEXT')) {return;}
 
 /**
@@ -30,28 +30,33 @@
  * @return float             computed ratio
  */
-	public static function computeContrastRatio($color,$background)
-	{
-		// Compute contrast ratio between two colors
-
-		$color = self::adjustColor($color);
-		if (($color == '') || (strlen($color) != 7)) return 0;
-		$background = self::adjustColor($background);
-		if (($background == '') || (strlen($background) != 7)) return 0;
-
-		$l1 = (0.2126 * pow(hexdec(substr($color,1,2))/255,2.2)) +
-			(0.7152 * pow(hexdec(substr($color,3,2))/255,2.2)) +
-			(0.0722 * pow(hexdec(substr($color,5,2))/255,2.2));
-
-		$l2 = (0.2126 * pow(hexdec(substr($background,1,2))/255,2.2)) +
-		 	(0.7152 * pow(hexdec(substr($background,3,2))/255,2.2)) +
-			(0.0722 * pow(hexdec(substr($background,5,2))/255,2.2));
-
-		if ($l1 > $l2) {
-			$ratio = ($l1 + 0.05) / ($l2 + 0.05);
-		} else {
-			$ratio = ($l2 + 0.05) / ($l1 + 0.05);
-		}
-		return $ratio;
-	}
+    public static function computeContrastRatio($color, $background)
+    {
+        // Compute contrast ratio between two colors
+
+        $color = self::adjustColor($color);
+        if (($color == '') || (strlen($color) != 7)) {
+            return 0;
+        }
+
+        $background = self::adjustColor($background);
+        if (($background == '') || (strlen($background) != 7)) {
+            return 0;
+        }
+
+        $l1 = (0.2126 * pow(hexdec(substr($color, 1, 2)) / 255, 2.2)) +
+            (0.7152 * pow(hexdec(substr($color, 3, 2)) / 255, 2.2)) +
+            (0.0722 * pow(hexdec(substr($color, 5, 2)) / 255, 2.2));
+
+        $l2 = (0.2126 * pow(hexdec(substr($background, 1, 2)) / 255, 2.2)) +
+            (0.7152 * pow(hexdec(substr($background, 3, 2)) / 255, 2.2)) +
+            (0.0722 * pow(hexdec(substr($background, 5, 2)) / 255, 2.2));
+
+        if ($l1 > $l2) {
+            $ratio = ($l1 + 0.05) / ($l2 + 0.05);
+        } else {
+            $ratio = ($l2 + 0.05) / ($l1 + 0.05);
+        }
+        return $ratio;
+    }
 
 /**
@@ -64,52 +69,52 @@
  * @return string         WCAG contrast ratio level (AAA, AA or <nothing>)
  */
-	public static function contrastRatioLevel($ratio,$size,$bold=false)
-	{
-		if ($size == '') {
-			return '';
-		}
-
-		// Eval font size in em (assume base font size in pixels equal to 16)
-		if (preg_match('/^([0-9.]+)\s*(%|pt|px|em|ex|rem)?$/',$size,$m)) {
-			if (empty($m[2])) {
-				$m[2] = 'em';
-			}
-		} else {
-			return '';
-		}
-		switch ($m[2]) {
-			case '%':
-				$s = (float) $m[1] / 100;
-				break;
-			case 'pt':
-				$s = (float) $m[1] / 12;
-				break;
-			case 'px':
-				$s = (float) $m[1] / 16;
-				break;
-			case 'em':
-				$s = (float) $m[1];
-				break;
-			case 'ex':
-				$s = (float) $m[1] / 2;
-				break;
-			default:
-				return '';
-		}
-
-		$large = ((($s > 1.5) && ($bold == false)) || (($s > 1.2) && ($bold == true)));
-
-		// Check ratio
-		if ($ratio > 7) {
-			return 'AAA';
-		} elseif (($ratio > 4.5) && $large) {
-			return 'AAA';
-		} elseif ($ratio > 4.5) {
-			return 'AA';
-		} elseif (($ratio > 3) && $large) {
-			return 'AA';
-		}
-		return '';
-	}
+    public static function contrastRatioLevel($ratio, $size, $bold = false)
+    {
+        if ($size == '') {
+            return '';
+        }
+
+        // Eval font size in em (assume base font size in pixels equal to 16)
+        if (preg_match('/^([0-9.]+)\s*(%|pt|px|em|ex|rem)?$/', $size, $m)) {
+            if (empty($m[2])) {
+                $m[2] = 'em';
+            }
+        } else {
+            return '';
+        }
+        switch ($m[2]) {
+            case '%':
+                $s = (float) $m[1] / 100;
+                break;
+            case 'pt':
+                $s = (float) $m[1] / 12;
+                break;
+            case 'px':
+                $s = (float) $m[1] / 16;
+                break;
+            case 'em':
+                $s = (float) $m[1];
+                break;
+            case 'ex':
+                $s = (float) $m[1] / 2;
+                break;
+            default:
+                return '';
+        }
+
+        $large = ((($s > 1.5) && ($bold == false)) || (($s > 1.2) && ($bold == true)));
+
+        // Check ratio
+        if ($ratio > 7) {
+            return 'AAA';
+        } elseif (($ratio > 4.5) && $large) {
+            return 'AAA';
+        } elseif ($ratio > 4.5) {
+            return 'AA';
+        } elseif (($ratio > 3) && $large) {
+            return 'AA';
+        }
+        return '';
+    }
 
 /**
@@ -123,15 +128,15 @@
  * @return string              contrast ratio including WCAG level
  */
-	public static function contrastRatio($color,$background,$size='',$bold=false)
-	{
-		if (($color != '') && ($background != '')) {
-			$ratio = self::computeContrastRatio($color,$background);
-			$level = self::contrastRatioLevel($ratio,$size,$bold);
-			return
-				sprintf(__('ratio %.1f'),$ratio).
-				($level != '' ? ' '.sprintf(__('(%s)'),$level) : '');
-		}
-		return '';
-	}
+    public static function contrastRatio($color, $background, $size = '', $bold = false)
+    {
+        if (($color != '') && ($background != '')) {
+            $ratio = self::computeContrastRatio($color, $background);
+            $level = self::contrastRatioLevel($ratio, $size, $bold);
+            return
+            sprintf(__('ratio %.1f'), $ratio) .
+                ($level != '' ? ' ' . sprintf(__('(%s)'), $level) : '');
+        }
+        return '';
+    }
 
 /**
@@ -142,14 +147,14 @@
  * @return string    checked font size
  */
-	public static function adjustFontSize($s)
-	{
-		if (preg_match('/^([0-9.]+)\s*(%|pt|px|em|ex|rem)?$/',$s,$m)) {
-			if (empty($m[2])) {
-				$m[2] = 'em';
-			}
-			return $m[1].$m[2];
-		}
-		return null;
-	}
+    public static function adjustFontSize($s)
+    {
+        if (preg_match('/^([0-9.]+)\s*(%|pt|px|em|ex|rem)?$/', $s, $m)) {
+            if (empty($m[2])) {
+                $m[2] = 'em';
+            }
+            return $m[1] . $m[2];
+        }
+        return;
+    }
 
 /**
@@ -160,13 +165,13 @@
  * @return string    checked position
  */
-	public static function adjustPosition($p)
-	{
-		if (!preg_match('/^[0-9]+(:[0-9]+)?$/',$p)) {
-			return null;
-		}
-		$p = explode(':',$p);
-
-		return $p[0].(count($p) == 1 ? ':0' : ':'.$p[1]);
-	}
+    public static function adjustPosition($p)
+    {
+        if (!preg_match('/^[0-9]+(:[0-9]+)?$/', $p)) {
+            return;
+        }
+        $p = explode(':', $p);
+
+        return $p[0] . (count($p) == 1 ? ':0' : ':' . $p[1]);
+    }
 
 /**
@@ -177,24 +182,24 @@
  * @return string    checked CSS color
  */
-	public static function adjustColor($c)
-	{
-		if ($c === '') {
-			return '';
-		}
-
-		$c = strtoupper($c);
-
-		if (preg_match('/^[A-F0-9]{3,6}$/',$c)) {
-			$c = '#'.$c;
-		}
-		if (preg_match('/^#[A-F0-9]{6}$/',$c)) {
-			return $c;
-		}
-		if (preg_match('/^#[A-F0-9]{3,}$/',$c)) {
-			return '#'.substr($c,1,1).substr($c,1,1).substr($c,2,1).substr($c,2,1).substr($c,3,1).substr($c,3,1);
-		}
-
-		return '';
-	}
+    public static function adjustColor($c)
+    {
+        if ($c === '') {
+            return '';
+        }
+
+        $c = strtoupper($c);
+
+        if (preg_match('/^[A-F0-9]{3,6}$/', $c)) {
+            $c = '#' . $c;
+        }
+        if (preg_match('/^#[A-F0-9]{6}$/', $c)) {
+            return $c;
+        }
+        if (preg_match('/^#[A-F0-9]{3,}$/', $c)) {
+            return '#' . substr($c, 1, 1) . substr($c, 1, 1) . substr($c, 2, 1) . substr($c, 2, 1) . substr($c, 3, 1) . substr($c, 3, 1);
+        }
+
+        return '';
+    }
 
 /**
@@ -205,9 +210,9 @@
  * @return string      checked CSS
  */
-	public static function cleanCSS($css)
-	{
-		// TODO ?
-		return $css;
-	}
+    public static function cleanCSS($css)
+    {
+        // TODO ?
+        return $css;
+    }
 
 /**
@@ -218,9 +223,9 @@
  * @return string         real path of CSS
  */
-	public static function cssPath($folder)
-	{
-		global $core;
-		return path::real($core->blog->public_path).'/'.$folder;
-	}
+    public static function cssPath($folder)
+    {
+        global $core;
+        return path::real($core->blog->public_path) . '/' . $folder;
+    }
 
 /**
@@ -231,9 +236,9 @@
  * @return string         CSS URL
  */
-	public static function cssURL($folder)
-	{
-		global $core;
-		return $core->blog->settings->system->public_url.'/'.$folder;
-	}
+    public static function cssURL($folder)
+    {
+        global $core;
+        return $core->blog->settings->system->public_url . '/' . $folder;
+    }
 
 /**
@@ -245,34 +250,34 @@
  * @return boolean          true if CSS folder exists and may be written, else false
  */
-	public static function canWriteCss($folder,$create=false)
-	{
-		global $core;
-
-		$public = path::real($core->blog->public_path);
-		$css = self::cssPath($folder);
-
-		if (!is_dir($public)) {
-			$core->error->add(__('The \'public\' directory does not exist.'));
-			return false;
-		}
-
-		if (!is_dir($css)) {
-			if (!is_writable($public)) {
-				$core->error->add(sprintf(__('The \'%s\' directory cannot be modified.'),'public'));
-				return false;
-			}
-			if ($create) {
-				files::makeDir($css);
-			}
-			return true;
-		}
-
-		if (!is_writable($css)) {
-			$core->error->add(sprintf(__('The \'%s\' directory cannot be modified.'),'public/'.$folder));
-			return false;
-		}
-
-		return true;
-	}
+    public static function canWriteCss($folder, $create = false)
+    {
+        global $core;
+
+        $public = path::real($core->blog->public_path);
+        $css    = self::cssPath($folder);
+
+        if (!is_dir($public)) {
+            $core->error->add(__('The \'public\' directory does not exist.'));
+            return false;
+        }
+
+        if (!is_dir($css)) {
+            if (!is_writable($public)) {
+                $core->error->add(sprintf(__('The \'%s\' directory cannot be modified.'), 'public'));
+                return false;
+            }
+            if ($create) {
+                files::makeDir($css);
+            }
+            return true;
+        }
+
+        if (!is_writable($css)) {
+            $core->error->add(sprintf(__('The \'%s\' directory cannot be modified.'), 'public/' . $folder));
+            return false;
+        }
+
+        return true;
+    }
 
 /**
@@ -284,10 +289,10 @@
  * @param  string $value    value
  */
-	public static function prop(&$css,$selector,$prop,$value)
-	{
-		if ($value) {
-			$css[$selector][$prop] = $value;
-		}
-	}
+    public static function prop(&$css, $selector, $prop, $value)
+    {
+        if ($value) {
+            $css[$selector][$prop] = $value;
+        }
+    }
 
 /**
@@ -300,11 +305,11 @@
  * @param  string $image    image filename
  */
-	public static function backgroundImg($folder,&$css,$selector,$value,$image)
-	{
-		$file = self::imagesPath($folder).'/'.$image;
-		if ($value && file_exists($file)){
-			$css[$selector]['background-image'] = 'url('.self::imagesURL($folder).'/'.$image.')';
-		}
-	}
+    public static function backgroundImg($folder, &$css, $selector, $value, $image)
+    {
+        $file = self::imagesPath($folder) . '/' . $image;
+        if ($value && file_exists($file)) {
+            $css[$selector]['background-image'] = 'url(' . self::imagesURL($folder) . '/' . $image . ')';
+        }
+    }
 
 /**
@@ -315,8 +320,8 @@
  * @param  string $css    CSS file content
  */
-	public static function writeCss($folder,$theme,$css)
-	{
-		file_put_contents(self::cssPath($folder).'/'.$theme.'.css', $css);
-	}
+    public static function writeCss($folder, $theme, $css)
+    {
+        file_put_contents(self::cssPath($folder) . '/' . $theme . '.css', $css);
+    }
 
 /**
@@ -326,11 +331,11 @@
  * @param  string $theme  CSS filename to be removed
  */
-	public static function dropCss($folder,$theme)
-	{
-		$file = path::real(self::cssPath($folder).'/'.$theme.'.css');
-		if (is_writable(dirname($file))) {
-			@unlink($file);
-		}
-	}
+    public static function dropCss($folder, $theme)
+    {
+        $file = path::real(self::cssPath($folder) . '/' . $theme . '.css');
+        if (is_writable(dirname($file))) {
+            @unlink($file);
+        }
+    }
 
 /**
@@ -341,16 +346,16 @@
  * @return string         CSS file URL
  */
-	public static function publicCssUrlHelper($folder)
-	{
-		$theme = $GLOBALS['core']->blog->settings->system->theme;
-		$url = self::cssURL($folder);
-		$path = self::cssPath($folder);
-
-		if (file_exists($path.'/'.$theme.'.css')) {
-			return $url.'/'.$theme.'.css';
-		}
-
-		return null;
-	}
+    public static function publicCssUrlHelper($folder)
+    {
+        $theme = $GLOBALS['core']->blog->settings->system->theme;
+        $url   = self::cssURL($folder);
+        $path  = self::cssPath($folder);
+
+        if (file_exists($path . '/' . $theme . '.css')) {
+            return $url . '/' . $theme . '.css';
+        }
+
+        return;
+    }
 
 /**
@@ -361,9 +366,9 @@
  * @return string         real path of folder
  */
-	public static function imagesPath($folder)
-	{
-		global $core;
-		return path::real($core->blog->public_path).'/'.$folder;
-	}
+    public static function imagesPath($folder)
+    {
+        global $core;
+        return path::real($core->blog->public_path) . '/' . $folder;
+    }
 
 /**
@@ -374,9 +379,9 @@
  * @return string         URL of images folder
  */
-	public static function imagesURL($folder)
-	{
-		global $core;
-		return $core->blog->settings->system->public_url.'/'.$folder;
-	}
+    public static function imagesURL($folder)
+    {
+        global $core;
+        return $core->blog->settings->system->public_url . '/' . $folder;
+    }
 
 /**
@@ -388,40 +393,40 @@
  * @return boolean          true if folder exists and may be written
  */
-	public static function canWriteImages($folder,$create=false)
-	{
-		global $core;
-
-		$public = path::real($core->blog->public_path);
-		$imgs = self::imagesPath($folder);
-
-		if (!function_exists('imagecreatetruecolor') || !function_exists('imagepng') || !function_exists('imagecreatefrompng')) {
-			$core->error->add(__('At least one of the following functions is not available: '.
-				'imagecreatetruecolor, imagepng & imagecreatefrompng.'));
-			return false;
-		}
-
-		if (!is_dir($public)) {
-			$core->error->add(__('The \'public\' directory does not exist.'));
-			return false;
-		}
-
-		if (!is_dir($imgs)) {
-			if (!is_writable($public)) {
-				$core->error->add(sprintf(__('The \'%s\' directory cannot be modified.'),'public'));
-				return false;
-			}
-			if ($create) {
-				files::makeDir($imgs);
-			}
-			return true;
-		}
-
-		if (!is_writable($imgs)) {
-			$core->error->add(sprintf(__('The \'%s\' directory cannot be modified.'),'public/'.$folder));
-			return false;
-		}
-
-		return true;
-	}
+    public static function canWriteImages($folder, $create = false)
+    {
+        global $core;
+
+        $public = path::real($core->blog->public_path);
+        $imgs   = self::imagesPath($folder);
+
+        if (!function_exists('imagecreatetruecolor') || !function_exists('imagepng') || !function_exists('imagecreatefrompng')) {
+            $core->error->add(__('At least one of the following functions is not available: ' .
+                'imagecreatetruecolor, imagepng & imagecreatefrompng.'));
+            return false;
+        }
+
+        if (!is_dir($public)) {
+            $core->error->add(__('The \'public\' directory does not exist.'));
+            return false;
+        }
+
+        if (!is_dir($imgs)) {
+            if (!is_writable($public)) {
+                $core->error->add(sprintf(__('The \'%s\' directory cannot be modified.'), 'public'));
+                return false;
+            }
+            if ($create) {
+                files::makeDir($imgs);
+            }
+            return true;
+        }
+
+        if (!is_writable($imgs)) {
+            $core->error->add(sprintf(__('The \'%s\' directory cannot be modified.'), 'public/' . $folder));
+            return false;
+        }
+
+        return true;
+    }
 
 /**
@@ -434,32 +439,32 @@
  * @return string         full pathname of uploaded image
  */
-	public static function uploadImage($folder,$f,$width=0)
-	{
-		if (!self::canWriteImages($folder,true)) {
-			throw new Exception(__('Unable to create images.'));
-		}
-
-		$name = $f['name'];
-		$type = files::getMimeType($name);
-
-		if ($type != 'image/jpeg' && $type != 'image/png') {
-			throw new Exception(__('Invalid file type.'));
-		}
-
-		$dest = self::imagesPath($folder).'/uploaded'.($type == 'image/png' ? '.png' : '.jpg');
-
-		if (@move_uploaded_file($f['tmp_name'],$dest) === false) {
-			throw new Exception(__('An error occurred while writing the file.'));
-		}
-
-		if ($width) {
-			$s = getimagesize($dest);
-			if ($s[0] != $width) {
-				throw new Exception(sprintf(__('Uploaded image is not %s pixels wide.'),$width));
-			}
-		}
-
-		return $dest;
-	}
+    public static function uploadImage($folder, $f, $width = 0)
+    {
+        if (!self::canWriteImages($folder, true)) {
+            throw new Exception(__('Unable to create images.'));
+        }
+
+        $name = $f['name'];
+        $type = files::getMimeType($name);
+
+        if ($type != 'image/jpeg' && $type != 'image/png') {
+            throw new Exception(__('Invalid file type.'));
+        }
+
+        $dest = self::imagesPath($folder) . '/uploaded' . ($type == 'image/png' ? '.png' : '.jpg');
+
+        if (@move_uploaded_file($f['tmp_name'], $dest) === false) {
+            throw new Exception(__('An error occurred while writing the file.'));
+        }
+
+        if ($width) {
+            $s = getimagesize($dest);
+            if ($s[0] != $width) {
+                throw new Exception(sprintf(__('Uploaded image is not %s pixels wide.'), $width));
+            }
+        }
+
+        return $dest;
+    }
 
 /**
@@ -469,20 +474,20 @@
  * @param  string $img    image filename
  */
-	public static function dropImage($folder,$img)
-	{
-		global $core;
-
-		$img = path::real(self::imagesPath($folder).'/'.$img);
-		if (is_writable(dirname($img))) {
-			// Delete thumbnails if any
-			try {
-				$media = new dcMedia($core);
-				$media->imageThumbRemove($img);
-			} catch (Exception $e) {
-				$core->error->add($e->getMessage());
-			}
-			// Delete image
-			@unlink($img);
-		}
-	}
+    public static function dropImage($folder, $img)
+    {
+        global $core;
+
+        $img = path::real(self::imagesPath($folder) . '/' . $img);
+        if (is_writable(dirname($img))) {
+            // Delete thumbnails if any
+            try {
+                $media = new dcMedia($core);
+                $media->imageThumbRemove($img);
+            } catch (Exception $e) {
+                $core->error->add($e->getMessage());
+            }
+            // Delete image
+            @unlink($img);
+        }
+    }
 }
