Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
update
  • Loading branch information
peter-mw committed Nov 29, 2022
1 parent 0d908ba commit 20df566
Show file tree
Hide file tree
Showing 11 changed files with 564 additions and 42 deletions.
12 changes: 10 additions & 2 deletions src/MicroweberPackages/App/Utils/Parser.php
Expand Up @@ -135,10 +135,14 @@ public function replace_url_placeholders($layout)

public function make_tags($layout, $options = array())
{

if ($layout == '') {
if ($layout == '') {
return $layout;
}

$layout = str_ireplace('{SITE_URL}','___mw-site-url-temp-replace-on-make-tags___', $layout);



require_once __DIR__ . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'phpQuery.php';

$pq = \phpQuery::newDocument($layout);
Expand Down Expand Up @@ -261,6 +265,10 @@ public function make_tags($layout, $options = array())
}
}

$layout = str_ireplace('___mw-site-url-temp-replace-on-make-tags___','{SITE_URL}', $layout);



return $layout;
}

Expand Down
37 changes: 34 additions & 3 deletions src/MicroweberPackages/App/Utils/lib/phpQuery.php
Expand Up @@ -221,7 +221,14 @@ public function load($markup, $contentType = null, $newDocumentID = null)
}
if ($loaded) {
// $this->document->formatOutput = true;
$this->document->formatOutput = false;
$this->document->preserveWhiteSpace = true;

$this->document->validateOnParse=false;
$this->document->strictErrorChecking=false;
$this->document->recover=false;


$this->xpath = new DOMXPath($this->document);
$this->afterMarkupLoad();

Expand Down Expand Up @@ -294,11 +301,21 @@ protected function documentCreate($charset, $version = '1.0')
if (!$version) {
$version = '1.0';
}

libxml_use_internal_errors(true);

$this->document = new DOMDocument($version, $charset);
$this->charset = $this->document->encoding;
// $this->document->encoding = $charset;
$this->document->formatOutput = true;
// $this->document->formatOutput = true;
$this->document->formatOutput = false;
// $this->document->standalone = true;
$this->document->preserveWhiteSpace = true;


$this->document->validateOnParse=false;
$this->document->strictErrorChecking=false;
$this->document->recover=false;
}

protected function loadMarkupHTML($markup, $requestedCharset = null)
Expand Down Expand Up @@ -378,7 +395,15 @@ protected function loadMarkupHTML($markup, $requestedCharset = null)
? $this->document->loadHTML($markup)
: @$this->document->loadHTML($markup); */

$return = @$this->document->loadHTML($markup);
// $return = @$this->document->loadHTML($markup);
$return = @$this->document->loadHTML($markup,
LIBXML_SCHEMA_CREATE |
LIBXML_HTML_NOIMPLIED |
LIBXML_HTML_NODEFDTD |
LIBXML_NOERROR |
LIBXML_NONET |
LIBXML_NOWARNING
);

if ($return) {
$this->root = $this->document;
Expand Down Expand Up @@ -763,6 +788,10 @@ private function documentFragmentLoadMarkup($fragment, $charset, $markup = null)
.'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" '
.'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
.'<fake xmlns="http://www.w3.org/1999/xhtml">'.$markup.'</fake>');

/* $fragment->loadMarkupXML('<?xml version="1.0" encoding="'.$charset.'"?>'*/
// . phpQuery::$defaultDoctype.''
// .'<fake xmlns="http://www.w3.org/1999/xhtml">'.$markup.'</fake>');
$fragment->root = $fragment->document->firstChild->nextSibling;
} else {
$fragment->loadMarkupXML('<?xml version="1.0" encoding="'.$charset.'"?><fake>'.$markup.'</fake>');
Expand Down Expand Up @@ -5079,8 +5108,10 @@ abstract class phpQuery
*
* @var unknown_type
*/
public static $defaultDoctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
public static $defaultDoctype_old = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">';

public static $defaultDoctype = '<!doctype html>';
public static $defaultCharset = 'UTF-8';

/**
Expand Down
1 change: 1 addition & 0 deletions src/MicroweberPackages/Content/ContentManagerCrud.php
Expand Up @@ -2,6 +2,7 @@
namespace MicroweberPackages\Content;

use MicroweberPackages\Content\Repositories\ContentRepository;
use MicroweberPackages\Content\Models\Content;
use MicroweberPackages\Database\Crud;
use Illuminate\Support\Facades\DB;
use function Opis\Closure\serialize as serializeClosure;
Expand Down
12 changes: 8 additions & 4 deletions src/MicroweberPackages/Content/ContentManagerHelpers.php
Expand Up @@ -1065,15 +1065,14 @@ public function save_from_live_edit($post_data)

$html_to_save = $content = $this->app->parser->make_tags($html_to_save);

// AntiXSS makes bug on save convertind comments to htmlentities
// $antixss = new AntiXSS();
// $html_to_save = $content = $antixss->xss_clean($html_to_save);
//\Log::info($html_to_save);


$xssClean = new XSSClean();
$html_to_save = $content = $xssClean->clean($html_to_save);



// \Log::info($html_to_save);

if ($save_module == false and $save_global == false and $save_layout == false) {
if ($content_id) {
Expand Down Expand Up @@ -1135,6 +1134,8 @@ public function save_from_live_edit($post_data)
$cont_table_save[$field]=$html_to_save;
}
}


$this->app->event_manager->trigger('mw.content.save_edit', $cont_field);

$to_save = array();
Expand Down Expand Up @@ -1371,6 +1372,7 @@ public function save_content_field($data, $delete_the_cache = true)
$table = $table_drafts;
}


$data = $this->app->format->strip_unsafe($data);

if (isset($data['is_draft']) and $data['is_draft'] and isset($data['url'])) {
Expand Down Expand Up @@ -1506,6 +1508,8 @@ public function save_content_field($data, $delete_the_cache = true)
$data['id'] = $find['id'];
}



$save = $this->app->database_manager->save($data);

$this->app->cache_manager->delete('content_fields');
Expand Down

0 comments on commit 20df566

Please sign in to comment.