MyBB Community Forums

Full Version: Lightbox Image Gallery Plugin
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Could anyone continue this pluggin as it was started but never really finished and would be a shame to just leave it as it is.
Does this work with 1.2.9?
Yes it does work.
Hi, sorry for digging up old threads, but I want to install this plugin on my forum and I ran into some problems.

The plugin activeates successfully and creates the templates in all template sets. But there doesn't appear a link to the gallery anywhere on the forums. Also, when i go to myforums/misc.php?action=ttbox manually I get a message saying "Unable to open".

Interestingly the gallery loads when I add the code on line 165 to the ttbox.php file (it seems to add line feeds in the code box, so if you copy and paste the code below it should be on line 329). It can then see subdirectories and creates a "thumb" link for every image, but it still doesn't create the thumbnail images. The lightbox slideshow works perfectly.

<?php

/*

MyBB 1.2 ttbox Page Plguin

Plugin: Lightbox TripTracker Gallery Page

Author: Adam Eivy

Date:	2007.05.01

Web: 	http://www.OwnYourPhone.com



License:

//	ttbox.php

//	Fully open source modifiable and distributable.

//	I would appreciate any modifications to be emailed to me (antic at shadowpuppet dot net) so I can add improvements to my file as well.

//

// TripTracker has it's own license for the slide.js gallery, visit http://blog.triptracker.net/2006/09/08/revamped-slideshow/ for details

*/



if(!defined("IN_MYBB")){

    die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");

}

$plugins->add_hook("misc_start", "ttbox");



function ttbox_info(){

	return array(

		"name"			=> "Lighbox TripTracker Gallery",

		"description"	=> "Adds a page which contains a Trip Tracker Lightbox gallery.",

		"website"		=> "http://www.OwnYourPhone.com",

		"author"		=> "Adam Eivy",

		"authorsite"	=> "http://adam.shadowpuppet.net",

		"version"		=> "2.0",

	);

}



function ttbox_activate(){

	global $db;



	// Call deactivate function to remove any old settings

	ttbox_deactivate();



	// Insert setting group

	$setting_group_array = array(

		"name" => "ttbox",

		"title" => "Lightbox TripTracker Gallery",

		"description" => "Setup a TripTracker Lightbox image gallery page.",

		"disporder" => 400,

		"isdefault" => "no"

	);

	$db->insert_query(TABLE_PREFIX."settinggroups", $setting_group_array);

	$gid = $db->insert_id();



	$settings = array(

		'ttbox_folder' => array('Image Folder', 'The folder to search for images', 'text', './uploads/downloads/'),

		'ttbox_thumbheight' => array('Thumbnail Height', 'Height in px to downsize thumbnail images (use \'auto\' to make proportional to width)', 'text', '60'),

		'ttbox_thumbwidth' => array('Thumbnail Width', 'Width in px to downsize thumbnail images (use \'auto\' to make proportional to width)', 'text', '80'),

//		'ttbox_grouping' => array('Grouping', 'Should each subfolder be a seperate group?', 'yesno', 'yes'),

		);



	$i = 1;

	foreach($settings as $name => $sinfo){

		$insert_array = array(

			'name' => $name,

			'title' => $db->escape_string($sinfo[0]),

			'description' => $db->escape_string($sinfo[1]),

			'optionscode' => $db->escape_string($sinfo[2]),

			'value' => $db->escape_string($sinfo[3]),

			'gid' => $gid,

			'disporder' => $i,

			);

		$db->insert_query(TABLE_PREFIX."settings", $insert_array);

		$i++;

	}

	rebuildsettings();



	// Attempt to modify header template

	require_once MYBB_ROOT."/inc/adminfunctions_templates.php";

	find_replace_templatesets("header", '#toplinks_help}</a></li>#', "$0\n<li class=\"ttbox_link\"><a href=\"{\$mybb->settings['bburl']}/misc.php?action=ttbox\"><img src=\"{\$theme['imgdir']}/toplinks/ttbox.png\" border=\"0\" alt=\"\" />Gallery</a></li>");



	// Insert 'misc_ttbox' template in to all template sets

	$template = <<<EOF

<head>

<title>{\$mybb->settings['bbname']} - Gallery</title>

{\$headerinclude}

<script type="text/javascript" src="http://slideshow.triptracker.net/slide.js"></script>

</head>

<body>

	{\$header}

	<table border="0" cellspacing="{\$theme['borderwidth']}" cellpadding="{\$theme['tablespace']}" class="tborder" style="clear: both;">

		<tr>

			<td class="thead"><strong>{\$mybb->settings['bbname']} Gallery</strong></td>

		</tr>

		<tr>

			<td class="trow1">

			{\$galleryListHTML}

			</td>

		</tr>

		<tr>

			<td class="trow1">

			<script type="text/javascript">

				<!--

				  var viewer = new PhotoViewer();

				  {\$imageJS}

				//-->

			</script>

			<a href="javascript:void(viewer.show(0))">Slideshow</a>

			{\$imageHTML}

			</td>

		</tr>

	</table>

	{\$footer}

</body>

</html>

EOF;



	$new_template = array(

		"title" => "misc_ttbox",

		"template" => $db->escape_string($template),

		"version" => $mybb->version_code,

		"status" => "",

		"dateline" => time()

	);



	$query = $db->query("SELECT sid FROM ".TABLE_PREFIX."templatesets");

	while($set = $db->fetch_array($query))	{

		$new_template['sid'] = $set['sid'];

		$db->insert_query(TABLE_PREFIX."templates", $new_template);

	}



	return true;

}



function ttbox_deactivate(){

	global $db;



	$info = ttbox_info();

	$result = $db->query("SELECT gid FROM ".TABLE_PREFIX."settinggroups WHERE name='".$info[name]."' LIMIT 1");

	$group = $db->fetch_array($result);



	if(!empty($group['gid'])){

		$db->delete_query(TABLE_PREFIX."settinggroups", "gid='".$group['gid']."'");

		$db->delete_query(TABLE_PREFIX."settings", "gid='".$group['gid']."'");

		$db->delete_query(TABLE_PREFIX."templates", "title='misc_ttbox'");

		rebuildsettings();

	}



	// Attempt to modify header template

	require_once MYBB_ROOT."/inc/adminfunctions_templates.php";

	find_replace_templatesets("header", '#<li class="ttbox_link">(.*)</li>#', '', 0);

}



function ttbox(){

	global $mybb, $templates, $theme, $header, $footer, $headerinclude;



	if($mybb->input['action'] != "ttbox"){

		return;

	}



	add_breadcrumb("Gallery");



	$ttbox_folder = nl2br($mybb->settings['ttbox_folder']);

	$ttbox_thumbwidth = nl2br($mybb->settings['ttbox_thumbwidth']);

	$ttbox_thumbheight = nl2br($mybb->settings['ttbox_thumbheight']);



	if($ttbox_thumbwidth=='auto' && $ttbox_thumbheight=='auto')	$ttbox_thumbheight = 50; // shouldn't auto both

	$imageJS = '';

	$imageHTML = '<br />';

//	$ttbox_folder = "./gallery/";

	$dir_handle = @opendir($ttbox_folder) or die("Unable to open $ttbox_folder");

	// get list of galleries

	$galleryListHTML = 'Select Gallery: <form id="frmGallery" method="POST">';

	$galleryListHTML.= '<select name="gal" id="gal" onChange="document.forms[\'frmGallery\'].submit();">';

	$galList = array();

	while ($file=readdir($dir_handle)) {

		if($file == "." || $file == ".." || $file == "thumbs")	continue;

		// communal graffiti hack

		if(is_dir($ttbox_folder.$file) && preg_match("/(.img)/i",$file)){ // only index directories called ****.img

			array_push($galList,$file);

		}

	}

	sort($galList);

	$options='';

	for($i=0;$i<sizeof($galList);$i++){

		if($_REQUEST['gal']==$galList[$i])	$selected = " selected='selected'";

		else	$selected='';

		$showName = str_replace('.img','',$galList[$i]);

		$options.= '<option value="'.$galList[$i].'"'.$selected.'>'.$showName.'</option>';

	}

	$galleryListHTML.=$options;

	$galleryListHTML.= '</select>';

	$galleryListHTML.= '</form>';

	$num = 0;



	if(isset($_REQUEST['gal']))$gal = $_REQUEST['gal'];

	else	$gal = $galList[0];

	$galFolder = $ttbox_folder.$gal;



	$dir_handle = @opendir($galFolder) or die("Unable to open ".$galFolder);

	$galFolder.='/';

	if(!file_exists($galFolder.'thumbs'))	mkdir($galFolder.'thumbs', 0755);



	// if neither height nor width are set to auto, then set the thumbnail size to absolute

	if($ttbox_thumbheight!='auto' && $ttbox_thumbwidth!='auto')	$abs = ' height="'.$ttbox_thumbheight.'" width="'.$ttbox_thumbwidth.'"';

	else	$abs='';



	// handle file removal case

	if(isset($_REQUEST['rmFile'])){

		if($mybb->user['uid']==1){ // admin

			$ext = get_extension(strtolower($_REQUEST['rmFile']));

			if(file_exists($_REQUEST['rmFileSrc'].$_REQUEST['rmFile']))	unlink($_REQUEST['rmFileSrc'].$_REQUEST['rmFile']);

			$thumb = str_replace('.'.$ext,'_thumb.'.$ext,$_REQUEST['rmFile']);

			if(file_exists($_REQUEST['rmFileSrc'].'thumbs/'.$thumb))	unlink($_REQUEST['rmFileSrc'].'thumbs/'.$thumb);

		}

	}



	// handle file moving case

	if(isset($_REQUEST['mvFile'])){

		if($mybb->user['uid']==1){ // admin

			$ext = get_extension(strtolower($_REQUEST['mvFile']));

			if(file_exists($_REQUEST['mvFileSrc'].$_REQUEST['mvFile']))	rename($_REQUEST['mvFileSrc'].$_REQUEST['mvFile'],$ttbox_folder.$_REQUEST['mvFileDest'].'/'.$_REQUEST['mvFile']);

			$thumb = str_replace('.'.$ext,'_thumb.'.$ext,$_REQUEST['mvFile']);

			if(file_exists($_REQUEST['mvFileSrc'].'thumbs/'.$thumb))	rename($_REQUEST['mvFileSrc'].'thumbs/'.$thumb,$ttbox_folder.$_REQUEST['mvFileDest'].'/thumbs/'.$thumb);

		}

	}



	while ($file = readdir($dir_handle)) {

		if($file == "." || $file == "..")	continue;

		//$fileExt = substr(strrchr($file,"."),1);



		// strip out ' from filenames

		if(preg_match("/'/i", $file)){

			$newFile = str_replace("'","",$file);

			rename($galFolder.$file,$galFolder.$newFile);

			$file = $newFile;

		}

		$ext = get_extension(strtolower($file));

		if(preg_match("/(gif|jpg|jpeg|jpe|bmp|png)$/i", $ext)) {

			$thumbFile = str_replace('.'.$ext,'_thumb.'.$ext,$file);

			$thumbPath = $galFolder.'thumbs/';



			$imageJS.="viewer.add('".$galFolder.$file."');\n";

 			if(!file_exists($thumbPath.$thumbFile)){ // generate thumbnail



				if($abs==''){

					$sizes = @getimagesize($galFolder.$file);

					if($sizes[1]){ // don't divide by zero

						$aspect_ratio = $sizes[0]/$sizes[1]; // width/hieght



						if($ttbox_thumbheight=='auto'){ // figure height

							//if($sizes[0] > $ttbox_thumbwidth){ // width is too big

								$new_width = $ttbox_thumbwidth;

								$maxheight = round(abs($new_width/$aspect_ratio)); // proportional scale

		//					}else{ // width will not change

		//						$new_width = $sizes[0];

		//						if($sizes[1] > $img_max_height){ // height is too big

		//							$maxheight = $img_max_height;

		//						}else{ // height is also ok

		//							$maxheight = $sizes[1];

		//						}

		//					}

						}else{

							$maxheight = $ttbox_thumbheight;

						}

						if($ttbox_thumbwidth=='auto'){

							$new_height = $ttbox_thumbheight;

							$maxwidth = round(abs($new_height/$aspect_ratio)); // proportional scale

						}else{

							$maxwidth = $ttbox_thumbwidth;

						}

						require_once MYBB_ROOT."/inc/functions_image.php";

						generate_thumbnail($galFolder.$file, $thumbPath, $thumbFile, $maxheight, $maxwidth);

					}

				}else{

						require_once MYBB_ROOT."/inc/functions_image.php";

						generate_thumbnail($galFolder.$file, $thumbPath, $thumbFile, $ttbox_thumbheight, $ttbox_thumbwidth);

				}

 			}

			$imageHTML.='<div style="position:relative;padding:10px;float:left;">';

			$imageHTML.='<a href="'.$galFolder.$file.'" rel="ttbox[gal1]" onclick="return viewer.show('.$num.')">';

			$imageHTML.='<img'.$abs.' src="'.$thumbPath.$thumbFile.'" alt="thumb" /></a>';

			if($mybb->user['uid']==1){

				$imageHTML.='<div><form method="POST" name="frmRm'.$num.'" id="frmRm'.$num.'">';

				$imageHTML.='	<input type="hidden" value="'.$galFolder.'" name="rmFileSrc" /><input type="hidden" value="'.$file.'" name="rmFile" /><input type="hidden" value="'.$gal.'" name="gal" /><input onclick="document.forms[\'frmRm'.$num.'\'].submit();" type="button" value="x" />';

				$imageHTML.='</form>';

				$imageHTML.='<form method="POST" name="frmMv'.$num.'" id="frmMv'.$num.'">';

				$imageHTML.='<input type="hidden" value="'.$galFolder.'" name="mvFileSrc" /><input type="hidden" value="'.$file.'" name="mvFile" /><input type="hidden" value="'.$gal.'" name="gal" />';

				$imageHTML.='	<select name="mvFileDest" onchange="document.forms[\'frmMv'.$num.'\'].submit();">';

				$imageHTML.=$options;

				$imageHTML.='	</select>';

				$imageHTML.='</form></div>';

			}

			//$imageHTML.='<input onclick="document.forms[\'frmRm\'].submit();" type="button" value="'.$mybb->user['uid'].'" />';

			$imageHTML.='</div>';



			$num++;

		}

	}



	eval("\$ttbox = \"".$templates->get("misc_ttbox")."\";");

	output_page($ttbox);

}

?>

Is this a version issue? I'm using myBB 1.2.13 and i'm guessing it has something to do with the $mybb->settings['tbox_folder'] bit (line 158, or 315 if you copy and paste the above code). But I don't know what to change it to.

I would really apreciate it if someone could help me with this.

Thanks a lot!

Bennie
Pages: 1 2 3