Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
open-source
hacklab-blocks
Commits
618a464f
Commit
618a464f
authored
1 year ago
by
Matheus Gimenez
Browse files
Options
Download
Email Patches
Plain Diff
Remove playlist dos resultados / garante ordenação por data de publicação
parent
6d710fde
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
0 deletions
+12
-0
blocks/video-playlist/video-playlist.php
blocks/video-playlist/video-playlist.php
+12
-0
No files found.
blocks/video-playlist/video-playlist.php
View file @
618a464f
...
...
@@ -166,6 +166,7 @@ function video_playlist_callback($attributes = [])
$url
=
"https://www.googleapis.com/youtube/v3/playlistItems?"
.
$query
;
}
else
if
(
$youtube_format
==
'channel'
)
{
$query_array
[
'channelId'
]
=
$youtube_id
;
$query_array
[
'type'
]
=
'video'
;
$query
=
http_build_query
(
$query_array
);
$url
=
"https://www.googleapis.com/youtube/v3/search?"
.
$query
;
}
...
...
@@ -189,6 +190,16 @@ function video_playlist_callback($attributes = [])
* e pega os primeiros videos de acordo com o maxResults.
*
*/
$result
=
json_decode
(
get_content
(
$url
,
get_site_url
()));
// ordena os videos
usort
(
$result
->
items
,
function
(
$a
,
$b
)
{
$dataA
=
strtotime
(
$a
->
snippet
->
publishedAt
);
$dataB
=
strtotime
(
$b
->
snippet
->
publishedAt
);
return
$dataA
>
$dataB
?
-
1
:
1
;
});
$result
->
items
=
array_slice
(
$result
->
items
,
0
,
$max_num
);
}
set_transient
(
$cache_key
,
$result
,
30
*
MINUTE_IN_SECONDS
);
...
...
@@ -198,6 +209,7 @@ function video_playlist_callback($attributes = [])
}
}
if
(
!
$result
->
items
)
{
return
;
}
...
...
This diff is collapsed.
Click to expand it.
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