Insert Copyright Attribution Once

Robust

Well-known member
Hey,

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

Something like this:
2d94bd0b0e.png


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.
 
Perhaps with template modifications regular expressions you could avoid inserting if already existing.
 
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
 
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
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.
 
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.
 
  • Like
Reactions: HWS
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.
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.
 
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
 
What I've suggested is unrelated. Probably best to just try it.
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.
 
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.
50b97c669f.png


It messes that up. It centres somehow and the timings, memory, db queries stuff is in huge font now.
 
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">).
 
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...
 
Top Bottom