Compare commits

...

6 commits

Author SHA1 Message Date
mrilyew
9bdf523f76
Merge 3fec1b57a4 into a12c77083b 2025-03-21 11:03:09 +05:00
Vladimir Barinov
a12c77083b
fix(links, away) (fixes #1253) 2025-03-16 17:57:21 +03:00
Vladimir Barinov
4815186b79
chore(statistics): change behavior of active users count (#1254) 2025-03-16 17:53:58 +03:00
Vladimir Barinov
9ef7d2d7c4
fix(age): calculation (fixes #1252) 2025-03-16 16:51:05 +03:00
mrilyew
3fec1b57a4 Merge branch 'master' into predictable-thumbnail-id-fix 2025-03-02 19:15:06 +03:00
mrilyew
ca8b6a83fb fix 2025-02-17 20:12:06 +03:00
8 changed files with 27 additions and 11 deletions

View file

@ -187,7 +187,7 @@ class Photo extends Media
foreach ($sizes as $id => $meta) { foreach ($sizes as $id => $meta) {
if (isset($meta[3]) && !$meta[3]) { if (isset($meta[3]) && !$meta[3]) {
$res[$id] = (object) [ $res[$id] = (object) [
"url" => ovk_scheme(true) . $_SERVER["HTTP_HOST"] . "/photos/thumbnails/" . $this->getId() . "_$id.jpeg", "url" => ovk_scheme(true) . $_SERVER["HTTP_HOST"] . "/photos/thumbnails/" . $this->getRecord()->hash . "_$id.jpeg",
"width" => null, "width" => null,
"height" => null, "height" => null,
"crop" => null, "crop" => null,

View file

@ -41,11 +41,11 @@ trait TRichText
return preg_replace_callback( return preg_replace_callback(
"%(([A-z]++):\/\/(\S*?\.\S*?))([\s)\[\]{},\"\'<]|\.\s|$)%", "%(([A-z]++):\/\/(\S*?\.\S*?))([\s)\[\]{},\"\'<]|\.\s|$)%",
(function (array $matches): string { (function (array $matches): string {
$href = str_replace("#", "&num;", $matches[1]); $href = rawurlencode($matches[1]);
$href = rawurlencode(str_replace(";", "&#59;", $href)); $href = str_replace("%26amp%3B", "%26", $href);
$link = str_replace("#", "&num;", $matches[3]); $link = $matches[3];
# this string breaks ampersands # this string breaks ampersands
$link = str_replace(";", "&#59;", $link); # $link = str_replace(";", "&#59;", $link);
$rel = $this->isAd() ? "sponsored" : "ugc"; $rel = $this->isAd() ? "sponsored" : "ugc";
/*$server_domain = str_replace(':' . $_SERVER['SERVER_PORT'], '', $_SERVER['HTTP_HOST']); /*$server_domain = str_replace(':' . $_SERVER['SERVER_PORT'], '', $_SERVER['HTTP_HOST']);

View file

@ -524,7 +524,10 @@ class User extends RowModel
public function getAge(): ?int public function getAge(): ?int
{ {
return (int) floor((time() - $this->getBirthday()->timestamp()) / YEAR); $birthday = new \DateTime();
$birthday->setTimestamp($this->getBirthday()->timestamp());
$today = new \DateTime();
return (int) $today->diff($birthday)->y;
} }
public function get2faSecret(): ?string public function get2faSecret(): ?string

View file

@ -28,6 +28,17 @@ class Photos
return new Photo($photo); return new Photo($photo);
} }
public function getByHash(string $hash): ?Photo
{
$photo = $this->photos->where("hash", $hash)->fetch();
if (!$photo) {
return null;
}
return new Photo($photo);
}
public function getByOwnerAndVID(int $owner, int $vId): ?Photo public function getByOwnerAndVID(int $owner, int $vId): ?Photo
{ {
$photo = $this->photos->where([ $photo = $this->photos->where([

View file

@ -157,7 +157,7 @@ class Users
{ {
return (object) [ return (object) [
"all" => (clone $this->users)->count('*'), "all" => (clone $this->users)->count('*'),
"active" => (clone $this->users)->where("online > 0")->count('*'), "active" => (clone $this->users)->where("online >= ?", time() - MONTH)->count('*'),
"online" => (clone $this->users)->where("online >= ?", time() - 900)->count('*'), "online" => (clone $this->users)->where("online >= ?", time() - 900)->count('*'),
]; ];
} }

View file

@ -20,7 +20,7 @@ final class AwayPresenter extends OpenVKPresenter
header("HTTP/1.0 302 Found"); header("HTTP/1.0 302 Found");
header("X-Robots-Tag: noindex, nofollow, noarchive"); header("X-Robots-Tag: noindex, nofollow, noarchive");
header("Location: " . $this->queryParam("to")); header("Location: " . rawurldecode($this->queryParam("to")));
exit; exit;
} }

View file

@ -229,9 +229,9 @@ final class PhotosPresenter extends OpenVKPresenter
$this->renderPhoto($photo->getOwner(true)->getId(), $photo->getVirtualId()); $this->renderPhoto($photo->getOwner(true)->getId(), $photo->getVirtualId());
} }
public function renderThumbnail($id, $size): void public function renderThumbnail($hash, $size): void
{ {
$photo = $this->photos->get($id); $photo = $this->photos->getByHash((string) $hash);
if (!$photo || $photo->isDeleted()) { if (!$photo || $photo->isDeleted()) {
$this->notFound(); $this->notFound();
} }

View file

@ -173,8 +173,10 @@ routes:
handler: "Photos->photo" handler: "Photos->photo"
- url: "/photo{num}_{num}/like" - url: "/photo{num}_{num}/like"
handler: "Photos->like" handler: "Photos->like"
- url: "/photos/thumbnails/{num}_{text}.jpeg" - url: "/photos/thumbnails/{?hash}_{text}.jpeg"
handler: "Photos->thumbnail" handler: "Photos->thumbnail"
placeholders:
hash: "[A-z0-9\\-_\\/]{15,}"
- url: "/photos/{text}" - url: "/photos/{text}"
handler: "Photos->absolutePhoto" handler: "Photos->absolutePhoto"
- url: "/photo{num}_{num}/edit" - url: "/photo{num}_{num}/edit"