Skip to content

Commit f5693fe

Browse files
committed
added check for upload permission to form class
1 parent d9fe946 commit f5693fe

7 files changed

Lines changed: 68 additions & 31 deletions

File tree

class/Files/Classes/ClassFiles.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,16 @@ private function getFunctionForm($module, $table, $fieldId, $fieldInForm)
285285
$getForm .= $pc->getPhpCodeConditions('false', ' === ', '$action', $action, false, "\t\t");
286286
$xUser = $pc->getPhpCodeGlobals('xoopsUser');
287287
$xModule = $pc->getPhpCodeGlobals('xoopsModule');
288+
$permString = 'upload_groups';
288289
if (1 != $tableCategory/* && (1 == $tablePermissions)*/) {
289290
$getForm .= $pc->getPhpCodeCommentLine('Permissions for', 'uploader', "\t\t");
290291
$getForm .= $xc->getXcEqualsOperator('$gpermHandler', "xoops_getHandler('groupperm')", null, true, "\t\t");
291292
$getForm .= $pc->getPhpCodeTernaryOperator('groups', 'is_object(' . $xUser . ')', $xUser . '->getGroups()', 'XOOPS_GROUP_ANONYMOUS', "\t\t");
292-
$checkRight = $xc->getXcCheckRight('$gpermHandler', $permString = '', 32, '$groups', $xModule . '->getVar(\'mid\')', true);
293-
$ternaryOperator = $pc->getPhpCodeTernaryOperator('permissionUpload', $checkRight, 'true', 'false', "\t\t\t\t");
293+
$checkRight = $xc->getXcCheckRight('$gpermHandler', $permString, 32, '$groups', $xModule . '->getVar(\'mid\')', true);
294+
$ternaryOperator = $pc->getPhpCodeTernaryOperator('permissionUpload', $checkRight, 'true', 'false', "\t\t\t");
294295
$permissionUpload = $xc->getXcEqualsOperator('$permissionUpload', 'true', null, false, "\t\t\t\t");
295296
$ternOperator = $pc->getPhpCodeRemoveCarriageReturn($ternaryOperator, '', "\r");
296-
$if = $pc->getPhpCodeConditions('!' . $xUser . '->isAdmin(' . $xModule . '->mid())', '', '', $ternaryOperator, $permissionUpload, "\t\t\t");
297+
$if = $pc->getPhpCodeConditions('!' . $xUser . '->isAdmin(' . $xModule . '->mid())', '', '', "\t" . $ternaryOperator, $permissionUpload, "\t\t\t");
297298
$getForm .= $pc->getPhpCodeConditions($xUser, '', '', $if, $ternOperator, "\t\t");
298299
}
299300
$getForm .= $pc->getPhpCodeCommentLine('Title', '', "\t\t");

class/Files/Classes/ClassFormElements.php

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,12 @@ private function getXoopsFormUploadImage($language, $moduleDirname, $tableName,
370370
$ucfFieldName = $tf->getCamelCase($fieldName, true);
371371
$ccFieldName = $tf->getCamelCase($fieldName, false, true);
372372
$t = "\t\t";
373-
$ret = $pc->getPhpCodeCommentLine('Form Upload', 'Image ' . $ucfFieldName, $t);
373+
$ret = $pc->getPhpCodeCommentLine('Form', 'Image ' . $ucfFieldName, $t);
374+
$ret .= $pc->getPhpCodeCommentLine("Form Image {$ucfFieldName}:", 'Select Uploaded Image ', $t);
374375
$ret .= $xc->getXcEqualsOperator('$get' . $ucfFieldName, "\$this->getVar('{$fieldName}')", null, false, $t);
375376
$ret .= $pc->getPhpCodeTernaryOperator($ccFieldName, '$get' . $ucfFieldName, '$get' . $ucfFieldName, "'blank.gif'", $t);
376377
$ret .= $xc->getXcEqualsOperator('$imageDirectory', "'/uploads/{$moduleDirname}/images/{$tableName}'", null, false, $t);
377-
$ret .= $cc->getClassXoopsFormElementTray('imageTray', '_OPTIONS', '<br>', $t);
378+
$ret .= $cc->getClassXoopsFormElementTray('imageTray', $language . 'FORM_UPLOAD', '<br>', $t);
378379
$sprintf = $pc->getPhpCodeSprintf($language . 'FORM_IMAGE_PATH', '".{$imageDirectory}/"');
379380
$ret .= $cc->getClassXoopsFormSelect('imageSelect', $sprintf, $fieldName, $ccFieldName, 5, 'false', false, $t);
380381
$ret .= $xc->getXcXoopsImgListArray('imageArray', 'XOOPS_ROOT_PATH . $imageDirectory', $t);
@@ -386,14 +387,13 @@ private function getXoopsFormUploadImage($language, $moduleDirname, $tableName,
386387
$paramLabel = "\"<br><img src='\".XOOPS_URL.\"/\".\$imageDirectory.\"/\".\${$ccFieldName}.\"' name='image1' id='image1' alt='' style='max-width:100px' />\"";
387388
$xoopsFormLabel = $cc->getClassXoopsFormLabel('', "''", $paramLabel, true, '');
388389
$ret .= $cc->getClassAddElement('imageTray', $xoopsFormLabel, $t);
389-
$ret .= $pc->getPhpCodeCommentLine('Form', 'File ' . $ucfFieldName, $t);
390-
$ret .= $cc->getClassXoopsFormElementTray('fileSelectTray', "''", '<br>', $t);
390+
$ret .= $pc->getPhpCodeCommentLine("Form Image {$ucfFieldName}:", 'Upload Image', $t);
391391
$getConfig = $xc->getXcGetConfig($moduleDirname, 'maxsize');
392-
$xoopsFormFile = $cc->getClassXoopsFormFile('', $language . 'FORM_UPLOAD_IMAGE_' . $stuTableName, 'attachedfile', $getConfig, true, '');
393-
$ret .= $cc->getClassAddElement('fileSelectTray', $xoopsFormFile, $t);
394-
$xoopsFormLabel1 = $cc->getClassXoopsFormLabel('', "''", null, true);
395-
$ret .= $cc->getClassAddElement('fileSelectTray', $xoopsFormLabel1, $t);
396-
$ret .= $cc->getClassAddElement('imageTray', '$fileSelectTray', $t);
392+
$xoopsFormFile = $cc->getClassXoopsFormFile('imageTray', $language . 'FORM_UPLOAD_NEW', 'attachedfile', $getConfig, true, '');
393+
$contIf = $cc->getClassAddElement('imageTray', $xoopsFormFile, $t . "\t");
394+
$formHidden = $cc->getClassXoopsFormHidden('', $fieldName, $ccFieldName, true, true, $t, true);
395+
$contElse = $cc->getClassAddElement('imageTray', $formHidden, $t . "\t");
396+
$ret .= $pc->getPhpCodeConditions('$permissionUpload', null, null, $contIf, $contElse, "\t\t");
397397
$ret .= $cc->getClassAddElement('form', "\$imageTray{$required}", $t);
398398

399399
return $ret;
@@ -418,17 +418,24 @@ private function getXoopsFormUploadFile($language, $moduleDirname, $tableName, $
418418
$cc = Tdmcreate\Files\Classes\ClassXoopsCode::getInstance();
419419
$ucfFieldName = $tf->getCamelCase($fieldName, true);
420420
$stuTableName = mb_strtoupper($tableName);
421-
$t = "\t\t";
422-
$ret = $pc->getPhpCodeCommentLine('Form', 'File ' . $ucfFieldName, $t);
423-
$ret .= $cc->getClassXoopsFormElementTray('fileUploadTray', $language . 'FORM_UPLOAD_FILE_' . $stuTableName, '<br>', $t);
424-
$getVar = $xc->getXcGetVar('', 'this', $fieldName, true);
425-
$xoopsFormLabel = $cc->getClassXoopsFormLabel('', "''", $getVar, true);
421+
$ccFieldName = $tf->getCamelCase($fieldName, false, true);
422+
423+
$t = "\t\t\t";
424+
$ret = $pc->getPhpCodeCommentLine('Form', 'File ' . $ucfFieldName, "\t\t");
425+
$ret .= $pc->getPhpCodeTernaryOperator($ccFieldName, '$this->isNew()', "''", "\$this->getVar('{$fieldName}')", "\t\t");
426+
427+
$uForm = $cc->getClassXoopsFormElementTray('fileUploadTray', $language . 'FORM_UPLOAD', '<br>', $t);
428+
$xoopsFormLabel = $cc->getClassXoopsFormLabel('', $language . 'FORM_UPLOAD_FILE_' . $stuTableName, $ccFieldName, true, "\t\t", true);
426429
$condIf = $cc->getClassAddElement('fileUploadTray', $xoopsFormLabel, $t . "\t");
427-
$ret .= $pc->getPhpCodeConditions('!$this->isNew()', null, null, $condIf, false, "\t\t");
430+
$uForm .= $pc->getPhpCodeConditions('!$this->isNew()', null, null, $condIf, false, "\t\t\t");
428431
$getConfig = $xc->getXcGetConfig($moduleDirname, 'maxsize');
429432
$xoopsFormFile = $cc->getClassXoopsFormFile('', "''", $fieldName, $getConfig, true, '');
430-
$ret .= $cc->getClassAddElement('fileUploadTray', $xoopsFormFile, $t);
431-
$ret .= $cc->getClassAddElement('form', '$fileUploadTray', $t);
433+
$uForm .= $cc->getClassAddElement('fileUploadTray', $xoopsFormFile, $t);
434+
$uForm .= $cc->getClassAddElement('form', '$fileUploadTray', $t);
435+
$formHidden = $cc->getClassXoopsFormHidden('', $fieldName, $ccFieldName, true, true, "\t\t", true);
436+
$contElse = $cc->getClassAddElement('form', $formHidden, $t);
437+
438+
$ret .= $pc->getPhpCodeConditions('$permissionUpload', null, null, $uForm, $contElse, "\t\t");
432439

433440
return $ret;
434441
}

class/Files/Classes/ClassXoopsCode.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,14 @@ public function getClassXoopsFormElementTray($var, $param1, $param2 = '', $t = "
277277
*
278278
* @return string
279279
*/
280-
public function getClassXoopsFormLabel($var, $param1 = '', $param2 = null, $isParam = false, $t = "\t\t")
280+
public function getClassXoopsFormLabel($var, $param1 = '', $param2 = null, $isParam = false, $t = "\t\t", $useParam = false)
281281
{
282282
$label = 'new \XoopsFormLabel(';
283-
$params = null != $param2 ? "{$param1}, {$param2}" : $param1;
283+
if (false === $useParam) {
284+
$params = null != $param2 ? "{$param1}, {$param2}" : $param1;
285+
} else {
286+
$params = null != $param2 ? "{$param1}, \${$param2}" : $param1;
287+
}
284288
if (false === $isParam) {
285289
$ret = "{$t}\${$var} = {$label}{$params});\n";
286290
} else {
@@ -326,7 +330,7 @@ public function getClassXoopsFormFile($var, $param1, $param2, $param3, $isParam
326330
*
327331
* @return string
328332
*/
329-
public function getClassXoopsFormHidden($var, $param1, $param2, $isForm = false, $isParam = false, $t = "\t\t")
333+
public function getClassXoopsFormHidden($var, $param1, $param2, $isForm = false, $isParam = false, $t = "\t\t", $useParam = false)
330334
{
331335
$hidden = 'new \XoopsFormHidden( ';
332336
$getVarHidden = Tdmcreate\Files\CreateXoopsCode::getInstance()->getXcGetVar('', 'this', $param2, true);
@@ -337,7 +341,11 @@ public function getClassXoopsFormHidden($var, $param1, $param2, $isForm = false,
337341
if (false === $isForm) {
338342
$ret .= "{$hidden}{$param1}, {$param2} )";
339343
} else {
340-
$ret .= "{$hidden}'{$param1}', '{$param2}' )";
344+
if (false === $useParam) {
345+
$ret .= "{$hidden}'{$param1}', '{$param2}' )";
346+
} else {
347+
$ret .= "{$hidden}'{$param1}', \${$param2} )";
348+
}
341349
}
342350
}
343351

class/Files/Language/LanguageAdmin.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function getLanguageAdminPages($language, $tables)
140140
* @param string $tables
141141
* @return string
142142
*/
143-
public function getLanguageAdminClass($language, $tables)
143+
public function getLanguageAdminClass($language, $tables, $moduleDirname)
144144
{
145145
$ret = $this->defines->getAboveHeadDefines('Admin Classes');
146146

@@ -193,17 +193,18 @@ public function getLanguageAdminClass($language, $tables)
193193
$ret .= $this->defines->getDefine($language, 'FORM_URL_UPLOAD', "{$fieldNameDesc} in uploads files");
194194
break;
195195
case 13:
196-
$ret .= $this->defines->getDefine($language, "FORM_UPLOAD_IMAGE_{$stuTableName}", "{$fieldNameDesc} in uploads images");
196+
$ret .= $this->defines->getDefine($language, "FORM_UPLOAD_IMAGE_{$stuTableName}", "{$fieldNameDesc} in ./uploads/{$moduleDirname}/images/{$tableName}/ :");
197197
break;
198198
case 14:
199-
$ret .= $this->defines->getDefine($language, "FORM_UPLOAD_FILE_{$stuTableName}", "{$fieldNameDesc} in uploads files");
199+
$ret .= $this->defines->getDefine($language, "FORM_UPLOAD_FILE_{$stuTableName}", "{$fieldNameDesc} in ./uploads/{$moduleDirname}/files/{$tableName}/ :");
200200
break;
201201
}
202202
}
203203
}
204204
$ret .= $this->defines->getAboveDefines('General');
205205
$ret .= $this->defines->getDefine($language, 'FORM_UPLOAD', 'Upload file');
206-
$ret .= $this->defines->getDefine($language, 'FORM_IMAGE_PATH', 'Files in %s ');
206+
$ret .= $this->defines->getDefine($language, 'FORM_UPLOAD_NEW', 'Upload new file: ');
207+
$ret .= $this->defines->getDefine($language, 'FORM_IMAGE_PATH', 'Files in %s :');
207208
$ret .= $this->defines->getDefine($language, 'FORM_ACTION', 'Action');
208209
$ret .= $this->defines->getDefine($language, 'FORM_EDIT', 'Modification');
209210
$ret .= $this->defines->getDefine($language, 'FORM_DELETE', 'Clear');
@@ -271,7 +272,7 @@ public function render()
271272
if (is_array($tables)) {
272273
$content .= $this->getLanguageAdminIndex($language, $tables);
273274
$content .= $this->getLanguageAdminPages($language, $tables);
274-
$content .= $this->getLanguageAdminClass($language, $tables);
275+
$content .= $this->getLanguageAdminClass($language, $tables, $moduleDirname);
275276
}
276277
if (in_array(1, $tablePermissions)) {
277278
$content .= $this->getLanguageAdminPermissions($language);

class/Files/Language/LanguageModinfo.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,8 @@ private function getLanguagePermissionsGroups($language)
405405
$ret .= $df->getDefine($language, 'GROUPS_DESC', 'Select general access permission for groups.');
406406
$ret .= $df->getDefine($language, 'ADMIN_GROUPS', 'Admin Group Permissions');
407407
$ret .= $df->getDefine($language, 'ADMIN_GROUPS_DESC', 'Which groups have access to tools and permissions page');
408+
$ret .= $df->getDefine($language, 'UPLOAD_GROUPS', 'Upload Group Permissions');
409+
$ret .= $df->getDefine($language, 'UPLOAD_GROUPS_DESC', 'Which groups have permissions to upload files');
408410

409411
return $ret;
410412
}

class/Files/User/UserXoopsVersion.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ private function getXoopsVersionConfig($module, $tables, $language)
540540
$ret .= $xCodeVConfig->getXcEqualsOperator('$xoopsGroups ', '$memberHandler->getGroupList()');
541541
$group = $xCodeVConfig->getXcEqualsOperator('$groups[$group] ', '$key', null, false, "\t");
542542
$ret .= $phpCodeVConfig->getPhpCodeForeach('xoopsGroups', false, 'key', 'group', $group);
543+
$ret .= $phpCodeVConfig->getPhpCodeCommentLine('General access groups');
543544
$groups = [
544545
'name' => "'groups'",
545546
'title' => "'{$language}GROUPS'",
@@ -551,6 +552,22 @@ private function getXoopsVersionConfig($module, $tables, $language)
551552
];
552553
$ret .= $uCodeVConfig->getUserModVersion(3, $groups, 'config', '$c');
553554
$ret .= $this->getSimpleString('++$c;');
555+
556+
$ret .= $phpCodeVConfig->getPhpCodeCommentLine('Upload groups');
557+
$uplgroups = [
558+
'name' => "'upload_groups'",
559+
'title' => "'{$language}UPLOAD_GROUPS'",
560+
'description' => "'{$language}UPLOAD_GROUPS_DESC'",
561+
'formtype' => "'select_multi'",
562+
'valuetype' => "'array'",
563+
'default' => '$groups',
564+
'options' => '$groups',
565+
];
566+
$ret .= $uCodeVConfig->getUserModVersion(3, $uplgroups, 'config', '$c');
567+
$ret .= $this->getSimpleString('++$c;');
568+
569+
570+
554571
$ret .= $phpCodeVConfig->getPhpCodeCommentLine('Get Admin groups');
555572
$ret .= $xCodeVConfig->getXcEqualsOperator('$criteria ', 'new \CriteriaCompo()');
556573
$ret .= $this->getSimpleString("\$criteria->add( new \Criteria( 'group_type', 'Admin' ) );");
@@ -560,8 +577,8 @@ private function getXoopsVersionConfig($module, $tables, $language)
560577
$ret .= $phpCodeVConfig->getPhpCodeForeach('adminXoopsGroups', false, 'key', 'adminGroup', $adminGroup);
561578
$adminGroups = [
562579
'name' => "'admin_groups'",
563-
'title' => "'{$language}GROUPS'",
564-
'description' => "'{$language}GROUPS_DESC'",
580+
'title' => "'{$language}ADMIN_GROUPS'",
581+
'description' => "'{$language}ADMIN_GROUPS_DESC'",
565582
'formtype' => "'select_multi'",
566583
'valuetype' => "'array'",
567584
'default' => '$adminGroups',

docs/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- fixed bug with save permissions in admin pages (goffy)
99
- fixed bugs in tpl creation (goffy)
1010
- improved tpl creation (goffy)
11+
- added check for upload permission to form class (goffy)
1112
*************************************************************
1213
THIS IS LAST VERSION WHICH CREATES MODULES WITHOUT NAMESPACES
1314
*************************************************************

0 commit comments

Comments
 (0)