Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sfink 8.1 compat #20

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion phpQuery/phpQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ public static function DOMNodeListToArray($DOMNodeList) {
* @todo still used ?
*/
public static function isMarkup($input) {
return ! is_array($input) && substr(trim($input), 0, 1) == '<';
return ! is_array($input) && substr(trim($input ?? ''), 0, 1) == '<';
}
public static function debug($text) {
if (self::$debug)
Expand Down
16 changes: 9 additions & 7 deletions phpQuery/phpQuery/DOMDocumentWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,17 @@ class DOMDocumentWrapper {
public $isXHTML = false;
public $isHTML = false;
public $charset;
public function __construct($markup = null, $contentType = null, $newDocumentID = null) {
public function __construct($markup = null, $contentType = '', $newDocumentID = null) {
if (isset($markup))
$this->load($markup, $contentType, $newDocumentID);
$this->id = $newDocumentID
? $newDocumentID
: md5(microtime());
}
public function load($markup, $contentType = null, $newDocumentID = null) {
public function load($markup, $contentType = '', $newDocumentID = null) {
// phpQuery::$documents[$id] = $this;
if ($contentType === null)
$contentType = '';
$this->contentType = strtolower($contentType);
if ($markup instanceof DOMDOCUMENT) {
$this->document = $markup;
Expand Down Expand Up @@ -131,7 +133,7 @@ protected function documentCreate($charset, $version = '1.0') {
$this->document->formatOutput = true;
$this->document->preserveWhiteSpace = true;
}
protected function loadMarkupHTML($markup, $requestedCharset = null) {
protected function loadMarkupHTML($markup, $requestedCharset = '') {
if (phpQuery::$debug)
phpQuery::debug('Full markup load (HTML): '.substr($markup, 0, 250));
$this->loadMarkupReset();
Expand All @@ -153,11 +155,11 @@ protected function loadMarkupHTML($markup, $requestedCharset = null) {
// @see http://www.w3.org/International/O-HTTP-charset
if (! $documentCharset) {
$documentCharset = 'ISO-8859-1';
$addDocumentCharset = true;
$addDocumentCharset = true;
}
// Should be careful here, still need 'magic encoding detection' since lots of pages have other 'default encoding'
// Worse, some pages can have mixed encodings... we'll try not to worry about that
$requestedCharset = strtoupper($requestedCharset);
$requestedCharset = $requestedCharset ? strtoupper($requestedCharset) : '';
$documentCharset = strtoupper($documentCharset);
phpQuery::debug("DOC: $documentCharset REQ: $requestedCharset");
if ($requestedCharset && $documentCharset && $requestedCharset !== $documentCharset) {
Expand Down Expand Up @@ -441,7 +443,7 @@ public function import($source, $sourceCharset = null) {
// if ($fake === false)
// throw new Exception("Error loading documentFragment markup");
// else
// $return = array_merge($return,
// $return = array_merge($return,
// $this->import($fake->root->childNodes)
// );
// } else {
Expand Down Expand Up @@ -510,7 +512,7 @@ protected function documentFragmentCreate($source, $charset = null) {
* @param $markup
* @return $document
*/
private function documentFragmentLoadMarkup($fragment, $charset, $markup = null) {
private function documentFragmentLoadMarkup($fragment, $charset, $markup = '') {
// TODO error handling
// TODO copy doctype
// tempolary turn off
Expand Down
17 changes: 14 additions & 3 deletions phpQuery/phpQuery/phpQueryObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ protected function parseSelector($query) {
// TODO include this inside parsing ?
$query = trim(
preg_replace('@\s+@', ' ',
preg_replace('@\s*(>|\\+|~)\s*@', '\\1', $query)
preg_replace('@\s*(>|\\+|~)\s*@', '\\1', $query ?? '')
)
);
$queries = array(array());
Expand Down Expand Up @@ -1672,9 +1672,11 @@ public function size() {
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
* @deprecated Use length as attribute
*/
#[\ReturnTypeWillChange]
public function length() {
return $this->size();
}
#[\ReturnTypeWillChange]
public function count() {
return $this->size();
}
Expand Down Expand Up @@ -2989,6 +2991,7 @@ public function removeData($key) {
/**
* @access private
*/
#[\ReturnTypeWillChange]
public function rewind(){
$this->debug('iterating foreach');
// phpQuery::selectDocument($this->getDocumentID());
Expand All @@ -3004,12 +3007,14 @@ public function rewind(){
/**
* @access private
*/
public function current(){
#[\ReturnTypeWillChange]
public function current() {
return $this->elementsInterator[ $this->current ];
}
/**
* @access private
*/
#[\ReturnTypeWillChange]
public function key(){
return $this->current;
}
Expand All @@ -3024,7 +3029,8 @@ public function key(){
* @see phpQueryObject::_next()
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
*/
public function next($cssSelector = null){
#[\ReturnTypeWillChange]
public function next($cssSelector = null) {
// if ($cssSelector || $this->valid)
// return $this->_next($cssSelector);
$this->valid = isset( $this->elementsInterator[ $this->current+1 ] )
Expand All @@ -3041,6 +3047,7 @@ public function next($cssSelector = null){
/**
* @access private
*/
#[\ReturnTypeWillChange]
public function valid(){
return $this->valid;
}
Expand All @@ -3049,25 +3056,29 @@ public function valid(){
/**
* @access private
*/
#[\ReturnTypeWillChange]
public function offsetExists($offset) {
return $this->find($offset)->size() > 0;
}
/**
* @access private
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset) {
return $this->find($offset);
}
/**
* @access private
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value) {
// $this->find($offset)->replaceWith($value);
$this->find($offset)->html($value);
}
/**
* @access private
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset) {
// empty
throw new Exception("Can't do unset, use array interface only for calling queries and replacing HTML.");
Expand Down