Featured Image From URL - Version 3.4.1

Version Description

  • Fix: Instagram URLs.
Download this release

Release Info

Developer marceljm
Plugin Icon 128x128 Featured Image From URL
Version 3.4.1
Comparing to
See all releases

Code changes from version 3.4.0 to 3.4.1

admin/api.php CHANGED
@@ -1,6 +1,20 @@
1
  <?php
2
 
3
  define('FIFU_QUERY_ADDRESS', 'https://query.featuredimagefromurl.com');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  function fifu_is_local() {
6
  $query = 'http://localhost';
@@ -27,7 +41,6 @@ function fifu_api_query($dataset) {
27
  $new_url = $data[2];
28
  $title = $data[3];
29
  $permalink = $data[4];
30
- $tags = $data[5];
31
 
32
  $time = time();
33
  $encoded_permalink = base64_encode($permalink);
@@ -40,7 +53,6 @@ function fifu_api_query($dataset) {
40
  'new_url' => base64_encode($new_url),
41
  'title' => base64_encode($title),
42
  'permalink' => $encoded_permalink,
43
- 'tags' => base64_encode($tags),
44
  'time' => $time,
45
  'signature' => $signature,
46
  'version' => $version,
@@ -71,6 +83,41 @@ function fifu_api_query($dataset) {
71
  }
72
  }
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  function fifu_enable_fake_api(WP_REST_Request $request) {
75
  update_option('fifu_fake_stop', false, 'no');
76
  fifu_enable_fake();
@@ -159,6 +206,12 @@ function fifu_api_list_all_without_dimensions(WP_REST_Request $request) {
159
  return fifu_db_get_all_without_dimensions();
160
  }
161
 
 
 
 
 
 
 
162
  function fifu_test_execution_time() {
163
  for ($i = 0; $i <= 120; $i++) {
164
  error_log($i);
@@ -208,6 +261,11 @@ add_action('rest_api_init', function () {
208
  'callback' => 'fifu_api_list_all_without_dimensions',
209
  'permission_callback' => 'fifu_get_private_data_permissions_check',
210
  ));
 
 
 
 
 
211
  register_rest_route('featured-image-from-url/v2', '/rest_url_api/', array(
212
  'methods' => ['GET', 'POST'],
213
  'callback' => 'fifu_rest_url',
1
  <?php
2
 
3
  define('FIFU_QUERY_ADDRESS', 'https://query.featuredimagefromurl.com');
4
+ define('FIFU_INSTAGRAM_ADDRESS', 'https://urls.featuredimagefromurl.com/instagram/');
5
+
6
+ function fifu_get_ip() {
7
+ foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key) {
8
+ if (array_key_exists($key, $_SERVER) === true) {
9
+ foreach (explode(',', $_SERVER[$key]) as $ip) {
10
+ $ip = trim($ip);
11
+ if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false)
12
+ return $ip;
13
+ }
14
+ }
15
+ }
16
+ return $_SERVER['REMOTE_ADDR'];
17
+ }
18
 
19
  function fifu_is_local() {
20
  $query = 'http://localhost';
41
  $new_url = $data[2];
42
  $title = $data[3];
43
  $permalink = $data[4];
 
44
 
45
  $time = time();
46
  $encoded_permalink = base64_encode($permalink);
53
  'new_url' => base64_encode($new_url),
54
  'title' => base64_encode($title),
55
  'permalink' => $encoded_permalink,
 
56
  'time' => $time,
57
  'signature' => $signature,
58
  'version' => $version,
83
  }
84
  }
85
 
86
+ function fifu_api_get_instagram_thumb($url) {
87
+ $site = fifu_get_home_url();
88
+ $ip = fifu_get_ip();
89
+ $time = time();
90
+ $encoded_url = base64_encode($url);
91
+ $url_sign = substr($encoded_url, -25);
92
+ $signature = hash_hmac('sha256', $url_sign . $time, $site);
93
+ $array = array(
94
+ 'headers' => array('Content-Type' => 'application/json; charset=utf-8'),
95
+ 'body' => json_encode(
96
+ array(
97
+ 'site' => $site,
98
+ 'signature' => $signature,
99
+ 'time' => $time,
100
+ 'ip' => $ip,
101
+ 'url' => $encoded_url,
102
+ 'version' => fifu_version_number(),
103
+ )
104
+ ),
105
+ 'method' => 'POST',
106
+ 'data_format' => 'body',
107
+ 'blocking' => true,
108
+ 'timeout' => 10,
109
+ );
110
+ $response = fifu_remote_post(FIFU_INSTAGRAM_ADDRESS, $array);
111
+ if (is_wp_error($response))
112
+ return null;
113
+
114
+ $json = json_decode($response['http_response']->get_response_object()->body);
115
+ if ($json && isset($json->url) && $json->url)
116
+ return $json->url;
117
+
118
+ return null;
119
+ }
120
+
121
  function fifu_enable_fake_api(WP_REST_Request $request) {
122
  update_option('fifu_fake_stop', false, 'no');
123
  fifu_enable_fake();
206
  return fifu_db_get_all_without_dimensions();
207
  }
208
 
209
+ function fifu_api_convert_instagram_url(WP_REST_Request $request) {
210
+ $url = $request['url'];
211
+ $new_url = fifu_api_get_instagram_thumb($url);
212
+ return $new_url ? $new_url : $url;
213
+ }
214
+
215
  function fifu_test_execution_time() {
216
  for ($i = 0; $i <= 120; $i++) {
217
  error_log($i);
261
  'callback' => 'fifu_api_list_all_without_dimensions',
262
  'permission_callback' => 'fifu_get_private_data_permissions_check',
263
  ));
264
+ register_rest_route('featured-image-from-url/v2', '/convert_instagram_url/', array(
265
+ 'methods' => 'POST',
266
+ 'callback' => 'fifu_api_convert_instagram_url',
267
+ 'permission_callback' => 'fifu_get_private_data_permissions_check',
268
+ ));
269
  register_rest_route('featured-image-from-url/v2', '/rest_url_api/', array(
270
  'methods' => ['GET', 'POST'],
271
  'callback' => 'fifu_rest_url',
admin/html/js/convert-url.js CHANGED
@@ -33,5 +33,29 @@ function fifu_instagram_id($url) {
33
  }
34
 
35
  function fifu_instagram_url($url) {
36
- return 'https://www.instagram.com/p/' + fifu_instagram_id($url) + '/media/?size=l';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  }
33
  }
34
 
35
  function fifu_instagram_url($url) {
36
+ url = jQuery('#fifu_input_url').val();
37
+ jQuery.ajax({
38
+ method: "POST",
39
+ url: fifu_get_rest_url() + 'featured-image-from-url/v2/convert_instagram_url/',
40
+ data: {
41
+ "url": url,
42
+ },
43
+ async: false,
44
+ beforeSend: function (xhr) {
45
+ xhr.setRequestHeader('X-WP-Nonce', fifuScriptVars.nonce);
46
+ },
47
+ success: function (data) {
48
+ url = data;
49
+ jQuery('#fifu_input_url').val(url);
50
+ },
51
+ error: function (jqXHR, textStatus, errorThrown) {
52
+ console.log(jqXHR);
53
+ console.log(textStatus);
54
+ console.log(errorThrown);
55
+ },
56
+ complete: function () {
57
+ },
58
+ timeout: 0
59
+ });
60
+ return url;
61
  }
admin/meta-box.php CHANGED
@@ -23,9 +23,17 @@ function fifu_register_meta_box_script() {
23
  wp_enqueue_style('fancy-box-css', 'https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.7/jquery.fancybox.css');
24
  wp_enqueue_script('fancy-box-js', 'https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.js');
25
 
 
26
  wp_enqueue_script('fifu-meta-box-js', plugins_url('/html/js/meta-box.js', __FILE__), array('jquery'), fifu_version_number());
27
  wp_enqueue_script('fifu-convert-url-js', plugins_url('/html/js/convert-url.js', __FILE__), array('jquery'), fifu_version_number());
28
 
 
 
 
 
 
 
 
29
  if (fifu_is_sirv_active())
30
  wp_enqueue_script('fifu-sirv-js', 'https://scripts.sirv.com/sirv.js');
31
 
23
  wp_enqueue_style('fancy-box-css', 'https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.7/jquery.fancybox.css');
24
  wp_enqueue_script('fancy-box-js', 'https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.js');
25
 
26
+ wp_enqueue_script('fifu-rest-route-js', plugins_url('/html/js/rest-route.js', __FILE__), array('jquery'), fifu_version_number());
27
  wp_enqueue_script('fifu-meta-box-js', plugins_url('/html/js/meta-box.js', __FILE__), array('jquery'), fifu_version_number());
28
  wp_enqueue_script('fifu-convert-url-js', plugins_url('/html/js/convert-url.js', __FILE__), array('jquery'), fifu_version_number());
29
 
30
+ // register custom variables for the AJAX script
31
+ wp_localize_script('fifu-rest-route-js', 'fifuScriptVars', [
32
+ 'restUrl' => esc_url_raw(rest_url()),
33
+ 'homeUrl' => esc_url_raw(home_url()),
34
+ 'nonce' => wp_create_nonce('wp_rest'),
35
+ ]);
36
+
37
  if (fifu_is_sirv_active())
38
  wp_enqueue_script('fifu-sirv-js', 'https://scripts.sirv.com/sirv.js');
39
 
featured-image-from-url.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin Name: Featured Image from URL | FIFU
5
  * Plugin URI: https://fifu.app/
6
  * Description: Use an external image as featured image of a post or WooCommerce product. Includes Image Search, Video, Social Tags, SEO, Lazy Load, Gallery, Automation etc.
7
- * Version: 3.4.0
8
  * Author: fifu.app
9
  * Author URI: https://fifu.app/
10
  * WC requires at least: 4.0
4
  * Plugin Name: Featured Image from URL | FIFU
5
  * Plugin URI: https://fifu.app/
6
  * Description: Use an external image as featured image of a post or WooCommerce product. Includes Image Search, Video, Social Tags, SEO, Lazy Load, Gallery, Automation etc.
7
+ * Version: 3.4.1
8
  * Author: fifu.app
9
  * Author URI: https://fifu.app/
10
  * WC requires at least: 4.0
includes/attachment.php CHANGED
@@ -106,8 +106,7 @@ function fifu_replace_attachment_image_src($image, $att_id, $size) {
106
  if (get_post_meta($post->ID, 'fifu_dataset', true) != 2) {
107
  $title = $post->post_title;
108
  $permalink = get_permalink($post->ID);
109
- $tags = fifu_get_tags($post->ID);
110
- $_POST['fifu-dataset'][$post->ID] = array($post->ID, $old_url, $new_url, $title, $permalink, $tags);
111
  }
112
  }
113
  }
@@ -296,6 +295,9 @@ function fifu_add_url_parameters($url, $att_id) {
296
  if (!$post_id)
297
  return $url;
298
 
 
 
 
299
  $post_thumbnail_id = get_post_thumbnail_id($post_id);
300
  $post_thumbnail_id = $post_thumbnail_id ? $post_thumbnail_id : get_term_meta($post_id, 'thumbnail_id', true);
301
  $featured = $post_thumbnail_id == $att_id ? 1 : 0;
106
  if (get_post_meta($post->ID, 'fifu_dataset', true) != 2) {
107
  $title = $post->post_title;
108
  $permalink = get_permalink($post->ID);
109
+ $_POST['fifu-dataset'][$post->ID] = array($post->ID, $old_url, $new_url, $title, $permalink);
 
110
  }
111
  }
112
  }
295
  if (!$post_id)
296
  return $url;
297
 
298
+ // instagram URL fixer
299
+ $url = fifu_check_instagram_thumb($url, $att_id, $post_id);
300
+
301
  $post_thumbnail_id = get_post_thumbnail_id($post_id);
302
  $post_thumbnail_id = $post_thumbnail_id ? $post_thumbnail_id : get_term_meta($post_id, 'thumbnail_id', true);
303
  $featured = $post_thumbnail_id == $att_id ? 1 : 0;
includes/convert-url.php CHANGED
@@ -39,3 +39,8 @@ function fifu_instagram_id($url) {
39
  function fifu_instagram_url($url) {
40
  return 'https://www.instagram.com/p/' . fifu_instagram_id($url) . '/media/?size=l';
41
  }
 
 
 
 
 
39
  function fifu_instagram_url($url) {
40
  return 'https://www.instagram.com/p/' . fifu_instagram_id($url) . '/media/?size=l';
41
  }
42
+
43
+ function fifu_is_old_instagram_url($url) {
44
+ return strpos($url, 'https://www.instagram.com/p/') !== false;
45
+ }
46
+
includes/util.php CHANGED
@@ -71,6 +71,27 @@ function fifu_get_tags($post_id) {
71
  return $names ? rtrim($names) : null;
72
  }
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  function fifu_get_home_url() {
75
  return explode('//', get_home_url())[1];
76
  }
71
  return $names ? rtrim($names) : null;
72
  }
73
 
74
+ function fifu_check_instagram_thumb($url, $att_id, $post_id) {
75
+ if (!fifu_is_old_instagram_url($url))
76
+ return $url;
77
+
78
+ if (!fifu_is_in_editor()) {
79
+ $db_url = get_post_meta($post_id, 'fifu_image_url', true);
80
+ if ($db_url == $url) {
81
+ $new_url = fifu_api_get_instagram_thumb($url);
82
+ if ($new_url) {
83
+ update_post_meta($post_id, 'fifu_image_url', $new_url);
84
+ update_post_meta($att_id, '_wp_attached_file', $new_url);
85
+ global $wpdb;
86
+ $wpdb->update($wpdb->posts, ['guid' => $new_url], ['ID' => $att_id]);
87
+ return $new_url;
88
+ }
89
+ } else
90
+ return $db_url;
91
+ }
92
+ return $url;
93
+ }
94
+
95
  function fifu_get_home_url() {
96
  return explode('//', get_home_url())[1];
97
  }
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://donorbox.org/fifu
4
  Tags: featured, image, url, woocommerce, thumbnail
5
  Requires at least: 5.3
6
  Tested up to: 5.5
7
- Stable tag: 3.4.0
8
  License: GPLv3
9
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -195,20 +195,20 @@ Supports videos from YouTube, Vimeo, Imgur, 9GAG, Cloudinary, Tumblr and Publiti
195
 
196
  == Changelog ==
197
 
 
 
 
198
  = 3.4.0 =
199
  * Notice: for users with image URLs from Instagram (FIFU Settings > Troubleshooting).
200
 
201
  = 3.3.9 =
202
  * Notice: for Jetpack CDN users.
203
 
204
- = 3.3.8 =
205
- * New feature: auto set featured image using ISBN and books API (great for book stores); notice: for Amazon associates.
206
-
207
  = others =
208
  * [more](https://fifu.app/changelog/)
209
 
210
 
211
  == Upgrade Notice ==
212
 
213
- = 3.4.0 =
214
- * Notice: for users with image URLs from Instagram (FIFU Settings > Troubleshooting).
4
  Tags: featured, image, url, woocommerce, thumbnail
5
  Requires at least: 5.3
6
  Tested up to: 5.5
7
+ Stable tag: 3.4.1
8
  License: GPLv3
9
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
10
 
195
 
196
  == Changelog ==
197
 
198
+ = 3.4.1 =
199
+ * Fix: Instagram URLs.
200
+
201
  = 3.4.0 =
202
  * Notice: for users with image URLs from Instagram (FIFU Settings > Troubleshooting).
203
 
204
  = 3.3.9 =
205
  * Notice: for Jetpack CDN users.
206
 
 
 
 
207
  = others =
208
  * [more](https://fifu.app/changelog/)
209
 
210
 
211
  == Upgrade Notice ==
212
 
213
+ = 3.4.1 =
214
+ * Fix: Instagram URLs.