Rewrote basic uploader for module zips
This commit is contained in:
@@ -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('<br />', $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('<br />', $error),
|
||||
|
||||
'U_ACTION' => $this->u_action,
|
||||
));
|
||||
}
|
||||
$portal_upload = new portal_upload($upload_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user