Skip to content

Commit

Permalink
Support show:DOCUMENTOPTION[type] to see MIME types.
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Sep 7, 2023
1 parent d58ecfa commit b4c2d51
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
10 changes: 10 additions & 0 deletions src/fieldrender.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class FieldRender {
/** @var ?PaperTable
* @readonly */
public $table;
/** @var ?PaperColumn
* @readonly */
public $column;
/** @var int
* @readonly */
public $context;
Expand Down Expand Up @@ -53,6 +56,13 @@ function make_table($table) {
$this->table = $table;
return $this;
}
/** @param PaperColumn $column
* @return $this
* @suppress PhanAccessReadOnlyProperty */
function make_column($column) {
$this->column = $column;
return $this;
}

function clear() {
$this->title = null;
Expand Down
12 changes: 10 additions & 2 deletions src/options/o_attachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,20 @@ function print_web_edit(PaperTable $pt, $ov, $reqov) {
}

function render(FieldRender $fr, PaperValue $ov) {
$want_mimetype = $fr->column && $fr->column->has_decoration("type");
$ts = [];
foreach ($ov->document_set() as $d) {
if ($want_mimetype) {
$t = $d->mimetype;
} else {
$t = $d->member_filename();
}
if ($fr->want(FieldRender::CFTEXT)) {
$ts[] = $d->member_filename();
$ts[] = $t;
} else if ($want_mimetype) {
$ts[] = htmlspecialchars($t);
} else {
$linkname = htmlspecialchars($d->member_filename());
$linkname = htmlspecialchars($t);
$dif = 0;
if ($fr->want(FieldRender::CFLIST)) {
$dif = DocumentInfo::L_SMALL | DocumentInfo::L_NOSIZE;
Expand Down
6 changes: 6 additions & 0 deletions src/papercolumns/pc_option.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ function __construct(Conf $conf, $cj) {
$this->override = PaperColumn::OVERRIDE_IFEMPTY;
$this->opt = $conf->checked_option_by_id($cj->option_id);
}
function add_decoration($decor) {
/* XXX ask PaperOption what decorations are supported */
return parent::add_decoration($decor)
|| $this->__add_decoration($decor);
}
function prepare(PaperList $pl, $visible) {
if (!$pl->user->can_view_some_option($this->opt)) {
return false;
}
$pl->qopts["options"] = true;
$this->fr = new FieldRender($pl->render_context | ($this->as_row ? FieldRender::CFROW : FieldRender::CFCOLUMN), $pl->user);
$this->fr->make_column($this);
if ($this->as_row) {
$this->className = ltrim(preg_replace('/(?: +|\A)(?:plrd|plr|plc)(?= |\z)/', "", $this->className));
}
Expand Down
21 changes: 13 additions & 8 deletions src/paperoption.php
Original file line number Diff line number Diff line change
Expand Up @@ -1546,23 +1546,28 @@ static function render_document(FieldRender $fr, PaperOption $opt, $d) {
}
return;
}

if ($fr->want(FieldRender::CFTEXT)) {
$fr->set_text($d->export_filename());
} else if ($fr->want(FieldRender::CFFORM)) {
if ($fr->want(FieldRender::CFFORM)) {
$fr->set_html($d->link_html(htmlspecialchars($d->filename), 0));
} else if ($fr->want(FieldRender::CFPAGE)) {
$th = $opt->title_html();
$dif = $opt->display() === PaperOption::DISP_TOP ? 0 : DocumentInfo::L_SMALL;
$fr->title = "";
$fr->set_html($d->link_html("<span class=\"pavfn\">{$th}</span>", $dif));
} else {
if ($fr->verbose() || $fr->want(FieldRender::CFLIST | FieldRender::CFROW)) {
$th = $d->export_filename();
$want_mimetype = $fr->column && $fr->column->has_decoration("type");
if ($want_mimetype) {
$t = $d->mimetype;
} else if (!$fr->want(FieldRender::CFLIST | FieldRender::CFCOLUMN)
|| $fr->verbose()) {
$t = $d->export_filename();
} else {
$t = "";
}
if ($fr->want(FieldRender::CFTEXT) || $want_mimetype) {
$fr->set_text($t);
} else {
$th = "";
$fr->set_html($d->link_html(htmlspecialchars($t), DocumentInfo::L_SMALL | DocumentInfo::L_NOSIZE));
}
$fr->set_html($d->link_html($th, DocumentInfo::L_SMALL | DocumentInfo::L_NOSIZE));
}
}

Expand Down

0 comments on commit b4c2d51

Please sign in to comment.