From 7c61b97986f17411271a1658aa9e68973f099b39 Mon Sep 17 00:00:00 2001 From: Eddie Kohler Date: Fri, 25 Oct 2024 13:58:03 -0400 Subject: [PATCH] Prefer `content` for page component content Rather than `html_content`. --- devel/manual/fmt.md | 4 ++-- devel/manual/pages.md | 31 ++++++++++++++++++++----------- src/componentset.php | 4 +++- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/devel/manual/fmt.md b/devel/manual/fmt.md index db18f76e23..9f5065fec8 100644 --- a/devel/manual/fmt.md +++ b/devel/manual/fmt.md @@ -14,7 +14,7 @@ nonnegative integer. The languages defined so far are: The `Ftext` class can convert between some formats. -(Note that open-source HotCRP ships without Markdown support.) +(Open-source HotCRP ships without Markdown support.) ## Ftext @@ -297,7 +297,7 @@ HotCRP understands the following format specifications. | Format specification | Result | |:--------------------------|:-----------------------------------------------------| | `:url` | The string argument is urlencoded. | -| `:html` | The string argument is HTML-encoded; i.e., `&<>"'` are replaced by HTML entities. | +| `:html` | The string argument is HTML-encoded: `&<>"'` are replaced by HTML entities. | | `:ftext` | When possible, the string argument is incorporated as an ftext, rather than having its format translated or stripped. | | `:humanize_url` | If the argument string is a simple url, such as `https://hotcrp.com/privacy`, it is replaced by a shorter version, such as `hotcrp.com/privacy`. | | `:.2f`, etc. | The numeric argument is rendered using a printf-style specification. | diff --git a/devel/manual/pages.md b/devel/manual/pages.md index a49b978493..2e9e5acc8c 100644 --- a/devel/manual/pages.md +++ b/devel/manual/pages.md @@ -59,26 +59,34 @@ and terminates request processing. A `request_function` may also throw a value of type `Redirection` to force HotCRP to redirect the user’s browser to another URI. -## Rendering the result +## Printing the result Assuming the `request_function`s do not throw a redirection, HotCRP next re-scans the component list and prints the corresponding components. -To print a component, HotCRP checks for: +Many HotCRP pages do not have separate `request_function`s, instead handling +all request parsing as part of the first `print_function` for a page. -1. A `print_function` property. If present, this calls the corresponding PHP - callback, using the same syntax and arguments as `request_function`, above. +To print a component, HotCRP: -2. Otherwise, an `html_content` property. If present, this is copied to the output. +1. First, HotCRP prints the component itself, by looking for a + `print_function` or `content` property. -3. In either case, if the component has a `print_members` property, HotCRP - next prints the members of the group with the component’s name. + * If `print_function` is present, HotCRP calls the corresponding PHP + callback to print the component. The `print_function` property uses the + same syntax as `request_function`, and the callback takes the same + arguments. -A `print_function` may cancel further rendering by returning explicit `false`, -or by throwing a `Redirection` or `PageCompletion` exception. + A `print_function` may cancel further rendering by returning explicit + `false`, or by throwing a `Redirection` or `PageCompletion` exception. -Many HotCRP pages do not have separate `request_function`s, instead handling -all request parsing as part of the first `print_function` for a page. + * Otherwise, if `content` is present, HotCRP prints that content. This + property is an [ftext string][ftext]. + + * Otherwise, HotCRP prints nothing for the component itself. + +2. Second, if the component has a `print_members` property, HotCRP recursively + prints the members of the group with the component’s name. ## Shorthand @@ -108,3 +116,4 @@ components support conditions relating to the current request. [components]: ./components.md +[ftext]: ./fmt.md diff --git a/src/componentset.php b/src/componentset.php index 4c05654463..8ea926f8ca 100644 --- a/src/componentset.php +++ b/src/componentset.php @@ -518,8 +518,10 @@ private function _print_body($gj, $print_members) { $result = null; if (isset($gj->print_function)) { $result = $this->call_function($gj, $gj->print_function, $gj); + } else if (isset($gj->content)) { + echo Ftext::as(5, $gj->content, 0); } else if (isset($gj->html_content)) { - echo $gj->html_content; + echo $gj->html_content; /* XXX backward compat */ } if (isset($gj->print_members)) { $print_members = $gj->print_members;