Zotpress issues using json_decode() with PHP 8?

43 views
Skip to first unread message

Jason Smith

unread,
Sep 21, 2022, 8:30:02 PM9/21/22
to zotero-dev
I am using Wordpress 6.02 with PHP 8.  The newest Plugin Zotpress is giving the following two errors.  The question is, are these errors related to issues with PHP 8? Or should I be looking somewhere else for the origin of these errors?



Issue #1
Uncaught TypeError: property_exists(): Argument #1 ($object_or_class) must be of type object|string, null given in %path%\wp-content\plugins\zotpress\lib\request\request.class.php:302
#8 {main}
thrown in %path%\wp-content\plugins\zotpress\lib\request\request.class.php on line 302

Code line with issue->if ( property_exists($data[$id]->library, 'type') ) unset($data[$id]->library->type);

// Remove unncessary details
                            // REVIEW: Does this account for all unused metadata? Depends on item type ...
                            foreach( $data as $id => $item )
                            {
                                if ( property_exists($data[$id], 'version') ) unset($data[$id]->version);
                                if ( property_exists($data[$id], 'links') ) unset($data[$id]->links);
                                if ( property_exists($data[$id]->library, 'type') ) unset($data[$id]->library->type);
                                if ( property_exists($data[$id]->library, 'name') ) unset($data[$id]->library->name);
                                if ( property_exists($data[$id]->library, 'links') ) unset($data[$id]->library->links);
                                if ( property_exists($data[$id]->data, 'key') ) unset($data[$id]->data->key);
                                if ( property_exists($data[$id]->data, 'version') ) unset($data[$id]->data->version);
                                if ( property_exists($data[$id]->data, 'series') ) unset($data[$id]->data->series);
                                if ( property_exists($data[$id]->data, 'seriesNumber') ) unset($data[$id]->data->seriesNumber);
                                if ( property_exists($data[$id]->data, 'seriesTitle') ) unset($data[$id]->data->seriesTitle);
                                if ( property_exists($data[$id]->data, 'seriesText') ) unset($data[$id]->data->seriesText);
                                if ( property_exists($data[$id]->data, 'publicationTitle') ) unset($data[$id]->data->publicationTitle);
                                if ( property_exists($data[$id]->data, 'journalAbbreviation') ) unset($data[$id]->data->journalAbbreviation);
                                if ( property_exists($data[$id]->data, 'issue') ) unset($data[$id]->data->issue);
                                if ( property_exists($data[$id]->data, 'volume') ) unset($data[$id]->data->volume);
                                if ( property_exists($data[$id]->data, 'numberOfVolumes') ) unset($data[$id]->data->numberOfVolumes);
                                if ( property_exists($data[$id]->data, 'edition') ) unset($data[$id]->data->edition);
                                if ( property_exists($data[$id]->data, 'place') ) unset($data[$id]->data->place);
                                if ( property_exists($data[$id]->data, 'publisher') ) unset($data[$id]->data->publisher);
                                if ( property_exists($data[$id]->data, 'pages') ) unset($data[$id]->data->pages);
                                if ( property_exists($data[$id]->data, 'numPages') ) unset($data[$id]->data->numPages);
                                if ( property_exists($data[$id]->data, 'shortTitle') ) unset($data[$id]->data->shortTitle);
                                if ( property_exists($data[$id]->data, 'accessDate') ) unset($data[$id]->data->accessDate);
                                if ( property_exists($data[$id]->data, 'archive') ) unset($data[$id]->data->archive);
                                if ( property_exists($data[$id]->data, 'archiveLocation') ) unset($data[$id]->data->archiveLocation);
                                if ( property_exists($data[$id]->data, 'libraryCatalog') ) unset($data[$id]->data->libraryCatalog);
                                if ( property_exists($data[$id]->data, 'callNumber') ) unset($data[$id]->data->callNumber);
                                if ( property_exists($data[$id]->data, 'rights') ) unset($data[$id]->data->rights);
                                if ( property_exists($data[$id]->data, 'extra') ) unset($data[$id]->data->extra);
                                if ( property_exists($data[$id]->data, 'relations') ) unset($data[$id]->data->relations);
                                if ( property_exists($data[$id]->data, 'dateAdded') ) unset($data[$id]->data->dateAdded);
                                if ( property_exists($data[$id]->data, 'websiteTitle') ) unset($data[$id]->data->websiteTitle);
                                if ( property_exists($data[$id]->data, 'websiteType') ) unset($data[$id]->data->websiteType);
                                if ( property_exists($data[$id]->data, 'inPublications') ) unset($data[$id]->data->inPublications);
                                if ( property_exists($data[$id]->data, 'presentationType') ) unset($data[$id]->data->presentationType);
                                if ( property_exists($data[$id]->data, 'meetingName') ) unset($data[$id]->data->meetingName);

                                // As of 7.1.4, tags are saved separately
                                // due to possibily large quantities and the
                                // limits of blob; so we always save now
                                // REVIEW: Do we need the account, too?


Issue #2
[21-Sep-2022 01:15:11] WARNING: child 597 said into stderr: "NOTICE: PHP message: PHP Warning:  json_decode() expects parameter 1 to be string, object given in /www/wp-content/plugins/zotpress/lib/shortcode/shortcode.request.php on line 320"

The Zotpress maintainers haven't replied about fixing the issue, so I am trying to fix it myself. 
The line 320 throwing  the error is 
$temp_headers = json_decode( $zp_request["headers"] );

Here is the actual code with error :

// Decode the JSONs
        $temp_headers = json_decode( $zp_request["headers"] );
        $temp_data = json_decode( $zp_request["json"] );

        // Figure out if there's multiple requests and how many
        if ( $zpr["request_start"] == 0
                && isset($temp_headers->link) && strpos( $temp_headers->link, 'rel="last"' ) !== false )
        {
            $temp_link = explode( ";", $temp_headers->link );
            $temp_link = explode( "start=", $temp_link[1] );
            $temp_link = explode( "&", $temp_link[1] );

            $zp_request_meta["request_last"] = $temp_link[0];
        }

Reply all
Reply to author
Forward
0 new messages