Commit 169df6de authored by Carsten  Rose's avatar Carsten Rose Committed by bbaer
Browse files

Feature 5425 / thumbnail: render mode 7 - implemented

parent d5c17999
......@@ -5840,18 +5840,6 @@ A limited set of attributes is supported: ::
Column: _thumbnail
^^^^^^^^^^^^^^^^^^
+-------+-------------------------------------------------+-------------------------------------------------------------+
| Token | Example | Comment |
+=======+=================================================+=============================================================+
| T | T:fileadmin/file3.pdf | File render a thumbnail |
+-------+-------------------------------------------------+-------------------------------------------------------------+
| W | W:200x, W:x100, W:200x100 | Dimension of the thumbnail: '<width>x<height>. Both |
| | | parameter are otional. If non is given the default is W:150x|
+-------+-------------------------------------------------+-------------------------------------------------------------+
| s | s:1, s:0 | Optional. Default: `s:1`. If SIP is enabled the rendered URL|
| | | is a link via api/download.php. Else a direct pathfilename |
+-------+-------------------------------------------------+-------------------------------------------------------------+
A thumbnail of the file `T:<pathFilename>` will be rendered and saved with the given pixel size as specified via
`W:<dimension>`. The file is only rendered once and will be rerendered, if the source file is newer than the thumbnail
or if the thumbnail dimension changes.
......@@ -5867,6 +5855,35 @@ scaled.
In `config.qfq.ini`_ the exact location of `convert` and `inkscape` can be configured (optional) as well as the directory
names for the cached thumbnails.
+-------+--------------------------------+----------------------------------------------------------------------------+
| Token | Example | Comment |
+=======+================================+============================================================================+
| T | T:fileadmin/file3.pdf | File render a thumbnail |
+-------+--------------------------------+----------------------------------------------------------------------------+
| W | W:200x, W:x100, W:200x100 | Dimension of the thumbnail: '<width>x<height>. Both |
| | | parameter are otional. If non is given the default is W:150x |
+-------+--------------------------------+----------------------------------------------------------------------------+
| s | s:1, s:0 | Optional. Default: `s:1`. If SIP is enabled, the rendered URL |
| | | is a link via `api/download.php?..`. Else a direct pathFilename. |
+-------+--------------------------------+----------------------------------------------------------------------------+
| r | r:7 | Render Mode. Default 'r:0'. With 'r:7' only the url will be delivered. |
+-------+--------------------------------+----------------------------------------------------------------------------+
Example: ::
# SIP protected, IMG tag, thumbnail width 150px
10.sql = SELECT 'T:fileadmin/file3.pdf' AS _thumbnail
# SIP protected, IMG tag, thumbnail width 50px
20.sql = SELECT 'T:fileadmin/file3.pdf|W:50x' AS _thumbnail
# No SIP protection, IMG tag, thumbnail width 150px
30.sql = SELECT 'T:fileadmin/file3.pdf|s:0' AS _thumbnail
# SIP protected, only the URL to the image, thumbnail width 150px
40.sql = SELECT 'T:fileadmin/file3.pdf|s:1|r:7' AS _thumbnail
Dimension
'''''''''
......@@ -5908,151 +5925,7 @@ QFQ returns a HTML 'img'-tag: ::
<img src="{{thumbnailDirPublic:Y}}/<md5 hash>.png">
.. _column_F:
Column: _F
^^^^^^^^^^
Challenge 1
'''''''''''
Due to the limitations of MySQL, reserved column names can't be further concatenated. Assume you want to display an image:
::
# This is valid:
10.sql = SELECT concat("/static/directory/", p.foto) AS _img FROM person AS p WHERE ...
# Returns:
<img src=...>
..
Now assume you want to wrap the image in a div tag:
::
# This is valid:
10.sql = SELECT "<div>", CONCAT("/static/directory/", p.foto) AS _img, "</div>" FROM person AS p WHERE ...
# Returns:
<div><img src=...></div>
..
The example above works fine - however, as soon as you want to use *field wrappers*, things get messy:
::
# This is valid:
10.sql = SELECT "<div>", CONCAT("/static/directory/", p.foto) AS _img, "</div>" FROM person AS p WHERE ...
10.fbeg = <td>
10.fend = </td>
# Returns:
<td><div></td><td><img src=...></td><td></div></td>
..
To achieve the desired result, one might want to try something like this:
::
# This is NOT valid:
10.sql = SELECT CONCAT("<div>", concat("/static/directory/", p.foto) AS _img, "</div>") FROM person AS p WHERE ...
10.fbeg = <td>
10.fend = </td>
# Returns a MySQL error because nesting concat() -functions is not allowed
..
Challenge 2
'''''''''''
Assume you have multiple columns with reserved names in the same query and want to use one of them in a later query:
::
10.sql = SELECT CONCAT("/static/directory/", g.picture) AS _img, CONCAT("/static/preview/", g.thumbnail) AS _img FROM gallery AS g WHERE ...
20.sql = SELECT "{{10.img}}", d.text FROM description AS d ...
..
The example above will fail because there are two img columns which can not be distinguished.
Solution
''''''''
The reserved column 'F'(=Format) can be used to
* further wrap columns with a reserved name
* assign an arbitrary name to a column built through a reserved name to make it accessible in later queries.
Solution for *#Challenge_1*:
::
10.sql = SELECT CONCAT("Q:img|T:div") AS wrappedImg FROM person AS p WHERE ...
10.fbeg = <td>
10.fend = </td>
# Returns:
<td><div><img src=...></div></td>
..
Solution for *#Challenge_2*:
::
10.sql = SELECT CONCAT("Q:img|V:mypic") AS wrappedImg FROM person AS p WHERE ...
20.sql = SELECT "{{10.mypic}}" ...
..
+-------------+--------------------------------------------------------------------+--------+
|**Parameter**|**Description** |Required|
+=============+====================================================================+========+
|Q |Any of the *reserved column names* | |
+-------------+--------------------------------------------------------------------+--------+
|Z |Process the column but don't display it | |
+-------------+--------------------------------------------------------------------+--------+
|X |Strip tags / Remove all tags | |
+-------------+--------------------------------------------------------------------+--------+
|T |Wrap the column with the defined tag. F.e.: T:tdcolspan="2" | |
+-------------+--------------------------------------------------------------------+--------+
|V |Define an unambiguous variable name for this colum. F.e.: V:someName| |
+-------------+--------------------------------------------------------------------+--------+
|* |Add all the parameters required for the column defined with Q: | |
+-------------+--------------------------------------------------------------------+--------+
The above example builds a link to pageB - refer to the :ref:`column-link`-manual for details. The link tells page B to
render the form with name formname and load the record with id id for editing.
Typical
QFQ CSS Classes
---------------
......
......@@ -1302,6 +1302,14 @@ const TOKEN_CLASS_NONE = 'n';
//const TOKEN_CLASS_INTERNAL = 'i';
//const TOKEN_CLASS_EXTERNAL = 'e';
const RENDER_MODE_1 = '1';
const RENDER_MODE_2 = '2';
const RENDER_MODE_3 = '3';
const RENDER_MODE_4 = '4';
const RENDER_MODE_5 = '5';
const RENDER_MODE_6 = '6';
const RENDER_MODE_7 = '7';
const WKHTML_OPTION_VIEWPORT = '--viewport-size';
const WKHTML_OPTION_VIEWPORT_VALUE = '1280x1024';
......
......@@ -1043,7 +1043,8 @@ EOF;
*/
private function doThumbnail(array $vars) {
if (empty($vars[NAME_THUMBNAIL])) {
// Check if there is a thumbnail and if it should be rendered
if (empty($vars[NAME_THUMBNAIL]) || $vars[NAME_RENDER] == RENDER_MODE_7) {
return '';
}
......
......@@ -75,7 +75,7 @@ class Thumbnail {
$pathFilenameThumbnail = $this->doThumbnail($pathFilenameSource, $pathFilenameThumbnail, $control[TOKEN_THUMBNAIL_DIMENSION]);
return $this->buildImageTag($pathFilenameThumbnail, $control[TOKEN_SIP] == "1");
return $this->buildImageTag($pathFilenameThumbnail, $control);
}
/**
......@@ -202,12 +202,18 @@ class Thumbnail {
/**
* @param string $pathFilenameThumbnail
* @param bool $flagSecure
* @param array $control
* @return string
* @internal param bool $flagSecure
*/
private function buildImageTag($pathFilenameThumbnail, $flagSecure) {
private function buildImageTag($pathFilenameThumbnail, array $control) {
$src = $flagSecure ? $this->buildDownloadLink($pathFilenameThumbnail) : $pathFilenameThumbnail;
$src = ($control[TOKEN_SIP] == "1") ? $this->buildDownloadLink($pathFilenameThumbnail) : $pathFilenameThumbnail;
// With RENDER_MODE_7 return only the URL
if (isset($control[TOKEN_RENDER]) && $control[TOKEN_RENDER] == RENDER_MODE_7) {
return $src;
}
$attribute = Support::doAttribute('src', $src);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment