diff --git a/.scrutinizer.yml b/.scrutinizer.yml index d758d13..40b69d7 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,5 +1,7 @@ # language: php build: + environment: + php: 8.0.11 nodes: tests: true analysis: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a88517a..fa7d1a0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,7 +1,7 @@ ![alt XOOPS CMS](https://xoops.org/images/logoXoops4GithubRepository.png) # Contributing to [XOOPS CMS](https://xoops.org) [![XOOPS CMS Module](https://img.shields.io/badge/XOOPS%20CMS-Module-blue.svg)](https://xoops.org) -[![Software License](https://img.shields.io/badge/license-GPL-brightgreen.svg?style=flat)](http://www.gnu.org/licenses/gpl-2.0.html) +[![Software License](https://img.shields.io/badge/license-GPL-brightgreen.svg?style=flat)](https://www.gnu.org/licenses/gpl-2.0.html) Contributions are **welcome** and will be fully **credited**. @@ -10,8 +10,8 @@ We accept contributions via Pull Requests on [Github](https://github.com/XoopsMo ## Pull Requests - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer). -- **Add tests!** - We encourage to provide tests for your contributions. -- **Document any change in behavior** - Make sure the `/docs/changelog.txt` and any other relevant documentation are kept up-to-date. +- **Add tests!** - We encourage providing tests for your contributions. +- **Document any change in behavior** - Make sure the `/docs/changelog.txt` and any other relevant documentation are up-to-date. - **Consider our release cycle** - We try to follow [Semantic Versioning v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. - **Create feature branches** - Don't ask us to pull from your master branch. - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. diff --git a/README.md b/README.md index 959fde3..355093c 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,15 @@ ![alt XOOPS CMS](https://xoops.org/images/logoXoops4GithubRepository.png) ## TdmDownloads module for [XOOPS CMS 2.5.9+](https://xoops.org) [![XOOPS CMS Module](https://img.shields.io/badge/XOOPS%20CMS-Module-blue.svg)](https://xoops.org) -[![Software License](https://img.shields.io/badge/license-GPL-brightgreen.svg?style=flat)](http://www.gnu.org/licenses/gpl-2.0.html) +[![Software License](https://img.shields.io/badge/license-GPL-brightgreen.svg?style=flat)](https://www.gnu.org/licenses/gpl-2.0.html) [![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/XoopsModules25x/tdmdownloads.svg?style=flat)](https://scrutinizer-ci.com/g/XoopsModules25x/tdmdownloads/?branch=master) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/95b12220e0ac4056b9af52af708379c9)](https://www.codacy.com/app/mambax7/tdmdownloads_2) [![Code Climate](https://img.shields.io/codeclimate/github/XoopsModules25x/tdmdownloads.svg?style=flat)](https://codeclimate.com/github/mambax7/tdmdownloads) -[![SensioLabsInsight](https://insight.sensiolabs.com/projects/68207475-07ff-4567-a282-6e2f119077d2/mini.png)](https://insight.sensiolabs.com/projects/68207475-07ff-4567-a282-6e2f119077d2) [![Latest Pre-Release](https://img.shields.io/github/tag/XoopsModules25x/tdmdownloads.svg?style=flat)](https://github.com/XoopsModules25x/tdmdownloads/tags/) [![Latest Version](https://img.shields.io/github/release/XoopsModules25x/tdmdownloads.svg?style=flat)](https://github.com/XoopsModules25x/tdmdownloads/releases/) -**TdmDownloads** module for [XOOPS CMS](https://xoops.org) creates a downloads section where users can download/submit/rate various files.. +**TdmDownloads** module for [XOOPS CMS](https://xoops.org) creates a Downloads section where users can download/submit/rate various files. [![Tutorial Available](https://xoops.org/images/tutorial-available-blue.svg)](https://xoops.gitbook.io/tdmdownloads-tutorial/) Tutorial: see [GitBook](https://xoops.gitbook.io/tdmdownloads-tutorial/). To contribute to the Tutorial, [fork it on GitHub](https://github.com/XoopsDocs/tdmdownloads-tutorial) @@ -19,4 +18,4 @@ To contribute to the Tutorial, [fork it on GitHub](https://github.com/XoopsDocs/ Please visit us on https://xoops.org -Current and upcoming "next generation" versions of XOOPS CMS are being crafted on GitHub at: https://github.com/XOOPS +Current and upcoming "next generation" versions of XOOPS CMS are crafted on GitHub at: https://github.com/XOOPS diff --git a/admin/about.php b/admin/about.php index 2c3f60e..8323b59 100644 --- a/admin/about.php +++ b/admin/about.php @@ -1,4 +1,5 @@ -
' . XOOPS_ROOT_PATH . '/uploads/' . $moduleDirName . '/downloads/' . '

' . _AM_TDMDOWNLOADS_ABOUT_FILEPROTECTION_INFO2 . '

'; -$fileProtection .= 'RewriteEngine on' . '
' . 'RewriteCond %{HTTP_REFERER} !' . $xoopsUrl . "/.*$ [NC]
ReWriteRule \.*$ - [F]"; +$fileProtection .= 'RewriteEngine on' . '
' . 'RewriteCond %s{HTTP_REFERER} !' . $xoopsUrl . '/.*$ [NC]
ReWriteRule \.*$ - [F]'; -$adminObject = \Xmf\Module\Admin::getInstance(); +$adminObject = Admin::getInstance(); $adminObject->addInfoBox(_AM_TDMDOWNLOADS_ABOUT_FILEPROTECTION); $adminObject->addInfoBoxLine(sprintf($fileProtection, '', '', 'information'), ''); diff --git a/admin/admin_footer.php b/admin/admin_footer.php index 7f61ed4..0ff14c1 100644 --- a/admin/admin_footer.php +++ b/admin/admin_footer.php @@ -1,4 +1,5 @@ -display("db:{$templateMain}"); } diff --git a/admin/admin_header.php b/admin/admin_header.php index 131b3bc..4e052d6 100644 --- a/admin/admin_header.php +++ b/admin/admin_header.php @@ -1,4 +1,5 @@ -isAdmin($xoopsModule->mid())) { redirect_header(XOOPS_URL . '/', 3, _NOPERM); } @@ -48,6 +54,7 @@ if (!isset($GLOBALS['xoopsTpl']) || !($GLOBALS['xoopsTpl'] instanceof XoopsTpl)) { require_once $GLOBALS['xoops']->path('class/template.php'); + $xoopsTpl = new \XoopsTpl(); } @@ -61,6 +68,7 @@ if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) { require_once $GLOBALS['xoops']->path('class/theme.php'); + $GLOBALS['xoTheme'] = new \xos_opal_Theme(); } @@ -81,12 +89,12 @@ //permission /** @var \XoopsGroupPermHandler $grouppermHandler */ $grouppermHandler = xoops_getHandler('groupperm'); -$groups = XOOPS_GROUP_ANONYMOUS; +$groups = XOOPS_GROUP_ANONYMOUS; if (is_object($xoopsUser)) { $groups = $xoopsUser->getGroups(); } -$perm_submit = $grouppermHandler->checkRight('tdmdownloads_ac', 4, $groups, $xoopsModule->getVar('mid')) ? true : false; -$perm_modif = $grouppermHandler->checkRight('tdmdownloads_ac', 8, $groups, $xoopsModule->getVar('mid')) ? true : false; -$perm_vote = $grouppermHandler->checkRight('tdmdownloads_ac', 16, $groups, $xoopsModule->getVar('mid')) ? true : false; -$perm_upload = $grouppermHandler->checkRight('tdmdownloads_ac', 32, $groups, $xoopsModule->getVar('mid')) ? true : false; +$perm_submit = $grouppermHandler->checkRight('tdmdownloads_ac', 4, $groups, $xoopsModule->getVar('mid')) ? true : false; +$perm_modif = $grouppermHandler->checkRight('tdmdownloads_ac', 8, $groups, $xoopsModule->getVar('mid')) ? true : false; +$perm_vote = $grouppermHandler->checkRight('tdmdownloads_ac', 16, $groups, $xoopsModule->getVar('mid')) ? true : false; +$perm_upload = $grouppermHandler->checkRight('tdmdownloads_ac', 32, $groups, $xoopsModule->getVar('mid')) ? true : false; $perm_autoapprove = $grouppermHandler->checkRight('tdmdownloads_ac', 64, $groups, $xoopsModule->getVar('mid')) ? true : false; diff --git a/admin/blockform.php b/admin/blockform.php index 2905e58..6d8015e 100644 --- a/admin/blockform.php +++ b/admin/blockform.php @@ -1,4 +1,5 @@ -addElement(new \XoopsFormLabel(_AM_SYSTEM_BLOCKS_NAME, $block['name'])); } $side_select = new \XoopsFormSelect(_AM_SYSTEM_BLOCKS_TYPE, 'bside', $block['side']); -$side_select->addOptionArray([ - 0 => _AM_SYSTEM_BLOCKS_SBLEFT, - 1 => _AM_SYSTEM_BLOCKS_SBRIGHT, - 3 => _AM_SYSTEM_BLOCKS_CBLEFT, - 4 => _AM_SYSTEM_BLOCKS_CBRIGHT, - 5 => _AM_SYSTEM_BLOCKS_CBCENTER, - 7 => _AM_SYSTEM_BLOCKS_CBBOTTOMLEFT, - 8 => _AM_SYSTEM_BLOCKS_CBBOTTOMRIGHT, - 9 => _AM_SYSTEM_BLOCKS_CBBOTTOM, - ]); +$side_select->addOptionArray( + [ + 0 => _AM_SYSTEM_BLOCKS_SBLEFT, + 1 => _AM_SYSTEM_BLOCKS_SBRIGHT, + 3 => _AM_SYSTEM_BLOCKS_CBLEFT, + 4 => _AM_SYSTEM_BLOCKS_CBRIGHT, + 5 => _AM_SYSTEM_BLOCKS_CBCENTER, + 7 => _AM_SYSTEM_BLOCKS_CBBOTTOMLEFT, + 8 => _AM_SYSTEM_BLOCKS_CBBOTTOMRIGHT, + 9 => _AM_SYSTEM_BLOCKS_CBBOTTOM, + ] +); $form->addElement($side_select); $form->addElement(new \XoopsFormText(constant('CO_' . $moduleDirNameUpper . '_' . 'WEIGHT'), 'bweight', 2, 5, $block['weight'])); $form->addElement(new \XoopsFormRadioYN(constant('CO_' . $moduleDirNameUpper . '_' . 'VISIBLE'), 'bvisible', $block['visible'])); @@ -49,50 +52,66 @@ $form->addElement(new \XoopsFormText(_AM_TITLE, 'btitle', 50, 255, $block['title']), false); if ($block['is_custom']) { $textarea = new \XoopsFormDhtmlTextArea(_AM_SYSTEM_BLOCKS_CONTENT, 'bcontent', $block['content'], 15, 70); + $textarea->setDescription('' . _AM_SYSTEM_BLOCKS_USEFULTAGS . '
' . sprintf(_AM_BLOCKTAG1, '{X_SITEURL}', XOOPS_URL . '/') . ''); + $form->addElement($textarea, true); + $ctype_select = new \XoopsFormSelect(_AM_SYSTEM_BLOCKS_CTYPE, 'bctype', $block['ctype']); - $ctype_select->addOptionArray([ - 'H' => _AM_SYSTEM_BLOCKS_HTML, - 'P' => _AM_SYSTEM_BLOCKS_PHP, - 'S' => _AM_SYSTEM_BLOCKS_AFWSMILE, - 'T' => _AM_SYSTEM_BLOCKS_AFNOSMILE, - ]); + + $ctype_select->addOptionArray( + [ + 'H' => _AM_SYSTEM_BLOCKS_HTML, + 'P' => _AM_SYSTEM_BLOCKS_PHP, + 'S' => _AM_SYSTEM_BLOCKS_AFWSMILE, + 'T' => _AM_SYSTEM_BLOCKS_AFNOSMILE, + ] + ); + $form->addElement($ctype_select); } else { if ('' !== $block['template']) { /** @var XoopsTplfileHandler $tplfileHandler */ + $tplfileHandler = xoops_getHandler('tplfile'); + /** @var \XoopsTplfile[] $btemplate */ + $btemplate = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $block['bid']); + if (count($btemplate) > 0) { $form->addElement(new \XoopsFormLabel(_AM_SYSTEM_BLOCKS_CONTENT, '' . _AM_SYSTEM_BLOCKS_EDITTPL . '')); } else { /** @var \XoopsTplfile[] $btemplate2 */ - $btemplate2 = &$tplfileHandler->find('default', 'block', $block['bid']); + + $btemplate2 = $tplfileHandler->find('default', 'block', $block['bid']); + if (count($btemplate2) > 0) { $form->addElement(new \XoopsFormLabel(_AM_SYSTEM_BLOCKS_CONTENT, '' . _AM_SYSTEM_BLOCKS_EDITTPL . '')); } } } + if (false !== $block['edit_form']) { $form->addElement(new \XoopsFormLabel(_AM_SYSTEM_BLOCKS_OPTIONS, $block['edit_form'])); } } $cache_select = new \XoopsFormSelect(_AM_SYSTEM_BLOCKS_BCACHETIME, 'bcachetime', $block['bcachetime']); -$cache_select->addOptionArray([ - '0' => _NOCACHE, - '30' => sprintf(_SECONDS, 30), - '60' => _MINUTE, - '300' => sprintf(_MINUTES, 5), - '1800' => sprintf(_MINUTES, 30), - '3600' => _HOUR, - '18000' => sprintf(_HOURS, 5), - '86400' => _DAY, - '259200' => sprintf(_DAYS, 3), - '604800' => _WEEK, - '2592000' => _MONTH, - ]); +$cache_select->addOptionArray( + [ + '0' => _NOCACHE, + '30' => sprintf(_SECONDS, 30), + '60' => _MINUTE, + '300' => sprintf(_MINUTES, 5), + '1800' => sprintf(_MINUTES, 30), + '3600' => _HOUR, + '18000' => sprintf(_HOURS, 5), + '86400' => _DAY, + '259200' => sprintf(_DAYS, 3), + '604800' => _WEEK, + '2592000' => _MONTH, + ] +); $form->addElement($cache_select); /** @var \XoopsGroupPermHandler $grouppermHandler */ @@ -112,7 +131,7 @@ } //Submit buttons -$buttonTray = new \XoopsFormElementTray('', ''); +$buttonTray = new \XoopsFormElementTray('', ''); $submit_button = new \XoopsFormButton('', 'submitblock', _SUBMIT, 'submit'); $buttonTray->addElement($submit_button); diff --git a/admin/blocksadmin.php b/admin/blocksadmin.php index 7f280d8..7b5717f 100644 --- a/admin/blocksadmin.php +++ b/admin/blocksadmin.php @@ -1,4 +1,5 @@ -isAdmin($xoopsModule->mid())) { @@ -26,12 +27,15 @@ } if ($GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) { require_once XOOPS_ROOT_PATH . '/class/xoopsblock.php'; + $op = 'list'; + if (isset($_POST)) { foreach ($_POST as $k => $v) { ${$k} = $v; } } + /* if (Request::hasVar('op')) { if ($_GET['op'] === "edit" || $_GET['op'] === "delete" || $_GET['op'] === "delete_ok" || $_GET['op'] === "clone" @@ -44,40 +48,65 @@ */ $op = Request::getString('op', $op); - if (in_array($op, ['edit', 'delete', 'delete_ok', 'clone'], true)) { + + if (in_array($op, ['edit', 'delete', 'delete_ok', 'clone'])) { $bid = Request::getInt('bid', 0, 'GET'); } function listBlocks() { global $xoopsModule, $pathIcon16; + require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; - $moduleDirName = basename(dirname(__DIR__)); - $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName + + $moduleDirName = basename(dirname(__DIR__)); + + $moduleDirNameUpper = \mb_strtoupper($moduleDirName); //$capsDirName + /** @var \XoopsMySQLDatabase $db */ + $db = \XoopsDatabaseFactory::getDatabaseConnection(); + xoops_loadLanguage('admin', 'system'); + xoops_loadLanguage('admin/blocksadmin', 'system'); + xoops_loadLanguage('admin/groups', 'system'); - /** @var XoopsModuleHandler $moduleHandler */ + /** @var \XoopsModuleHandler $moduleHandler */ + $moduleHandler = xoops_getHandler('module'); + /** @var \XoopsMemberHandler $memberHandler */ + $memberHandler = xoops_getHandler('member'); + /** @var \XoopsGroupPermHandler $grouppermHandler */ $grouppermHandler = xoops_getHandler('groupperm'); - $groups = $memberHandler->getGroups(); - $criteria = new \CriteriaCompo(new \Criteria('hasmain', 1)); + + $groups = $memberHandler->getGroups(); + + $criteria = new \CriteriaCompo(new \Criteria('hasmain', 1)); + $criteria->add(new \Criteria('isactive', 1)); - $module_list = $moduleHandler->getList($criteria); + + $module_list = $moduleHandler->getList($criteria); + $module_list[-1] = _AM_SYSTEM_BLOCKS_TOPPAGE; - $module_list[0] = _AM_SYSTEM_BLOCKS_ALLPAGES; + + $module_list[0] = _AM_SYSTEM_BLOCKS_ALLPAGES; + ksort($module_list); + echo "

" . constant('CO_' . $moduleDirNameUpper . '_' . 'BADMIN') . '

'; + $moduleHandler = xoops_getHandler('module'); - echo "
"; + + echo ""; + echo $GLOBALS['xoopsSecurity']->getTokenHTML(); + echo " '; - $block_arr = \XoopsBlock::getByModule($xoopsModule->mid()); + $block_arr = \XoopsBlock::getByModule($xoopsModule->mid()); + $block_count = count($block_arr); - $class = 'even'; - $cachetimes = [ + + $class = 'even'; + + $cachetimes = [ '0' => _NOCACHE, '30' => sprintf(_SECONDS, 30), '60' => _MINUTE, @@ -123,17 +154,24 @@ function listBlocks() '604800' => _WEEK, '2592000' => _MONTH, ]; + foreach ($block_arr as $i) { /** @var \XoopsBlock $i */ + $groups_perms = $grouppermHandler->getGroupIds('block_read', $i->getVar('bid')); - $sql = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . $i->getVar('bid'); - $result = $db->query($sql); - $modules = []; - while (false !== ($row = $db->fetchArray($result))) { - $modules[] = (int)$row['module_id']; - } + $sql = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . $i->getVar('bid'); + + $result = $db->query($sql); + + $modules = []; + if ($result instanceof \mysqli_result) { + while (false !== ($row = $db->fetchArray($result))) { + $modules[] = (int)$row['module_id']; + } + } $cachetime_options = ''; + foreach ($cachetimes as $cachetime => $cachetime_name) { if ($i->getVar('bcachetime') == $cachetime) { $cachetime_options .= "\n"; @@ -143,11 +181,13 @@ function listBlocks() } $sel0 = $sel1 = $ssel0 = $ssel1 = $ssel2 = $ssel3 = $ssel4 = $ssel5 = $ssel6 = $ssel7 = ''; + if (1 === $i->getVar('visible')) { $sel1 = ' checked'; } else { $sel0 = ' checked'; } + if (XOOPS_SIDEBLOCK_LEFT === $i->getVar('side')) { $ssel0 = ' checked'; } elseif (XOOPS_SIDEBLOCK_RIGHT === $i->getVar('side')) { @@ -165,12 +205,15 @@ function listBlocks() } elseif (XOOPS_CENTERBLOCK_BOTTOM === $i->getVar('side')) { $ssel7 = ' checked'; } + if ('' === $i->getVar('title')) { $title = ' '; } else { $title = $i->getVar('title'); } + $name = $i->getVar('name'); + echo "'; echo "'; // Cache lifetime + echo ''; @@ -258,10 +307,12 @@ function listBlocks() echo " "; - $class = ('even' === $class) ? 'odd' : 'even'; + + $class = 'even' === $class ? 'odd' : 'even'; } + echo "'; + $compare['cfields'][] = ['info' => $downloads_field[$i]->getVar('title'), 'current' => $contenu, 'modified' => $contentModified]; } } @@ -195,38 +239,58 @@ if (true === \Xmf\Request::getBool('new_file', false, 'REQUEST')) { $urlfile = substr_replace($obj->getVar('url'), '', 0, mb_strlen($uploadurl_downloads)); + // permet de donner le chemin du fichier + $urlfile = $uploaddir_downloads . $urlfile; + // si le fichier est sur le serveur il es détruit + if (is_file($urlfile)) { chmod($urlfile, 0777); + unlink($urlfile); } } + // supression des data des champs sup + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('lid', \Xmf\Request::getInt('mod_id', 0, 'REQUEST'))); + $downloads_fielddata = $modifieddataHandler->getAll($criteria); + foreach (array_keys($downloads_fielddata) as $i) { /** @var \XoopsModules\Tdmdownloads\Fielddata[] $downloads_fielddata */ + $objfielddata = $modifieddataHandler->get($downloads_fielddata[$i]->getVar('modiddata')); + $modifieddataHandler->delete($objfielddata) || $objvfielddata->getHtmlErrors(); } + if ($modifiedHandler->delete($obj)) { redirect_header('modified.php', 1, _AM_TDMDOWNLOADS_REDIRECT_DELOK); } + $GLOBALS['xoopsTpl']->assign('message_erreur', $obj->getHtmlErrors()); } else { $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation(basename(__FILE__))); + $adminObject->addItemButton(_MI_TDMDOWNLOADS_ADMENU5, 'modified.php', 'list'); + $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left')); - xoops_confirm([ - 'ok' => 1, - 'mod_id' => \Xmf\Request::getInt('mod_id', 0, 'REQUEST'), - 'new_file' => \Xmf\Request::getString('new_file', 0, 'REQUEST'), - 'op' => 'del_moddownloads', - ], $_SERVER['REQUEST_URI'], _AM_TDMDOWNLOADS_MODIFIED_SURDEL . '
'); + xoops_confirm( + [ + 'ok' => 1, + 'mod_id' => \Xmf\Request::getInt('mod_id', 0, 'REQUEST'), + 'new_file' => \Xmf\Request::getString('new_file', 0, 'REQUEST'), + 'op' => 'del_moddownloads', + ], + $_SERVER['REQUEST_URI'], + _AM_TDMDOWNLOADS_MODIFIED_SURDEL . '
' + ); } break; // permet d'accépter la modification @@ -237,11 +301,16 @@ // delete the current file if a new proposed file is accepted. if (true === \Xmf\Request::getBool('new_file', false, 'REQUEST')) { $urlfile = substr_replace($obj->getVar('url'), '', 0, mb_strlen($uploadurl_downloads)); + // permet de donner le chemin du fichier + $urlfile = $uploaddir_downloads . $urlfile; + // si le fichier est sur le serveur il es détruit + if (is_file($urlfile)) { chmod($urlfile, 0777); + unlink($urlfile); } } @@ -264,33 +333,52 @@ $downloads_field = $fieldHandler->getAll($criteria); foreach (array_keys($downloads_field) as $i) { /** @var \XoopsModules\Tdmdownloads\Field[] $downloads_field */ + $contenu = ''; - $iddata = 0; + + $iddata = 0; + if (0 == $downloads_field[$i]->getVar('status_def')) { $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('lid', $viewModdownloads->getVar('requestid'))); + $criteria->add(new \Criteria('fid', $downloads_field[$i]->getVar('fid'))); + $downloadsfieldmoddata = $modifieddataHandler->getAll($criteria); + foreach (array_keys($downloadsfieldmoddata) as $j) { /** @var \XoopsModules\Tdmdownloads\Modified[] $downloadsfieldmoddata */ + $contenu = $downloadsfieldmoddata[$j]->getVar('moddata'); } + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('lid', $viewModdownloads->getVar('lid'))); + $criteria->add(new \Criteria('fid', $downloads_field[$i]->getVar('fid'))); + $downloadsfielddata = $fielddataHandler->getAll($criteria); + foreach (array_keys($downloadsfielddata) as $j) { /** @var \XoopsModules\Tdmdownloads\Fielddata[] $downloadsfielddata */ + $iddata = $downloadsfielddata[$j]->getVar('iddata'); } + if (0 == $iddata) { $objdata = $fielddataHandler->create(); + $objdata->setVar('fid', $downloads_field[$i]->getVar('fid')); + $objdata->setVar('lid', $viewModdownloads->getVar('lid')); } else { $objdata = $fielddataHandler->get($iddata); } + $objdata->setVar('data', $contenu); + $fielddataHandler->insert($objdata) || $objdata->getHtmlErrors(); } } @@ -303,7 +391,9 @@ $downloads_fielddata = $modifieddataHandler->getAll($criteria); foreach (array_keys($downloads_fielddata) as $i) { /** @var \XoopsModules\Tdmdownloads\Fielddata[] $downloads_fielddata */ + $objfielddata = $modifieddataHandler->get($downloads_fielddata[$i]->getVar('modiddata')); + $modifieddataHandler->delete($objfielddata) || $objvfielddata->getHtmlErrors(); } // enregistrement @@ -317,9 +407,11 @@ // Local icons path if (is_object($helper->getModule())) { $pathModIcon16 = $helper->getModule()->getInfo('modicons16'); + $pathModIcon32 = $helper->getModule()->getInfo('modicons32'); $GLOBALS['xoopsTpl']->assign('pathModIcon16', XOOPS_URL . '/modules/' . $moduleDirName . '/' . $pathModIcon16); + $GLOBALS['xoopsTpl']->assign('pathModIcon32', $pathModIcon32); } diff --git a/admin/permissions.php b/admin/permissions.php index 416258c..fe54715 100644 --- a/admin/permissions.php +++ b/admin/permissions.php @@ -1,4 +1,5 @@ -path('www/class/xoopsform/grouppermform.php'); /** @var \XoopsModules\Tdmdownloads\Helper $helper */ -$helper = \XoopsModules\Tdmdownloads\Helper::getInstance(); +$helper = Helper::getInstance(); -$adminObject = \Xmf\Module\Admin::getInstance(); +$adminObject = Admin::getInstance(); $templateMain = 'tdmdownloads_admin_permissions.tpl'; $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation(basename(__FILE__))); @@ -35,8 +40,8 @@ ]; xoops_load('XoopsFormLoader'); -$permTableForm = new XoopsSimpleForm('', 'fselperm', 'permissions.php', 'post'); -$formSelect = new XoopsFormSelect('', 'permission', $permission); +$permTableForm = new \XoopsSimpleForm('', 'fselperm', 'permissions.php', 'post'); +$formSelect = new \XoopsFormSelect('', 'permission', $permission); $formSelect->setExtra('onchange="document.fselperm.submit()"'); foreach (array_keys($tab_perm) as $i) { $formSelect->addOption($i, $tab_perm[$i]); @@ -61,10 +66,12 @@ $formTitle = _AM_TDMDOWNLOADS_PERM_DOWNLOAD; if (1 == $helper->getConfig('permission_download')) { $permissionDescription = _AM_TDMDOWNLOADS_PERM_DOWNLOAD_DSC; - $permissionName = 'tdmdownloads_download'; + + $permissionName = 'tdmdownloads_download'; } else { $permissionDescription = _AM_TDMDOWNLOADS_PERM_DOWNLOAD_DSC2; - $permissionName = 'tdmdownloads_download_item'; + + $permissionName = 'tdmdownloads_download_item'; } break; case 4: @@ -88,17 +95,21 @@ } } else { if (3 === $permission && 2 === $helper->getConfig('permission_download')) { - $sql = 'SELECT lid, cid, title FROM ' . $xoopsDB->prefix('tdmdownloads_downloads') . ' ORDER BY title'; + $sql = 'SELECT lid, cid, title FROM ' . $xoopsDB->prefix('tdmdownloads_downloads') . ' ORDER BY title'; + $result = $xoopsDB->query($sql); - if ($result) { + + if ($result instanceof \mysqli_result) { while (false !== ($row = $xoopsDB->fetchArray($result))) { $permissionsForm->addItem($row['lid'], $row['title']); } } } else { - $sql = 'SELECT cat_cid, cat_pid, cat_title FROM ' . $xoopsDB->prefix('tdmdownloads_cat') . ' ORDER BY cat_title'; + $sql = 'SELECT cat_cid, cat_pid, cat_title FROM ' . $xoopsDB->prefix('tdmdownloads_cat') . ' ORDER BY cat_title'; + $result = $xoopsDB->query($sql); - if ($result) { + + if ($result instanceof \mysqli_result) { while (false !== ($row = $xoopsDB->fetchArray($result))) { $permissionsForm->addItem($row['cat_cid'], $row['cat_title'], $row['cat_pid']); } diff --git a/assets/css/blocks.css b/assets/css/blocks.css index 8a184dc..e3211a0 100644 --- a/assets/css/blocks.css +++ b/assets/css/blocks.css @@ -1,7 +1,7 @@ .endline { clear: both; width: 100%; -} +} .tdmdownloads-box { border-radius:5px; } diff --git a/assets/css/index.html b/assets/css/index.html deleted file mode 100644 index 990cbd6..0000000 --- a/assets/css/index.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/assets/css/index.php b/assets/css/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/assets/css/index.php @@ -0,0 +1,2 @@ +history.go(-1); \ No newline at end of file diff --git a/assets/images/admin/index.php b/assets/images/admin/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/assets/images/admin/index.php @@ -0,0 +1,2 @@ +history.go(-1); \ No newline at end of file diff --git a/assets/images/bookmarks/index.php b/assets/images/bookmarks/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/assets/images/bookmarks/index.php @@ -0,0 +1,2 @@ +history.go(-1); \ No newline at end of file diff --git a/assets/images/deco/index.php b/assets/images/deco/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/assets/images/deco/index.php @@ -0,0 +1,2 @@ +history.go(-1); \ No newline at end of file diff --git a/assets/images/icons/16/index.php b/assets/images/icons/16/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/assets/images/icons/16/index.php @@ -0,0 +1,2 @@ +history.go(-1); \ No newline at end of file diff --git a/assets/images/icons/32/index.php b/assets/images/icons/32/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/assets/images/icons/32/index.php @@ -0,0 +1,2 @@ +history.go(-1); \ No newline at end of file diff --git a/assets/images/icons/index.php b/assets/images/icons/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/assets/images/icons/index.php @@ -0,0 +1,2 @@ +history.go(-1); \ No newline at end of file diff --git a/assets/images/index.php b/assets/images/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/assets/images/index.php @@ -0,0 +1,2 @@ +history.go(-1); diff --git a/assets/index.php b/assets/index.php new file mode 100644 index 0000000..2ea9b7d --- /dev/null +++ b/assets/index.php @@ -0,0 +1,3 @@ +history.go(-1); diff --git a/assets/js/index.php b/assets/js/index.php new file mode 100644 index 0000000..2ea9b7d --- /dev/null +++ b/assets/js/index.php @@ -0,0 +1,3 @@ +history.go(-1); \ No newline at end of file diff --git a/blocks/index.php b/blocks/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/blocks/index.php @@ -0,0 +1,2 @@ +loadLanguage('admin'); + $helper->loadLanguage('main'); + $helper->loadLanguage('common'); /** @var \XoopsModules\Tdmdownloads\Utility $utility */ - $utility = new \XoopsModules\Tdmdownloads\Utility(); + + $utility = new \XoopsModules\Tdmdownloads\Utility(); + $categories = $utility->getItemIds('tdmdownloads_view', $moduleDirName); + /** @var \XoopsModules\Tdmdownloads\CategoryHandler $categoryHandler */ - $categoryHandler = \XoopsModules\Tdmdownloads\Helper::getInstance()->getHandler('Category'); + + $categoryHandler = Helper::getInstance()->getHandler('Category'); $block = []; //formulaire de recherche + $form = new \XoopsThemeForm(_MD_TDMDOWNLOADS_SEARCH, 'search', XOOPS_URL . '/modules/' . $moduleDirName . '/search.php', 'post'); + $form->setExtra('enctype="multipart/form-data"'); + //recherche par titre + $form->addElement(new \XoopsFormText(_MD_TDMDOWNLOADS_SEARCH_TITLE, 'title', 25, 255, '')); + //recherche par catégorie + $criteria = new \CriteriaCompo(); + $criteria->setSort('cat_weight ASC, cat_title'); + $criteria->setOrder('ASC'); + $criteria->add(new \Criteria('cat_cid', '(' . implode(',', $categories) . ')', 'IN')); + $downloadscatArray = $categoryHandler->getAll($criteria); - $mytree = new \XoopsModules\Tdmdownloads\Tree($downloadscatArray, 'cat_cid', 'cat_pid'); + + $mytree = new Tree($downloadscatArray, 'cat_cid', 'cat_pid'); + $form->addElement($mytree->makeSelectElement('cat', 'cat_title', '--', '', true, 0, '', _AM_TDMDOWNLOADS_FORMINCAT), true); + //recherche champ sup. + /** @var \XoopsModules\Tdmdownloads\FieldHandler $fieldHandler */ - $fieldHandler = \XoopsModules\Tdmdownloads\Helper::getInstance()->getHandler('Field'); - $criteria = new \CriteriaCompo(); + + $fieldHandler = Helper::getInstance()->getHandler('Field'); + + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('search', 1)); + $criteria->add(new \Criteria('status', 1)); + $criteria->setSort('weight ASC, title'); + $criteria->setOrder('ASC'); + $downloads_field = $fieldHandler->getAll($criteria); + + $fieldNameBase = ''; + foreach (array_keys($downloads_field) as $i) { /** @var \XoopsModules\Tdmdownloads\Field[] $downloads_field */ - $title_sup = ''; - $contentArray = []; - $lid_arr = []; - $fieldName = 'champ' . $downloads_field[$i]->getVar('fid'); - $criteria = new \CriteriaCompo(); + + $title_sup = ''; + + $contentArray = []; + + $lid_arr = []; + + $fieldName = 'champ' . $downloads_field[$i]->getVar('fid'); + + $criteria = new \CriteriaCompo(); + $fieldContent[$downloads_field[$i]->getVar('fid')] = 999; + if (1 == $downloads_field[$i]->getVar('status_def')) { $criteria->add(new \Criteria('status', 0, '!=')); + if (1 == $downloads_field[$i]->getVar('fid')) { //page d'accueil + $title_sup = _AM_TDMDOWNLOADS_FORMHOMEPAGE; + $criteria->setSort('homepage'); + $fieldNameBase = 'homepage'; } + if (2 == $downloads_field[$i]->getVar('fid')) { //version + $title_sup = _AM_TDMDOWNLOADS_FORMVERSION; + $criteria->setSort('version'); + $fieldNameBase = 'version'; } + if (3 == $downloads_field[$i]->getVar('fid')) { //taille du fichier + $title_sup = _AM_TDMDOWNLOADS_FORMSIZE; + $criteria->setSort('size'); + $fieldNameBase = 'size'; } + if (4 == $downloads_field[$i]->getVar('fid')) { //platform - $title_sup = _AM_TDMDOWNLOADS_FORMPLATFORM; + + $title_sup = _AM_TDMDOWNLOADS_FORMPLATFORM; + $platformArray = explode('|', xoops_getModuleOption('platform', $moduleDirName)); + foreach ($platformArray as $platform) { $contentArray[$platform] = $platform; } } else { $criteria->setOrder('ASC'); + /** @var \XoopsModules\Tdmdownloads\DownloadsHandler $downloadsHandler */ - $downloadsHandler = \XoopsModules\Tdmdownloads\Helper::getInstance()->getHandler('Downloads'); + + $downloadsHandler = Helper::getInstance()->getHandler('Downloads'); + $tdmdownloadsArray = $downloadsHandler->getAll($criteria); + foreach (array_keys($tdmdownloadsArray) as $j) { /** @var \XoopsModules\Tdmdownloads\Downloads[] $tdmdownloadsArray */ - $contentArray[$tdmdownloadsArray[$j]->getVar($fieldNameBase)] = $tdmdownloadsArray[$j]->getVar($fieldNameBase); + $temp = $tdmdownloadsArray[$j]->getVar($fieldNameBase); + $contentArray[$temp] = $temp; } } } else { $title_sup = $downloads_field[$i]->getVar('title'); + $criteria->add(new \Criteria('fid', $downloads_field[$i]->getVar('fid'))); + $criteria->setSort('data'); + $criteria->setOrder('ASC'); + /** @var \XoopsModules\Tdmdownloads\FielddataHandler $fielddataHandler */ - $fielddataHandler = \XoopsModules\Tdmdownloads\Helper::getInstance()->getHandler('Fielddata'); + + $fielddataHandler = Helper::getInstance()->getHandler('Fielddata'); + $tdmdownloadsArray = $fielddataHandler->getAll($criteria); + foreach (array_keys($tdmdownloadsArray) as $j) { /** @var \XoopsModules\Tdmdownloads\Downloads[] $tdmdownloadsArray */ + $contentArray[$tdmdownloadsArray[$j]->getVar('data', 'n')] = $tdmdownloadsArray[$j]->getVar('data'); } + if ('' != $fieldContent[$downloads_field[$i]->getVar('fid')]) { $criteria_1 = new \CriteriaCompo(); + $criteria_1->add(new \Criteria('data', $fieldContent[$downloads_field[$i]->getVar('fid')])); + /** @var \XoopsModules\Tdmdownloads\Fielddata $dataArray */ + $dataArray = $fielddataHandler->getAll($criteria_1); + foreach (array_keys($dataArray) as $k) { /** @var \XoopsModules\Tdmdownloads\Fielddata[] $dataArray */ + $lid_arr[] = $dataArray[$k]->getVar('lid'); } } - $form->addElement($select_sup); + +// $form->addElement($select_sup); } + $select_sup = new \XoopsFormSelect($title_sup, $fieldName, $fieldContent[$downloads_field[$i]->getVar('fid')]); + $select_sup->addOption(999, _MD_TDMDOWNLOADS_SEARCH_ALL1); + $select_sup->addOptionArray($contentArray); + $form->addElement($select_sup); + unset($select_sup); } + //bouton validation + $buttonTray = new \XoopsFormElementTray('', ''); + $buttonTray->addElement(new \XoopsFormButton('', 'submit', _MD_TDMDOWNLOADS_SEARCH_BT, 'submit')); + $form->addElement($buttonTray); + $block['form'] = $form->render(); return $block; diff --git a/blocks/tdmdownloads_top.php b/blocks/tdmdownloads_top.php index 34e88c6..2da2e16 100644 --- a/blocks/tdmdownloads_top.php +++ b/blocks/tdmdownloads_top.php @@ -1,4 +1,5 @@ -getByDirname($moduleDirName); + + $mymodule = $moduleHandler->getByDirname($moduleDirName); + //appel de la class + /** @var \XoopsModules\Tdmdownloads\DownloadsHandler $downloadsHandler */ - $downloadsHandler = \XoopsModules\Tdmdownloads\Helper::getInstance()->getHandler('Downloads'); - $block = []; - $type_block = $options[0]; - $nb_entree = $options[1]; - $lenght_title = (int)$options[2]; - $use_logo = $options[3]; - $use_description = $options[4]; - $show_information = $options[5]; - $logo_float = $options[6]; - $logo_width = $options[7]; + + $downloadsHandler = Helper::getInstance()->getHandler('Downloads'); + + $block = []; + + $type_block = $options[0]; + + $nb_entree = $options[1]; + + $lenght_title = (int)$options[2]; + + $use_logo = $options[3]; + + $use_description = $options[4]; + + $show_information = $options[5]; + + $logo_float = $options[6]; + + $logo_width = $options[7]; + $length_description = (int)$options[8]; - $blockstyle = $options[9]; + + $blockstyle = $options[9]; array_shift($options); + array_shift($options); + array_shift($options); + array_shift($options); + array_shift($options); + array_shift($options); + array_shift($options); + array_shift($options); + array_shift($options); + array_shift($options); // Add styles + global $xoTheme; + $db = null; + /** @var \xos_opal_Theme $xoTheme */ + $xoTheme->addStylesheet(XOOPS_URL . '/modules/' . $moduleDirName . '/assets/css/blocks.css', null); + /** @var \XoopsModules\Tdmdownloads\Utility $utility */ + $utility = new \XoopsModules\Tdmdownloads\Utility(); + + /** @var \XoopsModules\Tdmdownloads\Helper $helper */ + $helper->loadLanguage('main'); $categories = $utility->getItemIds('tdmdownloads_view', $moduleDirName); - $criteria = new \CriteriaCompo(); + + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('cid', '(' . implode(',', $categories) . ')', 'IN')); - if (!(0 == $options[0] && 1 === count($options))) { + + if (is_array($options) && !empty($options) && !0 == $options[0] && 1 === count($options)) { $criteria->add(new \Criteria('cid', '(' . implode(',', $options) . ')', 'IN')); } + $criteria->add(new \Criteria('status', 0, '!=')); + switch ($type_block) { // pour le bloc: dernier fichier case 'date': $criteria->setSort('date'); @@ -91,23 +137,35 @@ function b_tdmdownloads_top_show($options) $criteria->setSort('RAND()'); break; } + $criteria->setLimit($nb_entree); + $downloadsArray = $downloadsHandler->getAll($criteria); + foreach (array_keys($downloadsArray) as $i) { /** @var \XoopsModules\Tdmdownloads\Downloads[] $downloadsArray */ - $block[$i]['lid'] = $downloadsArray[$i]->getVar('lid'); + + $block[$i]['lid'] = $downloadsArray[$i]->getVar('lid'); + $titleFinal = $downloadsArray[$i]->getVar('title'); + if ($lenght_title > 0) { $titleFinal = mb_strlen($titleFinal) > $lenght_title ? mb_substr($titleFinal, 0, $lenght_title) . '...' : $titleFinal; } + $block[$i]['title'] = $titleFinal; - $descriptionFinal = ''; + + $descriptionFinal = ''; + if (true == $use_description) { $description = $downloadsArray[$i]->getVar('description'); + //permet d'afficher uniquement la description courte + if ($length_description > 0) { if (false === mb_strpos($description, '[pagebreak]')) { $descriptionFinal = mb_substr($description, 0, $length_description); + if (mb_strlen($description) > mb_strlen($descriptionFinal)) { $descriptionFinal .= ' ...'; } @@ -118,8 +176,10 @@ function b_tdmdownloads_top_show($options) $descriptionFinal = $description; } } + $block[$i]['description'] = $descriptionFinal; - $logourl = ''; + + $logourl = ''; if (true == $use_logo) { if ('blank.gif' === $downloadsArray[$i]->getVar('logourl') || '' === $downloadsArray[$i]->getVar('logourl')) { @@ -128,26 +188,43 @@ function b_tdmdownloads_top_show($options) $logourl = XOOPS_URL . '/uploads/' . $moduleDirName . '/images/shots/' . $downloadsArray[$i]->getVar('logourl'); } } - $block[$i]['logourl'] = $logourl; + + $block[$i]['logourl'] = $logourl; + $block[$i]['logourl_class'] = $logo_float; + $block[$i]['logourl_width'] = $logo_width; - $block[$i]['hits'] = $downloadsArray[$i]->getVar('hits'); - $block[$i]['rating'] = number_format($downloadsArray[$i]->getVar('rating'), 1); - $block[$i]['date'] = formatTimestamp($downloadsArray[$i]->getVar('date'), 's'); - $block[$i]['submitter'] = \XoopsUser::getUnameFromId($downloadsArray[$i]->getVar('submitter')); - $block[$i]['inforation'] = $show_information; - $block[$i]['blockstyle'] = $blockstyle; + + $block[$i]['hits'] = $downloadsArray[$i]->getVar('hits'); + + $block[$i]['rating'] = number_format((float)$downloadsArray[$i]->getVar('rating'), 1); + + $block[$i]['date'] = formatTimestamp($downloadsArray[$i]->getVar('date'), 's'); + + $block[$i]['submitter'] = \XoopsUser::getUnameFromId($downloadsArray[$i]->getVar('submitter')); + + $block[$i]['inforation'] = $show_information; + + $block[$i]['blockstyle'] = $blockstyle; } + $GLOBALS['xoopsTpl']->assign('tdmblockstyle', $blockstyle); + /** @var \XoopsGroupPermHandler $grouppermHandler */ $grouppermHandler = xoops_getHandler('groupperm'); - $groups = XOOPS_GROUP_ANONYMOUS; + + $groups = XOOPS_GROUP_ANONYMOUS; + if (is_object($GLOBALS['xoopsUser'])) { $groups = $GLOBALS['xoopsUser']->getGroups(); } + $perm_submit = $grouppermHandler->checkRight('tdmdownloads_ac', 4, $groups, $mymodule->getVar('mid')) ? true : false; - $perm_modif = $grouppermHandler->checkRight('tdmdownloads_ac', 8, $groups, $mymodule->getVar('mid')) ? true : false; + + $perm_modif = $grouppermHandler->checkRight('tdmdownloads_ac', 8, $groups, $mymodule->getVar('mid')) ? true : false; + $GLOBALS['xoopsTpl']->assign('perm_submit', $perm_submit); + $GLOBALS['xoopsTpl']->assign('perm_modif', $perm_modif); return $block; @@ -161,72 +238,123 @@ function b_tdmdownloads_top_show($options) function b_tdmdownloads_top_edit($options) { //appel de la class - $moduleDirName = basename(dirname(__DIR__)); - $categoryHandler = \XoopsModules\Tdmdownloads\Helper::getInstance()->getHandler('Category'); - $criteria = new \CriteriaCompo(); + + $moduleDirName = basename(dirname(__DIR__)); + + $categoryHandler = Helper::getInstance()->getHandler('Category'); + + $criteria = new \CriteriaCompo(); + $criteria->setSort('cat_weight ASC, cat_title'); + $criteria->setOrder('ASC'); + $downloadscatArray = $categoryHandler->getAll($criteria); - $form = _MB_TDMDOWNLOADS_DISP . " \n"; - $form .= '\n"; - $form .= ' ' . _MB_TDMDOWNLOADS_FILES . "
\n"; - $form .= _MB_TDMDOWNLOADS_CHARS . ' (' . _MB_TDMDOWNLOADS_CHARSDSC . '):
\n"; + + $form = _MB_TDMDOWNLOADS_DISP . " \n"; + + $form .= '\n"; + + $form .= ' ' . _MB_TDMDOWNLOADS_FILES . "
\n"; + + $form .= _MB_TDMDOWNLOADS_CHARS . ' (' . _MB_TDMDOWNLOADS_CHARSDSC . '):
\n"; + if (false == $options[3]) { $checked_yes = ''; - $checked_no = 'checked'; + + $checked_no = 'checked'; } else { $checked_yes = 'checked'; - $checked_no = ''; + + $checked_no = ''; } + $form .= _MB_TDMDOWNLOADS_LOGO . ' : ' . _YES . " \n"; + $form .= '' . _NO . "
\n"; + if (false == $options[4]) { $checked_yes = ''; - $checked_no = 'checked'; + + $checked_no = 'checked'; } else { $checked_yes = 'checked'; - $checked_no = ''; + + $checked_no = ''; } + $form .= _MB_TDMDOWNLOADS_DESCRIPTION . ' : ' . _YES . " \n"; + $form .= '' . _NO . "
\n"; + if (false == $options[5]) { $checked_yes = ''; - $checked_no = 'checked'; + + $checked_no = 'checked'; } else { $checked_yes = 'checked'; - $checked_no = ''; + + $checked_no = ''; } - $form .= _MB_TDMDOWNLOADS_INFORMATIONS . ' : ' . _YES . " \n"; - $form .= '' . _NO . "

\n"; + + $form .= _MB_TDMDOWNLOADS_INFORMATIONS . ' : ' . _YES . " \n"; + + $form .= '' . _NO . "

\n"; + $floatSelect = new \XoopsFormSelect('', 'options[6]', $options[6]); + $floatSelect->addOption('left', _MB_TDMDOWNLOADS_FLOAT_LEFT); + $floatSelect->addOption('right', _MB_TDMDOWNLOADS_FLOAT_RIGHT); + $form .= _MB_TDMDOWNLOADS_FLOAT . $floatSelect->render() . '
'; + $form .= _MB_TDMDOWNLOADS_WIDTH . ' (' . _MB_TDMDOWNLOADS_WIDTHDSC . '):
\n"; + $form .= _MB_TDMDOWNLOADS_DESCRIPTIONDSC . ':
\n"; + $styleSelect = new \XoopsFormSelect('', 'options[9]', $options[9]); + $styleSelect->addOption('default', 'default'); + $styleSelect->addOption('simple1', 'simple1'); + $styleSelect->addOption('simple2', 'simple2'); + $styleSelect->addOption('simple3', 'simple3'); + $styleSelect->addOption('simple4', 'simple4'); + $form .= _MB_TDMDOWNLOADS_BLOCKSTYLE . ': ' . $styleSelect->render() . '
'; array_shift($options); + array_shift($options); + array_shift($options); + array_shift($options); + array_shift($options); + array_shift($options); + array_shift($options); + array_shift($options); + array_shift($options); + $form .= _MB_TDMDOWNLOADS_CATTODISPLAY . "
\n"; return $form; diff --git a/brokenfile.php b/brokenfile.php index 944e272..ca22188 100644 --- a/brokenfile.php +++ b/brokenfile.php @@ -1,4 +1,5 @@ -getItemIds('tdmdownloads_view', $moduleDirName); -if (!in_array($viewDownloads->getVar('cid'), $categories, true)) { +if (!in_array($viewDownloads->getVar('cid'), $categories)) { redirect_header(XOOPS_URL, 2, _NOPERM); } @@ -52,16 +56,16 @@ $criteria->setOrder('ASC'); $criteria->add(new \Criteria('cat_cid', '(' . implode(',', $categories) . ')', 'IN')); $downloadscatArray = $categoryHandler->getAll($criteria); - $mytree = new \XoopsModules\Tdmdownloads\Tree($downloadscatArray, 'cat_cid', 'cat_pid'); + $mytree = new Tree($downloadscatArray, 'cat_cid', 'cat_pid'); //navigation - $navigation = $utility->getPathTreeUrl($mytree, $viewDownloads->getVar('cid'), $downloadscatArray, 'cat_title', $prefix = ' arrow ', true, 'ASC', true); + $navigation = $utility::getPathTreeUrl($mytree, $viewDownloads->getVar('cid'), $downloadscatArray, 'cat_title', $prefix = ' arrow ', true, 'ASC', true); $navigation .= ' arrow' . $viewDownloads->getVar('title') . ''; $navigation .= ' arrow ' . _MD_TDMDOWNLOADS_SINGLEFILE_REPORTBROKEN; $xoopsTpl->assign('navigation', $navigation); // référencement // titre de la page $pagetitle = _MD_TDMDOWNLOADS_SINGLEFILE_REPORTBROKEN . ' - ' . $viewDownloads->getVar('title') . ' - '; - $pagetitle .= $utility->getPathTreeUrl($mytree, $viewDownloads->getVar('cid'), $downloadscatArray, 'cat_title', $prefix = ' - ', false, 'DESC', true); + $pagetitle .= $utility::getPathTreeUrl($mytree, $viewDownloads->getVar('cid'), $downloadscatArray, 'cat_title', $prefix = ' - ', false, 'DESC', true); $xoopsTpl->assign('xoops_pagetitle', $pagetitle); //description $xoTheme->addMeta('meta', 'description', strip_tags(_MD_TDMDOWNLOADS_SINGLEFILE_REPORTBROKEN . ' (' . $viewDownloads->getVar('title') . ')')); @@ -83,33 +87,44 @@ } if (0 !== $ratinguser) { // si c'est un membre on vérifie qu'il n'envoie pas 2 fois un rapport + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('lid', $lid)); + $brokenArray = $brokenHandler->getAll($criteria); + foreach (array_keys($brokenArray) as $i) { /** @var \XoopsModules\Tdmdownloads\Broken[] $brokenArray */ + if ($brokenArray[$i]->getVar('sender') == $ratinguser) { redirect_header('singlefile.php?lid=' . $lid, 2, _MD_TDMDOWNLOADS_BROKENFILE_ALREADYREPORTED); } } } else { // si c'est un utilisateur anonyme on vérifie qu'il n'envoie pas 2 fois un rapport + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('lid', $lid)); + $criteria->add(new \Criteria('sender', 0)); + $criteria->add(new \Criteria('ip', getenv('REMOTE_ADDR'))); + if ($brokenHandler->getCount($criteria) >= 1) { redirect_header('singlefile.php?lid=' . $lid, 2, _MD_TDMDOWNLOADS_BROKENFILE_ALREADYREPORTED); } } - $erreur = false; + $erreur = false; $errorMessage = ''; // Test avant la validation xoops_load('captcha'); $xoopsCaptcha = \XoopsCaptcha::getInstance(); if (!$xoopsCaptcha->verify()) { $errorMessage .= $xoopsCaptcha->getMessage() . '
'; - $erreur = true; + + $erreur = true; } $obj->setVar('lid', $lid); $obj->setVar('sender', $ratinguser); @@ -118,13 +133,19 @@ $xoopsTpl->assign('message_erreur', $errorMessage); } else { if ($brokenHandler->insert($obj)) { - $tags = []; + $tags = []; + $tags['BROKENREPORTS_URL'] = XOOPS_URL . '/modules/' . $moduleDirName . '/admin/broken.php'; + /** @var \XoopsNotificationHandler $notificationHandler */ + $notificationHandler = xoops_getHandler('notification'); + $notificationHandler->triggerEvent('global', 0, 'file_broken', $tags); + redirect_header('singlefile.php?lid=' . $lid, 2, _MD_TDMDOWNLOADS_BROKENFILE_THANKSFORINFO); } + echo $obj->getHtmlErrors(); } //Affichage du formulaire de notation des téléchargements diff --git a/class/Broken.php b/class/Broken.php index 888ca5d..6055842 100644 --- a/class/Broken.php +++ b/class/Broken.php @@ -1,4 +1,4 @@ -initVar('reportid', XOBJ_DTYPE_INT, null, false, 5); - $this->initVar('lid', XOBJ_DTYPE_INT, null, false, 11); - $this->initVar('sender', XOBJ_DTYPE_INT, null, false, 11); - $this->initVar('ip', XOBJ_DTYPE_TXTBOX, null, false); + + $this->initVar('reportid', \XOBJ_DTYPE_INT, null, false, 5); + + $this->initVar('lid', \XOBJ_DTYPE_INT, null, false, 11); + + $this->initVar('sender', \XOBJ_DTYPE_INT, null, false, 11); + + $this->initVar('ip', \XOBJ_DTYPE_TXTBOX, null, false); + //pour les jointures: - $this->initVar('title', XOBJ_DTYPE_TXTBOX, null, false); - $this->initVar('cid', XOBJ_DTYPE_INT, null, false, 5); + + $this->initVar('title', \XOBJ_DTYPE_TXTBOX, null, false); + + $this->initVar('cid', \XOBJ_DTYPE_INT, null, false, 5); } /** @@ -47,18 +53,27 @@ public function __construct() public function getForm($lid, $action = false) { // global $xoopsDB, $xoopsModule, $xoopsModuleConfig; - if (false === $action) { + + if (!$action) { $action = $_SERVER['REQUEST_URI']; } $form = new \XoopsThemeForm(_MD_TDMDOWNLOADS_BROKENFILE_REPORTBROKEN, 'brokenform', 'brokenfile.php', 'post'); + $form->setExtra('enctype="multipart/form-data"'); + $form->addElement(new \XoopsFormCaptcha(), true); + $form->addElement(new \XoopsFormHidden('op', 'save')); + $form->addElement(new \XoopsFormHidden('lid', $lid)); + // Submit button + $buttonTray = new \XoopsFormElementTray(_MD_TDMDOWNLOADS_BROKENFILE_REPORTBROKEN, '', ''); + $buttonTray->addElement(new \XoopsFormButton('', 'post', _MD_TDMDOWNLOADS_BROKENFILE_REPORTBROKEN, 'submit')); + $form->addElement($buttonTray); return $form; diff --git a/class/BrokenHandler.php b/class/BrokenHandler.php index df48841..daea1ff 100644 --- a/class/BrokenHandler.php +++ b/class/BrokenHandler.php @@ -1,4 +1,4 @@ -initVar('cat_cid', XOBJ_DTYPE_INT, null, false, 5); - $this->initVar('cat_pid', XOBJ_DTYPE_INT, null, false, 5); - $this->initVar('cat_title', XOBJ_DTYPE_TXTBOX, null, false); - $this->initVar('cat_imgurl', XOBJ_DTYPE_TXTBOX, null, false); - $this->initVar('cat_description_main', XOBJ_DTYPE_TXTAREA, null, false); + + $this->helper = Helper::getInstance(); + + $this->permHelper = new Permission(); + + $this->initVar('cat_cid', \XOBJ_DTYPE_INT, null, false, 5); + + $this->initVar('cat_pid', \XOBJ_DTYPE_INT, null, false, 5); + + $this->initVar('cat_title', \XOBJ_DTYPE_TXTBOX, null, false); + + $this->initVar('cat_imgurl', \XOBJ_DTYPE_TXTBOX, null, false); + + $this->initVar('cat_description_main', \XOBJ_DTYPE_TXTAREA, null, false); + // Pour autoriser le html - $this->initVar('dohtml', XOBJ_DTYPE_INT, 1, false); - $this->initVar('cat_weight', XOBJ_DTYPE_INT, 0, false, 11); + + $this->initVar('dohtml', \XOBJ_DTYPE_INT, 1, false); + + $this->initVar('cat_weight', \XOBJ_DTYPE_INT, 0, false, 11); } /** @@ -49,7 +69,9 @@ public function __construct() public function getNewEnreg($db = null) { $newEnreg = 0; + /** @var \XoopsMySQLDatabase $db */ + if (null !== $db) { $newEnreg = $db->getInsertId(); } @@ -64,108 +86,180 @@ public function getNewEnreg($db = null) */ public function getForm($action = false) { - /** @var \XoopsModules\Tdmdownloads\Helper $helper */ - $helper = \XoopsModules\Tdmdownloads\Helper::getInstance(); + $helper = Helper::getInstance(); - if (false === $action) { + if (!$action) { $action = $_SERVER['REQUEST_URI']; } - $moduleDirName = basename(dirname(__DIR__)); + + $moduleDirName = \basename(\dirname(__DIR__)); + require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; //nom du formulaire selon l'action (editer ou ajouter): - $title = $this->isNew() ? sprintf(_AM_TDMDOWNLOADS_FORMADD) : sprintf(_AM_TDMDOWNLOADS_FORMEDIT); + + $title = $this->isNew() ? \sprintf(_AM_TDMDOWNLOADS_FORMADD) : \sprintf(_AM_TDMDOWNLOADS_FORMEDIT); //création du formulaire + $form = new \XoopsThemeForm($title, 'form', $action, 'post', true); + $form->setExtra('enctype="multipart/form-data"'); + //titre + $form->addElement(new \XoopsFormText(_AM_TDMDOWNLOADS_FORMTITLE, 'cat_title', 50, 255, $this->getVar('cat_title')), true); + //editeur - $editorConfigs = []; - $editorConfigs['name'] = 'cat_description_main'; - $editorConfigs['value'] = $this->getVar('cat_description_main', 'e'); - $editorConfigs['rows'] = 20; - $editorConfigs['cols'] = 160; - $editorConfigs['width'] = '100%'; + + $editorConfigs = []; + + $editorConfigs['name'] = 'cat_description_main'; + + $editorConfigs['value'] = $this->getVar('cat_description_main', 'e'); + + $editorConfigs['rows'] = 20; + + $editorConfigs['cols'] = 160; + + $editorConfigs['width'] = '100%'; + $editorConfigs['height'] = '400px'; + $editorConfigs['editor'] = $helper->getConfig('editor'); + $form->addElement(new \XoopsFormEditor(_AM_TDMDOWNLOADS_FORMTEXT, 'cat_description_main', $editorConfigs), false); + //image + $categoryImage = $this->getVar('cat_imgurl') ?: 'blank.gif'; - $uploadirectory = '/uploads/' . $moduleDirName . '/images/cats'; - $imgtray = new \XoopsFormElementTray(_AM_TDMDOWNLOADS_FORMIMG, '
'); - $imgpath = sprintf(_AM_TDMDOWNLOADS_FORMPATH, $uploadirectory); - $imageselect = new \XoopsFormSelect($imgpath, 'downloadscat_img', $categoryImage); - $topics_array = \XoopsLists:: getImgListAsArray(XOOPS_ROOT_PATH . $uploadirectory); + + $uploadirectory = '/uploads/' . $moduleDirName . '/images/cats'; + + $imgtray = new \XoopsFormElementTray(_AM_TDMDOWNLOADS_FORMIMG, '
'); + + $imgpath = \sprintf(_AM_TDMDOWNLOADS_FORMPATH, $uploadirectory); + + $imageselect = new \XoopsFormSelect($imgpath, 'downloadscat_img', $categoryImage); + + $topics_array = \XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH . $uploadirectory); + foreach ($topics_array as $image) { - $imageselect->addOption((string)$image, $image); + $imageselect->addOption($image, $image); } + $imageselect->setExtra("onchange='showImgSelected(\"image3\", \"downloadscat_img\", \"" . $uploadirectory . '", "", "' . XOOPS_URL . "\")'"); + $imgtray->addElement($imageselect, false); + $imgtray->addElement(new \XoopsFormLabel('', "
")); + $fileseltray = new \XoopsFormElementTray('', '
'); + $fileseltray->addElement(new \XoopsFormFile(_AM_TDMDOWNLOADS_FORMUPLOAD, 'attachedfile', $helper->getConfig('maxuploadsize')), false); + $fileseltray->addElement(new \XoopsFormLabel(''), false); + $imgtray->addElement($fileseltray); + $form->addElement($imgtray); + // Pour faire une sous-catégorie - /** @var \XoopsModules\Tdmdownloads\CategoryHandler $categoryHandler */ - $categoryHandler = \XoopsModules\Tdmdownloads\Helper::getInstance()->getHandler('Category'); - $criteria = new \CriteriaCompo(); + $categoryHandler = Helper::getInstance()->getHandler('Category'); + + $criteria = new \CriteriaCompo(); + $criteria->setSort('cat_weight ASC, cat_title'); + $criteria->setOrder('ASC'); + $downloadscatArray = $categoryHandler->getAll($criteria); - $mytree = new \XoopsModules\Tdmdownloads\Tree($downloadscatArray, 'cat_cid', 'cat_pid'); + + $mytree = new \XoopsModules\Tdmdownloads\Tree($downloadscatArray, 'cat_cid', 'cat_pid'); + $form->addElement($mytree->makeSelectElement('cat_pid', 'cat_title', '--', $this->getVar('cat_pid'), true, 0, '', _AM_TDMDOWNLOADS_FORMINCAT), true); + //poids de la catégorie + $form->addElement(new \XoopsFormText(_AM_TDMDOWNLOADS_FORMWEIGHT, 'cat_weight', 5, 5, $this->getVar('cat_weight', 'e')), false); //permissions + /** @var \XoopsMemberHandler $memberHandler */ - $memberHandler = xoops_getHandler('member'); - $group_list = $memberHandler->getGroupList(); + + $memberHandler = \xoops_getHandler('member'); + + $group_list = $memberHandler->getGroupList(); + /** @var \XoopsGroupPermHandler $grouppermHandler */ - $grouppermHandler = xoops_getHandler('groupperm'); - $full_list = array_keys($group_list); + $grouppermHandler = \xoops_getHandler('groupperm'); + + $full_list = \array_keys($group_list); + global $xoopsModule; + if (!$this->isNew()) { - $groups_ids_view = $grouppermHandler->getGroupIds('tdmdownloads_view', $this->getVar('cat_cid'), $xoopsModule->getVar('mid')); - $groups_ids_submit = $grouppermHandler->getGroupIds('tdmdownloads_submit', $this->getVar('cat_cid'), $xoopsModule->getVar('mid')); - $groups_ids_download = $grouppermHandler->getGroupIds('tdmdownloads_download', $this->getVar('cat_cid'), $xoopsModule->getVar('mid')); - $groups_ids_view = array_values($groups_ids_view); - $groups_news_can_view_checkbox = new \XoopsFormCheckBox(_AM_TDMDOWNLOADS_PERM_VIEW_DSC, 'groups_view[]', $groups_ids_view); - $groups_ids_submit = array_values($groups_ids_submit); - $groups_news_can_submit_checkbox = new \XoopsFormCheckBox(_AM_TDMDOWNLOADS_PERM_SUBMIT_DSC, 'groups_submit[]', $groups_ids_submit); - $groups_ids_download = array_values($groups_ids_download); + $groups_ids_view = $grouppermHandler->getGroupIds('tdmdownloads_view', $this->getVar('cat_cid'), $xoopsModule->getVar('mid')); + + $groups_ids_submit = $grouppermHandler->getGroupIds('tdmdownloads_submit', $this->getVar('cat_cid'), $xoopsModule->getVar('mid')); + + $groups_ids_download = $grouppermHandler->getGroupIds('tdmdownloads_download', $this->getVar('cat_cid'), $xoopsModule->getVar('mid')); + + $groups_ids_view = \array_values($groups_ids_view); + + $groups_news_can_view_checkbox = new \XoopsFormCheckBox(_AM_TDMDOWNLOADS_PERM_VIEW_DSC, 'groups_view[]', $groups_ids_view); + + $groups_ids_submit = \array_values($groups_ids_submit); + + $groups_news_can_submit_checkbox = new \XoopsFormCheckBox(_AM_TDMDOWNLOADS_PERM_SUBMIT_DSC, 'groups_submit[]', $groups_ids_submit); + + $groups_ids_download = \array_values($groups_ids_download); + $groups_news_can_download_checkbox = new \XoopsFormCheckBox(_AM_TDMDOWNLOADS_PERM_DOWNLOAD_DSC, 'groups_download[]', $groups_ids_download); } else { - $groups_news_can_view_checkbox = new \XoopsFormCheckBox(_AM_TDMDOWNLOADS_PERM_VIEW_DSC, 'groups_view[]', $full_list); - $groups_news_can_submit_checkbox = new \XoopsFormCheckBox(_AM_TDMDOWNLOADS_PERM_SUBMIT_DSC, 'groups_submit[]', $full_list); + $groups_news_can_view_checkbox = new \XoopsFormCheckBox(_AM_TDMDOWNLOADS_PERM_VIEW_DSC, 'groups_view[]', $full_list); + + $groups_news_can_submit_checkbox = new \XoopsFormCheckBox(_AM_TDMDOWNLOADS_PERM_SUBMIT_DSC, 'groups_submit[]', $full_list); + $groups_news_can_download_checkbox = new \XoopsFormCheckBox(_AM_TDMDOWNLOADS_PERM_DOWNLOAD_DSC, 'groups_download[]', $full_list); } + // pour voir + $groups_news_can_view_checkbox->addOptionArray($group_list); + $form->addElement($groups_news_can_view_checkbox); + // pour editer + $groups_news_can_submit_checkbox->addOptionArray($group_list); + $form->addElement($groups_news_can_submit_checkbox); + // pour télécharger + if (1 == $helper->getConfig('permission_download')) { $groups_news_can_download_checkbox->addOptionArray($group_list); + $form->addElement($groups_news_can_download_checkbox); } // pour passer "cid" si on modifie la catégorie + if (!$this->isNew()) { $form->addElement(new \XoopsFormHidden('cat_cid', $this->getVar('cat_cid'))); + $form->addElement(new \XoopsFormHidden('categorie_modified', true)); } + //pour enregistrer le formulaire + $form->addElement(new \XoopsFormHidden('op', 'save_cat')); + //boutton d'envoi du formulaire - $form->addElement(new \XoopsFormButtonTray('', _SUBMIT, 'submit', 'submit', false)); + + $form->addElement(new \XoopsFormButtonTray('', \_SUBMIT, 'submit', 'submit', false)); return $form; } diff --git a/class/CategoryHandler.php b/class/CategoryHandler.php index bc6607f..c6a3d18 100644 --- a/class/CategoryHandler.php +++ b/class/CategoryHandler.php @@ -1,4 +1,4 @@ -addLink( 'bread 3', 'index3.php' ); * echo $breadcrumb->render(); */ -defined('XOOPS_ROOT_PATH') || die('Restricted access'); /** * Class Breadcrumb */ class Breadcrumb { - public $dirname; + public $dirname; private $bread = []; public function __construct() { - $this->dirname = basename(dirname(dirname(__DIR__))); + $this->dirname = \basename(dirname(__DIR__, 2)); } /** @@ -62,15 +61,20 @@ public function addLink($title = '', $link = '') */ public function render() { - if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) { + if (!isset($GLOBALS['xoTheme']) || !\is_object($GLOBALS['xoTheme'])) { require_once $GLOBALS['xoops']->path('class/theme.php'); + $GLOBALS['xoTheme'] = new \xos_opal_Theme(); } require_once $GLOBALS['xoops']->path('class/template.php'); + $breadcrumbTpl = new \XoopsTpl(); + $breadcrumbTpl->assign('breadcrumb', $this->bread); + $html = $breadcrumbTpl->fetch('db:' . $this->dirname . '_common_breadcrumb.tpl'); + unset($breadcrumbTpl); return $html; diff --git a/class/Common/Configurator.php b/class/Common/Configurator.php index 3341325..bd7a766 100644 --- a/class/Common/Configurator.php +++ b/class/Common/Configurator.php @@ -1,4 +1,4 @@ -name = $config->name; $this->paths = $config->paths; @@ -59,6 +57,12 @@ public function __construct() $this->oldFiles = $config->oldFiles; $this->oldFolders = $config->oldFolders; $this->renameTables = $config->renameTables; + $this->renameColumns = $config->renameColumns; + $this->moduleStats = $config->moduleStats; $this->modCopyright = $config->modCopyright; + + $this->icons = require \dirname(__DIR__, 2) . '/config/icons.php'; + $this->paths = require \dirname(__DIR__, 2) . '/config/paths.php'; + } } diff --git a/class/Common/FilesManagement.php b/class/Common/FilesManagement.php index 68fb728..8163817 100644 --- a/class/Common/FilesManagement.php +++ b/class/Common/FilesManagement.php @@ -1,4 +1,4 @@ -history.go(-1);'); } - } catch (\Exception $e) { + } catch (\Throwable $e) { echo 'Caught exception: ', $e->getMessage(), "\n", '
'; } } @@ -48,7 +48,7 @@ public static function createFolder($folder) */ public static function copyFile($file, $folder) { - return copy($file, $folder); + return \copy($file, $folder); } /** @@ -58,20 +58,23 @@ public static function copyFile($file, $folder) */ public static function recurseCopy($src, $dst) { - $dir = opendir($src); - if (!mkdir($dst) && !is_dir($dst)) { + $dir = \opendir($src); + + if (!\mkdir($dst) && !\is_dir($dst)) { throw new \RuntimeException('The directory ' . $dst . ' could not be created.'); } - while (false !== ($file = readdir($dir))) { + + while (false !== ($file = \readdir($dir))) { if (('.' !== $file) && ('..' !== $file)) { - if (is_dir($src . '/' . $file)) { + if (\is_dir($src . '/' . $file)) { self::recurseCopy($src . '/' . $file, $dst . '/' . $file); } else { - copy($src . '/' . $file, $dst . '/' . $file); + \copy($src . '/' . $file, $dst . '/' . $file); } } } - closedir($dir); + + \closedir($dir); } /** @@ -79,44 +82,56 @@ public static function recurseCopy($src, $dst) * * @param string $src source directory to delete * - * @uses \Xmf\Module\Helper::getHelper() + * @return bool true on success * @uses \Xmf\Module\Helper::isUserAdmin() * - * @return bool true on success + * @uses \Xmf\Module\Helper::getHelper() */ public static function deleteDirectory($src) { // Only continue if user is a 'global' Admin + if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { return false; } $success = true; + // remove old files + $dirInfo = new \SplFileInfo($src); + // validate is a directory + if ($dirInfo->isDir()) { - $fileList = array_diff(scandir($src, SCANDIR_SORT_NONE), ['..', '.']); + $fileList = \array_diff(\scandir($src, \SCANDIR_SORT_NONE), ['..', '.']); + foreach ($fileList as $k => $v) { $fileInfo = new \SplFileInfo("{$src}/{$v}"); + if ($fileInfo->isDir()) { // recursively handle subdirectories + if (!$success = self::deleteDirectory($fileInfo->getRealPath())) { break; } } else { // delete the file - if (!($success = unlink($fileInfo->getRealPath()))) { + + if (!($success = \unlink($fileInfo->getRealPath()))) { break; } } } + // now delete this (sub)directory if all the files are gone + if ($success) { - $success = rmdir($dirInfo->getRealPath()); + $success = \rmdir($dirInfo->getRealPath()); } } else { // input is not a valid directory + $success = false; } @@ -135,33 +150,41 @@ public static function deleteDirectory($src) public static function rrmdir($src) { // Only continue if user is a 'global' Admin + if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { return false; } // If source is not a directory stop processing - if (!is_dir($src)) { + + if (!\is_dir($src)) { return false; } $success = true; // Open the source directory to read in files + $iterator = new \DirectoryIterator($src); + foreach ($iterator as $fObj) { if ($fObj->isFile()) { $filename = $fObj->getPathname(); + $fObj = null; // clear this iterator object to close the file - if (!unlink($filename)) { + + if (!\unlink($filename)) { return false; // couldn't delete the file } } elseif (!$fObj->isDot() && $fObj->isDir()) { // Try recursively on directory + self::rrmdir($fObj->getPathname()); } } + $iterator = null; // clear iterator Obj to close file/directory - return rmdir($src); // remove the directory & return results + return \rmdir($src); // remove the directory & return results } /** @@ -175,33 +198,40 @@ public static function rrmdir($src) public static function rmove($src, $dest) { // Only continue if user is a 'global' Admin + if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { return false; } // If source is not a directory stop processing - if (!is_dir($src)) { + + if (!\is_dir($src)) { return false; } // If the destination directory does not exist and could not be created stop processing - if (!is_dir($dest) && !mkdir($dest) && !is_dir($dest)) { + + if (!\is_dir($dest) && !\mkdir($dest) && !\is_dir($dest)) { return false; } // Open the source directory to read in files + $iterator = new \DirectoryIterator($src); + foreach ($iterator as $fObj) { if ($fObj->isFile()) { - rename($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); + \rename($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); } elseif (!$fObj->isDot() && $fObj->isDir()) { // Try recursively on directory + self::rmove($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); // rmdir($fObj->getPath()); // now delete the directory } } + $iterator = null; // clear iterator Obj to close file/directory - return rmdir($src); // remove the directory & return results + return \rmdir($src); // remove the directory & return results } /** @@ -210,33 +240,38 @@ public static function rmove($src, $dest) * @param string $src - Source of files being moved * @param string $dest - Destination of files being moved * - * @uses \Xmf\Module\Helper::getHelper() + * @return bool true on success * @uses \Xmf\Module\Helper::isUserAdmin() * - * @return bool true on success + * @uses \Xmf\Module\Helper::getHelper() */ public static function rcopy($src, $dest) { // Only continue if user is a 'global' Admin + if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { return false; } // If source is not a directory stop processing - if (!is_dir($src)) { + + if (!\is_dir($src)) { return false; } // If the destination directory does not exist and could not be created stop processing - if (!is_dir($dest) && !mkdir($dest) && !is_dir($dest)) { + + if (!\is_dir($dest) && !\mkdir($dest) && !\is_dir($dest)) { return false; } // Open the source directory to read in files + $iterator = new \DirectoryIterator($src); + foreach ($iterator as $fObj) { if ($fObj->isFile()) { - copy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); + \copy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); } elseif (!$fObj->isDot() && $fObj->isDir()) { self::rcopy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); } diff --git a/class/Common/FineimpuploadHandler.php b/class/Common/FineimpuploadHandler.php new file mode 100644 index 0000000..4213d2d --- /dev/null +++ b/class/Common/FineimpuploadHandler.php @@ -0,0 +1,367 @@ +allowedMimeTypes = ['image/gif', 'image/jpeg', 'image/png', 'application/zip']; + + $this->allowedExtensions = ['gif', 'jpeg', 'jpg', 'png', 'zip']; + } + + /** + * @param $target + * @param $mimeType + * @param $uid + * @return array|bool + */ + protected function storeUploadedFile($target, $mimeType, $uid) + { + $moduleDirName = \basename(dirname(__DIR__, 2)); + + $moduleDirNameUpper = \mb_strtoupper($moduleDirName); + + require_once XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/header.php'; + + $this->pathUpload = \constant($moduleDirNameUpper . '_' . 'UPLOAD_IMAGE_PATH'); + + $utility = new Utility(); + + /** @var \XoopsModules\Tdmdownloads\Helper $helper */ + + $helper = Helper::getInstance(); + + // if ( WGGALLERY_PERM_SUBMITAPPR === $permissionsHandler->permGlobalSubmit()) { + + // $this->permUseralbum = WGGALLERY_STATE_APPROVAL_VAL; + + // } else { + + // $this->permUseralbum = WGGALLERY_STATE_ONLINE_VAL; + + // } + + $this->permUseralbum = 1; //TODO: handle an option, whether images should be online immediately or not + + $pathParts = \pathinfo($this->getName()); + + $this->imageName = \uniqid('img', true) . '.' . \mb_strtolower($pathParts['extension']); + + $this->imageNicename = \str_replace(['_', '-'], ' ', $pathParts['filename']); + + $this->imageNameLarge = \uniqid('imgl', true) . '.' . \mb_strtolower($pathParts['extension']); + + $this->imagePath = $this->pathUpload . '/large/' . $this->imageNameLarge; + + if (!\move_uploaded_file($_FILES[$this->inputName]['tmp_name'], $this->imagePath)) { + return false; + } + + $this->imageNameOrig = $_FILES[$this->inputName]['name']; + + $this->imageMimetype = $_FILES[$this->inputName]['type']; + + $this->imageSize = $_FILES[$this->inputName]['size']; + + $ret = $this->handleImageDB(); + + if (!$ret) { + return [ + 'error' => \sprintf(\_FAILSAVEIMG, $this->imageNicename), + ]; + } + + // load watermark settings + + $albumObj = $albumsHandler->get($this->claims->cat); + + $wmId = $albumObj->getVar('alb_wmid'); + + $wmTargetM = false; + + $wmTargetL = false; + + if ($wmId > 0) { + $watermarksObj = $watermarksHandler->get($wmId); + + $wmTarget = $watermarksObj->getVar('wm_target'); + + if (\constant($moduleDirNameUpper . '_' . 'WATERMARK_TARGET_A') === $wmTarget || \constant($moduleDirNameUpper . '_' . 'WATERMARK_TARGET_M') === $wmTarget) { + $wmTargetM = true; + } + + if (\constant($moduleDirNameUpper . '_' . 'WATERMARK_TARGET_A') === $wmTarget || \constant($moduleDirNameUpper . '_' . 'WATERMARK_TARGET_L') === $wmTarget) { + $wmTargetL = true; + } + } + + // create medium image + + // $ret = $this->resizeImage($this->pathUpload . '/medium/' . $this->imageName, $helper->getConfig('maxwidth_medium'), $helper->getConfig('maxheight_medium')); + + $ret = $utility->resizeImage($this->imagePath, $this->pathUpload . '/medium/' . $this->imageName, $helper->getConfig('maxwidth_medium'), $helper->getConfig('maxheight_medium'), $this->imageMimetype); + + if (false === $ret) { + return ['error' => \sprintf(\constant($moduleDirNameUpper . '_' . 'FAILSAVEIMG_MEDIUM'), $this->imageNicename)]; + } + + if ('copy' === $ret) { + \copy($this->pathUpload . '/large/' . $this->imageNameLarge, $this->pathUpload . '/medium/' . $this->imageName); + } + + // create thumb + + // $ret = $this->resizeImage($this->pathUpload . '/thumbs/' . $this->imageName, $helper->getConfig('maxwidth_thumbs'), $helper->getConfig('maxheight_thumbs')); + + $ret = $utility->resizeImage($this->imagePath, $this->pathUpload . '/thumbs/' . $this->imageName, $helper->getConfig('maxwidth_thumbs'), $helper->getConfig('maxheight_thumbs'), $this->imageMimetype); + + if (false === $ret) { + return ['error' => \sprintf(\constant($moduleDirNameUpper . '_' . 'FAILSAVEIMG_THUMBS'), $this->imageNicename)]; + } + + if ('copy' === $ret) { + \copy($this->pathUpload . '/large/' . $this->imageNameLarge, $this->pathUpload . '/thumbs/' . $this->imageName); + } + + // add watermark to large image + + if ($wmTargetL) { + $imgWm = $this->pathUpload . '/large/' . $this->imageNameLarge; + + $resWm = $watermarksHandler->watermarkImage($wmId, $imgWm, $imgWm); + + if (true !== $resWm) { + return ['error' => \sprintf(\constant($moduleDirNameUpper . '_' . 'FAILSAVEWM_LARGE'), $this->imageNicename, $resWm)]; + } + } + + // add watermark to medium image + + if ($wmTargetM) { + $imgWm = $this->pathUpload . '/medium/' . $this->imageName; + + $resWm = $watermarksHandler->watermarkImage($wmId, $imgWm, $imgWm); + + if (true !== $resWm) { + return ['error' => \sprintf(\constant($moduleDirNameUpper . '_' . 'FAILSAVEWM_MEDIUM'), $this->imageNicename, $resWm)]; + } + } + + return ['success' => true, 'uuid' => $uuid]; + } + + /** + * @return bool + */ + private function handleImageDB() + { + $moduleDirName = \basename(dirname(__DIR__, 2)); + + require_once XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/header.php'; + + global $xoopsUser; + + $this->getImageDim(); + + $helper = Helper::getInstance(); + + $imagesHandler = $helper->getHandler('Images'); + +// $imagesHandler = new \XoopsModules\Tdmdownloads\Common\ImagesHandler(); + + $imagesObj = $imagesHandler->create(); + + // Set Vars + + $imagesObj->setVar('img_title', $this->imageNicename); + + $imagesObj->setVar('img_desc', ''); + + $imagesObj->setVar('img_name', $this->imageName); + + $imagesObj->setVar('img_namelarge', $this->imageNameLarge); + + $imagesObj->setVar('img_nameorig', $this->imageNameOrig); + + $imagesObj->setVar('img_mimetype', $this->imageMimetype); + + $imagesObj->setVar('img_size', $this->imageSize); + + $imagesObj->setVar('img_resx', $this->imageWidth); + + $imagesObj->setVar('img_resy', $this->imageHeight); + + $imagesObj->setVar('img_albid', $this->claims->cat); + + $imagesObj->setVar('img_state', $this->permUseralbum); + + $imagesObj->setVar('img_date', \time()); + + $imagesObj->setVar('img_submitter', $xoopsUser->id()); + + $imagesObj->setVar('img_ip', $_SERVER['REMOTE_ADDR']); + + // Insert Data + + if ($imagesHandler->insert($imagesObj)) { + $this->imageId = $imagesHandler->getInsertId(); + + return true; + } + + return false; + } + + /** + * @return bool|string + */ + private function getImageDim() + { + switch ($this->imageMimetype) { + case 'image/png': + $img = \imagecreatefrompng($this->imagePath); + break; + case 'image/jpeg': + $img = \imagecreatefromjpeg($this->imagePath); + break; + case 'image/gif': + $img = \imagecreatefromgif($this->imagePath); + break; + case 'application/zip': + $this->imageWidth = 0; + $this->imageHeight = 0; + // $img = imagecreatefromgif($this->imagePath); + break; + default: + $this->imageWidth = 0; + $this->imageHeight = 0; + + return 'Unsupported format'; + } + + $this->imageWidth = \imagesx($img); + + $this->imageHeight = \imagesy($img); + + \imagedestroy($img); + + return true; + } +} diff --git a/class/Common/ImageResizer.php b/class/Common/ImageResizer.php new file mode 100644 index 0000000..c50fb93 --- /dev/null +++ b/class/Common/ImageResizer.php @@ -0,0 +1,350 @@ + - Website: + */ +trait ImageResizer +{ + /** + * resize image if size exceed given width/height + * @param $sourcefile + * @param string $endfile + * @param int $max_width + * @param int $max_height + * @param $imageMimetype + * @return string|bool + */ + public function resizeImage($sourcefile, $endfile, $max_width, $max_height, $imageMimetype) + { + // check file extension + + switch ($imageMimetype) { + case 'image/png': + $img = \imagecreatefrompng($sourcefile); + break; + case 'image/jpeg': + $img = \imagecreatefromjpeg($sourcefile); + break; + case 'image/gif': + $img = \imagecreatefromgif($sourcefile); + break; + default: + return 'Unsupported format'; + } + + $width = \imagesx($img); + + $height = \imagesy($img); + + if ($width > $max_width || $height > $max_height) { + // recalc image size based on max_width/max_height + + if ($width > $height) { + if ($width < $max_width) { + $new_width = $width; + } else { + $new_width = $max_width; + + $divisor = $width / $new_width; + + $new_height = \floor($height / $divisor); + } + } elseif ($height < $max_height) { + $new_height = $height; + } else { + $new_height = $max_height; + + $divisor = $height / $new_height; + + $new_width = \floor($width / $divisor); + } + + // Create a new temporary image. + + $tmpimg = \imagecreatetruecolor($new_width, $new_height); + + imagealphablending($tmpimg, false); + + imagesavealpha($tmpimg, true); + + // Copy and resize old image into new image. + + \imagecopyresampled($tmpimg, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height); + + \unlink($endfile); + + //compressing the file + + switch ($imageMimetype) { + case 'image/png': + \imagepng($tmpimg, $endfile, 0); + break; + case 'image/jpeg': + \imagejpeg($tmpimg, $endfile, 100); + break; + case 'image/gif': + \imagegif($tmpimg, $endfile); + break; + } + + // release the memory + + \imagedestroy($tmpimg); + } else { + return 'copy'; + } + + \imagedestroy($img); + + return true; + } + + /** + * @param $src_url + * @param $src_mimetype + * @param $dest_url + * @param $dest_w + * @param $dest_h + * @param int $quality + * @return bool|string + */ + public function resizeAndCrop($src_url, $src_mimetype, $dest_url, $dest_w, $dest_h, $quality = 90) + { + // check file extension + + switch ($src_mimetype) { + case 'image/png': + $original = \imagecreatefrompng($src_url); + break; + case 'image/jpeg': + $original = \imagecreatefromjpeg($src_url); + break; + case 'image/gif': + $original = \imagecreatefromgif($src_url); + break; + default: + return 'Unsupported format'; + } + + if (!$original) { + return false; + } + + // GET ORIGINAL IMAGE DIMENSIONS + + [$original_w, $original_h] = \getimagesize($src_url); + + // RESIZE IMAGE AND PRESERVE PROPORTIONS + + $dest_w_resize = $dest_w; + + $dest_h_resize = $dest_h; + + if ($original_w > $original_h) { + $dest_h_ratio = $dest_h / $original_h; + + $dest_w_resize = (int)\round($original_w * $dest_h_ratio); + } else { + $dest_w_ratio = $dest_w / $original_w; + + $dest_h_resize = (int)\round($original_h * $dest_w_ratio); + } + + if ($dest_w_resize < $dest_w) { + $dest_h_ratio = $dest_w / $dest_w_resize; + + $dest_h_resize = (int)\round($dest_h * $dest_h_ratio); + + $dest_w_resize = $dest_w; + } + + // CREATE THE PROPORTIONAL IMAGE RESOURCE + + $thumb = \imagecreatetruecolor($dest_w_resize, $dest_h_resize); + + if (!\imagecopyresampled($thumb, $original, 0, 0, 0, 0, $dest_w_resize, $dest_h_resize, $original_w, $original_h)) { + return false; + } + + // CREATE THE CENTERED CROPPED IMAGE TO THE SPECIFIED DIMENSIONS + + $final = \imagecreatetruecolor($dest_w, $dest_h); + + $dest_w_offset = 0; + + $dest_h_offset = 0; + + if ($dest_w < $dest_w_resize) { + $dest_w_offset = (int)\round(($dest_w_resize - $dest_w) / 2); + } else { + $dest_h_offset = (int)\round(($dest_h_resize - $dest_h) / 2); + } + + if (!\imagecopy($final, $thumb, 0, 0, $dest_w_offset, $dest_h_offset, $dest_w_resize, $dest_h_resize)) { + return false; + } + + // STORE THE FINAL IMAGE - WILL OVERWRITE $dest_url + + if (!\imagejpeg($final, $dest_url, $quality)) { + return false; + } + + return true; + } + + /** + * @param $src_url + * @param $dest_url + * @param $pos + * @param $of + */ + public function mergeImage($src_url, $dest_url, $pos, $of) + { + $dest = \imagecreatefromjpeg($dest_url); + + $src = \imagecreatefromjpeg($src_url); + + // ImageCopy ( resource $dst_im , resource $src_im , int $dst_x , int $dst_y , int $src_x , int $src_y , int $src_w , int $src_h ) + + // $src = imagecreatefromjpeg($src_url); + + if (4 == $of) { + switch ($pos) { + case 1: + \imagecopy($dest, $src, 0, 0, 0, 0, 199, 149); //top left + break; + case 2: + \imagecopy($dest, $src, 201, 0, 0, 0, 199, 149); //top right + break; + case 3: + \imagecopy($dest, $src, 0, 151, 0, 0, 199, 149); //bottom left + break; + case 4: + \imagecopy($dest, $src, 201, 151, 0, 0, 199, 149); //bottom right + break; + } + } + + if (6 == $of) { + switch ($pos) { + case 1: + \imagecopy($dest, $src, 0, 0, 0, 0, 133, 149); //top left + break; + case 2: + \imagecopy($dest, $src, 134, 0, 0, 0, 133, 149); //top center + break; + case 3: + \imagecopy($dest, $src, 268, 0, 0, 0, 133, 149); //top right + break; + case 4: + \imagecopy($dest, $src, 0, 151, 0, 0, 133, 149); //bottom left + break; + case 5: + \imagecopy($dest, $src, 134, 151, 0, 0, 133, 149); //bottom center + break; + case 6: + \imagecopy($dest, $src, 268, 151, 0, 0, 133, 149); //bottom right + break; + } + } + + \imagejpeg($dest, $dest_url); + + \imagedestroy($src); + + \imagedestroy($dest); + } + + /** + * resize image if size exceed given width/height + * @param string $endfile + * @param int $max_width + * @param int $max_height + * @return string|bool + */ + /* private function resizeImageSave($endfile, $max_width, $max_height){ + // check file extension + switch ($this->imageMimetype) { + case'image/png': + $img = imagecreatefrompng($this->imagePath); + + break; + case'image/jpeg': + $img = imagecreatefromjpeg($this->imagePath); + break; + case'image/gif': + $img = imagecreatefromgif($this->imagePath); + break; + default: + return 'Unsupported format'; + } + + $width = imagesx($img); + $height = imagesy($img); + + if ($width > $max_width || $height > $max_height) { + // recalc image size based on max_width/max_height + if ($width > $height) { + if ($width < $max_width) { + $new_width = $width; + } else { + $new_width = $max_width; + $divisor = $width / $new_width; + $new_height = floor($height / $divisor); + } + } else if($height < $max_height){ + $new_height = $height; + } else { + $new_height = $max_height; + $divisor = $height / $new_height; + $new_width = floor($width / $divisor); + } + + // Create a new temporary image. + $tmpimg = imagecreatetruecolor($new_width, $new_height); + imagealphablending($tmpimg, false); + imagesavealpha($tmpimg, true); + + // Copy and resize old image into new image. + imagecopyresampled($tmpimg, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height); + + //compressing the file + switch ($this->imageMimetype) { + case'image/png': + imagepng($tmpimg, $endfile, 0); + break; + case'image/jpeg': + imagejpeg($tmpimg, $endfile, 100); + break; + case'image/gif': + imagegif($tmpimg, $endfile); + break; + } + + // release the memory + imagedestroy($tmpimg); + } else { + return 'copy'; + } + imagedestroy($img); + return true; + } */ +} diff --git a/class/Common/Images.php b/class/Common/Images.php new file mode 100644 index 0000000..a8e9fe9 --- /dev/null +++ b/class/Common/Images.php @@ -0,0 +1,354 @@ + - Website: + */ + +use XoopsModules\Tdmdownloads\{ + Helper +}; + +/** + * Class Object Images + */ +class Images extends \XoopsObject +{ + /** + * Constructor + * + * @param null + */ + public function __construct() + { + $this->initVar('img_id', \XOBJ_DTYPE_INT); + + $this->initVar('img_title', \XOBJ_DTYPE_TXTBOX); + + $this->initVar('img_desc', \XOBJ_DTYPE_TXTAREA); + + $this->initVar('img_name', \XOBJ_DTYPE_TXTBOX); + + $this->initVar('img_namelarge', \XOBJ_DTYPE_TXTBOX); + + $this->initVar('img_nameorig', \XOBJ_DTYPE_TXTBOX); + + $this->initVar('img_mimetype', \XOBJ_DTYPE_TXTBOX); + + $this->initVar('img_size', \XOBJ_DTYPE_INT); + + $this->initVar('img_resx', \XOBJ_DTYPE_INT); + + $this->initVar('img_resy', \XOBJ_DTYPE_INT); + + $this->initVar('img_downloads', \XOBJ_DTYPE_INT); + + $this->initVar('img_ratinglikes', \XOBJ_DTYPE_INT); + + $this->initVar('img_votes', \XOBJ_DTYPE_INT); + + $this->initVar('img_weight', \XOBJ_DTYPE_INT); + + $this->initVar('img_albid', \XOBJ_DTYPE_INT); + + $this->initVar('img_state', \XOBJ_DTYPE_INT); + + $this->initVar('img_date', \XOBJ_DTYPE_INT); + + $this->initVar('img_submitter', \XOBJ_DTYPE_INT); + + $this->initVar('img_ip', \XOBJ_DTYPE_TXTAREA); + + $this->initVar('dohtml', \XOBJ_DTYPE_INT, 1, false); + } + + /** + * @static function &getInstance + * + * @param null + */ + public static function getInstance() + { + static $instance = false; + + if (!$instance) { + $instance = new self(); + } + } + + /** + * @return int + */ + public function getNewInsertedIdImages() + { + return $GLOBALS['xoopsDB']->getInsertId(); + } + + /** + * @public function getForm + * @param bool $action + * @return \XoopsThemeForm + */ + public function getFormImages($action = false) + { + $moduleDirName = \basename(dirname(__DIR__, 2)); + + $moduleDirNameUpper = \mb_strtoupper($moduleDirName); + + $helper = Helper::getInstance(); + + if (!$action) { + $action = $_SERVER['REQUEST_URI']; + } + + // Title + + $title = $this->isNew() ? \sprintf(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_ADD')) : \sprintf(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_EDIT')); + + // Get Theme Form + + \xoops_load('XoopsFormLoader'); + + $form = new \XoopsThemeForm($title, 'form', $action, 'post', true); + + $form->setExtra('enctype="multipart/form-data"'); + + // Form Text ImgTitle + + $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_TITLE'), 'img_title', 50, 255, $this->getVar('img_title'))); + + // Form editor ImgDesc + + $editorConfigs = []; + + $editorConfigs['name'] = 'img_desc'; + + $editorConfigs['value'] = $this->getVar('img_desc', 'e'); + + $editorConfigs['rows'] = 5; + + $editorConfigs['cols'] = 40; + + $editorConfigs['width'] = '100%'; + + $editorConfigs['height'] = '400px'; + + $editorConfigs['editor'] = $helper->getConfig('editor'); + + $form->addElement(new \XoopsFormEditor(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_DESC'), 'img_desc', $editorConfigs)); + + // Form Text ImgName + + $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_NAME'), 'img_name', 50, 255, $this->getVar('img_name')), true); + + // Form Text ImgNameLarge + + $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_NAMELARGE'), 'img_namelarge', 50, 255, $this->getVar('img_namelarge')), true); + + // Form Text ImgOrigname + + $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_NAMEORIG'), 'img_nameorig', 50, 255, $this->getVar('img_nameorig')), true); + + // Form Text ImgMimetype + + $imgMimetype = $this->isNew() ? '0' : $this->getVar('img_mimetype'); + + $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_MIMETYPE'), 'img_mimetype', 20, 150, $imgMimetype)); + + // Form Text ImgSize + + $imgSize = $this->isNew() ? '0' : $this->getVar('img_size'); + + $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_SIZE'), 'img_size', 20, 150, $imgSize)); + + // Form Text ImgResx + + $imgResx = $this->isNew() ? '0' : $this->getVar('img_resx'); + + $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_RESX'), 'img_resx', 20, 150, $imgResx)); + + // Form Text ImgResy + + $imgResy = $this->isNew() ? '0' : $this->getVar('img_resy'); + + $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_RESY'), 'img_resy', 20, 150, $imgResy)); + + // Form Text ImgDownloads + + $imgDownloads = $this->isNew() ? '0' : $this->getVar('img_downloads'); + + $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_DOWNLOADS'), 'img_downloads', 20, 150, $imgDownloads)); + + // Form Text ImgRatinglikes + + $imgRatinglikes = $this->isNew() ? '0' : $this->getVar('img_ratinglikes'); + + $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_RATINGLIKES'), 'img_ratinglikes', 20, 150, $imgRatinglikes)); + + // Form Text ImgVotes + + $imgVotes = $this->isNew() ? '0' : $this->getVar('img_votes'); + + $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_VOTES'), 'img_votes', 20, 150, $imgVotes)); + + // Form Text ImgWeight + + $imgWeight = $this->isNew() ? '0' : $this->getVar('img_weight'); + + $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_WEIGHT'), 'img_weight', 20, 150, $imgWeight)); + + // Form Table albums + + $albumsHandler = $helper->getHandler('Albums'); + + $imgAlbidSelect = new \XoopsFormSelect(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_ALBID'), 'img_albid', $this->getVar('img_albid')); + + $imgAlbidSelect->addOptionArray($albumsHandler->getList()); + + $form->addElement($imgAlbidSelect, true); + + // Images handler + + $imagesHandler = $helper->getHandler('Images'); + + // Form Select Images + + $imgStateSelect = new \XoopsFormSelect(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_STATE'), 'img_state', $this->getVar('img_state')); + + $imgStateSelect->addOption('Empty'); + + $imgStateSelect->addOptionArray($imagesHandler->getList()); + + $form->addElement($imgStateSelect, true); + + // Form Text Date Select ImgDate + + $imgDate = $this->isNew() ? 0 : $this->getVar('img_date'); + + $form->addElement(new \XoopsFormTextDateSelect(\constant('CO_' . $moduleDirNameUpper . '_' . 'DATE'), 'img_date', '', $imgDate)); + + // Form Select User ImgSubmitter + + $form->addElement(new \XoopsFormSelectUser(\constant('CO_' . $moduleDirNameUpper . '_' . 'SUBMITTER'), 'img_submitter', false, $this->getVar('img_submitter'))); + + // Form Text ImgIp + + $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_IP'), 'img_ip', 50, 255, $this->getVar('img_ip'))); + + // To Save + + $form->addElement(new \XoopsFormHidden('op', 'save')); + + $form->addElement(new \XoopsFormButtonTray('', \_SUBMIT, 'submit', '', false)); + + return $form; + } + + /** + * Get Values + * @param null $keys + * @param null $format + * @param null $maxDepth + * @return array + */ + public function getValuesImages($keys = null, $format = null, $maxDepth = null) + { + $moduleDirName = \basename(dirname(__DIR__, 2)); + + $moduleDirNameUpper = \mb_strtoupper($moduleDirName); + + $helper = Helper::getInstance(); + + $ret = $this->getValues($keys, $format, $maxDepth); + + $ret['id'] = $this->getVar('img_id'); + + $ret['title'] = $this->getVar('img_title'); + + $ret['desc'] = $this->getVar('img_desc', 'n'); + + $ret['name'] = $this->getVar('img_name'); + + $ret['namelarge'] = $this->getVar('img_namelarge'); + + $ret['nameorig'] = $this->getVar('img_nameorig'); + + $ret['mimetype'] = $this->getVar('img_mimetype'); + + $ret['size'] = $this->getVar('img_size'); + + $ret['resx'] = $this->getVar('img_resx'); + + $ret['resy'] = $this->getVar('img_resy'); + + $ret['downloads'] = $this->getVar('img_downloads'); + + $ret['ratinglikes'] = $this->getVar('img_ratinglikes'); + + $ret['votes'] = $this->getVar('img_votes'); + + $ret['weight'] = $this->getVar('img_weight'); + + $ret['albid'] = $this->getVar('img_albid'); + + //$albums = $helper->getHandler('Albums'); + + //$albumsObj = $albums->get($this->getVar('img_albid')); + + //if (isset($albumsObj) && is_object($albumsObj)) { + + //$ret['alb_name'] = $albumsObj->getVar('alb_name'); + + //} + + $ret['state'] = $this->getVar('img_state'); + + $ret['state_text'] = $helper->getStateText($this->getVar('img_state')); + + $ret['date'] = \formatTimestamp($this->getVar('img_date'), 's'); + + $ret['submitter'] = \XoopsUser::getUnameFromId($this->getVar('img_submitter')); + + $ret['ip'] = $this->getVar('img_ip'); + + $ret['large'] = \constant($moduleDirNameUpper . '_' . 'UPLOAD_IMAGE_URL') . '/large/' . $this->getVar('img_namelarge'); + + $ret['medium'] = \constant($moduleDirNameUpper . '_' . 'UPLOAD_IMAGE_URL') . '/medium/' . $this->getVar('img_name'); + + $ret['thumb'] = \constant($moduleDirNameUpper . '_' . 'UPLOAD_IMAGE_URL') . '/thumbs/' . $this->getVar('img_name'); + + return $ret; + } + + /** + * Returns an array representation of the object + * + * @return array + */ + public function toArrayImages() + { + $ret = []; + + $vars = $this->getVars(); + + foreach (\array_keys($vars) as $var) { + $ret[$var] = $this->getVar('"{$var}"'); + } + + return $ret; + } +} diff --git a/class/Common/ImagesHandler.php b/class/Common/ImagesHandler.php new file mode 100644 index 0000000..bef5812 --- /dev/null +++ b/class/Common/ImagesHandler.php @@ -0,0 +1,148 @@ + - Website: + */ + +/** + * Class Object Handler Images + */ +class ImagesHandler extends \XoopsPersistableObjectHandler +{ + /** + * Constructor + * @param \XoopsDatabase|null $db + */ + public function __construct(?\XoopsDatabase $db = null) + { + parent::__construct($db, 'tdmdownloads_images', Images::class, 'img_id', 'img_name'); + } + + /** + * retrieve a field + * + * @param int $i field id + * @param null|mixed $fields + * @return mixed reference to the {@link Get} object + */ + public function get($i = null, $fields = null) + { + return parent::get($i, $fields); + } + + /** + * get inserted id + * + * @param null + * @return int reference to the {@link Get} object + */ + public function getInsertId() + { + return $this->db->getInsertId(); + } + + /** + * Get Count Images in the database + * @param int $albId + * @param int $start + * @param int $limit + * @param string $sort + * @param string $order + * @return int + */ + public function getCountImages($albId = 0, $start = 0, $limit = 0, $sort = 'img_id ASC, img_name', $order = 'ASC') + { + $crCountImages = new \CriteriaCompo(); + + $crCountImages = $this->getImagesCriteria($crCountImages, $albId, $start, $limit, $sort, $order); + + return parent::getCount($crCountImages); + } + + /** + * Get All Images in the database + * @param int $start + * @param int $limit + * @param string $sort + * @param string $order + * @return array + */ + public function getAllImages($start = 0, $limit = 0, $sort = 'img_id ASC, img_name', $order = 'ASC') + { + $crAllImages = new \CriteriaCompo(); + + $crAllImages = $this->getImagesCriteria($crAllImages, 0, $start, $limit, $sort, $order); + + return parent::getAll($crAllImages); + } + + /** + * Get Criteria Images + * @param $crImages + * @param $albId + * @param int $start + * @param int $limit + * @param string $sort + * @param string $order + * @return int + */ + private function getImagesCriteria($crImages, $albId, $start, $limit, $sort, $order) + { + if ($albId > 0) { + $crImages->add(new \Criteria('img_albid', $albId)); + } + + $crImages->setStart($start); + + $crImages->setLimit($limit); + + $crImages->setSort($sort); + + $crImages->setOrder($order); + + return $crImages; + } + + /** + * delete all copies of a specific image + * @param $imageName + * @return bool + */ + public function unlinkImages($imageName) + { + \unlink(\constant($moduleDirNameUpper . '_' . 'UPLOAD_IMAGE_PATH') . '/large/' . $imageName); + + if (\file_exists(\constant($moduleDirNameUpper . '_' . 'UPLOAD_IMAGE_PATH') . '/large/' . $imageName)) { + return false; + } + + \unlink(\constant($moduleDirNameUpper . '_' . 'UPLOAD_IMAGE_PATH') . '/medium/' . $imageName); + + if (\file_exists(\constant($moduleDirNameUpper . '_' . 'UPLOAD_IMAGE_PATH') . '/medium/' . $imageName)) { + return false; + } + + \unlink(\constant($moduleDirNameUpper . '_' . 'UPLOAD_IMAGE_PATH') . '/thumbs/' . $imageName); + + if (\file_exists(\constant($moduleDirNameUpper . '_' . 'UPLOAD_IMAGE_PATH') . '/thumbs/' . $imageName)) { + return false; + } + + return true; + } +} diff --git a/class/Common/Migrate.php b/class/Common/Migrate.php index e446c3f..a68effa 100644 --- a/class/Common/Migrate.php +++ b/class/Common/Migrate.php @@ -1,4 +1,4 @@ - * @copyright 2016 XOOPS Project (https://xoops.org) - * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) + * @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) * @link https://xoops.org */ class Migrate extends \Xmf\Database\Migrate { private $renameTables; + private $renameColumns; /** * Migrate constructor. @@ -32,18 +33,26 @@ class Migrate extends \Xmf\Database\Migrate */ public function __construct() { - require_once dirname(dirname(__DIR__)) . '/include/config.php'; - $config = getConfig(); - $this->renameTables = $config->renameTables; + $class = __NAMESPACE__ . '\\' . 'Configurator'; + + if (!\class_exists($class)) { + throw new \RuntimeException("Class '$class' not found"); + } + + $configurator = new $class(); + + $this->renameTables = $configurator->renameTables; + + $moduleDirName = \basename(dirname(__DIR__, 2)); - $moduleDirName = basename(dirname(dirname(__DIR__))); parent::__construct($moduleDirName); } + /** - * change table prefix if needed + * rename table if needed */ - private function changePrefix() + private function renameTable() { foreach ($this->renameTables as $oldName => $newName) { if ($this->tableHandler->useTable($oldName) && !$this->tableHandler->useTable($newName)) { @@ -53,42 +62,18 @@ private function changePrefix() } /** - * Change integer IPv4 column to varchar IPv6 capable - * - * @param string $tableName table to convert - * @param string $columnName column with IP address + * rename columns if needed */ - private function convertIPAddresses($tableName, $columnName) + private function renameColumns() { - if ($this->tableHandler->useTable($tableName)) { - $attributes = $this->tableHandler->getColumnAttributes($tableName, $columnName); - if (false !== mb_strpos($attributes, ' int(')) { - if (false === mb_strpos($attributes, 'unsigned')) { - $this->tableHandler->alterColumn($tableName, $columnName, " bigint(16) NOT NULL DEFAULT '0' "); - $this->tableHandler->update($tableName, [$columnName => "4294967296 + $columnName"], "WHERE $columnName < 0", false); + foreach ($this->renameColumns as $tableName) { + if ($this->tableHandler->useTable($tableName)) { + $oldName = $tableName['from']; + $newName = $tableName['to']; + $attributes = $this->tableHandler->getColumnAttributes($tableName, $oldName); + if (false !== \strpos($attributes, ' int(')) { + $this->tableHandler->alterColumn($tableName, $oldName, $attributes, $newName); } - $this->tableHandler->alterColumn($tableName, $columnName, " varchar(45) NOT NULL DEFAULT '' "); - $this->tableHandler->update($tableName, [$columnName => "INET_NTOA($columnName)"], '', false); - } - } - } - - /** - * Move do* columns from newbb_posts to newbb_posts_text table - */ - private function moveDoColumns() - { - $tableName = 'newbb_posts_text'; - $srcTableName = 'newbb_posts'; - if (false !== $this->tableHandler->useTable($tableName) - && false !== $this->tableHandler->useTable($srcTableName)) { - $attributes = $this->tableHandler->getColumnAttributes($tableName, 'dohtml'); - if (false === $attributes) { - $this->synchronizeTable($tableName); - $updateTable = $GLOBALS['xoopsDB']->prefix($tableName); - $joinTable = $GLOBALS['xoopsDB']->prefix($srcTableName); - $sql = "UPDATE `$updateTable` t1 INNER JOIN `$joinTable` t2 ON t1.post_id = t2.post_id \n" . "SET t1.dohtml = t2.dohtml, t1.dosmiley = t2.dosmiley, t1.doxcode = t2.doxcode\n" . ' , t1.doimage = t2.doimage, t1.dobr = t2.dobr'; - $this->tableHandler->addToQueue($sql); } } } @@ -102,12 +87,13 @@ private function moveDoColumns() */ protected function preSyncActions() { - // change 'bb' table prefix to 'newbb' - $this->changePrefix(); - // columns dohtml, dosmiley, doxcode, doimage and dobr moved between tables as some point - $this->moveDoColumns(); - // Convert IP address columns from int to readable varchar(45) for IPv6 - $this->convertIPAddresses('newbb_posts', 'poster_ip'); - $this->convertIPAddresses('newbb_report', 'reporter_ip'); + // rename table + if ($this->renameTables && \is_array($this->renameTables)) { + $this->renameTable(); + } + // rename column + if ($this->renameColumns && \is_array($this->renameColumns)) { + $this->renameColumns(); + } } } diff --git a/class/Common/ServerStats.php b/class/Common/ServerStats.php index 2ed5f4f..3279fe2 100644 --- a/class/Common/ServerStats.php +++ b/class/Common/ServerStats.php @@ -1,4 +1,4 @@ -prefix('wfdownloads_meta'); + // $sql .= " WHERE metakey='version' LIMIT 1"; + // $query = $GLOBALS['xoopsDB']->query($sql); + // list($meta) = $GLOBALS['xoopsDB']->fetchRow($query); - $html .= "
" . constant('CO_' . $moduleDirNameUpper . '_IMAGEINFO') . "\n"; + + $html .= "
" . \constant('CO_' . $moduleDirNameUpper . '_IMAGEINFO') . "\n"; + $html .= "
\n"; + // $html .= '
' . constant('CO_' . $moduleDirNameUpper . '_METAVERSION') . $meta . "
\n"; + // $html .= "
\n"; + // $html .= "
\n"; - $html .= '
' . constant('CO_' . $moduleDirNameUpper . '_SPHPINI') . "
\n"; + + $html .= '
' . \constant('CO_' . $moduleDirNameUpper . '_SPHPINI') . "
\n"; + $html .= "
    \n"; - $gdlib = function_exists('gd_info') ? '' . constant('CO_' . $moduleDirNameUpper . '_GDON') . '' : '' . constant('CO_' . $moduleDirNameUpper . '_GDOFF') . ''; - $html .= '
  • ' . constant('CO_' . $moduleDirNameUpper . '_GDLIBSTATUS') . $gdlib; - if (function_exists('gd_info')) { + $gdlib = \function_exists('gd_info') ? '' . \constant('CO_' . $moduleDirNameUpper . '_GDON') . '' : '' . \constant('CO_' . $moduleDirNameUpper . '_GDOFF') . ''; + + $html .= '
  • ' . \constant('CO_' . $moduleDirNameUpper . '_GDLIBSTATUS') . $gdlib; + + if (\function_exists('gd_info')) { if (true === $gdlib = gd_info()) { - $html .= '
  • ' . constant('CO_' . $moduleDirNameUpper . '_GDLIBVERSION') . '' . $gdlib['GD Version'] . ''; + $html .= '
  • ' . \constant('CO_' . $moduleDirNameUpper . '_GDLIBVERSION') . '' . $gdlib['GD Version'] . ''; } } - // + // $safemode = ini_get('safe_mode') ? constant('CO_' . $moduleDirNameUpper . '_ON') . constant('CO_' . $moduleDirNameUpper . '_SAFEMODEPROBLEMS : constant('CO_' . $moduleDirNameUpper . '_OFF'); + // $html .= '
  • ' . constant('CO_' . $moduleDirNameUpper . '_SAFEMODESTATUS . $safemode; - // + // $registerglobals = (!ini_get('register_globals')) ? "" . constant('CO_' . $moduleDirNameUpper . '_OFF') . '' : "" . constant('CO_' . $moduleDirNameUpper . '_ON') . ''; + // $html .= '
  • ' . constant('CO_' . $moduleDirNameUpper . '_REGISTERGLOBALS . $registerglobals; - // - $downloads = ini_get('file_uploads') ? '' . constant('CO_' . $moduleDirNameUpper . '_ON') . '' : '' . constant('CO_' . $moduleDirNameUpper . '_OFF') . ''; - $html .= '
  • ' . constant('CO_' . $moduleDirNameUpper . '_SERVERUPLOADSTATUS') . $downloads; - $html .= '
  • ' . constant('CO_' . $moduleDirNameUpper . '_MAXUPLOADSIZE') . ' ' . ini_get('upload_max_filesize') . "\n"; - $html .= '
  • ' . constant('CO_' . $moduleDirNameUpper . '_MAXPOSTSIZE') . ' ' . ini_get('post_max_size') . "\n"; - $html .= '
  • ' . constant('CO_' . $moduleDirNameUpper . '_MEMORYLIMIT') . ' ' . ini_get('memory_limit') . "\n"; + $downloads = \ini_get('file_uploads') ? '' . \constant('CO_' . $moduleDirNameUpper . '_ON') . '' : '' . \constant('CO_' . $moduleDirNameUpper . '_OFF') . ''; + + $html .= '
  • ' . \constant('CO_' . $moduleDirNameUpper . '_SERVERUPLOADSTATUS') . $downloads; + + $html .= '
  • ' . \constant('CO_' . $moduleDirNameUpper . '_MAXUPLOADSIZE') . ' ' . \ini_get('upload_max_filesize') . "\n"; + + $html .= '
  • ' . \constant('CO_' . $moduleDirNameUpper . '_MAXPOSTSIZE') . ' ' . \ini_get('post_max_size') . "\n"; + + $html .= '
  • ' . \constant('CO_' . $moduleDirNameUpper . '_MEMORYLIMIT') . ' ' . \ini_get('memory_limit') . "\n"; + $html .= "
\n"; + $html .= "
    \n"; - $html .= '
  • ' . constant('CO_' . $moduleDirNameUpper . '_SERVERPATH') . ' ' . XOOPS_ROOT_PATH . "\n"; + + $html .= '
  • ' . \constant('CO_' . $moduleDirNameUpper . '_SERVERPATH') . ' ' . XOOPS_ROOT_PATH . "\n"; + $html .= "
\n"; + $html .= "
\n"; - $html .= constant('CO_' . $moduleDirNameUpper . '_UPLOADPATHDSC') . "\n"; + + $html .= \constant('CO_' . $moduleDirNameUpper . '_UPLOADPATHDSC') . "\n"; + $html .= '
'; + $html .= '

'; return $html; diff --git a/class/Common/SysUtility.php b/class/Common/SysUtility.php new file mode 100644 index 0000000..9ca2ced --- /dev/null +++ b/class/Common/SysUtility.php @@ -0,0 +1,424 @@ + + * @author Mamba + */ + +use Xmf\Request; +use XoopsFormEditor; +use XoopsModules\Tdmdownloads\{ + Helper +}; + + +/** + * Class SysUtility + */ +class SysUtility +{ + use VersionChecks; //checkVerXoops, checkVerPhp Traits + use ServerStats; // getServerStats Trait + use FilesManagement; // Files Management Trait + + //--------------- Common module methods ----------------------------- + + /** + * Access the only instance of this class + * + * @return SysUtility + * + */ + public static function getInstance(): SysUtility + { + static $instance; + if (null === $instance) { + $instance = new static(); + } + + return $instance; + } + + /** + * @param $text + * @param $form_sort + * @return string + */ + public static function selectSorting($text, $form_sort): string + { + global $start, $order, $sort; + + $select_view = ''; + $moduleDirName = \basename(\dirname(__DIR__)); + $helper = Helper::getInstance(); + + //$pathModIcon16 = XOOPS_URL . '/modules/' . $moduleDirName . '/' . $helper->getConfig('modicons16'); + $pathModIcon16 = $helper->url($helper->getModule()->getInfo('modicons16')); + + $select_view = '' . $text . ''; + //$sorts = $sort == 'asc' ? 'desc' : 'asc'; + if ($form_sort == $sort) { + $sel1 = 'asc' === $order ? 'selasc.png' : 'asc.png'; + $sel2 = 'desc' === $order ? 'seldesc.png' : 'desc.png'; + } else { + $sel1 = 'asc.png'; + $sel2 = 'desc.png'; + } + $select_view .= ' ASC'; + $select_view .= 'DESC'; + $select_view .= ''; + + return $select_view; + } + + /***************Blocks***************/ + /** + * @param array $cats + * @return string + */ + public static function blockAddCatSelect(array $cats): string + { + $cat_sql = ''; + if (\is_array($cats) && !empty($cats)) { + $cat_sql = '(' . \current($cats); + \array_shift($cats); + foreach ($cats as $cat) { + $cat_sql .= ',' . $cat; + } + $cat_sql .= ')'; + } + + return $cat_sql; + } + + /** + * @param $content + */ + public static function metaKeywords($content): void + { + global $xoopsTpl, $xoTheme; + $myts = \MyTextSanitizer::getInstance(); + $content = $myts->undoHtmlSpecialChars($myts->displayTarea($content)); + if (\is_object($xoTheme)) { + $xoTheme->addMeta('meta', 'keywords', \strip_tags($content)); + } else { // Compatibility for old Xoops versions + $xoopsTpl->assign('xoops_metaKeywords', \strip_tags($content)); + } + } + + /** + * @param $content + */ + public static function metaDescription($content): void + { + global $xoopsTpl, $xoTheme; + $myts = \MyTextSanitizer::getInstance(); + $content = $myts->undoHtmlSpecialChars($myts->displayTarea($content)); + if (\is_object($xoTheme)) { + $xoTheme->addMeta('meta', 'description', \strip_tags($content)); + } else { // Compatibility for old Xoops versions + $xoopsTpl->assign('xoops_metaDescription', \strip_tags($content)); + } + } + + /** + * @param string $tableName + * @param string $columnName + * + * @return array|false + */ + public static function enumerate(string $tableName, string $columnName) + { + $table = $GLOBALS['xoopsDB']->prefix($tableName); + + // $result = $GLOBALS['xoopsDB']->query("SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS + // WHERE TABLE_NAME = '" . $table . "' AND COLUMN_NAME = '" . $columnName . "'") + // || exit ($GLOBALS['xoopsDB']->error()); + + $sql = 'SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = "' . $table . '" AND COLUMN_NAME = "' . $columnName . '"'; + $result = $GLOBALS['xoopsDB']->query($sql); + if (!$result) { + // trigger_error($GLOBALS['xoopsDB']->error()); + $logger = \XoopsLogger::getInstance(); + $logger->handleError(\E_USER_WARNING, $sql, __FILE__, __LINE__); + return false; + } + + $row = $GLOBALS['xoopsDB']->fetchBoth($result); + $enumList = \explode(',', \str_replace("'", '', \mb_substr($row['COLUMN_TYPE'], 5, - 6))); + return $enumList; + } + + + /** + * Clone a record in a dB + * + * @TODO need to exit more gracefully on error. Should throw/trigger error and then return false + * + * @param string $tableName name of dB table (without prefix) + * @param string $idField name of field (column) in dB table + * @param int $id item id to clone + * + * @return mixed + */ + public static function cloneRecord(string $tableName, string $idField, int $id) + { + $newId = false; + $table = $GLOBALS['xoopsDB']->prefix($tableName); + // copy content of the record you wish to clone + $sql = "SELECT * FROM $table WHERE $idField='" . (int)$id . "' "; + $tempTable = $GLOBALS['xoopsDB']->fetchArray($GLOBALS['xoopsDB']->query($sql), \MYSQLI_ASSOC); + if (!$tempTable) { + trigger_error($GLOBALS['xoopsDB']->error()); + } + // set the auto-incremented id's value to blank. + unset($tempTable[$idField]); + // insert cloned copy of the original record + $sql = "INSERT INTO $table (" . \implode(', ', \array_keys($tempTable)) . ") VALUES ('" . \implode("', '", \array_values($tempTable)) . "')"; + $result = $GLOBALS['xoopsDB']->queryF($sql); + if (!$result) { + trigger_error($GLOBALS['xoopsDB']->error()); + } + // Return the new id + return $GLOBALS['xoopsDB']->getInsertId(); + } + + /** + * truncateHtml can truncate a string up to a number of characters while preserving whole words and HTML tags + * www.gsdesign.ro/blog/cut-html-string-without-breaking-the-tags + * www.cakephp.org + * + * @TODO: Refactor to consider HTML5 & void (self-closing) elements + * @TODO: Consider using https://github.com/jlgrall/truncateHTML/blob/master/truncateHTML.php + * + * @param string $text String to truncate. + * @param int $length Length of returned string, including ellipsis. + * @param string $ending Ending to be appended to the trimmed string. + * @param bool $exact If false, $text will not be cut mid-word + * @param bool $considerHtml If true, HTML tags would be handled correctly + * + * @return string Trimmed string. + */ + public static function truncateHtml( + string $text, + ?int $length = 100, + ?string $ending = '...', + ?bool $exact = false, + ?bool $considerHtml = true + ): string { + $openTags = []; + if ($considerHtml) { + // if the plain text is shorter than the maximum length, return the whole text + if (\mb_strlen(\preg_replace('/<.*?' . '>/', '', $text)) <= $length) { + return $text; + } + // splits all html-tags to scanable lines + \preg_match_all('/(<.+?' . '>)?([^<>]*)/s', $text, $lines, \PREG_SET_ORDER); + $total_length = \mb_strlen($ending); + //$openTags = []; + $truncate = ''; + foreach ($lines as $line_matchings) { + // if there is any html-tag in this line, handle it and add it (uncounted) to the output + if (!empty($line_matchings[1])) { + // if it's an "empty element" with or without xhtml-conform closing slash + if (\preg_match('/^<(\s*.+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s.+?)?)>$/is', $line_matchings[1])) { + // do nothing + // if tag is a closing tag + } elseif (\preg_match('/^<\s*\/(\S+?)\s*>$/s', $line_matchings[1], $tag_matchings)) { + // delete tag from $openTags list + $pos = \array_search($tag_matchings[1], $openTags, true); + if (false !== $pos) { + unset($openTags[$pos]); + } + // if tag is an opening tag + } elseif (\preg_match('/^<\s*([^\s>!]+).*?' . '>$/s', $line_matchings[1], $tag_matchings)) { + // add tag to the beginning of $openTags list + \array_unshift($openTags, \mb_strtolower($tag_matchings[1])); + } + // add html-tag to $truncate'd text + $truncate .= $line_matchings[1]; + } + // calculate the length of the plain text part of the line; handle entities as one character + $content_length = \mb_strlen(\preg_replace('/&[0-9a-z]{2,8};|&#\d{1,7};|[0-9a-f]{1,6};/i', ' ', $line_matchings[2])); + if ($total_length + $content_length > $length) { + // the number of characters which are left + $left = $length - $total_length; + $entities_length = 0; + // search for html entities + if (\preg_match_all('/&[0-9a-z]{2,8};|&#\d{1,7};|[0-9a-f]{1,6};/i', $line_matchings[2], $entities, \PREG_OFFSET_CAPTURE)) { + // calculate the real length of all entities in the legal range + foreach ($entities[0] as $entity) { + if ($left >= $entity[1] + 1 - $entities_length) { + $left--; + $entities_length += \mb_strlen($entity[0]); + } else { + // no more characters left + break; + } + } + } + $truncate .= \mb_substr($line_matchings[2], 0, $left + $entities_length); + // maximum length is reached, so get off the loop + break; + } + $truncate .= $line_matchings[2]; + $total_length += $content_length; + + // if the maximum length is reached, get off the loop + if ($total_length >= $length) { + break; + } + } + } else { + if (\mb_strlen($text) <= $length) { + return $text; + } + $truncate = \mb_substr($text, 0, $length - \mb_strlen($ending)); + } + // if the words shouldn't be cut in the middle... + if (!$exact) { + // ...search the last occurance of a space... + $spacepos = \mb_strrpos($truncate, ' '); + if (isset($spacepos)) { + // ...and cut the text in this position + $truncate = \mb_substr($truncate, 0, $spacepos); + } + } + // add the defined ending to the text + $truncate .= $ending; + if ($considerHtml) { + // close all unclosed html-tags + foreach ($openTags as $tag) { + $truncate .= ''; + } + } + + return $truncate; + } + + /** + * Get correct text editor based on user rights + * + * @param \Xmf\Module\Helper $helper + * @param array|null $options + * + * @return \XoopsFormDhtmlTextArea|\XoopsFormEditor + */ + public static function getEditor(?\Xmf\Module\Helper $helper = null, ?array $options = null) + { + /** @var Helper $helper */ + if (null === $options) { + $options = []; + $options['name'] = 'Editor'; + $options['value'] = 'Editor'; + $options['rows'] = 10; + $options['cols'] = '100%'; + $options['width'] = '100%'; + $options['height'] = '400px'; + } + + if (null === $helper) { + $helper = Helper::getInstance(); + } + + $isAdmin = $helper->isUserAdmin(); + + if (\class_exists('XoopsFormEditor')) { + if ($isAdmin) { + $descEditor = new XoopsFormEditor(\ucfirst($options['name']), $helper->getConfig('editorAdmin'), $options, $nohtml = false, $onfailure = 'textarea'); + } else { + $descEditor = new XoopsFormEditor(\ucfirst($options['name']), $helper->getConfig('editorUser'), $options, $nohtml = false, $onfailure = 'textarea'); + } + } else { + $descEditor = new \XoopsFormDhtmlTextArea(\ucfirst($options['name']), $options['name'], $options['value'], '100%', '100%'); + } + + // $form->addElement($descEditor); + + return $descEditor; + } + + /** + * Check if column in dB table exists + * + * @param string $fieldname name of dB table field + * @param string $table name of dB table (including prefix) + * + * @return bool true if table exists + * @deprecated + */ + public static function fieldExists(string $fieldname, string $table): bool + { + $trace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 1); + \trigger_error(__METHOD__ . " is deprecated, use Xmf\Database\Tables instead - instantiated from {$trace[0]['file']} line {$trace[0]['line']},"); + + $result = $GLOBALS['xoopsDB']->queryF("SHOW COLUMNS FROM $table LIKE '$fieldname'"); + return ($GLOBALS['xoopsDB']->getRowsNum($result) > 0); + } + + + /** + * Function responsible for checking if a directory exists, we can also write in and create an index.html file + * + * @param string $folder The full path of the directory to check + */ + public static function prepareFolder(string $folder): void + { + try { + if (!@\mkdir($folder) && !\is_dir($folder)) { + throw new \RuntimeException(\sprintf('Unable to create the %s directory', $folder)); + } + file_put_contents($folder . '/index.html', ''); + } catch (\Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n", '
'; + } + } + + /** + * Check if dB table table exists + * + * @param string $tablename dB tablename with prefix + * @return bool true if table exists + */ + public static function tableExists(string $tablename): bool + { + $trace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 1); + \trigger_error(__FUNCTION__ . " is deprecated, called from {$trace[0]['file']} line {$trace[0]['line']}"); + $GLOBALS['xoopsLogger']->addDeprecated( + \basename(\dirname(__DIR__, 2)) . ' Module: ' . __FUNCTION__ . ' function is deprecated, please use Xmf\Database\Tables method(s) instead.' . " Called from {$trace[0]['file']}line {$trace[0]['line']}" + ); + $result = $GLOBALS['xoopsDB']->queryF("SHOW TABLES LIKE '$tablename'"); + + return $GLOBALS['xoopsDB']->getRowsNum($result) > 0 ; + } + + /** + * Add a field to a mysql table + * + * @param $field + * @param $table + * @return bool|\mysqli_result + */ + public static function addField($field, $table) + { + global $xoopsDB; + return $xoopsDB->queryF('ALTER TABLE ' . $table . " ADD $field;"); + } +} diff --git a/class/Common/TestdataButtons.php b/class/Common/TestdataButtons.php new file mode 100644 index 0000000..56b7202 --- /dev/null +++ b/class/Common/TestdataButtons.php @@ -0,0 +1,106 @@ + + * @copyright {@link https://xoops.org/ XOOPS Project} + * @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) + */ + +use Xmf\{ + Module\Admin, + Request, + Yaml +}; +use XoopsModules\Tdmdownloads\{ + Constants, + Helper +}; + +/** @var Helper $helper */ + +/** + * Class TestdataButtons + * + * Contains methods to create the Test buttons and change their visibility + */ +class TestdataButtons +{ + /** Button status constants */ + private const SHOW_BUTTONS = 1; + private const HIDE_BUTTONS = 0; + + /** + * Load the test button configuration + * + * @param \Xmf\Module\Admin $adminObject + * + * @return void + */ + public static function loadButtonConfig(Admin $adminObject): void + { + $moduleDirName = \basename(\dirname(__DIR__, 2)); + $moduleDirNameUpper = \mb_strtoupper($moduleDirName); + $helper = Helper::getInstance(); + $yamlFile = $helper->path('/config/admin.yml'); + $config = Yaml::readWrapped($yamlFile); // work with phpmyadmin YAML dumps + $displaySampleButton = $config['displaySampleButton']; + + if (self::SHOW_BUTTONS == $displaySampleButton) { + \xoops_loadLanguage('admin/modulesadmin', 'system'); + $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'LOAD_SAMPLEDATA'), $helper->url('testdata/index.php?op=load'), 'add'); + $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'SAVE_SAMPLEDATA'), $helper->url('testdata/index.php?op=save'), 'add'); + $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'CLEAR_SAMPLEDATA'), $helper->url('testdata/index.php?op=clear'), 'alert'); + // $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA'), $helper->url( 'testdata/index.php?op=exportschema'), 'add'); + $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'HIDE_SAMPLEDATA_BUTTONS'), '?op=hide_buttons', 'delete'); + } else { + $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'SHOW_SAMPLEDATA_BUTTONS'), '?op=show_buttons', 'add'); + // $displaySampleButton = $config['displaySampleButton']; + } + } + + /** + * Hide the test buttons + * + * @return void + */ + public static function hideButtons(): void + { + $helper = Helper::getInstance(); + $yamlFile = $helper->path('config/admin.yml'); + $app = []; + $app['displaySampleButton'] = self::HIDE_BUTTONS; + Yaml::save($app, $yamlFile); + $helper->redirect('admin/index.php', Constants::REDIRECT_DELAY_NONE, ''); + } + + /** + * Show the test buttons + * + * @return void + */ + public static function showButtons(): void + { + $helper = Helper::getInstance(); + $yamlFile = $helper->path('config/admin.yml'); + $app = []; + $app['displaySampleButton'] = self::SHOW_BUTTONS; + Yaml::save($app, $yamlFile); + $helper->redirect('admin/index.php', Constants::REDIRECT_DELAY_NONE, ''); + } +} diff --git a/class/Common/VersionChecks.php b/class/Common/VersionChecks.php index 08bdbdf..b333266 100644 --- a/class/Common/VersionChecks.php +++ b/class/Common/VersionChecks.php @@ -1,4 +1,4 @@ -getInfo('min_xoops'); //making sure it's a string } + $success = true; - if (version_compare($currentVer, $requiredVer, '<')) { + if (\version_compare($currentVer, $requiredVer, '<')) { $success = false; - $module->setErrors(sprintf(constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_XOOPS'), $requiredVer, $currentVer)); + + $module->setErrors(\sprintf(\constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_XOOPS'), $requiredVer, $currentVer)); } return $success; } /** - * * Verifies PHP version meets minimum requirements for this module * @static - * @param \XoopsModule|null $module * + * @param \XoopsModule|null $module * @return bool true if meets requirements, false if not */ - public static function checkVerPhp(\XoopsModule $module = null) + public static function checkVerPhp(?\XoopsModule $module = null) { - $moduleDirName = basename(dirname(dirname(__DIR__))); - $moduleDirNameUpper = mb_strtoupper($moduleDirName); + $moduleDirName = \basename(dirname(__DIR__, 2)); + + $moduleDirNameUpper = \mb_strtoupper($moduleDirName); + if (null === $module) { $module = \XoopsModule::getByDirname($moduleDirName); } - xoops_loadLanguage('admin', $moduleDirName); + + \xoops_loadLanguage('admin', $moduleDirName); + + \xoops_loadLanguage('common', $moduleDirName); + // check for minimum PHP version + $success = true; - $verNum = PHP_VERSION; - $reqVer =& $module->getInfo('min_php'); + $verNum = \PHP_VERSION; + + $reqVer = &$module->getInfo('min_php'); if (false !== $reqVer && '' !== $reqVer) { - if (version_compare($verNum, $reqVer, '<')) { - $module->setErrors(sprintf(constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_PHP'), $reqVer, $verNum)); + if (\version_compare($verNum, $reqVer, '<')) { + $module->setErrors(\sprintf(\constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_PHP'), $reqVer, $verNum)); + $success = false; } } @@ -85,8 +97,7 @@ public static function checkVerPhp(\XoopsModule $module = null) } /** - * - * compares current module version with latest GitHub release + * compares current module version with the latest GitHub release * @static * @param \Xmf\Module\Helper $helper * @param string|null $source @@ -94,56 +105,84 @@ public static function checkVerPhp(\XoopsModule $module = null) * * @return string|array info about the latest module version, if newer */ - - public static function checkVerModule($helper, $source = 'github', $default = 'master') + public static function checkVerModule(\Xmf\Module\Helper $helper, ?string $source = 'github', ?string $default = 'master'): ?array { - $moduleDirName = basename(dirname(dirname(__DIR__))); - $moduleDirNameUpper = mb_strtoupper($moduleDirName); - $update = ''; - $repository = 'XoopsModules25x/' . $moduleDirName; - //$repository = 'XoopsModules25x/publisher'; //for testing only + $moduleDirName = \basename(dirname(__DIR__, 2)); + + $moduleDirNameUpper = \mb_strtoupper($moduleDirName); + + $update = ''; + + $repository = 'XoopsModules25x/' . $moduleDirName; + + // $repository = 'XoopsModules25x/publisher'; //for testing only + $ret = ''; - $infoReleasesUrl = "https://api.github.com/repos/$repository/releases"; + + $infoReleasesUrl = "https://api.github.com/repos/$repository/releases"; + if ('github' === $source) { - if (function_exists('curl_init') && false !== ($curlHandle = curl_init())) { - curl_setopt($curlHandle, CURLOPT_URL, $infoReleasesUrl); - curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); - curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($curlHandle, CURLOPT_HTTPHEADER, array("User-Agent:Publisher\r\n")); - $curlReturn = curl_exec($curlHandle); - if (false === $curlReturn) { - trigger_error(curl_error($curlHandle)); - } else { - $file = json_decode($curlReturn, false); - $latestVersionLink = sprintf("https://github.com/$repository/archive/%s.zip", $file ? reset($file)->tag_name : $default); - $latestVersion = $file[0]->tag_name; - $prerelease = $file[0]->prerelease; - - if ('master' !== $latestVersionLink) { - $update = constant('CO_' . $moduleDirNameUpper . '_' . 'NEW_VERSION') . $latestVersion; - } - //"PHP-standardized" version - $latestVersion = mb_strtolower($latestVersion); - if (false !== mb_strpos($latestVersion, 'final')) { - $latestVersion = str_replace('_', '', mb_strtolower($latestVersion)); - $latestVersion = str_replace('final', '', mb_strtolower($latestVersion)); - } - - $moduleVersion = ($helper->getModule()->getInfo('version') . '_' . $helper->getModule()->getInfo('module_status')); - //"PHP-standardized" version - $moduleVersion = str_replace(' ', '', mb_strtolower($moduleVersion)); - //$moduleVersion = '1.0'; //for testing only - //$moduleDirName = 'publisher'; //for testing only - - if (!$prerelease && version_compare($moduleVersion, $latestVersion, '<')) { - $ret = []; - $ret[] = $update; - $ret[] = $latestVersionLink; - } - } - curl_close($curlHandle); - } + if (\function_exists('curl_init') && false !== ($curlHandle = \curl_init())) { + \curl_setopt($curlHandle, \CURLOPT_URL, $infoReleasesUrl); + + \curl_setopt($curlHandle, \CURLOPT_RETURNTRANSFER, true); + + \curl_setopt($curlHandle, \CURLOPT_SSL_VERIFYPEER, true); //TODO: how to avoid an error when 'Peer's Certificate issuer is not recognized' + + \curl_setopt($curlHandle, \CURLOPT_HTTPHEADER, ["User-Agent:Publisher\r\n"]); + + $curlReturn = \curl_exec($curlHandle); + + if (false === $curlReturn) { + \trigger_error(\curl_error($curlHandle)); + } elseif (false !== \mb_strpos($curlReturn, 'Not Found')) { + \trigger_error('Repository Not Found: ' . $infoReleasesUrl); + } else { + $file = \json_decode($curlReturn, false); + + $latestVersionLink = \sprintf("https://github.com/$repository/archive/%s.zip", $file ? \reset($file)->tag_name : $default); + + $latestVersion = $file[0]->tag_name; + + $prerelease = $file[0]->prerelease; + + if ('master' !== $latestVersionLink) { + $update = \constant('CO_' . $moduleDirNameUpper . '_' . 'NEW_VERSION') . $latestVersion; + } + + //"PHP-standardized" version + + $latestVersion = \mb_strtolower($latestVersion); + + if (false !== \mb_strpos($latestVersion, 'final')) { + $latestVersion = \str_replace('_', '', \mb_strtolower($latestVersion)); + + $latestVersion = \str_replace('final', '', \mb_strtolower($latestVersion)); + } + + $moduleVersion = $helper->getModule()->getInfo('version') . '_' . $helper->getModule()->getInfo('module_status'); + + //"PHP-standardized" version + + $moduleVersion = \str_replace(' ', '', \mb_strtolower($moduleVersion)); + + // $moduleVersion = '1.0'; //for testing only + + // $moduleDirName = 'publisher'; //for testing only + + if (!$prerelease && \version_compare($moduleVersion, $latestVersion, '<')) { + $ret = []; + + $ret[] = $update; + + $ret[] = $latestVersionLink; + } + } + + \curl_close($curlHandle); + } } + return $ret; } } diff --git a/class/Common/index.html b/class/Common/index.html deleted file mode 100644 index 74b6f45..0000000 --- a/class/Common/index.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/class/Common/index.php b/class/Common/index.php new file mode 100644 index 0000000..2ea9b7d --- /dev/null +++ b/class/Common/index.php @@ -0,0 +1,3 @@ +initVar('downlimit_id', XOBJ_DTYPE_INT, null, false, 11); - $this->initVar('downlimit_lid', XOBJ_DTYPE_INT, null, false, 11); - $this->initVar('downlimit_uid', XOBJ_DTYPE_INT, null, false, 11); - $this->initVar('downlimit_hostname', XOBJ_DTYPE_TXTBOX, null, false); - $this->initVar('downlimit_date', XOBJ_DTYPE_INT, null, false, 10); + + $this->initVar('downlimit_id', \XOBJ_DTYPE_INT, null, false, 11); + + $this->initVar('downlimit_lid', \XOBJ_DTYPE_INT, null, false, 11); + + $this->initVar('downlimit_uid', \XOBJ_DTYPE_INT, null, false, 11); + + $this->initVar('downlimit_hostname', \XOBJ_DTYPE_TXTBOX, null, false); + + $this->initVar('downlimit_date', \XOBJ_DTYPE_INT, null, false, 10); } } diff --git a/class/DownlimitHandler.php b/class/DownlimitHandler.php index d9fb807..017590e 100644 --- a/class/DownlimitHandler.php +++ b/class/DownlimitHandler.php @@ -1,4 +1,4 @@ -initVar('lid', XOBJ_DTYPE_INT, null, false, 11); - $this->initVar('cid', XOBJ_DTYPE_INT, null, false, 5); - $this->initVar('title', XOBJ_DTYPE_TXTBOX, null, false); - $this->initVar('url', XOBJ_DTYPE_TXTBOX, null, false); - $this->initVar('homepage', XOBJ_DTYPE_TXTBOX, null, false); - $this->initVar('version', XOBJ_DTYPE_TXTBOX, null, false); - $this->initVar('size', XOBJ_DTYPE_TXTBOX, null, false); - $this->initVar('platform', XOBJ_DTYPE_TXTBOX, null, false); - $this->initVar('description', XOBJ_DTYPE_TXTAREA, null, false); + $this->initVar('lid', \XOBJ_DTYPE_INT, null, false, 11); + + $this->initVar('cid', \XOBJ_DTYPE_INT, null, false, 5); + + $this->initVar('title', \XOBJ_DTYPE_TXTBOX, null, false); + + $this->initVar('url', \XOBJ_DTYPE_TXTBOX, null, false); + + $this->initVar('homepage', \XOBJ_DTYPE_TXTBOX, null, false); + + $this->initVar('version', \XOBJ_DTYPE_TXTBOX, null, false); + + $this->initVar('size', \XOBJ_DTYPE_TXTBOX, null, false); + + $this->initVar('platform', \XOBJ_DTYPE_TXTBOX, null, false); + + $this->initVar('description', \XOBJ_DTYPE_TXTAREA, null, false); + // Pour autoriser le html - $this->initVar('dohtml', XOBJ_DTYPE_INT, 1, false); - $this->initVar('logourl', XOBJ_DTYPE_TXTBOX, null, false); - $this->initVar('submitter', XOBJ_DTYPE_INT, null, false, 11); - $this->initVar('status', XOBJ_DTYPE_INT, null, false, 2); - $this->initVar('date', XOBJ_DTYPE_INT, null, false, 10); - $this->initVar('hits', XOBJ_DTYPE_INT, null, false, 10); - $this->initVar('rating', XOBJ_DTYPE_OTHER, null, false, 10); - $this->initVar('votes', XOBJ_DTYPE_INT, null, false, 11); - $this->initVar('comments', XOBJ_DTYPE_INT, null, false, 11); - $this->initVar('top', XOBJ_DTYPE_INT, null, false, 2); - $this->initVar('paypal', XOBJ_DTYPE_TXTBOX, null, false); + + $this->initVar('dohtml', \XOBJ_DTYPE_INT, 1, false); + + $this->initVar('logourl', \XOBJ_DTYPE_TXTBOX, null, false); + + $this->initVar('submitter', \XOBJ_DTYPE_INT, null, false, 11); + + $this->initVar('status', \XOBJ_DTYPE_INT, null, false, 2); + + $this->initVar('date', \XOBJ_DTYPE_INT, null, false, 10); + + $this->initVar('hits', \XOBJ_DTYPE_INT, null, false, 10); + + $this->initVar('rating', \XOBJ_DTYPE_OTHER, null, false, 10); + + $this->initVar('votes', \XOBJ_DTYPE_INT, null, false, 11); + + $this->initVar('comments', \XOBJ_DTYPE_INT, null, false, 11); + + $this->initVar('top', \XOBJ_DTYPE_INT, null, false, 2); + + $this->initVar('paypal', \XOBJ_DTYPE_TXTBOX, null, false); //pour les jointures: - $this->initVar('cat_title', XOBJ_DTYPE_TXTBOX, null, false); - $this->initVar('cat_imgurl', XOBJ_DTYPE_TXTBOX, null, false); + + $this->initVar('cat_title', \XOBJ_DTYPE_TXTBOX, null, false); + + $this->initVar('cat_imgurl', \XOBJ_DTYPE_TXTBOX, null, false); } /** @@ -63,7 +86,9 @@ public function __construct() public function getNewEnreg($db = null) { $newEnreg = 0; + /** @var \XoopsMySQLDatabase $db */ + if (null !== $db) { $newEnreg = $db->getInsertId(); } @@ -80,155 +105,232 @@ public function getNewEnreg($db = null) public function getForm($donnee = [], $erreur = false, $action = false) { global $xoopsModule, $xoopsUser; + /** @var \XoopsModules\Tdmdownloads\Helper $helper */ - $helper = \XoopsModules\Tdmdownloads\Helper::getInstance(); + + $helper = Helper::getInstance(); + /** @var \XoopsModules\Tdmdownloads\Utility $utility */ - $utility = new \XoopsModules\Tdmdownloads\Utility(); - $moduleDirName = basename(dirname(__DIR__)); - if (false === $action) { + + $utility = new \XoopsModules\Tdmdownloads\Utility(); + + $moduleDirName = \basename(\dirname(__DIR__)); + + if (!$action) { $action = $_SERVER['REQUEST_URI']; } + //permission pour uploader + /** @var \XoopsGroupPermHandler $grouppermHandler */ - $grouppermHandler = xoops_getHandler('groupperm'); - $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; + $grouppermHandler = \xoops_getHandler('groupperm'); + + $groups = \is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; + if ($xoopsUser) { $perm_upload = true; + if (!$xoopsUser->isAdmin($xoopsModule->mid())) { - $perm_upload = $grouppermHandler->checkRight('tdmdownloads_ac', 32, $groups, $xoopsModule->getVar('mid')) ? true : false; + $perm_upload = $grouppermHandler->checkRight('tdmdownloads_ac', 32, $groups, $xoopsModule->getVar('mid')); } } else { - $perm_upload = $grouppermHandler->checkRight('tdmdownloads_ac', 32, $groups, $xoopsModule->getVar('mid')) ? true : false; + $perm_upload = $grouppermHandler->checkRight('tdmdownloads_ac', 32, $groups, $xoopsModule->getVar('mid')); } + //nom du formulaire selon l'action (editer ou ajouter): - $title = $this->isNew() ? sprintf(_AM_TDMDOWNLOADS_FORMADD) : sprintf(_AM_TDMDOWNLOADS_FORMEDIT); + + $title = $this->isNew() ? \sprintf(_AM_TDMDOWNLOADS_FORMADD) : \sprintf(_AM_TDMDOWNLOADS_FORMEDIT); //création du formulaire + $form = new \XoopsThemeForm($title, 'form', $action, 'post', true); + $form->setExtra('enctype="multipart/form-data"'); + //titre + $form->addElement(new \XoopsFormText(_AM_TDMDOWNLOADS_FORMTITLE, 'title', 50, 255, $this->getVar('title')), true); + // fichier + $fichier = new \XoopsFormElementTray(_AM_TDMDOWNLOADS_FORMFILE, '

'); - $url = $this->isNew() ? 'http://' : $this->getVar('url'); + + $url = $this->isNew() ? 'http://' : $this->getVar('url'); + $formurl = new \XoopsFormText(_AM_TDMDOWNLOADS_FORMURL, 'url', 75, 255, $url); + $fichier->addElement($formurl, false); - if (true === $perm_upload) { + + if ($perm_upload) { $fichier->addElement(new \XoopsFormFile(_AM_TDMDOWNLOADS_FORMUPLOAD, 'attachedfile', $helper->getConfig('maxuploadsize')), false); } + $form->addElement($fichier); //catégorie + /** @var \XoopsModules\Tdmdownloads\CategoryHandler $categoryHandler */ - $categoryHandler = \XoopsModules\Tdmdownloads\Helper::getInstance()->getHandler('Category'); - $categories = $utility->getItemIds('tdmdownloads_submit', $moduleDirName); - $criteria = new \CriteriaCompo(); + + $categoryHandler = Helper::getInstance()->getHandler('Category'); + + $categories = $utility->getItemIds('tdmdownloads_submit', $moduleDirName); + + $criteria = new \CriteriaCompo(); + $criteria->setSort('cat_weight ASC, cat_title'); + $criteria->setOrder('ASC'); + if ($xoopsUser) { if (!$xoopsUser->isAdmin($xoopsModule->mid())) { - $criteria->add(new \Criteria('cat_cid', '(' . implode(',', $categories) . ')', 'IN')); + $criteria->add(new \Criteria('cat_cid', '(' . \implode(',', $categories) . ')', 'IN')); } } else { - $criteria->add(new \Criteria('cat_cid', '(' . implode(',', $categories) . ')', 'IN')); + $criteria->add(new \Criteria('cat_cid', '(' . \implode(',', $categories) . ')', 'IN')); } + $downloadscatArray = $categoryHandler->getAll($criteria); + if (empty($downloadscatArray)) { - redirect_header('index.php', 2, _NOPERM); + \redirect_header('index.php', 2, \_NOPERM); } + $mytree = new \XoopsModules\Tdmdownloads\Tree($downloadscatArray, 'cat_cid', 'cat_pid'); + $form->addElement($mytree->makeSelectElement('cid', 'cat_title', '--', $this->getVar('cid'), true, 0, '', _AM_TDMDOWNLOADS_FORMINCAT), true); //affichage des champs + /** @var \XoopsModules\Tdmdownloads\FieldHandler $fieldHandler */ - $fieldHandler = \XoopsModules\Tdmdownloads\Helper::getInstance()->getHandler('Field'); - $criteria = new \CriteriaCompo(); + + $fieldHandler = Helper::getInstance()->getHandler('Field'); + + $criteria = new \CriteriaCompo(); + $criteria->setSort('weight ASC, title'); + $criteria->setOrder('ASC'); + /** @var \XoopsModules\Tdmdownloads\Downloads[] $downloads_field */ + $downloads_field = $fieldHandler->getAll($criteria); - foreach (array_keys($downloads_field) as $i) { + + foreach (\array_keys($downloads_field) as $i) { /** @var \XoopsModules\Tdmdownloads\Field[] $downloads_field */ + if (1 == $downloads_field[$i]->getVar('status_def')) { if (1 == $downloads_field[$i]->getVar('fid')) { //page d'accueil + if (1 == $downloads_field[$i]->getVar('status')) { $form->addElement(new \XoopsFormText(_AM_TDMDOWNLOADS_FORMHOMEPAGE, 'homepage', 50, 255, $this->getVar('homepage'))); } else { $form->addElement(new \XoopsFormHidden('homepage', '')); } } + if (2 == $downloads_field[$i]->getVar('fid')) { //version + if (1 == $downloads_field[$i]->getVar('status')) { $form->addElement(new \XoopsFormText(_AM_TDMDOWNLOADS_FORMVERSION, 'version', 10, 255, $this->getVar('version'))); } else { $form->addElement(new \XoopsFormHidden('version', '')); } } + if (3 == $downloads_field[$i]->getVar('fid')) { //taille du fichier - if (1 == $downloads_field[$i]->getVar('status')) { - $size_value_arr = explode(' ', $this->getVar('size')); - $aff_size = new \XoopsFormElementTray(_AM_TDMDOWNLOADS_FORMSIZE, ''); - $aff_size->addElement(new \XoopsFormText('', 'sizeValue', 13, 13, $size_value_arr[0])); - if (array_key_exists (1, $size_value_arr) == false){ - $size_value_arr[1] = 'K'; - } - $type = new \XoopsFormSelect('', 'sizeType', $size_value_arr[1]); - $typeArray = [ - 'B' => _AM_TDMDOWNLOADS_BYTES, - 'K' => _AM_TDMDOWNLOADS_KBYTES, - 'M' => _AM_TDMDOWNLOADS_MBYTES, - 'G' => _AM_TDMDOWNLOADS_GBYTES, - 'T' => _AM_TDMDOWNLOADS_TBYTES - ]; - $type->addOptionArray($typeArray); - $aff_size->addElement($type); - $form->addElement($aff_size); + + if (1 == $downloads_field[$i]->getVar('status')) { + $size_value_arr = \explode(' ', $this->getVar('size')); + + $aff_size = new \XoopsFormElementTray(_AM_TDMDOWNLOADS_FORMSIZE_WHEN_SUBMIT, ''); + + $aff_size->addElement(new \XoopsFormText('', 'sizeValue', 13, 13, $size_value_arr[0])); + + if (!\array_key_exists(1, $size_value_arr)) { + $size_value_arr[1] = 'K'; + } + + $type = new \XoopsFormSelect('', 'sizeType', $size_value_arr[1]); + + $typeArray = [ + 'B' => _AM_TDMDOWNLOADS_BYTES, + 'K' => _AM_TDMDOWNLOADS_KBYTES, + 'M' => _AM_TDMDOWNLOADS_MBYTES, + 'G' => _AM_TDMDOWNLOADS_GBYTES, + 'T' => _AM_TDMDOWNLOADS_TBYTES, + ]; + + $type->addOptionArray($typeArray); + + $aff_size->addElement($type); + + $form->addElement($aff_size); } else { $form->addElement(new \XoopsFormHidden('size', '')); + $form->addElement(new \XoopsFormHidden('type_size', '')); } } + if (4 == $downloads_field[$i]->getVar('fid')) { //plateforme + if (1 == $downloads_field[$i]->getVar('status')) { - $platformselect = new \XoopsFormSelect(_AM_TDMDOWNLOADS_FORMPLATFORM, 'platform', explode('|', $this->getVar('platform')), 5, true); - $platformArray = explode('|', $helper->getConfig('platform')); + $platformselect = new \XoopsFormSelect(_AM_TDMDOWNLOADS_FORMPLATFORM, 'platform', \explode('|', $this->getVar('platform')), 5, true); + + $platformArray = \explode('|', $helper->getConfig('platform')); + foreach ($platformArray as $platform) { $platformselect->addOption((string)$platform, $platform); } + $form->addElement($platformselect, false); } else { $form->addElement(new \XoopsFormHidden('platform', '')); } } } else { - $contenu = ''; + $contenu = ''; + $contenu_iddata = ''; - $fieldName = 'champ' . $downloads_field[$i]->getVar('fid'); + + $fieldName = 'champ' . $downloads_field[$i]->getVar('fid'); + /** @var \XoopsModules\Tdmdownloads\FielddataHandler $fielddataHandler */ - $fielddataHandler = \XoopsModules\Tdmdownloads\Helper::getInstance()->getHandler('Fielddata'); - $criteria = new \CriteriaCompo(); + + $fielddataHandler = Helper::getInstance()->getHandler('Fielddata'); + + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('lid', $this->getVar('lid'))); + $criteria->add(new \Criteria('fid', $downloads_field[$i]->getVar('fid'))); + $downloadsfielddata = $fielddataHandler->getAll($criteria); - foreach (array_keys($downloadsfielddata) as $j) { + + foreach (\array_keys($downloadsfielddata) as $j) { /** @var \XoopsModules\Tdmdownloads\Fielddata[] $downloadsfielddata */ - if (true === $erreur) { + + if ($erreur) { $contenu = $donnee[$fieldName]; } else { if (!$this->isNew()) { $contenu = $downloadsfielddata[$j]->getVar('data'); } } + $contenu_iddata = $downloadsfielddata[$j]->getVar('iddata'); } + $iddata = 'iddata' . $downloads_field[$i]->getVar('fid'); + if (!$this->isNew()) { $form->addElement(new \XoopsFormHidden($iddata, $contenu_iddata)); } + if (1 == $downloads_field[$i]->getVar('status')) { $form->addElement(new \XoopsFormText($downloads_field[$i]->getVar('title'), $fieldName, 50, 255, $contenu)); } else { @@ -236,126 +338,196 @@ public function getForm($donnee = [], $erreur = false, $action = false) } } } + //description - $editorConfigs = []; - $editorConfigs['name'] = 'description'; - $editorConfigs['value'] = $this->getVar('description', 'e'); - $editorConfigs['rows'] = 20; - $editorConfigs['cols'] = 100; - $editorConfigs['width'] = '100%'; + + $editorConfigs = []; + + $editorConfigs['name'] = 'description'; + + $editorConfigs['value'] = $this->getVar('description', 'e'); + + $editorConfigs['rows'] = 20; + + $editorConfigs['cols'] = 100; + + $editorConfigs['width'] = '100%'; + $editorConfigs['height'] = '400px'; + $editorConfigs['editor'] = $helper->getConfig('editor'); + $form->addElement(new \XoopsFormEditor(_AM_TDMDOWNLOADS_FORMTEXTDOWNLOADS, 'description', $editorConfigs), true); + //tag - if ((1 == $helper->getConfig('usetag')) && class_exists(FormTag::class)) { + if (1 == $helper->getConfig('usetag') && \class_exists(FormTag::class)) { $tagId = $this->isNew() ? 0 : $this->getVar('lid'); - if (true === $erreur) { + + if ($erreur) { $tagId = $donnee['TAG']; } + $form->addElement(new \XoopsModules\Tag\FormTag('tag', 60, 255, $tagId, 0)); } //image + if ($helper->getConfig('useshots')) { - $uploaddir = XOOPS_ROOT_PATH . '/uploads/' . $moduleDirName . '/images/shots/' . $this->getVar('logourl'); + $uploaddir = XOOPS_ROOT_PATH . '/uploads/' . $moduleDirName . '/images/shots/' . $this->getVar('logourl'); + $categoryImage = $this->getVar('logourl') ?: 'blank.gif'; - if (!is_file($uploaddir)) { + + if (!\is_file($uploaddir)) { $categoryImage = 'blank.gif'; } + $uploadirectory = '/uploads/' . $moduleDirName . '/images/shots'; - $imgtray = new \XoopsFormElementTray(_AM_TDMDOWNLOADS_FORMIMG, '
'); - $imgpath = sprintf(_AM_TDMDOWNLOADS_FORMPATH, $uploadirectory); - $imageselect = new \XoopsFormSelect($imgpath, 'logo_img', $categoryImage); - $topics_array = \XoopsLists:: getImgListAsArray(XOOPS_ROOT_PATH . $uploadirectory); + + $imgtray = new \XoopsFormElementTray(_AM_TDMDOWNLOADS_FORMIMG, '
'); + + $imgpath = \sprintf(_AM_TDMDOWNLOADS_FORMPATH, $uploadirectory); + + $imageselect = new \XoopsFormSelect($imgpath, 'logo_img', $categoryImage); + + $topics_array = \XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH . $uploadirectory); + foreach ($topics_array as $image) { - $imageselect->addOption((string)$image, $image); + $imageselect->addOption($image, $image); } + $imageselect->setExtra("onchange='showImgSelected(\"image3\", \"logo_img\", \"" . $uploadirectory . '", "", "' . XOOPS_URL . "\")'"); + $imgtray->addElement($imageselect, false); + $imgtray->addElement(new \XoopsFormLabel('', "
")); + $fileseltray = new \XoopsFormElementTray('', '
'); - if (true === $perm_upload) { + + if ($perm_upload) { $fileseltray->addElement(new \XoopsFormFile(_AM_TDMDOWNLOADS_FORMUPLOAD, 'attachedimage', $helper->getConfig('maxuploadsize')), false); } + $imgtray->addElement($fileseltray); + $form->addElement($imgtray); } + // pour changer de poster et pour ne pas mettre à jour la date: if ($xoopsUser) { if ($xoopsUser->isAdmin($xoopsModule->mid())) { // auteur + if ($this->isNew()) { - $submitter = !empty($xoopsUser) ? $xoopsUser->getVar('uid') : 0; + $submitter = !empty($xoopsUser) ? $xoopsUser->getVar('uid') : 0; + $donnee['date_update'] = 0; } else { $submitter = $this->getVar('submitter'); - $v_date = $this->getVar('date'); + + $v_date = $this->getVar('date'); } - if (true === $erreur) { + + if ($erreur) { $date_update = $donnee['date_update']; - $v_status = $donnee['status']; - $submitter = $donnee['submitter']; + + $v_status = $donnee['status']; + + $submitter = $donnee['submitter']; } else { $date_update = 'N'; - $v_status = 1; + + $v_status = 1; } + $form->addElement(new \XoopsFormSelectUser(_AM_TDMDOWNLOADS_FORMSUBMITTER, 'submitter', true, $submitter, 1, false), true); // date + if (!$this->isNew()) { $selection_date = new \XoopsFormElementTray(_AM_TDMDOWNLOADS_FORMDATEUPDATE); - $date = new \XoopsFormRadio('', 'date_update', $date_update); - $options = [ - 'N' => _AM_TDMDOWNLOADS_FORMDATEUPDATE_NO . ' (' . formatTimestamp($v_date, 's') . ')', + + $date = new \XoopsFormRadio('', 'date_update', $date_update); + + $options = [ + 'N' => _AM_TDMDOWNLOADS_FORMDATEUPDATE_NO . ' (' . \formatTimestamp($v_date, 's') . ')', 'Y' => _AM_TDMDOWNLOADS_FORMDATEUPDATE_YES, ]; + $date->addOptionArray($options); + $selection_date->addElement($date); - $selection_date->addElement(new \XoopsFormTextDateSelect('', 'date', '', time())); + + $selection_date->addElement(new \XoopsFormTextDateSelect('', 'date', '', \time())); + $form->addElement($selection_date); } + $status = new \XoopsFormCheckBox(_AM_TDMDOWNLOADS_FORMSTATUS, 'status', $v_status); + $status->addOption(1, _AM_TDMDOWNLOADS_FORMSTATUS_OK); + $form->addElement($status); + //permissions pour télécharger + if (2 == $helper->getConfig('permission_download')) { /** @var \XoopsMemberHandler $memberHandler */ - $memberHandler = xoops_getHandler('member'); - $group_list = $memberHandler->getGroupList(); - $grouppermHandler = xoops_getHandler('groupperm'); - $full_list = array_keys($group_list); + $memberHandler = \xoops_getHandler('member'); + $group_list = $memberHandler->getGroupList(); + + /** @var \XoopsGroupPermHandler $grouppermHandler */ + $grouppermHandler = \xoops_getHandler('groupperm'); + + $full_list = \array_keys($group_list); + global $xoopsModule; + if (!$this->isNew()) { - $item_ids_download = $grouppermHandler->getGroupIds('tdmdownloads_download_item', $this->getVar('lid'), $xoopsModule->getVar('mid')); - $item_ids_downloa = array_values($item_ids_download); + $item_ids_download = $grouppermHandler->getGroupIds('tdmdownloads_download_item', $this->getVar('lid'), $xoopsModule->getVar('mid')); + + $item_ids_downloa = \array_values($item_ids_download); + $item_news_can_download_checkbox = new \XoopsFormCheckBox(_AM_TDMDOWNLOADS_FORMPERMDOWNLOAD, 'item_download[]', $item_ids_download); } else { $item_news_can_download_checkbox = new \XoopsFormCheckBox(_AM_TDMDOWNLOADS_FORMPERMDOWNLOAD, 'item_download[]', $full_list); } + $item_news_can_download_checkbox->addOptionArray($group_list); + $form->addElement($item_news_can_download_checkbox); } } } + //paypal + if (true === $helper->getConfig('use_paypal')) { $form->addElement(new \XoopsFormText(_AM_TDMDOWNLOADS_FORMPAYPAL, 'paypal', 50, 255, $this->getVar('paypal')), false); } else { $form->addElement(new \XoopsFormHidden('paypal', '')); } + // captcha + $form->addElement(new \XoopsFormCaptcha(), true); + // pour passer "lid" si on modifie la catégorie + if (!$this->isNew()) { $form->addElement(new \XoopsFormHidden('lid', $this->getVar('lid'))); + $form->addElement(new \XoopsFormHidden('downloads_modified', true)); } + //pour enregistrer le formulaire + $form->addElement(new \XoopsFormHidden('op', 'save_downloads')); + //bouton d'envoi du formulaire - $form->addElement(new \XoopsFormButtonTray('', _SUBMIT, 'submit', 'submit', false)); + + $form->addElement(new \XoopsFormButtonTray('', \_SUBMIT, 'submit', 'submit', false)); return $form; } diff --git a/class/DownloadsHandler.php b/class/DownloadsHandler.php index ec0385f..f0db020 100644 --- a/class/DownloadsHandler.php +++ b/class/DownloadsHandler.php @@ -1,4 +1,4 @@ -initVar('fid', XOBJ_DTYPE_INT, null, false, 11); - $this->initVar('title', XOBJ_DTYPE_TXTBOX, null, false); - $this->initVar('img', XOBJ_DTYPE_TXTBOX, null, false); - $this->initVar('weight', XOBJ_DTYPE_INT, null, false, 11); - $this->initVar('status', XOBJ_DTYPE_INT, null, false, 5); - $this->initVar('search', XOBJ_DTYPE_INT, null, false, 5); - $this->initVar('status_def', XOBJ_DTYPE_INT, null, false, 5); + $this->initVar('fid', \XOBJ_DTYPE_INT, null, false, 11); + + $this->initVar('title', \XOBJ_DTYPE_TXTBOX, null, false); + + $this->initVar('img', \XOBJ_DTYPE_TXTBOX, null, false); + + $this->initVar('weight', \XOBJ_DTYPE_INT, null, false, 11); + + $this->initVar('status', \XOBJ_DTYPE_INT, null, false, 5); + + $this->initVar('search', \XOBJ_DTYPE_INT, null, false, 5); + + $this->initVar('status_def', \XOBJ_DTYPE_INT, null, false, 5); //pour les jointures - $this->initVar('data', XOBJ_DTYPE_TXTAREA, null, false); + + $this->initVar('data', \XOBJ_DTYPE_TXTAREA, null, false); } /** @@ -46,7 +53,9 @@ public function __construct() public function getNewEnreg($db = null) { $newEnreg = 0; + /** @var \XoopsMySQLDatabase $db */ + if (null !== $db) { $newEnreg = $db->getInsertId(); } @@ -62,64 +71,104 @@ public function getNewEnreg($db = null) public function getForm($action = false) { /** @var \XoopsModules\Tdmdownloads\Helper $helper */ - $helper = \XoopsModules\Tdmdownloads\Helper::getInstance(); - $moduleDirName = basename(dirname(__DIR__)); - if (false === $action) { + $helper = Helper::getInstance(); + + $moduleDirName = \basename(\dirname(__DIR__)); + + if (!$action) { $action = $_SERVER['REQUEST_URI']; } + require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; //nom du formulaire selon l'action (editer ou ajouter): - $title = $this->isNew() ? sprintf(_AM_TDMDOWNLOADS_FORMADD) : sprintf(_AM_TDMDOWNLOADS_FORMEDIT); + + $title = $this->isNew() ? \sprintf(_AM_TDMDOWNLOADS_FORMADD) : \sprintf(_AM_TDMDOWNLOADS_FORMEDIT); //création du formulaire + $form = new \XoopsThemeForm($title, 'form', $action, 'post', true); + $form->setExtra('enctype="multipart/form-data"'); + //titre + if (1 == $this->getVar('status_def')) { $form->addElement(new \XoopsFormLabel(_AM_TDMDOWNLOADS_FORMTITLE, $this->getVar('title'))); + $form->addElement(new \XoopsFormHidden('title', $this->getVar('title'))); } else { $form->addElement(new \XoopsFormText(_AM_TDMDOWNLOADS_FORMTITLE, 'title', 50, 255, $this->getVar('title')), true); } + //image + $downloadsfield_img = $this->getVar('img') ?: 'blank.gif'; - $uploadirectory = '/uploads/' . $moduleDirName . '/images/field'; - $imgtray = new \XoopsFormElementTray(_AM_TDMDOWNLOADS_FORMIMAGE, '
'); - $imgpath = sprintf(_AM_TDMDOWNLOADS_FORMPATH, $uploadirectory); - $imageselect = new \XoopsFormSelect($imgpath, 'downloadsfield_img', $downloadsfield_img); - $topics_array = \XoopsLists:: getImgListAsArray(XOOPS_ROOT_PATH . $uploadirectory); + + $uploadirectory = '/uploads/' . $moduleDirName . '/images/field'; + + $imgtray = new \XoopsFormElementTray(_AM_TDMDOWNLOADS_FORMIMAGE, '
'); + + $imgpath = \sprintf(_AM_TDMDOWNLOADS_FORMPATH, $uploadirectory); + + $imageselect = new \XoopsFormSelect($imgpath, 'downloadsfield_img', $downloadsfield_img); + + $topics_array = \XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH . $uploadirectory); + foreach ($topics_array as $image) { - $imageselect->addOption((string)$image, $image); + $imageselect->addOption($image, $image); } + $imageselect->setExtra("onchange='showImgSelected(\"image3\", \"downloadsfield_img\", \"" . $uploadirectory . '", "", "' . XOOPS_URL . "\")'"); + $imgtray->addElement($imageselect, false); + $imgtray->addElement(new \XoopsFormLabel('', "

")); + $fileseltray = new \XoopsFormElementTray('', '
'); + $fileseltray->addElement(new \XoopsFormFile(_AM_TDMDOWNLOADS_FORMUPLOAD, 'attachedfile', $helper->getConfig('maxuploadsize')), false); + $fileseltray->addElement(new \XoopsFormLabel(''), false); + $imgtray->addElement($fileseltray); + $form->addElement($imgtray); + //poids du champ + $form->addElement(new \XoopsFormText(_AM_TDMDOWNLOADS_FORMWEIGHT, 'weight', 5, 5, $this->getVar('weight', 'e')), false); + // affiché? + $status = $this->getVar('status') ?: 0; + $form->addElement(new \XoopsFormRadioYN(_AM_TDMDOWNLOADS_FORMAFFICHE, 'status', $status)); + // affiché dans le champ de recherche? + $search = $this->getVar('search') ?: 0; + $form->addElement(new \XoopsFormRadioYN(_AM_TDMDOWNLOADS_FORMAFFICHESEARCH, 'search', $search)); + // pour passer "fid" si on modifie le champ + if (!$this->isNew()) { $form->addElement(new \XoopsFormHidden('fid', $this->getVar('fid'))); + $form->addElement(new \XoopsFormHidden('status_def', $this->getVar('status_def'))); } else { $form->addElement(new \XoopsFormHidden('status_def', 0)); } + //pour enregistrer le formulaire + $form->addElement(new \XoopsFormHidden('op', 'save_field')); + //boutton d'envoi du formulaire - $form->addElement(new \XoopsFormButtonTray('', _SUBMIT, 'submit', 'submit', false)); + + $form->addElement(new \XoopsFormButtonTray('', \_SUBMIT, 'submit', 'submit', false)); return $form; } diff --git a/class/FieldHandler.php b/class/FieldHandler.php index 36974dc..605302a 100644 --- a/class/FieldHandler.php +++ b/class/FieldHandler.php @@ -1,4 +1,4 @@ -initVar('iddata', XOBJ_DTYPE_INT, null, false, 11); - $this->initVar('fid', XOBJ_DTYPE_INT, null, false, 11); - $this->initVar('lid', XOBJ_DTYPE_INT, null, false, 11); - $this->initVar('data', XOBJ_DTYPE_TXTBOX, null, false); - $this->initVar('dohtml', XOBJ_DTYPE_INT, 1, false); + $this->initVar('iddata', \XOBJ_DTYPE_INT, null, false, 11); + + $this->initVar('fid', \XOBJ_DTYPE_INT, null, false, 11); + + $this->initVar('lid', \XOBJ_DTYPE_INT, null, false, 11); + + $this->initVar('data', \XOBJ_DTYPE_TXTBOX, null, false); + + $this->initVar('dohtml', \XOBJ_DTYPE_INT, 1, false); } } diff --git a/class/FielddataHandler.php b/class/FielddataHandler.php index d2649ef..65b1116 100644 --- a/class/FielddataHandler.php +++ b/class/FielddataHandler.php @@ -1,4 +1,4 @@ - + * @copyright {@link https://xoops.org/ XOOPS Project} + * @license GPL 2.0 or later + * @link https://xoops.org/ + * @since 1.0.0 + */ + +use Xmf\Request; +use XoopsModules\Tdmdownloads; + +require_once dirname(__DIR__, 2) . '/include/common.php'; + +//$moduleDirName = basename(dirname(dirname(__DIR__))); +//$helper = Tdmdownloads\Helper::getInstance(); +$permHelper = new \Xmf\Module\Helper\Permission(); + +\xoops_load('XoopsFormLoader'); + +/** + * Class FieldForm + */ +class UploadForm extends \XoopsThemeForm +{ + public $targetObject; + public $helper; + + /** + * Constructor + * + * @param \XoopsModules\Tdmdownloads\Category $target + */ + public function __construct($target) + { + $moduleDirName = \basename(dirname(__DIR__, 2)); + + $moduleDirNameUpper = \mb_strtoupper($moduleDirName); + + /** @var \XoopsModules\Tdmdownloads\Helper $this->helper */ + + $this->helper = $target->helper; + + $this->targetObject = $target; + + $title = $this->targetObject->isNew() ? \sprintf(\constant('CO_' . $moduleDirNameUpper . '_' . 'FIELD_ADD')) : \sprintf(\constant('CO_' . $moduleDirNameUpper . '_' . 'FIELD_EDIT')); + + parent::__construct('', 'form', \xoops_getenv('SCRIPT_NAME'), 'post', true); + + $this->setExtra('enctype="multipart/form-data"'); + + //include ID field, it's needed so the module knows if it is a new form or an edited form + + $hidden = new \XoopsFormHidden('fid', $this->targetObject->getVar('cat_cid')); + + $this->addElement($hidden); + + unset($hidden); + + $categoryHandler = new \XoopsModules\Tdmdownloads\CategoryHandler(); + + $start = Request::getInt('start', 0); + + $catPaginationLimit = $this->helper->getConfig('userpager') ?: 10; + + $criteria = new \CriteriaCompo(); + + $criteria->setOrder('DESC'); + + $criteria->setLimit($catPaginationLimit); + + $criteria->setStart($start); + + $catCount = $categoryHandler->getCount($criteria); + + $catArray = $categoryHandler->getAll($criteria); + + // Form Select Category + + $categoryIdSelect = new \XoopsFormSelect(\constant('CO_' . $moduleDirNameUpper . '_' . 'SELECT'), 'cat_title', $this->targetObject->getVar('cat_cid')); + + $categoryIdSelect->setExtra('onchange="submit()"'); + + // $categoryIdSelect->addOption(0, ' '); + + foreach (\array_keys($catArray) as $i) { + $catName = $catArray[$i]->getVar('cat_title'); + + $catPid = $catArray[$i]->getVar('cat_pid'); + + if ($catPid > 0) { + $categoryObj = $categoryHandler->get($catPid); + + if (\is_object($categoryObj)) { + $catName .= ' (' . $categoryObj->getVar('cat_title') . ')'; + } else { + $catName .= ' (' . \constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR_CATPID') . ')'; + } + } + + $categoryIdSelect->addOption($catArray[$i]->getVar('cat_cid'), $catName); + } + + $this->addElement($categoryIdSelect); + + unset($categoryCriteria); + + $this->addElement(new \XoopsFormHidden('start', 0)); + + $this->addElement(new \XoopsFormHidden('limit', 0)); + } +} diff --git a/class/Form/index.php b/class/Form/index.php new file mode 100644 index 0000000..2ea9b7d --- /dev/null +++ b/class/Form/index.php @@ -0,0 +1,3 @@ +debug = $debug; - $moduleDirName = basename(dirname(__DIR__)); + $this->debug = $debug; + + $moduleDirName = \basename(\dirname(__DIR__)); + parent::__construct($moduleDirName); } @@ -48,6 +49,7 @@ public function __construct($debug = false) public static function getInstance($debug = false) { static $instance; + if (null === $instance) { $instance = new static($debug); } @@ -72,12 +74,24 @@ public function getDirname() */ public function getHandler($name) { - $ret = false; - $db = \XoopsDatabaseFactory::getDatabaseConnection(); - $class = __NAMESPACE__ . '\\' . ucfirst($name) . 'Handler'; - $ret = new $class($db); + $ret = false; + + $class = __NAMESPACE__ . '\\' . \ucfirst($name) . 'Handler'; + + if (!\class_exists($class)) { + throw new \RuntimeException("Class '$class' not found"); + } + + /** @var \XoopsMySQLDatabase $db */ + + $db = \XoopsDatabaseFactory::getDatabaseConnection(); + + $helper = self::getInstance(); + + $ret = new $class($db, $helper); + + $this->addLog("Getting handler '{$name}'"); return $ret; } } - diff --git a/class/Modified.php b/class/Modified.php index 71a1b60..7d637a2 100644 --- a/class/Modified.php +++ b/class/Modified.php @@ -1,4 +1,4 @@ -initVar('requestid', XOBJ_DTYPE_INT, null, false, 11); - $this->initVar('lid', XOBJ_DTYPE_INT, null, false, 11); - $this->initVar('cid', XOBJ_DTYPE_INT, null, false, 5); - $this->initVar('title', XOBJ_DTYPE_TXTBOX, null, false); - $this->initVar('url', XOBJ_DTYPE_TXTBOX, null, false); - $this->initVar('homepage', XOBJ_DTYPE_TXTBOX, null, false); - $this->initVar('version', XOBJ_DTYPE_TXTBOX, null, false); - $this->initVar('size', XOBJ_DTYPE_TXTBOX, null, false); - $this->initVar('platform', XOBJ_DTYPE_TXTBOX, null, false); - $this->initVar('logourl', XOBJ_DTYPE_TXTBOX, null, false); - $this->initVar('description', XOBJ_DTYPE_TXTAREA, null, false); + $this->initVar('requestid', \XOBJ_DTYPE_INT, null, false, 11); + + $this->initVar('lid', \XOBJ_DTYPE_INT, null, false, 11); + + $this->initVar('cid', \XOBJ_DTYPE_INT, null, false, 5); + + $this->initVar('title', \XOBJ_DTYPE_TXTBOX, null, false); + + $this->initVar('url', \XOBJ_DTYPE_TXTBOX, null, false); + + $this->initVar('homepage', \XOBJ_DTYPE_TXTBOX, null, false); + + $this->initVar('version', \XOBJ_DTYPE_TXTBOX, null, false); + + $this->initVar('size', \XOBJ_DTYPE_TXTBOX, null, false); + + $this->initVar('platform', \XOBJ_DTYPE_TXTBOX, null, false); + + $this->initVar('logourl', \XOBJ_DTYPE_TXTBOX, null, false); + + $this->initVar('description', \XOBJ_DTYPE_TXTAREA, null, false); + // Pour autoriser le html - $this->initVar('dohtml', XOBJ_DTYPE_INT, 1, false); - $this->initVar('modifysubmitter', XOBJ_DTYPE_INT, null, false, 11); + + $this->initVar('dohtml', \XOBJ_DTYPE_INT, 1, false); + + $this->initVar('modifysubmitter', \XOBJ_DTYPE_INT, null, false, 11); } /** @@ -53,7 +65,9 @@ public function __construct() public function getNewEnreg($db = null) { $newEnreg = 0; + /** @var \XoopsMySQLDatabase $db */ + if (null !== $db) { $newEnreg = $db->getInsertId(); } @@ -71,141 +85,214 @@ public function getNewEnreg($db = null) public function getForm($lid, $erreur, $donnee = [], $action = false) { global $xoopsDB, $xoopsModule, $xoopsUser; + /** @var \XoopsModules\Tdmdownloads\Helper $helper */ - $helper = \XoopsModules\Tdmdownloads\Helper::getInstance(); - $moduleDirName = basename(dirname(__DIR__)); - if (false === $action) { + $helper = Helper::getInstance(); + + $moduleDirName = \basename(\dirname(__DIR__)); + + if (!$action) { $action = $_SERVER['REQUEST_URI']; } - $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; + + $groups = \is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; + /** @var \XoopsGroupPermHandler $grouppermHandler */ - $grouppermHandler = xoops_getHandler('groupperm'); - $perm_upload = $grouppermHandler->checkRight('tdmdownloads_ac', 32, $groups, $xoopsModule->getVar('mid')) ? true : false; + $grouppermHandler = \xoops_getHandler('groupperm'); + + $perm_upload = $grouppermHandler->checkRight('tdmdownloads_ac', 32, $groups, $xoopsModule->getVar('mid')); + //appel des class + /** @var \XoopsModules\Tdmdownloads\DownloadsHandler $downloadsHandler */ - $downloadsHandler = \XoopsModules\Tdmdownloads\Helper::getInstance()->getHandler('Downloads'); - // $categoryHandler = \XoopsModules\Tdmdownloads\Helper::getInstance()->getHandler('Category'); + + $downloadsHandler = Helper::getInstance()->getHandler('Downloads'); + + // $categoryHandler = Helper::getInstance()->getHandler('Category'); $viewDownloads = $downloadsHandler->get($lid); + require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; // affectation des variables + if (true === $erreur) { - $d_title = $donnee['title']; - $d_cid = $donnee['cid']; - $d_homepage = $donnee['homepage']; - $d_version = $donnee['version']; - $d_platform = $donnee['platform']; + $d_title = $donnee['title']; + + $d_cid = $donnee['cid']; + + $d_homepage = $donnee['homepage']; + + $d_version = $donnee['version']; + + $d_platform = $donnee['platform']; + $d_description = $donnee['description']; } else { - $d_title = $viewDownloads->getVar('title'); - $d_cid = $viewDownloads->getVar('cid'); - $d_homepage = $viewDownloads->getVar('homepage'); - $d_version = $viewDownloads->getVar('version'); - $d_platform = $viewDownloads->getVar('platform'); + $d_title = $viewDownloads->getVar('title'); + + $d_cid = $viewDownloads->getVar('cid'); + + $d_homepage = $viewDownloads->getVar('homepage'); + + $d_version = $viewDownloads->getVar('version'); + + $d_platform = $viewDownloads->getVar('platform'); + $d_description = $viewDownloads->getVar('description', 'e'); } //nom du formulaire - $title = sprintf(_AM_TDMDOWNLOADS_FORMEDIT); + + $title = \sprintf(_AM_TDMDOWNLOADS_FORMEDIT); //création du formulaire + $form = new \XoopsThemeForm($title, 'form', $action, 'post', true); + $form->setExtra('enctype="multipart/form-data"'); + //titre + $form->addElement(new \XoopsFormText(_AM_TDMDOWNLOADS_FORMTITLE, 'title', 50, 255, $d_title), true); + // fichier + $fichier = new \XoopsFormElementTray(_AM_TDMDOWNLOADS_FORMFILE, '

'); - $url = $viewDownloads->getVar('url'); + + $url = $viewDownloads->getVar('url'); + $formurl = new \XoopsFormText(_AM_TDMDOWNLOADS_FORMURL, 'url', 75, 255, $url); + $fichier->addElement($formurl, false); - if (true === $perm_upload) { + + if ($perm_upload) { $fichier->addElement(new \XoopsFormFile(_AM_TDMDOWNLOADS_FORMUPLOAD, 'attachedfile', $helper->getConfig('maxuploadsize')), false); } + $form->addElement($fichier); //catégorie + /** @var \XoopsModules\Tdmdownloads\CategoryHandler $categoryHandler */ - $categoryHandler = \XoopsModules\Tdmdownloads\Helper::getInstance()->getHandler('Category'); + + $categoryHandler = Helper::getInstance()->getHandler('Category'); + /** @var \XoopsModules\Tdmdownloads\Utility $utility */ - $utility = new \XoopsModules\Tdmdownloads\Utility(); + + $utility = new \XoopsModules\Tdmdownloads\Utility(); + $categories = $utility->getItemIds('tdmdownloads_submit', $moduleDirName); - $criteria = new \CriteriaCompo(); + + $criteria = new \CriteriaCompo(); + $criteria->setSort('cat_weight ASC, cat_title'); + $criteria->setOrder('ASC'); + if ($xoopsUser) { if (!$xoopsUser->isAdmin($xoopsModule->mid())) { - $criteria->add(new \Criteria('cat_cid', '(' . implode(',', $categories) . ')', 'IN')); + $criteria->add(new \Criteria('cat_cid', '(' . \implode(',', $categories) . ')', 'IN')); } } else { - $criteria->add(new \Criteria('cat_cid', '(' . implode(',', $categories) . ')', 'IN')); + $criteria->add(new \Criteria('cat_cid', '(' . \implode(',', $categories) . ')', 'IN')); } + $downloadscatArray = $categoryHandler->getAll($criteria); + if (empty($downloadscatArray)) { - redirect_header('index.php', 2, _NOPERM); + \redirect_header('index.php', 2, \_NOPERM); } + $mytree = new \XoopsModules\Tdmdownloads\Tree($downloadscatArray, 'cat_cid', 'cat_pid'); + $form->addElement($mytree->makeSelectElement('cid', 'cat_title', '--', $d_cid, true, 0, '', _AM_TDMDOWNLOADS_FORMINCAT), true); //affichage des champs - $fieldHandler = \XoopsModules\Tdmdownloads\Helper::getInstance()->getHandler('Field'); - $criteria = new \CriteriaCompo(); + + $fieldHandler = Helper::getInstance()->getHandler('Field'); + + $criteria = new \CriteriaCompo(); + $criteria->setSort('weight ASC, title'); + $criteria->setOrder('ASC'); + $downloads_field = $fieldHandler->getAll($criteria); - foreach (array_keys($downloads_field) as $i) { + + foreach (\array_keys($downloads_field) as $i) { /** @var \XoopsModules\Tdmdownloads\Field[] $downloads_field */ + if (1 == $downloads_field[$i]->getVar('status_def')) { if (1 == $downloads_field[$i]->getVar('fid')) { //page d'accueil + if (1 == $downloads_field[$i]->getVar('status')) { $form->addElement(new \XoopsFormText(_AM_TDMDOWNLOADS_FORMHOMEPAGE, 'homepage', 50, 255, $d_homepage)); } else { $form->addElement(new \XoopsFormHidden('homepage', '')); } } + if (2 == $downloads_field[$i]->getVar('fid')) { //version + if (1 == $downloads_field[$i]->getVar('status')) { $form->addElement(new \XoopsFormText(_AM_TDMDOWNLOADS_FORMVERSION, 'version', 10, 255, $d_version)); } else { $form->addElement(new \XoopsFormHidden('version', '')); } } + if (3 == $downloads_field[$i]->getVar('fid')) { //taille du fichier + if (1 == $downloads_field[$i]->getVar('status')) { - $size_value_arr = explode(' ', $viewDownloads->getVar('size')); - $aff_size = new \XoopsFormElementTray(_AM_TDMDOWNLOADS_FORMSIZE, ''); - $aff_size->addElement(new \XoopsFormText('', 'sizeValue', 13, 13, $size_value_arr[0])); - if (array_key_exists (1, $size_value_arr) == false){ - $size_value_arr[1] = 'K'; - } - $type = new \XoopsFormSelect('', 'sizeType', $size_value_arr[1]); - $typeArray = [ - 'B' => _AM_TDMDOWNLOADS_BYTES, - 'K' => _AM_TDMDOWNLOADS_KBYTES, - 'M' => _AM_TDMDOWNLOADS_MBYTES, - 'G' => _AM_TDMDOWNLOADS_GBYTES, - 'T' => _AM_TDMDOWNLOADS_TBYTES - ]; - $type->addOptionArray($typeArray); - $aff_size->addElement($type); - $form->addElement($aff_size); + $size_value_arr = \explode(' ', $viewDownloads->getVar('size')); + + $aff_size = new \XoopsFormElementTray(_AM_TDMDOWNLOADS_FORMSIZE_WHEN_SUBMIT, ''); + + $aff_size->addElement(new \XoopsFormText('', 'sizeValue', 13, 13, $size_value_arr[0])); + + if (!\array_key_exists(1, $size_value_arr)) { + $size_value_arr[1] = 'K'; + } + + $type = new \XoopsFormSelect('', 'sizeType', $size_value_arr[1]); + + $typeArray = [ + 'B' => _AM_TDMDOWNLOADS_BYTES, + 'K' => _AM_TDMDOWNLOADS_KBYTES, + 'M' => _AM_TDMDOWNLOADS_MBYTES, + 'G' => _AM_TDMDOWNLOADS_GBYTES, + 'T' => _AM_TDMDOWNLOADS_TBYTES, + ]; + + $type->addOptionArray($typeArray); + + $aff_size->addElement($type); + + $form->addElement($aff_size); } else { $form->addElement(new \XoopsFormHidden('size', '')); + $form->addElement(new \XoopsFormHidden('type_size', '')); } } + if (4 == $downloads_field[$i]->getVar('fid')) { //plateforme + if (1 == $downloads_field[$i]->getVar('status')) { - $platformselect = new \XoopsFormSelect(_AM_TDMDOWNLOADS_FORMPLATFORM, 'platform', explode('|', $d_platform), 5, true); - $platformArray = explode('|', $helper->getConfig('platform')); + $platformselect = new \XoopsFormSelect(_AM_TDMDOWNLOADS_FORMPLATFORM, 'platform', \explode('|', $d_platform), 5, true); + + $platformArray = \explode('|', $helper->getConfig('platform')); + foreach ($platformArray as $platform) { $platformselect->addOption((string)$platform, $platform); } + $form->addElement($platformselect, false); //$form->addElement(new \XoopsFormText(_AM_TDMDOWNLOADS_FORMPLATFORM, 'platform', 50, 255, $d_platform)); } else { @@ -213,21 +300,30 @@ public function getForm($lid, $erreur, $donnee = [], $action = false) } } } else { - $contenu = ''; - $fieldName = 'champ' . $downloads_field[$i]->getVar('fid'); - $fielddataHandler = \XoopsModules\Tdmdownloads\Helper::getInstance()->getHandler('Fielddata'); - $criteria = new \CriteriaCompo(); + $contenu = ''; + + $fieldName = 'champ' . $downloads_field[$i]->getVar('fid'); + + $fielddataHandler = Helper::getInstance()->getHandler('Fielddata'); + + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('lid', $viewDownloads->getVar('lid'))); + $criteria->add(new \Criteria('fid', $downloads_field[$i]->getVar('fid'))); + $downloadsfielddata = $fielddataHandler->getAll($criteria); - foreach (array_keys($downloadsfielddata) as $j) { + + foreach (\array_keys($downloadsfielddata) as $j) { /** @var \XoopsModules\Tdmdownloads\Fielddata[] $downloadsfielddata */ + if (true === $erreur) { $contenu = $donnee[$fieldName]; } else { $contenu = $downloadsfielddata[$j]->getVar('data'); } } + if (1 == $downloads_field[$i]->getVar('status')) { $form->addElement(new \XoopsFormText($downloads_field[$i]->getVar('title'), $fieldName, 50, 255, $contenu)); } else { @@ -235,47 +331,80 @@ public function getForm($lid, $erreur, $donnee = [], $action = false) } } } + //description - $editorConfigs = []; - $editorConfigs['name'] = 'description'; - $editorConfigs['value'] = $d_description; - $editorConfigs['rows'] = 20; - $editorConfigs['cols'] = 60; - $editorConfigs['width'] = '100%'; + + $editorConfigs = []; + + $editorConfigs['name'] = 'description'; + + $editorConfigs['value'] = $d_description; + + $editorConfigs['rows'] = 20; + + $editorConfigs['cols'] = 60; + + $editorConfigs['width'] = '100%'; + $editorConfigs['height'] = '400px'; + $editorConfigs['editor'] = $helper->getConfig('editor'); + $form->addElement(new \XoopsFormEditor(_AM_TDMDOWNLOADS_FORMTEXTDOWNLOADS, 'description', $editorConfigs), true); + //image + if ($helper->getConfig('useshots')) { - $uploaddir = XOOPS_ROOT_PATH . '/uploads/' . $moduleDirName . '/images/shots/' . $viewDownloads->getVar('logourl'); + $uploaddir = XOOPS_ROOT_PATH . '/uploads/' . $moduleDirName . '/images/shots/' . $viewDownloads->getVar('logourl'); + $categoryImage = $viewDownloads->getVar('logourl') ?: 'blank.gif'; - $uploadirectory = '/uploads/' . $moduleDirName . '/images/shots'; - if (!is_file($uploaddir)) { + + $uploadirectory = '/uploads/' . $moduleDirName . '/images/shots'; + + if (!\is_file($uploaddir)) { $categoryImage = 'blank.gif'; } - $imgtray = new \XoopsFormElementTray(_AM_TDMDOWNLOADS_FORMIMG, '
'); - $imgpath = sprintf(_AM_TDMDOWNLOADS_FORMPATH, $uploadirectory); - $imageselect = new \XoopsFormSelect($imgpath, 'logo_img', $categoryImage); - $topics_array = \XoopsLists:: getImgListAsArray(XOOPS_ROOT_PATH . $uploadirectory); + + $imgtray = new \XoopsFormElementTray(_AM_TDMDOWNLOADS_FORMIMG, '
'); + + $imgpath = \sprintf(_AM_TDMDOWNLOADS_FORMPATH, $uploadirectory); + + $imageselect = new \XoopsFormSelect($imgpath, 'logo_img', $categoryImage); + + $topics_array = \XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH . $uploadirectory); + foreach ($topics_array as $image) { - $imageselect->addOption((string)$image, $image); + $imageselect->addOption($image, $image); } + $imageselect->setExtra("onchange='showImgSelected(\"image3\", \"logo_img\", \"" . $uploadirectory . '", "", "' . XOOPS_URL . "\")'"); + $imgtray->addElement($imageselect, false); + $imgtray->addElement(new \XoopsFormLabel('', "
")); + $fileseltray = new \XoopsFormElementTray('', '
'); - if (true === $perm_upload) { + + if ($perm_upload) { $fileseltray->addElement(new \XoopsFormFile(_AM_TDMDOWNLOADS_FORMUPLOAD, 'attachedimage', $helper->getConfig('maxuploadsize')), false); } + $imgtray->addElement($fileseltray); + $form->addElement($imgtray); } + $form->addElement(new \XoopsFormCaptcha(), true); + $form->addElement(new \XoopsFormHidden('lid', $lid)); + //pour enregistrer le formulaire + $form->addElement(new \XoopsFormHidden('op', 'save')); + //bouton d'envoi du formulaire - $form->addElement(new \XoopsFormButtonTray('', _SUBMIT, 'submit', 'submit', false)); + + $form->addElement(new \XoopsFormButtonTray('', \_SUBMIT, 'submit', 'submit', false)); return $form; } diff --git a/class/ModifiedHandler.php b/class/ModifiedHandler.php index 4febb74..23b736d 100644 --- a/class/ModifiedHandler.php +++ b/class/ModifiedHandler.php @@ -1,4 +1,4 @@ -initVar('modiddata', XOBJ_DTYPE_INT, null, false, 11); - $this->initVar('fid', XOBJ_DTYPE_INT, null, false, 11); - $this->initVar('lid', XOBJ_DTYPE_INT, null, false, 11); - $this->initVar('moddata', XOBJ_DTYPE_TXTAREA, null, false); - $this->initVar('dohtml', XOBJ_DTYPE_INT, 1, false); + $this->initVar('modiddata', \XOBJ_DTYPE_INT, null, false, 11); + + $this->initVar('fid', \XOBJ_DTYPE_INT, null, false, 11); + + $this->initVar('lid', \XOBJ_DTYPE_INT, null, false, 11); + + $this->initVar('moddata', \XOBJ_DTYPE_TXTAREA, null, false); + + $this->initVar('dohtml', \XOBJ_DTYPE_INT, 1, false); } } diff --git a/class/ModifiedfielddataHandler.php b/class/ModifiedfielddataHandler.php index 8782885..18accf2 100644 --- a/class/ModifiedfielddataHandler.php +++ b/class/ModifiedfielddataHandler.php @@ -1,4 +1,4 @@ -initVar('ratingid', XOBJ_DTYPE_INT, null, false, 11); - $this->initVar('lid', XOBJ_DTYPE_INT, null, false, 11); - $this->initVar('ratinguser', XOBJ_DTYPE_INT, null, false, 11); - $this->initVar('rating', XOBJ_DTYPE_OTHER, null, false, 3); - $this->initVar('ratinghostname', XOBJ_DTYPE_TXTBOX, null, false); - $this->initVar('ratingtimestamp', XOBJ_DTYPE_INT, null, false, 10); + $this->initVar('ratingid', \XOBJ_DTYPE_INT, null, false, 11); + + $this->initVar('lid', \XOBJ_DTYPE_INT, null, false, 11); + + $this->initVar('ratinguser', \XOBJ_DTYPE_INT, null, false, 11); + + $this->initVar('rating', \XOBJ_DTYPE_OTHER, null, false, 3); + + $this->initVar('ratinghostname', \XOBJ_DTYPE_TXTBOX, null, false); + + $this->initVar('ratingtimestamp', \XOBJ_DTYPE_INT, null, false, 10); } /** @@ -44,17 +49,23 @@ public function __construct() public function getForm($lid, $action = false) { // global $xoopsDB, $xoopsModule, $xoopsModuleConfig; - if (false === $action) { + + if (!$action) { $action = $_SERVER['REQUEST_URI']; } + if (!$this->isNew()) { $rating = 11; } else { $rating = $this->getVar('rating'); } + $form = new \XoopsThemeForm(_MD_TDMDOWNLOADS_SINGLEFILE_RATHFILE, 'rateform', 'ratefile.php', 'post'); + $form->setExtra('enctype="multipart/form-data"'); - $rating = new \XoopsFormSelect(_MD_TDMDOWNLOADS_RATEFILE_VOTE, 'rating', $rating); + + $rating = new \XoopsFormSelect(_MD_TDMDOWNLOADS_RATEFILE_VOTE, 'rating', $rating); + $options = [ '11' => '--', '10' => '10', @@ -69,14 +80,23 @@ public function getForm($lid, $action = false) '1' => '1', '0' => '0', ]; + $rating->addOptionArray($options); + $form->addElement($rating, true); + $form->addElement(new \XoopsFormCaptcha(), true); + $form->addElement(new \XoopsFormHidden('op', 'save')); + $form->addElement(new \XoopsFormHidden('lid', $lid)); + // Submit button + $buttonTray = new \XoopsFormElementTray('', ''); + $buttonTray->addElement(new \XoopsFormButton('', 'post', _MD_TDMDOWNLOADS_RATEFILE_RATE, 'submit')); + $form->addElement($buttonTray); return $form; diff --git a/class/RatingHandler.php b/class/RatingHandler.php index 9eebd4f..8f8049b 100644 --- a/class/RatingHandler.php +++ b/class/RatingHandler.php @@ -1,4 +1,4 @@ -path('www/class/tree.php'); @@ -33,7 +33,7 @@ class Tree extends \XoopsObjectTree * @param $parentId * @param null $rootId */ - public function __construct(&$objectArr, $myId, $parentId, $rootId = null) + public function __construct($objectArr, $myId, $parentId, $rootId = null) { parent::__construct($objectArr, $myId, $parentId, $rootId); } @@ -48,10 +48,13 @@ public function __construct(&$objectArr, $myId, $parentId, $rootId = null) protected function makeArrayTreeOptions($fieldName, $key, &$ret, $prefix_orig, $prefix_curr = '') { if ($key > 0) { - $value = $this->tree[$key]['obj']->getVar($this->myId); + $value = $this->tree[$key]['obj']->getVar($this->myId); + $ret[$value] = $prefix_curr . $this->tree[$key]['obj']->getVar($fieldName); + $prefix_curr .= $prefix_orig; } + if (isset($this->tree[$key]['child']) && !empty($this->tree[$key]['child'])) { foreach ($this->tree[$key]['child'] as $childKey) { $this->makeArrayTreeOptions($fieldName, $childKey, $ret, $prefix_orig, $prefix_curr); @@ -69,13 +72,14 @@ protected function makeArrayTreeOptions($fieldName, $key, &$ret, $prefix_orig, $ public function makeArrayTree($fieldName, $prefix = '-', $key = 0) { $ret = []; + $this->makeArrayTreeOptions($fieldName, $key, $ret, $prefix); return $ret; } } /* xoops 2.5.8 -class Tree extends XoopsObjectTree { +class Tree extends \XoopsObjectTree { protected function makeArrayTreeOptions($fieldName, $key, &$ret, $prefix_orig, $prefix_curr = '') { @@ -92,7 +96,7 @@ protected function makeArrayTreeOptions($fieldName, $key, &$ret, $prefix_orig, $ } public function makeArrayTree($fieldName, $prefix = '-', $key = 0) { - $ret = array(); + $ret = []; $this->makeArrayTreeOptions($fieldName, $key, $ret, $prefix); return $ret; diff --git a/class/Utilities.php b/class/Utilities.php new file mode 100644 index 0000000..abf1dde --- /dev/null +++ b/class/Utilities.php @@ -0,0 +1,435 @@ +db = $db; + + // $this->helper = $helper; + + // } + + /** + * @param $permtype + * @param $dirname + * @return mixed + */ + public static function getItemIds($permtype, $dirname) + { + global $xoopsUser; + + $permissions = []; + + if (\is_array($permissions) && \array_key_exists($permtype, $permissions)) { + return $permissions[$permtype]; + } + + /** @var \XoopsModuleHandler $moduleHandler */ + $moduleHandler = \xoops_getHandler('module'); + + $tdmModule = $moduleHandler->getByDirname($dirname); + + $groups = \is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; + + /** @var \XoopsGroupPermHandler $grouppermHandler */ + $grouppermHandler = \xoops_getHandler('groupperm'); + + return $grouppermHandler->getItemIds($permtype, $groups, $tdmModule->getVar('mid')); + } + + /** + * returns the number of updates downloads in the categories of children category + * + * @param $mytree + * @param $categories + * @param $entries + * @param $cid + * + * @return int + */ + public static function getNumbersOfEntries($mytree, $categories, $entries, $cid) + { + $count = 0; + + $child_arr = []; + + if (\in_array($cid, $categories)) { + $child = $mytree->getAllChild($cid); + + foreach (\array_keys($entries) as $i) { + if ($entries[$i]->getVar('cid') === $cid) { + ++$count; + } + + foreach (\array_keys($child) as $j) { + if ($entries[$i]->getVar('cid') === $j) { + ++$count; + } + } + } + } + + return $count; + } + + /** + * returns an image "new" or "updated" + * @param $time + * @param $status + * @return string + */ + public static function getStatusImage($time, $status) + { + $moduleDirName = \basename(\dirname(__DIR__)); + + /** @var Tdmdownloads\Helper $helper */ + + $helper = Helper::getInstance(); + + $count = 7; + + $new = ''; + + $startdate = \time() - (86400 * $count); + + if (1 == $helper->getConfig('showupdated')) { + if ($startdate < $time) { + $language = $GLOBALS['xoopsConfig']['language']; + + if (!\is_dir(XOOPS_ROOT_PATH . "/modules/$moduleDirName/language/" . $language . '/')) { + $language = 'english'; + } + + $img_path = XOOPS_ROOT_PATH . "/modules/$moduleDirName/language/" . $language . '/'; + + $img_url = XOOPS_URL . "/modules/$moduleDirName/language/" . $language . '/'; + + if (1 == $status) { + if (\is_readable($img_path . 'new.png')) { + $new = ' ' . _MD_TDMDOWNLOADS_INDEX_NEWTHISWEEK . ''; + } else { + $new = ' ' . _MD_TDMDOWNLOADS_INDEX_NEWTHISWEEK . ''; + } + } elseif (2 == $status) { + if (\is_readable($img_path . 'updated.png')) { + $new = ' ' . _MD_TDMDOWNLOADS_INDEX_UPTHISWEEK . ''; + } else { + $new = ' ' . _MD_TDMDOWNLOADS_INDEX_UPTHISWEEK . ''; + } + } + } + } + + return $new; + } + + /** + * retourne une image "populaire" + * @param $hits + * @return string + */ + public static function getPopularImage($hits) + { + /** @var Tdmdownloads\Helper $helper */ + + $helper = Helper::getInstance(); + + $moduleDirName = \basename(\dirname(__DIR__)); + + $pop = ''; + + if ($hits >= $helper->getConfig('popular')) { + $language = $GLOBALS['xoopsConfig']['language']; + + if (!\is_dir(XOOPS_ROOT_PATH . "/modules/$moduleDirName/language/" . $language . '/')) { + $language = 'english'; + } + + $img_path = XOOPS_ROOT_PATH . "/modules/$moduleDirName/language/" . $language . '/'; + + $img_url = XOOPS_URL . "/modules/$moduleDirName/language/" . $language . '/'; + + if (\is_readable($img_path . 'popular.png')) { + $pop = ' ' . _MD_TDMDOWNLOADS_INDEX_POPULAR . ''; + } else { + $pop = ' ' . _MD_TDMDOWNLOADS_INDEX_POPULAR . ''; + } + } + + return $pop; + } + + /** + * @param mixed $global + * @param mixed $key + * @param mixed $default + * @param mixed $type + * + * @return string + */ + + // public static function convertFileSize($size) + + // { + + // if ($size > 0) { + + // $mb = 1024 * 1024; + + // if ($size > $mb) { + + // $mysize = sprintf("%01.2f", $size / $mb) . " MB"; + + // } elseif ($size >= 1024) { + + // $mysize = sprintf("%01.2f", $size / 1024) . " KB"; + + // } else { + + // $mysize = sprintf(_AM_TDMDOWNLOADS_NUMBYTES, $size); + + // } + + // return $mysize; + + // } else { + + // return ''; + + // } + + // } + + /** + * @param $global + * @param $key + * @param string $default + * @param string $type + * + * @return mixed|string + */ + public static function cleanVars($global, $key, $default = '', $type = 'int') + { + switch ($type) { + case 'string': + if (\defined('FILTER_SANITIZE_ADD_SLASHES')) { + $ret = isset($global[$key]) ? \filter_var($global[$key]) : $default; + } else { + $ret = isset($global[$key]) ? \filter_var($global[$key]) : $default; + } + break; + case 'int': + default: + $ret = isset($global[$key]) ? \filter_var($global[$key], \FILTER_SANITIZE_NUMBER_INT) : $default; + break; + } + + if (false === $ret) { + return $default; + } + + return $ret; + } + + /** + * @param $mytree + * @param $key + * @param $category_array + * @param $title + * @param string $prefix + * + * @return string + */ + public static function getPathTree($mytree, $key, $category_array, $title, $prefix = '') + { + $category_parent = $mytree->getAllParent($key); + + $category_parent = \array_reverse($category_parent); + + $Path = ''; + + foreach (\array_keys($category_parent) as $j) { + $Path .= $category_parent[$j]->getVar($title) . $prefix; + } + + $first_category = ''; + + if (\array_key_exists($key, $category_array)) { + $first_category = $category_array[$key]->getVar($title); + } + + $Path .= $first_category; + + return $Path; + } + + /** + * @param $mytree + * @param $key + * @param $category_array + * @param $title + * @param string $prefix + * @param bool $link + * @param string $order + * @param bool $lasturl + * + * @return string + */ + public static function getPathTreeUrl( + $mytree, + $key, + $category_array, + $title, + $prefix = '', + $link = false, + $order = 'ASC', + $lasturl = false + ) { + global $xoopsModule; + + $category_parent = $mytree->getAllParent($key); + + if ('ASC' === $order) { + $category_parent = \array_reverse($category_parent); + + if ($link) { + $Path = '' . $xoopsModule->name() . '' . $prefix; + } else { + $Path = $xoopsModule->name() . $prefix; + } + } else { + $first_category = ''; + + if (\array_key_exists($key, $category_array)) { + $first_category = $category_array[$key]->getVar($title); + } + + $Path = $first_category . $prefix; + } + + foreach (\array_keys($category_parent) as $j) { + if ($link) { + $Path .= '' . $category_parent[$j]->getVar($title) . '' . $prefix; + } else { + $Path .= $category_parent[$j]->getVar($title) . $prefix; + } + } + + if ('ASC' === $order) { + if (\array_key_exists($key, $category_array)) { + if ($lasturl) { + $first_category = '' . $category_array[$key]->getVar($title) . ''; + } else { + $first_category = $category_array[$key]->getVar($title); + } + } else { + $first_category = ''; + } + + $Path .= $first_category; + } else { + if ($link) { + $Path .= '' . $xoopsModule->name() . ''; + } else { + $Path .= $xoopsModule->name(); + } + } + + return $Path; + } + + /** + * @param $path + * @param int $mode + * @param $fileSource + * @param null $fileTarget + * @throws \RuntimeException + */ + public static function createFolder($path, $mode, $fileSource, $fileTarget = null) + { + if (!@\mkdir($path, $mode) && !\is_dir($path)) { + throw new \RuntimeException(\sprintf('Unable to create the %s directory', $path)); + } + + file_put_contents($path . '/index.html', ''); + + if (!empty($fileSource) && !empty($fileTarget)) { + @\copy($fileSource, $fileTarget); + } + + \chmod($path, $mode); + } + + /** + * @param $pathSource + * @param $pathTarget + * @throws \RuntimeException + */ + public static function cloneFolder($pathSource, $pathTarget) + { + if (\is_dir($pathSource)) { + // Create new dir + + if (!\mkdir($pathTarget) && !\is_dir($pathTarget)) { + throw new \RuntimeException(\sprintf('Unable to create the %s directory', $pathTarget)); + } + + // check all files in dir, and process it + + $handle = \opendir($pathSource); + + if ($handle) { + while ($file = \readdir($handle)) { + if ('.' !== $file && '..' !== $file) { + self::cloneFolder("$pathSource/$file", "$pathTarget/$file"); + } + } + + \closedir($handle); + } + } else { + \copy($pathSource, $pathTarget); + } + } + + /** + * Function responsible for checking if a directory exists, we can also write in and create an index.html file + * + * @param string $folder Le chemin complet du répertoire à vérifier + * + * @throws \RuntimeException + */ + public static function prepareFolder($folder) + { + if (!@\mkdir($folder) && !\is_dir($folder)) { + throw new \RuntimeException(\sprintf('Unable to create the %s directory', $folder)); + } + + file_put_contents($folder . '/index.html', ''); + } +} diff --git a/class/Utility.php b/class/Utility.php index 6a31e90..7b70392 100644 --- a/class/Utility.php +++ b/class/Utility.php @@ -1,4 +1,4 @@ -getByDirname($dirname); - $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; + + $moduleHandler = \xoops_getHandler('module'); + + $tdmModule = $moduleHandler->getByDirname($dirname); + + $groups = \is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; /** @var \XoopsGroupPermHandler $grouppermHandler */ - $grouppermHandler = xoops_getHandler('groupperm'); - $categories = $grouppermHandler->getItemIds($permtype, $groups, $tdmModule->getVar('mid')); + $grouppermHandler = \xoops_getHandler('groupperm'); - return $categories; + return $grouppermHandler->getItemIds($permtype, $groups, $tdmModule->getVar('mid')); } /** @@ -62,16 +60,21 @@ public function getItemIds($permtype, $dirname) */ public function getNumbersOfEntries($mytree, $categories, $entries, $cid) { - $count = 0; + $count = 0; + $child_arr = []; - if (in_array($cid, $categories, true)) { + + if (\in_array($cid, $categories)) { $child = $mytree->getAllChild($cid); - foreach (array_keys($entries) as $i) { + + foreach (\array_keys($entries) as $i) { /** @var \XoopsModules\Tdmdownloads\Downloads[] $entries */ + if ($entries[$i]->getVar('cid') == $cid) { $count++; } - foreach (array_keys($child) as $j) { + + foreach (\array_keys($child) as $j) { if ($entries[$i]->getVar('cid') == $j) { $count++; } @@ -91,28 +94,39 @@ public function getNumbersOfEntries($mytree, $categories, $entries, $cid) public function getStatusImage($time, $status) { global $xoopsModuleConfig; - $count = 7; - $new = ''; - $startdate = (time() - (86400 * $count)); + + $moduleDirName = basename(dirname(__DIR__)); + $helper = Helper::getInstance(); + + $count = 7; + + $new = ''; + + $startdate = \time() - (86400 * $count); + if (1 == $xoopsModuleConfig['showupdated']) { if ($startdate < $time) { $language = $GLOBALS['xoopsConfig']['language']; - if (!is_dir(XOOPS_ROOT_PATH . '/modules/tdmdownloads/language/' . $language . '/')) { + + if (!\is_dir(XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/language/' . $language . '/')) { $language = 'english'; } - $img_path = XOOPS_ROOT_PATH . '/modules/tdmdownloads/language/' . $language . '/'; - $img_url = XOOPS_URL . '/modules/tdmdownloads/language/' . $language . '/'; + + $img_path = XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/language/' . $language . '/'; + + $img_url = XOOPS_URL . '/modules/' . $moduleDirName . '/language/' . $language . '/'; + if (1 == $status) { - if (is_readable($img_path . 'new.png')) { + if (\is_readable($img_path . 'new.png')) { $new = ' ' . _MD_TDMDOWNLOADS_INDEX_NEWTHISWEEK . ''; } else { - $new = ' ' . _MD_TDMDOWNLOADS_INDEX_NEWTHISWEEK . ''; + $new = ' ' . _MD_TDMDOWNLOADS_INDEX_NEWTHISWEEK . ''; } } elseif (2 == $status) { - if (is_readable($img_path . 'updated.png')) { + if (\is_readable($img_path . 'updated.png')) { $new = ' ' . _MD_TDMDOWNLOADS_INDEX_UPTHISWEEK . ''; } else { - $new = ' ' . _MD_TDMDOWNLOADS_INDEX_UPTHISWEEK . ''; + $new = ' ' . _MD_TDMDOWNLOADS_INDEX_UPTHISWEEK . ''; } } } @@ -129,24 +143,80 @@ public function getStatusImage($time, $status) public function getPopularImage($hits) { global $xoopsModuleConfig; + $moduleDirName = basename(dirname(__DIR__)); + $pop = ''; + if ($hits >= $xoopsModuleConfig['popular']) { $language = $GLOBALS['xoopsConfig']['language']; - if (!is_dir(XOOPS_ROOT_PATH . '/modules/tdmdownloads/language/' . $language . '/')) { + + if (!\is_dir(XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/language/' . $language . '/')) { $language = 'english'; } - $img_path = XOOPS_ROOT_PATH . '/modules/tdmdownloads/language/' . $language . '/'; - $img_url = XOOPS_URL . '/modules/tdmdownloads/language/' . $language . '/'; - if (is_readable($img_path . 'popular.png')) { + + $img_path = XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/language/' . $language . '/'; + + $img_url = XOOPS_URL . '/modules/' . $moduleDirName . '/language/' . $language . '/'; + + if (\is_readable($img_path . 'popular.png')) { $pop = ' ' . _MD_TDMDOWNLOADS_INDEX_POPULAR . ''; } else { - $pop = ' ' . _MD_TDMDOWNLOADS_INDEX_POPULAR . ''; + $pop = ' ' . _MD_TDMDOWNLOADS_INDEX_POPULAR . ''; } } return $pop; } + /** + * @param int $size + * @return string + */ + public static function prettifyBytes($size) + { + if ($size > 0) { + $mb = 1024 * 1024; + + if ($size > $mb) { + $mysize = \sprintf('%01.2f', $size / $mb) . ' MB'; + } elseif ($size >= 1024) { + $mysize = \sprintf('%01.2f', $size / 1024) . ' KB'; + } else { + $mysize = \sprintf(_AM_TDMDOWNLOADS_NUMBYTES, $size); + } + + return $mysize; + } + + return ''; + } + + /** + * @param $global + * @param $key + * @param string $default + * @param string $type + * @return mixed|string + */ + public static function cleanVars($global, $key, $default = '', $type = 'int') + { + switch ($type) { + case 'string': + $ret = isset($global[$key]) ? \filter_var($global[$key], \FILTER_SANITIZE_MAGIC_QUOTES) : $default; + break; + case 'int': + default: + $ret = isset($global[$key]) ? \filter_var($global[$key], \FILTER_SANITIZE_NUMBER_INT) : $default; + break; + } + + if (false === $ret) { + return $default; + } + + return $ret; + } + /** * @param $mytree * @param $key @@ -155,21 +225,30 @@ public function getPopularImage($hits) * @param string $prefix * @return string */ - public function getPathTree($mytree, $key, $category_array, $title, $prefix = '') + public static function getPathTree($mytree, $key, $category_array, $title, $prefix = '') { + /** @var \XoopsObjectTree $mytree */ + $categoryParent = $mytree->getAllParent($key); - $categoryParent = array_reverse($categoryParent); - $path = ''; - foreach (array_keys($categoryParent) as $j) { + + $categoryParent = \array_reverse($categoryParent); + + $path = ''; + + foreach (\array_keys($categoryParent) as $j) { /** @var \XoopsModules\Tdmdownloads\Category[] $categoryParent */ + $path .= $categoryParent[$j]->getVar($title) . $prefix; } - if (array_key_exists($key, $category_array)) { + + if (\array_key_exists($key, $category_array)) { /** @var \XoopsModules\Tdmdownloads\Category[] $category_array */ + $firstCategory = $category_array[$key]->getVar($title); } else { $firstCategory = ''; } + $path .= $firstCategory; return $path; @@ -186,37 +265,45 @@ public function getPathTree($mytree, $key, $category_array, $title, $prefix = '' * @param bool $lasturl * @return string */ - public function getPathTreeUrl($mytree, $key, $category_array, $title, $prefix = '', $link = false, $order = 'ASC', $lasturl = false) + public static function getPathTreeUrl($mytree, $key, $category_array, $title, $prefix = '', $link = false, $order = 'ASC', $lasturl = false) { global $xoopsModule; + $categoryParent = $mytree->getAllParent($key); + if ('ASC' === $order) { - $categoryParent = array_reverse($categoryParent); - if (true === $link) { + $categoryParent = \array_reverse($categoryParent); + + if ($link) { $path = '' . $xoopsModule->name() . '' . $prefix; } else { $path = $xoopsModule->name() . $prefix; } } else { - if (array_key_exists($key, $category_array)) { + if (\array_key_exists($key, $category_array)) { /** @var \XoopsModules\Tdmdownloads\Category[] $category_array */ + $firstCategory = $category_array[$key]->getVar($title); } else { $firstCategory = ''; } + $path = $firstCategory . $prefix; } - foreach (array_keys($categoryParent) as $j) { + + foreach (\array_keys($categoryParent) as $j) { /** @var \XoopsModules\Tdmdownloads\Category[] $categoryParent */ - if (true === $link) { + + if ($link) { $path .= '' . $categoryParent[$j]->getVar($title) . '' . $prefix; } else { $path .= $categoryParent[$j]->getVar($title) . $prefix; } } + if ('ASC' === $order) { - if (array_key_exists($key, $category_array)) { - if (true === $lasturl) { + if (\array_key_exists($key, $category_array)) { + if ($lasturl) { $firstCategory = '' . $category_array[$key]->getVar($title) . ''; } else { $firstCategory = $category_array[$key]->getVar($title); @@ -224,9 +311,10 @@ public function getPathTreeUrl($mytree, $key, $category_array, $title, $prefix = } else { $firstCategory = ''; } + $path .= $firstCategory; } else { - if (true === $link) { + if ($link) { $path .= '' . $xoopsModule->name() . ''; } else { $path .= $xoopsModule->name(); @@ -235,129 +323,171 @@ public function getPathTreeUrl($mytree, $key, $category_array, $title, $prefix = return $path; } - /** - * Utility::StringSizeConvert() + + /** + * Utility::convertStringToSize() * * @param mixed $stringSize * @return mixed|int */ - public static function StringSizeConvert($stringSize){ - if ($stringSize != '') { + public static function convertStringToSize($stringSize) + { + if ('' != $stringSize) { $kb = 1024; - $mb = 1024*1024; - $gb = 1024*1024*1024; - $size_value_arr = explode(' ', $stringSize); - - if ($size_value_arr[1] == 'B') { + + $mb = 1024 * 1024; + + $gb = 1024 * 1024 * 1024; + + $size_value_arr = \explode(' ', $stringSize); + + if ('B' == $size_value_arr[1]) { $mysize = $size_value_arr[0]; - } elseif ($size_value_arr[1] == 'K') { + } elseif ('K' == $size_value_arr[1]) { $mysize = $size_value_arr[0] * $kb; - } elseif ($size_value_arr[1] == 'M') { + } elseif ('M' == $size_value_arr[1]) { $mysize = $size_value_arr[0] * $mb; } else { $mysize = $size_value_arr[0] * $gb; } + return $mysize; - } else { - return 0; } + + return 0; } - /** - * Utility::SizeConvertString() + + /** + * Utility::convertSizeToString() * * @param mixed $sizeString * @return mixed|string */ - public static function SizeConvertString($sizeString){ - $mysizeString = ''; - if ($sizeString != '') { - $size_value_arr = explode(' ', $sizeString); - if (array_key_exists (0, $size_value_arr) == true && array_key_exists (1, $size_value_arr) == true){ - if ($size_value_arr[0] != ''){ - $mysizeString = ''; - switch ($size_value_arr[1]) { - case 'B': - $mysizeString = $size_value_arr[0] . ' ' . _AM_TDMDOWNLOADS_BYTES; - break; - - case 'K': - $mysizeString = $size_value_arr[0] . ' ' . _AM_TDMDOWNLOADS_KBYTES; - break; - - case 'M': - $mysizeString = $size_value_arr[0] . ' ' . _AM_TDMDOWNLOADS_MBYTES; - break; - - case 'G': - $mysizeString = $size_value_arr[0] . ' ' . _AM_TDMDOWNLOADS_GBYTES; - break; - - case 'T': - $mysizeString = $size_value_arr[0] . ' ' . _AM_TDMDOWNLOADS_TBYTES; - break; - } - return $mysizeString; - } - } - } - return $mysizeString; + public static function convertSizeToString($sizeString) + { + $mysizeString = ''; + + if ('' != $sizeString) { + $size_value_arr = \explode(' ', $sizeString); + + if (\array_key_exists(0, $size_value_arr) && \array_key_exists(1, $size_value_arr)) { + if ('' != $size_value_arr[0]) { + $mysizeString = ''; + + switch ($size_value_arr[1]) { + case 'B': + $mysizeString = $size_value_arr[0] . ' ' . _AM_TDMDOWNLOADS_BYTES; + break; + case 'K': + $mysizeString = $size_value_arr[0] . ' ' . _AM_TDMDOWNLOADS_KBYTES; + break; + case 'M': + $mysizeString = $size_value_arr[0] . ' ' . _AM_TDMDOWNLOADS_MBYTES; + break; + case 'G': + $mysizeString = $size_value_arr[0] . ' ' . _AM_TDMDOWNLOADS_GBYTES; + break; + case 'T': + $mysizeString = $size_value_arr[0] . ' ' . _AM_TDMDOWNLOADS_TBYTES; + break; + } + + return $mysizeString; + } + } + } + + return $mysizeString; } - - /** - * Utility::GetFileSize() + + /** + * Utility::getFileSize() * * @param mixed $url * @return mixed|string */ - public static function GetFileSize($url) + public static function getFileSize($url) { - if (function_exists('curl_init') && false !== ($curlHandle = curl_init($url))) { - curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, TRUE); - curl_setopt($curlHandle, CURLOPT_HEADER, TRUE); - curl_setopt($curlHandle, CURLOPT_NOBODY, TRUE); - curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, false); - $curlReturn = curl_exec($curlHandle); - if (false === $curlReturn) { - trigger_error(curl_error($curlHandle)); - $size = 0; - } else { - $size = curl_getinfo($curlHandle, CURLINFO_CONTENT_LENGTH_DOWNLOAD); - } - curl_close($curlHandle); - if ($size <= 0){ - return 0; - } else { - return Utility::FileSizeConvert($size); - } - } else { - return 0; - } + if (\function_exists('curl_init') && false !== ($curlHandle = \curl_init($url))) { + \curl_setopt($curlHandle, \CURLOPT_RETURNTRANSFER, true); + + \curl_setopt($curlHandle, \CURLOPT_HEADER, true); + + \curl_setopt($curlHandle, \CURLOPT_NOBODY, true); + + \curl_setopt($curlHandle, \CURLOPT_SSL_VERIFYPEER, true); //TODO: how to avoid an error when 'Peer's Certificate issuer is not recognized' + + $curlReturn = \curl_exec($curlHandle); + + if (false === $curlReturn) { + \trigger_error(\curl_error($curlHandle)); + + $size = 0; + } else { + $size = \curl_getinfo($curlHandle, \CURLINFO_CONTENT_LENGTH_DOWNLOAD); + } + + \curl_close($curlHandle); + + if ($size <= 0) { + return 0; + } + + return self::convertFileSize($size); + } + + return 0; } - - /** - * Utility::FileSizeConvert() + + /** + * Utility::convertFileSize() * * @param mixed $size * @return mixed|string */ - public static function FileSizeConvert($size){ + public static function convertFileSize($size) + { if ($size > 0) { $kb = 1024; - $mb = 1024*1024; - $gb = 1024*1024*1024; + + $mb = 1024 * 1024; + + $gb = 1024 * 1024 * 1024; + if ($size >= $gb) { - $mysize = sprintf ("%01.2f",$size/$gb) . " " . 'G'; + $mysize = \sprintf('%01.2f', $size / $gb) . ' ' . 'G'; } elseif ($size >= $mb) { - $mysize = sprintf ("%01.2f",$size/$mb) . " " . 'M'; + $mysize = \sprintf('%01.2f', $size / $mb) . ' ' . 'M'; } elseif ($size >= $kb) { - $mysize = sprintf ("%01.2f",$size/$kb) . " " . 'K'; + $mysize = \sprintf('%01.2f', $size / $kb) . ' ' . 'K'; } else { - $mysize = sprintf ("%01.2f",$size) . " " . 'B'; + $mysize = \sprintf('%01.2f', $size) . ' ' . 'B'; } return $mysize; - } else { - return ''; + } + + return ''; + } + + /** + * @param $val + * @return float|int + */ + public static function returnBytes($val) + { + switch (\mb_substr($val, -1)) { + case 'K': + case 'k': + return (int)$val * 1024; + case 'M': + case 'm': + return (int)$val * 1048576; + case 'G': + case 'g': + return (int)$val * 1073741824; + default: + return $val; } } } diff --git a/class/index.html b/class/index.html deleted file mode 100644 index 990cbd6..0000000 --- a/class/index.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/class/index.php b/class/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/class/index.php @@ -0,0 +1,2 @@ + // // ------------------------------------------------------------------------ // // This program is free software; you can redistribute it and/or modify // @@ -24,5 +25,5 @@ // along with this program; if not, write to the Free Software // // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // ------------------------------------------------------------------------ // -require dirname(dirname(__DIR__)) . '/mainfile.php'; +require dirname(__DIR__, 2) . '/mainfile.php'; require XOOPS_ROOT_PATH . '/include/comment_delete.php'; diff --git a/comment_edit.php b/comment_edit.php index a342f51..03c2bd2 100644 --- a/comment_edit.php +++ b/comment_edit.php @@ -1,8 +1,9 @@ - // // ------------------------------------------------------------------------ // // This program is free software; you can redistribute it and/or modify // @@ -24,5 +25,5 @@ // along with this program; if not, write to the Free Software // // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // ------------------------------------------------------------------------ // -require dirname(dirname(__DIR__)) . '/mainfile.php'; +require dirname(__DIR__, 2) . '/mainfile.php'; require XOOPS_ROOT_PATH . '/include/comment_edit.php'; diff --git a/comment_new.php b/comment_new.php index 9891997..80b4e1c 100644 --- a/comment_new.php +++ b/comment_new.php @@ -1,8 +1,9 @@ - // // ------------------------------------------------------------------------ // // This program is free software; you can redistribute it and/or modify // @@ -29,15 +30,22 @@ $com_itemid = \Xmf\Request::getInt('com_itemid', 0, 'GET'); if ($com_itemid > 0) { // Get file title - $sql = 'SELECT title, cid FROM ' . $xoopsDB->prefix('tdmdownloads_downloads') . ' WHERE lid=' . $com_itemid; + + $sql = 'SELECT title, cid FROM ' . $xoopsDB->prefix('tdmdownloads_downloads') . ' WHERE lid=' . $com_itemid; + $result = $xoopsDB->query($sql); - if ($result) { + + if ($result instanceof \mysqli_result) { $categories = $utility->getItemIds('tdmdownloads_view', $moduleDirName); - $row = $xoopsDB->fetchArray($result); - if (!in_array($row['cid'], $categories, true)) { + + $row = $xoopsDB->fetchArray($result); + + if (!in_array($row['cid'], $categories)) { redirect_header(XOOPS_URL, 2, _NOPERM); } + $com_replytitle = $row['title']; + require XOOPS_ROOT_PATH . '/include/comment_new.php'; } } diff --git a/comment_post.php b/comment_post.php index e35c3eb..2e3ca7d 100644 --- a/comment_post.php +++ b/comment_post.php @@ -1,8 +1,9 @@ - // // ------------------------------------------------------------------------ // // This program is free software; you can redistribute it and/or modify // @@ -24,5 +25,5 @@ // along with this program; if not, write to the Free Software // // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // ------------------------------------------------------------------------ // -require dirname(dirname(__DIR__)) . '/mainfile.php'; +require dirname(__DIR__, 2) . '/mainfile.php'; require XOOPS_ROOT_PATH . '/include/comment_post.php'; diff --git a/comment_reply.php b/comment_reply.php index 52aa3f6..dcee807 100644 --- a/comment_reply.php +++ b/comment_reply.php @@ -1,8 +1,9 @@ - // // ------------------------------------------------------------------------ // // This program is free software; you can redistribute it and/or modify // @@ -24,5 +25,5 @@ // along with this program; if not, write to the Free Software // // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // ------------------------------------------------------------------------ // -require dirname(dirname(__DIR__)) . '/mainfile.php'; +require dirname(__DIR__, 2) . '/mainfile.php'; require XOOPS_ROOT_PATH . '/include/comment_reply.php'; diff --git a/config/admin.yml b/config/admin.yml new file mode 100644 index 0000000..01b1f3f --- /dev/null +++ b/config/admin.yml @@ -0,0 +1 @@ +displaySampleButton: 1 \ No newline at end of file diff --git a/config/config.php b/config/config.php new file mode 100644 index 0000000..5354180 --- /dev/null +++ b/config/config.php @@ -0,0 +1,92 @@ + $moduleDirNameUpper . ' Module Configurator', + 'paths' => [ + 'dirname' => $moduleDirName, + 'admin' => XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/admin', + 'modPath' => XOOPS_ROOT_PATH . '/modules/' . $moduleDirName, + 'modUrl' => XOOPS_URL . '/modules/' . $moduleDirName, + 'uploadPath' => XOOPS_UPLOAD_PATH . '/' . $moduleDirName, + 'uploadUrl' => XOOPS_UPLOAD_URL . '/' . $moduleDirName, + ], + 'uploadFolders' => [ + XOOPS_UPLOAD_PATH . '/' . $moduleDirName, + XOOPS_UPLOAD_PATH . '/' . $moduleDirName . '/downloads', + XOOPS_UPLOAD_PATH . '/' . $moduleDirName . '/images', + XOOPS_UPLOAD_PATH . '/' . $moduleDirName . '/images/cats', + XOOPS_UPLOAD_PATH . '/' . $moduleDirName . '/images/field', + XOOPS_UPLOAD_PATH . '/' . $moduleDirName . '/images/shots', + //XOOPS_UPLOAD_PATH . '/flags' + ], + 'copyBlankFiles' => [ + XOOPS_UPLOAD_PATH . '/' . $moduleDirName, + XOOPS_UPLOAD_PATH . '/' . $moduleDirName . '/downloads', + XOOPS_UPLOAD_PATH . '/' . $moduleDirName . '/images', + XOOPS_UPLOAD_PATH . '/' . $moduleDirName . '/images/cats', + XOOPS_UPLOAD_PATH . '/' . $moduleDirName . '/images/field', + XOOPS_UPLOAD_PATH . '/' . $moduleDirName . '/images/shots', + //XOOPS_UPLOAD_PATH . '/flags' + ], + + 'copyTestFolders' => [ + [ + XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/testdata/uploads', + XOOPS_UPLOAD_PATH . '/' . $moduleDirName, + ], + ], + + 'templateFolders' => [ + '/templates/', + // '/templates/blocks/', + // '/templates/admin/' + ], + 'oldFiles' => [ + '/class/request.php', + '/class/registry.php', + '/class/utilities.php', + '/class/util.php', + // '/include/constants.php', + // '/include/functions.php', + '/ajaxrating.txt', + ], + 'oldFolders' => [ + '/images', + '/css', + '/js', + ], + + 'renameTables' => [// 'XX_archive' => 'ZZZZ_archive', + ], + 'renameColumns' => [// 'extcal_event' => ['from' => 'event_etablissement', 'to' => 'event_location'], + ], + 'moduleStats' => [ + // 'totalcategories' => $helper->getHandler('Category')->getCategoriesCount(-1), + // 'totalitems' => $helper->getHandler('Item')->getItemsCount(), + // 'totalsubmitted' => $helper->getHandler('Item')->getItemsCount(-1, [Constants::PUBLISHER_STATUS_SUBMITTED]), + ], + 'modCopyright' => " + XOOPS Project", +]; diff --git a/config/icons.php b/config/icons.php new file mode 100644 index 0000000..18e3e31 --- /dev/null +++ b/config/icons.php @@ -0,0 +1,21 @@ + \mb_strtoupper($moduleDirName) . ' IconConfigurator', + 'icons' => [ + 'edit' => " . _EDIT . ", + 'delete' => "" . _DELETE . "", + 'clone' => "" . _CLONE . "", + 'preview' => "" . _PREVIEW . "", + 'print' => "" . _CLONE . "", + 'pdf' => "" . _CLONE . "", + 'add' => "" . _ADD . "", + '0' => "" . 0 . "", + '1' => "" . 1 . "", + ], +]; diff --git a/config/imageconfig.php b/config/imageconfig.php new file mode 100644 index 0000000..be14c9b --- /dev/null +++ b/config/imageconfig.php @@ -0,0 +1,47 @@ +loadLanguage('common'); + +// extra module configs +$modversion['config'][] = [ + 'name' => 'imageConfigs', + 'title' => 'CO_' . $moduleDirNameUpper . '_' . 'IMAGE_CONFIG', + 'description' => 'CO_' . $moduleDirNameUpper . '_' . 'IMAGE_CONFIG_DSC', + 'formtype' => 'line_break', + 'valuetype' => 'textbox', + 'default' => 'head', +]; + +$modversion['config'][] = [ + 'name' => 'imageWidth', + 'title' => 'CO_' . $moduleDirNameUpper . '_' . 'IMAGE_WIDTH', + 'description' => 'CO_' . $moduleDirNameUpper . '_' . 'IMAGE_WIDTH_DSC', + 'formtype' => 'textbox', + 'valuetype' => 'int', + 'default' => 1200, +]; // =1024/16 + +$modversion['config'][] = [ + 'name' => 'imageHeight', + 'title' => 'CO_' . $moduleDirNameUpper . '_' . 'IMAGE_HEIGHT', + 'description' => 'CO_' . $moduleDirNameUpper . '_' . 'IMAGE_HEIGHT_DSC', + 'formtype' => 'textbox', + 'valuetype' => 'int', + 'default' => 800, +]; // =768/16 + +$modversion['config'][] = [ + 'name' => 'imageUploadPath', + 'title' => 'CO_' . $moduleDirNameUpper . '_' . 'IMAGE_UPLOAD_PATH', + 'description' => 'CO_' . $moduleDirNameUpper . '_' . 'IMAGE_UPLOAD_PATH_DSC', + 'formtype' => 'textbox', + 'valuetype' => 'text', + 'default' => 'uploads/' . $modversion['dirname'] . '/images', +]; diff --git a/config/index.php b/config/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/config/index.php @@ -0,0 +1,2 @@ + \mb_strtoupper($moduleDirName) . ' PathConfigurator', + 'dirname' => $moduleDirName, + 'admin' => XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/admin', + 'modPath' => XOOPS_ROOT_PATH . '/modules/' . $moduleDirName, + 'modUrl' => XOOPS_URL . '/modules/' . $moduleDirName, + 'uploadPath' => XOOPS_UPLOAD_PATH . '/' . $moduleDirName, + 'uploadUrl' => XOOPS_UPLOAD_URL . '/' . $moduleDirName, + 'uploadFolders' => [ + XOOPS_UPLOAD_PATH . '/' . $moduleDirName, + XOOPS_UPLOAD_PATH . '/' . $moduleDirName . '/category', + XOOPS_UPLOAD_PATH . '/' . $moduleDirName . '/screenshots', + //XOOPS_UPLOAD_PATH . '/flags' + ], +]; diff --git a/docs/changelog.txt b/docs/changelog.txt index 530e779..e739e43 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -1,8 +1,27 @@ -
+
2.01 Beta 1 [2021-08-08]
Dev: XOOPS 2.5.11, PHP 7.4.22, PHP 8.08 +
+- PHP 7.1 & PHP 8 (mamba) +- various updates/cosmetics (mamba) +- replace index.html with index.php (mamba) +- PHP 8 Smarty defaults (mamba) +- fix PHP8 Unknown format specifier "{" (mamba) +- add TestdataButtons and testdata (mamba) +- Language translations adjustments (mamba) + + +
2.01 Alpha 1 [2020-05-018]
Dev: XOOPS 2.5.11, PHP 7.4.6
- added hits and ratings and for output of download in index.php (goffy) - added number of subcategories for output of category in index.php (goffy) - added new lang vars (goffy) +- Undefined variable $select_sup (geekwright) +- Class 'XoopsPageNav' not found error (geekwright) +- Add some category detail for theme use (geekwright) +- Turn off logger (geekwright) +- Fix xml (geekwright) +- add extra fields visibility (heyula) +- refactor Utility (mamba) +
2.0 RC 1 [2019-01-29]

@@ -65,6 +84,11 @@ - added Blocks admin (mamba) - switch admin sites to template based (goffy) +TODO: +- add test data +- do more testing +- update "update.php" file +
1.65 Final [2017/02/02]

@@ -139,7 +163,7 @@ List of improvements: Informations - - See the file "lang_diff.txt" for changes in language. + - See the file "lang_diff.txt" for changes in language. Installation: @@ -187,7 +211,7 @@ List of improvements: Informations: - Adding the suffix "cat_" in all fields of the table "tdmdownloads_cat. - - See the file "lang_diff.txt" for changes in language. + - See the file "lang_diff.txt" for changes in language.
1.10 [11.11.2009]
diff --git a/docs/index.html b/docs/index.html deleted file mode 100644 index 990cbd6..0000000 --- a/docs/index.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/docs/index.php b/docs/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/docs/index.php @@ -0,0 +1,2 @@ +history.go(-1); \ No newline at end of file diff --git a/extra/index.php b/extra/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/extra/index.php @@ -0,0 +1,2 @@ +history.go(-1); \ No newline at end of file diff --git a/extra/plugins/index.php b/extra/plugins/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/extra/plugins/index.php @@ -0,0 +1,2 @@ +history.go(-1); \ No newline at end of file diff --git a/extra/plugins/sitemap/index.php b/extra/plugins/sitemap/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/extra/plugins/sitemap/index.php @@ -0,0 +1,2 @@ +prefix('tdmdownloads_cat'), 'cid', 'pid', 'title', 'viewcat.php?cid=', 'title'); - return $block; + return sitemap_get_categories_map($xoopsDB->prefix('tdmdownloads_cat'), 'cid', 'pid', 'title', 'viewcat.php?cid=', 'title'); } diff --git a/extra/plugins/tag/index.html b/extra/plugins/tag/index.html deleted file mode 100644 index 74b6f45..0000000 --- a/extra/plugins/tag/index.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/extra/plugins/tag/index.php b/extra/plugins/tag/index.php new file mode 100644 index 0000000..2ea9b7d --- /dev/null +++ b/extra/plugins/tag/index.php @@ -0,0 +1,3 @@ +getHandler('Downloads'); + + $itemHandler = Helper::getInstance()->getHandler('Downloads'); + /** @var \XoopsModules\Tdmdownloads\Downloads $item_obj */ + $items_obj = $itemHandler->getObjects(new \Criteria('lid', '(' . implode(', ', $items_id) . ')', 'IN'), true); foreach (array_keys($items) as $cat_id) { foreach (array_keys($items[$cat_id]) as $item_id) { if (isset($items_obj[$item_id])) { - $item_obj = $items_obj[$item_id]; + $item_obj = $items_obj[$item_id]; + $items[$cat_id][$item_id] = [ 'title' => $item_obj->getVar('title'), 'uid' => $item_obj->getVar('submitter'), @@ -54,6 +66,7 @@ function tdmdownloads_tag_iteminfo(&$items) } } } + unset($items_obj); return null; @@ -65,12 +78,16 @@ function tdmdownloads_tag_iteminfo(&$items) function tdmdownloads_tag_synchronization($mid) { /** @var \XoopsModules\Tdmdownloads\DownloadsHandler $itemHandler */ - $itemHandler = \XoopsModules\Tdmdownloads\Helper::getInstance()->getHandler('Downloads'); + + $itemHandler = Helper::getInstance()->getHandler('Downloads'); + /** @var \XoopsModules\Tag\LinkHandler $linkHandler */ - $linkHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Link'); + + $linkHandler = Helper::getInstance()->getHandler('Link'); /* clear tag-item links */ - if (version_compare($GLOBALS['xoopsDB']->getServerVersion(), '4.1.0', 'ge')): + + if (version_compare($GLOBALS['xoopsDB']->getServerVersion(), '4.1.0', 'ge')) : $sql = " DELETE FROM {$linkHandler->table}" . ' WHERE ' . " tag_modid = {$mid}" @@ -81,7 +98,7 @@ function tdmdownloads_tag_synchronization($mid) . " WHERE {$itemHandler->table}.status > 0" . ' ) ' . ' )'; - else: + else : $sql = " DELETE {$linkHandler->table} FROM {$linkHandler->table}" . " LEFT JOIN {$itemHandler->table} AS aa ON {$linkHandler->table}.tag_itemid = aa.{$itemHandler->keyName} " . ' WHERE ' @@ -91,6 +108,7 @@ function tdmdownloads_tag_synchronization($mid) . ' OR aa.status < 1' . ' )'; endif; + if (!$result = $linkHandler->db->queryF($sql)) { //xoops_error($linkHandler->db->error()); } diff --git a/extra/plugins/waiting/index.html b/extra/plugins/waiting/index.html deleted file mode 100644 index 74b6f45..0000000 --- a/extra/plugins/waiting/index.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/extra/plugins/waiting/index.php b/extra/plugins/waiting/index.php new file mode 100644 index 0000000..2ea9b7d --- /dev/null +++ b/extra/plugins/waiting/index.php @@ -0,0 +1,3 @@ +query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('tdmdownloads_downloads') . ' WHERE status=0'); + if ($result) { $block['adminlink'] = XOOPS_URL . "/modules/$moduleDirName/admin/downloads.php?op=liste&statut_display=0"; - list($block['pendingnum']) = $xoopsDB->fetchRow($result); + + [$block['pendingnum']] = $xoopsDB->fetchRow($result); + $block['lang_linkname'] = _PI_WAITING_WAITINGS; } + $ret[] = $block; // TDMDownloads broken - $block = []; + + $block = []; + $result = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('tdmdownloads_broken')); + if ($result) { $block['adminlink'] = XOOPS_URL . "/modules/$moduleDirName/admin/broken.php"; - list($block['pendingnum']) = $xoopsDB->fetchRow($result); + + [$block['pendingnum']] = $xoopsDB->fetchRow($result); + $block['lang_linkname'] = _PI_WAITING_BROKENS; } + $ret[] = $block; // TDMDownloads modreq - $block = []; + + $block = []; + $result = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('tdmdownloads_mod')); + if ($result) { $block['adminlink'] = XOOPS_URL . "/modules/$moduleDirName/admin/modified.php"; - list($block['pendingnum']) = $xoopsDB->fetchRow($result); + + [$block['pendingnum']] = $xoopsDB->fetchRow($result); + $block['lang_linkname'] = _PI_WAITING_MODREQS; } + $ret[] = $block; return $ret; diff --git a/extra/plugins/whatsnew/index.html b/extra/plugins/whatsnew/index.html deleted file mode 100644 index 990cbd6..0000000 --- a/extra/plugins/whatsnew/index.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/extra/plugins/whatsnew/index.php b/extra/plugins/whatsnew/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/extra/plugins/whatsnew/index.php @@ -0,0 +1,2 @@ +prefix('tdmdownloads_downloads') . ' WHERE status>0 ORDER BY date'; + + $sql = 'SELECT lid, title, date, cid, submitter, hits, description FROM ' . $xoopsDB->prefix('tdmdownloads_downloads') . ' WHERE status>0 ORDER BY date'; $result = $xoopsDB->query($sql, $limit, $offset); - $i = 0; + $i = 0; + $ret = []; + if ($result instanceof \mysqli_result) { + while (false !== ($row = $xoopsDB->fetchArray($result))) { + $lid = $row['lid']; + + $ret[$i]['link'] = $URL_MOD . '/singlefile.php?lid=' . $lid; + + $ret[$i]['cat_link'] = $URL_MOD . '/viewcat.php?cid=' . $row['cid']; + + $ret[$i]['title'] = $row['title']; + + $ret[$i]['time'] = $row['date']; - while (false !== ($row = $xoopsDB->fetchArray($result))) { - $lid = $row['lid']; - $ret[$i]['link'] = $URL_MOD . '/singlefile.php?lid=' . $lid; - $ret[$i]['cat_link'] = $URL_MOD . '/viewcat.php?cid=' . $row['cid']; + // atom feed - $ret[$i]['title'] = $row['title']; - $ret[$i]['time'] = $row['date']; + $ret[$i]['id'] = $lid; - // atom feed - $ret[$i]['id'] = $lid; - $ret[$i]['description'] = $myts->displayTarea($row['description'], 0); //no html + $ret[$i]['description'] = $myts->displayTarea($row['description'], 0); //no html - // category - //$ret[$i]['cat_name'] = $row['ctitle']; + // category - // counter - $ret[$i]['hits'] = $row['hits']; + //$ret[$i]['cat_name'] = $row['ctitle']; - // this module dont show user name - $ret[$i]['uid'] = $row['submitter']; + // counter - ++$i; + $ret[$i]['hits'] = $row['hits']; + + // this module dont show user name + + $ret[$i]['uid'] = $row['submitter']; + + ++$i; + } } return $ret; @@ -68,9 +79,12 @@ function tdmdownloads_num() { global $xoopsDB; - $sql = 'SELECT count(*) FROM ' . $xoopsDB->prefix('tdmdownloads_downloads') . ' WHERE status>0 ORDER BY lid'; + $sql = 'SELECT count(*) FROM ' . $xoopsDB->prefix('tdmdownloads_downloads') . ' WHERE status>0 ORDER BY lid'; + $array = $xoopsDB->fetchRow($xoopsDB->query($sql)); - $num = $array[0]; + + $num = $array[0]; + if (empty($num)) { $num = 0; } @@ -87,22 +101,30 @@ function tdmdownloads_num() function tdmdownloads_data($limit = 0, $offset = 0) { global $xoopsDB; - $moduleDirName = basename(dirname(dirname(__DIR__))); - $sql = 'SELECT lid, title, date FROM ' . $xoopsDB->prefix('tdmdownloads_downloads') . ' WHERE status>0 ORDER BY lid'; + $moduleDirName = basename(dirname(__DIR__, 2)); + + $sql = 'SELECT lid, title, date FROM ' . $xoopsDB->prefix('tdmdownloads_downloads') . ' WHERE status>0 ORDER BY lid'; + $result = $xoopsDB->query($sql, $limit, $offset); - $i = 0; + $i = 0; + $ret = []; + if ($result instanceof \mysqli_result) { + while (false !== ($myrow = $xoopsDB->fetchArray($result))) { + $id = $myrow['lid']; - while (false !== ($myrow = $xoopsDB->fetchArray($result))) { - $id = $myrow['lid']; - $ret[$i]['id'] = $id; - $ret[$i]['link'] = XOOPS_URL . "/modules/$moduleDirName/singlefile.php?lid=" . $id . ''; - $ret[$i]['title'] = $myrow['title']; - $ret[$i]['time'] = $myrow['date']; - ++$i; - } + $ret[$i]['id'] = $id; + + $ret[$i]['link'] = XOOPS_URL . "/modules/$moduleDirName/singlefile.php?lid=" . $id . ''; + $ret[$i]['title'] = $myrow['title']; + + $ret[$i]['time'] = $myrow['date']; + + ++$i; + } + } return $ret; } diff --git a/extra/plugins/whatsnew/tdmdownloads/index.html b/extra/plugins/whatsnew/tdmdownloads/index.html deleted file mode 100644 index 990cbd6..0000000 --- a/extra/plugins/whatsnew/tdmdownloads/index.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/extra/plugins/whatsnew/tdmdownloads/index.php b/extra/plugins/whatsnew/tdmdownloads/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/extra/plugins/whatsnew/tdmdownloads/index.php @@ -0,0 +1,2 @@ +history.go(-1); \ No newline at end of file diff --git a/extra/uploads/index.php b/extra/uploads/index.php new file mode 100644 index 0000000..2ea9b7d --- /dev/null +++ b/extra/uploads/index.php @@ -0,0 +1,3 @@ +history.go(-1); \ No newline at end of file diff --git a/extra/uploads/tdmdownloads/downloads/index.php b/extra/uploads/tdmdownloads/downloads/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/extra/uploads/tdmdownloads/downloads/index.php @@ -0,0 +1,2 @@ +history.go(-1); \ No newline at end of file diff --git a/extra/uploads/tdmdownloads/images/cats/index.php b/extra/uploads/tdmdownloads/images/cats/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/extra/uploads/tdmdownloads/images/cats/index.php @@ -0,0 +1,2 @@ +history.go(-1); \ No newline at end of file diff --git a/extra/uploads/tdmdownloads/images/field/index.php b/extra/uploads/tdmdownloads/images/field/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/extra/uploads/tdmdownloads/images/field/index.php @@ -0,0 +1,2 @@ +history.go(-1); \ No newline at end of file diff --git a/extra/uploads/tdmdownloads/images/index.php b/extra/uploads/tdmdownloads/images/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/extra/uploads/tdmdownloads/images/index.php @@ -0,0 +1,2 @@ +history.go(-1); \ No newline at end of file diff --git a/extra/uploads/tdmdownloads/images/shots/index.php b/extra/uploads/tdmdownloads/images/shots/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/extra/uploads/tdmdownloads/images/shots/index.php @@ -0,0 +1,2 @@ +history.go(-1); \ No newline at end of file diff --git a/extra/uploads/tdmdownloads/index.php b/extra/uploads/tdmdownloads/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/extra/uploads/tdmdownloads/index.php @@ -0,0 +1,2 @@ +path('class/template.php'); - $xoopsTpl = new XoopsTpl(); + + $xoopsTpl = new \XoopsTpl(); } -$perm_submit = $grouppermHandler->checkRight('tdmdownloads_ac', 4, $groups, $xoopsModule->getVar('mid')) ? true : false; -$perm_modif = $grouppermHandler->checkRight('tdmdownloads_ac', 8, $groups, $xoopsModule->getVar('mid')) ? true : false; -$perm_vote = $grouppermHandler->checkRight('tdmdownloads_ac', 16, $groups, $xoopsModule->getVar('mid')) ? true : false; -$perm_upload = $grouppermHandler->checkRight('tdmdownloads_ac', 32, $groups, $xoopsModule->getVar('mid')) ? true : false; -$perm_autoapprove = $grouppermHandler->checkRight('tdmdownloads_ac', 64, $groups, $xoopsModule->getVar('mid')) ? true : false; +$perm_submit = $grouppermHandler->checkRight('tdmdownloads_ac', 4, $groups, $xoopsModule->getVar('mid')); +$perm_modif = $grouppermHandler->checkRight('tdmdownloads_ac', 8, $groups, $xoopsModule->getVar('mid')); +$perm_vote = $grouppermHandler->checkRight('tdmdownloads_ac', 16, $groups, $xoopsModule->getVar('mid')); +$perm_upload = $grouppermHandler->checkRight('tdmdownloads_ac', 32, $groups, $xoopsModule->getVar('mid')); +$perm_autoapprove = $grouppermHandler->checkRight('tdmdownloads_ac', 64, $groups, $xoopsModule->getVar('mid')); //paramètres: // pour les images des catégories: diff --git a/include/comment_functions.php b/include/comment_functions.php index 692e037..bee6b94 100644 --- a/include/comment_functions.php +++ b/include/comment_functions.php @@ -1,8 +1,9 @@ - // // ------------------------------------------------------------------------ // // This program is free software; you can redistribute it and/or modify // @@ -34,8 +35,11 @@ function tdmdownloads_com_update($downloadId, $totalNumber) { /** @var \XoopsMySQLDatabase $db */ - $db = \XoopsDatabaseFactory::getDatabaseConnection(); + + $db = \XoopsDatabaseFactory::getDatabaseConnection(); + $sql = 'UPDATE ' . $db->prefix('tdmdownloads_downloads') . ' SET comments = ' . $totalNumber . ' WHERE lid = ' . $downloadId; + $db->query($sql); } diff --git a/include/common.php b/include/common.php index f1a5408..fad9f6c 100644 --- a/include/common.php +++ b/include/common.php @@ -1,4 +1,5 @@ -getHandler('Category'); -$downloadsHandler = \XoopsModules\Tdmdownloads\Helper::getInstance()->getHandler('Downloads'); -$downlimitHandler = \XoopsModules\Tdmdownloads\Helper::getInstance()->getHandler('Downlimit'); -$ratingHandler = \XoopsModules\Tdmdownloads\Helper::getInstance()->getHandler('Rating'); -$fieldHandler = \XoopsModules\Tdmdownloads\Helper::getInstance()->getHandler('Field'); -$fielddataHandler = \XoopsModules\Tdmdownloads\Helper::getInstance()->getHandler('Fielddata'); -$brokenHandler = \XoopsModules\Tdmdownloads\Helper::getInstance()->getHandler('Broken'); -$modifiedHandler = \XoopsModules\Tdmdownloads\Helper::getInstance()->getHandler('Modified'); -$modifieddataHandler = \XoopsModules\Tdmdownloads\Helper::getInstance()->getHandler('Modifiedfielddata'); - -$pathIcon16 = \Xmf\Module\Admin::iconUrl('', 16); -$pathIcon32 = \Xmf\Module\Admin::iconUrl('', 32); +$categoryHandler = Helper::getInstance()->getHandler('Category'); +$downloadsHandler = Helper::getInstance()->getHandler('Downloads'); +$downlimitHandler = Helper::getInstance()->getHandler('Downlimit'); +$ratingHandler = Helper::getInstance()->getHandler('Rating'); +$fieldHandler = Helper::getInstance()->getHandler('Field'); +$fielddataHandler = Helper::getInstance()->getHandler('Fielddata'); +$brokenHandler = Helper::getInstance()->getHandler('Broken'); +$modifiedHandler = Helper::getInstance()->getHandler('Modified'); +$modifieddataHandler = Helper::getInstance()->getHandler('Modifiedfielddata'); + +$pathIcon16 = Admin::iconUrl('', '16'); +$pathIcon32 = Admin::iconUrl('', '32'); if (!defined($moduleDirNameUpper . '_CONSTANTS_DEFINED')) { define($moduleDirNameUpper . '_DIRNAME', basename(dirname(__DIR__))); + define($moduleDirNameUpper . '_ROOT_PATH', XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/'); + define($moduleDirNameUpper . '_PATH', XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/'); + define($moduleDirNameUpper . '_URL', XOOPS_URL . '/modules/' . $moduleDirName . '/'); + define($moduleDirNameUpper . '_IMAGE_URL', constant($moduleDirNameUpper . '_URL') . '/assets/images/'); + + define($moduleDirNameUpper . '_ICONS_URL', constant($moduleDirNameUpper . '_URL') . '/assets/icons/'); + define($moduleDirNameUpper . '_IMAGE_PATH', constant($moduleDirNameUpper . '_ROOT_PATH') . '/assets/images'); + define($moduleDirNameUpper . '_ADMIN_URL', constant($moduleDirNameUpper . '_URL') . '/admin/'); + define($moduleDirNameUpper . '_ADMIN_PATH', constant($moduleDirNameUpper . '_ROOT_PATH') . '/admin/'); + define($moduleDirNameUpper . '_ADMIN', constant($moduleDirNameUpper . '_URL') . '/admin/index.php'); + // define($moduleDirNameUpper . '_AUTHOR_LOGOIMG', constant($moduleDirNameUpper . '_URL') . '/assets/images/logoModule.png'); define($moduleDirNameUpper . '_UPLOAD_URL', XOOPS_UPLOAD_URL . '/' . $moduleDirName); // WITHOUT Trailing slash define($moduleDirNameUpper . '_UPLOAD_PATH', XOOPS_UPLOAD_PATH . '/' . $moduleDirName); // WITHOUT Trailing slash define($moduleDirNameUpper . '_AUTHOR_LOGOIMG', $pathIcon32 . '/xoopsmicrobutton.gif'); + define($moduleDirNameUpper . '_CONSTANTS_DEFINED', 1); } @@ -86,6 +102,7 @@ if (!isset($GLOBALS['xoopsTpl']) || !($GLOBALS['xoopsTpl'] instanceof \XoopsTpl)) { require $GLOBALS['xoops']->path('class/template.php'); + $GLOBALS['xoopsTpl'] = new \XoopsTpl(); } @@ -94,8 +111,10 @@ // Local icons path if (is_object($helper->getModule())) { $pathModIcon16 = $helper->getModule()->getInfo('modicons16'); + $pathModIcon32 = $helper->getModule()->getInfo('modicons32'); $GLOBALS['xoopsTpl']->assign('pathModIcon16', XOOPS_URL . '/modules/' . $moduleDirName . '/' . $pathModIcon16); - $GLOBALS['xoopsTpl']->assign('pathModIcon32', $pathModIcon32); + + $GLOBALS['xoopsTpl']->assign('pathModIcon32', XOOPS_URL . '/modules/' . $moduleDirName . '/' . $pathModIcon32); } diff --git a/include/config.php b/include/config.php deleted file mode 100644 index 4e6d8a2..0000000 --- a/include/config.php +++ /dev/null @@ -1,86 +0,0 @@ - mb_strtoupper($moduleDirName) . ' Module Configurator', - 'paths' => [ - 'dirname' => $moduleDirName, - 'admin' => XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/admin', - 'modPath' => XOOPS_ROOT_PATH . '/modules/' . $moduleDirName, - 'modUrl' => XOOPS_URL . '/modules/' . $moduleDirName, - 'uploadPath' => XOOPS_UPLOAD_PATH . '/' . $moduleDirName, - 'uploadUrl' => XOOPS_UPLOAD_URL . '/' . $moduleDirName, - ], - 'uploadFolders' => [ - XOOPS_UPLOAD_PATH . '/' . $moduleDirName, - XOOPS_UPLOAD_PATH . '/' . $moduleDirName . '/downloads', - XOOPS_UPLOAD_PATH . '/' . $moduleDirName . '/images', - XOOPS_UPLOAD_PATH . '/' . $moduleDirName . '/images/cats', - XOOPS_UPLOAD_PATH . '/' . $moduleDirName . '/images/field', - XOOPS_UPLOAD_PATH . '/' . $moduleDirName . '/images/shots', - //XOOPS_UPLOAD_PATH . '/flags' - ], - 'copyBlankFiles' => [ - XOOPS_UPLOAD_PATH . '/' . $moduleDirName, - XOOPS_UPLOAD_PATH . '/' . $moduleDirName . '/downloads', - XOOPS_UPLOAD_PATH . '/' . $moduleDirName . '/images', - XOOPS_UPLOAD_PATH . '/' . $moduleDirName . '/images/cats', - XOOPS_UPLOAD_PATH . '/' . $moduleDirName . '/images/field', - XOOPS_UPLOAD_PATH . '/' . $moduleDirName . '/images/shots', - //XOOPS_UPLOAD_PATH . '/flags' - ], - - 'copyTestFolders' => [ - // XOOPS_UPLOAD_PATH . '/' . $moduleDirName, - //[ - // constant($moduleDirNameUpper . '_PATH') . '/testdata/images', - // XOOPS_UPLOAD_PATH . '/' . $moduleDirName . '/images', - //] - ], - - 'templateFolders' => [ - '/templates/', - // '/templates/blocks/', - // '/templates/admin/' - ], - 'oldFiles' => [ - '/class/request.php', - '/class/registry.php', - '/class/utilities.php', - '/class/util.php', - // '/include/constants.php', - // '/include/functions.php', - '/ajaxrating.txt', - ], - 'oldFolders' => [ - '/images', - '/css', - '/js', - ], - - 'renameTables' => [// 'XX_archive' => 'ZZZZ_archive', - ], - 'modCopyright' => " - XOOPS Project", - ]; -} diff --git a/include/functions0.php0 b/include/functions0.php0 index e227fdb..cd91cba 100644 --- a/include/functions0.php0 +++ b/include/functions0.php0 @@ -10,7 +10,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * @copyright Gregory Mage (Aka Mage) - * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) + * @license GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html) * @author Gregory Mage (Aka Mage) * @param mixed $permtype * @param mixed $dirname @@ -49,7 +49,7 @@ function tdmdownloads_NumbersOfEntries($mytree, $categories, $entries, $cid) { $count = 0; $child_arr = []; - if (in_array($cid, $categories, true)) { + if (in_array($cid, $categories)) { $child = $mytree->getAllChild($cid); foreach (array_keys($entries) as $i) { if ($entries[$i]->getVar('cid') == $cid) { diff --git a/include/index.html b/include/index.html deleted file mode 100644 index 990cbd6..0000000 --- a/include/index.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/include/index.php b/include/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/include/index.php @@ -0,0 +1,2 @@ + // // ------------------------------------------------------------------------ // // This program is free software; you can redistribute it and/or modify // @@ -33,46 +34,68 @@ function tdmdownloads_notify_iteminfo($category, $item_id) { global $xoopsModule, $xoopsModuleConfig, $xoopsConfig; + $moduleDirName = basename(dirname(__DIR__)); - $item_id = (int)$item_id; + + $item_id = (int)$item_id; + if (empty($xoopsModule) || $xoopsModule->getVar('dirname') !== $moduleDirName) { /** @var \XoopsModuleHandler $moduleHandler */ + $moduleHandler = xoops_getHandler('module'); - $module = $moduleHandler->getByDirname($moduleDirName); + + $module = $moduleHandler->getByDirname($moduleDirName); + /** @var \XoopsConfigHandler $configHandler */ + $configHandler = xoops_getHandler('config'); - $config = $configHandler->getConfigsByCat(0, $module->getVar('mid')); + + $config = $configHandler->getConfigsByCat(0, $module->getVar('mid')); } else { $module = $xoopsModule; + $config = $xoopsModuleConfig; } if ('global' === $category) { $item['name'] = ''; - $item['url'] = ''; + + $item['url'] = ''; return $item; } global $xoopsDB; + if ('category' === $category) { // Assume we have a valid category id - $sql = 'SELECT title FROM ' . $xoopsDB->prefix('tdmdownloads_cat') . ' WHERE cid = ' . $item_id; - $result = $xoopsDB->query($sql); // TODO: error check - $result_array = $xoopsDB->fetchArray($result); + + $sql = 'SELECT title FROM ' . $xoopsDB->prefix('tdmdownloads_cat') . ' WHERE cid = ' . $item_id; + + $result = $xoopsDB->query($sql); // TODO: error check + if ($result instanceof \mysqli_result) { + $result_array = $xoopsDB->fetchArray($result); + } + $item['name'] = $result_array['title']; - $item['url'] = XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/viewcat.php?cid=' . $item_id; + + $item['url'] = XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/viewcat.php?cid=' . $item_id; return $item; } if ('file' === $category) { // Assume we have a valid file id - $sql = 'SELECT cid,title FROM ' . $xoopsDB->prefix('tdmdownloads_downloads') . ' WHERE lid = ' . $item_id; - $result = $xoopsDB->query($sql); // TODO: error check - $result_array = $xoopsDB->fetchArray($result); + + $sql = 'SELECT cid,title FROM ' . $xoopsDB->prefix('tdmdownloads_downloads') . ' WHERE lid = ' . $item_id; + + $result = $xoopsDB->query($sql); // TODO: error check + if ($result instanceof \mysqli_result) { + $result_array = $xoopsDB->fetchArray($result); + } $item['name'] = $result_array['title']; - $item['url'] = XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/singlefile.php?cid=' . $result_array['cid'] . '&lid=' . $item_id; + + $item['url'] = XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/singlefile.php?cid=' . $result_array['cid'] . '&lid=' . $item_id; return $item; } diff --git a/include/oninstall.php b/include/oninstall.php index 93aaee0..7b2b5f1 100644 --- a/include/oninstall.php +++ b/include/oninstall.php @@ -1,4 +1,4 @@ -getInfo('tables'); + + foreach ($mod_tables as $table) { + $GLOBALS['xoopsDB']->queryF('DROP TABLE IF EXISTS ' . $GLOBALS['xoopsDB']->prefix($table) . ';'); + } + } + + return $xoopsSuccess && $phpSuccess; +} + /** * @return bool */ function xoops_module_install_tdmdownloads() { global $xoopsModule, $xoopsConfig, $xoopsDB; + $moduleDirName = basename(dirname(__DIR__)); $namemodule = $moduleDirName; + if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/language/' . $xoopsConfig['language'] . '/admin.php')) { require_once XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/language/' . $xoopsConfig['language'] . '/admin.php'; } else { require_once XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/language/english/admin.php'; } - $fieldHandler = \XoopsModules\Tdmdownloads\Helper::getInstance()->getHandler('Field'); - $obj = $fieldHandler->create(); + + $fieldHandler = Helper::getInstance()->getHandler('Field'); + + $obj = $fieldHandler->create(); + $obj->setVar('title', _AM_TDMDOWNLOADS_FORMHOMEPAGE); + $obj->setVar('img', 'homepage.png'); + $obj->setVar('weight', 1); + $obj->setVar('search', 0); + $obj->setVar('status', 1); + $obj->setVar('status_def', 1); + $fieldHandler->insert($obj); + $obj = $fieldHandler->create(); + $obj->setVar('title', _AM_TDMDOWNLOADS_FORMVERSION); + $obj->setVar('img', 'version.png'); + $obj->setVar('weight', 2); + $obj->setVar('search', 0); + $obj->setVar('status', 1); + $obj->setVar('status_def', 1); + $fieldHandler->insert($obj); + $obj = $fieldHandler->create(); + $obj->setVar('title', _AM_TDMDOWNLOADS_FORMSIZE); + $obj->setVar('img', 'size.png'); + $obj->setVar('weight', 3); + $obj->setVar('search', 0); + $obj->setVar('status', 1); + $obj->setVar('status_def', 1); + $fieldHandler->insert($obj); + $obj = $fieldHandler->create(); + $obj->setVar('title', _AM_TDMDOWNLOADS_FORMPLATFORM); + $obj->setVar('img', 'platform.png'); + $obj->setVar('weight', 4); + $obj->setVar('search', 0); + $obj->setVar('status', 1); + $obj->setVar('status_def', 1); + $fieldHandler->insert($obj); - //Creation du fichier ".$namemodule."/ + //File creation ".$namemodule."/ + $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . ''; + if (!is_dir($dir)) { if (!mkdir($dir, 0777) && !is_dir($dir)) { throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); } } + chmod($dir, 0777); - //Creation du fichier ".$namemodule."/images/ + //File creation ".$namemodule."/images/ + $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images'; + if (!is_dir($dir)) { if (!mkdir($dir, 0777) && !is_dir($dir)) { throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); } } + chmod($dir, 0777); - //Creation du fichier ".$namemodule."/images/cat + //File creation ".$namemodule."/images/cat + $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/cats'; + if (!is_dir($dir)) { if (!mkdir($dir, 0777) && !is_dir($dir)) { throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); } } + chmod($dir, 0777); - //Creation du fichier ".$namemodule."/images/shots + //File creation ".$namemodule."/images/shots + $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/shots'; + if (!is_dir($dir)) { if (!mkdir($dir, 0777) && !is_dir($dir)) { throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); } } + chmod($dir, 0777); - //Creation du fichier ".$namemodule."/images/field + //File creation ".$namemodule."/images/field + $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field'; + if (!is_dir($dir)) { if (!mkdir($dir, 0777) && !is_dir($dir)) { throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); } } + chmod($dir, 0777); - //Creation du fichier ".$namemodule."/downloads + //File creation ".$namemodule."/downloads + $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/downloads'; + if (!is_dir($dir)) { if (!mkdir($dir, 0777) && !is_dir($dir)) { throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); } } + chmod($dir, 0777); - //Copie des index.html - $indexFile = XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/include/index.html'; - copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/index.html'); - copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/index.html'); - copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/cats/index.html'); - copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/shots/index.html'); - copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/index.html'); - copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/downloads/index.html'); + //Copy index.html + + $indexFile = XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/include/index.php'; + + copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/index.php'); + + copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/index.php'); + + copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/cats/index.php'); + + copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/shots/index.php'); + + copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/index.php'); + + copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/downloads/index.php'); + + //Copy blank.gif - //Copie des blank.gif $blankFile = XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/assets/images/blank.gif'; + copy($blankFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/cats/blank.gif'); + copy($blankFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/shots/blank.gif'); + copy($blankFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/blank.gif'); - //Copie des images pour les champs + //Copy images for fields + copy(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/assets/images/icons/16/homepage.png', XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/homepage.png'); + copy(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/assets/images/icons/16/version.png', XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/version.png'); + copy(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/assets/images/icons/16/size.png', XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/size.png'); + copy(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/assets/images/icons/16/platform.png', XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/platform.png'); return true; diff --git a/include/onupdate.php b/include/onupdate.php index 881381c..89b30f7 100644 --- a/include/onupdate.php +++ b/include/onupdate.php @@ -1,4 +1,23 @@ -IsAdmin()) { + exit('Restricted access' . PHP_EOL); +} + /** * TDMDownload * @@ -9,26 +28,76 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * @copyright Gregory Mage (Aka Mage) - * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) - * @author Gregory Mage (Aka Mage) * @param $module * @param null $prev_version * @return bool|null + * @copyright Gregory Mage (Aka Mage) + * @license GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html) + * @author Gregory Mage (Aka Mage) */ + +/** + * Prepares system prior to attempting to install module + * @param \XoopsModule $module {@link XoopsModule} + * @return bool true if ready to install, false if not + */ +function xoops_module_pre_update_tdmdownloads(\XoopsModule $module) +{ + $moduleDirName = \basename(\dirname(__DIR__)); + $helper = Helper::getInstance(); + $utility = new Utility(); + + $xoopsSuccess = $utility::checkVerXoops($module); + $phpSuccess = $utility::checkVerPhp($module); + + /** @var Configurator $configurator */ + $configurator = new Configurator(); + + //create upload folders + $uploadFolders = $configurator->uploadFolders; + foreach ($uploadFolders as $value) { + $utility::prepareFolder($value); + } + + $migrator = new Migrate(); + $migrator->synchronizeSchema(); + + return $xoopsSuccess && $phpSuccess; +} + + + function xoops_module_update_tdmdownloads(&$module, $prev_version = null) { $ret = null; + + $moduleDirName = \basename(\dirname(__DIR__)); + $moduleDirNameUpper = \mb_strtoupper($moduleDirName); + + $helper = Helper::getInstance(); + $utility = new Utility(); + $configurator = new Configurator(); + + $helper->loadLanguage('common'); + if ($prev_version < 163) { $ret = update_tdmdownloads_v163($module); } + if ($prev_version < 167) { $ret = update_tdmdownloads_v167($module); } - if ($prev_version < 200) { + + if ($prev_version < 200) { $ret = update_tdmdownloads_v200($module); } + + if ($prev_version < 201) { + $ret = update_tdmdownloads_v201($module); + } + $errors = $module->getErrors(); + if (!empty($errors)) { // print_r($errors); } @@ -36,100 +105,216 @@ function xoops_module_update_tdmdownloads(&$module, $prev_version = null) return $ret; } + +/** + * @param $module + * @return bool + */ +function update_tdmdownloads_v201(&$module) +{ + $moduleDirName = \basename(\dirname(__DIR__)); + $moduleDirNameUpper = \mb_strtoupper($moduleDirName); + + $helper = Helper::getInstance(); + $utility = new Utility(); + $configurator = new Configurator(); + + $helper->loadLanguage('common'); + + //delete old HTML templates + if (count($configurator->templateFolders) > 0) { + foreach ($configurator->templateFolders as $folder) { + $templateFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $folder); + if (is_dir($templateFolder)) { + $templateList = array_diff(scandir($templateFolder, SCANDIR_SORT_NONE), ['..', '.']); + foreach ($templateList as $k => $v) { + $fileInfo = new SplFileInfo($templateFolder . $v); + if ('html' === $fileInfo->getExtension() && 'index.html' !== $fileInfo->getFilename()) { + if (file_exists($templateFolder . $v)) { + unlink($templateFolder . $v); + } + } + } + } + } + } + + // --- DELETE OLD FILES --------------- + if (count($configurator->oldFiles) > 0) { + // foreach (array_keys($GLOBALS['uploadFolders']) as $i) { + foreach (array_keys($configurator->oldFiles) as $i) { + $tempFile = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFiles[$i]); + if (is_file($tempFile)) { + unlink($tempFile); + } + } + } + + // --- DELETE OLD FOLDERS --------------- + xoops_load('XoopsFile'); + if (count($configurator->oldFolders) > 0) { + // foreach (array_keys($GLOBALS['uploadFolders']) as $i) { + foreach (array_keys($configurator->oldFolders) as $i) { + $tempFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFolders[$i]); + /** @var XoopsObjectHandler $folderHandler */ + $folderHandler = \XoopsFile::getHandler('folder', $tempFolder); + $folderHandler->delete($tempFolder); + } + } + + // --- CREATE UPLOAD FOLDERS --------------- + if (count($configurator->uploadFolders) > 0) { + // foreach (array_keys($GLOBALS['uploadFolders']) as $i) { + foreach (array_keys($configurator->uploadFolders) as $i) { + $utility::createFolder($configurator->uploadFolders[$i]); + } + } + + // --- COPY blank.png FILES --------------- + if (count($configurator->copyBlankFiles) > 0) { + $file = dirname(__DIR__) . '/assets/images/blank.png'; + foreach (array_keys($configurator->copyBlankFiles) as $i) { + $dest = $configurator->copyBlankFiles[$i] . '/blank.png'; + $utility::copyFile($file, $dest); + } + } + + //delete .html entries from the tpl table + $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.html%'"; + $GLOBALS['xoopsDB']->queryF($sql); + + //delete .tpl entries from the tpl table + $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.tpl%'"; + $GLOBALS['xoopsDB']->queryF($sql); + + //delete tdmdownloads entries from the tpl_source table + $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplsource') . " WHERE `tpl_source` LIKE '%tdmdownloads%'"; + $GLOBALS['xoopsDB']->queryF($sql); + + $sql = 'CREATE TABLE `' . $GLOBALS['xoopsDB']->prefix('tdmdownloads_downlimit') . "` (downlimit_id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, downlimit_lid INT(11) UNSIGNED NOT NULL DEFAULT '0', + downlimit_uid INT(11) NOT NULL DEFAULT '0', downlimit_hostname VARCHAR(60) NOT NULL DEFAULT '', downlimit_date INT(10) NOT NULL DEFAULT '0', PRIMARY KEY (downlimit_id) + ) ENGINE=MyISAM"; + + $GLOBALS['xoopsDB']->query($sql); + + /** @var XoopsGroupPermHandler $gpermHandler */ + $gpermHandler = xoops_getHandler('groupperm'); + + return $gpermHandler->deleteByModule($module->getVar('mid'), 'item_read'); + +} + /** * @param $module - * * @return bool */ function update_tdmdownloads_v200(&$module) { - // Update size - $db = \XoopsDatabaseFactory::getDatabaseConnection(); - $sql = 'SELECT lid, size FROM ' . $db->prefix('tdmdownloads_downloads'); - $result = $db->query($sql); - $helper = \XoopsModules\Tdmdownloads\Helper::getInstance(); - $helper->loadLanguage('admin'); - while (false !== ($myrow = $db->fetchArray($result))) { - $size_value_arr = explode(' ', $myrow['size']); - switch ($size_value_arr[1]) { - case _AM_TDMDOWNLOADS_BYTES: - case 'Bytes': - $sql = 'UPDATE `' . $db->prefix('tdmdownloads_downloads') . '` SET `size` = \'' . $size_value_arr[0] . ' B\'' . ' WHERE `lid` = ' . $myrow['lid'] . ';'; - $db->query($sql); - break; - - case _AM_TDMDOWNLOADS_KBYTES: - case 'kB': - $sql = 'UPDATE `' . $db->prefix('tdmdownloads_downloads') . '` SET `size` = \'' . $size_value_arr[0] . ' K\'' . ' WHERE `lid` = ' . $myrow['lid'] . ';'; - $db->query($sql); - break; - - case _AM_TDMDOWNLOADS_MBYTES: - case 'MB': - $sql = 'UPDATE `' . $db->prefix('tdmdownloads_downloads') . '` SET `size` = \'' . $size_value_arr[0] . ' M\'' . ' WHERE `lid` = ' . $myrow['lid'] . ';'; - $db->query($sql); - break; - - case _AM_TDMDOWNLOADS_GBYTES: - case 'GB': - $sql = 'UPDATE `' . $db->prefix('tdmdownloads_downloads') . '` SET `size` = \'' . $size_value_arr[0] . ' G\'' . ' WHERE `lid` = ' . $myrow['lid'] . ';'; - $db->query($sql); - break; - - case _AM_TDMDOWNLOADS_TBYTES: - case 'TB': - $sql = 'UPDATE `' . $db->prefix('tdmdownloads_downloads') . '` SET `size` = \'' . $size_value_arr[0] . ' T\'' . ' WHERE `lid` = ' . $myrow['lid'] . ';'; - $db->query($sql); - break; - } - } - // Update folder - rename(XOOPS_ROOT_PATH . '/uploads/TDMDownloads', XOOPS_ROOT_PATH . '/uploads/tdmdownloads'); - // Change TDMDownloads with tdmdownloads - $sql = 'UPDATE `' . $db->prefix('tdmdownloads_downloads') . '` SET `url` = REPLACE(`url`, \'TDMDownloads\', \'tdmdownloads\') WHERE `url` LIKE \'%TDMDownloads%\''; - $result = $db->query($sql); - return true; + // Update size + + $moduleDirName = basename(dirname(__DIR__)); + $db = \XoopsDatabaseFactory::getDatabaseConnection(); + + $sql = 'SELECT lid, size FROM ' . $db->prefix('tdmdownloads_downloads'); + + $result = $db->query($sql); + + $helper = Helper::getInstance(); + + $helper->loadLanguage('admin'); + + if ($result instanceof \mysqli_result) { + while (false !== ($myrow = $db->fetchArray($result))) { + $size_value_arr = explode(' ', $myrow['size']); + + switch ($size_value_arr[1]) { + case _AM_TDMDOWNLOADS_BYTES: + case 'Bytes': + $sql = 'UPDATE `' . $db->prefix('tdmdownloads_downloads') . '` SET `size` = \'' . $size_value_arr[0] . ' B\'' . ' WHERE `lid` = ' . $myrow['lid'] . ';'; + $db->query($sql); + break; + case _AM_TDMDOWNLOADS_KBYTES: + case 'kB': + $sql = 'UPDATE `' . $db->prefix('tdmdownloads_downloads') . '` SET `size` = \'' . $size_value_arr[0] . ' K\'' . ' WHERE `lid` = ' . $myrow['lid'] . ';'; + $db->query($sql); + break; + case _AM_TDMDOWNLOADS_MBYTES: + case 'MB': + $sql = 'UPDATE `' . $db->prefix('tdmdownloads_downloads') . '` SET `size` = \'' . $size_value_arr[0] . ' M\'' . ' WHERE `lid` = ' . $myrow['lid'] . ';'; + $db->query($sql); + break; + case _AM_TDMDOWNLOADS_GBYTES: + case 'GB': + $sql = 'UPDATE `' . $db->prefix('tdmdownloads_downloads') . '` SET `size` = \'' . $size_value_arr[0] . ' G\'' . ' WHERE `lid` = ' . $myrow['lid'] . ';'; + $db->query($sql); + break; + case _AM_TDMDOWNLOADS_TBYTES: + case 'TB': + $sql = 'UPDATE `' . $db->prefix('tdmdownloads_downloads') . '` SET `size` = \'' . $size_value_arr[0] . ' T\'' . ' WHERE `lid` = ' . $myrow['lid'] . ';'; + $db->query($sql); + break; + } + } + } + // Update folder + + rename(XOOPS_ROOT_PATH . '/uploads/TDMDownloads', XOOPS_ROOT_PATH . '/uploads/' . $moduleDirName ); + + // Change TDMDownloads with tdmdownloads + + $sql = 'UPDATE `' . $db->prefix('tdmdownloads_downloads') . '` SET `url` = REPLACE(`url`, \'TDMDownloads\', \''. $moduleDirName.'\') WHERE `url` LIKE \'%TDMDownloads%\''; + + $result = $db->query($sql); + + return true; } /** * @param $module - * * @return bool */ function update_tdmdownloads_v167(&$module) { + $moduleDirName = basename(dirname(__DIR__)); // rename module dir from upper case to lower case - rename(XOOPS_ROOT_PATH . '/modules/TDMDownloads', XOOPS_ROOT_PATH . '/modules/tdmdownloads'); + + rename(XOOPS_ROOT_PATH . '/modules/TDMDownloads', XOOPS_ROOT_PATH . '/modules/' . $moduleDirName); + // rename upload dir from upper case to lower case - rename(XOOPS_ROOT_PATH . '/uploads/TDMDownloads', XOOPS_ROOT_PATH . '/uploads/tdmdownloads'); + + rename(XOOPS_ROOT_PATH . '/uploads/TDMDownloads', XOOPS_ROOT_PATH . '/uploads/' . $moduleDirName); // files have been moved to assets-folder - $src = XOOPS_ROOT_PATH . '/modules/tdmdownloads/css/'; + + $src = XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/css/'; rrmdir($src); - $src = XOOPS_ROOT_PATH . '/modules/tdmdownloads/images/'; + + $src = XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/images/'; rrmdir($src); // delete unneeded/replacfiles - // unlink( XOOPS_ROOT_PATH.'/modules/tdmdownloads/admin/admin_header.php' ); + + // unlink( XOOPS_ROOT_PATH.'/modules/' . $moduleDirName . '/admin/admin_header.php' ); // clean template directory - @unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_brokenfile.html'); - @unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_download.html'); - @unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_index.html'); - @unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_modfile.html'); - @unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_ratefile.html'); - @unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_singlefile.html'); - @unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_submit.html'); - @unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_viewcat.html'); - @unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_liste.html'); - @unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_rss.html'); - @unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/blocks/tdmdownloads_block_new.html'); - @unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/blocks/tdmdownloads_block_random.html'); - @unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/blocks/tdmdownloads_block_rating.html'); - @unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/blocks/tdmdownloads_block_search.html'); - @unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/blocks/tdmdownloads_block_top.html'); + + @unlink(XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/templates/tdmdownloads_brokenfile.html'); + @unlink(XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/templates/tdmdownloads_download.html'); + @unlink(XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/templates/tdmdownloads_index.html'); + @unlink(XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/templates/tdmdownloads_modfile.html'); + @unlink(XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/templates/tdmdownloads_ratefile.html'); + @unlink(XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/templates/tdmdownloads_singlefile.html'); + @unlink(XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/templates/tdmdownloads_submit.html'); + @unlink(XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/templates/tdmdownloads_viewcat.html'); + @unlink(XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/templates/tdmdownloads_liste.html'); + @unlink(XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/templates/tdmdownloads_rss.html'); + @unlink(XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/templates/blocks/tdmdownloads_block_new.html'); + @unlink(XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/templates/blocks/tdmdownloads_block_random.html'); + @unlink(XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/templates/blocks/tdmdownloads_block_rating.html'); + @unlink(XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/templates/blocks/tdmdownloads_block_search.html'); + @unlink(XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/templates/blocks/tdmdownloads_block_top.html'); return true; } @@ -141,9 +326,11 @@ function rrmdir($src) { if (is_dir($src)) { $dir = opendir($src); + while (false !== ($file = readdir($dir))) { if (('.' !== $file) && ('..' !== $file)) { $full = $src . '/' . $file; + if (is_dir($full)) { rrmdir($full); } else { @@ -151,7 +338,9 @@ function rrmdir($src) } } } + closedir($dir); + rmdir($src); } } @@ -162,28 +351,49 @@ function rrmdir($src) function update_tdmdownloads_v163() { /** @var \XoopsMySQLDatabase $db */ - $db = \XoopsDatabaseFactory::getDatabaseConnection(); + + $db = \XoopsDatabaseFactory::getDatabaseConnection(); + $sql = 'ALTER TABLE `' . $db->prefix('tdmdownloads_cat') . '` CHANGE `cid` `cat_cid` INT( 5 ) UNSIGNED NOT NULL AUTO_INCREMENT ;'; + $db->query($sql); + $sql = 'ALTER TABLE `' . $db->prefix('tdmdownloads_cat') . "` CHANGE `pid` `cat_pid` INT( 5 ) UNSIGNED NOT NULL DEFAULT '0' ;"; + $db->query($sql); + $sql = 'ALTER TABLE `' . $db->prefix('tdmdownloads_cat') . '` CHANGE `title` `cat_title` VARCHAR( 255 ) NOT NULL ;'; + $db->query($sql); + $sql = 'ALTER TABLE `' . $db->prefix('tdmdownloads_cat') . '` CHANGE `imgurl` `cat_imgurl` VARCHAR( 255 ) NOT NULL ;'; + $db->query($sql); + $sql = 'ALTER TABLE `' . $db->prefix('tdmdownloads_cat') . '` CHANGE `description_main` `cat_description_main` TEXT NOT NULL ;'; + $db->query($sql); + $sql = 'ALTER TABLE `' . $db->prefix('tdmdownloads_cat') . "` CHANGE `weight` `cat_weight` INT( 11 ) NOT NULL DEFAULT '0' ;"; + $db->query($sql); + $sql = 'ALTER TABLE `' . $db->prefix('tdmdownloads_downloads') . '` ADD `paypal` VARCHAR( 255 ) NOT NULL;'; + $db->query($sql); + $sql = 'ALTER TABLE `' . $db->prefix('tdmdownloads_downloads') . "` CHANGE `size` `size` VARCHAR( 15 ) NOT NULL DEFAULT '';"; + $db->query($sql); + $sql = 'ALTER TABLE `' . $db->prefix('tdmdownloads_mod') . "` CHANGE `size` `size` VARCHAR( 15 ) NOT NULL DEFAULT '';"; + $db->query($sql); + $sql = 'CREATE TABLE `' . $db->prefix('tdmdownloads_downlimit') . "` (downlimit_id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, downlimit_lid INT(11) UNSIGNED NOT NULL DEFAULT '0', downlimit_uid INT(11) NOT NULL DEFAULT '0', downlimit_hostname VARCHAR(60) NOT NULL DEFAULT '', downlimit_date INT(10) NOT NULL DEFAULT '0', PRIMARY KEY (downlimit_id) ) ENGINE=MyISAM"; + $db->query($sql); return true; diff --git a/include/search.inc.php b/include/search.inc.php index c8a542c..12c652d 100644 --- a/include/search.inc.php +++ b/include/search.inc.php @@ -1,4 +1,5 @@ -prefix('tdmdownloads_downloads') . ' WHERE status != 0'; @@ -33,9 +35,12 @@ function tdmdownloads_search($queryarray, $andor, $limit, $offset, $userid) $sql .= ' AND submitter=' . (int)$userid . ' '; } - $utility = new \XoopsModules\Tdmdownloads\Utility(); + $utility = new \XoopsModules\Tdmdownloads\Utility(); + $categories = $utility->getItemIds('tdmdownloads_view', $moduleDirName); -// if (is_array($categories) && count($categories) > 0) { + + // if (is_array($categories) && count($categories) > 0) { + if ($categories && is_array($categories)) { $sql .= ' AND cid IN (' . implode(',', $categories) . ') '; } else { @@ -47,23 +52,34 @@ function tdmdownloads_search($queryarray, $andor, $limit, $offset, $userid) for ($i = 1; $i < $count; ++$i) { $sql .= " $andor "; + $sql .= "(title LIKE '%$queryarray[$i]%' OR description LIKE '%$queryarray[$i]%')"; } + $sql .= ')'; } - $sql .= ' ORDER BY date DESC'; + $sql .= ' ORDER BY date DESC'; + $result = $xoopsDB->query($sql, $limit, $offset); - $ret = []; - $i = 0; - while (false !== ($myrow = $xoopsDB->fetchArray($result))) { - $ret[$i]['image'] = 'assets/images/deco/tdmdownloads_search.png'; - $ret[$i]['link'] = 'singlefile.php?cid=' . $myrow['cid'] . '&lid=' . $myrow['lid'] . ''; - $ret[$i]['title'] = $myrow['title']; - $ret[$i]['time'] = $myrow['date']; - $ret[$i]['uid'] = $myrow['submitter']; - ++$i; - } + $ret = []; + + $i = 0; + if ($result instanceof \mysqli_result) { + while (false !== ($myrow = $xoopsDB->fetchArray($result))) { + $ret[$i]['image'] = 'assets/images/deco/tdmdownloads_search.png'; + + $ret[$i]['link'] = 'singlefile.php?cid=' . $myrow['cid'] . '&lid=' . $myrow['lid'] . ''; + + $ret[$i]['title'] = $myrow['title']; + + $ret[$i]['time'] = $myrow['date']; + + $ret[$i]['uid'] = $myrow['submitter']; + + ++$i; + } + } return $ret; } diff --git a/include/xoops_version.inc.php b/include/xoops_version.inc.php deleted file mode 100644 index f4f87eb..0000000 --- a/include/xoops_version.inc.php +++ /dev/null @@ -1,36 +0,0 @@ -setOrder('ASC'); $criteria->add(new \Criteria('cat_cid', '(' . implode(',', $categories) . ')', 'IN')); $downloadscatArray = $categoryHandler->getAll($criteria); -$mytree = new \XoopsModules\Tdmdownloads\Tree($downloadscatArray, 'cat_cid', 'cat_pid'); +$mytree = new Tree($downloadscatArray, 'cat_cid', 'cat_pid'); //affichage des catégories $xoopsTpl->assign('nb_catcol', $helper->getConfig('nb_catcol')); @@ -48,33 +54,50 @@ $keywords = ''; foreach (array_keys($downloadscatArray) as $i) { /** @var \XoopsModules\Tdmdownloads\Category[] $downloadscatArray */ + if (0 === $downloadscatArray[$i]->getVar('cat_pid')) { - $totaldownloads = $utility->getNumbersOfEntries($mytree, $categories, $downloadsArray, $downloadscatArray[$i]->getVar('cat_cid')); + $totaldownloads = $utility->getNumbersOfEntries($mytree, $categories, $downloadsArray, $downloadscatArray[$i]->getVar('cat_cid')); + $subcategories_arr = $mytree->getFirstChild($downloadscatArray[$i]->getVar('cat_cid')); - $chcount = 0; - $subcategories = ''; + + $chcount = 0; + + $subcategories = ''; + //pour les mots clef + $keywords .= $downloadscatArray[$i]->getVar('cat_title') . ','; + foreach (array_keys($subcategories_arr) as $j) { /** @var \XoopsModules\Tdmdownloads\Category[] $subcategories_arr */ + if ($chcount >= $helper->getConfig('nbsouscat')) { $subcategories .= '
  • [+]
  • '; + break; } + $subcategories .= '
  • ' . $subcategories_arr[$j]->getVar('cat_title') . '
  • '; - $keywords .= $downloadscatArray[$i]->getVar('cat_title') . ','; + + $keywords .= $downloadscatArray[$i]->getVar('cat_title') . ','; + ++$chcount; } - $xoopsTpl->append('categories', [ - 'image' => $uploadurl . $downloadscatArray[$i]->getVar('cat_imgurl'), - 'id' => $downloadscatArray[$i]->getVar('cat_cid'), - 'title' => $downloadscatArray[$i]->getVar('cat_title'), - 'description_main' => $downloadscatArray[$i]->getVar('cat_description_main'), - 'subcategories' => $subcategories, - 'countsubs' => count($subcategories_arr), - 'totaldownloads' => $totaldownloads, - 'count' => $count, - ]); + + $xoopsTpl->append( + 'categories', + [ + 'image' => $uploadurl . $downloadscatArray[$i]->getVar('cat_imgurl'), + 'id' => $downloadscatArray[$i]->getVar('cat_cid'), + 'title' => $downloadscatArray[$i]->getVar('cat_title'), + 'description_main' => $downloadscatArray[$i]->getVar('cat_description_main'), + 'subcategories' => $subcategories, + 'countsubs' => count($subcategories_arr), + 'totaldownloads' => $totaldownloads, + 'count' => $count, + ] + ); + ++$count; } } @@ -84,76 +107,117 @@ //téléchargements récents if (1 == $helper->getConfig('bldate')) { $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('status', 0, '!=')); + $criteria->add(new \Criteria('cid', '(' . implode(',', $categories) . ')', 'IN')); + $criteria->setSort('date'); + $criteria->setOrder('DESC'); + $criteria->setLimit($helper->getConfig('nbbl')); + $downloads_arr_date = $downloadsHandler->getAll($criteria); + foreach (array_keys($downloads_arr_date) as $i) { /** @var \XoopsModules\Tdmdownloads\Downloads[] $downloads_arr_date */ + $title = $downloads_arr_date[$i]->getVar('title'); + if (mb_strlen($title) >= $helper->getConfig('longbl')) { $title = mb_substr($title, 0, $helper->getConfig('longbl')) . '...'; } + $date = formatTimestamp($downloads_arr_date[$i]->getVar('date'), 's'); - $xoopsTpl->append('bl_date', [ - 'id' => $downloads_arr_date[$i]->getVar('lid'), - 'cid' => $downloads_arr_date[$i]->getVar('cid'), - 'date' => $date, - 'title' => $title, - ]); + + $xoopsTpl->append( + 'bl_date', + [ + 'id' => $downloads_arr_date[$i]->getVar('lid'), + 'cid' => $downloads_arr_date[$i]->getVar('cid'), + 'date' => $date, + 'title' => $title, + ] + ); } } //plus téléchargés if (1 == $helper->getConfig('blpop')) { $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('status', 0, '!=')); + $criteria->add(new \Criteria('cid', '(' . implode(',', $categories) . ')', 'IN')); + $criteria->setSort('hits'); + $criteria->setOrder('DESC'); + $criteria->setLimit($helper->getConfig('nbbl')); + $downloads_arr_hits = $downloadsHandler->getAll($criteria); + foreach (array_keys($downloads_arr_hits) as $i) { /** @var \XoopsModules\Tdmdownloads\Downloads[] $downloads_arr_hits */ + $title = $downloads_arr_hits[$i]->getVar('title'); + if (mb_strlen($title) >= $helper->getConfig('longbl')) { $title = mb_substr($title, 0, $helper->getConfig('longbl')) . '...'; } - $xoopsTpl->append('bl_pop', [ - 'id' => $downloads_arr_hits[$i]->getVar('lid'), - 'cid' => $downloads_arr_hits[$i]->getVar('cid'), - 'hits' => $downloads_arr_hits[$i]->getVar('hits'), - 'title' => $title, - ]); + + $xoopsTpl->append( + 'bl_pop', + [ + 'id' => $downloads_arr_hits[$i]->getVar('lid'), + 'cid' => $downloads_arr_hits[$i]->getVar('cid'), + 'hits' => $downloads_arr_hits[$i]->getVar('hits'), + 'title' => $title, + ] + ); } } //mieux notés if (1 == $helper->getConfig('blrating')) { $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('status', 0, '!=')); + $criteria->add(new \Criteria('cid', '(' . implode(',', $categories) . ')', 'IN')); + $criteria->setSort('rating'); + $criteria->setOrder('DESC'); + $criteria->setLimit($helper->getConfig('nbbl')); + $downloads_arr_rating = $downloadsHandler->getAll($criteria); + foreach (array_keys($downloads_arr_rating) as $i) { /** @var \XoopsModules\Tdmdownloads\Downloads[] $downloads_arr_rating */ + $title = $downloads_arr_rating[$i]->getVar('title'); + if (mb_strlen($title) >= $helper->getConfig('longbl')) { $title = mb_substr($title, 0, $helper->getConfig('longbl')) . '...'; } - $rating = number_format($downloads_arr_rating[$i]->getVar('rating'), 1); - $xoopsTpl->append('bl_rating', [ - 'id' => $downloads_arr_rating[$i]->getVar('lid'), - 'cid' => $downloads_arr_rating[$i]->getVar('cid'), - 'rating' => $rating, - 'title' => $title, - ]); + + $rating = number_format((float)$downloads_arr_rating[$i]->getVar('rating'), 1); + + $xoopsTpl->append( + 'bl_rating', + [ + 'id' => $downloads_arr_rating[$i]->getVar('lid'), + 'cid' => $downloads_arr_rating[$i]->getVar('cid'), + 'rating' => $rating, + 'title' => $title, + ] + ); } } $bl_affichage = 1; -if (0 == $helper->getConfig('bldate') && 0 == $helper->getConfig('blpop') && 0 == $helper->getConfig('blrating')) { +if (0 === $helper->getConfig('bldate') && 0 === $helper->getConfig('blpop') && 0 === $helper->getConfig('blrating')) { $bl_affichage = 0; } $xoopsTpl->assign('bl_affichage', $bl_affichage); @@ -164,65 +228,112 @@ // affichage des téléchargements if ($helper->getConfig('newdownloads') > 0) { $xoopsTpl->assign('nb_dowcol', $helper->getConfig('nb_dowcol')); + //Utilisation d'une copie d'écran avec la largeur selon les préférences + if (1 == $helper->getConfig('useshots')) { $xoopsTpl->assign('shotwidth', $helper->getConfig('shotwidth')); + $xoopsTpl->assign('show_screenshot', true); + $xoopsTpl->assign('img_float', $helper->getConfig('img_float')); } + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('status', 0, '!=')); + $criteria->add(new \Criteria('cid', '(' . implode(',', $categories) . ')', 'IN')); + $criteria->setLimit($helper->getConfig('newdownloads')); - $tblsort = []; - $tblsort[1] = 'date'; - $tblsort[2] = 'date'; - $tblsort[3] = 'hits'; - $tblsort[4] = 'hits'; - $tblsort[5] = 'rating'; - $tblsort[6] = 'rating'; - $tblsort[7] = 'title'; - $tblsort[8] = 'title'; - $tblorder = []; + + $tblsort = []; + + $tblsort[1] = 'date'; + + $tblsort[2] = 'date'; + + $tblsort[3] = 'hits'; + + $tblsort[4] = 'hits'; + + $tblsort[5] = 'rating'; + + $tblsort[6] = 'rating'; + + $tblsort[7] = 'title'; + + $tblsort[8] = 'title'; + + $tblorder = []; + $tblorder[1] = 'DESC'; + $tblorder[2] = 'ASC'; + $tblorder[3] = 'DESC'; + $tblorder[4] = 'ASC'; + $tblorder[5] = 'DESC'; + $tblorder[6] = 'ASC'; + $tblorder[7] = 'DESC'; + $tblorder[8] = 'ASC'; - $sort = null !== $helper->getConfig('toporder') ? $helper->getConfig('toporder') : 1; - $order = null !== $helper->getConfig('toporder') ? $helper->getConfig('toporder') : 1; + + $sort = $helper->getConfig('toporder') ?? 1; + + $order = $helper->getConfig('toporder') ?? 1; + $criteria->setSort($tblsort[$sort]); + $criteria->setOrder($tblorder[$order]); + $downloadsArray = $downloadsHandler->getAll($criteria); - $categories = $utility->getItemIds('tdmdownloads_download', $moduleDirName); - $item = $utility->getItemIds('tdmdownloads_download_item', $moduleDirName); - $count = 1; + + $categories = $utility->getItemIds('tdmdownloads_download', $moduleDirName); + + $item = $utility->getItemIds('tdmdownloads_download_item', $moduleDirName); + + $count = 1; + foreach (array_keys($downloadsArray) as $i) { /** @var \XoopsModules\Tdmdownloads\Downloads[] $downloadsArray */ + if ('blank.gif' === $downloadsArray[$i]->getVar('logourl')) { $logourl = ''; } else { $logourl = $downloadsArray[$i]->getVar('logourl'); + $logourl = $uploadurl_shots . $logourl; } - $datetime = formatTimestamp($downloadsArray[$i]->getVar('date'), 's'); - $submitter = \XoopsUser::getUnameFromId($downloadsArray[$i]->getVar('submitter')); + + $datetime = formatTimestamp($downloadsArray[$i]->getVar('date'), 's'); + + $submitter = \XoopsUser::getUnameFromId($downloadsArray[$i]->getVar('submitter')); + $description = $downloadsArray[$i]->getVar('description'); + //permet d'afficher uniquement la description courte + if (false === mb_strpos($description, '[pagebreak]')) { $descriptionShort = $description; } else { $descriptionShort = mb_substr($description, 0, mb_strpos($description, '[pagebreak]')); } + // pour les vignettes "new" et "mis à jour" + $new = $utility->getStatusImage($downloadsArray[$i]->getVar('date'), $downloadsArray[$i]->getVar('status')); + $pop = $utility->getPopularImage($downloadsArray[$i]->getVar('hits')); // Défini si la personne est un admin + $adminlink = ''; + if (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->mid())) { $adminlink = ''; } + //permission de télécharger $downloadPermission = true; + if (1 === $helper->getConfig('permission_download')) { - if (!in_array($downloadsArray[$i]->getVar('cid'), $categories, true)) { + if (!in_array($downloadsArray[$i]->getVar('cid'), $categories)) { $downloadPermission = false; } } else { - if (!in_array($downloadsArray[$i]->getVar('lid'), $item, true)) { + if (!in_array($downloadsArray[$i]->getVar('lid'), $item)) { $downloadPermission = false; } } - $xoopsTpl->append('file', [ - 'id' => $downloadsArray[$i]->getVar('lid'), - 'cid' => $downloadsArray[$i]->getVar('cid'), - 'title' => $downloadsArray[$i]->getVar('title'), - 'rating' => $downloadsArray[$i]->getVar('rating'), - 'hits' => $downloadsArray[$i]->getVar('hits'), - 'new' => $new, - 'pop' => $pop, - 'logourl' => $logourl, - 'updated' => $datetime, - 'description_short' => $descriptionShort, - 'adminlink' => $adminlink, - 'submitter' => $submitter, - 'perm_download' => $downloadPermission, - 'count' => $count, - ]); + + $xoopsTpl->append( + 'file', + [ + 'id' => $downloadsArray[$i]->getVar('lid'), + 'cid' => $downloadsArray[$i]->getVar('cid'), + 'title' => $downloadsArray[$i]->getVar('title'), + 'rating' => $downloadsArray[$i]->getVar('rating'), + 'hits' => $downloadsArray[$i]->getVar('hits'), + 'new' => $new, + 'pop' => $pop, + 'logourl' => $logourl, + 'updated' => $datetime, + 'description_short' => $descriptionShort, + 'adminlink' => $adminlink, + 'submitter' => $submitter, + 'perm_download' => $downloadPermission, + 'count' => $count, + ] + ); + //pour les mots clef + $keywords .= $downloadsArray[$i]->getVar('title') . ','; + ++$count; } } diff --git a/language/english/admin.php b/language/english/admin.php index 599218a..c67db94 100644 --- a/language/english/admin.php +++ b/language/english/admin.php @@ -1,4 +1,5 @@ -Attention !

    Import will delete all data in TDMDownloads. It's highly recommended that you make a backup of all your data first, as well as of your website.

    TDM is not responsible if you lose your data. Unfortunately, the screen shots cannot be copied." + "Attention !

    Import will delete all data in TDMDownloads. It's highly recommended that you make a backup of all your data first, as well as of your website.

    TDM is not responsible if you lose your data. Unfortunately, the screen shots cannot be copied." ); define('_AM_TDMDOWNLOADS_IMPORT_WFDOWNLOADS', 'Import from WF Downloads (only for V3.23 RC5)'); define('_AM_TDMDOWNLOADS_IMPORT_WFDOWNLOADS_CATIMG', 'Select Upload Directory (the path) for categories images of WF-Downloads'); @@ -122,7 +124,8 @@ define('_AM_TDMDOWNLOADS_FORMPLATFORM', 'Platform: '); define('_AM_TDMDOWNLOADS_FORMPOSTER', 'Posted by '); define('_AM_TDMDOWNLOADS_FORMRATING', 'Note'); -define('_AM_TDMDOWNLOADS_FORMSIZE', "File Size
    To use the automatic system for calculating the file size, leave this field empty."); +define('_AM_TDMDOWNLOADS_FORMSIZE', "File Size"); +define('_AM_TDMDOWNLOADS_FORMSIZE_WHEN_SUBMIT', "File Size
    To use the automatic system for calculating the file size, leave this field empty."); define('_AM_TDMDOWNLOADS_FORMSTATUS', 'Download Status'); define('_AM_TDMDOWNLOADS_FORMSTATUS_OK', 'Approved'); define('_AM_TDMDOWNLOADS_FORMSUBMITTER', 'Posted by'); @@ -185,3 +188,5 @@ define('_AM_TDMDOWNLOADS_ERROR_BAD_REMOVE', 'Could not delete %s'); define('_AM_TDMDOWNLOADS_ERROR_NO_PLUGIN', 'Could not load plugin'); define('_AM_TDMDOWNLOADS_NUMBYTES', '%s bytes'); +//multi-upload +define('_AM_TDMDOWNLOADS_DOWNLOADS_NEW_MULTIUPLOAD', 'New Multi-upload'); diff --git a/language/english/blocks.php b/language/english/blocks.php index 81f6547..76d4375 100644 --- a/language/english/blocks.php +++ b/language/english/blocks.php @@ -1,4 +1,5 @@ -Disabled (No thumbnails available)"); -define('CO_' . $moduleDirNameUpper . '_GDON', "Enabled (Thumbsnails available)"); -define('CO_' . $moduleDirNameUpper . '_IMAGEINFO', 'Server status'); -define('CO_' . $moduleDirNameUpper . '_MAXPOSTSIZE', 'Max post size permitted (post_max_size directive in php.ini): '); -define('CO_' . $moduleDirNameUpper . '_MAXUPLOADSIZE', 'Max upload size permitted (upload_max_filesize directive in php.ini): '); -define('CO_' . $moduleDirNameUpper . '_MEMORYLIMIT', 'Memory limit (memory_limit directive in php.ini): '); -define('CO_' . $moduleDirNameUpper . '_METAVERSION', "Downloads meta version: "); -define('CO_' . $moduleDirNameUpper . '_OFF', "OFF"); -define('CO_' . $moduleDirNameUpper . '_ON', "ON"); -define('CO_' . $moduleDirNameUpper . '_SERVERPATH', 'Server path to XOOPS root: '); -define('CO_' . $moduleDirNameUpper . '_SERVERUPLOADSTATUS', 'Server uploads status: '); -define('CO_' . $moduleDirNameUpper . '_SPHPINI', "Information taken from PHP ini file:"); -define('CO_' . $moduleDirNameUpper . '_UPLOADPATHDSC', 'Note. Upload path *MUST* contain the full server path of your upload folder.'); - -define('CO_' . $moduleDirNameUpper . '_PRINT', "Print"); -define('CO_' . $moduleDirNameUpper . '_PDF', "Create PDF"); - -define('CO_' . $moduleDirNameUpper . '_UPGRADEFAILED0', "Update failed - couldn't rename field '%s'"); -define('CO_' . $moduleDirNameUpper . '_UPGRADEFAILED1', "Update failed - couldn't add new fields"); -define('CO_' . $moduleDirNameUpper . '_UPGRADEFAILED2', "Update failed - couldn't rename table '%s'"); -define('CO_' . $moduleDirNameUpper . '_ERROR_COLUMN', 'Could not create column in database : %s'); -define('CO_' . $moduleDirNameUpper . '_ERROR_BAD_XOOPS', 'This module requires XOOPS %s+ (%s installed)'); -define('CO_' . $moduleDirNameUpper . '_ERROR_BAD_PHP', 'This module requires PHP version %s+ (%s installed)'); -define('CO_' . $moduleDirNameUpper . '_ERROR_TAG_REMOVAL', 'Could not remove tags from Tag Module'); - -define('CO_' . $moduleDirNameUpper . '_FOLDERS_DELETED_OK', 'Upload Folders have been deleted'); +$moduleDirName = basename(dirname(__DIR__, 2)); +$moduleDirNameUpper = \mb_strtoupper($moduleDirName); + +\define('CO_' . $moduleDirNameUpper . '_GDLIBSTATUS', 'GD library support: '); +\define('CO_' . $moduleDirNameUpper . '_GDLIBVERSION', 'GD Library version: '); +\define('CO_' . $moduleDirNameUpper . '_GDOFF', "Disabled (No thumbnails available)"); +\define('CO_' . $moduleDirNameUpper . '_GDON', "Enabled (Thumbsnails available)"); +\define('CO_' . $moduleDirNameUpper . '_IMAGEINFO', 'Server status'); +\define('CO_' . $moduleDirNameUpper . '_MAXPOSTSIZE', 'Max post size permitted (post_max_size directive in php.ini): '); +\define('CO_' . $moduleDirNameUpper . '_MAXUPLOADSIZE', 'Max upload size permitted (upload_max_filesize directive in php.ini): '); +\define('CO_' . $moduleDirNameUpper . '_MEMORYLIMIT', 'Memory limit (memory_limit directive in php.ini): '); +\define('CO_' . $moduleDirNameUpper . '_METAVERSION', "Downloads meta version: "); +\define('CO_' . $moduleDirNameUpper . '_OFF', "OFF"); +\define('CO_' . $moduleDirNameUpper . '_ON', "ON"); +\define('CO_' . $moduleDirNameUpper . '_SERVERPATH', 'Server path to XOOPS root: '); +\define('CO_' . $moduleDirNameUpper . '_SERVERUPLOADSTATUS', 'Server uploads status: '); +\define('CO_' . $moduleDirNameUpper . '_SPHPINI', "Information taken from PHP ini file:"); +\define('CO_' . $moduleDirNameUpper . '_UPLOADPATHDSC', 'Note. Upload path *MUST* contain the full server path of your upload folder.'); + +\define('CO_' . $moduleDirNameUpper . '_PRINT', "Print"); +\define('CO_' . $moduleDirNameUpper . '_PDF', "Create PDF"); + +\define('CO_' . $moduleDirNameUpper . '_UPGRADEFAILED0', "Update failed - couldn't rename field '%s'"); +\define('CO_' . $moduleDirNameUpper . '_UPGRADEFAILED1', "Update failed - couldn't add new fields"); +\define('CO_' . $moduleDirNameUpper . '_UPGRADEFAILED2', "Update failed - couldn't rename table '%s'"); +\define('CO_' . $moduleDirNameUpper . '_ERROR_COLUMN', 'Could not create column in database : %s'); +\define('CO_' . $moduleDirNameUpper . '_ERROR_BAD_XOOPS', 'This module requires XOOPS %s+ (%s installed)'); +\define('CO_' . $moduleDirNameUpper . '_ERROR_BAD_PHP', 'This module requires PHP version %s+ (%s installed)'); +\define('CO_' . $moduleDirNameUpper . '_ERROR_TAG_REMOVAL', 'Could not remove tags from Tag Module'); + +\define('CO_' . $moduleDirNameUpper . '_FOLDERS_DELETED_OK', 'Upload Folders have been deleted'); // Error Msgs -define('CO_' . $moduleDirNameUpper . '_ERROR_BAD_DEL_PATH', 'Could not delete %s directory'); -define('CO_' . $moduleDirNameUpper . '_ERROR_BAD_REMOVE', 'Could not delete %s'); -define('CO_' . $moduleDirNameUpper . '_ERROR_NO_PLUGIN', 'Could not load plugin'); +\define('CO_' . $moduleDirNameUpper . '_ERROR_BAD_DEL_PATH', 'Could not delete %s directory'); +\define('CO_' . $moduleDirNameUpper . '_ERROR_BAD_REMOVE', 'Could not delete %s'); +\define('CO_' . $moduleDirNameUpper . '_ERROR_NO_PLUGIN', 'Could not load plugin'); //Help -define('CO_' . $moduleDirNameUpper . '_DIRNAME', basename(dirname(dirname(__DIR__)))); -define('CO_' . $moduleDirNameUpper . '_HELP_HEADER', __DIR__ . '/help/helpheader.tpl'); -define('CO_' . $moduleDirNameUpper . '_BACK_2_ADMIN', 'Back to Administration of '); -define('CO_' . $moduleDirNameUpper . '_OVERVIEW', 'Overview'); +\define('CO_' . $moduleDirNameUpper . '_DIRNAME', basename(dirname(__DIR__, 2))); +\define('CO_' . $moduleDirNameUpper . '_HELP_HEADER', __DIR__ . '/help/helpheader.tpl'); +\define('CO_' . $moduleDirNameUpper . '_BACK_2_ADMIN', 'Back to Administration of '); +\define('CO_' . $moduleDirNameUpper . '_OVERVIEW', 'Overview'); -//define('CO_' . $moduleDirNameUpper . '_HELP_DIR', __DIR__); +//\define('CO_' . $moduleDirNameUpper . '_HELP_DIR', __DIR__); //help multi-page -define('CO_' . $moduleDirNameUpper . '_DISCLAIMER', 'Disclaimer'); -define('CO_' . $moduleDirNameUpper . '_LICENSE', 'License'); -define('CO_' . $moduleDirNameUpper . '_SUPPORT', 'Support'); +\define('CO_' . $moduleDirNameUpper . '_DISCLAIMER', 'Disclaimer'); +\define('CO_' . $moduleDirNameUpper . '_LICENSE', 'License'); +\define('CO_' . $moduleDirNameUpper . '_SUPPORT', 'Support'); //Sample Data -define('CO_' . $moduleDirNameUpper . '_' . 'ADD_SAMPLEDATA', 'Import Sample Data (will delete ALL current data)'); -define('CO_' . $moduleDirNameUpper . '_' . 'SAMPLEDATA_SUCCESS', 'Sample Date uploaded successfully'); -define('CO_' . $moduleDirNameUpper . '_' . 'SAVE_SAMPLEDATA', 'Export Tables to YAML'); -define('CO_' . $moduleDirNameUpper . '_' . 'SHOW_SAMPLE_BUTTON', 'Show Sample Button?'); -define('CO_' . $moduleDirNameUpper . '_' . 'SHOW_SAMPLE_BUTTON_DESC', 'If yes, the "Add Sample Data" button will be visible to the Admin. It is Yes as a default for first installation.'); -define('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA', 'Export DB Schema to YAML'); -define('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA_SUCCESS', 'Export DB Schema to YAML was a success'); -define('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA_ERROR', 'ERROR: Export of DB Schema to YAML failed'); +\define('CO_' . $moduleDirNameUpper . '_' . 'LOAD_SAMPLEDATA', 'Import Sample Data (will delete ALL current data)'); +\define('CO_' . $moduleDirNameUpper . '_' . 'LOAD_SAMPLEDATA_CONFIRM', 'Are you sure to Import Sample Data? (It will delete ALL current data)'); +\define('CO_' . $moduleDirNameUpper . '_' . 'LOAD_SAMPLEDATA_SUCCESS', 'Sample Date saved successfully'); +\define('CO_' . $moduleDirNameUpper . '_' . 'SAVE_SAMPLEDATA', 'Export Tables to YAML'); +\define('CO_' . $moduleDirNameUpper . '_' . 'SAVE_SAMPLEDATA_SUCCESS', 'Export Tables to YAML successfully'); +\define('CO_' . $moduleDirNameUpper . '_' . 'CLEAR_SAMPLEDATA', 'Clear the Sample Data'); +\define('CO_' . $moduleDirNameUpper . '_' . 'CLEAR_SAMPLEDATA_OK', 'The Sample Data has been cleared'); +\define('CO_' . $moduleDirNameUpper . '_' . 'CLEAR_SAMPLEDATA_CONFIRM', 'Are you sure to Clear Sample Data? (It will delete ALL current data)'); +\define('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA', 'Export DB Schema to YAML'); +\define('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA_SUCCESS', 'Export DB Schema to YAML was a success'); +\define('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA_ERROR', 'ERROR: Export of DB Schema to YAML failed'); +\define('CO_' . $moduleDirNameUpper . '_' . 'SHOW_SAMPLE_BUTTON', 'Show Sample Button?'); +\define('CO_' . $moduleDirNameUpper . '_' . 'SHOW_SAMPLE_BUTTON_DESC', 'If yes, the "Add Sample Data" button will be visible to the Admin. It is Yes as a default for first installation.'); +\define('CO_' . $moduleDirNameUpper . '_' . 'HIDE_SAMPLEDATA_BUTTONS', 'Hide the Import buttons)'); +\define('CO_' . $moduleDirNameUpper . '_' . 'SHOW_SAMPLEDATA_BUTTONS', 'Show the Import buttons)'); + +\define('CO_' . $moduleDirNameUpper . '_' . 'CONFIRM', 'Confirm'); //letter choice -define('CO_' . $moduleDirNameUpper . '_' . 'BROWSETOTOPIC', "Browse items alphabetically"); -define('CO_' . $moduleDirNameUpper . '_' . 'OTHER', 'Other'); -define('CO_' . $moduleDirNameUpper . '_' . 'ALL', 'All'); +\define('CO_' . $moduleDirNameUpper . '_' . 'BROWSETOTOPIC', "Browse items alphabetically"); +\define('CO_' . $moduleDirNameUpper . '_' . 'OTHER', 'Other'); +\define('CO_' . $moduleDirNameUpper . '_' . 'ALL', 'All'); // block defines -define('CO_' . $moduleDirNameUpper . '_' . 'ACCESSRIGHTS', 'Access Rights'); -define('CO_' . $moduleDirNameUpper . '_' . 'ACTION', 'Action'); -define('CO_' . $moduleDirNameUpper . '_' . 'ACTIVERIGHTS', 'Active Rights'); -define('CO_' . $moduleDirNameUpper . '_' . 'BADMIN', 'Block Administration'); -define('CO_' . $moduleDirNameUpper . '_' . 'BLKDESC', 'Description'); -define('CO_' . $moduleDirNameUpper . '_' . 'CBCENTER', 'Center Middle'); -define('CO_' . $moduleDirNameUpper . '_' . 'CBLEFT', 'Center Left'); -define('CO_' . $moduleDirNameUpper . '_' . 'CBRIGHT', 'Center Right'); -define('CO_' . $moduleDirNameUpper . '_' . 'SBLEFT', 'Left'); -define('CO_' . $moduleDirNameUpper . '_' . 'SBRIGHT', 'Right'); -define('CO_' . $moduleDirNameUpper . '_' . 'SIDE', 'Alignment'); -define('CO_' . $moduleDirNameUpper . '_' . 'TITLE', 'Title'); -define('CO_' . $moduleDirNameUpper . '_' . 'VISIBLE', 'Visible'); -define('CO_' . $moduleDirNameUpper . '_' . 'VISIBLEIN', 'Visible In'); -define('CO_' . $moduleDirNameUpper . '_' . 'WEIGHT', 'Weight'); - -define('CO_' . $moduleDirNameUpper . '_' . 'PERMISSIONS', 'Permissions'); -define('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS', 'Blocks Admin'); -define('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_DESC', 'Blocks/Group Admin'); - -define('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_MANAGMENT', 'Manage'); -define('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_ADDBLOCK', 'Add a new block'); -define('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_EDITBLOCK', 'Edit a block'); -define('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_CLONEBLOCK', 'Clone a block'); +\define('CO_' . $moduleDirNameUpper . '_' . 'ACCESSRIGHTS', 'Access Rights'); +\define('CO_' . $moduleDirNameUpper . '_' . 'ACTION', 'Action'); +\define('CO_' . $moduleDirNameUpper . '_' . 'ACTIVERIGHTS', 'Active Rights'); +\define('CO_' . $moduleDirNameUpper . '_' . 'BADMIN', 'Block Administration'); +\define('CO_' . $moduleDirNameUpper . '_' . 'BLKDESC', 'Description'); +\define('CO_' . $moduleDirNameUpper . '_' . 'CBCENTER', 'Center Middle'); +\define('CO_' . $moduleDirNameUpper . '_' . 'CBLEFT', 'Center Left'); +\define('CO_' . $moduleDirNameUpper . '_' . 'CBRIGHT', 'Center Right'); +\define('CO_' . $moduleDirNameUpper . '_' . 'SBLEFT', 'Left'); +\define('CO_' . $moduleDirNameUpper . '_' . 'SBRIGHT', 'Right'); +\define('CO_' . $moduleDirNameUpper . '_' . 'SIDE', 'Alignment'); +\define('CO_' . $moduleDirNameUpper . '_' . 'TITLE', 'Title'); +\define('CO_' . $moduleDirNameUpper . '_' . 'VISIBLE', 'Visible'); +\define('CO_' . $moduleDirNameUpper . '_' . 'VISIBLEIN', 'Visible In'); +\define('CO_' . $moduleDirNameUpper . '_' . 'WEIGHT', 'Weight'); + +\define('CO_' . $moduleDirNameUpper . '_' . 'PERMISSIONS', 'Permissions'); +\define('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS', 'Blocks Admin'); +\define('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_DESC', 'Blocks/Group Admin'); + +\define('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_MANAGMENT', 'Manage'); +\define('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_ADDBLOCK', 'Add a new block'); +\define('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_EDITBLOCK', 'Edit a block'); +\define('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_CLONEBLOCK', 'Clone a block'); //myblocksadmin -define('CO_' . $moduleDirNameUpper . '_' . 'AGDS', 'Admin Groups'); -define('CO_' . $moduleDirNameUpper . '_' . 'BCACHETIME', 'Cache Time'); -define('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_ADMIN', 'Blocks Admin'); +\define('CO_' . $moduleDirNameUpper . '_' . 'AGDS', 'Admin Groups'); +\define('CO_' . $moduleDirNameUpper . '_' . 'BCACHETIME', 'Cache Time'); +\define('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_ADMIN', 'Blocks Admin'); +\define('CO_' . $moduleDirNameUpper . '_' . 'UPDATE_SUCCESS', 'Update successful'); //Template Admin -define('CO_' . $moduleDirNameUpper . '_' . 'TPLSETS', 'Template Management'); -define('CO_' . $moduleDirNameUpper . '_' . 'GENERATE', 'Generate'); -define('CO_' . $moduleDirNameUpper . '_' . 'FILENAME', 'File Name'); +\define('CO_' . $moduleDirNameUpper . '_' . 'TPLSETS', 'Template Management'); +\define('CO_' . $moduleDirNameUpper . '_' . 'GENERATE', 'Generate'); +\define('CO_' . $moduleDirNameUpper . '_' . 'FILENAME', 'File Name'); //Menu -define('CO_' . $moduleDirNameUpper . '_' . 'ADMENU_MIGRATE', 'Migrate'); -define('CO_' . $moduleDirNameUpper . '_' . 'FOLDER_YES', 'Folder "%s" exist'); -define('CO_' . $moduleDirNameUpper . '_' . 'FOLDER_NO', 'Folder "%s" does not exist. Create the specified folder with CHMOD 777.'); -define('CO_' . $moduleDirNameUpper . '_' . 'SHOW_DEV_TOOLS', 'Show Development Tools Button?'); -define('CO_' . $moduleDirNameUpper . '_' . 'SHOW_DEV_TOOLS_DESC', 'If yes, the "Migrate" Tab and other Development tools will be visible to the Admin.'); +\define('CO_' . $moduleDirNameUpper . '_' . 'ADMENU_MIGRATE', 'Migrate'); +\define('CO_' . $moduleDirNameUpper . '_' . 'FOLDER_YES', 'Folder "%s" exist'); +\define('CO_' . $moduleDirNameUpper . '_' . 'FOLDER_NO', 'Folder "%s" does not exist. Create the specified folder with CHMOD 777.'); +\define('CO_' . $moduleDirNameUpper . '_' . 'SHOW_DEV_TOOLS', 'Show Development Tools Button?'); +\define('CO_' . $moduleDirNameUpper . '_' . 'SHOW_DEV_TOOLS_DESC', 'If yes, the "Migrate" Tab and other Development tools will be visible to the Admin.'); +\define('CO_' . $moduleDirNameUpper . '_' . 'ADMENU_FEEDBACK', 'Feedback'); +\define('CO_' . $moduleDirNameUpper . '_' . 'MIGRATE_OK', 'Database migrated to current schema.'); +\define('CO_' . $moduleDirNameUpper . '_' . 'MIGRATE_WARNING', 'Warning! This is intended for developers only. Confirm write schema file from current database.'); +\define('CO_' . $moduleDirNameUpper . '_' . 'MIGRATE_SCHEMA_OK', 'Current schema file written'); //Latest Version Check -define('CO_' . $moduleDirNameUpper . '_' . 'NEW_VERSION', 'New Version: '); +\define('CO_' . $moduleDirNameUpper . '_' . 'NEW_VERSION', 'New Version: '); + +//DirectoryChecker +\define('CO_' . $moduleDirNameUpper . '_' . 'AVAILABLE', "Available"); +\define('CO_' . $moduleDirNameUpper . '_' . 'NOTAVAILABLE', "Not available"); +\define('CO_' . $moduleDirNameUpper . '_' . 'NOTWRITABLE', "Should have permission ( %d ), but it has ( %d )"); +\define('CO_' . $moduleDirNameUpper . '_' . 'CREATETHEDIR', 'Create it'); +\define('CO_' . $moduleDirNameUpper . '_' . 'SETMPERM', 'Set the permission'); +\define('CO_' . $moduleDirNameUpper . '_' . 'DIRCREATED', 'The directory has been created'); +\define('CO_' . $moduleDirNameUpper . '_' . 'DIRNOTCREATED', 'The directory cannot be created'); +\define('CO_' . $moduleDirNameUpper . '_' . 'PERMSET', 'The permission has been set'); +\define('CO_' . $moduleDirNameUpper . '_' . 'PERMNOTSET', 'The permission cannot be set'); + +//FileChecker +\define('CO_' . $moduleDirNameUpper . '_' . 'COPYTHEFILE', 'Copy it'); +\define('CO_' . $moduleDirNameUpper . '_' . 'FILECOPIED', 'The file has been copied'); +\define('CO_' . $moduleDirNameUpper . '_' . 'FILENOTCOPIED', 'The file cannot be copied'); + +//Uploader +define('CO_' . $moduleDirNameUpper . '_' . 'IMAGES_UPLOAD', 'Upload Files'); + +// ---------------- Errors ---------------- +define('CO_' . $moduleDirNameUpper . '_' . 'FAILSAVEIMG_THUMBS', 'Error when creating thumb image: %s'); +define('CO_' . $moduleDirNameUpper . '_' . 'FAILSAVEIMG_MEDIUM', 'Error when creating medium image: %s'); +define('CO_' . $moduleDirNameUpper . '_' . 'FAILSAVEWM_MEDIUM', 'Error when adding watermark to medium image: %s (reason: %g)'); +define('CO_' . $moduleDirNameUpper . '_' . 'FAILSAVEWM_LARGE', 'Error when adding watermark to large image: %s (reason: %g)'); + +// Album buttons +define('CO_' . $moduleDirNameUpper . '_' . 'ALBUM_ADD', 'Add Category'); +define('CO_' . $moduleDirNameUpper . '_' . 'ALBUM_EDIT', 'Edit Category'); + +//Uploader +define('CO_' . $moduleDirNameUpper . '_' . 'FIELD_ADD', 'Add Field'); +define('CO_' . $moduleDirNameUpper . '_' . 'FIELD_EDIT', 'Edit Field'); +define('CO_' . $moduleDirNameUpper . '_' . 'FIELD_TITLE', 'Title'); +define('CO_' . $moduleDirNameUpper . '_' . 'FIELD_FID', 'ID'); +define('CO_' . $moduleDirNameUpper . '_' . 'FORMIMAGE_PATH', 'File Path'); +define('CO_' . $moduleDirNameUpper . '_' . 'FIELD_IMG', 'File Field'); + +define('CO_' . $moduleDirNameUpper . '_' . 'FORMUPLOAD', 'Upload'); +define('CO_' . $moduleDirNameUpper . '_' . 'FIELD_WEIGHT', 'Weight'); +define('CO_' . $moduleDirNameUpper . '_' . 'FIELD_STATUS', 'Status'); +define('CO_' . $moduleDirNameUpper . '_' . 'FIELD_SEARCH', 'Search'); +define('CO_' . $moduleDirNameUpper . '_' . 'FIELD_STATUS_DEF', 'Status Defi'); + +// fine uploader +define('CO_' . $moduleDirNameUpper . '_' . 'FU_SUBMIT', 'Submitting file: '); +define('CO_' . $moduleDirNameUpper . '_' . 'FU_SUBMITTED', 'File successfully checked, please upload'); +define('CO_' . $moduleDirNameUpper . '_' . 'FU_UPLOAD', 'Upload file: '); +define('CO_' . $moduleDirNameUpper . '_' . 'FU_FAILED', 'Errors occurred during uploading the file'); +define('CO_' . $moduleDirNameUpper . '_' . 'FU_SUCCEEDED', 'Successfully uploaded all files'); + +define('CO_' . $moduleDirNameUpper . '_' . 'SELECT', 'Select Category'); +define('CO_' . $moduleDirNameUpper . '_' . 'ERROR_CATPID', 'Error: parent category not found'); + + + +//image config +\define('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_WIDTH', 'Image Display Width'); +\define('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_WIDTH_DSC', 'Display width for image'); +\define('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_HEIGHT', 'Image Display Height'); +\define('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_HEIGHT_DSC', 'Display height for image'); +\define('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_CONFIG', '--- EXTERNAL Image configuration --- '); +\define('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_CONFIG_DSC', ''); +\define('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_UPLOAD_PATH', 'Image Upload path'); +\define('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_UPLOAD_PATH_DSC', 'Path for uploading images'); + +\define('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_FILE_SIZE', 'Image File Size (in Bytes)'); +\define('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_FILE_SIZE_DSC','The maximum file size of the image file (in Bytes)'); + +//Preferences +\define('CO_' . $moduleDirNameUpper . '_' . 'TRUNCATE_LENGTH', 'Number of Characters to truncate to the long text field'); +\define('CO_' . $moduleDirNameUpper . '_' . 'TRUNCATE_LENGTH_DESC', 'Set the maximum number of characters to truncate the long text fields'); + +//Module Stats +\define('CO_' . $moduleDirNameUpper . '_' . 'STATS_SUMMARY', 'Module Statistics'); +\define('CO_' . $moduleDirNameUpper . '_' . 'TOTAL_CATEGORIES', 'Categories:'); +\define('CO_' . $moduleDirNameUpper . '_' . 'TOTAL_ITEMS', 'Items'); +\define('CO_' . $moduleDirNameUpper . '_' . 'TOTAL_OFFLINE', 'Offline'); +\define('CO_' . $moduleDirNameUpper . '_' . 'TOTAL_PUBLISHED', 'Published'); +\define('CO_' . $moduleDirNameUpper . '_' . 'TOTAL_REJECTED', 'Rejected'); +\define('CO_' . $moduleDirNameUpper . '_' . 'TOTAL_SUBMITTED', 'Submitted'); diff --git a/language/english/help/disclaimer.tpl b/language/english/help/disclaimer.tpl index 5df7a0c..d74e9ac 100644 --- a/language/english/help/disclaimer.tpl +++ b/language/english/help/disclaimer.tpl @@ -3,7 +3,7 @@

    DISCLAIMER


    -

    Software downloaded from the XOOPS web site is provided 'as is' without warranty +

    Software downloaded from the XOOPS website is provided 'as is' without warranty of any kind, either express or implied, including, but not limited to, the implied warranties of fitness for a purpose, or the warranty of non-infringement. Without limiting the foregoing, XOOPS Projects team makes no warranty that:

    @@ -15,21 +15,21 @@ accurate or reliable
  • the quality of the software will meet your expectations any errors in the - software obtained from XOOPS web site will be corrected. + software obtained from XOOPS website will be corrected.

  • -

    Software and its documentation made available on the XOOPS web site:

    +

    Software and its documentation made available on the XOOPS website:


    1. could include technical or other mistakes, inaccuracies or typographical errors. XOOPS may make changes to the software or documentation made available - on its web site. + on its website.
    2. may be out of date, and XOOPS makes no commitment to update such materials.
    3. XOOPS assumes no responsibility for errors or omissions in the software - or documentation available from its web site. + or documentation available from its website.


    In no event shall XOOPS team be liable to you or any third parties for @@ -43,6 +43,6 @@ and risk and with agreement that you will be solely responsible for any damage to your computer system or loss of data that results from such activities. No advice or information, whether oral or written, obtained by you from XOOPS or from XOOPS - web site shall create any warranty for the software

    + website shall create any warranty for the software

    diff --git a/language/english/help/help.html b/language/english/help/help.html deleted file mode 100644 index 7a56dd7..0000000 --- a/language/english/help/help.html +++ /dev/null @@ -1,42 +0,0 @@ -
    -

    Help: - TDMDownloads Back to the Administration of TDMDownloads - -

    - -

    Description

    -

    - Creates a downloads section where users can download/submit/rate various files. - It uses XOOPS permission and group management, thus allowing a great flexibility in use. -

    -

    Install/uninstall

    - No special measures necessary, follow the standard installation process - extract the /tdmdownloads folder into the ../modules directory. Install the module through Admin -> System Module -> Modules. -

    - Detailed instructions on installing modules are available in the - XOOPS Operations Manual -

    -

    Operating instructions

    - To set up this module you need to: -

    - i) Configure your preferences for the module (see "Preferences") and - optionally the Partners block if you intend to use it (see - Blocks) -

    - ii) Check that you have given your user groups the necessary module and - block access rights to use this module. Group permissions are set through - the Administration Menu -> System -> Groups. -

    - Detailed instructions on configuring the access rights for user groups are available in the - XOOPS Operations Manual -

    -

    Tutorial

    -

    - Not available at the moment. -

    - -
    diff --git a/language/english/help/help.tpl b/language/english/help/help.tpl index e3bb67c..fe3807e 100644 --- a/language/english/help/help.tpl +++ b/language/english/help/help.tpl @@ -13,21 +13,21 @@ extract the module folder into the ../modules directory. Install the module through Admin -> System Module -> Modules.

    Detailed instructions on installing modules are available in the - Chapter 2.12 of our XOOPS Operations Manual

    + Chapter 2.12 of our XOOPS Operations Manual

    OPERATING INSTRUCTIONS


    This module and its operations are very simple.

    Detailed instructions on configuring the access rights for user groups are available in the - Chapter 2.8 of our XOOPS Operations Manual

    + Chapter 2.8 of our XOOPS Operations Manual

    TUTORIAL


    - Tutorial has been started, but we might need your help! Please check out the status of the tutorial here . -

    To contribute to this Tutorial, please fork it on GitHub. -
    This document describes our Documentation Process and it will help you to understand how to contribute. + Tutorial has been started, but we might need your help! Please check out the status of the tutorial here . +

    To contribute to this Tutorial, please fork it on GitHub. +
    This document describes our Documentation Process and it will help you to understand how to contribute.

    There are more XOOPS Tutorials, so check them out in our XOOPS Tutorial Repository on GitBook.

    @@ -43,7 +43,7 @@

    DEVELOPMENT


    - This module is Open Source and we would love your help in making it better! You can fork this module on GitHub

    + This module is Open Source and we would love your help in making it better! You can fork this module on GitHub

    But there is more happening on GitHub:

    - XOOPS Core
    - XOOPS Modules
    diff --git a/language/english/help/index.html b/language/english/help/index.html deleted file mode 100644 index 990cbd6..0000000 --- a/language/english/help/index.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/language/english/help/index.php b/language/english/help/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/language/english/help/index.php @@ -0,0 +1,2 @@ +history.go(-1); \ No newline at end of file diff --git a/language/english/index.php b/language/english/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/language/english/index.php @@ -0,0 +1,2 @@ +history.go(-1); \ No newline at end of file diff --git a/language/english/mail_template/index.php b/language/english/mail_template/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/language/english/mail_template/index.php @@ -0,0 +1,2 @@ +
    thanks for writing an email to the webmaster of the website from where you are coming and tell him:
    NO OWNERSHIP OF LINKS FROM OTHER SITES! (LEECH)

    Leecher definition: Someone who is lazy to link to its own server or steals the hard work done by other people

    You are already registered.' + 'This file does not belong to the website from where you are coming.

    thanks for writing an email to the webmaster of the website from where you are coming and tell him:
    NO OWNERSHIP OF LINKS FROM OTHER SITES! (LEECH)

    Leecher definition: Someone who is lazy to link to its own server or steals the hard work done by other people

    You are already registered.' ); //Message d'erreur define('_MD_TDMDOWNLOADS_ERREUR_NOCAT', 'You have to choose a category!'); @@ -144,4 +146,7 @@ define('_MD_TDMDOWNLOADS_DISPLAYMORE', 'Show more downloads'); define('_MD_TDMDOWNLOADS_ADDNEW', 'Add new download'); define('_MD_TDMDOWNLOADS_COUNTDL', 'Available downloads'); -define('_MD_TDMDOWNLOADS_COUNTSUBS', 'Subcategories'); \ No newline at end of file +define('_MD_TDMDOWNLOADS_COUNTSUBS', 'Subcategories'); + +//module admin +define('_MD_TDMDOWNLOADS_ADMIN', 'Module Admin'); diff --git a/language/english/modinfo.php b/language/english/modinfo.php index cd7f971..acf2f2e 100644 --- a/language/english/modinfo.php +++ b/language/english/modinfo.php @@ -1,4 +1,5 @@ ---- --- '); //define('_MI_TDMDOWNLOADS_ADMENU5', 'Blocks Admin'); - diff --git a/language/french/admin.php b/language/french/admin.php index 645681b..2efdcd6 100644 --- a/language/french/admin.php +++ b/language/french/admin.php @@ -1,4 +1,5 @@ -Attention !

    l'importation supprimera toutes les données de TDMDownloads. Il est fortement recommandé de faire une sauvegarde de toutes vos données d'abord, ainsi que de votre site internet.

    TDM n'est pas responsable si vous perdez vos données. Malheureusement, les captures d'écran ne peuvent pas être copiées." + "Attention !

    l'importation supprimera toutes les données de TDMDownloads. Il est fortement recommandé de faire une sauvegarde de toutes vos données d'abord, ainsi que de votre site internet.

    TDM n'est pas responsable si vous perdez vos données. Malheureusement, les captures d'écran ne peuvent pas être copiées." ); define('_AM_TDMDOWNLOADS_IMPORT_WFDOWNLOADS', 'Importation de WF Downloads (Version 3.23 RC5 uniquement)'); define('_AM_TDMDOWNLOADS_IMPORT_WFDOWNLOADS_CATIMG', "Sélectionnez le répertoire Upload (le chemin d'accès) pour les images des catégories de WF-Downloads"); @@ -122,7 +124,8 @@ define('_AM_TDMDOWNLOADS_FORMPLATFORM', 'Plateforme :'); define('_AM_TDMDOWNLOADS_FORMPOSTER', 'Posté par '); define('_AM_TDMDOWNLOADS_FORMRATING', 'Note'); -define('_AM_TDMDOWNLOADS_FORMSIZE', "Taille du fichier
    Pour utiliser le système automatique de calcul de la taille du fichier, laissez ce champ vide."); +define('_AM_TDMDOWNLOADS_FORMSIZE', "Taille du fichier"); +define('_AM_TDMDOWNLOADS_FORMSIZE_WHEN_SUBMIT', "Taille du fichier
    Pour utiliser le système automatique de calcul de la taille du fichier, laissez ce champ vide."); define('_AM_TDMDOWNLOADS_FORMSTATUS', 'État du téléchargement'); define('_AM_TDMDOWNLOADS_FORMSTATUS_OK', 'Approuvé'); define('_AM_TDMDOWNLOADS_FORMSUBMITTER', 'Posté par'); @@ -185,4 +188,3 @@ define('_AM_TDMDOWNLOADS_ERROR_BAD_REMOVE', 'Impossible de supprimer %s'); define('_AM_TDMDOWNLOADS_ERROR_NO_PLUGIN', 'Impossible de charger le plug-in'); define('_AM_TDMDOWNLOADS_NUMBYTES', '%s octets'); - diff --git a/language/french/blocks.php b/language/french/blocks.php index fab5d6b..a2d73eb 100644 --- a/language/french/blocks.php +++ b/language/french/blocks.php @@ -1,4 +1,5 @@ -Browse items alphabetically"); @@ -111,6 +122,8 @@ //myblocksadmin define('CO_' . $moduleDirNameUpper . '_' . 'AGDS', 'Admin Groups'); define('CO_' . $moduleDirNameUpper . '_' . 'BCACHETIME', 'Cache Time'); +\define('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_ADMIN', 'Blocks Admin'); +\define('CO_' . $moduleDirNameUpper . '_' . 'UPDATE_SUCCESS', 'Update successful'); //Template Admin define('CO_' . $moduleDirNameUpper . '_' . 'TPLSETS', 'Template Management'); @@ -119,8 +132,96 @@ //Menu define('CO_' . $moduleDirNameUpper . '_' . 'ADMENU_MIGRATE', 'Migrate'); -define('CO_' . $moduleDirNameUpper . '_FOLDER_YES', 'Folder "%s" exist'); -define('CO_' . $moduleDirNameUpper . '_FOLDER_NO', 'Folder "%s" does not exist. Create the specified folder with CHMOD 777.'); +define('CO_' . $moduleDirNameUpper . '_' . 'FOLDER_YES', 'Folder "%s" exist'); +define('CO_' . $moduleDirNameUpper . '_' . 'FOLDER_NO', 'Folder "%s" does not exist. Create the specified folder with CHMOD 777.'); +\define('CO_' . $moduleDirNameUpper . '_' . 'SHOW_DEV_TOOLS', 'Show Development Tools Button?'); +\define('CO_' . $moduleDirNameUpper . '_' . 'SHOW_DEV_TOOLS_DESC', 'If yes, the "Migrate" Tab and other Development tools will be visible to the Admin.'); +\define('CO_' . $moduleDirNameUpper . '_' . 'ADMENU_FEEDBACK', 'Feedback'); +\define('CO_' . $moduleDirNameUpper . '_' . 'MIGRATE_OK', 'Database migrated to current schema.'); +\define('CO_' . $moduleDirNameUpper . '_' . 'MIGRATE_WARNING', 'Warning! This is intended for developers only. Confirm write schema file from current database.'); +\define('CO_' . $moduleDirNameUpper . '_' . 'MIGRATE_SCHEMA_OK', 'Current schema file written'); //Latest Version Check define('CO_' . $moduleDirNameUpper . '_' . 'NEW_VERSION', 'New Version: '); + +//DirectoryChecker +\define('CO_' . $moduleDirNameUpper . '_' . 'AVAILABLE', "Available"); +\define('CO_' . $moduleDirNameUpper . '_' . 'NOTAVAILABLE', "Not available"); +\define('CO_' . $moduleDirNameUpper . '_' . 'NOTWRITABLE', "Should have permission ( %d ), but it has ( %d )"); +\define('CO_' . $moduleDirNameUpper . '_' . 'CREATETHEDIR', 'Create it'); +\define('CO_' . $moduleDirNameUpper . '_' . 'SETMPERM', 'Set the permission'); +\define('CO_' . $moduleDirNameUpper . '_' . 'DIRCREATED', 'The directory has been created'); +\define('CO_' . $moduleDirNameUpper . '_' . 'DIRNOTCREATED', 'The directory cannot be created'); +\define('CO_' . $moduleDirNameUpper . '_' . 'PERMSET', 'The permission has been set'); +\define('CO_' . $moduleDirNameUpper . '_' . 'PERMNOTSET', 'The permission cannot be set'); + +//FileChecker +\define('CO_' . $moduleDirNameUpper . '_' . 'COPYTHEFILE', 'Copy it'); +\define('CO_' . $moduleDirNameUpper . '_' . 'FILECOPIED', 'The file has been copied'); +\define('CO_' . $moduleDirNameUpper . '_' . 'FILENOTCOPIED', 'The file cannot be copied'); + +//Uploader +define('CO_' . $moduleDirNameUpper . '_' . 'IMAGES_UPLOAD', 'Upload Files'); + +// ---------------- Errors ---------------- +define('CO_' . $moduleDirNameUpper . '_' . 'FAILSAVEIMG_THUMBS', 'Error when creating thumb image: %s'); +define('CO_' . $moduleDirNameUpper . '_' . 'FAILSAVEIMG_MEDIUM', 'Error when creating medium image: %s'); +define('CO_' . $moduleDirNameUpper . '_' . 'FAILSAVEWM_MEDIUM', 'Error when adding watermark to medium image: %s (reason: %g)'); +define('CO_' . $moduleDirNameUpper . '_' . 'FAILSAVEWM_LARGE', 'Error when adding watermark to large image: %s (reason: %g)'); + +// Album buttons +define('CO_' . $moduleDirNameUpper . '_' . 'ALBUM_ADD', 'Add Category'); +define('CO_' . $moduleDirNameUpper . '_' . 'ALBUM_EDIT', 'Edit Category'); + +//Uploader +define('CO_' . $moduleDirNameUpper . '_' . 'FIELD_ADD', 'Edit Field'); +define('CO_' . $moduleDirNameUpper . '_' . 'FIELD_EDIT', 'Add Field'); +define('CO_' . $moduleDirNameUpper . '_' . 'FIELD_TITLE', 'Title'); +define('CO_' . $moduleDirNameUpper . '_' . 'FIELD_FID', 'ID'); +define('CO_' . $moduleDirNameUpper . '_' . 'FORMIMAGE_PATH', 'File Path'); +define('CO_' . $moduleDirNameUpper . '_' . 'FIELD_IMG', 'File Field'); + +define('CO_' . $moduleDirNameUpper . '_' . 'FORMUPLOAD', 'Upload'); +define('CO_' . $moduleDirNameUpper . '_' . 'FIELD_WEIGHT', 'Weight'); +define('CO_' . $moduleDirNameUpper . '_' . 'FIELD_STATUS', 'Status'); +define('CO_' . $moduleDirNameUpper . '_' . 'FIELD_SEARCH', 'Search'); +define('CO_' . $moduleDirNameUpper . '_' . 'FIELD_STATUS_DEF', 'Status Defi'); + +// fine uploader +define('CO_' . $moduleDirNameUpper . '_' . 'FU_SUBMIT', 'Submitting file: '); +define('CO_' . $moduleDirNameUpper . '_' . 'FU_SUBMITTED', 'File successfully checked, please upload'); +define('CO_' . $moduleDirNameUpper . '_' . 'FU_UPLOAD', 'Upload file: '); +define('CO_' . $moduleDirNameUpper . '_' . 'FU_FAILED', 'Errors occurred during uploading the file'); +define('CO_' . $moduleDirNameUpper . '_' . 'FU_SUCCEEDED', 'Successfully uploaded all files'); + + +define('CO_' . $moduleDirNameUpper . '_' . 'SELECT', 'Select Category'); +define('CO_' . $moduleDirNameUpper . '_' . 'ERROR_CATPID', 'Error: parent category not found'); + + + +//image config +define('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_WIDTH', 'Image Display Width'); +define('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_WIDTH_DSC', 'Display width for image'); +define('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_HEIGHT', 'Image Display Height'); +define('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_HEIGHT_DSC', 'Display height for image'); +define('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_CONFIG', '--- EXTERNAL Image configuration --- '); +define('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_CONFIG_DSC', ''); +define('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_UPLOAD_PATH', 'Image Upload path'); +define('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_UPLOAD_PATH_DSC', 'Path for uploading images'); + +\define('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_FILE_SIZE', 'Image File Size (in Bytes)'); +\define('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_FILE_SIZE_DSC','The maximum file size of the image file (in Bytes)'); + +//Preferences +\define('CO_' . $moduleDirNameUpper . '_' . 'TRUNCATE_LENGTH', 'Number of Characters to truncate to the long text field'); +\define('CO_' . $moduleDirNameUpper . '_' . 'TRUNCATE_LENGTH_DESC', 'Set the maximum number of characters to truncate the long text fields'); + +//Module Stats +\define('CO_' . $moduleDirNameUpper . '_' . 'STATS_SUMMARY', 'Module Statistics'); +\define('CO_' . $moduleDirNameUpper . '_' . 'TOTAL_CATEGORIES', 'Categories:'); +\define('CO_' . $moduleDirNameUpper . '_' . 'TOTAL_ITEMS', 'Items'); +\define('CO_' . $moduleDirNameUpper . '_' . 'TOTAL_OFFLINE', 'Offline'); +\define('CO_' . $moduleDirNameUpper . '_' . 'TOTAL_PUBLISHED', 'Published'); +\define('CO_' . $moduleDirNameUpper . '_' . 'TOTAL_REJECTED', 'Rejected'); +\define('CO_' . $moduleDirNameUpper . '_' . 'TOTAL_SUBMITTED', 'Submitted'); diff --git a/language/french/help/disclaimer.tpl b/language/french/help/disclaimer.tpl index 5df7a0c..d74e9ac 100644 --- a/language/french/help/disclaimer.tpl +++ b/language/french/help/disclaimer.tpl @@ -3,7 +3,7 @@

    DISCLAIMER


    -

    Software downloaded from the XOOPS web site is provided 'as is' without warranty +

    Software downloaded from the XOOPS website is provided 'as is' without warranty of any kind, either express or implied, including, but not limited to, the implied warranties of fitness for a purpose, or the warranty of non-infringement. Without limiting the foregoing, XOOPS Projects team makes no warranty that:

    @@ -15,21 +15,21 @@ accurate or reliable
  • the quality of the software will meet your expectations any errors in the - software obtained from XOOPS web site will be corrected. + software obtained from XOOPS website will be corrected.

  • -

    Software and its documentation made available on the XOOPS web site:

    +

    Software and its documentation made available on the XOOPS website:


    1. could include technical or other mistakes, inaccuracies or typographical errors. XOOPS may make changes to the software or documentation made available - on its web site. + on its website.
    2. may be out of date, and XOOPS makes no commitment to update such materials.
    3. XOOPS assumes no responsibility for errors or omissions in the software - or documentation available from its web site. + or documentation available from its website.


    In no event shall XOOPS team be liable to you or any third parties for @@ -43,6 +43,6 @@ and risk and with agreement that you will be solely responsible for any damage to your computer system or loss of data that results from such activities. No advice or information, whether oral or written, obtained by you from XOOPS or from XOOPS - web site shall create any warranty for the software

    + website shall create any warranty for the software

    diff --git a/language/french/help/help.html b/language/french/help/help.html index 4c87319..ff183fd 100644 --- a/language/french/help/help.html +++ b/language/french/help/help.html @@ -1,7 +1,7 @@

    Aide : TDMDownloads Retour à l'administration de TDMDownloads diff --git a/language/french/help/help.tpl b/language/french/help/help.tpl index e3bb67c..fe3807e 100644 --- a/language/french/help/help.tpl +++ b/language/french/help/help.tpl @@ -13,21 +13,21 @@ extract the module folder into the ../modules directory. Install the module through Admin -> System Module -> Modules.

    Detailed instructions on installing modules are available in the -
    Chapter 2.12 of our XOOPS Operations Manual

    + Chapter 2.12 of our XOOPS Operations Manual

    OPERATING INSTRUCTIONS


    This module and its operations are very simple.

    Detailed instructions on configuring the access rights for user groups are available in the - Chapter 2.8 of our XOOPS Operations Manual

    + Chapter 2.8 of our XOOPS Operations Manual

    TUTORIAL


    - Tutorial has been started, but we might need your help! Please check out the status of the tutorial here . -

    To contribute to this Tutorial, please fork it on GitHub. -
    This document describes our Documentation Process and it will help you to understand how to contribute. + Tutorial has been started, but we might need your help! Please check out the status of the tutorial here . +

    To contribute to this Tutorial, please fork it on GitHub. +
    This document describes our Documentation Process and it will help you to understand how to contribute.

    There are more XOOPS Tutorials, so check them out in our XOOPS Tutorial Repository on GitBook.

    @@ -43,7 +43,7 @@

    DEVELOPMENT


    - This module is Open Source and we would love your help in making it better! You can fork this module on GitHub

    + This module is Open Source and we would love your help in making it better! You can fork this module on GitHub

    But there is more happening on GitHub:

    - XOOPS Core
    - XOOPS Modules
    diff --git a/language/french/help/index.html b/language/french/help/index.html deleted file mode 100644 index 990cbd6..0000000 --- a/language/french/help/index.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/language/french/help/index.php b/language/french/help/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/language/french/help/index.php @@ -0,0 +1,2 @@ +history.go(-1); \ No newline at end of file diff --git a/language/french/index.php b/language/french/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/language/french/index.php @@ -0,0 +1,2 @@ +history.go(-1); \ No newline at end of file diff --git a/language/french/mail_template/index.php b/language/french/mail_template/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/language/french/mail_template/index.php @@ -0,0 +1,2 @@ +
    Merci d'écrire un courrier électronique au webmestre du site d'où vous venez et dites-lui :
    VOUS N'ÊTES PAS PROPRIÉTAIRE DE LIENS PROVENANT D'AUTRES SITES ! (LEECH)
    Définition de leecher : Quelqu'un qui est trop paresseux pour afficher et héberger des liens sur son propre serveur ou vole le dur travail fait par d'autres personnes.

    Vous êtes déjà enregistré" + "Ce fichier n'appartient pas au site d'où vous venez.

    Merci d'écrire un courrier électronique au webmestre du site d'où vous venez et dites-lui :
    VOUS N'ÊTES PAS PROPRIÉTAIRE DE LIENS PROVENANT D'AUTRES SITES ! (LEECH)
    Définition de leecher : Quelqu'un qui est trop paresseux pour afficher et héberger des liens sur son propre serveur ou vole le dur travail fait par d'autres personnes.

    Vous êtes déjà enregistré" ); //Message d'erreur define('_MD_TDMDOWNLOADS_ERREUR_NOCAT', 'Vous devez choisir une catégorie !'); @@ -144,4 +146,4 @@ define('_MD_TDMDOWNLOADS_DISPLAYMORE', 'plus de téléchargement'); define('_MD_TDMDOWNLOADS_ADDNEW', 'Soumis téléchargement'); define('_MD_TDMDOWNLOADS_COUNTDL', 'téléchargement disponible'); -define('_MD_TDMDOWNLOADS_COUNTSUBS', 'Sous catégories'); \ No newline at end of file +define('_MD_TDMDOWNLOADS_COUNTSUBS', 'Sous catégories'); diff --git a/language/french/modinfo.php b/language/french/modinfo.php index 61db7d2..22b0612 100644 --- a/language/french/modinfo.php +++ b/language/french/modinfo.php @@ -1,4 +1,5 @@ -

  • De gauche à droite : Montrez la description des téléchargements du côté gauche et la colonne d'informations du côté droit
  • De droite à gauche : Montrez la description des téléchargements du côté droit et la colonne d'informations du côté gauche
  • " + "
    • De gauche à droite : Montrez la description des téléchargements du côté gauche et la colonne d'informations du côté droit
    • De droite à gauche : Montrez la description des téléchargements du côté droit et la colonne d'informations du côté gauche
    " ); define('_MI_TDMDOWNLOADS_DOWNLOADFLOAT_LTR', 'De gauche à droite'); define('_MI_TDMDOWNLOADS_DOWNLOADFLOAT_RTL', 'De droite à gauche'); @@ -104,7 +106,10 @@ define('_MI_TDMDOWNLOADS_DOWNLOAD_PREFIX', 'Préfixe des fichiers téléchargés'); define('_MI_TDMDOWNLOADS_DOWNLOAD_PREFIXDSC', "Valide uniquement si l'option pour renommer les fichiers téléchargés est oui"); define('_MI_TDMDOWNLOADS_MAXUPLOAD_SIZE', 'Taille maximum des fichiers de téléchargement'); -define('_MI_TDMDOWNLOADS_MAXUPLOAD_SIZE_DESC', "La sélection est limitée par les valeurs de 'post_max_size' et 'upload_max_filesize' dans les paramètres php.ini
    Si vous voulez augmenter les valeurs, vous devez d'abord augmenter ces paramètres dans php.ini et ensuite metre à jour le module pour faire apparaître les nouveaux choix."); +define( + '_MI_TDMDOWNLOADS_MAXUPLOAD_SIZE_DESC', + "La sélection est limitée par les valeurs de 'post_max_size' et 'upload_max_filesize' dans les paramètres php.ini
    Si vous voulez augmenter les valeurs, vous devez d'abord augmenter ces paramètres dans php.ini et ensuite metre à jour le module pour faire apparaître les nouveaux choix." +); define('_MI_TDMDOWNLOADS_MAXUPLOAD_SIZE_MB', 'Mo'); define('_MI_TDMDOWNLOADS_MIMETYPE', 'Types mime autorisés '); define('_MI_TDMDOWNLOADS_MIMETYPE_DSC', 'Entrer les types mime autorisés'); diff --git a/language/german/admin.php b/language/german/admin.php index 40c3d46..96e3d5a 100644 --- a/language/german/admin.php +++ b/language/german/admin.php @@ -1,4 +1,5 @@ -Achtung !

    Durch den Import werden alle Daten in TDMDownloads gelöscht. Es wird dringend empfohlen, zuerst ein Backup der Daten, wenn möglich der gesamten Webseite, zu erstellen.

    TDM übernimmt keinerlei Haftung für verloren gegangene Daten." + "Achtung !

    Durch den Import werden alle Daten in TDMDownloads gelöscht. Es wird dringend empfohlen, zuerst ein Backup der Daten, wenn möglich der gesamten Webseite, zu erstellen.

    TDM übernimmt keinerlei Haftung für verloren gegangene Daten." ); define('_AM_TDMDOWNLOADS_IMPORT_WFDOWNLOADS', 'Import von WF Downloads(nur V3.2 RC2)'); define('_AM_TDMDOWNLOADS_IMPORT_WFDOWNLOADS_CATIMG', 'Upload-Verzeichnis (Pfad) für Kategoriebilder von WF-Downloads angeben'); @@ -123,7 +125,7 @@ define('_AM_TDMDOWNLOADS_FORMPOSTER', 'Eingesendet von '); define('_AM_TDMDOWNLOADS_FORMRATING', 'Bewertung'); define('_AM_TDMDOWNLOADS_FORMSIZE', 'Dateigröße'); -define('_AM_TDMDOWNLOADS_FORMSIZE', "Dateigröße
    Um das automatische System zur Berechnung der Dateigröße zu verwenden, lassen Sie dieses Feld leer."); +define('_AM_TDMDOWNLOADS_FORMSIZE_WHEN_SUBMIT', "Dateigröße
    Um das automatische System zur Berechnung der Dateigröße zu verwenden, lassen Sie dieses Feld leer."); define('_AM_TDMDOWNLOADS_FORMSTATUS', 'Download Status'); define('_AM_TDMDOWNLOADS_FORMSTATUS_OK', 'Bestätigt'); define('_AM_TDMDOWNLOADS_FORMSUBMITTER', 'Eingesendet von'); diff --git a/language/german/blocks.php b/language/german/blocks.php index b155df8..82908e1 100644 --- a/language/german/blocks.php +++ b/language/german/blocks.php @@ -1,4 +1,5 @@ -Einträge alphabetisch anzeigen"); define('CO_' . $moduleDirNameUpper . '_OTHER', 'Andere'); define('CO_' . $moduleDirNameUpper . '_ALL', 'Alle'); + // block defines define('CO_' . $moduleDirNameUpper . '_ACCESSRIGHTS', 'Zugriffsberechtigungen'); define('CO_' . $moduleDirNameUpper . '_ACTION', 'Aktion'); @@ -94,10 +113,14 @@ define('CO_' . $moduleDirNameUpper . '_BLOCKS_ADDBLOCK', 'Add a new block'); define('CO_' . $moduleDirNameUpper . '_BLOCKS_EDITBLOCK', 'Edit a block'); define('CO_' . $moduleDirNameUpper . '_BLOCKS_CLONEBLOCK', 'Clone a block'); +\define('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_EDITBLOCK', 'Edit a block'); +\define('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_CLONEBLOCK', 'Clone a block'); + //myblocksadmin define('CO_' . $moduleDirNameUpper . '_' . 'AGDS', 'Admin Groups'); define('CO_' . $moduleDirNameUpper . '_' . 'BCACHETIME', 'Cache Time'); -define('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_ADMIN', 'Blocks Admin'); +\define('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_ADMIN', 'Blocks Admin'); +\define('CO_' . $moduleDirNameUpper . '_' . 'UPDATE_SUCCESS', 'Update successful'); //Template Admin define('CO_' . $moduleDirNameUpper . '_' . 'TPLSETS', 'Template Management'); @@ -105,12 +128,97 @@ define('CO_' . $moduleDirNameUpper . '_' . 'FILENAME', 'File Name'); //Menu -define('CO_' . $moduleDirNameUpper . '_' . 'ADMENU_MIGRATE', 'Migrate'); -define('CO_' . $moduleDirNameUpper . '_' . 'FOLDER_YES', 'Folder "%s" exist'); -define('CO_' . $moduleDirNameUpper . '_' . 'FOLDER_NO', 'Folder "%s" does not exist. Create the specified folder with CHMOD 777.'); -define('CO_' . $moduleDirNameUpper . '_' . 'SHOW_DEV_TOOLS', 'Show Development Tools Button?'); -define('CO_' . $moduleDirNameUpper . '_' . 'SHOW_DEV_TOOLS_DESC', 'If yes, the "Migrate" Tab and other Development tools will be visible to the Admin.'); - +\define('CO_' . $moduleDirNameUpper . '_' . 'ADMENU_MIGRATE', 'Migrate'); +\define('CO_' . $moduleDirNameUpper . '_' . 'FOLDER_YES', 'Folder "%s" exist'); +\define('CO_' . $moduleDirNameUpper . '_' . 'FOLDER_NO', 'Folder "%s" does not exist. Create the specified folder with CHMOD 777.'); +\define('CO_' . $moduleDirNameUpper . '_' . 'SHOW_DEV_TOOLS', 'Show Development Tools Button?'); +\define('CO_' . $moduleDirNameUpper . '_' . 'SHOW_DEV_TOOLS_DESC', 'If yes, the "Migrate" Tab and other Development tools will be visible to the Admin.'); +\define('CO_' . $moduleDirNameUpper . '_' . 'ADMENU_FEEDBACK', 'Feedback'); +\define('CO_' . $moduleDirNameUpper . '_' . 'MIGRATE_OK', 'Database migrated to current schema.'); +\define('CO_' . $moduleDirNameUpper . '_' . 'MIGRATE_WARNING', 'Warning! This is intended for developers only. Confirm write schema file from current database.'); +\define('CO_' . $moduleDirNameUpper . '_' . 'MIGRATE_SCHEMA_OK', 'Current schema file written'); //Latest Version Check define('CO_' . $moduleDirNameUpper . '_' . 'NEW_VERSION', 'New Version: '); + +//DirectoryChecker +\define('CO_' . $moduleDirNameUpper . '_' . 'AVAILABLE', "Available"); +\define('CO_' . $moduleDirNameUpper . '_' . 'NOTAVAILABLE', "Not available"); +\define('CO_' . $moduleDirNameUpper . '_' . 'NOTWRITABLE', "Should have permission ( %d ), but it has ( %d )"); +\define('CO_' . $moduleDirNameUpper . '_' . 'CREATETHEDIR', 'Create it'); +\define('CO_' . $moduleDirNameUpper . '_' . 'SETMPERM', 'Set the permission'); +\define('CO_' . $moduleDirNameUpper . '_' . 'DIRCREATED', 'The directory has been created'); +\define('CO_' . $moduleDirNameUpper . '_' . 'DIRNOTCREATED', 'The directory cannot be created'); +\define('CO_' . $moduleDirNameUpper . '_' . 'PERMSET', 'The permission has been set'); +\define('CO_' . $moduleDirNameUpper . '_' . 'PERMNOTSET', 'The permission cannot be set'); + +//FileChecker +\define('CO_' . $moduleDirNameUpper . '_' . 'COPYTHEFILE', 'Copy it'); +\define('CO_' . $moduleDirNameUpper . '_' . 'FILECOPIED', 'The file has been copied'); +\define('CO_' . $moduleDirNameUpper . '_' . 'FILENOTCOPIED', 'The file cannot be copied'); + +//Uploader +define('CO_' . $moduleDirNameUpper . '_' . 'IMAGES_UPLOAD', 'Upload Files'); + +// ---------------- Errors ---------------- +define('CO_' . $moduleDirNameUpper . '_' . 'FAILSAVEIMG_THUMBS', 'Error when creating thumb image: %s'); +define('CO_' . $moduleDirNameUpper . '_' . 'FAILSAVEIMG_MEDIUM', 'Error when creating medium image: %s'); +define('CO_' . $moduleDirNameUpper . '_' . 'FAILSAVEWM_MEDIUM', 'Error when adding watermark to medium image: %s (reason: %g)'); +define('CO_' . $moduleDirNameUpper . '_' . 'FAILSAVEWM_LARGE', 'Error when adding watermark to large image: %s (reason: %g)'); + +// Album buttons +define('CO_' . $moduleDirNameUpper . '_' . 'ALBUM_ADD', 'Add Category'); +define('CO_' . $moduleDirNameUpper . '_' . 'ALBUM_EDIT', 'Edit Category'); + +//Uploader +define('CO_' . $moduleDirNameUpper . '_' . 'FIELD_ADD', 'Edit Field'); +define('CO_' . $moduleDirNameUpper . '_' . 'FIELD_EDIT', 'Add Field'); +define('CO_' . $moduleDirNameUpper . '_' . 'FIELD_TITLE', 'Title'); +define('CO_' . $moduleDirNameUpper . '_' . 'FIELD_FID', 'ID'); +define('CO_' . $moduleDirNameUpper . '_' . 'FORMIMAGE_PATH', 'File Path'); +define('CO_' . $moduleDirNameUpper . '_' . 'FIELD_IMG', 'File Field'); + +define('CO_' . $moduleDirNameUpper . '_' . 'FORMUPLOAD', 'Upload'); +define('CO_' . $moduleDirNameUpper . '_' . 'FIELD_WEIGHT', 'Weight'); +define('CO_' . $moduleDirNameUpper . '_' . 'FIELD_STATUS', 'Status'); +define('CO_' . $moduleDirNameUpper . '_' . 'FIELD_SEARCH', 'Search'); +define('CO_' . $moduleDirNameUpper . '_' . 'FIELD_STATUS_DEF', 'Status Defi'); + +// fine uploader +define('CO_' . $moduleDirNameUpper . '_' . 'FU_SUBMIT', 'Submitting file: '); +define('CO_' . $moduleDirNameUpper . '_' . 'FU_SUBMITTED', 'File successfully checked, please upload'); +define('CO_' . $moduleDirNameUpper . '_' . 'FU_UPLOAD', 'Upload file: '); +define('CO_' . $moduleDirNameUpper . '_' . 'FU_FAILED', 'Errors occurred during uploading the file'); +define('CO_' . $moduleDirNameUpper . '_' . 'FU_SUCCEEDED', 'Successfully uploaded all files'); + + +define('CO_' . $moduleDirNameUpper . '_' . 'SELECT', 'Select Category'); +define('CO_' . $moduleDirNameUpper . '_' . 'ERROR_CATPID', 'Error: parent category not found'); + + + +//image config +define('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_WIDTH', 'Image Display Width'); +define('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_WIDTH_DSC', 'Display width for image'); +define('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_HEIGHT', 'Image Display Height'); +define('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_HEIGHT_DSC', 'Display height for image'); +define('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_CONFIG', '--- EXTERNAL Image configuration --- '); +define('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_CONFIG_DSC', ''); +define('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_UPLOAD_PATH', 'Image Upload path'); +define('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_UPLOAD_PATH_DSC', 'Path for uploading images'); + +\define('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_FILE_SIZE', 'Image File Size (in Bytes)'); +\define('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_FILE_SIZE_DSC','The maximum file size of the image file (in Bytes)'); + +//Preferences +\define('CO_' . $moduleDirNameUpper . '_' . 'TRUNCATE_LENGTH', 'Number of Characters to truncate to the long text field'); +\define('CO_' . $moduleDirNameUpper . '_' . 'TRUNCATE_LENGTH_DESC', 'Set the maximum number of characters to truncate the long text fields'); + +//Module Stats +\define('CO_' . $moduleDirNameUpper . '_' . 'STATS_SUMMARY', 'Module Statistics'); +\define('CO_' . $moduleDirNameUpper . '_' . 'TOTAL_CATEGORIES', 'Categories:'); +\define('CO_' . $moduleDirNameUpper . '_' . 'TOTAL_ITEMS', 'Items'); +\define('CO_' . $moduleDirNameUpper . '_' . 'TOTAL_OFFLINE', 'Offline'); +\define('CO_' . $moduleDirNameUpper . '_' . 'TOTAL_PUBLISHED', 'Published'); +\define('CO_' . $moduleDirNameUpper . '_' . 'TOTAL_REJECTED', 'Rejected'); +\define('CO_' . $moduleDirNameUpper . '_' . 'TOTAL_SUBMITTED', 'Submitted'); diff --git a/language/german/help/index.html b/language/german/help/index.html deleted file mode 100644 index 990cbd6..0000000 --- a/language/german/help/index.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/language/german/help/index.php b/language/german/help/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/language/german/help/index.php @@ -0,0 +1,2 @@ +history.go(-1); \ No newline at end of file diff --git a/language/german/index.php b/language/german/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/language/german/index.php @@ -0,0 +1,2 @@ +history.go(-1); \ No newline at end of file diff --git a/language/german/mail_template/index.php b/language/german/mail_template/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/language/german/mail_template/index.php @@ -0,0 +1,2 @@ +
    thanks to write an email to the webmaster of the website from where you are coming and tell him :
    NO OWNERSHIP OF LINKS FROM OTHER SITES !! (LEECH)

    Leecher definition : Someone who is lazy to link to its own server or steals the hard work done by other people

    You are already registered.' + 'This file does not belong to the website from where you are coming.

    thanks to write an email to the webmaster of the website from where you are coming and tell him :
    NO OWNERSHIP OF LINKS FROM OTHER SITES !! (LEECH)

    Leecher definition : Someone who is lazy to link to its own server or steals the hard work done by other people

    You are already registered.' ); //Message d'erreur define('_MD_TDMDOWNLOADS_ERREUR_NOCAT', 'Sie müssen eine Kategorie wählen!'); @@ -144,4 +146,4 @@ define('_MD_TDMDOWNLOADS_DISPLAYMORE', 'Weitere Downloads anzeigen'); define('_MD_TDMDOWNLOADS_ADDNEW', 'Neuen Downloads hinzufügen'); define('_MD_TDMDOWNLOADS_COUNTDL', 'Enthaltene Downloads'); -define('_MD_TDMDOWNLOADS_COUNTSUBS', 'Unterkategorien'); \ No newline at end of file +define('_MD_TDMDOWNLOADS_COUNTSUBS', 'Unterkategorien'); diff --git a/language/german/modinfo.php b/language/german/modinfo.php index c6df4b0..5b44276 100644 --- a/language/german/modinfo.php +++ b/language/german/modinfo.php @@ -1,4 +1,5 @@ -Wenn Sie diese Werte erhöhen möchten dann müssen Sie zuerst die Einstellungen in der php.ini erhöhen. Danach ist ein Update des Modules erforderlich."); +define( + '_MI_TDMDOWNLOADS_MAXUPLOAD_SIZE_DESC', + "Die Auswahlbox ist entsprechend den Einstellungen 'post_max_size' und 'upload_max_filesize' in der php.ini limitiert.
    Wenn Sie diese Werte erhöhen möchten dann müssen Sie zuerst die Einstellungen in der php.ini erhöhen. Danach ist ein Update des Modules erforderlich." +); define('_MI_TDMDOWNLOADS_MAXUPLOAD_SIZE_MB', 'MB'); define('_MI_TDMDOWNLOADS_MIMETYPE', 'Zulässige Mime types '); define('_MI_TDMDOWNLOADS_MIMETYPE_DSC', 'Eingabe der zulässige Mime types'); diff --git a/language/index.html b/language/index.html deleted file mode 100644 index 990cbd6..0000000 --- a/language/index.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/language/index.php b/language/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/language/index.php @@ -0,0 +1,2 @@ +addStylesheet(XOOPS_URL . '/modules/' . $moduleDirName . '/assets/css/styles.css', null); //On recupere la valeur de l'argument op dans l'URL$ -$op = \Xmf\Request::getString('op', 'list'); +$op = \Xmf\Request::getCmd('op', 'list'); // redirection si pas de droit pour poster if (false === $perm_modif) { @@ -50,8 +57,8 @@ case 'list': //navigation $view_category = $categoryHandler->get($viewDownloads->getVar('cid')); - $categories = $utility->getItemIds('tdmdownloads_view', $moduleDirName); - if (!in_array($viewDownloads->getVar('cid'), $categories, true)) { + $categories = $utility->getItemIds('tdmdownloads_view', $moduleDirName); + if (!in_array($viewDownloads->getVar('cid'), $categories)) { redirect_header('index.php', 2, _NOPERM); } //tableau des catégories @@ -60,16 +67,16 @@ $criteria->setOrder('ASC'); $criteria->add(new \Criteria('cat_cid', '(' . implode(',', $categories) . ')', 'IN')); $downloadscatArray = $categoryHandler->getAll($criteria); - $mytree = new \XoopsModules\Tdmdownloads\Tree($downloadscatArray, 'cat_cid', 'cat_pid'); + $mytree = new Tree($downloadscatArray, 'cat_cid', 'cat_pid'); //navigation - $navigation = $utility->getPathTreeUrl($mytree, $viewDownloads->getVar('cid'), $downloadscatArray, 'cat_title', $prefix = ' arrow ', true, 'ASC', true); + $navigation = $utility::getPathTreeUrl($mytree, $viewDownloads->getVar('cid'), $downloadscatArray, 'cat_title', $prefix = ' arrow ', true, 'ASC', true); $navigation .= ' arrow ' . $viewDownloads->getVar('title') . ''; $navigation .= ' arrow ' . _MD_TDMDOWNLOADS_SINGLEFILE_MODIFY; $xoopsTpl->assign('navigation', $navigation); // référencement // titre de la page $pagetitle = _MD_TDMDOWNLOADS_SINGLEFILE_MODIFY . ' - ' . $viewDownloads->getVar('title') . ' - '; - $pagetitle .= $utility->getPathTreeUrl($mytree, $viewDownloads->getVar('cid'), $downloadscatArray, 'cat_title', $prefix = ' - ', false, 'DESC', true); + $pagetitle .= $utility::getPathTreeUrl($mytree, $viewDownloads->getVar('cid'), $downloadscatArray, 'cat_title', $prefix = ' - ', false, 'DESC', true); $xoopsTpl->assign('xoops_pagetitle', $pagetitle); //description $xoTheme->addMeta('meta', 'description', strip_tags(_MD_TDMDOWNLOADS_SINGLEFILE_MODIFY . ' (' . $viewDownloads->getVar('title') . ')')); @@ -77,12 +84,17 @@ //Affichage du formulaire de notation des téléchargements if ($perm_autoapprove) { /** @var \XoopsModules\Tdmdownloads\Downloads $obj */ + $obj = $downloadsHandler->get($lid); + /** @var \XoopsThemeForm $form */ + $form = $obj->getForm($donnee = [], false, 'submit.php'); } else { /** @var \XoopsModules\Tdmdownloads\Modified $obj */ + $obj = $modifiedHandler->create(); + $form = $obj->getForm($lid, false, $donnee = []); } $xoopsTpl->assign('themeForm', $form->render()); @@ -92,10 +104,10 @@ case 'save': require_once XOOPS_ROOT_PATH . '/class/uploader.php'; /** @var \XoopsModules\Tdmdownloads\Downloads $obj */ - $obj = $modifiedHandler->create(); - $erreur = false; + $obj = $modifiedHandler->create(); + $erreur = false; $errorMessage = ''; - $donnee = []; + $donnee = []; $obj->setVar('title', \Xmf\Request::getString('title', '', 'POST')); //$_POST['title']); $donnee['title'] = \Xmf\Request::getString('title', '', 'POST'); //$_POST['title']; $obj->setVar('cid', \Xmf\Request::getInt('cid', 0, 'POST')); //$_POST['cid']); @@ -119,16 +131,21 @@ if (\Xmf\Request::hasVar('cid')) { if (0 == \Xmf\Request::getInt('cid', 0, 'POST')) { $erreur = true; + $errorMessage .= _MD_TDMDOWNLOADS_ERREUR_NOCAT . '
    '; } } // get captcha (members are skipped in class/download.php getForm if (!$xoopsUser) { // erreur si le captcha est faux + xoops_load('xoopscaptcha'); + $xoopsCaptcha = \XoopsCaptcha::getInstance(); + if (!$xoopsCaptcha->verify()) { $errorMessage .= $xoopsCaptcha->getMessage() . '
    '; + $erreur = true; } } @@ -139,8 +156,10 @@ $downloads_field = $fieldHandler->getAll($criteria); foreach (array_keys($downloads_field) as $i) { /** @var \XoopsModules\Tdmdownloads\Field[] $downloads_field */ + if (0 == $downloads_field[$i]->getVar('status_def')) { $fieldName = 'champ' . $downloads_field[$i]->getVar('fid'); + $donnee[$fieldName] = \Xmf\Request::getString($fieldName, '', 'POST'); } } @@ -148,50 +167,72 @@ $xoopsTpl->assign('message_erreur', $errorMessage); } else { // Pour le fichier - $mediaSize = 0; + + $mediaSize = 0; + if (isset($_POST['xoops_upload_file'][0])) { - $uploader = new \XoopsMediaUploader($uploaddir_downloads, $helper->getConfig('mimetype'), $helper->getConfig('maxuploadsize'), null, null); + $uploader = new \XoopsMediaUploader($uploaddir_downloads, $helper->getConfig('mimetypes'), $helper->getConfig('maxuploadsize'), null, null); + if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) { if ($helper->getConfig('newnamedownload')) { $uploader->setPrefix($helper->getConfig('prefixdownloads')); } + $uploader->fetchMedia($_POST['xoops_upload_file'][0]); + if (!$uploader->upload()) { $errors = $uploader->getErrors(); + redirect_header('javascript:history.go(-1)', 3, $errors); } else { - $mediaSize = $uploader->getMediaSize(); + $mediaSize = $uploader->getMediaSize(); + $obj->setVar('url', $uploadurl_downloads . $uploader->getSavedFileName()); } } else { if ($_FILES['attachedfile']['name'] > '') { // file name was given, but fetchMedia failed - show error when e.g. file size exceed maxuploadsize + $errorMessage .= $uploader->getErrors() . '
    '; + $GLOBALS['xoopsTpl']->assign('message_erreur', $errorMessage); + /** @var \XoopsThemeForm $form */ + $form = $obj->getForm($donnee, true); + $GLOBALS['xoopsTpl']->assign('themeForm', $form->render()); + break; } + $obj->setVar('url', \Xmf\Request::getString('url', '', 'REQUEST')); } } else { - $obj->setVar('url', \Xmf\Request::getString('url', '', 'REQUEST')); - } + $obj->setVar('url', \Xmf\Request::getString('url', '', 'REQUEST')); + } + // Pour l'image + if (isset($_POST['xoops_upload_file'][1])) { - $uploader_2 = new \XoopsMediaUploader($uploaddir_shots, [ - 'image/gif', - 'image/jpeg', - 'image/pjpeg', - 'image/x-png', - 'image/png', - ], $helper->getConfig('maxuploadsize'), null, null); + $uploader_2 = new \XoopsMediaUploader( + $uploaddir_shots, [ + 'image/gif', + 'image/jpeg', + 'image/pjpeg', + 'image/x-png', + 'image/png', + ], $helper->getConfig('maxuploadsize'), null, null + ); + if ($uploader_2->fetchMedia($_POST['xoops_upload_file'][1])) { $uploader_2->setPrefix('downloads_'); + $uploader_2->fetchMedia($_POST['xoops_upload_file'][1]); + if (!$uploader_2->upload()) { $errors = $uploader_2->getErrors(); + redirect_header('javascript:history.go(-1)', 3, $errors); } else { $obj->setVar('logourl', $uploader_2->getSavedFileName()); @@ -199,60 +240,94 @@ } else { if ($_FILES['attachedimage']['name'] > '') { // file name was given, but fetchMedia failed - show error when e.g. file size exceed maxuploadsize + $errorMessage .= $uploader_2->getErrors() . '
    '; + $GLOBALS['xoopsTpl']->assign('message_erreur', $errorMessage); + $form = $obj->getForm($donnee, true); + $GLOBALS['xoopsTpl']->assign('themeForm', $form->render()); + break; } + $obj->setVar('logourl', \Xmf\Request::getString('logo_img', '', 'REQUEST')); } } else { - $obj->setVar('logourl', \Xmf\Request::getString('logo_img', '', 'REQUEST')); - } - //Automatic file size - if (Xmf\Request::getString('sizeValue', '') == ''){ - if ($mediaSize == 0) { - $obj->setVar('size', $utility::GetFileSize(Xmf\Request::getUrl('url', ''))); - } else { - $obj->setVar('size', $utility::FileSizeConvert($mediaSize)); - } - } else { - $obj->setVar('size', Xmf\Request::getFloat('sizeValue', 0) . ' ' . Xmf\Request::getString('sizeType', '')); - } - $timeToRedirect = 2; - if ($obj->getVar('size') == 0){ - $obj->setVar('size', ''); - $error_message = _AM_TDMDOWNLOADS_ERREUR_SIZE; - $timeToRedirect = 10; - } + $obj->setVar('logourl', \Xmf\Request::getString('logo_img', '', 'REQUEST')); + } + + //Automatic file size + + if ('' == Xmf\Request::getString('sizeValue', '')) { + if (0 == $mediaSize) { + $obj->setVar('size', $utility::getFileSize(Xmf\Request::getUrl('url', ''))); + } else { + $obj->setVar('size', $utility::convertFileSize($mediaSize)); + } + } else { + $obj->setVar('size', Xmf\Request::getFloat('sizeValue', 0) . ' ' . Xmf\Request::getString('sizeType', '')); + } + + $timeToRedirect = 2; + + if (0 == $obj->getVar('size')) { + $obj->setVar('size', ''); + + $error_message = _AM_TDMDOWNLOADS_ERREUR_SIZE; + + $timeToRedirect = 10; + } + if ($modifiedHandler->insert($obj)) { $lidDownloads = $obj->getNewEnreg($db); + // Récupération des champs supplémentaires: + $criteria = new \CriteriaCompo(); + $criteria->setSort('weight ASC, title'); + $criteria->setOrder('ASC'); + $downloads_field = $fieldHandler->getAll($criteria); + foreach (array_keys($downloads_field) as $i) { /** @var \XoopsModules\Tdmdownloads\Field[] $downloads_field */ + if (0 == $downloads_field[$i]->getVar('status_def')) { //$objdata = $modifiedfielddataHandler->create(); + $objdata = $modifieddataHandler->create(); + $fieldName = 'champ' . $downloads_field[$i]->getVar('fid'); + $objdata->setVar('moddata', \Xmf\Request::getString($fieldName, '', 'POST')); + $objdata->setVar('lid', $lidDownloads); + $objdata->setVar('fid', $downloads_field[$i]->getVar('fid')); + //$modifiedfielddataHandler->insert($objdata) || $objdata->getHtmlErrors(); + $modifieddataHandler->insert($objdata) || $objdata->getHtmlErrors(); } } + $tags = []; + $tags['MODIFYREPORTS_URL'] = XOOPS_URL . '/modules/' . $moduleDirName . '/admin/modified.php'; + /** @var \XoopsNotificationHandler $notificationHandler */ + $notificationHandler = xoops_getHandler('notification'); + $notificationHandler->triggerEvent('global', 0, 'file_modify', $tags); - redirect_header('singlefile.php?lid=' . \Xmf\Request::getInt('lid', 0, 'REQUEST'), timeToRedirect, _MD_TDMDOWNLOADS_MODFILE_THANKSFORINFO . '

    ' . $error_message); + + redirect_header('singlefile.php?lid=' . \Xmf\Request::getInt('lid', 0, 'REQUEST'), $timeToRedirect, _MD_TDMDOWNLOADS_MODFILE_THANKSFORINFO . '

    ' . $error_message); } + echo $obj->getHtmlErrors(); } //Affichage du formulaire de notation des téléchargements diff --git a/notification_update.php b/notification_update.php index ee35836..23589e2 100644 --- a/notification_update.php +++ b/notification_update.php @@ -1,4 +1,5 @@ - */ -defined('XOOPS_ROOT_PATH') || die('Restricted access'); /** * Class TdmdownloadsCorePreload @@ -21,7 +22,6 @@ class TdmdownloadsCorePreload extends \XoopsPreloadItem { // to add PSR-4 autoloader - /** * @param $args */ diff --git a/preloads/index.html b/preloads/index.html deleted file mode 100644 index 2c5cdd3..0000000 --- a/preloads/index.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/preloads/index.php b/preloads/index.php new file mode 100644 index 0000000..2ea9b7d --- /dev/null +++ b/preloads/index.php @@ -0,0 +1,3 @@ +getItemIds('tdmdownloads_view', $moduleDirName); -if (!in_array($viewDownloads->getVar('cid'), $categories, true)) { +if (!in_array($viewDownloads->getVar('cid'), $categories)) { redirect_header(XOOPS_URL, 2, _NOPERM); } @@ -53,16 +57,16 @@ $criteria->setOrder('ASC'); $criteria->add(new \Criteria('cat_cid', '(' . implode(',', $categories) . ')', 'IN')); $downloadscatArray = $categoryHandler->getAll($criteria); - $mytree = new \XoopsModules\Tdmdownloads\Tree($downloadscatArray, 'cat_cid', 'cat_pid'); + $mytree = new Tree($downloadscatArray, 'cat_cid', 'cat_pid'); //navigation - $navigation = $utility->getPathTreeUrl($mytree, $viewDownloads->getVar('cid'), $downloadscatArray, 'cat_title', $prefix = ' arrow ', true, 'ASC', true); + $navigation = $utility::getPathTreeUrl($mytree, $viewDownloads->getVar('cid'), $downloadscatArray, 'cat_title', $prefix = ' arrow ', true, 'ASC', true); $navigation .= ' arrow ' . $viewDownloads->getVar('title') . ''; $navigation .= ' arrow ' . _MD_TDMDOWNLOADS_SINGLEFILE_RATHFILE; $xoopsTpl->assign('navigation', $navigation); // référencement // titre de la page $pagetitle = _MD_TDMDOWNLOADS_SINGLEFILE_RATHFILE . ' - ' . $viewDownloads->getVar('title') . ' - '; - $pagetitle .= $utility->getPathTreeUrl($mytree, $viewDownloads->getVar('cid'), $downloadscatArray, 'cat_title', $prefix = ' - ', false, 'DESC', true); + $pagetitle .= $utility::getPathTreeUrl($mytree, $viewDownloads->getVar('cid'), $downloadscatArray, 'cat_title', $prefix = ' - ', false, 'DESC', true); $xoopsTpl->assign('xoops_pagetitle', $pagetitle); //description $xoTheme->addMeta('meta', 'description', strip_tags(_MD_TDMDOWNLOADS_SINGLEFILE_RATHFILE . ' (' . $viewDownloads->getVar('title') . ')')); @@ -85,49 +89,68 @@ // si c'est un membre on vérifie qu'il ne vote pas pour son fichier if (0 !== $ratinguser) { $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('lid', $lid)); + $downloadsArray = $downloadsHandler->getAll($criteria); + foreach (array_keys($downloadsArray) as $i) { /** @var \XoopsModules\Tdmdownloads\Downloads[] $downloadsArray */ + if ($downloadsArray[$i]->getVar('submitter') == $ratinguser) { redirect_header('singlefile.php?lid=' . \Xmf\Request::getInt('lid', 0), 2, _MD_TDMDOWNLOADS_RATEFILE_CANTVOTEOWN); } } + // si c'est un membre on vérifie qu'il ne vote pas 2 fois + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('lid', $lid)); + $votesArray = $ratingHandler->getAll($criteria); + foreach (array_keys($votesArray) as $i) { /** @var \XoopsModules\Wfdownloads\Rating[] $votesArray */ + if ($votesArray[$i]->getVar('ratinguser') === $ratinguser) { redirect_header('singlefile.php?lid=' . \Xmf\Request::getInt('lid', 0), 2, _MD_TDMDOWNLOADS_RATEFILE_VOTEONCE); } } } else { // si c'est un utilisateur anonyme on vérifie qu'il ne vote pas 2 fois par jour - $yesterday = (time() - 86400); - $criteria = new \CriteriaCompo(); + + $yesterday = time() - 86400; + + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('lid', $lid)); + $criteria->add(new \Criteria('ratinguser', 0)); + $criteria->add(new \Criteria('ratinghostname', getenv('REMOTE_ADDR'))); + $criteria->add(new \Criteria('ratingtimestamp', $yesterday, '>')); + if ($ratingHandler->getCount($criteria) >= 1) { redirect_header('singlefile.php?lid=' . \Xmf\Request::getInt('lid', 0), 2, _MD_TDMDOWNLOADS_RATEFILE_VOTEONCE); } } - $erreur = false; + $erreur = false; $errorMessage = ''; // Test avant la validation $rating = \Xmf\Request::getInt('rating', 0, 'POST'); if ($rating < 0 || $rating > 10) { $errorMessage .= _MD_TDMDOWNLOADS_RATEFILE_NORATING . '
    '; - $erreur = true; + + $erreur = true; } xoops_load('captcha'); $xoopsCaptcha = \XoopsCaptcha::getInstance(); if (!$xoopsCaptcha->verify()) { $errorMessage .= $xoopsCaptcha->getMessage() . '
    '; - $erreur = true; + + $erreur = true; } $obj->setVar('lid', $lid); $obj->setVar('ratinguser', $ratinguser); @@ -139,22 +162,34 @@ } else { if ($ratingHandler->insert($obj)) { $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('lid', $lid)); + $votesArray = $ratingHandler->getAll($criteria); - $votesTotal = $ratingHandler->getCount($criteria); - $ratingTotal = 0; + + $votesTotal = $ratingHandler->getCount($criteria); + + $ratingTotal = 0; + foreach (array_keys($votesArray) as $i) { $ratingTotal += $votesArray[$i]->getVar('rating'); } - $rating = $ratingTotal / $votesTotal; + + $rating = $ratingTotal / $votesTotal; + $objdownloads = $downloadsHandler->get($lid); - $objdownloads->setVar('rating', number_format($rating, 1)); + + $objdownloads->setVar('rating', number_format((float)$rating, 1)); + $objdownloads->setVar('votes', $votesTotal); + if ($downloadsHandler->insert($objdownloads)) { redirect_header('singlefile.php?lid=' . $lid, 2, _MD_TDMDOWNLOADS_RATEFILE_VOTEOK); } + echo $objdownloads->getHtmlErrors(); } + echo $obj->getHtmlErrors(); } //Affichage du formulaire de notation des téléchargements diff --git a/rss.php b/rss.php index fdf1d2b..f40ced8 100644 --- a/rss.php +++ b/rss.php @@ -1,4 +1,5 @@ -activated = false; require_once XOOPS_ROOT_PATH . '/class/template.php'; global $xoopsModuleConfig; /** @var \XoopsModules\Tdmdownloads\Helper $helper */ -$helper = \XoopsModules\Tdmdownloads\Helper::getInstance(); +$helper = Helper::getInstance(); $itemsCount = $helper->getConfig('perpagerss'); -$cid = \Xmf\Request::getInt('cid', 0, 'GET'); +$cid = \Xmf\Request::getInt('cid', 0, 'GET'); if (function_exists('mb_http_output')) { mb_http_output('pass'); } @@ -40,7 +44,9 @@ $criteria->add(new \Criteria('cid', '(' . implode(',', $categories) . ')', 'IN')); if (0 !== $cid) { $criteria->add(new \Criteria('cid', $cid)); - $cat = $categoryHandler->get($cid); + + $cat = $categoryHandler->get($cid); + $title = $xoopsConfig['sitename'] . ' - ' . $xoopsModule->getVar('name') . ' - ' . $cat->getVar('cat_title'); } else { $title = $xoopsConfig['sitename'] . ' - ' . $xoopsModule->getVar('name'); @@ -52,14 +58,23 @@ if (!$xoopsTpl->is_cached('db:tdmdownloads_rss.tpl', $cid)) { $xoopsTpl->assign('channel_title', htmlspecialchars($title, ENT_QUOTES)); + $xoopsTpl->assign('channel_link', XOOPS_URL . '/'); + $xoopsTpl->assign('channel_desc', htmlspecialchars($xoopsConfig['slogan'], ENT_QUOTES)); + $xoopsTpl->assign('channel_lastbuild', formatTimestamp(time(), 'rss')); + $xoopsTpl->assign('channel_webmaster', $xoopsConfig['adminmail']); + $xoopsTpl->assign('channel_editor', $xoopsConfig['adminmail']); + $xoopsTpl->assign('channel_category', 'Event'); + $xoopsTpl->assign('channel_generator', 'XOOPS - ' . htmlspecialchars($xoopsModule->getVar('name'), ENT_QUOTES)); + $xoopsTpl->assign('channel_language', _LANGCODE); + if (_LANGCODE === 'fr') { $xoopsTpl->assign('docs', 'http://www.scriptol.fr/rss/RSS-2.0.html'); } else { @@ -67,35 +82,48 @@ } $xoopsTpl->assign('image_url', XOOPS_URL . $helper->getConfig('logorss')); + $dimention = getimagesize(XOOPS_ROOT_PATH . $helper->getConfig('logorss')); + if (empty($dimention[0])) { $width = 88; } else { - $width = ($dimention[0] > 144) ? 144 : $dimention[0]; + $width = $dimention[0] > 144 ? 144 : $dimention[0]; } + if (empty($dimention[1])) { $height = 31; } else { - $height = ($dimention[1] > 400) ? 400 : $dimention[1]; + $height = $dimention[1] > 400 ? 400 : $dimention[1]; } + $xoopsTpl->assign('image_width', $width); + $xoopsTpl->assign('image_height', $height); + foreach (array_keys($downloadsArray) as $i) { /** @var \XoopsModules\Tdmdownloads\Downloads[] $downloadsArray */ + $description = $downloadsArray[$i]->getVar('description'); + //permet d'afficher uniquement la description courte + if (false === mb_strpos($description, '[pagebreak]')) { $descriptionShort = $description; } else { $descriptionShort = mb_substr($description, 0, mb_strpos($description, '[pagebreak]')); } - $xoopsTpl->append('items', [ - 'title' => htmlspecialchars($downloadsArray[$i]->getVar('title'), ENT_QUOTES), - 'link' => XOOPS_URL . '/modules/' . $moduleDirName . '/singlefile.php?cid=' . $downloadsArray[$i]->getVar('cid') . '&lid=' . $downloadsArray[$i]->getVar('lid'), - 'guid' => XOOPS_URL . '/modules/' . $moduleDirName . '/singlefile.php?cid=' . $downloadsArray[$i]->getVar('cid') . '&lid=' . $downloadsArray[$i]->getVar('lid'), - 'pubdate' => formatTimestamp($downloadsArray[$i]->getVar('date'), 'rss'), - 'description' => htmlspecialchars($descriptionShort, ENT_QUOTES), - ]); + + $xoopsTpl->append( + 'items', + [ + 'title' => htmlspecialchars($downloadsArray[$i]->getVar('title'), ENT_QUOTES), + 'link' => XOOPS_URL . '/modules/' . $moduleDirName . '/singlefile.php?cid=' . $downloadsArray[$i]->getVar('cid') . '&lid=' . $downloadsArray[$i]->getVar('lid'), + 'guid' => XOOPS_URL . '/modules/' . $moduleDirName . '/singlefile.php?cid=' . $downloadsArray[$i]->getVar('cid') . '&lid=' . $downloadsArray[$i]->getVar('lid'), + 'pubdate' => formatTimestamp($downloadsArray[$i]->getVar('date'), 'rss'), + 'description' => htmlspecialchars($descriptionShort, ENT_QUOTES), + ] + ); } } header('Content-Type:text/xml; charset=' . _CHARSET); diff --git a/search.php b/search.php index 7c5e215..e9f05fd 100644 --- a/search.php +++ b/search.php @@ -1,4 +1,5 @@ -getHandler('Downloads'); +require __DIR__ . '/include/common.php'; // template d'affichage $GLOBALS['xoopsOption']['template_main'] = 'tdmdownloads_liste.tpl'; @@ -58,11 +72,11 @@ $cat_select->addOptionArray($categoryHandler->getList($criteria )); $form->addElement($cat_select);*/ $downloadscatArray = $categoryHandler->getAll($criteria); -$mytree = new \XoopsModules\Tdmdownloads\Tree($downloadscatArray, 'cat_cid', 'cat_pid'); +$mytree = new Tree($downloadscatArray, 'cat_cid', 'cat_pid'); $form->addElement($mytree->makeSelectElement('cat', 'cat_title', '--', $cat, true, 0, '', _AM_TDMDOWNLOADS_FORMINCAT), true); //recherche champ sup. -//$fieldHandler = \XoopsModules\Tdmdownloads\Helper::getInstance()->getHandler('Field'); +//$fieldHandler = Helper::getInstance()->getHandler('Field'); $criteria = new \CriteriaCompo(); $criteria->add(new \Criteria('search', 1)); $criteria->add(new \Criteria('status', 1)); @@ -73,87 +87,136 @@ $arguments = ''; foreach (array_keys($downloads_field) as $i) { /** @var \XoopsModules\Tdmdownloads\Field[] $downloads_field */ + $title_sup = ''; + $contentArray = []; + $lid_arr = []; + $fieldName = 'champ' . $downloads_field[$i]->getVar('fid'); + $criteria = new \CriteriaCompo(); + if (\Xmf\Request::hasVar($fieldName, 'REQUEST')) { 999 !== \Xmf\Request::getInt($fieldName, 0, 'REQUEST') ? $fieldContent[$downloads_field[$i]->getVar('fid')] = \Xmf\Request::getInt($fieldName, 0, 'REQUEST') : $fieldContent[$downloads_field[$i]->getVar('fid')] = 999; + $arguments .= $fieldName . '=' . \Xmf\Request::getInt($fieldName, 0, 'REQUEST') . '&'; } else { $fieldContent[$downloads_field[$i]->getVar('fid')] = 999; + $arguments .= $fieldName . '=&'; } + if (1 == $downloads_field[$i]->getVar('status_def')) { $criteria->add(new \Criteria('status', 0, '!=')); + if (1 == $downloads_field[$i]->getVar('fid')) { //page d'accueil + $title_sup = _AM_TDMDOWNLOADS_FORMHOMEPAGE; + $criteria->setSort('homepage'); + $fieldNameBase = 'homepage'; } + if (2 == $downloads_field[$i]->getVar('fid')) { //version + $title_sup = _AM_TDMDOWNLOADS_FORMVERSION; + $criteria->setSort('version'); + $fieldNameBase = 'version'; } + if (3 == $downloads_field[$i]->getVar('fid')) { //taille du fichier + $title_sup = _AM_TDMDOWNLOADS_FORMSIZE; + $criteria->setSort('size'); + $fieldNameBase = 'size'; } + if (4 == $downloads_field[$i]->getVar('fid')) { //platform + $title_sup = _AM_TDMDOWNLOADS_FORMPLATFORM; + $platformArray = explode('|', $helper->getConfig('plateform')); + foreach ($platformArray as $platform) { $contentArray[$platform] = $platform; } + if (999 !== $fieldContent[$downloads_field[$i]->getVar('fid')]) { $criteria_2->add(new \Criteria('platform', '%' . $fieldContent[$downloads_field[$i]->getVar('fid')] . '%', 'LIKE')); } } else { $criteria->setOrder('ASC'); + + /** @var Downloads $tdmdownloadsArray */ $tdmdownloadsArray = $downloadsHandler->getAll($criteria); + foreach (array_keys($tdmdownloadsArray) as $j) { /** @var \XoopsModules\Tdmdownloads\Downloads[] $tdmdownloadsArray */ - $contentArray[$tdmdownloadsArray[$j]->getVar($fieldNameBase)] = $tdmdownloadsArray[$j]->getVar($fieldNameBase); + $temp = $tdmdownloadsArray[$j]->getVar($fieldNameBase); + $contentArray[$temp] = $temp; } + if (999 !== $fieldContent[$downloads_field[$i]->getVar('fid')]) { $criteria_2->add(new \Criteria($fieldNameBase, $fieldContent[$downloads_field[$i]->getVar('fid')])); } } } else { $title_sup = $downloads_field[$i]->getVar('title'); + $criteria->add(new \Criteria('fid', $downloads_field[$i]->getVar('fid'))); + $criteria->setSort('data'); + $criteria->setOrder('ASC'); + $tdmdownloadsArray = $fielddataHandler->getAll($criteria); + foreach (array_keys($tdmdownloadsArray) as $j) { /** @var \XoopsModules\Tdmdownloads\Downloads[] $tdmdownloadsArray */ + $contentArray[$tdmdownloadsArray[$j]->getVar('data', 'n')] = $tdmdownloadsArray[$j]->getVar('data'); } + if ('' !== $fieldContent[$downloads_field[$i]->getVar('fid')]) { $criteria_1 = new \CriteriaCompo(); + $criteria_1->add(new \Criteria('data', $fieldContent[$downloads_field[$i]->getVar('fid')])); + $dataArray = $fielddataHandler->getAll($criteria_1); + foreach (array_keys($dataArray) as $k) { /** @var \XoopsModules\Tdmdownloads\Fielddata[] $dataArray */ + $lid_arr[] = $dataArray[$k]->getVar('lid'); } } } + if (count($lid_arr) > 0) { $criteria_2->add(new \Criteria('lid', '(' . implode(',', $lid_arr) . ')', 'IN')); } + $select_sup = new \XoopsFormSelect($title_sup, $fieldName, $fieldContent[$downloads_field[$i]->getVar('fid')]); + $select_sup->addOption(999, _MD_TDMDOWNLOADS_SEARCH_ALL1); + $select_sup->addOptionArray($contentArray); + $form->addElement($select_sup); + unset($select_sup); + $xoopsTpl->append('field', $downloads_field[$i]->getVar('title')); } @@ -164,22 +227,24 @@ if ('' !== $title) { $criteria_2->add(new \Criteria('title', '%' . $title . '%', 'LIKE')); + $arguments .= 'title=' . $title . '&'; } if (0 !== $cat) { $criteria_2->add(new \Criteria('cid', $cat)); + $arguments .= 'cat=' . $cat . '&'; } -$tblsort = []; -$tblsort[1] = 'date'; -$tblsort[2] = 'date'; -$tblsort[3] = 'hits'; -$tblsort[4] = 'hits'; -$tblsort[5] = 'rating'; -$tblsort[6] = 'rating'; -$tblsort[7] = 'title'; -$tblsort[8] = 'title'; -$tblorder = []; +$tblsort = []; +$tblsort[1] = 'date'; +$tblsort[2] = 'date'; +$tblsort[3] = 'hits'; +$tblsort[4] = 'hits'; +$tblsort[5] = 'rating'; +$tblsort[6] = 'rating'; +$tblsort[7] = 'title'; +$tblsort[8] = 'title'; +$tblorder = []; $tblorder[1] = 'DESC'; $tblorder[2] = 'ASC'; $tblorder[3] = 'DESC'; @@ -188,33 +253,39 @@ $tblorder[6] = 'ASC'; $tblorder[7] = 'DESC'; $tblorder[8] = 'ASC'; -$sort = null !== $helper->getConfig('searchorder') ? $helper->getConfig('searchorder') : 1; -$order = null !== $helper->getConfig('searchorder') ? $helper->getConfig('searchorder') : 1; +$sort = $helper->getConfig('searchorder') ?? 1; +$order = $helper->getConfig('searchorder') ?? 1; $criteria_2->setSort($tblsort[$sort]); $criteria_2->setOrder($tblorder[$order]); $numrows = $downloadsHandler->getCount($criteria_2); if (\Xmf\Request::hasVar('limit', 'REQUEST')) { $criteria_2->setLimit(\Xmf\Request::getInt('limit', 0, 'REQUEST')); + $limit = \Xmf\Request::getInt('limit', 0, 'REQUEST'); } else { $criteria_2->setLimit($helper->getConfig('perpageliste')); + $limit = $helper->getConfig('perpageliste'); } if (\Xmf\Request::hasVar('start', 'REQUEST')) { $criteria_2->setStart(\Xmf\Request::getInt('start', 0, 'REQUEST')); + $start = \Xmf\Request::getInt('start', 0, 'REQUEST'); } else { $criteria_2->setStart(0); + $start = 0; } //pour faire une jointure de table -$downloadsHandler->table_link = $downloadsHandler->db->prefix('tdmdownloads_cat'); // Nom de la table en jointure -$downloadsHandler->field_link = 'cat_cid'; // champ de la table en jointure +$downloadsHandler->table_link = $downloadsHandler->db->prefix('tdmdownloads_cat'); // Nom de la table en jointure +$downloadsHandler->field_link = 'cat_cid'; // champ de la table en jointure $downloadsHandler->field_object = 'cid'; // champ de la table courante -$tdmdownloadsArray = $downloadsHandler->getByLink($criteria_2); +$tdmdownloadsArray = $downloadsHandler->getByLink($criteria_2); if ($numrows > $limit) { - require_once XOOPS_ROOT_PATH.'/class/pagenav.php'; + require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; + $pagenav = new \XoopsPageNav($numrows, $limit, $start, 'start', $arguments); + $pagenav = $pagenav->renderNav(4); } else { $pagenav = ''; @@ -224,41 +295,63 @@ $keywords = ''; foreach (array_keys($tdmdownloadsArray) as $i) { $tdmdownloadsTab['lid'] = $tdmdownloadsArray[$i]->getVar('lid'); + $tdmdownloadsTab['cid'] = $tdmdownloadsArray[$i]->getVar('cid'); + $tdmdownloadsTab['title'] = $tdmdownloadsArray[$i]->getVar('title'); + $tdmdownloadsTab['cat'] = $tdmdownloadsArray[$i]->getVar('cat_title'); + $tdmdownloadsTab['imgurl'] = $uploadurl . $tdmdownloadsArray[$i]->getVar('cat_imgurl'); + $tdmdownloadsTab['date'] = formatTimestamp($tdmdownloadsArray[$i]->getVar('date'), 'd/m/Y'); - $tdmdownloadsTab['rating'] = number_format($tdmdownloadsArray[$i]->getVar('rating'), 0); + + $tdmdownloadsTab['rating'] = number_format((float)$tdmdownloadsArray[$i]->getVar('rating'), 0); + $tdmdownloadsTab['hits'] = $tdmdownloadsArray[$i]->getVar('hits'); + $contenu = ''; + foreach (array_keys($downloads_field) as $j) { if (1 == $downloads_field[$j]->getVar('status_def')) { if (1 == $downloads_field[$j]->getVar('fid')) { //page d'accueil + $contenu = $tdmdownloadsArray[$i]->getVar('homepage'); } + if (2 == $downloads_field[$j]->getVar('fid')) { //version + $contenu = $tdmdownloadsArray[$i]->getVar('version'); } + if (3 == $downloads_field[$j]->getVar('fid')) { //taille du fichier + //mb $contenu = $utilities->convertFileSize($tdmdownloads_arr[$i]->getVar('size')); + $contenu = $tdmdownloadsArray[$i]->getVar('size'); } + if (4 == $downloads_field[$j]->getVar('fid')) { //plateforme + $contenu = $tdmdownloadsArray[$i]->getVar('platform'); } } else { $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('lid', $tdmdownloadsArray[$i]->getVar('lid'))); + $criteria->add(new \Criteria('fid', $downloads_field[$j]->getVar('fid'))); + $downloadsfielddata = $fielddataHandler->getAll($criteria); + if (count($downloadsfielddata) > 0) { foreach (array_keys($downloadsfielddata) as $k) { /** @var \XoopsModules\Tdmdownloads\Fielddata[] $downloadsfielddata */ + $contenu = $downloadsfielddata[$k]->getVar('data', 'n'); } } else { @@ -267,8 +360,10 @@ } $tdmdownloadsTab['fielddata'][$j] = $contenu; + unset($contenu); } + $xoopsTpl->append('search_list', $tdmdownloadsTab); $keywords .= $tdmdownloadsArray[$i]->getVar('title') . ','; @@ -287,5 +382,6 @@ //keywords $keywords = mb_substr($keywords, 0, -1); $xoTheme->addMeta('meta', 'keywords', strip_tags($keywords)); +$GLOBALS['xoopsTpl']->assign('mod_url', XOOPS_URL . '/modules/' . $moduleDirName); require XOOPS_ROOT_PATH . '/footer.php'; diff --git a/singlefile.php b/singlefile.php index 15d9f97..590f533 100644 --- a/singlefile.php +++ b/singlefile.php @@ -1,6 +1,10 @@ -getItemIds('tdmdownloads_view', $moduleDirName); -if (!in_array($viewDownloads->getVar('cid'), $categories, true)) { +if (!in_array($viewDownloads->getVar('cid'), $categories)) { redirect_header(XOOPS_URL, 2, _NOPERM); } @@ -51,26 +55,30 @@ $criteria->setOrder('ASC'); $criteria->add(new \Criteria('cat_cid', '(' . implode(',', $categories) . ')', 'IN')); $downloadscatArray = $categoryHandler->getAll($criteria); -$mytree = new \XoopsModules\Tdmdownloads\Tree($downloadscatArray, 'cat_cid', 'cat_pid'); +$mytree = new Tree($downloadscatArray, 'cat_cid', 'cat_pid'); //navigation -$navigation = $utility->getPathTreeUrl($mytree, $viewDownloads->getVar('cid'), $downloadscatArray, 'cat_title', $prefix = ' arrow ', true, 'ASC', true); -$navigation = $navigation . ' arrow ' . $viewDownloads->getVar('title'); +$navigation = $utility::getPathTreeUrl($mytree, $viewDownloads->getVar('cid'), $downloadscatArray, 'cat_title', $prefix = ' arrow ', true, 'ASC', true); +$navigation .= ' arrow ' . $viewDownloads->getVar('title'); $xoopsTpl->assign('navigation', $navigation); // sortie des informations //Utilisation d'une copie d'écran avec la largeur selon les préférences if (1 == $helper->getConfig('useshots')) { $xoopsTpl->assign('shotwidth', $helper->getConfig('shotwidth')); + $xoopsTpl->assign('show_screenshot', true); + $xoopsTpl->assign('img_float', $helper->getConfig('img_float')); } if ('ltr' === $helper->getConfig('download_float')) { $xoopsTpl->assign('textfloat', 'floatleft'); + $xoopsTpl->assign('infofloat', 'floatright'); } else { $xoopsTpl->assign('textfloat', 'floatright'); + $xoopsTpl->assign('infofloat', 'floatleft'); } @@ -79,6 +87,7 @@ $logourl = ''; } else { $logourl = $viewDownloads->getVar('logourl'); + $logourl = $uploadurl_shots . $logourl; } // Défini si la personne est un admin @@ -116,7 +125,7 @@ $xoopsTpl->assign('date', formatTimestamp($viewDownloads->getVar('date'), 's')); $xoopsTpl->assign('author', \XoopsUser::getUnameFromId($viewDownloads->getVar('submitter'))); $xoopsTpl->assign('hits', sprintf(_MD_TDMDOWNLOADS_SINGLEFILE_NBTELECH, $viewDownloads->getVar('hits'))); -$xoopsTpl->assign('rating', number_format($viewDownloads->getVar('rating'), 1)); +$xoopsTpl->assign('rating', number_format((float)$viewDownloads->getVar('rating'), 1)); $xoopsTpl->assign('votes', sprintf(_MD_TDMDOWNLOADS_SINGLEFILE_VOTES, $viewDownloads->getVar('votes'))); $xoopsTpl->assign('nb_comments', sprintf(_MD_TDMDOWNLOADS_SINGLEFILE_COMMENTS, $viewDownloads->getVar('comments'))); $xoopsTpl->assign('show_bookmark', $helper->getConfig('show_bookmark')); @@ -135,6 +144,21 @@ } $xoopsTpl->assign('paypal', $paypal); +/** + * @param $k + * @return string + */ +function getXfieldKey($k) +{ + return \mb_strtolower( + str_replace( + ['Ü', 'ü', 'Ş', 'ş', 'I', 'ı', 'Ç', 'ç', 'Ğ', 'ğ', 'Ö', 'ö'], + ['u', 'u', 's', 's', 'i', 'i', 'c', 'c', 'g', 'g', 'o', 'o'], + $k + ) + ); +} + // pour les champs supplémentaires $criteria = new \CriteriaCompo(); $criteria->setSort('weight ASC, title'); @@ -145,62 +169,104 @@ $nb_champ = count($downloads_field); $champ_sup = ''; $champ_sup_vide = 0; +$xfields = []; foreach (array_keys($downloads_field) as $i) { /** @var \XoopsModules\Tdmdownloads\Field[] $downloads_field */ + if (1 == $downloads_field[$i]->getVar('status_def')) { if (1 == $downloads_field[$i]->getVar('fid')) { //page d'accueil + if ('' != $viewDownloads->getVar('homepage')) { $champ_sup = ' ' . _AM_TDMDOWNLOADS_FORMHOMEPAGE . ': ' . _MD_TDMDOWNLOADS_SINGLEFILE_ICI . ''; + ++$champ_sup_vide; + + $xfields['homepage'] = $champ_sup; } } + if (2 == $downloads_field[$i]->getVar('fid')) { //version + if ('' != $viewDownloads->getVar('version')) { $champ_sup = ' ' . _AM_TDMDOWNLOADS_FORMVERSION . ': ' . $viewDownloads->getVar('version'); + ++$champ_sup_vide; + + $xfields['version'] = $champ_sup; } } + if (3 == $downloads_field[$i]->getVar('fid')) { //taille du fichier + $size_value_arr = explode(' ', $viewDownloads->getVar('size')); + if ('' != $size_value_arr[0]) { - $champ_sup = ' ' . _AM_TDMDOWNLOADS_FORMSIZE . ': ' . $utility::SizeConvertString($viewDownloads->getVar('size')); + $champ_sup = ' ' . _AM_TDMDOWNLOADS_FORMSIZE . ': ' . $utility::convertSizeToString($viewDownloads->getVar('size')); + ++$champ_sup_vide; + + $xfields['size'] = $champ_sup; } } + if (4 == $downloads_field[$i]->getVar('fid')) { //plateforme + if ('' != $viewDownloads->getVar('platform')) { $champ_sup = ' ' . _AM_TDMDOWNLOADS_FORMPLATFORM . $viewDownloads->getVar('platform'); + ++$champ_sup_vide; + + $xfields['platform'] = $champ_sup; } } } else { $view_data = $fielddataHandler->get(); - $criteria = new \CriteriaCompo(); + + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('lid', \Xmf\Request::getInt('lid', 0, 'REQUEST'))); + $criteria->add(new \Criteria('fid', $downloads_field[$i]->getVar('fid'))); + $downloadsfielddata = $fielddataHandler->getAll($criteria); - $contenu = ''; + + $contenu = ''; + foreach (array_keys($downloadsfielddata) as $j) { /** @var \XoopsModules\Tdmdownloads\Fielddata[] $downloadsfielddata */ + $contenu = $downloadsfielddata[$j]->getVar('data', 'n'); } + if ('' != $contenu) { $champ_sup = ' ' . $downloads_field[$i]->getVar('title') . ': ' . $contenu; + ++$champ_sup_vide; + + $xfieldKey = getXfieldKey($downloads_field[$i]->getVar('title')); + + $xfields[$xfieldKey] = $contenu; } } + if ('' != $champ_sup) { - $xoopsTpl->append('champ_sup', [ - 'image' => $uploadurl_field . $downloads_field[$i]->getVar('img'), - 'data' => $champ_sup, - ]); + $xoopsTpl->append( + 'champ_sup', + [ + 'image' => $uploadurl_field . $downloads_field[$i]->getVar('img'), + 'data' => $champ_sup, + ] + ); } + $champ_sup = ''; } + +$xoopsTpl->assign('xfields', $xfields); if ($nb_champ > 0 && $champ_sup_vide > 0) { $xoopsTpl->assign('sup_aff', true); } else { @@ -212,13 +278,13 @@ $categories = $utility->getItemIds('tdmdownloads_download', $moduleDirName); $item = $utility->getItemIds('tdmdownloads_download_item', $moduleDirName); if (1 == $helper->getConfig('permission_download')) { - if (!in_array($viewDownloads->getVar('cid'), $categories, true)) { + if (!in_array($viewDownloads->getVar('cid'), $categories)) { $xoopsTpl->assign('perm_download', false); } else { $xoopsTpl->assign('perm_download', true); } } else { - if (!in_array($viewDownloads->getVar('lid'), $item, true)) { + if (!in_array($viewDownloads->getVar('lid'), $item)) { $xoopsTpl->assign('perm_download', false); } else { $xoopsTpl->assign('perm_download', true); @@ -226,37 +292,40 @@ } // pour utiliser tellafriend. -if ((1 == $helper->getConfig('usetellafriend')) && is_dir('../tellafriend')) { - $string = sprintf(_MD_TDMDOWNLOADS_SINGLEFILE_INTFILEFOUND, $xoopsConfig['sitename'] . ': ' . XOOPS_URL . '/modules/' . $moduleDirName . '/singlefile.php?lid=' . \Xmf\Request::getInt('lid', 0, 'REQUEST')); +if (1 == $helper->getConfig('usetellafriend') && is_dir('../tellafriend')) { + $string = sprintf(_MD_TDMDOWNLOADS_SINGLEFILE_INTFILEFOUND, $xoopsConfig['sitename'] . ': ' . XOOPS_URL . '/modules/' . $moduleDirName . '/singlefile.php?lid=' . \Xmf\Request::getInt('lid', 0, 'REQUEST')); + $subject = sprintf(_MD_TDMDOWNLOADS_SINGLEFILE_INTFILEFOUND, $xoopsConfig['sitename']); + if (false !== mb_strpos($subject, '%')) { $subject = rawurldecode($subject); } + if (false !== mb_stripos($string, '%3F')) { $string = rawurldecode($string); } + if (preg_match('/(' . preg_quote(XOOPS_URL, '/') . '.*)$/i', $string, $matches)) { $targetUri = str_replace('&', '&', $matches[1]); } else { $targetUri = XOOPS_URL . $_SERVER['REQUEST_URI']; } + $tellafriendText = '' . _MD_TDMDOWNLOADS_SINGLEFILE_TELLAFRIEND . ''; } else { - $tellafriendText = '' . _MD_TDMDOWNLOADS_SINGLEFILE_TELLAFRIEND . ''; + $tellafriendText = '' . _MD_TDMDOWNLOADS_SINGLEFILE_TELLAFRIEND . ''; } $xoopsTpl->assign('tellafriend_texte', $tellafriendText); // référencement // tags -if ((1 == $helper->getConfig('usetag')) && class_exists(Tag::class)) { +if (1 == $helper->getConfig('usetag') && class_exists(Tag::class)) { require_once XOOPS_ROOT_PATH . '/modules/tag/include/tagbar.php'; + $xoopsTpl->assign('tags', true); + $xoopsTpl->assign('tagbar', tagBar(\Xmf\Request::getInt('lid', 0, 'REQUEST'), 0)); } else { $xoopsTpl->assign('tags', false); @@ -264,7 +333,7 @@ // titre de la page $pagetitle = $viewDownloads->getVar('title') . ' - '; -$pagetitle .= $utility->getPathTreeUrl($mytree, $viewDownloads->getVar('cid'), $downloadscatArray, 'cat_title', $prefix = ' - ', false, 'DESC', true); +$pagetitle .= $utility::getPathTreeUrl($mytree, $viewDownloads->getVar('cid'), $downloadscatArray, 'cat_title', $prefix = ' - ', false, 'DESC', true); $xoopsTpl->assign('xoops_pagetitle', $pagetitle); //version for title $xoopsTpl->assign('version', $viewDownloads->getVar('version')); @@ -276,7 +345,7 @@ } $xoTheme->addMeta('meta', 'description', strip_tags($descriptionShort)); //keywords -$keywords = \Xmf\Metagen::generateKeywords($viewDownloads->getVar('description'), 10); +$keywords = Metagen::generateKeywords($viewDownloads->getVar('description'), 10); $xoTheme->addMeta('meta', 'keywords', implode(', ', $keywords)); /*$keywords = substr($keywords,0,-1); $xoTheme->addMeta( 'meta', 'keywords', $keywords);*/ diff --git a/sql/index.html b/sql/index.html deleted file mode 100644 index 990cbd6..0000000 --- a/sql/index.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/sql/index.php b/sql/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/sql/index.php @@ -0,0 +1,2 @@ +addStylesheet(XOOPS_URL . '/modules/' . $moduleDirName . '/assets/css/styles.css', null); //On recupere la valeur de l'argument op dans l'URL$ -$op = \Xmf\Request::getString('op', 'list'); +$op = \Xmf\Request::getString('op', 'list'); $lid = \Xmf\Request::getInt('lid', 0, 'REQUEST'); // redirection si pas de droit pour poster @@ -70,13 +76,14 @@ /** @var \XoopsModules\Tdmdownloads\Downloads $obj */ if (true === $perm_autoapprove && $lid > 0) { $obj = $downloadsHandler->get($lid); + $newUpload = false; } else { $obj = $downloadsHandler->create(); } - $erreur = false; + $erreur = false; $errorMessage = ''; - $donnee = []; + $donnee = []; $obj->setVar('title', \Xmf\Request::getString('title', '', 'POST')); $donnee['title'] = \Xmf\Request::getString('title', '', 'POST'); $obj->setVar('cid', \Xmf\Request::getString('cid', '', 'POST')); @@ -90,9 +97,11 @@ $obj->setVar('description', \Xmf\Request::getString('description', '', 'POST')); if (\Xmf\Request::hasVar('submitter', 'POST')) { $obj->setVar('submitter', \Xmf\Request::getString('submitter', '', 'POST')); + $donnee['submitter'] = \Xmf\Request::getString('submitter', '', 'POST'); } else { $obj->setVar('submitter', !empty($xoopsUser) ? $xoopsUser->getVar('uid') : 0); + $donnee['submitter'] = !empty($xoopsUser) ? $xoopsUser->getVar('uid') : 0; } $obj->setVar('date', time()); @@ -105,9 +114,11 @@ if ($xoopsUser->isAdmin($xoopsModule->mid())) { if (\Xmf\Request::hasVar('status', 'POST')) { $obj->setVar('status', \Xmf\Request::getInt('status', 0, 'POST')); + $donnee['status'] = \Xmf\Request::getInt('status', 0, 'POST'); } else { $obj->setVar('status', 0); + $donnee['status'] = 0; } } @@ -117,6 +128,7 @@ if (\Xmf\Request::hasVar('cid', 'REQUEST')) { if (0 === \Xmf\Request::getInt('cid', 0, 'REQUEST')) { $erreur = true; + $errorMessage .= _MD_TDMDOWNLOADS_ERREUR_NOCAT . '
    '; } } @@ -125,6 +137,7 @@ $xoopsCaptcha = \XoopsCaptcha::getInstance(); if (!$xoopsCaptcha->verify()) { $errorMessage .= $xoopsCaptcha->getMessage() . '
    '; + $erreur = true; } // pour enregistrer temporairement les valeur des champs sup @@ -134,172 +147,245 @@ $downloads_field = $fieldHandler->getAll($criteria); foreach (array_keys($downloads_field) as $i) { /** @var \XoopsModules\Tdmdownloads\Field[] $downloads_field */ + if (0 === $downloads_field[$i]->getVar('status_def')) { $fieldName = 'champ' . $downloads_field[$i]->getVar('fid'); + $donnee[$fieldName] = \Xmf\Request::getString($fieldName, '', 'POST'); } } // enregistrement temporaire des tags - if ((1 == $helper->getConfig('usetag')) && class_exists(Tag::class)) { + if (1 == $helper->getConfig('usetag') && class_exists(Tag::class)) { $donnee['TAG'] = $_POST['tag']; } if (true === $erreur) { $xoopsTpl->assign('message_erreur', $errorMessage); + /** @var \XoopsThemeForm $form */ + $form = $obj->getForm($donnee, true); + $GLOBALS['xoopsTpl']->assign('themeForm', $form->render()); + break; } - $obj->setVar('size', \Xmf\Request::getString('size', '', 'POST') . ' ' . \Xmf\Request::getString('type_size', '', 'POST')); - // Pour le fichier - $mediaSize = 0; - if (isset($_POST['xoops_upload_file'][0])) { - $uploader = new \XoopsMediaUploader($uploaddir_downloads, $helper->getConfig('mimetype'), $helper->getConfig('maxuploadsize'), null, null); - if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) { - if ($helper->getConfig('newnamedownload')) { - $uploader->setPrefix($helper->getConfig('prefixdownloads')); - } - $uploader->fetchMedia($_POST['xoops_upload_file'][0]); - if (!$uploader->upload()) { - $errors = $uploader->getErrors(); - redirect_header('javascript:history.go(-1)', 3, $errors); - } else { - $mediaSize = $uploader->getMediaSize(); - $obj->setVar('url', $uploadurl_downloads . $uploader->getSavedFileName()); - } - } else { - if ($_FILES['attachedfile']['name'] > '') { - // file name was given, but fetchMedia failed - show error when e.g. file size exceed maxuploadsize - $errorMessage .= $uploader->getErrors() . '
    '; - $GLOBALS['xoopsTpl']->assign('message_erreur', $errorMessage); - $form = $obj->getForm($donnee, true); - $GLOBALS['xoopsTpl']->assign('themeForm', $form->render()); - break; - } - $obj->setVar('url', \Xmf\Request::getString('url', '', 'REQUEST')); + $obj->setVar('size', \Xmf\Request::getString('size', '', 'POST') . ' ' . \Xmf\Request::getString('type_size', '', 'POST')); + // Pour le fichier + $mediaSize = 0; + if (isset($_POST['xoops_upload_file'][0])) { + $uploader = new \XoopsMediaUploader($uploaddir_downloads, $helper->getConfig('mimetypes'), $helper->getConfig('maxuploadsize'), null, null); + + if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) { + if ($helper->getConfig('newnamedownload')) { + $uploader->setPrefix($helper->getConfig('prefixdownloads')); } - } else { - $obj->setVar('url', \Xmf\Request::getString('url', '', 'REQUEST')); - } - // Pour l'image - if (isset($_POST['xoops_upload_file'][1])) { - $uploader_2 = new \XoopsMediaUploader($uploaddir_shots, [ - 'image/gif', - 'image/jpeg', - 'image/pjpeg', - 'image/x-png', - 'image/png', - ], $helper->getConfig('maxuploadsize'), null, null); - if ($uploader_2->fetchMedia($_POST['xoops_upload_file'][1])) { - $uploader_2->setPrefix('downloads_'); - $uploader_2->fetchMedia($_POST['xoops_upload_file'][1]); - if (!$uploader_2->upload()) { - $errors = $uploader_2->getErrors(); - redirect_header('javascript:history.go(-1)', 3, $errors); - } else { - $obj->setVar('logourl', $uploader_2->getSavedFileName()); - } + + $uploader->fetchMedia($_POST['xoops_upload_file'][0]); + + if (!$uploader->upload()) { + $errors = $uploader->getErrors(); + + redirect_header('javascript:history.go(-1)', 3, $errors); } else { - if ($_FILES['attachedimage']['name'] > '') { - // file name was given, but fetchMedia failed - show error when e.g. file size exceed maxuploadsize - $errorMessage .= $uploader_2->getErrors() . '
    '; - $GLOBALS['xoopsTpl']->assign('message_erreur', $errorMessage); - $form = $obj->getForm($donnee, true); - $GLOBALS['xoopsTpl']->assign('themeForm', $form->render()); - break; - } - $obj->setVar('logourl', \Xmf\Request::getString('logo_img', '', 'REQUEST')); + $mediaSize = $uploader->getMediaSize(); + + $obj->setVar('url', $uploadurl_downloads . $uploader->getSavedFileName()); } } else { - $obj->setVar('logourl', \Xmf\Request::getString('logo_img', '', 'REQUEST')); - } - //Automatic file size - if (Xmf\Request::getString('sizeValue', '') == ''){ - if ($mediaSize == 0) { - $obj->setVar('size', $utility::GetFileSize(Xmf\Request::getUrl('url', ''))); - } else { - $obj->setVar('size', $utility::FileSizeConvert($mediaSize)); - } - } else { - $obj->setVar('size', Xmf\Request::getFloat('sizeValue', 0) . ' ' . Xmf\Request::getString('sizeType', '')); - } - $timeToRedirect = 2; - if ($obj->getVar('size') == 0){ - $obj->setVar('size', ''); - $error_message = _AM_TDMDOWNLOADS_ERREUR_SIZE; - $timeToRedirect = 10; - } - if ($downloadsHandler->insert($obj)) { - if ($newUpload) { - $lidDownloads = $obj->getNewEnreg($db); + if ($_FILES['attachedfile']['name'] > '') { + // file name was given, but fetchMedia failed - show error when e.g. file size exceed maxuploadsize + + $errorMessage .= $uploader->getErrors() . '
    '; + + $GLOBALS['xoopsTpl']->assign('message_erreur', $errorMessage); + + $form = $obj->getForm($donnee, true); + + $GLOBALS['xoopsTpl']->assign('themeForm', $form->render()); + + break; + } + + $obj->setVar('url', \Xmf\Request::getString('url', '', 'REQUEST')); + } + } else { + $obj->setVar('url', \Xmf\Request::getString('url', '', 'REQUEST')); + } + // Pour l'image + if (isset($_POST['xoops_upload_file'][1])) { + $uploader_2 = new \XoopsMediaUploader( + $uploaddir_shots, [ + 'image/gif', + 'image/jpeg', + 'image/pjpeg', + 'image/x-png', + 'image/png', + ], $helper->getConfig('maxuploadsize'), null, null + ); + + if ($uploader_2->fetchMedia($_POST['xoops_upload_file'][1])) { + $uploader_2->setPrefix('downloads_'); + + $uploader_2->fetchMedia($_POST['xoops_upload_file'][1]); + + if (!$uploader_2->upload()) { + $errors = $uploader_2->getErrors(); + + redirect_header('javascript:history.go(-1)', 3, $errors); } else { - $lidDownloads = $lid; + $obj->setVar('logourl', $uploader_2->getSavedFileName()); } - //tags - if ((1 == $helper->getConfig('usetag')) && class_exists(TagHandler::class)) { - /** @var \XoopsModules\Tag\TagHandler $tagHandler */ - $tagHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Tag'); - $tagHandler->updateByItem($_POST['tag'], $lidDownloads, $moduleDirName, 0); + } else { + if ($_FILES['attachedimage']['name'] > '') { + // file name was given, but fetchMedia failed - show error when e.g. file size exceed maxuploadsize + + $errorMessage .= $uploader_2->getErrors() . '
    '; + + $GLOBALS['xoopsTpl']->assign('message_erreur', $errorMessage); + + $form = $obj->getForm($donnee, true); + + $GLOBALS['xoopsTpl']->assign('themeForm', $form->render()); + + break; } - // Récupération des champs supplémentaires: - $criteria = new \CriteriaCompo(); - $criteria->setSort('weight ASC, title'); - $criteria->setOrder('ASC'); - $downloads_field = $fieldHandler->getAll($criteria); - foreach (array_keys($downloads_field) as $i) { - if (0 === $downloads_field[$i]->getVar('status_def')) { - $objdata = $fielddataHandler->create(); - $fieldName = 'champ' . $downloads_field[$i]->getVar('fid'); - $objdata->setVar('data', \Xmf\Request::getString($fieldName, '', 'POST')); - $objdata->setVar('lid', $lidDownloads); - $objdata->setVar('fid', $downloads_field[$i]->getVar('fid')); - $fielddataHandler->insert($objdata) || $objdata->getHtmlErrors(); - } + + $obj->setVar('logourl', \Xmf\Request::getString('logo_img', '', 'REQUEST')); + } + } else { + $obj->setVar('logourl', \Xmf\Request::getString('logo_img', '', 'REQUEST')); + } + //Automatic file size + if ('' == Xmf\Request::getString('sizeValue', '')) { + if (0 == $mediaSize) { + $obj->setVar('size', $utility::getFileSize(Xmf\Request::getUrl('url', ''))); + } else { + $obj->setVar('size', $utility::convertFileSize($mediaSize)); + } + } else { + $obj->setVar('size', Xmf\Request::getFloat('sizeValue', 0) . ' ' . Xmf\Request::getString('sizeType', '')); + } + $timeToRedirect = 2; + if (0 == $obj->getVar('size')) { + $obj->setVar('size', ''); + + $error_message = _AM_TDMDOWNLOADS_ERREUR_SIZE; + + $timeToRedirect = 10; + } + if ($downloadsHandler->insert($obj)) { + if ($newUpload) { + $lidDownloads = $obj->getNewEnreg($db); + } else { + $lidDownloads = $lid; + } + + //tags + + if (1 == $helper->getConfig('usetag') && class_exists(TagHandler::class)) { + /** @var \XoopsModules\Tag\TagHandler $tagHandler */ + + $tagHandler = TagHelper::getInstance()->getHandler('Tag'); + + $tagHandler->updateByItem($_POST['tag'], $lidDownloads, $moduleDirName, 0); + } + + // Récupération des champs supplémentaires: + + $criteria = new \CriteriaCompo(); + + $criteria->setSort('weight ASC, title'); + + $criteria->setOrder('ASC'); + + $downloads_field = $fieldHandler->getAll($criteria); + + foreach (array_keys($downloads_field) as $i) { + if (0 === $downloads_field[$i]->getVar('status_def')) { + $objdata = $fielddataHandler->create(); + + $fieldName = 'champ' . $downloads_field[$i]->getVar('fid'); + + $objdata->setVar('data', \Xmf\Request::getString($fieldName, '', 'POST')); + + $objdata->setVar('lid', $lidDownloads); + + $objdata->setVar('fid', $downloads_field[$i]->getVar('fid')); + + $fielddataHandler->insert($objdata) || $objdata->getHtmlErrors(); } - if ($xoopsUser) { - if ($xoopsUser->isAdmin($xoopsModule->mid())) { - //permission pour télécharger - if (1 == $helper->getConfig('permission_download')) { - /** @var \XoopsGroupPermHandler $grouppermHandler */ - $grouppermHandler = xoops_getHandler('groupperm'); - $criteria = new \CriteriaCompo(); - $criteria->add(new \Criteria('gperm_itemid', $lidDownloads, '=')); - $criteria->add(new \Criteria('gperm_modid', $xoopsModule->getVar('mid'), '=')); - $criteria->add(new \Criteria('gperm_name', 'tdmdownloads_download_item', '=')); - $grouppermHandler->deleteAll($criteria); - if (\Xmf\Request::hasVar('item_download', 'POST')) { - foreach ($_POST['item_download'] as $onegroup_id) { - $grouppermHandler->addRight('tdmdownloads_download_item', $lidDownloads, $onegroup_id, $xoopsModule->getVar('mid')); - } + } + + if ($xoopsUser) { + if ($xoopsUser->isAdmin($xoopsModule->mid())) { + //permission pour télécharger + + if (1 == $helper->getConfig('permission_download')) { + /** @var \XoopsGroupPermHandler $grouppermHandler */ + $grouppermHandler = xoops_getHandler('groupperm'); + + $criteria = new \CriteriaCompo(); + + $criteria->add(new \Criteria('gperm_itemid', $lidDownloads, '=')); + + $criteria->add(new \Criteria('gperm_modid', $xoopsModule->getVar('mid'), '=')); + + $criteria->add(new \Criteria('gperm_name', 'tdmdownloads_download_item', '=')); + + $grouppermHandler->deleteAll($criteria); + + if (\Xmf\Request::hasVar('item_download', 'POST')) { + foreach ($_POST['item_download'] as $onegroup_id) { + $grouppermHandler->addRight('tdmdownloads_download_item', $lidDownloads, $onegroup_id, $xoopsModule->getVar('mid')); } } } } - /** @var \XoopsNotificationHandler $notificationHandler */ - $notificationHandler = xoops_getHandler('notification'); - $tags = []; - $tags['FILE_NAME'] = $donnee['title']; - $tags['FILE_URL'] = XOOPS_URL . '/modules/' . $moduleDirName . '/singlefile.php?cid=' . $donnee['cid'] . '&lid=' . $lidDownloads; - $downloadscat_cat = $categoryHandler->get($donnee['cid']); - $tags['CATEGORY_NAME'] = $downloadscat_cat->getVar('cat_title'); - $tags['CATEGORY_URL'] = XOOPS_URL . '/modules/' . $moduleDirName . '/viewcat.php?cid=' . $donnee['cid']; - - if (true === $perm_autoapprove) { - $notificationHandler->triggerEvent('global', 0, 'new_file', $tags); - $notificationHandler->triggerEvent('category', $donnee['cid'], 'new_file', $tags); - redirect_header('index.php', $timeToRedirect, _MD_TDMDOWNLOADS_SUBMIT_RECEIVED . '
    ' . _MD_TDMDOWNLOADS_SUBMIT_ISAPPROVED . '

    ' . $error_message); - exit; - } - $tags['WAITINGFILES_URL'] = XOOPS_URL . '/modules/' . $moduleDirName . '/admin/index.php?op=listNewDownloads'; - $notificationHandler->triggerEvent('global', 0, 'file_submit', $tags); - $notificationHandler->triggerEvent('category', $donnee['cid'], 'file_submit', $tags); - redirect_header('index.php', $timeToRedirect, _MD_TDMDOWNLOADS_SUBMIT_RECEIVED . '

    ' . $error_message); + } + + /** @var \XoopsNotificationHandler $notificationHandler */ + + $notificationHandler = xoops_getHandler('notification'); + + $tags = []; + + $tags['FILE_NAME'] = $donnee['title']; + + $tags['FILE_URL'] = XOOPS_URL . '/modules/' . $moduleDirName . '/singlefile.php?cid=' . $donnee['cid'] . '&lid=' . $lidDownloads; + + $downloadscat_cat = $categoryHandler->get($donnee['cid']); + + $tags['CATEGORY_NAME'] = $downloadscat_cat->getVar('cat_title'); + + $tags['CATEGORY_URL'] = XOOPS_URL . '/modules/' . $moduleDirName . '/viewcat.php?cid=' . $donnee['cid']; + + if (true === $perm_autoapprove) { + $notificationHandler->triggerEvent('global', 0, 'new_file', $tags); + + $notificationHandler->triggerEvent('category', $donnee['cid'], 'new_file', $tags); + + redirect_header('index.php', $timeToRedirect, _MD_TDMDOWNLOADS_SUBMIT_RECEIVED . '
    ' . _MD_TDMDOWNLOADS_SUBMIT_ISAPPROVED . '

    ' . $error_message); + exit; } - $errors = $obj->getHtmlErrors(); + + $tags['WAITINGFILES_URL'] = XOOPS_URL . '/modules/' . $moduleDirName . '/admin/index.php?op=listNewDownloads'; + + $notificationHandler->triggerEvent('global', 0, 'file_submit', $tags); + + $notificationHandler->triggerEvent('category', $donnee['cid'], 'file_submit', $tags); + + redirect_header('index.php', $timeToRedirect, _MD_TDMDOWNLOADS_SUBMIT_RECEIVED . '

    ' . $error_message); + + exit; + } + $errors = $obj->getHtmlErrors(); $form = $obj->getForm($donnee, true); $xoopsTpl->assign('themeForm', $form->render()); break; } + +$GLOBALS['xoopsTpl']->assign('mod_url', XOOPS_URL . '/modules/' . $moduleDirName); + require XOOPS_ROOT_PATH . '/footer.php'; diff --git a/templates/admin/index.html b/templates/admin/index.html deleted file mode 100644 index 990cbd6..0000000 --- a/templates/admin/index.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/templates/admin/index.php b/templates/admin/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/templates/admin/index.php @@ -0,0 +1,2 @@ + <{include file='db:tdmdownloads_admin_header.tpl'}> -<{if $message_erreur}> +<{if $message_erreur|default:''}>
    <{$message_erreur}>
    <{/if}> <{if $broken_list}> @@ -31,13 +31,13 @@ <{/if}>
    " . constant('CO_' . $moduleDirNameUpper . '_' . 'TITLE') @@ -90,10 +119,9 @@ function listBlocks() . '-' . _RIGHT . "" - . constant('CO_' - . $moduleDirNameUpper - . '_' - . 'WEIGHT') + . constant( + 'CO_' . $moduleDirNameUpper . '_' . 'WEIGHT' + ) . "" . constant('CO_' . $moduleDirNameUpper . '_' . 'VISIBLE') . "" @@ -107,10 +135,13 @@ function listBlocks() . '
    '; echo " " . _EDIT . " " . _CLONE . " "; + if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) { echo " getVar('bid') . "'>" . _DELETE . " "; } + echo " @@ -272,8 +323,10 @@ function listBlocks()
    " . $GLOBALS['xoopsSecurity']->getTokenHTML() . " @@ -284,32 +337,48 @@ function listBlocks() } /** - * @param $bid + * @param int $bid */ + function cloneBlock($bid) { require_once __DIR__ . '/admin_header.php'; + //require_once __DIR__ . '/admin_header.php'; + xoops_cp_header(); - $moduleDirName = basename(dirname(__DIR__)); - $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName + $moduleDirName = basename(dirname(__DIR__)); + + $moduleDirNameUpper = \mb_strtoupper($moduleDirName); //$capsDirName + xoops_loadLanguage('admin', 'system'); + xoops_loadLanguage('admin/blocksadmin', 'system'); + xoops_loadLanguage('admin/groups', 'system'); // mpu_adm_menu(); + $myblock = new \XoopsBlock($bid); + /** @var \XoopsMySQLDatabase $db */ - $db = \XoopsDatabaseFactory::getDatabaseConnection(); - $sql = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid; - $result = $db->query($sql); + + $db = \XoopsDatabaseFactory::getDatabaseConnection(); + + $sql = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid; + + $result = $db->query($sql); + $modules = []; - while (false !== ($row = $db->fetchArray($result))) { - $modules[] = (int)$row['module_id']; + if ($result instanceof \mysqli_result) { + while (false !== ($row = $db->fetchArray($result))) { + $modules[] = (int)$row['module_id']; + } } $is_custom = ('C' === $myblock->getVar('block_type') || 'E' === $myblock->getVar('block_type')); - $block = [ + + $block = [ 'title' => $myblock->getVar('title') . ' Clone', 'form_title' => constant('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_CLONEBLOCK'), 'name' => $myblock->getVar('name'), @@ -327,135 +396,208 @@ function cloneBlock($bid) 'template' => $myblock->getVar('template'), 'options' => $myblock->getVar('options'), ]; + echo '' . _AM_BADMIN . ' »» ' . _AM_SYSTEM_BLOCKS_CLONEBLOCK . '

    '; + require_once __DIR__ . '/blockform.php'; + /** @var \XoopsThemeForm $form */ + $form->display(); + // xoops_cp_footer(); + require_once __DIR__ . '/admin_footer.php'; + exit(); } /** - * @param $bid - * @param $bside - * @param $bweight - * @param $bvisible - * @param $bcachetime - * @param $bmodule - * @param $options + * @param int $bid + * @param $bside + * @param $bweight + * @param $bvisible + * @param $bcachetime + * @param $bmodule + * @param $options */ + function isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options) { xoops_loadLanguage('admin', 'system'); + xoops_loadLanguage('admin/blocksadmin', 'system'); + xoops_loadLanguage('admin/groups', 'system'); /** @var \XoopsBlock $block */ + $block = new \XoopsBlock($bid); + $clone = $block->xoopsClone(); + if (empty($bmodule)) { xoops_cp_header(); + xoops_error(sprintf(_AM_NOTSELNG, _AM_VISIBLEIN)); + xoops_cp_footer(); + exit(); } + $clone->setVar('side', $bside); + $clone->setVar('weight', $bweight); + $clone->setVar('visible', $bvisible); + //$clone->setVar('content', $_POST['bcontent']); + $clone->setVar('title', Request::getString('btitle', '', 'POST')); + $clone->setVar('bcachetime', $bcachetime); + if (isset($options) && (count($options) > 0)) { $options = implode('|', $options); + $clone->setVar('options', $options); } + $clone->setVar('bid', 0); + if ('C' === $block->getVar('block_type') || 'E' === $block->getVar('block_type')) { $clone->setVar('block_type', 'E'); } else { $clone->setVar('block_type', 'D'); } + $newid = $clone->store(); + if (!$newid) { xoops_cp_header(); + $clone->getHtmlErrors(); + xoops_cp_footer(); + exit(); } + if ('' !== $clone->getVar('template')) { /** @var \XoopsTplfileHandler $tplfileHandler */ + $tplfileHandler = xoops_getHandler('tplfile'); + /** @var \XoopsTplfile[] $btemplate */ + $btemplate = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $bid); + if (count($btemplate) > 0) { /** @var \XoopsObject $tplclone */ + $tplclone = $btemplate[0]->xoopsClone(); + $tplclone->setVar('tpl_id', 0); + $tplclone->setVar('tpl_refid', $newid); + $tplfileHandler->insert($tplclone); } } + /** @var \XoopsMySQLDatabase $db */ + $db = \XoopsDatabaseFactory::getDatabaseConnection(); + foreach ($bmodule as $bmid) { $sql = 'INSERT INTO ' . $db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newid . ', ' . $bmid . ')'; + $db->query($sql); } + $groups = &$GLOBALS['xoopsUser']->getGroups(); - $count = count($groups); + + $count = count($groups); + for ($i = 0; $i < $count; ++$i) { $sql = 'INSERT INTO ' . $db->prefix('group_permission') . ' (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (' . $groups[$i] . ', ' . $newid . ", 1, 'block_read')"; + $db->query($sql); } + redirect_header('blocksadmin.php?op=listar', 1, _AM_DBUPDATED); } /** - * @param $bid - * @param $title - * @param $weight - * @param $visible - * @param $side - * @param $bcachetime + * @param int $bid + * @param string $title + * @param int $weight + * @param bool $visible + * @param string $side + * @param int $bcachetime */ + function setOrder($bid, $title, $weight, $visible, $side, $bcachetime) { $myblock = new \XoopsBlock($bid); + $myblock->setVar('title', $title); + $myblock->setVar('weight', $weight); + $myblock->setVar('visible', $visible); + $myblock->setVar('side', $side); + $myblock->setVar('bcachetime', $bcachetime); + $myblock->store(); } /** - * @param $bid + * @param int $bid */ + function editBlock($bid) { require_once __DIR__ . '/admin_header.php'; + //require_once __DIR__ . '/admin_header.php'; + xoops_cp_header(); - $moduleDirName = basename(dirname(__DIR__)); - $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName + $moduleDirName = basename(dirname(__DIR__)); + + $moduleDirNameUpper = \mb_strtoupper($moduleDirName); //$capsDirName + xoops_loadLanguage('admin', 'system'); + xoops_loadLanguage('admin/blocksadmin', 'system'); + xoops_loadLanguage('admin/groups', 'system'); + // mpu_adm_menu(); + $myblock = new \XoopsBlock($bid); + /** @var \XoopsMySQLDatabase $db */ - $db = \XoopsDatabaseFactory::getDatabaseConnection(); - $sql = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid; - $result = $db->query($sql); + + $db = \XoopsDatabaseFactory::getDatabaseConnection(); + + $sql = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid; + + $result = $db->query($sql); + $modules = []; - while (false !== ($row = $db->fetchArray($result))) { - $modules[] = (int)$row['module_id']; + if ($result instanceof \mysqli_result) { + while (false !== ($row = $db->fetchArray($result))) { + $modules[] = (int)$row['module_id']; + } } $is_custom = ('C' === $myblock->getVar('block_type') || 'E' === $myblock->getVar('block_type')); - $block = [ + + $block = [ 'title' => $myblock->getVar('title'), 'form_title' => constant('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_EDITBLOCK'), // 'name' => $myblock->getVar('name'), @@ -473,105 +615,145 @@ function editBlock($bid) 'template' => $myblock->getVar('template'), 'options' => $myblock->getVar('options'), ]; + echo '' . _AM_BADMIN . ' »» ' . _AM_SYSTEM_BLOCKS_EDITBLOCK . '

    '; + require_once __DIR__ . '/blockform.php'; + /** @var \XoopsThemeForm $form */ + $form->display(); + // xoops_cp_footer(); + require_once __DIR__ . '/admin_footer.php'; + exit(); } /** - * @param $bid - * @param $btitle - * @param $bside - * @param $bweight - * @param $bvisible - * @param $bcachetime - * @param $bmodule - * @param $options - * @param $groups + * @param int $bid + * @param string $btitle + * @param string $bside + * @param int $bweight + * @param bool $bvisible + * @param int $bcachetime + * @param array $bmodule + * @param null|array|string $options + * @param null|array $groups */ + function updateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups) { - $moduleDirName = basename(dirname(__DIR__)); - $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName + $moduleDirName = basename(dirname(__DIR__)); + + $moduleDirNameUpper = \mb_strtoupper($moduleDirName); //$capsDirName $myblock = new \XoopsBlock($bid); + $myblock->setVar('title', $btitle); + $myblock->setVar('weight', $bweight); + $myblock->setVar('visible', $bvisible); + $myblock->setVar('side', $bside); + $myblock->setVar('bcachetime', $bcachetime); + $myblock->store(); if (!empty($bmodule) && count($bmodule) > 0) { $sql = sprintf('DELETE FROM `%s` WHERE block_id = %u', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid); + $GLOBALS['xoopsDB']->query($sql); - if (in_array(0, $bmodule, true)) { + + if (in_array(0, $bmodule)) { $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid, 0); + $GLOBALS['xoopsDB']->query($sql); } else { foreach ($bmodule as $bmid) { $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid, (int)$bmid); + $GLOBALS['xoopsDB']->query($sql); } } } + $sql = sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $GLOBALS['xoopsDB']->prefix('group_permission'), $bid); + $GLOBALS['xoopsDB']->query($sql); + if (!empty($groups)) { foreach ($groups as $grp) { $sql = sprintf("INSERT INTO `%s` (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (%u, %u, 1, 'block_read')", $GLOBALS['xoopsDB']->prefix('group_permission'), $grp, $bid); + $GLOBALS['xoopsDB']->query($sql); } } - redirect_header($_SERVER['PHP_SELF'], 1, constant('CO_' . $moduleDirNameUpper . '_' . 'UPDATE_SUCCESS')); + + redirect_header($_SERVER['SCRIPT_NAME'], 1, constant('CO_' . $moduleDirNameUpper . '_' . 'UPDATE_SUCCESS')); } if ('list' === $op) { xoops_cp_header(); + // mpu_adm_menu(); + listBlocks(); + require_once __DIR__ . '/admin_footer.php'; + exit(); } if ('order' === $op) { if (!$GLOBALS['xoopsSecurity']->check()) { - redirect_header($_SERVER['PHP_SELF'], 3, implode('
    ', $GLOBALS['xoopsSecurity']->getErrors())); + redirect_header($_SERVER['SCRIPT_NAME'], 3, implode('
    ', $GLOBALS['xoopsSecurity']->getErrors())); } + foreach (array_keys($bid) as $i) { if ($oldtitle[$i] !== $title[$i] || $oldweight[$i] !== $weight[$i] || $oldvisible[$i] !== $visible[$i] || $oldside[$i] !== $side[$i] || $oldbcachetime[$i] !== $bcachetime[$i]) { setOrder($bid[$i], $title[$i], $weight[$i], $visible[$i], $side[$i], $bcachetime[$i], $bmodule[$i]); } + if (!empty($bmodule[$i]) && count($bmodule[$i]) > 0) { $sql = sprintf('DELETE FROM `%s` WHERE block_id = %u', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid[$i]); + $GLOBALS['xoopsDB']->query($sql); - if (in_array(0, $bmodule[$i], true)) { + + if (in_array(0, $bmodule[$i])) { $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid[$i], 0); + $GLOBALS['xoopsDB']->query($sql); } else { foreach ($bmodule[$i] as $bmid) { $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid[$i], (int)$bmid); + $GLOBALS['xoopsDB']->query($sql); } } } + $sql = sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $GLOBALS['xoopsDB']->prefix('group_permission'), $bid[$i]); + $GLOBALS['xoopsDB']->query($sql); + if (!empty($groups[$i])) { foreach ($groups[$i] as $grp) { $sql = sprintf("INSERT INTO `%s` (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (%u, %u, 1, 'block_read')", $GLOBALS['xoopsDB']->prefix('group_permission'), $grp, $bid[$i]); + $GLOBALS['xoopsDB']->query($sql); } } } - redirect_header($_SERVER['PHP_SELF'], 1, constant('CO_' . $moduleDirNameUpper . '_' . 'UPDATE_SUCCESS')); + + redirect_header($_SERVER['SCRIPT_NAME'], 1, constant('CO_' . $moduleDirNameUpper . '_' . 'UPDATE_SUCCESS')); } + if ('clone' === $op) { cloneBlock($bid); } diff --git a/admin/broken.php b/admin/broken.php index e126a71..05e7be9 100644 --- a/admin/broken.php +++ b/admin/broken.php @@ -1,4 +1,5 @@ -assign('navigation', $adminObject->displayNavigation(basename(__FILE__))); $criteria = new \CriteriaCompo(); if (\Xmf\Request::hasVar('limit', 'REQUEST')) { $criteria->setLimit(\Xmf\Request::getInt('limit', 0, 'REQUEST')); + $limit = \Xmf\Request::getInt('limit', 0, 'REQUEST'); } else { $criteria->setLimit($helper->getConfig('perpageadmin')); + $limit = $helper->getConfig('perpageadmin'); } if (\Xmf\Request::hasVar('start', 'REQUEST')) { $criteria->setStart(\Xmf\Request::getInt('start', 0, 'REQUEST')); + $start = \Xmf\Request::getInt('start', 0, 'REQUEST'); } else { $criteria->setStart(0); + $start = 0; } $criteria->setSort('reportid'); @@ -54,19 +63,23 @@ $brokenHandler->table_link = $brokenHandler->db->prefix('tdmdownloads_downloads'); // Nom de la table en jointure $brokenHandler->field_link = 'lid'; // champ de la table en jointure $brokenHandler->field_object = 'lid'; // champ de la table courante - $brokenArray = $brokenHandler->getByLink($criteria); + $brokenArray = $brokenHandler->getByLink($criteria); $numrows = $brokenHandler->getCount($criteria); $pagenav = ''; if ($numrows > $limit) { $pagenav = new \XoopsPageNav($numrows, $limit, $start, 'start', 'op=list&limit=' . $limit); + $pagenav = $pagenav->renderNav(4); } //Affichage du tableau des téléchargements brisés if ($numrows > 0) { $GLOBALS['xoopsTpl']->assign('broken_count', $numrows); + $broken = []; + foreach (array_keys($brokenArray) as $i) { /** @var \XoopsModules\Tdmdownloads\Broken[] $brokenArray */ + $broken = [ 'lid' => $brokenArray[$i]->getVar('lid'), 'reportid' => $brokenArray[$i]->getVar('reportid'), @@ -75,7 +88,9 @@ 'sender' => \XoopsUser::getUnameFromId($brokenArray[$i]->getVar('sender')), 'ip' => $brokenArray[$i]->getVar('ip'), ]; + $GLOBALS['xoopsTpl']->append('broken_list', $broken); + unset($broken); } } else { @@ -89,17 +104,25 @@ if (!$GLOBALS['xoopsSecurity']->check()) { redirect_header('downloads.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); } + if ($brokenHandler->delete($obj)) { redirect_header('broken.php', 1, _AM_TDMDOWNLOADS_REDIRECT_DELOK); } + $GLOBALS['xoopsTpl']->assign('message_erreur', $obj->getHtmlErrors()); } else { //Affichage de la partie haute de l'administration de Xoops + xoops_cp_header(); - $adminObject = \Xmf\Module\Admin::getInstance(); + + $adminObject = Admin::getInstance(); + $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('broken.php')); + $adminObject->addItemButton(_MI_TDMDOWNLOADS_ADMENU4, 'broken.php?op=list', 'list'); + $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left')); + xoops_confirm(['ok' => 1, 'broken_id' => \Xmf\Request::getInt('broken_id', 0, 'REQUEST'), 'op' => 'del_brokendownloads'], $_SERVER['REQUEST_URI'], _AM_TDMDOWNLOADS_BROKEN_SURDEL . '
    '); } break; @@ -107,9 +130,11 @@ // Local icons path if (is_object($helper->getModule())) { $pathModIcon16 = $helper->getModule()->getInfo('modicons16'); + $pathModIcon32 = $helper->getModule()->getInfo('modicons32'); $GLOBALS['xoopsTpl']->assign('pathModIcon16', XOOPS_URL . '/modules/' . $moduleDirName . '/' . $pathModIcon16); + $GLOBALS['xoopsTpl']->assign('pathModIcon32', $pathModIcon32); } //Affichage de la partie basse de l'administration de Xoops diff --git a/admin/category.php b/admin/category.php index c1d62c1..dd0bbd1 100644 --- a/admin/category.php +++ b/admin/category.php @@ -1,6 +1,13 @@ -assign('navigation', $adminObject->displayNavigation(basename(__FILE__))); $adminObject->addItemButton(_AM_TDMDOWNLOADS_CAT_NEW, 'category.php?op=new_cat', 'add'); $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left')); @@ -48,11 +55,16 @@ // if (count($downloads_cat) > 0) { if (count($downloads_cat) > 0) { $GLOBALS['xoopsTpl']->assign('categories_count', count($downloads_cat)); - $mytree = new \XoopsModules\Tdmdownloads\Tree($downloads_cat, 'cat_cid', 'cat_pid'); + + $mytree = new Tree($downloads_cat, 'cat_cid', 'cat_pid'); + $category_ArrayTree = $mytree->makeArrayTree('cat_title', ''); - $category = []; + + $category = []; + foreach (array_keys($category_ArrayTree) as $i) { /** @var \XoopsModules\Tdmdownloads\Category[] $downloads_cat */ + $category = [ 'cid' => $i, 'title' => $downloads_cat[$i]->getVar('cat_title'), @@ -61,7 +73,9 @@ 'cat_description_main' => $downloads_cat[$i]->getVar('cat_description_main'), 'cat_weight' => $downloads_cat[$i]->getVar('cat_weight'), ]; + $GLOBALS['xoopsTpl']->append('categories_list', $category); + unset($category); } } @@ -71,7 +85,7 @@ case 'new_cat': //Affichage de la partie haute de l'administration de Xoops xoops_cp_header(); - $adminObject = \Xmf\Module\Admin::getInstance(); + $adminObject = Admin::getInstance(); $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation(basename(__FILE__))); $adminObject->addItemButton(_AM_TDMDOWNLOADS_CAT_LIST, 'category.php?op=list', 'list'); $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left')); @@ -87,7 +101,7 @@ case 'edit_cat': //Affichage de la partie haute de l'administration de Xoops xoops_cp_header(); - $adminObject = \Xmf\Module\Admin::getInstance(); + $adminObject = Admin::getInstance(); $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation(basename(__FILE__))); $adminObject->addItemButton(_AM_TDMDOWNLOADS_CAT_LIST, 'category.php?op=list', 'list'); $adminObject->addItemButton(_AM_TDMDOWNLOADS_CAT_NEW, 'category.php?op=new_cat', 'add'); @@ -110,171 +124,281 @@ if (!$GLOBALS['xoopsSecurity']->check()) { redirect_header('category.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); } + // supression des téléchargements de la catégorie + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('cid', $categoryId)); + $downloadsArray = $downloadsHandler->getAll($criteria); + foreach (array_keys($downloadsArray) as $i) { /** @var \XoopsModules\Tdmdownloads\Downloads[] $downloadsArray */ + // supression des votes + $criteria_1 = new \CriteriaCompo(); + $criteria_1->add(new \Criteria('lid', $downloadsArray[$i]->getVar('lid'))); + $votedata = $ratingHandler->getAll($criteria_1); + foreach (array_keys($votedata) as $j) { /** @var \XoopsModules\Tdmdownloads\Rating[] $votedata */ + $objvotedata = $ratingHandler->get($votedata[$j]->getVar('ratingid')); + $ratingHandler->delete($objvotedata) || $objvotedata->getHtmlErrors(); } + // supression des rapports de fichier brisé + $criteria_2 = new \CriteriaCompo(); + $criteria_2->add(new \Criteria('lid', $downloadsArray[$i]->getVar('lid'))); + $downloads_broken = $brokenHandler->getAll($criteria_2); + foreach (array_keys($downloads_broken) as $j) { /** @var \XoopsModules\Tdmdownloads\Broken[] $downloads_broken */ + $objbroken = $brokenHandler->get($downloads_broken[$j]->getVar('reportid')); + $brokenHandler->delete($objbroken) || $objbroken->getHtmlErrors(); } + // supression des data des champs sup. + $criteria_3 = new \CriteriaCompo(); + $criteria_3->add(new \Criteria('lid', $downloadsArray[$i]->getVar('lid'))); + $downloads_fielddata = $fielddataHandler->getAll($criteria_3); + if ($fielddataHandler->getCount($criteria_3) > 0) { foreach (array_keys($downloads_fielddata) as $j) { /** @var \XoopsModules\Tdmdownloads\Fielddata[] $downloads_fielddata */ + $objfielddata = $fielddataHandler->get($downloads_fielddata[$j]->getVar('iddata')); + $fielddataHandler->delete($objfielddata) || $objvfielddata->getHtmlErrors(); } } + // supression des commentaires + if ($downloadsArray[$i]->getVar('comments') > 0) { xoops_comment_delete($xoopsModule->getVar('mid'), $downloadsArray[$i]->getVar('lid')); } + //supression des tags - if ((1 == $helper->getConfig('usetag')) && class_exists(LinkHandler::class)) { + + if (1 == $helper->getConfig('usetag') && class_exists(LinkHandler::class)) { /** @var \XoopsModules\Tag\LinkHandler $linkHandler */ - $linkHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Link'); - $criteria = new \CriteriaCompo(); + + $linkHandler = TagHelper::getInstance()->getHandler('Link'); + + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('tag_itemid', $downloadsArray[$i]->getVar('lid'))); + $downloadsTags = $linkHandler->getAll($criteria); + if (count($downloadsTags) > 0) { foreach (array_keys($downloadsTags) as $j) { /** @var \XoopsModules\Tag\Link[] $downloadsTags */ + $objtags = $linkHandler->get($downloadsTags[$j]->getVar('tl_id')); + $linkHandler->delete($objtags) || $objtags->getHtmlErrors(); } } } + // supression du fichier + // pour extraire le nom du fichier + $urlfile = substr_replace($downloadsArray[$i]->getVar('url'), '', 0, mb_strlen($uploadurl_downloads)); + // chemin du fichier + $urlfile = $uploaddir_downloads . $urlfile; + if (is_file($urlfile)) { chmod($urlfile, 0777); + unlink($urlfile); } + // supression du téléchargment + $objdownloads = $downloadsHandler->get($downloadsArray[$i]->getVar('lid')); + $downloadsHandler->delete($objdownloads) || $objdownloads->getHtmlErrors(); } + // supression des sous catégories avec leurs téléchargements - $downloadscatArray = $categoryHandler->getAll(); - $mytree = new \XoopsModules\Tdmdownloads\Tree($downloadscatArray, 'cat_cid', 'cat_pid'); + + $downloadscatArray = $categoryHandler->getAll(); + + $mytree = new Tree($downloadscatArray, 'cat_cid', 'cat_pid'); + $downloads_childcat = $mytree->getAllChild($categoryId); + foreach (array_keys($downloads_childcat) as $i) { /** @var \XoopsModules\Tdmdownloads\Category[] $downloads_childcat */ + // supression de la catégorie + $objchild = $categoryHandler->get($downloads_childcat[$i]->getVar('cat_cid')); + $categoryHandler->delete($objchild) || $objchild->getHtmlErrors(); + // supression des téléchargements associés + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('cid', $downloads_childcat[$i]->getVar('cat_cid'))); + $downloadsArray = $downloadsHandler->getAll($criteria); + foreach (array_keys($downloadsArray) as $j) { // supression des votes + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('lid', $downloadsArray[$j]->getVar('lid'))); + $votedata = $ratingHandler->getAll($criteria); + foreach (array_keys($votedata) as $k) { $objvotedata = $ratingHandler->get($votedata[$k]->getVar('ratingid')); + $ratingHandler->delete($objvotedata) || $objvotedata->getHtmlErrors(); } + // supression des rapports de fichier brisé + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('lid', $downloadsArray[$j]->getVar('lid'))); + $downloads_broken = $brokenHandler->getAll($criteria); + foreach (array_keys($downloads_broken) as $k) { $objbroken = $brokenHandler->get($downloads_broken[$k]->getVar('reportid')); + $brokenHandler->delete($objbroken) || $objbroken->getHtmlErrors(); } + // supression des data des champs sup. + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('lid', $downloadsArray[$j]->getVar('lid'))); + $downloads_fielddata = $fielddataHandler->getAll($criteria); + foreach (array_keys($downloads_fielddata) as $k) { $objfielddata = $fielddataHandler->get($downloads_fielddata[$k]->getVar('iddata')); + $fielddataHandler->delete($objfielddata) || $objvfielddata->getHtmlErrors(); } + // supression des commentaires + if ($downloadsArray[$j]->getVar('comments') > 0) { xoops_comment_delete($xoopsModule->getVar('mid'), $downloadsArray[$j]->getVar('lid')); } + //supression des tags - if ((1 == $helper->getConfig('usetag')) && class_exists(LinkHandler::class)) { + + if (1 == $helper->getConfig('usetag') && class_exists(LinkHandler::class)) { /** @var \XoopsModules\Tag\LinkHandler $linkHandler */ - $linkHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Link'); - $criteria = new \CriteriaCompo(); + + $linkHandler = TagHelper::getInstance()->getHandler('Link'); + + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('tag_itemid', $downloadsArray[$j]->getVar('lid'))); + $downloadsTags = $linkHandler->getAll($criteria); + if (count($downloadsTags) > 0) { foreach (array_keys($downloadsTags) as $k) { $objtags = $linkHandler->get($downloadsTags[$k]->getVar('tl_id')); + $linkHandler->delete($objtags) || $objtags->getHtmlErrors(); } } } + // supression du fichier $urlfile = substr_replace($downloadsArray[$j]->getVar('url'), '', 0, mb_strlen($uploadurl_downloads)); // pour extraire le nom du fichier $urlfile = $uploaddir_downloads . $urlfile; // chemin du fichier if (is_file($urlfile)) { chmod($urlfile, 0777); + unlink($urlfile); } + // supression du téléchargment + $objdownloads = $downloadsHandler->get($downloadsArray[$j]->getVar('lid')); + $downloadsHandler->delete($objdownloads) || $objdownloads->getHtmlErrors(); } } + if ($categoryHandler->delete($obj)) { redirect_header('category.php', 1, _AM_TDMDOWNLOADS_REDIRECT_DELOK); } else { $GLOBALS['xoopsTpl']->assign('message_erreur', $obj->getHtmlErrors()); } } else { - $message = ''; + $message = ''; + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('cid', $categoryId)); + $downloadsArray = $downloadsHandler->getAll($criteria); + if (count($downloadsArray) > 0) { $message .= _AM_TDMDOWNLOADS_DELDOWNLOADS . '
    '; + foreach (array_keys($downloadsArray) as $i) { /** @var \XoopsModules\Tdmdownloads\Downloads[] $downloadsArray */ + $message .= '' . $downloadsArray[$i]->getVar('title') . '
    '; } } - $downloadscatArray = $categoryHandler->getAll(); - $mytree = new \XoopsModules\Tdmdownloads\Tree($downloadscatArray, 'cat_cid', 'cat_pid'); + + $downloadscatArray = $categoryHandler->getAll(); + + $mytree = new Tree($downloadscatArray, 'cat_cid', 'cat_pid'); + $downloads_childcat = $mytree->getAllChild($categoryId); + if (count($downloads_childcat) > 0) { $message .= _AM_TDMDOWNLOADS_DELSOUSCAT . '

    '; + foreach (array_keys($downloads_childcat) as $i) { /** @var \XoopsModules\Tdmdownloads\Category[] $downloads_childcat */ - $message .= '' . $downloads_childcat[$i]->getVar('cat_title') . '
    '; + + $message .= '' . $downloads_childcat[$i]->getVar('cat_title') . '
    '; + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('cid', $downloads_childcat[$i]->getVar('cat_cid'))); + $downloadsArray = $downloadsHandler->getAll($criteria); + if (count($downloadsArray) > 0) { $message .= _AM_TDMDOWNLOADS_DELDOWNLOADS . '
    '; + foreach (array_keys($downloadsArray) as $k) { $message .= '' . $downloadsArray[$k]->getVar('title') . '
    '; } @@ -283,18 +407,30 @@ } else { $message .= ''; } + //Affichage de la partie haute de l'administration de Xoops + xoops_cp_header(); - $adminObject = \Xmf\Module\Admin::getInstance(); + + $adminObject = Admin::getInstance(); + $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation(basename(__FILE__))); + $adminObject->addItemButton(_AM_TDMDOWNLOADS_CAT_LIST, 'category.php?op=list', 'list'); + $adminObject->addItemButton(_AM_TDMDOWNLOADS_CAT_NEW, 'category.php?op=new_cat', 'add'); + $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left')); - xoops_confirm([ - 'ok' => 1, - 'downloadscat_cid' => $categoryId, - 'op' => 'del_cat', - ], $_SERVER['REQUEST_URI'], sprintf(_AM_TDMDOWNLOADS_FORMSUREDEL, $obj->getVar('cat_title')) . '

    ' . $message); + + xoops_confirm( + [ + 'ok' => 1, + 'downloadscat_cid' => $categoryId, + 'op' => 'del_cat', + ], + $_SERVER['REQUEST_URI'], + sprintf(_AM_TDMDOWNLOADS_FORMSUREDEL, $obj->getVar('cat_title')) . '

    ' . $message + ); } break; @@ -310,23 +446,28 @@ } else { $obj = $categoryHandler->create(); } - $erreur = false; + $erreur = false; $errorMessage = ''; // Récupération des variables: // Pour l'image require_once XOOPS_ROOT_PATH . '/class/uploader.php'; - $uploader = new \XoopsMediaUploader($uploaddir, [ - 'image/gif', - 'image/jpeg', - 'image/pjpeg', - 'image/x-png', - 'image/png', - ], $helper->getConfig('maxuploadsize'), null, null); + $uploader = new \XoopsMediaUploader( + $uploaddir, [ + 'image/gif', + 'image/jpeg', + 'image/pjpeg', + 'image/x-png', + 'image/png', + ], $helper->getConfig('maxuploadsize'), null, null + ); if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) { $uploader->setPrefix('downloads_'); + $uploader->fetchMedia($_POST['xoops_upload_file'][0]); + if (!$uploader->upload()) { $errors = $uploader->getErrors(); + redirect_header('javascript:history.go(-1)', 3, $errors); } else { $obj->setVar('cat_imgurl', $uploader->getSavedFileName()); @@ -339,9 +480,11 @@ $obj->setVar('cat_title', \Xmf\Request::getString('cat_title', '', 'POST')); //$_POST['cat_title']); $obj->setVar('cat_description_main', \Xmf\Request::getString('cat_description_main', '', 'POST')); //$_POST['cat_description_main']); $obj->setVar('cat_weight', \Xmf\Request::getInt('cat_weight', 0, 'POST')); + if (\Xmf\Request::hasVar('cat_cid', 'REQUEST')) { if ($cat_cid === \Xmf\Request::getInt('cat_pid', 0, 'POST')) { - $erreur = true; + $erreur = true; + $errorMessage .= _AM_TDMDOWNLOADS_ERREUR_CAT; } } @@ -350,60 +493,98 @@ } else { if ($categoryHandler->insert($obj)) { /** @var \XoopsModules\Tdmdownloads\Category $obj */ - $newcat_cid = $obj->getNewEnreg($db); + + $newcat_cid = $obj->getNewEnreg($db); + //permission pour voir + $perm_id = \Xmf\Request::hasVar('cat_cid', 'POST') ? $cat_cid : $newcat_cid; + /** @var \XoopsGroupPermHandler $grouppermHandler */ $grouppermHandler = xoops_getHandler('groupperm'); - $criteria = new \CriteriaCompo(); + + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('gperm_itemid', $perm_id, '=')); + $criteria->add(new \Criteria('gperm_modid', $xoopsModule->getVar('mid'), '=')); + $criteria->add(new \Criteria('gperm_name', 'tdmdownloads_view', '=')); + $grouppermHandler->deleteAll($criteria); + if (\Xmf\Request::hasVar('groups_view', 'POST')) { foreach ($_POST['groups_view'] as $onegroup_id) { $grouppermHandler->addRight('tdmdownloads_view', $perm_id, $onegroup_id, $xoopsModule->getVar('mid')); } } + //permission pour editer - $perm_id = \Xmf\Request::getInt('cat_cid', $newcat_cid, 'POST'); + + $perm_id = \Xmf\Request::getInt('cat_cid', $newcat_cid, 'POST'); + + /** @var \XoopsGroupPermHandler $grouppermHandler */ $grouppermHandler = xoops_getHandler('groupperm'); - $criteria = new \CriteriaCompo(); + + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('gperm_itemid', $perm_id, '=')); + $criteria->add(new \Criteria('gperm_modid', $xoopsModule->getVar('mid'), '=')); + $criteria->add(new \Criteria('gperm_name', 'tdmdownloads_submit', '=')); + $grouppermHandler->deleteAll($criteria); + if (\Xmf\Request::hasVar('groups_submit', 'POST')) { foreach ($_POST['groups_submit'] as $onegroup_id) { $grouppermHandler->addRight('tdmdownloads_submit', $perm_id, $onegroup_id, $xoopsModule->getVar('mid')); } } + //permission pour télécharger + if (1 == $helper->getConfig('permission_download')) { - $perm_id = \Xmf\Request::getInt('cat_cid', $newcat_cid, 'POST'); + $perm_id = \Xmf\Request::getInt('cat_cid', $newcat_cid, 'POST'); + /** @var \XoopsGroupPermHandler $grouppermHandler */ $grouppermHandler = xoops_getHandler('groupperm'); - $criteria = new \CriteriaCompo(); + + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('gperm_itemid', $perm_id, '=')); + $criteria->add(new \Criteria('gperm_modid', $xoopsModule->getVar('mid'), '=')); + $criteria->add(new \Criteria('gperm_name', 'tdmdownloads_download', '=')); + $grouppermHandler->deleteAll($criteria); + if (\Xmf\Request::hasVar('groups_download', 'POST')) { foreach ($_POST['groups_download'] as $onegroup_id) { $grouppermHandler->addRight('tdmdownloads_download', $perm_id, $onegroup_id, $xoopsModule->getVar('mid')); } } } + //notification + if (!\Xmf\Request::hasVar('categorie_modified', 'POST')) { - $tags = []; + $tags = []; + $tags['CATEGORY_NAME'] = \Xmf\Request::getString('cat_title', '', 'POST'); - $tags['CATEGORY_URL'] = XOOPS_URL . '/modules/' . $moduleDirName . '/viewcat.php?cid=' . $newcat_cid; + + $tags['CATEGORY_URL'] = XOOPS_URL . '/modules/' . $moduleDirName . '/viewcat.php?cid=' . $newcat_cid; + /** @var \XoopsNotificationHandler $notificationHandler */ + $notificationHandler = xoops_getHandler('notification'); + $notificationHandler->triggerEvent('global', 0, 'new_category', $tags); } + redirect_header('category.php?op=list', 1, _AM_TDMDOWNLOADS_REDIRECT_SAVE); } + $GLOBALS['xoopsTpl']->assign('message_erreur', $obj->getHtmlErrors()); } $form = $obj->getForm(); @@ -414,9 +595,11 @@ // Local icons path if (is_object($helper->getModule())) { $pathModIcon16 = $helper->getModule()->getInfo('modicons16'); + $pathModIcon32 = $helper->getModule()->getInfo('modicons32'); $GLOBALS['xoopsTpl']->assign('pathModIcon16', XOOPS_URL . '/modules/' . $moduleDirName . '/' . $pathModIcon16); + $GLOBALS['xoopsTpl']->assign('pathModIcon32', $pathModIcon32); } diff --git a/admin/downloads.php b/admin/downloads.php index c839ccb..4f73344 100644 --- a/admin/downloads.php +++ b/admin/downloads.php @@ -1,8 +1,17 @@ -assign('navigation', $adminObject->displayNavigation(basename(__FILE__))); if (1 == $statusMenu) { $adminObject->addItemButton(_AM_TDMDOWNLOADS_DOWNLOADS_NEW, 'downloads.php?op=new_downloads', 'add'); + + $adminObject->addItemButton(_AM_TDMDOWNLOADS_DOWNLOADS_NEW_MULTIUPLOAD, '../upload.php?op=list&cat_cid=' . $catId, 'add'); + if (0 == $downloads_waiting) { $adminObject->addItemButton(_AM_TDMDOWNLOADS_DOWNLOADS_WAIT, 'downloads.php?op=list&statut_display=0', 'add'); } else { @@ -55,13 +68,14 @@ } } else { $adminObject->addItemButton(_AM_TDMDOWNLOADS_DOWNLOADS_LISTE, 'downloads.php?op=list', 'list'); + $adminObject->addItemButton(_AM_TDMDOWNLOADS_DOWNLOADS_NEW, 'downloads.php?op=new_downloads', 'add'); } $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left')); - $limit = $helper->getConfig('perpageadmin'); + $limit = $helper->getConfig('perpageadmin'); $categoryArray = $categoryHandler->getAll(); - $numrowscat = count($categoryArray); + $numrowscat = count($categoryArray); // redirection si il n'y a pas de catégories if (0 === $numrowscat) { @@ -72,36 +86,48 @@ if (\Xmf\Request::hasVar('statut_display', 'GET')) { if (0 === \Xmf\Request::getInt('statut_display', 0, 'GET')) { $criteria->add(new \Criteria('status', 0)); + $statusDisplay = 0; } else { $criteria->add(new \Criteria('status', 0, '!=')); + $statusDisplay = 1; } } else { $criteria->add(new \Criteria('status', 0, '!=')); + $statusDisplay = 1; } - $documentSort = 1; + $documentSort = 1; $documentOrder = 1; if (\Xmf\Request::hasVar('document_tri')) { if (1 == \Xmf\Request::getInt('document_tri')) { $criteria->setSort('date'); + $documentSort = 1; } + if (2 == \Xmf\Request::getInt('document_tri')) { $criteria->setSort('title'); + $documentSort = 2; } + if (3 == \Xmf\Request::getInt('document_tri')) { $criteria->setSort('hits'); + $documentSort = 3; } + if (4 == \Xmf\Request::getInt('document_tri')) { $criteria->setSort('rating'); + $documentSort = 4; } + if (5 == \Xmf\Request::getInt('document_tri')) { $criteria->setSort('cid'); + $documentSort = 5; } } else { @@ -110,10 +136,13 @@ if (\Xmf\Request::hasVar('document_order')) { if (1 == \Xmf\Request::getInt('document_order')) { $criteria->setOrder('DESC'); + $documentOrder = 1; } + if (2 == \Xmf\Request::getInt('document_order')) { $criteria->setOrder('ASC'); + $documentOrder = 2; } } else { @@ -123,15 +152,16 @@ $criteria->setStart($start); $criteria->setLimit($limit); //pour faire une jointure de table - $downloadsHandler->table_link = $downloadsHandler->db->prefix('tdmdownloads_cat'); // Nom de la table en jointure - $downloadsHandler->field_link = 'cat_cid'; // champ de la table en jointure + $downloadsHandler->table_link = $downloadsHandler->db->prefix('tdmdownloads_cat'); // Nom de la table en jointure + $downloadsHandler->field_link = 'cat_cid'; // champ de la table en jointure $downloadsHandler->field_object = 'cid'; // champ de la table courante - $downloadsArray = $downloadsHandler->getByLink($criteria); - $numrows = $downloadsHandler->getCount($criteria); + $downloadsArray = $downloadsHandler->getByLink($criteria); + $numrows = $downloadsHandler->getCount($criteria); $pagenav = ''; if ($numrows > $limit) { $pagenav = new \XoopsPageNav($numrows, $limit, $start, 'start', 'op=list&document_tri=' . $documentSort . '&document_order=' . $documentOrder . '&statut_display=' . $statusDisplay); + $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav(4)); } //Affichage du tableau des téléchargements @@ -143,39 +173,57 @@ . '/modules/' . $xoopsModule->dirname() . "/admin/downloads.php?statut_display=$statusDisplay&document_order=$documentOrder&document_tri='+this.options[this.selectedIndex].value\">"; + $selectDocument .= ''; + $selectDocument .= ''; + $selectDocument .= ''; + $selectDocument .= ''; + $selectDocument .= ''; + $selectDocument .= ' '; + $GLOBALS['xoopsTpl']->assign('selectDocument', $selectDocument); + $selectOrder = _AM_TDMDOWNLOADS_ORDER . " '; + $GLOBALS['xoopsTpl']->assign('selectOrder', $selectOrder); - $mytree = new \XoopsModules\Tdmdownloads\Tree($categoryArray, 'cat_cid', 'cat_pid'); + $mytree = new Tree($categoryArray, 'cat_cid', 'cat_pid'); + $class = 'odd'; + $downloads = []; + foreach (array_keys($downloadsArray) as $i) { /** @var \XoopsModules\Tdmdownloads\Downloads[] $downloadsArray */ + $download = [ - 'category' => $utility->getPathTree($mytree, $downloadsArray[$i]->getVar('cid'), $categoryArray, 'cat_title', $prefix = ' '), - 'cid' => $downloadsArray[$i]->getVar('cid'), - 'lid' => $i, - 'title' => $downloadsArray[$i]->getVar('title'), - 'hits' => $downloadsArray[$i]->getVar('hits'), - 'rating' => number_format($downloadsArray[$i]->getVar('rating'), 1), + 'category' => $utility::getPathTree($mytree, $downloadsArray[$i]->getVar('cid'), $categoryArray, 'cat_title', $prefix = ' '), + 'cid' => $downloadsArray[$i]->getVar('cid'), + 'lid' => $i, + 'title' => $downloadsArray[$i]->getVar('title'), + 'hits' => $downloadsArray[$i]->getVar('hits'), + 'rating' => number_format((float)$downloadsArray[$i]->getVar('rating'), 1), 'statut_display' => $statusDisplay, ]; + $GLOBALS['xoopsTpl']->append('downloads_list', $download); + unset($download); } } else { @@ -186,7 +234,7 @@ case 'new_downloads': //Affichage de la partie haute de l'administration de Xoops xoops_cp_header(); - $adminObject = \Xmf\Module\Admin::getInstance(); + $adminObject = Admin::getInstance(); $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation(basename(__FILE__))); $adminObject->addItemButton(_AM_TDMDOWNLOADS_DOWNLOADS_LISTE, 'downloads.php?op=list', 'list'); $adminObject->addItemButton(_AM_TDMDOWNLOADS_DOWNLOADS_NEW, 'downloads.php?op=new_downloads', 'add'); @@ -207,7 +255,7 @@ case 'edit_downloads': //Affichage de la partie haute de l'administration de Xoops xoops_cp_header(); - $adminObject = \Xmf\Module\Admin::getInstance(); + $adminObject = Admin::getInstance(); $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation(basename(__FILE__))); $adminObject->addItemButton(_AM_TDMDOWNLOADS_DOWNLOADS_LISTE, 'downloads.php?op=list', 'list'); $adminObject->addItemButton(_AM_TDMDOWNLOADS_DOWNLOADS_NEW, 'downloads.php?op=new_downloads', 'add'); @@ -229,73 +277,118 @@ case 'del_downloads': global $xoopsModule; $downloads_lid = \Xmf\Request::getInt('downloads_lid', 0, 'GET'); - $obj = $downloadsHandler->get($downloads_lid); + $obj = $downloadsHandler->get($downloads_lid); if (\Xmf\Request::hasVar('ok') && 1 == \Xmf\Request::getInt('ok')) { if (!$GLOBALS['xoopsSecurity']->check()) { redirect_header('downloads.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); } + // permet d'extraire le nom du fichier + $urlfile = substr_replace($obj->getVar('url'), '', 0, mb_strlen($uploadurl_downloads)); + if ($downloadsHandler->delete($obj)) { // permet de donner le chemin du fichier + $urlfile = $uploaddir_downloads . $urlfile; + // si le fichier est sur le serveur il es détruit + if (is_file($urlfile)) { chmod($urlfile, 0777); + unlink($urlfile); } + // supression des votes + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('lid', $downloads_lid)); + $votedata = $ratingHandler->getAll($criteria); + foreach (array_keys($votedata) as $i) { /** @var \XoopsModules\Tdmdownloads\Rating[] $votedata */ + $objvotedata = $ratingHandler->get($votedata[$i]->getVar('ratingid')); + $ratingHandler->delete($objvotedata) || $objvotedata->getHtmlErrors(); } + // supression des rapports de fichier brisé + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('lid', $downloads_lid)); + $downloads_broken = $brokenHandler->getAll($criteria); + foreach (array_keys($downloads_broken) as $i) { /** @var \XoopsModules\Tdmdownloads\Broken[] $downloads_broken */ + $objbroken = $brokenHandler->get($downloads_broken[$i]->getVar('reportid')); + $brokenHandler->delete($objbroken) || $objbroken->getHtmlErrors(); } + // supression des data des champs sup. + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('lid', $downloads_lid)); + $downloads_fielddata = $fielddataHandler->getAll($criteria); + foreach (array_keys($downloads_fielddata) as $i) { /** @var \XoopsModules\Tdmdownloads\Fielddata[] $downloads_fielddata */ + $objfielddata = $fielddataHandler->get($downloads_fielddata[$i]->getVar('iddata')); + $fielddataHandler->delete($objfielddata) || $objvfielddata->getHtmlErrors(); } + // supression des commentaires + xoops_comment_delete($xoopsModule->getVar('mid'), $downloads_lid); + //supression des tags - if ((1 == $helper->getConfig('usetag')) && class_exists(LinkHandler::class)) { + + if (1 == $helper->getConfig('usetag') && class_exists(LinkHandler::class)) { /** @var \XoopsModules\Tag\LinkHandler $linkHandler */ - $linkHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Link'); + + $linkHandler = TagHelper::getInstance()->getHandler('Link'); + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('tag_itemid', $downloads_lid)); + $downloadsTags = $linkHandler->getAll($criteria); + foreach (array_keys($downloadsTags) as $i) { /** @var \XoopsModules\Tag\Link[] $downloadsTags */ + $objtags = $linkHandler->get($downloadsTags[$i]->getVar('tl_id')); + $linkHandler->delete($objtags) || $objtags->getHtmlErrors(); } } + redirect_header('downloads.php', 1, _AM_TDMDOWNLOADS_REDIRECT_DELOK); } else { $GLOBALS['xoopsTpl']->assign('message_erreur', $obj->getHtmlErrors()); } } else { //Affichage de la partie haute de l'administration de Xoops + xoops_cp_header(); - $adminObject = \Xmf\Module\Admin::getInstance(); + + $adminObject = Admin::getInstance(); + $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation(basename(__FILE__))); + $adminObject->addItemButton(_AM_TDMDOWNLOADS_DOWNLOADS_LISTE, 'downloads.php?op=list', 'list'); + $adminObject->addItemButton(_AM_TDMDOWNLOADS_DOWNLOADS_NEW, 'downloads.php?op=new_downloads', 'add'); if (0 == $downloads_waiting) { @@ -303,11 +396,13 @@ } else { $adminObject->addItemButton(_AM_TDMDOWNLOADS_DOWNLOADS_WAIT, 'downloads.php?op=list&statut_display=0', 'add', 'style="color : Red"'); } + $adminObject->displayButton('left'); + xoops_confirm( ['ok' => 1, 'downloads_lid' => $downloads_lid, 'op' => 'del_downloads'], $_SERVER['REQUEST_URI'], - sprintf(_AM_TDMDOWNLOADS_FORMSUREDEL, $obj->getVar('title')) . '

    ' . _AM_TDMDOWNLOADS_FORMWITHFILE . ' ' . $obj->getVar('url') . '
    ' + sprintf(_AM_TDMDOWNLOADS_FORMSUREDEL, $obj->getVar('title')) . '

    ' . _AM_TDMDOWNLOADS_FORMWITHFILE . ' ' . $obj->getVar('url') . '
    ' ); } break; @@ -315,7 +410,7 @@ case 'view_downloads': //Affichage de la partie haute de l'administration de Xoops xoops_cp_header(); - $adminObject = \Xmf\Module\Admin::getInstance(); + $adminObject = Admin::getInstance(); $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation(basename(__FILE__))); $adminObject->addItemButton(_AM_TDMDOWNLOADS_DOWNLOADS_LISTE, 'downloads.php?op=list', 'list'); $adminObject->addItemButton(_AM_TDMDOWNLOADS_DOWNLOADS_NEW, 'downloads.php?op=new_downloads', 'add'); @@ -333,21 +428,21 @@ //catégorie //$view_category = $categoryHandler->get($viewDownloads->getVar('cid')); $categoryArray = $categoryHandler->getAll(); - $mytree = new \XoopsModules\Tdmdownloads\Tree($categoryArray, 'cat_cid', 'cat_pid'); + $mytree = new Tree($categoryArray, 'cat_cid', 'cat_pid'); // sortie des informations - $downloads_title = $viewDownloads->getVar('title'); + $downloads_title = $viewDownloads->getVar('title'); $downloads_description = $viewDownloads->getVar('description'); //permet d'enlever [pagebreak] du texte $downloads_description = str_replace('[pagebreak]', '', $downloads_description); - $category = $utility->getPathTree($mytree, $viewDownloads->getVar('cid'), $categoryArray, 'cat_title', $prefix = ' '); + $category = $utility::getPathTree($mytree, $viewDownloads->getVar('cid'), $categoryArray, 'cat_title', $prefix = ' '); // affichages des informations du téléchargement $download = [ - 'title' => $downloads_title, + 'title' => $downloads_title, 'description' => $downloads_description, - 'cid' => $viewDownloads->getVar('cid'), - 'lid' => $downloads_lid, - 'category' => $category, + 'cid' => $viewDownloads->getVar('cid'), + 'lid' => $downloads_lid, + 'category' => $category, ]; $criteria = new \CriteriaCompo(); @@ -355,44 +450,59 @@ $criteria->setOrder('ASC'); $criteria->add(new \Criteria('status', 1)); $downloads_field = $fieldHandler->getAll($criteria); - $fieldsList = []; + $fieldsList = []; foreach (array_keys($downloads_field) as $i) { /** @var \XoopsModules\Tdmdownloads\Field[] $downloads_field */ + if (1 == $downloads_field[$i]->getVar('status_def')) { if (1 == $downloads_field[$i]->getVar('fid')) { //page d'accueil + if ('' !== $viewDownloads->getVar('homepage')) { $fieldsList[] = ['name' => _AM_TDMDOWNLOADS_FORMHOMEPAGE, 'value' => '' . $viewDownloads->getVar('homepage') . '']; } } + if (2 == $downloads_field[$i]->getVar('fid')) { //version + if ('' !== $viewDownloads->getVar('version')) { $fieldsList[] = ['name' => _AM_TDMDOWNLOADS_FORMVERSION, 'value' => $viewDownloads->getVar('version')]; } } + if (3 == $downloads_field[$i]->getVar('fid')) { //taille du fichier + if ('' !== $viewDownloads->getVar('size')) { - $fieldsList[] = ['name' => _AM_TDMDOWNLOADS_FORMSIZE, 'value' => $viewDownloads->getVar('size')]; + $fieldsList[] = ['name' => _AM_TDMDOWNLOADS_FORMSIZE_WHEN_SUBMIT, 'value' => $viewDownloads->getVar('size')]; } } + if (4 == $downloads_field[$i]->getVar('fid')) { //plateforme + if ('' !== $viewDownloads->getVar('platform')) { $fieldsList[] = ['name' => _AM_TDMDOWNLOADS_FORMPLATFORM, 'value' => $viewDownloads->getVar('platform')]; } } } else { $contenu = ''; + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('lid', $downloads_lid)); + $criteria->add(new \Criteria('fid', $downloads_field[$i]->getVar('fid'))); + $downloadsfielddata = $fielddataHandler->getAll($criteria); + foreach (array_keys($downloadsfielddata) as $j) { /** @var \XoopsModules\Tdmdownloads\Fielddata[] $downloadsfielddata */ + $contenu = $downloadsfielddata[$j]->getVar('data'); } + if ('' !== $contenu) { $fieldsList[] = ['name' => $downloads_field[$i]->getVar('title'), 'value' => $contenu]; } @@ -400,14 +510,18 @@ } $download['fields_list'] = $fieldsList; // tags - if ((1 == $helper->getConfig('usetag')) && class_exists(Tag::class)) { + if (1 == $helper->getConfig('usetag') && class_exists(Tag::class)) { require_once XOOPS_ROOT_PATH . '/modules/tag/include/tagbar.php'; + $tags_array = tagBar($downloads_lid, 0); + if (!empty($tags_array)) { $tags = ''; + foreach (array_keys($tags_array['tags']) as $i) { $tags .= $tags_array['delimiter'] . ' ' . $tags_array['tags'][$i] . ' '; } + $download['tags'] = ['title' => $tags_array['title'], 'value' => $tags]; } } @@ -416,11 +530,11 @@ $download['logourl'] = $viewDownloads->getVar('logourl'); } } - $download['date'] = formatTimestamp($viewDownloads->getVar('date')); + $download['date'] = formatTimestamp($viewDownloads->getVar('date')); $download['submitter'] = XoopsUser::getUnameFromId($viewDownloads->getVar('submitter')); - $download['hits'] = $viewDownloads->getVar('hits'); - $download['rating'] = number_format($viewDownloads->getVar('rating'), 1); - $download['votes'] = $viewDownloads->getVar('votes'); + $download['hits'] = $viewDownloads->getVar('hits'); + $download['rating'] = number_format((float)$viewDownloads->getVar('rating'), 1); + $download['votes'] = $viewDownloads->getVar('votes'); if (true === $helper->getConfig('use_paypal') && '' !== $viewDownloads->getVar('paypal')) { $download['paypal'] = $viewDownloads->getVar('paypal'); @@ -430,22 +544,23 @@ $GLOBALS['xoopsTpl']->assign('download', $download); // Utilisateur enregistré - $ratings = []; + $ratings = []; $criteria = new \CriteriaCompo(); $criteria->add(new \Criteria('lid', $downloads_lid)); $criteria->add(new \Criteria('ratinguser', 0, '!=')); - $votedataArray = $ratingHandler->getAll($criteria); - $votesTotal = count($votedataArray); + $votedataArray = $ratingHandler->getAll($criteria); + $votesTotal = count($votedataArray); $ratings['user_total'] = $votesTotal; - $userList = []; + $userList = []; foreach (array_keys($votedataArray) as $i) { /** @var \XoopsModules\Tdmdownloads\Rating[] $votedataArray */ + $userList[] = [ - 'ratinguser' => \XoopsUser::getUnameFromId($votedataArray[$i]->getVar('ratinguser')), - 'ratinghostname' => $votedataArray[$i]->getVar('ratinghostname'), - 'rating' => $votedataArray[$i]->getVar('rating'), + 'ratinguser' => \XoopsUser::getUnameFromId($votedataArray[$i]->getVar('ratinguser')), + 'ratinghostname' => $votedataArray[$i]->getVar('ratinghostname'), + 'rating' => $votedataArray[$i]->getVar('rating'), 'ratingtimestamp' => formatTimestamp($votedataArray[$i]->getVar('ratingtimestamp')), - 'myTextForm' => myTextForm('downloads.php?op=del_vote&lid=' . $votedataArray[$i]->getVar('lid') . '&rid=' . $votedataArray[$i]->getVar('ratingid'), 'X'), + 'myTextForm' => myTextForm('downloads.php?op=del_vote&lid=' . $votedataArray[$i]->getVar('lid') . '&rid=' . $votedataArray[$i]->getVar('ratingid'), 'X'), ]; } $ratings['user_list'] = $userList; @@ -453,19 +568,19 @@ $criteria = new \CriteriaCompo(); $criteria->add(new \Criteria('lid', $downloads_lid)); $criteria->add(new \Criteria('ratinguser', 0)); - $votedataArray = $ratingHandler->getAll($criteria); - $votesTotal = count($votedataArray); + $votedataArray = $ratingHandler->getAll($criteria); + $votesTotal = count($votedataArray); $ratings['anon_total'] = $votesTotal; - $anon_list = []; + $anon_list = []; foreach (array_keys($votedataArray) as $i) { $anon_list[] = [ - 'ratinghostname' => $votedataArray[$i]->getVar('ratinghostname'), - 'rating' => $votedataArray[$i]->getVar('rating'), + 'ratinghostname' => $votedataArray[$i]->getVar('ratinghostname'), + 'rating' => $votedataArray[$i]->getVar('rating'), 'ratingtimestamp' => formatTimestamp($votedataArray[$i]->getVar('ratingtimestamp')), - 'myTextForm' => myTextForm('downloads.php?op=del_vote&lid=' . $votedataArray[$i]->getVar('lid') . '&rid=' . $votedataArray[$i]->getVar('ratingid'), 'X'), + 'myTextForm' => myTextForm('downloads.php?op=del_vote&lid=' . $votedataArray[$i]->getVar('lid') . '&rid=' . $votedataArray[$i]->getVar('ratingid'), 'X'), ]; } - $ratings['anon_list'] = $anon_list; + $ratings['anon_list'] = $anon_list; $ratings['votes_total'] = $ratings['user_total'] + $ratings['anon_total']; $GLOBALS['xoopsTpl']->assign('ratings', $ratings); $GLOBALS['xoopsTpl']->assign('download_detail', true); @@ -475,29 +590,43 @@ $objvotedata = $ratingHandler->get(\Xmf\Request::getInt('rid')); if ($ratingHandler->delete($objvotedata)) { $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('lid', \Xmf\Request::getInt('lid'))); + $votedataArray = $ratingHandler->getAll($criteria); + $votesTotal = $ratingHandler->getCount($criteria); + $obj = $downloadsHandler->get(\Xmf\Request::getInt('lid')); + if (0 === $votesTotal) { $obj->setVar('rating', number_format(0, 1)); + $obj->setVar('votes', 0); + if ($downloadsHandler->insert($obj)) { redirect_header('downloads.php?op=view_downloads&downloads_lid=' . \Xmf\Request::getInt('lid'), 1, _AM_TDMDOWNLOADS_REDIRECT_DELOK); } } else { $ratingTotal = 0; + foreach (array_keys($votedataArray) as $i) { /** @var \XoopsModules\Tdmdownloads\Rating[] $votedataArray */ + $ratingTotal += $votedataArray[$i]->getVar('rating'); } + $rating = $ratingTotal / $votesTotal; - $obj->setVar('rating', number_format($rating, 1)); + + $obj->setVar('rating', number_format((float)$rating, 1)); + $obj->setVar('votes', $votesTotal); + if ($downloadsHandler->insert($obj)) { redirect_header('downloads.php?op=view_downloads&downloads_lid=' . \Xmf\Request::getInt('lid'), 1, _AM_TDMDOWNLOADS_REDIRECT_DELOK); } } + $GLOBALS['xoopsTpl']->assign('message_erreur', $obj->getHtmlErrors()); } $GLOBALS['xoopsTpl']->assign('message_erreur', $objvotedata->getHtmlErrors()); @@ -516,53 +645,64 @@ } else { $obj = $downloadsHandler->create(); } - $erreur = false; + $erreur = false; $errorMessage = ''; - $donnee = []; + $donnee = []; $obj->setVar('title', \Xmf\Request::getString('title', '', 'POST')); $obj->setVar('cid', \Xmf\Request::getInt('cid', 0, 'POST')); $obj->setVar('homepage', formatURL(\Xmf\Request::getUrl('homepage', '', 'POST'))); $obj->setVar('version', \Xmf\Request::getString('version', '', 'POST')); $obj->setVar('paypal', \Xmf\Request::getString('paypal', '', 'POST')); if (\Xmf\Request::hasVar('platform', 'POST')) { - $obj->setVar('platform', implode('|', \Xmf\Request::getString('platform', '', 'POST'))); + $obj->setVar('platform', implode('|', \Xmf\Request::getArray('platform', [], 'POST'))); } $obj->setVar('description', \Xmf\Request::getString('description', '', 'POST')); if (\Xmf\Request::hasVar('submitter', 'POST')) { $obj->setVar('submitter', \Xmf\Request::getInt('submitter', 0, 'POST')); + $donnee['submitter'] = \Xmf\Request::getInt('submitter', 0, 'POST'); } else { $obj->setVar('submitter', !empty($xoopsUser) ? $xoopsUser->getVar('uid') : 0); + $donnee['submitter'] = !empty($xoopsUser) ? $xoopsUser->getVar('uid') : 0; } if (\Xmf\Request::hasVar('downloads_modified')) { $obj->setVar('date', time()); + if (\Xmf\Request::hasVar('status', 'POST')) { $obj->setVar('status', 1); + $donnee['status'] = 1; } else { $obj->setVar('status', 0); + $donnee['status'] = 0; } } else { if (\Xmf\Request::hasVar('date_update', 'POST') && 'Y' === $_POST['date_update']) { $obj->setVar('date', strtotime($_POST['date'])); + if (\Xmf\Request::hasVar('status', 'POST')) { $obj->setVar('status', 2); + $donnee['status'] = 1; } else { $obj->setVar('status', 0); + $donnee['status'] = 0; } } else { if (\Xmf\Request::hasVar('status', 'POST')) { $obj->setVar('status', 1); + $donnee['status'] = 1; } else { $obj->setVar('status', 0); + $donnee['status'] = 0; } + if (\Xmf\Request::hasVar('date', 'POST')) { $obj->setVar('date', strtotime($_POST['date'])); } else { @@ -575,6 +715,7 @@ if (\Xmf\Request::hasVar('description', 'POST')) { if ('' === \Xmf\Request::getString('description', '')) { $erreur = true; + $errorMessage .= _AM_TDMDOWNLOADS_ERREUR_NODESCRIPTION . '
    '; } } @@ -582,6 +723,7 @@ if (\Xmf\Request::hasVar('cid', 'POST')) { if (0 == \Xmf\Request::getInt('cid', 0, 'POST')) { $erreur = true; + $errorMessage .= _AM_TDMDOWNLOADS_ERREUR_NOCAT . '
    '; } } @@ -592,13 +734,15 @@ $downloads_field = $fieldHandler->getAll($criteria); foreach (array_keys($downloads_field) as $i) { /** @var \XoopsModules\Tdmdownloads\Field[] $downloads_field */ + if (0 == $downloads_field[$i]->getVar('status_def')) { $fieldName = 'champ' . $downloads_field[$i]->getVar('fid'); + $donnee[$fieldName] = \Xmf\Request::getString($fieldName, '', 'POST'); } } // enregistrement temporaire des tags - if ((1 == $helper->getConfig('usetag')) && class_exists(Tag::class)) { + if (1 == $helper->getConfig('usetag') && class_exists(Tag::class)) { $donnee['TAG'] = $_POST['tag']; } @@ -606,160 +750,233 @@ $GLOBALS['xoopsTpl']->assign('message_erreur', $errorMessage); /** @var \XoopsThemeForm $form */ + $form = $obj->getForm($donnee, true); + $GLOBALS['xoopsTpl']->assign('themeForm', $form->render()); + break; } - // Pour le fichier - $mediaSize = 0; - if (isset($_POST['xoops_upload_file'][0])) { - $uploader = new \XoopsMediaUploader($uploaddir_downloads, $helper->getConfig('mimetype'), $helper->getConfig('maxuploadsize'), null, null); - if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) { - if ($helper->getConfig('newnamedownload')) { - $uploader->setPrefix($helper->getConfig('prefixdownloads')); - } - $uploader->fetchMedia($_POST['xoops_upload_file'][0]); - if (!$uploader->upload()) { - $errorMessage .= $uploader->getErrors() . '
    '; - $GLOBALS['xoopsTpl']->assign('message_erreur', $errorMessage); - $form = $obj->getForm($donnee, true); - $GLOBALS['xoopsTpl']->assign('themeForm', $form->render()); - break; - } - $mediaSize = $uploader->getMediaSize(); - $obj->setVar('url', $uploadurl_downloads . $uploader->getSavedFileName()); - } else { - if ($_FILES['attachedfile']['name'] > '') { - // file name was given, but fetchMedia failed - show error when e.g. file size exceed maxuploadsize - $errorMessage .= $uploader->getErrors() . '
    '; - $GLOBALS['xoopsTpl']->assign('message_erreur', $errorMessage); - $form = $obj->getForm($donnee, true); - $GLOBALS['xoopsTpl']->assign('themeForm', $form->render()); - break; - } - $obj->setVar('url', \Xmf\Request::getUrl('url', '', 'POST')); + // Pour le fichier + $mediaSize = 0; + if (isset($_POST['xoops_upload_file'][0])) { + $uploader = new \XoopsMediaUploader($uploaddir_downloads, $helper->getConfig('mimetypes'), $helper->getConfig('maxuploadsize'), null, null); + + if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) { + if ($helper->getConfig('newnamedownload')) { + $uploader->setPrefix($helper->getConfig('prefixdownloads')); } - } else { - $obj->setVar('url', \Xmf\Request::getUrl('url', '', 'POST')); - } - // Pour l'image - if (isset($_POST['xoops_upload_file'][1])) { - $uploader_2 = new \XoopsMediaUploader($uploaddir_shots, [ - 'image/gif', - 'image/jpeg', - 'image/pjpeg', - 'image/x-png', - 'image/png', - ], $helper->getConfig('maxuploadsize'), null, null); - if ($uploader_2->fetchMedia($_POST['xoops_upload_file'][1])) { - $uploader_2->setPrefix('downloads_'); - $uploader_2->fetchMedia($_POST['xoops_upload_file'][1]); - if (!$uploader_2->upload()) { - $errorMessage .= $uploader_2->getErrors() . '
    '; - $GLOBALS['xoopsTpl']->assign('message_erreur', $errorMessage); - $form = $obj->getForm($donnee, true); - $GLOBALS['xoopsTpl']->assign('themeForm', $form->render()); - break; - } - $obj->setVar('logourl', $uploader_2->getSavedFileName()); - } else { - if ($_FILES['attachedimage']['name'] > '') { - // file name was given, but fetchMedia failed - show error when e.g. file size exceed maxuploadsize - $errorMessage .= $uploader_2->getErrors() . '
    '; - $GLOBALS['xoopsTpl']->assign('message_erreur', $errorMessage); - $form = $obj->getForm($donnee, true); - $GLOBALS['xoopsTpl']->assign('themeForm', $form->render()); - break; - } - $obj->setVar('logourl', \Xmf\Request::getString('logo_img', '', 'POST')); + + $uploader->fetchMedia($_POST['xoops_upload_file'][0]); + + if (!$uploader->upload()) { + $errorMessage .= $uploader->getErrors() . '
    '; + + $GLOBALS['xoopsTpl']->assign('message_erreur', $errorMessage); + + $form = $obj->getForm($donnee, true); + + $GLOBALS['xoopsTpl']->assign('themeForm', $form->render()); + + break; } + + $mediaSize = $uploader->getMediaSize(); + + $obj->setVar('url', $uploadurl_downloads . $uploader->getSavedFileName()); } else { - $obj->setVar('logourl', \Xmf\Request::getString('logo_img', '', 'POST')); - } - //Automatic file size - if (Xmf\Request::getString('sizeValue', '') == ''){ - if ($mediaSize == 0) { - $obj->setVar('size', $utility::GetFileSize(Xmf\Request::getUrl('url', ''))); - } else { - $obj->setVar('size', $utility::FileSizeConvert($mediaSize)); - } - } else { - $obj->setVar('size', Xmf\Request::getFloat('sizeValue', 0) . ' ' . Xmf\Request::getString('sizeType', '')); - } - $timeToRedirect = 2; - if ($obj->getVar('size') == 0){ - $obj->setVar('size', ''); - $error_message = _AM_TDMDOWNLOADS_ERREUR_SIZE; - $timeToRedirect = 10; - } - // enregistrement - if ($downloadsHandler->insert($obj)) { - if (!\Xmf\Request::hasVar('downloads_modified')) { - $lidDownloads = $obj->getNewEnreg($db); - } else { - $lidDownloads = \Xmf\Request::getInt('lid'); + if ($_FILES['attachedfile']['name'] > '') { + // file name was given, but fetchMedia failed - show error when e.g. file size exceed maxuploadsize + + $errorMessage .= $uploader->getErrors() . '
    '; + + $GLOBALS['xoopsTpl']->assign('message_erreur', $errorMessage); + + $form = $obj->getForm($donnee, true); + + $GLOBALS['xoopsTpl']->assign('themeForm', $form->render()); + + break; } - //tags - if ((1 == $helper->getConfig('usetag')) && class_exists(TagHandler::class)) { - /** @var \XoopsModules\Tag\TagHandler $tagHandler */ - $tagHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Tag'); - $tagHandler->updateByItem($_POST['tag'], $lidDownloads, $moduleDirName, 0); + + $obj->setVar('url', \Xmf\Request::getUrl('url', '', 'POST')); + } + } else { + $obj->setVar('url', \Xmf\Request::getUrl('url', '', 'POST')); + } + // Pour l'image + if (isset($_POST['xoops_upload_file'][1])) { + $uploader_2 = new \XoopsMediaUploader( + $uploaddir_shots, [ + 'image/gif', + 'image/jpeg', + 'image/pjpeg', + 'image/x-png', + 'image/png', + ], $helper->getConfig('maxuploadsize'), null, null + ); + + if ($uploader_2->fetchMedia($_POST['xoops_upload_file'][1])) { + $uploader_2->setPrefix('downloads_'); + + $uploader_2->fetchMedia($_POST['xoops_upload_file'][1]); + + if (!$uploader_2->upload()) { + $errorMessage .= $uploader_2->getErrors() . '
    '; + + $GLOBALS['xoopsTpl']->assign('message_erreur', $errorMessage); + + $form = $obj->getForm($donnee, true); + + $GLOBALS['xoopsTpl']->assign('themeForm', $form->render()); + + break; } - // Récupération des champs supplémentaires: - $criteria = new \CriteriaCompo(); - $criteria->setSort('weight ASC, title'); - $criteria->setOrder('ASC'); - $downloads_field = $fieldHandler->getAll($criteria); - foreach (array_keys($downloads_field) as $i) { - if (0 == $downloads_field[$i]->getVar('status_def')) { - $iddata = 'iddata' . $downloads_field[$i]->getVar('fid'); - if (\Xmf\Request::hasVar($iddata, 'POST')) { - if ('' === \Xmf\Request::getString($iddata, '')) { - $objdata = $fielddataHandler->create(); - } else { - $objdata = $fielddataHandler->get(\Xmf\Request::getString($iddata, '', 'POST')); - } - } else { + + $obj->setVar('logourl', $uploader_2->getSavedFileName()); + } else { + if ($_FILES['attachedimage']['name'] > '') { + // file name was given, but fetchMedia failed - show error when e.g. file size exceed maxuploadsize + + $errorMessage .= $uploader_2->getErrors() . '
    '; + + $GLOBALS['xoopsTpl']->assign('message_erreur', $errorMessage); + + $form = $obj->getForm($donnee, true); + + $GLOBALS['xoopsTpl']->assign('themeForm', $form->render()); + + break; + } + + $obj->setVar('logourl', \Xmf\Request::getString('logo_img', '', 'POST')); + } + } else { + $obj->setVar('logourl', \Xmf\Request::getString('logo_img', '', 'POST')); + } + //Automatic file size + if ('' == Xmf\Request::getString('sizeValue', '')) { + if (0 == $mediaSize) { + $obj->setVar('size', $utility::getFileSize(Xmf\Request::getUrl('url', ''))); + } else { + $obj->setVar('size', $utility::convertFileSize($mediaSize)); + } + } else { + $obj->setVar('size', Xmf\Request::getFloat('sizeValue', 0) . ' ' . Xmf\Request::getString('sizeType', '')); + } + $timeToRedirect = 2; + if (0 == $obj->getVar('size')) { + $obj->setVar('size', ''); + + $error_message = _AM_TDMDOWNLOADS_ERREUR_SIZE; + + $timeToRedirect = 10; + } + // enregistrement + if ($downloadsHandler->insert($obj)) { + if (!\Xmf\Request::hasVar('downloads_modified')) { + $lidDownloads = $obj->getNewEnreg($db); + } else { + $lidDownloads = \Xmf\Request::getInt('lid'); + } + + //tags + + if (1 == $helper->getConfig('usetag') && class_exists(TagHandler::class)) { + /** @var \XoopsModules\Tag\TagHandler $tagHandler */ + + $tagHandler = TagHelper::getInstance()->getHandler('Tag'); + + $tagHandler->updateByItem($_POST['tag'], $lidDownloads, $moduleDirName, 0); + } + + // Récupération des champs supplémentaires: + + $criteria = new \CriteriaCompo(); + + $criteria->setSort('weight ASC, title'); + + $criteria->setOrder('ASC'); + + $downloads_field = $fieldHandler->getAll($criteria); + + foreach (array_keys($downloads_field) as $i) { + if (0 == $downloads_field[$i]->getVar('status_def')) { + $iddata = 'iddata' . $downloads_field[$i]->getVar('fid'); + + if (\Xmf\Request::hasVar($iddata, 'POST')) { + if ('' === \Xmf\Request::getString($iddata, '')) { $objdata = $fielddataHandler->create(); + } else { + $objdata = $fielddataHandler->get(\Xmf\Request::getString($iddata, '', 'POST')); } - $fieldName = 'champ' . $downloads_field[$i]->getVar('fid'); - $objdata->setVar('data', \Xmf\Request::getString($fieldName, '', 'POST')); - $objdata->setVar('lid', $lidDownloads); - $objdata->setVar('fid', $downloads_field[$i]->getVar('fid')); - $fielddataHandler->insert($objdata) || $objdata->getHtmlErrors(); + } else { + $objdata = $fielddataHandler->create(); } + + $fieldName = 'champ' . $downloads_field[$i]->getVar('fid'); + + $objdata->setVar('data', \Xmf\Request::getString($fieldName, '', 'POST')); + + $objdata->setVar('lid', $lidDownloads); + + $objdata->setVar('fid', $downloads_field[$i]->getVar('fid')); + + $fielddataHandler->insert($objdata) || $objdata->getHtmlErrors(); } - //permission pour télécharger - if (2 == $helper->getConfig('permission_download')) { - /** @var \XoopsGroupPermHandler $grouppermHandler */ - $grouppermHandler = xoops_getHandler('groupperm'); - $criteria = new \CriteriaCompo(); - $criteria->add(new \Criteria('gperm_itemid', $lidDownloads, '=')); - $criteria->add(new \Criteria('gperm_modid', $xoopsModule->getVar('mid'), '=')); - $criteria->add(new \Criteria('gperm_name', 'tdmdownloads_download_item', '=')); - $grouppermHandler->deleteAll($criteria); - if (\Xmf\Request::hasVar('item_download', 'POST')) { - foreach ($_POST['item_download'] as $onegroup_id) { - $grouppermHandler->addRight('tdmdownloads_download_item', $lidDownloads, $onegroup_id, $xoopsModule->getVar('mid')); - } + } + + //permission pour télécharger + + if (2 == $helper->getConfig('permission_download')) { + /** @var \XoopsGroupPermHandler $grouppermHandler */ + + $grouppermHandler = xoops_getHandler('groupperm'); + + $criteria = new \CriteriaCompo(); + + $criteria->add(new \Criteria('gperm_itemid', $lidDownloads, '=')); + + $criteria->add(new \Criteria('gperm_modid', $xoopsModule->getVar('mid'), '=')); + + $criteria->add(new \Criteria('gperm_name', 'tdmdownloads_download_item', '=')); + + $grouppermHandler->deleteAll($criteria); + + if (\Xmf\Request::hasVar('item_download', 'POST')) { + foreach ($_POST['item_download'] as $onegroup_id) { + $grouppermHandler->addRight('tdmdownloads_download_item', $lidDownloads, $onegroup_id, $xoopsModule->getVar('mid')); } } - // pour les notifications uniquement lors d'un nouveau téléchargement - if (\Xmf\Request::hasVar('downloads_modified')) { - $tags = []; - $tags['FILE_NAME'] = \Xmf\Request::getString('title', '', 'POST'); - $tags['FILE_URL'] = XOOPS_URL . '/modules/' . $moduleDirName . '/singlefile.php?cid=' . \Xmf\Request::getInt('cid', 0, 'POST') . '&lid=' . $lidDownloads; - $downloadscat_cat = $categoryHandler->get(\Xmf\Request::getInt('cid', 0, 'POST')); - $tags['CATEGORY_NAME'] = $downloadscat_cat->getVar('cat_title'); - $tags['CATEGORY_URL'] = XOOPS_URL . '/modules/' . $moduleDirName . '/viewcat.php?cid=' . \Xmf\Request::getInt('cid', 0, 'POST'); - /** @var \XoopsNotificationHandler $notificationHandler */ - $notificationHandler = xoops_getHandler('notification'); - $notificationHandler->triggerEvent('global', 0, 'new_file', $tags); - $notificationHandler->triggerEvent('category', \Xmf\Request::getInt('cid', 0, 'POST'), 'new_file', $tags); - } - redirect_header('downloads.php', $timeToRedirect, _AM_TDMDOWNLOADS_REDIRECT_SAVE . '

    ' . $error_message); } - $GLOBALS['xoopsTpl']->assign('message_erreur', $obj->getHtmlErrors()); + + // pour les notifications uniquement lors d'un nouveau téléchargement + + if (\Xmf\Request::hasVar('downloads_modified')) { + $tags = []; + + $tags['FILE_NAME'] = \Xmf\Request::getString('title', '', 'POST'); + + $tags['FILE_URL'] = XOOPS_URL . '/modules/' . $moduleDirName . '/singlefile.php?cid=' . \Xmf\Request::getInt('cid', 0, 'POST') . '&lid=' . $lidDownloads; + + $downloadscat_cat = $categoryHandler->get(\Xmf\Request::getInt('cid', 0, 'POST')); + + $tags['CATEGORY_NAME'] = $downloadscat_cat->getVar('cat_title'); + + $tags['CATEGORY_URL'] = XOOPS_URL . '/modules/' . $moduleDirName . '/viewcat.php?cid=' . \Xmf\Request::getInt('cid', 0, 'POST'); + + /** @var \XoopsNotificationHandler $notificationHandler */ + + $notificationHandler = xoops_getHandler('notification'); + + $notificationHandler->triggerEvent('global', 0, 'new_file', $tags); + + $notificationHandler->triggerEvent('category', \Xmf\Request::getInt('cid', 0, 'POST'), 'new_file', $tags); + } + + redirect_header('downloads.php', $timeToRedirect, _AM_TDMDOWNLOADS_REDIRECT_SAVE . '

    ' . $error_message); + } + $GLOBALS['xoopsTpl']->assign('message_erreur', $obj->getHtmlErrors()); $form = $obj->getForm($donnee, true); $GLOBALS['xoopsTpl']->assign('themeForm', $form->render()); @@ -787,9 +1004,11 @@ // Local icons path if (is_object($helper->getModule())) { $pathModIcon16 = $helper->getModule()->getInfo('modicons16'); + $pathModIcon32 = $helper->getModule()->getInfo('modicons32'); $GLOBALS['xoopsTpl']->assign('pathModIcon16', XOOPS_URL . '/modules/' . $moduleDirName . '/' . $pathModIcon16); + $GLOBALS['xoopsTpl']->assign('pathModIcon32', $pathModIcon32); } diff --git a/admin/field.php b/admin/field.php index 011522d..4881e2e 100644 --- a/admin/field.php +++ b/admin/field.php @@ -1,4 +1,5 @@ -assign('navigation', $adminObject->displayNavigation(basename(__FILE__))); $adminObject->addItemButton(_AM_TDMDOWNLOADS_FIELD_NEW, 'field.php?op=new_field', 'add'); $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left')); @@ -46,6 +51,7 @@ foreach (array_keys($downloads_field) as $i) { /** @var \XoopsModules\Tdmdownloads\Field[] $downloads_field */ + $field = [ 'title' => $downloads_field[$i]->getVar('title'), 'img' => $uploadurl_field . $downloads_field[$i]->getVar('img'), @@ -56,7 +62,9 @@ 'status_def' => $downloads_field[$i]->getVar('status_def'), 'search' => $downloads_field[$i]->getVar('search'), ]; + $GLOBALS['xoopsTpl']->append('fields_list', $field); + unset($field); } } @@ -83,14 +91,14 @@ case 'new_field': //Affichage de la partie haute de l'administration de Xoops xoops_cp_header(); - $adminObject = \Xmf\Module\Admin::getInstance(); + $adminObject = Admin::getInstance(); $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation(basename(__FILE__))); $adminObject->addItemButton(_AM_TDMDOWNLOADS_FIELD_LIST, 'field.php?op=list', 'list'); $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left')); //Affichage du formulaire de création des champs /** @var \XoopsModules\Tdmdownloads\Field $obj */ - $obj = $fieldHandler->create(); + $obj = $fieldHandler->create(); /** @var \XoopsThemeForm $form */ $form = $obj->getForm(); $GLOBALS['xoopsTpl']->assign('themeForm', $form->render()); @@ -99,7 +107,7 @@ case 'edit_field': //Affichage de la partie haute de l'administration de Xoops xoops_cp_header(); - $adminObject = \Xmf\Module\Admin::getInstance(); + $adminObject = Admin::getInstance(); $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation(basename(__FILE__))); $adminObject->addItemButton(_AM_TDMDOWNLOADS_FIELD_NEW, 'field.php?op=new_field', 'add'); $adminObject->addItemButton(_AM_TDMDOWNLOADS_FIELD_LIST, 'field.php?op=list', 'list'); @@ -120,16 +128,25 @@ if (!$GLOBALS['xoopsSecurity']->check()) { redirect_header('field.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); } + // supression des entrée du champ + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('fid', \Xmf\Request::getInt('fid', 0))); + $downloadsArray = $fielddataHandler->getAll($criteria); + foreach (array_keys($downloadsArray) as $i) { /** @var \XoopsModules\Tdmdownloads\Downloads[] $downloadsArray */ + // supression de l'entrée + $objdownloadsfielddata = $fielddataHandler->get($downloadsArray[$i]->getVar('iddata')); + $fielddataHandler->delete($objdownloadsfielddata) || $objdownloads->getHtmlErrors(); } + if ($fieldHandler->delete($obj)) { redirect_header('field.php', 1, _AM_TDMDOWNLOADS_REDIRECT_DELOK); } else { @@ -137,26 +154,41 @@ } } else { $downloadsfield = $fieldHandler->get(\Xmf\Request::getInt('fid', 0, 'GET')); + if (1 == $downloadsfield->getVar('status_def')) { redirect_header('field.php', 2, _AM_TDMDOWNLOADS_REDIRECT_NODELFIELD); } - $message = ''; + + $message = ''; + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('fid', \Xmf\Request::getInt('fid', 0, 'GET'))); + /** @var \XoopsModules\Tdmdownloads\Fielddata[] $downloadsArray */ + $downloadsArray = $fielddataHandler->getAll($criteria); + if (count($downloadsArray) > 0) { $message .= _AM_TDMDOWNLOADS_DELDATA . '
    '; + foreach (array_keys($downloadsArray) as $i) { $message .= '' . $downloadsArray[$i]->getVar('data') . '
    '; } } + //Affichage de la partie haute de l'administration de Xoops + xoops_cp_header(); - $adminObject = \Xmf\Module\Admin::getInstance(); + + $adminObject = Admin::getInstance(); + $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation(basename(__FILE__))); + $adminObject->addItemButton(_AM_TDMDOWNLOADS_FIELD_NEW, 'field.php?op=new_field', 'add'); + $adminObject->addItemButton(_AM_TDMDOWNLOADS_FIELD_LIST, 'field.php?op=list', 'list'); + $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left')); xoops_confirm(['ok' => 1, 'fid' => \Xmf\Request::getInt('fid', 0, 'GET'), 'op' => 'del_field'], $_SERVER['REQUEST_URI'], sprintf(_AM_TDMDOWNLOADS_FORMSUREDEL, $obj->getVar('title')) . '

    ' . $message); @@ -174,23 +206,28 @@ } else { $obj = $fieldHandler->create(); } - $erreur = false; + $erreur = false; $errorMessage = ''; // Récupération des variables: // Pour l'image require_once XOOPS_ROOT_PATH . '/class/uploader.php'; - $uploader = new \XoopsMediaUploader($uploaddir_field, [ - 'image/gif', - 'image/jpeg', - 'image/pjpeg', - 'image/x-png', - 'image/png', - ], $helper->getConfig('maxuploadsize'), 16, null); + $uploader = new \XoopsMediaUploader( + $uploaddir_field, [ + 'image/gif', + 'image/jpeg', + 'image/pjpeg', + 'image/x-png', + 'image/png', + ], $helper->getConfig('maxuploadsize'), 16, null + ); if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) { $uploader->setPrefix('downloads_'); + $uploader->fetchMedia($_POST['xoops_upload_file'][0]); + if (!$uploader->upload()) { $errors = $uploader->getErrors(); + redirect_header('javascript:history.go(-1)', 3, $errors); } else { $obj->setVar('img', $uploader->getSavedFileName()); @@ -207,12 +244,15 @@ if (true === $erreur) { xoops_cp_header(); + $GLOBALS['xoopsTpl']->assign('message_erreur', $errorMessage); } else { if ($fieldHandler->insert($obj)) { redirect_header('field.php', 1, _AM_TDMDOWNLOADS_REDIRECT_SAVE); } + xoops_cp_header(); + $GLOBALS['xoopsTpl']->assign('message_erreur', $obj->getHtmlErrors()); } $form = $obj->getForm(); @@ -223,9 +263,11 @@ // Local icons path if (is_object($helper->getModule())) { $pathModIcon16 = $helper->getModule()->getInfo('modicons16'); + $pathModIcon32 = $helper->getModule()->getInfo('modicons32'); $GLOBALS['xoopsTpl']->assign('pathModIcon16', XOOPS_URL . '/modules/' . $moduleDirName . '/' . $pathModIcon16); + $GLOBALS['xoopsTpl']->assign('pathModIcon32', $pathModIcon32); } diff --git a/admin/import.php b/admin/import.php index bcd6549..47c5fe1 100644 --- a/admin/import.php +++ b/admin/import.php @@ -1,4 +1,5 @@ -assign('navigation', $adminObject->displayNavigation(basename(__FILE__))); @@ -37,13 +43,20 @@ function importMydownloads($path = '', $imgurl = '') { $moduleDirName = basename(dirname(__DIR__)); - $ok = \Xmf\Request::getInt('ok', 0, 'POST'); + + $ok = \Xmf\Request::getInt('ok', 0, 'POST'); + global $xoopsDB; + if (1 === $ok) { //Vider les tables + $myTables = ['tdmdownloads_broken', 'tdmdownloads_cat', 'tdmdownloads_downloads', 'tdmdownloads_fielddata', 'tdmdownloads_modfielddata', 'tdmdownloads_votedata']; - $table = new \Xmf\Database\TableLoad(); - $tables = new \Xmf\Database\Tables(); + + $table = new TableLoad(); + + $tables = new Tables(); + foreach ($myTables as $myTable) { if ($tables->useTable($myTable)) { // if this returns false, there is no table $table::truncateTable($myTable); @@ -51,100 +64,132 @@ function importMydownloads($path = '', $imgurl = '') } //Inserer les données des catégories - $query_topic = $xoopsDB->query('SELECT cid, pid, title, imgurl FROM ' . $xoopsDB->prefix('mydownloads_cat')); - while (false !== ($donnees = $xoopsDB->fetchArray($query_topic))) { - if ('' === $donnees['imgurl']) { - $img = 'blank.gif'; - } else { - $img = substr_replace($donnees['imgurl'], '', 0, mb_strlen($imgurl)); - @copy($path . $img, XOOPS_ROOT_PATH . '/uploads/' . $moduleDirName . '/images/cats/' . $img); - } - $title = $donnees['title']; - $insert = $xoopsDB->queryF('INSERT INTO ' . $xoopsDB->prefix('tdmdownloads_cat') . " (cat_cid, cat_pid, cat_title, cat_imgurl, cat_description_main, cat_weight ) VALUES ('" . $donnees['cid'] . "', '" . $donnees['pid'] . "', '" . $title . "', '" . $img . "', '', '0')"); - if (!$insert) { - $errors[] = ['title' => _AM_TDMDOWNLOADS_IMPORT_ERROR_DATA, 'info' => $donnees['title']]; + $result = $xoopsDB->query('SELECT cid, pid, title, imgurl FROM ' . $xoopsDB->prefix('mydownloads_cat')); + + if ($result instanceof \mysqli_result) { + while (false !== ($donnees = $xoopsDB->fetchArray($result))) { + if ('' === $donnees['imgurl']) { + $img = 'blank.gif'; + } else { + $img = substr_replace($donnees['imgurl'], '', 0, mb_strlen($imgurl)); + + @copy($path . $img, XOOPS_ROOT_PATH . '/uploads/' . $moduleDirName . '/images/cats/' . $img); + } + + $title = $donnees['title']; + + $insert = $xoopsDB->queryF('INSERT INTO ' . $xoopsDB->prefix('tdmdownloads_cat') . " (cat_cid, cat_pid, cat_title, cat_imgurl, cat_description_main, cat_weight ) VALUES ('" . $donnees['cid'] . "', '" . $donnees['pid'] . "', '" . $title . "', '" . $img . "', '', '0')"); + + if (!$insert) { + $errors[] = ['title' => _AM_TDMDOWNLOADS_IMPORT_ERROR_DATA, 'info' => $donnees['title']]; + } + + $successes[] = sprintf(_AM_TDMDOWNLOADS_IMPORT_CAT_IMP, $donnees['title']); } - $successes[] = sprintf(_AM_TDMDOWNLOADS_IMPORT_CAT_IMP, $donnees['title']); } echo '
    '; //Inserer les données des téléchargemnts - $query_links = $xoopsDB->query('SELECT lid, cid, title, url, homepage, version, size, platform, logourl, submitter, status, date, hits, rating, votes, comments FROM ' . $xoopsDB->prefix('mydownloads_downloads')); - while (false !== ($donnees = $xoopsDB->fetchArray($query_links))) { - //On recupere la description - $requete = $xoopsDB->queryF('SELECT description FROM ' . $xoopsDB->prefix('mydownloads_text') . " WHERE lid = '" . $donnees['lid'] . "'"); - list($description) = $xoopsDB->fetchRow($requete); - $insert = $xoopsDB->queryF('INSERT INTO ' - . $xoopsDB->prefix('tdmdownloads_downloads') - . " ( + + $result = $xoopsDB->query('SELECT lid, cid, title, url, homepage, version, size, platform, logourl, submitter, status, date, hits, rating, votes, comments FROM ' . $xoopsDB->prefix('mydownloads_downloads')); + if ($result instanceof \mysqli_result) { + while (false !== ($donnees = $xoopsDB->fetchArray($result))) { + //On recupere la description + + $requete = $xoopsDB->queryF('SELECT description FROM ' . $xoopsDB->prefix('mydownloads_text') . " WHERE lid = '" . $donnees['lid'] . "'"); + + [$description] = $xoopsDB->fetchRow($requete); + + $insert = $xoopsDB->queryF( + 'INSERT INTO ' + . $xoopsDB->prefix('tdmdownloads_downloads') + . " ( lid, cid, title, url, homepage, version, size, platform, description, logourl, submitter, status, date, hits, rating, votes, comments, top) VALUES ('" - . $donnees['lid'] - . "', '" - . $donnees['cid'] - . "', '" - . $donnees['title'] - . "', '" - . $donnees['url'] - . "', '" - . $donnees['homepage'] - . "', '" - . $donnees['version'] - . "', '" - . $donnees['size'] - . "', '" - . $donnees['platform'] - . "', '" - . $description - . "', '" - . $donnees['logourl'] - . "', '" - . $donnees['submitter'] - . "', '" - . $donnees['status'] - . "', '" - . $donnees['date'] - . "', '" - . $donnees['hits'] - . "', '" - . $donnees['rating'] - . "', '" - . $donnees['votes'] - . "', '0', '0' )"); - if (!$insert) { - $errors[] = ['title' => _AM_TDMDOWNLOADS_IMPORT_ERROR_DATA, 'info' => $donnees['title']]; + . $donnees['lid'] + . "', '" + . $donnees['cid'] + . "', '" + . $donnees['title'] + . "', '" + . $donnees['url'] + . "', '" + . $donnees['homepage'] + . "', '" + . $donnees['version'] + . "', '" + . $donnees['size'] + . "', '" + . $donnees['platform'] + . "', '" + . $description + . "', '" + . $donnees['logourl'] + . "', '" + . $donnees['submitter'] + . "', '" + . $donnees['status'] + . "', '" + . $donnees['date'] + . "', '" + . $donnees['hits'] + . "', '" + . $donnees['rating'] + . "', '" + . $donnees['votes'] + . "', '0', '0' )" + ); + + if (!$insert) { + $errors[] = ['title' => _AM_TDMDOWNLOADS_IMPORT_ERROR_DATA, 'info' => $donnees['title']]; + } + + $successes[] = sprintf(_AM_TDMDOWNLOADS_IMPORT_DOWNLOADS_IMP, $donnees['title']); + + @copy($path . $donnees['logourl'], XOOPS_ROOT_PATH . '/uploads/' . $moduleDirName . '/images/shots/' . $donnees['logourl']); } - $successes[] = sprintf(_AM_TDMDOWNLOADS_IMPORT_DOWNLOADS_IMP, $donnees['title']); - @copy($path . $donnees['logourl'], XOOPS_ROOT_PATH . '/uploads/' . $moduleDirName . '/images/shots/' . $donnees['logourl']); } + echo '
    '; + //Inserer les données des votes - $query_vote = $xoopsDB->query('SELECT ratingid, lid, ratinguser, rating, ratinghostname, ratingtimestamp FROM ' . $xoopsDB->prefix('mydownloads_votedata')); - while (false !== ($donnees = $xoopsDB->fetchArray($query_vote))) { - $insert = $xoopsDB->queryF('INSERT INTO ' - . $xoopsDB->prefix('tdmdownloads_votedata') - . " (ratingid, lid, ratinguser, rating, ratinghostname, ratingtimestamp ) VALUES ('" - . $donnees['ratingid'] - . "', '" - . $donnees['lid'] - . "', '" - . $donnees['ratinguser'] - . "', '" - . $donnees['rating'] - . "', '" - . $donnees['ratinghostname'] - . "', '" - . $donnees['ratingtimestamp'] - . "')"); - if (!$insert) { - $errors[] = ['title' => _AM_TDMDOWNLOADS_IMPORT_ERROR_DATA, 'info' => $donnees['ratingid']]; + + $result = $xoopsDB->query('SELECT ratingid, lid, ratinguser, rating, ratinghostname, ratingtimestamp FROM ' . $xoopsDB->prefix('mydownloads_votedata')); + if ($result instanceof \mysqli_result) { + while (false !== ($donnees = $xoopsDB->fetchArray($result))) { + $insert = $xoopsDB->queryF( + 'INSERT INTO ' + . $xoopsDB->prefix('tdmdownloads_votedata') + . " (ratingid, lid, ratinguser, rating, ratinghostname, ratingtimestamp ) VALUES ('" + . $donnees['ratingid'] + . "', '" + . $donnees['lid'] + . "', '" + . $donnees['ratinguser'] + . "', '" + . $donnees['rating'] + . "', '" + . $donnees['ratinghostname'] + . "', '" + . $donnees['ratingtimestamp'] + . "')" + ); + + if (!$insert) { + $errors[] = ['title' => _AM_TDMDOWNLOADS_IMPORT_ERROR_DATA, 'info' => $donnees['ratingid']]; + } + + $successes[] = sprintf(_AM_TDMDOWNLOADS_IMPORT_VOTE_IMP, $donnees['ratingid']); } - $successes[] = sprintf(_AM_TDMDOWNLOADS_IMPORT_VOTE_IMP, $donnees['ratingid']); } + echo '

    '; + echo "
    "; + echo _AM_TDMDOWNLOADS_IMPORT_OK; + echo '
    '; } else { xoops_confirm(['op' => 'importMydownloads', 'ok' => 1, 'path' => $path, 'imgurl' => $imgurl], 'import.php', _AM_TDMDOWNLOADS_IMPORT_CONF_MYDOWNLOADS . '
    '); @@ -159,13 +204,20 @@ function importMydownloads($path = '', $imgurl = '') function importWfdownloads($shots = '', $catimg = '') { $moduleDirName = basename(dirname(__DIR__)); - $ok = \Xmf\Request::getInt('ok', 0, 'POST'); + + $ok = \Xmf\Request::getInt('ok', 0, 'POST'); + global $xoopsDB; + if (1 === $ok) { //Vider les tables + $myTables = ['tdmdownloads_broken', 'tdmdownloads_cat', 'tdmdownloads_downloads', 'tdmdownloads_fielddata', 'tdmdownloads_modfielddata', 'tdmdownloads_votedata']; - $table = new \Xmf\Database\TableLoad(); - $tables = new \Xmf\Database\Tables(); + + $table = new TableLoad(); + + $tables = new Tables(); + foreach ($myTables as $myTable) { if ($tables->useTable($myTable)) { // if this returns false, there is no table $table::truncateTable($myTable); @@ -173,116 +225,105 @@ function importWfdownloads($shots = '', $catimg = '') } //Inserer les données des catégories - $query_topic = $xoopsDB->query('SELECT cid, pid, title, imgurl, description, total, summary, spotlighttop, spotlighthis, dohtml, dosmiley, doxcode, doimage, dobr, weight, formulize_fid FROM ' . $xoopsDB->prefix('wfdownloads_cat')); - while (false !== ($donnees = $xoopsDB->fetchArray($query_topic))) { - if ('' === $donnees['imgurl']) { - $img = 'blank.gif'; - } else { - $img = $donnees['imgurl']; - @copy($catimg . $img, XOOPS_ROOT_PATH . '/uploads/' . $moduleDirName . '/images/cats/' . $img); - } - $insert = $xoopsDB->queryF('INSERT INTO ' - . $xoopsDB->prefix('tdmdownloads_cat') - . " (cat_cid, cat_pid, cat_title, cat_imgurl, cat_description_main, cat_weight ) VALUES ('" - . $donnees['cid'] - . "', '" - . $donnees['pid'] - . "', '" - . addcslashes($donnees['title'], "'") - . "', '" - . $img - . "', '" - . addcslashes($donnees['description'], "'") - . "', '" - . $donnees['weight'] - . "')"); - if (!$insert) { - $errors[] = ['title' => _AM_TDMDOWNLOADS_IMPORT_ERROR_DATA, 'info' => $donnees['title']]; + + $result = $xoopsDB->query('SELECT cid, pid, title, imgurl, description, total, summary, spotlighttop, spotlighthis, dohtml, dosmiley, doxcode, doimage, dobr, weight, formulize_fid FROM ' . $xoopsDB->prefix('wfdownloads_cat')); + if ($result instanceof \mysqli_result) { + while (false !== ($donnees = $xoopsDB->fetchArray($result))) { + if ('' === $donnees['imgurl']) { + $img = 'blank.gif'; + } else { + $img = $donnees['imgurl']; + + @copy($catimg . $img, XOOPS_ROOT_PATH . '/uploads/' . $moduleDirName . '/images/cats/' . $img); + } + + $insert = $xoopsDB->queryF( + 'INSERT INTO ' . $xoopsDB->prefix('tdmdownloads_cat') . " (cat_cid, cat_pid, cat_title, cat_imgurl, cat_description_main, cat_weight ) VALUES ('" . $donnees['cid'] . "', '" . $donnees['pid'] . "', '" . addcslashes($donnees['title'], "'") . "', '" . $img . "', '" . addcslashes( + $donnees['description'], + "'" + ) . "', '" . $donnees['weight'] . "')" + ); + + if (!$insert) { + $errors[] = ['title' => _AM_TDMDOWNLOADS_IMPORT_ERROR_DATA, 'info' => $donnees['title']]; + } + + $successes[] = sprintf(_AM_TDMDOWNLOADS_IMPORT_CAT_IMP, $donnees['title']); } - $successes[] = sprintf(_AM_TDMDOWNLOADS_IMPORT_CAT_IMP, $donnees['title']); } + echo '
    '; //Inserer les données des téléchargemnts - $query_links = $xoopsDB->query('SELECT lid, cid, title, url, filename, filetype, homepage, version, size, platform, screenshot, screenshot2, screenshot3, screenshot4, submitter, publisher, status, date, hits, rating, votes, comments, license, mirror, price, paypalemail, features, requirements, homepagetitle, forumid, limitations, versiontypes, dhistory, published, expired, updated, offline, summary, description, ipaddress, notifypub, formulize_idreq FROM ' - . $xoopsDB->prefix('wfdownloads_downloads')); - while (false !== ($donnees = $xoopsDB->fetchArray($query_links))) { - if ('' === $donnees['url']) { - $newurl = XOOPS_URL . '/uploads/' . $donnees['filename']; - } else { - $newurl = $donnees['url']; - } - $insert = $xoopsDB->queryF('INSERT INTO ' - . $xoopsDB->prefix('tdmdownloads_downloads') - . " ( + + $query_links = $xoopsDB->query( + 'SELECT lid, cid, title, url, filename, filetype, homepage, version, size, platform, screenshot, screenshot2, screenshot3, screenshot4, submitter, publisher, status, date, hits, rating, votes, comments, license, mirror, price, paypalemail, features, requirements, homepagetitle, forumid, limitations, versiontypes, dhistory, published, expired, updated, offline, summary, description, ipaddress, notifypub, formulize_idreq FROM ' + . $xoopsDB->prefix('wfdownloads_downloads') + ); + if ($query_links instanceof \mysqli_result) { + while (false !== ($donnees = $xoopsDB->fetchArray($query_links))) { + if ('' === $donnees['url']) { + $newurl = XOOPS_URL . '/uploads/' . $donnees['filename']; + } else { + $newurl = $donnees['url']; + } + + $insert = $xoopsDB->queryF( + 'INSERT INTO ' . $xoopsDB->prefix('tdmdownloads_downloads') . " ( lid, cid, title, url, homepage, version, size, platform, description, logourl, submitter, status, date, hits, rating, votes, comments, top) VALUES - ('" - . $donnees['lid'] - . "', '" - . $donnees['cid'] - . "', '" - . addcslashes($donnees['title'], "'") - . "', '" - . $newurl - . "', '" - . $donnees['homepage'] - . "', '" - . $donnees['version'] - . "', '" - . $donnees['size'] - . "', '" - . $donnees['platform'] - . "', '" - . addcslashes($donnees['description'], "'") - . "', '" - . $donnees['screenshot'] - . "', '" - . $donnees['submitter'] - . "', '" - . $donnees['status'] - . "', '" - . $donnees['date'] - . "', '" - . $donnees['hits'] - . "', '" - . $donnees['rating'] - . "', '" - . $donnees['votes'] - . "', '0', '0' )"); - - if (!$insert) { - $errors[] = ['title' => _AM_TDMDOWNLOADS_IMPORT_ERROR_DATA, 'info' => $donnees['title']]; + ('" . $donnees['lid'] . "', '" . $donnees['cid'] . "', '" . addcslashes($donnees['title'], "'") . "', '" . $newurl . "', '" . $donnees['homepage'] . "', '" . $donnees['version'] . "', '" . $donnees['size'] . "', '" . $donnees['platform'] . "', '" . addcslashes( + $donnees['description'], + "'" + ) . "', '" . $donnees['screenshot'] . "', '" . $donnees['submitter'] . "', '" . $donnees['status'] . "', '" . $donnees['date'] . "', '" . $donnees['hits'] . "', '" . $donnees['rating'] . "', '" . $donnees['votes'] . "', '0', '0' )" + ); + + if (!$insert) { + $errors[] = ['title' => _AM_TDMDOWNLOADS_IMPORT_ERROR_DATA, 'info' => $donnees['title']]; + } + + $successes[] = sprintf(_AM_TDMDOWNLOADS_IMPORT_DOWNLOADS_IMP, $donnees['title']); + + @copy($shots . $donnees['screenshot'], XOOPS_ROOT_PATH . '/uploads/' . $moduleDirName . '/images/shots/' . $donnees['screenshot']); } - $successes[] = sprintf(_AM_TDMDOWNLOADS_IMPORT_DOWNLOADS_IMP, $donnees['title']); - @copy($shots . $donnees['screenshot'], XOOPS_ROOT_PATH . '/uploads/' . $moduleDirName . '/images/shots/' . $donnees['screenshot']); } + echo '
    '; //Inserer les données des votes + $query_vote = $xoopsDB->query('SELECT ratingid, lid, ratinguser, rating, ratinghostname, ratingtimestamp FROM ' . $xoopsDB->prefix('wfdownloads_votedata')); - while (false !== ($donnees = $xoopsDB->fetchArray($query_vote))) { - $insert = $xoopsDB->queryF('INSERT INTO ' - . $xoopsDB->prefix('tdmdownloads_votedata') - . " (ratingid, lid, ratinguser, rating, ratinghostname, ratingtimestamp ) VALUES ('" - . $donnees['ratingid'] - . "', '" - . $donnees['lid'] - . "', '" - . $donnees['ratinguser'] - . "', '" - . $donnees['rating'] - . "', '" - . $donnees['ratinghostname'] - . "', '" - . $donnees['ratingtimestamp'] - . "')"); - if (!$insert) { - echo '' . _AM_TDMDOWNLOADS_IMPORT_ERROR_DATA . ': ' . $donnees['ratingid'] . '
    '; + if ($query_vote instanceof \mysqli_result) { + while (false !== ($donnees = $xoopsDB->fetchArray($query_vote))) { + $insert = $xoopsDB->queryF( + 'INSERT INTO ' + . $xoopsDB->prefix('tdmdownloads_votedata') + . " (ratingid, lid, ratinguser, rating, ratinghostname, ratingtimestamp ) VALUES ('" + . $donnees['ratingid'] + . "', '" + . $donnees['lid'] + . "', '" + . $donnees['ratinguser'] + . "', '" + . $donnees['rating'] + . "', '" + . $donnees['ratinghostname'] + . "', '" + . $donnees['ratingtimestamp'] + . "')" + ); + + if (!$insert) { + echo '' . _AM_TDMDOWNLOADS_IMPORT_ERROR_DATA . ': ' . $donnees['ratingid'] . '
    '; + } + + echo sprintf(_AM_TDMDOWNLOADS_IMPORT_VOTE_IMP . '
    ', $donnees['ratingid']); } - echo sprintf(_AM_TDMDOWNLOADS_IMPORT_VOTE_IMP . '
    ', $donnees['ratingid']); } + $successes[] = _AM_TDMDOWNLOADS_IMPORT_OK; + $GLOBALS['xoopsTpl']->assign('successes', $successes); + $GLOBALS['xoopsTpl']->assign('errors', $errors); } else { xoops_confirm(['op' => 'importWfdownloads', 'ok' => 1, 'shots' => $shots, 'catimg' => $catimg], 'import.php', _AM_TDMDOWNLOADS_IMPORT_CONF_WFDOWNLOADS . '
    '); @@ -316,20 +357,22 @@ function importWfdownloads($shots = '', $catimg = '') global $xoopsDB; $sql = $xoopsDB->query('SELECT COUNT(lid) AS count FROM ' . $xoopsDB->prefix('mydownloads_downloads')); - list($count_downloads) = $xoopsDB->fetchRow($sql); + [$count_downloads] = $xoopsDB->fetchRow($sql); if ($count_downloads < 1) { $check .= '
  • ' . _AM_TDMDOWNLOADS_IMPORT_DONT_DOWNLOADS . '
  • '; } else { $check .= '
  • ' . sprintf(_AM_TDMDOWNLOADS_IMPORT_NB_DOWNLOADS, $count_downloads) . '
  • '; + $counter++; } $sql = $xoopsDB->query('SELECT COUNT(cid) AS count FROM ' . $xoopsDB->prefix('mydownloads_cat')); - list($count_topic) = $xoopsDB->fetchRow($sql); + [$count_topic] = $xoopsDB->fetchRow($sql); if ($count_topic < 1) { $check .= '
  • ' . _AM_TDMDOWNLOADS_IMPORT_DONT_TOPIC . '
  • '; } else { $check .= '
  • ' . sprintf('
    ' . _AM_TDMDOWNLOADS_IMPORT_NB_CAT, $count_topic) . '
  • '; + $counter++; } $check .= ''; @@ -341,9 +384,11 @@ function importWfdownloads($shots = '', $catimg = '') // To execute if ($counter > 0) { $form->addElement(new \XoopsFormHidden('op', 'import_mydownloads')); + $form->addElement(new \XoopsFormButtonTray('', _SUBMIT, 'submit', '', false)); } else { $form->addElement(new \XoopsFormHidden('op', 'cancel')); + $form->addElement(new \XoopsFormButton('', 'submit', _CANCEL, 'submit')); } $GLOBALS['xoopsTpl']->assign('themeForm', $form->render()); @@ -368,19 +413,21 @@ function importWfdownloads($shots = '', $catimg = '') $check = '
      '; $sql = $xoopsDB->query('SELECT COUNT(lid) AS count FROM ' . $xoopsDB->prefix('wfdownloads_downloads')); - list($count_downloads) = $xoopsDB->fetchRow($sql); + [$count_downloads] = $xoopsDB->fetchRow($sql); if ($count_downloads < 1) { $check .= '
    • ' . _AM_TDMDOWNLOADS_IMPORT_DONT_DOWNLOADS . '
    • '; } else { $check .= '
    • ' . sprintf(_AM_TDMDOWNLOADS_IMPORT_NB_DOWNLOADS, $count_downloads) . '
    • '; + $counter++; } $sql = $xoopsDB->query('SELECT COUNT(cid) AS count FROM ' . $xoopsDB->prefix('wfdownloads_cat')); - list($count_topic) = $xoopsDB->fetchRow($sql); + [$count_topic] = $xoopsDB->fetchRow($sql); if ($count_topic < 1) { $check .= '
    • ' . _AM_TDMDOWNLOADS_IMPORT_DONT_TOPIC . '
    • '; } else { $check .= '
    • ' . sprintf('
      ' . _AM_TDMDOWNLOADS_IMPORT_NB_CAT, $count_topic) . '
    • '; + $counter++; } $check .= '
    '; @@ -392,9 +439,11 @@ function importWfdownloads($shots = '', $catimg = '') // To execute if ($counter > 0) { $form->addElement(new \XoopsFormHidden('op', 'import_mydownloads')); + $form->addElement(new \XoopsFormButtonTray('', _SUBMIT, 'submit', '', false)); } else { $form->addElement(new \XoopsFormHidden('op', 'cancel')); + $form->addElement(new \XoopsFormButton('', 'submit', _CANCEL, 'submit')); } $GLOBALS['xoopsTpl']->assign('themeForm', $form->render()); diff --git a/admin/index.html b/admin/index.html deleted file mode 100644 index 990cbd6..0000000 --- a/admin/index.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/admin/index.php b/admin/index.php index c73c2a3..bb71725 100644 --- a/admin/index.php +++ b/admin/index.php @@ -1,4 +1,5 @@ -getCount(); -$adminObject = \Xmf\Module\Admin::getInstance(); +$adminObject = Admin::getInstance(); $adminObject->addInfoBox(_MI_TDMDOWNLOADS_ADMENU2); if (0 == $nb_categories) { $adminObject->addInfoBoxLine(sprintf(_AM_TDMDOWNLOADS_INDEX_CATEGORIES, '' . $nb_categories . ''), '', 'Red'); @@ -73,49 +88,45 @@ //--------------------------- $adminObject->addConfigBoxLine(''); -$helper = \XoopsModules\Tdmdownloads\Helper::getInstance(); +$helper = Helper::getInstance(); $helper->loadLanguage('common'); -/** @var \XoopsModules\Tdmdownloads\Common\Configurator $configurator */ -$configurator = new \XoopsModules\Tdmdownloads\Common\Configurator(); +$configurator = new Configurator(); -/** @var \XoopsModules\Tdmdownloads\Utility $utility */ -$utility = new \XoopsModules\Tdmdownloads\Utility(); +$utility = new Utility(); foreach (array_keys($configurator->uploadFolders) as $i) { $utility::createFolder($configurator->uploadFolders[$i]); + $adminObject->addConfigBoxLine($configurator->uploadFolders[$i], 'folder'); } $adminObject->displayNavigation(basename(__FILE__)); //check for latest release -$newRelease = $utility::checkVerModule($helper); -if (!empty($newRelease)) { - $adminObject->addItemButton($newRelease[0], $newRelease[1], 'download', 'style="color : Red"'); -} - -//------------- Test Data ---------------------------- +//$newRelease = $utility->checkVerModule($helper); +//if (null !== $newRelease) { +// $adminObject->addItemButton($newRelease[0], $newRelease[1], 'download', 'style="color : Red"'); +//} +//------------- Test Data Buttons ---------------------------- if ($helper->getConfig('displaySampleButton')) { - xoops_loadLanguage('admin/modulesadmin', 'system'); - require dirname(__DIR__) . '/testdata/index.php'; - - $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'ADD_SAMPLEDATA'), '__DIR__ . /../../testdata/index.php?op=load', 'add'); - - $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'SAVE_SAMPLEDATA'), '__DIR__ . /../../testdata/index.php?op=save', 'add'); - - // $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA'), '__DIR__ . /../../testdata/index.php?op=exportschema', 'add'); - + TestdataButtons::loadButtonConfig($adminObject); + $adminObject->displayButton('left', ''); } - -//------------- End Test Data ---------------------------- - -$adminObject->displayButton('left', ''); +$op = Request::getString('op', 0, 'GET'); +switch ($op) { + case 'hide_buttons': + TestdataButtons::hideButtons(); + break; + case 'show_buttons': + TestdataButtons::showButtons(); + break; +} +//------------- End Test Data Buttons ---------------------------- $adminObject->displayIndex(); - echo $utility::getServerStats(); + //codeDump(__FILE__); require __DIR__ . '/admin_footer.php'; - diff --git a/admin/menu.php b/admin/menu.php index 5641e6d..e0ef1f9 100644 --- a/admin/menu.php +++ b/admin/menu.php @@ -1,4 +1,5 @@ -loadLanguage('common'); +$helper->loadLanguage('feedback'); -$pathIcon32 = \Xmf\Module\Admin::menuIconPath(''); +$pathIcon32 = Admin::menuIconPath(''); if (is_object($helper->getModule())) { - $pathModIcon32 = $helper->getModule()->getInfo('modicons32'); +// $pathModIcon32 = $helper->getModule()->getInfo('modicons32'); + $pathModIcon32 = $helper->url($helper->getModule()->getInfo('modicons32')); } $adminmenu[] = [ 'title' => _MI_TDMDOWNLOADS_ADMENU1, 'link' => 'admin/index.php', - 'icon' => "{$pathModIcon32}/home.png", +// 'icon' => "{$pathModIcon32}/home.png", + 'icon' => 'assets/images/admin/home.png', ]; $adminmenu[] = [ 'title' => _MI_TDMDOWNLOADS_ADMENU2, 'link' => 'admin/category.php', - 'icon' => "{$pathModIcon32}/category.png", - //'menu' => "{$pathIcon32}/menu_category.png", +// 'icon' => "{$pathModIcon32}/category.png", + 'icon' => 'assets/images/admin/category.png', ]; $adminmenu[] = [ 'title' => _MI_TDMDOWNLOADS_ADMENU3, 'link' => 'admin/downloads.php', - 'icon' => "{$pathModIcon32}/downloads.png", +// 'icon' => "{$pathModIcon32}/downloads.png", + 'icon' => 'assets/images/admin/downloads.png', //'menu' => "{$pathIcon32}/menu_downloads.png", ]; $adminmenu[] = [ 'title' => _MI_TDMDOWNLOADS_ADMENU4, 'link' => 'admin/broken.php', - 'icon' => "{$pathModIcon32}/broken.png", +// 'icon' => "{$pathModIcon32}/broken.png", + 'icon' => 'assets/images/admin/broken.png', //'menu' => "{$pathIcon32}/menu_broken.png", ]; $adminmenu[] = [ 'title' => _MI_TDMDOWNLOADS_ADMENU5, 'link' => 'admin/modified.php', - 'icon' => "{$pathModIcon32}/modified.png", +// 'icon' => "{$pathModIcon32}/modified.png", + 'icon' => 'assets/images/admin/modified.png', //'menu' => "{$pathIcon32}/menu_modified.png", ]; $adminmenu[] = [ 'title' => _MI_TDMDOWNLOADS_ADMENU6, 'link' => 'admin/field.php', - 'icon' => "{$pathModIcon32}/field.png", +// 'icon' => "{$pathModIcon32}/field.png", + 'icon' => 'assets/images/admin/field.png', //'menu' => "{$pathIcon32}/menu_field.png", ]; $adminmenu[] = [ 'title' => _MI_TDMDOWNLOADS_ADMENU7, 'link' => 'admin/import.php', - 'icon' => "{$pathModIcon32}/import.png", +// 'icon' => "{$pathModIcon32}/import.png", + 'icon' => 'assets/images/admin/import.png', //'menu' => "{$pathIcon32}/menu_import.png", ]; @@ -89,7 +102,7 @@ 'icon' => $pathIcon32 . '/block.png', ]; -if ($helper->getConfig('displayDeveloperTools')) { +if (is_object($helper->getModule()) && $helper->getConfig('displayDeveloperTools')) { $adminmenu[] = [ 'title' => constant('CO_' . $moduleDirNameUpper . '_' . 'ADMENU_MIGRATE'), 'link' => 'admin/migrate.php', diff --git a/admin/migrate.php b/admin/migrate.php index dc26335..73936de 100644 --- a/admin/migrate.php +++ b/admin/migrate.php @@ -1,8 +1,9 @@ - // // ------------------------------------------------------------------------ // // This program is free software; you can redistribute it and/or modify // @@ -29,10 +30,20 @@ // Project: XOOPS Project // // ------------------------------------------------------------------------- // + use Xmf\Request; -use XoopsModules\Tdmdownloads; +use Xmf\Module\Admin; +use XoopsModules\Tdmdownloads\{ + Common\Configurator, + Common\Migrate, + Helper +}; -require_once __DIR__ . '/admin_header.php'; +/** @var Admin $adminObject */ +/** @var Configurator $configurator */ +/** @var Migrate $migrator */ + +require __DIR__ . '/admin_header.php'; xoops_cp_header(); $adminObject->displayNavigation(basename(__FILE__)); @@ -53,24 +64,23 @@ //XoopsLoad::load('migrate', 'newbb'); -/** @var Tdmdownloads\Common\Configurator $configurator */ -$configurator = new Tdmdownloads\Common\Configurator(); +$configurator = new Configurator(); -/** @var \XoopsModules\Tdmdownloads\Common\Migrate $migrator */ -$migrator = new \XoopsModules\Tdmdownloads\Common\Migrate($configurator); +$migrator = new Migrate($configurator); -$op = Request::getCmd('op', 'default'); -$opShow = Request::getCmd('show', null, 'POST'); +$op = Request::getCmd('op', 'show'); +$opShow = Request::getCmd('show', null, 'POST'); $opMigrate = Request::getCmd('migrate', null, 'POST'); -$opSchema = Request::getCmd('schema', null, 'POST'); -$op = !empty($opShow) ? 'show' : $op; -$op = !empty($opMigrate) ? 'migrate' : $op; -$op = !empty($opSchema) ? 'schema' : $op; +$opSchema = Request::getCmd('schema', null, 'POST'); +$op = !empty($opShow) ? 'show' : $op; +$op = !empty($opMigrate) ? 'migrate' : $op; +$op = !empty($opSchema) ? 'schema' : $op; $message = ''; switch ($op) { case 'show': + default: $queue = $migrator->getSynchronizeDDL(); if (!empty($queue)) { echo "
    \n";
    @@ -82,15 +92,16 @@
             break;
         case 'migrate':
             $migrator->synchronizeSchema();
    -        $message = 'Database migrated to current schema.';
    +        $message = constant('CO_' . $moduleDirNameUpper . '_' . 'MIGRATE_OK');
             break;
         case 'schema':
    -        xoops_confirm(['op' => 'confirmwrite'], 'migrate.php', 'Warning! This is intended for developers only. Confirm write schema file from current database.', 'Confirm');
    +        xoops_confirm(['op' => 'confirmwrite'], 'migrate.php', constant('CO_' . $moduleDirNameUpper . '_' . 'MIGRATE_WARNING'), constant('CO_' . $moduleDirNameUpper . '_' . 'CONFIRM'));
             break;
         case 'confirmwrite':
             if ($GLOBALS['xoopsSecurity']->check()) {
                 $migrator->saveCurrentSchema();
    -            $message = 'Current schema file written';
    +
    +            $message = constant('CO_' . $moduleDirNameUpper . '_' . 'MIGRATE_SCHEMA_OK');
             }
             break;
     }
    diff --git a/admin/modified.php b/admin/modified.php
    index c43818f..c0f8b38 100644
    --- a/admin/modified.php
    +++ b/admin/modified.php
    @@ -1,4 +1,5 @@
    -setLimit(\Xmf\Request::getInt('limit', 0, 'REQUEST'));
    +
                 $limit = \Xmf\Request::getInt('limit', 0, 'REQUEST');
             } else {
                 $criteria->setLimit($helper->getConfig('perpageadmin'));
    +
                 $limit = $helper->getConfig('perpageadmin');
             }
             if (\Xmf\Request::hasVar('start', 'REQUEST')) {
                 $criteria->setStart(\Xmf\Request::getInt('start', 0, 'REQUEST'));
    +
                 $start = \Xmf\Request::getInt('start', 0, 'REQUEST');
             } else {
                 $criteria->setStart(0);
    +
                 $start = 0;
             }
             $criteria->setSort('requestid');
    @@ -54,6 +62,7 @@
             $numrows = $modifiedHandler->getCount(); //Ggoffy
             if ($numrows > $limit) {
                 $pagenav = new \XoopsPageNav($numrows, $limit, $start, 'start', 'op=liste&limit=' . $limit);
    +
                 $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav(4));
             } else {
                 $pagenav = '';
    @@ -61,21 +70,30 @@
             //Affichage du tableau des téléchargements modifiés
             if ($numrows > 0) {
                 $GLOBALS['xoopsTpl']->assign('modified_count', $numrows);
    +
                 foreach (array_keys($downloadsmod_arr) as $i) {
                     /** @var \XoopsModules\Tdmdownloads\Modified[] $downloadsmod_arr */
    +
                     $downloads = $downloadsHandler->get($downloadsmod_arr[$i]->getVar('lid'));
    +
                     // pour savoir si le fichier est nouveau
    -                $downloads_url    = $downloads->getVar('url');
    +
    +                $downloads_url = $downloads->getVar('url');
    +
                     $moddownloads_url = $downloadsmod_arr[$i]->getVar('url');
    -                $new_file         = ($downloads_url != $moddownloads_url);
    -                $modified         = [
    +
    +                $new_file = ($downloads_url != $moddownloads_url);
    +
    +                $modified = [
                         'lid'             => $downloadsmod_arr[$i]->getVar('lid'),
                         'requestid'       => $downloadsmod_arr[$i]->getVar('requestid'),
                         'new_file'        => $new_file,
                         'download_title'  => $downloads->getVar('title'),
                         'modifysubmitter' => XoopsUser::getUnameFromId($downloadsmod_arr[$i]->getVar('modifysubmitter')),
                     ];
    +
                     $GLOBALS['xoopsTpl']->append('modified_list', $modified);
    +
                     unset($modified);
                 }
             } else {
    @@ -130,46 +148,72 @@
             $downloads_field = $fieldHandler->getAll($criteria);
             foreach (array_keys($downloads_field) as $i) {
                 /** @var \XoopsModules\Tdmdownloads\Field[] $downloads_field */
    +
                 if (1 == $downloads_field[$i]->getVar('status_def')) {
                     if (1 == $downloads_field[$i]->getVar('fid')) {
                         //page d'accueil
    +
                         $compare['cfields'][] = ['info' => _AM_TDMDOWNLOADS_FORMHOMEPAGE, 'current' => $downloads_homepage, 'modified' => $moddownloads_homepage];
                     }
    +
                     if (2 == $downloads_field[$i]->getVar('fid')) {
                         //version
    +
                         $compare['cfields'][] = ['info' => _AM_TDMDOWNLOADS_FORMVERSION, 'current' => $downloads_version, 'modified' => $moddownloads_version];
                     }
    +
                     if (3 == $downloads_field[$i]->getVar('fid')) {
                         //taille du fichier
    -                    $compare['cfields'][] = ['info' => _AM_TDMDOWNLOADS_FORMSIZE, 'current' => $downloads_size, 'modified' => $moddownloads_size];
    +
    +                    $compare['cfields'][] = ['info' => _AM_TDMDOWNLOADS_FORMSIZE_WHEN_SUBMIT, 'current' => $downloads_size, 'modified' => $moddownloads_size];
                     }
    +
                     if (4 == $downloads_field[$i]->getVar('fid')) {
                         //plateforme
    +
                         $compare['cfields'][] = ['info' => _AM_TDMDOWNLOADS_FORMPLATFORM, 'current' => $downloads_platform, 'modified' => $moddownloads_platform];
                     }
                 } else {
                     //original
    -                $contenu  = '';
    +
    +                $contenu = '';
    +
                     $criteria = new \CriteriaCompo();
    +
                     $criteria->add(new \Criteria('lid', \Xmf\Request::getInt('downloads_lid', 0, 'REQUEST')));
    +
                     $criteria->add(new \Criteria('fid', $downloads_field[$i]->getVar('fid')));
    +
                     $downloadsfielddata = $fielddataHandler->getAll($criteria);
    +
                     foreach (array_keys($downloadsfielddata) as $j) {
                         /** @var \XoopsModules\Tdmdownloads\Fielddata[] $downloadsfielddata */
    +
                         //                    $contenu = $downloadsfielddata[$j]->getVar('data');
    +
                         $contenu = $downloadsfielddata[$j]->getVar('data', 'e');
                     }
    +
                     //proposé
    +
                     $contentModified = '';
    -                $criteria    = new \CriteriaCompo();
    +
    +                $criteria = new \CriteriaCompo();
    +
                     $criteria->add(new \Criteria('lid', \Xmf\Request::getInt('mod_id', 0, 'REQUEST')));
    +
                     $criteria->add(new \Criteria('fid', $downloads_field[$i]->getVar('fid')));
    +
                     $downloadsfieldmoddata = $modifieddataHandler->getAll($criteria);
    +
                     foreach (array_keys($downloadsfieldmoddata) as $j) {
                         /** @var \XoopsModules\Tdmdownloads\Modified[] $downloadsfieldmoddata */
    +
                         $contentModified = $downloadsfieldmoddata[$j]->getVar('moddata', 'e');
                     }
    +
                     //                echo '
    ' . $downloads_field[$i]->getVar('title') . ': ' . $contentModified . '
     
    - <{if $pagenav}> + <{if $pagenav|default:''}>
    <{$pagenav}>
    <{/if}> <{/if}> -<{if $themeForm}> +<{if $themeForm|default:''}> <{$themeForm}> <{/if}>
    diff --git a/templates/admin/tdmdownloads_admin_category.tpl b/templates/admin/tdmdownloads_admin_category.tpl index cbb082d..8a2f44a 100644 --- a/templates/admin/tdmdownloads_admin_category.tpl +++ b/templates/admin/tdmdownloads_admin_category.tpl @@ -1,9 +1,9 @@ <{include file='db:tdmdownloads_admin_header.tpl'}> -<{if $message_erreur}> +<{if $message_erreur|default:''}>
    <{$message_erreur}>
    <{/if}> -<{if $categories_list}> +<{if $categories_list|default:''}> @@ -37,13 +37,13 @@ <{/if}>
     
    - <{if $pagenav}> + <{if $pagenav|default:''}>
    <{$pagenav}>
    <{/if}> <{/if}> -<{if $themeForm}> +<{if $themeForm|default:''}> <{$themeForm}> <{/if}> diff --git a/templates/admin/tdmdownloads_admin_downloads.tpl b/templates/admin/tdmdownloads_admin_downloads.tpl index 7ad50f6..5635d35 100644 --- a/templates/admin/tdmdownloads_admin_downloads.tpl +++ b/templates/admin/tdmdownloads_admin_downloads.tpl @@ -1,18 +1,18 @@ <{include file='db:tdmdownloads_admin_header.tpl'}> -<{if $message_erreur}> +<{if $message_erreur|default:''}>
    <{$message_erreur}>
    <{/if}>
    - <{$selectDocument}> <{$selectOrder}> + <{$selectDocument|default:''}> <{$selectOrder|default:''}>
    -<{if $downloads_list}> +<{if $downloads_list|default:''}> @@ -53,14 +53,14 @@ <{/if}>
     
    - <{if $pagenav}> + <{if $pagenav|default:''}>
    <{$pagenav}>
    <{/if}> <{/if}> -<{if $download_detail}> +<{if $download_detail|default:''}> @@ -184,7 +184,7 @@
    <{$download.title}>
    <{/if}> -<{if $themeForm}> +<{if $themeForm|default:''}> <{$themeForm}> <{/if}> diff --git a/templates/admin/tdmdownloads_admin_field.tpl b/templates/admin/tdmdownloads_admin_field.tpl index 2360421..a3ee1b7 100644 --- a/templates/admin/tdmdownloads_admin_field.tpl +++ b/templates/admin/tdmdownloads_admin_field.tpl @@ -1,6 +1,6 @@ <{include file='db:tdmdownloads_admin_header.tpl'}> -<{if $message_erreur}> +<{if $message_erreur|default:''}>
    <{$message_erreur}>
    <{/if}> <{if $fields_list}> @@ -42,13 +42,13 @@ <{/if}>
     
    - <{if $pagenav}> + <{if $pagenav|default:''}>
    <{$pagenav}>
    <{/if}> <{/if}> -<{if $themeForm}> +<{if $themeForm|default:''}> <{$themeForm}> <{/if}> diff --git a/templates/admin/tdmdownloads_admin_footer.tpl b/templates/admin/tdmdownloads_admin_footer.tpl index bbf04f0..10caf94 100644 --- a/templates/admin/tdmdownloads_admin_footer.tpl +++ b/templates/admin/tdmdownloads_admin_footer.tpl @@ -1,8 +1,10 @@ -
    XOOPS
    +
    XOOPS
    TDMDownloads <{$smarty.const._AM_TDMDOWNLOADS_MAINTAINEDBY}> Xoops Support Team - <{if $latestModRelease}> -


    + <{if $latestModRelease|default:''}> +
    +
    +
    <{$latestModRelease}> <{/if}>
    diff --git a/templates/admin/tdmdownloads_admin_header.tpl b/templates/admin/tdmdownloads_admin_header.tpl index d0ef53e..63bf592 100644 --- a/templates/admin/tdmdownloads_admin_header.tpl +++ b/templates/admin/tdmdownloads_admin_header.tpl @@ -1,8 +1,8 @@
    - <{if $navigation}> + <{if $navigation|default:''}> <{$navigation}>  <{/if}> - <{if $buttons}> + <{if $buttons|default:''}> <{$buttons}>  <{/if}>
    diff --git a/templates/admin/tdmdownloads_admin_import.tpl b/templates/admin/tdmdownloads_admin_import.tpl index 108c2de..f3f228a 100644 --- a/templates/admin/tdmdownloads_admin_import.tpl +++ b/templates/admin/tdmdownloads_admin_import.tpl @@ -11,21 +11,21 @@ -webkit-border-radius: 4px; border-radius: 4px; line-height: 140%; - margin-top: 0px; + margin-top: 0; margin-bottom: 50px; } <{include file='db:tdmdownloads_admin_header.tpl'}> -<{if $message_erreur}> +<{if $message_erreur|default:''}>
    <{$message_erreur}>
    <{/if}> -<{if $successes}> +<{if $successes|default:''}> <{foreach item=success from=$successes}> <{/foreach}> <{/if}> -<{if $errors}> +<{if $errors|default:''}> <{foreach item=error from=$errors}> <{$error.title}>: <{$error.info}>
    @@ -37,7 +37,7 @@
    <{$smarty.const._AM_TDMDOWNLOADS_IMPORT_WARNING}>
    <{/if}> -<{if $themeForm}> +<{if $themeForm|default:''}> <{$themeForm}> <{/if}> diff --git a/templates/admin/tdmdownloads_admin_index.tpl b/templates/admin/tdmdownloads_admin_index.tpl index 989a724..9990a9c 100644 --- a/templates/admin/tdmdownloads_admin_index.tpl +++ b/templates/admin/tdmdownloads_admin_index.tpl @@ -1,6 +1,6 @@ <{include file='db:tdmdownloads_admin_header.tpl'}> -
    <{$index}>
    +
    <{$index|default:''}>
    <{include file='db:tdmdownloads_admin_footer.tpl'}> diff --git a/templates/admin/tdmdownloads_admin_modified.tpl b/templates/admin/tdmdownloads_admin_modified.tpl index 80cef86..3c92aef 100644 --- a/templates/admin/tdmdownloads_admin_modified.tpl +++ b/templates/admin/tdmdownloads_admin_modified.tpl @@ -7,10 +7,10 @@ font-weight: bold; } -<{if $message_erreur}> +<{if $message_erreur|default:''}>
    <{$message_erreur}>
    <{/if}> -<{if $modified_list}> +<{if $modified_list|default:''}> @@ -35,13 +35,13 @@ <{/if}>
     
    - <{if $pagenav}> + <{if $pagenav|default:''}>
    <{$pagenav}>
    <{/if}> <{/if}> -<{if $compare_list}> +<{if $compare_list|default:''}> @@ -89,7 +89,7 @@ <{/if}> -<{if $themeForm}> +<{if $themeForm|default:''}> <{$themeForm}> <{/if}> diff --git a/templates/admin/tdmdownloads_admin_permissions.tpl b/templates/admin/tdmdownloads_admin_permissions.tpl index 580c0a1..8542f4c 100644 --- a/templates/admin/tdmdownloads_admin_permissions.tpl +++ b/templates/admin/tdmdownloads_admin_permissions.tpl @@ -1,6 +1,6 @@ <{include file='db:tdmdownloads_admin_header.tpl'}> -<{if $message_erreur}> +<{if $message_erreur|default:''}>
    <{$message_erreur}>
    <{/if}> <{if $form_select}> diff --git a/templates/blocks/index.html b/templates/blocks/index.html deleted file mode 100644 index 990cbd6..0000000 --- a/templates/blocks/index.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/templates/blocks/index.php b/templates/blocks/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/templates/blocks/index.php @@ -0,0 +1,2 @@ + <{/if}>
    - + + +
    <{/if}> diff --git a/templates/blocks/tdmdownloads_block_styledefault.tpl b/templates/blocks/tdmdownloads_block_styledefault.tpl index d4eb17e..ff0268e 100644 --- a/templates/blocks/tdmdownloads_block_styledefault.tpl +++ b/templates/blocks/tdmdownloads_block_styledefault.tpl @@ -1,7 +1,7 @@
    <{if $downloads.inforation}> @@ -15,13 +15,13 @@ <{if $downloads.logourl || $downloads.description}>
    - <{if $downloads.logourl != ""}> + <{if $downloads.logourl|default:'' != ''}> <{$downloads.title}> <{/if}> - <{if $downloads.description != ""}> + <{if $downloads.description|default:'' != ''}> <{$downloads.description}> - --> + --> <{/if}>
    diff --git a/templates/blocks/tdmdownloads_block_stylesimple.tpl b/templates/blocks/tdmdownloads_block_stylesimple.tpl index 00e58ec..e48d5b4 100644 --- a/templates/blocks/tdmdownloads_block_stylesimple.tpl +++ b/templates/blocks/tdmdownloads_block_stylesimple.tpl @@ -1,39 +1,40 @@ <{if $tdmblockstyle == 'simple4'}> -
    -<{elseif $tdmblockstyle == 'simple3'}> +
    + <{elseif $tdmblockstyle == 'simple3'}>
    -<{elseif $tdmblockstyle == 'simple2'}> -
    -<{else}> -
    -<{/if}> -
    -
    - <{if $downloads.logourl}> - + <{elseif $tdmblockstyle == 'simple2'}> +
    + <{else}> +
    <{/if}> -

    <{$downloads.title}>

    - <{if $downloads.description}> -

    <{$downloads.description}>

    - <{/if}> - <{if $downloads.inforation}> -

    - <{$smarty.const._MB_TDMDOWNLOADS_SUBMITDATE}><{$downloads.date}>
    - <{$smarty.const._MB_TDMDOWNLOADS_SUBMITTER}><{$downloads.submitter}>
    - <{$smarty.const._MB_TDMDOWNLOADS_REATING}><{$downloads.rating}>
    - <{$smarty.const._MB_TDMDOWNLOADS_HITS}><{$downloads.hits}> -

    - <{/if}> -
    -
    -

    - - <{if $perm_submit}> - - <{/if}> -

    +
    +
    + <{if $downloads.logourl}> + + <{/if}> +

    <{$downloads.title}>

    + <{if $downloads.description}> +

    <{$downloads.description}>

    + <{/if}> + <{if $downloads.inforation}> +

    + <{$smarty.const._MB_TDMDOWNLOADS_SUBMITDATE}><{$downloads.date}>
    + <{$smarty.const._MB_TDMDOWNLOADS_SUBMITTER}><{$downloads.submitter}>
    + <{$smarty.const._MB_TDMDOWNLOADS_REATING}><{$downloads.rating}>
    + <{$smarty.const._MB_TDMDOWNLOADS_HITS}><{$downloads.hits}> +

    + <{/if}> +
    +
    +

    + + <{if $perm_submit}> + + <{/if}> +

    +
    +
    -
    -
    diff --git a/templates/index.html b/templates/index.html deleted file mode 100644 index 990cbd6..0000000 --- a/templates/index.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/templates/index.php b/templates/index.php new file mode 100644 index 0000000..6a50543 --- /dev/null +++ b/templates/index.php @@ -0,0 +1,2 @@ + +
  • + <{foreach item=itm from=$xoBreadcrumbs name=bcloop}> +
  • + <{if $itm.link}> + <{$itm.title}> + <{else}> + <{$itm.title}> + <{/if}> +
  • + <{/foreach}> + diff --git a/templates/tdmdownloads_brokenfile.tpl b/templates/tdmdownloads_brokenfile.tpl index 0f8da96..2c08699 100644 --- a/templates/tdmdownloads_brokenfile.tpl +++ b/templates/tdmdownloads_brokenfile.tpl @@ -2,7 +2,7 @@ @@ -16,7 +16,7 @@
    - <{if $message_erreur}> + <{if $message_erreur|default:''}>
    <{$message_erreur}>
    <{/if}> diff --git a/templates/tdmdownloads_download.tpl b/templates/tdmdownloads_download.tpl index 4e9c4cd..ed0818c 100644 --- a/templates/tdmdownloads_download.tpl +++ b/templates/tdmdownloads_download.tpl @@ -1,7 +1,7 @@
    @@ -15,8 +15,8 @@ <{if $down.pop}> <{$down.pop}> <{/if}> - <{if $down.perm_download != ""}> - + <{$smarty.const._MD_TDMDOWNLOADS_INDEX_DLNOW}> <{/if}> <{$smarty.const._MD_TDMDOWNLOADS_INDEX_SUBMITDATE}><{$down.updated}> @@ -24,7 +24,7 @@ <{$down.description_short}>
    <{if $show_screenshot === true}> - <{if $down.logourl != ''}> + <{if $down.logourl|default:'' != ''}> <{$down.title}> <{/if}> <{/if}> @@ -33,7 +33,7 @@
    diff --git a/templates/tdmdownloads_footer.tpl b/templates/tdmdownloads_footer.tpl new file mode 100644 index 0000000..6971e04 --- /dev/null +++ b/templates/tdmdownloads_footer.tpl @@ -0,0 +1,24 @@ +<{if $error|default:''}> +
    <{$error}>
    +<{/if}> +
    +<{if $xoops_isadmin}> + +
    +<{/if}> +
    + <{if $comment_mode|default:'' == "flat"}> + <{include file="db:system_comments_flat.tpl"}> + <{elseif $comment_mode|default:'' == "thread"}> + <{include file="db:system_comments_thread.tpl"}> + <{elseif $comment_mode|default:'' == "nest"}> + <{include file="db:system_comments_nest.tpl"}> + <{/if}> +
    + +
    +<{include file='db:system_notification_select.tpl'}> +
    +<{if $copyright|default:''}> +
    <{$copyright}>
    +<{/if}> diff --git a/templates/tdmdownloads_header.tpl b/templates/tdmdownloads_header.tpl new file mode 100644 index 0000000..75a2fe0 --- /dev/null +++ b/templates/tdmdownloads_header.tpl @@ -0,0 +1,8 @@ +<{if $show_breadcrumbs|default:''}> + <{include file='db:tdmdownloads_breadcrumbs.tpl'}> +<{/if}> + +<{if $ads|default:'' != ''}> +
    +<{$ads}>
    +<{/if}> diff --git a/templates/tdmdownloads_index.tpl b/templates/tdmdownloads_index.tpl index 1bacef1..8c09dda 100644 --- a/templates/tdmdownloads_index.tpl +++ b/templates/tdmdownloads_index.tpl @@ -2,10 +2,10 @@ - <{if count($categories) gt 0}> + <{if is_array($categories|default:'') && count($categories) gt 0}>
    @@ -15,21 +15,21 @@
    - <{if $category.image != ""}> - <{$category.title}> + <{if $category.image|default:'' != ''}> + <{$category.title}> <{/if}> <{$category.description_main}>
    - <{if $category.subcategories != ""}> + <{if $category.subcategories|default:'' != ''}>
    <{$smarty.const._MD_TDMDOWNLOADS_INDEX_SCAT}>
      <{$category.subcategories}>
    @@ -48,23 +48,23 @@
    - <{$smarty.const._MD_TDMDOWNLOADS_RSS}> + <{$smarty.const._MD_TDMDOWNLOADS_RSS}>
    <{if $bl_affichage==1}>
    <{$smarty.const._MD_TDMDOWNLOADS_INDEX_BLNAME}>
    - <{if $bl_date != ""}> + <{if $bl_date|default:'' != ''}> <{/if}> - <{if $bl_pop != ""}> + <{if $bl_pop|default:'' != ''}> <{/if}> - <{if $bl_rating != ""}> + <{if $bl_rating|default:'' != ''}>
    - <{$smarty.const._MD_TDMDOWNLOADS_INDEX_BLDATE}><{$smarty.const._MD_TDMDOWNLOADS_INDEX_BLDATE}> + <{$smarty.const._MD_TDMDOWNLOADS_INDEX_BLDATE}><{$smarty.const._MD_TDMDOWNLOADS_INDEX_BLDATE}>
    - <{$smarty.const._MD_TDMDOWNLOADS_INDEX_BLPOP}><{$smarty.const._MD_TDMDOWNLOADS_INDEX_BLPOP}> + <{$smarty.const._MD_TDMDOWNLOADS_INDEX_BLPOP}><{$smarty.const._MD_TDMDOWNLOADS_INDEX_BLPOP}>
    - <{$smarty.const._MD_TDMDOWNLOADS_INDEX_BLRATING}><{$smarty.const._MD_TDMDOWNLOADS_INDEX_BLRATING}> + <{$smarty.const._MD_TDMDOWNLOADS_INDEX_BLRATING}><{$smarty.const._MD_TDMDOWNLOADS_INDEX_BLRATING}>
      <{foreach item=bl_rating from=$bl_rating}>
    • - <{$bl_rating.title}> + <{$bl_rating.title}> (<{$bl_rating.rating}>)
    • <{/foreach}> @@ -115,7 +115,7 @@ <{if $show_latest_files}> - <{if $file != ""}> + <{if $file|default:'' != ''}>
      <{$smarty.const._MD_TDMDOWNLOADS_INDEX_LATESTLIST}>
      diff --git a/templates/tdmdownloads_liste.tpl b/templates/tdmdownloads_liste.tpl index 4d09807..a960e1f 100644 --- a/templates/tdmdownloads_liste.tpl +++ b/templates/tdmdownloads_liste.tpl @@ -1,7 +1,7 @@
      @@ -23,13 +23,13 @@ <{foreach item=download from=$search_list}>
      <{foreach item=fielddata from=$download.fielddata}> @@ -38,14 +38,14 @@
      - <{$download.title}> + <{$download.title}> <{$download.cat}> - <{$download.cat}> + <{$download.cat}> <{$fielddata}><{$download.rating}> <{$download.hits}> - + <{$smarty.const._MD_TDMDOWNLOADS_SEARCH_DOWNLOAD}><{$download.title}> - + <{$smarty.const._PREVIEW}><{$download.title}> <{if $perm_submit}> - + <{$smarty.const._EDIT}><{$download.title}> <{/if}> @@ -54,9 +54,9 @@ <{/foreach}>
      - <{if $pagenav != ''}> + <{if $pagenav|default:'' != ''}>
      <{$pagenav}>
      <{/if}> -
    \ No newline at end of file + diff --git a/templates/tdmdownloads_modfile.tpl b/templates/tdmdownloads_modfile.tpl index d4bccad..c0dda07 100644 --- a/templates/tdmdownloads_modfile.tpl +++ b/templates/tdmdownloads_modfile.tpl @@ -2,13 +2,13 @@
    <{$navigation}>
    - <{if $message_erreur}> + <{if $message_erreur|default:''}>
    <{$message_erreur}>
    <{/if}> diff --git a/templates/tdmdownloads_ratefile.tpl b/templates/tdmdownloads_ratefile.tpl index 0e02755..292bce3 100644 --- a/templates/tdmdownloads_ratefile.tpl +++ b/templates/tdmdownloads_ratefile.tpl @@ -2,7 +2,7 @@ @@ -18,7 +18,7 @@ - <{if $message_erreur}> + <{if $message_erreur|default:''}>
    <{$message_erreur}>
    <{/if}> diff --git a/templates/tdmdownloads_rss.tpl b/templates/tdmdownloads_rss.tpl index b60ba1c..b5a8beb 100644 --- a/templates/tdmdownloads_rss.tpl +++ b/templates/tdmdownloads_rss.tpl @@ -12,7 +12,7 @@ <{$channel_webmaster}> <{$channel_language}> - <{if $image_url != ""}> + <{if $image_url|default:'' != ''}> <{$channel_title}> <{$image_url}> diff --git a/templates/tdmdownloads_singlefile.tpl b/templates/tdmdownloads_singlefile.tpl index e6be16a..cd1f8f3 100644 --- a/templates/tdmdownloads_singlefile.tpl +++ b/templates/tdmdownloads_singlefile.tpl @@ -2,7 +2,7 @@ @@ -22,7 +22,7 @@
    <{if $show_screenshot === true}> - <{if $logourl != ''}> + <{if $logourl|default:'' != ''}> <{$title}> <{/if}> <{/if}> @@ -34,7 +34,7 @@
    <{$smarty.const._MD_TDMDOWNLOADS_SINGLEFILE_AUTHOR}><{$author}>
    <{$hits}>
    <{$smarty.const._MD_TDMDOWNLOADS_SINGLEFILE_RATING}><{$rating}><{$votes}>
    - <{if $commentsnav != ''}> + <{if $commentsnav|default:'' != ''}>
    <{$nb_comments}>
    <{/if}>
    @@ -46,22 +46,22 @@
    <{/if}> - <{if $perm_download != ""}> + <{if $perm_download|default:'' != ''}>
    <{$smarty.const._MD_TDMDOWNLOADS_INDEX_DLNOW}> @@ -100,13 +100,13 @@
  • @@ -124,45 +124,45 @@
    <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_ME}>
    - <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_BLINKLIST}> - <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_DELICIOUS}> - <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_DIGG}> + <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_BLINKLIST}> + <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_DELICIOUS}> + <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_DIGG}> <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_FARK}> - <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_FURL}> - <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_NEWSVINE}> - <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_REDDIT}> - <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_YAHOO}> - <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_BALATARIN}> - <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_FACEBOOK}> - <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_TWITTER}> - <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_SCRIPSTYLE}> - <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_STUMBLE}> - <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_TECHNORATI}> - <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_MIXX}> - <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_MYSPACE}> - <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_DESIGNFLOAT}> - <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_GOOGLEPLUS}> - <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_GOOGLEBOOKMARKS}> + href="http://cgi.fark.com/cgi/fark/edit.pl?new_url=<{$mod_url}>/singlefile.php?lid=<{$lid}>&new_comment=<{$downloads.title}>&new_link_other=<{$downloads.title}>&linktype=Misc"><{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_FARK}> + <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_FURL}> + <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_NEWSVINE}> + <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_REDDIT}> + <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_YAHOO}> + <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_BALATARIN}> + <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_FACEBOOK}> + <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_TWITTER}> + <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_SCRIPSTYLE}> + <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_STUMBLE}> + <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_TECHNORATI}> + <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_MIXX}> + <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_MYSPACE}> + <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_DESIGNFLOAT}> + <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_GOOGLEPLUS}> + <{$smarty.const._MD_TDMDOWNLOADS_BOOKMARK_TO_GOOGLEBOOKMARKS}>
    <{/if}> @@ -172,11 +172,11 @@ <{$lang_notice}>
  • - <{if $comment_mode == "flat"}> - <{include file="db:system_comments_flat.tpl"}> - <{elseif $comment_mode == "thread"}> - <{include file="db:system_comments_thread.tpl"}> - <{elseif $comment_mode == "nest"}> + <{if $comment_mode|default:'' == "flat"}> + <{include file="db:system_comments_flat.tpl"}> + <{elseif $comment_mode|default:'' == "thread"}> + <{include file="db:system_comments_thread.tpl"}> + <{elseif $comment_mode|default:'' == "nest"}> <{include file="db:system_comments_nest.tpl"}> <{/if}>
    diff --git a/templates/tdmdownloads_submit.tpl b/templates/tdmdownloads_submit.tpl index ec9a486..9d64e41 100644 --- a/templates/tdmdownloads_submit.tpl +++ b/templates/tdmdownloads_submit.tpl @@ -2,7 +2,7 @@ @@ -18,7 +18,7 @@
    - <{if $message_erreur}> + <{if $message_erreur|default:''}>
    <{$message_erreur}>
    <{/if}> diff --git a/templates/tdmdownloads_trigger_uploads.tpl b/templates/tdmdownloads_trigger_uploads.tpl new file mode 100644 index 0000000..be4ebe2 --- /dev/null +++ b/templates/tdmdownloads_trigger_uploads.tpl @@ -0,0 +1,70 @@ + + diff --git a/templates/tdmdownloads_upload.tpl b/templates/tdmdownloads_upload.tpl new file mode 100644 index 0000000..017b28d --- /dev/null +++ b/templates/tdmdownloads_upload.tpl @@ -0,0 +1,113 @@ +<{include file='db:tdmdownloads_header.tpl'}> + +<{if $form}> + <{$form}> +<{/if}> + +<{if $multiupload}> +
     
    + <{include file="db:tdmdownloads_trigger_uploads.tpl"}> +

    <{$categoryname}>

    +
    +
    <{$smarty.const._IMGMAXSIZE}> <{$file_maxsize}>
    +
    <{$smarty.const._IMGMAXWIDTH}> <{$img_maxwidth}>
    +
    <{$smarty.const._IMGMAXHEIGHT}> <{$img_maxheight}>
    + + +<{/if}> +
     
    + + + +<{include file='db:tdmdownloads_footer.tpl'}> diff --git a/templates/tdmdownloads_viewcat.tpl b/templates/tdmdownloads_viewcat.tpl index a8fbc35..c8b9e4e 100644 --- a/templates/tdmdownloads_viewcat.tpl +++ b/templates/tdmdownloads_viewcat.tpl @@ -2,13 +2,13 @@
    <{$category_path}>
    - <{if $cat_description != ""}> + <{if $cat_description|default:'' != ''}>
    <{$cat_description}>
    <{/if}> @@ -21,18 +21,18 @@
    - <{if $category.image != ""}> - <{$category.title}> + <{if $category.image|default:'' != ''}> + <{$category.title}> <{/if}> <{$category.description_main}>
    - <{if $category.subcategories != ""}> + <{if $category.subcategories|default:'' != ''}>
    <{$smarty.const._MD_TDMDOWNLOADS_INDEX_SCAT}>
      <{$category.subcategories}>
    @@ -51,7 +51,7 @@
    - <{$smarty.const._MD_TDMDOWNLOADS_RSS}> + <{$smarty.const._MD_TDMDOWNLOADS_RSS}>
    <{if $bl_affichage==1}> @@ -59,43 +59,43 @@
    <{$smarty.const._MD_TDMDOWNLOADS_INDEX_BLNAME}>
    - <{if $bl_date != ""}> + <{if $bl_date|default:'' != ''}> <{/if}> - <{if $bl_pop != ""}> + <{if $bl_pop|default:'' != ''}> <{/if}> - <{if $bl_rating != ""}> + <{if $bl_rating|default:'' != ''}>
    - <{$smarty.const._MD_TDMDOWNLOADS_INDEX_BLDATE}><{$smarty.const._MD_TDMDOWNLOADS_INDEX_BLDATE}> + <{$smarty.const._MD_TDMDOWNLOADS_INDEX_BLDATE}><{$smarty.const._MD_TDMDOWNLOADS_INDEX_BLDATE}>
    - <{$smarty.const._MD_TDMDOWNLOADS_INDEX_BLPOP}><{$smarty.const._MD_TDMDOWNLOADS_INDEX_BLPOP}> + <{$smarty.const._MD_TDMDOWNLOADS_INDEX_BLPOP}><{$smarty.const._MD_TDMDOWNLOADS_INDEX_BLPOP}>
    - <{$smarty.const._MD_TDMDOWNLOADS_INDEX_BLRATING}><{$smarty.const._MD_TDMDOWNLOADS_INDEX_BLRATING}> + <{$smarty.const._MD_TDMDOWNLOADS_INDEX_BLRATING}><{$smarty.const._MD_TDMDOWNLOADS_INDEX_BLRATING}>
    @@ -134,38 +134,38 @@ <{$smarty.const._MD_TDMDOWNLOADS_CAT_SORTBY}> <{$smarty.const._MD_TDMDOWNLOADS_CAT_TITLE}> ( - - <{$smarty.const._MD_TDMDOWNLOADS_CAT_TITLEATOZ}> + + <{$smarty.const._MD_TDMDOWNLOADS_CAT_TITLEATOZ}> - - <{$smarty.const._MD_TDMDOWNLOADS_CAT_TITLEZTOA}> + + <{$smarty.const._MD_TDMDOWNLOADS_CAT_TITLEZTOA}> ) <{$smarty.const._MD_TDMDOWNLOADS_CAT_DATE}>( - - <{$smarty.const._MD_TDMDOWNLOADS_CAT_DATEOLD}> + + <{$smarty.const._MD_TDMDOWNLOADS_CAT_DATEOLD}> - - <{$smarty.const._MD_TDMDOWNLOADS_CAT_DATENEW}> + + <{$smarty.const._MD_TDMDOWNLOADS_CAT_DATENEW}> ) <{$smarty.const._MD_TDMDOWNLOADS_CAT_RATING}>( - - <{$smarty.const._MD_TDMDOWNLOADS_CAT_RATINGLTOH}> + + <{$smarty.const._MD_TDMDOWNLOADS_CAT_RATINGLTOH}> - - <{$smarty.const._MD_TDMDOWNLOADS_CAT_RATINGHTOL}> + + <{$smarty.const._MD_TDMDOWNLOADS_CAT_RATINGHTOL}> ) <{$smarty.const._MD_TDMDOWNLOADS_CAT_POPULARITY}>( - - <{$smarty.const._MD_TDMDOWNLOADS_CAT_POPULARITYLTOM}> + + <{$smarty.const._MD_TDMDOWNLOADS_CAT_POPULARITYLTOM}> - - <{$smarty.const._MD_TDMDOWNLOADS_CAT_POPULARITYMTOL}> + + <{$smarty.const._MD_TDMDOWNLOADS_CAT_POPULARITYMTOL}> ) @@ -174,7 +174,7 @@ <{/if}> - <{if $file != ""}> + <{if $file|default:'' != ''}>
    <{$smarty.const._MD_TDMDOWNLOADS_CAT_LIST}>
    @@ -192,7 +192,7 @@
    - <{if $pagenav != ''}> + <{if $pagenav|default:'' != ''}>
    <{$pagenav}>
    <{/if}> diff --git a/testdata/english/group_permission.yml b/testdata/english/group_permission.yml new file mode 100644 index 0000000..b7924c6 --- /dev/null +++ b/testdata/english/group_permission.yml @@ -0,0 +1,115 @@ +- + gperm_groupid: '2' + gperm_itemid: '32' + gperm_modid: '1831' + gperm_name: tdmdownloads_ac +- + gperm_groupid: '2' + gperm_itemid: '16' + gperm_modid: '1831' + gperm_name: tdmdownloads_ac +- + gperm_groupid: '2' + gperm_itemid: '8' + gperm_modid: '1831' + gperm_name: tdmdownloads_ac +- + gperm_groupid: '2' + gperm_itemid: '4' + gperm_modid: '1831' + gperm_name: tdmdownloads_ac +- + gperm_groupid: '1' + gperm_itemid: '64' + gperm_modid: '1831' + gperm_name: tdmdownloads_ac +- + gperm_groupid: '1' + gperm_itemid: '32' + gperm_modid: '1831' + gperm_name: tdmdownloads_ac +- + gperm_groupid: '1' + gperm_itemid: '16' + gperm_modid: '1831' + gperm_name: tdmdownloads_ac +- + gperm_groupid: '1' + gperm_itemid: '8' + gperm_modid: '1831' + gperm_name: tdmdownloads_ac +- + gperm_groupid: '1' + gperm_itemid: '4' + gperm_modid: '1831' + gperm_name: tdmdownloads_ac +- + gperm_groupid: '2' + gperm_itemid: '2' + gperm_modid: '1831' + gperm_name: tdmdownloads_download +- + gperm_groupid: '2' + gperm_itemid: '1' + gperm_modid: '1831' + gperm_name: tdmdownloads_download +- + gperm_groupid: '1' + gperm_itemid: '2' + gperm_modid: '1831' + gperm_name: tdmdownloads_download +- + gperm_groupid: '1' + gperm_itemid: '1' + gperm_modid: '1831' + gperm_name: tdmdownloads_download +- + gperm_groupid: '2' + gperm_itemid: '2' + gperm_modid: '1831' + gperm_name: tdmdownloads_submit +- + gperm_groupid: '2' + gperm_itemid: '1' + gperm_modid: '1831' + gperm_name: tdmdownloads_submit +- + gperm_groupid: '1' + gperm_itemid: '2' + gperm_modid: '1831' + gperm_name: tdmdownloads_submit +- + gperm_groupid: '1' + gperm_itemid: '1' + gperm_modid: '1831' + gperm_name: tdmdownloads_submit +- + gperm_groupid: '3' + gperm_itemid: '2' + gperm_modid: '1831' + gperm_name: tdmdownloads_view +- + gperm_groupid: '3' + gperm_itemid: '1' + gperm_modid: '1831' + gperm_name: tdmdownloads_view +- + gperm_groupid: '2' + gperm_itemid: '2' + gperm_modid: '1831' + gperm_name: tdmdownloads_view +- + gperm_groupid: '2' + gperm_itemid: '1' + gperm_modid: '1831' + gperm_name: tdmdownloads_view +- + gperm_groupid: '1' + gperm_itemid: '2' + gperm_modid: '1831' + gperm_name: tdmdownloads_view +- + gperm_groupid: '1' + gperm_itemid: '1' + gperm_modid: '1831' + gperm_name: tdmdownloads_view diff --git a/testdata/english/index.php b/testdata/english/index.php new file mode 100644 index 0000000..4ae18fd --- /dev/null +++ b/testdata/english/index.php @@ -0,0 +1,2 @@ +history.go(-1); diff --git a/testdata/images/index.php b/testdata/images/index.php new file mode 100644 index 0000000..2ea9b7d --- /dev/null +++ b/testdata/images/index.php @@ -0,0 +1,3 @@ +history.go(-1); diff --git a/testdata/index.php b/testdata/index.php index a1d533a..4149986 100644 --- a/testdata/index.php +++ b/testdata/index.php @@ -1,4 +1,5 @@ -loadLanguage('common'); switch ($op) { case 'load': - loadSampleData(); + if (Request::hasVar('ok', 'REQUEST') && 1 === Request::getInt('ok', 0)) { + if (!$GLOBALS['xoopsSecurity']->check()) { + \redirect_header($helper->url('admin/index.php'), 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); + } + loadSampleData(); + } else { + xoops_cp_header(); + xoops_confirm(['ok' => 1, 'op' => 'load'], 'index.php', \sprintf(\constant('CO_' . $moduleDirNameUpper . '_' . 'LOAD_SAMPLEDATA_CONFIRM')), \constant('CO_' . $moduleDirNameUpper . '_' . 'CONFIRM'), true); + xoops_cp_footer(); + } break; case 'save': saveSampleData(); break; + case 'clear': + clearSampleData(); + break; } // XMF TableLoad for SAMPLE data function loadSampleData() { - $moduleDirName = basename(dirname(__DIR__)); - $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName - $helper = Tdmdownloads\Helper::getInstance(); - $utility = new Tdmdownloads\Utility(); - $configurator = new Common\Configurator(); - // Load language files - $helper->loadLanguage('admin'); - $helper->loadLanguage('modinfo'); - $helper->loadLanguage('common'); + global $xoopsConfig; + $moduleDirName = \basename(\dirname(__DIR__)); + $moduleDirNameUpper = \mb_strtoupper($moduleDirName); - // $items = \Xmf\Yaml::readWrapped('quotes_data.yml'); - // \Xmf\Database\TableLoad::truncateTable($moduleDirName . '_quotes'); - // \Xmf\Database\TableLoad::loadTableFromArray($moduleDirName . '_quotes', $items); + $utility = new Utility(); + $configurator = new Configurator(); $tables = \Xmf\Module\Helper::getHelper($moduleDirName)->getModule()->getInfo('tables'); + $language = 'english/'; + if (\is_dir(__DIR__ . '/' . $xoopsConfig['language'])) { + $language = $xoopsConfig['language'] . '/'; + } + + // load module tables foreach ($tables as $table) { - $tabledata = \Xmf\Yaml::readWrapped($table . '.yml'); - \Xmf\Database\TableLoad::truncateTable($table); - \Xmf\Database\TableLoad::loadTableFromArray($table, $tabledata); + $tabledata = Yaml::readWrapped($language . $table . '.yml'); + TableLoad::truncateTable($table); + TableLoad::loadTableFromArray($table, $tabledata); } + // load permissions + $table = 'group_permission'; + $tabledata = Yaml::readWrapped($language . $table . '.yml'); + $mid = \Xmf\Module\Helper::getHelper($moduleDirName)->getModule()->getVar('mid'); + loadTableFromArrayWithReplace($table, $tabledata, 'gperm_modid', $mid); + // --- COPY test folder files --------------- - if (is_array($configurator->copyTestFolders) && count($configurator->copyTestFolders) > 0) { + if (\is_array($configurator->copyTestFolders) && \count($configurator->copyTestFolders) > 0) { // $file = dirname(__DIR__) . '/testdata/images/'; - foreach (array_keys($configurator->copyTestFolders) as $i) { - $src = $configurator->copyTestFolders[$i][0]; + foreach (\array_keys($configurator->copyTestFolders) as $i) { + $src = $configurator->copyTestFolders[$i][0]; $dest = $configurator->copyTestFolders[$i][1]; $utility::rcopy($src, $dest); } } - - redirect_header('../admin/index.php', 1, constant('CO_' . $moduleDirNameUpper . '_' . 'SAMPLEDATA_SUCCESS')); + \redirect_header('../admin/index.php', 1, \constant('CO_' . $moduleDirNameUpper . '_' . 'LOAD_SAMPLEDATA_SUCCESS')); } function saveSampleData() { - $moduleDirName = basename(dirname(__DIR__)); - $moduleDirNameUpper = mb_strtoupper($moduleDirName); - - $tables = \Xmf\Module\Helper::getHelper($moduleDirName)->getModule()->getInfo('tables'); + global $xoopsConfig; + $moduleDirName = \basename(\dirname(__DIR__)); + $moduleDirNameUpper = \mb_strtoupper($moduleDirName); + $helper = Helper::getInstance(); + $tables = $helper->getModule()->getInfo('tables'); + + $languageFolder = __DIR__ . '/' . $xoopsConfig['language']; + if (!\file_exists($languageFolder . '/')) { + Utility::createFolder($languageFolder . '/'); + } + $exportFolder = $languageFolder . '/Exports-' . date('Y-m-d-H-i-s') . '/'; + Utility::createFolder($exportFolder); + // save module tables foreach ($tables as $table) { - \Xmf\Database\TableLoad::saveTableToYamlFile($table, $table . '_' . date('Y-m-d H-i-s') . '.yml'); + TableLoad::saveTableToYamlFile($table, $exportFolder . $table . '.yml'); } - redirect_header('../admin/index.php', 1, constant('CO_' . $moduleDirNameUpper . '_' . 'SAMPLEDATA_SUCCESS')); + // save permissions + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('gperm_modid', $helper->getModule()->getVar('mid'))); + $skipColumns[] = 'gperm_id'; + TableLoad::saveTableToYamlFile('group_permission', $exportFolder . 'group_permission.yml', $criteria, $skipColumns); + unset($criteria); + + \redirect_header('../admin/index.php', 1, \constant('CO_' . $moduleDirNameUpper . '_' . 'SAVE_SAMPLEDATA_SUCCESS')); } function exportSchema() { + $moduleDirName = \basename(\dirname(__DIR__)); + $moduleDirNameUpper = \mb_strtoupper($moduleDirName); + try { - $moduleDirName = basename(dirname(__DIR__)); - $moduleDirNameUpper = mb_strtoupper($moduleDirName); + // TODO set exportSchema + // $migrate = new Migrate($moduleDirName); + // $migrate->saveCurrentSchema(); + // + // redirect_header('../admin/index.php', 1, constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA_SUCCESS')); + } catch (\Throwable $e) { + exit(constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA_ERROR')); + } +} - $migrate = new \Xmf\Database\Migrate($moduleDirName); - $migrate->saveCurrentSchema(); +/** + * loadTableFromArrayWithReplace + * + * @param string $table value with should be used insead of original value of $search + * + * @param array $data array of rows to insert + * Each element of the outer array represents a single table row. + * Each row is an associative array in 'column' => 'value' format. + * @param string $search name of column for which the value should be replaced + * @param $replace + * @return int number of rows inserted + */ +function loadTableFromArrayWithReplace($table, $data, $search, $replace) +{ + /** @var \XoopsMySQLDatabase $db */ + $db = \XoopsDatabaseFactory::getDatabaseConnection(); + + $prefixedTable = $db->prefix($table); + $count = 0; + + $sql = 'DELETE FROM ' . $prefixedTable . ' WHERE `' . $search . '`=' . $db->quote($replace); + + $result = $db->queryF($sql); + + if ($result) { + foreach ($data as $row) { + $insertInto = 'INSERT INTO ' . $prefixedTable . ' ('; + $valueClause = ' VALUES ('; + $first = true; + foreach ($row as $column => $value) { + if ($first) { + $first = false; + } else { + $insertInto .= ', '; + $valueClause .= ', '; + } + + $insertInto .= $column; + if ($search === $column) { + $valueClause .= $db->quote($replace); + } else { + $valueClause .= $db->quote($value); + } + } + + $sql = $insertInto . ') ' . $valueClause . ')'; + + $result = $db->queryF($sql); + if (false !== $result) { + ++$count; + } + } + } + return $count; +} - redirect_header('../admin/index.php', 1, constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA_SUCCESS')); - } catch (\Exception $e) { - exit(constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA_ERROR')); +function clearSampleData() +{ + $moduleDirName = \basename(\dirname(__DIR__)); + $moduleDirNameUpper = \mb_strtoupper($moduleDirName); + $helper = Helper::getInstance(); + // Load language files + $helper->loadLanguage('common'); + $tables = $helper->getModule()->getInfo('tables'); + // truncate module tables + foreach ($tables as $table) { + \Xmf\Database\TableLoad::truncateTable($table); } + redirect_header($helper->url('admin/index.php'), 1, constant('CO_' . $moduleDirNameUpper . '_' . 'CLEAR_SAMPLEDATA_OK')); } diff --git a/testdata/uploads/blank.png b/testdata/uploads/blank.png new file mode 100644 index 0000000..e1ee728 Binary files /dev/null and b/testdata/uploads/blank.png differ diff --git a/testdata/uploads/category/blank.png b/testdata/uploads/category/blank.png new file mode 100644 index 0000000..e1ee728 Binary files /dev/null and b/testdata/uploads/category/blank.png differ diff --git a/testdata/uploads/category/index.php b/testdata/uploads/category/index.php new file mode 100644 index 0000000..4ae18fd --- /dev/null +++ b/testdata/uploads/category/index.php @@ -0,0 +1,2 @@ +history.go(-1); \ No newline at end of file diff --git a/testdata/uploads/index.php b/testdata/uploads/index.php new file mode 100644 index 0000000..2ea9b7d --- /dev/null +++ b/testdata/uploads/index.php @@ -0,0 +1,3 @@ +history.go(-1); diff --git a/tests/index.php b/tests/index.php new file mode 100644 index 0000000..2ea9b7d --- /dev/null +++ b/tests/index.php @@ -0,0 +1,3 @@ + - Website: + */ + +use Xmf\Jwt\TokenFactory; +use Xmf\Module\Admin; +use Xmf\Request; +use XoopsModules\Tdmdownloads\{ + CategoryHandler, + Form\UploadForm +}; +/** @var \Xmf\Module\Helper\Permission $permHelper */ + +require_once __DIR__ . '/header.php'; + +$moduleDirName = basename(__DIR__); +$moduleDirNameUpper = \mb_strtoupper($moduleDirName); + +// It recovered the value of argument op in URL$ +$op = Request::getString('op', 'form'); +$catId = Request::getInt('cat_cid', 0); +// Template +$GLOBALS['xoopsOption']['template_main'] = $moduleDirName . '_upload.tpl'; +require_once XOOPS_ROOT_PATH . '/header.php'; + +$pathIcon16 = Admin::iconUrl('', '16'); +$GLOBALS['xoopsTpl']->assign('pathIcon16', $pathIcon16); + +$categoryHandler = new CategoryHandler(); + +// Form Create +if (isset($catId)) { + $categoryObj = $categoryHandler->get($catId); +} else { + $categoryObj = $categoryHandler->create(); +} + +$catId = 1; //for testing, comment out later +$xoopsTpl->assign('multiupload', true); + +$form = new UploadForm($categoryObj); +$form->setExtra('enctype="multipart/form-data"'); +$GLOBALS['xoopsTpl']->assign('form', $form->render()); + +$permHelper->checkPermissionRedirect('tdmdownloads_submit', $catId, 'index.php', 3, 'You are not allowed to submit a file', false); +$permissionUpload = $permHelper->checkPermission('tdmdownloads_submit', $catId, false); +if ($permissionUpload) { + if ($catId > 0) { + $GLOBALS['xoopsTpl']->assign('catId', $catId); + + $categoryObj = $categoryHandler->get($catId); + + // get config for file type/extenstion + + $fileextions = $helper->getConfig('mimetypes'); + + $mimetypes = []; + + foreach ($fileextions as $fe) { + switch ($fe) { + case 'jpg': + case 'jpeg': + case 'jpe': + $mimetypes['image/jpeg'] = 'image/jpeg'; + break; + case 'gif': + $mimetypes['image/gif'] = 'image/gif'; + break; + case 'png': + $mimetypes['image/png'] = 'image/png'; + break; + case 'bmp': + $mimetypes['image/bmp'] = 'image/bmp'; + break; + case 'tiff': + case 'tif': + $mimetypes['image/tiff'] = 'image/tiff'; + break; + case 'zip': + $mimetypes['application/zip'] = 'application/zip'; + break; + case 'else': + default: + break; + } + } + + $allowedfileext = implode("', '", $fileextions); + + if ('' !== $allowedfileext) { + $allowedfileext = "'" . $allowedfileext . "'"; + } + + $allowedmimetypes = implode("', '", $mimetypes); + + if ('' !== $allowedmimetypes) { + $allowedmimetypes = "'" . $allowedmimetypes . "'"; + } + + // Define Stylesheet + + /** @var xos_opal_Theme $xoTheme */ + + $xoTheme->addStylesheet(XOOPS_URL . '/media/fine-uploader/fine-uploader-new.css'); + + $xoTheme->addStylesheet(XOOPS_URL . '/media/fine-uploader/ManuallyTriggerUploads.css'); + + $xoTheme->addStylesheet(XOOPS_URL . '/media/font-awesome/css/font-awesome.min.css'); + + $xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/admin.css'); + + // Define scripts + + $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js'); + + $xoTheme->addScript('modules/system/js/admin.js'); + + $xoTheme->addScript('media/fine-uploader/fine-uploader.js'); + + // Define Breadcrumb and tips + + $xoopsTpl->assign('multiupload', true); + + // echo $helper->getConfig('mimetypes'); + + $xoopsTpl->assign('file_maxsize', $helper->getConfig('maxuploadsize')); + + $xoopsTpl->assign('img_maxwidth', $helper->getConfig('imageWidth')); + + $xoopsTpl->assign('img_maxheight', $helper->getConfig('imageHeight')); + + $xoopsTpl->assign('categoryname', $categoryObj->getVar('cat_title')); + + $xoopsTpl->assign('allowedfileext', $categoryObj->getVar('allowedfileext')); + + $xoopsTpl->assign('allowedmimetypes', $categoryObj->getVar('allowedmimetypes')); + + $payload = [ + 'aud' => 'ajaxfineupload.php', + 'cat' => $catId, + 'uid' => $xoopsUser instanceof \XoopsUser ? $xoopsUser->id() : 0, + 'handler' => '\XoopsModules\\' . ucfirst($moduleDirName) . '\Common\FineimpuploadHandler', + 'moddir' => $moduleDirName, + ]; + + $jwt = TokenFactory::build('fineuploader', $payload, 60 * 30); // token good for 30 minutes + + $xoopsTpl->assign('jwt', $jwt); + + setcookie('jwt', $jwt); + + $fineup_debug = 'false'; + + if (($xoopsUser instanceof \XoopsUser ? $xoopsUser->isAdmin() : false) + && isset($_REQUEST['FINEUPLOADER_DEBUG'])) { + $fineup_debug = 'true'; + } + + $xoopsTpl->assign('fineup_debug', $fineup_debug); + } +} + +// Breadcrumbs +$xoBreadcrumbs[] = ['title' => constant('CO_' . $moduleDirNameUpper . '_IMAGES_UPLOAD')]; +//require __DIR__ . '/footer.php'; +require_once XOOPS_ROOT_PATH . '/footer.php'; diff --git a/view.tag.php b/view.tag.php index 56abb33..239bf08 100644 --- a/view.tag.php +++ b/view.tag.php @@ -1,4 +1,5 @@ -setOrder('ASC'); $criteria->add(new \Criteria('cat_cid', '(' . implode(',', $categories) . ')', 'IN')); $downloadscatArray = $categoryHandler->getAll($criteria); -$mytree = new \XoopsModules\Tdmdownloads\Tree($downloadscatArray, 'cat_cid', 'cat_pid'); +$mytree = new Tree($downloadscatArray, 'cat_cid', 'cat_pid'); //tableau des téléchargements $criteria = new \CriteriaCompo(); @@ -56,16 +63,16 @@ $xoopsTpl->assign('lang_thereare', sprintf(_MD_TDMDOWNLOADS_INDEX_THEREARE, count($downloadsArray))); //navigation -$navCategory = $utility->getPathTreeUrl($mytree, $cid, $downloadscatArray, 'cat_title', $prefix = ' arrow ', true, 'ASC'); +$navCategory = $utility::getPathTreeUrl($mytree, $cid, $downloadscatArray, 'cat_title', $prefix = ' arrow ', true, 'ASC'); $xoopsTpl->assign('category_path', $navCategory); // info catégorie $xoopsTpl->assign('category_id', $cid); $cat_info = $categoryHandler->get($cid); $xoopsTpl->assign('cat_description', $cat_info->getVar('cat_description_main')); -$uploadurl = XOOPS_URL . '/uploads/' . $moduleDirName . '/images/cats/'; +$uploadurl = XOOPS_URL . '/uploads/' . $moduleDirName . '/images/cats/'; $categoryObject = $categoryHandler->get($cid); -$tempCategory = [ +$tempCategory = [ 'image' => $cat_info->getVar('cat_imgurl'), 'id' => $cat_info->getVar('cat_cid'), 'title' => $cat_info->getVar('cat_title'), @@ -82,32 +89,49 @@ $keywords = ''; foreach (array_keys($downloadscatArray) as $i) { /** @var \XoopsModules\Tdmdownloads\Category[] $downloadscatArray */ + if ($downloadscatArray[$i]->getVar('cat_pid') == $cid) { - $totaldownloads = $utility->getNumbersOfEntries($mytree, $categories, $downloadsArray, $downloadscatArray[$i]->getVar('cat_cid')); + $totaldownloads = $utility->getNumbersOfEntries($mytree, $categories, $downloadsArray, $downloadscatArray[$i]->getVar('cat_cid')); + $subcategories_arr = $mytree->getFirstChild($downloadscatArray[$i]->getVar('cat_cid')); - $chcount = 0; - $subcategories = ''; + + $chcount = 0; + + $subcategories = ''; + //pour les mots clef + $keywords .= $downloadscatArray[$i]->getVar('cat_title') . ','; + foreach (array_keys($subcategories_arr) as $j) { /** @var \XoopsModules\Tdmdownloads\Category[] $subcategories_arr */ + if ($chcount >= $helper->getConfig('nbsouscat')) { $subcategories .= '
  • [+]
  • '; + break; } + $subcategories .= '
  • ' . $subcategories_arr[$j]->getVar('cat_title') . '
  • '; - $keywords .= $downloadscatArray[$i]->getVar('cat_title') . ','; + + $keywords .= $downloadscatArray[$i]->getVar('cat_title') . ','; + ++$chcount; } - $xoopsTpl->append('subcategories', [ - 'image' => $uploadurl . $downloadscatArray[$i]->getVar('cat_imgurl'), - 'id' => $downloadscatArray[$i]->getVar('cat_cid'), - 'title' => $downloadscatArray[$i]->getVar('cat_title'), - 'description_main' => $downloadscatArray[$i]->getVar('cat_description_main'), - 'infercategories' => $subcategories, - 'totaldownloads' => $totaldownloads, - 'count' => $count, - ]); + + $xoopsTpl->append( + 'subcategories', + [ + 'image' => $uploadurl . $downloadscatArray[$i]->getVar('cat_imgurl'), + 'id' => $downloadscatArray[$i]->getVar('cat_cid'), + 'title' => $downloadscatArray[$i]->getVar('cat_title'), + 'description_main' => $downloadscatArray[$i]->getVar('cat_description_main'), + 'infercategories' => $subcategories, + 'totaldownloads' => $totaldownloads, + 'count' => $count, + ] + ); + ++$count; } } @@ -117,73 +141,115 @@ //téléchargements récents if (1 == $helper->getConfig('bldate')) { $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('status', 0, '!=')); + $criteria->add(new \Criteria('cid', '(' . implode(',', $categories) . ')', 'IN')); + $criteria->add(new \Criteria('cid', \Xmf\Request::getInt('cid', 0, 'REQUEST'))); + $criteria->setSort('date'); + $criteria->setOrder('DESC'); + $criteria->setLimit($helper->getConfig('nbbl')); + $downloadsArray = $downloadsHandler->getAll($criteria); + foreach (array_keys($downloadsArray) as $i) { /** @var \XoopsModules\Tdmdownloads\Downloads[] $downloadsArray */ + $title = $downloadsArray[$i]->getVar('title'); + if (mb_strlen($title) >= $helper->getConfig('longbl')) { $title = mb_substr($title, 0, $helper->getConfig('longbl')) . '...'; } + $date = formatTimestamp($downloadsArray[$i]->getVar('date'), 's'); - $xoopsTpl->append('bl_date', [ - 'id' => $downloadsArray[$i]->getVar('lid'), - 'cid' => $downloadsArray[$i]->getVar('cid'), - 'date' => $date, - 'title' => $title, - ]); + + $xoopsTpl->append( + 'bl_date', + [ + 'id' => $downloadsArray[$i]->getVar('lid'), + 'cid' => $downloadsArray[$i]->getVar('cid'), + 'date' => $date, + 'title' => $title, + ] + ); } } //plus téléchargés if (1 == $helper->getConfig('blpop')) { $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('status', 0, '!=')); + $criteria->add(new \Criteria('cid', '(' . implode(',', $categories) . ')', 'IN')); + $criteria->add(new \Criteria('cid', \Xmf\Request::getInt('cid', 0, 'REQUEST'))); + $criteria->setSort('hits'); + $criteria->setOrder('DESC'); + $criteria->setLimit($helper->getConfig('nbbl')); + $downloadsArray = $downloadsHandler->getAll($criteria); + foreach (array_keys($downloadsArray) as $i) { $title = $downloadsArray[$i]->getVar('title'); + if (mb_strlen($title) >= $helper->getConfig('longbl')) { $title = mb_substr($title, 0, $helper->getConfig('longbl')) . '...'; } - $xoopsTpl->append('bl_pop', [ - 'id' => $downloadsArray[$i]->getVar('lid'), - 'cid' => $downloadsArray[$i]->getVar('cid'), - 'hits' => $downloadsArray[$i]->getVar('hits'), - 'title' => $title, - ]); + + $xoopsTpl->append( + 'bl_pop', + [ + 'id' => $downloadsArray[$i]->getVar('lid'), + 'cid' => $downloadsArray[$i]->getVar('cid'), + 'hits' => $downloadsArray[$i]->getVar('hits'), + 'title' => $title, + ] + ); } } //mieux notés if (1 == $helper->getConfig('blrating')) { $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('status', 0, '!=')); + $criteria->add(new \Criteria('cid', '(' . implode(',', $categories) . ')', 'IN')); + $criteria->add(new \Criteria('cid', \Xmf\Request::getInt('cid', 0, 'REQUEST'))); + $criteria->setSort('rating'); + $criteria->setOrder('DESC'); + $criteria->setLimit($helper->getConfig('nbbl')); + $downloadsArray = $downloadsHandler->getAll($criteria); + foreach (array_keys($downloadsArray) as $i) { $title = $downloadsArray[$i]->getVar('title'); + if (mb_strlen($title) >= $helper->getConfig('longbl')) { $title = mb_substr($title, 0, $helper->getConfig('longbl')) . '...'; } - $rating = number_format($downloadsArray[$i]->getVar('rating'), 1); - $xoopsTpl->append('bl_rating', [ - 'id' => $downloadsArray[$i]->getVar('lid'), - 'cid' => $downloadsArray[$i]->getVar('cid'), - 'rating' => $rating, - 'title' => $title, - ]); + + $rating = number_format((float)$downloadsArray[$i]->getVar('rating'), 1); + + $xoopsTpl->append( + 'bl_rating', + [ + 'id' => $downloadsArray[$i]->getVar('lid'), + 'cid' => $downloadsArray[$i]->getVar('cid'), + 'rating' => $rating, + 'title' => $title, + ] + ); } } // affichage du résumé @@ -196,84 +262,126 @@ // affichage des téléchargements if ($helper->getConfig('perpage') > 0) { $xoopsTpl->assign('nb_dowcol', $helper->getConfig('nb_dowcol')); + //Utilisation d'une copie d'écran avec la largeur selon les préférences + if (1 == $helper->getConfig('useshots')) { $xoopsTpl->assign('shotwidth', $helper->getConfig('shotwidth')); + $xoopsTpl->assign('show_screenshot', true); + $xoopsTpl->assign('img_float', $helper->getConfig('img_float')); } + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('status', 0, '!=')); + $criteria->add(new \Criteria('cid', '(' . implode(',', $categories) . ')', 'IN')); + $criteria->add(new \Criteria('cid', \Xmf\Request::getInt('cid', 0, 'REQUEST'))); + $numrows = $downloadsHandler->getCount($criteria); + $xoopsTpl->assign('lang_thereare', sprintf(_MD_TDMDOWNLOADS_CAT_THEREARE, $numrows)); // Pour un affichage sur plusieurs pages + if (\Xmf\Request::hasVar('limit', 'REQUEST')) { $criteria->setLimit(\Xmf\Request::getInt('limit', 0, 'REQUEST')); + $limit = \Xmf\Request::getInt('limit', 0, 'REQUEST'); } else { $criteria->setLimit($helper->getConfig('perpage')); + $limit = $helper->getConfig('perpage'); } + if (\Xmf\Request::hasVar('start', 'REQUEST')) { $criteria->setStart(\Xmf\Request::getInt('start', 0, 'REQUEST')); + $start = \Xmf\Request::getInt('start', 0, 'REQUEST'); } else { $criteria->setStart(0); + $start = 0; } + if (\Xmf\Request::hasVar('sort', 'REQUEST')) { $criteria->setSort(\Xmf\Request::getString('sort', '', 'REQUEST')); + $sort = \Xmf\Request::getString('sort', '', 'REQUEST'); } else { $criteria->setSort('date'); + $sort = 'date'; } + if (\Xmf\Request::hasVar('order', 'REQUEST')) { $criteria->setOrder(\Xmf\Request::getString('order', '', 'REQUEST')); + $order = \Xmf\Request::getString('order', '', 'REQUEST'); } else { $criteria->setOrder('DESC'); + $order = 'DESC'; } $downloadsArray = $downloadsHandler->getAll($criteria); + if ($numrows > $limit) { - require_once XOOPS_ROOT_PATH.'/class/pagenav.php'; + require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; + $pagenav = new \XoopsPageNav($numrows, $limit, $start, 'start', 'limit=' . $limit . '&cid=' . \Xmf\Request::getInt('cid', 0, 'REQUEST') . '&sort=' . $sort . '&order=' . $order); + $pagenav = $pagenav->renderNav(4); } else { $pagenav = ''; } + $xoopsTpl->assign('pagenav', $pagenav); - $summary = ''; - $cpt = 0; + + $summary = ''; + + $cpt = 0; + $categories = $utility->getItemIds('tdmdownloads_download', $moduleDirName); - $item = $utility->getItemIds('tdmdownloads_download_item', $moduleDirName); + + $item = $utility->getItemIds('tdmdownloads_download_item', $moduleDirName); + foreach (array_keys($downloadsArray) as $i) { if ('blank.gif' === $downloadsArray[$i]->getVar('logourl')) { $logourl = ''; } else { $logourl = $downloadsArray[$i]->getVar('logourl'); + $logourl = $uploadurl_shots . $logourl; } - $datetime = formatTimestamp($downloadsArray[$i]->getVar('date'), 's'); - $submitter = \XoopsUser::getUnameFromId($downloadsArray[$i]->getVar('submitter')); + + $datetime = formatTimestamp($downloadsArray[$i]->getVar('date'), 's'); + + $submitter = \XoopsUser::getUnameFromId($downloadsArray[$i]->getVar('submitter')); + $description = $downloadsArray[$i]->getVar('description'); + //permet d'afficher uniquement la description courte + if (false === mb_strpos($description, '[pagebreak]')) { $descriptionShort = $description; } else { $descriptionShort = mb_substr($description, 0, mb_strpos($description, '[pagebreak]')); } + // pour les vignettes "new" et "mis à jour" + $new = $utility->getStatusImage($downloadsArray[$i]->getVar('date'), $downloadsArray[$i]->getVar('status')); + $pop = $utility->getPopularImage($downloadsArray[$i]->getVar('hits')); // Défini si la personne est un admin + $adminlink = ''; + if (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->mid())) { $adminlink = ''; } + //permission de télécharger + $downloadPermission = true; + if (1 === $helper->getConfig('permission_download')) { - if (!in_array($downloadsArray[$i]->getVar('cid'), $categories, true)) { + if (!in_array($downloadsArray[$i]->getVar('cid'), $categories)) { $downloadPermission = false; } } else { - if (!in_array($downloadsArray[$i]->getVar('lid'), $item, true)) { + if (!in_array($downloadsArray[$i]->getVar('lid'), $item)) { $downloadPermission = false; } } + // utilisation du sommaire + ++$cpt; + $summary = $cpt . '- ' . $downloadsArray[$i]->getVar('title') . '
    '; + $xoopsTpl->append('summary', ['title' => $summary, 'count' => $cpt]); - $xoopsTpl->append('file', [ - 'id' => $downloadsArray[$i]->getVar('lid'), - 'cid' => $downloadsArray[$i]->getVar('cid'), - 'title' => $downloadsArray[$i]->getVar('title'), - 'rating' => number_format($downloadsArray[$i]->getVar('rating'), 1), - 'hits' => $downloadsArray[$i]->getVar('hits'), - 'new' => $new, - 'pop' => $pop, - 'logourl' => $logourl, - 'updated' => $datetime, - 'description_short' => $descriptionShort, - 'adminlink' => $adminlink, - 'submitter' => $submitter, - 'perm_download' => $downloadPermission, - 'count' => $cpt, - ]); + $xoopsTpl->append( + 'file', + [ + 'id' => $downloadsArray[$i]->getVar('lid'), + 'cid' => $downloadsArray[$i]->getVar('cid'), + 'title' => $downloadsArray[$i]->getVar('title'), + 'rating' => number_format((float)$downloadsArray[$i]->getVar('rating'), 1), + 'hits' => $downloadsArray[$i]->getVar('hits'), + 'new' => $new, + 'pop' => $pop, + 'logourl' => $logourl, + 'updated' => $datetime, + 'description_short' => $descriptionShort, + 'adminlink' => $adminlink, + 'submitter' => $submitter, + 'perm_download' => $downloadPermission, + 'count' => $cpt, + ] + ); + //pour les mots clef + $keywords .= $downloadsArray[$i]->getVar('title') . ','; } if (0 == $numrows) { $bl_affichage = 0; } + $xoopsTpl->assign('bl_affichage', $bl_affichage); // affichage du sommaire + if ($helper->getConfig('autosummary')) { if (0 == $numrows) { $xoopsTpl->assign('aff_summary', false); @@ -344,40 +466,51 @@ } // sort menu display + if ($numrows > 1) { $xoopsTpl->assign('navigation', true); + $sortorder = $sort . $order; + if ('hitsASC' === $sortorder) { $displaySort = _MD_TDMDOWNLOADS_CAT_POPULARITYLTOM; } + if ('hitsDESC' === $sortorder) { $displaySort = _MD_TDMDOWNLOADS_CAT_POPULARITYMTOL; } + if ('titleASC' === $sortorder) { $displaySort = _MD_TDMDOWNLOADS_CAT_TITLEATOZ; } + if ('titleDESC' === $sortorder) { $displaySort = _MD_TDMDOWNLOADS_CAT_TITLEZTOA; } + if ('dateASC' === $sortorder) { $displaySort = _MD_TDMDOWNLOADS_CAT_DATEOLD; } + if ('dateDESC' === $sortorder) { $displaySort = _MD_TDMDOWNLOADS_CAT_DATENEW; } + if ('ratingASC' === $sortorder) { $displaySort = _MD_TDMDOWNLOADS_CAT_RATINGLTOH; } + if ('ratingDESC' === $sortorder) { $displaySort = _MD_TDMDOWNLOADS_CAT_RATINGHTOL; } + $xoopsTpl->assign('affichage_tri', sprintf(_MD_TDMDOWNLOADS_CAT_CURSORTBY, $displaySort)); } } // référencement // titre de la page -$pagetitle = $utility->getPathTreeUrl($mytree, $cid, $downloadscatArray, 'cat_title', $prefix = ' - ', false, 'DESC'); +$pagetitle = $utility::getPathTreeUrl($mytree, $cid, $downloadscatArray, 'cat_title', $prefix = ' - ', false, 'DESC'); $xoopsTpl->assign('xoops_pagetitle', $pagetitle); //description $xoTheme->addMeta('meta', 'description', strip_tags($downloadscatArray[$cid]->getVar('cat_description_main'))); diff --git a/visit.php b/visit.php index 1b4a23c..09b4169 100644 --- a/visit.php +++ b/visit.php @@ -1,4 +1,5 @@ -getItemIds('tdmdownloads_view', $moduleDirName); -if (!in_array($viewDownloads->getVar('cid'), $categories, true)) { +if (!in_array($viewDownloads->getVar('cid'), $categories)) { redirect_header(XOOPS_URL, 2, _NOPERM); } //redirection si pas de permission (télécharger) if (2 == $helper->getConfig('permission_download')) { $item = $utility->getItemIds('tdmdownloads_download_item', $moduleDirName); - if (!in_array($viewDownloads->getVar('lid'), $item, true)) { + + if (!in_array($viewDownloads->getVar('lid'), $item)) { redirect_header('singlefile.php?lid=' . $viewDownloads->getVar('lid'), 2, _MD_TDMDOWNLOADS_SINGLEFILE_NOPERMDOWNLOAD); } } else { $categories = $utility->getItemIds('tdmdownloads_download', $moduleDirName); - if (!in_array($viewDownloads->getVar('cid'), $categories, true)) { + + if (!in_array($viewDownloads->getVar('cid'), $categories)) { redirect_header('singlefile.php?lid=' . $viewDownloads->getVar('lid'), 2, _MD_TDMDOWNLOADS_SINGLEFILE_NOPERMDOWNLOAD); } } //check download limit option if (1 == $helper->getConfig('downlimit')) { - $limitlid = $helper->getConfig('limitlid'); + $limitlid = $helper->getConfig('limitlid'); + $limitglobal = $helper->getConfig('limitglobal'); - $yesterday = strtotime(formatTimestamp(time() - 86400)); + + $yesterday = strtotime(formatTimestamp(time() - 86400)); + if ($limitlid > 0) { $criteria = new \CriteriaCompo(); + if ($xoopsUser) { $criteria->add(new \Criteria('downlimit_uid', $xoopsUser->getVar('uid'), '=')); } else { $criteria->add(new \Criteria('downlimit_hostname', getenv('REMOTE_ADDR'), '=')); } + $criteria->add(new \Criteria('downlimit_lid', $lid, '=')); + $criteria->add(new \Criteria('downlimit_date', $yesterday, '>')); + $numrows = $downlimitHandler->getCount($criteria); + if ($numrows >= $limitlid) { redirect_header('singlefile.php?lid=' . $viewDownloads->getVar('lid'), 5, sprintf(_MD_TDMDOWNLOADS_SINGLEFILE_LIMITLID, $numrows, $limitlid)); } } + if ($limitglobal > 0) { $criteria = new \CriteriaCompo(); + if ($xoopsUser) { $criteria->add(new \Criteria('downlimit_uid', $xoopsUser->getVar('uid'), '=')); } else { $criteria->add(new \Criteria('downlimit_hostname', getenv('REMOTE_ADDR'), '=')); } + $criteria->add(new \Criteria('downlimit_date', $yesterday, '>')); + $numrows = $downlimitHandler->getCount($criteria); + if ($numrows >= $limitglobal) { redirect_header('singlefile.php?lid=' . $viewDownloads->getVar('lid'), 5, sprintf(_MD_TDMDOWNLOADS_SINGLEFILE_LIMITGLOBAL, $numrows, $limitglobal)); } } /** @var \XoopsModules\Tdmdownloads\Downlimit $obj */ + $obj = $downlimitHandler->create(); + $obj->setVar('downlimit_lid', $lid); + $obj->setVar('downlimit_uid', !empty($xoopsUser) ? $xoopsUser->getVar('uid') : 0); + $obj->setVar('downlimit_hostname', getenv('REMOTE_ADDR')); + $obj->setVar('downlimit_date', strtotime(formatTimestamp(time()))); + $downlimitHandler->insert($obj) || $obj->getHtmlErrors(); + // purge + $criteria = new \CriteriaCompo(); + $criteria->add(new \Criteria('downlimit_date', time() - 172800, '<')); + $numrows = $downlimitHandler->getCount($criteria); + echo 'a détruire: ' . $numrows . '
    '; + $downlimitHandler->deleteAll($criteria); } @$xoopsLogger->activated = false; error_reporting(0); if ($helper->getConfig('check_host')) { - $goodhost = 0; - $referer = parse_url(xoops_getenv('HTTP_REFERER')); + $goodhost = 0; + + $referer = parse_url(xoops_getenv('HTTP_REFERER')); + $refererHost = $referer['host']; + foreach ($helper->getConfig('referers') as $ref) { if (!empty($ref) && preg_match('/' . $ref . '/i', $refererHost)) { $goodhost = '1'; + break; } } + if (!$goodhost) { redirect_header(XOOPS_URL . "/modules/$moduleDirName/singlefile.php?cid=$cid&lid=$lid", 30, _MD_TDMDOWNLOADS_NOPERMISETOLINK); } @@ -112,10 +148,11 @@ $sql = sprintf('UPDATE %s SET hits = hits+1 WHERE lid = %u AND status > 0', $xoopsDB->prefix('tdmdownloads_downloads'), $lid); $xoopsDB->queryF($sql); -$url = $viewDownloads->getVar('url', 'n'); -$contentLength = $utility::StringSizeConvert($viewDownloads->getVar('size')); +$url = $viewDownloads->getVar('url', 'n'); +$contentLength = $utility::convertStringToSize($viewDownloads->getVar('size')); if (!preg_match("/^ed2k*:\/\//i", $url)) { - header("Content-Length: $contentLength"); + header("Content-Length: $contentLength"); + header("Location: $url"); } echo ''; diff --git a/xoops_version.php b/xoops_version.php index 80b3f51..b8b3900 100644 --- a/xoops_version.php +++ b/xoops_version.php @@ -1,4 +1,5 @@ - _MI_TDMDOWNLOADS_NAME, - 'version' => '2.0', - 'module_status' => 'RC 1', - 'release_date' => '2019/01/31', - 'description' => _MI_TDMDOWNLOADS_DESC, - 'credits' => 'Mage, Mamba, Goffy', - 'author' => 'Mage', - 'nickname' => 'Mage', - 'module_website_url' => 'www.xoops.org', + 'name' => _MI_TDMDOWNLOADS_NAME, + 'version' => '2.01', + 'module_status' => 'Beta 1', + 'release_date' => '2021/08/08', + 'description' => _MI_TDMDOWNLOADS_DESC, + 'credits' => 'Mage, Mamba, Goffy, Heyula', + 'author' => 'Mage', + 'nickname' => 'Mage', + 'module_website_url' => 'www.xoops.org', 'module_website_name' => 'Support site', - 'help' => 'page=help', - 'license' => 'GNU GPL 2.0 or later', - 'license_url' => 'www.gnu.org/licenses/gpl-2.0.html', - 'official' => 0, + 'help' => 'page=help', + 'license' => 'GNU GPL 2.0 or later', + 'license_url' => 'www.gnu.org/licenses/gpl-2.0.html', + 'official' => 0, // ------------------- Folders & Files ------------------- - 'dirname' => $moduleDirName, - 'image' => 'assets/images/logoModule.png', - 'modicons16' => 'assets/images/icons/16', - 'modicons32' => 'assets/images/icons/32', - 'release_file' => XOOPS_URL . '/modules/' . $moduleDirName . '/docs/changelog.txt', - 'onInstall' => 'include/oninstall.php', - 'onUpdate' => 'include/onupdate.php', + 'dirname' => $moduleDirName, + 'image' => 'assets/images/logoModule.png', + 'modicons16' => 'assets/images/icons/16', + 'modicons32' => 'assets/images/icons/32', + 'release_file' => XOOPS_URL . '/modules/' . $moduleDirName . '/docs/changelog.txt', + 'onInstall' => 'include/oninstall.php', + 'onUpdate' => 'include/onupdate.php', // ------------------- Min Requirements ------------------- - 'min_php' => '7.0', - 'min_xoops' => '2.5.9', - 'min_admin' => '1.1', - 'min_db' => ['mysql' => '5.0.7', 'mysqli' => '5.0.7'], + 'min_php' => '7.1', + 'min_xoops' => '2.5.10', + 'min_admin' => '1.2', + 'min_db' => ['mysql' => '5.5'], // ------------------- Admin Menu ------------------- - 'hasAdmin' => 1, - 'system_menu' => 1, - 'adminindex' => 'admin/index.php', - 'adminmenu' => 'admin/menu.php', + 'hasAdmin' => 1, + 'system_menu' => 1, + 'adminindex' => 'admin/index.php', + 'adminmenu' => 'admin/menu.php', // ------------------- Mysql ------------------- - 'sqlfile' => ['mysql' => 'sql/mysql.sql'], + 'sqlfile' => ['mysql' => 'sql/mysql.sql'], // ------------------- Tables ------------------- - 'tables' => [ + 'tables' => [ $moduleDirName . '_broken', $moduleDirName . '_cat', $moduleDirName . '_downloads', @@ -72,21 +74,21 @@ ], // ------------------- Menu ------------------- - 'hasMain' => 1, - 'sub' => [ + 'hasMain' => 1, + 'sub' => [ [ 'name' => _MI_TDMDOWNLOADS_SMNAME1, - 'url' => 'submit.php', + 'url' => 'submit.php', ], [ 'name' => _MI_TDMDOWNLOADS_SMNAME2, - 'url' => 'search.php', + 'url' => 'search.php', ], ], // ------------------- Search ------------------- 'hasSearch' => 1, - 'search' => [ + 'search' => [ 'file' => 'include/search.inc.php', 'func' => 'tdmdownloads_search', ], @@ -95,63 +97,63 @@ // Pour les blocs $modversion['blocks'][] = [ - 'file' => 'tdmdownloads_top.php', - 'name' => _MI_TDMDOWNLOADS_BNAME1, + 'file' => 'tdmdownloads_top.php', + 'name' => _MI_TDMDOWNLOADS_BNAME1, 'description' => _MI_TDMDOWNLOADS_BNAMEDSC1, - 'show_func' => 'b_tdmdownloads_top_show', - 'edit_func' => 'b_tdmdownloads_top_edit', - 'options' => 'date|10|19|1|1|1|left|90|400|0', - 'template' => $moduleDirName . '_block_new.tpl', + 'show_func' => 'b_tdmdownloads_top_show', + 'edit_func' => 'b_tdmdownloads_top_edit', + 'options' => 'date|10|19|1|1|1|left|90|400|0', + 'template' => $moduleDirName . '_block_new.tpl', ]; $modversion['blocks'][] = [ - 'file' => 'tdmdownloads_top.php', - 'name' => _MI_TDMDOWNLOADS_BNAME2, + 'file' => 'tdmdownloads_top.php', + 'name' => _MI_TDMDOWNLOADS_BNAME2, 'description' => _MI_TDMDOWNLOADS_BNAMEDSC2, - 'show_func' => 'b_tdmdownloads_top_show', - 'edit_func' => 'b_tdmdownloads_top_edit', - 'options' => 'hits|10|19|1|1|1|left|90|400|0', - 'template' => $moduleDirName . '_block_top.tpl', + 'show_func' => 'b_tdmdownloads_top_show', + 'edit_func' => 'b_tdmdownloads_top_edit', + 'options' => 'hits|10|19|1|1|1|left|90|400|0', + 'template' => $moduleDirName . '_block_top.tpl', ]; $modversion['blocks'][] = [ - 'file' => 'tdmdownloads_top.php', - 'name' => _MI_TDMDOWNLOADS_BNAME3, + 'file' => 'tdmdownloads_top.php', + 'name' => _MI_TDMDOWNLOADS_BNAME3, 'description' => _MI_TDMDOWNLOADS_BNAMEDSC3, - 'show_func' => 'b_tdmdownloads_top_show', - 'edit_func' => 'b_tdmdownloads_top_edit', - 'options' => 'rating|10|19|1|1|1|left|90|400|0', - 'template' => $moduleDirName . '_block_rating.tpl', + 'show_func' => 'b_tdmdownloads_top_show', + 'edit_func' => 'b_tdmdownloads_top_edit', + 'options' => 'rating|10|19|1|1|1|left|90|400|0', + 'template' => $moduleDirName . '_block_rating.tpl', ]; $modversion['blocks'][] = [ - 'file' => 'tdmdownloads_top.php', - 'name' => _MI_TDMDOWNLOADS_BNAME4, + 'file' => 'tdmdownloads_top.php', + 'name' => _MI_TDMDOWNLOADS_BNAME4, 'description' => _MI_TDMDOWNLOADS_BNAMEDSC4, - 'show_func' => 'b_tdmdownloads_top_show', - 'edit_func' => 'b_tdmdownloads_top_edit', - 'options' => 'random|10|19|1|1|1|left|90|400|0', - 'template' => $moduleDirName . '_block_random.tpl', + 'show_func' => 'b_tdmdownloads_top_show', + 'edit_func' => 'b_tdmdownloads_top_edit', + 'options' => 'random|10|19|1|1|1|left|90|400|0', + 'template' => $moduleDirName . '_block_random.tpl', ]; $modversion['blocks'][] = [ - 'file' => 'tdmdownloads_search.php', - 'name' => _MI_TDMDOWNLOADS_BNAME5, + 'file' => 'tdmdownloads_search.php', + 'name' => _MI_TDMDOWNLOADS_BNAME5, 'description' => _MI_TDMDOWNLOADS_BNAMEDSC5, - 'show_func' => 'b_tdmdownloads_search_show', - 'edit_func' => '', - 'options' => '', - 'template' => $moduleDirName . '_block_search.tpl', + 'show_func' => 'b_tdmdownloads_search_show', + 'edit_func' => '', + 'options' => '', + 'template' => $moduleDirName . '_block_search.tpl', ]; // Commentaires -$modversion['hasComments'] = 1; -$modversion['comments']['itemName'] = 'lid'; -$modversion['comments']['pageName'] = 'singlefile.php'; -$modversion['comments']['extraParams'] = ['cid']; -$modversion['comments']['callbackFile'] = 'include/comment_functions.php'; +$modversion['hasComments'] = 1; +$modversion['comments']['itemName'] = 'lid'; +$modversion['comments']['pageName'] = 'singlefile.php'; +$modversion['comments']['extraParams'] = ['cid']; +$modversion['comments']['callbackFile'] = 'include/comment_functions.php'; $modversion['comments']['callback']['approve'] = 'tdmdownloads_com_approve'; -$modversion['comments']['callback']['update'] = 'tdmdownloads_com_update'; +$modversion['comments']['callback']['update'] = 'tdmdownloads_com_update'; // Templates $modversion['templates'] = [ @@ -181,6 +183,12 @@ ['file' => $moduleDirName . '_viewcat.tpl', 'description' => ''], ['file' => $moduleDirName . '_liste.tpl', 'description' => ''], ['file' => $moduleDirName . '_rss.tpl', 'description' => ''], + //uploads + ['file' => $moduleDirName . '_trigger_uploads.tpl', 'description' => ''], + ['file' => $moduleDirName . '_upload.tpl', 'description' => ''], + ['file' => $moduleDirName . '_header.tpl', 'description' => ''], + ['file' => $moduleDirName . '_footer.tpl', 'description' => ''], + ['file' => $moduleDirName . '_breadcrumbs.tpl', 'description' => ''], ]; // ------------------- Help files ------------------- // @@ -193,151 +201,154 @@ // Préférences $modversion['config'][] = [ - 'name' => 'break', - 'title' => '_MI_TDMDOWNLOADS_PREFERENCE_BREAK_GENERAL', + 'name' => 'break', + 'title' => '_MI_TDMDOWNLOADS_PREFERENCE_BREAK_GENERAL', 'description' => '', - 'formtype' => 'line_break', - 'valuetype' => 'textbox', - 'default' => 'head', + 'formtype' => 'line_break', + 'valuetype' => 'textbox', + 'default' => 'head', ]; $modversion['config'][] = [ - 'name' => 'popular', - 'title' => '_MI_TDMDOWNLOADS_POPULAR', + 'name' => 'popular', + 'title' => '_MI_TDMDOWNLOADS_POPULAR', 'description' => '', - 'formtype' => 'textbox', - 'valuetype' => 'int', - 'default' => 100, + 'formtype' => 'textbox', + 'valuetype' => 'int', + 'default' => 100, ]; $modversion['config'][] = [ - 'name' => 'autosummary', - 'title' => '_MI_TDMDOWNLOADS_AUTO_SUMMARY', + 'name' => 'autosummary', + 'title' => '_MI_TDMDOWNLOADS_AUTO_SUMMARY', 'description' => '', - 'formtype' => 'yesno', - 'valuetype' => 'int', - 'default' => 0, + 'formtype' => 'yesno', + 'valuetype' => 'int', + 'default' => 0, ]; $modversion['config'][] = [ - 'name' => 'showupdated', - 'title' => '_MI_TDMDOWNLOADS_SHOW_UPDATED', + 'name' => 'showupdated', + 'title' => '_MI_TDMDOWNLOADS_SHOW_UPDATED', 'description' => '', - 'formtype' => 'yesno', - 'valuetype' => 'int', - 'default' => 1, + 'formtype' => 'yesno', + 'valuetype' => 'int', + 'default' => 1, ]; $modversion['config'][] = [ - 'name' => 'useshots', - 'title' => '_MI_TDMDOWNLOADS_USESHOTS', + 'name' => 'useshots', + 'title' => '_MI_TDMDOWNLOADS_USESHOTS', 'description' => '', - 'formtype' => 'yesno', - 'valuetype' => 'int', - 'default' => 1, + 'formtype' => 'yesno', + 'valuetype' => 'int', + 'default' => 1, ]; $modversion['config'][] = [ - 'name' => 'shotwidth', - 'title' => '_MI_TDMDOWNLOADS_SHOTWIDTH', + 'name' => 'shotwidth', + 'title' => '_MI_TDMDOWNLOADS_SHOTWIDTH', 'description' => '', - 'formtype' => 'textbox', - 'valuetype' => 'int', - 'default' => 90, + 'formtype' => 'textbox', + 'valuetype' => 'int', + 'default' => 90, ]; $modversion['config'][] = [ - 'name' => 'img_float', - 'title' => '_MI_TDMDOWNLOADS_IMGFLOAT', + 'name' => 'img_float', + 'title' => '_MI_TDMDOWNLOADS_IMGFLOAT', 'description' => '', - 'formtype' => 'select', - 'valuetype' => 'text', - 'default' => 'left', - 'options' => [_MI_TDMDOWNLOADS_IMGFLOAT_LEFT => 'left', _MI_TDMDOWNLOADS_IMGFLOAT_RIGHT => 'Aaright'], + 'formtype' => 'select', + 'valuetype' => 'text', + 'default' => 'left', + 'options' => [_MI_TDMDOWNLOADS_IMGFLOAT_LEFT => 'left', _MI_TDMDOWNLOADS_IMGFLOAT_RIGHT => 'Aaright'], ]; $modversion['config'][] = [ - 'name' => 'platform', - 'title' => '_MI_TDMDOWNLOADS_PLATEFORM', + 'name' => 'platform', + 'title' => '_MI_TDMDOWNLOADS_PLATEFORM', 'description' => '_MI_TDMDOWNLOADS_PLATEFORM_DSC', - 'formtype' => 'textarea', - 'valuetype' => 'text', - 'default' => 'None|XOOPS 2.0.x|XOOPS 2.2.x|XOOPS 2.3.x|XOOPS 2.4.x|XOOPS 2.5.x|XOOPS 2.6.x|Other', + 'formtype' => 'textarea', + 'valuetype' => 'text', + 'default' => 'None|XOOPS 2.0.x|XOOPS 2.2.x|XOOPS 2.3.x|XOOPS 2.4.x|XOOPS 2.5.x|XOOPS 2.6.x|Other', ]; $modversion['config'][] = [ - 'name' => 'usetellafriend', - 'title' => '_MI_TDMDOWNLOADS_USETELLAFRIEND', + 'name' => 'usetellafriend', + 'title' => '_MI_TDMDOWNLOADS_USETELLAFRIEND', 'description' => '_MI_TDMDOWNLOADS_USETELLAFRIENDDSC', - 'formtype' => 'yesno', - 'valuetype' => 'int', - 'default' => 0, + 'formtype' => 'yesno', + 'valuetype' => 'int', + 'default' => 0, ]; $modversion['config'][] = [ - 'name' => 'usetag', - 'title' => '_MI_TDMDOWNLOADS_USETAG', + 'name' => 'usetag', + 'title' => '_MI_TDMDOWNLOADS_USETAG', 'description' => '_MI_TDMDOWNLOADS_USETAGDSC', - 'formtype' => 'yesno', - 'valuetype' => 'int', - 'default' => 0, + 'formtype' => 'yesno', + 'valuetype' => 'int', + 'default' => 0, ]; +//xoops_load('xoopseditorhandler'); +//$editorHandler = \XoopsEditorHandler::getInstance(); + $modversion['config'][] = [ - 'name' => 'editor', - 'title' => '_MI_TDMDOWNLOADS_FORM_OPTIONS', + 'name' => 'editor', + 'title' => '_MI_TDMDOWNLOADS_FORM_OPTIONS', 'description' => '', - 'formtype' => 'select', - 'valuetype' => 'text', - 'default' => 'dhtmltextarea', - 'options' => array_flip($editorHandler->getList()), + 'formtype' => 'select', + 'valuetype' => 'text', + 'default' => 'dhtmltextarea', + 'options' => array_flip($editorHandler->getList()), ]; $modversion['config'][] = [ - 'name' => 'break', - 'title' => '_MI_TDMDOWNLOADS_PREFERENCE_BREAK_USER', + 'name' => 'break', + 'title' => '_MI_TDMDOWNLOADS_PREFERENCE_BREAK_USER', 'description' => '', - 'formtype' => 'line_break', - 'valuetype' => 'textbox', - 'default' => 'head', + 'formtype' => 'line_break', + 'valuetype' => 'textbox', + 'default' => 'head', ]; $modversion['config'][] = [ - 'name' => 'perpage', - 'title' => '_MI_TDMDOWNLOADS_PERPAGE', + 'name' => 'perpage', + 'title' => '_MI_TDMDOWNLOADS_PERPAGE', 'description' => '', - 'formtype' => 'textbox', - 'valuetype' => 'int', - 'default' => 10, + 'formtype' => 'textbox', + 'valuetype' => 'int', + 'default' => 10, ]; $modversion['config'][] = [ - 'name' => 'nb_dowcol', - 'title' => '_MI_TDMDOWNLOADS_NBDOWCOL', + 'name' => 'nb_dowcol', + 'title' => '_MI_TDMDOWNLOADS_NBDOWCOL', 'description' => '', - 'formtype' => 'select', - 'valuetype' => 'int', - 'default' => 1, - 'options' => ['1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5], + 'formtype' => 'select', + 'valuetype' => 'int', + 'default' => 1, + 'options' => ['1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5], ]; $modversion['config'][] = [ - 'name' => 'newdownloads', - 'title' => '_MI_TDMDOWNLOADS_NEWDLS', + 'name' => 'newdownloads', + 'title' => '_MI_TDMDOWNLOADS_NEWDLS', 'description' => '', - 'formtype' => 'textbox', - 'valuetype' => 'int', - 'default' => 10, + 'formtype' => 'textbox', + 'valuetype' => 'int', + 'default' => 10, ]; $modversion['config'][] = [ - 'name' => 'toporder', - 'title' => '_MI_TDMDOWNLOADS_TOPORDER', + 'name' => 'toporder', + 'title' => '_MI_TDMDOWNLOADS_TOPORDER', 'description' => '', - 'formtype' => 'select', - 'valuetype' => 'int', - 'default' => 1, - 'options' => [ + 'formtype' => 'select', + 'valuetype' => 'int', + 'default' => 1, + 'options' => [ '_MI_TDMDOWNLOADS_TOPORDER1' => 1, '_MI_TDMDOWNLOADS_TOPORDER2' => 2, '_MI_TDMDOWNLOADS_TOPORDER3' => 3, @@ -350,22 +361,22 @@ ]; $modversion['config'][] = [ - 'name' => 'perpageliste', - 'title' => '_MI_TDMDOWNLOADS_PERPAGELISTE', + 'name' => 'perpageliste', + 'title' => '_MI_TDMDOWNLOADS_PERPAGELISTE', 'description' => '', - 'formtype' => 'textbox', - 'valuetype' => 'int', - 'default' => 15, + 'formtype' => 'textbox', + 'valuetype' => 'int', + 'default' => 15, ]; $modversion['config'][] = [ - 'name' => 'searchorder', - 'title' => '_MI_TDMDOWNLOADS_SEARCHORDER', + 'name' => 'searchorder', + 'title' => '_MI_TDMDOWNLOADS_SEARCHORDER', 'description' => '', - 'formtype' => 'select', - 'valuetype' => 'int', - 'default' => 8, - 'options' => [ + 'formtype' => 'select', + 'valuetype' => 'int', + 'default' => 8, + 'options' => [ '_MI_TDMDOWNLOADS_TOPORDER1' => 1, '_MI_TDMDOWNLOADS_TOPORDER2' => 2, '_MI_TDMDOWNLOADS_TOPORDER3' => 3, @@ -378,295 +389,309 @@ ]; $modversion['config'][] = [ - 'name' => 'nbsouscat', - 'title' => '_MI_TDMDOWNLOADS_SUBCATPARENT', + 'name' => 'nbsouscat', + 'title' => '_MI_TDMDOWNLOADS_SUBCATPARENT', 'description' => '', - 'formtype' => 'textbox', - 'valuetype' => 'int', - 'default' => 5, + 'formtype' => 'textbox', + 'valuetype' => 'int', + 'default' => 5, ]; $modversion['config'][] = [ - 'name' => 'nb_catcol', - 'title' => '_MI_TDMDOWNLOADS_NBCATCOL', + 'name' => 'nb_catcol', + 'title' => '_MI_TDMDOWNLOADS_NBCATCOL', 'description' => '', - 'formtype' => 'select', - 'valuetype' => 'int', - 'default' => 3, - 'options' => ['1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5], + 'formtype' => 'select', + 'valuetype' => 'int', + 'default' => 3, + 'options' => ['1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5], ]; $modversion['config'][] = [ - 'name' => 'bldate', - 'title' => '_MI_TDMDOWNLOADS_BLDATE', + 'name' => 'bldate', + 'title' => '_MI_TDMDOWNLOADS_BLDATE', 'description' => '', - 'formtype' => 'yesno', - 'valuetype' => 'int', - 'default' => 1, + 'formtype' => 'yesno', + 'valuetype' => 'int', + 'default' => 1, ]; $modversion['config'][] = [ - 'name' => 'blpop', - 'title' => '_MI_TDMDOWNLOADS_BLPOP', + 'name' => 'blpop', + 'title' => '_MI_TDMDOWNLOADS_BLPOP', 'description' => '', - 'formtype' => 'yesno', - 'valuetype' => 'int', - 'default' => 1, + 'formtype' => 'yesno', + 'valuetype' => 'int', + 'default' => 1, ]; $modversion['config'][] = [ - 'name' => 'blrating', - 'title' => '_MI_TDMDOWNLOADS_BLRATING', + 'name' => 'blrating', + 'title' => '_MI_TDMDOWNLOADS_BLRATING', 'description' => '', - 'formtype' => 'yesno', - 'valuetype' => 'int', - 'default' => 1, + 'formtype' => 'yesno', + 'valuetype' => 'int', + 'default' => 1, ]; $modversion['config'][] = [ - 'name' => 'nbbl', - 'title' => '_MI_TDMDOWNLOADS_NBBL', + 'name' => 'nbbl', + 'title' => '_MI_TDMDOWNLOADS_NBBL', 'description' => '', - 'formtype' => 'textbox', - 'valuetype' => 'int', - 'default' => 5, + 'formtype' => 'textbox', + 'valuetype' => 'int', + 'default' => 5, ]; $modversion['config'][] = [ - 'name' => 'longbl', - 'title' => '_MI_TDMDOWNLOADS_LONGBL', + 'name' => 'longbl', + 'title' => '_MI_TDMDOWNLOADS_LONGBL', 'description' => '', - 'formtype' => 'textbox', - 'valuetype' => 'int', - 'default' => 20, + 'formtype' => 'textbox', + 'valuetype' => 'int', + 'default' => 20, ]; $modversion['config'][] = [ - 'name' => 'show_bookmark', - 'title' => '_MI_TDMDOWNLOADS_BOOKMARK', + 'name' => 'show_bookmark', + 'title' => '_MI_TDMDOWNLOADS_BOOKMARK', 'description' => '_MI_TDMDOWNLOADS_BOOKMARK_DSC', - 'formtype' => 'yesno', - 'valuetype' => 'int', - 'default' => 1, + 'formtype' => 'yesno', + 'valuetype' => 'int', + 'default' => 1, ]; $modversion['config'][] = [ - 'name' => 'show_social', - 'title' => '_MI_TDMDOWNLOADS_SOCIAL', + 'name' => 'show_social', + 'title' => '_MI_TDMDOWNLOADS_SOCIAL', 'description' => '_MI_TDMDOWNLOADS_SOCIAL_DSC', - 'formtype' => 'yesno', - 'valuetype' => 'int', - 'default' => 1, + 'formtype' => 'yesno', + 'valuetype' => 'int', + 'default' => 1, ]; $modversion['config'][] = [ - 'name' => 'download_float', - 'title' => '_MI_TDMDOWNLOADS_DOWNLOADFLOAT', + 'name' => 'download_float', + 'title' => '_MI_TDMDOWNLOADS_DOWNLOADFLOAT', 'description' => '_MI_TDMDOWNLOADS_DOWNLOADFLOAT_DSC', - 'formtype' => 'select', - 'valuetype' => 'text', - 'default' => 'ltr', - 'options' => [_MI_TDMDOWNLOADS_DOWNLOADFLOAT_LTR => 'ltr', _MI_TDMDOWNLOADS_DOWNLOADFLOAT_RTL => 'rtl'], + 'formtype' => 'select', + 'valuetype' => 'text', + 'default' => 'ltr', + 'options' => [_MI_TDMDOWNLOADS_DOWNLOADFLOAT_LTR => 'ltr', _MI_TDMDOWNLOADS_DOWNLOADFLOAT_RTL => 'rtl'], ]; $modversion['config'][] = [ - 'name' => 'show_latest_files', - 'title' => '_MI_TDMDOWNLOADS_SHOW_LATEST_FILES', + 'name' => 'show_latest_files', + 'title' => '_MI_TDMDOWNLOADS_SHOW_LATEST_FILES', 'description' => '_MI_TDMDOWNLOADS_SHOW_LATEST_FILES_DSC', - 'formtype' => 'yesno', - 'valuetype' => 'int', - 'default' => 1, + 'formtype' => 'yesno', + 'valuetype' => 'int', + 'default' => 1, ]; $modversion['config'][] = [ - 'name' => 'break', - 'title' => '_MI_TDMDOWNLOADS_PREFERENCE_BREAK_ADMIN', + 'name' => 'break', + 'title' => '_MI_TDMDOWNLOADS_PREFERENCE_BREAK_ADMIN', 'description' => '', - 'formtype' => 'line_break', - 'valuetype' => 'textbox', - 'default' => 'head', + 'formtype' => 'line_break', + 'valuetype' => 'textbox', + 'default' => 'head', ]; $modversion['config'][] = [ - 'name' => 'perpageadmin', - 'title' => '_MI_TDMDOWNLOADS_PERPAGEADMIN', + 'name' => 'perpageadmin', + 'title' => '_MI_TDMDOWNLOADS_PERPAGEADMIN', 'description' => '', - 'formtype' => 'textbox', - 'valuetype' => 'int', - 'default' => 15, + 'formtype' => 'textbox', + 'valuetype' => 'int', + 'default' => 15, ]; $modversion['config'][] = [ - 'name' => 'break', - 'title' => '_MI_TDMDOWNLOADS_PREFERENCE_BREAK_DOWNLOADS', + 'name' => 'break', + 'title' => '_MI_TDMDOWNLOADS_PREFERENCE_BREAK_DOWNLOADS', 'description' => '', - 'formtype' => 'line_break', - 'valuetype' => 'textbox', - 'default' => 'head', + 'formtype' => 'line_break', + 'valuetype' => 'textbox', + 'default' => 'head', ]; $modversion['config'][] = [ - 'name' => 'permission_download', - 'title' => '_MI_TDMDOWNLOADS_PERMISSIONDOWNLOAD', + 'name' => 'permission_download', + 'title' => '_MI_TDMDOWNLOADS_PERMISSIONDOWNLOAD', 'description' => '', - 'formtype' => 'select', - 'valuetype' => 'int', - 'default' => 1, - 'options' => ['_MI_TDMDOWNLOADS_PERMISSIONDOWNLOAD1' => 1, '_MI_TDMDOWNLOADS_PERMISSIONDOWNLOAD2' => 2], + 'formtype' => 'select', + 'valuetype' => 'int', + 'default' => 1, + 'options' => ['_MI_TDMDOWNLOADS_PERMISSIONDOWNLOAD1' => 1, '_MI_TDMDOWNLOADS_PERMISSIONDOWNLOAD2' => 2], ]; $modversion['config'][] = [ - 'name' => 'newnamedownload', - 'title' => '_MI_TDMDOWNLOADS_DOWNLOAD_NAME', + 'name' => 'newnamedownload', + 'title' => '_MI_TDMDOWNLOADS_DOWNLOAD_NAME', 'description' => '_MI_TDMDOWNLOADS_DOWNLOAD_NAMEDSC', - 'formtype' => 'yesno', - 'valuetype' => 'int', - 'default' => 1, + 'formtype' => 'yesno', + 'valuetype' => 'int', + 'default' => 1, ]; $modversion['config'][] = [ - 'name' => 'prefixdownloads', - 'title' => '_MI_TDMDOWNLOADS_DOWNLOAD_PREFIX', + 'name' => 'prefixdownloads', + 'title' => '_MI_TDMDOWNLOADS_DOWNLOAD_PREFIX', 'description' => '_MI_TDMDOWNLOADS_DOWNLOAD_PREFIXDSC', - 'formtype' => 'textbox', - 'valuetype' => 'text', - 'default' => 'downloads_', + 'formtype' => 'textbox', + 'valuetype' => 'text', + 'default' => 'downloads_', ]; -include_once XOOPS_ROOT_PATH . '/modules/tdmdownloads/include/xoops_version.inc.php'; -$iniPostMaxSize = tdmdownloadsReturnBytes(ini_get('post_max_size')); -$iniUploadMaxFileSize = tdmdownloadsReturnBytes(ini_get('upload_max_filesize')); -$maxSize = min($iniPostMaxSize, $iniUploadMaxFileSize); +$iniPostMaxSize = \XoopsModules\Tdmdownloads\Utility::returnBytes(ini_get('post_max_size')); +$iniUploadMaxFileSize = \XoopsModules\Tdmdownloads\Utility::returnBytes(ini_get('upload_max_filesize')); +$maxSize = min($iniPostMaxSize, $iniUploadMaxFileSize); if ($maxSize > 10000 * 1048576) { $increment = 500; } -if ($maxSize <= 10000 * 1048576){ +if ($maxSize <= 10000 * 1048576) { $increment = 200; } -if ($maxSize <= 5000 * 1048576){ +if ($maxSize <= 5000 * 1048576) { $increment = 100; } -if ($maxSize <= 2500 * 1048576){ +if ($maxSize <= 2500 * 1048576) { $increment = 50; } -if ($maxSize <= 1000 * 1048576){ +if ($maxSize <= 1000 * 1048576) { $increment = 20; } -if ($maxSize <= 500 * 1048576){ +if ($maxSize <= 500 * 1048576) { $increment = 10; } -if ($maxSize <= 100 * 1048576){ +if ($maxSize <= 100 * 1048576) { $increment = 2; } -if ($maxSize <= 50 * 1048576){ +if ($maxSize <= 50 * 1048576) { $increment = 1; } -if ($maxSize <= 25 * 1048576){ +if ($maxSize <= 25 * 1048576) { $increment = 0.5; } $optionMaxsize = []; -$i = $increment; -while ($i* 1048576 <= $maxSize) { +$i = $increment; +while ($i * 1048576 <= $maxSize) { $optionMaxsize[$i . ' ' . _MI_TDMDOWNLOADS_MAXUPLOAD_SIZE_MB] = $i * 1048576; + $i += $increment; } $modversion['config'][] = [ - 'name' => 'maxuploadsize', - 'title' => '_MI_TDMDOWNLOADS_MAXUPLOAD_SIZE', + 'name' => 'maxuploadsize', + 'title' => '_MI_TDMDOWNLOADS_MAXUPLOAD_SIZE', 'description' => '_MI_TDMDOWNLOADS_MAXUPLOAD_SIZE_DESC', - 'formtype' => 'select', - 'valuetype' => 'int', - 'default' => 1048576, - 'options' => $optionMaxsize, + 'formtype' => 'select', + 'valuetype' => 'int', + 'default' => 1048576, + 'options' => $optionMaxsize, ]; $modversion['config'][] = [ - 'name' => 'mimetype', - 'title' => '_MI_TDMDOWNLOADS_MIMETYPE', + 'name' => 'mimetypes', + 'title' => '_MI_TDMDOWNLOADS_MIMETYPE', 'description' => '_MI_TDMDOWNLOADS_MIMETYPE_DSC', - 'formtype' => 'select_multi', - 'valuetype' => 'array', - 'default' => [ - 'image/gif', 'image/jpeg', 'image/png', - 'application/zip', 'application/rar', 'application/pdf', 'application/x-gtar', 'application/x-tar', - 'application/msword', 'application/vnd.ms-excel', 'application/vnd.oasis.opendocument.text', 'application/vnd.oasis.opendocument.spreadsheet', - 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + 'formtype' => 'select_multi', + 'valuetype' => 'array', + 'default' => [ + 'image/gif', + 'image/jpeg', + 'image/png', + 'application/zip', + 'application/rar', + 'application/pdf', + 'application/x-gtar', + 'application/x-tar', + 'application/msword', + 'application/vnd.ms-excel', + 'application/vnd.oasis.opendocument.text', + 'application/vnd.oasis.opendocument.spreadsheet', + 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', ], - 'options' => include $GLOBALS['xoops']->path('include/mimetypes.inc.php'), + 'options' => require $GLOBALS['xoops']->path('include/mimetypes.inc.php'), ]; +//---------------- picture ------------------------- +require_once __DIR__ . '/config/imageconfig.php'; +//---------------- picture ------------------------- + $modversion['config'][] = [ - 'name' => 'check_host', - 'title' => '_MI_TDMDOWNLOADS_CHECKHOST', + 'name' => 'check_host', + 'title' => '_MI_TDMDOWNLOADS_CHECKHOST', 'description' => '', - 'formtype' => 'yesno', - 'valuetype' => 'int', - 'default' => 0, + 'formtype' => 'yesno', + 'valuetype' => 'int', + 'default' => 0, ]; -$xoopsUrl = parse_url(XOOPS_URL); +$xoopsUrl = parse_url(XOOPS_URL); $modversion['config'][] = [ - 'name' => 'referers', - 'title' => '_MI_TDMDOWNLOADS_REFERERS', + 'name' => 'referers', + 'title' => '_MI_TDMDOWNLOADS_REFERERS', 'description' => '', - 'formtype' => 'textarea', - 'valuetype' => 'array', - 'default' => [$xoopsUrl['host']], + 'formtype' => 'textarea', + 'valuetype' => 'array', + 'default' => [$xoopsUrl['host']], ]; $modversion['config'][] = [ - 'name' => 'downlimit', - 'title' => '_MI_TDMDOWNLOADS_DOWNLIMIT', + 'name' => 'downlimit', + 'title' => '_MI_TDMDOWNLOADS_DOWNLIMIT', 'description' => '_MI_TDMDOWNLOADS_DOWNLIMITDSC', - 'formtype' => 'yesno', - 'valuetype' => 'int', - 'default' => 0, + 'formtype' => 'yesno', + 'valuetype' => 'int', + 'default' => 0, ]; $modversion['config'][] = [ - 'name' => 'limitglobal', - 'title' => '_MI_TDMDOWNLOADS_LIMITGLOBAL', + 'name' => 'limitglobal', + 'title' => '_MI_TDMDOWNLOADS_LIMITGLOBAL', 'description' => '_MI_TDMDOWNLOADS_LIMITGLOBALDSC', - 'formtype' => 'textbox', - 'valuetype' => 'int', - 'default' => 10, + 'formtype' => 'textbox', + 'valuetype' => 'int', + 'default' => 10, ]; $modversion['config'][] = [ - 'name' => 'limitlid', - 'title' => '_MI_TDMDOWNLOADS_LIMITLID', + 'name' => 'limitlid', + 'title' => '_MI_TDMDOWNLOADS_LIMITLID', 'description' => '_MI_TDMDOWNLOADS_LIMITLIDDSC', - 'formtype' => 'textbox', - 'valuetype' => 'int', - 'default' => 2, + 'formtype' => 'textbox', + 'valuetype' => 'int', + 'default' => 2, ]; $modversion['config'][] = [ - 'name' => 'break', - 'title' => '_MI_TDMDOWNLOADS_PREFERENCE_BREAK_PAYPAL', + 'name' => 'break', + 'title' => '_MI_TDMDOWNLOADS_PREFERENCE_BREAK_PAYPAL', 'description' => '', - 'formtype' => 'line_break', - 'valuetype' => 'textbox', - 'default' => 'head', + 'formtype' => 'line_break', + 'valuetype' => 'textbox', + 'default' => 'head', ]; $modversion['config'][] = [ - 'name' => 'use_paypal', - 'title' => '_MI_TDMDOWNLOADS_USEPAYPAL', + 'name' => 'use_paypal', + 'title' => '_MI_TDMDOWNLOADS_USEPAYPAL', 'description' => '', - 'formtype' => 'yesno', - 'valuetype' => 'int', - 'default' => 0, + 'formtype' => 'yesno', + 'valuetype' => 'int', + 'default' => 0, ]; $modversion['config'][] = [ - 'name' => 'currency_paypal', - 'title' => '_MI_TDMDOWNLOADS_CURRENCYPAYPAL', + 'name' => 'currency_paypal', + 'title' => '_MI_TDMDOWNLOADS_CURRENCYPAYPAL', 'description' => '', - 'formtype' => 'select', - 'valuetype' => 'text', - 'default' => 'EUR', - 'options' => [ + 'formtype' => 'select', + 'valuetype' => 'text', + 'default' => 'EUR', + 'options' => [ 'AUD' => 'AUD', 'BRL' => 'BRL', 'CAD' => 'CAD', @@ -693,202 +718,202 @@ ]; $modversion['config'][] = [ - 'name' => 'image_paypal', - 'title' => '_MI_TDMDOWNLOADS_IMAGEPAYPAL', + 'name' => 'image_paypal', + 'title' => '_MI_TDMDOWNLOADS_IMAGEPAYPAL', 'description' => '_MI_TDMDOWNLOADS_IMAGEPAYPALDSC', - 'formtype' => 'textbox', - 'valuetype' => 'text', - 'default' => 'https://www.paypal.com/fr_FR/FR/i/btn/btn_donateCC_LG.gif', + 'formtype' => 'textbox', + 'valuetype' => 'text', + 'default' => 'https://www.paypal.com/fr_FR/FR/i/btn/btn_donateCC_LG.gif', ]; $modversion['config'][] = [ - 'name' => 'break', - 'title' => '_MI_TDMDOWNLOADS_PREFERENCE_BREAK_RSS', + 'name' => 'break', + 'title' => '_MI_TDMDOWNLOADS_PREFERENCE_BREAK_RSS', 'description' => '', - 'formtype' => 'line_break', - 'valuetype' => 'textbox', - 'default' => 'head', + 'formtype' => 'line_break', + 'valuetype' => 'textbox', + 'default' => 'head', ]; $modversion['config'][] = [ - 'name' => 'perpagerss', - 'title' => '_MI_TDMDOWNLOADS_PERPAGERSS', + 'name' => 'perpagerss', + 'title' => '_MI_TDMDOWNLOADS_PERPAGERSS', 'description' => '_MI_TDMDOWNLOADS_PERPAGERSSDSC', - 'formtype' => 'textbox', - 'valuetype' => 'int', - 'default' => 10, + 'formtype' => 'textbox', + 'valuetype' => 'int', + 'default' => 10, ]; $modversion['config'][] = [ - 'name' => 'timecacherss', - 'title' => '_MI_TDMDOWNLOADS_TIMECACHERSS', + 'name' => 'timecacherss', + 'title' => '_MI_TDMDOWNLOADS_TIMECACHERSS', 'description' => '_MI_TDMDOWNLOADS_TIMECACHERSSDSC', - 'formtype' => 'textbox', - 'valuetype' => 'int', - 'default' => 60, + 'formtype' => 'textbox', + 'valuetype' => 'int', + 'default' => 60, ]; $modversion['config'][] = [ - 'name' => 'logorss', - 'title' => '_MI_TDMDOWNLOADS_LOGORSS', + 'name' => 'logorss', + 'title' => '_MI_TDMDOWNLOADS_LOGORSS', 'description' => '', - 'formtype' => 'textbox', - 'valuetype' => 'text', - 'default' => '/modules/tdmdownloads/assets/images/mydl_slogo.png', + 'formtype' => 'textbox', + 'valuetype' => 'text', + 'default' => '/modules/' . $moduleDirName . '/assets/images/mydl_slogo.png', ]; $modversion['config'][] = [ - 'name' => 'break', - 'title' => '_MI_TDMDOWNLOADS_CONFCAT_OTHERS', + 'name' => 'break', + 'title' => '_MI_TDMDOWNLOADS_CONFCAT_OTHERS', 'description' => '', - 'formtype' => 'line_break', - 'valuetype' => 'textbox', - 'default' => 'head', + 'formtype' => 'line_break', + 'valuetype' => 'textbox', + 'default' => 'head', ]; /** * Make Sample button visible? */ $modversion['config'][] = [ - 'name' => 'displaySampleButton', - 'title' => '_MI_TDMDOWNLOADS_SHOW_SAMPLE_BUTTON', + 'name' => 'displaySampleButton', + 'title' => '_MI_TDMDOWNLOADS_SHOW_SAMPLE_BUTTON', 'description' => '_MI_TDMDOWNLOADS_SHOW_SAMPLE_BUTTON_DESC', - 'formtype' => 'yesno', - 'valuetype' => 'int', - 'default' => 1, + 'formtype' => 'yesno', + 'valuetype' => 'int', + 'default' => 1, ]; /** * Show Developer Tools? */ $modversion['config'][] = [ - 'name' => 'displayDeveloperTools', - 'title' => '_MI_TDMDOWNLOADS_SHOW_DEV_TOOLS', + 'name' => 'displayDeveloperTools', + 'title' => '_MI_TDMDOWNLOADS_SHOW_DEV_TOOLS', 'description' => '_MI_TDMDOWNLOADS_SHOW_DEV_TOOLS_DESC', - 'formtype' => 'yesno', - 'valuetype' => 'int', - 'default' => 0, + 'formtype' => 'yesno', + 'valuetype' => 'int', + 'default' => 0, ]; // ------------------- Notifications ------------------- -$modversion['config'][] = [ - 'name' => 'break', - 'title' => '_MI_TDMDOWNLOADS_PREFERENCE_BREAK_COMNOTI', +$modversion['config'][] = [ + 'name' => 'break', + 'title' => '_MI_TDMDOWNLOADS_PREFERENCE_BREAK_COMNOTI', 'description' => '', - 'formtype' => 'line_break', - 'valuetype' => 'textbox', - 'default' => 'head', + 'formtype' => 'line_break', + 'valuetype' => 'textbox', + 'default' => 'head', ]; -$modversion['hasNotification'] = 1; +$modversion['hasNotification'] = 1; $modversion['notification']['lookup_file'] = 'include/notification.inc.php'; $modversion['notification']['lookup_func'] = 'tdmdownloads_notify_iteminfo'; $modversion['notification']['category'][] = [ - 'name' => 'global', - 'title' => _MI_TDMDOWNLOADS_GLOBAL_NOTIFY, - 'description' => _MI_TDMDOWNLOADS_GLOBAL_NOTIFYDSC, + 'name' => 'global', + 'title' => _MI_TDMDOWNLOADS_GLOBAL_NOTIFY, + 'description' => _MI_TDMDOWNLOADS_GLOBAL_NOTIFYDSC, 'subscribe_from' => ['index.php', 'viewcat.php', 'singlefile.php'], ]; $modversion['notification']['category'][] = [ - 'name' => 'category', - 'title' => _MI_TDMDOWNLOADS_CATEGORY_NOTIFY, - 'description' => _MI_TDMDOWNLOADS_CATEGORY_NOTIFYDSC, + 'name' => 'category', + 'title' => _MI_TDMDOWNLOADS_CATEGORY_NOTIFY, + 'description' => _MI_TDMDOWNLOADS_CATEGORY_NOTIFYDSC, 'subscribe_from' => ['viewcat.php', 'singlefile.php'], - 'item_name' => 'cid', + 'item_name' => 'cid', 'allow_bookmark' => 1, ]; $modversion['notification']['category'][] = [ - 'name' => 'file', - 'title' => _MI_TDMDOWNLOADS_FILE_NOTIFY, - 'description' => _MI_TDMDOWNLOADS_FILE_NOTIFYDSC, + 'name' => 'file', + 'title' => _MI_TDMDOWNLOADS_FILE_NOTIFY, + 'description' => _MI_TDMDOWNLOADS_FILE_NOTIFYDSC, 'subscribe_from' => 'singlefile.php', - 'item_name' => 'lid', + 'item_name' => 'lid', 'allow_bookmark' => 1, ]; $modversion['notification']['event'][] = [ - 'name' => 'new_category', - 'category' => 'global', - 'title' => _MI_TDMDOWNLOADS_GLOBAL_NEWCATEGORY_NOTIFY, - 'caption' => _MI_TDMDOWNLOADS_GLOBAL_NEWCATEGORY_NOTIFYCAP, - 'description' => _MI_TDMDOWNLOADS_GLOBAL_NEWCATEGORY_NOTIFYDSC, + 'name' => 'new_category', + 'category' => 'global', + 'title' => _MI_TDMDOWNLOADS_GLOBAL_NEWCATEGORY_NOTIFY, + 'caption' => _MI_TDMDOWNLOADS_GLOBAL_NEWCATEGORY_NOTIFYCAP, + 'description' => _MI_TDMDOWNLOADS_GLOBAL_NEWCATEGORY_NOTIFYDSC, 'mail_template' => 'global_newcategory_notify', - 'mail_subject' => _MI_TDMDOWNLOADS_GLOBAL_NEWCATEGORY_NOTIFYSBJ, + 'mail_subject' => _MI_TDMDOWNLOADS_GLOBAL_NEWCATEGORY_NOTIFYSBJ, ]; $modversion['notification']['event'][] = [ - 'name' => 'file_modify', - 'category' => 'global', - 'admin_only' => 1, - 'title' => _MI_TDMDOWNLOADS_GLOBAL_FILEMODIFY_NOTIFY, - 'caption' => _MI_TDMDOWNLOADS_GLOBAL_FILEMODIFY_NOTIFYCAP, - 'description' => _MI_TDMDOWNLOADS_GLOBAL_FILEMODIFY_NOTIFYDSC, + 'name' => 'file_modify', + 'category' => 'global', + 'admin_only' => 1, + 'title' => _MI_TDMDOWNLOADS_GLOBAL_FILEMODIFY_NOTIFY, + 'caption' => _MI_TDMDOWNLOADS_GLOBAL_FILEMODIFY_NOTIFYCAP, + 'description' => _MI_TDMDOWNLOADS_GLOBAL_FILEMODIFY_NOTIFYDSC, 'mail_template' => 'global_filemodify_notify', - 'mail_subject' => _MI_TDMDOWNLOADS_GLOBAL_FILEMODIFY_NOTIFYSBJ, + 'mail_subject' => _MI_TDMDOWNLOADS_GLOBAL_FILEMODIFY_NOTIFYSBJ, ]; $modversion['notification']['event'][] = [ - 'name' => 'file_submit', - 'category' => 'global', - 'admin_only' => 1, - 'title' => _MI_TDMDOWNLOADS_GLOBAL_FILESUBMIT_NOTIFY, - 'caption' => _MI_TDMDOWNLOADS_GLOBAL_FILESUBMIT_NOTIFYCAP, - 'description' => _MI_TDMDOWNLOADS_GLOBAL_FILESUBMIT_NOTIFYDSC, + 'name' => 'file_submit', + 'category' => 'global', + 'admin_only' => 1, + 'title' => _MI_TDMDOWNLOADS_GLOBAL_FILESUBMIT_NOTIFY, + 'caption' => _MI_TDMDOWNLOADS_GLOBAL_FILESUBMIT_NOTIFYCAP, + 'description' => _MI_TDMDOWNLOADS_GLOBAL_FILESUBMIT_NOTIFYDSC, 'mail_template' => 'global_filesubmit_notify', - 'mail_subject' => _MI_TDMDOWNLOADS_GLOBAL_FILESUBMIT_NOTIFYSBJ, + 'mail_subject' => _MI_TDMDOWNLOADS_GLOBAL_FILESUBMIT_NOTIFYSBJ, ]; $modversion['notification']['event'][] = [ - 'name' => 'file_broken', - 'category' => 'global', - 'admin_only' => 1, - 'title' => _MI_TDMDOWNLOADS_GLOBAL_FILEBROKEN_NOTIFY, - 'caption' => _MI_TDMDOWNLOADS_GLOBAL_FILEBROKEN_NOTIFYCAP, - 'description' => _MI_TDMDOWNLOADS_GLOBAL_FILEBROKEN_NOTIFYDSC, + 'name' => 'file_broken', + 'category' => 'global', + 'admin_only' => 1, + 'title' => _MI_TDMDOWNLOADS_GLOBAL_FILEBROKEN_NOTIFY, + 'caption' => _MI_TDMDOWNLOADS_GLOBAL_FILEBROKEN_NOTIFYCAP, + 'description' => _MI_TDMDOWNLOADS_GLOBAL_FILEBROKEN_NOTIFYDSC, 'mail_template' => 'global_filebroken_notify', - 'mail_subject' => _MI_TDMDOWNLOADS_GLOBAL_FILEBROKEN_NOTIFYSBJ, + 'mail_subject' => _MI_TDMDOWNLOADS_GLOBAL_FILEBROKEN_NOTIFYSBJ, ]; $modversion['notification']['event'][] = [ - 'name' => 'new_file', - 'category' => 'global', - 'title' => _MI_TDMDOWNLOADS_GLOBAL_NEWFILE_NOTIFY, - 'caption' => _MI_TDMDOWNLOADS_GLOBAL_NEWFILE_NOTIFYCAP, - 'description' => _MI_TDMDOWNLOADS_GLOBAL_NEWFILE_NOTIFYDSC, + 'name' => 'new_file', + 'category' => 'global', + 'title' => _MI_TDMDOWNLOADS_GLOBAL_NEWFILE_NOTIFY, + 'caption' => _MI_TDMDOWNLOADS_GLOBAL_NEWFILE_NOTIFYCAP, + 'description' => _MI_TDMDOWNLOADS_GLOBAL_NEWFILE_NOTIFYDSC, 'mail_template' => 'global_newfile_notify', - 'mail_subject' => _MI_TDMDOWNLOADS_GLOBAL_NEWFILE_NOTIFYSBJ, + 'mail_subject' => _MI_TDMDOWNLOADS_GLOBAL_NEWFILE_NOTIFYSBJ, ]; $modversion['notification']['event'][] = [ - 'name' => 'file_submit', - 'category' => 'category', - 'admin_only' => 1, - 'title' => _MI_TDMDOWNLOADS_CATEGORY_FILESUBMIT_NOTIFY, - 'caption' => _MI_TDMDOWNLOADS_CATEGORY_FILESUBMIT_NOTIFYCAP, - 'description' => _MI_TDMDOWNLOADS_CATEGORY_FILESUBMIT_NOTIFYDSC, + 'name' => 'file_submit', + 'category' => 'category', + 'admin_only' => 1, + 'title' => _MI_TDMDOWNLOADS_CATEGORY_FILESUBMIT_NOTIFY, + 'caption' => _MI_TDMDOWNLOADS_CATEGORY_FILESUBMIT_NOTIFYCAP, + 'description' => _MI_TDMDOWNLOADS_CATEGORY_FILESUBMIT_NOTIFYDSC, 'mail_template' => 'category_filesubmit_notify', - 'mail_subject' => _MI_TDMDOWNLOADS_CATEGORY_FILESUBMIT_NOTIFYSBJ, + 'mail_subject' => _MI_TDMDOWNLOADS_CATEGORY_FILESUBMIT_NOTIFYSBJ, ]; $modversion['notification']['event'][] = [ - 'name' => 'new_file', - 'category' => 'category', - 'title' => _MI_TDMDOWNLOADS_CATEGORY_NEWFILE_NOTIFY, - 'caption' => _MI_TDMDOWNLOADS_CATEGORY_NEWFILE_NOTIFYCAP, - 'description' => _MI_TDMDOWNLOADS_CATEGORY_NEWFILE_NOTIFYDSC, + 'name' => 'new_file', + 'category' => 'category', + 'title' => _MI_TDMDOWNLOADS_CATEGORY_NEWFILE_NOTIFY, + 'caption' => _MI_TDMDOWNLOADS_CATEGORY_NEWFILE_NOTIFYCAP, + 'description' => _MI_TDMDOWNLOADS_CATEGORY_NEWFILE_NOTIFYDSC, 'mail_template' => 'category_newfile_notify', - 'mail_subject' => _MI_TDMDOWNLOADS_CATEGORY_NEWFILE_NOTIFYSBJ, + 'mail_subject' => _MI_TDMDOWNLOADS_CATEGORY_NEWFILE_NOTIFYSBJ, ]; $modversion['notification']['event'][] = [ - 'name' => 'approve', - 'category' => 'file', - 'invisible' => 1, - 'title' => _MI_TDMDOWNLOADS_FILE_APPROVE_NOTIFY, - 'caption' => _MI_TDMDOWNLOADS_FILE_APPROVE_NOTIFYCAP, - 'description' => _MI_TDMDOWNLOADS_FILE_APPROVE_NOTIFYDSC, + 'name' => 'approve', + 'category' => 'file', + 'invisible' => 1, + 'title' => _MI_TDMDOWNLOADS_FILE_APPROVE_NOTIFY, + 'caption' => _MI_TDMDOWNLOADS_FILE_APPROVE_NOTIFYCAP, + 'description' => _MI_TDMDOWNLOADS_FILE_APPROVE_NOTIFYDSC, 'mail_template' => 'file_approve_notify', - 'mail_subject' => _MI_TDMDOWNLOADS_FILE_APPROVE_NOTIFYSBJ, + 'mail_subject' => _MI_TDMDOWNLOADS_FILE_APPROVE_NOTIFYSBJ, ];