Merge pull request #430 from marc1706/ticket/429

[ticket/429] Remove upload module
This commit is contained in:
Marc Alexander
2014-12-01 15:06:07 +01:00
10 changed files with 4 additions and 519 deletions

2
.gitattributes vendored
View File

@@ -10,5 +10,3 @@ git-tools/ export-ignore
.coveralls.yml export-ignore
composer.phar export-ignore
composer.lock export-ignore
portal/upload/ export-ignore
includes/functions_upload.php export-ignore

View File

@@ -19,11 +19,10 @@ class portal_info
return array(
'filename' => '\board3\portal\acp\portal_module',
'title' => 'ACP_PORTAL',
'version' => '2.0.0b2',
'version' => '2.0.1-rc1',
'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')),
// 'upload_module' => array('title' => 'ACP_PORTAL_UPLOAD', 'auth' => 'acl_a_manage_portal', 'cat' => array('ACP_PORTAL')),
),
);
}

View File

@@ -690,47 +690,7 @@ class portal_module
$this->tpl_name = 'portal/acp_portal_modules';
$this->page_title = 'ACP_PORTAL_MODULES';
break;
case 'upload_module':
$error = array();
if($submit)
{
if(!check_form_key('acp_portal_module_upload'))
{
trigger_error($this->user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
}
include($this->root_path . 'includes/functions_upload.' . $this->php_ext);
// Default upload path is portal/upload/
$upload_path = $this->root_path . 'portal/upload/';
new portal_upload($upload_path, $this->u_action);
$this->tpl_name = 'portal/acp_portal_upload_module';
$this->page_title = $this->user->lang['ACP_PORTAL_UPLOAD'];
}
else
{
// start the page
$this->template->assign_vars(array(
'U_UPLOAD' => $this->u_action,
'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"',
));
add_form_key('acp_portal_module_upload');
$this->tpl_name = 'portal/acp_portal_upload_module';
$this->page_title = $this->user->lang['ACP_PORTAL_UPLOAD'];
$this->template->assign_vars(array(
'L_TITLE' => $this->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;

View File

@@ -1,63 +0,0 @@
<!-- 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>
<dt>{L_MODULE_UPLOAD_EXP}</dt>
<dd>
<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" />
</dd>
</dl>
</fieldset>
</form>
<!-- ELSE -->
<div class="successbox">
<p>{MESSAGE}</p>
<br />
<p><a href="{U_RETURN}">{L_BACK}</a></p>
</div>
<fieldset>
<legend>{L_PORTAL_NEW_FILES}</legend>
<table cellspacing="1">
<col class="row1" /><col class="row1" /><col class="row2" />
<thead>
<tr>
<th>{L_PORTAL_MODULE_SOURCE}</th>
<th>{L_PORTAL_MODULE_TARGET}</th>
<th>{L_PORTAL_MODULE_STATUS}</th>
</tr>
</thead>
<tbody>
<!-- BEGIN new_files -->
<tr>
<td><strong>{new_files.SOURCE}<!-- IF new_files.S_MISSING_FILE -->&nbsp;&nbsp;&nbsp;<strong><font color="red">({L_FILE_MISSING})</font><!-- ENDIF --></strong></td>
<td>{new_files.TARGET}</td>
<!-- IF S_INSTALL -->
<td style="<!-- IF new_files.S_SUCCESS -->color: green;">{L_PORTAL_MODULE_SUCCESS}<!-- ELSE -->color: red;">{L_PORTAL_MODULE_ERROR}<!-- ENDIF --></td>
<!-- ENDIF -->
</tr>
<!-- END new_files -->
</tbody>
</table>
</fieldset>
<!-- ENDIF -->
<!-- INCLUDE overall_footer.html -->

View File

@@ -1,354 +0,0 @@
<?php
/**
*
* @package Board3 Portal v2.1
* @copyright (c) 2013 Board3 Group ( www.board3.de )
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace board3\portal\includes;
/**
* @ignore
*/
class portal_upload
{
/*
* pre-defined vars
*/
private $upload_path;
private $u_action;
/*
* constructor function
*/
public function __construct($path, $u_action)
{
// This shouldn't happen, but we check for it anyways
if(is_dir($path))
{
$this->upload_path = $path;
$this->u_action = $u_action;
$this->upload_file();
}
}
/**
* upload module zip
*/
private function upload_file()
{
global $user, $phpbb_root_path, $phpEx, $phpbb_admin_path, $template;
// 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');
// this is for module zips so don't allow anything else
if (empty($file->filename) || !preg_match('.zip.', $file->get('realname')))
{
trigger_error($user->lang['NO_FILE_B3P'] . 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, '', $this->upload_path), true, true);
if (!sizeof($file->error))
{
include($phpbb_root_path . 'includes/functions_compress.' . $phpEx);
$mod_dir = $this->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], $this->upload_path . $folder_contents[0]);
$new_mod_dir = $this->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);
$new_mod_dir = $mod_dir;
}
$this->directory_delete($mod_dir . '_tmp/');
// make sure we set $mod_dir to the correct folder after the above step
$mod_dir = (isset($new_mod_dir)) ? $new_mod_dir : $mod_dir;
// 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));
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($mod_dir, FilesystemIterator::SKIP_DOTS)); // requires PHP 5
foreach($iterator as $cur_file)
{
$cur_path = $cur_file->getPathname();
$cur_path = str_replace('\\', '/', $cur_path); // we want unix-like paths
$cur_path = str_replace($mod_dir . '/', '', $cur_path);
$cut_pos = strpos($cur_path, '/');
// Only allow files in adm, language, portal and styles folder and a license.txt
if(!in_array(substr($cur_path, 0, $cut_pos), array('adm', 'language', 'portal', 'styles')) && $cur_file->getFilename() != 'license.txt')
{
$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&amp;mode=modules')), E_USER_WARNING);
}
else
{
$actions['NEW_FILES'][$mod_dir . '/' . $cur_path] = $phpbb_root_path . $cur_path;
}
}
if (!sizeof($file->error))
{
// Let's start moving our files where they belong
foreach ($actions['NEW_FILES'] as $source => $target)
{
/*
* make sure we don't try to copy folders
* folders will be created if necessary in copy_content
*/
if(is_dir($source))
{
continue;
}
$status = $this->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,
));
}
$template->assign_vars(array(
'S_MOD_SUCCESSBOX' => true,
'MESSAGE' => $user->lang['MODULE_UPLOADED'],
'U_RETURN' => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=portal&amp;mode=modules'),
'S_INSTALL' => true,
));
}
}
}
$file->remove();
$this->directory_delete($mod_dir);
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' => false, // if we get here, there was no error or we can ignore it
'ERROR_MSG' => '',
'U_ACTION' => $this->u_action,
));
}
}
/**
* Cuts the unneeded '.' and '..' from the folder content info scandir returns
*
* @return: cut array
*/
private function cut_folder($folder_content)
{
$cut_array = array('.', '..');
$folder_content = array_diff($folder_content, $cut_array);
return $folder_content;
}
private function directory_move($src, $dest)
{
$src_contents = scandir($src);
if (!is_dir($dest) && is_dir($src))
{
mkdir($dest . '/', 0755);
}
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, 0644);
}
}
}
}
/**
* the following functions are from the AutoMOD package
* @copyright (c) 2008 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
*/
private function directory_delete($dir)
{
if (!file_exists($dir))
{
return true;
}
if (!is_dir($dir) && is_file($dir))
{
@chmod($dir, 0644);
return @unlink($dir);
}
foreach (scandir($dir) as $item)
{
if ($item == '.' || $item == '..')
{
continue;
}
if (!$this->directory_delete($dir . "/" . $item))
{
@chmod($dir . "/" . $item, 0644);
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
*/
private 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);
}
}
// leave a backup file if it already exists
if(file_exists($to))
{
// remove old backup file first
if(file_exists($to . '.bak'))
{
@chmod($to . '.bak', 0644);
unlink($to . '.bak');
}
@rename($to, $to . '.bak');
@chmod($to, 0644);
}
if (!@copy($from, $to))
{
return sprintf($user->lang['MODULE_COPY_FAILURE'], $to);
}
@chmod($to, 0644);
return true;
}
/**
* @author Michal Nazarewicz (from the php manual)
* Creates all non-existent directories in a path
* @param $path - path to create
* @param $mode - CHMOD the new dir to these permissions
* @return bool
*/
private function recursive_mkdir($path, $mode = false)
{
if (!$mode)
{
$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;
}
}

View File

@@ -98,23 +98,6 @@ $lang = array_merge($lang, array(
'LINK_ADDED' => 'Der Link wurde erfolgreich eingetragen',
'LINK_UPDATED' => 'Der Link wurde erfolgreich geändert',
// Upload Module
'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_FILE_B3P' => 'Es wurde keine Zip-Datei ausgewählt.',
'MODULE_UPLOADED' => 'Modul 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.',
'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
'PORTAL_BASIC_INSTALL' => 'Füge Basismodule hinzu',
'PORTAL_BASIC_UNINSTALL' => 'Entferne Module von Datenbank',

View File

@@ -97,23 +97,6 @@ $lang = array_merge($lang, array(
'LINK_ADDED' => 'The link has been successfully added',
'LINK_UPDATED' => 'The link has been successfully updated',
// 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_FILE_B3P' => 'No zip file specified.',
'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.',
'PORTAL_NEW_FILES' => 'New files',
'PORTAL_MODULE_SOURCE' => 'Source',
'PORTAL_MODULE_TARGET' => 'Target',
'PORTAL_MODULE_STATUS' => 'Status',
'PORTAL_MODULE_SUCCESS' => 'Success',
'PORTAL_MODULE_ERROR' => 'Error',
// Install
'PORTAL_BASIC_INSTALL' => 'Adding basic set of modules',
'PORTAL_BASIC_UNINSTALL' => 'Removing modules from database',

View File

@@ -69,6 +69,7 @@ $lang = array_merge($lang, array(
'MODULE_ADD_ONCE' => 'Deze module kan maar één keer worden toegevoegd.',
'MODULE_IMAGE_ERROR' => 'Er is een fout opgetreden tijdens het controleren van de module afbeelding:',
'UNKNOWN_MODULE_METHOD' => 'De methode van de %1$s module kan niet worden gevonden.',
// general
'ACP_PORTAL_CONFIG_INFO' => 'Algemene instellingen',
'ACP_PORTAL_GENERAL_TITLE' => 'Portaal beheer',
@@ -89,25 +90,11 @@ $lang = array_merge($lang, array(
'PORTAL_RIGHT_COLUMN_WIDTH_EXP' => 'Verander de breedte van de rechterkolom in pixels; aanbevolen waarde is 180',
'LINK_ADDED' => 'De link is succesvol toegevoegd',
'LINK_UPDATED' => 'De link is succesvol gewijzigd',
// Upload Module
'MODULE_UPLOAD' => 'Een module uploaden',
'MODULE_UPLOAD_EXP' => 'Kies het ZIP-bestand van de module die je wilt uploaden:',
'MODULE_UPLOAD_GO' => 'Upload',
'NO_MODULE_UPLOAD' => 'Je server configuratie staat het uploaden van bestanden niet toe.',
'NO_FILE_B3P' => 'Geen zip-bestand gespecificeerd.',
'MODULE_UPLOADED' => 'Module succesvol geüpload.',
'MODULE_UPLOAD_MKDIR_FAILURE' => 'Niet instaat om een map aan te maken.',
'MODULE_COPY_FAILURE' => 'Niet instaat om de map: %1$s te kopiëren',
'MODULE_CORRUPTED' => 'De module die je probeert te uploaden lijkt corrupt te zijn.',
'PORTAL_NEW_FILES' => 'Nieuwe bestanden',
'PORTAL_MODULE_SOURCE' => 'Bron',
'PORTAL_MODULE_TARGET' => 'Doel',
'PORTAL_MODULE_STATUS' => 'Status',
'PORTAL_MODULE_SUCCESS' => 'Succes',
'PORTAL_MODULE_ERROR' => 'Fout',
// Install
'PORTAL_BASIC_INSTALL' => 'Basisset van modules toevoegen',
'PORTAL_BASIC_UNINSTALL' => 'Modules verwijderen uit de database',
/**
* A copy of Handyman` s MOD version check, to view it on the portal overview
*/

View File

@@ -1,7 +0,0 @@
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
</head>
<body bgcolor="#FFFFFF" text="#000000">
</body>
</html>

View File

@@ -25,7 +25,6 @@ class phpbb_functional_portal_acp_test extends \board3\portal\tests\testframewor
return array(
array('config'),
array('modules'),
// array('upload_module'),
);
}