Revert "Merge tag 'v2.10.6'"

This reverts commit 122ea4ab9e, reversing
changes made to c54a11e250.
This commit is contained in:
2024-02-16 23:06:09 -06:00
parent 122ea4ab9e
commit 6c08ee9675
521 changed files with 12363 additions and 14503 deletions

View File

@@ -33,25 +33,22 @@ class NumericScoreVote
public static function score(Image $post): int
{
global $database;
if ($post['score'] ?? null) {
return $post['score'];
if ($post->score ?? null) {
return $post->score;
}
return $database->get_one(
"SELECT sum(score) FROM numeric_score_votes WHERE image_id=:image_id",
['image_id' => $post->id]
['image_id'=>$post->id]
) ?? 0;
}
/**
* @return NumericScoreVote[]
*/
#[Field(extends: "Post", type: "[NumericScoreVote!]!")]
public static function votes(Image $post): array
{
global $database;
$rows = $database->get_all(
"SELECT * FROM numeric_score_votes WHERE image_id=:image_id",
['image_id' => $post->id]
['image_id'=>$post->id]
);
$votes = [];
foreach ($rows as $row) {
@@ -70,7 +67,7 @@ class NumericScoreVote
global $database, $user;
return $database->get_one(
"SELECT score FROM numeric_score_votes WHERE image_id=:image_id AND user_id=:user_id",
['image_id' => $post->id, "user_id" => $user->id]
['image_id'=>$post->id, "user_id"=>$user->id]
) ?? 0;
}
@@ -107,12 +104,7 @@ class NumericScore extends Extension
/** @var NumericScoreTheme */
protected Themelet $theme;
public function onInitExt(InitExtEvent $event): void
{
Image::$prop_types["numeric_score"] = ImagePropType::INT;
}
public function onDisplayingImage(DisplayingImageEvent $event): void
public function onDisplayingImage(DisplayingImageEvent $event)
{
global $user;
if ($user->can(Permissions::CREATE_VOTE)) {
@@ -120,21 +112,22 @@ class NumericScore extends Extension
}
}
public function onUserPageBuilding(UserPageBuildingEvent $event): void
public function onUserPageBuilding(UserPageBuildingEvent $event)
{
global $user;
if ($user->can(Permissions::EDIT_OTHER_VOTE)) {
$this->theme->get_nuller($event->display_user);
}
$n_up = Search::count_images(["upvoted_by={$event->display_user->name}"]);
$link_up = search_link(["upvoted_by={$event->display_user->name}"]);
$n_down = Search::count_images(["downvoted_by={$event->display_user->name}"]);
$link_down = search_link(["downvoted_by={$event->display_user->name}"]);
$u_name = url_escape($event->display_user->name);
$n_up = Image::count_images(["upvoted_by={$event->display_user->name}"]);
$link_up = make_link("post/list/upvoted_by=$u_name/1");
$n_down = Image::count_images(["downvoted_by={$event->display_user->name}"]);
$link_down = make_link("post/list/downvoted_by=$u_name/1");
$event->add_stats("<a href='$link_up'>$n_up Upvotes</a> / <a href='$link_down'>$n_down Downvotes</a>");
}
public function onPageRequest(PageRequestEvent $event): void
public function onPageRequest(PageRequestEvent $event)
{
global $config, $database, $user, $page;
@@ -145,7 +138,7 @@ class NumericScore extends Extension
FROM numeric_score_votes
JOIN users ON numeric_score_votes.user_id=users.id
WHERE image_id=:image_id",
['image_id' => $image_id]
['image_id'=>$image_id]
);
$html = "<table style='width: 100%;'>";
foreach ($x as $vote) {
@@ -160,7 +153,7 @@ class NumericScore extends Extension
if ($user->can(Permissions::CREATE_VOTE)) {
$image_id = int_escape($_POST['image_id']);
$score = int_escape($_POST['vote']);
if (($score == -1 || $score == 0 || $score == 1) && $image_id > 0) {
if (($score == -1 || $score == 0 || $score == 1) && $image_id>0) {
send_event(new NumericScoreSetEvent($image_id, $user, $score));
}
$page->set_mode(PageMode::REDIRECT);
@@ -171,11 +164,11 @@ class NumericScore extends Extension
$image_id = int_escape($_POST['image_id']);
$database->execute(
"DELETE FROM numeric_score_votes WHERE image_id=:image_id",
['image_id' => $image_id]
['image_id'=>$image_id]
);
$database->execute(
"UPDATE images SET numeric_score=0 WHERE id=:id",
['id' => $image_id]
['id'=>$image_id]
);
$page->set_mode(PageMode::REDIRECT);
$page->set_redirect(make_link("post/view/$image_id"));
@@ -205,25 +198,25 @@ class NumericScore extends Extension
$totaldate = $year."/".$month."/".$day;
$sql = "SELECT id FROM images WHERE EXTRACT(YEAR FROM posted) = :year";
$sql = "SELECT id FROM images
WHERE EXTRACT(YEAR FROM posted) = :year
";
$args = ["limit" => $config->get_int(IndexConfig::IMAGES), "year" => $year];
if ($event->page_matches("popular_by_day")) {
$sql .= " AND EXTRACT(MONTH FROM posted) = :month AND EXTRACT(DAY FROM posted) = :day";
$sql .=
"AND EXTRACT(MONTH FROM posted) = :month
AND EXTRACT(DAY FROM posted) = :day";
$args = array_merge($args, ["month" => $month, "day" => $day]);
$current = date("F jS, Y", strtotime_ex($totaldate)).
$name = "day";
$fmt = "\\y\\e\\a\\r\\=Y\\&\\m\\o\\n\\t\\h\\=m\\&\\d\\a\\y\\=d";
$dte = [$totaldate, date("F jS, Y", (strtotime($totaldate))), "\\y\\e\\a\\r\\=Y\\&\\m\\o\\n\\t\\h\\=m\\&\\d\\a\\y\\=d", "day"];
} elseif ($event->page_matches("popular_by_month")) {
$sql .= " AND EXTRACT(MONTH FROM posted) = :month";
$sql .= "AND EXTRACT(MONTH FROM posted) = :month";
$args = array_merge($args, ["month" => $month]);
$current = date("F Y", strtotime_ex($totaldate));
$name = "month";
$fmt = "\\y\\e\\a\\r\\=Y\\&\\m\\o\\n\\t\\h\\=m";
$dte = [$totaldate, date("F Y", (strtotime($totaldate))), "\\y\\e\\a\\r\\=Y\\&\\m\\o\\n\\t\\h\\=m", "month"];
} elseif ($event->page_matches("popular_by_year")) {
$current = "$year";
$name = "year";
$fmt = "\\y\\e\\a\\r\=Y";
$dte = [$totaldate, $year, "\\y\\e\\a\\r\=Y", "year"];
} else {
// this should never happen due to the fact that the page event is already matched against earlier.
throw new \UnexpectedValueException("Error: Invalid page event.");
@@ -232,35 +225,39 @@ class NumericScore extends Extension
//filter images by score != 0 + date > limit to max images on one page > order from highest to lowest score
$ids = $database->get_col($sql, $args);
$images = Search::get_images($ids);
$this->theme->view_popular($images, $totaldate, $current, $name, $fmt);
$result = $database->get_col($sql, $args);
$images = [];
foreach ($result as $id) {
$images[] = Image::by_id((int)$id);
}
$this->theme->view_popular($images, $dte);
}
}
public function onNumericScoreSet(NumericScoreSetEvent $event): void
public function onNumericScoreSet(NumericScoreSetEvent $event)
{
global $user;
log_debug("numeric_score", "Rated >>{$event->image_id} as {$event->score}", "Rated Post");
$this->add_vote($event->image_id, $user->id, $event->score);
}
public function onImageDeletion(ImageDeletionEvent $event): void
public function onImageDeletion(ImageDeletionEvent $event)
{
global $database;
$database->execute("DELETE FROM numeric_score_votes WHERE image_id=:id", ["id" => $event->image->id]);
}
public function onUserDeletion(UserDeletionEvent $event): void
public function onUserDeletion(UserDeletionEvent $event)
{
$this->delete_votes_by($event->id);
}
public function delete_votes_by(int $user_id): void
public function delete_votes_by(int $user_id)
{
global $database;
$image_ids = $database->get_col("SELECT image_id FROM numeric_score_votes WHERE user_id=:user_id", ['user_id' => $user_id]);
$image_ids = $database->get_col("SELECT image_id FROM numeric_score_votes WHERE user_id=:user_id", ['user_id'=>$user_id]);
if (count($image_ids) == 0) {
return;
@@ -272,7 +269,7 @@ class NumericScore extends Extension
$id_list = implode(",", $chunk);
$database->execute(
"DELETE FROM numeric_score_votes WHERE user_id=:user_id AND image_id IN (".$id_list.")",
['user_id' => $user_id]
['user_id'=>$user_id]
);
$database->execute("
UPDATE images
@@ -288,14 +285,14 @@ class NumericScore extends Extension
}
}
public function onParseLinkTemplate(ParseLinkTemplateEvent $event): void
public function onParseLinkTemplate(ParseLinkTemplateEvent $event)
{
$event->replace('$score', (string)$event->image['numeric_score']);
$event->replace('$score', (string)$event->image->numeric_score);
}
public function onHelpPageBuilding(HelpPageBuildingEvent $event): void
public function onHelpPageBuilding(HelpPageBuildingEvent $event)
{
if ($event->key === HelpPages::SEARCH) {
if ($event->key===HelpPages::SEARCH) {
$block = new Block();
$block->header = "Numeric Score";
$block->body = $this->theme->get_help_html();
@@ -303,7 +300,7 @@ class NumericScore extends Extension
}
}
public function onSearchTermParse(SearchTermParseEvent $event): void
public function onSearchTermParse(SearchTermParseEvent $event)
{
if (is_null($event->term)) {
return;
@@ -323,7 +320,7 @@ class NumericScore extends Extension
}
$event->add_querylet(new Querylet(
"images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:ns_user_id AND score=1)",
["ns_user_id" => $duser->id]
["ns_user_id"=>$duser->id]
));
} elseif (preg_match("/^downvoted_by[=|:](.*)$/i", $event->term, $matches)) {
$duser = User::by_name($matches[1]);
@@ -334,19 +331,19 @@ class NumericScore extends Extension
}
$event->add_querylet(new Querylet(
"images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:ns_user_id AND score=-1)",
["ns_user_id" => $duser->id]
["ns_user_id"=>$duser->id]
));
} elseif (preg_match("/^upvoted_by_id[=|:](\d+)$/i", $event->term, $matches)) {
$iid = int_escape($matches[1]);
$event->add_querylet(new Querylet(
"images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:ns_user_id AND score=1)",
["ns_user_id" => $iid]
["ns_user_id"=>$iid]
));
} elseif (preg_match("/^downvoted_by_id[=|:](\d+)$/i", $event->term, $matches)) {
$iid = int_escape($matches[1]);
$event->add_querylet(new Querylet(
"images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:ns_user_id AND score=-1)",
["ns_user_id" => $iid]
["ns_user_id"=>$iid]
));
} elseif (preg_match("/^order[=|:](?:numeric_)?(score)(?:_(desc|asc))?$/i", $event->term, $matches)) {
$default_order_for_column = "DESC";
@@ -355,14 +352,14 @@ class NumericScore extends Extension
}
}
public function onTagTermCheck(TagTermCheckEvent $event): void
public function onTagTermCheck(TagTermCheckEvent $event)
{
if (preg_match("/^vote[=|:](up|down|remove)$/i", $event->term)) {
$event->metatag = true;
}
}
public function onTagTermParse(TagTermParseEvent $event): void
public function onTagTermParse(TagTermParseEvent $event)
{
$matches = [];
@@ -375,16 +372,16 @@ class NumericScore extends Extension
}
}
public function onPageSubNavBuilding(PageSubNavBuildingEvent $event): void
public function onPageSubNavBuilding(PageSubNavBuildingEvent $event)
{
if ($event->parent == "posts") {
if ($event->parent=="posts") {
$event->add_nav_link("numeric_score_day", new Link('popular_by_day'), "Popular by Day");
$event->add_nav_link("numeric_score_month", new Link('popular_by_month'), "Popular by Month");
$event->add_nav_link("numeric_score_year", new Link('popular_by_year'), "Popular by Year");
}
}
public function onDatabaseUpgrade(DatabaseUpgradeEvent $event): void
public function onDatabaseUpgrade(DatabaseUpgradeEvent $event)
{
global $database;
@@ -408,7 +405,7 @@ class NumericScore extends Extension
}
}
private function add_vote(int $image_id, int $user_id, int $score): void
private function add_vote(int $image_id, int $user_id, int $score)
{
global $database;
$database->execute(