From cce0e54a54f932d68ce82babbecce59d6a62fb50 Mon Sep 17 00:00:00 2001 From: oleg Date: Tue, 2 Feb 2021 01:39:14 +0300 Subject: [PATCH 1/2] Added: support template engine Fenom (package pdoTools) --- _build/data/transport.chunks.php | 4 ++++ .../elements/chunks/chunk.item_fenom.tpl | 7 +++++++ .../elements/snippets/snippet.fileattach.php | 2 +- .../model/fileattach/fileattach.class.php | 19 ++++++++++++++++++- 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 core/components/fileattach/elements/chunks/chunk.item_fenom.tpl diff --git a/_build/data/transport.chunks.php b/_build/data/transport.chunks.php index f334b85..28ea836 100644 --- a/_build/data/transport.chunks.php +++ b/_build/data/transport.chunks.php @@ -7,6 +7,10 @@ 'file' => 'item', 'description' => '', ), + 'FileAttachFenomTpl' => array( + 'file' => 'item_fenom', + 'description' => 'Пример оформления чанка с помощью шаблонизатора Fenom' + ), ); // Save chunks for setup options diff --git a/core/components/fileattach/elements/chunks/chunk.item_fenom.tpl b/core/components/fileattach/elements/chunks/chunk.item_fenom.tpl new file mode 100644 index 0000000..9d1e6dc --- /dev/null +++ b/core/components/fileattach/elements/chunks/chunk.item_fenom.tpl @@ -0,0 +1,7 @@ +

{$description ? '' ~ $description ~ '
' : null} + {$name} {$download} + {$size ? '
Size:' ~ $size ~ 'bytes ' : null} + {$ext ? '
Size:' ~ $ext ~ '' : null} + {$timestamp ? '
Size:' ~ $timestamp ~ '' : null} + {$hash ? '
Size:' ~ $hash ~ '' : null} +

diff --git a/core/components/fileattach/elements/snippets/snippet.fileattach.php b/core/components/fileattach/elements/snippets/snippet.fileattach.php index 81c4d76..7bd151f 100644 --- a/core/components/fileattach/elements/snippets/snippet.fileattach.php +++ b/core/components/fileattach/elements/snippets/snippet.fileattach.php @@ -139,7 +139,7 @@ if (($ext != '') && ($ext != $itemArr['ext'])) continue; } - $list[] = $modx->getChunk($tpl, $itemArr); + $list[] = $FileAttach->pdoTools->getChunk($tpl, $itemArr); } // Output diff --git a/core/components/fileattach/model/fileattach/fileattach.class.php b/core/components/fileattach/model/fileattach/fileattach.class.php index 2e1f5b5..e8567f1 100644 --- a/core/components/fileattach/model/fileattach/fileattach.class.php +++ b/core/components/fileattach/model/fileattach/fileattach.class.php @@ -29,11 +29,18 @@ class FileAttach { /* @var modX $modx */ public $modx; + /** @var array $config */ + public $config = array(); + + /** @var pdoFetch $pdoTools */ + public $pdoTools = null; + /** * @param modX $modx * @param array $config */ function __construct(modX &$modx, array $config = array()) { + $this->modx =& $modx; $corePath = $this->modx->getOption('fileattach.core_path', $config, $this->modx->getOption('core_path') . 'components/fileattach/'); @@ -56,5 +63,15 @@ function __construct(modX &$modx, array $config = array()) { $this->modx->addPackage('fileattach', $this->config['modelPath']); $this->modx->lexicon->load('fileattach:default'); - } + $this->pdoTools = $this->modx->getService('pdoTools'); + + $fqn = $this->modx->getOption('pdoTools.class', null, 'pdotools.pdotools', true); + $path = $this->modx->getOption('pdofetch_class_path', null, MODX_CORE_PATH . 'components/pdotools/model/', true); + + if($pdoClass = $modx->loadClass($fqn, $path, false, true)) { + $this->pdoTools = new $pdoClass($modx, $config); + } else { + $this->pdoTools =& $modx; + } + } } \ No newline at end of file From 6dd77e7164b6cee6a4fbb129d8eec49187e4eb2f Mon Sep 17 00:00:00 2001 From: oleg Date: Mon, 8 Feb 2021 01:55:34 +0300 Subject: [PATCH 2/2] Improved: support template engine Fenom (package pdoTools) --- .../elements/snippets/snippet.fileattach.php | 7 ++++++- .../fileattach/model/fileattach/fileattach.class.php | 11 ++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/core/components/fileattach/elements/snippets/snippet.fileattach.php b/core/components/fileattach/elements/snippets/snippet.fileattach.php index 7bd151f..a60750f 100644 --- a/core/components/fileattach/elements/snippets/snippet.fileattach.php +++ b/core/components/fileattach/elements/snippets/snippet.fileattach.php @@ -139,7 +139,12 @@ if (($ext != '') && ($ext != $itemArr['ext'])) continue; } - $list[] = $FileAttach->pdoTools->getChunk($tpl, $itemArr); + /** @var pdoTools $pdo */ + if (class_exists('pdoTools')) { + $list[] = $FileAttach->pdoTools->getChunk($tpl, $itemArr); + } else { + $list[] = $modx->getChunk($tpl, $itemArr); + } } // Output diff --git a/core/components/fileattach/model/fileattach/fileattach.class.php b/core/components/fileattach/model/fileattach/fileattach.class.php index e8567f1..fa1e0c6 100644 --- a/core/components/fileattach/model/fileattach/fileattach.class.php +++ b/core/components/fileattach/model/fileattach/fileattach.class.php @@ -40,7 +40,6 @@ class FileAttach { * @param array $config */ function __construct(modX &$modx, array $config = array()) { - $this->modx =& $modx; $corePath = $this->modx->getOption('fileattach.core_path', $config, $this->modx->getOption('core_path') . 'components/fileattach/'); @@ -63,15 +62,9 @@ function __construct(modX &$modx, array $config = array()) { $this->modx->addPackage('fileattach', $this->config['modelPath']); $this->modx->lexicon->load('fileattach:default'); - $this->pdoTools = $this->modx->getService('pdoTools'); - - $fqn = $this->modx->getOption('pdoTools.class', null, 'pdotools.pdotools', true); - $path = $this->modx->getOption('pdofetch_class_path', null, MODX_CORE_PATH . 'components/pdotools/model/', true); - if($pdoClass = $modx->loadClass($fqn, $path, false, true)) { - $this->pdoTools = new $pdoClass($modx, $config); - } else { - $this->pdoTools =& $modx; + if (class_exists('pdoTools') && !is_object($this->pdoTools)) { + $this->pdoTools = $this->modx->getService('pdoTools'); } } } \ No newline at end of file