We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29635
    • 361 Posts
    Hello all.
    Wondering if somebody could get me started on the right path with this. I’m trying to get uploaded TV images to go into specific folders based on the date and/or ID of the document. So when a manager user clicks on "Insert" and launches the resource browser, it’d open to /assets/images/2007/02/05/ or /assets/images/182 (if the doc ID was 182) for them to upload the image.

    I’m having some difficulty putting the pieces together. My approach so far (which isn’t working):
    // <?php
    global $content;
    $template = $content['template'];
    $output = 'test :: ';
    
    // Play with the rb_base_dir value
    $dir = $modx->config['rb_base_dir'];
    $id = $modx->event->params['id'];
    $modx->config['rb_base_dir'] = $dir . $id . '/';
    $dirNew = $modx->config['rb_base_dir'];
    
    $e = &$modx->Event;
    if (($e->name == 'OnDocFormRender') && ($template > 0)) {
        // Include the JQuery call
        $output .= $dirNew ;
    }
    
    $e->output($output);
    // ?>


    This doesn’t seem to effect the path I get in the resource browser when I click "Insert" though... Not sure if I’m not actually affecting the rb_base_dir value, or if the resource browser is pulling the value from somewhere else.

    Anybody have an idea of how to make this work? I’ve been kicking this around for a while but haven’t had any luck.
    Thanks for any help.
      Need MODx Ecommerce? Try FoxyCart!
      • 29635
      • 361 Posts
      Anybody have any thoughts on this? The best I’ve figured so far is changing the actual rb_base_dir via a cron or something on a daily basis, but that wouldn’t allow anything based on the document ID.

      I’ve also realized that basing an upload path on the doc ID might be impossible for new not-yet-saved documents, as they don’t have an ID at that point.

      Any ideas? I could definitely use some help from somebody smarter than me wink
        Need MODx Ecommerce? Try FoxyCart!
        • 30223
        • 1,010 Posts
        I’ve just had a fairly thorough look at this and as far as I can see what you are trying to achieve is not possible without making some significant changes to some of the files of the resource browser itself.

        With your plugin you are trying to set the $modx->config[’rb_base_dir’]. The problem however is that this is only valid in the current instance of $modx. When the resource browser opens a new document parser is opened and thus a fresh new rb_base_dir is fteched from the settings database table. The only way I could see something like this working is if you change the rb_base_dir setting in the database itself (and reset it afterwards), however this could have major implications, especially if you have more then one editor working simultaneously.

        There is another complicating factor in that the resource browser adds the "image" (or files or media) subdirectory to this path itself. So even if you manage to set the rb_base_dir a directory like /assets/images/182 would not be possible, instead you would need to create a directory like /assets/images/[doc_id]/images (or /assets/[doc_id]/images)

        Oh yes,... as far as your offer is concerned. Drop some coins in this piggy bank. Won’t help me but it will help MODx
          • 29635
          • 361 Posts
          Thanks for taking a look at it. Kind of what I had figured.
          Going to see about either some cron job magic on the database value itself (though that’s probably not going to work with all the extra /images/ /files/ etc. stuff), or ... a major hack job on the resource browser... haha, ugly!...

          (That’s the best piggy bank of all. Already a regular contributor wink
            Need MODx Ecommerce? Try FoxyCart!