Skip to content

Commit

Permalink
Merge pull request #7 from mambax7/master
Browse files Browse the repository at this point in the history
fixes, 3.03 Alpha 3
  • Loading branch information
mambax7 committed May 10, 2020
2 parents eac6425 + 962c975 commit 0cad66a
Show file tree
Hide file tree
Showing 37 changed files with 747 additions and 281 deletions.
10 changes: 5 additions & 5 deletions _archive/class/AddFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

/**
* morefiles class.
* AddFiles class.
*
* @copyright The XOOPS Project http:sourceforge.net/projects/xoops/
* @license GNU GPL 2 (http:www.gnu.org/licenses/old-licenses/gpl-2.0.html)
Expand All @@ -28,7 +28,7 @@
//include __DIR__.'/autoload.php';

/**
* Class MoreFiles.
* Class AddFiles.
*/
class AddFiles extends \XoopsObject
{
Expand Down Expand Up @@ -90,7 +90,7 @@ public static function getInstance()
}

/**
* @public function getFormMoreFiles
* @public function getFormMorefiles
* @param mixed $action
*
* @return \XoopsThemeForm
Expand All @@ -109,7 +109,7 @@ public function getFormAddFiles($action = false)
$form = new \XoopsThemeForm($title, 'addfilesform', $action, 'post', true);
$form->setExtra('enctype="multipart/form-data"');

$modules = $this->helper->getHandler('modules')->getObjects(null);
$modules = $this->helper->getHandler('Modules')->getObjects(null);
$modulesSelect = new \XoopsFormSelect(_AM_MODULEBUILDER_ADDFILES_MODULES, 'file_mid', $this->getVar('file_mid'));
$modulesSelect->addOption('', _AM_MODULEBUILDER_ADDFILES_MODULE_SELECT);
foreach ($modules as $mod) {
Expand Down Expand Up @@ -147,7 +147,7 @@ public function getAddFilesValues($keys = null, $format = null, $maxDepth = null
$ret = $this->getValues($keys, $format, $maxDepth);
// Values
$ret['id'] = $this->getVar('file_id');
$ret['mid'] = $this->helper->getHandler('modules')->get($this->getVar('file_mid'))->getVar('mod_name');
$ret['mid'] = $this->helper->getHandler('Modules')->get($this->getVar('file_mid'))->getVar('mod_name');
$ret['name'] = $this->getVar('file_name');
$ret['extension'] = $this->getVar('file_extension');
$ret['infolder'] = $this->getVar('file_infolder');
Expand Down
4 changes: 2 additions & 2 deletions _archive/class/AddFilesHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

/**
* morefiles class.
* AddFilesHandler class.
*
* @copyright The XOOPS Project http:sourceforge.net/projects/xoops/
* @license GNU GPL 2 (http:www.gnu.org/licenses/old-licenses/gpl-2.0.html)
Expand All @@ -26,7 +26,7 @@
//include __DIR__.'/autoload.php';

/**
* Class MoreFilesHandler.
* Class AddFilesHandler.
*/
class AddFilesHandler extends \XoopsPersistableObjectHandler
{
Expand Down
4 changes: 2 additions & 2 deletions _archive/class/Files/User/UserObjects.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function getUrlFileSetVar($moduleDirname, $tableName, $fieldName)
\${$tableName}Obj->setVar('{$fieldName}', formatUrl(\$_REQUEST['{$fieldName}']));\n
// Set Var {$fieldName}
include_once XOOPS_ROOT_PATH.'/class/uploader.php';
\$uploaddir = {$stuModuleDirname}_UPLOAD_PATH.'/files/{$tableName}';
\$uploaddir = {$stuModuleDirname}_UPLOAD_PATH.'/Files/{$tableName}';
\$uploader = new \XoopsMediaUploader(\$uploaddir, \$helper->getConfig('mimetypes_file'),
\$helper->getConfig('maxsize_file'), null, null);
if (\$uploader->fetchMedia(\$_POST['xoops_upload_file'][])) {
Expand Down Expand Up @@ -264,7 +264,7 @@ public function getUploadFileSetVar($moduleDirname, $tableName, $fieldName)
$ret = <<<EOT
// Set Var {$fieldName}
include_once XOOPS_ROOT_PATH.'/class/uploader.php';
\$uploaddir = {$stuModuleDirname}_UPLOAD_PATH.'/files/{$tableName}';
\$uploaddir = {$stuModuleDirname}_UPLOAD_PATH.'/Files/{$tableName}';
\$uploader = new \XoopsMediaUploader(\$uploaddir, \$helper->getConfig('mimetypes_file'),
\$helper->getConfig('maxsize_file'), null, null);
if (\$uploader->fetchMedia(\$_POST['xoops_upload_file'][])) {
Expand Down
2 changes: 1 addition & 1 deletion admin/building.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
}
}
// Structure
// include_once TDMC_CLASS_PATH . '/files/Architecture.php';
// include_once TDMC_CLASS_PATH . '/Files/Architecture.php';
$handler = Modulebuilder\Files\CreateArchitecture::getInstance();
// Creation of the structure of folders and files
$baseArchitecture = $handler->setBaseFoldersFiles($moduleObj);
Expand Down
21 changes: 19 additions & 2 deletions admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
* @author Txmod Xoops http://www.txmodxoops.org
*
*/

use XoopsModules\Modulebuilder\Common;

$GLOBALS['xoopsOption']['template_main'] = 'modulebuilder_index.tpl';

include __DIR__ . '/header.php';
Expand All @@ -47,11 +50,25 @@
];

// Uploads Folders Created
//foreach (array_keys($folder) as $i) {
// $utility::createFolder($folder[$i]);
// $adminObject->addConfigBoxLine($folder[$i], 'folder');
// $adminObject->addConfigBoxLine([$folder[$i], '777'], 'chmod');
//}

//------ check Upload Folders ---------------

$adminObject->addConfigBoxLine('');
$redirectFile = $_SERVER['SCRIPT_NAME'];

foreach (array_keys($folder) as $i) {
$adminObject->addConfigBoxLine($folder[$i], 'folder');
$adminObject->addConfigBoxLine([$folder[$i], '777'], 'chmod');
$adminObject->addConfigBoxLine(Common\DirectoryChecker::getDirectoryStatus($folder[$i], 0777, $redirectFile));
}

//foreach ($pathArray as $path) {
// $adminObject->addConfigBoxLine(DirectoryChecker::getDirectoryStatus($path['dir'], $path['perm'], $languageConstants, $path['action']));
//}


$adminObject->displayNavigation(basename(__FILE__));

Expand Down
12 changes: 6 additions & 6 deletions admin/morefiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@
if (0 == $modulesCount) {
redirect_header('modules.php?op=new', 2, _AM_MODULEBUILDER_NOTMODULES);
}
$morefilesCount = $helper->getHandler('Morefiles')->getCountMoreFiles();
$morefilesAll = $helper->getHandler('Morefiles')->getAllMoreFiles($start, $limit);
$morefilesCount = $helper->getHandler('Morefiles')->getCountMorefiles();
$morefilesAll = $helper->getHandler('Morefiles')->getAllMorefiles($start, $limit);
// Display morefiles list
if ($morefilesCount > 0) {
foreach (array_keys($morefilesAll) as $i) {
$files = $morefilesAll[$i]->getValuesMoreFiles();
$files = $morefilesAll[$i]->getValuesMorefiles();
$GLOBALS['xoopsTpl']->append('files_list', $files);
unset($files);
}
Expand All @@ -75,7 +75,7 @@
$GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left'));

$morefilesObj = $helper->getHandler('Morefiles')->create();
$form = $morefilesObj->getFormMoreFiles();
$form = $morefilesObj->getFormMorefiles();
$GLOBALS['xoopsTpl']->assign('form', $form->render());
break;
case 'save':
Expand Down Expand Up @@ -106,7 +106,7 @@
}

$GLOBALS['xoopsTpl']->assign('error', $morefilesObj->getHtmlErrors());
$form = $morefilesObj->getFormMoreFiles();
$form = $morefilesObj->getFormMorefiles();
$GLOBALS['xoopsTpl']->assign('form', $form->render());
break;
case 'edit':
Expand All @@ -119,7 +119,7 @@
$GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left'));

$morefilesObj = $helper->getHandler('Morefiles')->get($fileId);
$form = $morefilesObj->getFormMoreFiles();
$form = $morefilesObj->getFormMorefiles();
$GLOBALS['xoopsTpl']->assign('form', $form->render());
break;
case 'delete':
Expand Down
2 changes: 1 addition & 1 deletion admin/tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@
}
if ($helper->getHandler('Tables')->delete($tablesObj)) {
// Delete items in table fieldelements - idea by goffy
$fieldelements = $helper->getHandler('Fieldelements')->getAllFieldElementsByModuleAndTableId($tableMid, $tableId);
$fieldelements = $helper->getHandler('Fieldelements')->getAllFieldelementsByModuleAndTableId($tableMid, $tableId);
foreach (array_keys($fieldelements) as $fe) {
$fieldElementsObj = $helper->getHandler('Fieldelements')->get($fieldelements[$fe]->getVar('fieldelement_id'));
if (!$helper->getHandler('Fieldelements')->delete($fieldElementsObj)) {
Expand Down
2 changes: 1 addition & 1 deletion class/Building.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function getForm($action = false)
xoops_load('XoopsFormLoader');
$form = new \XoopsThemeForm(_AM_MODULEBUILDER_ADMIN_CONST, 'buildform', $action, 'post', true);
$form->setExtra('enctype="multipart/form-data"');
$moduleObj = $helper->getHandler('modules')->getObjects(null);
$moduleObj = $helper->getHandler('Modules')->getObjects(null);
$mod_select = new \XoopsFormSelect(_AM_MODULEBUILDER_CONST_MODULES, 'mod_id', 'mod_id');
$mod_select->addOption('', _AM_MODULEBUILDER_BUILD_MODSELOPT);
foreach ($moduleObj as $mod) {
Expand Down
161 changes: 161 additions & 0 deletions class/Common/DirectoryChecker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<?php

namespace XoopsModules\Modulebuilder\Common;

/*
You may not change or alter any portion of this comment or credits
of supporting developers from this source code or any supporting source code
which is considered copyrighted (c) material of the original comment or credit authors.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/

/**
* Modulebuilder module
*
* @copyright XOOPS Project (https://xoops.org)
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
* @author Xoops Development Team
*/

use Xmf\Request;
use XoopsModules\Modulebuilder;

//defined('XOOPS_ROOT_PATH') || die('XOOPS root path not defined');

require_once dirname(dirname(dirname(dirname(__DIR__)))) . '/mainfile.php';
$moduleDirName = basename(dirname(dirname(__DIR__)));
$moduleDirNameUpper = mb_strtoupper($moduleDirName);
xoops_loadLanguage('directorychecker', $moduleDirName);

/**
* Class DirectoryChecker
* check status of a directory
*/
class DirectoryChecker
{
/**
* @param $path
* @param int $mode
* @param $redirectFile
*
* @return bool|string
*/
public static function getDirectoryStatus($path, $mode = 0777, $redirectFile = null)
{
$pathIcon16 = \Xmf\Module\Admin::iconUrl('', 16);

if (empty($path)) {
return false;
}
if (null === $redirectFile) {
$redirectFile = $_SERVER['SCRIPT_NAME'];
}
$moduleDirName = basename(dirname(dirname(__DIR__)));
$moduleDirNameUpper = mb_strtoupper($moduleDirName);
if (!@is_dir($path)) {
$path_status = "<img src='$pathIcon16/0.png' >";
$path_status .= "$path (" . constant('CO_' . $moduleDirNameUpper . '_' . 'DC_NOTAVAILABLE') . ') ';
$path_status .= "<form action='" . $_SERVER['SCRIPT_NAME'] . "' method='post'>";
$path_status .= "<input type='hidden' name='op' value='createdir'>";
$path_status .= "<input type='hidden' name='path' value='$path'>";
$path_status .= "<input type='hidden' name='redirect' value='$redirectFile'>";
$path_status .= "<button class='submit' onClick='this.form.submit();'>" . constant('CO_' . $moduleDirNameUpper . '_' . 'DC_CREATETHEDIR') . '</button>';
$path_status .= '</form>';
} elseif (@is_writable($path)) {
$path_status = "<img src='$pathIcon16/1.png' >";
$path_status .= "$path (" . constant('CO_' . $moduleDirNameUpper . '_' . 'DC_AVAILABLE') . ') ';
$currentMode = mb_substr(decoct(fileperms($path)), 2);
if ($currentMode != decoct($mode)) {
$path_status = "<img src='$pathIcon16/0.png' >";
$path_status .= $path . sprintf(constant('CO_' . $moduleDirNameUpper . '_' . 'DC_NOTWRITABLE'), decoct($mode), $currentMode);
$path_status .= "<form action='" . $_SERVER['SCRIPT_NAME'] . "' method='post'>";
$path_status .= "<input type='hidden' name='op' value='setdirperm'>";
$path_status .= "<input type='hidden' name='mode' value='$mode'>";
$path_status .= "<input type='hidden' name='path' value='$path'>";
$path_status .= "<input type='hidden' name='redirect' value='$redirectFile'>";
$path_status .= "<button class='submit' onClick='this.form.submit();'>" . constant('CO_' . $moduleDirNameUpper . '_' . 'DC_SETMPERM') . '</button>';
$path_status .= '</form>';
}
} else {
$currentMode = mb_substr(decoct(fileperms($path)), 2);
$path_status = "<img src='$pathIcon16/0.png' >";
$path_status .= $path . sprintf(constant('CO_' . $moduleDirNameUpper . '_' . 'DC_NOTWRITABLE'), decoct($mode), $currentMode);
$path_status .= "<form action='" . $_SERVER['SCRIPT_NAME'] . "' method='post'>";
$path_status .= "<input type='hidden' name='op' value='setdirperm'>";
$path_status .= "<input type='hidden' name='mode' value='$mode'>";
$path_status .= "<input type='hidden' name='path' value='$path'>";
$path_status .= "<input type='hidden' name='redirect' value='$redirectFile'>";
$path_status .= "<button class='submit' onClick='this.form.submit();'>" . constant('CO_' . $moduleDirNameUpper . '_' . 'DC_SETMPERM') . '</button>';
$path_status .= '</form>';
}

return $path_status;
}

/**
* @param $target
* @param int $mode
*
* @return bool
*/
public static function createDirectory($target, $mode = 0777)
{
$target = str_replace('..', '', $target);

// http://www.php.net/manual/en/function.mkdir.php
return is_dir($target) || (self::createDirectory(dirname($target), $mode) && !mkdir($target, $mode) && !is_dir($target));
}

/**
* @param $target
* @param int $mode
*
* @return bool
*/
public static function setDirectoryPermissions($target, $mode = 0777)
{
$target = str_replace('..', '', $target);

return @chmod($target, (int)$mode);
}

/**
* @param $dir_path
*
* @return bool
*/
public static function dirExists($dir_path)
{
return is_dir($dir_path);
}
}

$op = Request::getString('op', '', 'POST');
switch ($op) {
case 'createdir':
if (\Xmf\Request::hasVar('path', 'POST')) {
$path = $_POST['path'];
}
if (\Xmf\Request::hasVar('redirect', 'POST')) {
$redirect = $_POST['redirect'];
}
$msg = DirectoryChecker::createDirectory($path) ? constant('CO_' . $moduleDirNameUpper . '_' . 'DC_DIRCREATED') : constant('CO_' . $moduleDirNameUpper . '_' . 'DC_DIRNOTCREATED');
redirect_header($redirect, 2, $msg . ': ' . $path);
break;
case 'setdirperm':
if (\Xmf\Request::hasVar('path', 'POST')) {
$path = $_POST['path'];
}
if (\Xmf\Request::hasVar('redirect', 'POST')) {
$redirect = $_POST['redirect'];
}
if (\Xmf\Request::hasVar('mode', 'POST')) {
$mode = $_POST['mode'];
}
$msg = DirectoryChecker::setDirectoryPermissions($path, $mode) ? constant('CO_' . $moduleDirNameUpper . '_' . 'DC_PERMSET') : constant('CO_' . $moduleDirNameUpper . '_' . 'DC_PERMNOTSET');
redirect_header($redirect, 2, $msg . ': ' . $path);
break;
}
Loading

0 comments on commit 0cad66a

Please sign in to comment.