[SUBMITTED] Large Images MOD

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment! No new topics are allowed in this forum.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: MOD Development Forum rules

On February 1, 2009 this forum will be set to read only as part of retiring of phpBB2.
User avatar
Sian
Registered User
Posts: 33
Joined: Mon Oct 28, 2002 1:03 pm
Location: Cracow, Poland

[SUBMITTED] Large Images MOD

Post by Sian »

Hello,

First of all, sorry for my English - still learnig... :)

I'm administrator of phpBB forum, that is windowed (800x600). I had a problem with keeping layout with large images posted on forum.
I tried to find a solution, but find only one based on javascript (http://www.phpbb.com/phpBB/viewtopic.php?p=678874), but this wasn't what I needed, so I wrote my own mod with different solution.
This MOD will allow the board administrators to set maximum width of an posted images. If width of an image exceeds entered value, a horizontal scrollbar will appear under image. This will maintain forum layout.

You can find code in .txt file or below:

Code: Select all

############################################################## 
## MOD Title:          Large Images MOD
## MOD Author:         Sian < sebastian.weglarczyk@interia.pl >
## MOD Description:    This MOD will allow the board administrators
##                     to set maximum width of an posted images.
##                     If width of an image exceeds entered value,
##                     a horizontal scrollbar will appear under image.
##                     This will maintain forum layout.
##                     Entering zero or leaving empty disables this function.
## MOD Version:        1.0
## Compatibility:      2.0.4 - 2.0.6 (prior release not tested but expected to work fine)
##
## Installation Level: Easy
## Installation Time:  5-10 Minutes
## Files To Edit:      5
##      admin/admin_board.php
##      includes/bbcode.php
##      language/lang_english/lang_admin.php 
##      templates/subSilver/viewtopic_body.tpl
##      templates/subSilver/admin/board_config_body.tpl
##
##############################################################
## Security Disclaimer: This MOD Cannot Be Posted To Or Added At Any Non-Official phpBB Sites 
############################################################## 
## 
## Author Notes: 
##
## To set maximum image width:
## Go to administration panel -> General Admin -> Configuration -> User and Forum Basic Settings
## 
##	This mod should work with any template, although there will be differences in the .tpl
##	files with some templates. You should be able to work around the differences.
##
##	If you have other templates or languages installed you should modify respective files.
##
############################################################## 
##
## MOD History: 
## 
##   2003-08-27 - Version 1.0
##      - Initial final release
##
##############################################################
## This MOD is released under the GPL License.
############################################################## 
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD 
############################################################## 
#
# 
#-----[ SQL ]------------------------------------------------- 
# 
# Add the "image_max_width" value to the "config" table. 
# You can use the following SQL statement, replacing 
# the database name and the prefix with those of your choice. 
# 
INSERT INTO `phpbb_config` (`config_name`, `config_value`) VALUES ('image_max_width', '0');

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

# 
#-----[ FIND ]------------------------------------------------ 
# 
	"L_MAX_SIG_LENGTH" => $lang['Max_sig_length'],
	"L_MAX_SIG_LENGTH_EXPLAIN" => $lang['Max_sig_length_explain'],

# 
#-----[ AFTER, ADD ]------------------------------------------ 
# 
	// Start add - LargeImages MOD
	"L_MAX_IMG_WIDTH" => $lang['Max_image_width'],
	"L_MAX_IMG_WIDTH_EXPLAIN" => $lang['Max_image_width_explain'],
	// End add - LargeImages MOD

# 
#-----[ FIND ]------------------------------------------------ 
# 
	"SIG_YES" => $sig_yes,
	"SIG_NO" => $sig_no,
	"SIG_SIZE" => $new['max_sig_chars'],

# 
#-----[ AFTER, ADD ]------------------------------------------ 
# 
	// Start add - LargeImages MOD
	"MAX_IMG_WIDTH" => $new['image_max_width'],
	// End add - LargeImages MOD

# 
#-----[ OPEN ]------------------------------------------------ 
# 
includes/bbcode.php 

# 
#-----[ FIND ]------------------------------------------------
# 
	global $lang, $bbcode_tpl;
# 
#-----[ REPLACE WITH ]----------------------------------------
#
	// Start replacement - LargeImages MOD
	global $lang, $bbcode_tpl, $board_config;
	// Start replacement - LargeImages MOD

# 
#-----[ FIND ]------------------------------------------------
# 
	$text = preg_replace($patterns, $replacements, $text);

# 
#-----[ BEFORE, ADD ]----------------------------------------- 
# 
	// Start add - LargeImages MOD
	if (!empty($board_config['image_max_width']) && ($board_config['image_max_width'] > 0))
	{
		if (preg_match_all("#\[img:$uid\](.*?)\[/img:$uid\]#si", $text, $images)) {
			$imagePatterns = $imageReplacements = array();
			foreach($images[1] as $index=>$image_link)
			{
				$image_dimensions = @getimagesize($image_link);
				if ($image_dimensions && $image_dimensions[0] > $board_config['image_max_width']) {
					$div_height = $image_dimensions[1] + 20;
					$imagePatterns[] = $images[0][$index];
					$imageReplacements[] = '<div style="width:'.$board_config['image_max_width'].'px; height:'.$div_height.'px; overflow:auto;">'.$images[0][$index].'</div>';
				}
			}
			$text = str_replace($imagePatterns,$imageReplacements,$text);
		}
	}
	// End add - LargeImages MOD

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

# 
#-----[ FIND ]------------------------------------------------
# 
$lang['Max_sig_length'] = 'Maximum signature length';
$lang['Max_sig_length_explain'] = 'Maximum number of characters in user signatures';

# 
#-----[ AFTER, ADD ]------------------------------------------ 
# 
// Start add - LargeImages MOD
$lang['Max_image_width'] = 'Maximum images width';
$lang['Max_image_width_explain'] = 'If width of an image exceeds this value, a horizontal scrollbar will appear under image. This will maintain forum layout. Enter zero or leave empty to disable this function.';
// End add - LargeImages MOD

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

# 
#-----[ FIND ]------------------------------------------------
# 
		<td class="{postrow.ROW_CLASS}" width="100%" height="28" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td width="100%"><a href="{postrow.U_MINI_POST}"><img src="{postrow.MINI_POST_IMG}" width="12" height="9" alt="{postrow.L_MINI_POST_ALT}" title="{postrow.L_MINI_POST_ALT}" border="0" /></a><span class="postdetails">{L_POSTED}: {postrow.POST_DATE}<span class="gen">&</span>& &{L_POST_SUBJECT}: {postrow.POST_SUBJECT}</span></td>
				<td valign="top" nowrap="nowrap">{postrow.QUOTE_IMG} {postrow.EDIT_IMG} {postrow.DELETE_IMG} {postrow.IP_IMG}</td>
			</tr>
			<tr> 
				<td colspan="2"><hr /></td>
			</tr>
			<tr>
				<td colspan="2"><span class="postbody">{postrow.MESSAGE}{postrow.SIGNATURE}</span><span class="gensmall">{postrow.EDITED_MESSAGE}</span></td>
			</tr>
		</table></td>

# 
#-----[ REPLACE WITH ]---------------------------------------- 
#
		<!-- Start replacement - LargeImages MOD -->
		<td class="{postrow.ROW_CLASS}" width="100%" height="28" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td width="100%"><a href="{postrow.U_MINI_POST}"><img src="{postrow.MINI_POST_IMG}" width="12" height="9" alt="{postrow.L_MINI_POST_ALT}" title="{postrow.L_MINI_POST_ALT}" border="0" /></a><span class="postdetails">{L_POSTED}: {postrow.POST_DATE}<span class="gen">&</span><br />{L_POST_SUBJECT}: {postrow.POST_SUBJECT}</span></td>
						<td valign="top" nowrap="nowrap">{postrow.REPLY_IMG_MINI} {postrow.QUOTE_IMG} {postrow.EDIT_IMG} {postrow.DELETE_IMG} {postrow.IP_IMG}</td> 
					</tr>
				</table></td>
			</tr>
			<tr> 
				<td><hr /></td>
			</tr>
			<tr>
				<td><span class="postbody">{postrow.MESSAGE}{postrow.SIGNATURE}</span><span class="gensmall">{postrow.EDITED_MESSAGE}</span></td>
			</tr>
		</table></td>
		<!-- End replacement - LargeImages MOD -->

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

# 
#-----[ FIND ]------------------------------------------------
# 
	<tr>
		<td class="row1">{L_MAX_SIG_LENGTH}<br /><span class="gensmall">{L_MAX_SIG_LENGTH_EXPLAIN}</span></td>
		<td class="row2"><input class="post" type="text" size="5" maxlength="4" name="max_sig_chars" value="{SIG_SIZE}" /></td>
	</tr>

# 
#-----[ AFTER, ADD ]------------------------------------------ 
# 
	<!-- Start add - LargeImages MOD -->
	<tr>
		<td class="row1">{L_MAX_IMG_WIDTH}<br /><span class="gensmall">{L_MAX_IMG_WIDTH_EXPLAIN}</span></td>
		<td class="row2"><input class="post" type="text" size="5" maxlength="4" name="image_max_width" value="{MAX_IMG_WIDTH}" /> px.</td>
	</tr>
	<!-- End add - LargeImages MOD -->

# 
#-----[ SAVE/CLOSE ALL FILES ]-------------------------------- 
# 
# EoM 
Hope this mod would be useful... :mrgreen:
Last edited by Sian on Sun Aug 31, 2003 7:13 am, edited 2 times in total.
Sian

User avatar
vze3k59w
Registered User
Posts: 485
Joined: Fri May 09, 2003 1:09 am

Post by vze3k59w »

some ocde to execute the sql

Code: Select all

<?php
##############################################################
##                      Large Images MOD
##                      ----------------
##
##
##############################################################

define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . 'config.'.$phpEx);
//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//


if( !$userdata['session_logged_in'] )
{
	$header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: ';
	header('Location: ' . append_sid($phpbb_root_path.'login.'.$phpEx.'?redirect=update.'.$phpEx));
	exit;
}

if( $userdata['user_level'] != ADMIN )
{
	message_die(GENERAL_MESSAGE, 'You are not authorised to access this page');
}


$page_title = 'Updating the database';
include($phpbb_root_path . 'includes/page_header.'.$phpEx);

echo '<table width="100%" cellspacing="1" cellpadding="2" border="0" class="forumline">';
echo '<tr><th>Updating the database</th></tr><tr><td><span class="genmed"><ul type="circle">';


$sql = array();
$sql[] = "INSERT INTO " . CONFIG_TABLE . " (`config_name`, `config_value`) VALUES ('image_max_width', '0')";

for( $i = 0; $i < count($sql); $i++ )
{
	if( !$result = $db->sql_query ($sql[$i]) )
	{
		$error = $db->sql_error();

		echo '<li>' . $sql[$i] . '<br /> +++ <font color="#FF0000"><b>Error:</b></font> ' . $error['message'] . '</li><br />';
	}
	else
	{
		echo '<li>' . $sql[$i] . '<br /> +++ <font color="#00AA00"><b>Successfull</b></font></li><br />';
	}
}


echo '</ul></span></td></tr><tr><td class="catBottom" height="28">&</td></tr>';

echo '<tr><th>End</th></tr><tr><td><span class="genmed">Installation is now finished. Please be sure to delete this file now.</span></td></tr>';
echo '<tr><td class="catBottom" height="28" align="center"><span class="genmed"><a href="' . append_sid("index.$phpEx") . '">Click Here to return to the index</a></span></td></table>';

include($phpbb_root_path . 'includes/page_tail.'.$phpEx);

?>
Wanna join a very advanced OO based modular port of phpBB? PM me :)

User avatar
Sian
Registered User
Posts: 33
Joined: Mon Oct 28, 2002 1:03 pm
Location: Cracow, Poland

Post by Sian »

Thanks :)
Sian

netclectic
Former Team Member
Posts: 4439
Joined: Wed Mar 13, 2002 3:08 pm
Location: Omnipresent
Contact:

Post by netclectic »

Moved to Beta Dev - you should submit this to the mod db, see here for instructions.
Defend the game:
Image

User avatar
Sian
Registered User
Posts: 33
Joined: Mon Oct 28, 2002 1:03 pm
Location: Cracow, Poland

Post by Sian »

Thanks again, mod submitted. :)
Sian

Q-Zar
Registered User
Posts: 779
Joined: Sun Nov 17, 2002 8:30 pm
Location: Brussels
Contact:

Post by Q-Zar »

Good idea ! :)
Traductions : Cash Mod v2.2.2 (Getting Started) / Dice Mod v1.2.3 / Activity Mod Plus 1.0.8
Remember this. Please read the F.A.Q/Troubleshooting of a mod before asking questions.
Image

User avatar
vze3k59w
Registered User
Posts: 485
Joined: Fri May 09, 2003 1:09 am

Post by vze3k59w »

you should change the name of the thread to [SUBMITTED] Large Images MOD
Wanna join a very advanced OO based modular port of phpBB? PM me :)

User avatar
Carpe Diem
Registered User
Posts: 580
Joined: Tue Dec 10, 2002 11:19 pm

Post by Carpe Diem »

Sian wrote: Thanks again, mod submitted. :)


You might have wanted to wait a little while to get some more feedback and even possible bug reports and other improvement suggestions and so on before submitting the mod for the database... the mod is a good idea but it's wise to see if it actually works with other mods and also be sure that it does not clash with different phpbb versions.

That is my honest opinion.

:?

testebr
Registered User
Posts: 303
Joined: Thu Nov 28, 2002 5:05 am

Post by testebr »

Demo forum? Where? 8)

User avatar
Carpe Diem
Registered User
Posts: 580
Joined: Tue Dec 10, 2002 11:19 pm

Post by Carpe Diem »

testebr wrote: Demo forum? Where? 8)


Why would you need a demo forum for this mod? The idea is very simple.. if a user submit a pic big enough to mess up the width of the viewtopic page, this mod, would shrink the pic to keep the width. I don't see the use of a demo link for this idea?

User avatar
Sian
Registered User
Posts: 33
Joined: Mon Oct 28, 2002 1:03 pm
Location: Cracow, Poland

Post by Sian »

testebr wrote: Demo forum? Where? 8)

OK, If you wish see http://www.op.osw.pl/forum/viewtopic.php?t=14
Sian

User avatar
Sian
Registered User
Posts: 33
Joined: Mon Oct 28, 2002 1:03 pm
Location: Cracow, Poland

Post by Sian »

Carpe Diem wrote: You might have wanted to wait a little while (...)

Maybe you have right, but netclectic said "submit", and I did it.
Sian

lifeform
Registered User
Posts: 43
Joined: Tue Jul 01, 2003 1:26 pm

don't work with attachment mod

Post by lifeform »

I have tested this mod..

it is working offsite images.. but doesn't work with attached pictures..if it works with attached mod it would be great..

may be I made something wrong..anybody tested it with attachment mod?

best regards

User avatar
Carpe Diem
Registered User
Posts: 580
Joined: Tue Dec 10, 2002 11:19 pm

Post by Carpe Diem »

Thank you, a good and useful mod really.¨

Found one typo though..
The

Code: Select all

# 
# 
#-----[ AFTER, ADD ]------------------------------------------ 
# 
// Start add - LargeImages MOD 
$lang['Max_image_width'] = 'Maximum images width'; 
$lang['Max_image_width_explain'] = 'If width of an image exceeds this value, a horizontal scrollbar will appear under image. This will maintain forum layout. Enter zero or leave empty to disable this function.' 
// End add - LargeImages MOD


should be

Code: Select all

# 
#-----[ AFTER, ADD ]------------------------------------------ 
# 
// Start add - LargeImages MOD 
$lang['Max_image_width'] = 'Maximum images width'; 
$lang['Max_image_width_explain'] = 'If width of an image exceeds this value, a horizontal scrollbar will appear under image. This will maintain forum layout. Enter zero or leave empty to disable this function.'; 
// End add - LargeImages MOD 
The final ";" was missing in your original code.
:wink:

User avatar
Sian
Registered User
Posts: 33
Joined: Mon Oct 28, 2002 1:03 pm
Location: Cracow, Poland

Post by Sian »

Carpe Diem wrote: (...) The final ";" was missing in your original code.

Thank you very much, my mistake. :oops:
Mod corrected.
Now I see, you've had right about waiting for feedback, bug reports and other suggestions before submitting the mod to database...
Sian

Locked

Return to “[2.0.x] MODs in Development”