Replace upload files with the actual files
This commit is contained in:
@@ -31,18 +31,18 @@
|
|||||||
<div class="successbox">
|
<div class="successbox">
|
||||||
<p>{MESSAGE}</p>
|
<p>{MESSAGE}</p>
|
||||||
<br />
|
<br />
|
||||||
<p><a href="{U_RETURN}">{L_RETURN_MODS}</a></p>
|
<p><a href="{U_RETURN}">{L_BACK}</a></p>
|
||||||
</div>
|
</div>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>{L_NEW_FILES}</legend>
|
<legend>{L_PORTAL_NEW_FILES}</legend>
|
||||||
|
|
||||||
<table cellspacing="1">
|
<table cellspacing="1">
|
||||||
<col class="row1" /><col class="row1" /><col class="row2" />
|
<col class="row1" /><col class="row1" /><col class="row2" />
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>{L_SOURCE}</th>
|
<th>{L_PORTAL_MODULE_SOURCE}</th>
|
||||||
<th>{L_TARGET}</th>
|
<th>{L_PORTAL_MODULE_TARGET}</th>
|
||||||
<th>{L_STATUS}</th>
|
<th>{L_PORTAL_MODULE_STATUS}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -51,7 +51,7 @@
|
|||||||
<td><strong>{new_files.SOURCE}<!-- IF new_files.S_MISSING_FILE --> <strong><font color="red">({L_FILE_MISSING})</font><!-- ENDIF --></strong></td>
|
<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>
|
<td>{new_files.TARGET}</td>
|
||||||
<!-- IF S_INSTALL -->
|
<!-- 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>
|
<td><!-- IF new_files.S_SUCCESS --><font color="green">{L_PORTAL_MODULE_SUCCESS}</font><!-- ELSE --><font color="red">{L_PORTAL_MODULE_ERROR}</font><!-- ENDIF --></td>
|
||||||
<!-- ENDIF -->
|
<!-- ENDIF -->
|
||||||
</tr>
|
</tr>
|
||||||
<!-- END new_files -->
|
<!-- END new_files -->
|
||||||
|
|||||||
@@ -907,38 +907,28 @@ class acp_portal
|
|||||||
$error = array();
|
$error = array();
|
||||||
if($submit)
|
if($submit)
|
||||||
{
|
{
|
||||||
|
if(!check_form_key('acp_portal_module_upload'))
|
||||||
|
{
|
||||||
|
trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||||
|
}
|
||||||
include($phpbb_root_path . 'portal/includes/functions_upload.' . $phpEx);
|
include($phpbb_root_path . 'portal/includes/functions_upload.' . $phpEx);
|
||||||
// Default upload path is portal/upload/
|
// Default upload path is portal/upload/
|
||||||
$upload_path = $phpbb_root_path . 'portal/upload/';
|
$upload_path = $phpbb_root_path . 'portal/upload/';
|
||||||
|
|
||||||
$portal_upload = new portal_upload($upload_path);
|
$portal_upload = new portal_upload($upload_path);
|
||||||
|
|
||||||
|
$this->tpl_name = 'portal/acp_portal_upload_module';
|
||||||
|
$this->page_title = $user->lang['ACP_PORTAL_UPLOAD'];
|
||||||
}
|
}
|
||||||
else
|
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
|
// start the page
|
||||||
$user->add_lang(array('install', 'acp/mods'));
|
|
||||||
|
|
||||||
$template->assign_vars(array(
|
$template->assign_vars(array(
|
||||||
'U_UPLOAD' => $this->u_action,
|
'U_UPLOAD' => $this->u_action,
|
||||||
'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"',
|
'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"',
|
||||||
));
|
));
|
||||||
|
|
||||||
add_form_key('acp_mods_upload');
|
add_form_key('acp_portal_module_upload');
|
||||||
|
|
||||||
$this->tpl_name = 'portal/acp_portal_upload_module';
|
$this->tpl_name = 'portal/acp_portal_upload_module';
|
||||||
$this->page_title = $user->lang['ACP_PORTAL_UPLOAD'];
|
$this->page_title = $user->lang['ACP_PORTAL_UPLOAD'];
|
||||||
@@ -959,64 +949,4 @@ class acp_portal
|
|||||||
break;
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,10 +110,16 @@ $lang = array_merge($lang, array(
|
|||||||
'MODULE_UPLOAD_EXP' => 'Wähle die ZIP-Datei des Moduls das du hochladen willst:',
|
'MODULE_UPLOAD_EXP' => 'Wähle die ZIP-Datei des Moduls das du hochladen willst:',
|
||||||
'MODULE_UPLOAD_GO' => 'Hochladen',
|
'MODULE_UPLOAD_GO' => 'Hochladen',
|
||||||
'NO_MODULE_UPLOAD' => 'Deine Server-Konfiguration erlaubt das Hochladen von Dateien nicht.',
|
'NO_MODULE_UPLOAD' => 'Deine Server-Konfiguration erlaubt das Hochladen von Dateien nicht.',
|
||||||
'MODULE_UPLOADED' => 'Module erfolgreich hochgeladen.',
|
'MODULE_UPLOADED' => 'Modul erfolgreich hochgeladen.',
|
||||||
'MODULE_UPLOAD_MKDIR_FAILURE' => 'Es konnte kein Ordner erstellt werden.',
|
'MODULE_UPLOAD_MKDIR_FAILURE' => 'Es konnte kein Ordner erstellt werden.',
|
||||||
'MODULE_COPY_FAILURE' => 'Die folgende Datei konnte nicht kopiert werden: %1$s',
|
'MODULE_COPY_FAILURE' => 'Die folgende Datei konnte nicht kopiert werden: %1$s',
|
||||||
'MODULE_CORRUPTED' => 'Das Modul das du hochladen willst, scheint defekt zu sein.',
|
'MODULE_CORRUPTED' => 'Das Modul das du hochladen willst, scheint defekt zu sein.',
|
||||||
|
'PORTAL_NEW_FILES' => 'Neue Dateien',
|
||||||
|
'PORTAL_MODULE_SOURCE' => 'Quelle',
|
||||||
|
'PORTAL_MODULE_TARGET' => 'Ziel',
|
||||||
|
'PORTAL_MODULE_STATUS' => 'Status',
|
||||||
|
'PORTAL_MODULE_SUCCESS' => 'Erfolgreich kopiert.',
|
||||||
|
'PORTAL_MODULE_ERROR' => 'Datei exisitert schon oder konnte nicht kopiert werden.',
|
||||||
|
|
||||||
// Install
|
// Install
|
||||||
'PORTAL_BASIC_INSTALL' => 'Füge Basismodule hinzu',
|
'PORTAL_BASIC_INSTALL' => 'Füge Basismodule hinzu',
|
||||||
|
|||||||
@@ -15,13 +15,12 @@ if (!defined('IN_PHPBB'))
|
|||||||
/**
|
/**
|
||||||
* @ignore
|
* @ignore
|
||||||
*/
|
*/
|
||||||
class portal_upload
|
class portal_upload extends acp_portal
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* pre-defined vars
|
* pre-defined vars
|
||||||
*/
|
*/
|
||||||
var $this->upload_path;
|
var $upload_path;
|
||||||
var $this->error = array();
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* constructor function for PHP<5
|
* constructor function for PHP<5
|
||||||
@@ -32,19 +31,13 @@ class portal_upload
|
|||||||
{
|
{
|
||||||
$this->upload_path = $path;
|
$this->upload_path = $path;
|
||||||
|
|
||||||
$result = $this->upload_file();
|
$this->upload_file();
|
||||||
|
|
||||||
if($result != true)
|
|
||||||
{
|
|
||||||
$this->error = $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->finishing_touches();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function upload_file()
|
function upload_file()
|
||||||
{
|
{
|
||||||
|
global $user, $phpbb_root_path, $phpEx, $phpbb_admin_path, $template;
|
||||||
// Upload part
|
// Upload part
|
||||||
$user->add_lang('posting'); // For error messages
|
$user->add_lang('posting'); // For error messages
|
||||||
include($phpbb_root_path . 'includes/functions_upload.' . $phpEx);
|
include($phpbb_root_path . 'includes/functions_upload.' . $phpEx);
|
||||||
@@ -63,12 +56,12 @@ class portal_upload
|
|||||||
if (!$file->init_error && !sizeof($file->error))
|
if (!$file->init_error && !sizeof($file->error))
|
||||||
{
|
{
|
||||||
$file->clean_filename('real');
|
$file->clean_filename('real');
|
||||||
$file->move_file(str_replace($phpbb_root_path, '', $upload_path), true, true);
|
$file->move_file(str_replace($phpbb_root_path, '', $this->upload_path), true, true);
|
||||||
|
|
||||||
if (!sizeof($file->error))
|
if (!sizeof($file->error))
|
||||||
{
|
{
|
||||||
include($phpbb_root_path . 'includes/functions_compress.' . $phpEx);
|
include($phpbb_root_path . 'includes/functions_compress.' . $phpEx);
|
||||||
$mod_dir = $upload_path . str_replace('.zip', '', $file->get('realname'));
|
$mod_dir = $this->upload_path . str_replace('.zip', '', $file->get('realname'));
|
||||||
// make sure we don't already have the new folder
|
// make sure we don't already have the new folder
|
||||||
if(is_dir($mod_dir))
|
if(is_dir($mod_dir))
|
||||||
{
|
{
|
||||||
@@ -83,7 +76,7 @@ class portal_upload
|
|||||||
if (sizeof($folder_contents) == 1)
|
if (sizeof($folder_contents) == 1)
|
||||||
{
|
{
|
||||||
// We need to move that directory then
|
// We need to move that directory then
|
||||||
$this->directory_move($mod_dir . '_tmp/' . $folder_contents[0], $upload_path . '/' . $folder_contents[0]);
|
$this->directory_move($mod_dir . '_tmp/' . $folder_contents[0], $this->upload_path . '/' . $folder_contents[0]);
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (!is_dir($mod_dir))
|
else if (!is_dir($mod_dir))
|
||||||
@@ -122,7 +115,13 @@ class portal_upload
|
|||||||
|
|
||||||
foreach($langs as $cur_lang)
|
foreach($langs as $cur_lang)
|
||||||
{
|
{
|
||||||
$lang_content = $this->cut_folder(scandir($mod_dir . '/language/' . $cur_lang . '/'));
|
if(!file_exists($mod_dir . '/language/' . $cur_lang . '/mods/portal/'))
|
||||||
|
{
|
||||||
|
$file->remove();
|
||||||
|
$this->directory_delete($mod_dir);
|
||||||
|
trigger_error($user->lang['MODULE_CORRUPTED'] . adm_back_link(append_sid("{$phpbb_admin_path}index.$phpEx", 'i=portal&mode=modules')), E_USER_WARNING);
|
||||||
|
}
|
||||||
|
$lang_content = $this->cut_folder(scandir($mod_dir . '/language/' . $cur_lang . '/mods/portal/'));
|
||||||
|
|
||||||
foreach($lang_content as $new_file)
|
foreach($lang_content as $new_file)
|
||||||
{
|
{
|
||||||
@@ -130,12 +129,18 @@ class portal_upload
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'module':
|
case 'portal':
|
||||||
$cur_folder_content = $this->cut_folder(scandir($mod_dir . '/module/'));
|
if(!file_exists($mod_dir . '/portal/modules/'))
|
||||||
|
{
|
||||||
|
$file->remove();
|
||||||
|
$this->directory_delete($mod_dir);
|
||||||
|
trigger_error($user->lang['MODULE_CORRUPTED'] . adm_back_link(append_sid("{$phpbb_admin_path}index.$phpEx", 'i=portal&mode=modules')), E_USER_WARNING);
|
||||||
|
}
|
||||||
|
$cur_folder_content = $this->cut_folder(scandir($mod_dir . '/portal/modules/'));
|
||||||
|
|
||||||
foreach($cur_folder_content as $copy_file)
|
foreach($cur_folder_content as $copy_file)
|
||||||
{
|
{
|
||||||
$actions['NEW_FILES'][$mod_dir . '/module/' . $copy_file] = $phpbb_root_path . 'portal/modules/' . $copy_file;
|
$actions['NEW_FILES'][$mod_dir . '/portal/modules/' . $copy_file] = $phpbb_root_path . 'portal/modules/' . $copy_file;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'styles':
|
case 'styles':
|
||||||
@@ -150,42 +155,34 @@ class portal_upload
|
|||||||
|
|
||||||
foreach($styles as $cur_style)
|
foreach($styles as $cur_style)
|
||||||
{
|
{
|
||||||
$style_content = $this->cut_folder(scandir($mod_dir . '/styles/' . $cur_style));
|
if(!file_exists($mod_dir . '/styles/' . $cur_style . '/template/portal/modules/'))
|
||||||
|
{
|
||||||
|
$file->remove();
|
||||||
|
$this->directory_delete($mod_dir);
|
||||||
|
trigger_error($user->lang['MODULE_CORRUPTED'] . adm_back_link(append_sid("{$phpbb_admin_path}index.$phpEx", 'i=portal&mode=modules')), E_USER_WARNING);
|
||||||
|
}
|
||||||
|
$style_content = $this->cut_folder(scandir($mod_dir . '/styles/' . $cur_style . '/template/portal/modules/'));
|
||||||
|
|
||||||
foreach($style_content as $new_file)
|
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;
|
$actions['NEW_FILES'][$mod_dir . '/styles/' . $cur_style . '/template/portal/modules/' . $new_file] = $phpbb_root_path . 'styles/' . $cur_style . '/template/portal/modules/' . $new_file;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// there shouldn't be other files or folders
|
// there shouldn't be other files or folders
|
||||||
|
$file->remove();
|
||||||
|
$this->directory_delete($mod_dir);
|
||||||
trigger_error($user->lang['MODULE_CORRUPTED'] . adm_back_link(append_sid("{$phpbb_admin_path}index.$phpEx", 'i=portal&mode=modules')), E_USER_WARNING);
|
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))
|
if (!sizeof($file->error))
|
||||||
{
|
{
|
||||||
include("{$phpbb_root_path}includes/functions_transfer.$phpEx");
|
// Let's start moving our files where they belong
|
||||||
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)
|
foreach ($actions['NEW_FILES'] as $source => $target)
|
||||||
{
|
{
|
||||||
$status = $editor->copy_content($source, $target);
|
$status = $this->copy_content($source, $target);
|
||||||
|
|
||||||
if ($status !== true && !is_null($status))
|
if ($status !== true && !is_null($status))
|
||||||
{
|
{
|
||||||
@@ -200,17 +197,17 @@ class portal_upload
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
$editor->commit_changes($mod_dir . '_edited', '');
|
|
||||||
|
|
||||||
$template->assign_vars(array(
|
$template->assign_vars(array(
|
||||||
'S_MOD_SUCCESSBOX' => true,
|
'S_MOD_SUCCESSBOX' => true,
|
||||||
'MESSAGE' => $user->lang['INSTALLED'],
|
'MESSAGE' => $user->lang['MODULE_UPLOADED'],
|
||||||
'U_RETURN' => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=portal&mode=modules'),
|
'U_RETURN' => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=portal&mode=modules'),
|
||||||
|
'S_INSTALL' => true,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$file->remove();
|
$file->remove();
|
||||||
|
$this->directory_delete($mod_dir);
|
||||||
if ($file->init_error || sizeof($file->error))
|
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);
|
trigger_error((sizeof($file->error) ? implode('<br />', $file->error) : $user->lang['MOD_UPLOAD_INIT_FAIL']) . adm_back_link($this->u_action), E_USER_WARNING);
|
||||||
@@ -223,8 +220,8 @@ class portal_upload
|
|||||||
'L_TITLE' => $user->lang['ACP_PORTAL_UPLOAD'],
|
'L_TITLE' => $user->lang['ACP_PORTAL_UPLOAD'],
|
||||||
'L_TITLE_EXPLAIN' => '',
|
'L_TITLE_EXPLAIN' => '',
|
||||||
|
|
||||||
'S_ERROR' => (sizeof($error)) ? true : false,
|
'S_ERROR' => false, // if we get here, there was no error or we can ignore it
|
||||||
'ERROR_MSG' => implode('<br />', $error),
|
'ERROR_MSG' => '',
|
||||||
|
|
||||||
'U_ACTION' => $this->u_action,
|
'U_ACTION' => $this->u_action,
|
||||||
));
|
));
|
||||||
@@ -241,27 +238,148 @@ class portal_upload
|
|||||||
$cut_array = array('.', '..');
|
$cut_array = array('.', '..');
|
||||||
$folder_content = array_diff($folder_content, $cut_array);
|
$folder_content = array_diff($folder_content, $cut_array);
|
||||||
|
|
||||||
return $folder_content
|
return $folder_content;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 determine_write_method($pre_install = false)
|
function directory_delete($dir)
|
||||||
{
|
{
|
||||||
global $phpbb_root_path, $config;
|
if (!file_exists($dir))
|
||||||
|
|
||||||
/*
|
|
||||||
* to be truly correct, we should scan all files ...
|
|
||||||
* no ftp upload here
|
|
||||||
*/
|
|
||||||
if ((is_writable($phpbb_root_path)) || $pre_install)
|
|
||||||
{
|
{
|
||||||
$write_method = 'direct';
|
return true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (!is_dir($dir) && is_file($dir))
|
||||||
{
|
{
|
||||||
$write_method = 'manual';
|
phpbb_chmod($dir, CHMOD_ALL);
|
||||||
|
return unlink($dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $write_method;
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves files or complete directories
|
||||||
|
*
|
||||||
|
* @param $from string Can be a file or a directory. Will move either the file or all files within the directory
|
||||||
|
* @param $to string Where to move the file(s) to. If not specified then will get moved to the root folder
|
||||||
|
* @param $strip Used for FTP only
|
||||||
|
* @return mixed: Bool true on success, error string on failure, NULL if no action was taken
|
||||||
|
*
|
||||||
|
* NOTE: function should preferably not return in case of failure on only one file.
|
||||||
|
* The current method makes error handling difficult
|
||||||
|
*/
|
||||||
|
function copy_content($from, $to = '', $strip = '')
|
||||||
|
{
|
||||||
|
global $phpbb_root_path, $user, $config;
|
||||||
|
|
||||||
|
if (strpos($from, $phpbb_root_path) !== 0)
|
||||||
|
{
|
||||||
|
$from = $phpbb_root_path . $from;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strpos($to, $phpbb_root_path) !== 0)
|
||||||
|
{
|
||||||
|
$to = $phpbb_root_path . $to;
|
||||||
|
}
|
||||||
|
|
||||||
|
$dirname_check = dirname($to);
|
||||||
|
|
||||||
|
if (!is_dir($dirname_check))
|
||||||
|
{
|
||||||
|
if ($this->recursive_mkdir($dirname_check) === false)
|
||||||
|
{
|
||||||
|
return sprintf($user->lang['MODULE_UPLOAD_MKDIR_FAILURE'], $dirname_check);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$dest = $to;
|
||||||
|
|
||||||
|
if (!@copy($from, $to))
|
||||||
|
{
|
||||||
|
return sprintf($user->lang['MODULE_COPY_FAILURE'], $dest);
|
||||||
|
}
|
||||||
|
@chmod($dest, octdec(0666));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Michal Nazarewicz (from the php manual)
|
||||||
|
* Creates all non-existant directories in a path
|
||||||
|
* @param $path - path to create
|
||||||
|
* @param $mode - CHMOD the new dir to these permissions
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function recursive_mkdir($path, $mode = false)
|
||||||
|
{
|
||||||
|
if (!$mode)
|
||||||
|
{
|
||||||
|
global $config;
|
||||||
|
$mode = octdec(0777);
|
||||||
|
}
|
||||||
|
|
||||||
|
$dirs = explode('/', $path);
|
||||||
|
$count = sizeof($dirs);
|
||||||
|
$path = '.';
|
||||||
|
for ($i = 0; $i < $count; $i++)
|
||||||
|
{
|
||||||
|
$path .= '/' . $dirs[$i];
|
||||||
|
|
||||||
|
if (!is_dir($path))
|
||||||
|
{
|
||||||
|
@mkdir($path, $mode);
|
||||||
|
@chmod($path, $mode);
|
||||||
|
|
||||||
|
if (!is_dir($path))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user