|
Index: wp-content/plugins/tablepress-table-auto-update/tablepress-table-auto-update.php |
|
IDEA additional info: |
|
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP |
|
<+>UTF-8 |
|
=================================================================== |
|
--- wp-content/plugins/tablepress-table-auto-update/tablepress-table-auto-update.php (date 1573826959000) |
|
+++ wp-content/plugins/tablepress-table-auto-update/tablepress-table-auto-update.php (date 1573869984299) |
|
@@ -75,6 +75,36 @@ |
|
return $schedules; |
|
} |
|
|
|
+ /** |
|
+ * Log Function |
|
+ * |
|
+ * @param string|Object $log Message to log, |
|
+ * @param string $prefix Optional prefix |
|
+ */ |
|
+ public static function _log ( $log, $prefix="" ) { |
|
+ |
|
+ $log_message=array("TablePress: "); |
|
+ |
|
+ if ($prefix) { |
|
+ array_push($log_message, $prefix . " "); |
|
+ } |
|
+ |
|
+ switch(true) { |
|
+ |
|
+ case ( is_wp_error($log)): |
|
+ array_push($log_message, $log->get_error_message()); |
|
+ break; |
|
+ |
|
+ case ( is_array( $log ) || is_object( $log ) ): |
|
+ array_push($log_message,( print_r( $log, true ) )); |
|
+ break; |
|
+ |
|
+ default: |
|
+ array_push($log_message, $log); |
|
+ } |
|
+ error_log(join("",$log_message)); |
|
+ } |
|
+ |
|
/** |
|
* Every 15 minutes: Loop through the list of tables, import them from their given source, |
|
* and replace the existing data with the new data. |
|
@@ -112,12 +142,88 @@ |
|
continue; |
|
} |
|
|
|
+ self::_log( |
|
+ join(" ", |
|
+ array( |
|
+ "Importing Table ID", |
|
+ $table_id, |
|
+ "Type", |
|
+ $table_config['source_type'], |
|
+ "Format", |
|
+ $table_config['source_format'], |
|
+ "Source", |
|
+ $table_config['source'] |
|
+ ) |
|
+ ) |
|
+ ); |
|
+ |
|
$result = self::_import_table( $table_id, $table_config['source_type'], $table_config['source_format'], $table_config['source'] ); |
|
- $tables[ $table_id ]['last_auto_import'] = ( ( false !== $result ) ? 'Success' : '<strong>Failed</strong>' ). ' @ ' . current_time( 'mysql' ); |
|
+ |
|
+ switch(true) { |
|
+ case ($result === false): |
|
+ $success=false; |
|
+ $reason=""; |
|
+ break; |
|
+ |
|
+ case (is_wp_error($result)): |
|
+ $success=false; |
|
+ $reason=join("", |
|
+ array( |
|
+ "<em>", |
|
+ $result->get_error_message(), |
|
+ "</em>" |
|
+ ) |
|
+ ); |
|
+ break; |
|
+ |
|
+ default: |
|
+ $success=true; |
|
+ $reason=""; |
|
+ |
|
+ } |
|
+ $import_message = join(" ", |
|
+ array( |
|
+ (false !== $success) ? 'Success' : '<strong>Failed</strong>', |
|
+ "@", |
|
+ current_time('mysql'), |
|
+ $reason |
|
+ ) |
|
+ ); |
|
+ |
|
+ $tables[ $table_id ]['last_auto_import'] = $import_message; |
|
+ self::_log($import_message,"Set Status Message:"); |
|
+ |
|
} |
|
$auto_import_config->update( $tables ); |
|
} |
|
|
|
+ /** |
|
+ * Get a URL based source's data |
|
+ * Wraps WP functions to set timeout, and return WP_Error information |
|
+ * |
|
+ * @param string $uri |
|
+ * @return bool|string|WP_Error |
|
+ */ |
|
+ public static function _get_url_source( $uri ) { |
|
+ $parsed_url = @parse_url( $uri ); |
|
+ |
|
+ if ( ! $parsed_url || ! is_array( $parsed_url ) ) { |
|
+ return false; |
|
+ } |
|
+ |
|
+ $options = array(); |
|
+ $options['timeout'] = 30; |
|
+ |
|
+ $response = wp_safe_remote_get( $uri, $options ); |
|
+ |
|
+ if ( is_wp_error( $response ) ) { |
|
+ self::_log($response, "Couldn't retrieve " . $uri); |
|
+ return $response; |
|
+ } |
|
+ |
|
+ return wp_remote_retrieve_body( $response ); |
|
+ } |
|
+ |
|
/** |
|
* Update a single table from the given source. |
|
* |
|
@@ -139,7 +245,7 @@ |
|
if ( 'http://' === $source ) { |
|
return false; |
|
} |
|
- $import_data = wp_remote_fopen( $source ); |
|
+ $import_data = self::_get_url_source( $source ); |
|
break; |
|
case 'server': |
|
if ( ABSPATH === $source ) { |
|
@@ -154,6 +260,10 @@ |
|
return false; |
|
} |
|
|
|
+ if ( is_wp_error($import_data)) { |
|
+ return $import_data; |
|
+ } |
|
+ |
|
if ( empty( $import_data ) ) { |
|
return false; |
|
} |