Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .wp-env.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"WP_DEBUG_DISPLAY": false
},
"mappings": {
"wp-content/mu-plugins": "./tests/e2e/mu-plugins",
"wp-content/themes/gutenberg-test-themes/twentytwentyone": "https://downloads.wordpress.org/theme/twentytwentyone.2.1.zip",
"wp-content/themes/gutenberg-test-themes/twentytwentyfour": "https://downloads.wordpress.org/theme/twentytwentyfour.1.0.zip"
}
Expand Down
28 changes: 28 additions & 0 deletions css/settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -2821,6 +2821,34 @@ button.feedzy-action-button {
margin-top: 10px;
}

/* Import/feed attribution badges */
.fz-log-container__badges {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 6px;
}

.fz-log-context-import,
.fz-log-context-feed-url {
display: inline-block;
padding: 1px 8px;
border-radius: 10px;
font-size: 0.85em;
word-break: break-all;
overflow-wrap: break-word;
}

.fz-log-context-import {
background-color: #eef2ff;
color: #3730a3;
}

.fz-log-context-feed-url {
background-color: #ecfdf5;
color: #065f46;
}

/* Right section - Context */
.fz-log-container__right {
flex: 1;
Expand Down
4 changes: 4 additions & 0 deletions form/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
* @subpackage feedzy-rss-feeds/form
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

$html_parts = Feedzy_Rss_Feeds_Ui_Lang::get_form_elements();
?>
<!DOCTYPE html>
Expand Down
28 changes: 20 additions & 8 deletions includes/abstract/feedzy-rss-feeds-admin-abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -899,15 +899,26 @@ private function init_single_feed( $feed_url, $cache, $sc, $allow_https = FEEDZY

$feed->init();

if ( ! $feed->get_type() ) {
return $feed;
}

$error = $feed->error();
if ( is_array( $error ) ) {
$error = implode( '|', $error );
}

if ( ! $feed->get_type() ) {
if ( ! empty( $error ) ) {
Feedzy_Rss_Feeds_Log::error(
// translators: %1$s is the feed URL, %2$s is the error message.
sprintf( __( 'Error while parsing feed URL "%1$s": %2$s', 'feedzy-rss-feeds' ), $feed_url, $error ),
array(
'feed_url' => $feed_url,
'cache' => $cache,
'sc' => $sc,
)
);
}
return $feed;
}

if ( ! empty( $error ) ) {
$feed = $this->handle_feed_error( $feed, $cloned_feed, $feed_url, $cache, $sc, $allow_https, $default_agent, $error );
}
Expand Down Expand Up @@ -1074,10 +1085,10 @@ private function get_lazyload_cache_key( $sc, $feed_url ) {
* @param array<string, mixed> $sc The shortcode attributes.
* @param bool $allow_https Whether to allow HTTPS.
*
* @return Feedzy_Rss_Feeds_Util_SimplePie SimplePie instance.
* @return Feedzy_Rss_Feeds_Util_Feed SimplePie instance.
*/
private function create_simplepie_instance( array $sc, $allow_https ) {
$feed = new Feedzy_Rss_Feeds_Util_SimplePie( $sc );
$feed = new Feedzy_Rss_Feeds_Util_Feed( $sc );

if ( ! $allow_https && method_exists( $feed, 'set_curl_options' ) ) {
$feed->set_curl_options(
Expand Down Expand Up @@ -1198,8 +1209,9 @@ private function handle_feed_error( $feed, $cloned_feed, $feed_url, $cache, $sc,
Feedzy_Rss_Feeds_Log::debug(
sprintf( 'Using raw data for feed: %s', $feed_url ),
array(
'cache' => $cache,
'sc' => $sc,
'feed_url' => $feed_url,
'cache' => $cache,
'sc' => $sc,
)
);

Expand Down
4 changes: 4 additions & 0 deletions includes/admin/feedzy-rss-feeds-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
* @subpackage feedzy-rss-feeds/includes/admin
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

if ( ! class_exists( 'Feedzy_Rss_Feeds_Actions' ) ) {
/**
* Singleton class for content action process.
Expand Down
84 changes: 60 additions & 24 deletions includes/admin/feedzy-rss-feeds-import.php
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,9 @@ private function run_now() {
isset( $job->post_title ) ? $job->post_title : 'Unknown Job'
),
array(
'job_id' => $job_id,
'job_id' => $job_id,
'import_id' => (int) $job_id,
'import_title' => isset( $job->post_title ) ? $job->post_title : '',
)
);

Expand Down Expand Up @@ -1612,8 +1614,10 @@ public function run_cron( $max = 100, $job_id = 0 ) {
Feedzy_Rss_Feeds_Log::debug(
'Cron job run for: ' . $job->post_title,
array(
'job_id' => $job->ID,
'result' => $result,
'job_id' => $job->ID,
'import_id' => $job->ID,
'import_title' => $job->post_title,
'result' => $result,
)
);

Expand All @@ -1623,8 +1627,10 @@ public function run_cron( $max = 100, $job_id = 0 ) {
Feedzy_Rss_Feeds_Log::debug(
'Previous run did not return any results, running again for job: ' . $job->post_title,
array(
'job_id' => $job->ID,
'result' => $result,
'job_id' => $job->ID,
'import_id' => $job->ID,
'import_title' => $job->post_title,
'result' => $result,
)
);
}
Expand All @@ -1638,26 +1644,61 @@ public function run_cron( $max = 100, $job_id = 0 ) {
// translators: %1$s is the import job title, %2$s is the error message.
sprintf( __( 'Error when running "%1$s": %2$s', 'feedzy-rss-feeds' ), $job->post_title, $e->getMessage() ),
array(
'job_id' => $job->ID,
'error' => $e->getMessage(),
'job_id' => $job->ID,
'import_id' => $job->ID,
'import_title' => $job->post_title,
'error' => $e->getMessage(),
)
);
}
}
}

/**
* Runs a specific job.
*
* Runs a specific job, scoping the logger context to it.
*
* Every log entry written while the job runs (including feed fetch/parse
* errors logged deeper in the stack) is tagged with the import ID, title
* and source, so it can be traced back to this job.
*
* @param \WP_Post $job The custom post type with the job options.
* @param int $max The import feed limit.
*
* @return int The number of imported items.
*
*
* @since 1.6.1
* @access private
*/
private function run_job( $job, $max ) {
$logger = Feedzy_Rss_Feeds_Log::get_instance();
$previous_context = $logger->get_context();
$logger->set_context(
array(
'import_id' => $job->ID,
'import_title' => $job->post_title,
'source' => (string) get_post_meta( $job->ID, 'source', true ),
)
);

try {
return $this->run_job_logic( $job, $max );
} finally {
$logger->set_context( $previous_context );
}
}

/**
* The logic of running a specific job.
*
* @param \WP_Post $job The custom post type with the job options.
* @param int $max The import feed limit.
*
* @return int The number of imported items.
*
* @since 1.6.1
* @access private
*/
private function run_job_logic( $job, $max ) {
Feedzy_Rss_Feeds_Usage::get_instance()->track_rss_import();
Feedzy_Rss_Feeds_Log::get_instance()->enable_error_messages_retention();

Expand Down Expand Up @@ -1708,7 +1749,8 @@ private function run_job( $job, $max ) {
'inc_key' => $inc_key,
'inc_on' => $inc_on,
'exc_on' => $exc_on,
'import_title' => $import_title,
// `import_title` is reserved for the job attribution set in run_job(); this is the post-title mapping template.
'import_post_title' => $import_title,
'import_date' => $import_date,
'post_excerpt' => $post_excerpt,
'import_content' => $import_content,
Expand Down Expand Up @@ -3156,8 +3198,7 @@ private function try_save_featured_image( $img_source_url, $post_id, $post_title
)
);

// phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_unlink
unlink( $local_file );
wp_delete_file( $local_file );

return false;
}
Expand All @@ -3174,8 +3215,7 @@ private function try_save_featured_image( $img_source_url, $post_id, $post_title
)
);

// phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_unlink
unlink( $local_file );
wp_delete_file( $local_file );

return false;
}
Expand All @@ -3187,7 +3227,7 @@ private function try_save_featured_image( $img_source_url, $post_id, $post_title
$correct_local_file = preg_replace( '/\.[a-z0-9]+$/i', $correct_extension, $local_file );

if ( $correct_local_file !== $local_file ) {
// phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_rename
// phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_rename, WordPress.WP.AlternativeFunctions.rename_rename -- renaming a temp file created by download_url().
if ( rename( $local_file, $correct_local_file ) ) {
$local_file = $correct_local_file;
} else {
Expand All @@ -3201,8 +3241,7 @@ private function try_save_featured_image( $img_source_url, $post_id, $post_title
)
);

// phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_unlink
unlink( $local_file );
wp_delete_file( $local_file );

return false;
}
Expand Down Expand Up @@ -3283,7 +3322,7 @@ private function try_save_featured_image( $img_source_url, $post_id, $post_title
$extension = ! empty( $extension ) ? '.' . $extension : str_replace( 'image/', '.', $type );
$new_local_file = preg_replace( '/\.tmp$/', $extension, $local_file );

// phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_rename
// phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_rename, WordPress.WP.AlternativeFunctions.rename_rename -- renaming a temp file created by download_url().
$renamed = rename( $local_file, $new_local_file );
if ( $renamed ) {
$local_file = $new_local_file;
Expand Down Expand Up @@ -3313,8 +3352,7 @@ private function try_save_featured_image( $img_source_url, $post_id, $post_title
)
);

// phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_unlink
unlink( $local_file );
wp_delete_file( $local_file );

return false;
}
Expand All @@ -3334,10 +3372,8 @@ private function try_save_featured_image( $img_source_url, $post_id, $post_title
)
);

// phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_unlink
if ( file_exists( $file_array['tmp_name'] ) ) {
// phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_unlink
unlink( $file_array['tmp_name'] );
wp_delete_file( $file_array['tmp_name'] );
}

return false;
Expand Down
15 changes: 15 additions & 0 deletions includes/admin/feedzy-rss-feeds-log.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,19 @@ public function set_context( array $context ) {
return $this;
}

/**
* Get the current context of the logger.
*
* Useful for saving the context before temporarily overriding it, so it
* can be restored afterwards.
*
* @since 5.2.6
* @return array<string, mixed> The current context.
*/
public function get_context() {
return $this->context;
}

/**
* Log a message.
*
Expand Down Expand Up @@ -611,6 +624,7 @@ private function tail_file( $lines = 50 ) {
break;
}
}
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose -- direct-access fast path, guarded by can_use_direct_file_access().
fclose( $handle );

return $text;
Expand Down Expand Up @@ -740,6 +754,7 @@ public function export_logs_endpoint( $request ) {
header( 'Pragma: public' );
header( 'Content-Length: ' . filesize( $this->filepath ) );

// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_readfile -- streams the log download without loading it into memory.
readfile( $this->filepath );

exit;
Expand Down
4 changes: 4 additions & 0 deletions includes/admin/feedzy-rss-feeds-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
* @subpackage feedzy-rss-feeds/includes/admin
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

if ( ! class_exists( 'Feedy_Rss_Feeds_Options' ) ) {
/**
* Singleton class for options wrapper
Expand Down
4 changes: 4 additions & 0 deletions includes/admin/feedzy-rss-feeds-upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
* @subpackage feedzy-rss-feeds/includes/admin
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

if ( ! class_exists( 'Feedzy_Rss_Feeds_Upgrader' ) ) {
/**
* Class Feedzy_Rss_Feeds_Upgrader for upgrading processes
Expand Down
4 changes: 4 additions & 0 deletions includes/feedzy-rss-feeds-feed-tweaks.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
* @subpackage feedzy-rss-feeds/includes
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

/**
* Adds the featured image to the website's RSS feed.
*
Expand Down
5 changes: 5 additions & 0 deletions includes/layouts/feedzy-documentation.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<!--
Layout For Document Page of Feedzy RSS Feeds

Expand Down
5 changes: 5 additions & 0 deletions includes/layouts/feedzy-improve.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<div id="fz-feedback-modal"></div>
<div class="fz-help-improve-wrap">
<div class="fz-help-improve-box">
Expand Down
Loading
Loading