Changeset 3333340
- Timestamp:
- 07/24/2025 07:51:56 AM (7 months ago)
- Location:
- feed2post-ircf/trunk
- Files:
-
- 3 edited
-
README.txt (modified) (2 diffs)
-
feed2post.php (modified) (2 diffs)
-
includes/feed2post-feed.php (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
feed2post-ircf/trunk/README.txt
r3329519 r3333340 30 30 - LinkedIn : LinkedIn Client ID, LinkedIn Client key 31 31 - Google Reviews (experimental) : Google Place ID, Google Place API key 32 - Infolocale / Ouest-France : Client ID, Client secret 32 33 33 34 = FREE VERSION : = … … 120 121 == Changelog == 121 122 123 = 1.46 = 124 Fixed sanitize url bug. 125 Added filters to get_single, get_single_user. 126 122 127 = 1.45 = 123 128 Added filters to http methods. -
feed2post-ircf/trunk/feed2post.php
r3329519 r3333340 3 3 * Plugin Name: Feed2Post IRCF 4 4 * Plugin URI: https://ircf.fr 5 * Description: Import CSV, XLS, XML, RSS, JSON, SQL, Open AI Chat GPT, Google Reviews, Facebook, LinkedIn, AC3, S IRTAQUIand many more feed types6 * Version: 1.4 55 * Description: Import CSV, XLS, XML, RSS, JSON, SQL, Open AI Chat GPT, Google Reviews, Facebook, LinkedIn, AC3, Sirtaqui/Tourinsoft, Infolocale/Ouest-France and many more feed types 6 * Version: 1.46 7 7 * Author: IRCF 8 8 * Author URI: https://ircf.fr/ … … 662 662 if (isset($_POST['feed_options']) && is_array($_POST['feed_options'])){ 663 663 foreach ( $feed->get_options_fields() as $name => $field ) { 664 if (strpos($field['template'], 'textarea') !== false){ 664 if (strpos($name, 'url') !== false){ 665 $value = sanitize_url($_POST['feed_options'][$name] ?? ''); 666 }elseif (strpos($field['template'], 'textarea') !== false){ 665 667 $value = sanitize_textarea_field($_POST['feed_options'][$name] ?? ''); 666 668 }else{ -
feed2post-ircf/trunk/includes/feed2post-feed.php
r3329519 r3333340 1 1 <?php 2 2 abstract class Feed2Post_Feed{ 3 4 const DEFAULT_POST_ID_META = 'post_id'; 3 5 4 6 static private $instances = array(); … … 78 80 $this->posts_updated_at_end = $this->get_meta('posts_updated_at_end'); 79 81 $this->post_id_field = $this->get_option('post_id_field'); 80 // TODO $this->post_date_field = $this->get_option('post_date_field');82 $this->post_id_meta = $this->get_option('post_id_meta'); 81 83 $this->multiple_values_separator = $this->get_option('multiple_values_separator'); 82 84 $this->style = $this->get_meta('style'); … … 106 108 $result = array_merge(array( 107 109 'post_id_match' => true, 110 'post_id_meta' => self::DEFAULT_POST_ID_META, 108 111 ), feed2post_default_options()); 109 112 return $result; … … 116 119 'post_id_match' => array('label' => __('Match and update posts', 'feed2post'), 'description' => __('If enabled, will make a query to find and update each post. You can disable this for faster initial or unique import. It will always be enabled for automatic imports.', 'feed2post'), 'template' => '<input type="checkbox" name="%s" value="1" %s>'), 117 120 'post_id_field' => array('label' => __('ID Field', 'feed2post'), 'description' => __('Required, name of the identifier field in feed (for updates)', 'feed2post'), 'template' => '<input type="text" name="%s" value="%s" size="30" required>'), 118 // TODO 'post_id_meta' => array('label' => __('ID Meta', 'feed2post'), 'description' => __('Required, name of the identifier field in meta table (for updates)', 'feed2post'), 'template' => '<input type="text" name="%s" value="%s" size="30" required>'),121 // TODO ? 'post_id_meta' => array('label' => __('ID Meta', 'feed2post'), 'description' => __('Required, name of the identifier field in meta table (for updates)', 'feed2post'), 'template' => '<input type="text" name="%s" value="%s" size="30" required>'), 119 122 'lines_start' => array('label' => __('Start at line', 'feed2post'), 'description' => __('Optional, skip N lines before importing (0 or empty to start from first line)', 'feed2post'), 'template' => '<input type="number" name="%s" value="%s" size="30">'), 120 123 'lines_length' => array('label' => __('Number of lines to import', 'feed2post'), 'description' => __('Optional, import N lines (0 or empty to import all lines)', 'feed2post'), 'template' => '<input type="number" name="%s" value="%s" size="30">'), … … 306 309 if ($this->post_type == 'user') return $this->update_single_user($result); 307 310 //feed2post_logger()->debug('Feed2Post_Feed::update_single : data = ' . print_r($result, true)); 308 $post s= null;311 $post = null; 309 312 if ($this->get_option('post_id_match') || $this->get_option('crontab_enabled') > 0){ 310 // Find post by post_id_field for updates 311 if (!isset($result[$this->post_id_field])){ 312 $error_msg = sprintf(__('Missing ID field : %s', 'feed2post'), esc_html($this->post_id_field)); 313 throw new Exception($error_msg); 314 } 315 $posts = get_posts(array( 316 'post_type' => $this->post_type, 317 'meta_key' => 'post_id', 318 'meta_value' => (string) $result[$this->post_id_field], 319 'numberposts' => 1, 320 )); 313 $post = $this->get_single($result); 314 if ($post) $post = get_object_vars($post); 321 315 } 322 316 // Initialize post data 323 if ($posts){ 324 $post = get_object_vars($posts[0]); 317 if (isset($post)){ 325 318 $is_new = false; 326 319 }else{ … … 337 330 // Set default post fields 338 331 $post['meta_input'] = array( 339 'post_id'=> (string) $result[$this->post_id_field],332 $this->post_id_meta => (string) $result[$this->post_id_field], 340 333 'feed_id' => $this->post_id, 341 334 'feed_updated_at' => current_time('timestamp'), … … 360 353 } 361 354 // Insert or update post 362 $post = apply_filters('feed2post_before_post_update', $post, $result );355 $post = apply_filters('feed2post_before_post_update', $post, $result, $this); 363 356 feed2post_logger()->debug('Feed2Post_Feed::update_single : post = ' . print_r($post, true)); 364 357 $post_id = wp_insert_post($post, true, false); … … 370 363 $this->update_single_taxonomies($post_id, $result, $is_new); 371 364 $this->update_single_medias($post_id, $result); 372 do_action('feed2post_after_post_update', $post_id, $post, $result );365 do_action('feed2post_after_post_update', $post_id, $post, $result, $this); 373 366 return 1; 367 } 368 369 /** 370 * Find post by ID field ID Meta for update 371 */ 372 function get_single($result){ 373 if (!isset($result[$this->post_id_field])){ 374 $error_msg = sprintf(__('Missing ID field : %s', 'feed2post'), esc_html($this->post_id_field)); 375 throw new Exception($error_msg); 376 } 377 if (!isset($this->post_id_meta) || empty($this->post_id_meta)){ 378 $error_msg = sprintf(__('Missing ID meta : %s', 'feed2post')); 379 throw new Exception($error_msg); 380 } 381 $opts = array( 382 'post_type' => $this->post_type, 383 'meta_key' => $this->post_id_meta, 384 'meta_value' => (string) $result[$this->post_id_field], 385 'numberposts' => 1, 386 ); 387 $opts = apply_filters('feed2post_pre_get_single', $opts, $result, $this); 388 $posts = get_posts($opts); 389 $post = $posts ? $posts[0] : null; 390 $post = apply_filters('feed2post_post_get_single', $post, $result, $this); 391 return $post; 374 392 } 375 393 … … 434 452 } 435 453 // Create or update media 436 $media = apply_filters('feed2post_before_media_update', $media, $post_id );454 $media = apply_filters('feed2post_before_media_update', $media, $post_id, $this); 437 455 if (empty($media)) continue; // Skip empty urls 438 456 feed2post_logger()->debug('Feed2Post_Feed::update_single_medias : media = ' . $media); … … 471 489 472 490 function update_single_user($result){ 473 $user_id_field = null; 474 foreach($this->fields as $name => $field){ 475 if ($field['mapping'] == 'user_login'){ 476 $user_id_field = $name; 477 break; 478 } 479 } 480 if (!isset($user_id_field)){ 481 $error_msg = sprintf(__('Missing ID field : %s', 'feed2post'), $user_id_field); 482 feed2post_logger()->error('Feed2Post_Feed::update_single_user : ' . $error_msg); 483 throw new Exception($error_msg); 484 } 485 $wp_user = get_user_by('login', sanitize_user($result[$user_id_field], true)); 491 $wp_user = $this->get_single_user($result); 486 492 $is_new = ($wp_user == false); 487 493 $user = array(); … … 509 515 if ($is_new && !isset($user['user_pass'])) $user['user_pass'] = wp_generate_password(32, true, true); 510 516 if (!$is_new) $user['user_pass'] = wp_hash_password( $user['user_pass'] ); 511 $user = apply_filters('feed2post_before_user_update', $user, $result );517 $user = apply_filters('feed2post_before_user_update', $user, $result, $this); 512 518 feed2post_logger()->debug('Feed2Post_Feed::update_single_user : user = '.print_r($user, true)); 513 519 $user_id = wp_insert_user($user); … … 518 524 } 519 525 return 1; 526 } 527 528 /** 529 * Find single user for update 530 */ 531 function get_single_user($result){ 532 $user_id_field = null; 533 foreach($this->fields as $name => $field){ 534 if ($field['mapping'] == 'user_login'){ 535 $user_id_field = $name; 536 break; 537 } 538 } 539 if (!isset($user_id_field)){ 540 $error_msg = sprintf(__('Missing ID field : %s', 'feed2post'), $user_id_field); 541 feed2post_logger()->error('Feed2Post_Feed::update_single_user : ' . $error_msg); 542 throw new Exception($error_msg); 543 } 544 // TODO $opts = apply_filters('feed2post_pre_get_single_user', $opts, $result, $this); 545 $wp_user = get_user_by('login', sanitize_user($result[$user_id_field], true)); 546 $wp_user = apply_filters('feed2post_post_get_single_user', $post, $result, $this); 547 return $wp_user; 520 548 } 521 549
Note: See TracChangeset
for help on using the changeset viewer.