Added feature for adding modules via ZIP-File
This commit is contained in:
61
root/adm/style/portal/acp_portal_upload_module.html
Normal file
61
root/adm/style/portal/acp_portal_upload_module.html
Normal file
@@ -0,0 +1,61 @@
|
||||
<!-- INCLUDE overall_header.html -->
|
||||
|
||||
<a name="maincontent"></a>
|
||||
|
||||
<h1>{L_TITLE}</h1>
|
||||
|
||||
<p>{L_TITLE_EXPLAIN}</p>
|
||||
|
||||
<!-- IF S_ERROR -->
|
||||
<div class="errorbox">
|
||||
<h3>{L_WARNING}</h3>
|
||||
<p>{ERROR_MSG}</p>
|
||||
</div>
|
||||
<!-- ENDIF -->
|
||||
|
||||
<!-- IF not S_MOD_SUCCESSBOX -->
|
||||
<form action="{U_ACTION}" method="post" id="mod_upload"{S_FORM_ENCTYPE}>
|
||||
<fieldset>
|
||||
<legend>{L_MODULE_UPLOAD}</legend>
|
||||
<dl>
|
||||
<p>{L_MODULE_UPLOAD_EXP}</p>
|
||||
<input type="file" name="modupload" id="modupload" value="" style="width:50%" />
|
||||
{S_FORM_TOKEN}
|
||||
<br /><br /><input type="submit" name="submit" value="{L_MODULE_UPLOAD_GO}" id="submit" class="button1" />
|
||||
</dl>
|
||||
</fieldset>
|
||||
</form>
|
||||
<!-- ELSE -->
|
||||
<div class="successbox">
|
||||
<p>{MESSAGE}</p>
|
||||
<br />
|
||||
<p><a href="{U_RETURN}">{L_RETURN_MODS}</a></p>
|
||||
</div>
|
||||
<fieldset>
|
||||
<legend>{L_NEW_FILES}</legend>
|
||||
|
||||
<table cellspacing="1">
|
||||
<col class="row1" /><col class="row1" /><col class="row2" />
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{L_SOURCE}</th>
|
||||
<th>{L_TARGET}</th>
|
||||
<th>{L_STATUS}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<!-- BEGIN new_files -->
|
||||
<tr>
|
||||
<td><strong>{new_files.SOURCE}<!-- IF new_files.S_MISSING_FILE --> <strong><font color="red">({L_FILE_MISSING})</font><!-- ENDIF --></strong></td>
|
||||
<td>{new_files.TARGET}</td>
|
||||
<!-- IF S_INSTALL -->
|
||||
<td><!-- IF new_files.S_SUCCESS --><font color="green">{L_SUCCESS}</font><!-- ELSEIF new_files.S_NO_COPY_ATTEMPT -->{L_MANUAL_COPY}<!-- ELSE --><font color="red">{L_ERROR}</font><!-- ENDIF --></td>
|
||||
<!-- ENDIF -->
|
||||
</tr>
|
||||
<!-- END new_files -->
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
<!-- ENDIF -->
|
||||
|
||||
<!-- INCLUDE overall_footer.html -->
|
||||
@@ -282,7 +282,7 @@ class acp_portal
|
||||
{
|
||||
add_log('admin', 'LOG_PORTAL_CONFIG', $user->lang['ACP_PORTAL_' . strtoupper($mode) . '_INFO']);
|
||||
}
|
||||
trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link(($module_id) ? append_sid("{$phpbb_root_path}adm/index.$phpEx", 'i=portal&mode=modules') : $this->u_action));
|
||||
trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link(($module_id) ? append_sid("{$phpbb_root_path}adm/index.$phpEx", 'i=portal&mode=modules') : $this->u_action));
|
||||
}
|
||||
|
||||
// show custom HTML files on the settings page of the modules instead of the standard board3 portal one, if chosen by module
|
||||
@@ -872,10 +872,310 @@ class acp_portal
|
||||
$this->tpl_name = 'portal/acp_portal_modules';
|
||||
$this->page_title = 'ACP_PORTAL_MODULES';
|
||||
break;
|
||||
case 'upload_module':
|
||||
$error = array();
|
||||
if($submit)
|
||||
{
|
||||
// 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
|
||||
//print_r($folder_contents);
|
||||
// We need to check if there's a main directory inside the temp MOD directory
|
||||
if (sizeof($folder_contents) == 3)
|
||||
{
|
||||
// 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);
|
||||
$cut_array = array('.', '..');
|
||||
|
||||
$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 . '/mods/portal/');
|
||||
$lang_content = array_diff($lang_content, $cut_array);
|
||||
|
||||
foreach($lang_content as $new_file)
|
||||
{
|
||||
$actions['NEW_FILES'][$mod_dir . '/language/' . $cur_lang . '/mods/portal/' . $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,
|
||||
));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(@ini_get('file_uploads') == '0' || strtolower(@ini_get('file_uploads')) == 'off' || !@extension_loaded('zlib'))
|
||||
{
|
||||
trigger_error($user->lang['NO_MODULE_UPLOAD'] . adm_back_link(append_sid("{$phpbb_admin_path}index.$phpEx", 'i=portal&mode=modules')), E_USER_WARNING);
|
||||
}
|
||||
|
||||
if(!isset($config['am_file_perms']))
|
||||
{
|
||||
trigger_error($user->lang['NO_AUTOMOD_INSTALLED'] . adm_back_link(append_sid("{$phpbb_admin_path}index.$phpEx", 'i=portal&mode=modules')), E_USER_WARNING);
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
// start the page
|
||||
$user->add_lang(array('install', 'acp/mods'));
|
||||
|
||||
$template->assign_vars(array(
|
||||
'U_UPLOAD' => $this->u_action,
|
||||
'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"',
|
||||
));
|
||||
|
||||
add_form_key('acp_mods_upload');
|
||||
|
||||
$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,
|
||||
));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
trigger_error('NO_MODE', E_USER_ERROR);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function directory_move($src, $dest)
|
||||
{
|
||||
global $config;
|
||||
|
||||
$src_contents = scandir($src);
|
||||
|
||||
if (!is_dir($dest) && is_dir($src))
|
||||
{
|
||||
mkdir($dest . '/', octdec($config['am_dir_perms']));
|
||||
}
|
||||
|
||||
foreach ($src_contents as $src_entry)
|
||||
{
|
||||
if ($src_entry != '.' && $src_entry != '..')
|
||||
{
|
||||
if (is_dir($src . '/' . $src_entry) && !is_dir($dest . '/' . $src_entry))
|
||||
{
|
||||
$this->directory_move($src . '/' . $src_entry, $dest . '/' . $src_entry);
|
||||
}
|
||||
else if (is_file($src . '/' . $src_entry) && !is_file($dest . '/' . $src_entry))
|
||||
{
|
||||
copy($src . '/' . $src_entry, $dest . '/' . $src_entry);
|
||||
chmod($dest . '/' . $src_entry, octdec($config['am_file_perms']));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function directory_delete($dir)
|
||||
{
|
||||
if (!file_exists($dir))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!is_dir($dir) && is_file($dir))
|
||||
{
|
||||
phpbb_chmod($dir, CHMOD_ALL);
|
||||
return unlink($dir);
|
||||
}
|
||||
|
||||
foreach (scandir($dir) as $item)
|
||||
{
|
||||
if ($item == '.' || $item == '..')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!$this->directory_delete($dir . "/" . $item))
|
||||
{
|
||||
phpbb_chmod($dir . "/" . $item, CHMOD_ALL);
|
||||
if (!$this->directory_delete($dir . "/" . $item))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rmdir($dir);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -23,8 +23,9 @@ class acp_portal_info
|
||||
'title' => 'ACP_PORTAL',
|
||||
'version' => '2.0.0',
|
||||
'modes' => array(
|
||||
'config' => array('title' => 'ACP_PORTAL_GENERAL_INFO', 'auth' => 'acl_a_manage_portal', 'cat' => array('ACP_PORTAL')),
|
||||
'modules' => array('title' => 'ACP_PORTAL_MODULES', 'auth' => 'acl_a_manage_portal', 'cat' => array('ACP_PORTAL')),
|
||||
'config' => array('title' => 'ACP_PORTAL_GENERAL_INFO', 'auth' => 'acl_a_manage_portal', 'cat' => array('ACP_PORTAL')),
|
||||
'modules' => array('title' => 'ACP_PORTAL_MODULES', 'auth' => 'acl_a_manage_portal', 'cat' => array('ACP_PORTAL')),
|
||||
'upload_module' => array('title' => 'ACP_PORTAL_UPLOAD', 'auth' => 'acl_a_manage_portal', 'cat' => array('ACP_PORTAL')),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -100,6 +100,14 @@ $lang = array_merge($lang, array(
|
||||
'LOG_PORTAL_EVENT_ADDED' => '<strong>Portal-Einstellungen geändert</strong><br />» Termin eingetragen: %s ',
|
||||
'LOG_PORTAL_EVENT_UPDATED' => '<strong>Portal-Einstellungen geändert</strong><br />» 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.',
|
||||
|
||||
// Install
|
||||
'PORTAL_BASIC_INSTALL' => 'Füge Basismodule hinzu',
|
||||
'PORTAL_BASIC_UNINSTALL' => 'Entferne Module von Datenbank',
|
||||
|
||||
@@ -101,6 +101,14 @@ $lang = array_merge($lang, array(
|
||||
'LOG_PORTAL_EVENT_ADDED' => '<strong>Altered Portal settings</strong><br />» Event added: %s ',
|
||||
'LOG_PORTAL_EVENT_UPDATED' => '<strong>Altered Portal settings</strong><br />» 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.',
|
||||
|
||||
// Install
|
||||
'PORTAL_BASIC_INSTALL' => 'Adding basic set of modules',
|
||||
'PORTAL_BASIC_UNINSTALL' => 'Removing modules from database',
|
||||
|
||||
7
root/portal/upload/index.html
Normal file
7
root/portal/upload/index.html
Normal file
@@ -0,0 +1,7 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF" text="#000000">
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user