|
@@ -2089,308 +2089,6 @@ function createPost(&$msgOptions, &$topicOptions, &$posterOptions)
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-/**
|
|
|
- * Create an attachment, with the given array of parameters.
|
|
|
- * - Adds any addtional or missing parameters to $attachmentOptions.
|
|
|
- * - Renames the temporary file.
|
|
|
- * - Creates a thumbnail if the file is an image and the option enabled.
|
|
|
- *
|
|
|
- * @param array $attachmentOptions
|
|
|
- */
|
|
|
-function createAttachment(&$attachmentOptions)
|
|
|
-{
|
|
|
- global $modSettings, $sourcedir, $smcFunc, $context;
|
|
|
- global $txt, $boarddir;
|
|
|
-
|
|
|
- require_once($sourcedir . '/Subs-Graphics.php');
|
|
|
-
|
|
|
- if (!empty($modSettings['currentAttachmentUploadDir']))
|
|
|
- $id_folder = $modSettings['currentAttachmentUploadDir'];
|
|
|
- else
|
|
|
- $id_folder = 1;
|
|
|
-
|
|
|
- // These are the only valid image types for SMF.
|
|
|
- $validImageTypes = array(
|
|
|
- 1 => 'gif',
|
|
|
- 2 => 'jpeg',
|
|
|
- 3 => 'png',
|
|
|
- 5 => 'psd',
|
|
|
- 6 => 'bmp',
|
|
|
- 7 => 'tiff',
|
|
|
- 8 => 'tiff',
|
|
|
- 9 => 'jpeg',
|
|
|
- 14 => 'iff'
|
|
|
- );
|
|
|
-
|
|
|
- // If this is an image we need to set a few additional parameters.
|
|
|
- $size = @getimagesize($attachmentOptions['tmp_name']);
|
|
|
- list ($attachmentOptions['width'], $attachmentOptions['height']) = $size;
|
|
|
-
|
|
|
- // If it's an image get the mime type right.
|
|
|
- if (empty($attachmentOptions['mime_type']) && $attachmentOptions['width'])
|
|
|
- {
|
|
|
- // Got a proper mime type?
|
|
|
- if (!empty($size['mime']))
|
|
|
- $attachmentOptions['mime_type'] = $size['mime'];
|
|
|
- // Otherwise a valid one?
|
|
|
- elseif (isset($validImageTypes[$size[2]]))
|
|
|
- $attachmentOptions['mime_type'] = 'image/' . $validImageTypes[$size[2]];
|
|
|
- }
|
|
|
-
|
|
|
- // Get the hash if no hash has been given yet.
|
|
|
- if (empty($attachmentOptions['file_hash']))
|
|
|
- $attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true);
|
|
|
-
|
|
|
- // Assuming no-one set the extension let's take a look at it.
|
|
|
- if (empty($attachmentOptions['fileext']))
|
|
|
- {
|
|
|
- $attachmentOptions['fileext'] = strtolower(strrpos($attachmentOptions['name'], '.') !== false ? substr($attachmentOptions['name'], strrpos($attachmentOptions['name'], '.') + 1) : '');
|
|
|
- if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name'])
|
|
|
- $attachmentOptions['fileext'] = '';
|
|
|
- }
|
|
|
-
|
|
|
- $smcFunc['db_insert']('',
|
|
|
- '{db_prefix}attachments',
|
|
|
- array(
|
|
|
- 'id_folder' => 'int', 'id_msg' => 'int', 'filename' => 'string-255', 'file_hash' => 'string-40', 'fileext' => 'string-8',
|
|
|
- 'size' => 'int', 'width' => 'int', 'height' => 'int',
|
|
|
- 'mime_type' => 'string-20', 'approved' => 'int',
|
|
|
- ),
|
|
|
- array(
|
|
|
- $id_folder, (int) $attachmentOptions['post'], $attachmentOptions['name'], $attachmentOptions['file_hash'], $attachmentOptions['fileext'],
|
|
|
- (int) $attachmentOptions['size'], (empty($attachmentOptions['width']) ? 0 : (int) $attachmentOptions['width']), (empty($attachmentOptions['height']) ? '0' : (int) $attachmentOptions['height']),
|
|
|
- (!empty($attachmentOptions['mime_type']) ? $attachmentOptions['mime_type'] : ''), (int) $attachmentOptions['approved'],
|
|
|
- ),
|
|
|
- array('id_attach')
|
|
|
- );
|
|
|
- $attachmentOptions['id'] = $smcFunc['db_insert_id']('{db_prefix}attachments', 'id_attach');
|
|
|
-
|
|
|
- // @todo Add an error here maybe?
|
|
|
- if (empty($attachmentOptions['id']))
|
|
|
- return false;
|
|
|
-
|
|
|
- // Now that we have the attach id, let's rename this sucker and finish up.
|
|
|
- $attachmentOptions['destination'] = getAttachmentFilename(basename($attachmentOptions['name']), $attachmentOptions['id'], $id_folder, false, $attachmentOptions['file_hash']);
|
|
|
- rename($attachmentOptions['tmp_name'], $attachmentOptions['destination']);
|
|
|
-
|
|
|
- // If it's not approved then add to the approval queue.
|
|
|
- if (!$attachmentOptions['approved'])
|
|
|
- $smcFunc['db_insert']('',
|
|
|
- '{db_prefix}approval_queue',
|
|
|
- array(
|
|
|
- 'id_attach' => 'int', 'id_msg' => 'int',
|
|
|
- ),
|
|
|
- array(
|
|
|
- $attachmentOptions['id'], (int) $attachmentOptions['post'],
|
|
|
- ),
|
|
|
- array()
|
|
|
- );
|
|
|
-
|
|
|
- if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height'])))
|
|
|
- return true;
|
|
|
-
|
|
|
- // Like thumbnails, do we?
|
|
|
- if (!empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attachmentOptions['width'] > $modSettings['attachmentThumbWidth'] || $attachmentOptions['height'] > $modSettings['attachmentThumbHeight']))
|
|
|
- {
|
|
|
- if (createThumbnail($attachmentOptions['destination'], $modSettings['attachmentThumbWidth'], $modSettings['attachmentThumbHeight']))
|
|
|
- {
|
|
|
- // Figure out how big we actually made it.
|
|
|
- $size = @getimagesize($attachmentOptions['destination'] . '_thumb');
|
|
|
- list ($thumb_width, $thumb_height) = $size;
|
|
|
-
|
|
|
- if (!empty($size['mime']))
|
|
|
- $thumb_mime = $size['mime'];
|
|
|
- elseif (isset($validImageTypes[$size[2]]))
|
|
|
- $thumb_mime = 'image/' . $validImageTypes[$size[2]];
|
|
|
- // Lord only knows how this happened...
|
|
|
- else
|
|
|
- $thumb_mime = '';
|
|
|
-
|
|
|
- $thumb_filename = $attachmentOptions['name'] . '_thumb';
|
|
|
- $thumb_size = filesize($attachmentOptions['destination'] . '_thumb');
|
|
|
- $thumb_file_hash = getAttachmentFilename($thumb_filename, false, null, true);
|
|
|
-
|
|
|
- // To the database we go!
|
|
|
- $smcFunc['db_insert']('',
|
|
|
- '{db_prefix}attachments',
|
|
|
- array(
|
|
|
- 'id_folder' => 'int', 'id_msg' => 'int', 'attachment_type' => 'int', 'filename' => 'string-255', 'file_hash' => 'string-40', 'fileext' => 'string-8',
|
|
|
- 'size' => 'int', 'width' => 'int', 'height' => 'int', 'mime_type' => 'string-20', 'approved' => 'int',
|
|
|
- ),
|
|
|
- array(
|
|
|
- $id_folder, (int) $attachmentOptions['post'], 3, $thumb_filename, $thumb_file_hash, $attachmentOptions['fileext'],
|
|
|
- $thumb_size, $thumb_width, $thumb_height, $thumb_mime, (int) $attachmentOptions['approved'],
|
|
|
- ),
|
|
|
- array('id_attach')
|
|
|
- );
|
|
|
- $attachmentOptions['thumb'] = $smcFunc['db_insert_id']('{db_prefix}attachments', 'id_attach');
|
|
|
-
|
|
|
- if (!empty($attachmentOptions['thumb']))
|
|
|
- {
|
|
|
- $smcFunc['db_query']('', '
|
|
|
- UPDATE {db_prefix}attachments
|
|
|
- SET id_thumb = {int:id_thumb}
|
|
|
- WHERE id_attach = {int:id_attach}',
|
|
|
- array(
|
|
|
- 'id_thumb' => $attachmentOptions['thumb'],
|
|
|
- 'id_attach' => $attachmentOptions['id'],
|
|
|
- )
|
|
|
- );
|
|
|
-
|
|
|
- rename($attachmentOptions['destination'] . '_thumb', getAttachmentFilename($thumb_filename, $attachmentOptions['thumb'], $id_folder, false, $thumb_file_hash));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return true;
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Performs various checks on an uploaded file.
|
|
|
- * - Requires that $_SESSION['temp_attachments'][$attachID] be properly populated.
|
|
|
- *
|
|
|
- * @param $attachID
|
|
|
- */
|
|
|
-function attachmentChecks($attachID)
|
|
|
-{
|
|
|
- global $modSettings, $context, $sourcedir, $smcFunc;
|
|
|
-
|
|
|
- // No data or missing data .... Not necessarily needed, but in case a mod author missed something.
|
|
|
- if ( empty($_SESSION['temp_attachments'][$attachID]))
|
|
|
- $errror = '$_SESSION[\'temp_attachments\'][$attachID]';
|
|
|
- elseif (empty($attachID))
|
|
|
- $errror = '$attachID';
|
|
|
- elseif (empty($context['attachments']))
|
|
|
- $errror = '$context[\'attachments\']';
|
|
|
- elseif (empty($context['attach_dir']))
|
|
|
- $errror = '$context[\'attach_dir\']';
|
|
|
-
|
|
|
- // Let's get their attention.
|
|
|
- if (!empty($error))
|
|
|
- fatal_lang_error('attach_check_nag', 'debug', array($error));
|
|
|
-
|
|
|
- // These are the only valid image types for SMF.
|
|
|
- $validImageTypes = array(
|
|
|
- 1 => 'gif',
|
|
|
- 2 => 'jpeg',
|
|
|
- 3 => 'png',
|
|
|
- 5 => 'psd',
|
|
|
- 6 => 'bmp',
|
|
|
- 7 => 'tiff',
|
|
|
- 8 => 'tiff',
|
|
|
- 9 => 'jpeg',
|
|
|
- 14 => 'iff'
|
|
|
- );
|
|
|
-
|
|
|
- // Just in case this slipped by the first checks, we stop it here and now
|
|
|
- if ($_SESSION['temp_attachments'][$attachID]['size'] == 0)
|
|
|
- {
|
|
|
- $_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_0_byte_file';
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- // First, the dreaded security check. Sorry folks, but this can't be avoided
|
|
|
- $size = @getimagesize($_SESSION['temp_attachments'][$attachID]['tmp_name']);
|
|
|
- if (isset($validImageTypes[$size[2]]))
|
|
|
- {
|
|
|
- require_once($sourcedir . '/Subs-Graphics.php');
|
|
|
- if (!checkImageContents($_SESSION['temp_attachments'][$attachID]['tmp_name'], !empty($modSettings['attachment_image_paranoid'])))
|
|
|
- {
|
|
|
- // It's bad. Last chance, maybe we can re-encode it?
|
|
|
- if (empty($modSettings['attachment_image_reencode']) || (!reencodeImage($_SESSION['temp_attachments'][$attachID]['tmp_name'], $size[2])))
|
|
|
- {
|
|
|
- // Nothing to do: not allowed or not successful re-encoding it.
|
|
|
- $_SESSION['temp_attachments'][$attachID]['errors'][] = 'bad_attachment';
|
|
|
- return false;
|
|
|
- }
|
|
|
- // Success! However, successes usually come for a price:
|
|
|
- // we might get a new format for our image...
|
|
|
- $old_format = $size[2];
|
|
|
- $size = @getimagesize($attachmentOptions['tmp_name']);
|
|
|
- if (!(empty($size)) && ($size[2] != $old_format))
|
|
|
- {
|
|
|
- if (isset($validImageTypes[$size[2]]))
|
|
|
- $_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $validImageTypes[$size[2]];
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (!empty($modSettings['attachmentDirSizeLimit']))
|
|
|
- {
|
|
|
- // Check the folder size if it hasn't been done already.
|
|
|
- if (!isset($context['dir_size']))
|
|
|
- {
|
|
|
- $request = $smcFunc['db_query']('', '
|
|
|
- SELECT SUM(size)
|
|
|
- FROM {db_prefix}attachments
|
|
|
- WHERE id_folder = {int:folder_id}',
|
|
|
- array(
|
|
|
- 'folder_id' => empty($modSettings['currentAttachmentUploadDir']) ? 1 : $modSettings['currentAttachmentUploadDir'],
|
|
|
- )
|
|
|
- );
|
|
|
- list ($context['dir_size']) = $smcFunc['db_fetch_row']($request);
|
|
|
- $smcFunc['db_free_result']($request);
|
|
|
- }
|
|
|
-
|
|
|
- $context['dir_size'] += $_SESSION['temp_attachments'][$attachID]['size'];
|
|
|
-
|
|
|
- // Soon to be too big - warn the admins...
|
|
|
- if (empty($modSettings['attachment_full_notified']) && $modSettings['attachmentDirSizeLimit'] > 4000 && $context['dir_size'] > ($modSettings['attachmentDirSizeLimit'] - 2000) * 1024)
|
|
|
- {
|
|
|
- require_once($sourcedir . '/Subs-Admin.php');
|
|
|
- emailAdmins('admin_attachments_full');
|
|
|
- updateSettings(array('attachment_full_notified' => 1));
|
|
|
- }
|
|
|
-
|
|
|
- // Too big! Maybe you could zip it or something...
|
|
|
- if ($context['dir_size'] > $modSettings['attachmentDirSizeLimit'] * 1024)
|
|
|
- $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
|
|
|
- }
|
|
|
-
|
|
|
- // Is the file too big?
|
|
|
- $context['attachments']['total_size'] += $_SESSION['temp_attachments'][$attachID]['size'];
|
|
|
- if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024)
|
|
|
- $_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0)));
|
|
|
-
|
|
|
- // Check the total upload size for this post...
|
|
|
- if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024)
|
|
|
- $_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0)));
|
|
|
-
|
|
|
- // Have we reached the maximum number of files we are allowed?
|
|
|
- $context['attachments']['quantity']++;
|
|
|
-
|
|
|
- // Set a max limit if none exists
|
|
|
- if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50)
|
|
|
- $modSettings['attachmentNumPerPostLimit'] = 50;
|
|
|
-
|
|
|
- if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit'])
|
|
|
- $_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit']));
|
|
|
-
|
|
|
- // File extension check
|
|
|
- if (!empty($modSettings['attachmentCheckExtensions']))
|
|
|
- {
|
|
|
- $allowed = explode(',', strtolower($modSettings['attachmentExtensions']));
|
|
|
- foreach ($allowed as $k => $dummy)
|
|
|
- $allowed[$k] = trim($dummy);
|
|
|
-
|
|
|
- if (!in_array(strtolower(substr(strrchr($_SESSION['temp_attachments'][$attachID]['name'], '.'), 1)), $allowed))
|
|
|
- {
|
|
|
- $allowed_extensions = strtr(strtolower($modSettings['attachmentExtensions']), array(',' => ', '));
|
|
|
- $_SESSION['temp_attachments'][$attachID]['errors'][] = array('cant_upload_type', array($allowed_extensions));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // back up to the previous one if there's been an error.
|
|
|
- if (!empty($_SESSION['temp_attachments'][$attachID]['errors']))
|
|
|
- {
|
|
|
- $context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
|
|
|
- $context['attachments']['total_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
|
|
|
- $context['attachments']['quantity']--;
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- return true;
|
|
|
-}
|
|
|
-
|
|
|
/**
|
|
|
* Modifying a post...
|
|
|
*
|
|
@@ -2419,7 +2117,7 @@ function modifyPost(&$msgOptions, &$topicOptions, &$posterOptions)
|
|
|
if (isset($msgOptions['body']))
|
|
|
{
|
|
|
$messages_columns['body'] = $msgOptions['body'];
|
|
|
-
|
|
|
+
|
|
|
// using a custom search index, then lets get the old message so we can update our index as needed
|
|
|
if (!empty($modSettings['search_custom_index_config']))
|
|
|
{
|