Integrating Gallery into MovableType - a tutorial
ryandlugosz
Joined: 2002-12-01
Posts: 2 |
Posted: Thu, 2003-03-13 18:33 |
All - Since I didn't see anyone else who's posted a tutorial on how to do this, I posted one myself once I got my Gallery integrated into MovableType. You can view it here: http://dlugosz.net/archives/000005.php Please email me with any comments you have, I'd be happy to hear any suggestions! -Ryan, |
|
Posts: 8
I spent many hours today getting this working. It grabs the last 5 images from my nested album and displays them acrossed my movable type blog.
pthree
http://diversionmary.com
Blog is here http://diversionmary.com/dmblog/
Gallery is here http://diversionmary.com/gallery/art
This is what it looks like in raw php form http://diversionmary.com/dmblog/test.php
And the php/source to do this is such: http://diversionmary.com/dmblog/test.phps
<?
/*
* This little example prints a sorted directory
* listing, with dirs first and files afterwards.
*/
// Open current directory
if($handle = opendir("../albums/drawings")){
// Loop through all files
while(false !== ($file = readdir($handle))){
// Ignore hidden files
if(preg_match ("/thumb/", $file)){
// Put dirs in $dirs[] and files in $files[]
if(is_dir($file)){
$dirs[] = $file;
}else{
$files[] = $file;
}
}
}
// Close directory
closedir($handle);
// if $files[] exists, sort it and print all elements in it. $i = 0;
if(is_array($files)){
rsort($files);
while ($i < 5) {
$test = substr($files[i],0,3); $target_dir="../gallery/drawings";
$thumb_dir="../albums/drawings";
$target_url=substr($files[$i], 0, 3);
echo "<a href=".$target_dir."/".$target_url."><img
src=".$thumb_dir."/".$files[$i]."></a><br> ";
echo "";
$i++;
}
}
}
?>
Posts: 25
Hi,
I tried out the php file you came up with and it seems to work pretty well. only one issue, it generates the 5 thumbnails but the first one isn't an image
<!-- BBCode Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font class="pn-sub">Code:</font><HR></TD></TR><TR><TD><FONT class="pn-sub"><PRE>
<a href=../gallery/dhs/><img src=../albums/dhs/></a><br>
<a href=../gallery/dhs/aaj><img src=../albums/dhs/aaj.thumb.jpg></a><br>
<a href=../gallery/dhs/aai><img src=../albums/dhs/aai.thumb.jpg></a><br>
<a href=../gallery/dhs/aah><img src=../albums/dhs/aah.thumb.jpg></a><br>
<a href=../gallery/dhs/aag><img src=../albums/dhs/aag.thumb.jpg></a><br>
</TD></TR></TABLE><!-- BBCode End -->
Its very odd but its only pulling in 4 thumbnails and the first isn't one of them. Any suggestions?
Posts: 8
hmm weird, can you show me the page? If you toss an "s" after .php (.phps) it is color coded legible source. Perhaps you could try starting over with the source i've included below. Please make note of absolute paths to gallery albums and change to your paths. this will probably alleviate your problems. I also commented things out, so that it would be easier to read and modify. If you have any additional problems please feel free to contact me.
In addition this is what i've monkied my code into, it uses css2 code's to size the image width to 60px, height constrained proportion of that.
here is example:
http://diversionmary.com/dmblog/monkey.php
here is source to example:
http://diversionmary.com/dmblog/monkey.phps
and here is source:
<?
/*
* This grabs all thumbnails from a specified directory
* sorts them in reverse order and displays the last 7 files
* The files are displayed with their thumbnail href'd to the gallery page
* and the images are auto-sized down to 60pixels width, auto-height using
* css2
*/
// Open nested album absolute path
if($handle = opendir("/home/p/pthree/diversionmary.com/albums/drawings")){
// Loop through all files
while(false !== ($file = readdir($handle))){
// Ignore hidden files
if(preg_match ("/thumb/", $file)){
// Put dirs in $dirs[] and files in $files[]
if(is_dir($file)){
$dirs[] = $file;
}else{
$files[] = $file;
}
}
}
// Close nested album
closedir($handle);
// if $files[] exists, sort it and print last N elements in it, reverse order.
$i = 0;
if(is_array($files)){
rsort($files);
//specify how many items should be displayed
while ($i < 7) {
//specify where the nested album is displayed
$target_dir="http://diversionmary.com/gallery/drawings";
//specify where the item's thumbnail exists
$thumb_dir="http://diversionmary.com/albums/drawings";
//specify the object's identity for href, do not modify
$target_url=substr($files[$i], 0, 3);
//specify how the output will look. currently thumbnails will be 60px wide
//with 2 line breaks.
echo "<a href=".$target_dir."/".$target_url."><img
src=".$thumb_dir."/".$files[$i]." style="width: 60px"></a><br><br>";
echo "";
$i++;
}
}
}
?>
Posts: 25
I used the new code and changed
while ($i < 7) {
To
while ($i < 5) {
as you suggested and its working beautifully! Thank you for taking the time to write something that we can all benefit from!
THANK YOU!!!!!!!!
Posts: 8
i have commented the source, monkey.phps but im not going to paste here as ive already cluttered the forum enough :smile:
http://diversionmary.com/dmblog/monkey.phps
Posts: 14
Hi,
This is great, got it working nicely EXCEPt for the href goes to the thumbnail pic, rather than the full size pic. Is this the design or have i done something wrong?
Have used the code below, page is displayed <!-- BBCode Start --><A HREF="http://ukvsaus.com/modules/gallery/lastupdated.php" TARGET="_blank">here</A><!-- BBCode End -->
Any imput would be great,
Cheers,
Steve
Posts: 8
looks like you got it.
Posts: 14
yeah made a few changes and it works on, now i have to put it into a phpnuke block!
new code is below if anyones interested (its the code above but hacked pretty badly. Works though :razz: )
Steve
<?
/*
* This grabs all thumbnails from a specified directory
* sorts them in reverse order and displays the last 7 files
* The files are displayed with their thumbnail href'd to the gallery page
* and the images are auto-sized down to 60pixels width, auto-height using
* css2
*/
//error_reporting(E_ALL);
// Open nested album absolute path
if($handle = opendir("/home/steve/ukvsaus.com/html/modules/albums/album02")){
// Loop through all files
while(false !== ($file = readdir($handle))){
// Ignore hidden files
if(eregi(".thumb.", $file)){
// Put dirs in $dirs[] and files in $files[]
if(is_dir($file)){
$dirs[] = $file;
}else{
$files[] = $file;
}
}
}
// Close nested album
closedir($handle);
// if $files[] exists, sort it and print last N elements in it, reverse order.
$i = 0;
if(is_array($files)){
rsort($files);
//specify how many items should be displayed number must be less than
//or equal to objects in gallery
while ($i < 10) {
//specify where the nested album is displayed
$target_dir="http://ukvsaus.com/modules/albums/album02";
//specify where the item's thumbnail exists
$thumb_dir="http://ukvsaus.com/modules/albums/album02";
//specify the object's identity for href, do not modify
$target_url=substr($files[$i], 0, -9);
//specify how the output will look. currently thumbnails will be 120px wide
//with 2 line breaks.
echo "<a href=".$target_dir."/".$target_url."jpg><img src=".$thumb_dir."/".$files[$i]." style="width: 120px"></a><br><br>";
echo "";
$i++;
}
}
}
?>
Posts: 8
yeah i ended up going with a 0, -9 substr for another person's site (he was matching movable type entries to like-named jpg's) the 0, 3 substr is really only useful if you are pointing to an "album" within gallery (as it forms its url with a 3 letter abbrev) glad you got what you needed working though. perhaps you can post a url to a finished page that is using that code as an example for other people?
Posts: 14
no problems. made a few more changes as well and it seems to be working perfect for me!
code is as follows (ihave commented what changes i have made.) Scripts runs 10 or so individual times as each script is a phpnuke block. Can be seen on the left and right sides of the page <!-- BBCode Start --><A HREF="http://ukvsaus.com" TARGET="_blank">here</A><!-- BBCode End --> . Let me know what you think. steve at ukvsaus.com
Also, a brief disclaimer.....this may not look pretty in some peoples eyes but i'm only new at this....
Cheers,
Steve :lol:
Posts: 3
1.
i get this same thing, but it is because the album i want to use has a nested album within it. so i get links, with no thumbnail. i'd rather it ignored the links that go to sub albums... hmpf.
2. i was wondering about a way to integrate this in a moveabletype category template. where you'd have a MTCategory name and gallery album name the same, so you could include something like this in your Category Archive template: (assuming you use PHP for your MT archive pages)
Sad News : This works only if you do not have spaces in your category names, because moveabletype and gallery 'dirify' in different ways.
Is the MT dirify method better? using _ underscores instead of - dashes... because if you want to use these same names in an XML file for example, or for other uses... the _ won't be misconstrued ...
Does anyone know if there is a way to change the way Gallery 'dirifies' the names?
Posts: 11
I think it would be much easier to "integrate" Gallery1.xx into a better blog open source product called Nucleus:
http://nucleuscms.org/
Has anyone tried that - I may be soon on a client's site.
Stephen
Posts: 4
I built off pthree's code a bit. This picks ten random images from all the albums in your /albums directory (including all subdirectories), displays the thumbnail, then links to the corresponding medium-sized photo in the gallery album.
Unfortunately, I don't have the coding prowess to enable exceptions (ie, private albums, etc), so if any of you have thoughts, they'd be much appreciated.
CF
Posts: 2
I use something slightly different. I don't want my main page to have to be written in php because it doesn't get indexed by search engines (and I'm far too lazy to set last-mod myself).
The code I have will only display non-hidden images. It's biggest flaw is that it doesn't handle sub-albums.
I just use the following code in a file called 'random_photo.php in the /gallery directory:
And then in my blog I have something like the following:
(Note the ?0 is because browsers are far too smart for their own good, so making each a distinct url keeps it from displaying the same image three times).
You can see an example of this in action at http://www.zenzen.org/
Posts: 2
I made a modification because of browsers caching the location tag (so going to the same page over and over wouldn't cycle the images unleas reload was pressed). This reads the image straight out and passes it directly to the browser while setting the expires to force revalidation.
As before, you have to reference each instance uniquely or the browser will just dup the same image out multiple times, so :
Posts: 34
has anyone integrated gallery with moveabletype in such a way that an entire photo album can be displayed in a moveabletype entry?
it seems like the easiest way to do this (for my purposes anyway) would be to have moveabletype create a new album.header file in html_wrap for each entry. then i would modify view_album.php:
<?php includeHtmlWrap("album.header"); ?>
to
<?php includeHtmlWrap("album.header.$albumName"); ?>
and create one MT entry by the name of each gallery album. then i would create a category in my blog called photos and use the MT regex plugin to tell MT to replace links to entries in the "photos" category with a link to the respective gallery album..
thoughts?
p.