...

View Full Version : wordpress pictures galery



Mihai
12-14-2008, 06:24 AM
I am using this script on my webblog to post some pictures, can someone show me how to split in to more pages the output ( i have some galeries with more then 200 pictures that dont need to load in the same page, and the final result can be modified to be more then 450?

$dw=750 does not change the defaut 450


<?php
/* Plugin Name: Gallery
Version: 0.1.7
Plugin URI: http://blog.perfectspace.com/2006/03/28/duh-gallery-the-simple-wordpress-photo-gallery-plugin/
Description: Makes a gallery out of the uploaded files in the wp-content/uploads folder that are above a certain size.
Uses the default folder hierarchy for album titles.
Just paste <?php do_action('duh_gallery'); ?> into the page you want to use as your photo album
Author: Nate Ritter
Author URI: http://blog.perfectspace.com/

Version History
---------------------------------------------------------------------------
2006-03-28 0.1.1 First release
2006-03-28 0.1.2 Added thumbnail display instead of full image
Added display width ($dw) as an optional element (buggy though)
2006-03-29 0.1.3 Added next/previous links to enlarged image page
2006-03-29 0.1.4 Added support for not-nice permalinks
2006-03-31 0.1.5 Added better sorting
2006-04-10 0.1.6 Fixed construct error in PHP5
2006-04-24 0.1.7 Fixed else error (thanks to "mr nice ash" at http://dhost.info/mrniceash)
*/
class Duh_Gallery {
var $min_width;
var $min_height;

function Duh_Gallery($dw=750, $mw=300, $mh=300)
{
global $min_width, $min_height;
// CHANGE THE LINE BELOW TO FIT YOUR UPLOAD PATH
// ToDo: get the location from the db (get_option('fileupload_realpath') and get_option('fileupload_url') don't work)
$subdir = 'wp-content/uploads';

$min_width = $mw;
$min_height = $mh;
$dw = (empty($dw) ? 750 : $dw); // Todo: Fix this... not sure why it's not using the default
$p_struct = get_option('permalink_structure');
if (empty($p_struct)) {
if (!empty($_GET['page_id'])) {
$p_type = 'page_id';
$p_id = $_GET['page_id'];
} else {
$p_type = 'p';
$p_id = $_GET['p'];
}
}
$dir = ABSPATH.$subdir;
$array = Duh_Gallery::showDirectory($dir);
$str_path = $_GET['path'];
$f = $_GET['f'];
if (!empty($str_path)) $path = explode('/', $str_path);
$contents = $array;

if (!empty($path)) {
foreach ($path as $v) {
$contents = $contents[$v];
}
}
if (!empty($contents)) {
foreach ($contents as $k => $v) {
if (is_array($v)) {
$folders[] = $k;
} else {
$files[] = $v;
}
}
}
echo '<div id="duh_gallery_photos"><h3>Selecteaza cartea:</h3><p><a href="?page_id=10">Meniu principal</a> ';
if (!empty($path)) {
for ($i=0; $i<count($path); $i++) {
if ($i==0) {
echo ' &raquo; ';
echo (empty($p_struct) ? "<a href=\"?$p_type=$p_id&path=" : "<a href=\"?path=");
echo $path[$i].'">'.$path[$i].'</a>';
} else {
echo ' &raquo; ';
echo (empty($p_struct) ? "<a href=\"?$p_type=$p_id&path=" : "<a href=\"?path=");
for ($j=0; $j<$i; $j++) {
echo $path[$j].'/';
}
echo $path[$i].'">'.$path[$i].'</a>';
}
}
}
echo '</p>';
if (!empty($folders)) {
sort($folders);
echo '<h3>Carti:</h3><p> ';
for ($i=0; $i<(count($folders)); $i++) {
if ($i != 0) {
echo (empty($p_struct) ? "<a href=\"?$p_type=$p_id&path=" : "<a href=\"?path=");
if (!empty($str_path)) echo $str_path.'/';
echo $folders[$i-1].'">'.$folders[$i-1].'</a> | ';
}
}
echo (empty($p_struct) ? "<a href=\"?$p_type=$p_id&path=" : "<a href=\"?path=");
if (!empty($str_path)) echo $str_path.'/';
echo $folders[count($folders)-1].'">'.$folders[count($folders)-1].'</a></p>';
}
if (empty($f)) {
if (!empty($files) && !empty($files[0])) {
sort($files);
echo '<h3>Files:</h3>';
if (count($files)>0) {
echo '<p class="attachment"> ';
}
foreach ($files as $v) {
# Make thumbnail and make sure it exists
$vf = substr_replace($v, '.thumbnail.', strrpos($v, '.'), (strpos($v, '.') - strlen($v) +1));
if (file_exists("$dir/$str_path/$vf")) {
# Show the thumbnail since it exists. Don't define the width.
echo (empty($p_struct) ? "<a href=\"?$p_type=$p_id&path=" : "<a href=\"?path=");
echo "$str_path&f=$v\" title=\"$v\" ><img src=\"".get_bloginfo('home')."/$subdir/$str_path/$vf\" alt=\"\"/></a>";
} else {
# my code added here
$directory="$subdir/$str_path";
Duh_Gallery::createThumb($vf, $v, $directory);
# end of modifcation
# Show the original at 100px wide
echo (empty($p_struct) ? "<a href=\"?$p_type=$p_id&path=" : "<a href=\"?path=");
echo "$str_path&f=$v\" title=\"$v\" ><img src=\"".get_bloginfo('home')."/$subdir/$str_path/$v\" width=\"150\" alt=\"\"/></a>";
}
}
if (count($files)>0) {
echo '</p>';
}
}
} else {
if (count($files)>0) {
echo '<h3>Pagina:</h3><p class="attachment">';
}
if (!empty($files)) {
sort($files);
$start = 0;
$end = count($files)-1;
$here = array_search($f, $files);
if ($here>0) { echo (empty($p_struct) ? "<a href=\"?$p_type=$p_id&path=" : "<a href=\"?path="); echo "$str_path&f=".$files[$here-1]."\">&laquo; Pagina precedenta</a> "; }
if ($end>1 && $here>0 && $here<$end) { echo ' | '; }
if ($here<$end) { echo (empty($p_struct) ? "<a href=\"?$p_type=$p_id&path=" : "<a href=\"?path="); echo "$str_path&f=".$files[$here+1]."\">Pagina urmatoare &raquo;</a>"; }
if ($end>$start) { echo "<br />"; }
}
if (count($files)>0) {
echo "<img src=\"".get_bloginfo('home')."/$subdir/$str_path/$f\" width=\"$dw\" />";
echo '</p>';

//echo get_bloginfo('home'),"/",$subdir,"/",$str_path,"/",$f;

// <<THIS IS MY MODIFICATION>>
$sql = "SELECT post_title,guid FROM wp_posts;";
$result = mysql_query($sql) OR die(mysql_error());
$compare = get_bloginfo('home')."/".$subdir."/".$str_path."/".$f;

while($row = mysql_fetch_assoc($result)) {if ($row['guid']==$compare)
echo $row['post_title']." <br />\n";
}
echo '</p>';
echo "(Picture ",$here+1," of ",$end+1,")";
// <<END OF MY MODIFICATION>>

}
}
echo '<br style="clear:both;"/></p></div>';
}

# my function added
function createThumb($vf, $org, $directory)
{
$thumbWidth=100;
$origImg = imagecreatefromjpeg("$directory"."/$org");
$origWidth = imagesx($origImg);
$origHeight = imagesy($origImg);

$dimension = $origWidth / $thumbWidth;
$thumbHeight = $origHeight / $dimension;

$thumbImg = imageCreateTrueColor($thumbWidth, $thumbHeight);
imageCopyResampled($thumbImg, $origImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $origWidth, $origHeight);

imagejpeg($thumbImg, "$directory"."/$vf");
imagedestroy($origImg);
imagedestroy($thumbImg);
}

function showDirectory( $directory = '.', $level = 0 ) {
global $min_height, $min_width; // In general, these directories should be ignored
// ToDo: add .jpg, .jpeg, and .png files that are above a specified width/height only
$ignore = array( '.', '..', 'cgi-bin' );
$dh = opendir( $directory );
while( false !== ( $file = readdir( $dh ) ) ){ // Just check the file isn't in the ignore array
if( !in_array( $file, $ignore ) ){
if( is_dir( "$directory/$file" ) ){
$array[$file] = Duh_Gallery::showDirectory("$directory/$file", ($level+1)); } else {
$details = getimagesize($directory.'/'.$file);
if ($details[0] >= $min_width && $details[1] >= $min_height) {
$array[] = $file;
} } } } closedir( $dh );
return $array; }}

add_action('duh_gallery', array('Duh_Gallery', 'Duh_Gallery'), 5, 3);
?>




thank you a lot

Mihai
12-14-2008, 06:42 AM
http://www.cetatea.info/2008/12/14/?path=oameni%20mari%20ai%20Romaniei

Split an array to many pages?
count($lines) / 40;?

Mihai
12-14-2008, 10:22 AM
// styles
function lightbox_styles() {
$lightbox_path = get_option('siteurl')."/wp-content/plugins/lightbox-2-wordpress-plugin/lightbox/";
$lightboxscript.= "<script type=\"text/javascript\"> lb_path = \"$lightbox_path\"; </script>\n";
$lightboxscript.= "<link rel=\"stylesheet\" href=\"".$lightbox_path."css/lightbox.css\" type=\"text/css\" media=\"screen\" />\n";
$lightboxscript.= "<script type=\"text/javascript\" src=\"".$lightbox_path."js/prototype.js\"></script>\n";
$lightboxscript.= "<script type=\"text/javascript\" src=\"".$lightbox_path."js/scriptaculous.js?load=effects,builder\"></script>\n";
$lightboxscript.= "<script type=\"text/javascript\" src=\"".$lightbox_path."js/lightbox.js\"></script>\n";
print($lightboxscript);
}
// function lightbox_create($content){
// return preg_replace('/<a(.*?)href=(.*?).(jpg|jpeg|png|gif|bmp|ico)"(.*?)>/i', '<a$1href=$2.$3" $4 rel="lightbox[roadtrip]">', $content);
// }
// add_filter('the_content', 'lightbox_create', 2);
add_action('wp_head', 'lightbox_styles');


any way that i can load this in ?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum