Skip to content

Commit

Permalink
Add 'plain' decoration for 'title' column.
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Jul 25, 2023
1 parent f94b23c commit 124fa5e
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 15 deletions.
47 changes: 43 additions & 4 deletions lib/column.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,35 @@ function decorations() {
return $this->decorations ?? [];
}

/** @param string $decor
* @return int|false */
function decoration_index($decor) {
$l = strlen($decor);
foreach ($this->decorations ?? [] as $i => $s) {
if (str_starts_with($s, $decor)
&& (strlen($s) === $l || $s[$l] === "=")) {
return $i;
}
}
return false;
}

/** @return bool */
function has_decoration($decor) {
return $this->decoration_index($decor) !== false;
}

/** @return ?string */
function decoration_value($decor) {
if (($i = $this->decoration_index($decor)) !== false) {
$s = $this->decorations[$i];
$l = strlen($decor);
return strlen($s) === $l ? "" : substr($s, $l + 1);
} else {
return null;
}
}

/** @param string $decor
* @return bool */
function add_decoration($decor) {
Expand Down Expand Up @@ -130,11 +159,21 @@ function sort_decoration() {
* @param ?list<string> $remove
* @return true */
protected function __add_decoration($add, $remove = []) {
if (!empty($remove)) {
$this->decorations = array_values(array_diff($this->decorations ?? [], $remove));
foreach ($remove as $s) {
if (($i = $this->decoration_index($s)) !== false) {
array_splice($this->decorations, $i, 1);
}
}
if ($add !== null && $add !== "" && !in_array($add, $this->decorations ?? [])) {
$this->decorations[] = $add;
if ($add !== null && $add !== "") {
$addx = $add;
if (($eq = strpos($add, "=")) !== false) {
$addx = substr($add, 0, $eq);
}
if (($i = $this->decoration_index($addx)) !== false) {
$this->decorations[$i] = $add;
} else {
$this->decorations[] = $add;
}
}
return true;
}
Expand Down
36 changes: 25 additions & 11 deletions src/papercolumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,28 @@ function text(PaperList $pl, PaperInfo $row) {
}

class Title_PaperColumn extends PaperColumn {
private $has_decoration = false;
/** @var bool */
private $want_decoration = true;
/** @var bool */
private $want_pdf = true;
/** @var bool */
private $highlight = false;
function __construct(Conf $conf, $cj) {
parent::__construct($conf, $cj);
}
function add_decoration($decor) {
if ($decor === "plain" || $decor === "bare") {
$this->want_decoration = $this->want_pdf = false;
return $this->__add_decoration("plain");
} else {
return parent::add_decoration($decor);
}
}
function prepare(PaperList $pl, $visible) {
$this->has_decoration = $pl->user->can_view_tags(null)
$this->want_decoration = $this->want_decoration
&& $pl->user->can_view_tags(null)
&& $pl->conf->tags()->has_decoration;
if ($this->has_decoration) {
if ($this->want_decoration) {
$pl->qopts["tags"] = 1;
}
$this->highlight = $pl->search->field_highlighter("ti");
Expand All @@ -234,8 +247,6 @@ function compare(PaperInfo $a, PaperInfo $b, PaperList $pl) {
return $collator->compare($a->title, $b->title);
}
function content(PaperList $pl, PaperInfo $row) {
$t = '<a href="' . $pl->_paperLink($row) . '" class="ptitle taghl';

if ($row->title !== "") {
$highlight_text = Text::highlight($row->title, $this->highlight, $highlight_count);
} else {
Expand All @@ -246,16 +257,19 @@ function content(PaperList $pl, PaperInfo $row) {
if (!$highlight_count && ($format = $row->title_format())) {
$pl->need_render = true;
$th = htmlspecialchars($row->title);
$t .= " need-format\" data-format=\"{$format}\" data-title=\"{$th}";
$klass_extra = " need-format\" data-format=\"{$format}\" data-title=\"{$th}";
} else {
$klass_extra = "";
}

$t .= '">' . $highlight_text . '</a>'
. $pl->_contentDownload($row);

if ($this->has_decoration && (string) $row->paperTags !== "") {
$link = $pl->_paperLink($row);
$t = "<a href=\"{$link}\" class=\"ptitle taghl{$klass_extra}\">{$highlight_text}</a>";
if ($this->want_pdf) {
$t .= $pl->_contentDownload($row);
}
if ($this->want_decoration && (string) $row->paperTags !== "") {
$t .= $row->decoration_html($pl->user, $pl->row_tags, $pl->row_tags_override);
}

return $t;
}
function text(PaperList $pl, PaperInfo $row) {
Expand Down

0 comments on commit 124fa5e

Please sign in to comment.