diff --git a/src/IDF/FileUtil.php b/src/IDF/FileUtil.php index c9ec8e9..725d980 100644 --- a/src/IDF/FileUtil.php +++ b/src/IDF/FileUtil.php @@ -162,15 +162,4 @@ class IDF_FileUtil $ext = array_merge(self::$supportedExtenstions, explode(' ' , $ext)); return (in_array($fileinfo[2], $ext)); } - - /* - * - */ - public static function getPictureInline($file) - { - $info = IDF_FileUtil::getMimeType($file); - $content = file_get_contents($file); - $base64 = 'data:' . $info[0] . ';base64,' . base64_encode($content); - return $base64; - } } diff --git a/src/IDF/Form/ProjectConf.php b/src/IDF/Form/ProjectConf.php index 1a3bd45..9290cde 100644 --- a/src/IDF/Form/ProjectConf.php +++ b/src/IDF/Form/ProjectConf.php @@ -54,16 +54,16 @@ class IDF_Form_ProjectConf extends Pluf_Form // Logo part $upload_path = Pluf::f('upload_path', false); - if(false === $upload_path) { - throw new Pluf_Exception_SettingError(__('The "upload_issue_path" configuration variable was not set.')); + if (false === $upload_path) { + throw new Pluf_Exception_SettingError(__('The "upload_path" configuration variable was not set.')); } - $md5 = md5(rand().microtime().Pluf_Utils::getRandomString()); - $filename = substr($md5, 0, 2).'/'.substr($md5, 2, 2).'/'.substr($md5, 4).'/%s'; + $upload_path .= '/' . $this->project->shortname; + $filename = '/%s'; $this->fields['logo'] = new Pluf_Form_Field_File(array('required' => false, 'label' => __('Update the logo'), 'initial' => '', - 'help_text' => __('The logo must be a picture with a size of 16 by 16.'), - 'max_size' => Pluf::f('max_upload_size', 2097152), + 'help_text' => __('The logo must be a picture with a size of 32 by 32.'), + 'max_size' => Pluf::f('max_upload_size', 100 * 1024), 'move_function_params' => array('upload_path' => $upload_path, 'upload_path_create' => true, @@ -84,15 +84,15 @@ class IDF_Form_ProjectConf extends Pluf_Form */ function failed() { - if(!empty($this->cleaned_data['logo']) - and file_exists(Pluf::f('upload_path').'/'.$this->cleaned_data['logo'])) { + if (!empty($this->cleaned_data['logo']) + && file_exists(Pluf::f('upload_path').'/'.$this->cleaned_data['logo'])) { unlink(Pluf::f('upload_path').'/'.$this->cleaned_data['logo']); } } public function clean() { - if(!isset($this->cleaned_data['logo_remove'])) { + if (!isset($this->cleaned_data['logo_remove'])) { $this->cleaned_data['logo_remove'] = false; } @@ -101,19 +101,18 @@ class IDF_Form_ProjectConf extends Pluf_Form public function clean_logo() { - if(!isset($this->cleaned_data['logo']) || - $this->cleaned_data['logo'] == "") { + if (empty($this->cleaned_data['logo'])) { return ''; } - $meta = getimagesize(Pluf::f('upload_path').'/'.$this->cleaned_data['logo']); + $meta = getimagesize(Pluf::f('upload_path') . '/' . $this->project->shortname . $this->cleaned_data['logo']); - if($meta === FALSE) { - throw new Pluf_Form_Invalid("Error during the determination of the size of the picture"); + if ($meta === false) { + throw new Pluf_Form_Invalid("Could not determine the size of the uploaded picture."); } - if($meta[0] !== 32 || $meta[1] !== 32) { - throw new Pluf_Form_Invalid("The picture must have a size of 16 by 16."); + if ($meta[0] !== 32 || $meta[1] !== 32) { + throw new Pluf_Form_Invalid("The picture must have a size of 32 by 32."); } return $this->cleaned_data['logo']; @@ -130,11 +129,11 @@ class IDF_Form_ProjectConf extends Pluf_Form $this->project->update(); // Logo part - if($this->cleaned_data['logo'] !== "") { + if ($this->cleaned_data['logo'] !== "") { $conf->setVal('logo', $this->cleaned_data['logo']); } - if($this->cleaned_data['logo_remove'] === true) { - @unlink(Pluf::f('upload_path').'/'.$conf->getVal('logo')); + if ($this->cleaned_data['logo_remove'] === true) { + @unlink(Pluf::f('upload_path') . '/' . $this->project->shortname . $conf->getVal('logo')); $conf->delVal('logo'); } } diff --git a/src/IDF/Views.php b/src/IDF/Views.php index 8dc92b7..da0ec0a 100644 --- a/src/IDF/Views.php +++ b/src/IDF/Views.php @@ -42,23 +42,11 @@ class IDF_Views $projects = self::getProjects($request->user); $stats = self::getProjectsStatistics ($projects); - $logos = array(); - foreach ($projects as $p) { - $logo = $p->getConf()->getVal('logo'); - if (!empty($logo)) { - $logo = Pluf::f('upload_path').'/'.$logo; - $logos[$p->shortname] = IDF_FileUtil::getPictureInline($logo); - } else { - $logos[$p->shortname] = ""; - } - } - if ($api == true) return $projects; return Pluf_Shortcuts_RenderToResponse('idf/index.html', array('page_title' => __('Projects'), 'projects' => $projects, - 'stats' => new Pluf_Template_ContextVars($stats), - 'logos' => $logos), + 'stats' => new Pluf_Template_ContextVars($stats)), $request); } diff --git a/src/IDF/Views/Project.php b/src/IDF/Views/Project.php index d78dd9c..57b63d8 100644 --- a/src/IDF/Views/Project.php +++ b/src/IDF/Views/Project.php @@ -31,6 +31,25 @@ Pluf::loadFunction('Pluf_Shortcuts_GetFormForModel'); */ class IDF_Views_Project { + /** + * Home page of a project. + */ + public $logo_precond = array('IDF_Precondition::baseAccess'); + public function logo($request, $match) + { + $prj = $request->project; + + $logo = $prj->getConf()->getVal('logo'); + if(empty($logo)) { + $url = Pluf::f('url_media') . '/idf/img/no_logo.png'; + return new Pluf_HTTP_Response_Redirect($url); + } + + $info = IDF_FileUtil::getMimeType($logo); + return new Pluf_HTTP_Response_File(Pluf::f('upload_path') . '/' . $prj->shortname . $logo, + $info[0]); + } + /** * Home page of a project. */ @@ -284,16 +303,12 @@ class IDF_Views_Project } $logo = $prj->getConf()->getVal('logo'); - if (!empty($logo)) { - $logo = Pluf::f('upload_path').'/'.$logo; - $logo_base64 = IDF_FileUtil::getPictureInline($logo); - } return Pluf_Shortcuts_RenderToResponse('idf/admin/summary.html', array( 'page_title' => $title, 'form' => $form, 'project' => $prj, - 'logo' => $logo_base64, + 'logo' => $logo, ), $request); } diff --git a/src/IDF/conf/urls.php b/src/IDF/conf/urls.php index dccf03b..7ba9582 100644 --- a/src/IDF/conf/urls.php +++ b/src/IDF/conf/urls.php @@ -73,6 +73,11 @@ $ctl[] = array('regex' => '#^/p/([\-\w]+)/$#', 'base' => $base, 'model' => 'IDF_Views_Project', 'method' => 'home'); + +$ctl[] = array('regex' => '#^/p/([\-\w]+)/logo/$#', + 'base' => $base, + 'model' => 'IDF_Views_Project', + 'method' => 'logo'); $ctl[] = array('regex' => '#^/p/([\-\w]+)/timeline/(\w+)/$#', 'base' => $base, diff --git a/src/IDF/templates/idf/admin/summary.html b/src/IDF/templates/idf/admin/summary.html index 9653ede..0436a02 100644 --- a/src/IDF/templates/idf/admin/summary.html +++ b/src/IDF/templates/idf/admin/summary.html @@ -31,10 +31,10 @@ -{trans 'Actual logo'}: +{trans 'Current logo'}: {if $logo} -project logo +{trans 'project logo'} {else} {trans 'Your project do not have a logo configured yet.'} {/if} diff --git a/src/IDF/templates/idf/index.html b/src/IDF/templates/idf/index.html index 5f70957..14d0d7b 100644 --- a/src/IDF/templates/idf/index.html +++ b/src/IDF/templates/idf/index.html @@ -12,17 +12,22 @@ {foreach $projects as $p}
- {if $logos[$p->shortname]} - {trans 'Project logo'} - {else} - {trans 'Project logo'} - {/if} + {trans 'Project logo'} - {if $p.private}
{trans 'Private project'}
{/if} + {if $p.private} +
+ + {trans 'Private project'} + +
+ {/if}
-

{$p}{if $p.private} - {trans 'Private project'}

{/if}

- {if $p.shortdesc}

{$p.shortdesc}

{/if} +

+ {$p} + {if $p.private} - {trans 'Private project'}{/if} +

+

{$p.shortdesc}

{/foreach} diff --git a/www/media/idf/css/style.css b/www/media/idf/css/style.css index 3e92715..903abc5 100644 --- a/www/media/idf/css/style.css +++ b/www/media/idf/css/style.css @@ -1049,18 +1049,21 @@ span.scm-action.property-changed { */ div.p-list-img { float: left; + height: 32px; + margin-top: .5em; } div.p-list-prj { float: left; - margin: 0 0 .5em 1em; + margin: .5em 0 .5em 1em; } div.p-list-prj p { margin: 0px; } -.p-list-private { +div.p-list-private { bottom: 10px; + right: -6px; position: relative; }