show thumbs for relationships

master
butterbutt 9 months ago
parent 3d4b53b5e8
commit d111b5e13c
Signed by: butterbutt
GPG Key ID: 4D2AD715BC930E49
  1. 31
      ext/relationships/main.php
  2. 50
      ext/relationships/style.css
  3. 69
      ext/relationships/theme.php

@ -210,4 +210,35 @@ class Relationships extends Extension
["has_children"=>$children>0, "pid"=>$parent_id]
);
}
public static function has_siblings(int $image_id): bool
{
global $database;
$image = Image::by_id($image_id);
$count = $database->get_one(
"SELECT COUNT(*) FROM images WHERE id!=:id AND parent_id=:pid",
["id"=>$image_id, "pid"=>$image->parent_id]
);
if ($count > 0) {
return true;
}
return false;
}
public static function get_siblings(int $image_id): array
{
global $database;
$image = Image::by_id($image_id);
$siblings = $database->get_col(
"SELECT id FROM images WHERE id!=:id AND parent_id=:pid",
["id"=>$image_id, "pid"=>$image->parent_id]
);
return $siblings;
}
}

@ -3,13 +3,57 @@
}
.shm-thumb-has_child img {
border-color: lime !important;
border-color: cyan;
}
.shm-thumb-has_parent img {
border-color: #cc0 !important;
border-color: cyan;
}
.shm-thumb-has_child.shm-thumb-has_parent img {
border-color: lime #cc0 #cc0 lime !important;
border-color: magenta #cc0 #cc0 magenta !important;
}
#PostRelationships {
margin-top: 0;
}
#PostRelationships * {
box-sizing: border-box;
}
#PostRelationships .shm-relationships-thumbs {
padding-top: 5px;
}
#PostRelationships .shm-parent-thumbs,
#PostRelationships .shm-sibling-thumbs {
display: inline-block;
}
#PostRelationships img {
display: inline-block;
height: 96px;
width: auto;
margin: 0 5px;
}
#PostRelationships .shm-parent-thumbs img {
border: solid;
border-color: #f5ffad;
}
#PostRelationships .shm-child-thumbs img {
border: solid;
border-color: cyan;
}
#PostRelationships .shm-sibling-thumbs img {
border: solid;
border-color: cyan;
}
.shm-relationships-toggle {
padding-left: 5px;
text-align: right;
}

@ -7,22 +7,77 @@ class RelationshipsTheme extends Themelet
global $page, $database;
if ($image->parent_id !== null) {
$a = "<a href='".make_link("post/view/".$image->parent_id)."'>parent post</a>";
$page->add_block(new Block(null, "This post belongs to a $a.", "main", 5, "ImageHasParent"));
$a = "<a href='".make_link("post/view/".$image->parent_id)."'>#$image->parent_id</a>";
$shtml = "<span>This post belongs to a parent post ($a)";
$thtml = "<div class='shm-relationships-thumbs'><div class='shm-parent-thumbs'>" . $this->get_parent_thumbnail_html($image) . "</div>";
if (Relationships::has_siblings($image->id)) {
$siblings = Relationships::get_siblings($image->id);
$shtml .= " and has " .count($siblings) . (count($siblings) > 1 ? " siblings" : " sibling");
$shtml .= " (";
foreach ($siblings as $sibling) {
$shtml .= "<a href='" . make_link('post/view/'.$sibling) . "'>#$sibling</a>" . (count($siblings) > 1 ? ", " : ")");
}
$thtml .= "<div class='shm-sibling-thumbs'>" . $this->get_sibling_thumbnail_html($image) . "</div>";
}
$shtml .= ".</span>";
$shtml .= "<a href='#' id='relationships-toggle' class='shm-relationships-toggle'>« hide</a>";
$thtml .= "</div>";
$html = $shtml . $thtml;
$page->add_block(new Block(null, $html, "main", 5, "PostRelationships"));
}
if (bool_escape($image->has_children)) {
$ids = $database->get_col("SELECT id FROM images WHERE parent_id = :iid", ["iid"=>$image->id]);
$html = "This post has <a href='".make_link('post/list/parent='.$image->id.'/1')."'>".(count($ids) > 1 ? "child posts" : "a child post")."</a>";
$html .= " (post ";
$shtml = "This post has <a href='".make_link('post/list/parent='.$image->id.'/1')."'>".(count($ids) > 1 ? "child posts" : "a child post")."</a>";
$shtml .= " (post ";
$thtml = "<div class='shm-relationships-thumbs'><div class='shm-child-thumbs'>";
foreach ($ids as $id) {
$html .= "#<a href='".make_link('post/view/'.$id)."'>{$id}</a>, ";
$shtml .= "<a href='".make_link('post/view/'.$id)."'>#{$id}</a>, ";
$thtml .= $this->get_child_thumbnail_html(Image::by_id($id));
}
$html = rtrim($html, ", ").").";
$shtml = rtrim($shtml, ", ").").";
$shtml .= "<a href='#' id='relationships-toggle' class='shm-relationships-toggle'>« hide</a>";
$thmtl .= "</div></div>";
$html = $shtml . $thtml;
$page->add_block(new Block(null, $html, "main", 5, "PostRelationships"));
}
}
private function get_parent_thumbnail_html(Image $image): string
{
global $user;
$parent_id = $image->parent_id;
$parent_image = Image::by_id($parent_id);
$html = $this->build_thumb_html($parent_image);
return $html;
}
private function get_child_thumbnail_html(Image $image): string
{
$html = $this->build_thumb_html($image);
return $html;
}
$page->add_block(new Block(null, $html, "main", 6, "ImageHasChildren"));
private function get_sibling_thumbnail_html(Image $image): string
{
global $user;
$siblings = Relationships::get_siblings($image->id);
$html = "";
foreach ($siblings as $sibling) {
$sibling_image = Image::by_id($sibling);
$html .= $this->build_thumb_html($sibling_image);
}
return $html;
}
public function get_parent_editor_html(Image $image): string

Loading…
Cancel
Save