## Image Upload Module v0.4

Created by: Cent (www.cando-ent.com)
Created on: 2007/04/12
Requires Extra Fields Enabled, Thickbox Module (used if installed and the module is activated. Settings can be changed in image_upload_settings.php)

### Description

This module allow users to upload a photo with their submission. All images are stored locally on the server and are named the same as the entry id (ie. 1024.img). Currently the module does not keep the original file name in the database. Images can be uploaded in JPG, GIF, PNG and WBMP. All images are resized upon upload to the dimensions set by the site admin and GIF, PNG and WBMP images are automatically converted to JPG format. After the new image is sized and saved, the original image the user uploaded is deleted.

### Installation

1. Edit /libs/extra_fields.php
   Enable the extra field that will hold the image file name by changing:
   Define('Enable_Extra_Field_1', false)
   -to-
   Define('Enable_Extra_Field_1', true)
   Change:
   Define('Field_1_Title', '');
   -to-
   Define('Field_1_Title', 'Select a photo:');
   Change:
   Define('Field_1_Instructions', '');
   -to-
   Define('Field_1_Instructions', 'Select a JPG, GIF, PNG or WBMP photo from your computer.');
2. Edit /templates/(your template)/submit_extra_fields.tpl
   Look for the extra field you enabled. If you are using link_field1 (as with the example above),
   Change:
   <input type="text" name="link_field1" id="link_field1" value="{$submit_link_field1}" size="60" class="form-full" />
   -to-
   <input type="file" name="link_field1" id="link_field1" size="20" class="form-full" />
   This will allow for file uploads.
3. Edit /templates/(your template)/submit_step_2.tpl
   Change:
   <form action="submit.php" method="post" name="thisform" id="thisform">
   -to-
   <form action="submit.php" method="post" name="thisform" id="thisform" enctype="multipart/form-data">
   Required for file uploads.
4. Edit /templates/(your template)/submit_step_3.tpl
   Look for:
   $linkres->store();
   tags_insert_string($linkres->id, $dblang, $linkres->tags);
   And add the code below between those 2 lines:
   // START: Image Upload Module
   check_actions('image_upload_process');
   // END: Image Upload Module
5. Edit /templates/(your template)/link_summary.tpl
   Look For:
   <div class="news-submitted">
   Add add the code below above that line
   <div style="float:right;"> {php} check_actions('image_upload_preview'); {/php} </div>
   This code triggers the Image Upload module to show the image. Ideally you can place the above code anywhere within link_summary.tpl where you want to image to show up at.
   Also, be sure to comment out or remove the following two lines:
   {if $Enable_Extra_Field_1 eq 1}{if $link_field1 neq ""}<br/><b>{$Field_1_Title}:</b> {$link_field1}{/if}{/if}<br/><br/>
   and
   {if $use_thumbnails eq true && $pagename eq "story" && $url_short neq "http://" && $url_short neq "://"}<b><img src="http://images.websnapr.com/?url={$url_short}&size=T" style="float:right; padding-left:10px;padding-top:35px;"></b>{/if}
   To comment out and keep for later, simply change it to:
   <!-- {if $Enable_Extra_Field_1 eq 1}{if $link_field1 neq ""}<br/><b>{$Field_1_Title}:</b> {$link_field1}{/if}{/if}<br/><br/> //-->
   and
   <!-- {if $use_thumbnails eq true && $pagename eq "story" && $url_short neq "http://" && $url_short neq "://"}<b><img src="http://images.websnapr.com/?url={$url_short}&size=T" style="float:right; padding-left:10px;padding-top:35px;"></b>{/if} //-->

### Module Configuration

All admin settings are changed in this file. Modifying these settings can be trial and error to fit the design of your site.
6. Edit /modules/image_upload/image_upload_settings.php

   Module Setting | Default Setting | Options | Usage
   module_imageupload_basedir | $_SERVER['DOCUMENT_ROOT'].$mypliggbase |  | Used to know where Pligg's installed at. It's a little hack as thumb.php uses part of it.
   module_imageupload_imagedir | images/ |  | The path from your Pligg installation to an images folder within your Pligg directory -- must include the trailing slash. If Pligg is installed in your WWW root, then this should be changed to images/. This directory must be writable so chmod it to 755 or 644.
   module_imageupload_gdversion | 2 | 1 or 2 | To create thumbnails, GD support needs to be enabled in PHP. Most PHP installations has GD 2.x installed. If your host only has GD 1.x installed, change this to 1.
   module_imageupload_jpg_quality | 80 | 1-100 | By default, all images larger than the fullsize width / height you indicate will be resized. All GIF, PNG and WBMP images will be converted to JPG format. In either case, this sets the JPG quality of the final image. Higher numbers = less compression and larger file size. Lower numbers = more compression and smaller file size. The more compression, the more artifacts will be visible in the image.
   module_imageupload_use_thickbox | true | true / false | If set to true, Image Upload will attempt to use Thickbox module to overlay image in a "lightbox" effect.
   module_imageupload_use_thumb | true | true / false | If set to true, module will show a thumbnail. If false, the fullsize image will be shown.
   module_imageupload_thumb_width | 150 |  | This is the maximum width the thumbnail should be.
   module_imageupload_thumb_height | 150 |  | This is the maximum height the thumbnail should be.
   module_imageupload_thumb_square | true | true / false | If set to true, the thumbnail will be the width x height set for thumbnails with as little scaling as possible. Thumbnail will be cropped.
   module_imageupload_thumb_prefix | th_ |  | (future use)
   module_imageupload_fullsize_maxtoggle | w | w / h | If thumbnails are scaled and module_imageupload_thumb_square is false, then this allows you to set the maximum width or maximum height of the thumbnail. As images are rarely square, this will force the thumbnail routine to be sure it adheres to one dimension.
   module_imageupload_fullsize_width | 500 |  | Maximum width any uploaded images should be. Any image wider than this value is scaled in proportion to the maximum height (below).
   module_imageupload_fullsize_height | 500 |  | Maximum height any uploaded pictures should be.
   module_imageupload_filename_field | link_field1 |  | Very important. As Extra Fields need to be enabled in the Admin, indicating the link_field you are using will allow the module to update the database with the correct image filename when completed.
   module_imageupload_debugmode | false | true / false | Turning on debug mode will output messages from the module about what its currently doing and information about the file being processed. This should be turned off in a production environment.
   module_imageupload_legendtext | (HTML Code) |  | This is the legend text that appears below a thumbnail to inform the user to clic the image for larger version. This can contain properly formatted and escaped HTML code.

   There are additional settings, however, for most people they will not have to adjust them. Changing them may cause issues.

### Revision History

v0.4 2007/04/12 Cent - Fixed image conversion process.
v0.3 2007/04/11 Cent - Added code for square thumbnails. Improved documentation readability.
v0.2 2007/04/10 Cent - Fixed code and stability issues
v0.1 2007/04/08 Cent - First version