2021-12-14 18:32:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2014-02-03 13:54:09 +00:00
|
|
|
|
2023-01-10 22:44:09 +00:00
|
|
|
namespace Shimmie2;
|
|
|
|
|
2023-08-17 17:09:38 +00:00
|
|
|
use MicroHTML\HTMLElement;
|
|
|
|
|
|
|
|
use function MicroHTML\{TR, TH, TD, emptyHTML, DIV, INPUT};
|
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
class RelationshipsTheme extends Themelet
|
|
|
|
{
|
|
|
|
public function relationship_info(Image $image)
|
|
|
|
{
|
|
|
|
global $page, $database;
|
|
|
|
|
|
|
|
if ($image->parent_id !== null) {
|
|
|
|
$a = "<a href='".make_link("post/view/".$image->parent_id)."'>parent post</a>";
|
2021-02-09 06:44:37 +00:00
|
|
|
$page->add_block(new Block(null, "This post belongs to a $a.", "main", 5, "ImageHasParent"));
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bool_escape($image->has_children)) {
|
|
|
|
$ids = $database->get_col("SELECT id FROM images WHERE parent_id = :iid", ["iid"=>$image->id]);
|
|
|
|
|
2023-08-18 12:38:55 +00:00
|
|
|
$html = "This post has <a href='".search_link(['parent='.$image->id])."'>".(count($ids) > 1 ? "child posts" : "a child post")."</a>";
|
2019-05-28 16:59:38 +00:00
|
|
|
$html .= " (post ";
|
|
|
|
foreach ($ids as $id) {
|
|
|
|
$html .= "#<a href='".make_link('post/view/'.$id)."'>{$id}</a>, ";
|
|
|
|
}
|
|
|
|
$html = rtrim($html, ", ").").";
|
|
|
|
|
2021-02-09 06:44:37 +00:00
|
|
|
$page->add_block(new Block(null, $html, "main", 6, "ImageHasChildren"));
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-17 17:09:38 +00:00
|
|
|
public function get_parent_editor_html(Image $image): HTMLElement
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
global $user;
|
|
|
|
|
2023-08-17 17:09:38 +00:00
|
|
|
return SHM_POST_INFO(
|
|
|
|
"Parent",
|
|
|
|
!$user->is_anonymous(),
|
2023-11-05 15:40:12 +00:00
|
|
|
strval($image->parent_id) ?: "None",
|
2023-08-17 17:09:38 +00:00
|
|
|
INPUT(["type"=>"number", "name"=>"tag_edit__parent", "value"=>$image->parent_id])
|
|
|
|
);
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2019-08-02 20:05:49 +00:00
|
|
|
|
|
|
|
|
2021-03-14 23:43:50 +00:00
|
|
|
public function get_help_html(): string
|
2019-08-02 20:05:49 +00:00
|
|
|
{
|
2020-10-26 15:23:32 +00:00
|
|
|
return '<p>Search for posts that have parent/child relationships.</p>
|
2019-08-02 20:05:49 +00:00
|
|
|
<div class="command_example">
|
|
|
|
<pre>parent=any</pre>
|
2020-10-26 15:23:32 +00:00
|
|
|
<p>Returns posts that have a parent.</p>
|
|
|
|
</div>
|
2019-08-02 20:05:49 +00:00
|
|
|
<div class="command_example">
|
|
|
|
<pre>parent=none</pre>
|
2020-10-26 15:23:32 +00:00
|
|
|
<p>Returns posts that have no parent.</p>
|
|
|
|
</div>
|
2019-08-02 20:05:49 +00:00
|
|
|
<div class="command_example">
|
|
|
|
<pre>parent=123</pre>
|
2020-10-26 15:23:32 +00:00
|
|
|
<p>Returns posts that have image 123 set as parent.</p>
|
|
|
|
</div>
|
2019-08-02 20:05:49 +00:00
|
|
|
<div class="command_example">
|
|
|
|
<pre>child=any</pre>
|
2020-10-26 15:23:32 +00:00
|
|
|
<p>Returns posts that have at least 1 child.</p>
|
|
|
|
</div>
|
2019-08-02 20:05:49 +00:00
|
|
|
<div class="command_example">
|
|
|
|
<pre>child=none</pre>
|
2020-10-26 15:23:32 +00:00
|
|
|
<p>Returns posts that have no children.</p>
|
|
|
|
</div>
|
2019-08-02 20:05:49 +00:00
|
|
|
';
|
|
|
|
}
|
2014-02-03 13:54:09 +00:00
|
|
|
}
|