public function get_comment($zip_file) { $result = false; $za = NULL; // This should give us a new archive object, of not catch it and bail out try { $za = new pluginbuddy_ZipArchive(); $result = true; } catch (Exception $e) { // Something fishy - the methods indicated ziparchive but we couldn't find the class $error_string = $e->getMessage(); pb_backupbuddy::status('details', sprintf(__('ziparchive indicated as available method but error reported: %1$s', 'it-l10n-backupbuddy'), $error_string)); $result = false; } // Only continue if we have a valid archive object if (true === $result) { $result = $za->open($zip_file); // Make sure at least the zip file opened ok if (true === $result) { // Get the comment or false on failure for some reason // Note: Currently, due to a bug in ZipArchive, getArchiveComment() // returns false for an empty comment whereas it should just return an // empty string. We'll live with this for now as it should only happen // when an archive is fresh and has the Integrity Check run (or when the // check is rerun). Once a comment is added the function behaves. // If any problems are thrown up then there is the option to use the // archive property but that has a downside in that it can only ever // return a string so if there really is an error in reading the comment // it is not possible to know (AFAIK). Perhaps an error status value might // be set somewhere? // The bug will be reported to PHP developers but we will still have to // live with this for a while because it takes hosts ages to catch up to // updated PHP versions. $comment = $za->getArchiveComment(ZIPARCHIVE::FL_UNCHANGED); //$comment = $za->comment; // If we have a comment (even if empty) then return it if (false !== $comment) { // Note: new archives will return an empty comment if one was not added at creation pb_backupbuddy::status('details', sprintf(__('ZipArchive retrieved comment in file %1$s', 'it-l10n-backupbuddy'), $zip_file)); $result = $comment; } else { // If we failed to get the commnent then log it (?) and drop through pb_backupbuddy::status('details', sprintf(__('ZipArchive failed to retrieve comment in file %1$s', 'it-l10n-backupbuddy'), $zip_file)); $result = false; } } else { // If we couldn't open the zip file then log it (?) and drop through $error_string = $za->errorInfo($result); pb_backupbuddy::status('details', sprintf(__('ZipArchive failed to open file to get comment in file %1$s - Error Info: %2$s', 'it-l10n-backupbuddy'), $zip_file, $error_string)); $result = false; } $za->close(); } else { // Something fishy - the methods indicated ziparchive but we couldn't find the class pb_backupbuddy::status('details', __('ziparchive indicated as available method but ZipArchive class non-existent', 'it-l10n-backupbuddy')); $result = false; } if (NULL != $za) { unset($za); } return $result; }