Skip to content

Commit

Permalink
Merge pull request #115 from ggoffy/master
Browse files Browse the repository at this point in the history
added feature to clone module
  • Loading branch information
ggoffy committed Oct 13, 2021
2 parents 2011d38 + bd9e99c commit 573835a
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 48 deletions.
188 changes: 148 additions & 40 deletions admin/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,21 @@
*
*/

use Xmf\Request;

// Define main template
$templateMain = 'modulebuilder_modules.tpl';

require __DIR__ . '/header.php';
// Recovered value of argument op in the URL $
$op = \Xmf\Request::getString('op', 'list');
$modId = \Xmf\Request::getInt('mod_id');
$op = Request::getString('op', 'list');
$modId = Request::getInt('mod_id');

switch ($op) {
case 'list':
default:
$start = \Xmf\Request::getInt('start', 0);
$limit = \Xmf\Request::getInt('limit', $helper->getConfig('modules_adminpager'));
$start = Request::getInt('start', 0);
$limit = Request::getInt('limit', $helper->getConfig('modules_adminpager'));
$GLOBALS['xoTheme']->addScript('modules/modulebuilder/assets/js/functions.js');
$GLOBALS['xoTheme']->addStylesheet('modules/modulebuilder/assets/css/admin/style.css');
$GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('modules.php'));
Expand Down Expand Up @@ -89,29 +91,29 @@
} else {
$modulesObj = $helper->getHandler('Modules')->create();
}
$moduleDirname = \preg_replace('/[^a-zA-Z0-9]\s+/', '', \mb_strtolower(\Xmf\Request::getString('mod_dirname', '', 'POST')));
$moduleDirname = \preg_replace('/[^a-zA-Z0-9]\s+/', '', \mb_strtolower(Request::getString('mod_dirname', '', 'POST')));
//Form module save
$modulesObj->setVars(
[
'mod_name' => \Xmf\Request::getString('mod_name', '', 'POST'),
'mod_name' => Request::getString('mod_name', '', 'POST'),
'mod_dirname' => $moduleDirname,
'mod_version' => \Xmf\Request::getString('mod_version', '', 'POST'),
'mod_since' => \Xmf\Request::getString('mod_since', '', 'POST'),
'mod_min_php' => \Xmf\Request::getString('mod_min_php', '', 'POST'),
'mod_min_xoops' => \Xmf\Request::getString('mod_min_xoops', '', 'POST'),
'mod_min_admin' => \Xmf\Request::getString('mod_min_admin', '', 'POST'),
'mod_min_mysql' => \Xmf\Request::getString('mod_min_mysql', '', 'POST'),
'mod_description' => \Xmf\Request::getString('mod_description', '', 'POST'),
'mod_author' => \Xmf\Request::getString('mod_author', '', 'POST'),
'mod_author_mail' => \Xmf\Request::getString('mod_author_mail', '', 'POST'),
'mod_author_website_url' => \Xmf\Request::getString('mod_author_website_url', '', 'POST'),
'mod_author_website_name' => \Xmf\Request::getString('mod_author_website_name', '', 'POST'),
'mod_credits' => \Xmf\Request::getString('mod_credits', '', 'POST'),
'mod_license' => \Xmf\Request::getString('mod_license', '', 'POST'),
'mod_release_info' => \Xmf\Request::getString('mod_release_info', '', 'POST'),
'mod_release_file' => \Xmf\Request::getString('mod_release_file', '', 'POST'),
'mod_manual' => \Xmf\Request::getString('mod_manual', '', 'POST'),
'mod_manual_file' => \Xmf\Request::getString('mod_manual_file', '', 'POST'),
'mod_version' => Request::getString('mod_version', '', 'POST'),
'mod_since' => Request::getString('mod_since', '', 'POST'),
'mod_min_php' => Request::getString('mod_min_php', '', 'POST'),
'mod_min_xoops' => Request::getString('mod_min_xoops', '', 'POST'),
'mod_min_admin' => Request::getString('mod_min_admin', '', 'POST'),
'mod_min_mysql' => Request::getString('mod_min_mysql', '', 'POST'),
'mod_description' => Request::getString('mod_description', '', 'POST'),
'mod_author' => Request::getString('mod_author', '', 'POST'),
'mod_author_mail' => Request::getString('mod_author_mail', '', 'POST'),
'mod_author_website_url' => Request::getString('mod_author_website_url', '', 'POST'),
'mod_author_website_name' => Request::getString('mod_author_website_name', '', 'POST'),
'mod_credits' => Request::getString('mod_credits', '', 'POST'),
'mod_license' => Request::getString('mod_license', '', 'POST'),
'mod_release_info' => Request::getString('mod_release_info', '', 'POST'),
'mod_release_file' => Request::getString('mod_release_file', '', 'POST'),
'mod_manual' => Request::getString('mod_manual', '', 'POST'),
'mod_manual_file' => Request::getString('mod_manual_file', '', 'POST'),
]
);
//Form mod_image
Expand All @@ -128,24 +130,24 @@
$modulesObj->setVar('mod_image', $uploader->getSavedFileName());
}
} else {
$modulesObj->setVar('mod_image', \Xmf\Request::getString('mod_image', '', 'POST'));
$modulesObj->setVar('mod_image', Request::getString('mod_image', '', 'POST'));
}
//Form module save
$modulesObj->setVars(
[
'mod_demo_site_url' => \Xmf\Request::getString('mod_demo_site_url', '', 'POST'),
'mod_demo_site_name' => \Xmf\Request::getString('mod_demo_site_name', '', 'POST'),
'mod_support_url' => \Xmf\Request::getString('mod_support_url', '', 'POST'),
'mod_support_name' => \Xmf\Request::getString('mod_support_name', '', 'POST'),
'mod_website_url' => \Xmf\Request::getString('mod_website_url', '', 'POST'),
'mod_website_name' => \Xmf\Request::getString('mod_website_name', '', 'POST'),
'mod_release' => \Xmf\Request::getString('mod_release', '', 'POST'),
'mod_status' => \Xmf\Request::getString('mod_status', '', 'POST'),
'mod_donations' => \Xmf\Request::getString('mod_donations', '', 'POST'),
'mod_subversion' => \Xmf\Request::getString('mod_subversion', '', 'POST'),
'mod_demo_site_url' => Request::getString('mod_demo_site_url', '', 'POST'),
'mod_demo_site_name' => Request::getString('mod_demo_site_name', '', 'POST'),
'mod_support_url' => Request::getString('mod_support_url', '', 'POST'),
'mod_support_name' => Request::getString('mod_support_name', '', 'POST'),
'mod_website_url' => Request::getString('mod_website_url', '', 'POST'),
'mod_website_name' => Request::getString('mod_website_name', '', 'POST'),
'mod_release' => Request::getString('mod_release', '', 'POST'),
'mod_status' => Request::getString('mod_status', '', 'POST'),
'mod_donations' => Request::getString('mod_donations', '', 'POST'),
'mod_subversion' => Request::getString('mod_subversion', '', 'POST'),
]
);
$moduleOption = \Xmf\Request::getArray('module_option', []);
$moduleOption = Request::getArray('module_option', []);
$modulesObj->setVar('mod_admin', \in_array('admin', $moduleOption));
$modulesObj->setVar('mod_user', \in_array('user', $moduleOption));
$modulesObj->setVar('mod_blocks', \in_array('blocks', $moduleOption));
Expand All @@ -157,9 +159,9 @@

if ($helper->getHandler('Modules')->insert($modulesObj)) {
if ($modulesObj->isNew()) {
\redirect_header('tables.php', 5, \sprintf(\_AM_MODULEBUILDER_MODULE_FORM_CREATED_OK, \Xmf\Request::getString('mod_name', '', 'POST')));
\redirect_header('tables.php', 5, \sprintf(\_AM_MODULEBUILDER_MODULE_FORM_CREATED_OK, Request::getString('mod_name', '', 'POST')));
} else {
\redirect_header('modules.php', 5, \sprintf(\_AM_MODULEBUILDER_MODULE_FORM_UPDATED_OK, \Xmf\Request::getString('mod_name', '', 'POST')));
\redirect_header('modules.php', 5, \sprintf(\_AM_MODULEBUILDER_MODULE_FORM_UPDATED_OK, Request::getString('mod_name', '', 'POST')));
}
}

Expand Down Expand Up @@ -208,7 +210,7 @@
} else {
$xoopsconfirm = new \XoopsModules\Modulebuilder\Common\XoopsConfirm(
['ok' => 1, 'mod_id' => $modId, 'op' => 'delete'],
\Xmf\Request::getString('REQUEST_URI', '', 'SERVER'),
Request::getString('REQUEST_URI', '', 'SERVER'),
$modulesObj->getVar('mod_name')
);
$form = $xoopsconfirm->getFormXoopsConfirm();
Expand All @@ -217,7 +219,7 @@
break;
case 'display':
$modFieldArray = ['admin', 'user', 'blocks', 'search', 'comments', 'notifications', 'permissions'];
$id = \Xmf\Request::getInt('mod_id', 0, 'POST');
$id = Request::getInt('mod_id', 0, 'POST');
if ($id > 0) {
$modulesObj = $helper->getHandler('Modules')->get($id);
foreach ($modFieldArray as $moduleField) {
Expand All @@ -231,8 +233,114 @@
}
$GLOBALS['xoopsTpl']->assign('error', $modulesObj->getHtmlErrors());
}
break;
case 'clone':
$modIdSource = Request::getInt('mod_id', 0);
if ($modIdSource > 0) {
//clone data table modules
$modulesHandler = $helper->getHandler('Modules');
$tablesHandler = $helper->getHandler('Tables');
$fieldsHandler = $helper->getHandler('Fields');
$moduleSource = $modulesHandler->get($modIdSource);
$moduleTarget = $modulesHandler->create();
$sourceVars = $moduleSource->getVars();
foreach ($sourceVars as $varKey => $varArray) {
if ('mod_id' !== $varKey) {
if (in_array($varKey, ['mod_name', 'mod_dirname'])) {
for ($i = 1; $i <= 10; $i++) {
$uniqValue = $varArray['value'] . $i;
$result = $GLOBALS['xoopsDB']->query(
'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('modulebuilder_modules') . " as ms WHERE ms.{$varKey} = '{$uniqValue}'"
);
$num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
if ($num_rows == 0) {
break;
}
}
$moduleTarget->setVar($varKey, $uniqValue);
} else {
$moduleTarget->setVar($varKey, $varArray['value']);
}
}
}

if ($modulesHandler->insert($moduleTarget)) {
//get new mod_id
$modIdTarget = $GLOBALS['xoopsDB']->getInsertId();
} else {
\redirect_header('modules.php', 5, \_AM_MODULEBUILDER_MODULE_CLONE_ERROR);
}

//clone data table tables
$resultTables = $GLOBALS['xoopsDB']->query(
'SELECT table_id FROM ' . $GLOBALS['xoopsDB']->prefix('modulebuilder_tables') . " as ts WHERE ts.table_mid = '{$modIdSource}'"
);
$num_rows1 = $GLOBALS['xoopsDB']->getRowsNum($resultTables);
if ($num_rows1 > 0) {
while (false !== ($myTables = $GLOBALS['xoopsDB']->fetchArray($resultTables))) {
$tableIdSource = $myTables['table_id'];
$tableSource = $tablesHandler->get($tableIdSource);
$tableTarget = $tablesHandler->create();
$sourceVars = $tableSource->getVars();
foreach ($sourceVars as $varKey => $varArray) {
//skip table_id
if ('table_id' !== $varKey) {
//replace mod_id by new mod_id
if ('table_mid' === $varKey) {
$tableTarget->setVar($varKey, $modIdTarget);
} else {
$tableTarget->setVar($varKey, $varArray['value']);
}
}
}
if ($tablesHandler->insert($tableTarget)) {
//get new table_id
$tableIdTarget = $GLOBALS['xoopsDB']->getInsertId();
} else {
\redirect_header('modules.php', 5, \_AM_MODULEBUILDER_MODULE_CLONE_ERROR);
}

//clone data table fields
$resultFields = $GLOBALS['xoopsDB']->query(
'SELECT field_id FROM ' . $GLOBALS['xoopsDB']->prefix('modulebuilder_fields') . " as fs WHERE fs.field_tid = '{$tableIdSource}'"
);
$num_rows2 = $GLOBALS['xoopsDB']->getRowsNum($resultFields);
if ($num_rows2 > 0) {
while (false !== ($myField = $GLOBALS['xoopsDB']->fetchArray($resultFields))) {
$fieldIdSource = $myField['field_id'];
$fieldsSource = $fieldsHandler->get($fieldIdSource);
$fieldsTarget = $fieldsHandler->create();
$sourceVars = $fieldsSource->getVars();
foreach ($sourceVars as $varKey => $varArray) {
//skip field_id
if ('field_id' !== $varKey) {
if ('field_mid' === $varKey) {
//replace mod_id by new mod_id
$fieldsTarget->setVar($varKey, $modIdTarget);
} elseif ('field_tid' === $varKey) {
//replace table_id by new table_id
$fieldsTarget->setVar($varKey, $tableIdTarget);
} else {
$fieldsTarget->setVar($varKey, $varArray['value']);
}
}
}
if (!$fieldsHandler->insert($fieldsTarget)) {
\redirect_header('modules.php', 5, \_AM_MODULEBUILDER_MODULE_CLONE_ERROR);
}
}
}
}
}

\redirect_header('modules.php', 5, \_AM_MODULEBUILDER_MODULE_CLONE_SUCCESS);
}





break;
}

require __DIR__ . '/footer.php';

Binary file added assets/images/icons/32/page_copy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<h5>3.05 RC2 [2021-10-13]</h5> Dev: XOOPS 2.5.11, PHP 7.4.5
<hr>
- added icon for clone (goffy)
- added feature to clone module (mamba/goffy)

<h5>3.05 RC1 [2020-11-11]</h5> Dev: XOOPS 2.5.11, PHP 7.4.5
<hr>
- fixed bug with l\trim (alain/goffy)
Expand Down
8 changes: 8 additions & 0 deletions include/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,13 @@ function xoops_module_install_modulebuilder(\XoopsModule $module)
}
}

// --- COPY page_copy.png ---------------
// needed for clone feature of by modulebuilder created modules
$dest =\XOOPS_ROOT_PATH . '/Frameworks/moduleclasses/icons/32/page_copy.png';
if (!\file_exists($dest)) {
$file = \dirname(__DIR__) . '/assets/images/icons/32/page_copy.png';
$utility::copyFile($file, $dest);
}

return true;
}
2 changes: 2 additions & 0 deletions language/english/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@
\define('_AM_MODULEBUILDER_MODULE_FORM_UPDATED_OK', "The module <b class='green'>%s</b> is successfully updated");
\define('_AM_MODULEBUILDER_MODULE_BUTTON_NEW_LOGO', 'Create new Logo');
\define('_AM_MODULEBUILDER_MODULE_NOACTSET', 'Error: No active setting found');
\define('_AM_MODULEBUILDER_MODULE_CLONE_SUCCESS', 'Module successfully cloned');
\define('_AM_MODULEBUILDER_MODULE_CLONE_ERROR', 'An error occured when cloning module');
//
// ------------------- Tables --------------------------------- //
// buttons
Expand Down
13 changes: 6 additions & 7 deletions templates/admin/modulebuilder_modules.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,13 @@
</td>
<td class='xo-actions txtcenter width5'>
<a href="modules.php?op=edit&amp;mod_id=<{$module.id}>" title="<{$smarty.const._EDIT}>">
<img src="<{xoModuleIcons16 edit.png}>" alt="<{$smarty.const._EDIT}>"/>
</a>
<img src="<{xoModuleIcons16 edit.png}>" alt="<{$smarty.const._EDIT}>"/></a>
<a href="modules.php?op=delete&amp;mod_id=<{$module.id}>" title="<{$smarty.const._DELETE}>">
<img src="<{xoModuleIcons16 delete.png}>" alt="<{$smarty.const._DELETE}>"/>
</a>
<a href="building.php?op=build&amp;mod_id=<{$module.id}>"><img src="<{xoModuleIcons16 forward.png}>"
alt="<{$smarty.const._AM_MODULEBUILDER_ADMIN_CONST}>"
title="<{$smarty.const._AM_MODULEBUILDER_ADMIN_CONST}>"></a>
<img src="<{xoModuleIcons16 delete.png}>" alt="<{$smarty.const._DELETE}>"/></a>
<a href="building.php?op=build&amp;mod_id=<{$module.id}>">
<img src="<{xoModuleIcons16 forward.png}>" alt="<{$smarty.const._AM_MODULEBUILDER_ADMIN_CONST}>" title="<{$smarty.const._AM_MODULEBUILDER_ADMIN_CONST}>"></a>
<a href="modules.php?op=clone&amp;mod_id=<{$module.id}>" title="<{$smarty.const._CLONE}>">
<img src="<{xoModuleIcons16 editcopy.png}>" alt="<{$smarty.const._CLONE}>"/></a>
</td>
</tr>
<{/foreach}>
Expand Down
2 changes: 1 addition & 1 deletion xoops_version.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
$moduleDirNameUpper = \mb_strtoupper($moduleDirName);

$modversion['version'] = 3.05;
$modversion['module_status'] = 'RC1';
$modversion['module_status'] = 'RC2';
$modversion['release_date'] = '2020/11/11';
$modversion['name'] = \_MI_MODULEBUILDER_NAME;
$modversion['description'] = \_MI_MODULEBUILDER_DESC;
Expand Down

0 comments on commit 573835a

Please sign in to comment.