We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13735
    • 62 Posts
    Hey,

    I use the following connector:
    <?php
    $basePath = dirname(dirname(dirname(dirname(dirname(dirname( __FILE__ ))))));
    
    require_once $basePath . '/config.core.php';
    require_once MODX_CORE_PATH . 'config/' . MODX_CONFIG_KEY . '.inc.php';
    require_once MODX_CONNECTORS_PATH . 'index.php';
    
    $modx->request->handleRequest( array(
        'processors_path'   => $modx->getOption( 'core_path' ) . 'components/gallerygear/processors/',
        'location'          => 'photo'
    ) );


    and it works for manager stuff pretty well. But when I log out and access the same url
    [tt]localhost:8888/bild-worte/assets/components/gallerygear/connectors/photo/index.php?action=resizedphoto&key=6840dbe5a4eadeb08bde8deb657db1cf[/tt]
    I don’t get what I want.
    I tried [tt]local...657db1cf&ctx=web[/tt] as well. But I guess I just don’t understand the underlying basics to solve this myself. How can I achieve this? This connecter returns an image file and I need it’s functionality on the frontend as well.

    regards,
    JB
      • 26903
      • 1,336 Posts
      Its probably because you’re logged out, the index.php include sets the context to manager(mgr) and does an access check if I remember correctly. Putting a debugger on it and stepping through should show you what’s going on.
        Use MODx, or the cat gets it!
        • 13735
        • 62 Posts
        It’s definitly because I am logged out.

        I know what you mean:
        <?php /* initialize the proper context */
        $ctx = isset($_REQUEST['ctx']) && !empty($_REQUEST['ctx']) ? $_REQUEST['ctx'] : 'mgr';
        $modx->initialize($ctx);

        This is the part in the connector index.php. I added [tt]&ctx=web[/tt] to the url in order to set it into the web context - but it doesn’t work. I still get a blank page. My processor looks like this:
        <?php
        include_once ($modx->getOption('core_path') . "components/gallerygear/gallerygear.class.php");
        $gg = new GalleryGear();
        
        $resizedPhoto = $modx->getObject('ggResizedPhoto', $_REQUEST['key']);
        
        $pathFile = $resizedPhoto->getPathFile();
        if($pathFile) {
            header('Content-type: ' . $resizedPhoto->getContentType());
            return file_get_contents($pathFile);
        } else {
            return 'No such file.';
        }

        As you can see it doesn’t check for any permissions.
          • 26903
          • 1,336 Posts
          Going back to here from the first post :-
          $modx->request->handleRequest
          The request handler is different for back end and front end. The back end(mgr) context uses the modmanagerRequest/Response classes while the front end(web) uses the modRequest/Response classes. The front end doesn’t execute processors, it looks for a page to get(id=xx).

          Note in the index.php of the connectors directory we have :-
          $connectorRequestClass = $modx->getOption(’modConnectorRequest.class’,null,’modConnectorRequest’);
          $modx->config[’modRequest.class’] = $connectorRequestClass;
          This sets the request class to modConnectorRequest, which is an extension of modmanagerRequest so you are using this class not the front end class.
          This will assume you are ’the manager’ and not the front end.

          I’m not sure what you are trying to do here structurally, if you just want to share code then you could probably write a snippet that hooks in the processor code and can be placed on appropriate pages say.
            Use MODx, or the cat gets it!
            • 13735
            • 62 Posts
            I’m not sure what you are trying to do here
            It’s for a gallery system. [Revolution Third Party Component] GalleryGear It outputs a resized version of a photo if it’s needed. Let’s say you have a page on which you use fancybox. You don’t need all the big photos at once. This saves some page loading time and I have the ability to count the views. Is what I’m trying to achieve possible if I load modx externally in a php script?

            regards,
            JB
              • 26903
              • 1,336 Posts
              Why can’ you just take the processor code(maybe adjust slightly) and put it in a snippet, which can be placed on the page you want?
                Use MODx, or the cat gets it!
                • 13735
                • 62 Posts
                Because this way is much more ellegant and offers me the features mentioned above.

                Example:
                <a href="... .php?key=..." class="fancybox">
                    <img src="image.jpg" />
                </a>


                The snippet doesn’t create a jpg but insead it provides a php file which returns the image if it’s accessed. This way the image gets created when the fancybox is opened by the user. If the snippet creates all the images while the page loads for the first time and lets say that the page has about 50 photos on it the php runs for over 30 seconds and the execution time is restricted on many servers including mine. When I do it my way a single php script never runs for more than 30 seconds because it doesn’t create all the pictures at once.

                Why doesn’t modx offer its great connector capabilities for its frontend, too?
                  • 26903
                  • 1,336 Posts
                  Ok, I’m with you a bit more now, so, can you not leave your processor code where it is and just call it from your href link with the right params of course, this will return your pic when the link is pressed, not on page load. You don’t need to go through a connector as such from the front end.
                    Use MODx, or the cat gets it!
                    • 13735
                    • 62 Posts
                    Yeah I know - but I like the connector concept so much that I had to ask. I now move this processor into the assets folder, out of the core, and let it load modx so it can do the db stuff. What I like about the connector concept is that in order to create a new task/action I only have to create a new php file in the processors folder of my 3pc. I think that’s great... Maybe this will be possible someday also for frontend stuff. I saw that - I think it was - "discuss" uses a modx page with a single snippet as gateway. This is crap in my opinion and far away from a good solution.
                      • 26903
                      • 1,336 Posts
                      You do have a point here, I don’t like putting stuff in assets if I can help it and I don’t like the page concept either, we only really need a connector for the front end that loads a request handler(maybe a new one) and executes the processor but ’knows’ its not the manager etc. Maybe file an enhancement in JIRA referencing this thread for discussion.
                        Use MODx, or the cat gets it!