clonemeagain / attachment_preview

osTicket Plugin: Allows inline view of attachments
GNU General Public License v2.0
47 stars 16 forks source link

bug: Cannot use object of type DOMNodeList as array #22

Closed mckaygerhard closed 6 years ago

mckaygerhard commented 6 years ago

solving the issue #21 now i have this problem in AttachmentPreviewPlugin.php on line 217 Cannot use object of type DOMNodeList as array

Fatal error: Cannot use object of type DOMNodeList as array in /var/share/www/osticket/include/plugins/attachment_preview/class.AttachmentPreviewPlugin.php on line 217
mckaygerhard commented 6 years ago

i got the problem based on the documentation, the $dom variable its a object,

but in the foreach are get as an array to iterate, getElementsByTagName() returns a DOMNodeList, which implements ArrayAccess as of PHP 5.6.3. This is what allows you to access a node in that iteration but its a compatiblity break

solving that will able to use the plugin in both osticket

https://bugs.php.net/bug.php?id=67949 reported but only availabel for php 5.6

i provided solution for the issue #21 but for this i'm very tyred, please some help

mckaygerhard commented 6 years ago

Gottcha solution:

--- a/class.AttachmentPreviewPlugin.php
+++ b/class.AttachmentPreviewPlugin.php
@@ -214,7 +214,7 @@

                 $ext          = $this->getExtension($link->textContent);
-                $size_element = $xpath->query("following-sibling::*[1]", $link)[0];
+                $size_element = $xpath->query("following-sibling::*[1]", $link)->item[0];
                 if ($size_element instanceof DomElement) {
                     $size_kb = $this->unFormatSize($size_element->nodeValue);
                     $this->debug_log("Attachment is roughly: " . $size_kb . ' bytes in size.');
mckaygerhard commented 6 years ago

i'll try the DB alternative tonight and will' test agains php 5.X and php 7.X then report feedback ...