Commit f2cbd6bd authored by jan.koester's avatar jan.koester
Browse files

section + i18n extended

parent 8a350a66
Loading
Loading
Loading
Loading
+104 −8
Changes for data/template/default/editor.html: 104 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -490,10 +490,10 @@
                </div>
            </div>

            <!-- Theme Color Palette ("Farbwahl") -->
            <!-- Theme Color Palette -->
            <div id="theme-palette" class="bg-gray-800 p-4 rounded-lg shadow-inner mt-4">
                <h3 class="font-bold text-purple-300 mb-2">Farbwahl</h3>
                <p class="text-xs text-gray-500 mb-2">Theme-Farben &ndash; klicken um in aktives Farbfeld zu &uuml;bernehmen.</p>
                <h3 class="font-bold text-purple-300 mb-2">${I18N_COLOR_PALETTE}</h3>
                <p class="text-xs text-gray-500 mb-2">${I18N_COLOR_PALETTE_DESC}</p>
                <div id="theme-swatches" style="display:flex; flex-wrap:wrap; gap:6px;"></div>
            </div>
        </div>
@@ -1240,13 +1240,15 @@
            ],
            'Button': [
                { key: 'label', label: 'Button Label', type: 'text' },
                { key: 'link_url', label: 'Link URL', type: 'text', placeholder: 'https://...' },
                { key: 'link_type', label: 'Link Type', type: 'select', options: ['url','section'] },
                { key: 'link_url', label: 'Link URL', type: 'text', placeholder: 'https://...', visibleWhen: { key: 'link_type', value: 'url' } },
                { key: 'open_new_tab', label: 'Open in New Tab', type: 'checkbox', visibleWhen: { key: 'link_type', value: 'url' } },
                { key: 'section_id', label: 'Target Section', type: 'section_select', visibleWhen: { key: 'link_type', value: 'section' } },
                { key: 'background_color', label: 'Background Color', type: 'color' },
                { key: 'text_color', label: 'Text Color', type: 'color' },
                { key: 'font_size', label: 'Font Size', type: 'text', placeholder: '16px', responsive: true },
                { key: 'border_radius', label: 'Border Radius', type: 'text', placeholder: '4px', responsive: true },
                { key: 'padding', label: 'Padding', type: 'text', placeholder: '10px 20px', responsive: true },
                { key: 'open_new_tab', label: 'Open in New Tab', type: 'checkbox' },
                { key: 'hidden', label: 'Hidden', type: 'checkbox', responsive: true }
            ],
            'Grid': [
@@ -1287,6 +1289,19 @@
                { key: 'css_content', label: 'CSS', type: 'textarea', placeholder: 'color: red; font-size: 16px;' },
                { key: 'js_content', label: 'JavaScript', type: 'textarea', placeholder: 'console.log("Hello from widget");' },
                { key: 'hidden', label: 'Hidden', type: 'checkbox', responsive: true }
            ],
            'Section': [
                { key: 'background_color', label: 'Background Color', type: 'color', responsive: true },
                { key: 'css_class', label: 'CSS Class', type: 'text', placeholder: 'e.g. hero-section' },
                { key: 'padding', label: 'Padding', type: 'text', placeholder: 'e.g. 40px 20px', responsive: true },
                { key: 'margin', label: 'Margin', type: 'text', placeholder: 'e.g. 0 auto', responsive: true },
                { key: 'max_width', label: 'Max Width', type: 'text', placeholder: 'e.g. 1200px', responsive: true },
                { key: 'min_height', label: 'Min Height', type: 'text', placeholder: 'e.g. 400px', responsive: true },
                { key: 'border_radius', label: 'Border Radius', type: 'text', placeholder: 'e.g. 8px', responsive: true },
                { key: 'border_style', label: 'Border', type: 'text', placeholder: 'e.g. 1px solid #ccc', responsive: true },
                { key: 'opacity', label: 'Opacity', type: 'text', placeholder: '0.0 - 1.0', responsive: true },
                { key: 'vertical_align', label: 'Vertical Align', type: 'select', options: ['top','center','bottom'], responsive: true },
                { key: 'hidden', label: 'Hidden', type: 'checkbox', responsive: true }
            ]
        };

@@ -1434,6 +1449,9 @@

            elementSettingsPanel.innerHTML = html;

            // Apply conditional visibility rules
            applyConditionalVisibility(schema, properties);

            // Attach auto-save listeners to all form inputs
            const form = document.getElementById('prop-editor-form');
            if (form) {
@@ -1442,6 +1460,79 @@
            }
        }

        /**
         * Applies visibleWhen rules: shows/hides fields based on another field's value.
         * Also attaches change listeners to re-evaluate on user interaction.
         */
        function applyConditionalVisibility(schema, properties) {
            for (const field of schema) {
                if (!field.visibleWhen) continue;
                const depKey = field.visibleWhen.key;
                const depVal = field.visibleWhen.value;
                const groupEl = document.getElementById(`prop-${field.key}`);
                if (!groupEl) continue;
                const wrapper = groupEl.closest('.prop-group');
                if (!wrapper) continue;

                // Initial visibility
                const depEl = document.getElementById(`prop-${depKey}`);
                if (depEl) {
                    wrapper.style.display = (depEl.value === depVal) ? '' : 'none';
                    // Listen for changes on the controlling field
                    depEl.addEventListener('change', function() {
                        wrapper.style.display = (this.value === depVal) ? '' : 'none';
                    });
                }
            }
        }

        /**
         * Populates a section_select dropdown with all Section widgets from the document tree.
         */
        async function populateSectionSelect(selectId, currentValue) {
            const selectEl = document.getElementById(selectId);
            if (!selectEl) return;
            try {
                const response = await sendApiRequest([{ command: 'GetDocTree' }]);
                const docTreeResponse = response.find(item => item.doc_tree) || response.find(item => item.docTree) || {};
                const rootNode = docTreeResponse.doc_tree || docTreeResponse.docTree;
                const sections = [];
                if (rootNode) collectSections(rootNode, sections);

                selectEl.innerHTML = '';
                const emptyOpt = document.createElement('option');
                emptyOpt.value = '';
                emptyOpt.textContent = '(select a section)';
                selectEl.appendChild(emptyOpt);

                for (const sec of sections) {
                    const opt = document.createElement('option');
                    opt.value = sec.uuid;
                    opt.textContent = sec.label;
                    if (sec.uuid === currentValue) opt.selected = true;
                    selectEl.appendChild(opt);
                }
            } catch (e) {
                selectEl.innerHTML = '<option value="">(failed to load sections)</option>';
            }
        }

        /**
         * Recursively collects Section nodes from the document tree.
         */
        function collectSections(node, result, depth) {
            depth = depth || 0;
            if (node.name === 'Section') {
                const prefix = '\u00A0\u00A0'.repeat(depth);
                result.push({ uuid: node.uuid, label: prefix + 'Section (' + node.uuid.substring(0, 8) + '...)' });
            }
            if (node.children) {
                for (const child of node.children) {
                    collectSections(child, result, depth + 1);
                }
            }
        }

        /**
         * Renders a single form field based on its type.
         */
@@ -1484,6 +1575,11 @@
                    const checked = (val === true || val === 'true') ? ' checked' : '';
                    html += `<div class="prop-checkbox-row"><input type="checkbox" id="${inputId}" name="${field.key}"${checked}><label for="${inputId}" class="text-sm text-gray-300">${field.label}</label></div>`;
                    break;
                case 'section_select':
                    html += `<select class="prop-select" id="${inputId}" name="${field.key}"><option value="">(loading sections...)</option></select>`;
                    // Async-populate section list after render
                    setTimeout(() => populateSectionSelect(inputId, String(val)), 0);
                    break;
                case 'textarea':
                    html += `<textarea class="prop-textarea" id="${inputId}" name="${field.key}" placeholder="${field.placeholder || ''}">${escapeHtml(String(val))}</textarea>`;
                    break;
@@ -1554,7 +1650,7 @@
        }

        function rteInsertLink() {
            const url = prompt('URL eingeben:', 'https://');
            const url = prompt('${I18N_ENTER_URL}', 'https://');
            if (url) {
                document.execCommand('createLink', false, url);
                const editable = elementSettingsPanel.querySelector('.rte-editable');
@@ -2151,7 +2247,7 @@
            }
        });

        // --- Theme Color Palette ("Farbwahl") ---
        // --- Theme Color Palette ---
        // Active color input that will receive the swatch value
        let _activeColorInput = null;

@@ -2191,7 +2287,7 @@
                html += '</div>';
            }

            container.innerHTML = html || '<p class="text-xs text-gray-600 italic">Keine Theme-Farben gefunden.</p>';
            container.innerHTML = html || '<p class="text-xs text-gray-600 italic">${I18N_NO_THEME_COLORS}</p>';
        }

        /**
+6 −4
Changes for plugins/contact/contact.cpp: 6 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@
#include <session.h>
#include <mail.h>
#include <blogi.h>
#include <i18n.h>

namespace blogi {
    class Contact : public PluginApi{
@@ -74,6 +75,7 @@ namespace blogi {
            }

            libhtmlpp::HtmlString cform,out;
            std::string _lang = getLang(*Args->database[tid]);

            if(!mail.empty() && !name.empty() && !message.empty() && !sessionid.empty()){
                std::string subject="Message from Blogi(";
@@ -82,12 +84,12 @@ namespace blogi {
                subject+=") ";
                subject+=mail;
                sendMail(Args->smtp.get(),_Receiver.c_str(),subject.c_str(),message.c_str());
                cform << "<div id=\"contactform\" ><span>Mail versand!</span></div>";
                cform << "<div id=\"contactform\" ><span>" << tr(_lang,"Mail sent!") << "</span></div>";
            }else{
                cform << "<div id=\"contactform\" ><form method=\"post\" action=\"" << Args->config->buildurl("contact")
                <<"\" ><label for=\"name\">Name: </label> <input type=\"text\" id=\"name\" name=\"name\" ><label for=\"mail\">Email:</label>"
                << " <input id=\"mail\" name=\"mail\" type=\"text\"><label for=\"message\">Nachricht:</label><textarea id=\"message\""
                << " name=\"message\" ></textarea><input type=\"submit\" value=\"Senden\"></form></div>";
                <<"\" ><label for=\"name\">" << tr(_lang,"Name:") << " </label> <input type=\"text\" id=\"name\" name=\"name\" ><label for=\"mail\">" << tr(_lang,"Email:") << "</label>"
                << " <input id=\"mail\" name=\"mail\" type=\"text\"><label for=\"message\">" << tr(_lang,"Message:") << "</label><textarea id=\"message\""
                << " name=\"message\" ></textarea><input type=\"submit\" value=\"" << tr(_lang,"Send") << "\"></form></div>";

            }

+37 −32
Changes for plugins/content/content.cpp: 37 added lines, 32 removed lines.
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@
#include <conf.h>
#include <plugin.h>
#include <session.h>
#include <i18n.h>

#define SITELIMIT 10

@@ -85,8 +86,7 @@ namespace blogi {
            }
        }

        void contentIdxPage(const int tid,libhttppp::HttpRequest &curreq,libhtmlpp::HtmlElement *page,const std::string &tag,int start,int end,const std::string &sessionid){
            libhttppp::HTTPException excep;
        void contentIdxPage(const int tid,libhttppp::HttpRequest &curreq,libhtmlpp::HtmlElement *page,const std::string &tag,int start,int end,const std::string &sessionid){            std::string _lang = getLang(*Args->database[tid]);            libhttppp::HTTPException excep;
            libhtmlpp::HtmlString condat;

            condat << "<div id=\"contentidx\">";
@@ -143,8 +143,8 @@ namespace blogi {
                condat << "<div class=\"blog_entry\">"
                << "<span class=\"title\">" << res[i][1] << "</span>"
                << "<div class=\"blog_entry_idx_content\" ><div  class=\"entry_text\">" << res[i][2] << "</div>"
                << "<span class=\"readmore\"><a href=\""<< Args->config->buildurl("content/read/") << res[i][0] << "\">weiterlesen ...</a></span>"
                << "<span class=\"author\">verfasst von " << res[i][3] << " am "<< res[i][4]  <<" </span></div></div>";
                << "<span class=\"readmore\"><a href=\""<< Args->config->buildurl("content/read/") << res[i][0] << "\">"+tr(_lang,"read more ...")+"</a></span>"
                << "<span class=\"author\">"+tr(_lang,"written by")+" " << res[i][3] << " "+tr(_lang,"on")+" "<< res[i][4]  <<" </span></div></div>";
                meta.append(res[i][1]);
                meta.append(" author: ");
                meta.append(res[i][3]);
@@ -156,10 +156,10 @@ namespace blogi {
            condat << "<div id=\"pager\">";

            if((start - end) >= 0)
                condat << "<a href=\"" << curreq.getRequestURL() << "?start=" << (start- end) <<"\" > Zur&uuml;ck </a>";
                condat << "<a href=\"" << curreq.getRequestURL() << "?start=" << (start- end) <<"\" > "+tr(_lang,"Back")+" </a>";

            if((ncount -10) >= 0 )
                condat << "<a href=\"" << curreq.getRequestURL() << "?start=" << start+10 <<"\" > Weiter </a>";
                condat << "<a href=\"" << curreq.getRequestURL() << "?start=" << start+10 <<"\" > "+tr(_lang,"Next")+" </a>";

            condat << "</div></div>";

@@ -216,6 +216,7 @@ namespace blogi {
        };

        void contentPage(const int tid,libhttppp::HttpRequest& curreq,libhtmlpp::HtmlElement &page,const std::string &sessionid) {
            std::string _lang = getLang(*Args->database[tid]);
            libhttppp::HTTPException excep;
            libhtmlpp::HtmlString condat;

@@ -240,16 +241,16 @@ namespace blogi {
            if (Args->auth->isLoggedIn(tid,curreq,sessionid)) {
                condat << "<div class=\"blog_adminmenu\">"
                << "<ul>"
                << "<li><a href=\"" << Args->config->buildurl("content/edit/") << cid << "\">Bearbeiten</a></li>"
                << "<li><a href=\"" << Args->config->buildurl("content/del/") << cid << "\">Loeschen</a></li>"
                << "<li><a href=\"" << Args->config->buildurl("content/edit/") << cid << "\">"+tr(_lang,"Edit")+"</a></li>"
                << "<li><a href=\"" << Args->config->buildurl("content/del/") << cid << "\">"+tr(_lang,"Delete")+"</a></li>"
                << "</ul>"
                << "</div>";
            }
            condat << "<div class=\"blog_entry\">"
            << "<span class=\"title\">" << res[0][1] << "</span>"
            << "<div class=\"blog_entry_idx_content\" ><div  class=\"text\">" << res[0][2] << "</div>"
            << "<span class=\"author\">verfasst von " << res[0][3] << " am "<< res[0][4]  <<" </span>"
            << "</div></div><a class=\"back_content\" href=\"#\" onclick=\"history.back()\">Zurück</a></div>";
            << "<span class=\"author\">"+tr(_lang,"written by")+" " << res[0][3] << " "+tr(_lang,"on")+" "<< res[0][4]  <<" </span>"
            << "</div></div><a class=\"back_content\" href=\"#\" onclick=\"history.back()\">"+tr(_lang,"Back")+"</a></div>";

            libhtmlpp::HtmlString out;

@@ -277,6 +278,7 @@ namespace blogi {
        };

        void addPostPage(const int tid,libhttppp::HttpRequest &curreq,libhtmlpp::HtmlElement &page,const std::string &sessionid){
            std::string _lang = getLang(*Args->database[tid]);
            char url[512];
            std::vector<char> sbuf;

@@ -427,11 +429,11 @@ namespace blogi {
            libhtmlpp::HtmlString condat;
            condat << "<div id=\"content\">"
            << "<form action=\""<< Args->config->buildurl("content/addpost") << "\" method=\"post\" enctype=\"multipart/form-data\" >"
            << "<span>Titel:</span><input maxlength=\"255\" name=\"blog_title\" type=\"text\" style=\"width: 100%;\" /><br/>"
            << "<span>Kurzbeschreibung:</span><input maxlength=\"255\" name=\"blog_description\" type=\"text\"  style=\"width: 100%;\" /><br/>"
            << "<span>Schlagworte:</span><input name=\"blog_tags\" type=\"text\"  style=\"width: 100%;\" /><br/>"
            << "<span>Text:</span><textarea name=\"blog_content\" type=\"text\" style=\"width: 100%; height:480px;\"> </textarea>"
            << "<input type=\"submit\" value=\"Blog eintrag Posten\"/>"
            << "<span>"+tr(_lang,"Title:")+"</span><input maxlength=\"255\" name=\"blog_title\" type=\"text\" style=\"width: 100%;\" /><br/>"
            << "<span>"+tr(_lang,"Short description:")+"</span><input maxlength=\"255\" name=\"blog_description\" type=\"text\"  style=\"width: 100%;\" /><br/>"
            << "<span>"+tr(_lang,"Tags:")+"</span><input name=\"blog_tags\" type=\"text\"  style=\"width: 100%;\" /><br/>"
            << "<span>"+tr(_lang,"Text:")+"</span><textarea name=\"blog_content\" type=\"text\" style=\"width: 100%; height:480px;\"> </textarea>"
            << "<input type=\"submit\" value=\""+tr(_lang,"Post blog entry")+"\"/>"
            << "</form>"
            << "</div>";

@@ -448,6 +450,7 @@ namespace blogi {
        }

        void delPostPage(const int tid,libhttppp::HttpRequest& curreq,libhtmlpp::HtmlElement &page,const std::string &sessionid) {
            std::string _lang = getLang(*Args->database[tid]);
            std::string sid;
            char url[512];

@@ -479,7 +482,7 @@ namespace blogi {

            libhtmlpp::HtmlString condat;

            condat << "<span>Beitrag geloescht</span>";
            condat << "<span>"+tr(_lang,"Post deleted")+"</span>";

            libhtmlpp::HtmlString out;

@@ -538,7 +541,7 @@ namespace blogi {
        }

        void editPostPage(const int tid,libhttppp::HttpRequest& curreq,libhtmlpp::HtmlElement &page,const std::string &sessionid) {

            std::string _lang = getLang(*Args->database[tid]);
            char url[512];
            if (!Args->auth->isLoggedIn(tid,curreq,sessionid)) {
                libhttppp::HTTPException exp;
@@ -672,17 +675,17 @@ namespace blogi {
            if (ccamount > 0) {
                condat << "<div id=\"content\">"
                << "<form action=\"" << Args->config->buildurl("content/edit/") << cid << "\" method=\"post\" enctype=\"multipart/form-data\" >"
                << "<span>Titel:</span><input maxlength=\"255\" name=\"blog_title\" type=\"text\" style=\"width: 100%;\" value=\"" << res[0][0] << "\" ><br>"
                << "<span>Kurzbeschreibung:</span><input maxlength=\"255\" name=\"blog_descrition\" type=\"text\"  style=\"width: 100%;\" value=\"" << res[0][1] << "\" ><br>"
                << "<span>Schlagworte:</span><input name=\"blog_tags\" type=\"text\"  style=\"width: 100%;\" value=\"";
                << "<span>"+tr(_lang,"Title:")+"</span><input maxlength=\"255\" name=\"blog_title\" type=\"text\" style=\"width: 100%;\" value=\"" << res[0][0] << "\" ><br>"
                << "<span>"+tr(_lang,"Short description:")+"</span><input maxlength=\"255\" name=\"blog_descrition\" type=\"text\"  style=\"width: 100%;\" value=\"" << res[0][1] << "\" ><br>"
                << "<span>"+tr(_lang,"Tags:")+"</span><input name=\"blog_tags\" type=\"text\"  style=\"width: 100%;\" value=\"";
                for (int i = 0; i < ccamount; ++i) {
                    condat << res[i][3];
                    if ((ccamount - 1) != i)
                        condat << " ";
                }
                condat << "\" ><br>"
                << "<span>Text:</span><textarea name=\"blog_content\" type=\"text\" style=\"width: 100%; height:480px;\" >" << res[0][2] << "</textarea>"
                << "<input type=\"submit\" value=\"Blog eintrag Posten\">"
                << "<span>"+tr(_lang,"Text:")+"</span><textarea name=\"blog_content\" type=\"text\" style=\"width: 100%; height:480px;\" >" << res[0][2] << "</textarea>"
                << "<input type=\"submit\" value=\""+tr(_lang,"Post blog entry")+"\">"
                << "</form>"
                << "</div>";
            };
@@ -822,35 +825,37 @@ namespace blogi {
        }

        json_object* getPublishForm(const int tid) override {
            std::string _lang = getLang(*Args->database[tid]);
            json_object *fields = json_object_new_array();

            json_object *f_title = json_object_new_object();
            json_object_object_add(f_title, "key", json_object_new_string("title"));
            json_object_object_add(f_title, "label", json_object_new_string("Title"));
            json_object_object_add(f_title, "label", json_object_new_string(tr(_lang,"Title").c_str()));
            json_object_object_add(f_title, "type", json_object_new_string("text"));
            json_object_object_add(f_title, "required", json_object_new_boolean(1));
            json_object_object_add(f_title, "placeholder", json_object_new_string("Post title"));
            json_object_object_add(f_title, "placeholder", json_object_new_string(tr(_lang,"Post title").c_str()));
            json_object_array_add(fields, f_title);

            json_object *f_desc = json_object_new_object();
            json_object_object_add(f_desc, "key", json_object_new_string("description"));
            json_object_object_add(f_desc, "label", json_object_new_string("Description"));
            json_object_object_add(f_desc, "label", json_object_new_string(tr(_lang,"Description").c_str()));
            json_object_object_add(f_desc, "type", json_object_new_string("text"));
            json_object_object_add(f_desc, "required", json_object_new_boolean(1));
            json_object_object_add(f_desc, "placeholder", json_object_new_string("Short description"));
            json_object_object_add(f_desc, "placeholder", json_object_new_string(tr(_lang,"Short description").c_str()));
            json_object_array_add(fields, f_desc);

            json_object *f_tags = json_object_new_object();
            json_object_object_add(f_tags, "key", json_object_new_string("tags"));
            json_object_object_add(f_tags, "label", json_object_new_string("Tags"));
            json_object_object_add(f_tags, "label", json_object_new_string(tr(_lang,"Tags").c_str()));
            json_object_object_add(f_tags, "type", json_object_new_string("text"));
            json_object_object_add(f_tags, "placeholder", json_object_new_string("tag1 tag2 tag3"));
            json_object_object_add(f_tags, "placeholder", json_object_new_string(tr(_lang,"tag1 tag2 tag3").c_str()));
            json_object_array_add(fields, f_tags);

            return fields;
        }

        void Publish(const int tid, const std::string &html, json_object *params, json_object *response) override {
            std::string _lang = getLang(*Args->database[tid]);
            std::vector<char> sbuf;
            json_object *val_obj = nullptr;

@@ -873,7 +878,7 @@ namespace blogi {

            if (title.empty() || description.empty()) {
                json_object_object_add(response, "status", json_object_new_string("error"));
                json_object_object_add(response, "message", json_object_new_string("Title and description are required."));
                json_object_object_add(response, "message", json_object_new_string(tr(_lang,"Title and description are required.").c_str()));
                return;
            }

@@ -910,7 +915,7 @@ namespace blogi {

                if (authorId <= 0) {
                    json_object_object_add(response, "status", json_object_new_string("error"));
                    json_object_object_add(response, "message", json_object_new_string("No valid author found. Please ensure a user exists."));
                    json_object_object_add(response, "message", json_object_new_string(tr(_lang,"No valid author found. Please ensure a user exists.").c_str()));
                    return;
                }

@@ -951,7 +956,7 @@ namespace blogi {
                }

                json_object_object_add(response, "status", json_object_new_string("success"));
                json_object_object_add(response, "message", json_object_new_string("Content published successfully."));
                json_object_object_add(response, "message", json_object_new_string(tr(_lang,"Content published successfully.").c_str()));
                std::string url = Args->config->getprefix() + "/content/read/" + std::to_string(content_id);
                json_object_object_add(response, "url", json_object_new_string(url.c_str()));
            } catch (std::exception &e) {
@@ -959,7 +964,7 @@ namespace blogi {
                json_object_object_add(response, "message", json_object_new_string(e.what()));
            } catch (...) {
                json_object_object_add(response, "status", json_object_new_string("error"));
                json_object_object_add(response, "message", json_object_new_string("Unknown error during content publish."));
                json_object_object_add(response, "message", json_object_new_string(tr(_lang,"Unknown error during content publish.").c_str()));
            }
        }

+10 −8

File changed.

Preview size limit exceeded, changes collapsed.

+4 −2

File changed.

Preview size limit exceeded, changes collapsed.

Loading