Jump to content

Hide tab based on group


caspert_ghost

Recommended Posts

Below you will find the code for a photo album, the designer does not have a forum or email for answering questions and I need help on this.

In this code there is a section called "tabs" this section creates the tabs: Browse (index.php), My Albums (if user has an album), Hot, recent, views, upload...

 

If user has an album it will show "My Albums", if not it hides this button.

 

I would like to hide "upload" unless user is a member of a specific group.

 

Also there is no way to delete photos which to me is not a good idea, so if someone who knows how to code could assist with:

1: how to hide the "upload" tab

2: how to add a delete button so the user who uploaded may delete AND the admin has the ability to delete any.

thank you

 

Full information and download for the complete code can be found at:

http://www.phpbb.com/community/viewtopic.php?f=70&t=579254&st=0&sk=t&sd=a

 

This is only a partial code script, this is installed with phpbb boards.

<?php
/**
*
* @package Gallery
* @version $Id: gallery.php v0.1.0 12.09.2007 17:52:03 danieLs Exp $
* @copyright (c) danieLs - http://www.safereaction.ro
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

class Gallery
{
var $config;

function load_config()
{
	global $db;

	$sql = 'SELECT *
			FROM ' . GALLERY_CONFIG_TABLE;

	$result = $db->sql_query($sql);
	if ($row = $db->sql_fetchrow($result))
	{
		do
		{
			$this->config[ $row['config_name'] ] = (int) $row['config_value'];
		} 
		while ($row = $db->sql_fetchrow($result));
	}
	$db->sql_freeresult($result);
}

function get_config($name)
{
	return $this->config[$name];
}

function generate_menu($page = GALLERY_PAGE_BROWSE)
{
	global $template, $phpEx, $user, $db;

	$template->assign_block_vars('tabs', array(
		'S_SELECTED'	=> ($page == GALLERY_PAGE_BROWSE ? true : false),
		'U_TITLE'		=> "index.{$phpEx}",
		'L_TITLE'		=> $user->lang['GALLERY_MENU_BROWSE']
		)
	);

	if ($user->data['is_registered'])
	{
		$sql = 'SELECT album_id  
				FROM ' . GALLERY_ALBUMS_TABLE . ' 
				WHERE album_user_id = ' . $user->data['user_id'];
		$result = $db->sql_query($sql);
		if ($row = $db->sql_fetchrow($result))
		{
			$template->assign_block_vars('tabs', array(
				'S_SELECTED'	=> ($page == GALLERY_PAGE_MYALBUM ? true : false),
				'U_TITLE'		=> append_sid("index.{$phpEx}", '?gallery=members&album_id=' . $row['album_id']),
				'L_TITLE'		=> $user->lang['GALLERY_MENU_MYALBUM']
				)
			);
		}
		$db->sql_freeresult($result);
	}

	$template->assign_block_vars('tabs', array(
		'S_SELECTED'	=> ($page == GALLERY_PAGE_HOT ? true : false),
		'U_TITLE'		=> append_sid("hot.{$phpEx}"),
		'L_TITLE'		=> $user->lang['GALLERY_MENU_HOT']
		)
	);
	$template->assign_block_vars('tabs', array(
		'S_SELECTED'	=> ($page == GALLERY_PAGE_RECENT ? true : false),
		'U_TITLE'		=> append_sid("recent.{$phpEx}"),
		'L_TITLE'		=> $user->lang['GALLERY_MENU_RECENT']
		)
	);
	$template->assign_block_vars('tabs', array(
		'S_SELECTED'	=> ($page == GALLERY_PAGE_VIEWS ? true : false),
		'U_TITLE'		=> append_sid("views.{$phpEx}"),
		'L_TITLE'		=> $user->lang['GALLERY_MENU_VIEWS']
		)
	);
	$template->assign_block_vars('tabs', array(
		'S_SELECTED'	=> ($page == GALLERY_PAGE_UPLOAD ? true : false),
		'U_TITLE'		=> append_sid("upload.{$phpEx}"),
		'L_TITLE'		=> $user->lang['GALLERY_MENU_UPLOAD']
		)
	);		
}

function get_albums()
{
	global $db, $user;

	$sql = 'SELECT album_id, album_name  
			FROM ' . GALLERY_ALBUMS_TABLE . '
			WHERE album_parent_id = 0
				AND album_user_id = 0';

	$result = $db->sql_query($sql);

	$options = '<option value="0">' . $user->lang['GALLERY_PERSONAL_ALBUM'] . '</option>
				<option value="-1" disabled="disabled">------------------------------</option>';

	$albums = array();
	if ($row = $db->sql_fetchrow($result))
	{
		do
		{
			$albums[]	= array(
							'album_id'		=> $row['album_id'],
							'album_name'	=> $row['album_name']
						);
		}
		while ($row = $db->sql_fetchrow($result));
	}
	$db->sql_freeresult($result);

	foreach ($albums as $item)
	{
		$options .= '<option value="' . $item['album_id'] . '">|--' . $item['album_name'] . '</option>';

		$sql = 'SELECT album_id, album_name  
				FROM ' . GALLERY_ALBUMS_TABLE . ' 
				WHERE album_parent_id = ' . $item['album_id'] . '
					AND album_user_id = 0';
		$result = $db->sql_query($sql);
		if ($row = $db->sql_fetchrow($result))
		{
			do
			{
				$options .= '<option value="' . $row['album_id'] . '">|   |--' . $row['album_name'] . '</option>';
			}
			while ($row = $db->sql_fetchrow($result));
		}
	}
	$db->sql_freeresult($result);

	return $options;
}	

function handle_upload($form_name = 'fileupload')
{
	global $phpbb_root_path, $phpEx, $user;

	$filedata = array(
		'error'	=> array()
	);

	$upload = new fileupload();

	$filedata['post_attach'] = ($upload->is_valid($form_name)) ? true : false;

	if (!$filedata['post_attach'])
	{
		$filedata['error'][] = $user->lang['NO_UPLOAD_FORM_FOUND'];
		return $filedata;
	}


	$extensions = array();

	if ( (int) $this->config['jpg_allowed'] == 1 )
	{
		$extensions[] = 'jpg';
		$extensions[] = 'jpeg';
	}

	if ( (int) $this->config['gif_allowed'] == 1 )
	{
		$extensions[] = 'gif';
	}

	if ( (int) $this->config['gif_allowed'] == 1 )
	{
		$extensions[] = 'png';
	}

	$upload->set_allowed_extensions($extensions);
	$file = $upload->form_upload($form_name);

	if ($file->init_error)
	{
		$filedata['post_attach'] = false;
		return $filedata;
	}

	if (!$file->is_image())
	{
		$file->remove();
		$filedata['error'][] = $user->lang['ATTACHED_IMAGE_NOT_IMAGE'];
		return $filedata;
	}

	if((int) $this->config['bigger_allowed'] == 0)
	{
		$file->upload->set_allowed_dimensions(0, 0, (int) $this->config['max_width'], (int) $this->config['max_height']);
	}

	$file->clean_filename('unique');
	$file->move_file('gallery/upload/pics', false, false);

	if (sizeof($file->error))
	{
		$file->remove();
		$filedata['error'][] = $file->error;
		$filedata['post_attach'] = false;
		return $filedata;
	}

	if((int) $this->config['bigger_allowed'] == 1)
	{
		if ($file->get('height') > (int) $this->config['max_width'] || $file->get('width') > (int) $this->config['max_height'])
		{
			$destination = $source = $file->get('destination_file');
			if (!$this->create_thumbnail($source, $destination, $file->get('mimetype')))
			{
				$file->remove();
				$filedata['error'][] = $user->lang['GALLERY_ERROR_RESIZEING_PIC'];
				$filedata['post_attach'] = false;
				return $filedata;
			}
		}
	}

	$filedata['filesize'] = $file->get('filesize');
	$filedata['physical_filename'] = $file->get('realname');
	$filedata['real_filename'] = $file->get('uploadname');
	$filedata['filetime'] = time();
	$filedata['mimetype'] = $file->get('mimetype');

	// Check free disk space
	if ($free_space = @disk_free_space($phpbb_root_path . $config['upload_path']))
	{
		if ($free_space <= $file->get('filesize'))
		{
			$filedata['error'][] = $user->lang['ATTACH_QUOTA_REACHED'];
			$filedata['post_attach'] = false;
			$file->remove();
			return $filedata;
		}
	}
	return $filedata;
}

function create_thumbnail($source, $destination, $mimetype, $size = 'large') 
{
	global $config;

	$min_filesize 	= (int) $config['img_min_thumb_filesize'];
	$img_filesize 	= (file_exists($source)) ? @filesize($source) : false;

	if (!$img_filesize || $img_filesize <= $min_filesize)
	{
		return false;
	}

	$dimension = @getimagesize($source);

	if ($dimension === false)
	{
		return false;
	}

	list($width, $height) = $dimension;

	if ($size == 'small')
	{
		$max_width	= 128;
		$max_height	= 128;
	}
	else if ($size == 'med')
	{
		$max_width	= 640;
		$max_height	= 480;
	}
	else
	{
		$max_width	= (int) $this->config['max_width'];
		$max_height	= (int) $this->config['max_height'];
	}

	if (empty($width) || empty($height))
	{
		return false;
	}

	if ($width > $height)
	{
		$new_width	= round($width * ($max_width / $width));
		$new_height	= round($height * ($max_width / $width));
	}
	else
	{
		$new_width	= round($width * ($max_width / $height));
		$new_height	= round($height * ($max_width / $height));
	}


	// Do not create a thumbnail if the resulting width/height is bigger than the original one
	if ($new_width > $width && $new_height > $height)
	{
		$new_width	= $width;
		$new_height	= $height;			
	}

	switch ($mimetype) 
	{
		case 'image/gif':
			$image = @imagecreatefromgif($source);
		break;

		case 'image/jpg':
		case 'image/jpeg':
			$image = @imagecreatefromjpeg($source);
		break;

		case 'image/png':
			$image = @imagecreatefrompng($source);
		break;
	}

	if (function_exists('imagecreatetruecolor'))
	{
		$new_image = imagecreatetruecolor($new_width, $new_height);

		if ($new_image === false)
		{
			return false;
		}

		imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
	}
	else
	{
		$new_image = imagecreate($new_width, $new_height);

		if ($new_image === false)
		{
			return false;
		}

		imagecopyresized($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
	}

	// If we are in safe mode create the destination file prior to using the gd functions to circumvent a PHP bug
	if (@ini_get('safe_mode') || @strtolower(ini_get('safe_mode')) == 'on')
	{
		@touch($destination);
	}

	switch ($mimetype) 
	{
		case 'image/gif':
			imagegif($new_image, $destination);
		break;

		case 'image/jpg':
		case 'image/jpeg':
			$image_quality = ($size == 'small' || $size = 'med') ? (int) $this->config['thumbnail_quality'] : 100;
			imagejpeg($new_image, $destination, $image_quality);
		break;

		case 'image/png':
			imagepng($new_image, $destination);
		break;
	}

	imagedestroy($new_image);


	if (!file_exists($destination))
	{
		return false;
	}

	@chmod($destination, 0666);

	return true;
}

function redirect($meta_url, $message, $delay)
{
	meta_refresh($delay, $meta_url);
	trigger_error($message);
}
}
?>

Link to comment
Share on other sites

I would normally say "Move to third party scripts"..

But you are not allow to change this script

Copyright © 1989, 1991 Free Software Foundation, Inc.

59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Everyone is permitted to copy and distribute verbatim copies

of this license document, but changing it is not allowed.

Link to comment
Share on other sites

the script is a third party script and all of it is released under the gnu license so changing altering the code is ok.

 

the above code is the only section that refers to the link buttons (as tabs) and I want to hide the one tab.

 

There is no (at the moment) any way to delete the photos once uploaded.

 

I want to add a button to delete for admin only for now and will work on user delete later.

Link to comment
Share on other sites

the script is a third party script and all of it is released under the gnu license so changing altering the code is ok.

 

NO. it is not ok.. you should always read the license

 

 

Copyright © 1989, 1991 Free Software Foundation, Inc.

59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Everyone is permitted to copy and distribute verbatim copies

of this license document, but changing it is not allowed.

Link to comment
Share on other sites

read the next paragraph of that same page:

 

The licenses for most software are designed to take away your

freedom to share and change it. By contrast, the GNU General Public

License is intended to guarantee your freedom to share and change free

software--to make sure the software is free for all its users. This

General Public License applies to most of the Free Software

Foundation's software and to any other program whose authors commit to

using it. (Some other Free Software Foundation software is covered by

the GNU Library General Public License instead.) You can apply it to

your programs, too.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.