-
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"plugin-data": {
|
||||
"description": "Definer kode for de brugerdefinerede felter, og fortolk indholdet af siderne.",
|
||||
"name": "Custom fields parser"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"plugin-data":
|
||||
{
|
||||
"name": "Custom fields parser",
|
||||
"description": "Define code for the custom fields and parse the content of the pages."
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"plugin-data":
|
||||
{
|
||||
"name": "تحلیلگر کادر سفارشی",
|
||||
"description": "برای کادرهای سفارشی کد تعریف کرده و محتوای صفحات را تحلیل کنید."
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"plugin-data":
|
||||
{
|
||||
"name": "Analyseur de champs personnalisés",
|
||||
"description": "Définissez le code des champs personnalisés et analysez le contenu des pages."
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"plugin-data": {
|
||||
"name": "Парсер пользовательских полей",
|
||||
"description": "Ищет код пользовательских полей и отпределяет содержимое страниц в соответствии с найденным кодом."
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"author": "Bludit",
|
||||
"email": "",
|
||||
"website": "https://plugins.bludit.com",
|
||||
"version": "3.22.0",
|
||||
"releaseDate": "2026-05-10",
|
||||
"license": "MIT",
|
||||
"compatible": "3.22",
|
||||
"notes": ""
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
class pluginCustomFieldsParser extends Plugin {
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->dbFields = array(
|
||||
'label'=>'Custom fields parser',
|
||||
'jsondb'=>json_encode(array())
|
||||
);
|
||||
}
|
||||
|
||||
public function form()
|
||||
{
|
||||
global $L;
|
||||
global $site;
|
||||
|
||||
$html = '<div class="alert alert-primary" role="alert">';
|
||||
$html .= $this->description();
|
||||
$html .= '</div>';
|
||||
|
||||
$jsondb = $this->getValue('jsondb', false);
|
||||
$database = json_decode($jsondb, true);
|
||||
|
||||
$customFields = $site->customFields();
|
||||
|
||||
foreach ($customFields as $field=>$options) {
|
||||
if ($options['type']=="string") {
|
||||
$html .= '<div>';
|
||||
$html .= '<label>'.$options['label'].'</label>';
|
||||
$html .= '<textarea name="'.$field.'">'.(isset($database[$field])?$database[$field]:'').'</textarea>';
|
||||
$html .= '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function post()
|
||||
{
|
||||
$this->db['jsondb'] = Sanitize::html(json_encode($_POST));
|
||||
return $this->save();
|
||||
}
|
||||
|
||||
public function parse($page)
|
||||
{
|
||||
$jsondb = $this->getValue('jsondb', false);
|
||||
$database = json_decode($jsondb, true);
|
||||
$parsedCode = array();
|
||||
|
||||
// Ensure $database is a valid array before iterating
|
||||
if (is_array($database)) {
|
||||
foreach ($database as $field=>$code) {
|
||||
$value = $page->custom($field);
|
||||
$parsedCode['{{ '.$field.' }}'] = str_replace('{{ value }}', $value, $code);
|
||||
}
|
||||
}
|
||||
|
||||
$content = $page->contentRaw();
|
||||
if (!empty($parsedCode)) {
|
||||
$content = str_replace(array_keys($parsedCode), array_values($parsedCode), $content);
|
||||
}
|
||||
|
||||
// Parse Markdown
|
||||
if (MARKDOWN_PARSER) {
|
||||
$parsedown = new Parsedown();
|
||||
$content = $parsedown->text($content);
|
||||
}
|
||||
|
||||
// Parse img src relative to absolute (with domain)
|
||||
if (IMAGE_RELATIVE_TO_ABSOLUTE) {
|
||||
$domain = IMAGE_RESTRICT ? DOMAIN_UPLOADS_PAGES . $page->uuid() . '/' : DOMAIN_UPLOADS;
|
||||
$content = Text::imgRel2Abs($content, $domain);
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
public function beforeSiteLoad()
|
||||
{
|
||||
if ($GLOBALS['WHERE_AM_I']=='page') {
|
||||
$GLOBALS['page']->setField('content', $this->parse($GLOBALS['page']));
|
||||
} else {
|
||||
foreach ($GLOBALS['content'] as $key=>$page) {
|
||||
$GLOBALS['content'][$key]->setField('content', $this->parse($GLOBALS['content'][$key]));
|
||||
}
|
||||
if (!empty($GLOBALS['content'])) {
|
||||
$GLOBALS['page'] = $GLOBALS['content'][0];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user