#$parent_id"; $parent_summary_html = "This post belongs to a parent post ($a)"; $parent_thumb_html = "
" . $this->get_parent_thumbnail_html($image) . "
"; if (Relationships::has_siblings($image->id)) { $visible_siblings = Relationships::get_siblings($image->id); if (!empty($visible_siblings)) { $parent_summary_html .= " and has " .count($visible_siblings) . (count($visible_siblings) > 1 ? " siblings" : " sibling"); $parent_summary_html .= " ("; foreach ($visible_siblings as $sibling) { $parent_summary_html .= "id) . "'>#$sibling->id" . (count($visible_siblings) > 1 ? ", " : ""); } $parent_summary_html = trim($parent_summary_html, ', '); $parent_summary_html .= ")"; $parent_thumb_html .= "
" . $this->get_sibling_thumbnail_html($image) . "
"; } } $parent_summary_html .= "."; $parent_summary_html .= "« hide"; $parent_thumb_html .= "
"; $html = $parent_summary_html . $parent_thumb_html; $page->add_block(new Block(null, $html, "main", 5, "PostRelationshipsParent")); } if (bool_escape($image['has_children'])) { $visible_children = Relationships::get_children($image->id); if (!empty($visible_children)) { $child_summary_html = "This post has ".(count($visible_children) > 1 ? "child posts" : "a child post").""; $child_summary_html .= " (post "; $child_thumb_html = "
"; foreach ($visible_children as $child) { $child_summary_html .= "id)."'>#{$child->id}, "; $child_thumb_html .= $this->get_child_thumbnail_html($child); } $child_summary_html = rtrim($child_summary_html, ", ").")."; $child_summary_html .= "« hide"; $child_thumb_html .= "
"; $html = $child_summary_html . $child_thumb_html; $page->add_block(new Block(null, $html, "main", 5, "PostRelationshipsChildren")); } } } public function get_parent_editor_html(Image $image): HTMLElement { global $user; return SHM_POST_INFO( "Parent", strval($image['parent_id']) ?: "None", !$user->is_anonymous() ? INPUT(["type" => "number", "name" => "parent", "value" => $image['parent_id']]) : null ); } public function get_help_html(): string { return '

Search for posts that have parent/child relationships.

parent=any

Returns posts that have a parent.

parent=none

Returns posts that have no parent.

parent=123

Returns posts that have image 123 set as parent.

child=any

Returns posts that have at least 1 child.

child=none

Returns posts that have no children.

'; } private function get_parent_thumbnail_html(Image $image): HTMLElement { $parent_id = $image['parent_id']; $parent_image = Image::by_id_ex($parent_id); return $this->build_thumb_html($parent_image); } private function get_child_thumbnail_html(Image $image): HTMLElement { return $this->build_thumb_html($image); } private function get_sibling_thumbnail_html(Image $image): string { $siblings = Relationships::get_siblings($image->id); $html = ""; foreach ($siblings as $sibling) { $html .= $this->build_thumb_html($sibling); } return $html; } }