diff --git a/root/includes/acp/acp_portal.php b/root/includes/acp/acp_portal.php
index 5cbee843..2807a8df 100644
--- a/root/includes/acp/acp_portal.php
+++ b/root/includes/acp/acp_portal.php
@@ -907,201 +907,11 @@ class acp_portal
$error = array();
if($submit)
{
+ include($phpbb_root_path . 'portal/includes/functions_upload.' . $phpEx);
// Default upload path is portal/upload/
$upload_path = $phpbb_root_path . 'portal/upload/';
- // Upload part
- $user->add_lang('posting'); // For error messages
- include($phpbb_root_path . 'includes/functions_upload.' . $phpEx);
- $upload = new fileupload();
- // Only allow ZIP files
- $upload->set_allowed_extensions(array('zip'));
- $file = $upload->form_upload('modupload');
-
- if (empty($file->filename))
- {
- trigger_error($user->lang['NO_UPLOAD_FILE'] . adm_back_link($this->u_action), E_USER_WARNING);
- }
- else
- {
- if (!$file->init_error && !sizeof($file->error))
- {
- $file->clean_filename('real');
- $file->move_file(str_replace($phpbb_root_path, '', $upload_path), true, true);
-
- if (!sizeof($file->error))
- {
- include($phpbb_root_path . 'includes/functions_compress.' . $phpEx);
- $mod_dir = $upload_path . str_replace('.zip', '', $file->get('realname'));
- // make sure we don't already have the new folder
- if(is_dir($mod_dir))
- {
- $this->directory_delete($mod_dir);
- }
- $compress = new compress_zip('r', $file->destination_file);
- $compress->extract($mod_dir . '_tmp/');
- $compress->close();
- $folder_contents = scandir($mod_dir . '_tmp/', 1); // This ensures dir is at index 0
- $cut_array = array('.', '..');
- $folder_contents = array_diff($folder_contents, $cut_array);
-
- // We need to check if there's a main directory inside the temp MOD directory
- if (sizeof($folder_contents) == 1)
- {
- // We need to move that directory then
- $this->directory_move($mod_dir . '_tmp/' . $folder_contents[0], $upload_path . '/' . $folder_contents[0]);
-
- }
- else if (!is_dir($mod_dir))
- {
- // Change the name of the directory by moving to directory without _tmp in it
- $this->directory_move($mod_dir . '_tmp/', $mod_dir);
-
- }
-
- $this->directory_delete($mod_dir . '_tmp/');
-
- // if we got until here set $actions['NEW_FILES']
- $actions['NEW_FILES'] = array();
-
- // Now we need to get the files inside the folders
- $folder_contents = scandir($mod_dir);
-
- $folder_contents = array_diff($folder_contents, $cut_array);
-
- /*
- * This will tell us what files we need to copy incl. the path
- * In loving memory of PHP 4.x .... NOT
- */
- foreach($folder_contents as $cur_content)
- {
- $cur_folder_content = array();
- switch($cur_content)
- {
- case 'language':
- // there are more foreach to come .....
- $cur_folder_content = scandir($mod_dir . '/language/');
- $cur_folder_content = array_diff($cur_folder_content, $cut_array);
- $langs = array();
-
- foreach($cur_folder_content as $copy_file)
- {
- $langs[] = $copy_file;
- }
-
- foreach($langs as $cur_lang)
- {
- $lang_content = scandir($mod_dir . '/language/' . $cur_lang . '/');
- $lang_content = array_diff($lang_content, $cut_array);
-
- foreach($lang_content as $new_file)
- {
- $actions['NEW_FILES'][$mod_dir . '/language/' . $cur_lang . '/' . $new_file] = $phpbb_root_path . 'language/' . $cur_lang . '/mods/portal/' . $new_file;
- }
- }
- break;
- case 'module':
- $cur_folder_content = scandir($mod_dir . '/module/');
- $cur_folder_content = array_diff($cur_folder_content, $cut_array);
-
- foreach($cur_folder_content as $copy_file)
- {
- $actions['NEW_FILES'][$mod_dir . '/module/' . $copy_file] = $phpbb_root_path . 'portal/modules/' . $copy_file;
- }
- break;
- case 'styles':
- // there are more foreach to come .....
- $cur_folder_content = scandir($mod_dir . '/styles/');
- $cur_folder_content = array_diff($cur_folder_content, $cut_array);
- $styles = array();
-
- foreach($cur_folder_content as $copy_file)
- {
- $styles[] = $copy_file;
- }
-
- foreach($styles as $cur_style)
- {
- $style_content = scandir($mod_dir . '/styles/' . $cur_style);
- $style_content = array_diff($style_content, $cut_array);
-
- foreach($style_content as $new_file)
- {
- $actions['NEW_FILES'][$mod_dir . '/styles/' . $cur_style . '/' . $new_file] = $phpbb_root_path . 'styles/' . $cur_style . '/template/portal/modules/' . $new_file;
- }
- }
- break;
- default:
- // there shouldn't be other files ...
- trigger_error($user->lang['MODULE_CORRUPTED'] . adm_back_link(append_sid("{$phpbb_admin_path}index.$phpEx", 'i=portal&mode=modules')), E_USER_WARNING);
- }
- }
-
- if (!sizeof($file->error))
- {
- include("{$phpbb_root_path}includes/functions_transfer.$phpEx");
- include("{$phpbb_root_path}includes/editor.$phpEx");
- include("{$phpbb_root_path}includes/functions_mods.$phpEx");
- include("{$phpbb_root_path}includes/mod_parser.$phpEx");
-
- if(!function_exists('determine_write_method') || !class_exists('editor') || !class_exists('parser'))
- {
- trigger_error($user->lang['NO_AUTOMOD_INSTALLED'] . adm_back_link(append_sid("{$phpbb_admin_path}index.$phpEx", 'i=portal&mode=modules')), E_USER_WARNING);
- }
-
- // start the page
- $user->add_lang(array('install', 'acp/mods'));
-
- // Let's start moving our files where they belong
- $write_method = 'editor_' . determine_write_method(false);
- $editor = new $write_method();
-
- foreach ($actions['NEW_FILES'] as $source => $target)
- {
- $status = $editor->copy_content($source, $target);
-
- if ($status !== true && !is_null($status))
- {
- $module_installed = false;
- }
-
- $template->assign_block_vars('new_files', array(
- 'S_SUCCESS' => ($status === true) ? true : false,
- 'S_NO_COPY_ATTEMPT' => (is_null($status)) ? true : false,
- 'SOURCE' => $source,
- 'TARGET' => $target,
- ));
- }
-
- $editor->commit_changes($mod_dir . '_edited', '');
-
- $template->assign_vars(array(
- 'S_MOD_SUCCESSBOX' => true,
- 'MESSAGE' => $user->lang['INSTALLED'],
- 'U_RETURN' => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=portal&mode=modules'),
- ));
- }
- }
- }
- $file->remove();
- if ($file->init_error || sizeof($file->error))
- {
- trigger_error((sizeof($file->error) ? implode('
', $file->error) : $user->lang['MOD_UPLOAD_INIT_FAIL']) . adm_back_link($this->u_action), E_USER_WARNING);
- }
-
- $this->tpl_name = 'portal/acp_portal_upload_module';
- $this->page_title = $user->lang['ACP_PORTAL_UPLOAD'];
-
- $template->assign_vars(array(
- 'L_TITLE' => $user->lang['ACP_PORTAL_UPLOAD'],
- 'L_TITLE_EXPLAIN' => '',
-
- 'S_ERROR' => (sizeof($error)) ? true : false,
- 'ERROR_MSG' => implode('
', $error),
-
- 'U_ACTION' => $this->u_action,
- ));
- }
+ $portal_upload = new portal_upload($upload_path);
}
else
{
diff --git a/root/language/de/mods/info_acp_portal.php b/root/language/de/mods/info_acp_portal.php
index 6c483839..24d88e54 100644
--- a/root/language/de/mods/info_acp_portal.php
+++ b/root/language/de/mods/info_acp_portal.php
@@ -105,12 +105,15 @@ $lang = array_merge($lang, array(
'LOG_PORTAL_EVENT_UPDATED' => 'Portal-Einstellungen geändert
» Termin geändert: %s ',
// Upload Module
- 'ACP_PORTAL_UPLOAD' => 'Modul hochladen',
- 'MODULE_UPLOAD' => 'Lade ein Modul hoch',
- 'MODULE_UPLOAD_EXP' => 'Wähle die ZIP-Datei des Moduls das du hochladen willst:',
- 'MODULE_UPLOAD_GO' => 'Hochladen',
- 'NO_MODULE_UPLOAD' => 'Deine Server-Konfiguration erlaubt das Hochladen von Dateien nicht.',
- 'NO_AUTOMOD_INSTALLED' => 'Du hast AutoMOD nicht installiert, AutoMOD ist für dieses Feature aber zwingend erforderlich.',
+ 'ACP_PORTAL_UPLOAD' => 'Modul hochladen',
+ 'MODULE_UPLOAD' => 'Lade ein Modul hoch',
+ 'MODULE_UPLOAD_EXP' => 'Wähle die ZIP-Datei des Moduls das du hochladen willst:',
+ 'MODULE_UPLOAD_GO' => 'Hochladen',
+ 'NO_MODULE_UPLOAD' => 'Deine Server-Konfiguration erlaubt das Hochladen von Dateien nicht.',
+ 'MODULE_UPLOADED' => 'Module erfolgreich hochgeladen.',
+ 'MODULE_UPLOAD_MKDIR_FAILURE' => 'Es konnte kein Ordner erstellt werden.',
+ 'MODULE_COPY_FAILURE' => 'Die folgende Datei konnte nicht kopiert werden: %1$s',
+ 'MODULE_CORRUPTED' => 'Das Modul das du hochladen willst, scheint defekt zu sein.',
// Install
'PORTAL_BASIC_INSTALL' => 'Füge Basismodule hinzu',
diff --git a/root/language/en/mods/info_acp_portal.php b/root/language/en/mods/info_acp_portal.php
index 16919f5d..2249a3a1 100755
--- a/root/language/en/mods/info_acp_portal.php
+++ b/root/language/en/mods/info_acp_portal.php
@@ -102,12 +102,15 @@ $lang = array_merge($lang, array(
'LOG_PORTAL_EVENT_UPDATED' => 'Altered Portal settings
» Event updated: %s ',
// Upload Module
- 'ACP_PORTAL_UPLOAD' => 'Upload module',
- 'MODULE_UPLOAD' => 'Upload a module',
- 'MODULE_UPLOAD_EXP' => 'Choose the zip file of the module you want to upload:',
- 'MODULE_UPLOAD_GO' => 'Upload',
- 'NO_MODULE_UPLOAD' => 'Your server configuration does not allow file uploads.',
- 'NO_AUTOMOD_INSTALLED' => 'You don’t have AutoMOD installed, but AutoMOD is required for this module.',
+ 'ACP_PORTAL_UPLOAD' => 'Upload module',
+ 'MODULE_UPLOAD' => 'Upload a module',
+ 'MODULE_UPLOAD_EXP' => 'Choose the zip file of the module you want to upload:',
+ 'MODULE_UPLOAD_GO' => 'Upload',
+ 'NO_MODULE_UPLOAD' => 'Your server configuration does not allow file uploads.',
+ 'MODULE_UPLOADED' => 'Module uploaded successfully.',
+ 'MODULE_UPLOAD_MKDIR_FAILURE' => 'Unable to create a folder.',
+ 'MODULE_COPY_FAILURE' => 'Unable to copy the following file: %1$s',
+ 'MODULE_CORRUPTED' => 'The module you are trying to upload seems to be corrupted.',
// Install
'PORTAL_BASIC_INSTALL' => 'Adding basic set of modules',
diff --git a/root/portal/includes/functions_upload.php b/root/portal/includes/functions_upload.php
new file mode 100644
index 00000000..addcd997
--- /dev/null
+++ b/root/portal/includes/functions_upload.php
@@ -0,0 +1,267 @@
+upload_path;
+ var $this->error = array();
+
+ /*
+ * constructor function for PHP<5
+ */
+ function portal_upload($path)
+ {
+ if(is_dir($path))
+ {
+ $this->upload_path = $path;
+
+ $result = $this->upload_file();
+
+ if($result != true)
+ {
+ $this->error = $result;
+ }
+
+ $this->finishing_touches();
+ }
+ }
+
+ function upload_file()
+ {
+ // Upload part
+ $user->add_lang('posting'); // For error messages
+ include($phpbb_root_path . 'includes/functions_upload.' . $phpEx);
+ $upload = new fileupload();
+ // Only allow ZIP files
+ $upload->set_allowed_extensions(array('zip'));
+
+ $file = $upload->form_upload('modupload');
+
+ if (empty($file->filename))
+ {
+ trigger_error($user->lang['NO_UPLOAD_FILE'] . adm_back_link($this->u_action), E_USER_WARNING);
+ }
+ else
+ {
+ if (!$file->init_error && !sizeof($file->error))
+ {
+ $file->clean_filename('real');
+ $file->move_file(str_replace($phpbb_root_path, '', $upload_path), true, true);
+
+ if (!sizeof($file->error))
+ {
+ include($phpbb_root_path . 'includes/functions_compress.' . $phpEx);
+ $mod_dir = $upload_path . str_replace('.zip', '', $file->get('realname'));
+ // make sure we don't already have the new folder
+ if(is_dir($mod_dir))
+ {
+ $this->directory_delete($mod_dir);
+ }
+ $compress = new compress_zip('r', $file->destination_file);
+ $compress->extract($mod_dir . '_tmp/');
+ $compress->close();
+ $folder_contents = $this->cut_folder(scandir($mod_dir . '_tmp/', 1)); // This ensures dir is at index 0
+
+ // We need to check if there's a main directory inside the temp MOD directory
+ if (sizeof($folder_contents) == 1)
+ {
+ // We need to move that directory then
+ $this->directory_move($mod_dir . '_tmp/' . $folder_contents[0], $upload_path . '/' . $folder_contents[0]);
+
+ }
+ else if (!is_dir($mod_dir))
+ {
+ // Change the name of the directory by moving to directory without _tmp in it
+ $this->directory_move($mod_dir . '_tmp/', $mod_dir);
+
+ }
+
+ $this->directory_delete($mod_dir . '_tmp/');
+
+ // if we got until here set $actions['NEW_FILES']
+ $actions['NEW_FILES'] = array();
+
+ // Now we need to get the files inside the folders
+ $folder_contents = $this->cut_folder(scandir($mod_dir));
+
+ /*
+ * This will tell us what files we need to copy incl. the path
+ * In loving memory of PHP 4.x ... NOT
+ */
+ foreach($folder_contents as $cur_content)
+ {
+ $cur_folder_content = array();
+ switch($cur_content)
+ {
+ case 'language':
+ // there are more foreach to come .....
+ $cur_folder_content = $this->cut_folder(scandir($mod_dir . '/language/'));
+ $langs = array();
+
+ foreach($cur_folder_content as $copy_file)
+ {
+ $langs[] = $copy_file;
+ }
+
+ foreach($langs as $cur_lang)
+ {
+ $lang_content = $this->cut_folder(scandir($mod_dir . '/language/' . $cur_lang . '/'));
+
+ foreach($lang_content as $new_file)
+ {
+ $actions['NEW_FILES'][$mod_dir . '/language/' . $cur_lang . '/' . $new_file] = $phpbb_root_path . 'language/' . $cur_lang . '/mods/portal/' . $new_file;
+ }
+ }
+ break;
+ case 'module':
+ $cur_folder_content = $this->cut_folder(scandir($mod_dir . '/module/'));
+
+ foreach($cur_folder_content as $copy_file)
+ {
+ $actions['NEW_FILES'][$mod_dir . '/module/' . $copy_file] = $phpbb_root_path . 'portal/modules/' . $copy_file;
+ }
+ break;
+ case 'styles':
+ // there are more foreach to come .....
+ $cur_folder_content = $this->cut_folder(scandir($mod_dir . '/styles/'));
+ $styles = array();
+
+ foreach($cur_folder_content as $copy_file)
+ {
+ $styles[] = $copy_file;
+ }
+
+ foreach($styles as $cur_style)
+ {
+ $style_content = $this->cut_folder(scandir($mod_dir . '/styles/' . $cur_style));
+
+ foreach($style_content as $new_file)
+ {
+ $actions['NEW_FILES'][$mod_dir . '/styles/' . $cur_style . '/' . $new_file] = $phpbb_root_path . 'styles/' . $cur_style . '/template/portal/modules/' . $new_file;
+ }
+ }
+ break;
+ default:
+ // there shouldn't be other files or folders
+ trigger_error($user->lang['MODULE_CORRUPTED'] . adm_back_link(append_sid("{$phpbb_admin_path}index.$phpEx", 'i=portal&mode=modules')), E_USER_WARNING);
+ }
+ }
+
+ if (!sizeof($file->error))
+ {
+ include("{$phpbb_root_path}includes/functions_transfer.$phpEx");
+ include("{$phpbb_root_path}includes/editor.$phpEx");
+ include("{$phpbb_root_path}includes/functions_mods.$phpEx");
+ include("{$phpbb_root_path}includes/mod_parser.$phpEx");
+
+ if(!function_exists('determine_write_method') || !class_exists('editor') || !class_exists('parser'))
+ {
+ trigger_error($user->lang['NO_AUTOMOD_INSTALLED'] . adm_back_link(append_sid("{$phpbb_admin_path}index.$phpEx", 'i=portal&mode=modules')), E_USER_WARNING);
+ }
+
+ // start the page
+ $user->add_lang(array('install', 'acp/mods'));
+
+ // Let's start moving our files where they belong
+ $write_method = 'editor_' . determine_write_method(false);
+ $editor = new $write_method();
+
+ foreach ($actions['NEW_FILES'] as $source => $target)
+ {
+ $status = $editor->copy_content($source, $target);
+
+ if ($status !== true && !is_null($status))
+ {
+ $module_installed = false;
+ }
+
+ $template->assign_block_vars('new_files', array(
+ 'S_SUCCESS' => ($status === true) ? true : false,
+ 'S_NO_COPY_ATTEMPT' => (is_null($status)) ? true : false,
+ 'SOURCE' => $source,
+ 'TARGET' => $target,
+ ));
+ }
+
+ $editor->commit_changes($mod_dir . '_edited', '');
+
+ $template->assign_vars(array(
+ 'S_MOD_SUCCESSBOX' => true,
+ 'MESSAGE' => $user->lang['INSTALLED'],
+ 'U_RETURN' => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=portal&mode=modules'),
+ ));
+ }
+ }
+ }
+ $file->remove();
+ if ($file->init_error || sizeof($file->error))
+ {
+ trigger_error((sizeof($file->error) ? implode('
', $file->error) : $user->lang['MOD_UPLOAD_INIT_FAIL']) . adm_back_link($this->u_action), E_USER_WARNING);
+ }
+
+ $this->tpl_name = 'portal/acp_portal_upload_module';
+ $this->page_title = $user->lang['ACP_PORTAL_UPLOAD'];
+
+ $template->assign_vars(array(
+ 'L_TITLE' => $user->lang['ACP_PORTAL_UPLOAD'],
+ 'L_TITLE_EXPLAIN' => '',
+
+ 'S_ERROR' => (sizeof($error)) ? true : false,
+ 'ERROR_MSG' => implode('
', $error),
+
+ 'U_ACTION' => $this->u_action,
+ ));
+ }
+ }
+
+ /**
+ * Cuts the unneeded '.' and '..' from the folder content info scandir returns
+ *
+ * @return: cut array
+ */
+ function cut_folder($folder_content)
+ {
+ $cut_array = array('.', '..');
+ $folder_content = array_diff($folder_content, $cut_array);
+
+ return $folder_content
+ }
+
+ function determine_write_method($pre_install = false)
+ {
+ global $phpbb_root_path, $config;
+
+ /*
+ * to be truly correct, we should scan all files ...
+ * no ftp upload here
+ */
+ if ((is_writable($phpbb_root_path)) || $pre_install)
+ {
+ $write_method = 'direct';
+ }
+ else
+ {
+ $write_method = 'manual';
+ }
+
+ return $write_method;
+ }
+
+}
\ No newline at end of file