Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Structuring #1295

Merged
merged 6 commits into from Jan 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions sources/Dispatcher.class.php
Expand Up @@ -311,7 +311,8 @@ public function dispatch()
if (method_exists($controller, 'pre_dispatch'))
$controller->pre_dispatch();

$hook = substr($this->_function_name, -1) == 2 ? substr($this->_function_name, 0, -1) : $this->_function_name;
$hook = strtolower(str_replace('_Controller', '', $this->_controller_name));
$hook = substr($hook, -1) == 2 ? substr($hook, 0, -1) : $hook;
call_integration_hook('integrate_' . $hook . '_before');

// 3, 2, ... and go
Expand All @@ -329,10 +330,10 @@ public function dispatch()
// Things went pretty bad, huh?
// board index :P
require_once(CONTROLLERDIR . '/BoardIndex.controller.php');
call_integration_hook('integrate_action_boardindex_before');
call_integration_hook('integrate_boardindex_before');
$controller = new BoardIndex_Controller();
$this->action_boardindex();
call_integration_hook('integrate_action_boardindex_after');
call_integration_hook('integrate_boardindex_after');
}
call_integration_hook('integrate_' . $hook . '_after');
}
Expand Down
31 changes: 23 additions & 8 deletions sources/Errors.class.php
Expand Up @@ -107,8 +107,8 @@ public function addError($error, $severity = null, $lang_file = null)
$this->_errors[$severity][$error] = $error;
}

if (!empty($lang_file))
$this->_language_files[] = $lang_file;
if (!empty($lang_file) && !isset($this->_language_files[$lang_file]))
$this->_language_files[$lang_file] = false;
}

/**
Expand Down Expand Up @@ -209,12 +209,7 @@ public function prepareErrors($severity = null)
if (empty($this->_errors))
return array();

// Load the default error language and any other language file needed
// @todo: we could load these languages only if really necessary...it just needs a couple of changes
loadLanguage('Errors');
if (!empty($this->_language_files))
foreach ($this->_language_files as $language)
loadLanguage($language);
$this->_loadLang();

call_integration_hook('integrate_' . $this->_name . '_errors', array(&$this->_errors, &$this->_severity_levels));

Expand All @@ -239,6 +234,26 @@ public function prepareErrors($severity = null)
return $returns;
}

/**
* Load the default error language and any other language file needed
*/
private function _loadLang()
{
// Errors is always needed
loadLanguage('Errors');

// Any custom one?
if (!empty($this->_language_files))
foreach ($this->_language_files as $language => $loaded)
if (!$loaded)
{
loadLanguage($language);

// Remember this file has been loaded already
$this->_language_files[$language] = true;
}
}

/**
* Find and return error_context instance if it exists,
* or create a new instance for $id if it didn't already exist.
Expand Down
60 changes: 32 additions & 28 deletions sources/controllers/Post.controller.php
Expand Up @@ -216,7 +216,7 @@ function action_post()
$context['show_approval'] = allowedTo('approve_posts') && $context['becomes_approved'] ? 2 : (allowedTo('approve_posts') ? 1 : 0);

// An array to hold all the attachments for this topic.
$context['current_attachments'] = array();
$context['attachments']['current'] = array();

// Don't allow a post if it's locked and you aren't all powerful.
if ($locked && !allowedTo('moderate_board'))
Expand Down Expand Up @@ -607,19 +607,19 @@ function action_post()
}
}

$context['can_post_attachment'] = !empty($modSettings['attachmentEnable']) && $modSettings['attachmentEnable'] == 1 && (allowedTo('post_attachment') || ($modSettings['postmod_active'] && allowedTo('post_unapproved_attachments')));
if ($context['can_post_attachment'])
$context['attachments']['can']['post'] = !empty($modSettings['attachmentEnable']) && $modSettings['attachmentEnable'] == 1 && (allowedTo('post_attachment') || ($modSettings['postmod_active'] && allowedTo('post_unapproved_attachments')));
if ($context['attachments']['can']['post'])
{
// If there are attachments, calculate the total size and how many.
$context['attachments']['total_size'] = 0;
$context['attachments']['quantity'] = 0;
$attachments['total_size'] = 0;
$attachments['quantity'] = 0;

// If this isn't a new post, check the current attachments.
if (isset($_REQUEST['msg']))
{
$context['attachments']['quantity'] = count($context['current_attachments']);
foreach ($context['current_attachments'] as $attachment)
$context['attachments']['total_size'] += $attachment['size'];
$attachments['quantity'] = count($context['attachments']['current']);
foreach ($context['attachments']['current'] as $attachment)
$attachments['total_size'] += $attachment['size'];
}

// A bit of house keeping first.
Expand Down Expand Up @@ -665,9 +665,9 @@ function action_post()
{
// Since, they don't belong here. Let's inform the user that they exist..
if (!empty($topic))
$delete_link = '<a href="' . $scripturl . '?action=post' .(!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp">' . $txt['here'] . '</a>';
$delete_url = $scripturl . '?action=post' .(!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp';
else
$delete_link = '<a href="' . $scripturl . '?action=post;board=' . $board . ';delete_temp">' . $txt['here'] . '</a>';
$delete_url = $scripturl . '?action=post;board=' . $board . ';delete_temp';

// Compile a list of the files to show the user.
$file_list = array();
Expand All @@ -683,12 +683,12 @@ function action_post()
// We have a message id, so we can link back to the old topic they were trying to edit..
$goback_link = '<a href="' . $scripturl . '?action=post' .(!empty($_SESSION['temp_attachments']['post']['msg']) ? (';msg=' . $_SESSION['temp_attachments']['post']['msg']) : '') . (!empty($_SESSION['temp_attachments']['post']['last_msg']) ? (';last_msg=' . $_SESSION['temp_attachments']['post']['last_msg']) : '') . ';topic=' . $_SESSION['temp_attachments']['post']['topic'] . ';additionalOptions">' . $txt['here'] . '</a>';

$attach_errors->addError(array('temp_attachments_found', array($delete_link, $goback_link, $file_list)));
$attach_errors->addError(array('temp_attachments_found', array($delete_url, $goback_link, $file_list)));
$context['ignore_temp_attachments'] = true;
}
else
{
$attach_errors->addError(array('temp_attachments_lost', array($delete_link, $file_list)));
$attach_errors->addError(array('temp_attachments_lost', array($delete_url, $file_list)));
$context['ignore_temp_attachments'] = true;
}
}
Expand Down Expand Up @@ -734,13 +734,13 @@ function action_post()
continue;
}

$context['attachments']['quantity']++;
$context['attachments']['total_size'] += $attachment['size'];
$attachments['quantity']++;
$attachments['total_size'] += $attachment['size'];

if (!isset($context['files_in_session_warning']))
$context['files_in_session_warning'] = $txt['attached_files_in_session'];

$context['current_attachments'][] = array(
$context['attachments']['current'][] = array(
'name' => '<u>' . htmlspecialchars($attachment['name'], ENT_COMPAT, 'UTF-8') . '</u>',
'size' => $attachment['size'],
'id' => $attachID,
Expand Down Expand Up @@ -935,26 +935,30 @@ function action_post()
}

// If the user can post attachments prepare the warning labels.
if ($context['can_post_attachment'])
if ($context['attachments']['can']['post'])
{
// If they've unchecked an attachment, they may still want to attach that many more files, but don't allow more than num_allowed_attachments.
$context['num_allowed_attachments'] = empty($modSettings['attachmentNumPerPostLimit']) ? 50 : min($modSettings['attachmentNumPerPostLimit'] - count($context['current_attachments']), $modSettings['attachmentNumPerPostLimit']);
$context['can_post_attachment_unapproved'] = allowedTo('post_attachment');
$context['attachment_restrictions'] = array();
$context['allowed_extensions'] = strtr(strtolower($modSettings['attachmentExtensions']), array(',' => ', '));
$context['attachments']['num_allowed'] = empty($modSettings['attachmentNumPerPostLimit']) ? 50 : min($modSettings['attachmentNumPerPostLimit'] - count($context['attachments']['current']), $modSettings['attachmentNumPerPostLimit']);
$context['attachments']['can']['post_unapproved'] = allowedTo('post_attachment');
$context['attachments']['restrictions'] = array();
$context['attachments']['allowed_extensions'] = strtr(strtolower($modSettings['attachmentExtensions']), array(',' => ', '));
$context['attachments']['templates'] = array(
'add_new' => 'template_add_new_attachments',
'existing' => 'template_show_existing_attachments',
);

$attachmentRestrictionTypes = array('attachmentNumPerPostLimit', 'attachmentPostLimit', 'attachmentSizeLimit');
foreach ($attachmentRestrictionTypes as $type)
{
if (!empty($modSettings[$type]))
{
$context['attachment_restrictions'][] = sprintf($txt['attach_restrict_' . $type], comma_format($modSettings[$type], 0));
$context['attachments']['restrictions'][] = sprintf($txt['attach_restrict_' . $type], comma_format($modSettings[$type], 0));

// Show some numbers. If they exist.
if ($type == 'attachmentNumPerPostLimit' && $context['attachments']['quantity'] > 0)
$context['attachment_restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $context['attachments']['quantity']);
elseif ($type == 'attachmentPostLimit' && $context['attachments']['total_size'] > 0)
$context['attachment_restrictions'][] = sprintf($txt['attach_available'], comma_format(round(max($modSettings['attachmentPostLimit'] - ($context['attachments']['total_size'] / 1028), 0)), 0));
if ($type == 'attachmentNumPerPostLimit' && $attachments['quantity'] > 0)
$context['attachments']['restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $attachments['quantity']);
elseif ($type == 'attachmentPostLimit' && $attachments['total_size'] > 0)
$context['attachments']['restrictions'][] = sprintf($txt['attach_available'], comma_format(round(max($modSettings['attachmentPostLimit'] - ($attachments['total_size'] / 1028), 0)), 0));
}
}
}
Expand Down Expand Up @@ -1081,8 +1085,8 @@ function action_post2()
}

// Then try to upload any attachments.
$context['can_post_attachment'] = !empty($modSettings['attachmentEnable']) && $modSettings['attachmentEnable'] == 1 && (allowedTo('post_attachment') || ($modSettings['postmod_active'] && allowedTo('post_unapproved_attachments')));
if ($context['can_post_attachment'] && empty($_POST['from_qr']))
$context['attachments']['can']['post'] = !empty($modSettings['attachmentEnable']) && $modSettings['attachmentEnable'] == 1 && (allowedTo('post_attachment') || ($modSettings['postmod_active'] && allowedTo('post_unapproved_attachments')));
if ($context['attachments']['can']['post'] && empty($_POST['from_qr']))
{
require_once(SUBSDIR . '/Attachments.subs.php');
if (isset($_REQUEST['msg']))
Expand Down Expand Up @@ -1543,7 +1547,7 @@ function action_post2()
$id_poll = 0;

// ...or attach a new file...
if (empty($ignore_temp) && $context['can_post_attachment'] && !empty($_SESSION['temp_attachments']) && empty($_POST['from_qr']))
if (empty($ignore_temp) && $context['attachments']['can']['post'] && !empty($_SESSION['temp_attachments']) && empty($_POST['from_qr']))
{
$attachIDs = array();

Expand Down
2 changes: 1 addition & 1 deletion sources/subs/Messages.subs.php
Expand Up @@ -169,7 +169,7 @@ function prepareMessageContext($message)
// Load up 'em attachments!
foreach ($message['attachment_stuff'] as $attachment)
{
$context['current_attachments'][] = array(
$context['attachments']['current'][] = array(
'name' => htmlspecialchars($attachment['filename'], ENT_COMPAT, 'UTF-8'),
'size' => $attachment['filesize'],
'id' => $attachment['id_attach'],
Expand Down