We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 41816
    • 2 Posts
    Hi,
    We have a website that consists of lots of "sub-sites", which are set up as directories, with in our resource tree.

    The other day I duplicated one (The directory, and child resources), to show two examples of different directions we could take the sub-site...

    The two problems I'm having are; one, is there a way to get rid of "duplicate of" on each of the child pages -- it's a pain to change. Two, since all the links are resource IDs, (and not relative links) every contextual (in content) link has to be changed when it gets duplicated.

    My first thought was to see if there was a plug in, that would allow me to find and replace content from specific TV, for a given directory and all it's children.

    Any suggestions on how to do this, or a better approach would be greatly appreciated!
      • 22427
      • 793 Posts
      To your first problem:
      It's just an entry in the file core/lexicon/en/default.inc.php in line 119:
      $_lang['duplicate_of'] = 'Duplicate of [[+name]]';
      Just change it to
      $_lang['duplicate_of'] = '[[+name]]';
      or whatever you prefer.
        • 14883 ☆ A M B ☆
        • 450 Posts
        ottogal,

        We tried changing the value of 'duplicate_of' to '[ [+name] ]' in the Lexicon Management area. It doesn't seem to be taking. Does it have to be done directly in the file? I try to avoid editing files in /core unless I absolutely have to.

          • 813 ☆ A M B ☆
          • 326 Posts
          I've had to do quite a bit of work with duplicating contexts and can probably help. Let me point out a couple of things, and tell me if I missed anything or you need additional help:


          • You didn't specifically ask this, but toggling whether all resources stay published by default can be done with the "default_duplicate_publish_option" system setting.
          • I used to have an issue with the "Duplicate of" text, but it stopped doing that at some point. What version of MODX are you running? Is that happening when you duplicate contexts, or just resources? I'm going to go back and figure out how I got it to stop doing this.
          • I wrote a plugin that I call FreshLinks that solves your contextual linking issue across contexts, but it's incredibly custom and probably won't work "out of the box." It fires on OnWebPagePrerender, checks the context of all the links on the page, compares them to the current context loaded, and then changes them to the equivalent page if one exists.

            However, this worked very well in my situation because I'm also using a plugin that loads each of my contexts based on the first subpath in my URL (i.e., www.site.com/context1, www.site.com/context2, etc.), which made it very simple to determine context. Can you explain your multi-context setup? I might be able to help modify the plugin to meet your needs, or at least share what I've got with you.
            • 813 ☆ A M B ☆
            • 326 Posts
            One other thing: I also needed the ability to keep aliases and menu index the same when duplicating a context. Unfortunately, as of 2.2.5, this can't be done without hacking the core. If hacking's an option for you, I can show you how wink
              • 18373 ☆ A M B ☆
              • 3,141 Posts
              Mark Hamstra Reply #6, 14 years ago
              Quote from: jrotering at Oct 24, 2012, 09:21 AM
              ottogal,

              We tried changing the value of 'duplicate_of' to '[ [+name] ]' in the Lexicon Management area. It doesn't seem to be taking. Does it have to be done directly in the file? I try to avoid editing files in /core unless I absolutely have to.

              It probably needs a cache clear, as lexicons are cached by default.
                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.
                • 22427
                • 793 Posts
                It is indeed strange. I don't get the "Duplicate of " anymore. May be because I edited the file
                core/lexicon/en/default.inc.php in the mentioned way yesterday.

                But in my 2.2.5-pl (local), now neither using the Lexicon Management nor editing the file
                core/lexicon/en/default.inc.php has an effect, even after clearing the cache.
                (I'm quite sure that the latter worked in some of the previous versions.)

                Unaffected by those changes, there are two different cases:

                If I use the Duplicate button in the edit area, the duplicated resource will get the original Title.

                If I choose Duplicate Resource from the context menu in the Resources tree a dialogue opens showing an empty New Resource Name field. [ed. note: ottogal last edited this post 14 years ago.]
                  • 14883 ☆ A M B ☆
                  • 450 Posts
                  Aaron,

                  Our situation does not involve duplicating contexts or multiple contexts at all. The main issue is with duplicating a (usually root-level) resource and all of its child hierarchy, and the internal linking within.

                  For example, if we duplicate resource ID#5 and its children (6-10), the new resource tree has resource #11 with children #12-16. But if #5 contained a hard-coded link to #6, #11 will contain the same hard-coded link to #6, when we really want it to link to #12.

                  It seems like the solution would involve building some sort of mapping array that maps all of the original IDs to their duplicate IDs, and does a substitution inside of link tags in all the duplicate resources. Is this more-or-less what your plugin does?

                  Keeping aliases and menu index is also important to us, but 1) aliases seem to be working now that "Duplicate of" is gone (I think it was a cache issue as Mark suggested), 2) I'm not sure right now how important menu index preservation is to us or whether it is an issue. Keeping "published" status would also be nice, but I think Batcher can do that if need be. The internal linking is definitely the primary issue.
                    • 813 ☆ A M B ☆
                    • 326 Posts
                    Hm, okay. Doing all of this within the same context is probably more complicated, and not exactly what I've had to do in the past. Would moving to a multi-context setup make sense in your situation, or even be a possibility? The reason I ask is, I've found that this is the sort of situation where contexts really excel -- you're able to uniquely identify pages and groups of pages by their context, and also apply context-level settings that will override system settings.

                    For example, I mentioned FreshLinks, which solves my contextual linking problem. Pretend for a second that your site is using the same subpath context-routing plugin I mentioned, so each of your contexts can be accessed at site.com/context1/, site.com/context2, etc. Here's what FreshLinks does:

                    1. Executes on OnWebPagePrerender, so all [[~id]] links have already been converted into URLs in the HTML.
                    2. Gets the first subpath of the page URL
                    3. Gets a reference to the page output, and finds every link on the page (with a few restrictions that keep it from being too "greedy" with certain URL patterns).
                    4. Loops through all of the links it finds, and compares the first subpath of each link URL to the page URL subpath it finds in step #2.
                    5. If there's a match in #4, it does nothing (i.e., you're already linking to the correct context). If there's not a match, it updates that link to the subpath in #2 (i.e., the current context).
                    6. Returns the new, modified page output.

                    The problem is, if you're not using contexts, I'm not sure what's "unique" about your URLs, without creating an array map as you suggested. That's definitely possible, but seems a lot more complicated than letting the contexts sort things out automatically.

                    Again, FreshLinks (at this point anyway) is pretty custom to my site setup and still has a few bugs I need to work out, but here it is if you want to see it: https://gist.github.com/3953786.

                    EDIT: I said in step #2 that I got the page's URL subpath. If you look at my script, I'm actually getting the context key and massaging it a little bit, but either way should work.
                    [ed. note: aladage last edited this post 14 years ago.]
                      • 813 ☆ A M B ☆
                      • 326 Posts
                      If you can't go the context way, I talked to Mark Hamstra a little bit about it, and our idea was to write a custom duplicating plugin that loops over all resources fed to it (possibly executing on OnResourceDuplicate), create the old=>new array map of URLs you suggested, and then use regex to go through and make those replacements as the pages are processed.