srchub

srchub Commit Details


Date:2015-10-16 22:09:57 (9 years 2 months ago)
Author:Natalie Adams
Branch:master
Commit:75986bb272ed6925d480880c4525857c417cbcdf
Parents: 4421b6d4a181fd9f4d26cab2451911f033a61454
Message:Issue 81: Allow users to create downloads that point offsite

Changes:

File differences

indefero/src/IDF/Form/Upload.php
4444
4545
4646
47
48
49
50
51
52
53
54
55
4756
4857
4958
......
5564
5665
5766
58
67
5968
6069
6170
......
8089
8190
8291
92
93
94
8395
8496
8597
......
121133
122134
123135
136
137
138
124139
125140
126141
......
162177
163178
164179
180
165181
166182
167183
168184
169185
170186
171
172
187
188
189
190
191
192
193
194
173195
174196
175197
'size' => 67,
),
));
$this->fields['ext_file'] = new Pluf_Form_Field_Varchar(
array('required' => false,
'label' => __('External File'),
'initial' => '',
'widget_attrs' => array(
'maxlength' => 200,
'size' => 67,
),
));
$this->fields['changelog'] = new Pluf_Form_Field_Varchar(
array('required' => false,
'label' => __('Description'),
),
));
$this->fields['file'] = new Pluf_Form_Field_File(
array('required' => true,
array('required' => false,
'label' => __('File'),
'initial' => '',
'max_size' => Pluf::f('max_upload_size', 2097152),
public function clean_file()
{
// FIXME: we do the same in IDF_Form_WikiResourceCreate and a couple of other places as well
if (empty($this->cleaned_data['file'])) {
return $this->cleaned_data['file'];
}
$extra = strtolower(implode('|', explode(' ', Pluf::f('idf_extra_upload_ext'))));
if (strlen($extra)) $extra .= '|';
if (!preg_match('/\.('.$extra.'png|jpg|jpeg|gif|bmp|psd|tif|aiff|asf|avi|bz2|css|doc|eps|gz|jar|mdtext|mid|mov|mp3|mpg|ogg|pdf|ppt|ps|qt|ra|ram|rm|rtf|sdd|sdw|sit|sxi|sxw|swf|tgz|txt|wav|xls|xml|war|wmv|zip)$/i', $this->cleaned_data['file'])) {
throw new Pluf_Form_Invalid(__('You provided an invalid label.'));
}
}
if (empty($this->cleaned_data["file"]) && empty($this->cleaned_data["ext_file"])) {
throw new Pluf_Form_Invalid(__("Must upload a file or specify an external file"));
}
return $this->cleaned_data;
}
$tags[] = IDF_Tag::add($name, $this->project, $class);
}
}
// Create the upload
$upload = new IDF_Upload();
$upload->project = $this->project;
$upload->submitter = $this->user;
$upload->summary = trim($this->cleaned_data['summary']);
$upload->changelog = trim($this->cleaned_data['changelog']);
$upload->file = $this->cleaned_data['file'];
$upload->filesize = filesize(Pluf::f('upload_path').'/'.$this->project->shortname.'/files/'.$this->cleaned_data['file']);
if (!empty($this->cleaned_data["file"])) {
$upload->file = $this->cleaned_data['file'];
$upload->filesize = filesize(Pluf::f('upload_path').'/'.$this->project->shortname.'/files/'.$this->cleaned_data['file']);
} else {
$upload->file = end(explode("/", $this->cleaned_data["ext_file"]));
$upload->ext_file = $this->cleaned_data['ext_file'];
}
$upload->downloads = 0;
$upload->create();
foreach ($tags as $tag) {
indefero/src/IDF/Migrations/32ExternalFile.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
function IDF_Migrations_32ExternalFile_up()
{
$table = Pluf::factory('IDF_Upload')->getSqlTable();
$sql = array();
$sql["MySQL"] = "ALTER TABLE " . $table . " ADD COLUMN `ext_file` VARCHAR(250) NULL AFTER `modif_dtime`;";
$db = Pluf::db();
$engine = Pluf::f('db_engine');
$db->execute($sql[$engine]);
}
function IDF_Migrations_32ExternalFile_down()
{
$table = Pluf::factory('IDF_Upload')->getSqlTable();
$sql = array();
$sql["MySQL"] = "ALTER TABLE " . $table . " DROP COLUMN `ext_file`;";
$db = Pluf::db();
$engine = Pluf::f('db_engine');
$db->execute($sql[$engine]);
}
indefero/src/IDF/Upload.php
5656
5757
5858
59
60
61
62
63
64
65
5966
6067
6168
......
140147
141148
142149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
143198
144199
145200
......
150205
151206
152207
153
208
209
210
211
212
154213
155214
156215
'size' => 250,
'verbose' => __('summary'),
),
'ext_file' =>
array(
'type' => 'Pluf_DB_Field_Varchar',
'blank' => false,
'size' => 250,
'verbose' => __('External File URL'),
),
'changelog' =>
array(
'type' => 'Pluf_DB_Field_Text',
return $this->file;
}
/**
* Get the file size of any remote resource (using get_headers()),
* either in bytes or - default - as human-readable formatted string.
*
* @author Stephan Schmitz <eyecatchup@gmail.com>
* @license MIT <http://eyecatchup.mit-license.org/>
* @url <https://gist.github.com/eyecatchup/f26300ffd7e50a92bc4d>
*
* @param string $url Takes the remote object's URL.
* @param boolean $formatSize Whether to return size in bytes or formatted.
* @param boolean $useHead Whether to use HEAD requests. If false, uses GET.
* @return string Returns human-readable formatted size
* or size in bytes (default: formatted).
*
* <code>
* //example
* echo getRemoteFilesize('https://github.com/eyecatchup/SEOstats/archive/master.zip');
* </code>
*/
private function getRemoteFilesize($url, $formatSize = true, $useHead = true)
{
if (false !== $useHead) {
stream_context_set_default(array('http' => array('method' => 'HEAD')));
}
$head = array_change_key_case(get_headers($url, 1));
// content-length of download (in bytes), read from Content-Length: field
$clen = isset($head['content-length']) ? $head['content-length'] : 0;
// cannot retrieve file size, return "-1"
if (!$clen) {
return -1;
}
if (!$formatSize) {
return $clen; // return size in bytes
}
$size = $clen;
switch ($clen) {
case $clen < 1024:
$size = $clen .' B'; break;
case $clen < 1048576:
$size = round($clen / 1024, 2) .' KiB'; break;
case $clen < 1073741824:
$size = round($clen / 1048576, 2) . ' MiB'; break;
case $clen < 1099511627776:
$size = round($clen / 1073741824, 2) . ' GiB'; break;
}
return $size; // return formatted size
}
function _toIndex()
{
return '';
if ($this->id == '') {
$this->creation_dtime = gmdate('Y-m-d H:i:s');
$this->modif_dtime = gmdate('Y-m-d H:i:s');
$this->md5 = md5_file ($this->getFullPath());
if ($this->ext_file == "") {
$this->md5 = md5_file ($this->getFullPath());
} else {
$this->filesize = $this->getRemoteFilesize($this->ext_file, false);
}
}
}
indefero/src/IDF/Views/Download.php
204204
205205
206206
207
208
209
210
211
207
208
209
210
211
212
213
214
215
212216
213217
214218
$prj->inOr404($upload);
$upload->downloads += 1;
$upload->update();
$path = $upload->getFullPath();
$mime = IDF_FileUtil::getMimeType($path);
$render = new Pluf_HTTP_Response_File($path, $mime[0]);
$render->headers['Content-MD5'] = $upload->md5;
$render->headers['Content-Disposition'] = 'attachment; filename="'.$upload->file.'"';
if ($upload->ext_file == "") {
$path = $upload->getFullPath();
$mime = IDF_FileUtil::getMimeType($path);
$render = new Pluf_HTTP_Response_File($path, $mime[0]);
$render->headers['Content-MD5'] = $upload->md5;
$render->headers['Content-Disposition'] = 'attachment; filename="'.$upload->file.'"';
} else {
$render = new Pluf_HTTP_Response_Redirect($upload->ext_file);
}
return $render;
}
indefero/src/IDF/templates/idf/downloads/create.html
1919
2020
2121
22
23
24
25
26
27
2228
2329
2430
</td>
</tr>
<tr>
<th><strong>{$form.f.ext_file.labelTag}:</strong></th>
<td>{if $form.f.ext_file.errors}{$form.f.ext_file.fieldErrors}{/if}
{$form.f.ext_file|unsafe}
</td>
</tr>
<tr>
<th>{$form.f.changelog.labelTag}:</th>
<td>{if $form.f.changelog.errors}{$form.f.changelog.fieldErrors}{/if}
{$form.f.changelog|unsafe}
indefero/src/IDF/templates/idf/downloads/view.html
44
55
66
7
78
9
810
911
12
13
14
1015
1116
1217
<div class="download-file">
{if $deprecated}<p class="smaller">{blocktrans}<strong>Attention!</strong> This file is marked as deprecated, download it only if you are sure you need this specific version.{/blocktrans}</p>{/if}
<a href="{url 'IDF_Views_Download::download', array($project.shortname, $file.file)}">{$file}</a> - {$file.filesize|size}
{if !$file.ext_file}
<br />
<span class="helptext">{trans 'md5:'} {$file.md5}</span>
{/if}
</div>
{if $file.changelog}
<h2 class="changes">{trans 'Changes'}</h2>

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.08398s using 20 queries.