Просмотр исходного кода

fix: recursive content and effected image module

master
Dominik Schmidt-Philipp 1 день назад
Родитель
Сommit
9727ce1ac4
3 измененных файлов: 44 добавлений и 29 удалений
  1. +17
    -13
      app/modules/ceimage.php
  2. +24
    -4
      app/modules/elementdispatcher.php
  3. +3
    -12
      app/modules/filesinfolders.php

+ 17
- 13
app/modules/ceimage.php Просмотреть файл

@@ -8,12 +8,14 @@ class CEimage
public $b;
public $structs;
public $content;
public $domains;
function __construct($request,$body=[],$structs=false,$content=false) {
function __construct($request,$body=[],$structs=false,$content=false,$domains=false) {
$this->r = $request;
$this->b = $body;
$this->structs = &$structs;
$this->content = &$content;
$this->domains = &$domains;
}
function is_width($string) {
@@ -46,21 +48,23 @@ class CEimage
}
}

// image positioning
if( in_array($request[2],array('left','right','full','auto'))) {
$class = $request[2];
} else {
$class = 'full';
}
if (isset($request[3])) {
$width=self::is_width($request[3]) ? $request[3] : false;
}

if ($image) {

// image positioning
if( in_array($request[2],array('left','right','full','auto'))) {
$class = $request[2];
} else {
$class = 'full';
}
if (isset($request[3])) {
$width=self::is_width($request[3]) ? $request[3] : false;
}

$gallery = "gallery";
// image orientation?
$img = new \Image($image);
// $ratio = "landscape";
// $ratio = "landscape";
$ratio = ($img->width() >= $img->height())
? "landscape"
: "portrait"
@@ -84,7 +88,7 @@ class CEimage
."</div>",
$class,
$ratio,
($width ? "style=\"flex-basis:$width;\"" : ''),
(isset($width) ? "style=\"flex-basis:$width;\"" : ''),
$cached->get_src(1600),
$cached->get_src(1600),
$cached->get_src(1600),
@@ -98,7 +102,7 @@ class CEimage
."<div class=\"caption\">\n%s\n</div>\n"
."</div>\n",
$class,
$ratio,
"landscape",
$md->text(implode("\n",$body))
);
}

+ 24
- 4
app/modules/elementdispatcher.php Просмотреть файл

@@ -6,14 +6,34 @@ class ElementDispatcher {
private $folder = "";
private $config = [];
public $structs = null;
public $content = null;
public $domains = null;
function __construct($folder = "",$config = []) {
function __construct($folder = "",$config = [],$structs=false,$content=false,$domains=false) {
if (is_string($folder)) {
$this->folder = $folder;
}
if (is_array($config)) {
$this->config = $config;
}
$this->structs = &$structs;
$this->content = &$content;
$this->domains = &$domains;
}

function dispatch($string) {
// find occorances of {| keyword |}
$pattern = "/\{\|(.+?)\|\}/s";
$f = preg_match_all($pattern, $string,$matches,PREG_PATTERN_ORDER);

for ($i=0;$i<$f;$i++) {
$body = preg_split("/\R/",trim($matches[1][$i]));
$request = explode(":", trim(array_shift($body)));
$new = $this->content_element($request,$body);
$string = str_replace($matches[0][$i],$new,$string);
}
return $string;
}
function content_element($request = [], $body = null) {
@@ -255,7 +275,7 @@ class ElementDispatcher {
}
if (count($request) >= 2) {
$body=str_replace([$request[0],$request[1]],["{|","|}"],$body);
$body=$this->content_element($body);
$body=$this->dispatch($body);
}
$hash=md5($body);
$add=sprintf("<div id=\"%s\" class=\"content_elment_box_body\">\n%s\n</div>",
@@ -435,7 +455,7 @@ class ElementDispatcher {
$new = $checkout->html_cart();
break;
case 'image':
$module = new CEimage($request, $body, $this->structs, $this->content);
$module = new CEimage($request, $body, $this->structs, $this->content, $this->domains);
$new = $module->index();
unset($module);
break;
@@ -458,7 +478,7 @@ class ElementDispatcher {
$counter++;
if (count($request) >= 4) {
$part=str_replace([$request[2],$request[3]],["{|","|}"],$part);
$part=$this->content_element($part);
$part=$this->dispatch($part);
}
$new .= sprintf("<div>\n%s\n</div>",
$md->text($part)

+ 3
- 12
app/modules/filesinfolders.php Просмотреть файл

@@ -7,7 +7,7 @@ class FilesInFolders {
private $folder;
public $content = array();
public $extras = array();
private $domains = array('default'=>'default');
public $domains = array('default'=>'default');
private $keyfiles = array();
public $structs = array();
public $EXT=array(
@@ -375,18 +375,9 @@ class FilesInFolders {
}
function content_element_dispatcher($string) {
$f3 = \Base::instance();
$ED = new ElementDispatcher($this->folder,$this->config);
$ED = new ElementDispatcher($this->folder,$this->config,$this->structs,$this->content,$this->domains);
$string = $ED->dispatch($string);

// find occorances of {| keyword |}
$pattern = "/\{\|(.+?)\|\}/s";
$f = preg_match_all($pattern, $string,$matches,PREG_PATTERN_ORDER);
for ($i=0;$i<$f;$i++) {
$body = preg_split("/\R/",trim($matches[1][$i]));
$request = explode(":", trim(array_shift($body)));
$new = $ED->content_element($request,$body);
$string = str_replace($matches[0][$i],$new,$string);
}
return $string;
}

Загрузка…
Отмена
Сохранить