Skip to content

Commit 4d09680

Browse files
committed
The component can now work without pdoTools
1 parent a5d4b64 commit 4d09680

13 files changed

Lines changed: 154 additions & 42 deletions

File tree

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Auto detect text files and perform LF normalization
2-
* text=auto
2+
* text=auto eol=lf

_build/elements/chunks.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22

33
return [
44
'tpl.FileMan.Files' => array(
5-
'file' => 'files',
6-
'description' => '',
7-
)
5+
'file' => 'files',
6+
'description' => 'Chunk using the Fenom template engine.',
7+
),
8+
'tpl.FileMan.Group' => array(
9+
'file' => 'group',
10+
'description' => '',
11+
),
12+
'tpl.FileMan.Row' => array(
13+
'file' => 'row',
14+
'description' => '',
15+
)
816
];

_build/elements/settings.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,9 @@
4141
'value' => 'id,name,title,description,group,private,download',
4242
'area' => 'fileman_main',
4343
),
44+
'pdotools' => array(
45+
'xtype' => 'combo-boolean',
46+
'value' => true,
47+
'area' => 'fileman_main',
48+
)
4449
];

_build/elements/snippets.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@
99
'type' => 'textfield',
1010
'value' => 'tpl.FileMan.Files',
1111
),
12+
'tplRow' => array(
13+
'type' => 'textfield',
14+
'value' => 'tpl.FileMan.Row',
15+
),
16+
'tplGroup' => array(
17+
'type' => 'textfield',
18+
'value' => 'tpl.FileMan.Group',
19+
),
20+
'tplWrapper' => array(
21+
'type' => 'textfield',
22+
'value' => '',
23+
),
24+
'wrapIfEmpty' => array(
25+
'type' => 'combo-boolean',
26+
'value' => false,
27+
),
1228
'sortBy' => array(
1329
'type' => 'textfield',
1430
'value' => 'sort_order',

_build/resolvers/_setup.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212

1313
$modx = $transport->xpdo;
1414
$packages = [
15-
'Ace' => [
15+
/*'Ace' => [
1616
'version' => '1.9.3-pl',
1717
'service_url' => 'modstore.pro',
1818
],
1919
'pdoTools' => [
2020
'version' => '3.0.0-beta',
2121
'service_url' => 'modstore.pro',
22-
],
22+
],*/
2323
];
2424

2525
$downloadPackage = function ($src, $dst) {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[[+group:notempty=`<h2>[[+group]]</h2>`]]
2+
[[+output]]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<p>
2+
<a href="[[+url]]" download>[[+title:default=`[[+name]]`]]</a>
3+
[[+description:notempty=`<br /><small>[[+description]]</small>`]]
4+
</p>

core/components/fileman/elements/snippets/files.php

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,25 @@
22

33
use FileMan\FileMan;
44
use FileMan\Model\File;
5+
use MODX\Revolution\modX;
6+
use MODX\Revolution\Sources\modMediaSource;
57

68
/** @var array $scriptProperties */
9+
/** @var modX $modx */
710
/** @var FileMan $fileMan */
811
$fileMan = $modx->services->get('FileMan');
912

10-
// Get script options
13+
// Fenom tpl
1114
$tpl = $modx->getOption('tpl', $scriptProperties, 'tpl.FileMan.Files');
15+
// MODX tpls
16+
$tplWrapper = $modx->getOption('tplWrapper', $scriptProperties, '');
17+
$tplGroup = $modx->getOption('tplGroup', $scriptProperties, 'tpl.FileMan.Group');
18+
$tplRow = $modx->getOption('tplRow', $scriptProperties, 'tpl.FileMan.Row');
19+
$wrapIfEmpty = $modx->getOption('wrapIfEmpty', $scriptProperties, false);
20+
21+
$usePdoTools = $fileMan->pdoToolsAvailable()
22+
? $modx->getOption('fileman_pdotools', $scriptProperties, true)
23+
: false;
1224

1325
$sortby = $modx->getOption('sortBy', $scriptProperties, 'sort_order');
1426
$sortdir = $modx->getOption('sortDir', $scriptProperties, 'ASC');
@@ -20,17 +32,18 @@
2032

2133
$ids = $modx->getOption('ids', $scriptProperties, '');
2234
$resource = $modx->getOption('resource', $scriptProperties, 0);
23-
$showGroups = $modx->getOption('showGroups', $scriptProperties, 1);
35+
$showGroups = $modx->getOption('showGroups', $scriptProperties, true);
2436
$makeUrl = $modx->getOption('makeUrl', $scriptProperties, true);
2537
$private = $modx->getOption('private', $scriptProperties, false);
2638
$includeTimeStamp = $modx->getOption('includeTimeStamp', $scriptProperties, false);
2739

40+
$outputSeparator = $modx->getOption('outputSeparator', $scriptProperties, "\n");
2841

29-
//
3042
$mediaSource = $modx->getOption('fileman_mediasource', null, 1);
31-
$ms = $modx->getObject('sources.modMediaSource', array('id' => $mediaSource));
32-
$ms->initialize();
33-
$public_url = $ms->getBaseUrl();
43+
/** @var modMediaSource $mediaSource */
44+
$mediaSource = $modx->getObject(modMediaSource::class, array('id' => $mediaSource));
45+
$mediaSource->initialize();
46+
$public_url = $mediaSource->getBaseUrl();
3447
$private_url = $modx->getOption('fileman_assets_url', null, $modx->getOption('assets_url')) . 'components/fileman/';
3548
$private_url .= 'download.php?fid=';
3649

@@ -45,7 +58,7 @@
4558
// ids
4659
$ids = explode(',', $ids);
4760
$ids = array_filter(array_map('trim', $ids));
48-
if(!empty($ids)) {
61+
if (!empty($ids)) {
4962
$ids = array_map('intval', $ids);
5063
$c->where(['id:IN' => $ids]);
5164
}
@@ -63,34 +76,72 @@
6376
$items = $modx->getIterator(File::class, $c);
6477

6578
$outputData = [];
79+
$groupOutputData = [];
80+
$curGroup = '';
81+
$itemsCount = iterator_count($items);
82+
$index = 0;
6683

6784
/** @var File $item */
6885
foreach ($items as $item) {
69-
$item->source = $ms;
70-
86+
$item->source = $mediaSource;
7187
$itemArr = $item->toArray();
7288

7389
if ($makeUrl) {
7490
if ($itemArr['private'] || $private) {
7591
$itemArr['url'] = $private_url . $itemArr['fid'];
76-
}
77-
else {
92+
} else {
7893
$itemArr['url'] = $public_url . $itemArr['path'] . $itemArr['internal_name'];
7994
}
8095
}
8196

97+
if (!$showGroups) {
98+
$itemArr['group'] = false;
99+
}
100+
82101
if ($includeTimeStamp) {
83102
$itemArr['timestamp'] = filectime($item->getFullPath());
84103
}
85104

86-
$outputData[] = $itemArr;
105+
if ($usePdoTools) {
106+
$outputData[] = $itemArr;
107+
} else {
108+
// Checking if we need to start a new group...
109+
if ($curGroup != $itemArr['group']) {
110+
if (count($groupOutputData) > 0) {
111+
$outputData[] = $fileMan->getChunk($tplGroup, [
112+
'group' => $curGroup,
113+
'output' => implode($outputSeparator, $groupOutputData)
114+
]);
115+
$groupOutputData = [];
116+
}
117+
$curGroup = $itemArr['group'];
118+
}
119+
$groupOutputData[] = $fileMan->getChunk($tplRow, $itemArr);
120+
121+
$index++;
122+
123+
// ..or is this the last iteration
124+
if ($index === $itemsCount) {
125+
$outputData[] = $fileMan->getChunk($tplGroup, [
126+
'group' => $curGroup,
127+
'output' => implode($outputSeparator, $groupOutputData)
128+
]);
129+
}
130+
}
87131
}
88132

89133
// Output
90-
$output = $fileMan->getChunk($tpl, ['files' => $outputData]);
134+
if ($usePdoTools) {
135+
$output = $fileMan->getChunk($tpl, ['files' => $outputData]);
136+
} else {
137+
$output = implode($outputSeparator, $outputData);
138+
if (!empty($tplWrapper) && $wrapIfEmpty) {
139+
$output = $fileMan->getChunk($tplWrapper, ['output' => $output]);
140+
}
141+
}
91142

143+
// If using a toPlaceholder, output nothing and set output to specified placeholder
92144
if (!empty($toPlaceholder)) {
93-
// If using a placeholder, output nothing and set output to specified placeholder
94145
$modx->setPlaceholder($toPlaceholder, $output);
95146
return '';
96147
}

core/components/fileman/lexicon/en/properties.inc.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
22

3-
$_lang['fileman_prop_tpl'] = 'File list design chunk';
3+
$_lang['fileman_prop_tpl'] = 'Main chunk if the "fileman_pdotools" setting is enabled';
4+
$_lang['fileman_prop_tplRow'] = 'Chunk for one row (if the "fileman_pdotools" setting is disabled)';
5+
$_lang['fileman_prop_tplGroup'] = 'Chunk for group (if the "fileman_pdotools" setting is disabled)';
6+
$_lang['fileman_prop_tplWrapper'] = 'Chunk - wrapper, to wrap all results (if the "fileman_pdotools" setting is disabled)';
47
$_lang['fileman_prop_sortBy'] = 'Sort field';
58
$_lang['fileman_prop_sortDir'] = 'Sort direction';
69
$_lang['fileman_prop_limit'] = 'Limit the number of results';

core/components/fileman/lexicon/en/setting.inc.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@
2525

2626
$_lang['setting_fileman_grid_fields'] = 'Fields in the grid';
2727
$_lang['setting_fileman_grid_fields_desc'] = 'Fields, separated by commas, that will be displayed in the list of files.';
28+
29+
$_lang['setting_fileman_pdotools'] = 'Use the pdoTools parser and the Fenom template engine';
30+
$_lang['setting_fileman_pdotools_desc'] = 'If pdoTools installed, the fmFiles snippet uses the single chunk specified in the tpl parameter, otherwise the chunks specified in the tplRow, tplGroup, tplWrapper parameters.';

0 commit comments

Comments
 (0)