Обновлена логика центральных блоков: теперь поддерживается несколько блоков

This commit is contained in:
2025-11-15 21:33:38 +02:00
parent ec41330624
commit 5c3e28fd55
26 changed files with 355 additions and 435 deletions

View File

@@ -15,81 +15,11 @@
<content tclass="btitle" bclass="bfloat">
<ru><![CDATA[
<div>
текст текст текст текст текст текст текст текст текст текст текст тексритчрсотат текст текст текст текст </div>
<div>
 текст текст текст текст текыККПАФЦКАКПАМст текст текст текст текст текст текст текст урпкцуептекст текст текст
test1цыкцып
</div>
<div>
 текст текст текст текст текст текст текст текст текст текст текст текст текст текст текст текст текст
test2
</div>
<div>
<hr style="height: 5px; width: 50%; background: rgb(0, 0, 0); border: 0px;">
<br>
</div>
<div>
<table style="width: 50%; margin: 1px; float: left; border: 1px solid rgb(0, 0, 0); background-color: rgb(255, 255, 255); border-collapse: collapse;">
<tbody>
<tr>
<td style="padding: 1px; border: 1px solid rgb(0, 0, 0);">
</td>
<td style="padding: 1px; border: 1px solid rgb(0, 0, 0);">
</td>
<td style="padding: 1px; border: 1px solid rgb(0, 0, 0);">
</td>
<td style="padding: 1px; border: 1px solid rgb(0, 0, 0);">
</td>
</tr>
<tr>
<td style="padding: 1px; border: 1px solid rgb(0, 0, 0);">
</td>
<td style="padding: 1px; border: 1px solid rgb(0, 0, 0);">
</td>
<td style="padding: 1px; border: 1px solid rgb(0, 0, 0);">
</td>
<td style="padding: 1px; border: 1px solid rgb(0, 0, 0);">
</td>
</tr>
<tr>
<td style="padding: 1px; border: 1px solid rgb(0, 0, 0);">
</td>
<td style="padding: 1px; border: 1px solid rgb(0, 0, 0);">
</td>
<td style="padding: 1px; border: 1px solid rgb(0, 0, 0);">
</td>
<td style="padding: 1px; border: 1px solid rgb(0, 0, 0);">
</td>
</tr>
<tr>
<td style="padding: 1px; border: 1px solid rgb(0, 0, 0);">
</td>
<td style="padding: 1px; border: 1px solid rgb(0, 0, 0);">
</td>
<td style="padding: 1px; border: 1px solid rgb(0, 0, 0);">
</td>
<td style="padding: 1px; border: 1px solid rgb(0, 0, 0);">
</td>
</tr>
</tbody>
</table>
<br>
</div>
<div>
<br>
</div>
<div>
<br>
</div>
<div>
<br>
</div>
<div>
<br>
</div>
<div>
<br>
</div>
<div><br>
</div>
]]></ru>
<lv><![CDATA[
<p>Uz šo brīdi šeit ne kā nav</p>

View File

@@ -8,24 +8,12 @@
</general>
<!--Содержание страницы-->
<!--Левые блоки-->
<lblock>
<block url="/plugin/foto/" title="df" tclass="btitle" bclass="bfloat"/>
<block url="/plugin/plugintest/" title="кнерцу" tclass="btitle" bclass="bfloat"/>
<block url="/plugin/foto/" title="цкпм" tclass="btitle" bclass="bfloat"/>
</lblock>
<lblock/>
<!--Правые блоки-->
<rblock>
<block url="/plugin/plugintest/" title="a5ysd" tclass="btitle" bclass="bfloat"/>
</rblock>
<rblock/>
<!--Текст страницы-->
<content tclass="btitle" bclass="bfloat">
<ru><![CDATA[
<!--?php
header('Content-Type: text/html; charset=utf-8');
readfile(__DIR__ . '/DgrmJS-main/src/index.html');
?-->
text
]]></ru>
<ru/>
<lv><![CDATA[
echo file_get_contents(__DIR__ . '/DgrmJS-main/src/index.html');
]]></lv>

View File

@@ -8,95 +8,18 @@
</general>
<!--Содержание страницы-->
<!--Левые блоки-->
<lblock>
</lblock>
<lblock/>
<!--Правые блоки-->
<rblock>
</rblock>
<rblock/>
<!--Текст страницы-->
<content tclass="btitle" bclass="bfloat">
<ru><![CDATA[
<div>
текст текст текст текст текст текст текст текст текст текст текст тексритчрсотат текст текст текст текст </div>
<div>
 текст текст текст текст текыККПАФЦКАКПАМст текст текст текст текст текст текст текст урпкцуептекст текст текст
</div>
<div>
 текст текст текст текст текст текст текст текст текст текст текст текст текст текст текст текст текст
</div>
<div>
<hr style="height: 5px; width: 50%; background: rgb(0, 0, 0); border: 0px;">
<br>
</div>
<div>
<table style="width: 50%; margin: 1px; float: left; border: 1px solid rgb(0, 0, 0); background-color: rgb(255, 255, 255); border-collapse: collapse;">
<tbody>
<tr>
<td style="padding: 1px; border: 1px solid rgb(0, 0, 0);">
</td>
<td style="padding: 1px; border: 1px solid rgb(0, 0, 0);">
</td>
<td style="padding: 1px; border: 1px solid rgb(0, 0, 0);">
</td>
<td style="padding: 1px; border: 1px solid rgb(0, 0, 0);">
</td>
</tr>
<tr>
<td style="padding: 1px; border: 1px solid rgb(0, 0, 0);">
</td>
<td style="padding: 1px; border: 1px solid rgb(0, 0, 0);">
</td>
<td style="padding: 1px; border: 1px solid rgb(0, 0, 0);">
</td>
<td style="padding: 1px; border: 1px solid rgb(0, 0, 0);">
</td>
</tr>
<tr>
<td style="padding: 1px; border: 1px solid rgb(0, 0, 0);">
</td>
<td style="padding: 1px; border: 1px solid rgb(0, 0, 0);">
</td>
<td style="padding: 1px; border: 1px solid rgb(0, 0, 0);">
</td>
<td style="padding: 1px; border: 1px solid rgb(0, 0, 0);">
</td>
</tr>
<tr>
<td style="padding: 1px; border: 1px solid rgb(0, 0, 0);">
</td>
<td style="padding: 1px; border: 1px solid rgb(0, 0, 0);">
</td>
<td style="padding: 1px; border: 1px solid rgb(0, 0, 0);">
</td>
<td style="padding: 1px; border: 1px solid rgb(0, 0, 0);">
</td>
</tr>
</tbody>
</table>
<br>
</div>
<div>
<br>
</div>
<div>
<br>
</div>
<div>
<br>
</div>
<div>
<br>
</div>
<div>
<br>
</div>
<div><br>
</div>
]]></ru>
<ru>
<![CDATA[<div>
test1цыуквацыфавп
</div>]]><![CDATA[<div>
test2
</div>]]>
</ru>
<lv><![CDATA[
<p>  cb <b>bbvcdjyfdyhyhdывепиwstdg</b></p>
]]></lv>

View File

@@ -533,12 +533,12 @@ if(isPhone){
/** @brief Флаг, указывающий, были ли изменения в контенте */
window.contentIsEdit = false;
if (document.getElementById("content")) {
document.getElementById("content").addEventListener("input", function() {
window.contentIsEdit = true;
});
if (document.querySelectorAll(".content").length) {
document.querySelectorAll(".content").forEach(el => {
el.addEventListener("input", () => window.contentIsEdit = true);
const observer = new MutationObserver(() => window.contentIsEdit = true);
observer.observe(document.getElementById("content"), { childList: true, subtree: true });
observer.observe(el, { childList: true, subtree: true });
});
}
/** @brief Очередь сообщений для отображения */
@@ -738,8 +738,11 @@ let cou=1;
* @brief Показать/скрыть HTML-код страницы в textarea
*/
function showHtmlCode() {
let contents = document.getElementsByClassName("content");
if (cou==1) {
document.getElementById("tex").value=document.getElementById("content").innerHTML;
let combined = "";
for (let i=0; i<contents.length; i++) combined += "<![CDATA[" + contents[i].innerHTML + "]]>";
document.getElementById("tex").value = combined;
document.getElementById("tex").value = decodeHtmlEntities(document.getElementById("tex").value);
document.getElementById("tex").value = formatHTML(document.getElementById("tex").value);
let sbe=document.getElementsByClassName("sb");
@@ -754,11 +757,18 @@ function showHtmlCode() {
}
cou=2;
} else {
document.getElementById("content").innerHTML=document.getElementById("tex").value;
let text = document.getElementById("tex").value;
let split = text.match(/<!\[CDATA\[(.*?)\]\]>/gs);
if (split) {
for (let i=0; i<contents.length; i++) {
if (split[i]) contents[i].innerHTML = split[i].replace(/<!\[CDATA\[|\]\]>/g, '');
}
}
document.getElementById("tex").style.visibility="hidden";
cou=1;
}
}
window.showHtmlCode = showHtmlCode;
/** @brief Флаг нового состояния страницы при сохранении */
@@ -783,8 +793,10 @@ window.saveChanges = saveChanges;
*/
function saveContentId() {
if(cou==1) {
document.getElementById("content").innerHTML = decodeHtmlEntities(document.getElementById("content").innerHTML);
document.getElementById("tex").value=document.getElementById("content").innerHTML;
let contents = document.getElementsByClassName("content");
let combined = "";
for (let i = 0; i < contents.length; i++) combined += "<![CDATA[" + contents[i].innerHTML.trim() + "]]>";
document.getElementById("tex").value = combined;
}
document.getElementById("tex").value = decodeHtmlEntities(document.getElementById("tex").value);
let saveContentIdData = document.getElementById("tex").value.trim();
@@ -796,7 +808,7 @@ function saveContentId() {
messageFunction("{{main_block_not_saved}}");
}
});
}
}
/**
* @brief Сохраняет данные подключённых плагинов (левой и правой колонок)
@@ -897,11 +909,10 @@ function formatHTML(html) {
*/
window.saveContentIdHow = async function (currentPath) {
if (cou == 1) {
document.getElementById("content").innerHTML = decodeHtmlEntities(document.getElementById("content").innerHTML);
document.getElementById("tex").value = document.getElementById("content").innerHTML;
let contents = Array.from(document.getElementsByClassName("content")).map(el => el.innerHTML.trim());
document.getElementById("tex").value = contents.map(c => `<![CDATA[${c}]]>`).join('');
}
document.getElementById("tex").value = decodeHtmlEntities(document.getElementById("tex").value);
let saveContentIdData = document.getElementById("tex").value.trim();
let saveContentIdData = decodeHtmlEntities(document.getElementById("tex").value).trim();
let nameFile = document.getElementById('saveHowName').value;
if (!nameFile.endsWith('.page.php')) {
nameFile += '.page.php';
@@ -1315,17 +1326,47 @@ window.functionOpenPage = false;
function getPage(newPath) {
window.functionOpenPage = true;
jsonrpcRequest("getPage", { newPath }).then(page => {
const centerFloat = document.querySelector('.center-float');
const oldBlocks = centerFloat.querySelectorAll('.bfloat');
oldBlocks.forEach(b => {
if (b.querySelector('.content')) {
const next = b.nextSibling;
if (next && next.nodeType === 1 && next.tagName === 'BR') next.remove();
if (next && next.nodeType === 3 && next.textContent.trim() === '') {
const next2 = next.nextSibling;
if (next2 && next2.nodeType === 1 && next2.tagName === 'BR') next2.remove();
}
b.remove();
}
});
page.content.forEach((c, i) => {
const placeholder = document.getElementById('news-placeholder');
if (i > 0) {
const br = document.createElement('br');
centerFloat.insertBefore(br, placeholder);
}
const block = document.createElement('div');
block.className = 'bfloat' + (i === 0 ? ' content1' : '');
block.style.fontSize = '1em';
const inner = document.createElement('div');
inner.className = 'content';
inner.innerHTML = c;
block.appendChild(inner);
centerFloat.insertBefore(block, placeholder);
});
document.getElementById("right-float").innerHTML = page.right;
document.getElementById("left-float").innerHTML = page.left;
document.getElementById("content").innerHTML = page.content;
document.getElementById("managerDiv").style.visibility = "hidden";
// history.pushState(null, '', page.pagePath);
document.getElementById("mainTitle").innerHTML = "<i>{{new_file}}!</i>";
removePluginDom("manager")
removePluginDom("manager");
});
window.newPageFunValue = "";
}
//обьявление функции для того, чтобы обращатся к ней из других файлов
window.getPage = getPage;
window.managerData = managerData;

View File

@@ -3,5 +3,13 @@
<sitename>RaspberryqePi</sitename>
<slogan>Raspberry Pi</slogan>
<index url='content/index' title='Sākuma lapa' name='index' template='rpi' PageMenu='0,1,2' users='' group=''>
<page1 url="content/rpi/index" title="Новый ф6нрцуеыкеа" name="page1" template="MedWait" PageMenu="0,1,2" users="" group="" news="" plugins="">
<underpage1 url="content/rpi/index" title="Загловок" name="underpage1" template="rpi" PageMenu="0,1,2" users="" group="" news="" plugins="">
</underpage1>
<underpage2 url="content/rpi/index" title="Загловок" name="underpage2" template="rpi" PageMenu="0,1,2" users="" group="" news="" plugins="SvgEditorM">
</underpage2>
<createSite url="data/createSite" title="Страница создание нового сайта" name="createSite" template="MedWait" PageMenu="0,1,2" users="" group="" news="" plugins="dgrm">
</createSite>
</page1>
</index>
</site>

View File

@@ -3,7 +3,7 @@
<sitename>site</sitename>
<slogan>site</slogan>
<index url="content/index" title="Новый ф6нрцуеыке" name="index" template="start" PageMenu="0,0" users="" group="" news="" plugins="">
<page1 url="content/rpi/index" title="Новый фрцуеыкеа" name="page1" template="MedWait" PageMenu="0,1,2" users="" group="" news="" plugins="">
<page1 url="content/rpi/index" title="Новый файл" name="page1" template="MedWait" PageMenu="0,1,2" users="" group="" news="" plugins="dgrm,SvgEditorM,form_editor">
<underpage1 url="content/rpi/index" title="Загловок" name="underpage1" template="rpi" PageMenu="0,1,2" users="" group="" news="" plugins="">
</underpage1>
<underpage2 url="content/rpi/index" title="Загловок" name="underpage2" template="rpi" PageMenu="0,1,2" users="" group="" news="" plugins="SvgEditorM">

View File

@@ -307,17 +307,6 @@ function GetBlock ($BlockVar, $side) {
}
}
return $Block;
// $Block.='<div class="'.$BlockVar[$i]['bclass'].'"><div class="bcont">ku ku</div></div>';
/*is_countable($$BlockVar) && count($BlockVar)
$Block = "";
if (is_countable($$BlockVar) && count($BlockVar) > 0){
$Block = "true";
}
else{
$Block = "false";
}
$Block = count($BlockVar);*/
}
@@ -769,14 +758,14 @@ if ($RURLstr!='error'){
function loadPluginsInCenterBlock() {
global $_SESSION, $path, $config;
if ($_SESSION['Login'] == 'true') {
$availablePlugins = ['dgrm', 'SvgEditorM'];
$availablePlugins = ['dgrm', 'SvgEditorM', 'form_editor'];
$pluginDir = $path . 'main_plugin/';
if (is_dir($pluginDir)) {
$dirs = array_diff(scandir($pluginDir), ['.', '..']);
foreach ($dirs as $dir) {
if (is_dir($pluginDir . $dir)) {
if (!in_array($dir, $availablePlugins) || strpos($config['page_plugins'] ?? '', $dir) !== false) {
if ($dir === 'SvgEditorM' || $dir === 'dgrm') {
if ($dir === 'SvgEditorM' || $dir === 'dgrm' || $dir === 'form_editor') {
$html .= includePlugin(['plugin' => $dir]);
}
}
@@ -784,7 +773,6 @@ function loadPluginsInCenterBlock() {
}
}
}
$html .= includePlugin(['plugin' => 'form_editor']);
return $html;
}
?>

View File

@@ -0,0 +1,29 @@
<![CDATA[
<div>
test1цыкцып
</div>]]><![CDATA[
<div>
test2
</div>]]>
<![CDATA[
<div>
test1цыкцып
</div>]]><![CDATA[
<div>
test2
</div>]]>
Array
(
[0] => <div>
test1цыкцып
</div>
[1] => <div>
test2
</div>
)
<![CDATA[<div>
test1цыкцып
</div>]]><![CDATA[<div>
test2
</div>]]>

View File

@@ -7,7 +7,7 @@
/** @brief Путь к текущей директории */
$path = dirname(__FILE__) . '/';
/* if(isset($_SESSION)) { file_put_contents($path . '/error.txt', "" . PHP_EOL, FILE_APPEND); }*/
/* file_put_contents($path . '/error.txt', "" . PHP_EOL, FILE_APPEND); */
session_start();
@@ -150,7 +150,7 @@ if ($access) {
$config['right'] = "<div id='right-float'>" . $config['right'] . "</div>";
$center = '<div class="center-float">' . GetBlock($xmlstr->cblock->block, 'center') . '<div>';
$config['content'] = $xmlstr->content->{$config['lng']};
/* $config['content'] = $xmlstr->content->{$config['lng']}; */
} else {
if ($_SESSION['log_in']) {
$xmlstr = simplexml_load_file($path . 'content/adm/user.page.php');
@@ -161,7 +161,18 @@ if ($access) {
$config['left'] = '';
$config['right'] = '';
$center = '<div class="center-float">' . GetBlock($xmlstr->cblock->block, 'center') . '<div>';
$config['content'] = $xmlstr->content->$config['lng'];
/* $config['content'] = $xmlstr->content->{$config['lng']}; */
}
$xmlString = file_get_contents($path . $config['page_url'] . ".page.php");
preg_match('#<' . $config['lng'] . '>(.*?)</' . $config['lng'] . '>#s', $xmlString, $tagMatch);
$config['content'] = '';
if (preg_match_all('#<!\[CDATA\[(.*?)\]\]>#s', $tagMatch[1], $matches)) {
foreach ($matches[1] as $i => $cdata) {
if ($i > 0)
$config['content'] .= "<br>";
$config['content'] .= '<div class="%cfloat%' . ($i == 0 ? ' content1' : '') . '"><div class="content">' . $cdata . '</div></div>';
}
}
foreach ($config as $key=>$value) if ($key!="request_url")
$config['content'] =str_replace('%'.$key.'%', $value, $config['content']);

View File

@@ -57,7 +57,7 @@ a {
}
textarea {
text-align: center;
/* text-align: center;
border: none;;
padding: 10px;
padding-top: 0.8em;
@@ -69,7 +69,7 @@ a {
overflow: hidden;
resize: none;
line-height: 1em;
caret-color: #fff;
caret-color: #fff; */
}
[data-connect] { display: none; }

View File

@@ -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);
}
@@ -76,11 +76,11 @@ function basisVis() {
}
}
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,65 +494,70 @@ 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;
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;
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 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);
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 <= 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);
}
} else node.childNodes.forEach(traverse);
})(content);
}
} catch (e) {}
const sel = window.getSelection();
sel.removeAllRanges();
@@ -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,11 +1545,14 @@ specialFormats.forEach(f => {
const events = ['pointerup','keyup','input','focus','blur','click'];
events.forEach(evt => {
if (!content) return;
const contents = document.querySelectorAll('.content');
if (!contents || contents.length === 0) return;
contents.forEach(content => {
content.addEventListener(evt, () => {
updateToolbarStyles();
updateSingleSelectors();
});
});
});
}, { once: true });
@@ -1561,7 +1566,8 @@ let currentIndex = 0
/** @brief Сохраняет текущее состояние контента, если оно изменилось */
function inter() {
const editable = document.getElementById("content")
const editables = document.querySelectorAll(".content")
editables.forEach(editable => {
if (editable) {
let currentContent = editable.innerHTML
if (currentContent !== arr[currentIndex]) {
@@ -1570,27 +1576,32 @@ function inter() {
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")
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")
const editables = document.querySelectorAll(".content")
editables.forEach(editable => {
editable.innerHTML = arr[currentIndex]
editable.setAttribute("contenteditable", "true")
})
}
})
@@ -1785,9 +1796,11 @@ function divApplyformat(range, format) {
range.compareBoundaryPoints(Range.START_TO_END, er) > 0;
};
Array.from(document.querySelectorAll('.content')).forEach(content => {
Array.from(content.children).forEach(child => {
if (intersects(child)) externals.add(child);
});
});
externals.forEach(div => {
div.style.textAlign = style.textAlign;
@@ -1811,9 +1824,11 @@ function listApplyformat(range, format) {
if (type === 'listNone') {
const lists = new Set();
Array.from(document.querySelectorAll('.content')).forEach(content => {
Array.from(content.querySelectorAll('li')).forEach(li => {
if (intersects(li)) lists.add(li.parentNode);
});
});
lists.forEach(list => {
const parent = list.parentNode;
@@ -1849,6 +1864,7 @@ function listApplyformat(range, format) {
parent.removeChild(list);
});
} else {
Array.from(document.querySelectorAll('.content')).forEach(content => {
const items = Array.from(content.children).filter(child => intersects(child));
if (!items.length) return;
@@ -1875,6 +1891,7 @@ function listApplyformat(range, format) {
listEl.appendChild(li);
}
});
});
}
}
@@ -1959,13 +1976,16 @@ function formaFun(range) {
return range.compareBoundaryPoints(Range.END_TO_START, er) < 0
&& range.compareBoundaryPoints(Range.START_TO_END, er) > 0;
};
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 = '';
});
Array.from(document.querySelectorAll('.content')).forEach(content => {
const itList = document.createNodeIterator(
content,
NodeFilter.SHOW_ELEMENT,
@@ -1985,6 +2005,7 @@ function formaFun(range) {
});
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()
}

View File

@@ -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) {
if (file_put_contents($filePath, $xml) !== false) return 'true';
throw new Exception("Failed to save content", -32003);
}
return 'true';
}
/**
@@ -184,11 +175,12 @@ function createNewPage($params) {
}
$file = simplexml_load_file($saveContentIdXml);
$node = $file->content->{$_SESSION['lng']};
$file->content->{$_SESSION['lng']} = '';
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) {

View File

@@ -254,7 +254,15 @@ function getPage($params) {
$page = [];
$page['right'] = GetBlock($pageXml->rblock->block, 'right');
$page['left'] = GetBlock($pageXml->lblock->block, 'left');
$page['content'] = (string)$pageXml->content->{$_SESSION['lng']};
$xmlContent = file_get_contents($file);
$lng = $_SESSION['lng'];
preg_match('#<' . $lng . '>(.*?)</' . $lng . '>#s', $xmlContent, $block);
$langBlock = $block[1] ?? '';
preg_match_all('#<!\[CDATA\[(.*?)\]\]>#s', $langBlock, $matches);
$contents = $matches[1] ?? [];
$page['content'] = $contents;
$_SESSION['page_url'] = $rel;
session_write_close();
return $page;

View File

@@ -993,7 +993,7 @@ function treePropertiesDiv() {
inputHtml = `<input type="text" value="${value}" style="font-size: inherit;" readonly disabled>`;
} else if (key.toLowerCase() === "plugins") {
let plugins = (value || '').split(',');
let allPlugins = ['dgrm','SvgEditorM'];
let allPlugins = ['dgrm','SvgEditorM', 'form_editor'];
inputHtml = allPlugins.map(p =>
`<label><input type="checkbox" value="${p}"${plugins.includes(p)?' checked':''}>${p}</label>`
).join(' ');

View File

@@ -187,12 +187,15 @@ ul, ol {
.bfloat {
overflow-x: hidden;
left: -1px;
top: -1px;
position: relative;
border-radius: 0 0 10px 10px;
border-radius: 10px;
padding: 10px;
font-size: 1em;
}
.content1 {
top: -1px;
border-radius: 0 0 10px 10px;
}
.cfloat {
left: -1px;
@@ -228,11 +231,11 @@ ul, ol {
font-weight: bold;
}
#content {
#content, .content {
overflow-x: hidden;
overflow-y: hidden;
}
#content td {
#content td, .content td {
height: 19px;
}
#editor a {

View File

@@ -14,9 +14,7 @@
<div class="%ctitle%" id="mainTitle">
%title%
</div>
<div class="%cfloat%">
<div id="content">%content%</div>
</div>
%content%
</div>
%left%
%right%

View File

@@ -27,8 +27,6 @@
<div class="%ctitle%" id="mainTitle">
%title%
</div>
<div class="%cfloat%">
<div id="content">%content%</div>
</div>
%content%
</div>
</div>

View File

@@ -27,8 +27,6 @@
<div class="%ctitle%" id="mainTitle">
%title%
</div>
<div class="%cfloat%">
<div id="content">%content%</div>
</div>
%content%
</div>
</div>

View File

@@ -27,8 +27,6 @@
<div class="%ctitle%" id="mainTitle">
%title%
</div>
<div class="%cfloat%">
<div id="content">%content%</div>
</div>
%content%
</div>
</div>

View File

@@ -27,8 +27,6 @@
<div class="%ctitle%" id="mainTitle">
%title%
</div>
<div class="%cfloat%">
<div id="content">%content%</div>
</div>
%content%
</div>
</div>

View File

@@ -27,8 +27,6 @@
<div class="%ctitle%" id="mainTitle">
%title%
</div>
<div class="%cfloat%">
<div id="content">%content%</div>
</div>
%content%
</div>
</div>

View File

@@ -23,7 +23,5 @@
<div class="%ctitle%" id="mainTitle">
%title%
</div>
<div class="%cfloat%">
<div id="content">%content%</div>
</div>
%content%
</div>

View File

@@ -49,9 +49,7 @@
<div class="%ctitle%" id="mainTitle">
%title%
</div>
<div class="%cfloat%">
<div id="content">%content%</div>
</div>
%content%
</div>
</div>

View File

@@ -28,9 +28,7 @@
<div class="%ctitle%" id="mainTitle">
%title%
</div>
<div class="%cfloat%">
<div id="content">%content%</div>
</div>
%content%
</div>
</div>

View File

@@ -49,9 +49,7 @@
<div class="%ctitle%" id="mainTitle">
%title%
</div>
<div class="%cfloat%">
<div id="content">%content%</div>
</div>
%content%
</div>
</div>

View File

@@ -26,9 +26,7 @@
<div class="%ctitle%" id="mainTitle">
%title%
</div>
<div class="%cfloat%">
<div id="content">%content%</div>
</div>
%content%
</div>
</div>