Permalink
Browse files

add option for default userpic

  • Loading branch information...
1 parent a9565c7 commit e0c5c421126aba6d541e58761068911bb15fe6c7 @tommyrot committed Feb 8, 2014
Showing with 18 additions and 5 deletions.
  1. +2 −1 sss.conf
  2. +2 −1 sss.php
  3. +1 −1 www/sss.css
  4. +13 −2 www/user.php
View
@@ -108,7 +108,8 @@ logfile_dateformat = ""
#mainpage = "./"
# Show user pics on user.php if an image is found in the supplied directory with
-# an identical name to one of the user's aliases.
+# an identical name to one of the user's aliases. Fall back to default if set.
# Enable (true) or disable (false).
#userpics = "false"
#userpics_dir = "./userpics/"
+#userpics_default = ""
View
@@ -262,7 +262,8 @@ private function export_settings()
'timezone' => 'string',
'userstats' => 'bool',
'userpics' => 'bool',
- 'userpics_dir' => 'string');
+ 'userpics_dir' => 'string',
+ 'userpics_default' => 'string');
$vars = '$settings[\''.(!empty($this->settings['cid']) ? $this->settings['cid'] : $this->settings['channel']).'\'] = array(';
foreach ($settings_list as $key => $type) {
View
@@ -70,7 +70,7 @@ body {
.userpic {
float:right;
height:80px;
- padding:2px;
+ padding:2px 1px;
width:80px;
}
/**
View
@@ -31,6 +31,7 @@
private $stylesheet = 'sss.css';
private $timezone = 'UTC';
private $userpics = false;
+ private $userpics_default = '';
private $userpics_dir = './userpics/';
/**
@@ -101,6 +102,16 @@ public function __construct($cid, $nick)
private function get_userpic($sqlite3)
{
/**
+ * If a default image is provided in the configuration file it will be returned if no specific image is
+ * found for the user. If omitted, null will be returned in said case.
+ */
+ if (preg_match('/^\S+\.(bmp|gif|jpe?g|png)$/i', $this->userpics_default)) {
+ $userpics_default = '<img src="'.htmlspecialchars(rtrim($this->userpics_dir, '/').'/'.$this->userpics_default).'" alt="" class="userpic">';
+ } else {
+ $userpics_default = null;
+ }
+
+ /**
* Try to open and read from $userpics_dir.
*/
if (is_dir($this->userpics_dir)) {
@@ -118,7 +129,7 @@ private function get_userpic($sqlite3)
}
if (empty($files)) {
- return null;
+ return $userpics_default;
}
/**
@@ -139,7 +150,7 @@ private function get_userpic($sqlite3)
}
}
- return null;
+ return $userpics_default;
}
/**

0 comments on commit e0c5c42

Please sign in to comment.