Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Ad Aures
Castopod
Commits
c5f18bb6
Commit
c5f18bb6
authored
Dec 15, 2021
by
Yassine Doghri
Browse files
fix(import): add extension when downloading file without + truncate slug if too long
parent
d86315ed
Pipeline
#1154
passed with stages
in 11 minutes and 4 seconds
Changes
6
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
app/Config/Mimes.php
View file @
c5f18bb6
...
...
@@ -131,9 +131,9 @@ class Mimes
'rar'
=>
[
'application/vnd.rar'
,
'application/x-rar'
,
'application/rar'
,
'application/x-rar-compressed'
],
'mid'
=>
'audio/midi'
,
'midi'
=>
'audio/midi'
,
'mp3'
=>
[
'audio/mpeg'
,
'audio/mpg'
,
'audio/mpeg3'
,
'audio/mp3'
],
'mpga'
=>
'audio/mpeg'
,
'mp2'
=>
'audio/mpeg'
,
'mp3'
=>
[
'audio/mpeg'
,
'audio/mpg'
,
'audio/mpeg3'
,
'audio/mp3'
],
'aif'
=>
[
'audio/x-aiff'
,
'audio/aiff'
],
'aiff'
=>
[
'audio/x-aiff'
,
'audio/aiff'
],
'aifc'
=>
'audio/x-aiff'
,
...
...
@@ -306,10 +306,10 @@ class Mimes
/**
* Attempts to determine the best file extension for a given mime type.
*
* @param string
|null
$proposedExtension - default extension (in case there is more than one with the same mime type)
* @param string $proposedExtension - default extension (in case there is more than one with the same mime type)
* @return string|null The extension determined, or null if unable to match.
*/
public
static
function
guessExtensionFromType
(
string
$type
,
string
$proposedExtension
=
null
):
?string
public
static
function
guessExtensionFromType
(
string
$type
,
string
$proposedExtension
=
''
):
?string
{
$type
=
trim
(
strtolower
(
$type
),
'. '
);
...
...
app/Controllers/Admin/PodcastImportController.php
View file @
c5f18bb6
...
...
@@ -305,11 +305,10 @@ class PodcastImportController extends BaseController
);
$nsContent
=
$item
->
children
(
'http://purl.org/rss/1.0/modules/content/'
);
$slug
=
slugify
(
$this
->
request
->
getPost
(
'slug_field'
)
===
'title'
?
(
string
)
$item
->
title
:
basename
((
string
)
$item
->
link
),
);
$textToSlugify
=
$this
->
request
->
getPost
(
'slug_field'
)
===
'title'
?
(
string
)
$item
->
title
:
basename
((
string
)
$item
->
link
);
$slug
=
slugify
(
$textToSlugify
,
185
);
if
(
in_array
(
$slug
,
$slugs
,
true
))
{
$slugNumber
=
2
;
while
(
in_array
(
$slug
.
'-'
.
$slugNumber
,
$slugs
,
true
))
{
...
...
@@ -348,7 +347,10 @@ class PodcastImportController extends BaseController
'title'
=>
$item
->
title
,
'slug'
=>
$slug
,
'guid'
=>
$item
->
guid
??
null
,
'audio_file'
=>
download_file
((
string
)
$item
->
enclosure
->
attributes
()[
'url'
]),
'audio_file'
=>
download_file
(
(
string
)
$item
->
enclosure
->
attributes
()[
'url'
],
(
string
)
$item
->
enclosure
->
attributes
()[
'type'
]
),
'description_markdown'
=>
$converter
->
convert
(
$itemDescriptionHtml
),
'description_html'
=>
$itemDescriptionHtml
,
'image'
=>
$episodeImage
,
...
...
app/Helpers/media_helper.php
View file @
c5f18bb6
...
...
@@ -11,6 +11,7 @@ declare(strict_types=1);
use
CodeIgniter\Files\File
;
use
CodeIgniter\HTTP\Files\UploadedFile
;
use
CodeIgniter\HTTP\ResponseInterface
;
use
Config\Mimes
;
use
Config\Services
;
if
(
!
function_exists
(
'save_media'
))
{
...
...
@@ -41,7 +42,7 @@ if (! function_exists('save_media')) {
}
if
(
!
function_exists
(
'download_file'
))
{
function
download_file
(
string
$fileUrl
):
File
function
download_file
(
string
$fileUrl
,
string
$mimetype
=
''
):
File
{
$client
=
Services
::
curlrequest
();
...
...
@@ -75,12 +76,15 @@ if (! function_exists('download_file')) {
'http_errors'
=>
false
,
]);
}
$fileExtension
=
pathinfo
(
parse_url
(
$newFileUrl
,
PHP_URL_PATH
),
PATHINFO_EXTENSION
);
$extension
=
$fileExtension
===
''
?
Mimes
::
guessExtensionFromType
(
$mimetype
)
:
$fileExtension
;
$tmpFilename
=
time
()
.
'_'
.
bin2hex
(
random_bytes
(
10
))
.
'.'
.
pathinfo
(
parse_url
(
$newFileUrl
,
PHP_URL_PATH
),
PATHINFO_EXTENSION
)
;
$extension
;
$tmpFilePath
=
WRITEPATH
.
'uploads/'
.
$tmpFilename
;
file_put_contents
(
$tmpFilePath
,
$response
->
getBody
());
...
...
app/Helpers/misc_helper.php
View file @
c5f18bb6
...
...
@@ -23,8 +23,13 @@ if (! function_exists('get_browser_language')) {
}
if
(
!
function_exists
(
'slugify'
))
{
function
slugify
(
string
$text
):
string
function
slugify
(
string
$text
,
int
$maxLength
=
191
):
string
{
// trim text to the nearest whole word if too long
if
(
strlen
(
$text
)
>
$maxLength
)
{
$text
=
substr
(
$text
,
0
,
strrpos
(
substr
(
$text
,
0
,
$maxLength
),
' '
));
}
// replace non letter or digits by -
$text
=
preg_replace
(
'~[^\pL\d]+~u'
,
'-'
,
$text
);
...
...
app/Views/admin/podcast/import.php
View file @
c5f18bb6
...
...
@@ -89,29 +89,29 @@
<?=
form_fieldset
(
''
,
[
'class'
=>
'flex flex-col mb-4'
])
?>
<legend>
<?=
lang
(
'PodcastImport.slug_field.label'
)
?>
</legend>
<label
for=
"
link
"
class=
"inline-flex items-center"
>
<label
for=
"
title
"
class=
"inline-flex items-center"
>
<?=
form_radio
(
[
'id'
=>
'
link
'
,
'id'
=>
'
title
'
,
'name'
=>
'slug_field'
,
'class'
=>
'form-radio text-pine-700'
,
],
'
link
'
,
old
(
'slug_field'
)
?
old
(
'slug_field'
)
==
'
link
'
:
true
,
'
title
'
,
old
(
'slug_field'
)
?
old
(
'slug_field'
)
==
=
'
title
'
:
true
,
)
?>
<span
class=
"ml-2"
>
<?=
lang
(
'PodcastImport.slug_field.
link
'
)
?>
</span>
<span
class=
"ml-2"
>
<?=
lang
(
'PodcastImport.slug_field.
title
'
)
?>
</span>
</label>
<label
for=
"
title
"
class=
"inline-flex items-center"
>
<label
for=
"
link
"
class=
"inline-flex items-center"
>
<?=
form_radio
(
[
'id'
=>
'
title
'
,
'id'
=>
'
link
'
,
'name'
=>
'slug_field'
,
'class'
=>
'form-radio text-pine-700'
,
],
'
title
'
,
old
(
'slug_field'
)
&&
old
(
'slug_field'
)
==
'
title
'
,
'
link
'
,
old
(
'slug_field'
)
&&
old
(
'slug_field'
)
==
=
'
link
'
,
)
?>
<span
class=
"ml-2"
>
<?=
lang
(
'PodcastImport.slug_field.
title
'
)
?>
</span>
<span
class=
"ml-2"
>
<?=
lang
(
'PodcastImport.slug_field.
link
'
)
?>
</span>
</label>
<?=
form_fieldset_close
()
?>
...
...
composer.lock
View file @
c5f18bb6
...
...
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "
371c6aac9ca489338bf3b3fa06ffdb21
",
"content-hash": "
49719de3dd6af8c394ea0553e2180b5a
",
"packages": [
{
"name": "brick/math",
...
...
@@ -494,24 +494,24 @@
},
{
"name": "james-heinrich/getid3",
"version": "v2.0.0-beta
3
",
"version": "v2.0.0-beta
4
",
"source": {
"type": "git",
"url": "https://github.com/JamesHeinrich/getID3.git",
"reference": "5
515a2d24667c3c0ff49fdcbdadc405c0880c7a2
"
"reference": "5
ad79104e937e7d9c8a9141a97e1f063dd1123f8
"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/JamesHeinrich/getID3/zipball/5
515a2d24667c3c0ff49fdcbdadc405c0880c7a2
",
"reference": "5
515a2d24667c3c0ff49fdcbdadc405c0880c7a2
",
"url": "https://api.github.com/repos/JamesHeinrich/getID3/zipball/5
ad79104e937e7d9c8a9141a97e1f063dd1123f8
",
"reference": "5
ad79104e937e7d9c8a9141a97e1f063dd1123f8
",
"shasum": ""
},
"require": {
"php": ">=5.4.0"
},
"require-dev": {
"
jakub-onderka
/php-parallel-lint": "
^0.9 ||
^1.0",
"phpunit/phpunit": "^4.8
|^5.0
"
"
php-parallel-lint
/php-parallel-lint": "^1.0",
"phpunit/phpunit": "^4.8
|| ^5.0 || ^6.1 || ^7.5 || ^8.5
"
},
"suggest": {
"ext-SimpleXML": "SimpleXML extension is required to analyze RIFF/WAV/BWF audio files (also requires `ext-libxml`).",
...
...
@@ -562,9 +562,9 @@
"keywords": ["audio", "codecs", "id3", "metadata", "tags", "video"],
"support": {
"issues": "https://github.com/JamesHeinrich/getID3/issues",
"source": "https://github.com/JamesHeinrich/getID3/tree/2.0"
"source": "https://github.com/JamesHeinrich/getID3/tree/
v
2.0
.0-beta4
"
},
"time": "202
0-07-21T08:15
:4
4
+00:00"
"time": "202
1-10-06T16:23
:4
5
+00:00"
},
{
"name": "kint-php/kint",
...
...
@@ -7465,5 +7465,5 @@
"php": "^8.0"
},
"platform-dev": [],
"plugin-api-version": "2.
0
.0"
"plugin-api-version": "2.
1
.0"
}
Yassine Doghri
@yassine
mentioned in commit
548234aa
·
Dec 15, 2021
mentioned in commit
548234aa
mentioned in commit 548234aa4d981486fa536a24671c353ea88326fc
Toggle commit list
Yassine Doghri
@yassine
mentioned in commit
d807ab97
·
Jan 23, 2022
mentioned in commit
d807ab97
mentioned in commit d807ab9732d8e4ad1eae956f0b728f8a5c0f868d
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment