From 8e3824cb3c0cd05e546c4ec34ef5c30e5a86fea2 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 24 Jun 2014 15:10:31 +0000 Subject: [PATCH] added usericon_dir. also added some functions useful for showing a user icon --- codepot/etc/codepot.ini.in | 5 ++++ codepot/src/codepot/controllers/project.php | 2 +- codepot/src/codepot/models/projectmodel.php | 29 +++++++++++++++++++++ codepot/src/codepot/views/project_home.php | 23 +++++++++++++++- codepot/src/config.php.in | 1 + 5 files changed, 58 insertions(+), 2 deletions(-) diff --git a/codepot/etc/codepot.ini.in b/codepot/etc/codepot.ini.in index ba30d727..20e73551 100644 --- a/codepot/etc/codepot.ini.in +++ b/codepot/etc/codepot.ini.in @@ -154,6 +154,11 @@ file_dir = "@DEPOTDIR@/files" ;------------------------------------------------------------------------------ attachment_dir = "@DEPOTDIR@/attachments" +;------------------------------------------------------------------------------ +; directory to store user icons +;------------------------------------------------------------------------------ +usericon_dir = "@DEPOTDIR@/usericons" + ;------------------------------------------------------------------------------ ; log threshold ;------------------------------------------------------------------------------ diff --git a/codepot/src/codepot/controllers/project.php b/codepot/src/codepot/controllers/project.php index 6ea95b13..428a7fdd 100644 --- a/codepot/src/codepot/controllers/project.php +++ b/codepot/src/codepot/controllers/project.php @@ -199,7 +199,7 @@ class Project extends Controller $project->description = $this->input->post('project_description'); $project->commitable = $this->input->post('project_commitable'); $project->public = $this->input->post('project_public'); - $project->members = explode (',', $this->input->post('project_members')); + $project->members = array_unique (preg_split ('/[[:space:],]+/', $this->input->post('project_members'))); // validate the form if ($this->form_validation->run()) diff --git a/codepot/src/codepot/models/projectmodel.php b/codepot/src/codepot/models/projectmodel.php index 7a86e793..dc9f11d2 100644 --- a/codepot/src/codepot/models/projectmodel.php +++ b/codepot/src/codepot/models/projectmodel.php @@ -460,6 +460,35 @@ class ProjectModel extends Model foreach ($files as $file) @unlink (CODEPOT_FILE_DIR . "/{$file->encname}"); } + + function getUserIcons ($users) + { + $this->db->trans_start (); + + $this->db->select ('userid,icon_name'); + $this->db->where_in ('userid', $users); + $this->db->where ('icon_name IS NOT NULL', null); + + $query = $this->db->get ('user_settings'); + if ($this->db->trans_status() === FALSE) + { + $this->db->trans_complete (); + return FALSE; + } + + $out = array(); + $result = $query->result(); + + if (!empty($result)) + { + foreach ($result as $t) $out[$t->userid] = $t->icon_name; + } + + $this->db->trans_complete (); + if ($this->db->trans_status() === FALSE) return FALSE; + + return $out; + } } ?> diff --git a/codepot/src/codepot/views/project_home.php b/codepot/src/codepot/views/project_home.php index edabb702..6c322dc9 100644 --- a/codepot/src/codepot/views/project_home.php +++ b/codepot/src/codepot/views/project_home.php @@ -77,13 +77,34 @@ $this->load->view ( $member_count = count($members); $members = array_unique ($members); $priority = 0; + + $icons = $this->projects->getUserIcons($members); + if ($icons === FALSE) $icons = array(); // can't get the icon array for members. + for ($i = 0; $i < $member_count; $i++) { if (!array_key_exists($i, $members)) continue; $m = $members[$i]; if ($m == '') continue; - print "
  • {$m}
  • "; + + $icon = ''; + if (array_key_exists($m, $icons)) + { + // old browsers don't support image data URI. + $icon_path = CODEPOT_USERICON_DIR . '/' . $icons[$m]; + $icon_image = file_get_contents($icon_path); + if ($icon_image) + { + $icon = sprintf ( + ' ', + mime_content_type($icon_path), + base64_encode($icon_image) + ); + } + } + + print "
  • {$icon}{$m}
  • "; } ?> diff --git a/codepot/src/config.php.in b/codepot/src/config.php.in index 6ffc6371..dcab4f3d 100644 --- a/codepot/src/config.php.in +++ b/codepot/src/config.php.in @@ -70,6 +70,7 @@ function load_ini ($file) array ('svnrepo_dir', 'string', CODEPOT_DEPOT_DIR.'/svnrepo'), array ('file_dir', 'string', CODEPOT_DEPOT_DIR.'/files'), array ('attachment_dir', 'string', CODEPOT_DEPOT_DIR.'/attachments'), + array ('usericon_dir', 'string', CODEPOT_DEPOT_DIR.'/usericons'), array ('log_threshold', 'integer', 0),