diff --git a/root/adm/style/portal/acp_portal_upload_module.html b/root/adm/style/portal/acp_portal_upload_module.html index 3b17c50b..d29ace3f 100755 --- a/root/adm/style/portal/acp_portal_upload_module.html +++ b/root/adm/style/portal/acp_portal_upload_module.html @@ -31,18 +31,18 @@

{MESSAGE}


-

{L_RETURN_MODS}

+

{L_BACK}

- {L_NEW_FILES} + {L_PORTAL_NEW_FILES} - - - + + + @@ -51,7 +51,7 @@ - + diff --git a/root/includes/acp/acp_portal.php b/root/includes/acp/acp_portal.php index 5cbee843..b4729682 100644 --- a/root/includes/acp/acp_portal.php +++ b/root/includes/acp/acp_portal.php @@ -907,228 +907,28 @@ class acp_portal $error = array(); 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); // 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'); + $portal_upload = new portal_upload($upload_path, $this->u_action); - 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, - )); - } + $this->tpl_name = 'portal/acp_portal_upload_module'; + $this->page_title = $user->lang['ACP_PORTAL_UPLOAD']; } 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'); + add_form_key('acp_portal_module_upload'); $this->tpl_name = 'portal/acp_portal_upload_module'; $this->page_title = $user->lang['ACP_PORTAL_UPLOAD']; @@ -1149,64 +949,4 @@ class acp_portal 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); - } } diff --git a/root/language/de/mods/info_acp_portal.php b/root/language/de/mods/info_acp_portal.php index 6c483839..5cbb6857 100644 --- a/root/language/de/mods/info_acp_portal.php +++ b/root/language/de/mods/info_acp_portal.php @@ -105,12 +105,21 @@ $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' => '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', 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..735df998 --- /dev/null +++ b/root/portal/includes/functions_upload.php @@ -0,0 +1,333 @@ +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'); + + 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, '', $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)); // requires PHP >= 5.1.0 + + 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, '/'); + + if(!in_array(substr($cur_path, 0, $cut_pos), array('portal', 'language', 'styles'))) + { + $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); + } + 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) + { + $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&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('
', $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 . '/', octdec(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, octdec(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)) + { + 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); + } + + /** + * 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); + } + } + + if (!@copy($from, $to)) + { + return sprintf($user->lang['MODULE_COPY_FAILURE'], $to); + } + @chmod($to, 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 + */ + 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; + } +} \ No newline at end of file
{L_SOURCE}{L_TARGET}{L_STATUS}{L_PORTAL_MODULE_SOURCE}{L_PORTAL_MODULE_TARGET}{L_PORTAL_MODULE_STATUS}
{new_files.SOURCE}   ({L_FILE_MISSING}) {new_files.TARGET} {L_SUCCESS}{L_MANUAL_COPY}{L_ERROR}{L_PORTAL_MODULE_SUCCESS}{L_PORTAL_MODULE_ERROR}