♻️ Handle field management inside pageTypes

This commit is contained in:
Kazhnuz 2025-03-01 12:49:24 +01:00
parent 2b02949ff8
commit e06b2397dc
6 changed files with 166 additions and 89 deletions

View file

@ -1,5 +1,67 @@
<?php <?php
class ContentPage
{
private static function canShow($contentType, $args)
{
return $contentType->canShow($args['name']);
}
public static function formInputTextBlock($contentType, $args) {
if (ContentPage::canShow($contentType, $args)) {
return Bootstrap::formInputTextBlock($args);
}
return '';
}
public static function formInputFile($contentType, $args) {
if (ContentPage::canShow($contentType, $args)) {
return Bootstrap::formInputFile($args);
}
return '';
}
public static function formTextarea($contentType, $args) {
if (ContentPage::canShow($contentType, $args)) {
return Bootstrap::formTextarea($args);
}
return '';
}
public static function formTextareaBlock($contentType, $args) {
if (ContentPage::canShow($contentType, $args)) {
return Bootstrap::formTextareaBlock($args);
}
return '';
}
public static function formInputText($contentType, $args) {
if (ContentPage::canShow($contentType, $args)) {
return Bootstrap::formInputText($args);
}
return '';
}
public static function formCheckbox($contentType, $args) {
if (ContentPage::canShow($contentType, $args)) {
return Bootstrap::formCheckbox($args);
}
return '';
}
public static function formSelect($contentType, $args) {
if (ContentPage::canShow($contentType, $args)) {
return Bootstrap::formSelect($args);
}
return '';
}
public static function formSelectBlock($contentType, $args) {
if (ContentPage::canShow($contentType, $args)) {
return Bootstrap::formSelectBlock($args);
}
return '';
}
public static function formInputHidden($contentType, $args) {
if (ContentPage::canShow($contentType, $args)) {
return Bootstrap::formInputHidden($args);
}
return '';
}
}
class Bootstrap class Bootstrap
{ {

View file

@ -78,8 +78,9 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("Edit")." (".$contentType->plural
</div> </div>
<!-- Editor --> <!-- Editor -->
<textarea id="jseditor" class="editable h-100" style=""><?php echo $page->contentRaw(true) ?></textarea> <?php if ($contentType->canShow('content')): ?>
<textarea id="jseditor" class="editable h-100" style=""><?php echo $page->contentRaw(true) ?></textarea>
<?php endif; ?>
<!-- Custom fields: BOTTOM --> <!-- Custom fields: BOTTOM -->
<?php <?php
$customFields = $site->customFields(); $customFields = $site->customFields();
@ -131,30 +132,28 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("Edit")." (".$contentType->plural
<div class="tab-content pr-3 pl-3 pb-3 card-body"> <div class="tab-content pr-3 pl-3 pb-3 card-body">
<div id="nav-general" class="tab-pane fade show active" role="tabpanel" aria-labelledby="general-tab"> <div id="nav-general" class="tab-pane fade show active" role="tabpanel" aria-labelledby="general-tab">
<?php <?php
if ($contentTypeKey == "article") { // Category
// Category echo ContentPage::formSelectBlock($contentType,array(
echo Bootstrap::formSelectBlock(array( 'name' => 'category',
'name' => 'category', 'label' => $L->g('Category'),
'label' => $L->g('Category'), 'selected' => $page->categoryKey(),
'selected' => $page->categoryKey(), 'class' => '',
'class' => '', 'emptyOption' => '- ' . $L->g('Uncategorized') . ' -',
'emptyOption' => '- ' . $L->g('Uncategorized') . ' -', 'options' => $categories->getKeyNameArray(),
'options' => $categories->getKeyNameArray(), 'mt'=>'mt-0'
'mt'=>'mt-0' ));
));
// Tags
// Tags echo ContentPage::formInputTextBlock($contentType,array(
echo Bootstrap::formInputTextBlock(array( 'name' => 'tags',
'name' => 'tags', 'label' => $L->g('Tags'),
'label' => $L->g('Tags'), 'placeholder' => '',
'placeholder' => '', 'tip' => $L->g('Write the tags separated by comma'),
'tip' => $L->g('Write the tags separated by comma'), 'value' => $page->tags()
'value' => $page->tags() ));
));
}
// Description // Description
echo Bootstrap::formTextareaBlock(array( echo ContentPage::formTextareaBlock($contentType,array(
'name' => 'description', 'name' => 'description',
'label' => $L->g('Description'), 'label' => $L->g('Description'),
'selected' => '', 'selected' => '',
@ -164,19 +163,20 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("Edit")." (".$contentType->plural
'placeholder' => $L->get('this-field-can-help-describe-the-content') 'placeholder' => $L->get('this-field-can-help-describe-the-content')
)); ));
if ($contentTypeKey == "article") { // Sticky
// Sticky echo ContentPage::formCheckbox($contentType,array(
echo Bootstrap::formCheckbox(array( 'name' => 'sticky',
'name' => 'sticky', 'label' => $L->g('Sticky'),
'label' => $L->g('Sticky'), 'labelForCheckbox' => $L->g('Put this article in first position in the article list.'),
'labelForCheckbox' => $L->g('Put this article in first position in the article list.'), 'placeholder' => '',
'placeholder' => '', 'checked' => $page->sticky(),
'checked' => $page->sticky(), 'tip' => ""
'tip' => "" ));
));
}
?> ?>
<?php if ($contentType->canShow('cover')): ?>
<!-- Cover Image --> <!-- Cover Image -->
<?php <?php
$coverImage = $page->coverImage(false); $coverImage = $page->coverImage(false);
@ -210,11 +210,12 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("Edit")." (".$contentType->plural
}); });
}); });
</script> </script>
<?php endif; ?>
</div> </div>
<div id="nav-advanced" class="tab-pane fade" role="tabpanel" aria-labelledby="advanced-tab"> <div id="nav-advanced" class="tab-pane fade" role="tabpanel" aria-labelledby="advanced-tab">
<?php <?php
// Date // Date
echo Bootstrap::formInputTextBlock(array( echo ContentPage::formInputTextBlock($contentType, array(
'name' => 'date', 'name' => 'date',
'label' => $L->g('Date'), 'label' => $L->g('Date'),
'placeholder' => '', 'placeholder' => '',
@ -224,7 +225,7 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("Edit")." (".$contentType->plural
)); ));
// Position // Position
echo Bootstrap::formInputTextBlock(array( echo ContentPage::formInputTextBlock($contentType, array(
'name' => 'position', 'name' => 'position',
'label' => $L->g('Position'), 'label' => $L->g('Position'),
'tip' => $L->g('Field used when ordering content by position'), 'tip' => $L->g('Field used when ordering content by position'),
@ -242,7 +243,7 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("Edit")." (".$contentType->plural
} catch (Exception $e) { } catch (Exception $e) {
// continue // continue
} }
echo Bootstrap::formSelectBlock(array( echo ContentPage::formSelectBlock($contentType,array(
'name' => 'parent', 'name' => 'parent',
'label' => $L->g('Parent'), 'label' => $L->g('Parent'),
'options' => $options, 'options' => $options,
@ -290,7 +291,7 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("Edit")." (".$contentType->plural
<?php <?php
// Template // Template
echo Bootstrap::formInputTextBlock(array( echo ContentPage::formInputTextBlock($contentType, array(
'name' => 'template', 'name' => 'template',
'label' => $L->g('Template'), 'label' => $L->g('Template'),
'placeholder' => '', 'placeholder' => '',
@ -298,7 +299,7 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("Edit")." (".$contentType->plural
'tip' => $L->g('Write a template name to filter the page in the theme and change the style of the page.') 'tip' => $L->g('Write a template name to filter the page in the theme and change the style of the page.')
)); ));
echo Bootstrap::formInputTextBlock(array( echo ContentPage::formInputTextBlock($contentType, array(
'name' => 'externalCoverImage', 'name' => 'externalCoverImage',
'label' => $L->g('External cover image'), 'label' => $L->g('External cover image'),
'placeholder' => "https://", 'placeholder' => "https://",
@ -364,7 +365,7 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("Edit")." (".$contentType->plural
<div id="nav-seo" class="tab-pane fade" role="tabpanel" aria-labelledby="seo-tab"> <div id="nav-seo" class="tab-pane fade" role="tabpanel" aria-labelledby="seo-tab">
<?php <?php
// Friendly URL // Friendly URL
echo Bootstrap::formInputTextBlock(array( echo ContentPage::formInputTextBlock($contentType, array(
'name' => 'slug', 'name' => 'slug',
'tip' => $L->g('URL associated with the content'), 'tip' => $L->g('URL associated with the content'),
'label' => $L->g('Friendly URL'), 'label' => $L->g('Friendly URL'),
@ -374,7 +375,7 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("Edit")." (".$contentType->plural
)); ));
// Robots // Robots
echo Bootstrap::formCheckbox(array( echo ContentPage::formCheckbox($contentType, array(
'name' => 'noindex', 'name' => 'noindex',
'label' => 'Robots', 'label' => 'Robots',
'labelForCheckbox' => $L->g('apply-code-noindex-code-to-this-page'), 'labelForCheckbox' => $L->g('apply-code-noindex-code-to-this-page'),
@ -384,7 +385,7 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("Edit")." (".$contentType->plural
)); ));
// Robots // Robots
echo Bootstrap::formCheckbox(array( echo ContentPage::formCheckbox($contentType, array(
'name' => 'nofollow', 'name' => 'nofollow',
'label' => '', 'label' => '',
'labelForCheckbox' => $L->g('apply-code-nofollow-code-to-this-page'), 'labelForCheckbox' => $L->g('apply-code-nofollow-code-to-this-page'),
@ -394,7 +395,7 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("Edit")." (".$contentType->plural
)); ));
// Robots // Robots
echo Bootstrap::formCheckbox(array( echo ContentPage::formCheckbox($contentType, array(
'name' => 'noarchive', 'name' => 'noarchive',
'label' => '', 'label' => '',
'labelForCheckbox' => $L->g('apply-code-noarchive-code-to-this-page'), 'labelForCheckbox' => $L->g('apply-code-noarchive-code-to-this-page'),

View file

@ -71,7 +71,9 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("New")." (".$contentType->plural(
</div> </div>
<!-- Editor --> <!-- Editor -->
<textarea id="jseditor" class="editable h-100 mb-1"></textarea> <?php if ($contentType->canShow('content')): ?>
<textarea id="jseditor" class="editable h-100 mb-1"></textarea>
<?php endif; ?>
<!-- Custom fields: BOTTOM --> <!-- Custom fields: BOTTOM -->
<?php <?php
@ -124,29 +126,27 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("New")." (".$contentType->plural(
<div class="tab-content pr-3 pl-3 pb-3"> <div class="tab-content pr-3 pl-3 pb-3">
<div id="nav-general" class="tab-pane fade show active" role="tabpanel" aria-labelledby="general-tab"> <div id="nav-general" class="tab-pane fade show active" role="tabpanel" aria-labelledby="general-tab">
<?php <?php
if ($contentTypeKey == "article") { // Category
// Category echo ContentPage::formSelectBlock($contentType, array(
echo Bootstrap::formSelectBlock(array( 'name' => 'category',
'name' => 'category', 'label' => $L->g('Category'),
'label' => $L->g('Category'), 'selected' => '',
'selected' => '', 'class' => '',
'class' => '', 'emptyOption' => '- ' . $L->g('Uncategorized') . ' -',
'emptyOption' => '- ' . $L->g('Uncategorized') . ' -', 'options' => $categories->getKeyNameArray(),
'options' => $categories->getKeyNameArray(), 'mt' => 'mt-0'
'mt' => 'mt-0' ));
));
// Tags // Tags
echo Bootstrap::formInputTextBlock(array( echo ContentPage::formInputTextBlock($contentType, array(
'name' => 'tags', 'name' => 'tags',
'label' => $L->g('Tags'), 'label' => $L->g('Tags'),
'placeholder' => '', 'placeholder' => '',
'tip' => $L->g('Write the tags separated by comma') 'tip' => $L->g('Write the tags separated by comma')
)); ));
}
// Description // Description
echo Bootstrap::formTextareaBlock(array( echo ContentPage::formTextareaBlock($contentType, array(
'name' => 'description', 'name' => 'description',
'label' => $L->g('Description'), 'label' => $L->g('Description'),
'selected' => '', 'selected' => '',
@ -156,19 +156,18 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("New")." (".$contentType->plural(
'placeholder' => $L->get('this-field-can-help-describe-the-content') 'placeholder' => $L->get('this-field-can-help-describe-the-content')
)); ));
if ($contentTypeKey == "article") { // Sticky
// Sticky echo ContentPage::formCheckbox($contentType, array(
echo Bootstrap::formCheckbox(array( 'name' => 'sticky',
'name' => 'sticky', 'label' => $L->g('Sticky'),
'label' => $L->g('Sticky'), 'labelForCheckbox' => $L->g('Put this article in first position in the article list.'),
'labelForCheckbox' => $L->g('Put this article in first position in the article list.'), 'placeholder' => '',
'placeholder' => '', 'checked' => false,
'checked' => false, 'tip' => ""
'tip' => "" ));
));
}
?> ?>
<?php if ($contentType->canShow('cover')): ?>
<!-- Cover Image --> <!-- Cover Image -->
<label class="mt-2 mb-0 pb-1 text-uppercase w-100"><?php $L->p('Cover Image') ?></label> <label class="mt-2 mb-0 pb-1 text-uppercase w-100"><?php $L->p('Cover Image') ?></label>
<div> <div>
@ -194,11 +193,12 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("New")." (".$contentType->plural(
}); });
}); });
</script> </script>
<?php endif; ?>
</div> </div>
<div id="nav-advanced" class="tab-pane fade" role="tabpanel" aria-labelledby="advanced-tab"> <div id="nav-advanced" class="tab-pane fade" role="tabpanel" aria-labelledby="advanced-tab">
<?php <?php
// Date // Date
echo Bootstrap::formInputTextBlock(array( echo ContentPage::formInputTextBlock($contentType, array(
'name' => 'date', 'name' => 'date',
'label' => $L->g('Date'), 'label' => $L->g('Date'),
'placeholder' => '', 'placeholder' => '',
@ -208,7 +208,7 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("New")." (".$contentType->plural(
)); ));
// Position // Position
echo Bootstrap::formInputTextBlock(array( echo ContentPage::formInputTextBlock($contentType, array(
'name' => 'position', 'name' => 'position',
'label' => $L->g('Position'), 'label' => $L->g('Position'),
'tip' => $L->g('Field used when ordering content by position'), 'tip' => $L->g('Field used when ordering content by position'),
@ -216,7 +216,7 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("New")." (".$contentType->plural(
)); ));
// Parent // Parent
echo Bootstrap::formSelectBlock(array( echo ContentPage::formSelectBlock($contentType, array(
'name' => 'parent', 'name' => 'parent',
'label' => $L->g('Parent'), 'label' => $L->g('Parent'),
'options' => array(), 'options' => array(),
@ -263,7 +263,7 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("New")." (".$contentType->plural(
<?php <?php
// Template // Template
echo Bootstrap::formInputTextBlock(array( echo ContentPage::formInputTextBlock($contentType, array(
'name' => 'template', 'name' => 'template',
'label' => $L->g('Template'), 'label' => $L->g('Template'),
'placeholder' => '', 'placeholder' => '',
@ -271,7 +271,7 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("New")." (".$contentType->plural(
'tip' => $L->g('Write a template name to filter the page in the theme and change the style of the page.') 'tip' => $L->g('Write a template name to filter the page in the theme and change the style of the page.')
)); ));
echo Bootstrap::formInputTextBlock(array( echo ContentPage::formInputTextBlock($contentType, array(
'name' => 'externalCoverImage', 'name' => 'externalCoverImage',
'label' => $L->g('External cover image'), 'label' => $L->g('External cover image'),
'placeholder' => "https://", 'placeholder' => "https://",
@ -348,7 +348,7 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("New")." (".$contentType->plural(
<div id="nav-seo" class="tab-pane fade" role="tabpanel" aria-labelledby="seo-tab"> <div id="nav-seo" class="tab-pane fade" role="tabpanel" aria-labelledby="seo-tab">
<?php <?php
// Friendly URL // Friendly URL
echo Bootstrap::formInputTextBlock(array( echo ContentPage::formInputTextBlock($contentType, array(
'name' => 'slug', 'name' => 'slug',
'tip' => $L->g('URL associated with the content'), 'tip' => $L->g('URL associated with the content'),
'label' => $L->g('Friendly URL'), 'label' => $L->g('Friendly URL'),
@ -357,7 +357,7 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("New")." (".$contentType->plural(
)); ));
// Robots // Robots
echo Bootstrap::formCheckbox(array( echo ContentPage::formCheckbox($contentType, array(
'name' => 'noindex', 'name' => 'noindex',
'label' => 'Robots', 'label' => 'Robots',
'labelForCheckbox' => $L->g('apply-code-noindex-code-to-this-page'), 'labelForCheckbox' => $L->g('apply-code-noindex-code-to-this-page'),
@ -367,7 +367,7 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("New")." (".$contentType->plural(
)); ));
// Robots // Robots
echo Bootstrap::formCheckbox(array( echo ContentPage::formCheckbox($contentType, array(
'name' => 'nofollow', 'name' => 'nofollow',
'label' => '', 'label' => '',
'labelForCheckbox' => $L->g('apply-code-nofollow-code-to-this-page'), 'labelForCheckbox' => $L->g('apply-code-nofollow-code-to-this-page'),
@ -377,7 +377,7 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("New")." (".$contentType->plural(
)); ));
// Robots // Robots
echo Bootstrap::formCheckbox(array( echo ContentPage::formCheckbox($contentType, array(
'name' => 'noarchive', 'name' => 'noarchive',
'label' => '', 'label' => '',
'labelForCheckbox' => $L->g('apply-code-noarchive-code-to-this-page'), 'labelForCheckbox' => $L->g('apply-code-noarchive-code-to-this-page'),

View file

@ -57,5 +57,18 @@ class PageType
{ {
return $this->getValue("plural"); return $this->getValue("plural");
} }
public function canShow($field)
{
$hideFields = $this->getValue("hideFields");
if ($hideFields === '' || !isset($hideFields))
{
return true;
}
return !str_contains($hideFields, $field);
}
public function mustHide($field)
{
return !$this->canShow($field);
}
} }

View file

@ -5,7 +5,8 @@ class PageTypes extends dbJSON {
protected $dbFields = array( protected $dbFields = array(
'name'=>'', 'name'=>'',
'plural'=>'', 'plural'=>'',
'icon'=>'fa-file' 'icon'=>'fa-file',
'hideField'=>''
); );
function __construct() function __construct()

View file

@ -469,9 +469,9 @@ function install($adminPassword, $timezone)
file_put_contents(PATH_DATABASES . 'categories.php', $dataHead . json_encode($data, JSON_PRETTY_PRINT), LOCK_EX); file_put_contents(PATH_DATABASES . 'categories.php', $dataHead . json_encode($data, JSON_PRETTY_PRINT), LOCK_EX);
$data = array( $data = array(
'article' => array('name' => $L->g("Article"), 'plural' => $L->g("Articles"), 'icon'=>'file-text'), 'article' => array('name' => $L->g("Article"), 'plural' => $L->g("Articles"), 'icon'=>'file-text', 'hideFields'=>''),
'static' => array('name' => $L->g("Static page"), 'plural' => $L->g("Static pages"), 'icon'=>'file'), 'static' => array('name' => $L->g("Static page"), 'plural' => $L->g("Static pages"), 'icon'=>'file', 'hideFields'=>'category tags sticky'),
'share' => array('name' => $L->g("Share"), 'plural' => $L->g("Shares"), 'icon'=>'retweet'), 'share' => array('name' => $L->g("Share"), 'plural' => $L->g("Shares"), 'icon'=>'retweet', 'hideFields'=>'content category cover position parent template externalCoverImage custom noindex nofollow noarchive'),
); );
file_put_contents(PATH_DATABASES . 'pagetypes.php', $dataHead . json_encode($data, JSON_PRETTY_PRINT), LOCK_EX); file_put_contents(PATH_DATABASES . 'pagetypes.php', $dataHead . json_encode($data, JSON_PRETTY_PRINT), LOCK_EX);