2015-09-19 09:19:56 +00:00
< ? php
register_module ([
" name " => " Page list " ,
2015-12-21 08:45:38 +00:00
" version " => " 0.9 " ,
2015-09-19 09:19:56 +00:00
" author " => " Starbeamrainbowlabs " ,
" description " => " Adds a page that lists all the pages in the index along with their metadata. " ,
" id " => " page-list " ,
" code " => function () {
2015-12-21 08:45:38 +00:00
global $settings ;
2015-09-19 09:19:56 +00:00
add_action ( " list " , function () {
global $pageindex , $settings ;
2015-10-25 15:45:25 +00:00
$title = " All Pages " ;
$content = " <h1> $title on $settings->sitename </h1> " ;
2015-09-19 09:19:56 +00:00
$sorted_pageindex = get_object_vars ( $pageindex );
ksort ( $sorted_pageindex , SORT_NATURAL );
2015-10-25 15:45:25 +00:00
$content .= generate_page_list ( array_keys ( $sorted_pageindex ));
exit ( page_renderer :: render_main ( " $title - $settings->sitename " , $content ));
});
add_action ( " list-tags " , function () {
global $pageindex , $settings ;
2015-11-09 07:37:38 +00:00
if ( ! isset ( $_GET [ " tag " ]))
2015-10-25 15:45:25 +00:00
{
2015-11-09 07:37:38 +00:00
// Render a list of all tags
$all_tags = [];
foreach ( $pageindex as $entry )
{
if ( ! isset ( $entry -> tags )) continue ;
foreach ( $entry -> tags as $tag )
{
if ( ! in_array ( $tag , $all_tags )) $all_tags [] = $tag ;
}
}
$content = " <h1>All tags</h1>
2015-12-12 20:31:35 +00:00
< ul class = 'tag-list' > \n " ;
2015-11-09 07:37:38 +00:00
foreach ( $all_tags as $tag )
{
2015-12-12 20:31:35 +00:00
$content .= " <li><a href='?action=list-tags&tag= " . rawurlencode ( $tag ) . " ' class='mini-tag'> $tag </a></li> \n " ;
2015-11-09 07:37:38 +00:00
}
2015-12-20 10:54:47 +00:00
$content .= " </ul> \n " ;
2015-11-09 07:37:38 +00:00
exit ( page_renderer :: render ( " All tags - $settings->sitename " , $content ));
2015-10-25 15:45:25 +00:00
}
$tag = $_GET [ " tag " ];
$sorted_pageindex = get_object_vars ( $pageindex );
ksort ( $sorted_pageindex , SORT_NATURAL );
$pagelist = [];
foreach ( $pageindex as $pagename => $pagedetails )
{
if ( empty ( $pagedetails -> tags )) continue ;
if ( in_array ( $tag , $pagedetails -> tags ))
$pagelist [] = $pagename ;
}
$content = " <h1> $tag </h1> \n " ;
$content .= generate_page_list ( $pagelist );
2015-12-20 10:54:47 +00:00
$content .= " <p>(<a href='?action=list-tags'>All tags</a>)</p> \n " ;
2015-10-25 15:45:25 +00:00
exit ( page_renderer :: render ( " $tag - Page List - $settings->sitename " , $content ));
});
2015-12-21 08:45:38 +00:00
add_help_section ( " 30-all-pages-tags " , " Listing pages and tags " , " <p>All the pages and tags on $settings->sitename are listed on a pair of paegs to aid navigation. The list of all pages on $settings->sitename can be found by clicking "All Pages" on the top bar. The list of all the tags currently in use can be found by clicking "All Tags" in the "More..." menu in the top right.</p>
< p > Each tag on either page can be clicked , and leads to a list of all pages that possess that particular tag .</ p >
< p > A page ' s last known editor is also shown next to each entry on a list of pages , along with the last known size ( which should correct , unless it was changed outside of $settings -> sitename ) and the time since the last modification ( hovering over this will show the exact time that the last modification was made in a tooltip ) .</ p > " );
2015-10-25 15:45:25 +00:00
}
]);
function generate_page_list ( $pagelist )
{
global $pageindex ;
2015-12-16 10:24:13 +00:00
// ✎ ✎ 🕒 🕒
$result = " <ul class='page-list'> \n " ;
2015-10-25 15:45:25 +00:00
foreach ( $pagelist as $pagename )
{
2015-12-12 20:11:17 +00:00
// Construct a list of tags that are attached to this page ready for display
$tags = " " ;
// Make sure that this page does actually have some tags first
if ( isset ( $pageindex -> $pagename -> tags ))
{
foreach ( $pageindex -> $pagename -> tags as $tag )
{
$tags .= " <a href='?action=list-tags&tag= " . rawurlencode ( $tag ) . " ' class='mini-tag'> $tag </a>, " ;
}
$tags = substr ( $tags , 0 , - 2 ); // Remove the last ", " from the tag list
}
2015-12-16 10:24:13 +00:00
$result .= " <li><a href='index.php?page= $pagename '> $pagename </a>
< em class = 'size' > ( " . human_filesize( $pageindex -> $pagename->size ) . " ) </ em >
2015-12-16 19:05:08 +00:00
< span class = 'editor' >& #9998; " . $pageindex->$pagename->lasteditor . "</span>
2015-12-16 10:24:13 +00:00
< time title = '" . date("l jS \of F Y \a\\t h:ia T", $pageindex->$pagename->lastmodified) . "' > " . human_time_since( $pageindex -> $pagename->lastmodified ) . " </ time >
< span class = 'tags' > $tags </ span ></ li > " ;
2015-09-19 09:19:56 +00:00
}
2015-12-20 10:54:47 +00:00
$result .= " </ul> \n " ;
2015-10-25 15:45:25 +00:00
return $result ;
}
2015-09-19 09:19:56 +00:00
?>