Fix deprecation warnings coming from pQuery library
[MAILPOET-3980]
This commit is contained in:
committed by
Veljko V
parent
539f518f64
commit
df6a955f0c
2
lib-3rd-party/pquery/IQuery.php
vendored
2
lib-3rd-party/pquery/IQuery.php
vendored
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace pQuery;
|
||||
namespace MailPoetVendor\pQuery;
|
||||
|
||||
interface IQuery extends \Countable {
|
||||
/// Methods ///
|
||||
|
4
lib-3rd-party/pquery/gan_formatter.php
vendored
4
lib-3rd-party/pquery/gan_formatter.php
vendored
@@ -7,7 +7,7 @@
|
||||
* @package pQuery
|
||||
*/
|
||||
|
||||
namespace pQuery;
|
||||
namespace MailPoetVendor\pQuery;
|
||||
|
||||
/**
|
||||
* Indents text
|
||||
@@ -216,7 +216,7 @@ class HtmlFormatter {
|
||||
}
|
||||
|
||||
if (trim($text)) {
|
||||
$text = \JSMinPlus::minify($text);
|
||||
$text = JSMinPlus::minify($text);
|
||||
if ($wrap_comment) {
|
||||
$text = "<!--\n".$text."\n//-->";
|
||||
}
|
||||
|
26
lib-3rd-party/pquery/gan_node_html.php
vendored
26
lib-3rd-party/pquery/gan_node_html.php
vendored
@@ -7,7 +7,7 @@
|
||||
* @package pQuery
|
||||
*/
|
||||
|
||||
namespace pQuery;
|
||||
namespace MailPoetVendor\pQuery;
|
||||
|
||||
/**
|
||||
* Holds (x)html/xml tag information like tag name, attributes,
|
||||
@@ -65,14 +65,14 @@ class DomNode implements IQuery {
|
||||
* @var string
|
||||
* @see select()
|
||||
*/
|
||||
var $selectClass = 'pQuery\\HtmlSelector';
|
||||
var $selectClass = 'MailPoetVendor\\pQuery\\HtmlSelector';
|
||||
/**
|
||||
* Name of the parser class
|
||||
* @var string
|
||||
* @see setOuterText()
|
||||
* @see setInnerText()
|
||||
*/
|
||||
var $parserClass = 'pQuery\\Html5Parser';
|
||||
var $parserClass = 'MailPoetVendor\\pQuery\\Html5Parser';
|
||||
|
||||
/**
|
||||
* Name of the class used for {@link addChild()}
|
||||
@@ -83,37 +83,37 @@ class DomNode implements IQuery {
|
||||
* Name of the class used for {@link addText()}
|
||||
* @var string
|
||||
*/
|
||||
var $childClass_Text = 'pQuery\\TextNode';
|
||||
var $childClass_Text = 'MailPoetVendor\\pQuery\\TextNode';
|
||||
/**
|
||||
* Name of the class used for {@link addComment()}
|
||||
* @var string
|
||||
*/
|
||||
var $childClass_Comment = 'pQuery\\CommentNode';
|
||||
var $childClass_Comment = 'MailPoetVendor\\pQuery\\CommentNode';
|
||||
/**
|
||||
* Name of the class used for {@link addContional()}
|
||||
* @var string
|
||||
*/
|
||||
var $childClass_Conditional = 'pQuery\\ConditionalTagNode';
|
||||
var $childClass_Conditional = 'MailPoetVendor\\pQuery\\ConditionalTagNode';
|
||||
/**
|
||||
* Name of the class used for {@link addCDATA()}
|
||||
* @var string
|
||||
*/
|
||||
var $childClass_CDATA = 'pQuery\\CdataNode';
|
||||
var $childClass_CDATA = 'MailPoetVendor\\pQuery\\CdataNode';
|
||||
/**
|
||||
* Name of the class used for {@link addDoctype()}
|
||||
* @var string
|
||||
*/
|
||||
var $childClass_Doctype = 'pQuery\\DoctypeNode';
|
||||
var $childClass_Doctype = 'MailPoetVendor\\pQuery\\DoctypeNode';
|
||||
/**
|
||||
* Name of the class used for {@link addXML()}
|
||||
* @var string
|
||||
*/
|
||||
var $childClass_XML = 'pQuery\\XmlNode';
|
||||
var $childClass_XML = 'MailPoetVendor\\pQuery\\XmlNode';
|
||||
/**
|
||||
* Name of the class used for {@link addASP()}
|
||||
* @var string
|
||||
*/
|
||||
var $childClass_ASP = 'pQuery\\AspEmbeddedNode';
|
||||
var $childClass_ASP = 'MailPoetVendor\\pQuery\\AspEmbeddedNode';
|
||||
|
||||
/**
|
||||
* Parent node, null if none
|
||||
@@ -311,7 +311,7 @@ class DomNode implements IQuery {
|
||||
/**
|
||||
* Class magic invoke method, performs {@link query()}.
|
||||
* @param string $query The css query to run on the nodes.
|
||||
* @return \pQuery
|
||||
* @return pQuery
|
||||
*/
|
||||
function __invoke($query = '*') {
|
||||
return $this->query($query);
|
||||
@@ -1922,7 +1922,7 @@ class DomNode implements IQuery {
|
||||
*/
|
||||
public function query($query = '*') {
|
||||
$select = $this->select($query);
|
||||
$result = new \pQuery((array)$select);
|
||||
$result = new pQuery((array)$select);
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -2352,7 +2352,7 @@ class DomNode implements IQuery {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function count() {
|
||||
public function count(): int {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
4
lib-3rd-party/pquery/gan_parser_html.php
vendored
4
lib-3rd-party/pquery/gan_parser_html.php
vendored
@@ -7,7 +7,7 @@
|
||||
* @package pQuery
|
||||
*/
|
||||
|
||||
namespace pQuery;
|
||||
namespace MailPoetVendor\pQuery;
|
||||
|
||||
/**
|
||||
* Parses a HTML document
|
||||
@@ -488,7 +488,7 @@ class HtmlParser extends HtmlParserBase {
|
||||
* @internal If string, then it will create a new instance as root
|
||||
* @var DomNode
|
||||
*/
|
||||
var $root = 'pQuery\\DomNode';
|
||||
var $root = 'MailPoetVendor\\pQuery\\DomNode';
|
||||
|
||||
/**
|
||||
* Current parsing hierarchy
|
||||
|
6
lib-3rd-party/pquery/gan_selector_html.php
vendored
6
lib-3rd-party/pquery/gan_selector_html.php
vendored
@@ -7,7 +7,7 @@
|
||||
* @package pQuery
|
||||
*/
|
||||
|
||||
namespace pQuery;
|
||||
namespace MailPoetVendor\pQuery;
|
||||
|
||||
/**
|
||||
* Tokenizes a css selector query
|
||||
@@ -281,7 +281,7 @@ class HtmlSelector {
|
||||
* @internal If string, then it will create a new instance as parser
|
||||
* @var CSSQueryTokenizer
|
||||
*/
|
||||
var $parser = 'pQuery\\CSSQueryTokenizer';
|
||||
var $parser = 'MailPoetVendor\\pQuery\\CSSQueryTokenizer';
|
||||
|
||||
/**
|
||||
* Target of queries
|
||||
@@ -945,5 +945,3 @@ class HtmlSelector {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
2
lib-3rd-party/pquery/gan_tokenizer.php
vendored
2
lib-3rd-party/pquery/gan_tokenizer.php
vendored
@@ -7,7 +7,7 @@
|
||||
* @package pQuery
|
||||
*/
|
||||
|
||||
namespace pQuery;
|
||||
namespace MailPoetVendor\pQuery;
|
||||
|
||||
/**
|
||||
* Converts a document into tokens
|
||||
|
2
lib-3rd-party/pquery/gan_xml2array.php
vendored
2
lib-3rd-party/pquery/gan_xml2array.php
vendored
@@ -7,7 +7,7 @@
|
||||
* @package pQuery
|
||||
*/
|
||||
|
||||
namespace pQuery;
|
||||
namespace MailPoetVendor\pQuery;
|
||||
|
||||
/**
|
||||
* Converts a XML document to an array
|
||||
|
4
lib-3rd-party/pquery/ganon.php
vendored
4
lib-3rd-party/pquery/ganon.php
vendored
@@ -7,8 +7,8 @@
|
||||
* @package pQuery
|
||||
*/
|
||||
|
||||
use pQuery\Html5Parser;
|
||||
use pQuery\HtmlFormatter;
|
||||
use MailPoetVendor\pQuery\Html5Parser;
|
||||
use MailPoetVendor\pQuery\HtmlFormatter;
|
||||
|
||||
/**
|
||||
* Returns HTML DOM from string
|
||||
|
28
lib-3rd-party/pquery/pQuery.php
vendored
28
lib-3rd-party/pquery/pQuery.php
vendored
@@ -7,12 +7,13 @@
|
||||
* @package pQuery
|
||||
*/
|
||||
|
||||
use pQuery\IQuery;
|
||||
namespace MailPoetVendor\pQuery;
|
||||
|
||||
|
||||
/**
|
||||
* A jQuery-like object for php.
|
||||
*/
|
||||
class pQuery implements ArrayAccess, IteratorAggregate, IQuery {
|
||||
class pQuery implements \ArrayAccess, \IteratorAggregate, IQuery {
|
||||
/// Properties ///
|
||||
|
||||
/**
|
||||
@@ -78,15 +79,15 @@ class pQuery implements ArrayAccess, IteratorAggregate, IQuery {
|
||||
*
|
||||
* @return int Returns the count of matched elements.
|
||||
*/
|
||||
public function count() {
|
||||
public function count(): int {
|
||||
return count($this->nodes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format/beautify a DOM.
|
||||
*
|
||||
* @param pQuery\DomNode $dom The dom to format.
|
||||
* @param array $options Extra formatting options. See {@link pQuery\HtmlFormatter::$options}.
|
||||
* @param DomNode $dom The dom to format.
|
||||
* @param array $options Extra formatting options. See {@link HtmlFormatter::$options}.
|
||||
* @return bool Returns `true` on sucess and `false` on failure.
|
||||
*/
|
||||
// public static function format($dom, $options = array()) {
|
||||
@@ -94,8 +95,8 @@ class pQuery implements ArrayAccess, IteratorAggregate, IQuery {
|
||||
// return $formatter->format($dom);
|
||||
// }
|
||||
|
||||
public function getIterator() {
|
||||
return new ArrayIterator($this->nodes);
|
||||
public function getIterator(): \ArrayIterator {
|
||||
return new \ArrayIterator($this->nodes);
|
||||
}
|
||||
|
||||
public function hasClass($classname) {
|
||||
@@ -118,15 +119,16 @@ class pQuery implements ArrayAccess, IteratorAggregate, IQuery {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function offsetExists($offset) {
|
||||
public function offsetExists($offset): bool {
|
||||
return isset($this->nodes[$offset]);
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetGet($offset) {
|
||||
return isset($this->nodes[$offset]) ? $this->nodes[$offset] : null;
|
||||
}
|
||||
|
||||
public function offsetSet($offset, $value) {
|
||||
public function offsetSet($offset, $value): void {
|
||||
|
||||
if (is_null($offset) || !isset($this->nodes[$offset])) {
|
||||
throw new \BadMethodCallException("You are not allowed to add new nodes to the pQuery object.");
|
||||
@@ -135,7 +137,7 @@ class pQuery implements ArrayAccess, IteratorAggregate, IQuery {
|
||||
}
|
||||
}
|
||||
|
||||
public function offsetUnset($offset) {
|
||||
public function offsetUnset($offset): void {
|
||||
if (isset($this->nodes[$offset])) {
|
||||
$this->nodes[$offset]->remove();
|
||||
unset($this->nodes[$offset]);
|
||||
@@ -147,7 +149,7 @@ class pQuery implements ArrayAccess, IteratorAggregate, IQuery {
|
||||
*
|
||||
* @param string $path The path to the url.
|
||||
* @param resource $context A context suitable to be passed into {@link file_get_contents}
|
||||
* @return pQuery\DomNode Returns the root dom node for the html file.
|
||||
* @return DomNode Returns the root dom node for the html file.
|
||||
*/
|
||||
public static function parseFile($path, $context = null) {
|
||||
$html_str = file_get_contents($path, false, $context);
|
||||
@@ -158,10 +160,10 @@ class pQuery implements ArrayAccess, IteratorAggregate, IQuery {
|
||||
* Query a string of html.
|
||||
*
|
||||
* @param string $html
|
||||
* @return pQuery\DomNode Returns the root dom node for the html string.
|
||||
* @return DomNode Returns the root dom node for the html string.
|
||||
*/
|
||||
public static function parseStr($html) {
|
||||
$parser = new pQuery\Html5Parser($html);
|
||||
$parser = new Html5Parser($html);
|
||||
return $parser->root;
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace MailPoetVendor\pQuery;
|
||||
|
||||
/**
|
||||
* JSMinPlus version 1.4
|
||||
*
|
||||
|
@@ -14,7 +14,6 @@ class RequirementsChecker {
|
||||
|
||||
public $displayErrorNotice;
|
||||
public $vendorClasses = [
|
||||
'\pQuery',
|
||||
'\Cron\CronExpression',
|
||||
'\Html2Text\Html2Text',
|
||||
];
|
||||
|
@@ -3,8 +3,8 @@
|
||||
namespace MailPoet\Newsletter\Editor;
|
||||
|
||||
use MailPoet\Util\DOM as DOMUtil;
|
||||
use pQuery;
|
||||
use pQuery\DomNode;
|
||||
use MailPoet\Util\pQuery\DomNode;
|
||||
use MailPoet\Util\pQuery\pQuery;
|
||||
|
||||
class StructureTransformer {
|
||||
public function transform($content, $imageFullWidth) {
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace MailPoet\Util;
|
||||
|
||||
use pQuery\DomNode;
|
||||
use MailPoet\Util\pQuery\DomNode;
|
||||
|
||||
class DOM {
|
||||
/**
|
||||
|
@@ -2,8 +2,11 @@
|
||||
|
||||
namespace MailPoet\Util\pQuery;
|
||||
|
||||
class DomNode extends \pQuery\DomNode {
|
||||
public $childClass = 'MailPoet\Util\pQuery\DomNode';
|
||||
use MailPoetVendor\pQuery\DomNode as pQueryDomNode;
|
||||
|
||||
class DomNode extends pQueryDomNode {
|
||||
public $childClass = DomNode::class;
|
||||
public $parserClass = Html5Parser::class;
|
||||
|
||||
public function getInnerText() {
|
||||
return html_entity_decode($this->toString(true, true, 1), ENT_NOQUOTES, 'UTF-8');
|
||||
@@ -12,4 +15,10 @@ class DomNode extends \pQuery\DomNode {
|
||||
public function getOuterText() {
|
||||
return html_entity_decode($this->toString(), ENT_NOQUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
public function query($query = '*') {
|
||||
$select = $this->select($query);
|
||||
$result = new pQuery((array)$select);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace MailPoet\Util\pQuery;
|
||||
|
||||
class Html5Parser extends \pQuery\HtmlParser {
|
||||
/** @var string|\pQuery\DomNode */
|
||||
public $root = 'MailPoet\Util\pQuery\DomNode';
|
||||
use MailPoetVendor\pQuery\HtmlParser;
|
||||
|
||||
class Html5Parser extends HtmlParser {
|
||||
/** @var string|DomNode */
|
||||
public $root = DomNode::class;
|
||||
}
|
||||
|
@@ -2,13 +2,15 @@
|
||||
|
||||
namespace MailPoet\Util\pQuery;
|
||||
|
||||
use MailPoetVendor\pQuery\pQuery as pQuerypQuery;
|
||||
|
||||
// extend pQuery class to use UTF-8 encoding when getting elements' inner/outer text
|
||||
// phpcs:ignore Squiz.Classes.ValidClassName
|
||||
class pQuery extends \pQuery {
|
||||
public static function parseStr($html) {
|
||||
class pQuery extends pQuerypQuery {
|
||||
public static function parseStr($html): DomNode {
|
||||
$parser = new Html5Parser($html);
|
||||
|
||||
if (!$parser->root instanceof \pQuery\DomNode) {
|
||||
if (!$parser->root instanceof DomNode) {
|
||||
// this condition shouldn't happen it is here only for PHPStan
|
||||
throw new \Exception('Renderer is not configured correctly');
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@ parameters:
|
||||
ignoreErrors:
|
||||
- '#Function members_register_.+ not found#'
|
||||
- '#Call to an undefined method MailPoetVendor\\Idiorm\\IdiormResultSet::set\(\)#'
|
||||
- '#Argument of an invalid type pQuery\\IQuery supplied for foreach, only iterables are supported#'
|
||||
- '#Argument of an invalid type MailPoetVendor\\pQuery\\IQuery supplied for foreach, only iterables are supported#'
|
||||
- '/(with|has) no (return )?typehint specified/' # exclude level 6 errors
|
||||
- # Primary keys ScheduledTaskSubscriberEntity of are foreign keys and foreign keys may be null because of missing related record
|
||||
message: '#Property MailPoet\\Entities\\[a-zA-Z]+::\$[a-z]+ type mapping mismatch: property can contain MailPoet\\Entities\\[a-zA-Z]+\|null but database expects MailPoet\\Entities\\[a-zA-Z]+.#'
|
||||
|
@@ -12,6 +12,7 @@ use MailPoet\Models\Subscriber;
|
||||
use MailPoet\Newsletter\Url;
|
||||
use MailPoet\Router\Router;
|
||||
use MailPoet\Tasks\Sending as SendingTask;
|
||||
use MailPoet\Util\pQuery\pQuery;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
use MailPoetVendor\Idiorm\ORM;
|
||||
|
||||
@@ -51,7 +52,7 @@ class ShortcodesTest extends \MailPoetTest {
|
||||
// result contains a link pointing to the "view in browser" router endpoint
|
||||
$result = $shortcodes->getArchive($params = false);
|
||||
WordPress::releaseFunction('apply_filters');
|
||||
$dom = \pQuery::parseStr($result);
|
||||
$dom = pQuery::parseStr($result);
|
||||
$link = $dom->query('a');
|
||||
/** @var string $link */
|
||||
$link = $link->attr('href');
|
||||
|
@@ -18,6 +18,7 @@ use MailPoet\Newsletter\Renderer\Preprocessor;
|
||||
use MailPoet\Newsletter\Renderer\Renderer;
|
||||
use MailPoet\Services\Bridge;
|
||||
use MailPoet\Util\License\License;
|
||||
use MailPoet\Util\pQuery\pQuery;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use WP_Error;
|
||||
|
||||
@@ -60,7 +61,7 @@ class RendererTest extends \MailPoetTest {
|
||||
$this->license
|
||||
);
|
||||
$this->columnRenderer = new ColumnRenderer();
|
||||
$this->dOMParser = new \pQuery();
|
||||
$this->dOMParser = new pQuery();
|
||||
}
|
||||
|
||||
public function testItRendersCompleteNewsletter() {
|
||||
|
@@ -35,7 +35,7 @@ class TextTest extends \MailPoetUnitTest {
|
||||
$this->block['text'] = '<p>Text</p>';
|
||||
$output = (new Text)->render($this->block);
|
||||
$table = $this->parser->parseStr($output)->query('table');
|
||||
assert($table instanceof \pQuery);
|
||||
assert($table instanceof pQuery);
|
||||
$paragraphTable = $table[0]->toString();
|
||||
$expectedResult = '<table style="border-spacing:0;mso-table-lspace:0;mso-table-rspace:0;" width="100%" cellpadding="0">
|
||||
<tr>
|
||||
@@ -53,7 +53,7 @@ class TextTest extends \MailPoetUnitTest {
|
||||
';
|
||||
$output = (new Text)->render($this->block);
|
||||
$table = $this->parser->parseStr($output)->query('table');
|
||||
assert($table instanceof \pQuery);
|
||||
assert($table instanceof pQuery);
|
||||
$paragraphTable = $table[0]->toString();
|
||||
$expectedResult = '<table style="border-spacing:0;mso-table-lspace:0;mso-table-rspace:0;" width="100%" cellpadding="0">
|
||||
<tr>
|
||||
@@ -79,7 +79,7 @@ class TextTest extends \MailPoetUnitTest {
|
||||
';
|
||||
$output = (new Text)->render($this->block);
|
||||
$table = $this->parser->parseStr($output)->query('table');
|
||||
assert($table instanceof \pQuery);
|
||||
assert($table instanceof pQuery);
|
||||
$paragraphTable = $table[0]->toString();
|
||||
$expectedResult = '<table style="border-spacing:0;mso-table-lspace:0;mso-table-rspace:0;" width="100%" cellpadding="0">
|
||||
<tr>
|
||||
@@ -89,7 +89,7 @@ class TextTest extends \MailPoetUnitTest {
|
||||
</tr></table>';
|
||||
expect($paragraphTable)->equals($expectedResult);
|
||||
$heading = $this->parser->parseStr($output)->query('h1');
|
||||
assert($heading instanceof \pQuery);
|
||||
assert($heading instanceof pQuery);
|
||||
$heading = $heading[0]->toString();
|
||||
$expectedResult = '<h1 style="text-align:left;padding:0;font-style:normal;font-weight:normal;">Second</h1>';
|
||||
expect($heading)->equals($expectedResult);
|
||||
@@ -99,7 +99,7 @@ class TextTest extends \MailPoetUnitTest {
|
||||
$this->block['text'] = '<ul><li>Item 1</li><li>Item 2</li></ul>';
|
||||
$output = (new Text)->render($this->block);
|
||||
$ul = $this->parser->parseStr($output)->query('ul');
|
||||
assert($ul instanceof \pQuery);
|
||||
assert($ul instanceof pQuery);
|
||||
$list = $ul[0]->toString();
|
||||
$expectedResult = '<ul class="mailpoet_paragraph" style="padding-top:0;padding-bottom:0;margin-top:10px;text-align:left;margin-bottom:10px;"><li class="mailpoet_paragraph" style="text-align:left;margin-bottom:10px;">Item 1</li><li class="mailpoet_paragraph" style="text-align:left;margin-bottom:10px;">Item 2</li></ul>';
|
||||
expect($list)->equals($expectedResult);
|
||||
@@ -109,7 +109,7 @@ class TextTest extends \MailPoetUnitTest {
|
||||
$this->block['text'] = '<blockquote><p>Quote</p></blockquote>';
|
||||
$output = (new Text)->render($this->block);
|
||||
$table = $this->parser->parseStr($output)->query('table');
|
||||
assert($table instanceof \pQuery);
|
||||
assert($table instanceof pQuery);
|
||||
$blockquoteTable = $table[0]->toString();
|
||||
$expectedResult = '<table class="mailpoet_blockquote" width="100%" spacing="0" border="0" cellpadding="0">
|
||||
<tbody>
|
||||
|
@@ -3,10 +3,11 @@
|
||||
namespace MailPoet\Test\Util;
|
||||
|
||||
use MailPoet\Util\DOM as DOMUtil;
|
||||
use pQuery;
|
||||
use MailPoet\Util\pQuery\DomNode;
|
||||
use MailPoet\Util\pQuery\pQuery;
|
||||
|
||||
class DOMTest extends \MailPoetUnitTest {
|
||||
/** @var pQuery\DomNode */
|
||||
/** @var DomNode */
|
||||
private $root;
|
||||
|
||||
public function _before() {
|
||||
|
Reference in New Issue
Block a user