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
{
2024-01-20 14:10:59 +00:00
public function relationship_info ( Image $image ) : void
2019-05-28 16:59:38 +00:00
{
global $page , $database ;
2024-02-15 04:30:41 +00:00
$parent = Search :: get_images ([ $image [ 'parent_id' ]]);
if ( ! empty ( $parent )) {
$parent_id = $image [ 'parent_id' ];
$a = " <a href=' " . make_link ( " post/view/ " . $parent_id ) . " '># $parent_id </a> " ;
$parent_summary_html = " <span>This post belongs to a parent post ( $a ) " ;
$parent_thumb_html = " <div class='shm-relationships-parent-thumbs'><div class='shm-parent-thumbs'> " . $this -> get_parent_thumbnail_html ( $image ) . " </div> " ;
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 .= " <a href=' " . make_link ( 'post/view/' . $sibling -> id ) . " '># $sibling->id </a> " . ( count ( $visible_siblings ) > 1 ? " , " : " " );
}
$parent_summary_html = trim ( $parent_summary_html , ', ' );
$parent_summary_html .= " ) " ;
$parent_thumb_html .= " <div class='shm-sibling-thumbs'> " . $this -> get_sibling_thumbnail_html ( $image ) . " </div> " ;
}
}
$parent_summary_html .= " .</span> " ;
$parent_summary_html .= " <a href='#' id='relationships-parent-toggle' class='shm-relationships-parent-toggle'>« hide</a> " ;
$parent_thumb_html .= " </div> " ;
$html = $parent_summary_html . $parent_thumb_html ;
2024-02-15 04:40:42 +00:00
$page -> add_block ( new Block ( null , $html , " main " , 5 , " PostRelationshipsParent " ));
2019-05-28 16:59:38 +00:00
}
2024-01-15 17:12:36 +00:00
if ( bool_escape ( $image [ 'has_children' ])) {
2024-02-15 04:30:41 +00:00
$visible_children = Relationships :: get_children ( $image -> id );
if ( ! empty ( $visible_children )) {
$child_summary_html = " <span>This post has <a href=' " . make_link ( 'post/list/parent=' . $image -> id . '/1' ) . " '> " . ( count ( $visible_children ) > 1 ? " child posts " : " a child post " ) . " </a> " ;
$child_summary_html .= " (post " ;
$child_thumb_html = " <div class='shm-relationships-child-thumbs'><div class='shm-child-thumbs'> " ;
foreach ( $visible_children as $child ) {
$child_summary_html .= " <a href=' " . make_link ( 'post/view/' . $child -> id ) . " '># { $child -> id } </a>, " ;
2024-02-15 21:00:25 +00:00
$child_thumb_html .= $this -> get_child_thumbnail_html ( $child );
2024-02-15 04:30:41 +00:00
}
$child_summary_html = rtrim ( $child_summary_html , " , " ) . " ). " ;
$child_summary_html .= " </span><a href='#' id='relationships-child-toggle' class='shm-relationships-child-toggle'>« hide</a> " ;
$child_thumb_html .= " </div></div> " ;
$html = $child_summary_html . $child_thumb_html ;
2024-02-15 04:40:42 +00:00
$page -> add_block ( new Block ( null , $html , " main " , 5 , " PostRelationshipsChildren " ));
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 " ,
2024-01-15 17:12:36 +00:00
strval ( $image [ 'parent_id' ]) ? : " None " ,
2024-07-15 01:33:07 +00:00
$user -> can ( Permissions :: EDIT_IMAGE_RELATIONSHIPS ) ? INPUT ([ " type " => " number " , " name " => " parent " , " value " => $image [ 'parent_id' ]]) : null
2023-08-17 17:09:38 +00:00
);
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 " >
2024-06-11 15:02:52 +00:00
< code > parent = any </ code >
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 " >
2024-06-11 15:02:52 +00:00
< code > parent = none </ code >
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 " >
2024-06-11 15:02:52 +00:00
< code > parent = 123 </ code >
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 " >
2024-06-11 15:02:52 +00:00
< code > child = any </ code >
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 " >
2024-06-11 15:02:52 +00:00
< code > child = none </ code >
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
' ;
}
2024-02-15 04:30:41 +00:00
private function get_parent_thumbnail_html ( Image $image ) : HTMLElement
{
$parent_id = $image [ 'parent_id' ];
2024-02-20 00:22:25 +00:00
$parent_image = Image :: by_id_ex ( $parent_id );
2024-02-15 04:30:41 +00:00
2024-02-15 21:00:25 +00:00
return $this -> build_thumb_html ( $parent_image );
2024-02-15 04:30:41 +00:00
}
private function get_child_thumbnail_html ( Image $image ) : HTMLElement
{
2024-02-15 21:00:25 +00:00
return $this -> build_thumb_html ( $image );
2024-02-15 04:30:41 +00:00
}
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 ;
}
2014-02-03 13:54:09 +00:00
}