dynamicly creating NEW xml files

10 posts by 2 authors in: Forums > CMS Builder
Last Post: September 17, 2009   (RSS)

By rez - September 14, 2009

Hello, I have populated flash galleries by changing an xml file to galleryxml.php and using CMS Builder to to fill in the title, category, picture, caption, and description. This works very well.

The problem is that several flash galleries that i want to use have a new xml file for each category desired. So it's not just one xml file for everything. (Usually, I add the cms php to loop and list all categories, pictures, and info in one xml file) With these new galleries, the xml files for future categories don't exist and have to be created for each new category. How do i do this to allow clients to add new categories?

There is a main.xml file that lists all the categories with nodes. And then each category has it's own xml file that has the picture paths nodes.

Setting up the main.xml file to loop and show all new categories is easy. But how can I create these new xml files with CMS Builder each time a category is created in CMS Builder?

thanks!

Re: [rez] dynamicly creating NEW xml files

By Chris - September 15, 2009

Hi rez,

How about having mainXml.php supply category xml files like this?

categoryXml.php?category=1
categoryXml.php?category=2
categoryXml.php?category=3

Does that help?

Which flash galleries require this format? If you can't get this working, I'd like to have a stab at it. :)
All the best,
Chris

Re: [rez] dynamicly creating NEW xml files

By Chris - September 15, 2009

Yes, but you wouldn't need a ++, just use the category record's "num". So your mainXml.php would be a "list page" of categories.

Something like this maybe?

<?php
list($categoryRecords,) = getRecords(array(
'tableName' => 'category',
));
?>
<categories>
<?php foreach ($categoryRecords as $record): ?>
<category>
<name><?php echo $record['name'] ?></name>
<file>categoryXml.php?category=<?php echo $record['num'] ?></file>
</category>
<?php endforeach; ?>
</categories>


I'm not sure if this approach makes sense for your application though. What exactly are these catgeories? An example would be nice. :)
All the best,
Chris

Re: [chris] dynamicly creating NEW xml files

By rez - September 15, 2009 - edited: September 15, 2009

I'll be looking into this further tonight. Here are the examples:

The categories xml file (category1.xml for example):
<images>
<image

thumb="gallery_asset/thumb_images/thumb1.jpg"
main="gallery_asset/main_images/main1.jpg"
url="gallery_asset/main_images/main1.jpg" target="_blank"
title="Title 01"><![CDATA[Description text 01]]>
</image>
</images




data/main xml file:
<data>
<imageCategories>
<Category path="All" buttonCaption="All images" title="all pictures"/>
<Category path="gallery_asset/category1.xml" buttonCaption="Corporate" title="Corporate"/>
<Category path="gallery_asset/category2.xml" buttonCaption="Christmas" title="Merry Christmas"/>
<Category path="gallery_asset/category3.xml" buttonCaption="Abstract" title="3d Abstract"/>
<Category path="gallery_asset/category4.xml" buttonCaption="Nature" title="Nature"/>
<Category path="gallery_asset/category5.xml" buttonCaption="City life" title="City Life"/>
<Category path="gallery_asset/category6.xml" buttonCaption="Videos" title="FLV videos"/>
</imageCategories>
</data>

Re: [rez] dynamicly creating NEW xml files

By Chris - September 15, 2009

So, assuming you wanted CMS Builder to manage these categories, your mainXml.php file would look something like this:

<?php
list($categoryRecords,) = getRecords(array(
'tableName' => 'category',
));
?>
<data>
<imageCategories>
<Category path="All" buttonCaption="All images" title="all pictures"/>
<?php foreach ($categoryRecords as $record): ?>
<Category path="categoryXml.php?category=<?php echo $record['num']; ?>" buttonCaption="<?php echo htmlspecialchars($record['name']); ?>" title="<?php echo htmlspecialchars($record['name']); ?>"/>
<?php endforeach; ?>
</imageCategories>
</data>


And your categoryXml.php file would look something like this:

<?php
list($imagesRecords,) = getRecords(array(
'tableName' => 'images',
));
?>
<images>
<?php foreach ( $imagesRecords as $record ): ?>
<?php foreach ( $record['uploads'] as $upload ): ?>
<image
thumb="<?php echo htmlspecialchars($upload['thumbUrlPath']); ?>"
main="<?php echo htmlspecialchars($upload['urlPath']); ?>"
url="<?php echo htmlspecialchars($upload['urlPath']); ?>"
target="_blank"
title="<?php echo htmlspecialchars($upload['info1']); ?>"><![CDATA[<?php echo $upload['info2']; ?>]]>
</image>
<?php endforeach; ?>
</images>


I'm making some assumptions about how you've got your CMS Builder sections configured. If you want them set up a different way, please explain it and I'll show you how to generate XML for that instead.

Hope this helps! :)
All the best,
Chris

Re: [chris] dynamicly creating NEW xml files

By rez - September 16, 2009 - edited: September 16, 2009

I'm testing this but can't get it to work. I do want to create the categories in CMS Builder. I want clients to control categories and uploads. The problem with the way it's done above is that all the pictures are in one editor. I had it set to 25 per upload. If there are hundreds of pictures in each category, I think it will be hard to manage them. It would be better to have an editor per category for images. ? Or something to better manage the pictures. I don't know the best way to manage a lot of pictures and categories right now with CMS Builder, but if I get this to work either way, i should be able to figure out how to change things.

The second problem with the above way is that the description could be a whole paragraph including links or other html that works in flash. So the info2 field is too small for that. A text box would be better.

Anyway, i didn't get it to work. Looking at the source pages of the xml.php files, everything looks good. I'm thinking Flash doesn't like the file names like categoryXml.php?category=1. but I read that flash doesnt care what the extension is.

I tried to attach the original working files, zipped since you mentioned you would like to try it but the attachment was too large. Is there somewhere I can upload or e-mail it? It's 11 mb because of the pics. Without them, its around 2. I can also send you a link to the zip in a text file attachment?

Let me know. It would be interesting to see this working. I can use a different gallery but would really like to learn how to do this to master different CMS Builder ideas.

Re: [rez] dynamicly creating NEW xml files

By Chris - September 17, 2009

Hi rez,

The problem with the way it's done above is that all the pictures are in one editor.


I'll try to think of a solution for this.

...the info2 field is too small...


If you set things up with one image per record, you can use another field in the record for a description (and the title!)

I tried to attach the original working files...


Do you have anywhere you can host the zip and send a link? There are also many free web services for uploading (large) files.
All the best,
Chris

Re: [chris] dynamicly creating NEW xml files

By rez - September 17, 2009

"If you set things up with one image per record, you can use another field in the record for a description (and the title!) "

I considered that. Then a client is limited to uploading 1 picture at a time. Although this also gives other category and management options, with a large site i have coming up (lot's of old scanned and uploaded pictures by the client), it could be pretty inconvenient to upload 1 picture at a time.

I sent you a PM with a link to my zip.

Re: [rez] dynamicly creating NEW xml files

By Chris - September 17, 2009

Hi rez,

Hmm, yes, would be somewhat tedious. I'm going to try to come up with a feature request or two on this topic, but no promises!

So, the other solution would be to have one record per category and remove the "maximum number of uploaded images" restriction on the upload field. That should work well, except for the field length restriction on the info fields.

Optionally, we could extend the info fields with some custom programming or with a custom plugin. Please let me know if you're interested in that.
All the best,
Chris