♻️ Handle field management inside pageTypes
This commit is contained in:
parent
2b02949ff8
commit
e06b2397dc
6 changed files with 166 additions and 89 deletions
|
@ -1,5 +1,67 @@
|
|||
<?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
|
||||
{
|
||||
|
||||
|
|
|
@ -78,8 +78,9 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("Edit")." (".$contentType->plural
|
|||
</div>
|
||||
|
||||
<!-- 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 -->
|
||||
<?php
|
||||
$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 id="nav-general" class="tab-pane fade show active" role="tabpanel" aria-labelledby="general-tab">
|
||||
<?php
|
||||
if ($contentTypeKey == "article") {
|
||||
// Category
|
||||
echo Bootstrap::formSelectBlock(array(
|
||||
'name' => 'category',
|
||||
'label' => $L->g('Category'),
|
||||
'selected' => $page->categoryKey(),
|
||||
'class' => '',
|
||||
'emptyOption' => '- ' . $L->g('Uncategorized') . ' -',
|
||||
'options' => $categories->getKeyNameArray(),
|
||||
'mt'=>'mt-0'
|
||||
));
|
||||
|
||||
// Tags
|
||||
echo Bootstrap::formInputTextBlock(array(
|
||||
'name' => 'tags',
|
||||
'label' => $L->g('Tags'),
|
||||
'placeholder' => '',
|
||||
'tip' => $L->g('Write the tags separated by comma'),
|
||||
'value' => $page->tags()
|
||||
));
|
||||
}
|
||||
// Category
|
||||
echo ContentPage::formSelectBlock($contentType,array(
|
||||
'name' => 'category',
|
||||
'label' => $L->g('Category'),
|
||||
'selected' => $page->categoryKey(),
|
||||
'class' => '',
|
||||
'emptyOption' => '- ' . $L->g('Uncategorized') . ' -',
|
||||
'options' => $categories->getKeyNameArray(),
|
||||
'mt'=>'mt-0'
|
||||
));
|
||||
|
||||
// Tags
|
||||
echo ContentPage::formInputTextBlock($contentType,array(
|
||||
'name' => 'tags',
|
||||
'label' => $L->g('Tags'),
|
||||
'placeholder' => '',
|
||||
'tip' => $L->g('Write the tags separated by comma'),
|
||||
'value' => $page->tags()
|
||||
));
|
||||
|
||||
// Description
|
||||
echo Bootstrap::formTextareaBlock(array(
|
||||
echo ContentPage::formTextareaBlock($contentType,array(
|
||||
'name' => 'description',
|
||||
'label' => $L->g('Description'),
|
||||
'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')
|
||||
));
|
||||
|
||||
if ($contentTypeKey == "article") {
|
||||
// Sticky
|
||||
echo Bootstrap::formCheckbox(array(
|
||||
'name' => 'sticky',
|
||||
'label' => $L->g('Sticky'),
|
||||
'labelForCheckbox' => $L->g('Put this article in first position in the article list.'),
|
||||
'placeholder' => '',
|
||||
'checked' => $page->sticky(),
|
||||
'tip' => ""
|
||||
));
|
||||
}
|
||||
// Sticky
|
||||
echo ContentPage::formCheckbox($contentType,array(
|
||||
'name' => 'sticky',
|
||||
'label' => $L->g('Sticky'),
|
||||
'labelForCheckbox' => $L->g('Put this article in first position in the article list.'),
|
||||
'placeholder' => '',
|
||||
'checked' => $page->sticky(),
|
||||
'tip' => ""
|
||||
));
|
||||
?>
|
||||
|
||||
|
||||
<?php if ($contentType->canShow('cover')): ?>
|
||||
|
||||
<!-- Cover Image -->
|
||||
<?php
|
||||
$coverImage = $page->coverImage(false);
|
||||
|
@ -210,11 +210,12 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("Edit")." (".$contentType->plural
|
|||
});
|
||||
});
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div id="nav-advanced" class="tab-pane fade" role="tabpanel" aria-labelledby="advanced-tab">
|
||||
<?php
|
||||
// Date
|
||||
echo Bootstrap::formInputTextBlock(array(
|
||||
echo ContentPage::formInputTextBlock($contentType, array(
|
||||
'name' => 'date',
|
||||
'label' => $L->g('Date'),
|
||||
'placeholder' => '',
|
||||
|
@ -224,7 +225,7 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("Edit")." (".$contentType->plural
|
|||
));
|
||||
|
||||
// Position
|
||||
echo Bootstrap::formInputTextBlock(array(
|
||||
echo ContentPage::formInputTextBlock($contentType, array(
|
||||
'name' => 'position',
|
||||
'label' => $L->g('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) {
|
||||
// continue
|
||||
}
|
||||
echo Bootstrap::formSelectBlock(array(
|
||||
echo ContentPage::formSelectBlock($contentType,array(
|
||||
'name' => 'parent',
|
||||
'label' => $L->g('Parent'),
|
||||
'options' => $options,
|
||||
|
@ -290,7 +291,7 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("Edit")." (".$contentType->plural
|
|||
<?php
|
||||
|
||||
// Template
|
||||
echo Bootstrap::formInputTextBlock(array(
|
||||
echo ContentPage::formInputTextBlock($contentType, array(
|
||||
'name' => 'template',
|
||||
'label' => $L->g('Template'),
|
||||
'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.')
|
||||
));
|
||||
|
||||
echo Bootstrap::formInputTextBlock(array(
|
||||
echo ContentPage::formInputTextBlock($contentType, array(
|
||||
'name' => 'externalCoverImage',
|
||||
'label' => $L->g('External cover image'),
|
||||
'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">
|
||||
<?php
|
||||
// Friendly URL
|
||||
echo Bootstrap::formInputTextBlock(array(
|
||||
echo ContentPage::formInputTextBlock($contentType, array(
|
||||
'name' => 'slug',
|
||||
'tip' => $L->g('URL associated with the content'),
|
||||
'label' => $L->g('Friendly URL'),
|
||||
|
@ -374,7 +375,7 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("Edit")." (".$contentType->plural
|
|||
));
|
||||
|
||||
// Robots
|
||||
echo Bootstrap::formCheckbox(array(
|
||||
echo ContentPage::formCheckbox($contentType, array(
|
||||
'name' => 'noindex',
|
||||
'label' => 'Robots',
|
||||
'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
|
||||
echo Bootstrap::formCheckbox(array(
|
||||
echo ContentPage::formCheckbox($contentType, array(
|
||||
'name' => 'nofollow',
|
||||
'label' => '',
|
||||
'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
|
||||
echo Bootstrap::formCheckbox(array(
|
||||
echo ContentPage::formCheckbox($contentType, array(
|
||||
'name' => 'noarchive',
|
||||
'label' => '',
|
||||
'labelForCheckbox' => $L->g('apply-code-noarchive-code-to-this-page'),
|
||||
|
|
|
@ -71,7 +71,9 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("New")." (".$contentType->plural(
|
|||
</div>
|
||||
|
||||
<!-- 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 -->
|
||||
<?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 id="nav-general" class="tab-pane fade show active" role="tabpanel" aria-labelledby="general-tab">
|
||||
<?php
|
||||
if ($contentTypeKey == "article") {
|
||||
// Category
|
||||
echo Bootstrap::formSelectBlock(array(
|
||||
'name' => 'category',
|
||||
'label' => $L->g('Category'),
|
||||
'selected' => '',
|
||||
'class' => '',
|
||||
'emptyOption' => '- ' . $L->g('Uncategorized') . ' -',
|
||||
'options' => $categories->getKeyNameArray(),
|
||||
'mt' => 'mt-0'
|
||||
));
|
||||
// Category
|
||||
echo ContentPage::formSelectBlock($contentType, array(
|
||||
'name' => 'category',
|
||||
'label' => $L->g('Category'),
|
||||
'selected' => '',
|
||||
'class' => '',
|
||||
'emptyOption' => '- ' . $L->g('Uncategorized') . ' -',
|
||||
'options' => $categories->getKeyNameArray(),
|
||||
'mt' => 'mt-0'
|
||||
));
|
||||
|
||||
// Tags
|
||||
echo Bootstrap::formInputTextBlock(array(
|
||||
'name' => 'tags',
|
||||
'label' => $L->g('Tags'),
|
||||
'placeholder' => '',
|
||||
'tip' => $L->g('Write the tags separated by comma')
|
||||
));
|
||||
}
|
||||
// Tags
|
||||
echo ContentPage::formInputTextBlock($contentType, array(
|
||||
'name' => 'tags',
|
||||
'label' => $L->g('Tags'),
|
||||
'placeholder' => '',
|
||||
'tip' => $L->g('Write the tags separated by comma')
|
||||
));
|
||||
|
||||
// Description
|
||||
echo Bootstrap::formTextareaBlock(array(
|
||||
echo ContentPage::formTextareaBlock($contentType, array(
|
||||
'name' => 'description',
|
||||
'label' => $L->g('Description'),
|
||||
'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')
|
||||
));
|
||||
|
||||
if ($contentTypeKey == "article") {
|
||||
// Sticky
|
||||
echo Bootstrap::formCheckbox(array(
|
||||
'name' => 'sticky',
|
||||
'label' => $L->g('Sticky'),
|
||||
'labelForCheckbox' => $L->g('Put this article in first position in the article list.'),
|
||||
'placeholder' => '',
|
||||
'checked' => false,
|
||||
'tip' => ""
|
||||
));
|
||||
}
|
||||
// Sticky
|
||||
echo ContentPage::formCheckbox($contentType, array(
|
||||
'name' => 'sticky',
|
||||
'label' => $L->g('Sticky'),
|
||||
'labelForCheckbox' => $L->g('Put this article in first position in the article list.'),
|
||||
'placeholder' => '',
|
||||
'checked' => false,
|
||||
'tip' => ""
|
||||
));
|
||||
?>
|
||||
|
||||
<?php if ($contentType->canShow('cover')): ?>
|
||||
<!-- Cover Image -->
|
||||
<label class="mt-2 mb-0 pb-1 text-uppercase w-100"><?php $L->p('Cover Image') ?></label>
|
||||
<div>
|
||||
|
@ -194,11 +193,12 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("New")." (".$contentType->plural(
|
|||
});
|
||||
});
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div id="nav-advanced" class="tab-pane fade" role="tabpanel" aria-labelledby="advanced-tab">
|
||||
<?php
|
||||
// Date
|
||||
echo Bootstrap::formInputTextBlock(array(
|
||||
echo ContentPage::formInputTextBlock($contentType, array(
|
||||
'name' => 'date',
|
||||
'label' => $L->g('Date'),
|
||||
'placeholder' => '',
|
||||
|
@ -208,7 +208,7 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("New")." (".$contentType->plural(
|
|||
));
|
||||
|
||||
// Position
|
||||
echo Bootstrap::formInputTextBlock(array(
|
||||
echo ContentPage::formInputTextBlock($contentType, array(
|
||||
'name' => 'position',
|
||||
'label' => $L->g('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
|
||||
echo Bootstrap::formSelectBlock(array(
|
||||
echo ContentPage::formSelectBlock($contentType, array(
|
||||
'name' => 'parent',
|
||||
'label' => $L->g('Parent'),
|
||||
'options' => array(),
|
||||
|
@ -263,7 +263,7 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("New")." (".$contentType->plural(
|
|||
|
||||
<?php
|
||||
// Template
|
||||
echo Bootstrap::formInputTextBlock(array(
|
||||
echo ContentPage::formInputTextBlock($contentType, array(
|
||||
'name' => 'template',
|
||||
'label' => $L->g('Template'),
|
||||
'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.')
|
||||
));
|
||||
|
||||
echo Bootstrap::formInputTextBlock(array(
|
||||
echo ContentPage::formInputTextBlock($contentType, array(
|
||||
'name' => 'externalCoverImage',
|
||||
'label' => $L->g('External cover image'),
|
||||
'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">
|
||||
<?php
|
||||
// Friendly URL
|
||||
echo Bootstrap::formInputTextBlock(array(
|
||||
echo ContentPage::formInputTextBlock($contentType, array(
|
||||
'name' => 'slug',
|
||||
'tip' => $L->g('URL associated with the content'),
|
||||
'label' => $L->g('Friendly URL'),
|
||||
|
@ -357,7 +357,7 @@ echo Bootstrap::pageTitle(array('title'=>$L->g("New")." (".$contentType->plural(
|
|||
));
|
||||
|
||||
// Robots
|
||||
echo Bootstrap::formCheckbox(array(
|
||||
echo ContentPage::formCheckbox($contentType, array(
|
||||
'name' => 'noindex',
|
||||
'label' => 'Robots',
|
||||
'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
|
||||
echo Bootstrap::formCheckbox(array(
|
||||
echo ContentPage::formCheckbox($contentType, array(
|
||||
'name' => 'nofollow',
|
||||
'label' => '',
|
||||
'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
|
||||
echo Bootstrap::formCheckbox(array(
|
||||
echo ContentPage::formCheckbox($contentType, array(
|
||||
'name' => 'noarchive',
|
||||
'label' => '',
|
||||
'labelForCheckbox' => $L->g('apply-code-noarchive-code-to-this-page'),
|
||||
|
|
|
@ -57,5 +57,18 @@ class PageType
|
|||
{
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
|
@ -5,7 +5,8 @@ class PageTypes extends dbJSON {
|
|||
protected $dbFields = array(
|
||||
'name'=>'',
|
||||
'plural'=>'',
|
||||
'icon'=>'fa-file'
|
||||
'icon'=>'fa-file',
|
||||
'hideField'=>''
|
||||
);
|
||||
|
||||
function __construct()
|
||||
|
|
|
@ -469,9 +469,9 @@ function install($adminPassword, $timezone)
|
|||
file_put_contents(PATH_DATABASES . 'categories.php', $dataHead . json_encode($data, JSON_PRETTY_PRINT), LOCK_EX);
|
||||
|
||||
$data = array(
|
||||
'article' => array('name' => $L->g("Article"), 'plural' => $L->g("Articles"), 'icon'=>'file-text'),
|
||||
'static' => array('name' => $L->g("Static page"), 'plural' => $L->g("Static pages"), 'icon'=>'file'),
|
||||
'share' => array('name' => $L->g("Share"), 'plural' => $L->g("Shares"), 'icon'=>'retweet'),
|
||||
'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', 'hideFields'=>'category tags sticky'),
|
||||
'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);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue