Skip to content

Commit

Permalink
Обновы для плейлистов и поиска (#1137)
Browse files Browse the repository at this point in the history
* search: a bit refactor

* search: a bit refactor 2

* audios: a bit changes

* results highlight, midnight changes, player insear

* add audio download button, simplify css

* upload page changes, add playlist add menu

* -comments search, arrow keys on tips

* move $query var and optimize users/groups.search

го рофлить

* слегка проебался
  • Loading branch information
mrilyew authored Oct 25, 2024
1 parent b3e5714 commit 53f6b3e
Show file tree
Hide file tree
Showing 55 changed files with 2,451 additions and 1,556 deletions.
76 changes: 0 additions & 76 deletions ServiceAPI/Search.php

This file was deleted.

13 changes: 9 additions & 4 deletions VKAPI/Handlers/Audio.php
Original file line number Diff line number Diff line change
Expand Up @@ -581,13 +581,18 @@ function getAlbums(int $owner_id = 0, int $offset = 0, int $count = 50, int $dro
];
}

function searchAlbums(string $query, int $offset = 0, int $limit = 25, int $drop_private = 0): object
function searchAlbums(string $query = '', int $offset = 0, int $limit = 25, int $drop_private = 0, int $order = 0, int $from_me = 0): object
{
$this->requireUser();

$playlists = [];
$search = (new Audios)->searchPlaylists($query)->offsetLimit($offset, $limit);
foreach($search as $playlist) {
$params = [];
$order_str = (['id', 'length', 'listens'][$order] ?? 'id');
if($from_me === 1)
$params['from_me'] = $this->getUser()->getId();

$search = (new Audios)->findPlaylists($query, $params, ['type' => $order_str, 'invert' => false]);
foreach($search->offsetLimit($offset, $limit) as $playlist) {
if(!$playlist->canBeViewedBy($this->getUser())) {
if($drop_private == 0)
$playlists[] = NULL;
Expand All @@ -599,7 +604,7 @@ function searchAlbums(string $query, int $offset = 0, int $limit = 25, int $drop
}

return (object) [
"count" => sizeof($playlists),
"count" => $search->size(),
"items" => $playlists,
];
}
Expand Down
21 changes: 14 additions & 7 deletions VKAPI/Handlers/Groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,23 +252,30 @@ function getById(string $group_ids = "", string $group_id = "", string $fields =
return $response;
}

function search(string $q, int $offset = 0, int $count = 100)
function search(string $q, int $offset = 0, int $count = 100, string $fields = "screen_name,is_admin,is_member,is_advertiser,photo_50,photo_100,photo_200")
{
if($count > 100) {
$this->fail(100, "One of the parameters specified was missing or invalid: count should be less or equal to 100");
}

$clubs = new ClubsRepo;

$array = [];
$find = $clubs->find($q);

foreach ($find as $group)
foreach ($find->offsetLimit($offset, $count) as $group)
$array[] = $group->getId();

if(!$array || sizeof($array) < 1) {
return (object) [
"count" => 0,
"items" => [],
];
}

return (object) [
"count" => $find->size(),
"items" => $this->getById(implode(',', $array), "", "is_admin,is_member,is_advertiser,photo_50,photo_100,photo_200", $offset, $count)
/*
* As there is no thing as "fields" by the original documentation
* i'll just bake this param by the example shown here: https://dev.vk.com/method/groups.search
*/
"items" => $this->getById(implode(',', $array), "", $fields)
];
}

Expand Down
118 changes: 61 additions & 57 deletions VKAPI/Handlers/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ function get(string $user_ids = "0", string $fields = "", int $offset = 0, int $
case 'is_dead':
$response[$i]->is_dead = $usr->isDead();
break;
case 'nickname':
$response[$i]->nickname = $usr->getPseudo();
break;
}
}

Expand Down Expand Up @@ -314,89 +317,90 @@ function search(string $q,
int $count = 100,
string $city = "",
string $hometown = "",
int $sex = 2,
int $status = 0, # это про marital status
int $sex = 3,
int $status = 0, # marital_status
bool $online = false,
# дальше идут параметры которых нету в vkapi но есть на сайте
string $profileStatus = "", # а это уже нормальный статус
# non standart params:
int $sort = 0,
int $before = 0,
int $politViews = 0,
int $after = 0,
string $interests = "",
int $polit_views = 0,
string $fav_music = "",
string $fav_films = "",
string $fav_shows = "",
string $fav_books = "",
string $fav_quotes = ""
string $fav_books = ""
)
{
$users = new UsersRepo;

$sortg = "id ASC";
if($count > 100) {
$this->fail(100, "One of the parameters specified was missing or invalid: count should be less or equal to 100");
}

$nfilds = $fields;
$users = new UsersRepo;
$output_sort = ['type' => 'id', 'invert' => false];
$output_params = [
"ignore_private" => true,
];

switch($sort) {
default:
case 0:
$sortg = "id DESC";
$output_sort = ['type' => 'id', 'invert' => false];
break;
case 1:
$sortg = "id ASC";
break;
case 2:
$sortg = "first_name DESC";
break;
case 3:
$sortg = "first_name ASC";
$output_sort = ['type' => 'id', 'invert' => true];
break;
case 4:
$sortg = "rating DESC";
$output_sort = ['type' => 'rating', 'invert' => false];
break;
}

if(!str_contains($nfilds, "rating")) {
$nfilds .= "rating";
}
if(!empty($city))
$output_params['city'] = $city;

break;
case 5:
$sortg = "rating DESC";
if(!empty($hometown))
$output_params['hometown'] = $hometown;

if(!str_contains($nfilds, "rating")) {
$nfilds .= "rating";
}
if($sex != 3)
$output_params['gender'] = $sex;

break;
}
if($status != 0)
$output_params['marital_status'] = $status;

if($polit_views != 0)
$output_params['polit_views'] = $polit_views;

$array = [];
if(!empty($interests))
$output_params['interests'] = $interests;

$parameters = [
"city" => !empty($city) ? $city : NULL,
"hometown" => !empty($hometown) ? $hometown : NULL,
"gender" => $sex < 2 ? $sex : NULL,
"maritalstatus" => (bool)$status ? $status : NULL,
"politViews" => (bool)$politViews ? $politViews : NULL,
"is_online" => $online ? 1 : NULL,
"status" => !empty($profileStatus) ? $profileStatus : NULL,
"before" => $before != 0 ? $before : NULL,
"after" => $after != 0 ? $after : NULL,
"interests" => !empty($interests) ? $interests : NULL,
"fav_music" => !empty($fav_music) ? $fav_music : NULL,
"fav_films" => !empty($fav_films) ? $fav_films : NULL,
"fav_shows" => !empty($fav_shows) ? $fav_shows : NULL,
"fav_books" => !empty($fav_books) ? $fav_books : NULL,
"fav_quotes" => !empty($fav_quotes) ? $fav_quotes : NULL,
"doNotSearchPrivate" => true,
];
if(!empty($fav_music))
$output_params['fav_music'] = $fav_music;

if(!empty($fav_films))
$output_params['fav_films'] = $fav_films;

$find = $users->find($q, $parameters, $sortg);
if(!empty($fav_shows))
$output_params['fav_shows'] = $fav_shows;

if(!empty($fav_books))
$output_params['fav_books'] = $fav_books;

foreach ($find as $user)
if($online)
$output_params['is_online'] = 1;

$array = [];
$find = $users->find($q, $output_params, $output_sort);

foreach ($find->offsetLimit($offset, $count) as $user)
$array[] = $user->getId();

if(!$array || sizeof($array) < 1) {
return (object) [
"count" => 0,
"items" => [],
];
}

return (object) [
"count" => $find->size(),
"items" => $this->get(implode(',', $array), $nfilds, $offset, $count)
"count" => $find->size(),
"items" => $this->get(implode(',', $array), $fields)
];
}

Expand Down
56 changes: 56 additions & 0 deletions VKAPI/Handlers/Video.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,60 @@ function get(int $owner_id, string $videos = "", int $offset = 0, int $count = 3
];
}
}

function search(string $q = '', int $sort = 0, int $offset = 0, int $count = 10, bool $extended = false, string $fields = ''): object
{
$this->requireUser();

$params = [];
$db_sort = ['type' => 'id', 'invert' => false];
$videos = (new VideosRepo)->find($q, $params, $db_sort);
$items = iterator_to_array($videos->offsetLimit($offset, $count));
$count = $videos->size();

$return_items = [];
$profiles = [];
$groups = [];
foreach($items as $item)
$return_item = $item->getApiStructure($this->getUser());
$return_item = $return_item->video;
$return_items[] = $return_item;

if($return_item['owner_id']) {
if($return_item['owner_id'] > 0)
$profiles[] = $return_item['owner_id'];
else
$groups[] = abs($return_item['owner_id']);
}

if($extended) {
$profiles = array_unique($profiles);
$groups = array_unique($groups);

$profilesFormatted = [];
$groupsFormatted = [];

foreach($profiles as $prof) {
$profile = (new UsersRepo)->get($prof);
$profilesFormatted[] = $profile->toVkApiStruct($this->getUser(), $fields);
}

foreach($groups as $gr) {
$group = (new ClubsRepo)->get($gr);
$groupsFormatted[] = $group->toVkApiStruct($this->getUser(), $fields);
}

return (object) [
"count" => $count,
"items" => $return_items,
"profiles" => $profilesFormatted,
"groups" => $groupsFormatted,
];
}

return (object) [
"count" => $count,
"items" => $return_items,
];
}
}
5 changes: 5 additions & 0 deletions Web/Models/Entities/Audio.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ function getName(): string
return $this->getPerformer() . "" . $this->getTitle();
}

function getDownloadName(): string
{
return preg_replace('/[\\/:*?"<>|]/', '_', str_replace(' ', '_', $this->getName()));
}

function getGenre(): ?string
{
return $this->getRecord()->genre;
Expand Down
2 changes: 1 addition & 1 deletion Web/Models/Entities/Club.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ function getAudiosCollectionSize()
return (new \openvk\Web\Models\Repositories\Audios)->getClubCollectionSize($this);
}

function toVkApiStruct(?User $user = NULL): object
function toVkApiStruct(?User $user = NULL, string $fields = ''): object
{
$res = (object) [];

Expand Down
Loading

0 comments on commit 53f6b3e

Please sign in to comment.