We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17698
    • 19 Posts
    On an old site that we are currently upgrading to the current version, we have about 35 reps around the world. They each have their own segmented portion of the site (tree_root_id), and their own folders to store images and documents. The folders were pretty easy to deal with in pre-2.2 versions with the now deprecated filemanager_path and filemanager_url. However, I can't seem to figure out how to accomplish the same thing in 2.2.7 without also creating a user group for each and every user. There has got to be a better way.

    The documentation for media sources only covers the most basic use cases. I've tried setting base_path & base_url and baseURL & basePath in the User Settings, but this had no effect or would break the media source all together. Perhaps it is one of these, but I'm messing up a parameter, which is causing it to fail.

    It seems like there should be a simple solution to this like the previous filemanager_path and filemanager_url, considering this has been out there for a year.

    Does anyone have a suggestion/solution? I've search for hours in the forum, and looked through the entire Media Source documentation... twice, but am not coming up with much.

    Thanks,

    Erik [ed. note: lutenegger last edited this post 13 years, 5 months ago.]
      Erik Lutenegger
      Founder | Tenacity
      • 17698
      • 19 Posts
      It's been about a week now, so resigned myself to the fact that there wasn't an easy way to do what I'm asking. Or at least not one that anyone knows about.

      So I went about more searching and found this Feature Request
      http://tracker.modx.com/issues/6507

      I tried that plugin code, as is, and it didn't work for me, but using that I wrote the following plugin that is called on the event 'OnMediaSourceGetProperties'.

      <?php
      	$username = $modx->getUser()->get('username');
      	$params=$modx->fromJson($scriptProperties['properties']);
      	if($modx->user->isMember('Users')){
      		$params['basePath']['value']='users/'.$username.'/';
      	 	$params['baseUrl']['value']='users/'.$username.'/';
      	}
      	$modx->event->output($modx->toJson($params));
      


      For every user in the 'Users' group, this swaps their media source basePath and baseUrl to the a folder structure users/username. I tried a bunch of different iterations, but this is the only one that worked the way I expected it to, without causing other issues/errors.

      I understand why filemanager_path and filemanager_url were deprecated, but am pretty confused why something similar wasn't added (or perhaps documented) to complete the same task. Hopefully, this will be addressed in the future. For now, there's this. Not ideal, but relatively simple.

      Thanks, Bruno17 https://forums.modx.com/u/Bruno17 for getting me most of the way. [ed. note: lutenegger last edited this post 13 years, 4 months ago.]
        Erik Lutenegger
        Founder | Tenacity
        • 4172
        • 5,888 Posts
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 17698
          • 19 Posts
          Great, where were you a week ago? I like that option since it doesn't override the security model. This capability should probably be added to the documentation for Media Sources.

          For those that need help with this kind of thing, here is the snippet code example.
          <?php
          	$username = $modx->getUser()->get('username');
          	$newbase='users/'.$username.'/';
          	return $newbase;
          


          Then follow the documentation for adding a new media source and use your snippet in BaseURL and BasePath
          http://rtfm.modx.com/display/revolution20/Adding+a+Media+Source

          Bruno17, Do you know whether there is a way to change a setting for an entire user group? Like you can for an individual user? I'm looking to change the default_media_source, but have about 50 users in 3 groups to manage. [ed. note: lutenegger last edited this post 13 years, 4 months ago.]
            Erik Lutenegger
            Founder | Tenacity
            • 4172
            • 5,888 Posts
            do you want to change them only once?

            you are looking for a function which does this?
            set the user-setting 'default_media_source' of all users with the primary-group of foo to bar 
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 17698
              • 19 Posts
              Yeah, really just once. I was basically asking if something like that exists, but within the confines of the MODX Manager. I just feel like you should be able to have settings at the group level, in addition to the user level.

              I suppose a plugin would be pretty straightforward maybe "OnManagerPageInit" or "OnManagerPageBeforeRender". It's probably just easier to INSERT the correct records in the modx_user_settings table.
                Erik Lutenegger
                Founder | Tenacity
                • 4172
                • 5,888 Posts
                A snippet like that could do it:

                <?php
                //[[setGroupDefaultSource? &usergroup=`1` &default_source=`3`]]
                
                $c = $modx->newQuery('modUser');
                $c->where(array('primary_group'=>$usergroup));
                
                if ($collection = $modx->getCollection('modUser',$c)){
                    foreach ($collection as $user){
                       $cs = $modx->newQuery('modUserSetting');
                       $cs->where(array('key'=>'default_media_source')); 
                       if($settings = $user->getMany('UserSettings',$cs)){
                           foreach ($settings as $setting){
                               $setting->set('value',$default_source);
                               $setting->save(); 
                           } 
                       }else{
                           $setting = $modx->newObject('modUserSetting');
                           $setting->set('key','default_media_source');
                           $setting->set('value',$default_source);
                           $settings = array();
                           $settings[$setting->get('key')] = $setting;
                           $user->addMany($settings);
                           $user->save(); 
                       } 
                    }
                }
                
                
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 17698
                  • 19 Posts
                  Wow. Thanks!
                    Erik Lutenegger
                    Founder | Tenacity
                    • 49540
                    • 12 Posts
                    This is exactly what I've been looking for. However, I don't quite understand what I need to do to be able dynamically create individual user folders after they signed up as well as set basePath and baseUrl to their individual paths.

                    i followed instructions here http://rtfm.modx.com/revolution/2.x/administering-your-site/media-sources/securing-a-media-source/creating-a-media-source-for-clients-tutorial but right now all images are viewable for any user.

                    What do I need to do next?