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
    Maybe it should be a CMP and not have anything to do with the front-end at all? I'd love to know the purpose behind all of this.
      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
      • 4172
      • 5,888 Posts
      just out of interest.
      where does this ini-files come from?
      Are they generated by another system, or written by hand?
      Can you tell a bit more about the whole situation?

      If you really want to do it this way, it should be possible to store this ini-file as a chunk and read it by your script (snippet) with $modx->getChunk('theIniChunkName')
      or if you have one ini-file for one page, you can create a modx-Resource for each ini-file and store the content of the ini-file into the content or into a TV and let your snippet process it.
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 43069
        • 7 Posts
        Since some people are asking about the situation, I'll post it. I would have from the beginning, but I didn't want some long wall of text giving a whole bunch of context that might have been irrelevant.

        I was hired by a developer who uses ModX to develop sites for clients. The developer, however, isn't very handy with programming in general, and focuses primarily on design. One of her clients, who runs a softball league, needed a script written in javascript that would take scores from an html page, and calculate how many wins, losses, runs, etc. that each team had, as well as rank the teams. All this would be done client side. The team names and scores would exist already in tables, and the script would pull the data, calculate the stuff, and then print to another table in the same page.

        So I come in to do the script, no fuss no muss. The client, however, has another problem, which is that she is sick of having to manually type in each team name in each game for each pool of each league, each season. And since the same teams play the same games (ie: team1 plays team3 first, then team2 plays team5, etc.), it would be nice if she could just input the new team names each season just once, and the pages would all pop up, and she wouldn't have to type each team name a thousand times.

        So I tell her that that requires the team names to be stored on the server, and have the server generate the pages.

        I could do that if I ran my own server, but the original developer who hired me is already doing the rest of the client's website on ModX, so I need to work within what she already has.

        Which is fine, except that on top of that, the client needs the team names to exist in the actual html code, rather than some php variables, so that she can see the names when she's typing the scores into the visual html editor, ala DreamWeaver.

        Ideally I guess I would create some sort of solution that changes the way she inputs the scores for the games, where she inputs them onto a live page so that the server generates the names and she can actually see them, and it would involve a database or something. However, I am not super familiar with back-end development; the client has been using the same system for a long time now and, being that she is rather un-tech-oriented, I think she would be resistant to change; and also what originally started as a nice little javascript file has now bloomed into a more complicated project, and very little extra compensation is being thrown my way.

        So here I am trying to shoe-horn a ini-reading, html-writing script into a CMS that should probably be doing what the script does already.

        And latest news: "File extension .ini is not permitted", when I try to upload. So I'm kind of back to square-one, or at least square<10.

        Any suggestions how to deal with the problem? The developer would like me to continue working with her, and she uses ModX so I would like to get familiar. And the script isn't required to go live until July, so I can do it the right way if need be. I would use MySQL to store the information and create a score-inputting page for the client, but I'm confused as to how to access database stuff in ModX.

        Any help, once again, is sincerely and greatly appreciated.



          • 3749
          • 24,544 Posts
          First of all, go to System -> System Settings on the top menu, type "upload" in the search box at the upper right, and hit Enter. Change the upload_files setting (right-click on it and select "Update Setting" or double click in the "Value" column. Add ini to the list of allowed file types.

          It may or may not work, since your host may be blocking as well. If it doesn't, change the extension to .txt, upload it, and try renaming it on the "Files" tab.

          I can think of many ways to make life easier for the person who inputs the scores, but I don't think any of them could be done without a major revamping of how the site operates and I can see why you wouldn't want to rock the boat to that point. Since you're working in JS, you might be able to put the team names in a series of drop-down lists, let her select the two teams involved and the date or game number, and enter the score for each team.
            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
            • 43069
            • 7 Posts
            I can upload the ini file thanks to BobRay's suggestion, and I think I can get the html files generated with the php script.

            The problem still, if I continue down this path, is that the client will be editing the pages through the resource's 'Content' section using TinyMCE, a package that includes a visual editor. How can I get the html code into the resource so it's visible while editing?

            If I use your other suggestion, BobRay, to create a GetContent snippet, getting the code from the files, then all the resource will show is just the [[!GetContent]] tag. I need the actual html to show up there for the client.

            Any ideas?

            @Bruno17: The ini file is hand written. It is just a way for the client to edit the team names each season that makes sense for her, and will be visual. She will edit the ini file each season with the team names and re-upload it to the server. An ini is being used specifically just because PHP has a nice function that parses them into a multidimensional array that is easy to use, and also because when looking at the file, it will make visual sense for the client.


              • 3749
              • 24,544 Posts
              One way would be to write a plugin that reads the file into the resource content during one of the System Events that fire when the Create/Edit Resource form is loaded and also writes the content back to the file during OnDocFormSave. That way, the file and the resource content will always be synchronized.

              If it only happens once per year, a utility snippet to create or fill the resources' content fields based on the files should be fairly simple.

              Both methods assume that you can use the filenames as the page titles. With scandir, the script wouldn't have to know the filenames as long as they're all in the same directory and there's nothing else there.

              There is also Tools -> Import Resources on the top menu, which does the same thing as the utility snippet, but I've never used it so I don't know how well it would meet your needs.
                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
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                If you have your snippet return the HTML it generates from the ini file then its results will be inserted into the page's content area. Something like

                <?php
                $file = 'path/to/file.ini';
                function process_ini($file) {
                   ...
                }
                return process_ini();


                Personally, I would think editing a MIGx TV grid - or even a CMP using MIGXdb - would be a lot more "visual" than handwriting an ini file.

                I would create a template and resource just for doing this, hiding the rest of the resource's fields using form customization, then use QuickBar to let her access the resource with the TV from the front-end. Or if using a CMP, just use a customized QuickBar to let her access only this CMP from the front-end.

                  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
                  • 43069
                  • 7 Posts
                  Hello again,

                  I took some time off from the project because I had other projects to attend to. I'm back on now, and using some of your suggestions, I am much closer to being done.

                  @BobRay, Import Resources is exactly what I needed. Once I have the html files generated, this turns them into resources with the content sections already populated. Thank you for the help.

                  @sottwell, I like your idea to use a MIGx TV grid rather than an ini file, but I can't seem to figure out how to make it work. I can set up the grid, but I can't seem to figure out how to reference the individual TVs in my PHP code. Specifically, I have it set up so each pool of 7 teams has their own MIGx aggregate TV. All the MIGx tutorials, however, only show how to output the data into html, via a chunk. I want to assign the team names to variables in a PHP snippet. Any ideas how to do this?

                  Any help is again greatly appreciated.

                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    A regular MIGx TV stores its data as a JSON string in the site_tmplvar_contentvalues table, so you could access it via the API and convert it to an object to do with as you wish.
                    $page = $modx->getObject('modResource', 123);
                    $value = $page->getTVValue('teams');
                    $teams = $modx->fromJSON($value);

                    http://rtfm.modx.com/display/revolution20/Accessing+Template+Variable+Values+via+the+API
                    http://rtfm.modx.com/display/xPDO20/fromJSON

                    You could use the $teams->toArray() function to convert the object to an array if you're more comfortable working with arrays.
                    http://rtfm.modx.com/display/xPDO20/toArray
                      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
                      • 3749
                      • 24,544 Posts
                      Susan, toArray() only works as a method of modX/xPDO objects and I think $teams will already be a PHP array rather than an object.

                        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