Merge branch 'feature.better-home' of projects.ceondo.com:indefero into feature.better-home

This commit is contained in:
Thomas Keller 2011-04-07 22:38:40 +02:00
commit 47a077bc82
8 changed files with 64 additions and 60 deletions

View File

@ -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;
}
}

View File

@ -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');
}
}

View File

@ -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);
}

View File

@ -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.
*/
@ -290,16 +309,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);
}

View File

@ -74,6 +74,11 @@ $ctl[] = array('regex' => '#^/p/([\-\w]+)/$#',
'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,
'model' => 'IDF_Views_Project',

View File

@ -31,10 +31,10 @@
</td>
</tr>
<tr>
<th><strong>{trans 'Actual logo'}:</strong></th>
<th><strong>{trans 'Current logo'}:</strong></th>
<td>
{if $logo}
<img src="{$logo}" alt="project logo" />
<img src="{url 'IDF_Views_Project::logo', array($project.shortname)}" alt="{trans 'project logo'}" />
{else}
{trans 'Your project do not have a logo configured yet.'}
{/if}

View File

@ -12,17 +12,22 @@
{foreach $projects as $p}
<div class="p-list-img">
<a href="{url 'IDF_Views_Project::home', array($p.shortname)}">
{if $logos[$p->shortname]}
<img src="{$logos[$p->shortname]}" alt="{trans 'Project logo'}" />
{else}
<img src="{media '/idf/img/no_logo.png'}" alt="{trans 'Project logo'}" />
{/if}
<img src="{url 'IDF_Views_Project::logo', array($p.shortname)}" alt="{trans 'Project logo'}" />
</a>
{if $p.private}<div class="p-list-private"><a href="{url 'IDF_Views_Project::home', array($p.shortname)}"><img style="float:right" src="{media '/idf/img/lock.png'}" alt="{trans 'Private project'}" /></a></div>{/if}
{if $p.private}
<div class="p-list-private">
<a href="{url 'IDF_Views_Project::home', array($p.shortname)}">
<img style="float:right" src="{media '/idf/img/lock.png'}" alt="{trans 'Private project'}" />
</a>
</div>
{/if}
</div>
<div class="p-list-prj">
<p><a href="{url 'IDF_Views_Project::home', array($p.shortname)}"><strong>{$p}</strong></a>{if $p.private} - {trans 'Private project'}</p>{/if}</p>
{if $p.shortdesc}<p>{$p.shortdesc}</p>{/if}
<p>
<a href="{url 'IDF_Views_Project::home', array($p.shortname)}"><strong>{$p}</strong></a>
{if $p.private} - {trans 'Private project'}{/if}
</p>
<p>{$p.shortdesc}</p>
</div>
<div style="clear: both"></div>
{/foreach}

View File

@ -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;
}