Indefero

Indefero Commit Details


Date:2011-04-06 08:33:26 (13 years 8 months ago)
Author:William MARTIN
Branch:develop, feature-issue_links, feature.better-home, feature.content-md5, feature.diff-whitespace, feature.download-md5, feature.issue-links, feature.issue-of-others, feature.issue-summary, feature.search-filter, feature.webrepos, feature.wiki-default-page, release-1.2, release-1.3
Commit:836ff71364668ae7ae190530caf2d3ed5dd4e7db
Parents: 352dc3e179cfa1dc804552aef1e4e83728422306
Message:Update code to fix thomas review's

Changes:

File differences

src/IDF/FileUtil.php
162162
163163
164164
165
166
167
168
169
170
171
172
173
174
175
176165
$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;
}
}
src/IDF/Form/ProjectConf.php
5454
5555
5656
57
58
57
58
5959
60
61
60
61
6262
6363
6464
65
66
65
66
6767
6868
6969
......
8484
8585
8686
87
88
87
88
8989
9090
9191
9292
9393
9494
95
95
9696
9797
9898
......
101101
102102
103103
104
105
104
106105
107106
108107
109
108
110109
111
112
110
111
113112
114113
115
116
114
115
117116
118117
119118
......
130129
131130
132131
133
132
134133
135134
136
137
135
136
138137
139138
140139
// 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,
*/
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;
}
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'];
$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');
}
}
src/IDF/Views.php
4242
4343
4444
45
46
47
48
49
50
51
52
53
54
55
5645
5746
5847
5948
60
61
49
6250
6351
6452
$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);
}
src/IDF/Views/Project.php
3434
3535
3636
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
3756
3857
3958
......
284303
285304
286305
287
288
289
290
291306
292307
293308
294309
295310
296
311
297312
298313
299314
/**
* 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.
*/
public $home_precond = array('IDF_Precondition::baseAccess');
public function home($request, $match)
{
}
$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);
}
src/IDF/conf/urls.php
7373
7474
7575
76
77
78
79
80
7681
7782
7883
'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,
src/IDF/templates/idf/admin/summary.html
3131
3232
3333
34
34
3535
3636
37
37
3838
3939
4040
</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}
src/IDF/templates/idf/index.html
1212
1313
1414
15
16
17
18
19
15
2016
21
17
18
19
20
21
22
23
2224
2325
24
25
26
27
28
29
30
2631
2732
2833
{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}
www/media/idf/css/style.css
10491049
10501050
10511051
1052
1053
10521054
10531055
10541056
10551057
1056
1058
10571059
10581060
10591061
10601062
10611063
10621064
1063
1065
10641066
1067
10651068
10661069
*/
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;
}

Archive Download the corresponding diff file

Page rendered in 0.11220s using 13 queries.