2020-01-26 13:19:35 +00:00
|
|
|
<?php declare(strict_types=1);
|
2007-07-19 12:13:46 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
class SetupTheme extends Themelet
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Display a set of setup option blocks
|
|
|
|
*
|
|
|
|
* $panel = the container of the blocks
|
|
|
|
* $panel->blocks the blocks to be displayed, unsorted
|
|
|
|
*
|
|
|
|
* It's recommented that the theme sort the blocks before doing anything
|
|
|
|
* else, using: usort($panel->blocks, "blockcmp");
|
|
|
|
*
|
|
|
|
* The page should wrap all the options in a form which links to setup_save
|
|
|
|
*/
|
|
|
|
public function display_page(Page $page, SetupPanel $panel)
|
|
|
|
{
|
|
|
|
usort($panel->blocks, "blockcmp");
|
2007-07-19 12:13:46 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
/*
|
|
|
|
* Try and keep the two columns even; count the line breaks in
|
|
|
|
* each an calculate where a block would work best
|
|
|
|
*/
|
|
|
|
$setupblock_html = "";
|
|
|
|
foreach ($panel->blocks as $block) {
|
|
|
|
$setupblock_html .= $this->sb_to_html($block);
|
|
|
|
}
|
2007-07-19 12:13:46 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
$table = "
|
2010-09-22 11:56:19 +00:00
|
|
|
".make_form(make_link("setup/save"))."
|
2012-02-12 09:51:25 +00:00
|
|
|
<div class='setupblocks'>$setupblock_html</div>
|
|
|
|
<input type='submit' value='Save Settings'>
|
2010-09-22 11:56:19 +00:00
|
|
|
</form>
|
2007-07-19 12:13:46 +00:00
|
|
|
";
|
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
$page->set_title("Shimmie Setup");
|
|
|
|
$page->set_heading("Shimmie Setup");
|
|
|
|
$page->add_block(new Block("Navigation", $this->build_navigation(), "left", 0));
|
|
|
|
$page->add_block(new Block("Setup", $table));
|
|
|
|
}
|
2007-07-19 12:13:46 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
public function display_advanced(Page $page, $options)
|
|
|
|
{
|
|
|
|
$h_rows = "";
|
|
|
|
ksort($options);
|
|
|
|
foreach ($options as $name => $value) {
|
2020-01-26 16:38:26 +00:00
|
|
|
if (is_null($value)) {
|
|
|
|
$value = '';
|
|
|
|
}
|
2020-01-26 13:19:35 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
$h_name = html_escape($name);
|
2020-01-26 13:19:35 +00:00
|
|
|
$h_value = html_escape((string)$value);
|
2009-01-17 04:24:43 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
$h_box = "";
|
2020-01-26 13:19:35 +00:00
|
|
|
if (is_string($value) && strpos($value, "\n") > 0) {
|
2019-05-28 16:59:38 +00:00
|
|
|
$h_box .= "<textarea cols='50' rows='4' name='_config_$h_name'>$h_value</textarea>";
|
|
|
|
} else {
|
|
|
|
$h_box .= "<input type='text' name='_config_$h_name' value='$h_value'>";
|
|
|
|
}
|
|
|
|
$h_box .= "<input type='hidden' name='_type_$h_name' value='string'>";
|
|
|
|
$h_rows .= "<tr><td>$h_name</td><td>$h_box</td></tr>";
|
|
|
|
}
|
2008-04-06 21:03:13 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
$table = "
|
2010-09-22 11:56:19 +00:00
|
|
|
".make_form(make_link("setup/save"))."
|
2020-03-26 14:57:38 +00:00
|
|
|
<table id='settings' class='zebra'>
|
2010-09-22 11:56:19 +00:00
|
|
|
<thead><tr><th width='25%'>Name</th><th>Value</th></tr></thead>
|
2012-02-13 20:51:34 +00:00
|
|
|
<tbody>$h_rows</tbody>
|
2010-09-22 11:56:19 +00:00
|
|
|
<tfoot><tr><td colspan='2'><input type='submit' value='Save Settings'></td></tr></tfoot>
|
|
|
|
</table>
|
|
|
|
</form>
|
2008-04-06 21:03:13 +00:00
|
|
|
";
|
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
$page->set_title("Shimmie Setup");
|
|
|
|
$page->set_heading("Shimmie Setup");
|
|
|
|
$page->add_block(new Block("Navigation", $this->build_navigation(), "left", 0));
|
|
|
|
$page->add_block(new Block("Setup", $table));
|
|
|
|
}
|
2008-04-06 21:03:13 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
protected function build_navigation()
|
|
|
|
{
|
|
|
|
return "
|
2007-07-26 13:19:39 +00:00
|
|
|
<a href='".make_link()."'>Index</a>
|
2013-08-05 19:34:50 +00:00
|
|
|
<br><a href='https://github.com/shish/shimmie2/wiki/Settings'>Help</a>
|
2008-04-06 21:03:13 +00:00
|
|
|
<br><a href='".make_link("setup/advanced")."'>Advanced</a>
|
2007-07-19 12:13:46 +00:00
|
|
|
";
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2007-07-19 12:13:46 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
protected function sb_to_html(SetupBlock $block)
|
|
|
|
{
|
|
|
|
$h = $block->header;
|
|
|
|
$b = $block->body;
|
|
|
|
$i = preg_replace('/[^a-zA-Z0-9]/', '_', $h) . "-setup";
|
|
|
|
$html = "
|
2012-03-12 05:31:19 +00:00
|
|
|
<section class='setupblock'>
|
2012-03-12 02:50:41 +00:00
|
|
|
<b class='shm-toggler' data-toggle-sel='#$i'>$h</b>
|
2012-03-10 02:04:15 +00:00
|
|
|
<br><div id='$i'>$b</div>
|
2012-03-12 05:31:19 +00:00
|
|
|
</section>
|
2012-03-10 02:04:15 +00:00
|
|
|
";
|
2019-05-28 16:59:38 +00:00
|
|
|
return $html;
|
|
|
|
}
|
2007-07-19 12:13:46 +00:00
|
|
|
}
|