Added table-building support to SetupBlock to allow easily building cleaner setup controls
This commit is contained in:
parent
9ca800d1c4
commit
c16d55995b
@ -13,7 +13,7 @@ TD>BUTTON {width: 100%;}
|
|||||||
TABLE.form {width: 300px;}
|
TABLE.form {width: 300px;}
|
||||||
TABLE.form TD, TABLE.form TH {vertical-align: middle;}
|
TABLE.form TD, TABLE.form TH {vertical-align: middle;}
|
||||||
TABLE.form TBODY TD {text-align: left;}
|
TABLE.form TBODY TD {text-align: left;}
|
||||||
TABLE.form TBODY TH {text-align: right; padding-right: 4px; width: 1%;}
|
TABLE.form TBODY TH {text-align: right; padding-right: 4px; width: 1%; white-space: nowrap;}
|
||||||
TABLE.form TD + TH {padding-left: 8px;}
|
TABLE.form TD + TH {padding-left: 8px;}
|
||||||
|
|
||||||
*[onclick],
|
*[onclick],
|
||||||
|
@ -11,6 +11,16 @@
|
|||||||
* Documentation:
|
* Documentation:
|
||||||
* This extension allows admins to resize images.
|
* This extension allows admins to resize images.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
abstract class ResizeConfig
|
||||||
|
{
|
||||||
|
const ENABLED = 'resize_enabled';
|
||||||
|
const UPLOAD = 'resize_upload';
|
||||||
|
const ENGINE = 'resize_engine';
|
||||||
|
const DEFAULT_WIDTH = 'resize_default_width';
|
||||||
|
const DEFAULT_HEIGHT = 'resize_default_height';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class handles image resize requests.
|
* This class handles image resize requests.
|
||||||
*/
|
*/
|
||||||
@ -49,15 +59,20 @@ class ResizeImage extends Extension
|
|||||||
public function onSetupBuilding(SetupBuildingEvent $event)
|
public function onSetupBuilding(SetupBuildingEvent $event)
|
||||||
{
|
{
|
||||||
$sb = new SetupBlock("Image Resize");
|
$sb = new SetupBlock("Image Resize");
|
||||||
$sb->add_bool_option("resize_enabled", "Allow resizing images: ");
|
$sb->start_table();
|
||||||
$sb->add_bool_option("resize_upload", "<br>Resize on upload: ");
|
$sb->add_bool_option(ResizeConfig::ENABLED, "Allow resizing images: ", true);
|
||||||
$sb->add_label("<br>Preset/Default Width: ");
|
$sb->add_bool_option(ResizeConfig::UPLOAD, "Resize on upload: ", true);
|
||||||
$sb->add_int_option("resize_default_width");
|
$sb->end_table();
|
||||||
$sb->add_label(" px");
|
$sb->start_table();
|
||||||
$sb->add_label("<br>Preset/Default Height: ");
|
$sb->add_table_header("Preset/Default Dimensions");
|
||||||
$sb->add_int_option("resize_default_height");
|
$sb->add_label("<tr><th>Width</th><td>");
|
||||||
$sb->add_label(" px");
|
$sb->add_int_option(ResizeConfig::DEFAULT_WIDTH);
|
||||||
$sb->add_label("<br>(enter 0 for no default)");
|
$sb->add_label("</td><td>px</td></tr>");
|
||||||
|
$sb->add_label("<tr><th>Height</th><td>");
|
||||||
|
$sb->add_int_option(ResizeConfig::DEFAULT_HEIGHT);
|
||||||
|
$sb->add_label("</td><td>px</td></tr>");
|
||||||
|
$sb->add_label("<tr><td></td><td>(enter 0 for no default)</td></tr>");
|
||||||
|
$sb->end_table();
|
||||||
$event->panel->add_block($sb);
|
$event->panel->add_block($sb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,6 +61,8 @@ class SetupBlock extends Block
|
|||||||
/** @var string */
|
/** @var string */
|
||||||
public $body;
|
public $body;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct(string $title)
|
public function __construct(string $title)
|
||||||
{
|
{
|
||||||
$this->header = $title;
|
$this->header = $title;
|
||||||
@ -74,38 +76,123 @@ class SetupBlock extends Block
|
|||||||
$this->body .= $text;
|
$this->body .= $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add_text_option(string $name, string $label=null)
|
public function start_table()
|
||||||
{
|
{
|
||||||
|
$this->body .= "<table class='form'>";
|
||||||
|
}
|
||||||
|
public function end_table()
|
||||||
|
{
|
||||||
|
$this->body .= "</table>";
|
||||||
|
}
|
||||||
|
public function start_table_row()
|
||||||
|
{
|
||||||
|
$this->body .= "</tr>";
|
||||||
|
}
|
||||||
|
public function end_table_row()
|
||||||
|
{
|
||||||
|
$this->body .= "</tr>";
|
||||||
|
}
|
||||||
|
public function start_table_head()
|
||||||
|
{
|
||||||
|
$this->body .= "<thead>";
|
||||||
|
}
|
||||||
|
public function end_table_head()
|
||||||
|
{
|
||||||
|
$this->body .= "</thead>";
|
||||||
|
}
|
||||||
|
public function add_table_header($content, int $colspan = 2)
|
||||||
|
{
|
||||||
|
$this->start_table_head();
|
||||||
|
$this->start_table_row();
|
||||||
|
$this->add_table_header_cell($content, $colspan);
|
||||||
|
$this->end_table_row();
|
||||||
|
$this->end_table_head();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function start_table_cell(int $colspan = 1)
|
||||||
|
{
|
||||||
|
$this->body .= "<td colspan='$colspan'>";
|
||||||
|
}
|
||||||
|
public function end_table_cell()
|
||||||
|
{
|
||||||
|
$this->body .= "</td>";
|
||||||
|
}
|
||||||
|
public function add_table_cell($content, int $colspan = 1)
|
||||||
|
{
|
||||||
|
$this->start_table_cell($colspan);
|
||||||
|
$this->body .= $content;
|
||||||
|
$this->end_table_cell();
|
||||||
|
}
|
||||||
|
public function start_table_header_cell(int $colspan = 1)
|
||||||
|
{
|
||||||
|
$this->body .= "<th colspan='$colspan'>";
|
||||||
|
}
|
||||||
|
public function end_table_header_cell()
|
||||||
|
{
|
||||||
|
$this->body .= "</th>";
|
||||||
|
}
|
||||||
|
public function add_table_header_cell($content, int $colspan = 1)
|
||||||
|
{
|
||||||
|
$this->start_table_header_cell($colspan);
|
||||||
|
$this->body .= $content;
|
||||||
|
$this->end_table_header_cell();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private function format_option(string $name, $html, ?string $label, bool $table_row) {
|
||||||
global $config;
|
global $config;
|
||||||
$val = html_escape($config->get_string($name));
|
|
||||||
|
if($table_row) $this->start_table_row();
|
||||||
|
if($table_row) $this->start_table_header_cell();
|
||||||
if (!is_null($label)) {
|
if (!is_null($label)) {
|
||||||
$this->body .= "<label for='{$name}'>{$label}</label>";
|
$this->body .= "<label for='{$name}'>{$label}</label>";
|
||||||
}
|
}
|
||||||
$this->body .= "<input type='text' id='{$name}' name='_config_{$name}' value='{$val}'>\n";
|
if($table_row) $this->end_table_header_cell();
|
||||||
$this->body .= "<input type='hidden' name='_type_{$name}' value='string'>\n";
|
|
||||||
|
if($table_row) $this->start_table_cell();
|
||||||
|
$this->body .= $html;
|
||||||
|
if($table_row) $this->end_table_cell();
|
||||||
|
if($table_row) $this->end_table_row();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add_longtext_option(string $name, string $label=null)
|
public function add_text_option(string $name, string $label=null, bool $table_row = false)
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
$val = html_escape($config->get_string($name));
|
$val = html_escape($config->get_string($name));
|
||||||
if (!is_null($label)) {
|
|
||||||
$this->body .= "<label for='$name'>$label</label>";
|
$html = "<input type='text' id='{$name}' name='_config_{$name}' value='{$val}'>\n";
|
||||||
}
|
$html .= "<input type='hidden' name='_type_{$name}' value='string'>\n";
|
||||||
$rows = max(3, min(10, count(explode("\n", $val))));
|
|
||||||
$this->body .= "<textarea rows='$rows' id='$name' name='_config_$name'>$val</textarea>\n";
|
$this->format_option($name, $html, $label, $table_row);
|
||||||
$this->body .= "<input type='hidden' name='_type_$name' value='string'>\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add_bool_option(string $name, string $label=null)
|
public function add_longtext_option(string $name, string $label=null, bool $table_row = false)
|
||||||
|
{
|
||||||
|
global $config;
|
||||||
|
$val = html_escape($config->get_string($name));
|
||||||
|
|
||||||
|
$rows = max(3, min(10, count(explode("\n", $val))));
|
||||||
|
$html = "<textarea rows='$rows' id='$name' name='_config_$name'>$val</textarea>\n";
|
||||||
|
$html .= "<input type='hidden' name='_type_$name' value='string'>\n";
|
||||||
|
|
||||||
|
$this->format_option($name, $html, $label, $table_row);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function add_bool_option(string $name, string $label=null, bool $table_row = false)
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
$checked = $config->get_bool($name) ? " checked" : "";
|
$checked = $config->get_bool($name) ? " checked" : "";
|
||||||
|
|
||||||
|
$html = "<input type='checkbox' id='$name' name='_config_$name'$checked>\n";
|
||||||
if (!is_null($label)) {
|
if (!is_null($label)) {
|
||||||
$this->body .= "<label for='$name'>$label</label>";
|
$html .= "<label for='{$name}'>{$label}</label>";
|
||||||
|
$label = null;
|
||||||
}
|
}
|
||||||
$this->body .= "<input type='checkbox' id='$name' name='_config_$name'$checked>\n";
|
|
||||||
$this->body .= "<input type='hidden' name='_type_$name' value='bool'>\n";
|
$html .= "<input type='hidden' name='_type_$name' value='bool'>\n";
|
||||||
|
|
||||||
|
$this->format_option($name, $html, $label, $table_row);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public function add_hidden_option($name, $label=null) {
|
// public function add_hidden_option($name, $label=null) {
|
||||||
@ -114,36 +201,33 @@ class SetupBlock extends Block
|
|||||||
// $this->body .= "<input type='hidden' id='$name' name='$name' value='$val'>";
|
// $this->body .= "<input type='hidden' id='$name' name='$name' value='$val'>";
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public function add_int_option(string $name, string $label=null)
|
public function add_int_option(string $name, string $label=null, bool $table_row = false)
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
$val = html_escape($config->get_string($name));
|
$val = html_escape($config->get_string($name));
|
||||||
if (!is_null($label)) {
|
|
||||||
$this->body .= "<label for='$name'>$label</label>";
|
$html = "<input type='text' id='$name' name='_config_$name' value='$val' size='4' style='text-align: center;'>\n";
|
||||||
}
|
$html .= "<input type='hidden' name='_type_$name' value='int'>\n";
|
||||||
$this->body .= "<input type='text' id='$name' name='_config_$name' value='$val' size='4' style='text-align: center;'>\n";
|
|
||||||
$this->body .= "<input type='hidden' name='_type_$name' value='int'>\n";
|
$this->format_option($name, $html, $label, $table_row);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add_shorthand_int_option(string $name, string $label=null)
|
public function add_shorthand_int_option(string $name, string $label=null, bool $table_row = false)
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
$val = to_shorthand_int($config->get_string($name));
|
$val = to_shorthand_int($config->get_string($name));
|
||||||
if (!is_null($label)) {
|
$html = "<input type='text' id='$name' name='_config_$name' value='$val' size='6' style='text-align: center;'>\n";
|
||||||
$this->body .= "<label for='$name'>$label</label>";
|
$html .= "<input type='hidden' name='_type_$name' value='int'>\n";
|
||||||
}
|
|
||||||
$this->body .= "<input type='text' id='$name' name='_config_$name' value='$val' size='6' style='text-align: center;'>\n";
|
$this->format_option($name, $html, $label, $table_row);
|
||||||
$this->body .= "<input type='hidden' name='_type_$name' value='int'>\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add_choice_option(string $name, array $options, string $label=null)
|
public function add_choice_option(string $name, array $options, string $label=null, bool $table_row = false)
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
$current = $config->get_string($name);
|
$current = $config->get_string($name);
|
||||||
|
|
||||||
if (!is_null($label)) {
|
|
||||||
$this->body .= "<label for='$name'>$label</label>";
|
|
||||||
}
|
|
||||||
$html = "<select id='$name' name='_config_$name'>";
|
$html = "<select id='$name' name='_config_$name'>";
|
||||||
foreach ($options as $optname => $optval) {
|
foreach ($options as $optname => $optval) {
|
||||||
if ($optval == $current) {
|
if ($optval == $current) {
|
||||||
@ -154,19 +238,16 @@ class SetupBlock extends Block
|
|||||||
$html .= "<option value='$optval'$selected>$optname</option>\n";
|
$html .= "<option value='$optval'$selected>$optname</option>\n";
|
||||||
}
|
}
|
||||||
$html .= "</select>";
|
$html .= "</select>";
|
||||||
$this->body .= "<input type='hidden' name='_type_$name' value='string'>\n";
|
$html .= "<input type='hidden' name='_type_$name' value='string'>\n";
|
||||||
|
|
||||||
$this->body .= $html;
|
$this->format_option($name, $html, $label, $table_row);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add_multichoice_option(string $name, array $options, string $label=null)
|
public function add_multichoice_option(string $name, array $options, string $label=null, bool $table_row = false)
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
$current = $config->get_array($name);
|
$current = $config->get_array($name);
|
||||||
|
|
||||||
if (!is_null($label)) {
|
|
||||||
$this->body .= "<label for='$name'>$label</label>";
|
|
||||||
}
|
|
||||||
$html = "<select id='$name' name='_config_{$name}[]' multiple size='5'>";
|
$html = "<select id='$name' name='_config_{$name}[]' multiple size='5'>";
|
||||||
foreach ($options as $optname => $optval) {
|
foreach ($options as $optname => $optval) {
|
||||||
if (in_array($optval, $current)) {
|
if (in_array($optval, $current)) {
|
||||||
@ -177,10 +258,10 @@ class SetupBlock extends Block
|
|||||||
$html .= "<option value='$optval'$selected>$optname</option>\n";
|
$html .= "<option value='$optval'$selected>$optname</option>\n";
|
||||||
}
|
}
|
||||||
$html .= "</select>";
|
$html .= "</select>";
|
||||||
$this->body .= "<input type='hidden' name='_type_$name' value='array'>\n";
|
$html .= "<input type='hidden' name='_type_$name' value='array'>\n";
|
||||||
$this->body .= "<!--<br><br><br><br>-->\n"; // setup page auto-layout counts <br> tags
|
$html .= "<!--<br><br><br><br>-->\n"; // setup page auto-layout counts <br> tags
|
||||||
|
|
||||||
$this->body .= $html;
|
$this->format_option($name, $html, $label, $table_row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// }}}
|
// }}}
|
||||||
|
@ -133,16 +133,18 @@ class TranscodeImage extends Extension
|
|||||||
|
|
||||||
|
|
||||||
$sb = new SetupBlock("Image Transcode");
|
$sb = new SetupBlock("Image Transcode");
|
||||||
$sb->add_bool_option("transcode_enabled", "Allow transcoding images: ");
|
$sb->start_table();
|
||||||
$sb->add_bool_option("transcode_upload", "<br>Transcode on upload: ");
|
$sb->add_bool_option(TranscodeConfig::ENABLED, "Allow transcoding images: ", true);
|
||||||
$sb->add_choice_option('transcode_engine', self::CONVERSION_ENGINES, "<br />Transcode engine: ");
|
$sb->add_bool_option(TranscodeConfig::UPLOAD, "Transcode on upload: ", true);
|
||||||
|
$sb->add_choice_option(TranscodeConfig::ENGINE, self::CONVERSION_ENGINES, "Engine", true);
|
||||||
foreach (self::INPUT_FORMATS as $display=>$format) {
|
foreach (self::INPUT_FORMATS as $display=>$format) {
|
||||||
if (in_array($format, self::ENGINE_INPUT_SUPPORT[$engine])) {
|
if (in_array($format, self::ENGINE_INPUT_SUPPORT[$engine])) {
|
||||||
$outputs = $this->get_supported_output_formats($engine, $format);
|
$outputs = $this->get_supported_output_formats($engine, $format);
|
||||||
$sb->add_choice_option('transcode_upload_'.$format, $outputs, "<br />$display to: ");
|
$sb->add_choice_option(TranscodeConfig::UPLOAD_PREFIX.$format, $outputs, "$display", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$sb->add_int_option("transcode_quality", "<br/>Lossy format quality: ");
|
$sb->add_int_option(TranscodeConfig::QUALITY, "Lossy format quality: ");
|
||||||
|
$sb->end_table();
|
||||||
$event->panel->add_block($sb);
|
$event->panel->add_block($sb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user