Compare commits

...

2 commits

Author SHA1 Message Date
mrilyew
59513bf2e2 Update Photos.php 2025-04-03 21:50:28 +03:00
mrilyew
e4983df532 feat(settings): move js settings from feed settigs 2025-04-03 21:42:03 +03:00
5 changed files with 72 additions and 40 deletions

View file

@ -278,19 +278,23 @@ final class Photos extends VKAPIRequestHandler
$album = (new Albums())->getAlbumByOwnerAndId($owner_id, $album_id); $album = (new Albums())->getAlbumByOwnerAndId($owner_id, $album_id);
if (!$album || $album->isDeleted() || $album->isCreatedBySystem()) if (!$album || $album->isDeleted() || $album->isCreatedBySystem()) {
$this->fail(114, "Invalid album id"); $this->fail(114, "Invalid album id");
if (!$album->canBeModifiedBy($this->getUser())) }
if (!$album->canBeModifiedBy($this->getUser())) {
$this->fail(15, "Access denied"); $this->fail(15, "Access denied");
}
if (!is_null($title) && !empty($title) && !ctype_space($content)) if (!is_null($title) && !empty($title) && !ctype_space($title)) {
$album->setName($title); $album->setName($title);
if (!is_null($description)) }
if (!is_null($description)) {
$album->setDescription($description); $album->setDescription($description);
}
try { try {
$album->save(); $album->save();
} catch(\Throwable $e) { } catch (\Throwable $e) {
return 1; return 1;
} }
@ -312,10 +316,12 @@ final class Photos extends VKAPIRequestHandler
if (empty($album_ids)) { if (empty($album_ids)) {
$owner = get_entity_by_id($owner_id); $owner = get_entity_by_id($owner_id);
if (!$owner || !$owner->canBeViewedBy($this->getUser())) if (!$owner || !$owner->canBeViewedBy($this->getUser())) {
$this->fail(15, "Access denied"); $this->fail(15, "Access denied");
if ($owner_id > 0 && !$owner->getPrivacyPermission('photos.read', $this->getUser())) }
if ($owner_id > 0 && !$owner->getPrivacyPermission('photos.read', $this->getUser())) {
$this->fail(15, "Access denied"); $this->fail(15, "Access denied");
}
$albums_list = null; $albums_list = null;
if ($owner_id > 0) { if ($owner_id > 0) {
@ -329,17 +335,19 @@ final class Photos extends VKAPIRequestHandler
} else { } else {
$album_ids = explode(',', $album_ids); $album_ids = explode(',', $album_ids);
foreach ($album_ids as $album_id) { foreach ($album_ids as $album_id) {
$album = (new Albums())->getAlbumByOwnerAndId((int)$owner_id, (int)$album_id); $album = (new Albums())->getAlbumByOwnerAndId((int) $owner_id, (int) $album_id);
if (!$album || $album->isDeleted() || !$album->canBeViewedBy($this->getUser())) if (!$album || $album->isDeleted() || !$album->canBeViewedBy($this->getUser())) {
continue; continue;
}
$albums_list[] = $album; $albums_list[] = $album;
} }
} }
foreach ($albums_list as $album) { foreach ($albums_list as $album) {
if (!$need_system && $album->isCreatedBySystem()) # TODO use queries if (!$need_system && $album->isCreatedBySystem()) { # TODO use queries
continue; continue;
}
$res["items"][] = $album->toVkApiStruct($this->getUser(), $need_covers, $photo_sizes); $res["items"][] = $album->toVkApiStruct($this->getUser(), $need_covers, $photo_sizes);
} }
@ -355,7 +363,7 @@ final class Photos extends VKAPIRequestHandler
$user_id = $this->getUser()->getId(); $user_id = $this->getUser()->getId();
} }
if (!is_null($user_id)){ if (!is_null($user_id)) {
$__user = (new UsersRepo())->get($user_id); $__user = (new UsersRepo())->get($user_id);
if (!$__user || $__user->isDeleted() || !$__user->getPrivacyPermission('photos.read', $this->getUser())) { if (!$__user || $__user->isDeleted() || !$__user->getPrivacyPermission('photos.read', $this->getUser())) {
$this->fail(15, "Access denied"); $this->fail(15, "Access denied");
@ -388,8 +396,9 @@ final class Photos extends VKAPIRequestHandler
foreach ($photos_splitted_list as $photo_id) { foreach ($photos_splitted_list as $photo_id) {
$photo_s_id = explode("_", $photo_id); $photo_s_id = explode("_", $photo_id);
$photo = (new PhotosRepo())->getByOwnerAndVID((int) $photo_s_id[0], (int) $photo_s_id[1]); $photo = (new PhotosRepo())->getByOwnerAndVID((int) $photo_s_id[0], (int) $photo_s_id[1]);
if(!$photo || $photo->isDeleted() || !$photo->canBeViewedBy($this->getUser())) if (!$photo || $photo->isDeleted() || !$photo->canBeViewedBy($this->getUser())) {
continue; continue;
}
$res[] = $photo->toVkApiStruct($photo_sizes, $extended); $res[] = $photo->toVkApiStruct($photo_sizes, $extended);
} }
@ -435,8 +444,9 @@ final class Photos extends VKAPIRequestHandler
$id = explode("_", $photo); $id = explode("_", $photo);
$photo_entity = (new PhotosRepo())->getByOwnerAndVID((int) $id[0], (int) $id[1]); $photo_entity = (new PhotosRepo())->getByOwnerAndVID((int) $id[0], (int) $id[1]);
if (!$photo_entity || $photo_entity->isDeleted() || !$photo_entity->canBeViewedBy($this->getUser())) if (!$photo_entity || $photo_entity->isDeleted() || !$photo_entity->canBeViewedBy($this->getUser())) {
continue; continue;
}
$res["items"][] = $photo_entity->toVkApiStruct($photo_sizes, $extended); $res["items"][] = $photo_entity->toVkApiStruct($photo_sizes, $extended);
} }
@ -485,13 +495,14 @@ final class Photos extends VKAPIRequestHandler
$this->requireUser(); $this->requireUser();
$this->willExecuteWriteAction(); $this->willExecuteWriteAction();
if(!$owner_id) { if (!$owner_id) {
$owner_id = $this->getUser()->getId(); $owner_id = $this->getUser()->getId();
} }
if (is_null($photos)) { if (is_null($photos)) {
if(is_null($photo_id)) if (is_null($photo_id)) {
return 0; return 0;
}
$photo = (new PhotosRepo())->getByOwnerAndVID($owner_id, $photo_id); $photo = (new PhotosRepo())->getByOwnerAndVID($owner_id, $photo_id);
if (!$photo || $photo->isDeleted() || !$photo->canBeModifiedBy($this->getUser())) { if (!$photo || $photo->isDeleted() || !$photo->canBeModifiedBy($this->getUser())) {
@ -508,8 +519,9 @@ final class Photos extends VKAPIRequestHandler
foreach ($photos_list as $photo_id) { foreach ($photos_list as $photo_id) {
$id = explode("_", $photo_id); $id = explode("_", $photo_id);
$photo = (new PhotosRepo())->getByOwnerAndVID((int) $id[0], (int) $id[1]); $photo = (new PhotosRepo())->getByOwnerAndVID((int) $id[0], (int) $id[1]);
if (!$photo || $photo->isDeleted() || !$photo->canBeModifiedBy($this->getUser())) if (!$photo || $photo->isDeleted() || !$photo->canBeModifiedBy($this->getUser())) {
continue; continue;
}
$photo->delete(); $photo->delete();
} }

View file

@ -596,6 +596,17 @@
</table> </table>
</form> </form>
<table cellspacing="7" cellpadding="0" width="60%" border="0" align="center" id="_js_settings">
<tbody>
<tr>
<td width="120" valign="top" align="right"></td>
<td>
<a href="javascript:openJsSettings()">{_ui_settings_window}</a>
</td>
</tr>
</tbody>
</table>
<h4>{_ui_settings_sidebar}</h4> <h4>{_ui_settings_sidebar}</h4>
<form action="/settings?act=lMenu" method="POST" enctype="multipart/form-data"> <form action="/settings?act=lMenu" method="POST" enctype="multipart/form-data">
<table cellspacing="7" cellpadding="0" width="60%" border="0" align="center"> <table cellspacing="7" cellpadding="0" width="60%" border="0" align="center">

View file

@ -84,8 +84,6 @@ u(document).on('click', '#__feed_settings_link', (e) => {
const CURRENT_PERPAGE = Number(__temp_url.searchParams.get('posts') ?? 10) const CURRENT_PERPAGE = Number(__temp_url.searchParams.get('posts') ?? 10)
const CURRENT_PAGE = Number(__temp_url.searchParams.get('p') ?? 1) const CURRENT_PAGE = Number(__temp_url.searchParams.get('p') ?? 1)
const CURRENT_RETURN_BANNED = Number(__temp_url.searchParams.get('return_banned') ?? 0) const CURRENT_RETURN_BANNED = Number(__temp_url.searchParams.get('return_banned') ?? 0)
const CURRENT_AUTO_SCROLL = Number(localStorage.getItem('ux.auto_scroll') ?? 1)
const CURRENT_DISABLE_AJAX = Number(localStorage.getItem('ux.disable_ajax_routing') ?? 0)
const COUNT = [1, 5, 10, 20, 30, 40, 50] const COUNT = [1, 5, 10, 20, 30, 40, 50]
u('#_feed_settings_container #__content').html(` u('#_feed_settings_container #__content').html(`
<table cellspacing="7" cellpadding="0" border="0" align="center"> <table cellspacing="7" cellpadding="0" border="0" align="center">
@ -116,26 +114,6 @@ u(document).on('click', '#__feed_settings_link', (e) => {
<label for='showIgnored'>${tr('show_ignored_sources')}</label> <label for='showIgnored'>${tr('show_ignored_sources')}</label>
</td> </td>
</tr> </tr>
<tr>
<td width="120" valign="top">
<span class="nobold">
<input type='checkbox' data-act='localstorage_item' data-inverse="1" name='ux.disable_ajax_routing' id="ux.disable_ajax_routing" ${CURRENT_DISABLE_AJAX == 0 ? 'checked' : ''}>
</span>
</td>
<td>
<label for='ux.disable_ajax_routing'>${tr('ajax_routing')}</label>
</td>
</tr>
<tr>
<td width="120" valign="top">
<span class="nobold">
<input type='checkbox' data-act='localstorage_item' name='ux.auto_scroll' id="ux.auto_scroll" ${CURRENT_AUTO_SCROLL == 1 ? 'checked' : ''}>
</span>
</td>
<td>
<label for='ux.auto_scroll'>${tr('auto_scroll')}</label>
</td>
</tr>
<tr> <tr>
<td width="120" valign="top"> <td width="120" valign="top">
</td> </td>
@ -299,3 +277,32 @@ u(document).on('change', `input[data-act='localstorage_item']`, (e) => {
localStorage.setItem(e.target.name, Number(e.target.checked)) localStorage.setItem(e.target.name, Number(e.target.checked))
}) })
function openJsSettings() {
const CURRENT_AUTO_SCROLL = Number(localStorage.getItem('ux.auto_scroll') ?? 1)
const CURRENT_DISABLE_AJAX = Number(localStorage.getItem('ux.disable_ajax_routing') ?? 0)
u("#_js_settings td").remove()
u("#_js_settings").append(`
<tr>
<td width="120" valign="top">
<span class="nobold">
<input type='checkbox' data-act='localstorage_item' data-inverse="1" name='ux.disable_ajax_routing' id="ux.disable_ajax_routing" ${CURRENT_DISABLE_AJAX == 0 ? 'checked' : ''}>
</span>
</td>
<td>
<label for='ux.disable_ajax_routing'>${tr('ajax_routing')}</label>
</td>
</tr>
<tr>
<td width="120" valign="top">
<span class="nobold">
<input type='checkbox' data-act='localstorage_item' name='ux.auto_scroll' id="ux.auto_scroll" ${CURRENT_AUTO_SCROLL == 1 ? 'checked' : ''}>
</span>
</td>
<td>
<label for='ux.auto_scroll'>${tr('auto_scroll')}</label>
</td>
</tr>
`)
}

View file

@ -703,6 +703,7 @@
"round_avatars" = "Round"; "round_avatars" = "Round";
"apply_style_for_this_device" = "Apply style only for this device"; "apply_style_for_this_device" = "Apply style only for this device";
"ui_settings_window" = "Advanced settings";
"search_for_groups" = "Search for groups"; "search_for_groups" = "Search for groups";
"search_for_users" = "Search for users"; "search_for_users" = "Search for users";

View file

@ -676,6 +676,7 @@
"cut" = "Квадратные"; "cut" = "Квадратные";
"round_avatars" = "Круглые"; "round_avatars" = "Круглые";
"apply_style_for_this_device" = "Применить стиль только для этого устройства"; "apply_style_for_this_device" = "Применить стиль только для этого устройства";
"ui_settings_window" = "Дополнительные настройки";
"search_for_groups" = "Поиск групп"; "search_for_groups" = "Поиск групп";
"search_for_users" = "Поиск людей"; "search_for_users" = "Поиск людей";
"search_for_posts" = "Поиск записей"; "search_for_posts" = "Поиск записей";