1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Insert Copyright Attribution Once

Discussion in 'XenForo Development Discussions' started by Robust, Oct 22, 2015.

  1. Robust

    Robust Well-Known Member

    Hey,

    I have multiple add-ons that include copyright attribution/branding into the footer.

    Something like this:
    [​IMG]

    As multiple add-ons include this branding, I only want one add-on to be taking control of this. To insert the branding I use a template modification that makes a PHP callback to our servers to check branding.

    That being said, I've tried changing the 'unique modification key' to the same thing, as it is really just the same thing, and I guess XenForo wasn't kidding when they said 'unique' - that one didn't work. I've already explored the idea of setting a variable in XenForo_Application with the add-on ID of what's handling the modification, and then add an extra check into the template callback to see if that add-on ID is its. I don't think that's too good of an idea. I mean, you can unset it during uninstall and all but it's just a poor concept.

    I'm guessing someone here has a brighter idea.

    So yeah, clarification, I want the "Some add-ons by Apantic" to only appear once, even if multiple Apantic add-ons are installed.
     
  2. MtoR

    MtoR Well-Known Member

    Perhaps with template modifications regular expressions you could avoid inserting if already existing.
     
  3. Robust

    Robust Well-Known Member

    Not sure what you mean. Not too good with regex personally.
     
  4. MtoR

    MtoR Well-Known Member

    I mean perhaps you could do so the regexp don't trigger a match when your stuff is alredy existing (added by another template modification just before).

    I am not that good too but I usually use that website to build mine:
    http://www.regex101.com
     
    Robust likes this.
  5. Robust

    Robust Well-Known Member

    That's a really handy website actually. Do you have an example of what you mean? I mean, your idea makes sense but I'm not sure if I can use regex to check if it's already been inserted.
     
  6. Chris D

    Chris D XenForo Developer Staff Member

    Try using <xen:set tags. I've not tested it but if each copyright message did:
    Code:
    <xen:if is="!{$copyrightInserted}">Copyright 2015<xen:set var="$copyrightInserted" value="1" /></xen:if>
    I'm pretty sure it would only show the first copyright and skip the others.
     
    HWS likes this.
  7. Robust

    Robust Well-Known Member

    Well, I return the string to set through PHP:
    http://paste.ubuntu.com/12894915/

    I mean, I can set a var (XenForo_Application::set) but what if that add-on is uninstalled? The var would still be set. I can unset it at uninstall, I suppose, and then it'd begin the cycle all over again.
     
  8. Liam W

    Liam W Well-Known Member

    When I did this, I had a shared branding file, that contained the method to add the branding.

    This checked a static class variable as to whether it had already been added.

    This could be done with a xen:callback tag easily, to run the PHP on every load (and cache the branding response in the simple cache).

    Liam
     
  9. Chris D

    Chris D XenForo Developer Staff Member

    What I've suggested is unrelated. Probably best to just try it.
     
  10. Robust

    Robust Well-Known Member

    Tried something like this:

    Code:
        public static function insert($matches)
        {
            if(!XenForo_Application::get('apBrandingInserted'))
            {
                XenForo_Application::set('apBrandingInserted', 1);
                return self::_checkBranding($matches);
            }
    
            return @$matches[1];
        }
    No copyright branding is inserted now

    Edit: One more problem with that idea, if templates are rebuilt, the var is still going to be set to 1.

    Adding: XenForo_Application::set('apBrandingInserted', 0)
    before the if statement makes it work, of course.
     
  11. Robust

    Robust Well-Known Member

    Made some progress.

    Renamed the insert function to printBranding. Changed the PHP callback to a simple replacement, and used the xen:callback tag.

    It's working now, partially.
    [​IMG]

    It messes that up. It centres somehow and the timings, memory, db queries stuff is in huge font now.
     
  12. Robust

    Robust Well-Known Member

    Fixed. Thank you @Chris D, @Liam W and @MtoR

    Final solution was to use what Chris said, combined with the <xen:callback> tag. I'm still testing to see if this works with uninstall. The problem above was because I forgot to add $0 to replace the replaced text (the <div id="copyright">).
     
  13. Robust

    Robust Well-Known Member

    Ah, great. One more problemo, and it's probably going to complicate this.

    Different add-ons have different copyright removal. It is not global. If any of the add-ons installed don't have copyright removal, it should display the attribution notice.

    I have a very clumsy idea that may work. A high priority listener that checks the branding, and if true then it does XenForo_Application::set('apShowBranding', 1) and then another listener (lower priority) that inserts it, this listener does what we talked about above (check if var showBranding is set and if the branding is already inserted, if showBranding is 1 and brandingSet is 0, show the branding and set brandingSet to 1).

    There is probably a neater way to do it, that would OCD me out of the air. I could distribute ApanticGeneric or something as well and have the idea @Liam W suggested but that reminds me of *******Helper and that went really well...
     
  14. Robust

    Robust Well-Known Member

    I'm dumb, lol. No additional refinements to the code are needed, what Chris suggested is perfect. Thanks @Chris D ;)
     

Share This Page