################################################################
## Hack Title:		Music Song Image (Music Online Mod by Cf Manager) 
## Hack Version:	1.0.1 (ex phpbb 2.0.8)
## Hack Author:		Cf Manager < cf_manager@yahoo.com > (Vincent Thai)
## Support:		http://cfmanager.net.tf
##
## Description:	 	Add the Song Image to the section of each song.
##			(Maybe CD Cover, Artist Photo or any image you want ;)
##
## Features:		- Maximum image size
##
## Compatibility:	2.0.4 --> 2.0.9 (I tested on phpBB 2.0.6, 2.0.8 & 2.0.9)	 
##
## Installation Level:	Advanced
## Installation time:	10 - 15 min
## Files to edit:	8
##			admin/admin_music_config.php
##			music_upload.php
##			music_page.php
##	                language/lang_english/lang_main_music.php
##	                language/lang_english/lang_admin_music.php
##              	templates/subSilver/admin/music_config_body.tpl
## 	                templates/subSilver/music_upload_body.tpl
##      	        templates/subSilver/music_page_body.tpl
##
## Included Files:	3
##			music_box/upload/song_image/.htaccess
##			music_box/upload/song_image/index.html
##			music_box/upload/song_image/no_image.gif 
##
################################################################
## Installation/Author Notes:
##
## 	This HACK adds new column to 'phpbb_music' and 'phpbb_music_config' table.
## 	Full support for this HACK can be obtained at: http://cfmanager.net.tf 
## 	This Hack was tested with the following databases: MySQL 
################################################################
## Hack History:
##		22/07/2004 v1.0.1: more fixed bugs
## 		12/06/2004 v1.0.0: First Release :)
################################################################
## This HACK is released under the GPL License.
################################################################
## BEFORE, ADDing This HACK To Your Forum, You Should Back Up All Files Related To This HACK
################################################################
################################################################
#
#-----[ SQL ]---------------------------------------------------
#
# Copy asi_update.php to your root directory and execute it with your navigator 
# and after delete it.
# You can do it manually by the way copy the followings

ALTER TABLE phpbb_music ADD song_imagename VARCHAR(255) NOT NULL AFTER song_filename;
INSERT INTO phpbb_music_config VALUES ('max_image_size', '10240');
INSERT INTO phpbb_music_config VALUES ('max_image_width', '300'); 
INSERT INTO phpbb_music_config VALUES ('max_image_height', '200');

#
#-----[ COPY ]--------------------------------------------------
#
COPY root/music_box/upload/song_image/*.htaccess TO music_box/upload/song_image/
COPY root/music_box/upload/song_image/index.html TO music_box/upload/song_image/
COPY root/music_box/upload/song_image/no_image.gif TO music_box/upload/song_image/

#
#-----[ OPEN ]--------------------------------------------------
#  
admin/admin_music_config.php

# 
#-----[ FIND ]--------------------------------------------------
# 
	'TOP' => $new['top'],

# 
#-----[ AFTER, ADD ]---------------------------------------------
# 
	//
	// Song image
	//
	'MAX_IMAGE_SIZE' => $new['max_image_size'],
	'MAX_IMAGE_WIDTH' => $new['max_image_width'],
	'MAX_IMAGE_HEIGHT' => $new['max_image_height'],

# 
#-----[ FIND ]--------------------------------------------------
# 
	'L_TOP' => $lang['Top'],

# 
#-----[ AFTER, ADD ]---------------------------------------------
# 
	//
	// Lang Song image
	//
	'L_MAX_IMAGE_SIZE' => $lang['Max_image_size'],
	'L_MAX_IMAGE_WIDTH' => $lang['Max_image_width'],
	'L_MAX_IMAGE_HEIGHT' => $lang['Max_image_height'],

#
#-----[ OPEN ]--------------------------------------------------
#
language/lang_english/lang_admin_music.php

# 
#-----[ FIND ]--------------------------------------------------
# 
?>

# 
#-----[ BEFORE, ADD ]--------------------------------------------
# 
//
// Song Image
//
$lang['Max_image_size'] = 'Max song image size (bytes)';
$lang['Max_image_width'] = 'Max song image width (pixel)';
$lang['Max_image_height'] = 'Max song image height (pixel)';


#
#-----[ OPEN ]--------------------------------------------------
#
templates/subSilver/admin/music_config_body.tpl

# 
#-----[ FIND ]--------------------------------------------------
# 
	<tr>
	  <td class="row1"><span class="genmed">{L_TOP}</span></td>
	  <td class="row2"><input class="post" type="text" maxlength="2" size="2" name="top" value="{TOP}" /></td>
	</tr>

# 
#-----[ AFTER, ADD ]---------------------------------------------
# 
	<tr>
	  <td class="row1"><span class="genmed">{L_MAX_IMAGE_SIZE}</span></td>
	  <td class="row2"><input class="post" type="text" maxlength="10" size="6" name="max_image_size" value="{MAX_IMAGE_SIZE}" /></td>
	</tr>
	<tr>
	  <td class="row1"><span class="genmed">{L_MAX_IMAGE_WIDTH}</span></td>
	  <td class="row2"><input class="post" type="text" maxlength="3" size="2" name="max_image_width" value="{MAX_IMAGE_WIDTH}" /></td>
	</tr>
	<tr>
	  <td class="row1"><span class="genmed">{L_MAX_IMAGE_HEIGHT}</span></td>
	  <td class="row2"><input class="post" type="text" maxlength="3" size="2" name="max_image_height" value="{MAX_IMAGE_HEIGHT}" /></td>
	</tr>

################################################################
# 
#-----[ OPEN ]--------------------------------------------------
#  
music_upload.php

# 
#-----[ FIND ]--------------------------------------------------
# 
$music_root_path = $phpbb_root_path . 'music_box/';

# 
#-----[ AFTER, ADD ]---------------------------------------------
# The directory of song images
$song_image_path = $phpbb_root_path . 'music_box/upload/song_image/';

# 
#-----[ FIND ]--------------------------------------------------
# 
		'L_UPLOAD_SONG_FROM_MACHINE' => $lang['Upload_song_from_machine'],

# 
#-----[ AFTER, ADD ]---------------------------------------------
# 
		'L_SONG_IMAGE' => $lang['Song_image'],
		'L_SONG_IMAGE_DESC' => $lang['Song_image_desc'],
		'L_NO_IMAGE' => $lang['No_image'],
		'L_UPLOAD_IMAGE' => $lang['Upload_image'],

# 
#-----[ FIND ]--------------------------------------------------
# 
	$song_url = str_replace("\'", "''", htmlspecialchars(trim($HTTP_POST_VARS['song_url'])));

# 
#-----[ AFTER, ADD ]---------------------------------------------
# 
	$image_system = str_replace("\'", "''", htmlspecialchars(trim($HTTP_POST_VARS['image_system'])));


# 
#-----[ FIND ]--------------------------------------------------
# 
	$filetmp = $HTTP_POST_FILES['song_file']['tmp_name'];

# 
#-----[ AFTER, ADD ]---------------------------------------------
# 
	// --------------------------------
	// Get Song Image Upload Info
	// --------------------------------

	$imagetype = ( !empty($HTTP_POST_FILES['song_image']['type']) ) ?  $HTTP_POST_FILES['song_image']['type'] : '';
	$imagesize = ( !empty($HTTP_POST_FILES['song_image']['size']) ) ?  $HTTP_POST_FILES['song_image']['size'] : 0;
	$imagetmp = ( !empty($HTTP_POST_FILES['song_image']['tmp_name']) ) ?  $HTTP_POST_FILES['song_image']['tmp_name'] : '';

	// --------------------------------
	// Check image size
	// --------------------------------

	if( $image_system == '1' )
	{
		if( $imagesize > $music_config['max_image_size'] )
		{
			message_die(GENERAL_MESSAGE, $lang['Bad_upload_image_size']);
		}
	}

	// --------------------------------
	// Check image type
	// --------------------------------

	if( $image_system == '1' )
	{
		switch ($imagetype)
		{
			case 'image/jpeg':
			case 'image/jpg':
			case 'image/pjpeg':
				$song_imagetype = '.jpg';
				break;

			case 'image/gif':
				$song_imagetype = '.gif';
				break;

			case 'image/png':
			case 'image/x-png':
				$song_imagetype = '.png';
				break;

			default:
				message_die(GENERAL_ERROR, $lang['Not_allowed_image_type']);
		}
	}

# 
#-----[ FIND ]--------------------------------------------------
# 
	while( file_exists(MUSIC_UPLOAD_PATH . $song_filename) );

# 
#-----[ AFTER, ADD ]---------------------------------------------
# 
	// --------------------------------
	// Generate imagename
	// --------------------------------
	if( $image_system == '1' )
	{
		do
		{
			$song_imagename = md5(uniqid(rand())) . $song_imagetype;
		}
		while( file_exists($song_image_path . $song_imagename) );
	}

# 
#-----[ FIND ]--------------------------------------------------
# 
	@chmod(MUSIC_UPLOAD_PATH . $song_filename, 0777);
	}

# 
#-----[ AFTER, ADD ]---------------------------------------------
# 
	// --------------------------------
	// Move song image to directory
	// --------------------------------

	if( $image_system == '1' )
	{
		if( !empty($HTTP_POST_FILES['song_image']['tmp_name']) )
		{
		$ini_val = ( @phpversion() >= '4.0.0' ) ? 'ini_get' : 'get_cfg_var';

		if ( @$ini_val('open_basedir') != '' )
		{
			if ( @phpversion() < '4.0.3' )
			{
			message_die(GENERAL_ERROR, 'open_basedir is set and your PHP version does not allow move_uploaded_file<br /><br />Please contact your server admin', '', __LINE__, __FILE__);
			}

			$move_file = 'move_uploaded_file';
		}
		else
		{
			$move_file = 'copy';
		}
		$move_file($imagetmp, $song_image_path . $song_imagename);

		@chmod($song_image_path . $song_imagename, 0777);
		}
	}

	// --------------------------------
	// Check its image size
	// --------------------------------

	if( $image_system == '1' )
	{
		if( !empty($HTTP_POST_FILES['song_image']['size']) )
		{
			$image_size = getimagesize($song_image_path . $song_imagename);

			$image_width = $image_size[0];
			$image_height = $image_size[1];

			if ( ($image_width >  $music_config['max_image_width']) or ($image_height > $music_config['max_image_height']) )
			{
			@unlink($song_image_path . $song_imagename);

			message_die(GENERAL_ERROR, 'Your uploaded image size is too big');
			}
		}
	}

# 
#-----[ FIND ]--------------------------------------------------
# 
	$sql = "INSERT INTO ". MUSIC_TABLE ." (song_filename

# 
#-----[ AFTER, ADD ]---------------------------------------------
# 
, song_imagename

# 
#-----[ FIND ]--------------------------------------------------
# 
			VALUES ('$song_filename'

# 
#-----[ AFTER, ADD ]---------------------------------------------
# 
, '$song_imagename'


#
#-----[ OPEN ]--------------------------------------------------
#  
music_page.php

# 
#-----[ FIND ]--------------------------------------------------
# 
$music_root_path = $phpbb_root_path . 'music_box/';

# 
#-----[ AFTER, ADD ]---------------------------------------------
# 
$song_image_path = $phpbb_root_path . 'music_box/upload/song_image/';
$song_image_default = $song_image_path . 'no_image.gif';  // The default image

# 
#-----[ FIND ]--------------------------------------------------
# 
if( empty($thissong) or !file_exists(MUSIC_UPLOAD_PATH . $song_filename) )
{
	message_die(GENERAL_ERROR, $lang['Song_not_exist']);
}

# 
#-----[ AFTER, ADD ]---------------------------------------------
# 
if ( $thissong['song_imagename'] == '' )
{
	$img_id = $song_image_default;
}
else
{
	$img_id = ( $song_image_path . $thissong['song_imagename'] );
}

# 
#-----[ FIND ]--------------------------------------------------
# 
	'U_SONG' => append_sid("music_song.$phpEx?song_id=$song_id"),

# 
#-----[ AFTER, ADD ]---------------------------------------------
# 
	'U_IMG' => append_sid("$img_id"),

#
#-----[ OPEN ]--------------------------------------------------
#  
language/lang_english/lang_main_music.php

# 
#-----[ FIND ]--------------------------------------------------
# 
?>

# 
#-----[ BEFORE, ADD ]--------------------------------------------
# 
//
// Song Image
//
$lang['Song_image'] = 'Song Image';
$lang['Song_image_desc'] = 'The Image of this song<br />(such as CD Cover, Artist Photo...)';
$lang['No_image'] = 'No Image';
$lang['Upload_image'] = 'Upload Image from your PC';
$lang['Not_allowed_image_type'] = 'Your uploaded image type is not allowed';
$lang['Bad_upload_image_size'] = 'Bad upload image size';
$lang['Upload_image_size_too_big'] = 'Your uploaded image size is too big';

#
#-----[ OPEN ]--------------------------------------------------
#  
templates/subSilver/music_upload_body.tpl

# 
#-----[ FIND ]--------------------------------------------------
# 
  <tr>
	<td class="row1" height="28"><span class="gen">{L_SONG_URL}:</span></td>
	<td class="row2"><input class="post" type="text" name="song_url" size="60" /></td>
  </tr>

# 
#-----[ AFTER, ADD ]---------------------------------------------
# 
  <tr>
		<td class="row1" rowspan="2"><span class="gen">{L_SONG_IMAGE}:</span><br /><span class="gensmall">{L_SONG_IMAGE_DESC}</span></td>
		<td class="row2"><span class="gen"><input type="radio" name="image_system" value="0" checked="checked" />{L_NO_IMAGE} &nbsp; &nbsp;<input type="radio" name="image_system" value="1"  /> {L_UPLOAD_IMAGE}</span></td>
  </tr>
  <tr>
	<td class="row2"><input class="post" type="file" name="song_image" size="49" /></td>
  </tr>

#
#-----[ OPEN ]--------------------------------------------------
#  
templates/subSilver/music_page_body.tpl

# 
#-----[ FIND ]--------------------------------------------------
# 
<object id="wmp"

# 
#-----[ BEFORE, ADD ]--------------------------------------------
# Add this line to the place where you wish to the song image display
<img src="{U_IMG}" border="0"><br />
#
#-----[ SAVE/CLOSE ALL FILES ]--------------------------
#
# EoM