assets/ID/000/
00/
1 -> ID: 1 -> assets/ID/000/00/1
2 -> ID: 2 -> assets/ID/000/00/2
...
10/
20/
1 -> ID: 21 -> assets/ID/000/20/1
2 -> ID: 22 -> assets/ID/000/20/2
...
...
assets/ID/100/
assets/ID/200/
assets/ID/...
assets/img/ID[[!pathToDocFolder]]
<?php
/* documentResourcePath Snippet */
/* Returns a path string depending on the id of the current resource */
/* Example: 0000/100/20/0/ = 120 */
$docID = $modx->resource->get('id');
$maxDocs = 9999;
$maxKey = count( str_split( $maxDocs ) ) - 1;
$digits = str_split( $docID );
$numberOfDigits = count( $digits );
/* mirrow array */
$digits = array_reverse($digits);
/* add missing key/value pairs to the array */
for( $key=0; $key <= $maxKey ;$key++ ){
if( !array_key_exists( $key, $digits ) ) {
$digits[$key] = "0";
}
}
/* mirrow again */
$digits = array_reverse($digits);
/* add trailing zeros to array values */
foreach( $digits as $key => $value ) {
$suffix = "";
for( $i=$key; $i < $maxKey; $i++ ) {
$suffix .= "0";
}
$digits[$key] = $value.$suffix."/";
}
$docResourcePath = "";
/* combine all values to a path*/
foreach ( $digits as $key => $value ){
$docResourcePath .= $value;
}
return $docResourcePath;
$modx->event->output($modx->toJson($params));
if (!function_exists('processMediaPathes')) {
function processMediaPathes($path)
{
global $modx;
$chunk = $modx->newObject('modChunk');
$chunk->setContent($path);
$chunk->setCacheable(false);
return $chunk->process();
}
}
switch ($modx->event->name) {
case 'OnMediaSourceGetProperties':
$sourceUpdateActionID = 0;
if ($object = $modx->getObject('modAction', array('namespace' => 'core', 'controller' => 'source/update', ))) {
$sourceUpdateActionID = $object->get('id');
}
$params = $modx->fromJson($scriptProperties['properties']);
// don't manpulate-path if updating mediasource
if (empty($params['processPath']) || $_REQUEST['a'] == $sourceUpdateActionID) {
$modx->event->output($scriptProperties['properties']);
return;
}
//$path = $params['basePath']['value'];
//$modx->parser->processElementTags('',$path,true,true);
if (!is_Object($modx->resource)) {
//try to get the actual resource out from HTTP_REFERER
$parsedUrl = parse_url($_SERVER['HTTP_REFERER']);
parse_str($parsedUrl['query'], $parsedQuery);
if (isset($parsedQuery['amp;id'])) {
$parsedQuery['id'] = $parsedQuery['amp;id'];
}
if (isset($parsedQuery['id'])) {
$modx->resource = $modx->getObject('modResource', $parsedQuery['id']);
}
}
$params['basePath']['value'] = processMediaPathes($params['basePath']['value']);
$params['baseUrl']['value'] = processMediaPathes($params['baseUrl']['value']);
$modx->event->output($modx->toJson($params));
$debug['http_referer'] = $_SERVER['HTTP_REFERER'];
$debug['parsedUrl'] = $parsedUrl;
$debug['parsedQuery'] = $parsedQuery;
$debug['basePath'] = $params['basePath']['value'];
$chunk = $modx->getObject('modChunk', array('name' => 'debug'));
$chunk->setContent($chunk->get('snippet') . print_r($debug, 1));
$chunk->save();
break;
}
return;
). In the end I gave up on the whole topic and switched over to other things. 
[[!Executioner?
&tElementClass=`modSnippet`
&tElement=`getResourceField`
&tEcho=`comment`
&id=`27`
&field=`nav248`
&processTV=`1`
&default=`Sorry, no data available`
&docid=`27`
]]
Executioner Snippet
Document: test_mediapath (ID:143)
modSnippet: getResourceField
Execution time:0.5957 s
[[!Executioner?
&tElementClass=`modSnippet`
&tElement=`getResourceField`
&tEcho=`comment`
&id=`27`
&field=`pagetitle`
&default=`Sorry, no data available`
&docid=`27`
]]
Executioner Snippet
Document: test_mediapath (ID:143)
modSnippet: getResourceField
Execution time:0.0053 s