We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42398
    • 5 Posts
    I am using Modx to manage multiple websites. These websites have their own context with clients having access only to their own context.

    When inserting link via Tinymce and using the search function, a user seems to be able to select other resources that do not belong to their context (see attached).

    As you can see, "Website7" has only one "Home" resource, but the search function shows a laundry list of all other Home resources from other contexts.

    Would this be a Modx issue or have I setup my user permissions or settings wrong?

    Please, let me know if anyone has any idea how to fix this issue.

    Thanks!
    • Do you mean the WYSWYG editor path? For multiple context, it's safe to always set the generated url as "full". From the System Setting page:


      • core: link_tag_scheme -> set the value to full
      • tinymce: tiny.path_options -> set the value to fullpathurl
        zaenal.lokamaya
        • 42398
        • 5 Posts
        Thanks lokamaya,

        What I mean by resources is Documents..not assets in the file system.
          • 42398
          • 5 Posts
          It seems its a bug, already reported: http://tracker.modx.com/issues/9226
          • Oh I see...

            But I guess it's TinyMCE bugs because when searching for resources it use his own connector: /assets/components/tinymce/jscript/tiny_mce/plugins/modxlink/search.php

              zaenal.lokamaya
            • The hard fix is by editing /assets/components/tinymce/jscripts/tiny_mce/plugins/modxlink/js/modxlink.js

              Get the current context using top.window.MODx.ctx, then add it to extraParams
              function init() {
                  var ctx = top.window.MODx.ctx || '';
                  $('#search').autocomplete('search.php',{
                      extraParams: {
                          'search-mode': 'pagetitle',
                          'context': ctx
                      }
                      ,formatItem: function(item) {
                          return item[0];
                      }
                  }).result(function(e,item) {
                      $('#href').val('[[~'+item[1]+']]');
                      $('#search').val('');
                  });
                  //....
              }


              Then in /assets/components/tinymce/jscripts/tiny_mce/plugins/modxlink/search.php, add the context to where clause:

              $searchMode = $modx->getOption('search-mode',$_REQUEST,'pagetitle');
              $searchContext = $modx->getOption('context',$_REQUEST,'web');
              
              $query = $modx->getOption('q',$_REQUEST,'');
              
              $c = $modx->newQuery('modResource');
              $c->where(array(
                  $searchMode.':LIKE' => '%'.$query.'%',
                  'context:=' => $searchContext,
              ));
              [ed. note: lokamaya last edited this post 11 years, 4 months ago.]
                zaenal.lokamaya
              • More safe fix:

                1. Add new system setting: tiny.allow_cross_context = true/false
                2. Edit /assets/components/tinymce/jscripts/tiny_mce/plugins/modxlink/search.php

                $searchMode = $modx->getOption('search-mode',$_REQUEST,'pagetitle');
                $searchContext = $modx->getOption('context',$_REQUEST,null);
                $allowCrossContext = $modx->getOption('tiny.allow_cross_context',null,false);
                 
                $query = $modx->getOption('q',$_REQUEST,'');
                 
                $c = $modx->newQuery('modResource');
                
                if (!$allowCrossContext && !empty($searchContext)) {
                    $c->where(array(
                        $searchMode.':LIKE' => '%'.$query.'%',
                        'context:=' => $searchContext,
                    ));
                } else {
                    $c->where(array(
                        $searchMode.':LIKE' => '%'.$query.'%',
                    ));
                }


                3. Edit /assets/components/tinymce/jscripts/tiny_mce/plugins/modxlink/js/modxlink.js as mentioned in previous post.
                  zaenal.lokamaya
                  • 42398
                  • 5 Posts
                  Thanks lokamaya! I appreciate your help.

                  I will try this out.

                  • Here the better approach.

                    No need to add system setting or edit modxlink.js, only modify 1 file /assets/components/tinymce/jscripts/tiny_mce/plugins/modxlink/search.php


                    <?php
                    /**
                     * Handles dynamic search
                     *
                     * @package tinymce
                     */
                    require_once dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))))).'/config.core.php';
                    require_once MODX_CORE_PATH.'config/'.MODX_CONFIG_KEY.'.inc.php';
                    require_once MODX_CONNECTORS_PATH.'index.php';
                    
                    $searchMode = $modx->getOption('search-mode',$_REQUEST,'pagetitle');
                    $query = $modx->getOption('q',$_REQUEST,'');
                    
                    $c = $modx->newQuery('modResource');
                    $c->where(array(
                        $searchMode.':LIKE' => '%'.$query.'%',
                    ));
                    
                    $count = $modx->getCount('modResource',$c);
                    
                    $c->select(array('id','pagetitle','alias'));
                    $c->limit(10);
                    
                    $resources = $modx->getCollection('modResource',$c);
                    
                    foreach ($resources as $resource) {
                        if ($resource->checkPolicy('list')) {
                            echo $resource->get('pagetitle').' ('.$resource->get('id').')|'.$resource->get('id')."\n";
                        }
                    }
                    
                    session_write_close();
                    die();
                    [ed. note: lokamaya last edited this post 11 years, 4 months ago.]
                      zaenal.lokamaya
                    • I tried this (the script above) on 2.3.1 and I still see a full list of Resources that have the same name from other contexts. Anyone had any luck getting this to function?