init
This commit is contained in:
+335
@@ -0,0 +1,335 @@
|
||||
<?php
|
||||
/**
|
||||
* Mageplaza
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Mageplaza.com license that is
|
||||
* available through the world-wide-web at this URL:
|
||||
* https://www.mageplaza.com/LICENSE.txt
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this extension to newer
|
||||
* version in the future.
|
||||
*
|
||||
* @category Mageplaza
|
||||
* @package Mageplaza_Blog
|
||||
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
|
||||
* @license https://www.mageplaza.com/LICENSE.txt
|
||||
*/
|
||||
|
||||
use Mageplaza\Blog\Block\Post\AuthorPost;
|
||||
use Mageplaza\Blog\Model\Post;
|
||||
use Magento\Framework\Escaper;
|
||||
|
||||
/** @var AuthorPost $block */
|
||||
/** @var Escaper $escaper */
|
||||
$postCollection = $block->getPostCollection();
|
||||
$modalViewModel = $viewModels->require(\Hyva\Theme\ViewModel\Modal::class);
|
||||
$postDatas = $block->getPostDatas($postCollection);
|
||||
$jsonData = json_encode($postDatas);
|
||||
|
||||
?>
|
||||
<?php if (!$block->getAuthorStatus()) : ?>
|
||||
<div>
|
||||
<h3><?= $escaper->escapeHtml(__('Your account must be licensed in order to perform the Post creation and management function')) ?></h3>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<div class="mp-blog-new-post" x-data="{
|
||||
...hyva.modal(),
|
||||
init() {
|
||||
window.openDialogNewPost = function (event) {
|
||||
this.show('add-new-post-name', event);
|
||||
}.bind(this);
|
||||
window.hideMyDialogNewPost = function (event) {
|
||||
this.hide('add-new-post-name', event);
|
||||
|
||||
}.bind(this);
|
||||
|
||||
|
||||
}
|
||||
}" x-init="init()">
|
||||
<button onclick="handleAddPost()" type="button" aria-haspopup="dialog"
|
||||
class="action primary btn btn-primary" title="<?= $escaper->escapeHtmlAttr(__('Add New Post')) ?>">
|
||||
<?= $escaper->escapeHtml(__('Add New Post')) ?>
|
||||
</button>
|
||||
<?= /** @noEscape */ $modalViewModel->createModal()
|
||||
->addDialogClass('overflow-y-hidden overflow-x-hidden fixed z-50 justify-center items-center w-3/4 md:inset-0 h-4/5')
|
||||
->removeDialogClass('p-10')
|
||||
->withDialogRefName("add-new-post-name")
|
||||
->withContent(<<<HTML
|
||||
<div id="mp-blog-new-post-popup">
|
||||
<header class="modal-header mb-3">
|
||||
<h3 id="popup_author_post" class="modal-title text-3xl border-b p-4" data-role="title">Add New Post</h3>
|
||||
</header>
|
||||
{$block->getChildHtml('mpblog_manage_post')}
|
||||
</div>
|
||||
HTML
|
||||
) ?>
|
||||
|
||||
</div>
|
||||
<div class="post-list-content" id="mpblog-list-container">
|
||||
<?php if ($postCollection && count($postCollection) > 0) : ?>
|
||||
<div class="post-list-body">
|
||||
<?php $i = 1 ?>
|
||||
<?php /** @var Post $post */
|
||||
foreach ($postCollection as $post) : ?>
|
||||
<div data-post-id="<?= $escaper->escapeHtml($post->getId()); ?>"
|
||||
class="post-list-item col-mp post-item-list mp-12">
|
||||
<div class="post-item-wraper">
|
||||
<?= /* @noEscape */
|
||||
$block->getStatusHtmlById($post->getEnabled()) ?>
|
||||
<?php if ($post->getImage()) : ?>
|
||||
<div class="post-image">
|
||||
<a href="<?= $escaper->escapeUrl($post->getUrl()) ?>">
|
||||
<img class="img-responsive"
|
||||
src="<?= $escaper->escapeUrl($block->resizeImage($post->getImage(),
|
||||
'400x')) ?>"
|
||||
alt="<?= $escaper->escapeHtmlAttr($post->getName()) ?>"/>
|
||||
</a>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="post-info-wraper">
|
||||
<h2 class="mp-post-title">
|
||||
<a class="post-link-title" title="<?= $escaper->escapeHtml($post->getName()); ?>"
|
||||
href="<?= $escaper->escapeUrl($post->getUrl()) ?>">
|
||||
<?= $escaper->escapeHtml($post->getName()) ?>
|
||||
</a>
|
||||
</h2>
|
||||
<div class="mp-post-info">
|
||||
<?= /* @noEscape */
|
||||
$block->getPostInfo($post) ?>
|
||||
</div>
|
||||
<div class="post-short-description">
|
||||
<p>
|
||||
<?= /* @noEscape */
|
||||
$block->maxShortDescription($post->getShortDescription()) ?>
|
||||
</p>
|
||||
</div>
|
||||
<div class="mp-clearfix"></div>
|
||||
<div class="mp-post-meta-info mp-alignright">
|
||||
<div class="actions">
|
||||
<a class="mp-read-more" href="<?= $escaper->escapeUrl($post->getUrl()) ?>"
|
||||
title="<?= $escaper->escapeHtmlAttr(__('Read More')) ?>">
|
||||
<?= $escaper->escapeHtml(__('Read More')) ?>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="post-info-action" data-postId="<?= $escaper->escapeHtml($post->getId()); ?>">
|
||||
<div class="mpblog-post-duplicate"
|
||||
onclick='handleDuplicate(this,<?= /** @noEscape */ $post->getId() ?>, "<?= /** @noEscape */ $post->getImage() ?>")'
|
||||
>
|
||||
<img
|
||||
src="<?= $escaper->escapeUrl($block->getViewFileUrl('Mageplaza_Blog::media/images/duplicate.svg')) ?>"
|
||||
align="middle"
|
||||
alt="<?= $escaper->escapeHtmlAttr(__('Duplicate')); ?>"
|
||||
title="<?= $escaper->escapeHtmlAttr(__('Duplicate')) ?>"
|
||||
/>
|
||||
</div>
|
||||
<div class="mpblog-post-edit"
|
||||
onclick='handleEdit(this,<?= /** @noEscape */ $post->getId() ?>, "<?= /** @noEscape */ $post->getImage() ?>")'
|
||||
>
|
||||
<img src="<?= $escaper->escapeUrl($block->getViewFileUrl('Mageplaza_Blog::media/images/writing.svg')) ?>"
|
||||
align="middle"
|
||||
alt="<?= $escaper->escapeHtmlAttr(__('Edit')); ?>"
|
||||
title="<?= $escaper->escapeHtmlAttr(__('Edit')) ?>"
|
||||
/>
|
||||
</div>
|
||||
<div class="mpblog-post-delete" onclick="handleDelete(this)">
|
||||
<img src="<?= $escaper->escapeUrl($block->getViewFileUrl('Mageplaza_Blog::media/images/delete.svg')) ?>"
|
||||
align="middle"
|
||||
alt="<?= $escaper->escapeHtmlAttr(__('Delete')) ?>"
|
||||
title="<?= $escaper->escapeHtmlAttr(__('Delete')) ?>"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php $i++; ?>
|
||||
<?php if ($i % 2 == 0) : ?>
|
||||
<div class="mp-clear"></div>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
<div class="mp-clear"></div>
|
||||
</div>
|
||||
<?= $block->getPagerHtml() ?>
|
||||
<?php else : ?>
|
||||
<?= $escaper->escapeHtml(__('There are no posts at this moment')) ?>
|
||||
<?php endif; ?>
|
||||
<?= /* @noEscape */
|
||||
$block->getChildHtml('additional') ?>
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
let pubUrl = "<?= $escaper->escapeHtml($block->getBaseMediaUrl()) ?>";
|
||||
let title = document.querySelector('#popup_author_post');
|
||||
let name = document.querySelector('#name');
|
||||
let post_id = document.querySelector('#post_id');
|
||||
let short_description = document.querySelector('#short_description');
|
||||
let allow_comment = document.querySelector('#allow_comment');
|
||||
let publish_date = document.querySelector('#publish_date');
|
||||
|
||||
function handleDelete (element) {
|
||||
var postId = element.closest('.post-info-action').getAttribute('data-postId');
|
||||
fetch("<?= $escaper->escapeHtml($block->getUrl('mpblog/post/deletepost')) ?>", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
"X-Requested-With": "XMLHttpRequest"
|
||||
},
|
||||
body: new URLSearchParams({
|
||||
post_id: postId
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(result => {
|
||||
if (result.status === 1) {
|
||||
var postListItem = document.querySelector('.post-list-item[data-post-id="' + result.post_id + '"]');
|
||||
if (postListItem) {
|
||||
postListItem.remove();
|
||||
const reloadCustomerDataEvent = new CustomEvent("reload-customer-section-data");
|
||||
window.dispatchEvent(reloadCustomerDataEvent);
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => console.error('Error:', error));
|
||||
}
|
||||
// open modal add new post
|
||||
function handleAddPost () {
|
||||
resetFormModal();
|
||||
title.innerText = 'Add New Post';
|
||||
openDialogNewPost();
|
||||
}
|
||||
// open modal edit new post
|
||||
function handleEdit (e, post_id, image) {
|
||||
resetFormModal();
|
||||
let listData = <?php echo /** @noEscape */ json_decode($jsonData) ?>;
|
||||
let dataSelect = listData[post_id];
|
||||
name.value = dataSelect?.name;
|
||||
post_id.value = dataSelect?.post_id;
|
||||
short_description.value = dataSelect?.short_description;
|
||||
editor.setData(dataSelect?.post_content ?? "");
|
||||
allow_comment.value = dataSelect?.allow_comment;
|
||||
publish_date.value = convertDateToDisplay(dataSelect?.publish_date);
|
||||
treeselectCategories.updateValue(dataSelect?.category_ids);
|
||||
|
||||
treeselectTags.updateValue(dataSelect?.tag_ids);
|
||||
treeselectTopics.updateValue(dataSelect?.topic_ids);
|
||||
addPreviewImg(image);
|
||||
|
||||
title.innerText = 'Edit Post';
|
||||
openDialogNewPost()
|
||||
}
|
||||
// open modal duplicate new post
|
||||
function handleDuplicate (e, post_id, image) {
|
||||
resetFormModal();
|
||||
let listData = <?php echo /** @noEscape */ json_decode($jsonData) ?>;
|
||||
let dataSelect = listData[post_id];
|
||||
name.value = dataSelect?.name;
|
||||
short_description.value = dataSelect?.short_description;
|
||||
editor.setData(dataSelect?.post_content ?? "");
|
||||
allow_comment.value = dataSelect?.allow_comment;
|
||||
publish_date.value = convertDateToDisplay(dataSelect?.publish_date);
|
||||
treeselectCategories.updateValue(dataSelect?.category_ids);
|
||||
treeselectTags.updateValue(dataSelect?.tag_ids);
|
||||
treeselectTopics.updateValue(dataSelect?.topic_ids);
|
||||
addPreviewImg(image);
|
||||
title.innerText = 'Duplicate Post';
|
||||
openDialogNewPost()
|
||||
}
|
||||
// reset data when hide modal
|
||||
function resetFormModal () {
|
||||
name.value = '';
|
||||
post_id.value = '';
|
||||
short_description.value = '';
|
||||
editor.setData("");
|
||||
allow_comment.value = 0;
|
||||
publish_date.value = '';
|
||||
treeselectCategories.updateValue([]);
|
||||
treeselectTags.updateValue([]);
|
||||
treeselectTopics.updateValue([]);
|
||||
var element = document.querySelector('.mp-image-link');
|
||||
if (element) {
|
||||
element.parentNode.removeChild(element);
|
||||
}
|
||||
let messagesError = document.querySelectorAll('#mp-blog-new-post-popup form .messages');
|
||||
messagesError.forEach(mess => {
|
||||
mess.remove()
|
||||
})
|
||||
}
|
||||
// add preview image when open modal edit and duplicate modal
|
||||
function addPreviewImg (value) {
|
||||
if (value) {
|
||||
const imageEl = document.getElementById("image")?.parentElement;
|
||||
var linkElement = document.createElement('a');
|
||||
linkElement.className = 'mp-image-link';
|
||||
linkElement.style = "margin-right: 15px";
|
||||
linkElement.href = pubUrl + 'mageplaza/blog/post/' + value;
|
||||
linkElement.onclick = function () {
|
||||
imagePreview('post_image_image');
|
||||
return false;
|
||||
};
|
||||
var imageElement = document.createElement('img');
|
||||
imageElement.src = pubUrl + 'mageplaza/blog/post/' + value;
|
||||
imageElement.id = 'post_image_image';
|
||||
imageElement.title = value;
|
||||
imageElement.alt = value;
|
||||
imageElement.height = 40;
|
||||
imageElement.width = 40;
|
||||
imageElement.className = 'small-image-preview v-middle';
|
||||
linkElement.appendChild(imageElement);
|
||||
if (imageEl) {
|
||||
imageEl.insertBefore(linkElement, imageEl.children[0]);
|
||||
}
|
||||
var deleteSpan = document.createElement('span');
|
||||
deleteSpan.className = 'delete-image';
|
||||
deleteSpan.style.display = 'inline-flex';
|
||||
var deleteInput = document.createElement('input');
|
||||
deleteInput.type = 'checkbox';
|
||||
deleteInput.name = 'image[delete]';
|
||||
deleteInput.value = '1';
|
||||
deleteInput.className = 'checkbox';
|
||||
deleteInput.id = 'post_image_delete';
|
||||
|
||||
var deleteLabel = document.createElement('label');
|
||||
deleteLabel.htmlFor = 'post_image_delete';
|
||||
deleteLabel.textContent = 'Delete Image';
|
||||
|
||||
deleteSpan.appendChild(deleteInput);
|
||||
deleteSpan.appendChild(deleteLabel);
|
||||
if (!imageEl.querySelector('.delete-image')) {
|
||||
imageEl.appendChild(deleteSpan);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// convert date in modal
|
||||
function convertDateToSave (publicDateValue) {
|
||||
var inputDate = new Date(publicDateValue);
|
||||
var formattedDate = ("0" + (inputDate.getMonth() + 1)).slice(-2) + '/' +
|
||||
("0" + inputDate.getDate()).slice(-2) + '/' +
|
||||
inputDate.getFullYear() + ' ' +
|
||||
("0" + inputDate.getHours()).slice(-2) + ':' +
|
||||
("0" + inputDate.getMinutes()).slice(-2) + ':' +
|
||||
("0" + inputDate.getSeconds()).slice(-2);
|
||||
return formattedDate
|
||||
}
|
||||
|
||||
function convertDateToDisplay (dateString) {
|
||||
var currentDate = new Date(dateString);
|
||||
var year = currentDate.getFullYear();
|
||||
var month = ('0' + (currentDate.getMonth() + 1)).slice(-2);
|
||||
var day = ('0' + currentDate.getDate()).slice(-2);
|
||||
var hours = ('0' + currentDate.getHours()).slice(-2);
|
||||
var minutes = ('0' + currentDate.getMinutes()).slice(-2);
|
||||
var formattedDateTime = year + '-' + month + '-' + day + 'T' + hours + ':' + minutes;
|
||||
return formattedDateTime;
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
+336
@@ -0,0 +1,336 @@
|
||||
<?php
|
||||
/**
|
||||
* Mageplaza
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Mageplaza.com license that is
|
||||
* available through the world-wide-web at this URL:
|
||||
* https://www.mageplaza.com/LICENSE.txt
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this extension to newer
|
||||
* version in the future.
|
||||
*
|
||||
* @category Mageplaza
|
||||
* @package Mageplaza_Blog
|
||||
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
|
||||
* @license https://www.mageplaza.com/LICENSE.txt
|
||||
*/
|
||||
|
||||
use Mageplaza\Blog\Block\Post\ManagePost;
|
||||
use Magento\Framework\Escaper;
|
||||
|
||||
/** @var ManagePost $block */
|
||||
/** @var Escaper $escaper */
|
||||
?>
|
||||
<button title="Close (Esc)" type="button" class="mfp-close" style="position: absolute;top: -5px;right: 10px;font-size: 25px;" onclick="hideMyDialogNewPost()">×</button>
|
||||
<form enctype="multipart/form-data" data-mage-init='{"validation": {}}'
|
||||
action="<?= $escaper->escapeHtml($block->getUrl('mpblog/post/manage')) ?>" method="post" class="form"
|
||||
name="mp_blog_post_form" id="mp_blog_post_form"
|
||||
style="overflow-y: auto; height: 700px"
|
||||
x-data="Object.assign(hyva.formValidation($el), initAddNewPost())"
|
||||
@submit.prevent="submitForm();"
|
||||
>
|
||||
<?= /* @noEscape */ $block->getBlockHtml('formkey'); ?>
|
||||
<fieldset class="fieldset">
|
||||
<div class="field required mp-field">
|
||||
<label for="name" class="label">
|
||||
<span>
|
||||
<b><?= $escaper->escapeHtml(__('Post Name')) ?></b>
|
||||
</span></label>
|
||||
<div class="control">
|
||||
<input type="text" name="name" id="name" title="<?= $escaper->escapeHtmlAttr(__('Post Name')) ?>"
|
||||
class="input-text" data-validate='{"required": true}'>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" name="post_id" id="post_id">
|
||||
<div class="field mp-field" style="margin-top: 1.5rem">
|
||||
<b for="short_description" class="label">
|
||||
<span><?= $escaper->escapeHtml(__('Short Description')) ?></span>
|
||||
</b>
|
||||
<div class="control">
|
||||
<textarea name="short_description" id="short_description" rows="5" cols="19" class="w-full"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field mp-field" style="margin-top: 1.5rem">
|
||||
<b for="post_content" class="label">
|
||||
<span><?= $escaper->escapeHtml(__('Post Content')) ?></span>
|
||||
</b>
|
||||
<div class="control">
|
||||
<textarea name="post_content" id="post_content" class="post_content_hyva" rows="5" cols="19">
|
||||
</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field mp-field" style="margin-top: 1.5rem">
|
||||
<label for="image" class="label"><b><?= $escaper->escapeHtml(__('Image')) ?></b></label>
|
||||
<div class="control" style="display: flex">
|
||||
<input type="file" name="image" id="image" title="<?= $escaper->escapeHtmlAttr(__('Image')) ?>"
|
||||
class="input-file">
|
||||
</div>
|
||||
</div>
|
||||
<div class="mp-custom">
|
||||
<div class="field mp-field" style="margin-top: 1.5rem">
|
||||
<label class="label"><span><?= $escaper->escapeHtml(__('Select Category')) ?></span></label>
|
||||
<div data-bind="scope: 'customCategory'">
|
||||
<div id="categories_ids"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field mp-field" style="margin-top: 1.5rem">
|
||||
<label class="label"><span><?= $escaper->escapeHtml(__('Select Topic')) ?></span></label>
|
||||
<div data-bind="scope: 'customTopic'">
|
||||
<div id="topics_ids"></div>
|
||||
<!-- ko template: getTemplate() --><!-- /ko -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="field mp-field" style="margin-top: 1.5rem">
|
||||
<label class="label"><span><?= $escaper->escapeHtml(__('Select Tag')) ?></span></label>
|
||||
<div data-bind="scope: 'customTag'">
|
||||
<div id="tags_ids"></div>
|
||||
<!-- ko template: getTemplate() --><!-- /ko -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field mp-field" style="margin-top: 1.5rem">
|
||||
<label for="allow_comment" class="label"><b><?= $escaper->escapeHtml(__('Allow Comment')) ?></b></label>
|
||||
<div class="control">
|
||||
<select id="allow_comment" name="allow_comment" class="w-full">
|
||||
<option value="0"><span><?= $escaper->escapeHtml(__('No')) ?></option>
|
||||
<option value="1"><span><?= $escaper->escapeHtml(__('Yes')) ?></option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field mp-field" style="margin-top: 1.5rem">
|
||||
<label for="publish_date" class="label"><b><?= $escaper->escapeHtml(__('Publish Date')) ?></b></label>
|
||||
<div class="control">
|
||||
<input name="publish_date" id="publish_date" type="datetime-local">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<?= $block->getChildHtml('field_additional') ?>
|
||||
</fieldset>
|
||||
<div class="actions-toolbar">
|
||||
<div class="primary">
|
||||
<button type="submit" class="action submit primary mpblog-action-new"
|
||||
title="<?= $escaper->escapeHtmlAttr(__('Save')) ?>">
|
||||
<span><?= $escaper->escapeHtml(__('Save')) ?></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<?php if ($block->checkTheme()) : ?>
|
||||
<style>
|
||||
.admin__action-multiselect-crumb .action-close:before {
|
||||
top: -6px;
|
||||
right: 8px;
|
||||
}
|
||||
|
||||
.admin__action-multiselect-menu-inner-item._root .action-menu-item .admin__action-multiselect-label:before {
|
||||
content: '\f846';
|
||||
font-family: 'porto-icons';
|
||||
}
|
||||
|
||||
.admin__action-multiselect-dropdown:before {
|
||||
content: '\f803';
|
||||
font-family: 'porto-icons';
|
||||
}
|
||||
|
||||
.admin__action-multiselect-tree .action-menu-item._expended .admin__action-multiselect-dropdown:before {
|
||||
right: 5px;
|
||||
position: absolute;
|
||||
content: '\f800';
|
||||
font-family: 'porto-icons';
|
||||
}
|
||||
|
||||
</style>
|
||||
<?php endif; ?>
|
||||
</form>
|
||||
<style>
|
||||
.ck-editor__editable {min-height: 300px;}
|
||||
</style>
|
||||
<script>
|
||||
CKEDITOR.ClassicEditor.create(document.getElementById("post_content"), {
|
||||
toolbar: {
|
||||
items: [
|
||||
'undo', 'redo', '|',
|
||||
'heading', '|',
|
||||
'bold', 'italic', 'strikethrough', 'underline', 'code', 'subscript', 'superscript', 'removeFormat', '|',
|
||||
'bulletedList', 'numberedList', 'todoList', '|',
|
||||
'alignment:left', 'alignment:right', 'alignment:center', 'alignment:justify', '|',
|
||||
'blockQuote', '|',
|
||||
'outdent', 'indent'
|
||||
],
|
||||
shouldNotGroupWhenFull: true
|
||||
},
|
||||
list: {
|
||||
properties: {
|
||||
styles: true,
|
||||
startIndex: true,
|
||||
reversed: true
|
||||
}
|
||||
},
|
||||
heading: {
|
||||
options: [
|
||||
{model: 'paragraph', title: 'Paragraph', class: 'ck-heading_paragraph'},
|
||||
{model: 'heading1', view: 'h1', title: 'Heading 1', class: 'ck-heading_heading1'},
|
||||
{model: 'heading2', view: 'h2', title: 'Heading 2', class: 'ck-heading_heading2'},
|
||||
{model: 'heading3', view: 'h3', title: 'Heading 3', class: 'ck-heading_heading3'},
|
||||
{model: 'heading4', view: 'h4', title: 'Heading 4', class: 'ck-heading_heading4'},
|
||||
{model: 'heading5', view: 'h5', title: 'Heading 5', class: 'ck-heading_heading5'},
|
||||
{model: 'heading6', view: 'h6', title: 'Heading 6', class: 'ck-heading_heading6'}
|
||||
]
|
||||
},
|
||||
placeholder: '',
|
||||
removePlugins: [
|
||||
'AIAssistant',
|
||||
'CKBox',
|
||||
'CKFinder',
|
||||
'EasyImage',
|
||||
'RealTimeCollaborativeComments',
|
||||
'RealTimeCollaborativeTrackChanges',
|
||||
'RealTimeCollaborativeRevisionHistory',
|
||||
'PresenceList',
|
||||
'Comments',
|
||||
'TrackChanges',
|
||||
'TrackChangesData',
|
||||
'RevisionHistory',
|
||||
'Pagination',
|
||||
'WProofreader',
|
||||
'MathType',
|
||||
'SlashCommand',
|
||||
'Template',
|
||||
'DocumentOutline',
|
||||
'FormatPainter',
|
||||
'TableOfContents',
|
||||
'PasteFromOfficeEnhanced'
|
||||
]
|
||||
}).then(editor => {
|
||||
window.editor = editor;
|
||||
}).catch(err => {
|
||||
console.error(err.stack);
|
||||
});
|
||||
|
||||
const categories = <?php echo /** @noEscape */ ($block->getCategoriesTree()) ?>;
|
||||
const topics = <?php echo /** @noEscape */ ($block->getTopicTree()) ?>;
|
||||
const tags = <?php echo /** @noEscape */ ($block->getTagTree()) ?>;
|
||||
const optionsCategories = categories?.map(data => {
|
||||
return {
|
||||
name: data?.label,
|
||||
value: data?.value
|
||||
}
|
||||
});
|
||||
const optionsTopics = Object.values(topics)?.map(data => {
|
||||
return {
|
||||
name: data?.label,
|
||||
value: data?.value
|
||||
}
|
||||
});
|
||||
const optionsTags = Object.values(tags)?.map(data => {
|
||||
return {
|
||||
name: data?.label,
|
||||
value: data?.value
|
||||
}
|
||||
});
|
||||
const domElementCategories = document.querySelector('#categories_ids');
|
||||
const treeselectCategories = new Treeselect({
|
||||
parentHtmlContainer: domElementCategories,
|
||||
options: optionsCategories,
|
||||
value: []
|
||||
|
||||
});
|
||||
const domElementTopics = document.querySelector('#topics_ids');
|
||||
const treeselectTopics = new Treeselect({
|
||||
parentHtmlContainer: domElementTopics,
|
||||
options: optionsTopics,
|
||||
value: []
|
||||
|
||||
});
|
||||
const domElementTags = document.querySelector('#tags_ids');
|
||||
const treeselectTags = new Treeselect({
|
||||
parentHtmlContainer: domElementTags,
|
||||
options: optionsTags,
|
||||
value: []
|
||||
|
||||
});
|
||||
treeselectTags.srcElement.addEventListener('input', (e) => {
|
||||
tags_ids = e.detail?.join(',')
|
||||
});
|
||||
function initAddNewPost () {
|
||||
return {
|
||||
errors: 0,
|
||||
hasCaptchaToken: 0,
|
||||
showPassword: false,
|
||||
displayErrorMessage: false,
|
||||
errorMessages: [],
|
||||
setErrorMessages (messages) {
|
||||
this.errorMessages = [messages];
|
||||
this.displayErrorMessage = this.errorMessages.length
|
||||
},
|
||||
submitForm () {
|
||||
this.validate()
|
||||
.then(() => {
|
||||
const $form = document.querySelector('#mp_blog_post_form');
|
||||
if (this.errors === 0) {
|
||||
this.dispatchAddNewPostRequest($form);
|
||||
}
|
||||
})
|
||||
.catch((invalid) => {
|
||||
if (invalid.length > 0) {
|
||||
invalid[0].focus();
|
||||
}
|
||||
});
|
||||
},
|
||||
dispatchAddNewPostRequest: function (form) {
|
||||
const formData = new FormData();
|
||||
var imageInput = document.querySelector('#image');
|
||||
if (imageInput?.files.length > 0) {
|
||||
formData.append('image', imageInput.files[0]);
|
||||
} else {
|
||||
var emptyBlob = new Blob([''], {type: 'application/octet-stream'});
|
||||
formData.append('image', emptyBlob, 'empty_image.txt');
|
||||
}
|
||||
formData.append('name', document.querySelector('#name').value);
|
||||
formData.append('post_id', document.querySelector('#post_id').value);
|
||||
formData.append('short_description', document.querySelector('#short_description').value);
|
||||
formData.append('post_content', document.querySelector('#post_content').value);
|
||||
|
||||
formData.append('categories_ids', treeselectCategories.value?.join(','));
|
||||
formData.append('topics_ids', treeselectTopics.value?.join(','));
|
||||
formData.append('tags_ids', treeselectTags.value?.join(','));
|
||||
formData.append('allow_comment', document.querySelector('#allow_comment').value);
|
||||
|
||||
const publicDateValue = document.querySelector('#publish_date').value;
|
||||
if(publicDateValue) {
|
||||
formData.append('publish_date', convertDateToSave(publicDateValue));
|
||||
} else {
|
||||
formData.append('publish_date', '');
|
||||
}
|
||||
var checkboxElement = document.getElementById("post_image_delete");
|
||||
if(checkboxElement && checkboxElement.checked) {
|
||||
formData.append(checkboxElement.name, checkboxElement.value);
|
||||
}
|
||||
var imgElement= document.getElementById("post_image_image");
|
||||
if(imgElement) {
|
||||
|
||||
formData.append('image', imgElement.title);
|
||||
}
|
||||
|
||||
fetch("<?= $escaper->escapeHtml($block->getUrl('mpblog/post/manage')) ?>", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"X-Requested-With": "XMLHttpRequest"
|
||||
},
|
||||
body: formData,
|
||||
mode: "cors",
|
||||
credentials: "include"
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(response => {
|
||||
window.location.reload();
|
||||
})
|
||||
.catch(error => console.error('Error:', error));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
/**
|
||||
* Mageplaza
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Mageplaza.com license that is
|
||||
* available through the world-wide-web at this URL:
|
||||
* https://www.mageplaza.com/LICENSE.txt
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this extension to newer
|
||||
* version in the future.
|
||||
*
|
||||
* @category Mageplaza
|
||||
* @package Mageplaza_Blog
|
||||
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
|
||||
* @license https://www.mageplaza.com/LICENSE.txt
|
||||
*/
|
||||
use Mageplaza\Blog\Block\Post\RelatedPost;
|
||||
use Mageplaza\Blog\Model\ResourceModel\Post\Collection;
|
||||
use Magento\Framework\Escaper;
|
||||
|
||||
/** @var Collection $posts */
|
||||
/** @var RelatedPost $block */
|
||||
/** @var Escaper $escaper */
|
||||
$posts = $block->getRelatedPostList();
|
||||
if ($posts && $block->isEnabledBlog()) : ?>
|
||||
<h2 class="text-xl"><?= $posts->getSize() ? $escaper->escapeHtml(__('Related Posts')) : $escaper->escapeHtml(__('No Related Posts')) ?></h2>
|
||||
<?php if ($block->getRelatedMode()) : ?>
|
||||
<div class="mp-blog-owl-carousel ">
|
||||
<section id="relatedposts-carousel" class="splide" aria-label="Related Posts">
|
||||
<div class="splide__track">
|
||||
<ul class="splide__list">
|
||||
<?php foreach ($posts as $post) : ?>
|
||||
<li class="splide__slide">
|
||||
<div class="item post-list-item col-mp post-item-list mp-4">
|
||||
<div class="post-item-wraper">
|
||||
<div class="post-info-wraper">
|
||||
<a href="<?= $escaper->escapeUrl($post->getUrl()) ?>">
|
||||
<img class="img-responsive"
|
||||
src="<?= $escaper->escapeUrl($block->resizeImage($post->getImage(),
|
||||
'400x')) ?>"
|
||||
alt="<?= $escaper->escapeHtml($post->getName()); ?>"/>
|
||||
</a>
|
||||
<h2 class="mp-post-title" style="margin: 20px 0;">
|
||||
<a class="post-link-title"
|
||||
title="<?= $escaper->escapeHtml($post->getName()); ?>"
|
||||
href="<?= $escaper->escapeUrl($post->getUrl()) ?>">
|
||||
<?= $escaper->escapeHtml($post->getName()) ?>
|
||||
</a>
|
||||
</h2>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
new Splide('#relatedposts-carousel', {
|
||||
perPage: 3,
|
||||
gap: 15,
|
||||
breakpoints: {
|
||||
1028: {
|
||||
perPage: 2
|
||||
}
|
||||
}
|
||||
}).mount();
|
||||
});
|
||||
</script>
|
||||
<?php else : ?>
|
||||
<ul class="relatedposts-list" style="list-style-type:disc; padding-left: 30px">
|
||||
<?php foreach ($posts as $post) : ?>
|
||||
<li>
|
||||
<a href="<?= $escaper->escapeUrl($post->getUrl()) ?>"><?= $escaper->escapeHtml($post->getName()) ?></a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
<style>
|
||||
.post-item-wraper:hover {
|
||||
border: 1px solid #eee;
|
||||
box-shadow: 3px 3px 4px 0 rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
.splide__pagination {
|
||||
bottom: -0.5em;
|
||||
}
|
||||
|
||||
.splide__arrow {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.splide__pagination__page.is-active {
|
||||
background: #869791
|
||||
}
|
||||
.post-item-wraper {
|
||||
border: 1px solid #eee;
|
||||
padding: 10px !important;
|
||||
|
||||
}
|
||||
#relatedposts-carousel, .relatedposts-list a:visited, .alink:visited {
|
||||
color: #006bb4;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
#relatedposts-carousel a:hover, .alink:hover {
|
||||
color: #006bb4;
|
||||
text-decoration: underline;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,959 @@
|
||||
<?php
|
||||
/**
|
||||
* Mageplaza
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Mageplaza.com license that is
|
||||
* available through the world-wide-web at this URL:
|
||||
* https://www.mageplaza.com/LICENSE.txt
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this extension to newer
|
||||
* version in the future.
|
||||
*
|
||||
* @category Mageplaza
|
||||
* @package Mageplaza_Blog
|
||||
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
|
||||
* @license https://www.mageplaza.com/LICENSE.txt
|
||||
*/
|
||||
|
||||
use Magento\Framework\Escaper;
|
||||
use Mageplaza\Blog\Block\Post\View;
|
||||
use Mageplaza\Blog\Helper\Image;
|
||||
use Mageplaza\Blog\Model\Config\Source\Comments\Type;
|
||||
|
||||
/** @var Escaper $escaper */
|
||||
/** @var View $block */
|
||||
$helper = $block->getBlogHelper();
|
||||
$_post = $block->getPost();
|
||||
$author = $helper->getAuthorByPost($_post);
|
||||
$authorName = $author !== null ? $author->getName() : '';
|
||||
$modifier = $helper->getAuthorByPost($_post, true);
|
||||
$modifierName = $modifier !== null ? $modifier->getName() : '';
|
||||
$isLogged = ($block->isLoggedIn()) ? 'Yes' : 'No';
|
||||
$color = $helper->getDisplayConfig('font_color');
|
||||
?>
|
||||
<div class="mp-blog-view">
|
||||
<!--div class="mp-blog-rss">
|
||||
<a href="<?= $escaper->escapeUrl($block->getRssUrl('post/rss')) ?>" class="bb-rss-icon">
|
||||
<img src="<?= $escaper->escapeUrl($block->getViewFileUrl('Mageplaza_Blog::media/images/rss.png')) ?>"
|
||||
width="16px">
|
||||
</a>
|
||||
</div-->
|
||||
<div class="mpcss post-view" id="mpblog-list-container">
|
||||
<div class="post-list-content col-md-12 col-sm-8">
|
||||
<div class="post-view-image col-xs-12">
|
||||
<?php if ($_post->getImage()) : ?>
|
||||
<img class="img-responsive" src="<?= $escaper->escapeUrl($block->getImageUrl($_post->getImage())) ?>"
|
||||
alt="<?= $escaper->escapeHtmlAttr($_post->getName()) ?>"/>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="post-post_content col-xs-12">
|
||||
<?= /** @noEscape */
|
||||
$block->getPageFilter($_post->getPostContent() ?: '') ?>
|
||||
</div>
|
||||
<div class="mp-clear"></div>
|
||||
<?= $block->getChildHtml('mp_blog_post_info') ?>
|
||||
|
||||
<?= $block->getChildHtml('mp_blog_post_slider') ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php if ($helper->isEnabledReview()) : ?>
|
||||
<div class="mp-blog-review-title">
|
||||
<span><?= $escaper->escapeHtml(__('Did you find it helpful?')) ?></span>
|
||||
</div>
|
||||
<div id="mp-blog-review">
|
||||
<div class="mp-blog-like" style="width: 155px">
|
||||
<i class="fa fa-thumbs-up" aria-hidden="true"></i>
|
||||
<span><?= $escaper->escapeHtml(__('LIKE')) ?></span>
|
||||
<span class="mp-blog-view">
|
||||
<?php if (!empty($block->getPostLike($_post->getId(), '1'))) : ?>
|
||||
(<?= $escaper->escapeHtml($block->getPostLike($_post->getId(), '1')) ?>)
|
||||
<?php endif; ?>
|
||||
</span>
|
||||
</div>
|
||||
<div class="mp-blog-dislike" style="width: 155px">
|
||||
<i class="fa fa-thumbs-down" aria-hidden="true"></i>
|
||||
<span><?= $escaper->escapeHtml(__('DISLIKE')) ?></span>
|
||||
<span class="mp-blog-view">
|
||||
<?php if (!empty($block->getPostLike($_post->getId(), '0'))) : ?>
|
||||
(<?= $escaper->escapeHtml($block->getPostLike($_post->getId(), '0')) ?>)
|
||||
<?php endif; ?>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mp-blog-review-label"></div>
|
||||
<script type="text/x-magento-init">
|
||||
{
|
||||
"#mp-blog-review": {
|
||||
"Mageplaza_Blog/js/helpful-rate": {
|
||||
"url": "<?= /* @noEscape */ $block->getUrl('mpblog/post/review') ?>",
|
||||
"post_id" : <?= /* @noEscape */ $_post->getId() ?>,
|
||||
"mode": <?= /* @noEscape */ $helper->getReviewMode() ?>
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
var options = {
|
||||
url: "<?= /* @noEscape */ $block->getUrl('mpblog/post/review') ?>",
|
||||
post_id: "<?= /* @noEscape */ $_post->getId() ?>",
|
||||
mode: "<?= /* @noEscape */ $helper->getReviewMode() ?>"
|
||||
};
|
||||
|
||||
function create () {
|
||||
const formKey = hyva.getFormKey();
|
||||
|
||||
var post_id = options.post_id,
|
||||
url = options.url,
|
||||
subPostId = {};
|
||||
if (options.mode === '1') {
|
||||
fetch(url, {
|
||||
"headers": {
|
||||
"content-type": "application/x-www-form-urlencoded; charset=UTF-8"
|
||||
},
|
||||
"body": "form_key=" + formKey + '&post_id=' + post_id + '&action=3&mode=' + options.mode,
|
||||
"method": "POST",
|
||||
"mode": "cors",
|
||||
"credentials": "include"
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(response => {
|
||||
if (response.status === 0) {
|
||||
disableReview(response.action);
|
||||
}
|
||||
})
|
||||
.catch(error => console.error('Error:', error));
|
||||
} else {
|
||||
var storedPostData = JSON.parse(getCookie('mpblog_post_data'));
|
||||
if (storedPostData) {
|
||||
subPostId = storedPostData;
|
||||
if (subPostId[post_id] !== undefined) {
|
||||
disableReview(subPostId[post_id].type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
document.querySelectorAll('#mp-blog-review div').forEach(function (el) {
|
||||
el.addEventListener('click', function () {
|
||||
var action = 0,
|
||||
currentPostIds = {},
|
||||
likeId = 0;
|
||||
|
||||
var storedPostIds = JSON.parse(getCookie('mpblog_post_data'));
|
||||
|
||||
if (this.classList.contains('mp-blog-like')) {
|
||||
action = 1;
|
||||
}
|
||||
|
||||
if (storedPostIds && storedPostIds[post_id] !== undefined && options.mode === '0') {
|
||||
likeId = storedPostIds[post_id].likeId;
|
||||
enableReview(storedPostIds[post_id].type);
|
||||
if (action === storedPostIds[post_id].type) {
|
||||
delete storedPostIds[post_id];
|
||||
document.cookie = 'mpblog_post_data=' + JSON.stringify(storedPostIds);
|
||||
} else {
|
||||
storedPostIds[post_id].type = action;
|
||||
disableReview(action);
|
||||
}
|
||||
}
|
||||
|
||||
fetch(url, {
|
||||
"headers": {
|
||||
"content-type": "application/x-www-form-urlencoded; charset=UTF-8"
|
||||
},
|
||||
"body": "form_key=" + formKey + '&post_id=' + post_id + '&action=' + action + '&mode=' + options.mode + '&likeId=' + likeId,
|
||||
"method": "POST",
|
||||
"mode": "cors",
|
||||
"credentials": "include"
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(response => {
|
||||
var storedPostIds, jsonStringIds;
|
||||
if (response['postLike'] && options.mode === '0' && typeof currentPostIds[post_id] === 'undefined') {
|
||||
var storedPostIds = receiveCookiePostIds(post_id, action, response['postLike'], self);
|
||||
var jsonStringIds = JSON.stringify(storedPostIds);
|
||||
|
||||
document.cookie = 'mpblog_post_data=' + jsonStringIds + '; expires=Sun, 1 Jan 2023 00:00:00 GMT; path=/';
|
||||
}
|
||||
|
||||
if (response['status']) {
|
||||
if (response.sumLike) {
|
||||
document.querySelector('#mp-blog-review .mp-blog-like .mp-blog-view').textContent = '(' + response.sumLike + ')';
|
||||
} else {
|
||||
document.querySelector('#mp-blog-review .mp-blog-like .mp-blog-view').textContent = '';
|
||||
}
|
||||
if (response.sumDislike) {
|
||||
document.querySelector('#mp-blog-review .mp-blog-dislike .mp-blog-view').textContent = '(' + response.sumDislike + ')';
|
||||
} else {
|
||||
document.querySelector('#mp-blog-review .mp-blog-dislike .mp-blog-view').textContent = '';
|
||||
}
|
||||
}
|
||||
|
||||
if (response['status']) {
|
||||
enableAllReview();
|
||||
if (response['postLike']) {
|
||||
disableReview(action);
|
||||
}
|
||||
}
|
||||
const reloadCustomerDataEvent = new CustomEvent("reload-customer-section-data");
|
||||
window.dispatchEvent(reloadCustomerDataEvent);
|
||||
window.scrollTo({
|
||||
top: document.body.offsetTop,
|
||||
behavior: 'smooth'
|
||||
});
|
||||
})
|
||||
.catch(error => console.error('Error:', error));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function disableReview (action) {
|
||||
if (action === '1') {
|
||||
document.querySelector('.mp-blog-like').style.backgroundColor = '#658259';
|
||||
} else {
|
||||
document.querySelector('.mp-blog-dislike').style.backgroundColor = '#9a6464';
|
||||
}
|
||||
}
|
||||
|
||||
function enableReview (action) {
|
||||
if (action === '1') {
|
||||
document.querySelector('.mp-blog-like').style.backgroundColor = '#6AA84F';
|
||||
} else {
|
||||
document.querySelector('.mp-blog-dislike').style.backgroundColor = '#EC3A3C';
|
||||
}
|
||||
}
|
||||
|
||||
function enableAllReview () {
|
||||
document.querySelector('.mp-blog-like').style.backgroundColor = '#6AA84F';
|
||||
document.querySelector('.mp-blog-dislike').style.backgroundColor = '#EC3A3C';
|
||||
}
|
||||
|
||||
function getCookie (name) {
|
||||
var v = document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)');
|
||||
return v ? v[2] : null;
|
||||
}
|
||||
|
||||
function receiveCookiePostIds (postId, action, likeId) {
|
||||
var postData = {
|
||||
id: postId,
|
||||
type: action,
|
||||
likeId: likeId
|
||||
},
|
||||
receivedJsonStr = getCookie('mpblog_post_data'),
|
||||
postIds = JSON.parse(receivedJsonStr) || {};
|
||||
|
||||
if (postIds[postId] !== undefined) {
|
||||
return postIds;
|
||||
}
|
||||
postIds[postId] = postData;
|
||||
return postIds;
|
||||
}
|
||||
|
||||
create();
|
||||
});
|
||||
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
<?php if ($helper->getBlogConfig('platforms/fb_platform/fb_share') || $helper->getBlogConfig('platforms/x_platform/x_share')) : ?>
|
||||
<div class="mp-clear"></div>
|
||||
<div class="mpcss">
|
||||
<div id="sharing">
|
||||
<div class="share-col-left">
|
||||
<h5><?= $escaper->escapeHtml(__('Share this post')) ?></h5>
|
||||
</div>
|
||||
<div class="share-col-right">
|
||||
<div class="post-sharing-button flex">
|
||||
<?php if ($helper->getBlogConfig('platforms/x_platform/x_share')) : ?>
|
||||
<img class="img-responsive"
|
||||
src="<?= $escaper->escapeUrl($block->getViewFileUrl('Mageplaza_Blog::media/images/twitter.png')) ?>"
|
||||
alt="Share on Twitter"
|
||||
onclick="window.open('https://twitter.com/share?text=&url=<?= /* @noEscape */
|
||||
$_post->getUrl() ?>','Twitter-dialog','width=626,height=436'); return false;"
|
||||
style="cursor: pointer;width: 43%;position: relative; left: 0.5rem"
|
||||
/>
|
||||
<?php endif; ?>
|
||||
<?php if ($helper->getBlogConfig('platforms/fb_platform/fb_share')) : ?>
|
||||
<img class="img-responsive"
|
||||
src="<?= $escaper->escapeUrl($block->getViewFileUrl('Mageplaza_Blog::media/images/facebook.png')) ?>"
|
||||
alt="Share on Facebook"
|
||||
onclick="window.open('https://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent('<?= /* @noEscape */
|
||||
$_post->getUrl() ?>'),'facebook-share-dialog','width=626,height=436'); return false;"
|
||||
style="cursor: pointer;"
|
||||
/>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if ($authorName && $helper->showAuthorInfo()) :
|
||||
$block->resizeImage($author->getImage(), '135x', Image::TEMPLATE_MEDIA_TYPE_AUTH);
|
||||
?>
|
||||
<div class="block-blog-related about-admin">
|
||||
<h2><?= $escaper->escapeHtml(__('About the Author')) ?></h2>
|
||||
<div class="related-content-container">
|
||||
<div class="author-content-image">
|
||||
<img class="img-responsive"
|
||||
src="<?= /* @noEscape */
|
||||
$author->getImage()
|
||||
? $block->resizeImage($author->getImage(), '135x', Image::TEMPLATE_MEDIA_TYPE_AUTH)
|
||||
: $block->getDefaultAuthorImage() ?>">
|
||||
</div>
|
||||
<div class="author-content-information">
|
||||
<div class="author-name"><?= /* @noEscape */
|
||||
$authorName ?></div>
|
||||
<p class="author-description">
|
||||
<?= /* @noEscape */
|
||||
$author->getShortDescription() ? $block->getPageFilter($author->getShortDescription()) : '' ?>
|
||||
</p>
|
||||
</div>
|
||||
<div class="mp-clear"></div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php $relatedPosts = $_post->getRelatedPostsCollection(); ?>
|
||||
<?php if ($relatedPosts && count($relatedPosts)) : ?>
|
||||
<div class="block-blog-related topic-list mpcss" style="width: 90%;">
|
||||
<h2><?= $escaper->escapeHtml(__('Related Posts')) ?></h2>
|
||||
<?php if ($block->getRelatedMode()) : ?>
|
||||
<div class="">
|
||||
<section id="card-carousel" class="splide" aria-label="Related Posts">
|
||||
<div class="splide__track">
|
||||
<ul class="splide__list">
|
||||
<?php foreach ($relatedPosts as $post) : ?>
|
||||
<li class="splide__slide">
|
||||
<div class="item post-list-item" style="margin-right: 10px">
|
||||
<div class="post-item-wraper">
|
||||
<div class="post-image">
|
||||
<?php if ($post->getImage()) : ?>
|
||||
<a href="<?= /* @noEscape */
|
||||
$post->getUrl() ?>">
|
||||
<img class="img-responsive"
|
||||
src="<?= $escaper->escapeUrl($block->resizeImage($post->getImage(),
|
||||
'400x')) ?>"
|
||||
alt="<?= $escaper->escapeHtmlAttr($post->getName()) ?>"/>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="post-info-wraper">
|
||||
<h2 class="mp-post-title">
|
||||
<a class="post-link-title"
|
||||
title="<?= $escaper->escapeHtmlAttr($post->getName()) ?>"
|
||||
href="<?= $escaper->escapeUrl($post->getUrl()) ?>">
|
||||
<?= $escaper->escapeHtml($post->getName()) ?>
|
||||
</a>
|
||||
</h2>
|
||||
<div class="mp-post-info">
|
||||
<?= /* @noEscape */
|
||||
$block->getPostInfo($post); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<style>
|
||||
.splide__pagination {
|
||||
bottom: -0.5em;
|
||||
}
|
||||
|
||||
.splide__arrow {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.splide__pagination__page.is-active {
|
||||
background: #869791
|
||||
}
|
||||
|
||||
|
||||
</style>
|
||||
|
||||
<?php else : ?>
|
||||
<div class="related-content-container" style="display: flex; flex-wrap: wrap;">
|
||||
<?php foreach ($relatedPosts as $post) : ?>
|
||||
<div class="post-list-item col-mp mp-6 mp-lg-4 mp-md-6 mp-xs-12">
|
||||
<div class="post-item-wraper">
|
||||
<div class="post-image">
|
||||
<?php if ($post->getImage()) : ?>
|
||||
<a href="<?= $escaper->escapeUrl($post->getUrl()) ?>">
|
||||
<img class="img-responsive"
|
||||
src="<?= $escaper->escapeUrl($block->resizeImage($post->getImage(),
|
||||
'400x')) ?>"
|
||||
alt="<?= $escaper->escapeHtmlAttr($post->getName()) ?>"/>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="post-info-wraper">
|
||||
<h2 class="mp-post-title">
|
||||
<a class="post-link-title"
|
||||
title="<?= $escaper->escapeHtmlAttr($post->getName()); ?>"
|
||||
href="<?= $escaper->escapeUrl($post->getUrl()) ?>">
|
||||
<?= $escaper->escapeHtml($post->getName()) ?>
|
||||
</a>
|
||||
</h2>
|
||||
<div class="mp-post-info">
|
||||
<?= /* @noEscape */
|
||||
$block->getPostInfo($post) ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<div class="mp-clear"></div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if ($helper->getBlogConfig('product_post/post_detail/enable_product')) : ?>
|
||||
<?php $relatedBlock = $block->getChildBlock('related_products'); ?>
|
||||
<?php if ($relatedBlock->hasProduct()) : ?>
|
||||
<div class="block-blog-related products-same-post page-products mpcss" style="width: 90%;">
|
||||
<h2><?= $helper->getBlogConfig('product_post/post_detail/title') ?: $escaper->escapeHtml(__('Related Products')) ?></h2>
|
||||
<div class="related-content-container">
|
||||
<?= $relatedBlock->toHtml(); ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
<?php $typeComment = $block->helperComment('type'); ?>
|
||||
<?php if (((int) $typeComment !== Type::DISABLE) && $_post->getAllowComment()) : ?>
|
||||
<div class="block-blog-related blog-comment">
|
||||
<h2><?= $escaper->escapeHtml(__('Comments')) ?></h2>
|
||||
<?php if ((int) $typeComment === Type::DISQUS) : ?>
|
||||
<div class="related-content-container box-collateral box-reviews" id="post-reviews">
|
||||
<div id="disqus_thread"></div>
|
||||
<script type="text/javascript">
|
||||
var disShortName = '<?= /** @noEscape */ $block->helperComment('disqus'); ?>';
|
||||
|
||||
/* * * DON'T EDIT BELOW THIS LINE * * */
|
||||
(function () {
|
||||
var dsq = document.createElement('script');
|
||||
dsq.type = 'text/javascript';
|
||||
dsq.async = true;
|
||||
dsq.src = '//' + disShortName + '.disqus.com/embed.js';
|
||||
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
|
||||
})();
|
||||
</script>
|
||||
</div>
|
||||
<?php elseif ($typeComment == Type::FACEBOOK) : ?>
|
||||
<div class="related-content-container box-collateral box-reviews
|
||||
<?= /* @noEscape */
|
||||
$helper->getBlogConfig('comment/facebook_colorscheme') ?>"
|
||||
id="post-reviews">
|
||||
<div id="fb-root"></div>
|
||||
<script>(function (d, s, id) {
|
||||
var js, fjs = d.getElementsByTagName(s)[0];
|
||||
if (d.getElementById(id)) return;
|
||||
js = d.createElement(s);
|
||||
js.id = id;
|
||||
js.src = "//connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v12.0&appId=<?=
|
||||
/* @noEscape */ $block->getDecrypt($block->helperComment('facebook_appid')) ?>";
|
||||
fjs.parentNode.insertBefore(js, fjs);
|
||||
}(document, 'script', 'facebook-jssdk'));
|
||||
</script>
|
||||
<div class="fb-comments" data-href="<?= /* @noEscape */
|
||||
$_post->getUrl() ?>"
|
||||
data-numposts="<?= /* @noEscape */
|
||||
$block->helperComment('facebook_number_comment') ?>"
|
||||
data-width="100%"
|
||||
data-colorscheme="<?= /* @noEscape */
|
||||
$block->helperComment('facebook_colorscheme') ?>"
|
||||
data-order-by="<?= /* @noEscape */
|
||||
$block->helperComment('facebook_order_by') ?>">
|
||||
</div>
|
||||
</div>
|
||||
<?php elseif ($typeComment == Type::DEFAULT_COMMENT) : ?>
|
||||
<div class="related-content-container container default-cmt">
|
||||
<?php if (!$block->isLoggedIn()) : ?>
|
||||
<div class="col-mp default-cmt__cmt-login">
|
||||
<button class="primary btn default-cmt__cmt-login__btn-login">
|
||||
<?= $escaper->escapeHtml(__('Login')) ?>
|
||||
</button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="col-mp mp-12" style="float: left;">
|
||||
<div class="default-cmt__content">
|
||||
<div class="default-cmt__content__cmt-block">
|
||||
<?php if (!$block->isLoggedIn()) : ?>
|
||||
<form id="default-cmt__content__cmt-block__guest-form"
|
||||
|
||||
x-data="Object.assign(hyva.formValidation($el), initCustomerCommentForm())"
|
||||
@submit.prevent="submitForm();"
|
||||
>
|
||||
<?= /* @noEscape */
|
||||
$block->getBlockHtml('formkey'); ?>
|
||||
<div class="col-mp mp-6 default-cmt__content__cmt-block__guest-box">
|
||||
<label for="default-cmt__content__cmt-block__guest-box__name-input">Name
|
||||
*</label>
|
||||
<input id="default-cmt__content__cmt-block__guest-box__name-input"
|
||||
type="text"
|
||||
name="default-cmt__content__cmt-block__guest-box__name-input"
|
||||
placeholder="<?= $escaper->escapeHtmlAttr(__('Your display name')) ?>"
|
||||
data-validate='{"required": true}'>
|
||||
</div>
|
||||
<div class="col-mp mp-6 default-cmt__content__cmt-block__guest-box">
|
||||
<label for="default-cmt__content__cmt-block__guest-box__email-input">Email
|
||||
*</label>
|
||||
<input id="default-cmt__content__cmt-block__guest-box__email-input"
|
||||
type="text"
|
||||
name="default-cmt__content__cmt-block__guest-box__email-input"
|
||||
placeholder="<?= $escaper->escapeHtmlAttr(__('Your email')) ?> "
|
||||
data-validate='{"required": true, "email": true}'
|
||||
>
|
||||
</div>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
<div class="default-cmt__content__cmt-block__cmt-box">
|
||||
<div class="col-mp mp-12">
|
||||
<label for="mp-guest-cmt-commentbox">Comment</label>
|
||||
<div>
|
||||
<textarea
|
||||
class="default-cmt__content__cmt-block__cmt-box__cmt-input w-full"
|
||||
maxlength="255"
|
||||
placeholder="<?= $escaper->escapeHtmlAttr(__('Type comments here...')) ?>">
|
||||
|
||||
</textarea>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="default-cmt__content__cmt-block__cmt-box__cmt-btn">
|
||||
<div class="default-cmt_loading" style="display: none">
|
||||
<img
|
||||
src="<?= $escaper->escapeUrl($block->getViewFileUrl('images/loader-1.gif')) ?>"
|
||||
alt="Loading...">
|
||||
</div>
|
||||
<button class="default-cmt__content__cmt-block__cmt-box__cmt-btn__btn-submit
|
||||
primary btn btn-primary" type="submit" style="display: block"
|
||||
form="default-cmt__content__cmt-block__guest-form">
|
||||
<?= $escaper->escapeHtml(__('Comment')) ?>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="default-cmt__content__cmt-content">
|
||||
<?php
|
||||
$comments = $block->getPostComments($_post->getId());
|
||||
$block->getCommentsTree($comments, 0);
|
||||
?>
|
||||
<?= $block->getCommentsHtml() ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
//get login url, text of button like, reply
|
||||
var loginUrl = '<?= /* @noEscape */ $block->getLoginUrl(); ?>',
|
||||
like = '<?= /* @noEscape */ __('Like') ?>',
|
||||
reply = '<?= /* @noEscape */ __('Reply') ?>',
|
||||
isLogged = '<?= /* @noEscape */ $isLogged ?>',
|
||||
likedColor = '<?= /* @noEscape */ $color?>',
|
||||
messengerBox = {
|
||||
cmt_warning: '<?= /* @noEscape */ $block->getMessagesHtml('adderror',
|
||||
'Please write the comment.')?>',
|
||||
exist_email_warning: '<?= /* @noEscape */$block->getMessagesHtml('adderror',
|
||||
'This email is exist. Please <a href="' . $block->getLoginUrl() . '"> Login </a> as our customer.')?>',
|
||||
login_warning: '<?= /* @noEscape */ $block->getMessagesHtml('adderror',
|
||||
'You are not logged in. Please <a href="' . $block->getLoginUrl() . '"> Login </a> or <a href="' . $block->getRegisterUrl() . '"> Signup </a> to like or send a reply.</div>')?>',
|
||||
comment_approve: '<?= /* @noEscape */ $block->getMessagesHtml('addsuccess',
|
||||
'Your comment has been sent successfully. Please wait admin approve !')?>'
|
||||
};
|
||||
|
||||
require(['comment']);
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?= $block->getChildHtml('mp_blog_post_view_add') ?>
|
||||
</div>
|
||||
<style>
|
||||
.default-cmt__content__cmt-content.row {
|
||||
padding-inline-start: 40px;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
if(document.getElementById('card-carousel')) {
|
||||
new Splide('#card-carousel', {
|
||||
perPage: 3,
|
||||
breakpoints: {
|
||||
1028: {
|
||||
perPage: 2
|
||||
}
|
||||
}
|
||||
}).mount();
|
||||
}
|
||||
|
||||
});
|
||||
var cmtBox = document.querySelector('.default-cmt__content__cmt-block__cmt-box__cmt-input');
|
||||
var submitCmt = document.querySelector('.default-cmt__content__cmt-block__cmt-box__cmt-btn__btn-submit');
|
||||
var defaultCmt = document.querySelector('ul.default-cmt__content__cmt-content:first-child');
|
||||
var likeBtn = defaultCmt.querySelectorAll('.btn-like');
|
||||
var replyBtn = defaultCmt.querySelectorAll('.btn-reply');
|
||||
|
||||
let loginBtnCmt = document.querySelector('.default-cmt__cmt-login__btn-login');
|
||||
if (loginBtnCmt) {
|
||||
loginBtnCmt.addEventListener('click', function () {
|
||||
var socialPopup = document.querySelector(".social-login-popup");
|
||||
if (socialPopup) {
|
||||
openMyDialog();
|
||||
showLogin();
|
||||
} else {
|
||||
window.location.href = loginUrl;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function initCustomerCommentForm () {
|
||||
return {
|
||||
errors: 0,
|
||||
hasCaptchaToken: 0,
|
||||
showPassword: false,
|
||||
displayErrorMessage: false,
|
||||
errorMessages: [],
|
||||
setErrorMessages (messages) {
|
||||
this.errorMessages = [messages];
|
||||
this.displayErrorMessage = this.errorMessages.length
|
||||
},
|
||||
submitForm () {
|
||||
this.validate()
|
||||
.then(() => {
|
||||
const $form = document.querySelector('#default-cmt__content__cmt-block__guest-form');
|
||||
if (this.errors === 0) {
|
||||
this.dispatchCommentRequest($form);
|
||||
}
|
||||
})
|
||||
.catch((invalid) => {
|
||||
if (invalid.length > 0) {
|
||||
invalid[0].focus();
|
||||
}
|
||||
});
|
||||
},
|
||||
dispatchCommentRequest: function (form) {
|
||||
callApiSubmitComment();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function submitComment () {
|
||||
if (isLogged === 'Yes') {
|
||||
submitCmt.addEventListener('click', function () {
|
||||
callApiSubmitComment();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
submitComment();
|
||||
|
||||
async function callApiSubmitComment () {
|
||||
var messagesContainer = document.querySelector('.default-cmt__content__cmt-block__cmt-box .messages');
|
||||
if (messagesContainer) {
|
||||
messagesContainer.style.display = 'none';
|
||||
}
|
||||
|
||||
var cmtBox = document.querySelector('.default-cmt__content__cmt-block__cmt-box__cmt-input');
|
||||
var submitCmt = document.querySelector('.default-cmt__content__cmt-block__cmt-box__cmt-btn__btn-submit');
|
||||
var cmtText = cmtBox.value;
|
||||
if (cmtText.trim().length) {
|
||||
document.querySelector('.default-cmt_loading').style.display = 'block';
|
||||
this.disabled = true;
|
||||
await ajaxCommentActions(cmtText, submitCmt);
|
||||
cmtBox.value = '';
|
||||
document.querySelector('.default-cmt_loading').style.display = 'none';
|
||||
submitCmt.disabled = false;
|
||||
|
||||
} else {
|
||||
var cmtInputParent = document.querySelector('.default-cmt__content__cmt-block__cmt-box__cmt-input').parentElement;
|
||||
cmtInputParent.insertAdjacentHTML('beforeend', messengerBox.cmt_warning);
|
||||
}
|
||||
}
|
||||
|
||||
// ajax call api to comments
|
||||
function ajaxCommentActions (cmtText, inputEl, checkReply, cmtId, parentComment) {
|
||||
var isReply = (typeof checkReply !== 'undefined') ? 1 : 0,
|
||||
replyId = (typeof cmtId !== 'undefined') ? cmtId : 0,
|
||||
displayReply = (typeof checkReply !== 'undefined');
|
||||
var guestName = document.querySelector('#default-cmt__content__cmt-block__guest-box__name-input')?.value;
|
||||
|
||||
var guestEmail = document.querySelector('#default-cmt__content__cmt-block__guest-box__email-input')?.value;
|
||||
let url = window.location.href;
|
||||
const body = new URLSearchParams({
|
||||
form_key: hyva.getFormKey(),
|
||||
cmt_text: cmtText,
|
||||
isReply: isReply,
|
||||
replyId: replyId,
|
||||
guestName: guestName,
|
||||
guestEmail: guestEmail
|
||||
});
|
||||
fetch(url, {
|
||||
headers: {
|
||||
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
|
||||
"X-Requested-With": "XMLHttpRequest"
|
||||
},
|
||||
body: body,
|
||||
method: "POST",
|
||||
mode: "cors",
|
||||
credentials: "include"
|
||||
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
switch (data.status){
|
||||
case 'duplicated':
|
||||
document.querySelector('.default-cmt__content__cmt-block__cmt-box__cmt-input').parentElement.appendChild(document.createRange().createContextualFragment(messengerBox.exist_email_warning));
|
||||
break;
|
||||
case 3:
|
||||
document.querySelector('.default-cmt__content__cmt-block').insertAdjacentHTML('afterbegin', messengerBox.comment_approve);
|
||||
break;
|
||||
case 1:
|
||||
displayComment(data, displayReply);
|
||||
var cmtCount = document.querySelectorAll('.default-cmt li').length;
|
||||
if (document.querySelector('.mp-cmt-count')) {
|
||||
document.querySelector('.mp-cmt-count').textContent = cmtCount;
|
||||
}
|
||||
|
||||
inputEl.value = '';
|
||||
break;
|
||||
case 'error':
|
||||
if (checkReply !== 'undefined') {
|
||||
parentComment.insertAdjacentHTML('beforeend', data.error);
|
||||
} else {
|
||||
document.querySelector('.default-cmt').insertAdjacentHTML('beforeend', data.error);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
})
|
||||
.catch(error => console.error('Error:', error));
|
||||
}
|
||||
// handle display comments
|
||||
function displayComment (cmt, isReply) {
|
||||
function htmlComment (text) {
|
||||
var html = '';
|
||||
var sub = text.split("\n");
|
||||
for (var i = 0; i < sub.length; i++){
|
||||
html += '<p>' + sub[i] + '</p>';
|
||||
}
|
||||
return html;
|
||||
}
|
||||
|
||||
var cmtRow = document.createElement('li');
|
||||
cmtRow.style.width = '100%';
|
||||
cmtRow.id = 'cmt-id-' + cmt.cmt_id;
|
||||
cmtRow.className = 'default-cmt__content__cmt-content__cmt-row cmt-row-' + cmt.cmt_id + ' cmt-row col-m-12' +
|
||||
(isReply ? ' reply-row' : '');
|
||||
cmtRow.setAttribute('data-cmt-id', cmt.cmt_id);
|
||||
if (isReply) {
|
||||
cmtRow.setAttribute('data-reply-id', cmt.reply_cmt);
|
||||
}
|
||||
|
||||
cmtRow.innerHTML = '<div class="cmt-row__cmt-username"> ' +
|
||||
'<span class="cmt-row__cmt-username username username__' + cmt.cmt_id + '">' + cmt.user_cmt + '</span> ' +
|
||||
'</div>' +
|
||||
'<div class="cmt-row__cmt-content"> ' +
|
||||
'<p>' + htmlComment(cmt.cmt_text) + '</p> ' +
|
||||
'</div>' +
|
||||
'<div class="cmt-row__cmt-interactions interactions"> <div class="interactions__btn-actions"> ' +
|
||||
'<a class="interactions__btn-actions action btn-like mpblog-like" data-cmt-id="' + cmt.cmt_id + '" click="1">' +
|
||||
'<i class="fa fa-thumbs-up" aria-hidden="true" style="margin-right: 3px"></i>' +
|
||||
'<span class="count-like__like-text"></span>' +
|
||||
'</a>' +
|
||||
'<a class="interactions__btn-actions action btn-reply" data-cmt-id="' + cmt.cmt_id + '">' + reply + '</a> ' +
|
||||
'</div>' +
|
||||
'<div class="interactions__cmt-createdat"> ' +
|
||||
'<span>' + cmt.created_at + '</span> ' +
|
||||
'</div> ';
|
||||
|
||||
if (isReply) {
|
||||
var replyCmtId = cmt.reply_cmt;
|
||||
var replyCmtList = document.querySelectorAll('.default-cmt__content__cmt-content__cmt-row');
|
||||
|
||||
replyCmtList.forEach(function (cmtEl) {
|
||||
if (cmtEl.getAttribute('data-cmt-id') === replyCmtId) {
|
||||
var replyList = cmtEl.querySelector('ul.default-cmt__content__cmt-content:first-child');
|
||||
|
||||
if (!replyList) {
|
||||
var newUl = document.createElement('ul');
|
||||
newUl.className = 'default-cmt__content__cmt-content row';
|
||||
newUl.appendChild(cmtRow);
|
||||
cmtEl.appendChild(newUl);
|
||||
|
||||
likeComment(cmtRow.querySelectorAll('.btn-like'));
|
||||
showReply(cmtRow.querySelectorAll('.btn-reply'));
|
||||
} else {
|
||||
replyList.appendChild(cmtRow);
|
||||
|
||||
likeComment(cmtRow.querySelectorAll('.btn-like'));
|
||||
showReply(cmtRow.querySelectorAll('.btn-reply'));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
defaultCmt.appendChild(cmtRow);
|
||||
|
||||
likeComment(cmtRow.querySelectorAll('.btn-like'));
|
||||
showReply(cmtRow.querySelectorAll('.btn-reply'));
|
||||
}
|
||||
}
|
||||
// handle click like comment
|
||||
function likeComment (btns) {
|
||||
btns.forEach(function (likeEl) {
|
||||
likeEl.addEventListener('click', function () {
|
||||
var cmtId = this.getAttribute('data-cmt-id');
|
||||
var cmtRowContainer = this.closest('.default-cmt__content__cmt-content__cmt-row');
|
||||
|
||||
if (isLogged === 'Yes') {
|
||||
var likeCountText = this.querySelector('span').textContent.trim();
|
||||
var likeCount = parseInt(likeCountText, 10) || 0; // Convert to integer, default to 0 if NaN
|
||||
if (this.getAttribute('click') === '1') {
|
||||
if (this.classList.contains('mpblog-liked')) {
|
||||
this.style.color = '#333333';
|
||||
likeCount--;
|
||||
this.querySelector('span').textContent = (likeCount === 0) ? "" : likeCount;
|
||||
this.classList.remove('mpblog-liked');
|
||||
} else {
|
||||
likeCount++;
|
||||
this.querySelector('span').textContent = likeCount;
|
||||
this.style.color = likedColor;
|
||||
this.classList.add('mpblog-liked');
|
||||
}
|
||||
|
||||
fetch(window.location.href, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
||||
"X-Requested-With": "XMLHttpRequest"
|
||||
},
|
||||
body: 'cmtId=' + cmtId,
|
||||
mode: "cors",
|
||||
credentials: "include"
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(response => {
|
||||
if (response.status === 'ok') {
|
||||
likeEl.setAttribute('click', '1');
|
||||
} else if (response.status === 'error' && response.hasOwnProperty('error')) {
|
||||
var errorElement = document.createElement('div');
|
||||
errorElement.innerHTML = response.error;
|
||||
defaultCmt.appendChild(errorElement);
|
||||
}
|
||||
})
|
||||
.catch(error => console.error('Error:', error));
|
||||
}
|
||||
|
||||
likeEl.setAttribute('click', '0');
|
||||
} else {
|
||||
cmtRowContainer.insertAdjacentHTML('beforeend', messengerBox.login_warning);
|
||||
setTimeout(function () {
|
||||
var errorNotification = document.querySelector('.message.error.message-error');
|
||||
if (errorNotification) {
|
||||
errorNotification.parentElement.removeChild(errorNotification);
|
||||
}
|
||||
}, 3000);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
likeComment(likeBtn);
|
||||
// handle show reply comment
|
||||
function showReply (btns) {
|
||||
btns.forEach(function (btn) {
|
||||
btn.addEventListener('click', function () {
|
||||
var cmtId = (typeof closestWithDataAttr(btn, 'data-cmt-id') !== 'undefined') ? closestWithDataAttr(btn, 'data-cmt-id') : btn.getAttribute('data-cmt-id');
|
||||
|
||||
var inputCmtID = this.getAttribute('data-cmt-id');
|
||||
var cmtRowCmt = document.querySelector('#cmt-row');
|
||||
var cmtRowContainer = this.closest('.default-cmt__content__cmt-content__cmt-row');
|
||||
|
||||
if (document.querySelectorAll('.cmt-row__reply-row.row__' + inputCmtID).length) {
|
||||
cmtRowContainer = document.querySelector("#cmt-id-" + cmtId + " ul:last-child");
|
||||
}
|
||||
|
||||
var cmtRow = cmtRowContainer.querySelector('.cmt-row__reply-row.row__' + inputCmtID);
|
||||
var cmtName = document.querySelector(".username__" + inputCmtID).textContent;
|
||||
|
||||
if (isLogged === 'Yes') {
|
||||
if (cmtRowCmt) {
|
||||
cmtRowCmt.style.display = (cmtRowCmt.style.display === 'none') ? 'block' : 'none';
|
||||
cmtRowCmt.parentElement.removeChild(cmtRowCmt);
|
||||
}
|
||||
|
||||
if (cmtRow) {
|
||||
cmtRow.style.display = (cmtRow.style.display === 'none') ? 'block' : 'none';
|
||||
cmtRow.parentElement.removeChild(cmtRow);
|
||||
} else {
|
||||
cmtRowContainer.insertAdjacentHTML('beforeend', '<div id="cmt-row" class="cmt-row__reply-row row row__' + inputCmtID + ' col-md-12">' +
|
||||
'<div class="reply-form__form-input form-group col-xs-8 col-md-6">' +
|
||||
'<label for="reply_cmt' + inputCmtID + '"></label>' +
|
||||
'<input type="text" id="reply_cmt' + inputCmtID + '" class="form-group__input form-control" placeholder="Press enter to submit reply" value="' + cmtName + ' " autofocus onfocus="this.setSelectionRange(1000,1001);"/>' +
|
||||
'</div>' +
|
||||
'</div>');
|
||||
|
||||
var input = document.getElementById('reply_cmt' + inputCmtID);
|
||||
input.closest('.form-group').appendChild(
|
||||
document.querySelector('.default-cmt__content__cmt-block__cmt-box__cmt-btn .default-cmt_loading').cloneNode(true)
|
||||
);
|
||||
input.focus();
|
||||
|
||||
submitReply(input, cmtId, cmtRowContainer);
|
||||
}
|
||||
} else {
|
||||
cmtRowContainer.insertAdjacentHTML('beforeend', messengerBox.login_warning);
|
||||
setTimeout(function () {
|
||||
var errorNotification = document.querySelector('.message.error.message-error');
|
||||
if (errorNotification) {
|
||||
errorNotification.parentElement.removeChild(errorNotification);
|
||||
}
|
||||
}, 3000);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
// handle find comment id closest
|
||||
function closestWithDataAttr (element, attribute) {
|
||||
while (element && !element.getAttribute(attribute)){
|
||||
element = element.parentNode;
|
||||
}
|
||||
return element ? element.getAttribute(attribute) : null;
|
||||
}
|
||||
|
||||
showReply(replyBtn);
|
||||
|
||||
var firstCmtRow = document.querySelector('li.default-cmt__content__cmt-content__cmt-row:first-child');
|
||||
if (firstCmtRow) {
|
||||
firstCmtRow.style.borderTop = 'none';
|
||||
}
|
||||
// handle reply comment
|
||||
function submitReply (input, replyId, parentComment) {
|
||||
input.addEventListener('keypress', async function (e) {
|
||||
var text = input.value;
|
||||
if (text !== '') {
|
||||
if (e.keyCode === 13) {
|
||||
input.nextElementSibling.style.display = 'block';
|
||||
input.disabled = true;
|
||||
await ajaxCommentActions(text, input, true, replyId, parentComment);
|
||||
input.closest('.cmt-row__reply-row').style.display = 'none';
|
||||
input.nextElementSibling.style.display = 'none';
|
||||
input.disabled = false;
|
||||
var cmtRow = document.getElementById('cmt-row');
|
||||
if (cmtRow) {
|
||||
cmtRow.remove();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user