2021-12-14 18:32:47 +00:00
< ? php
declare ( strict_types = 1 );
2007-07-10 22:33:49 +00:00
2023-01-10 22:44:09 +00:00
namespace Shimmie2 ;
2023-07-10 18:04:23 +00:00
use MicroHTML\HTMLElement ;
use function MicroHTML\emptyHTML ;
2024-06-21 17:29:26 +00:00
use function MicroHTML\ { BR , H3 , HR , P , META };
2023-07-10 18:04:23 +00:00
2019-05-28 16:59:38 +00:00
class IndexTheme extends Themelet
{
2021-03-14 23:43:50 +00:00
protected int $page_number ;
protected int $total_pages ;
2024-01-20 14:10:59 +00:00
/** @var string[] */
2021-03-14 23:43:50 +00:00
protected array $search_terms ;
2019-05-28 16:59:38 +00:00
2024-01-20 14:10:59 +00:00
/**
* @ param string [] $search_terms
*/
public function set_page ( int $page_number , int $total_pages , array $search_terms ) : void
2019-05-28 16:59:38 +00:00
{
$this -> page_number = $page_number ;
$this -> total_pages = $total_pages ;
$this -> search_terms = $search_terms ;
}
2024-01-15 14:23:00 +00:00
public function display_intro ( Page $page ) : void
2019-05-28 16:59:38 +00:00
{
$text = "
2012-02-02 05:27:40 +00:00
< div style = 'text-align: left;' >
2009-01-22 09:39:44 +00:00
< p > The first thing you ' ll probably want to do is create a new account ; note
that the first account you create will by default be marked as the board ' s
administrator , and any further accounts will be regular users .
< p > Once logged in you can play with the settings , install extra features ,
and of course start organising your images :- )
2009-01-22 10:14:16 +00:00
< p > This message will go away once your first image is uploaded ~
2009-01-22 09:39:44 +00:00
</ div >
2012-02-02 05:27:40 +00:00
" ;
2019-05-28 16:59:38 +00:00
$page -> set_title ( " Welcome to Shimmie " . VERSION );
$page -> set_heading ( " Welcome to Shimmie " );
2020-03-22 15:23:23 +00:00
$page -> add_block ( new Block ( " Nothing here yet! " , $text , " main " , 0 ));
2019-05-28 16:59:38 +00:00
}
/**
2024-01-01 03:27:39 +00:00
* @ param Image [] $images
2019-05-28 16:59:38 +00:00
*/
2024-01-15 14:23:00 +00:00
public function display_page ( Page $page , array $images ) : void
2019-05-28 16:59:38 +00:00
{
2020-03-23 12:48:38 +00:00
$this -> display_shortwiki ( $page );
2019-05-28 16:59:38 +00:00
$this -> display_page_header ( $page , $images );
$nav = $this -> build_navigation ( $this -> page_number , $this -> total_pages , $this -> search_terms );
$page -> add_block ( new Block ( " Navigation " , $nav , " left " , 0 ));
if ( count ( $images ) > 0 ) {
$this -> display_page_images ( $page , $images );
} else {
2020-10-26 13:45:25 +00:00
$this -> display_error ( 404 , " No posts Found " , " No posts were found to match the search criteria " );
2019-05-28 16:59:38 +00:00
}
}
/**
2024-01-01 03:27:39 +00:00
* @ param string [] $parts
2019-05-28 16:59:38 +00:00
*/
2024-01-15 14:23:00 +00:00
public function display_admin_block ( array $parts ) : void
2019-05-28 16:59:38 +00:00
{
global $page ;
$page -> add_block ( new Block ( " List Controls " , join ( " <br> " , $parts ), " left " , 50 ));
}
/**
2024-01-01 03:27:39 +00:00
* @ param string [] $search_terms
2019-05-28 16:59:38 +00:00
*/
protected function build_navigation ( int $page_number , int $total_pages , array $search_terms ) : string
{
$prev = $page_number - 1 ;
$next = $page_number + 1 ;
2023-08-18 12:38:55 +00:00
$h_prev = ( $page_number <= 1 ) ? " Prev " : '<a href="' . search_link ( $search_terms , $prev ) . '">Prev</a>' ;
2019-05-28 16:59:38 +00:00
$h_index = " <a href=' " . make_link () . " '>Index</a> " ;
2023-08-18 12:38:55 +00:00
$h_next = ( $page_number >= $total_pages ) ? " Next " : '<a href="' . search_link ( $search_terms , $next ) . '">Next</a>' ;
2019-05-28 16:59:38 +00:00
$h_search_string = html_escape ( Tag :: implode ( $search_terms ));
2023-08-18 12:38:55 +00:00
$h_search_link = search_link ();
2019-05-28 16:59:38 +00:00
$h_search = "
2024-02-11 11:34:09 +00:00
< p >< form action = '$h_search_link' method = 'GET' >
2023-12-26 12:53:46 +00:00
< input type = 'search' name = 'search' value = '$h_search_string' placeholder = 'Search' class = 'autocomplete_tags' />
2024-02-12 11:11:14 +00:00
< input type = 'hidden' name = 'q' value = 'post/list' >
2007-07-10 22:33:49 +00:00
< input type = 'submit' value = 'Find' style = 'display: none;' />
</ form >
2012-02-09 14:34:29 +00:00
" ;
2007-07-10 22:33:49 +00:00
2019-05-28 16:59:38 +00:00
return $h_prev . ' | ' . $h_index . ' | ' . $h_next . '<br>' . $h_search ;
}
/**
2024-01-01 03:27:39 +00:00
* @ param Image [] $images
2019-05-28 16:59:38 +00:00
*/
2019-05-28 18:00:23 +00:00
protected function build_table ( array $images , ? string $query ) : string
2019-05-28 16:59:38 +00:00
{
$h_query = html_escape ( $query );
$table = " <div class='shm-image-list' data-query=' $h_query '> " ;
foreach ( $images as $image ) {
$table .= $this -> build_thumb_html ( $image );
}
$table .= " </div> " ;
return $table ;
}
2024-01-20 14:10:59 +00:00
protected function display_shortwiki ( Page $page ) : void
2020-03-23 12:48:38 +00:00
{
global $config ;
2024-01-20 01:03:01 +00:00
if ( Extension :: is_enabled ( WikiInfo :: KEY ) && $config -> get_bool ( WikiConfig :: TAG_SHORTWIKIS )) {
2020-03-23 12:48:38 +00:00
if ( count ( $this -> search_terms ) == 1 ) {
$st = Tag :: implode ( $this -> search_terms );
$wikiPage = Wiki :: get_page ( $st );
$short_wiki_description = '' ;
if ( $wikiPage -> id != - 1 ) {
// only show first line of wiki
$short_wiki_description = explode ( " \n " , $wikiPage -> body , 2 )[ 0 ];
2023-02-04 20:50:26 +00:00
$tfe = send_event ( new TextFormattingEvent ( $short_wiki_description ));
2020-03-23 12:48:38 +00:00
$short_wiki_description = $tfe -> formatted ;
}
$wikiLink = make_link ( " wiki/ $st " );
2024-01-20 01:03:01 +00:00
if ( Extension :: is_enabled ( TagCategoriesInfo :: KEY )) {
2023-02-03 16:44:16 +00:00
$tagcategories = new TagCategories ();
$tag_category_dict = $tagcategories -> getKeyedDict ();
$st = $tagcategories -> getTagHtml ( html_escape ( $st ), $tag_category_dict );
2020-03-23 12:48:38 +00:00
}
$short_wiki_description = '<h2>' . $st . ' <a href="' . $wikiLink . '"><sup>ⓘ</sup></a></h2>' . $short_wiki_description ;
$page -> add_block ( new Block ( null , $short_wiki_description , " main " , 0 , " short-wiki-description " ));
}
}
}
2019-05-28 16:59:38 +00:00
/**
2024-01-01 03:27:39 +00:00
* @ param Image [] $images
2019-05-28 16:59:38 +00:00
*/
2024-01-20 14:10:59 +00:00
protected function display_page_header ( Page $page , array $images ) : void
2019-05-28 16:59:38 +00:00
{
global $config ;
if ( count ( $this -> search_terms ) == 0 ) {
2019-08-02 19:40:03 +00:00
$page_title = $config -> get_string ( SetupConfig :: TITLE );
2019-05-28 16:59:38 +00:00
} else {
$search_string = implode ( ' ' , $this -> search_terms );
$page_title = html_escape ( $search_string );
if ( count ( $images ) > 0 ) {
$page -> set_subheading ( " Page { $this -> page_number } / { $this -> total_pages } " );
}
}
2019-11-04 01:04:08 +00:00
/*
2019-05-28 16:59:38 +00:00
if ( $this -> page_number > 1 || count ( $this -> search_terms ) > 0 ) {
2019-11-04 01:04:08 +00:00
$page_title .= " / $page_number " ;
2019-05-28 16:59:38 +00:00
}
2019-11-04 01:04:08 +00:00
*/
2019-05-28 16:59:38 +00:00
$page -> set_title ( $page_title );
$page -> set_heading ( $page_title );
}
/**
2024-01-01 03:27:39 +00:00
* @ param Image [] $images
2019-05-28 16:59:38 +00:00
*/
2024-01-20 14:10:59 +00:00
protected function display_page_images ( Page $page , array $images ) : void
2019-05-28 16:59:38 +00:00
{
if ( count ( $this -> search_terms ) > 0 ) {
if ( $this -> page_number > 3 ) {
// only index the first pages of each term
2024-06-21 17:29:26 +00:00
$page -> add_html_header ( META ([ " name " => " robots " , " content " => " noindex, nofollow " ]));
2019-05-28 16:59:38 +00:00
}
2023-12-24 21:12:59 +00:00
$query = url_escape ( Tag :: implode ( $this -> search_terms ));
2020-10-26 15:12:54 +00:00
$page -> add_block ( new Block ( " Posts " , $this -> build_table ( $images , " #search= $query " ), " main " , 10 , " image-list " ));
2019-05-28 16:59:38 +00:00
$this -> display_paginator ( $page , " post/list/ $query " , null , $this -> page_number , $this -> total_pages , true );
} else {
2020-10-26 15:12:54 +00:00
$page -> add_block ( new Block ( " Posts " , $this -> build_table ( $images , null ), " main " , 10 , " image-list " ));
2019-05-28 16:59:38 +00:00
$this -> display_paginator ( $page , " post/list " , null , $this -> page_number , $this -> total_pages , true );
}
}
2019-08-02 20:05:49 +00:00
2023-07-10 18:04:23 +00:00
public function get_help_html () : HTMLElement
2019-08-02 20:05:49 +00:00
{
2023-07-10 18:04:23 +00:00
return emptyHTML (
H3 ( " Tag Searching " ),
P ( " Searching is largely based on tags, with a number of special keywords available that allow searching based on properties of the posts. " ),
SHM_COMMAND_EXAMPLE ( " tagname " , 'Returns posts that are tagged with "tagname".' ),
SHM_COMMAND_EXAMPLE ( " tagname othertagname " , 'Returns posts that are tagged with "tagname" and "othertagme".' ),
2023-07-10 18:06:52 +00:00
//
2023-07-10 18:04:23 +00:00
BR (),
P ( " Most tags and keywords can be prefaced with a negative sign (-) to indicate that you want to search for posts that do not match something. " ),
SHM_COMMAND_EXAMPLE ( " -tagname " , 'Returns posts that are not tagged with "tagname".' ),
SHM_COMMAND_EXAMPLE ( " -tagname -othertagname " , 'Returns posts that are not tagged with "tagname" or "othertagname".' ),
SHM_COMMAND_EXAMPLE ( " tagname -othertagname " , 'Returns posts that are tagged with "tagname", but are not tagged with "othertagname".' ),
2023-07-10 18:06:52 +00:00
//
2023-07-10 18:04:23 +00:00
BR (),
P ( 'Wildcard searches are possible as well using * for "any one, more, or none" and ? for "any one".' ),
2024-02-20 06:38:46 +00:00
SHM_COMMAND_EXAMPLE ( " tag* " , 'Returns posts that are tagged with "tag", "tags", "tagme", "tagname", or anything else that starts with "tag".' ),
SHM_COMMAND_EXAMPLE ( " *name " , 'Returns posts that are tagged with "name", "tagname", "othertagname" or anything else that ends with "name".' ),
SHM_COMMAND_EXAMPLE ( " tagn?me " , 'Returns posts that are tagged with "tagname", "tagnome", or anything else that starts with "tagn", then has one character, and ends with "me".' ),
2023-07-10 18:06:52 +00:00
//
//
//
2023-07-10 18:04:23 +00:00
HR (),
H3 ( " Comparing values (<, <=, >, >=, or =) " ),
P ( " For example, you can use this to count tags. " ),
SHM_COMMAND_EXAMPLE ( " tags=1 " , " Returns posts with exactly 1 tag. " ),
SHM_COMMAND_EXAMPLE ( " tags>0 " , " Returns posts with 1 or more tags. " ),
2023-07-10 18:06:52 +00:00
//
2023-07-10 18:04:23 +00:00
BR (),
P ( " Searching for posts by aspect ratio. " ),
P ( " The relation is calculated as: width / height. " ),
SHM_COMMAND_EXAMPLE ( " ratio=4:3 " , " Returns posts with an aspect ratio of 4:3. " ),
SHM_COMMAND_EXAMPLE ( " ratio>16:9 " , " Returns posts with an aspect ratio greater than 16:9. " ),
2023-07-10 18:06:52 +00:00
//
2023-07-10 18:04:23 +00:00
BR (),
P ( " Searching by dimentions. " ),
SHM_COMMAND_EXAMPLE ( " size=640x480 " , " Returns posts exactly 640 pixels wide by 480 pixels high. " ),
SHM_COMMAND_EXAMPLE ( " size>1920x1080 " , " Returns posts with a width larger than 1920 and a height larger than 1080. " ),
SHM_COMMAND_EXAMPLE ( " width=1000 " , " Returns posts exactly 1000 pixels wide. " ),
SHM_COMMAND_EXAMPLE ( " height=1000 " , " Returns posts exactly 1000 pixels high. " ),
2023-07-10 18:06:52 +00:00
//
2023-07-10 18:04:23 +00:00
BR (),
P ( " Searching by file size. " ),
P ( " Supported suffixes are kb, mb, and gb. Uses multiples of 1024. " ),
SHM_COMMAND_EXAMPLE ( " filesize=1 " , " Returns posts exactly 1 byte in size " ),
SHM_COMMAND_EXAMPLE ( " filesize>100mb " , " Returns posts greater than 100 megabytes in size. " ),
2023-07-10 18:06:52 +00:00
//
2023-07-10 18:04:23 +00:00
BR (),
P ( " Searching by date posted. " ),
P ( " Date format is yyyy-mm-dd. Date posted includes time component, so = will not work unless the time is exact. " ),
SHM_COMMAND_EXAMPLE ( " posted>=2019-07-19 " , " Returns posts posted on or after 2019-07-19. " ),
2023-07-10 18:06:52 +00:00
//
2023-07-10 18:04:23 +00:00
BR (),
P ( " Searching posts by media length. " ),
P ( " Available suffixes are ms, s, m, h, d, and y. A number by itself will be interpreted as milliseconds. Searches using = are not likely to work unless time is specified down to the millisecond. " ),
2023-07-10 18:06:52 +00:00
SHM_COMMAND_EXAMPLE ( " length>=1h " , " Returns posts that are longer than an hour. " ),
SHM_COMMAND_EXAMPLE ( " length<=10h15m " , " Returns posts that are shorter than 10 hours and 15 minutes. " ),
SHM_COMMAND_EXAMPLE ( " length>=10000 " , " Returns posts that are longer than 10,000 milliseconds, or 10 seconds. " ),
//
2023-07-10 18:04:23 +00:00
BR (),
P ( " Searching posts by ID. " ),
SHM_COMMAND_EXAMPLE ( " id=1234 " , " Find the 1234th thing uploaded. " ),
SHM_COMMAND_EXAMPLE ( " id>1234 " , " Find more recently posted things. " ),
2023-07-10 18:06:52 +00:00
//
//
//
2023-07-10 18:04:23 +00:00
HR (),
H3 ( " Post attributes. " ),
P ( " Searching by MD5 hash. " ),
SHM_COMMAND_EXAMPLE ( " hash=0D3512CAA964B2BA5D7851AF5951F33B " , " Returns post with MD5 hash 0D3512CAA964B2BA5D7851AF5951F33B. " ),
2023-07-10 18:06:52 +00:00
//
2023-07-10 18:04:23 +00:00
BR (),
P ( " Searching by file name. " ),
SHM_COMMAND_EXAMPLE ( " filename=picasso.jpg " , 'Returns posts that are named "picasso.jpg".' ),
2023-07-10 18:06:52 +00:00
//
2023-07-10 18:04:23 +00:00
BR (),
P ( " Searching for posts by source. " ),
SHM_COMMAND_EXAMPLE ( " source=https:///google.com/ " , 'Returns posts with a source of "https://google.com/".' ),
SHM_COMMAND_EXAMPLE ( " source=any " , " Returns posts with a source set. " ),
SHM_COMMAND_EXAMPLE ( " source=none " , " Returns posts without a source set. " ),
2023-07-10 18:06:52 +00:00
//
//
//
2023-07-10 18:04:23 +00:00
HR (),
H3 ( " Sorting search results " ),
P ( " Sorting can be done using the pattern order:field_direction. " ),
P ( " Supported fields: id, width, height, filesize, filename. " ),
P ( " Direction can be either asc or desc, indicating ascending (123) or descending (321) order. " ),
SHM_COMMAND_EXAMPLE ( " order:id_asc " , " Returns posts sorted by ID, smallest first. " ),
SHM_COMMAND_EXAMPLE ( " order:width_desc " , " Returns posts sorted by width, largest first. " ),
);
2019-08-02 20:05:49 +00:00
}
2007-07-10 22:33:49 +00:00
}