We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32025
    • 305 Posts
    I hope this post does not make real PHP coders sick, but I am going to mention (ask) anyway. I don't write PHP and frankly for a webmaster like me, I can easily add my templates and a simple checkout form (via add-ons) to MODx. which is why I love it! But writing an add-on is just confusing to me although I have installed a few with instructions.

    So I buy simple PHP scripts for functionality. I found a few different PHP scripts that you log into to make changes and they easily update on the website (Like and online appointment scheduler and online image gallery that the non-tech user can update very easily). My delimma is that my customers would have to log into two places (MODx and the Script Login) to make changes to their website.

    I would like if the scripts can be run and embedded into MODx control panel somewhere. Bascially, if they click the link the script runs on a MODx admin page and automatically logs into the script. Then the script could be run right inside the MODx window. This solution would make it so they user can log into MODx only and make changes to the embedded script. Sounds easy to me the problem is: I don't know how to do this.

    These are fairly basic scripts that I use and since I own the developers license, I can modify the source code of the script. It is written in: MVC stands for Model View Controller.

    Would this be as easy as disabling the log-in and then adding maybe a chunk or a snipplet to show the script directly inside the MODx control panel?

    So.... is there an add-on that would allow me to do this? If not does this sound difficult to do? Perhaps someone can point me in the right direction.
      Making the web a better place on site at a time! Dayton Web Design: http://www.dayton-web-design.com/
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      How easy/hard it is to disable the login depends on the script of course.

      To integrate it into the MODX back-end there's a few steps:

      1. Go to System > Namespaces. Add a new namespace (could name it "customstuff" and assign its path to be your/core/dir/components/customstuff/).
      2. Go to System > Actions (& Menus). In the left hand tree find your new namespace, right click it to add an action. The controller should be a php file, relative to your namespace path, which you want to open. If you have your custom script in core/components/customstuff/script1/index.php, you would set the controller to script1/index - we skip the .php suffix.
      3. Still in System > Actions, right click on Components in the tree and choose to place an action there. Choose the action you just created (note that it's a dropdown box with paging, could be on a further page) and give the menu a name and optionally a description. If you need to pass parameters to the php file, you can do so with the parameters field.
      4. Refresh the page and find your item in the top menu under Components.
        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.
        • 32025
        • 305 Posts
        First off mark thank you for the detailed description, I really appreciate your effort!.

        I will try and do this by the weekend, I will let you know what happens. If I were to disable the log-in for the script will it be secure wrapped up in the MODx core folders? I would assume the MODx log in security would be in play since these scripts would be located within the MODx core folders. I guess I wouldn't want to jeopardize the security on my server by doing something foolish like disabling a log-in.
          Making the web a better place on site at a time! Dayton Web Design: http://www.dayton-web-design.com/
          • 32025
          • 305 Posts
          3. Still in System > Actions, right click on Components in the tree and choose to place an action there. Choose the action you just created (note that it's a dropdown box with paging, could be on a further page) and give the menu a name and optionally a description. If you need to pass parameters to the php file, you can do so with the parameters field.

          I have Revolution 2.2.0-pl2 and when I right click the Components there is a mandatory field called: "Lexicon Key" what would I enter here?
            Making the web a better place on site at a time! Dayton Web Design: http://www.dayton-web-design.com/
            • 32025
            • 305 Posts
            I created a test page and it shows in the menu and displays. I do have one problem though, the page shows above everything else including the menu, instead of showing below the menu like the other pages. Any idea as to how I can fix this?
              Making the web a better place on site at a time! Dayton Web Design: http://www.dayton-web-design.com/
              • 18373 ☆ A M B ☆
              • 3,141 Posts
              If I were to disable the log-in for the script will it be secure wrapped up in the MODx core folders?
              Probably not. If building a component from scratch it builds up dependencies to MODX, so wont run without it (ie direct access). What you could do is do something like this in the script instead of its login:

              if (!$modx || !($modx instanceof modX)) { die('No direct access allowed'); }
              
              if (!$modx->user || !$modx->user->hasSessionContext('mgr')) { die ('Please make sure you are logged in to the MODX Manager'); }


              I have Revolution 2.2.0-pl2 and when I right click the Components there is a mandatory field called: "Lexicon Key" what would I enter here?
              Looks like you figured it out, but that's where you enter the menu items' name. You can use lexicons there, which are translated strings basically, which explains the name. If you're just doing a simple integration you likely don't have the lexicon files in place though.

              I created a test page and it shows in the menu and displays. I do have one problem though, the page shows above everything else including the menu, instead of showing below the menu like the other pages. Any idea as to how I can fix this?
              One out of two things:

              1. Modify the script to not use "echo" or "print", but to return all content output at the end of the processing with the "return" statement.
              2. Create a new file that you set up as the action controller, which return's an iframe to your custom script. With this you will lose access to $modx though, so the security checks above wouldn't work anymore.
                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.
                • 32025
                • 305 Posts
                OK all is working fine now except for now that I have the script loaded into MODx, when I click on the script it loads fine. The problem is that it only shows the script. Meaning, the menu items from the /manager/ and all things MODx are completely gone (except for the URL location). This is the URL: http://www.MYWEBSITE.com/core/components/MYAPPNAME/index.php?controller=Admin&action=index

                Is this a simple setting?

                Under: System>Actions>Right click my app name under: components and select update I have this:
                Lexicon Key: Appointment Scheduler
                Description: My description here
                Action: index (this may be the problem but I tested a few other options and nothing worked.

                I suspect this is an easy setting, but I don't know where this is going wrong. Please help I am very close!
                  Making the web a better place on site at a time! Dayton Web Design: http://www.dayton-web-design.com/
                  • 32025
                  • 305 Posts
                  OK, I once again at least I have the MODx menu showing again. I loaded this into an iFrame and it still displays up top over the menu (but in the iFrame). Even if I make the iFrame small in width it crowds to the left and does not go in the lower portion. I have attached an image to show:



                  As you can see it still shows above the menu. An more ideas?
                    Making the web a better place on site at a time! Dayton Web Design: http://www.dayton-web-design.com/
                    • 18373 ☆ A M B ☆
                    • 3,141 Posts
                    Are you using "return" to place the iframe in the action controller, or are you using echo?
                      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.
                      • 32025
                      • 305 Posts
                      I am sorry for being so daft, but I do not understand what you mean by placing "return" or "echo" to place the iframe in the action controller.

                      I don't think I have either selected, all I have is an iFrame.php page that looks like this:
                      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                      <html xmlns="http://www.w3.org/1999/xhtml">
                      <head>
                      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                      <title>Appointment Scheduler</title>
                      </head>
                      
                      <body>
                      <div> 
                      <iframe src="http://www.TheLocationOfMySoftareIndex.php" scrolling="yes" width="100%" height="600">
                      </iframe></div>
                      
                      </body>
                      </html>


                      With your instructions above:
                      1. Modify the script to not use "echo" or "print", but to return all content output at the end of the processing with the "return" statement.
                      2. Create a new file that you set up as the action controller, which return's an iframe to your custom script. With this you will lose access to $modx though, so the security checks above wouldn't work anymore.

                      I used #2 since I can create a page with an iFrame but don't know how to modify the script to use "echo" or "print".

                      Am I supposed to add something to the: Parameters or Handlers field of the iFrame?

                      I created a page called iFrame.php (above is the coding). I uploaded that page to the directory where this component is located. I maybe see a problem under: Actions>Top Menu>Components>Appointment Scheduler (iframe/index.php), that I do not have an iframe folder with index.php page. I have this: core/components/appscheduler then all my core files for the script and an iframe.php page.
                        Making the web a better place on site at a time! Dayton Web Design: http://www.dayton-web-design.com/