Skip to content

Commit

Permalink
cs fix
Browse files Browse the repository at this point in the history
  • Loading branch information
marcohanke committed Sep 23, 2023
1 parent e761005 commit 5fc47c3
Show file tree
Hide file tree
Showing 28 changed files with 294 additions and 396 deletions.
11 changes: 6 additions & 5 deletions boot.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@

// register extensions
// alfred post post
rex_extension::register('REX_FORM_SAVED', function (rex_extension_point $params) {
rex_extension::register('REX_FORM_SAVED', static function (rex_extension_point $params) {
/** @var rex_form|null $form */
$form = ($params->hasParam('form')) ? $params->getParam('form') : null;
if ($form instanceof mblock_rex_form)
return MBlockRexFormProcessor::postPostSaveAction($params->getSubject(), $form, $_POST); // execute post post
else
return $params->getSubject();
if ($form instanceof mblock_rex_form) {
return MBlockRexFormProcessor::postPostSaveAction($params->getSubject(), $form, $_POST);
} // execute post post

return $params->getSubject();
});

// assets
Expand Down
23 changes: 7 additions & 16 deletions lib/MBlock/DTO/MBlockElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,17 @@

class MBlockElement
{
const KEY = "<mblock:%s/>";
public const KEY = '<mblock:%s/>';

/**
* @var
*/
public $settings;

/**
* @var string
*/
/** @var string */
public $output;

/**
* @var string
*/
/** @var string */
public $form;

/**
* @var int
*/
/** @var int */
public $index;

/**
Expand Down Expand Up @@ -95,7 +86,7 @@ public function setIndex($index)
*/
public function getKeys()
{
$keys = array();
$keys = [];
foreach (get_object_vars($this) as $f => $v) {
$keys[] = sprintf(self::KEY, $f);
}
Expand All @@ -108,10 +99,10 @@ public function getKeys()
*/
public function getValues()
{
$values = array();
$values = [];
foreach (get_object_vars($this) as $f => $v) {
$values[] = $v;
}
return $values;
}
}
}
36 changes: 10 additions & 26 deletions lib/MBlock/DTO/MBlockItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,26 @@

class MBlockItem
{
/**
* @var array
*/
/** @var array */
public $result;

/**
* @var integer
*/
/** @var int */
public $id;

/**
* @var integer
*/
/** @var int */
public $valueId;

/**
* @var integer
*/
/** @var int */
public $systemId;

/**
* @var string
*/
/** @var string */
public $systemName;

/**
* @var string
*/
/** @var string */
public $form;

/**
* @var array
*/
public $payload = array();
/** @var array */
public $payload = [];

/**
* @return array
Expand Down Expand Up @@ -169,7 +155,7 @@ public function setForm($form)
*/
public function getPayload($key = null)
{
if (!is_null($key) && array_key_exists($key, $this->payload)) {
if (null !== $key && array_key_exists($key, $this->payload)) {
return $this->payload[$key];
}
return $this->payload;
Expand All @@ -187,8 +173,6 @@ public function setPayload($payload)
}

/**
* @param $key
* @param $value
* @return $this
* @author Joachim Doerr
*/
Expand All @@ -197,4 +181,4 @@ public function addPayload($key, $value)
$this->payload[$key] = $value;
return $this;
}
}
}
43 changes: 16 additions & 27 deletions lib/MBlock/Decorator/MBlockFormItemDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ class MBlockFormItemDecorator
use \MBlock\Decorator\MBlockDOMTrait;

/**
* @param MBlockItem $item
* @return String
* @return string
* @author Joachim Doerr
*/
static public function decorateFormItem(MBlockItem $item)
public static function decorateFormItem(MBlockItem $item)
{
$dom = self::createDom($item->getForm());

Expand Down Expand Up @@ -58,8 +57,8 @@ static public function decorateFormItem(MBlockItem $item)
/** @var DOMElement $match */
foreach ($matches as $match) {
// continue by media elements
if (strpos($match->getAttribute('id'), 'REX_MEDIA') !== false
or strpos($match->getAttribute('id'), 'REX_LINK') !== false) {
if (str_contains($match->getAttribute('id'), 'REX_MEDIA')
|| str_contains($match->getAttribute('id'), 'REX_LINK')) {
continue;
}
// label for and id change
Expand All @@ -74,8 +73,9 @@ static public function decorateFormItem(MBlockItem $item)
foreach ($match->childNodes as $child) {
switch ($child->nodeName) {
case 'optgroup':
foreach ($child->childNodes as $nodeChild)
foreach ($child->childNodes as $nodeChild) {
self::replaceOptionSelect($match, $nodeChild, $item);
}
break;
case 'option':
if (isset($child->tagName)) {
Expand All @@ -93,20 +93,18 @@ static public function decorateFormItem(MBlockItem $item)
}

/**
* @param DOMElement $element
* @param MBlockItem $item
* @author Joachim Doerr
*/
protected static function replaceName(DOMElement $element, MBlockItem $item)
{
// replace attribute id
preg_match('/\]\[\d+\]\[/', $element->getAttribute('name'), $matches);
if ($matches) $element->setAttribute('name', str_replace($matches[0], '][' . $item->getId() . '][', $element->getAttribute('name')));
if ($matches) {
$element->setAttribute('name', str_replace($matches[0], '][' . $item->getId() . '][', $element->getAttribute('name')));
}
}

/**
* @param DOMElement $element
* @param MBlockItem $item
* @param bool $valueEmpty
* @author Joachim Doerr
*/
Expand All @@ -132,15 +130,15 @@ protected static function replaceValue(DOMElement $element, MBlockItem $item, $v
case 'textarea':
if ($matches && array_key_exists($matches[1], $item->getResult())) {
$result = $item->getResult();
$id = uniqid(md5(rand(1000, 9999)), true);
$id = uniqid(md5(random_int(1000, 9999)), true);
// node value cannot contains &
// so set a unique id there we replace later with the right value
$element->nodeValue = $id;

$valueResult = $result[$matches[1]];

// add the id to the result value
$result[$matches[1]] = array('id' => $id, 'value' => $valueResult);
$result[$matches[1]] = ['id' => $id, 'value' => $valueResult];

// reset result
$item->setResult($result);
Expand All @@ -154,8 +152,6 @@ protected static function replaceValue(DOMElement $element, MBlockItem $item, $v
}

/**
* @param DOMElement $element
* @param MBlockItem $item
* @author Joachim Doerr
*/
protected static function replaceSelectedData(DOMElement $element, MBlockItem $item)
Expand All @@ -178,8 +174,6 @@ protected static function replaceSelectedData(DOMElement $element, MBlockItem $i
}

/**
* @param DOMElement $element
* @param MBlockItem $item
* @author Joachim Doerr
*/
protected static function replaceChecked(DOMElement $element, MBlockItem $item)
Expand All @@ -201,9 +195,6 @@ protected static function replaceChecked(DOMElement $element, MBlockItem $item)
}

/**
* @param DOMElement $select
* @param DOMElement $option
* @param MBlockItem $item
* @author Joachim Doerr
*/
protected static function replaceOptionSelect(DOMElement $select, DOMElement $option, MBlockItem $item)
Expand Down Expand Up @@ -236,20 +227,19 @@ protected static function replaceOptionSelect(DOMElement $select, DOMElement $op
}

/**
* @param DOMDocument $dom
* @param DOMElement $element
* @param MBlockItem $item
* @return bool
* @author Joachim Doerr
*/
protected static function replaceForId(DOMDocument $dom, DOMElement $element, MBlockItem $item)
{
// get input id
if (!$elementId = $element->getAttribute('id')) return true;
if (!$elementId = $element->getAttribute('id')) {
return true;
}

// ignore system elements
if (strpos($elementId, 'REX_MEDIA') !== false
or strpos($elementId, 'REX_LINK') !== false) {
if (str_contains($elementId, 'REX_MEDIA')
|| str_contains($elementId, 'REX_LINK')) {
return false;
}

Expand All @@ -271,7 +261,6 @@ protected static function replaceForId(DOMDocument $dom, DOMElement $element, MB
}

/**
* @param DOMElement $element
* @return mixed
* @author Joachim Doerr
*/
Expand Down
39 changes: 17 additions & 22 deletions lib/MBlock/Decorator/MBlockReplacerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,46 @@
/**
* User: joachimdoerr
* Date: 31.05.18
* Time: 15:07
* Time: 15:07.
*/

namespace MBlock\Decorator;


use DOMDocument;
use DOMElement;
use IntlChar;

use function count;

trait MBlockDOMTrait
{
/**
* @param $html
* @return DOMDocument
* @author Joachim Doerr
*/
private static function createDom($html)
{
$dom = new DOMDocument();
//replaces $html = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8');
$html = preg_replace_callback('/[\x{80}-\x{10FFFF}]/u', function ($match) {
// replaces $html = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8');
$html = preg_replace_callback('/[\x{80}-\x{10FFFF}]/u', static function ($match) {
$utf8 = $match[0];
return '&#' . \IntlChar::ord($utf8) . ';';
return '&#' . IntlChar::ord($utf8) . ';';
}, htmlentities($html, ENT_COMPAT, 'UTF-8'));
$html = htmlspecialchars_decode($html,ENT_QUOTES);
$html = htmlspecialchars_decode($html, ENT_QUOTES);
@$dom->loadHTML("<html xmlns=\"http://www.w3.org/1999/xhtml\"><body>$html</body></html>");
$dom->preserveWhiteSpace = false;
return $dom;
}

/**
* @param DOMDocument $dom
* @return string
* @author Joachim Doerr
*/
private static function saveHtml(DOMDocument $dom)
{
$html = $dom->saveHTML();
if (strpos($html, '<body') !== false) {
preg_match("/<body>(.*)<\/body>/ism", $html, $matches);
if (str_contains($html, '<body')) {
preg_match('/<body>(.*)<\\/body>/ism', $html, $matches);
if (isset($matches[1])) {
$html = $matches[1];
}
Expand All @@ -50,23 +50,20 @@ private static function saveHtml(DOMDocument $dom)
}

/**
* @param DOMDocument $dom
* @param $element
* @param $class
* @return array
* @author Joachim Doerr
*/
private static function getElementsByClass(DOMDocument $dom, $element)
{
$elementClass= explode('.', $element);
$elementClass = explode('.', $element);
$element = $elementClass[0];
$class = $elementClass[1];
$nodeList = array();
$nodeList = [];
$elements = $dom->getElementsByTagName($element);
if (sizeof($elements) > 0) {
if (count($elements) > 0) {
/** @var DOMElement $element */
foreach ($elements as $element) {
if (strpos($element->getAttribute('class'), $class) !== false) {
if (str_contains($element->getAttribute('class'), $class)) {
$nodeList[] = $element;
}
}
Expand All @@ -75,20 +72,18 @@ private static function getElementsByClass(DOMDocument $dom, $element)
}

/**
* @param DOMDocument $dom
* @param $element
* @return array
* @author Joachim Doerr
*/
private static function getElementsByData(DOMDocument $dom, $element)
{
preg_match('/^.(\[.*?\])$/m', $element, $matches);
$element = str_replace($matches[1], '', $matches[0]);
$data = str_replace(array('[',']','"'), '', $matches[1]);
$data = str_replace(['[', ']', '"'], '', $matches[1]);
$data = explode('=', $data);
$nodeList = array();
$nodeList = [];
$elements = $dom->getElementsByTagName($element);
if (sizeof($elements) > 0) {
if (count($elements) > 0) {
/** @var DOMElement $element */
foreach ($elements as $element) {
if ($element->hasAttribute($data[0]) && $element->getAttribute($data[0]) == $data[1]) {
Expand Down
Loading

0 comments on commit 5fc47c3

Please sign in to comment.