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

    What i am doing is retrieving BLOB field from the database, modifying the header so it would be downloaded, the contents of these fields are PDF or DOC files.
    I had the files downloaded from modx corrupted but from a static php files works fine, after troubleshooting for so long doubting the headers, i found out with wire-shark the below:

    The problem is when a file contains an image the image is usually between square brackets which modx assumes they are snippets try to process them and fails so this part is stripped out from the file, causes the file to be without the image and in most cases gets corrupted.

    My question is: How can i force modx to output these files without processing the square brackets? usually when i want to display square brackets in the output i use
    <pre><html><body><pre><span>[</span><span>[</span>TEXT[[data]]<span>]</span><span>]</span></pre>
    which corrupts the file.

    Update:
    To workaround this issue i zipped the file on the fly, however it is just a workaround and not a solution [ed. note: mina_gerges last edited this post 13 years ago.]
      • 10208 ☆ A M B ☆
      • 1,780 Posts
      MODX Revolution processes double square brackets. The only way to get it to not process them is to comment them out by adding -. (that I'm aware of)

      Commenting in MODX Revolution:
      [[-yourSnippet/chunk/tv/markup]]


      The - may show up in your output though, which is not ideal. Curious what others have to say.

      edit: Revolution processes double square brackets (i.e. [[ ). Single brackets are not processed, however MODX Evolution does process single square brackets. The commenting rule for Revolution to add - is not applicable to Evolution (in all cases), do not rely on it even if it seems to work. I learned this the hard way recently. [ed. note: frogabog last edited this post 13 years ago.]
        Frogabog- MODX Websites in Portland Oregon
        "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
        Having server issues? These guys have MODX Hosting perfected - SkyToaster
        • 38237
        • 83 Posts
        Thank you for your response. In my situation the PDF files has double square brackets whenever they have images which makes MODX think they are calls to a snippet, snippet not found then data is stripped. So what i am hoping for is a way to stop processing any snippets between special brackets, something like:

        [[noprocess]] [[something here]] [[/noprocess]]


        Any other attempt to add a dash just after the first double square brackets will cause the PDF file to be corrupted. And i am talking about Modx Rev.
        I've a strong feeling that Modx Core devs has implemented such functionality to stop processing API calls.

        Quote from: frogabog at Sep 23, 2013, 05:32 AM
        MODX Revolution processes double square brackets. The only way to get it to not process them is to comment them out by adding -. (that I'm aware of)

        Commenting in MODX Revolution:
        [[-yourSnippet/chunk/tv/markup]]


        The - may show up in your output though, which is not ideal. Curious what others have to say.

        edit: Revolution processes double square brackets (i.e. [[ ). Single brackets are not processed, however MODX Evolution does process single square brackets. The commenting rule for Revolution to add - is not applicable to Evolution (in all cases), do not rely on it even if it seems to work. I learned this the hard way recently.
          • 3749
          • 24,544 Posts
          Are there tags in the file that you *do* want processed?

          If not, you might be able to use a plugin connected to OnParseDocument and OnWebPagePrerender. Translate '[[' to some arbitrary string that won't occur in the file in OnParseDocument(before the tags are processed), then translate it back in OnWebPagePrerender (after the tags are processed).

          If there are tags you do want processed, I think you're out of luck unless you want identify and selectively skip the translation on the ones that should be processed.
            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
            Have you considered using Static Resources to access the files instead of storing them as BLOBs in the database? You can store the files outside of the web root, and the static resource will have all of the properties of an ordinary resource, including Resource Group assignments.
              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
              • 38237
              • 83 Posts
              Thanks for responses, much appreciated smiley

              @Bob:
              the plugin idea is good, as far as i understood that you suggest me to build my own plugin which will filter specific placeholder to stop processing the double square brackets as snippet calls. If i understood correctly, can you give an example of such code! much appreciated.

              @sottwell:
              using a static resource is a good idea, however the files will be posted from a form, and the amount of files might be thousands, using a custom table is ok, but overloading the resources table will not be good, plus the customer doesn't want to have the files on the disk they need them in the DB. My problem is that my code runs fine on regular php but getting. I really believe that there must be an API call which will stop processing tags on that resource.

              Now i found out that even zipping doesn't resolve the problem coz still some files gets modified as zip. I am on a specific customer requirement, and i guess the solution for me is to stop processing tags on that specific resource sad
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                The system I have uses static resources for thousands of .pdf and other downloadable files. I have the QuickBar add-on installed and configured so the manager user gets a drop-down menu bar at the top of the screen on pages where the QuickBar snippet is placed. He goes to the page under which he wants to add the new file and chooses to create a new static resource there. QuickBar sends him to the appropriate Manger page with all the appropriate settings. When choosing the file to link to, he is able to upload the file itself to where it needs to go - in this case, the files are in a directory structure above the web root. The static resources are set to not show in the Tree, so they don't clutter up the tree. A fairly basic MIGXdb-based TV for each container resource allows management of the static resources (similar to the Articles add-on). The editor can also create new static resources there if he prefers.
                  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
                  • 38237
                  • 83 Posts
                  @sottwell Thank you for your concern and fast responses.
                  In my case, the files are added from a public form, and the file has to be downloaded from the DB through the front end. It's a customer request to have the files in the DB no matter what i say.

                  I tried adding <pre></pre>, but double square brackets inside a PDF or DOCX files are considered snippets by modx then stripped out.
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    You could try the "FixedPre" plugin, that is used on sites that display code, like this page http://sottwell.sottwell.modxcloud.com/articles/90-minutes.html

                    http://bobsguides.com/fixedpre-tutorial.html
                      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
                      • 38237
                      • 83 Posts
                      Thanks a million really.

                      I was writing my own plugin according to bob advise here, and then you (Suzan) came up with this one which is awesome as well thanks to you and Bob, doesn't work for me as is because it replaces brackets with html hexes which corrupts the file, so I will proceed with writing the plugin to strip the square brackets and put them back after as bob suggested
                      OnParseDocument(before the tags are processed), then translate it back in OnWebPagePrerender (after the tags are processed).

                      Once i am done with it and it works i will publish it in case someone else would be in the same situation.