Sign in to follow this  
Gnac

PHP-based one-script LXF Gallery Viewer-thing!

Recommended Posts

I've been hoarding this thing for a while - it was a proof of concept which formed the basis of a personal inventory management app which I've lost interest in, but I kept it because it performs its purpose so well.

If you have a PHP enabled webserver or localhost, this script can scan a folder of LXF files and return some useful information, such as the thumbnail image, brick count, LDD version and brickset.

257a6lxg4gv20j26g.jpg

It's probably not suitable for reading several hundred files at once, but I hope it will be interesting and useful to novices and experts alike, perhaps even serving as a basis for your own projects.

See the thing here! (demo with some MOCs / official models, using a mix of internal and external image previews)

Get the thing here! (link updated: 2014-12-10)

CHANGELOG (full changelog is included with the readme, also viewable here)

20141210 @ 16:11

  • [bugfix] Added a check on the main gallery loop to supress a script error when no LXFs are found.
  • [bugfix] Completely removed the XML parsing "function" responsible for the "file_exists()" issue - the functionality is used only once per loop, and can be done in a single line anyway.

Edited by Gnac

Share this post


Link to post
Share on other sites

That looks nice! Altough I haven't any localhost or webserver with php at the moment (I had in the past), I'll sure try this out sometime. It's funny though; I was thinking about the same kind of thing, but for LDraw files :tongue:

Share this post


Link to post
Share on other sites

Very good work.

Here is a test with my Official Sets creations.

It seems the script "eat" the first digit of the filename.

Another little improvement could be to allow set's name to be wrapped in more lines, to avoid the excessive enlargement of the thumbnail. Or, maybe even better, use the suspension points for characters that exceed a certain length and a tooltip to show the complete name.

Share this post


Link to post
Share on other sites

That looks nice! Altough I haven't any localhost or webserver with php at the moment (I had in the past), I'll sure try this out sometime. It's funny though; I was thinking about the same kind of thing, but for LDraw files :tongue:

LDraw files are a very different beast from LXFMLs (XML-based), but I have experience with creating libraries to parse specialised data formats, and parsing shouldn't pose a problem, considering the "open-source" nature of LDraw and its various supporting projects.

I'm happy that the LDD team chose standard formats such as ZIP files and XML, though - since PHP has the ability to deal with these things effortlessly. One day, I will get around to reading the documentation provided by Superkalle properly, and implementing it in a useful way (like all them Jedi trix).

If I manage to create something satisfactory, I wonder if it may even form the basis of a redesigned digital model repository for EuroBricks!

:doushio:

Share this post


Link to post
Share on other sites

Very good work.

Here is a test with my Official Sets creations.

It seems the script "eat" the first digit of the filename.

Another little improvement could be to allow set's name to be wrapped in more lines, to avoid the excessive enlargement of the thumbnail. Or, maybe even better, use the suspension points for characters that exceed a certain length and a tooltip to show the complete name.

I've updated the link in the first post, with a new file which I hope fixes these issues. The "first letter eating thing" was a due to personal preference, and also because I didn't properly "clean up" the script for public use (this is fixed). I've also implemented your layout suggestions in the CSS rules.

Share this post


Link to post
Share on other sites

[...]

If I manage to create something satisfactory, I wonder if it may even form the basis of a redesigned digital model repository for EuroBricks!

I once made a simple setup for this with aspx. Sadly, I lost it in a crash :sceptic:

Although I don't know if it will work with EB. Of course you can make a site with a repository of all LDD or LDraw files/models, but how do you incorporate it in EB?

Share this post


Link to post
Share on other sites
I've updated the link in the first post, with a new file which I hope fixes these issues. The "first letter eating thing" was a due to personal preference, and also because I didn't properly "clean up" the script for public use (this is fixed). I've also implemented your layout suggestions in the CSS rules.

Thanks for that!

Anyway I meant the set's name, not the filename! :tongue:

That because it is the set's name that usually enlarge the box (the filename has the whole line).

Add this rule to the filename too is the best choice, anyway!

EDIT: look at my gallery now, I modified a bit your script to achieve what I mean.

The result is much more... aligned! :grin:

Share this post


Link to post
Share on other sites

I once made a simple setup for this with aspx. Sadly, I lost it in a crash :sceptic:

Although I don't know if it will work with EB. Of course you can make a site with a repository of all LDD or LDraw files/models, but how do you incorporate it in EB?

I don't know the first thing about Microsoft's ASP, but seeing that Eurobricks' forums run on PHP, I assume that the modules to run this script are present. It really depends on how the site administrators feel about implementing this functionality. I have no idea of how busy they are (most likely VERY), so it may be something which is simply not possible due to time, no matter how interesting the concept. I am willing to take up the challenge of integrating it, but then there is the matter of trust. This may be a thing which can be worked out through THE POWER OF SUGGESTION.

I've considered setting up a site for this sort of thing, but I'd really like it to live here, where there is already a community of dedicated contributors and administrators (many of my own websites just DIED through apathy, LOL).

Share this post


Link to post
Share on other sites

Well, I don't know too much about asp either, but my knowledge is growing slowly (partly because of a friend who is like a VB master), like it did with html, css and js and is doing with php and ruby.

Anyway, I choose for asp back then because

1- I wanted to learn by doing :wink:

2- We have all the models (LDD and LDraw) in an access database and asp and access are good friends. Although you can of course just export the access databese to sql or whatever

Share this post


Link to post
Share on other sites

I've in mind other two modifies, Gnac:

- make the whole "file" line (the one containing the name of the file and with the gray background) clickable to download the file (example).

- click on the thumbnail don't start the download of the file but open an image with a better resolution, if any (the script should search inside the folder if there is an image with the same name of the lxf file).

Share this post


Link to post
Share on other sites

It looks like I missed your example while my mobile internet was crapping itself, but those ideas are actually things I intended to do for my own abandoned project, so the work was halfway done already.

The challenge was finding a lightbox script compact enough to keep everything in one file. I cheated by having an external link to Google's hosted jQuery library, because everything requires jQuery these days.

DAMN THAT JQUERY AND ITS WHOLE EVERYTHING.

Share this post


Link to post
Share on other sites

In the meantime I modified the link. Here is a working one.

As I had a bit of time, I was trying something similar to a lightbox or a popup for a bigger image, but results don't satisfy me.

I think it is important to don't use frameworks to make the gallery as much compatible as possible.

At the moment one of the greatest difficulties is to center the image box on the page without retrieving image data.

Maybe it is impossible and I'll (you'll :tongue: ) have to transfer that data (the function I made is bare but arranged for this).

Here is the "WIP" gallery (box is in fixed position).

Do you want my php files?

Share this post


Link to post
Share on other sites

I think it is important to don't use frameworks to make the gallery as much compatible as possible.

Yeah, I wasn't happy about relying on jQuery, but my own solution ran into the same problem.

I've uploaded it here, for curiosity's sake.

Do you want my php files?

It can't hurt to take a look, maybe we've tackled the same problem from different angles.

Share this post


Link to post
Share on other sites

You added much code!

I'm trying to minimize the complexity of the gallery as much as possible.

Here is the last "wip" file (it is a sort of draft in some points).

Later I'll try to add image's data to center the box.

EDIT: I updated the link of the WIP version, because I added the code to center the box.

The preview is ever at the same link.

PS: your file gives a little layout problem with my gallery, there are some blank spaces.

Share this post


Link to post
Share on other sites

Hi Gnac and Calabar, interesting development... can you post the final versions, as the link in the post renders a "file not found" error. TIA

Share this post


Link to post
Share on other sites

Here are the links of my version of Gnac's gallery.

Here is the gallery.

Here is the source file (the last two WIP versions).

Edited by Calabar

Share this post


Link to post
Share on other sites

Hee, great that there's still interest for this. It had been buried under other projects and forgotten, and I had no idea that Dev-Host links could expire.

The first post has been updated with a (hopefully more persistent) Mediafire link. Also, thanks Calabar for hanging on to past releases, because I have terrible version control.

Share this post


Link to post
Share on other sites

It seems that some kind of update (in php runtime or in its configuration) generate a warning in my gallery (the gallery is still there under the warnings).

The error is clear, but now I've not time to look at the problem, but if someone has fixed it already... could report the solution?

Gnaaaac? :tongue:

Edited by Calabar

Share this post


Link to post
Share on other sites

!

I forgot to make a "nudge" post when I updated the OP. As well as a fix for the above issue, there's a new download link (on my OWN SITE!) which should never accidentally expire.

Share this post


Link to post
Share on other sites

Great, I'll integrate my version soon!

Did you simply removed the check or you replaced it in some way?

Edited by Calabar

Share this post


Link to post
Share on other sites

Wagh, I'm afraid you'll need to download it again, because I realised that the check is actually redundant (no need to get external XML from anywhere), so I removed the whole function and just replaced it with a single, efficent line.

$dat = xml_to_arr ($data_xml);

Got replaced with

$dat = json_decode (json_encode (simplexml_load_string ($data_xml) ), true);

Since that was really the only purpose of the function, anyway. I just used something from my own little code library, but forgot to remove the unnecessary stuff D:

Share this post


Link to post
Share on other sites

Yes, I took a look at the code.

In the previous file it seems you simply hush the warning with the @, but the xml_to_arr made a check that failed every time (it checked for a file but the path was a whole xml, and the true condition, if used, would generate a warning it too).

Now it has much more sense. :wink:

Here is the gallery.

Here is the source file (the last WIP version).

Edited by Calabar

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.