Skip to content

Commit 23f3bb0

Browse files
committedOct 8, 2019
Add option to only allow content records to be placed in sysfolders
1 parent 98e6336 commit 23f3bb0

File tree

8 files changed

+124
-69
lines changed

8 files changed

+124
-69
lines changed
 

‎Classes/Controller/H5pModuleController.php

+34-13
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ class H5pModuleController extends ActionController
5151
*/
5252
public $perms_clause;
5353

54+
/**
55+
* @var bool
56+
*/
57+
protected $h5pContentAllowedOnPage = false;
58+
5459
/**
5560
* @var string
5661
*/
@@ -136,6 +141,15 @@ public function initializeAction()
136141
$this->isAccessibleForCurrentUser = false;
137142
}
138143

144+
// Get extension configuration
145+
$allowContentOnStandardPages = false;
146+
$extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['h5p']);
147+
if (!isset($extConf['onlyAllowRecordsInSysfolders']) || (int)$extConf['onlyAllowRecordsInSysfolders'] === 0) {
148+
$allowContentOnStandardPages = true;
149+
}
150+
$pageIsSysfolder = (int)$this->pageRecord['doktype'] === 254;
151+
$this->h5pContentAllowedOnPage = $allowContentOnStandardPages || $pageIsSysfolder;
152+
139153
// read configuration
140154
$modTS = $backendUser->getTSConfig('mod.recycler');
141155
if ($this->isCurrentUserAdmin()) {
@@ -233,14 +247,16 @@ protected function registerDocheaderButtons()
233247
->setGetVariables($getVars);
234248
$buttonBar->addButton($shortcutButton);
235249

236-
if (in_array($this->request->getControllerActionName(), ['content', 'index', 'show'])) {
237-
$title = $this->getLanguageService()->sL('LLL:EXT:h5p/Resources/Private/Language/locallang.xlf:module.menu.new');
238-
$icon = $this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-document-new', Icon::SIZE_SMALL);
239-
$addUserButton = $buttonBar->makeLinkButton()
240-
->setHref($this->getHref('H5pModule', 'new'))
241-
->setTitle($title)
242-
->setIcon($icon);
243-
$buttonBar->addButton($addUserButton, ButtonBar::BUTTON_POSITION_LEFT);
250+
if ($this->h5pContentAllowedOnPage) {
251+
if (in_array($this->request->getControllerActionName(), ['content', 'index', 'show'])) {
252+
$title = $this->getLanguageService()->sL('LLL:EXT:h5p/Resources/Private/Language/locallang.xlf:module.menu.new');
253+
$icon = $this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-document-new', Icon::SIZE_SMALL);
254+
$addUserButton = $buttonBar->makeLinkButton()
255+
->setHref($this->getHref('H5pModule', 'new'))
256+
->setTitle($title)
257+
->setIcon($icon);
258+
$buttonBar->addButton($addUserButton, ButtonBar::BUTTON_POSITION_LEFT);
259+
}
244260
}
245261

246262
if (in_array($this->request->getControllerActionName(), ['show'])) {
@@ -293,11 +309,13 @@ protected function generateMenu()
293309
'action' => 'content',
294310
'label' => $this->getLanguageService()->sL('LLL:EXT:h5p/Resources/Private/Language/locallang.xlf:module.menu.content')
295311
];
296-
$menuItems['new'] = [
297-
'controller' => 'H5pModule',
298-
'action' => 'new',
299-
'label' => $this->getLanguageService()->sL('LLL:EXT:h5p/Resources/Private/Language/locallang.xlf:module.menu.new')
300-
];
312+
if ($this->h5pContentAllowedOnPage) {
313+
$menuItems['new'] = [
314+
'controller' => 'H5pModule',
315+
'action' => 'new',
316+
'label' => $this->getLanguageService()->sL('LLL:EXT:h5p/Resources/Private/Language/locallang.xlf:module.menu.new')
317+
];
318+
}
301319
$menuItems['libraries'] = [
302320
'controller' => 'H5pModule',
303321
'action' => 'libraries',
@@ -336,6 +354,7 @@ public function indexAction()
336354
$contentRepository = $this->objectManager->get(ContentRepository::class);
337355
$content = $contentRepository->findAll();
338356

357+
$this->view->assign('h5pContentAllowedOnPage', $this->h5pContentAllowedOnPage);
339358
$this->view->assign('dateFormat', $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']);
340359
$this->view->assign('timeFormat', $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm']);
341360
$this->view->assign('id', $this->id);
@@ -357,6 +376,7 @@ public function contentAction()
357376
$contentRepository = $this->objectManager->get(ContentRepository::class);
358377
$content = $contentRepository->findByPid($this->id);
359378

379+
$this->view->assign('h5pContentAllowedOnPage', $this->h5pContentAllowedOnPage);
360380
$this->view->assign('dateFormat', $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']);
361381
$this->view->assign('timeFormat', $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm']);
362382
$this->view->assign('id', $this->id);
@@ -885,6 +905,7 @@ public function consentAction()
885905
public function newAction(int $contentId = 0)
886906
{
887907
$this->view->assign('didConsent', (int)$this->h5pFramework->getOption('hub_is_enabled') === 1);
908+
$this->view->assign('h5pContentAllowedOnPage', $this->h5pContentAllowedOnPage);
888909

889910
$this->view->getModuleTemplate()->getPageRenderer()->addInlineLanguageLabelFile('EXT:h5p/Resources/Private/Language/locallang.xlf');
890911
if ($this->isAccessibleForCurrentUser) {

‎Resources/Private/Language/locallang.xlf

+3
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@
298298
<trans-unit id="settings.displayCopyright">
299299
<source>Display Copyright button</source>
300300
</trans-unit>
301+
<trans-unit id="settings.onlyAllowRecordsInSysfolders">
302+
<source>Only allow H5P records in sysfolders: Keep your records organised</source>
303+
</trans-unit>
301304
<trans-unit id="module.menu.choose">
302305
<source>...</source>
303306
</trans-unit>

‎Resources/Private/Templates/H5pModule/Content.html

+10-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,16 @@ <h1><f:translate key="content_on_current_page"/></h1>
5353
</f:then>
5454
<f:else>
5555
<p>No H5P content available. You must upload or create new content.</p>
56-
<f:form action="new" controller="H5pModule">
57-
<f:form.button class="button" type="submit"><f:translate key="module.menu.new">Create</f:translate></f:form.button>
58-
</f:form>
56+
<f:if condition="{h5pContentAllowedOnPage}">
57+
<f:then>
58+
<f:form action="new" controller="H5pModule">
59+
<f:form.button class="button" type="submit"><f:translate key="module.menu.new">Create</f:translate></f:form.button>
60+
</f:form>
61+
</f:then>
62+
<f:else>
63+
<p>No H5P content allowed on this page, please navigate to a folder and add content there.</p>
64+
</f:else>
65+
</f:if>
5966
</f:else>
6067
</f:if>
6168
</f:section>

‎Resources/Private/Templates/H5pModule/Index.html

+10-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,16 @@ <h1>Content</h1>
5353
</f:then>
5454
<f:else>
5555
<p>No H5P content available. You must upload or create new content.</p>
56-
<f:form action="new" controller="H5pModule">
57-
<f:form.button class="button" type="submit"><f:translate key="module.menu.new">Create</f:translate></f:form.button>
58-
</f:form>
56+
<f:if condition="{h5pContentAllowedOnPage}">
57+
<f:then>
58+
<f:form action="new" controller="H5pModule">
59+
<f:form.button class="button" type="submit"><f:translate key="module.menu.new">Create</f:translate></f:form.button>
60+
</f:form>
61+
</f:then>
62+
<f:else>
63+
<p>No H5P content allowed on this page, please navigate to a folder and add content there.</p>
64+
</f:else>
65+
</f:if>
5966
</f:else>
6067
</f:if>
6168
</f:section>

‎Resources/Private/Templates/H5pModule/New.html

+54-47
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,63 @@
44
<f:section name="content">
55
<f:if condition="{didConsent}">
66
<f:then>
7-
<h1><f:translate key="module.menu.new">New</f:translate></h1>
8-
<f:flashMessages/>
7+
<f:if condition="{h5pContentAllowedOnPage}">
8+
<f:then>
9+
<h1><f:translate key="module.menu.new">New</f:translate></h1>
10+
<f:flashMessages/>
911

10-
<f:form method="post" enctype="multipart/form-data" id="h5p-content-form" action="create" controller="H5pModule">
11-
<div id="post-body-content">
12-
<div class="h5p-upload">
13-
<f:form.upload name="h5p_file" id="h5p-file"/>
14-
<div class="h5p-disable-file-check">
15-
<label><input type="checkbox" name="h5p_disable_file_check" id="h5p-disable-file-check"/> Disable
16-
file extension check</label>
17-
<div class="h5p-warning">Warning! This may have security implications as it allows for uploading php
18-
files. That in turn could make it possible for attackers to execute malicious code on your site.
19-
Please make sure you know exactly what you're uploading.
12+
<f:form method="post" enctype="multipart/form-data" id="h5p-content-form" action="create" controller="H5pModule">
13+
<div id="post-body-content">
14+
<div class="h5p-upload">
15+
<f:form.upload name="h5p_file" id="h5p-file"/>
16+
<div class="h5p-disable-file-check">
17+
<label><input type="checkbox" name="h5p_disable_file_check" id="h5p-disable-file-check"/> Disable
18+
file extension check</label>
19+
<div class="h5p-warning">Warning! This may have security implications as it allows for uploading php
20+
files. That in turn could make it possible for attackers to execute malicious code on your site.
21+
Please make sure you know exactly what you're uploading.
22+
</div>
23+
</div>
24+
</div>
25+
<div class="h5p-create">
26+
<div class="h5p-editor">Waiting for javascript...</div>
2027
</div>
2128
</div>
22-
</div>
23-
<div class="h5p-create">
24-
<div class="h5p-editor">Waiting for javascript...</div>
25-
</div>
26-
</div>
27-
<div class="postbox h5p-sidebar">
28-
<h2>Actions</h2>
29-
<div id="minor-publishing" style="display:none">
30-
<label><input type="radio" name="action" value="upload"/>Upload</label>
31-
<label><input type="radio" name="action" value="create"/>Create</label>
32-
<f:form.hidden name="library" value="{library}"/>
33-
<f:form.hidden name="parameters" value="{parameters}"/>
34-
</div>
35-
<div id="major-publishing-actions" class="submitbox">
36-
<input type="submit" name="submit-button" value="Create" class="button button-primary button-large"/>
37-
</div>
38-
</div>
39-
<div class="postbox h5p-sidebar">
40-
<h2>Display Options</h2>
41-
<div class="h5p-action-bar-settings h5p-panel">
42-
<label>
43-
<f:form.checkbox name="frame" value="true" checked="checked"/>
44-
Display toolbar below content </label>
45-
<label title="If checked a reuse button will always be displayed for this content and allow users to download the content as an .h5p file">
46-
<f:form.checkbox name="download" value="true" checked="checked"/>
47-
Allow users to download the content </label>
48-
<label>
49-
<f:form.checkbox name="embed" value="true" checked="checked"/>
50-
Display Embed button </label>
51-
<label>
52-
<f:form.checkbox name="copyright" value="true" checked="checked"/>
53-
Display Copyright button </label>
54-
</div>
55-
</div>
56-
</f:form>
29+
<div class="postbox h5p-sidebar">
30+
<h2>Actions</h2>
31+
<div id="minor-publishing" style="display:none">
32+
<label><input type="radio" name="action" value="upload"/>Upload</label>
33+
<label><input type="radio" name="action" value="create"/>Create</label>
34+
<f:form.hidden name="library" value="{library}"/>
35+
<f:form.hidden name="parameters" value="{parameters}"/>
36+
</div>
37+
<div id="major-publishing-actions" class="submitbox">
38+
<input type="submit" name="submit-button" value="Create" class="button button-primary button-large"/>
39+
</div>
40+
</div>
41+
<div class="postbox h5p-sidebar">
42+
<h2>Display Options</h2>
43+
<div class="h5p-action-bar-settings h5p-panel">
44+
<label>
45+
<f:form.checkbox name="frame" value="true" checked="checked"/>
46+
Display toolbar below content </label>
47+
<label title="If checked a reuse button will always be displayed for this content and allow users to download the content as an .h5p file">
48+
<f:form.checkbox name="download" value="true" checked="checked"/>
49+
Allow users to download the content </label>
50+
<label>
51+
<f:form.checkbox name="embed" value="true" checked="checked"/>
52+
Display Embed button </label>
53+
<label>
54+
<f:form.checkbox name="copyright" value="true" checked="checked"/>
55+
Display Copyright button </label>
56+
</div>
57+
</div>
58+
</f:form>
59+
</f:then>
60+
<f:else>
61+
<p>No H5P content allowed on this page, please navigate to a folder and add content there.</p>
62+
</f:else>
63+
</f:if>
5764
</f:then>
5865
<f:else>
5966
<f:form method="post" enctype="multipart/form-data" id="h5p-content-form" action="consent" controller="H5pModule">

‎ext_conf_template.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# cat=basic/enable/010; type=boolean; label=LLL:EXT:h5p/Resources/Private/Language/locallang.xlf:settings.toolbarBelowContent:
32
toolbarBelowContent = 1
43
# cat=basic/enable/020; type=boolean; label=LLL:EXT:h5p/Resources/Private/Language/locallang.xlf:settings.allowDownload:
@@ -7,3 +6,5 @@ allowDownload = 1
76
displayEmbed = 1
87
# cat=basic/enable/040; type=boolean; label=LLL:EXT:h5p/Resources/Private/Language/locallang.xlf:settings.displayCopyright:
98
displayCopyright = 1
9+
# cat=basic/enable/050; type=boolean; label=LLL:EXT:h5p/Resources/Private/Language/locallang.xlf:settings.onlyAllowRecordsInSysfolders:
10+
onlyAllowRecordsInSysfolders = 0

‎ext_emconf.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
'dependencies' => '',
1212
'state' => 'stable',
1313
'uploadfolder' => 0,
14-
'version' => '0.1.2',
14+
'version' => '0.2.2',
1515
'constraints' => [
1616
'depends' => [
1717
'typo3' => '7.0.0-9.5.99',

‎ext_tables.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,14 @@
4141
['source' => 'EXT:h5p/ext_icon.gif']
4242
);
4343

44+
call_user_func(
45+
function ($extKey) {
46+
$extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extKey]);
47+
if (!isset($extConf['onlyAllowRecordsInSysfolders']) || (int)$extConf['onlyAllowRecordsInSysfolders'] === 0) {
48+
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages('tx_h5p_domain_model_content');
49+
}
50+
},
51+
'h5p'
52+
);
53+
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages('tx_h5p_domain_model_configsetting');
4454
}
45-
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages('tx_h5p_domain_model_configsetting');

0 commit comments

Comments
 (0)