2019-08-25 17:12:08 +00:00
< ? php
register_module ([
" name " => " Theme Gallery " ,
" version " => " 0.1 " ,
" author " => " Starbeamrainbowlabs " ,
2019-08-26 14:27:24 +00:00
" description " => " Adds a theme gallery page and optional automatic theme updates. Contacts a remote server, where IP addresses are stored in automatic server logs for security and attack mitigation purposes. " ,
2019-08-25 17:12:08 +00:00
" id " => " feature-theme-gallery " ,
" code " => function () {
global $settings ;
/**
* @ api { get } ? action = theme - gallery Display the theme gallery
* @ apiName ThemeGallery
* @ apiGroup Utility
* @ apiPermission Moderator
*/
add_action ( " theme-gallery " , function () {
global $settings ;
$themes_available = [];
$gallery_urls = explode ( " " , $settings -> css_theme_gallery_index_url );
foreach ( $gallery_urls as $url ) {
if ( empty ( $url )) continue ;
$next_obj = json_decode ( file_get_contents ( $url ));
if ( $next_obj === null ) {
http_response_code ( 503 );
exit ( page_renderer :: render_main ( " Error - Theme Gallery - $settings->sitename " , " <p>Error: Failed to download theme index file from <code> " . htmlentities ( $url ) . " </code>. " ));
}
2019-08-26 12:16:13 +00:00
foreach ( $next_obj as $theme ) {
2019-08-26 14:27:24 +00:00
$theme -> index_url = $url ;
$theme -> root = dirname ( $url ) . " / { $theme -> id } " ;
$theme -> url = " { $theme -> root } /theme.css " ;
$theme -> preview_large = " { $theme -> root } /preview_large.png " ;
$theme -> preview_small = " { $theme -> root } /preview_small.png " ;
2019-08-26 12:16:13 +00:00
$themes_available [] = $theme ;
}
2019-08-25 17:12:08 +00:00
}
2019-08-26 14:48:37 +00:00
usort ( $themes_available , function ( $a , $b ) {
return strcmp ( $a -> name , $b -> name );
});
2019-08-25 17:12:08 +00:00
$content = " <h1>Theme Gallery</h1>
< div class = 'grid theme-list' > \n " ;
foreach ( $themes_available as $theme ) {
$content .= " <div class='theme-item'>
2019-08-26 14:27:24 +00:00
< a href = '" . htmlentities($theme->preview_large) . "' >< img src = '" . htmlentities($theme->preview_small) . "' title = 'Click to enlarge.' /></ a >
< input type = 'radio' id = '" . htmlentities($theme->id) . "' name = 'theme-selector' value = '" . htmlentities($theme->id) . "' />
< label for = '" . htmlentities($theme->id) . "' > " . htmlentities( $theme->name ) . " </ label >
< p > " . str_replace( " \n " , " </ p > \n < p > " , htmlentities( $theme->description )) . " </ p >
< p > By < a href = '" . htmlentities($theme->author_link) . "' > " . htmlentities( $theme->author ) . " </ a > ( < a href = '" . htmlentities($theme->url) . "' > View CSS </ a > , < a href = '" . htmlentities($theme->index_url) . "' > View Index </ a > )
2019-08-25 17:12:08 +00:00
</ div > " ;
}
$content .= " </div> " ;
2019-08-26 14:27:24 +00:00
exit ( page_renderer :: render_main ( " Theme Gallery - $settings->sitename " , " $content " ));
2019-08-25 17:12:08 +00:00
});
add_help_section ( " 26-random-redirect " , " Jumping to a random page " , " <p> $settings->sitename has a function that can send you to a random page. To use it, click <a href='?action=random'>here</a>. $settings->admindetails_name ( $settings->sitename 's adminstrator) may have added it to one of the menus.</p> " );
}
]);
?>