Skip to content

Commit

Permalink
Merge pull request #2992 from emanuele45/fixes_1.1
Browse files Browse the repository at this point in the history
Fixes 1.1
  • Loading branch information
Spuds committed Sep 18, 2017
2 parents 84535f2 + f034bfd commit 6fa0bdc
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 27 deletions.
9 changes: 9 additions & 0 deletions bootstrap.php
Expand Up @@ -309,6 +309,15 @@
}
else
{
if (!empty($modSettings['front_page']) && is_callable(array($modSettings['front_page'], 'frontPageHook')))
{
$modSettings['default_forum_action'] = '?action=forum;';
}
else
{
$modSettings['default_forum_action'] = '';
}

setupThemeContext();
}

Expand Down
50 changes: 26 additions & 24 deletions sources/subs/Attachments.subs.php
Expand Up @@ -352,6 +352,7 @@ function processAttachments($id_msg = null)
global $context, $modSettings, $txt, $user_info, $ignore_temp, $topic, $board;

$attach_errors = ElkArte\Errors\AttachmentErrorContext::context();
$added_initial_error = false;

// Make sure we're uploading to the right place.
if (!empty($modSettings['automanage_attachments']))
Expand Down Expand Up @@ -435,36 +436,37 @@ function processAttachments($id_msg = null)
'board' => !empty($board) ? $board : 0,
);

// If we have an initial error, lets just display it.
if (!empty($initial_error))
{
$_SESSION['temp_attachments']['initial_error'] = $initial_error;

// This is a generic error
$attach_errors->activate();
$attach_errors->addError('attach_no_upload');
// @todo This is likely the result of some refactoring, verify when $attachment is not set and why
if (isset($attachment))
{
$attach_errors->addError(is_array($attachment) ? array($attachment[0], $attachment[1]) : $attachment);
}

// And delete the files 'cos they ain't going nowhere.
foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
{
if (file_exists($_FILES['attachment']['tmp_name'][$n]))
unlink($_FILES['attachment']['tmp_name'][$n]);
}

$_FILES['attachment']['tmp_name'] = array();
}

// Loop through $_FILES['attachment'] array and move each file to the current attachments folder.
foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
{
if ($_FILES['attachment']['name'][$n] == '')
continue;

// If we have an initial error, lets just display it.
if (!empty($initial_error) && $added_initial_error === false)
{
$added_initial_error = true;
$_SESSION['temp_attachments']['initial_error'] = $initial_error;

// This is a generic error
$attach_errors->activate();
$attach_errors->addError('attach_no_upload');
// @todo This is likely the result of some refactoring, verify when $attachment is not set and why
if (isset($attachment))
{
$attach_errors->addError(is_array($attachment) ? array($attachment[0], $attachment[1]) : $attachment);
}

// And delete the files 'cos they ain't going nowhere.
foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
{
if (file_exists($_FILES['attachment']['tmp_name'][$n]))
unlink($_FILES['attachment']['tmp_name'][$n]);
}

$_FILES['attachment']['tmp_name'] = array();
}

// First, let's first check for PHP upload errors.
$errors = attachmentUploadChecks($n);

Expand Down
9 changes: 9 additions & 0 deletions sources/subs/Errors/AttachmentErrorContext.php
Expand Up @@ -207,16 +207,25 @@ public function prepareErrors($severity = null)
);

if (!empty($this->_attachs))
{
foreach ($this->_attachs as $attachID => $error)
{
$returns[$attachID] = array(
'errors' => $error['error']->prepareErrors($severity),
'type' => $this->getErrorType(),
'title' => sprintf($txt['attach_warning'], $error['name']),
);
}
}

return $returns;
}

public function getName()
{
return 'attach_error_title';
}

/**
* Return the type of the error
*/
Expand Down
56 changes: 54 additions & 2 deletions sources/subs/Errors/ErrorContext.php
Expand Up @@ -138,11 +138,51 @@ public function removeError($error)
protected function getErrorName($error)
{
if (is_array($error))
return $error[0];
{
$first_error = array_values($error);
if (is_object($first_error[0]))
{
return $this->getErrorName($first_error[0]);
}
else
{
return $first_error[0];
}
}
elseif (is_object($error))
{
return $error->getName();
}
else
{
return $error;
}
}

/**
* Finds the "value" of the error (Usually applicable only to
* array of strings, being the second element of the array)
*
* @param mixed|mixed[] $error error code
*/
protected function getErrorValue($error)
{
if (is_array($error))
{
$first_error = array_values($error);
if (is_object($first_error[0]))
{
return null;
}
else
{
return $first_error[1];
}
}
else
{
return null;
}
}

/**
Expand Down Expand Up @@ -266,11 +306,23 @@ public function prepareErrors($severity = null)
foreach ($errors as $error_val)
{
if (is_array($error_val))
$returns[$error_val[0]] = vsprintf(isset($txt['error_' . $error_val[0]]) ? $txt['error_' . $error_val[0]] : (isset($txt[$error_val[0]]) ? $txt[$error_val[0]] : $error_val[0]), $error_val[1]);
{
$name = $this->getErrorName($error_val);
$value = $this->getErrorValue($error_val);
if ($value === null)
{
continue;
}
$returns[$name] = vsprintf(isset($txt['error_' . $name]) ? $txt['error_' . $name] : (isset($txt[$name]) ? $txt[$name] : $name), $value);
}
elseif (is_object($error_val))
{
continue;
}
else
{
$returns[$error_val] = isset($txt['error_' . $error_val]) ? $txt['error_' . $error_val] : (isset($txt[$error_val]) ? $txt[$error_val] : $error_val);
}
}

return $returns;
Expand Down
2 changes: 1 addition & 1 deletion sources/subs/ManageAttachments.subs.php
Expand Up @@ -1281,7 +1281,7 @@ function attachDirStatus($dir, $expected_files)

// Count the files with a glob, easier and less time consuming
$glob = new GlobIterator($dir . '/*.elk', FilesystemIterator::SKIP_DOTS);
$num_files = count(iterator_to_array($glob));
$num_files = $glob->count();

if ($num_files < $expected_files)
return array('files_missing', true, $num_files);
Expand Down

0 comments on commit 6fa0bdc

Please sign in to comment.