Plugin Directory

Changeset 3333340


Ignore:
Timestamp:
07/24/2025 07:51:56 AM (7 months ago)
Author:
ircf
Message:

1.46 : Fixed sanitize url bug. Added filters to get_single, get_single_user.

Location:
feed2post-ircf/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • feed2post-ircf/trunk/README.txt

    r3329519 r3333340  
    3030- LinkedIn : LinkedIn Client ID, LinkedIn Client key
    3131- Google Reviews (experimental) : Google Place ID, Google Place API key
     32- Infolocale / Ouest-France : Client ID, Client secret
    3233
    3334= FREE VERSION : =
     
    120121== Changelog ==
    121122
     123= 1.46 =
     124Fixed sanitize url bug.
     125Added filters to get_single, get_single_user.
     126
    122127= 1.45 =
    123128Added filters to http methods.
  • feed2post-ircf/trunk/feed2post.php

    r3329519 r3333340  
    33 * Plugin Name: Feed2Post IRCF
    44 * Plugin URI: https://ircf.fr
    5  * Description: Import CSV, XLS, XML, RSS, JSON, SQL, Open AI Chat GPT, Google Reviews, Facebook, LinkedIn, AC3, SIRTAQUI and many more feed types
    6  * Version: 1.45
     5 * 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
    77 * Author: IRCF
    88 * Author URI: https://ircf.fr/
     
    662662  if (isset($_POST['feed_options']) && is_array($_POST['feed_options'])){
    663663    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){
    665667        $value = sanitize_textarea_field($_POST['feed_options'][$name] ?? '');
    666668      }else{
  • feed2post-ircf/trunk/includes/feed2post-feed.php

    r3329519 r3333340  
    11<?php
    22abstract class Feed2Post_Feed{
     3
     4  const DEFAULT_POST_ID_META = 'post_id';
    35
    46  static private $instances = array();
     
    7880    $this->posts_updated_at_end = $this->get_meta('posts_updated_at_end');
    7981    $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');
    8183    $this->multiple_values_separator = $this->get_option('multiple_values_separator');
    8284    $this->style = $this->get_meta('style');
     
    106108    $result = array_merge(array(
    107109      'post_id_match' => true,
     110      'post_id_meta' => self::DEFAULT_POST_ID_META,
    108111    ), feed2post_default_options());
    109112    return $result;
     
    116119      '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>'),
    117120      '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>'),
    119122      '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">'),
    120123      '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">'),
     
    306309    if ($this->post_type == 'user') return $this->update_single_user($result);
    307310    //feed2post_logger()->debug('Feed2Post_Feed::update_single : data = ' . print_r($result, true));
    308     $posts = null;
     311    $post = null;
    309312    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);
    321315    }
    322316    // Initialize post data
    323     if ($posts){
    324       $post = get_object_vars($posts[0]);
     317    if (isset($post)){
    325318      $is_new = false;
    326319    }else{
     
    337330    // Set default post fields
    338331    $post['meta_input'] = array(
    339       'post_id' => (string) $result[$this->post_id_field],
     332      $this->post_id_meta => (string) $result[$this->post_id_field],
    340333      'feed_id' => $this->post_id,
    341334      'feed_updated_at' => current_time('timestamp'),
     
    360353    }
    361354    // 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);
    363356    feed2post_logger()->debug('Feed2Post_Feed::update_single : post = ' . print_r($post, true));
    364357    $post_id = wp_insert_post($post, true, false);
     
    370363    $this->update_single_taxonomies($post_id, $result, $is_new);
    371364    $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);
    373366    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;
    374392  }
    375393
     
    434452        }
    435453        // 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);
    437455        if (empty($media)) continue; // Skip empty urls
    438456        feed2post_logger()->debug('Feed2Post_Feed::update_single_medias : media = ' . $media);
     
    471489
    472490  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);
    486492    $is_new = ($wp_user == false);
    487493    $user = array();
     
    509515    if ($is_new && !isset($user['user_pass'])) $user['user_pass'] = wp_generate_password(32, true, true);
    510516    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);
    512518    feed2post_logger()->debug('Feed2Post_Feed::update_single_user : user = '.print_r($user, true));
    513519    $user_id = wp_insert_user($user);
     
    518524    }
    519525    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;
    520548  }
    521549
Note: See TracChangeset for help on using the changeset viewer.