We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20640
    • 5 Posts
    Hi folks,
    I urgently need to export my whole web site as plain content HTML, without any template stuff around it.
    So I had a look at the export_site.static.php, but couldn’t find the part where it gets the template and puts it around the content.
    Honestly spoken, I even don’t understand where does the template code come from as it only gets the content column from the database.
    I’m needing help, my friends. Any idea?
    Thank you for your time,
    Karolina
      • 10487 MODX Staff
      • 1,535 Posts
      The export site feature uses fopen() to grab the page as if it was rendered out in the browser.

      If you have PHPMyAdmin (or similar), you could:

      1. Backup your existing site_content table.
      2. Run a query like this to set all the documents to use a blank template:
      UPDATE modx_site_content SET template=0;

      3. Once done, truncate your site_content table and reimport the backup data (that you will have made in Step 1).

      I think the above approach should work, but make sure you take the proper backups so you can restore your data if something should go wrong.
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 20640
        • 5 Posts
        Hi garryn,

        thanx for your reply. Well, it is a solution that I have also been thinking of.
        But the problem is, that it won’t always be me initialising the export. So I can’t back it up, change the tables and so on.
        I thought in generating a view from the table, setting all the templates to 0 or blank or whatever and then doing a select on this view, dropping the view and done.
        Unfortunately I did not understand where the export_site.static.php combines the content with the template data. I can’t see it taking the template with a select or whatever... how come???

        What do you think of my view-solution?
          • 12872
          • 68 Posts
          The Quote from: muppetti at Mar 26, 2010, 02:45 PM

          Unfortunately I did not understand where the export_site.static.php combines the content with the template data. I can’t see it taking the template with a select or whatever... how come???
          Quote from: muppetti at Mar 26, 2010, 12:15 PM

          I urgently need to export my whole web site as plain content HTML, without any template stuff around it.
          The moment you say you need your site in HTML, it means that you need a template- however simple like a bare bones template. Without a template you cannot get HTML output.
          Alternately you can choose to export the database only. Modx stores your data and text in database fields.
          I suggest that you choose a simple template without much formatting and export your site.
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            The problem with exporting the database only is that chunks, snippets and plugins would not be processed, so their content output would not be in the pages.

            If this is going to be a regular occurrence, perhaps a module to emulate the Export Static HTML function and a plugin to change the template to a simple one (don’t forget that any TVs, chunks or snippets in the template itself, and not just the content, need to be processed to get the full final generated page) as the pages are generated.

            See the manager/actions/export_site.static.php file. The actual page grab is pretty simple
            if(@$handle = fopen($baseURL."/index.php?id=".$docid, "r")) {
                $buffer = "";
                while (!feof ($handle)) {
                    $buffer .= fgets($handle, 4096);
                }
            fclose ($handle);
            ...
            

            Some value would have to be set (perhaps in the SESSION) for a plugin to trigger on and reset the document’s template to the simple one if that SESSION setting is found.
              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
              • 20640
              • 5 Posts
              Hi Susan,
              thanks for your answer. At least I now understand what it does. I was thinking, the export script is taking the contents from the database table, but it’s not. It takes everything from the URL-call. Well.
              I think I need to rewirte the export, so that it takes the simple contents column from the site_content table, instead of reading the generated file.
              Furthermore, I couldn’t find any paramter concerning the template in the session. And I even think it doesn’t work that way. Every page carries it template already rendered after the URL call, so I think it has to be before that call.
              I’ll try.
              Thanx!
                • 20640
                • 5 Posts
                Quote from: indeman at Mar 26, 2010, 03:41 PM

                I suggest that you choose a simple template without much formatting and export your site.

                Well, that doesn’t work for me, because my site is bilingual. So I don’t want to set everything to a blank-template before the export, because afterwards I need to change every template in two language roots - that’s very uncomfortable.
                But thanx for the hint.
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  Not true. The document’s data is retrieved when the parser first starts, and as soon as the documentObject array has been created the template value ($modx->documentObject[’template’]) can be modified in a plugin. There is already a plugin to allow template switching. The only thing is that a document that is cached will be taken from cache first, so this behavior also needs to be overridden; or the cache automatically cleared so the document has to be pulled from the database and parsed. That’s what plugins and events are for.

                  http://www.sottwell.com/how-plugins-work.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
                    • 20640
                    • 5 Posts
                    Hi Susan,
                    I need to have a look at the plugins later, unfortunately. I need a good and rather fast solution - as usaually.
                    I changed the source from where the export_site.static.php took its contents...

                    In Line: 133, after the handel close; I override the $buffer with db table content
                    $result = $modx->db->query( ’SELECT alias, content FROM ’.$table_prefix.’site_content WHERE id = ’.$docid);
                    $row=mysql_fetch_assoc($result);

                    //$somecontent = $buffer;
                    $somecontent = $row[’content’];

                    BUT this effect I can’t see, seems to depend on my MODx page structure and folders

                    AND (what works fine for me) in Line 296:

                    //$somecontent = $buffer;
                    $somecontent = $row[’content’];

                    I changed the SQL stat and added just "content" to the SELECT stat.

                    Thank you, have a nice day!