Обновлена логика центральных блоков: теперь поддерживается несколько блоков
This commit is contained in:
@@ -54,13 +54,13 @@ function basisVis() {
|
||||
editableElementsFun();
|
||||
let basis3 = document.getElementById('basis3');
|
||||
let sideFloatClass = basis3 ? basis3.querySelectorAll('[style*="visibility: visible;"]') : null;
|
||||
if (!basis3 || !sideFloatClass || !editableElements || editableElements.length === 0) return;
|
||||
elementsСhecked = [basis3, ...sideFloatClass, ...editableElements];
|
||||
|
||||
if (!basis3 || !sideFloatClass || !window.editableElements || window.editableElements.length === 0) return;
|
||||
let elementsСhecked = [basis3, ...sideFloatClass, ...window.editableElements];
|
||||
|
||||
if (basis3.style.visibility === "visible") {
|
||||
basis3.style.visibility = "hidden";
|
||||
sessionStorage.setItem('basis3_visibility', 'hidden');
|
||||
editableElements.forEach(function(element) {
|
||||
window.editableElements.forEach(function(element) {
|
||||
if (element) {
|
||||
element.setAttribute("contenteditable", false);
|
||||
}
|
||||
@@ -69,18 +69,18 @@ function basisVis() {
|
||||
sideFloatClass.forEach(function(element) {
|
||||
element.style.visibility = "hidden";
|
||||
});
|
||||
for (let i = 0; i < editId.length; i++) {
|
||||
for (let i = 0; i < editId.length; i++) {
|
||||
editMode = -1;
|
||||
if (document.getElementById(editId[i])) {
|
||||
document.getElementById(editId[i]).classList.remove('active');
|
||||
}
|
||||
}
|
||||
document.getElementById('bcbody').style.top = '0px';
|
||||
document.querySelectorAll('.bfloat').forEach(e=>e.style.fontSize='')
|
||||
document.querySelectorAll('.bfloat').forEach(e => e.style.fontSize = '')
|
||||
} else {
|
||||
basis3.style.visibility = "visible";
|
||||
sessionStorage.setItem('basis3_visibility', 'visible');
|
||||
editableElements.forEach(function(element) {
|
||||
window.editableElements.forEach(function(element) {
|
||||
if (element) {
|
||||
element.setAttribute("contenteditable", true);
|
||||
}
|
||||
@@ -90,20 +90,20 @@ function basisVis() {
|
||||
basis3.style.top = '20%';
|
||||
basis3.style.transform = 'translate(0%, -20%)';
|
||||
document.getElementById('bcbody').style.top = '30px';
|
||||
document.querySelectorAll('.bfloat').forEach(e=>e.style.fontSize='1em')
|
||||
|
||||
document.querySelectorAll('.bfloat').forEach(e => e.style.fontSize = '1em')
|
||||
}
|
||||
}
|
||||
window.basisVis = basisVis;
|
||||
|
||||
/** @brief Сбор всех редактируемых элементов */
|
||||
function editableElementsFun() {
|
||||
let content = document.getElementById('content');
|
||||
editableElements = document.querySelectorAll('.pluginEditable');
|
||||
editableElements = Array.from(editableElements);
|
||||
editableElements.push(content);
|
||||
window.editableElements = [];
|
||||
let contents = document.querySelectorAll('.content');
|
||||
let pluginEls = document.querySelectorAll('.pluginEditable');
|
||||
pluginEls = Array.from(pluginEls);
|
||||
window.editableElements.push(...pluginEls, ...contents);
|
||||
|
||||
editableElements.forEach(function(element) {
|
||||
window.editableElements.forEach(function(element) {
|
||||
if (!element) {
|
||||
console.log("Element " + element + " not found.");
|
||||
return;
|
||||
@@ -111,31 +111,28 @@ function editableElementsFun() {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
addEventListener("LoadeditorJs", function()
|
||||
{
|
||||
|
||||
let te=document.getElementById("tex"); // Ссылка на текстовое поле
|
||||
let tex=document.getElementById("tex"); // Ссылка на стили текстового поля
|
||||
|
||||
if (document.getElementById("content") == "") {
|
||||
te.value=document.getElementById("content").innerHTML; // Передача данных из области контента в текстовое поле
|
||||
}
|
||||
// Передаём содержимое пустых блоков в поле
|
||||
document.querySelectorAll('.content').forEach(el => {
|
||||
if (!el.innerHTML) te.value = el.innerHTML;
|
||||
});
|
||||
|
||||
// Символы клавиш со знаками препинания или перевода строки
|
||||
let symb = ["Enter", "!", "?", ";", ":", ",", ".", " ", "-", "'", "\"", "(", ")", "{", "}", "[", "]", "_", "&", "/", "\\", "*"];
|
||||
|
||||
// Запись в память введенного текста при нажатии клавиши со знаком препинания или перевода строки
|
||||
if (document.getElementById("content")) {
|
||||
document.getElementById("content").addEventListener("keyup", function(ev)
|
||||
{
|
||||
for(let i=0; i<symb.length; i++)
|
||||
{
|
||||
if(symb[i]==ev.key)
|
||||
inter();
|
||||
}
|
||||
});
|
||||
}
|
||||
document.querySelectorAll('.content').forEach(el => {
|
||||
el.addEventListener('keyup', ev => {
|
||||
for (let i = 0; i < symb.length; i++) {
|
||||
if (symb[i] == ev.key) inter();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
let sel = document.getSelection();
|
||||
function selInContenteditable(insertType) {
|
||||
@@ -497,69 +494,74 @@ document.getElementById("newPage").addEventListener("click", newPageFun);
|
||||
function newPageFun() {
|
||||
document.getElementById("right-float").innerHTML = "";
|
||||
document.getElementById("left-float").innerHTML = "";
|
||||
document.getElementById("content").innerHTML = "";
|
||||
document.querySelectorAll('.content').forEach(el => el.innerHTML = "");
|
||||
document.getElementById("mainTitle").innerHTML = "<i>{{new_file}}!</i>";
|
||||
window.newPageFunValue = "newPage";
|
||||
document.getElementById("settingsMain_d").style.visibility="hidden";
|
||||
}
|
||||
|
||||
// Сохранение выделение
|
||||
|
||||
document.addEventListener('selectionchange', () => {
|
||||
const content = document.getElementById('content');
|
||||
const contents = document.querySelectorAll('.content');
|
||||
if (!contents || contents.length === 0) return;
|
||||
const sel = window.getSelection();
|
||||
if (!sel.rangeCount) return;
|
||||
const range = sel.getRangeAt(0);
|
||||
const startNode = range.startContainer;
|
||||
if (content.contains(startNode)) {
|
||||
saveSelection();
|
||||
for (let content of contents) {
|
||||
if (content.contains(startNode)) {
|
||||
saveSelection();
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
let savedSel = null;
|
||||
|
||||
function saveSelection() {
|
||||
const content = document.getElementById('content');
|
||||
const contents = document.querySelectorAll('.content');
|
||||
const sel = window.getSelection();
|
||||
if (!sel.rangeCount) return;
|
||||
const range = sel.getRangeAt(0);
|
||||
if (!content.contains(range.commonAncestorContainer)) return;
|
||||
const pre = range.cloneRange();
|
||||
pre.selectNodeContents(content);
|
||||
pre.setEnd(range.startContainer, range.startOffset);
|
||||
const start = pre.toString().length;
|
||||
const end = start + range.toString().length;
|
||||
savedSel = { start, end };
|
||||
for (let content of contents) {
|
||||
if (content.contains(range.commonAncestorContainer)) {
|
||||
const pre = range.cloneRange();
|
||||
pre.selectNodeContents(content);
|
||||
pre.setEnd(range.startContainer, range.startOffset);
|
||||
const start = pre.toString().length;
|
||||
const end = start + range.toString().length;
|
||||
savedSel = { start, end };
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function restoreSelection() {
|
||||
if (!savedSel) return;
|
||||
const content = document.getElementById('content');
|
||||
const { start, end } = savedSel;
|
||||
let charIndex = 0;
|
||||
const range = document.createRange();
|
||||
range.setStart(content, 0);
|
||||
range.collapse(true);
|
||||
try {
|
||||
(function traverse(node) {
|
||||
if (node.nodeType === Node.TEXT_NODE) {
|
||||
const next = charIndex + node.length;
|
||||
if (charIndex <= start && next >= start) {
|
||||
range.setStart(node, start - charIndex);
|
||||
}
|
||||
if (charIndex <= end && next >= end) {
|
||||
range.setEnd(node, end - charIndex);
|
||||
throw 'done';
|
||||
}
|
||||
charIndex = next;
|
||||
} else {
|
||||
node.childNodes.forEach(traverse);
|
||||
}
|
||||
})(content);
|
||||
} catch (e) {}
|
||||
const sel = window.getSelection();
|
||||
sel.removeAllRanges();
|
||||
sel.addRange(range);
|
||||
if (!savedSel) return;
|
||||
const contents = document.querySelectorAll('.content');
|
||||
const { start, end } = savedSel;
|
||||
let charIndex = 0;
|
||||
const range = document.createRange();
|
||||
try {
|
||||
for (const content of contents) {
|
||||
range.setStart(content, 0);
|
||||
range.collapse(true);
|
||||
(function traverse(node) {
|
||||
if (node.nodeType === Node.TEXT_NODE) {
|
||||
const next = charIndex + node.length;
|
||||
if (charIndex <= start && next >= start) range.setStart(node, start - charIndex);
|
||||
if (charIndex <= end && next >= end) {
|
||||
range.setEnd(node, end - charIndex);
|
||||
throw 'done';
|
||||
}
|
||||
charIndex = next;
|
||||
} else node.childNodes.forEach(traverse);
|
||||
})(content);
|
||||
}
|
||||
} catch (e) {}
|
||||
const sel = window.getSelection();
|
||||
sel.removeAllRanges();
|
||||
sel.addRange(range);
|
||||
}
|
||||
|
||||
// Взаимодействие с плагинами
|
||||
@@ -1457,14 +1459,14 @@ const singleFormats = [
|
||||
const specialFormats = ['butlink', 'linkdel', 'forma', 'col', 'backgr'];
|
||||
|
||||
addEventListener("LoadeditorJs", function() {
|
||||
const content = document.getElementById('content');
|
||||
const content = document.querySelectorAll('.content');
|
||||
|
||||
simpleFormats.forEach(f => {
|
||||
document.getElementById(f.id).addEventListener('click', () => {
|
||||
const sel = window.getSelection();
|
||||
if (!sel.rangeCount) return;
|
||||
const range = sel.getRangeAt(0);
|
||||
if (!content.contains(range.commonAncestorContainer)) return;
|
||||
if (![...document.querySelectorAll('.content')].some(c => c.contains(range.commonAncestorContainer))) return;
|
||||
let all = true;
|
||||
const it = document.createNodeIterator(
|
||||
range.commonAncestorContainer,
|
||||
@@ -1495,7 +1497,7 @@ divFormats.forEach(f => {
|
||||
const sel = window.getSelection();
|
||||
if (!sel.rangeCount) return;
|
||||
const range = sel.getRangeAt(0);
|
||||
if (!content.contains(range.commonAncestorContainer)) return;
|
||||
if (![...document.querySelectorAll('.content')].some(c => c.contains(range.commonAncestorContainer))) return;
|
||||
divApplyformat(range, f);
|
||||
inter();
|
||||
});
|
||||
@@ -1506,7 +1508,7 @@ listFormats.forEach(f => {
|
||||
const sel = window.getSelection();
|
||||
if (!sel.rangeCount) return;
|
||||
const range = sel.getRangeAt(0);
|
||||
if (!content.contains(range.commonAncestorContainer)) return;
|
||||
if (![...document.querySelectorAll('.content')].some(c => c.contains(range.commonAncestorContainer))) return;
|
||||
listApplyformat(range, f);
|
||||
inter();
|
||||
});
|
||||
@@ -1523,7 +1525,7 @@ singleFormats.forEach(f => {
|
||||
const sel = window.getSelection()
|
||||
if (!sel.rangeCount) return
|
||||
const range = sel.getRangeAt(0)
|
||||
if (!content.contains(range.commonAncestorContainer)) return
|
||||
if (![...document.querySelectorAll('.content')].some(c => c.contains(range.commonAncestorContainer))) return;
|
||||
singleApplyformat(range, f)
|
||||
inter()
|
||||
})
|
||||
@@ -1534,7 +1536,7 @@ specialFormats.forEach(f => {
|
||||
const sel = window.getSelection();
|
||||
if (!sel.rangeCount) return;
|
||||
const range = sel.getRangeAt(0);
|
||||
if (!content.contains(range.commonAncestorContainer)) return;
|
||||
if (![...content].some(c => c.contains(range.commonAncestorContainer))) return;
|
||||
if (typeof document[f + 'Fun'] === 'function') document[f + 'Fun'](range);
|
||||
else window[f + 'Fun'](range);
|
||||
inter();
|
||||
@@ -1543,10 +1545,13 @@ specialFormats.forEach(f => {
|
||||
|
||||
const events = ['pointerup','keyup','input','focus','blur','click'];
|
||||
events.forEach(evt => {
|
||||
if (!content) return;
|
||||
content.addEventListener(evt, () => {
|
||||
updateToolbarStyles();
|
||||
updateSingleSelectors();
|
||||
const contents = document.querySelectorAll('.content');
|
||||
if (!contents || contents.length === 0) return;
|
||||
contents.forEach(content => {
|
||||
content.addEventListener(evt, () => {
|
||||
updateToolbarStyles();
|
||||
updateSingleSelectors();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1561,36 +1566,42 @@ let currentIndex = 0
|
||||
|
||||
/** @brief Сохраняет текущее состояние контента, если оно изменилось */
|
||||
function inter() {
|
||||
const editable = document.getElementById("content")
|
||||
if (editable) {
|
||||
let currentContent = editable.innerHTML
|
||||
if (currentContent !== arr[currentIndex]) {
|
||||
currentIndex++
|
||||
arr = arr.slice(0, currentIndex)
|
||||
arr.push(currentContent)
|
||||
const editables = document.querySelectorAll(".content")
|
||||
editables.forEach(editable => {
|
||||
if (editable) {
|
||||
let currentContent = editable.innerHTML
|
||||
if (currentContent !== arr[currentIndex]) {
|
||||
currentIndex++
|
||||
arr = arr.slice(0, currentIndex)
|
||||
arr.push(currentContent)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (document.getElementById("content")) {
|
||||
arr[0] = document.getElementById("content").innerHTML
|
||||
}
|
||||
document.querySelectorAll(".content").forEach((editable, i) => {
|
||||
if (i === 0) arr[0] = editable.innerHTML
|
||||
})
|
||||
|
||||
document.getElementById("forw").addEventListener("click", function() {
|
||||
if (currentIndex < arr.length - 1) {
|
||||
currentIndex++
|
||||
const editable = document.getElementById("content")
|
||||
editable.innerHTML = arr[currentIndex]
|
||||
editable.setAttribute("contenteditable", "true")
|
||||
const editables = document.querySelectorAll(".content")
|
||||
editables.forEach(editable => {
|
||||
editable.innerHTML = arr[currentIndex]
|
||||
editable.setAttribute("contenteditable", "true")
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
document.getElementById("bac").addEventListener("click", function() {
|
||||
if (currentIndex > 0) {
|
||||
currentIndex--
|
||||
const editable = document.getElementById("content")
|
||||
editable.innerHTML = arr[currentIndex]
|
||||
editable.setAttribute("contenteditable", "true")
|
||||
const editables = document.querySelectorAll(".content")
|
||||
editables.forEach(editable => {
|
||||
editable.innerHTML = arr[currentIndex]
|
||||
editable.setAttribute("contenteditable", "true")
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1785,8 +1796,10 @@ function divApplyformat(range, format) {
|
||||
range.compareBoundaryPoints(Range.START_TO_END, er) > 0;
|
||||
};
|
||||
|
||||
Array.from(content.children).forEach(child => {
|
||||
if (intersects(child)) externals.add(child);
|
||||
Array.from(document.querySelectorAll('.content')).forEach(content => {
|
||||
Array.from(content.children).forEach(child => {
|
||||
if (intersects(child)) externals.add(child);
|
||||
});
|
||||
});
|
||||
|
||||
externals.forEach(div => {
|
||||
@@ -1811,8 +1824,10 @@ function listApplyformat(range, format) {
|
||||
|
||||
if (type === 'listNone') {
|
||||
const lists = new Set();
|
||||
Array.from(content.querySelectorAll('li')).forEach(li => {
|
||||
if (intersects(li)) lists.add(li.parentNode);
|
||||
Array.from(document.querySelectorAll('.content')).forEach(content => {
|
||||
Array.from(content.querySelectorAll('li')).forEach(li => {
|
||||
if (intersects(li)) lists.add(li.parentNode);
|
||||
});
|
||||
});
|
||||
|
||||
lists.forEach(list => {
|
||||
@@ -1849,31 +1864,33 @@ function listApplyformat(range, format) {
|
||||
parent.removeChild(list);
|
||||
});
|
||||
} else {
|
||||
const items = Array.from(content.children).filter(child => intersects(child));
|
||||
if (!items.length) return;
|
||||
Array.from(document.querySelectorAll('.content')).forEach(content => {
|
||||
const items = Array.from(content.children).filter(child => intersects(child));
|
||||
if (!items.length) return;
|
||||
|
||||
let listEl;
|
||||
if (type === 'listNumbers' || type === 'listLetters') {
|
||||
listEl = document.createElement('ol');
|
||||
listEl.style.listStyleType = format.style.listStyleType;
|
||||
} else {
|
||||
listEl = document.createElement('ul');
|
||||
listEl.style.listStyleType = format.style.listStyleType;
|
||||
}
|
||||
content.insertBefore(listEl, items[0]);
|
||||
|
||||
items.forEach(node => {
|
||||
if (node.tagName === 'UL' || node.tagName === 'OL') {
|
||||
Array.from(node.children).forEach(li => {
|
||||
listEl.appendChild(li);
|
||||
});
|
||||
content.removeChild(node);
|
||||
let listEl;
|
||||
if (type === 'listNumbers' || type === 'listLetters') {
|
||||
listEl = document.createElement('ol');
|
||||
listEl.style.listStyleType = format.style.listStyleType;
|
||||
} else {
|
||||
const li = document.createElement('li');
|
||||
content.removeChild(node);
|
||||
li.appendChild(node);
|
||||
listEl.appendChild(li);
|
||||
listEl = document.createElement('ul');
|
||||
listEl.style.listStyleType = format.style.listStyleType;
|
||||
}
|
||||
content.insertBefore(listEl, items[0]);
|
||||
|
||||
items.forEach(node => {
|
||||
if (node.tagName === 'UL' || node.tagName === 'OL') {
|
||||
Array.from(node.children).forEach(li => {
|
||||
listEl.appendChild(li);
|
||||
});
|
||||
content.removeChild(node);
|
||||
} else {
|
||||
const li = document.createElement('li');
|
||||
content.removeChild(node);
|
||||
li.appendChild(node);
|
||||
listEl.appendChild(li);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1959,32 +1976,36 @@ function formaFun(range) {
|
||||
return range.compareBoundaryPoints(Range.END_TO_START, er) < 0
|
||||
&& range.compareBoundaryPoints(Range.START_TO_END, er) > 0;
|
||||
};
|
||||
Array.from(content.children).forEach(child => {
|
||||
if (intersects(child)) externals.add(child);
|
||||
Array.from(document.querySelectorAll('.content')).forEach(content => {
|
||||
Array.from(content.children).forEach(child => {
|
||||
if (intersects(child)) externals.add(child);
|
||||
});
|
||||
});
|
||||
externals.forEach(el => {
|
||||
el.style.textAlign = '';
|
||||
});
|
||||
|
||||
const itList = document.createNodeIterator(
|
||||
content,
|
||||
NodeFilter.SHOW_ELEMENT,
|
||||
{
|
||||
acceptNode: n =>
|
||||
(n.tagName === 'UL' || n.tagName === 'OL') &&
|
||||
range.intersectsNode(n)
|
||||
? NodeFilter.FILTER_ACCEPT
|
||||
: NodeFilter.FILTER_REJECT
|
||||
Array.from(document.querySelectorAll('.content')).forEach(content => {
|
||||
const itList = document.createNodeIterator(
|
||||
content,
|
||||
NodeFilter.SHOW_ELEMENT,
|
||||
{
|
||||
acceptNode: n =>
|
||||
(n.tagName === 'UL' || n.tagName === 'OL') &&
|
||||
range.intersectsNode(n)
|
||||
? NodeFilter.FILTER_ACCEPT
|
||||
: NodeFilter.FILTER_REJECT
|
||||
}
|
||||
);
|
||||
let listEl;
|
||||
while (listEl = itList.nextNode()) {
|
||||
const parent = listEl.parentNode;
|
||||
Array.from(listEl.children).forEach(li => {
|
||||
while (li.firstChild) parent.insertBefore(li.firstChild, listEl);
|
||||
});
|
||||
parent.removeChild(listEl);
|
||||
}
|
||||
);
|
||||
let listEl;
|
||||
while (listEl = itList.nextNode()) {
|
||||
const parent = listEl.parentNode;
|
||||
Array.from(listEl.children).forEach(li => {
|
||||
while (li.firstChild) parent.insertBefore(li.firstChild, listEl);
|
||||
});
|
||||
parent.removeChild(listEl);
|
||||
}
|
||||
});
|
||||
|
||||
function unwrapAllSpansAndLinks(node) {
|
||||
const frag = document.createDocumentFragment();
|
||||
@@ -2079,7 +2100,7 @@ function detectFormatState(format) {
|
||||
const sel = window.getSelection();
|
||||
if (!sel.rangeCount) return 'none';
|
||||
const range = sel.getRangeAt(0);
|
||||
if (!content.contains(range.commonAncestorContainer)) return 'none';
|
||||
if (![...document.querySelectorAll('.content')].some(c => c.contains(range.commonAncestorContainer))) return 'none';
|
||||
const it = document.createNodeIterator(
|
||||
range.commonAncestorContainer,
|
||||
NodeFilter.SHOW_TEXT,
|
||||
@@ -2091,7 +2112,7 @@ function detectFormatState(format) {
|
||||
if (!text) continue;
|
||||
total++;
|
||||
let cur = node.parentElement, ok = false;
|
||||
while (cur && cur !== content) {
|
||||
while (cur && ![...document.querySelectorAll('.content')].includes(cur)) {
|
||||
const fmt = simpleFormats.find(f => f.id === format);
|
||||
const v = fmt ? getComputedStyle(cur)[fmt.prop] || '' : '';
|
||||
if (fmt && fmt.test(v)) { ok = true; break; }
|
||||
@@ -2128,7 +2149,7 @@ function detectSingleState(format) {
|
||||
const sel = window.getSelection();
|
||||
if (!sel.rangeCount) return '';
|
||||
const range = sel.getRangeAt(0);
|
||||
if (!content.contains(range.commonAncestorContainer)) return '';
|
||||
if (![...document.querySelectorAll('.content')].some(c => c.contains(range.commonAncestorContainer))) return '';
|
||||
const it = document.createNodeIterator(
|
||||
range.commonAncestorContainer,
|
||||
NodeFilter.SHOW_TEXT,
|
||||
@@ -2263,7 +2284,7 @@ document.querySelectorAll('.align-dropdown-text').forEach(dropdown => {
|
||||
const sel = window.getSelection()
|
||||
if (sel.rangeCount) {
|
||||
const range = sel.getRangeAt(0)
|
||||
if (content.contains(range.commonAncestorContainer)) {
|
||||
if ([...document.querySelectorAll('.content')].some(c => c.contains(range.commonAncestorContainer))) {
|
||||
singleApplyformat(range, f)
|
||||
inter()
|
||||
}
|
||||
|
||||
@@ -15,22 +15,19 @@ function savePageCenterBlock($params) {
|
||||
|
||||
$saveContentIdXml = $path . $_SESSION['page_url'] . ".page.php";
|
||||
$saveContentIdData = $params['saveContentIdData'] ?? '';
|
||||
$file = @simplexml_load_file($saveContentIdXml);
|
||||
$node = $file->content->{$_SESSION['lng']};
|
||||
|
||||
$file->content->{$_SESSION['lng']} = '';
|
||||
$node = dom_import_simplexml($node);
|
||||
$doc = $node->ownerDocument;
|
||||
$appended = $node->appendChild($doc->createCDATASection("\n" . $saveContentIdData . "\n"));
|
||||
$saved = $file->asXML($saveContentIdXml);
|
||||
$xml = file_get_contents($saveContentIdXml);
|
||||
$xml = preg_replace('#<' . $_SESSION['lng'] . '>.*?</' . $_SESSION['lng'] . '>#s', '<' . $_SESSION['lng'] . '></' . $_SESSION['lng'] . '>', $xml);
|
||||
|
||||
if ($appended && $saved) {
|
||||
return 'true';
|
||||
if (preg_match('#<' . $_SESSION['lng'] . '>#', $xml, $pos)) {
|
||||
$xml = preg_replace('#(<' . $_SESSION['lng'] . '>)#', '$1' . "\n" . $saveContentIdData . "\n", $xml, 1);
|
||||
}
|
||||
|
||||
if (file_put_contents($saveContentIdXml, $xml) !== false) return 'true';
|
||||
throw new Exception("Problem saving content", -32003);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Сохраняет левый и правый блоки страницы
|
||||
* @param array $params Массив с данными блоков, ключ 'floatsBlock' содержит массив левых и правых блоков
|
||||
@@ -130,39 +127,33 @@ function saveHowPageContent($params) {
|
||||
|
||||
$_SESSION['page_url'] = $params['page_url'] . str_replace('.page.php', '', $params['nameFile']);
|
||||
$filePath = $path . $params['page_url'] . $params['nameFile'];
|
||||
$contentData = $params['saveContentIdData'] ?? '';
|
||||
$file = simplexml_load_file($filePath);
|
||||
$langNode = $file->content->{$_SESSION['lng']};
|
||||
$file->content->{$_SESSION['lng']} = '';
|
||||
$node = dom_import_simplexml($langNode);
|
||||
$doc = $node->ownerDocument;
|
||||
$node->appendChild($doc->createCDATASection("\n" . $contentData . "\n"));
|
||||
$contentData = html_entity_decode($params['saveContentIdData'] ?? '', ENT_QUOTES, 'UTF-8');
|
||||
|
||||
$xml = file_get_contents($filePath);
|
||||
$xml = preg_replace('#<' . $_SESSION['lng'] . '>.*?</' . $_SESSION['lng'] . '>#s', '<' . $_SESSION['lng'] . '></' . $_SESSION['lng'] . '>', $xml);
|
||||
$xml = preg_replace('#(<' . $_SESSION['lng'] . '>)#', "$1\n" . $contentData . "\n", $xml, 1);
|
||||
|
||||
$xml = preg_replace('#<rblock>.*?</rblock>#s', '<rblock></rblock>', $xml);
|
||||
$xml = preg_replace('#<lblock>.*?</lblock>#s', '<lblock></lblock>', $xml);
|
||||
|
||||
$file->rblock = '';
|
||||
$file->lblock = '';
|
||||
$blocks = $params['floatsBlock'] ?? [];
|
||||
$titles = $params['title'] ?? [];
|
||||
$urls = $params['pluginUrl'] ?? [];
|
||||
$tclasses = $params['tclass'] ?? [];
|
||||
$bclasses = $params['bclass'] ?? [];
|
||||
|
||||
foreach ($blocks as $i => $blockName) {
|
||||
$newBlock = $file->$blockName->addChild('block');
|
||||
$newBlock->addAttribute('url', htmlspecialchars($urls[$i] ?? '', ENT_QUOTES,'UTF-8'));
|
||||
$newBlock->addAttribute('title', htmlspecialchars($titles[$i] ?? '', ENT_QUOTES,'UTF-8'));
|
||||
$newBlock->addAttribute('tclass',htmlspecialchars($tclasses[$i] ?? '',ENT_QUOTES,'UTF-8'));
|
||||
$newBlock->addAttribute('bclass',htmlspecialchars($bclasses[$i] ?? '',ENT_QUOTES,'UTF-8'));
|
||||
$url = htmlspecialchars($urls[$i] ?? '', ENT_QUOTES, 'UTF-8');
|
||||
$title = htmlspecialchars($titles[$i] ?? '', ENT_QUOTES, 'UTF-8');
|
||||
$tclass = htmlspecialchars($tclasses[$i] ?? '', ENT_QUOTES, 'UTF-8');
|
||||
$bclass = htmlspecialchars($bclasses[$i] ?? '', ENT_QUOTES, 'UTF-8');
|
||||
|
||||
$blockXml = '<block url="' . $url . '" title="' . $title . '" tclass="' . $tclass . '" bclass="' . $bclass . '"/>';
|
||||
$xml = preg_replace('#<' . $blockName . '>#', '<' . $blockName . '>' . "\n" . $blockXml, $xml, 1);
|
||||
}
|
||||
|
||||
$dom = new DOMDocument('1.0','UTF-8');
|
||||
$dom->preserveWhiteSpace = false;
|
||||
$dom->formatOutput = true;
|
||||
$dom->loadXML($file->asXML());
|
||||
|
||||
$saved = $dom->save($filePath);
|
||||
if ($saved === false) {
|
||||
throw new Exception("Failed to save content", -32003);
|
||||
}
|
||||
return 'true';
|
||||
if (file_put_contents($filePath, $xml) !== false) return 'true';
|
||||
throw new Exception("Failed to save content", -32003);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,11 +175,12 @@ function createNewPage($params) {
|
||||
}
|
||||
|
||||
$file = simplexml_load_file($saveContentIdXml);
|
||||
$node = $file->content->{$_SESSION['lng']};
|
||||
$file->content->{$_SESSION['lng']} = '';
|
||||
$node = dom_import_simplexml($node);
|
||||
$no = $node->ownerDocument;
|
||||
$node->appendChild($no->createCDATASection("\n" . $saveContentIdData . "\n"));
|
||||
foreach ($file->content->{$_SESSION['lng']} as $node) {
|
||||
$node = dom_import_simplexml($node);
|
||||
$no = $node->ownerDocument;
|
||||
while ($node->firstChild) $node->removeChild($node->firstChild);
|
||||
$node->appendChild($no->createCDATASection("\n" . $saveContentIdData . "\n"));
|
||||
}
|
||||
|
||||
$saved = $file->asXML($saveContentIdXml);
|
||||
if ($saved === false) {
|
||||
|
||||
Reference in New Issue
Block a user