We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    I believe ModMore has a custom file browser for their Redactor. Control to the folders it can access is rather limited, though. I would like to be able to restrict editors with a Media Source, even on a resource-level basis, perhaps using the migxResourceMediaPath snippet in the Media Source.
      Studying MODX in the desert - http://sottwell.com
      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
      Join the Slack Community - http://modx.org
      • 25803 ☆ A M B ☆
      • 721 Posts
      Good to know about the differences, particularly when there are multiple extras for the same technology. I've read that in the 2.3.4, the file browser will respect Media Sources (up to this point we've just hidden part of the file browser with CSS so that users could not see all the media sources). Would a non-standard file browser even be aware of media sources?
        • 18373 ☆ A M B ☆
        • 3,141 Posts
        Quote from: rx2 at Jun 22, 2015, 01:55 PM
        Good to know about the differences, particularly when there are multiple extras for the same technology. I've read that in the 2.3.4, the file browser will respect Media Sources (up to this point we've just hidden part of the file browser with CSS so that users could not see all the media sources). Would a non-standard file browser even be aware of media sources?

        Depends on how they're implemented. I don't think TinyMCE knows the concept of a media source, it just opens the core MODX browser, and waits for some kind of event to insert the image.

        Redactor is aware of media sources, and lets you set upload and browse paths relative to those. In v1.5 (current stable) it's a more simple and limited user experience for selecting images - there's a dropdown of folders within the configured browse path, and it then shows thumbnails for the images in that folder. In Redactor v2 we did a bunch more work on that, which we'll announce and share when it's ready for a pre-release. wink

        One of the biggest plusses of Redactor though is its upload.. just drag and drop (or select) an image, and it is automatically uploaded to the configured upload path. This path can contain placeholders, so your upload path is based on the context, date, user or resource. Even more placeholders have been added for v2 so that'll be even more powerful too.

        1. It pulls its RTE settings from RTE specific chunks.
        2. So any whoever can go, to say, the TinyMCE chunk and edit ALL of TinyMCE's settings, simple, done, voila!
        The existing extras make it almost impossible to find the blasted settings, and these settings are mere JavaScript, and in my opinion should not, never be obfuscated; I mean, TinyMCE is so easy to setup, why should it be complicated? Why should TinyMCE-specific questions be asked in a MODx forum? E.g. TinyMCE is eating my code, how do I stop it? TinyMCE adds line breaks unnecessarily, how do I stop that?
        Yet basic questions on TinyMCE are so rampant here, because the simple <script>tinymce.init(...);</script> can't be found. And yes, the settings in the MODx settings page is highly limiting.

        Interesting approach!

        Redactor provides a ton of settings (like, 150 or so in v2) which allow tweaking pretty much all the options that the redactor core exposes, as well as all our customisations and extra plugins. These then apply to the resource content, richtext TVs and components that support loading RTEs. As of v2 all these settings can also be overridden on the context level. For finer control we've also added a special Redactor TV type which has a subset of those 150 settings to allow changing the most important bits and pieces for specific use cases.
          Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

          Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
          • 3749
          • 24,544 Posts
          NewsPublisher is aware of Media Sources, though that won't help you in the Manager.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 42562
            • 1,145 Posts
            @BobRay ...I am about to finish here.
            With the latest MODx 2.3.4, these calls, within a plugin, fail woefully:
             $isRichText = $modx->resource->get('richtext');
            $isNewResource = $modx->resource->get("pagetitle");

            Is there a more efficient way to get the values I am seeking? I want to know if the [[*richtext]] was clicked or not.
            I don't want the TinyMCE to fire anywhichway.
            UPDATE - found solution to the above
            if (isset($scriptProperties['resource']) && $resource->get('richtext')){
            //do stuff here
            }
            

            Also do you have any links to read on Media Sources api? I got a custom file manager to work perfectly with MODx manager, but as @sottwell mentioned, it might be good to incorporate media source access.

            Cheers. [ed. note: donshakespeare last edited this post 9 years, 5 months ago.]
              TinymceWrapper: Complete back/frontend content solution.
              Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
              5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
              • 3749
              • 24,544 Posts
              If that's a DocSave event, you can skip the isset(). $resource will always be set when the event fires.

              I don't have any words of wisdom on Media Sources. This code for NewsPublisher was written by Marcus Schlegel and might be helpful (or not) -- it's for file TVs:

              case 'file':
                              
                  /* code adapted from core/model/modx/processors/element/tv/renders/mgr/input/file.php
                   * and (...)/image.php */
              
                  $this->modx->getService('fileHandler',
                      'modFileHandler', '', array('context' => $this->context));
                  $params['wctx'] = $this->context;
                  $value = $tv->getValue($this->existing);
                  $openTo = '';
              
                  $source = $tv->getSource($this->context);
                  if (!$source) {
                      $this->setError($this->modx->lexicon('np_no_media_source') .
                          $name);
                      return null;
                  }
                  if (!$source->getWorkingContext()) {
                      $this->setError($this->modx->lexicon('np_source_wctx_error') .
                          $name);
                  }
                  $source->initialize();
                  $params['source'] = $source->get('id');
                  
                  if (!$source->checkPolicy('view')) {
                      $this->setError($this->modx->lexicon('np_media_source_access_denied')
                          . $name);
                      return null;
                  }
              
                  if (!empty($value)) {
                      $openTo = $source->getOpenTo($value,$params);
                  }
              
                  $formTpl .= $this->_displayFileInput($name, $tvType.'Tpl',
                      $params, $openTo);
              


              Here is the _displayFileInput() method:

                  /** Produces the HTML code for file/image TVs
                   * 
                   * @access protected
                   * @param $name string - name of the TV
                   * @param $tplName string - name of the template chunk that should be used
                   * @param $sourceOptions array - Associative array of options. Accepts all file/image TV input options.
                   *       Possible options: all (processed) TV input options (Revo versions below 2.20), respectively the media source.
                   *       'wctx' doesn't seem to have an effect (?)
                   * @param $openTo string - Path for the directory to open to
                   * @return string - HTML code */
              
                  protected function _displayFileInput($name, $tplName, $sourceOptions = array(), $openTo = '') {
                      /* @var $browserAction modAction */
                      $browserAction = $this->modx->getObject('modAction',
                          array('namespace' => 'newspublisher', 'controller' => 'filebrowser'));
                      $browserUrl = $browserAction ? $this->modx->getOption('manager_url',null,
                              MODX_MANAGER_URL).'index.php?a='.$browserAction->get('id') : null;
              
                      if ($browserUrl) {
                          $phpthumbUrl = $this->modx->getOption('connectors_url',null,
                                  MODX_CONNECTORS_URL) . 'system/phpthumb.php?';
                          foreach ($sourceOptions as $key => $value) {
                              $phpthumbUrl .= "&{$key}={$value}";
                          }
              
                          $browserUrl .= '&field=' . $name;
                          $sourceOptions['openTo'] = $openTo;
                          $_SESSION['newspublisher']['filebrowser'][$name] = $sourceOptions;
              
                           $PHs = array(
                              '[[+npx.phpthumbBaseUrl]]' => $phpthumbUrl,
                              '[[+npx.browserUrl]]'   => $browserUrl
                          );
                          
                          return $this->strReplaceAssoc($PHs, $this->getTpl($tplName));
              
                      } else {
                          
                          $this->setError($this->modx->lexicon('np_no_action_found'));
                          return null;
                      }
                  
                  }
              


                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 42562
                • 1,145 Posts
                Thanks, I am still digging through, at least I can get the Media source paths now https://forums.modx.com/thread/86910/modmediasource-object
                  TinymceWrapper: Complete back/frontend content solution.
                  Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
                  5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
                  • 27708 MODX Staff
                  • 2,502 Posts
                  @donshakespeare is there any reason to reinvent the wheel here? I wonder if you'd consider forking and submitting FRs around this idea for the init config, to the TinyMCE RTE instead of creating a new 3rd one? I think this is a brilliant idea (though I am not sure a chunk is the right place or not). I certainly would like to be able to use any and all of the tiny configs and not have to rely on whether the plugin author added each directive etc into system settings.
                    Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. BlogTwitterLinkedInGitHub
                    • 42562
                    • 1,145 Posts
                    @smashingred
                    is there any reason to reinvent the wheel here? I wonder if you'd consider forking and submitting FRs around this idea for the init config, to the TinyMCE RTE instead of creating a new 3rd one? I think this is a brilliant idea (though I am not sure a chunk is the right place or not). I certainly would like to be able to use any and all of the tiny configs and not have to rely on whether the plugin author added each directive etc into system settings.
                    At least for MODx, the wheel for TinyMCE has not been invented...not yet.
                    The reason people swear against TinyMCE (or any other RTE for that matter) all over the internet is not because TinyMCE is what it is, but rather, the CMSs they use have ruined whatever experience they might have had.

                    There should not exist a 'TinyMCE' extra at all, as experience shows, we need merely and only a 'TinyMCE wrapper'. So that the user can dump out, upgrade, downgrade the actual TinyMCE at any desired time (without regard to the author of the MODx TinyMCE wrapper), use an existing TinyMCE (frontend/backend) on their server; in fact, the user should be able to not have TinyMCE on the local server, that is, to use CDN at will.

                    What deserves utmost respect is the existing bridge between MODx File Browser and the TinyMCE Extra; now we need a bridge between MODx File Browser and TinyMCE itself (not the extra).
                    We need MODx for TinyMCE, not TinyMCE for MODx - if that makes sense outside of my head.

                    With this regard, the wheel needs to be invented for the first time, so I think incorporating any fresh ideas into existing Extras will be impossible (for me at least).

                    Yes, you are right, no TinyMCE config must be hindered (not one should be hardcoded anywhichplace). I am using chunks for now, I wonder if resources would be faster, or even external files???
                    Using a MODx element/resource to house the TinyMCE init: is great, because then, someone could put some MODx magic logic in the init: do some wonders, and hopefully not risk slowing down the Manager.

                    This thread suggests RTE anguish by echoing the cries from 9 years ago.
                      TinymceWrapper: Complete back/frontend content solution.
                      Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
                      5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
                      • 3749
                      • 24,544 Posts
                      I did play around with using the CDN version of TinyMCE in NewsPublisher, I got it working, but of course I soon ran into trouble with the file browser. sad

                      I looked at some of the "drop in" file browsers out there, but they all seemed to have some fatal flaw. Part of the problem is that they also have to handle File TVs and be aware of MODX Media Sources.
                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting