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_PclZip($zip_file); $result = true; } catch (Exception $e) { // Something fishy - the methods indicated pclzip but we couldn't find the class $error_string = $e->getMessage(); pb_backupbuddy::status('details', sprintf(__('pclzip 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) { // Make sure we opened the zip ok and it has properties if (0 !== ($properties = $za->properties())) { // We got properties so should have a comment to return, even if empty pb_backupbuddy::status('details', sprintf(__('PclZip retrieved comment in file %1$s', 'it-l10n-backupbuddy'), $zip_file)); $result = $properties['comment']; } else { // If we failed to get the commnent then log it (?) and drop through $error_string = $za->errorInfo(true); pb_backupbuddy::status('details', sprintf(__('PclZip failed to retrieve comment in file %1$s - Error Info: %2$s', 'it-l10n-backupbuddy'), $zip_file, $error_string)); $result = false; } } if (NULL != $za) { unset($za); } return $result; }
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_PclZip($zip_file); $result = true; } catch (Exception $e) { // Something fishy - the methods indicated pclzip but we couldn't find the class $error_string = $e->getMessage(); $this->log('details', sprintf(__('pclzip 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) { // Make sure we opened the zip ok and it has properties if (0 !== ($properties = $za->properties())) { // Because comment may have been added by zip utility it may have been split over // multiple lines so we need to "unsplit" it - need to check for different possible // line endings $lines = preg_split("/\r\n|\n|\r/", $properties['comment']); // Now convert back to a string but with line endings removed $comment = implode("", $lines); // We got properties so should have a comment to return, even if empty $this->log('details', sprintf(__('PclZip 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 $error_string = $za->errorInfo(true); $this->log('details', sprintf(__('PclZip failed to retrieve comment in file %1$s - Error Info: %2$s', 'it-l10n-backupbuddy'), $zip_file, $error_string)); $result = false; } } if (null != $za) { unset($za); } return $result; }