We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 52024
    • 15 Posts
    I manage this French-language site, editart.ch. I aim to add a Letsencrypt certificate, but before doing so I need to make all connections to the site via https. I host the majority of the site's images on AWS S3 and use imgix.com to transport and compress the images, more than 400 of them.

    The connections from AWS to editart.ch are made via http. I need to change all the URLs to https, all 400 of them.

    Is there a way to do this in bulk on ModX?

    Thanks.

    This question has been answered by fgarydc. See the first response.

      • 3749
      • 24,544 Posts
      If the links are uniform enough, you could do it with a utility snippet using preg_replace(), but it would take some careful testing.

      Can you give a few examples of the links?

      Also, where are the links (resources, templates, chunks, tvValues, etc.)?
        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
        • 52024
        • 15 Posts
        Quote from: BobRay at Jul 06, 2017, 09:41 PM
        If the links are uniform enough, you could do it with a utility snippet using preg_replace(), but it would take some careful testing.

        Can you give a few examples of the links?

        Also, where are the links (resources, templates, chunks, tvValues, etc.)?

        The vast majority of the links look like this -- http://editart.imgix.net/artists-and-poets/poemas-para-mirar/adami.jpg where the path differs for each image. That's the http I want to change to https. They are placed in a TvValue called Art Image with the input option of URL.
          • 52024
          • 15 Posts
          Quote from: BobRay at Jul 06, 2017, 09:41 PM
          If the links are uniform enough, you could do it with a utility snippet using preg_replace(), but it would take some careful testing.

          Can you give a few examples of the links?

          Also, where are the links (resources, templates, chunks, tvValues, etc.)?

          The vast majority of the links look like this -- http://editart.imgix.net/artists-and-poets/poemas-para-mirar/adami.jpg where the path differs for each image. That's the http I want to change to https. They are placed in a TvValue called Art Image with the input option of URL.
            • 3749
            • 24,544 Posts
            Having them in a TV value makes it much easier. Just put this tag on a page:

            [[!convertHttp]]

            Then create a snippet called convertHttp, with this code (untested):

            <?php
            
            $tvId = 12; // IMPORTANT: change this to the ID of your Art Image TV.
            
            $tvrs = $modx->getCollection('modTemplateVarResource', array('tmplvarid' => $tvId));
            
            $count = 0;
            foreach($tvrs as $tvr) {
               $value = $tvr->get('value');
               $value = str_replace('http', 'https', $value);
               $tvr->set('value', $value);
               $tvr->save();
               $count++;
            }
            
            return "<h3>Fixed " . $count . ' TVs</h3>';


            (Be sure to change the $tvId variable value in the code above. The TV's ID is shown in parentheses in the Template Variable tree in the Manager.)

            Then, visit the page with the tag on it and you should be in business.

            This assumes that there are no values of Art Image TVs with http that you don't want to convert.

              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
            • discuss.answer
              • 52024
              • 15 Posts
              Quote from: BobRay at Jul 08, 2017, 04:05 AM
              Having them in a TV value makes it much easier. Just put this tag on a page:

              [[!convertHttp]]

              Then create a snippet called convertHttp, with this code (untested):

              <!--?php
              
              $tvId = 12; // IMPORTANT: change this to the ID of your Art Image TV.
              
              $tvrs = $modx--->getCollection('modTemplateVarResource', array('tmplvarid' => $tvId));
              
              $count = 0;
              foreach($tvrs as $tvr) {
                 $value = $tvr->get('value');
                 $value = str_replace('http', 'https', $value);
                 $tvr->set('value', $value);
                 $tvr->save();
                 $count++;
              }
              
              return "<h3>Fixed " . $count . ' TVs</h3>';


              (Be sure to change the $tvId variable value in the code above. The TV's ID is shown in parentheses in the Template Variable tree in the Manager.)

              Then, visit the page with the tag on it and you should be in business.

              This assumes that there are no values of Art Image TVs with http that you don't want to convert.


              Almost works. The code is replacing http with httpsssssss. Do you know why?
                • 52024
                • 15 Posts
                Quote from: fgarydc at Jul 08, 2017, 03:47 PM
                Quote from: BobRay at Jul 08, 2017, 04:05 AM
                Having them in a TV value makes it much easier. Just put this tag on a page:

                [[!convertHttp]]

                Then create a snippet called convertHttp, with this code (untested):

                <!--?php
                
                $tvId = 12; // IMPORTANT: change this to the ID of your Art Image TV.
                
                $tvrs = $modx--->getCollection('modTemplateVarResource', array('tmplvarid' => $tvId));
                
                $count = 0;
                foreach($tvrs as $tvr) {
                   $value = $tvr->get('value');
                   $value = str_replace('http', 'https', $value);
                   $tvr->set('value', $value);
                   $tvr->save();
                   $count++;
                }
                
                return "<h3>Fixed " . $count . ' TVs</h3>';


                (Be sure to change the $tvId variable value in the code above. The TV's ID is shown in parentheses in the Template Variable tree in the Manager.)

                Then, visit the page with the tag on it and you should be in business.

                This assumes that there are no values of Art Image TVs with http that you don't want to convert.


                Almost works. The code is replacing http with httpsssssss. Do you know why?

                I just used the code to convert "httpsssssss" to https. Worked like a charm. Many thanks.
                  • 3749
                  • 24,544 Posts
                  I'm glad I could help. Thanks for reporting back. smiley
                    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