Skip to content

Commit 0cad66a

Browse files
authored
Merge pull request #7 from mambax7/master
fixes, 3.03 Alpha 3
2 parents eac6425 + 962c975 commit 0cad66a

37 files changed

+747
-281
lines changed

_archive/class/AddFiles.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

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

3030
/**
31-
* Class MoreFiles.
31+
* Class AddFiles.
3232
*/
3333
class AddFiles extends \XoopsObject
3434
{
@@ -90,7 +90,7 @@ public static function getInstance()
9090
}
9191

9292
/**
93-
* @public function getFormMoreFiles
93+
* @public function getFormMorefiles
9494
* @param mixed $action
9595
*
9696
* @return \XoopsThemeForm
@@ -109,7 +109,7 @@ public function getFormAddFiles($action = false)
109109
$form = new \XoopsThemeForm($title, 'addfilesform', $action, 'post', true);
110110
$form->setExtra('enctype="multipart/form-data"');
111111

112-
$modules = $this->helper->getHandler('modules')->getObjects(null);
112+
$modules = $this->helper->getHandler('Modules')->getObjects(null);
113113
$modulesSelect = new \XoopsFormSelect(_AM_MODULEBUILDER_ADDFILES_MODULES, 'file_mid', $this->getVar('file_mid'));
114114
$modulesSelect->addOption('', _AM_MODULEBUILDER_ADDFILES_MODULE_SELECT);
115115
foreach ($modules as $mod) {
@@ -147,7 +147,7 @@ public function getAddFilesValues($keys = null, $format = null, $maxDepth = null
147147
$ret = $this->getValues($keys, $format, $maxDepth);
148148
// Values
149149
$ret['id'] = $this->getVar('file_id');
150-
$ret['mid'] = $this->helper->getHandler('modules')->get($this->getVar('file_mid'))->getVar('mod_name');
150+
$ret['mid'] = $this->helper->getHandler('Modules')->get($this->getVar('file_mid'))->getVar('mod_name');
151151
$ret['name'] = $this->getVar('file_name');
152152
$ret['extension'] = $this->getVar('file_extension');
153153
$ret['infolder'] = $this->getVar('file_infolder');

_archive/class/AddFilesHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414

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

2828
/**
29-
* Class MoreFilesHandler.
29+
* Class AddFilesHandler.
3030
*/
3131
class AddFilesHandler extends \XoopsPersistableObjectHandler
3232
{

_archive/class/Files/User/UserObjects.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public function getUrlFileSetVar($moduleDirname, $tableName, $fieldName)
166166
\${$tableName}Obj->setVar('{$fieldName}', formatUrl(\$_REQUEST['{$fieldName}']));\n
167167
// Set Var {$fieldName}
168168
include_once XOOPS_ROOT_PATH.'/class/uploader.php';
169-
\$uploaddir = {$stuModuleDirname}_UPLOAD_PATH.'/files/{$tableName}';
169+
\$uploaddir = {$stuModuleDirname}_UPLOAD_PATH.'/Files/{$tableName}';
170170
\$uploader = new \XoopsMediaUploader(\$uploaddir, \$helper->getConfig('mimetypes_file'),
171171
\$helper->getConfig('maxsize_file'), null, null);
172172
if (\$uploader->fetchMedia(\$_POST['xoops_upload_file'][])) {
@@ -264,7 +264,7 @@ public function getUploadFileSetVar($moduleDirname, $tableName, $fieldName)
264264
$ret = <<<EOT
265265
// Set Var {$fieldName}
266266
include_once XOOPS_ROOT_PATH.'/class/uploader.php';
267-
\$uploaddir = {$stuModuleDirname}_UPLOAD_PATH.'/files/{$tableName}';
267+
\$uploaddir = {$stuModuleDirname}_UPLOAD_PATH.'/Files/{$tableName}';
268268
\$uploader = new \XoopsMediaUploader(\$uploaddir, \$helper->getConfig('mimetypes_file'),
269269
\$helper->getConfig('maxsize_file'), null, null);
270270
if (\$uploader->fetchMedia(\$_POST['xoops_upload_file'][])) {

admin/building.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
}
6363
}
6464
// Structure
65-
// include_once TDMC_CLASS_PATH . '/files/Architecture.php';
65+
// include_once TDMC_CLASS_PATH . '/Files/Architecture.php';
6666
$handler = Modulebuilder\Files\CreateArchitecture::getInstance();
6767
// Creation of the structure of folders and files
6868
$baseArchitecture = $handler->setBaseFoldersFiles($moduleObj);

admin/index.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
* @author Txmod Xoops http://www.txmodxoops.org
2222
*
2323
*/
24+
25+
use XoopsModules\Modulebuilder\Common;
26+
2427
$GLOBALS['xoopsOption']['template_main'] = 'modulebuilder_index.tpl';
2528

2629
include __DIR__ . '/header.php';
@@ -47,11 +50,25 @@
4750
];
4851

4952
// Uploads Folders Created
53+
//foreach (array_keys($folder) as $i) {
54+
// $utility::createFolder($folder[$i]);
55+
// $adminObject->addConfigBoxLine($folder[$i], 'folder');
56+
// $adminObject->addConfigBoxLine([$folder[$i], '777'], 'chmod');
57+
//}
58+
59+
//------ check Upload Folders ---------------
60+
61+
$adminObject->addConfigBoxLine('');
62+
$redirectFile = $_SERVER['SCRIPT_NAME'];
63+
5064
foreach (array_keys($folder) as $i) {
51-
$adminObject->addConfigBoxLine($folder[$i], 'folder');
52-
$adminObject->addConfigBoxLine([$folder[$i], '777'], 'chmod');
65+
$adminObject->addConfigBoxLine(Common\DirectoryChecker::getDirectoryStatus($folder[$i], 0777, $redirectFile));
5366
}
5467

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

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

admin/morefiles.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@
5050
if (0 == $modulesCount) {
5151
redirect_header('modules.php?op=new', 2, _AM_MODULEBUILDER_NOTMODULES);
5252
}
53-
$morefilesCount = $helper->getHandler('Morefiles')->getCountMoreFiles();
54-
$morefilesAll = $helper->getHandler('Morefiles')->getAllMoreFiles($start, $limit);
53+
$morefilesCount = $helper->getHandler('Morefiles')->getCountMorefiles();
54+
$morefilesAll = $helper->getHandler('Morefiles')->getAllMorefiles($start, $limit);
5555
// Display morefiles list
5656
if ($morefilesCount > 0) {
5757
foreach (array_keys($morefilesAll) as $i) {
58-
$files = $morefilesAll[$i]->getValuesMoreFiles();
58+
$files = $morefilesAll[$i]->getValuesMorefiles();
5959
$GLOBALS['xoopsTpl']->append('files_list', $files);
6060
unset($files);
6161
}
@@ -75,7 +75,7 @@
7575
$GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left'));
7676

7777
$morefilesObj = $helper->getHandler('Morefiles')->create();
78-
$form = $morefilesObj->getFormMoreFiles();
78+
$form = $morefilesObj->getFormMorefiles();
7979
$GLOBALS['xoopsTpl']->assign('form', $form->render());
8080
break;
8181
case 'save':
@@ -106,7 +106,7 @@
106106
}
107107

108108
$GLOBALS['xoopsTpl']->assign('error', $morefilesObj->getHtmlErrors());
109-
$form = $morefilesObj->getFormMoreFiles();
109+
$form = $morefilesObj->getFormMorefiles();
110110
$GLOBALS['xoopsTpl']->assign('form', $form->render());
111111
break;
112112
case 'edit':
@@ -119,7 +119,7 @@
119119
$GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left'));
120120

121121
$morefilesObj = $helper->getHandler('Morefiles')->get($fileId);
122-
$form = $morefilesObj->getFormMoreFiles();
122+
$form = $morefilesObj->getFormMorefiles();
123123
$GLOBALS['xoopsTpl']->assign('form', $form->render());
124124
break;
125125
case 'delete':

admin/tables.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@
246246
}
247247
if ($helper->getHandler('Tables')->delete($tablesObj)) {
248248
// Delete items in table fieldelements - idea by goffy
249-
$fieldelements = $helper->getHandler('Fieldelements')->getAllFieldElementsByModuleAndTableId($tableMid, $tableId);
249+
$fieldelements = $helper->getHandler('Fieldelements')->getAllFieldelementsByModuleAndTableId($tableMid, $tableId);
250250
foreach (array_keys($fieldelements) as $fe) {
251251
$fieldElementsObj = $helper->getHandler('Fieldelements')->get($fieldelements[$fe]->getVar('fieldelement_id'));
252252
if (!$helper->getHandler('Fieldelements')->delete($fieldElementsObj)) {

class/Building.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function getForm($action = false)
6262
xoops_load('XoopsFormLoader');
6363
$form = new \XoopsThemeForm(_AM_MODULEBUILDER_ADMIN_CONST, 'buildform', $action, 'post', true);
6464
$form->setExtra('enctype="multipart/form-data"');
65-
$moduleObj = $helper->getHandler('modules')->getObjects(null);
65+
$moduleObj = $helper->getHandler('Modules')->getObjects(null);
6666
$mod_select = new \XoopsFormSelect(_AM_MODULEBUILDER_CONST_MODULES, 'mod_id', 'mod_id');
6767
$mod_select->addOption('', _AM_MODULEBUILDER_BUILD_MODSELOPT);
6868
foreach ($moduleObj as $mod) {

class/Common/DirectoryChecker.php

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
<?php
2+
3+
namespace XoopsModules\Modulebuilder\Common;
4+
5+
/*
6+
You may not change or alter any portion of this comment or credits
7+
of supporting developers from this source code or any supporting source code
8+
which is considered copyrighted (c) material of the original comment or credit authors.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13+
*/
14+
15+
/**
16+
* Modulebuilder module
17+
*
18+
* @copyright XOOPS Project (https://xoops.org)
19+
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
20+
* @author Xoops Development Team
21+
*/
22+
23+
use Xmf\Request;
24+
use XoopsModules\Modulebuilder;
25+
26+
//defined('XOOPS_ROOT_PATH') || die('XOOPS root path not defined');
27+
28+
require_once dirname(dirname(dirname(dirname(__DIR__)))) . '/mainfile.php';
29+
$moduleDirName = basename(dirname(dirname(__DIR__)));
30+
$moduleDirNameUpper = mb_strtoupper($moduleDirName);
31+
xoops_loadLanguage('directorychecker', $moduleDirName);
32+
33+
/**
34+
* Class DirectoryChecker
35+
* check status of a directory
36+
*/
37+
class DirectoryChecker
38+
{
39+
/**
40+
* @param $path
41+
* @param int $mode
42+
* @param $redirectFile
43+
*
44+
* @return bool|string
45+
*/
46+
public static function getDirectoryStatus($path, $mode = 0777, $redirectFile = null)
47+
{
48+
$pathIcon16 = \Xmf\Module\Admin::iconUrl('', 16);
49+
50+
if (empty($path)) {
51+
return false;
52+
}
53+
if (null === $redirectFile) {
54+
$redirectFile = $_SERVER['SCRIPT_NAME'];
55+
}
56+
$moduleDirName = basename(dirname(dirname(__DIR__)));
57+
$moduleDirNameUpper = mb_strtoupper($moduleDirName);
58+
if (!@is_dir($path)) {
59+
$path_status = "<img src='$pathIcon16/0.png' >";
60+
$path_status .= "$path (" . constant('CO_' . $moduleDirNameUpper . '_' . 'DC_NOTAVAILABLE') . ') ';
61+
$path_status .= "<form action='" . $_SERVER['SCRIPT_NAME'] . "' method='post'>";
62+
$path_status .= "<input type='hidden' name='op' value='createdir'>";
63+
$path_status .= "<input type='hidden' name='path' value='$path'>";
64+
$path_status .= "<input type='hidden' name='redirect' value='$redirectFile'>";
65+
$path_status .= "<button class='submit' onClick='this.form.submit();'>" . constant('CO_' . $moduleDirNameUpper . '_' . 'DC_CREATETHEDIR') . '</button>';
66+
$path_status .= '</form>';
67+
} elseif (@is_writable($path)) {
68+
$path_status = "<img src='$pathIcon16/1.png' >";
69+
$path_status .= "$path (" . constant('CO_' . $moduleDirNameUpper . '_' . 'DC_AVAILABLE') . ') ';
70+
$currentMode = mb_substr(decoct(fileperms($path)), 2);
71+
if ($currentMode != decoct($mode)) {
72+
$path_status = "<img src='$pathIcon16/0.png' >";
73+
$path_status .= $path . sprintf(constant('CO_' . $moduleDirNameUpper . '_' . 'DC_NOTWRITABLE'), decoct($mode), $currentMode);
74+
$path_status .= "<form action='" . $_SERVER['SCRIPT_NAME'] . "' method='post'>";
75+
$path_status .= "<input type='hidden' name='op' value='setdirperm'>";
76+
$path_status .= "<input type='hidden' name='mode' value='$mode'>";
77+
$path_status .= "<input type='hidden' name='path' value='$path'>";
78+
$path_status .= "<input type='hidden' name='redirect' value='$redirectFile'>";
79+
$path_status .= "<button class='submit' onClick='this.form.submit();'>" . constant('CO_' . $moduleDirNameUpper . '_' . 'DC_SETMPERM') . '</button>';
80+
$path_status .= '</form>';
81+
}
82+
} else {
83+
$currentMode = mb_substr(decoct(fileperms($path)), 2);
84+
$path_status = "<img src='$pathIcon16/0.png' >";
85+
$path_status .= $path . sprintf(constant('CO_' . $moduleDirNameUpper . '_' . 'DC_NOTWRITABLE'), decoct($mode), $currentMode);
86+
$path_status .= "<form action='" . $_SERVER['SCRIPT_NAME'] . "' method='post'>";
87+
$path_status .= "<input type='hidden' name='op' value='setdirperm'>";
88+
$path_status .= "<input type='hidden' name='mode' value='$mode'>";
89+
$path_status .= "<input type='hidden' name='path' value='$path'>";
90+
$path_status .= "<input type='hidden' name='redirect' value='$redirectFile'>";
91+
$path_status .= "<button class='submit' onClick='this.form.submit();'>" . constant('CO_' . $moduleDirNameUpper . '_' . 'DC_SETMPERM') . '</button>';
92+
$path_status .= '</form>';
93+
}
94+
95+
return $path_status;
96+
}
97+
98+
/**
99+
* @param $target
100+
* @param int $mode
101+
*
102+
* @return bool
103+
*/
104+
public static function createDirectory($target, $mode = 0777)
105+
{
106+
$target = str_replace('..', '', $target);
107+
108+
// http://www.php.net/manual/en/function.mkdir.php
109+
return is_dir($target) || (self::createDirectory(dirname($target), $mode) && !mkdir($target, $mode) && !is_dir($target));
110+
}
111+
112+
/**
113+
* @param $target
114+
* @param int $mode
115+
*
116+
* @return bool
117+
*/
118+
public static function setDirectoryPermissions($target, $mode = 0777)
119+
{
120+
$target = str_replace('..', '', $target);
121+
122+
return @chmod($target, (int)$mode);
123+
}
124+
125+
/**
126+
* @param $dir_path
127+
*
128+
* @return bool
129+
*/
130+
public static function dirExists($dir_path)
131+
{
132+
return is_dir($dir_path);
133+
}
134+
}
135+
136+
$op = Request::getString('op', '', 'POST');
137+
switch ($op) {
138+
case 'createdir':
139+
if (\Xmf\Request::hasVar('path', 'POST')) {
140+
$path = $_POST['path'];
141+
}
142+
if (\Xmf\Request::hasVar('redirect', 'POST')) {
143+
$redirect = $_POST['redirect'];
144+
}
145+
$msg = DirectoryChecker::createDirectory($path) ? constant('CO_' . $moduleDirNameUpper . '_' . 'DC_DIRCREATED') : constant('CO_' . $moduleDirNameUpper . '_' . 'DC_DIRNOTCREATED');
146+
redirect_header($redirect, 2, $msg . ': ' . $path);
147+
break;
148+
case 'setdirperm':
149+
if (\Xmf\Request::hasVar('path', 'POST')) {
150+
$path = $_POST['path'];
151+
}
152+
if (\Xmf\Request::hasVar('redirect', 'POST')) {
153+
$redirect = $_POST['redirect'];
154+
}
155+
if (\Xmf\Request::hasVar('mode', 'POST')) {
156+
$mode = $_POST['mode'];
157+
}
158+
$msg = DirectoryChecker::setDirectoryPermissions($path, $mode) ? constant('CO_' . $moduleDirNameUpper . '_' . 'DC_PERMSET') : constant('CO_' . $moduleDirNameUpper . '_' . 'DC_PERMNOTSET');
159+
redirect_header($redirect, 2, $msg . ': ' . $path);
160+
break;
161+
}

0 commit comments

Comments
 (0)