bludit/bl-kernel/admin/views/new-content.php

434 lines
12 KiB
PHP
Raw Normal View History

<?php defined('BLUDIT') or die('Bludit CMS.'); ?>
2018-10-17 22:35:30 +02:00
<?php
// FORM START
echo Bootstrap::formOpen(array(
'id'=>'jsform',
'class'=>'d-flex flex-column h-100'
));
// Token CSRF
echo Bootstrap::formInputHidden(array(
'name'=>'tokenCSRF',
'value'=>$security->getTokenCSRF()
));
// Parent
echo Bootstrap::formInputHidden(array(
'name'=>'parent',
'value'=>''
));
// UUID
// The UUID is generated in the controller
echo Bootstrap::formInputHidden(array(
'name'=>'uuid',
'value'=>$uuid
));
// Type = published, draft, sticky, static
echo Bootstrap::formInputHidden(array(
'name'=>'type',
'value'=>'published'
));
// Cover image
echo Bootstrap::formInputHidden(array(
'name'=>'coverImage',
'value'=>''
));
// Content
echo Bootstrap::formInputHidden(array(
'name'=>'content',
'value'=>''
));
?>
<!-- TOOLBAR -->
<div>
<div class="btn-group btn-group-sm" role="group" aria-label="Basic example">
<button type="button" class="btn btn-light" id="jsmediaManagerOpenModal" data-toggle="modal" data-target="#jsmediaManagerModal"><?php $L->p('Images') ?></button>
<button type="button" class="btn btn-light" id="jscoverImageOpenModal" data-toggle="modal" data-target="#jscoverImageModal"><?php $L->p('Cover image') ?></button>
<button type="button" class="btn btn-light" id="jscategoryOpenModal" data-toggle="modal" data-target="#jscategoryModal"><?php $L->p('Category') ?><span class="option"></span></button>
<button type="button" class="btn btn-light" id="jsdescriptionOpenModal" data-toggle="modal" data-target="#jsdescriptionModal"><?php $L->p('Description') ?><span class="option"></span></button>
<button type="button" class="btn btn-light" id="jsoptionsOpenModal" data-toggle="modal" data-target="#jsoptionsModal"><?php $L->p('More options') ?></button>
</div>
2018-10-17 22:35:30 +02:00
<div class="btn-group btn-group-sm float-right" role="group" aria-label="Basic example">
<button type="button" class="btn btn-primary" id="jsbuttonSave"><?php $L->p('Publish') ?></button>
<button type="button" class="btn btn-secondary" id="jsbuttonDraft"><?php $L->p('Save as draft') ?></button>
<a href="<?php echo HTML_PATH_ADMIN_ROOT ?>dashboard" class="btn btn-secondary"><?php $L->p('Cancel') ?></a>
</div>
</div>
<!-- Title -->
<div class="form-group mt-1 mb-1">
<input id="jstitle" name="title" type="text" class="form-control form-control-lg rounded-0" value="" placeholder="<?php $L->p('Enter title') ?>">
</div>
<!-- Editor -->
2018-10-18 22:40:35 +02:00
<div id="jseditor" class="editable h-100 mb-1"></div>
2018-10-17 22:35:30 +02:00
<!-- Modal for Cover Image -->
<div id="jscoverImageModal" class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><?php $L->p('Cover Image') ?></h5>
</div>
2018-10-17 22:35:30 +02:00
<div class="modal-body">
<div>
<img id="jscoverImagePreview" style="width: 350px; height: 200px;" class="mx-auto d-block" alt="Cover image preview" src="<?php echo HTML_PATH_ADMIN_THEME_IMG ?>default.svg" />
</div>
<div class="mt-2 text-center">
<button type="button" id="jsbuttonSelectCoverImage" class="btn btn-primary btn-sm"><?php echo $L->g('Select cover image') ?></button>
<button type="button" id="jsbuttonRemoveCoverImage" class="btn btn-secondary btn-sm"><?php echo $L->g('Remove cover image') ?></button>
</div>
2018-10-17 22:35:30 +02:00
<hr>
2018-10-17 22:35:30 +02:00
<?php
echo Bootstrap::formTitle(array('title'=>$L->g('External Cover Image')));
2018-07-11 23:36:46 +02:00
2018-10-17 22:35:30 +02:00
echo Bootstrap::formInputTextBlock(array(
'name'=>'externalCoverImage',
'placeholder'=>"https://",
'value'=>'',
'tip'=>$L->g('Set a cover image from external URL, such as a CDN or some server dedicated for images.')
));
?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal"><?php $L->p('Done') ?></button>
</div>
</div>
</div>
2018-10-17 22:35:30 +02:00
<script>
$(document).ready(function() {
$("#jsexternalCoverImage").change(function() {
$("#jscoverImage").val( $(this).val() );
});
2018-07-07 12:04:34 +02:00
2018-10-17 22:35:30 +02:00
$("#jscoverImagePreview").on("click", function() {
openMediaManager();
});
$("#jsbuttonSelectCoverImage").on("click", function() {
openMediaManager();
});
$("#jsbuttonRemoveCoverImage").on("click", function() {
$("#jscoverImage").val('');
$("#jscoverImagePreview").attr('src', HTML_PATH_ADMIN_THEME_IMG+'default.svg');
});
});
</script>
</div>
<!-- Modal for Categories -->
<div id="jscategoryModal" class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><?php $L->p('Category') ?></h5>
</div>
<div class="modal-body">
<?php
echo Bootstrap::formSelectBlock(array(
'name'=>'category',
'label'=>'',
'selected'=>'',
'class'=>'',
'emptyOption'=>'- '.$L->g('Uncategorized').' -',
'options'=>$categories->getKeyNameArray()
));
?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal"><?php $L->p('Done') ?></button>
2018-07-07 12:04:34 +02:00
</div>
</div>
</div>
<script>
2018-07-10 18:37:46 +02:00
$(document).ready(function() {
function setCategoryBox(value) {
var selected = $("#jscategory option:selected");
var value = selected.val().trim();
if (value) {
2018-10-17 22:35:30 +02:00
$("#jscategoryOpenModal").find("span.option").html(": "+selected.text());
2018-07-10 18:37:46 +02:00
} else {
2018-10-17 22:35:30 +02:00
$("#jscategoryOpenModal").find("span.option").html("");
2018-07-07 12:04:34 +02:00
}
2018-07-10 18:37:46 +02:00
}
2018-07-07 12:04:34 +02:00
2018-07-10 18:37:46 +02:00
// Set the current category selected
setCategoryBox();
2018-07-07 12:04:34 +02:00
2018-07-10 18:37:46 +02:00
// When the user select the category update the category button
$("#jscategory").on("change", function() {
setCategoryBox();
2018-07-07 12:04:34 +02:00
});
2018-07-10 18:37:46 +02:00
});
2018-07-07 12:04:34 +02:00
</script>
2018-10-17 22:35:30 +02:00
</div>
<!-- Modal for Description -->
<div id="jsdescriptionModal" class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><?php $L->p('Description') ?></h5>
</div>
<div class="modal-body">
<?php
echo Bootstrap::formTextareaBlock(array(
'name'=>'description',
'label'=>'',
'selected'=>'',
'class'=>'',
'value'=>'',
'rows'=>3,
'placeholder'=>$L->get('this-field-can-help-describe-the-content')
));
?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal"><?php $L->p('Done') ?></button>
2018-07-07 12:04:34 +02:00
</div>
</div>
</div>
<script>
2018-07-10 18:37:46 +02:00
$(document).ready(function() {
function setDescriptionBox(value) {
var value = $("#jsdescription").val();
2018-10-17 22:35:30 +02:00
if (value) {
value = ": "+$.trim(value).substring(0, 30).split(" ").slice(0, -1).join(" ") + "...";
2018-07-07 12:04:34 +02:00
}
2018-10-17 22:35:30 +02:00
$("#jsdescriptionOpenModal").find("span.option").html(value);
2018-07-10 18:37:46 +02:00
}
2018-07-07 12:04:34 +02:00
2018-07-10 18:37:46 +02:00
// Set the current description
setDescriptionBox();
2018-07-07 12:04:34 +02:00
2018-07-10 18:37:46 +02:00
// When the user write the description update the description button
$("#jsdescription").on("change", function() {
setDescriptionBox();
2018-07-07 12:04:34 +02:00
});
2018-07-10 18:37:46 +02:00
});
2018-07-07 12:04:34 +02:00
</script>
2018-10-17 22:35:30 +02:00
</div>
<!-- Modal for More options -->
<div id="jsoptionsModal" class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><?php $L->p('More options') ?></h5>
</div>
<div class="modal-body">
<?php
// Username
echo Bootstrap::formInputText(array(
'name'=>'',
'label'=>$L->g('Author'),
'placeholder'=>'',
'value'=>$login->username(),
'tip'=>'',
'disabled'=>true
));
// Date
echo Bootstrap::formInputText(array(
'name'=>'date',
'label'=>$L->g('Date'),
'placeholder'=>'',
'value'=>Date::current(DB_DATE_FORMAT),
'tip'=>$L->g('date-format-format')
));
// Type
echo Bootstrap::formSelect(array(
'name'=>'typeTMP',
'label'=>$L->g('Type'),
'selected'=>'',
'options'=>array(
'published'=>'- '.$L->g('Default').' -',
'sticky'=>$L->g('Sticky'),
'static'=>$L->g('Static')
),
'tip'=>''
));
// Parent
echo Bootstrap::formInputText(array(
'name'=>'parentTMP',
'label'=>$L->g('Parent'),
'placeholder'=>'',
'tip'=>$L->g('Start typing a page title to see a list of suggestions.'),
'value'=>''
));
// Position
echo Bootstrap::formInputText(array(
'name'=>'position',
'label'=>$L->g('Position'),
'tip'=>$L->g('Field used when ordering content by position'),
'value'=>$pages->nextPositionNumber()
));
// Template
echo Bootstrap::formInputText(array(
'name'=>'template',
'label'=>$L->g('Template'),
'placeholder'=>'',
'value'=>'',
'tip'=>$L->g('Write a template name to filter the page in the theme and change the style of the page.')
));
// Tags
echo Bootstrap::formInputText(array(
'name'=>'tags',
'label'=>$L->g('Tags'),
'placeholder'=>'',
'tip'=>$L->g('Write the tags separated by comma')
));
echo Bootstrap::formTitle(array('title'=>$L->g('SEO')));
// Friendly URL
echo Bootstrap::formInputText(array(
'name'=>'slug',
'tip'=>$L->g('URL associated with the content'),
'label'=>$L->g('Friendly URL'),
'placeholder'=>$L->g('Leave empty for autocomplete by Bludit.')
));
echo Bootstrap::formCheckbox(array(
'name'=>'noindex',
'label'=>'Robots',
'labelForCheckbox'=>$L->g('apply-code-noindex-code-to-this-page'),
'placeholder'=>'',
'class'=>'mt-4',
'checked'=>false,
'tip'=>$L->g('This tells search engines not to show this page in their search results.')
));
echo Bootstrap::formCheckbox(array(
'name'=>'nofollow',
'label'=>'',
'labelForCheckbox'=>$L->g('apply-code-nofollow-code-to-this-page'),
'placeholder'=>'',
'checked'=>false,
'tip'=>$L->g('This tells search engines not to follow links on this page.')
));
echo Bootstrap::formCheckbox(array(
'name'=>'noarchive',
'label'=>'',
'labelForCheckbox'=>$L->g('apply-code-noarchive-code-to-this-page'),
'placeholder'=>'',
'checked'=>false,
'tip'=>$L->g('This tells search engines not to save a cached copy of this page.')
));
?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal"><?php $L->p('Done') ?></button>
</div>
</div>
</div>
<script>
$(document).ready(function() {
// Generate slug when the user type the title
$("#jstitle").keyup(function() {
var text = $(this).val();
var parent = $("#jsparent").val();
var currentKey = "";
var ajax = new bluditAjax();
var callBack = $("#jsslug");
ajax.generateSlug(text, parent, currentKey, callBack);
});
// Datepicker
$("#jsdate").datetimepicker({format:DB_DATE_FORMAT});
// Parent autocomplete
var parentsXHR;
var parentsList; // Keep the parent list returned to get the key by the title page
$("#jsparentTMP").autoComplete({
minChars: 1,
source: function(term, response) {
// Prevent call inmediatly another ajax request
try { parentsXHR.abort(); } catch(e){}
// Get the list of parent pages by title (term)
parentsXHR = $.getJSON(HTML_PATH_ADMIN_ROOT+"ajax/get-parents", {query: term},
function(data) {
parentsList = data;
term = term.toLowerCase();
var matches = [];
for (var title in data) {
if (~title.toLowerCase().indexOf(term))
matches.push(title);
}
response(matches);
});
},
onSelect: function(event, term, item) {
// parentsList = array( pageTitle => pageKey )
var parentKey = parentsList[term];
$("#jsparent").attr("value", parentKey);
}
});
});
</script>
</div>
</form>
2015-05-05 03:00:01 +02:00
2018-07-10 18:37:46 +02:00
<!-- Modal for Media Manager -->
<?php include(PATH_ADMIN_THEMES.'booty/html/media.php'); ?>
2015-05-05 03:00:01 +02:00
<script>
$(document).ready(function() {
2017-01-10 17:43:38 +01:00
2018-10-17 22:35:30 +02:00
// Button Publish or Save
$("#jsbuttonSave").on("click", function() {
// Get the type
var type = $("#jstypeTMP option:selected").val();
$("#jstype").val(type);
2018-10-17 22:35:30 +02:00
// Get the content
2018-07-03 23:04:08 +02:00
$("#jscontent").val( editorGetContent() );
2018-10-17 22:35:30 +02:00
// Submit the form
2018-05-08 23:25:18 +02:00
$("#jsform").submit();
});
2017-01-10 17:43:38 +01:00
// Button Save as draft
2018-10-17 22:35:30 +02:00
$("#jsbuttonDraft").on("click", function() {
// Set the type as draft
$("#jstype").val("draft");
2018-05-08 23:25:18 +02:00
2018-10-17 22:35:30 +02:00
// Get the content
$("#jscontent").val( editorGetContent() );
2018-10-17 22:35:30 +02:00
// Submit the form
$("#jsform").submit();
2018-05-08 00:15:40 +02:00
});
// Autosave interval
2018-06-03 21:51:47 +02:00
// Autosave works when the content of the page is bigger than 100 characters
2018-05-08 00:15:40 +02:00
setInterval(function() {
var uuid = $("#jsuuid").val();
var title = $("#jstitle").val();
var content = editorGetContent();
var ajax = new bluditAjax();
// showAlert is the function to display an alert defined in alert.php
ajax.autosave(uuid, title, content, showAlert);
2018-07-07 12:04:34 +02:00
},1000*60*AUTOSAVE_INTERVAL);
2018-05-08 00:15:40 +02:00
2015-05-05 03:00:01 +02:00
});
</script>