Search…

X3 Photo Gallery Support Forums

Search…
 
timberline
Topic Author
Posts: 22
Joined: 23 Sep 2012, 13:08

How to automate adding custom XML feed to many sites?

25 Jan 2017, 18:15

We have an application that creates an XML feed for the last 5 entries, similar to an RSS feed for a blog. I have the javascript and CSS to create the objects and display the feed as desired. We show the title (with a hyperlink) and an associated image for those 5 entries on only the Home page. Currently I have only done 1 site as a test and placed it into the Content section of the index page. I understand I could also place the code in Settings > Custom (aside from the div container the script uses).

The issue is I need to automate this with a script so I don't have to use the Panel because we need to install the same thing on many sites. I can inject the necessary code into either page.json for 1.index or config.user.json but then I still have to go into the Panel and Save the appropriate page. I can't inject into the appropriate file in _cache\pages because it wouldn't have been created yet anyway.

What do you suggest to make adding this "feed" functionality as quick and easy as possible on lots of sites? Thank you!
 
User avatar
mjau-mjau
X3 Wizard
Posts: 13998
Joined: 30 Sep 2006, 03:37

Re: How to automate adding custom XML feed to many sites?

26 Jan 2017, 03:36

timberline wrote:The issue is I need to automate this with a script so I don't have to use the Panel because we need to install the same thing on many sites. I can inject the necessary code into either page.json for 1.index or config.user.json but then I still have to go into the Panel and Save the appropriate page. I can't inject into the appropriate file in _cache\pages because it wouldn't have been created yet anyway.
You would always need to do something from the panel. How else would you be able to tell a specific page: "On this page I want to load XML feed and display"? I would have liked to have a more concrete technical description, including links for the XML resources, so I could give a cut-and-paste response. Therefore, my reply will be a bit generic:

1. For each page you want to display this feed, simply add empty element into content:
Code
<div data-obituary></div>
2. In panel settings -> custom -> custom JS, use the x3_page_load() function, and check if the empty element exists:
Code
function x3_load_page(){
  if($('div[data-obituary]').length){
    // element exists, load some stuff into it
    var element = $('div[data-obituary]');
    // YOUR CODE HERE
  }
}
3. Then you would just load the feed, and inject the loaded content into the element
Code
// YOUR CODE HERE
$.get('http://somedomain/somefolder/feed', function (data) {
  // loaded!
});
Basically the #3 above would be similar to what you are already using. So I am not sure how it can get any easier than this ... The site admin simply needs to add <div data-obituary></div> when they want to load the dynamic content. It obviously needs to get activated for a page somehow the panel in any case.
timberline wrote:What do you suggest to make adding this "feed" functionality as quick and easy as possible on lots of sites? Thank you!
Well, you already have the feed no? Just include the custom script into the custom JS settings for your X3 website, and it's ready. To include the feed in a page, user would just need to add the <div data-obituary></div> into the content input for any page.

So the above is to load the feed into X3. I don't have any idea about how feed output is created of course, and it would not have anything to do with X3 so I can't comment on that. Likely you just upload your FEED script into location.
 
timberline
Topic Author
Posts: 22
Joined: 23 Sep 2012, 13:08

Re: How to automate adding custom XML feed to many sites?

26 Jan 2017, 08:16

Yes, the actual feed generation is irrelevant to the issue. The whole reason I started on this entire endeavor was because the designer of the application had used the Google API that had already been deprecated in 2012 when this app was created. Not sure why they did that since the feed was local, but anyway, I came up with a solution that took the feed as-is and processed it in a way similar to what the API had done so I didn't have to touch the application itself because it's one big mess! That worked fine on the X2 pages since they use index.html that I could just inject stuff into. Not so with X3.

From what you're telling me they MUST cut and paste into three different sections (custom CSS, custom JS and Content) using the Panel on every site they want to add the feed to, which leads it ripe for human error. I'll document that very precisely.
 
User avatar
mjau-mjau
X3 Wizard
Posts: 13998
Joined: 30 Sep 2006, 03:37

Re: How to automate adding custom XML feed to many sites?

26 Jan 2017, 10:08

timberline wrote:From what you're telling me they MUST cut and paste into three different sections (custom CSS, custom JS and Content) using the Panel on every site they want to add the feed to, which leads it ripe for human error. I'll document that very precisely.
As far as the comparison with X2 goes, you would of course have to ADD all that script manually to a PHP file anyway on site setup in X2. In X3, you would just paste the code ONCE into custom CSS and custom JS when you setup the website, without editing any files. This would also make it easy to upgrade to new X3 versions because the settings are stored in a user-config without exiting core files, which would break your customization on update. Surely this process would not take more than a few minutes on site setup if you have a recipe ready.

The only reason I can see that might make you think that it's easier in X2, is that you want to create a customized distribution of X3 for upload to multiple websites, without having to add the custom JS CSS on a per-website basis. Am I correct? In this case, you could 1. Set it up on ONE website first, 2. Get the /config/config.user.json file, and add that to your distribution. It will contain the custom JS and custom CSS already, and you can still "upgrade" X3 to latest versions without loosing your customizations.
timberline wrote:three different sections (custom CSS, custom JS and Content).
As for the "third" section "content", surely you want a way for panel admin to be able to control what pages they want to add the feed to though? I can't see how you did this in X2, unless you hardcoded it to a certain page/section. You could of course do the same in X3, and force the feed to load for a specific page. I would have assumed it's practical to have a simple toggle so they can decide on what page(s) to add the FEED. In addition of course, by using a simple tag <div data-feed></div>, they would be able to control from the content editor exactly where they want the feed to appear also.
 
timberline
Topic Author
Posts: 22
Joined: 23 Sep 2012, 13:08

Re: How to automate adding custom XML feed to many sites?

26 Jan 2017, 10:55

mjau-mjau wrote:As far as the comparison with X2 goes, you would of course have to ADD all that script manually to a PHP file anyway on site setup in X2. In X3, you would just paste the code ONCE into custom CSS and custom JS when you setup the website, without editing any files. This would also make it easy to upgrade to new X3 versions because the settings are stored in a user-config without exiting core files, which would break your customization on update. Surely this process would not take more than a few minutes on site setup if you have a recipe ready.
I see the misunderstanding I had with why I thought the old sites were "easy" to do this. They are using X2 for only one section of the site. All the feed processing code was originally in index.html and that is where I changed it. New sites use X3 for everything.
mjau-mjau wrote:The only reason I can see that might make you think that it's easier in X2, is that you want to create a customized distribution of X3 for upload to multiple websites, without having to add the custom JS CSS on a per-website basis. Am I correct? In this case, you could 1. Set it up on ONE website first, 2. Get the /config/config.user.json file, and add that to your distribution. It will contain the custom JS and custom CSS already, and you can still "upgrade" X3 to latest versions without loosing your customizations.
That seems promising so will look into that further. I have made an interface for them that can create a new X3 site by copying any other X3 site they currently have or by using your download zip for a clean install. If they copy a current site, it would obviously copy the feed as well. If I add it to the "base" site as you suggest above, maybe the issue is resolved except for the sites they already have in place.
mjau-mjau wrote:As for the "third" section "content", surely you want a way for panel admin to be able to control what pages they want to add the feed to though? I can't see how you did this in X2, unless you hardcoded it to a certain page/section. You could of course do the same in X3, and force the feed to load for a specific page. I would have assumed it's practical to have a simple toggle so they can decide on what page(s) to add the FEED. In addition of course, by using a simple tag <div data-feed></div>, they would be able to control from the content editor exactly where they want the feed to appear also.
It will always display on only the home page (if at all). Whether left, right, bottom, etc they would have to adjust where the container is placed (or remove it) using the Panel, of course.
 
User avatar
mjau-mjau
X3 Wizard
Posts: 13998
Joined: 30 Sep 2006, 03:37

Re: How to automate adding custom XML feed to many sites?

26 Jan 2017, 11:53

:thumbsup: :star:

Let me know at some point if you need any assistance to integrate it appropriately within the custom JS section.