PluginProbe ʕ •ᴥ•ʔ
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress / 4.10.0
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress v4.10.0
4.12.0 4.10.0 4.9.0 4.8.1 trunk 1.0 1.1 1.12.1 1.2.3 1.2.4 1.2.5 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.5 1.5.1 1.5.2 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.4.1 1.6.5 1.6.5.1 1.6.6 1.6.6.1 1.6.6.2 1.6.6.3 1.6.7 1.6.7.1 1.6.8 1.6.8.1 1.6.8.2 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.9.0 1.9.1 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.8.1 1.9.9 1.9.9.1 1.9.9.2 1.9.9.3 2.0 2.0.1 2.1 2.1.1 2.1.2 2.1.3 2.10 2.11 2.11.1 2.12 2.12.1 2.12.2 2.12.3 2.12.4 2.13 2.14 2.14.1 2.15 2.15.1 2.16 2.16.1 2.17 2.17.1 2.18 2.18.1 2.18.2 2.18.3 2.19 2.19.1 2.19.2 2.19.3 2.2 2.2.1 2.3 2.3.1 2.3.10 2.3.2 2.3.3 2.3.4 2.3.6 2.3.7 2.3.8 2.3.9 2.4 2.4.1 2.4.1.1 2.4.1.2 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5 2.5.1 2.5.2 2.6 2.6.1 2.6.2 2.6.3 2.6.4 2.7 2.7.1 2.7.2 2.8 2.9 2.9.1 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.1 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.7.5 4.7.6 4.7.7
custom-facebook-feed / inc / Admin / CFF_oEmbeds.php
custom-facebook-feed / inc / Admin Last commit date
Blocks 3 weeks ago Traits 3 weeks ago CFF_About_Us.php 3 weeks ago CFF_Admin.php 3 weeks ago CFF_Admin_Notices.php 3 weeks ago CFF_Callout.php 3 weeks ago CFF_Global_Settings.php 3 weeks ago CFF_Install_Skin.php 3 weeks ago CFF_New_User.php 3 weeks ago CFF_Notifications.php 3 weeks ago CFF_Onboarding_Wizard.php 3 weeks ago CFF_Support.php 3 weeks ago CFF_Support_Tool.php 3 weeks ago CFF_Upgrader.php 3 weeks ago CFF_oEmbeds.php 3 weeks ago index.php 3 weeks ago
CFF_oEmbeds.php
538 lines
1 <?php
2
3 /**
4 * The Settings Page
5 *
6 * @since 4.0
7 */
8
9 namespace CustomFacebookFeed\Admin;
10
11 if (! defined('ABSPATH')) {
12 exit; // Exit if accessed directly
13 }
14
15 use CustomFacebookFeed\CFF_View;
16 use CustomFacebookFeed\CFF_Response;
17 use CustomFacebookFeed\Helpers\Util;
18
19 class CFF_oEmbeds
20 {
21 /**
22 * Admin menu page slug.
23 *
24 * @since 4.0
25 *
26 * @var string
27 */
28 const SLUG = 'cff-oembeds-manager';
29
30 /**
31 * Initializing the class
32 *
33 * @since 4.0
34 */
35 public function __construct()
36 {
37 $this->init();
38 }
39
40 /**
41 * Determining if the user is viewing the our page, if so, party on.
42 *
43 * @since 4.0
44 */
45 public function init()
46 {
47 if (! is_admin()) {
48 return;
49 }
50
51 add_action('admin_menu', [$this, 'register_menu']);
52
53 add_action( 'wp_ajax_cff_oembed_connect_init', array( $this, 'oembed_connect_init' ) );
54 add_action('wp_ajax_disable_facebook_oembed', [$this, 'disable_facebook_oembed']);
55 add_action('wp_ajax_disable_instagram_oembed', [$this, 'disable_instagram_oembed']);
56 }
57
58 /**
59 * Register Menu.
60 *
61 * @since 4.0
62 */
63 public function register_menu()
64 {
65 $cap = current_user_can('manage_custom_facebook_feed_options') ? 'manage_custom_facebook_feed_options' : 'manage_options';
66 $cap = apply_filters('cff_settings_pages_capability', $cap);
67
68 $oembeds_manager = add_submenu_page(
69 'cff-top',
70 __('oEmbeds', 'custom-facebook-feed'),
71 __('oEmbeds', 'custom-facebook-feed'),
72 $cap,
73 self::SLUG,
74 [$this, 'oembeds_manager'],
75 2
76 );
77 add_action('load-' . $oembeds_manager, [$this,'oembeds_enqueue_admin_scripts']);
78 }
79
80 /**
81 * Marks an oEmbed connect as started for the current user.
82 *
83 * The external connect service redirects back with cff_access_token on a plain page
84 * load and does not carry any of our query parameters through, so there is no nonce on
85 * the inbound request to verify. This one-shot, short-lived, per-user marker stands in
86 * for the OAuth "state" value: only a real click on Connect (an authenticated,
87 * nonce-checked, same-origin POST) can set it, so a cross-site GET carrying an
88 * attacker's token has nothing to consume. processCffOembedAccessToken() deletes it on use.
89 *
90 * @since 4.9.1
91 *
92 * @return void
93 */
94 public function oembed_connect_init() {
95 // Same gate as the sibling disable_*_oembed handlers: wp_die()s on either a bad
96 // nonce or an insufficient capability, rather than returning a 200 with an error
97 // payload. The caller treats any non-success response as a failed init.
98 \CustomFacebookFeed\Builder\CFF_Feed_Builder::check_privilege( 'nonce' );
99
100 set_transient( self::connect_pending_key(), 1, 15 * MINUTE_IN_SECONDS );
101
102 wp_send_json_success();
103 }
104
105 /**
106 * Transient key holding the "connect started" marker for the current user.
107 *
108 * @since 4.9.1
109 *
110 * @return string
111 */
112 private static function connect_pending_key() {
113 return 'cff_oembed_connect_pending_' . get_current_user_id();
114 }
115
116 /**
117 * Disable Facebook oEmbed
118 *
119 * @since 4.0
120 *
121 * @return CFF_Response
122 */
123 public function disable_facebook_oembed()
124 {
125 \CustomFacebookFeed\Builder\CFF_Feed_Builder::check_privilege('nonce');
126
127 $oembed_settings = get_option('cff_oembed_token', array());
128 $oembed_settings['access_token'] = '';
129 $oembed_settings['disabled'] = true;
130 update_option('cff_oembed_token', $oembed_settings);
131
132 $response = new CFF_Response(true, array(
133 'connectionUrl' => $this->get_connection_url()
134 ));
135 $response->send();
136 }
137
138 /**
139 * Disable Instagram oEmbed
140 *
141 * @since 4.0
142 *
143 * @return CFF_Response
144 */
145 public function disable_instagram_oembed()
146 {
147 \CustomFacebookFeed\Builder\CFF_Feed_Builder::check_privilege('nonce');
148
149 $oembed_settings = get_option('sbi_oembed_token', array());
150 $oembed_settings['access_token'] = '';
151 $oembed_settings['disabled'] = true;
152 update_option('sbi_oembed_token', $oembed_settings);
153
154 $response = new CFF_Response(true, array(
155 'connectionUrl' => $this->get_connection_url()
156 ));
157 $response->send();
158 }
159
160 /**
161 * Enqueue oEmbeds CSS & Script.
162 *
163 * Loads only for oEmbeds page
164 *
165 * @since 4.0
166 */
167 public function oembeds_enqueue_admin_scripts()
168 {
169 if (! Util::current_page_is('cff-oembeds')) {
170 return;
171 }
172
173 wp_enqueue_style(
174 'oembeds-style',
175 CFF_PLUGIN_URL . 'admin/assets/css/oembeds.css',
176 false,
177 CFFVER
178 );
179
180 wp_enqueue_script(
181 'sb-vue',
182 CFF_PLUGIN_URL . 'admin/assets/js/vue.min.js',
183 null,
184 '2.6.12',
185 true
186 );
187
188 wp_enqueue_script(
189 'oembeds-app',
190 CFF_PLUGIN_URL . 'admin/assets/js/oembeds.js',
191 array( 'sb-vue' ),
192 CFFVER,
193 true
194 );
195
196 $cff_oembends = $this->statuses_and_info();
197 $cff_oembends['nonce'] = wp_create_nonce('cff-admin');
198
199 wp_localize_script(
200 'oembeds-app',
201 'cff_oembeds',
202 $cff_oembends
203 );
204 }
205
206 /**
207 * Statuses and info about the current state of oEmbed connection
208 *
209 * @return array
210 *
211 * @since 4.0
212 */
213 public function statuses_and_info()
214 {
215 $return = array(
216 'admin_url' => admin_url(),
217 'ajax_handler' => admin_url('admin-ajax.php'),
218 'supportPageUrl' => admin_url('admin.php?page=cff-support'),
219 'links' => \CustomFacebookFeed\Builder\CFF_Feed_Builder::get_links_with_utm(),
220 'socialWallLinks' => \CustomFacebookFeed\Builder\CFF_Feed_Builder::get_social_wall_links(),
221 'socialWallActivated' => is_plugin_active('social-wall/social-wall.php'),
222 'genericText' => array(
223 'help' => __('Help', 'custom-facebook-feed'),
224 'title' => __('oEmbeds', 'custom-facebook-feed'),
225 'description' => __('Use Smash Balloon to power any Facebook or Instagram oEmbeds across your site. Just click the button below and we\'ll do the rest. ', 'custom-facebook-feed'),
226 'facebookOEmbeds' => __('Facebook oEmbeds are currently not being handled by Smash Balloon', 'custom-facebook-feed'),
227 'facebookOEmbedsEnabled' => __('Facebook oEmbeds are turned on', 'custom-facebook-feed'),
228 'instagramOEmbeds' => __('Instagram oEmbeds are currently not being handled by Smash Balloon', 'custom-facebook-feed'),
229 'instagramOEmbedsEnabled' => __('Instagram oEmbeds are turned on', 'custom-facebook-feed'),
230 'enable' => __('Enable', 'custom-facebook-feed'),
231 'connectError' => __( 'Could not start the connection. Please reload this page and try again.', 'custom-facebook-feed' ),
232 'disable' => __('Disable', 'custom-facebook-feed'),
233 'whatAreOembeds' => __('What are oEmbeds?', 'custom-facebook-feed'),
234 'whatElseOembeds' => __('What else can the Custom Facebook Feed plugin do?', 'custom-facebook-feed'),
235 'whenYouPaste' => __('When you paste a link to a Facebook or Instagram post in WordPress, it automatically displays the post instead of the URL. That is called an oEmbed.', 'custom-facebook-feed'),
236 'dueToRecent' => __('Due to recent API changes from Facebook, WordPress cannot automatically embed your posts.', 'custom-facebook-feed'),
237 'however' => __('However, we have added this feature to Smash Balloon to make sure your oEmbeds keep working.', 'custom-facebook-feed'),
238 'justEnable' => __('Just enable it above, and all your existing and new embeds should work automatically, no other input required.', 'custom-facebook-feed'),
239 'displayACompletely' => __('Display a completely customizable Facebook Feed with tons of features', 'custom-facebook-feed'),
240 'createACustom' => __('Create a custom styled feed of your Facebook Page or Group posts which integrates seamlessly with your WordPress theme.', 'custom-facebook-feed'),
241 ),
242 'images' => array(
243 'fbIcon' => '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 2.04004C6.5 2.04004 2 6.53004 2 12.06C2 17.06 5.66 21.21 10.44 21.96V14.96H7.9V12.06H10.44V9.85004C10.44 7.34004 11.93 5.96004 14.22 5.96004C15.31 5.96004 16.45 6.15004 16.45 6.15004V8.62004H15.19C13.95 8.62004 13.56 9.39004 13.56 10.18V12.06H16.34L15.89 14.96H13.56V21.96C15.9164 21.5879 18.0622 20.3856 19.6099 18.5701C21.1576 16.7546 22.0054 14.4457 22 12.06C22 6.53004 17.5 2.04004 12 2.04004Z" fill="#006BFA"/></svg>',
244 'instaIcon' => '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 6.60938C9 6.60938 6.60938 9.04688 6.60938 12C6.60938 15 9 17.3906 12 17.3906C14.9531 17.3906 17.3906 15 17.3906 12C17.3906 9.04688 14.9531 6.60938 12 6.60938ZM12 15.5156C10.0781 15.5156 8.48438 13.9688 8.48438 12C8.48438 10.0781 10.0312 8.53125 12 8.53125C13.9219 8.53125 15.4688 10.0781 15.4688 12C15.4688 13.9688 13.9219 15.5156 12 15.5156ZM18.8438 6.42188C18.8438 5.71875 18.2812 5.15625 17.5781 5.15625C16.875 5.15625 16.3125 5.71875 16.3125 6.42188C16.3125 7.125 16.875 7.6875 17.5781 7.6875C18.2812 7.6875 18.8438 7.125 18.8438 6.42188ZM22.4062 7.6875C22.3125 6 21.9375 4.5 20.7188 3.28125C19.5 2.0625 18 1.6875 16.3125 1.59375C14.5781 1.5 9.375 1.5 7.64062 1.59375C5.95312 1.6875 4.5 2.0625 3.23438 3.28125C2.01562 4.5 1.64062 6 1.54688 7.6875C1.45312 9.42188 1.45312 14.625 1.54688 16.3594C1.64062 18.0469 2.01562 19.5 3.23438 20.7656C4.5 21.9844 5.95312 22.3594 7.64062 22.4531C9.375 22.5469 14.5781 22.5469 16.3125 22.4531C18 22.3594 19.5 21.9844 20.7188 20.7656C21.9375 19.5 22.3125 18.0469 22.4062 16.3594C22.5 14.625 22.5 9.42188 22.4062 7.6875ZM20.1562 18.1875C19.8281 19.125 19.0781 19.8281 18.1875 20.2031C16.7812 20.7656 13.5 20.625 12 20.625C10.4531 20.625 7.17188 20.7656 5.8125 20.2031C4.875 19.8281 4.17188 19.125 3.79688 18.1875C3.23438 16.8281 3.375 13.5469 3.375 12C3.375 10.5 3.23438 7.21875 3.79688 5.8125C4.17188 4.92188 4.875 4.21875 5.8125 3.84375C7.17188 3.28125 10.4531 3.42188 12 3.42188C13.5 3.42188 16.7812 3.28125 18.1875 3.84375C19.0781 4.17188 19.7812 4.92188 20.1562 5.8125C20.7188 7.21875 20.5781 10.5 20.5781 12C20.5781 13.5469 20.7188 16.8281 20.1562 18.1875Z" fill="url(#paint0_linear)"/><defs><linearGradient id="paint0_linear" x1="8.95781" y1="41.6859" x2="53.1891" y2="-3.46406" gradientUnits="userSpaceOnUse"><stop stop-color="white"/><stop offset="0.147864" stop-color="#F6640E"/><stop offset="0.443974" stop-color="#BA03A7"/><stop offset="0.733337" stop-color="#6A01B9"/><stop offset="1" stop-color="#6B01B9"/></linearGradient></defs></svg>',
245 'image1_2x' => CFF_PLUGIN_URL . 'admin/assets/img/oembeds-image-1@2x.png',
246 'image2_2x' => CFF_PLUGIN_URL . 'admin/assets/img/oembeds-image-2@2x.png',
247 'image3_2x' => CFF_PLUGIN_URL . 'admin/assets/img/oembeds-image-3@2x.png',
248 'image4_2x' => CFF_PLUGIN_URL . 'admin/assets/img/oembeds-image-4@2x.png',
249 ),
250 'modal' => array(
251 'title' => __('Enable Instagram oEmbeds', 'custom-facebook-feed'),
252 'description' => __('To enable Instagram oEmbeds our Instagram Feed plugin is required. Click the button below to Install it and enable Instagram oEmbeds.', 'custom-facebook-feed'),
253 'install' => __('Install Plugin', 'custom-facebook-feed'),
254 'activate' => __('Activate Plugin', 'custom-facebook-feed'),
255 'cancel' => __('Cancel', 'custom-facebook-feed'),
256 'instaIcon' => CFF_PLUGIN_URL . 'admin/assets/img/instagram-color-icon.svg',
257 'timesIcon' => '<svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M14.2084 2.14275L12.8572 0.791504L7.50008 6.14859L2.143 0.791504L0.791748 2.14275L6.14883 7.49984L0.791748 12.8569L2.143 14.2082L7.50008 8.85109L12.8572 14.2082L14.2084 12.8569L8.85133 7.49984L14.2084 2.14275Z" fill="#141B38"/></svg>',
258 'plusIcon' => '<svg width="13" height="12" viewBox="0 0 13 12" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12.0832 6.83317H7.08317V11.8332H5.4165V6.83317H0.416504V5.1665H5.4165V0.166504H7.08317V5.1665H12.0832V6.83317Z" fill="white"/></svg>'
259 ),
260 'loaderSVG' => '<svg version="1.1" id="loader-1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="20px" height="20px" viewBox="0 0 50 50" style="enable-background:new 0 0 50 50;" xml:space="preserve"><path fill="#fff" d="M43.935,25.145c0-10.318-8.364-18.683-18.683-18.683c-10.318,0-18.683,8.365-18.683,18.683h4.068c0-8.071,6.543-14.615,14.615-14.615c8.072,0,14.615,6.543,14.615,14.615H43.935z"><animateTransform attributeType="xml" attributeName="transform" type="rotate" from="0 25 25" to="360 25 25" dur="0.6s" repeatCount="indefinite"/></path></svg>',
261 'checkmarkSVG' => '<svg class="checkmark" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40"><path class="checkmark__check" fill="none" d="M14.1 27.2l7.1 7.2 16.7-16.8"/></svg>',
262 );
263
264 $oembed_token_settings = get_option('cff_oembed_token', array());
265 $saved_access_token_data = isset($oembed_token_settings['access_token']) ? $oembed_token_settings['access_token'] : false;
266 $newly_retrieved_oembed_connection_data = $this->maybeConnectionData($saved_access_token_data);
267 if (! empty($newly_retrieved_oembed_connection_data['access_token'])) {
268 $oembed_token_settings = $newly_retrieved_oembed_connection_data;
269 $return['newOembedData'] = $newly_retrieved_oembed_connection_data;
270
271 $encryption = new \CustomFacebookFeed\SB_Facebook_Data_Encryption();
272 if (isset($newly_retrieved_oembed_connection_data['access_token']) && ! $encryption->decrypt($newly_retrieved_oembed_connection_data['access_token'])) {
273 $newly_retrieved_oembed_connection_data['access_token'] = $encryption->encrypt($newly_retrieved_oembed_connection_data['access_token']);
274 }
275
276 update_option('cff_oembed_token', $newly_retrieved_oembed_connection_data);
277 update_option('sbi_oembed_token', $newly_retrieved_oembed_connection_data);
278 } elseif (! empty($newly_retrieved_oembed_connection_data)) {
279 $return['newOembedData'] = $newly_retrieved_oembed_connection_data;
280 }
281
282 $return['connectionURL'] = $this->get_connection_url();
283 $return['tokenData'] = $oembed_token_settings;
284
285 $return['facebook'] = array(
286 'doingOembeds' => $this->facebook_oembed_enabled()
287 );
288 $return['instagram'] = [
289 'active' => class_exists('\SB_Instagram_Oembed'),
290 'doingOembeds' => false
291 ];
292
293 $return['instagram']['installer'] = $this->instagram_installer_info();
294
295 if (class_exists('\SB_Instagram_Oembed')) {
296 $return['instagram']['doingOembeds'] = \SB_Instagram_Oembed::can_do_oembed();
297 }
298
299 return $return;
300 }
301
302 /**
303 * Connection URLs are based on the website connecting accounts so that is
304 * configured here and returned
305 *
306 * @return array
307 *
308 * @since 4.0
309 */
310 public static function get_connection_url()
311 {
312
313 $admin_url_state = admin_url('admin.php?page=cff-oembeds-manager');
314 $nonce = wp_create_nonce('cff_con');
315 // If the admin_url isn't returned correctly then use a fallback.
316 if ($admin_url_state === '/wp-admin/admin.php?page=cff-oembeds-manager') {
317 $admin_url_state = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
318 }
319 // Carry a dedicated nonce on the return URL where the connect service preserves the
320 // state query string. processCffOembedAccessToken() verifies this nonce — or the
321 // cff_con nonce POSTed below — before accepting cff_access_token, and falls back to
322 // the one-shot connect marker when the service returns neither.
323 $admin_url_state = add_query_arg( 'cff_oembed_nonce', wp_create_nonce( 'cff_oembed_connect' ), $admin_url_state );
324 return array(
325 'connect' => CFF_OEMBED_CONNECT_URL,
326 'cff_con' => $nonce,
327 'stateURL' => $admin_url_state
328 );
329 }
330
331 /**
332 * Listener for retrieving and storing an access token for oEmbeds
333 *
334 * @param string $saved_access_token_data
335 *
336 * @return array|bool
337 *
338 * @since 4.0
339 */
340 public static function maybeConnectionData($saved_access_token_data)
341 {
342 global $cff_notices;
343 $screen = get_current_screen();
344 $return = false;
345
346 if (!$screen || $screen->id !== 'facebook-feed_page_cff-oembeds-manager') {
347 return false;
348 }
349
350 $oembed_success_notice = $cff_notices->get_notice('oembed_api_change_reconnect');
351 if ($oembed_success_notice) {
352 $cff_notices->remove_notice('oembed_api_change_reconnect');
353 }
354
355 if (!empty($_GET['transfer']) && class_exists('\SB_Instagram_Oembed')) {
356 $sbi_oembed_token = \SB_Instagram_Oembed::last_access_token();
357 $return = get_option('sbi_oembed_token', array());
358 $return['access_token'] = $sbi_oembed_token;
359 $return['disabled'] = false;
360 }
361
362 if (isset($_GET['cff_access_token'])) {
363 $return = self::processCffOembedAccessToken($saved_access_token_data);
364 }
365 return $return;
366 }
367
368 /**
369 * Process oEmbed Access Token
370 *
371 * @return array
372 *
373 * @since 4.0
374 */
375 public static function processCffOembedAccessToken($saved_access_token_data)
376 {
377 global $cff_notices;
378 $return = [];
379
380 // Never accept cff_access_token from an unsolicited request. The connect service
381 // returns none of our parameters, so authorise on the one-shot marker that
382 // oembed_connect_init() sets when this user actually clicks Connect. A nonce is
383 // still honoured first for any return URL that does preserve the query string.
384 $oembed_nonce = isset( $_GET['cff_oembed_nonce'] ) ? sanitize_key( wp_unslash( $_GET['cff_oembed_nonce'] ) ) : '';
385 $connect_nonce = isset( $_GET['cff_con'] ) ? sanitize_key( wp_unslash( $_GET['cff_con'] ) ) : '';
386
387 $has_valid_nonce = wp_verify_nonce( $oembed_nonce, 'cff_oembed_connect' )
388 || wp_verify_nonce( $connect_nonce, 'cff_con' );
389
390 if ( ! $has_valid_nonce ) {
391 $pending_key = self::connect_pending_key();
392 if ( ! get_transient( $pending_key ) ) {
393 $return['error'] = 'Invalid Nonce';
394 return $return;
395 }
396 // One shot: a replay of the same URL is rejected.
397 delete_transient( $pending_key );
398 }
399
400 $access_token = $_GET['cff_access_token'];
401
402 $valid_new_access_token = !empty($access_token) && strlen($access_token) > 20 && $saved_access_token_data !== $access_token ?
403 sanitize_text_field($_GET['cff_access_token']) : false;
404
405 if ($valid_new_access_token) {
406 $return['access_token'] = $valid_new_access_token;
407 $return['disabled'] = false;
408 $return['expiration_date'] = 'never';
409
410 $oembed_notice = $cff_notices->get_notice('oembed_api_change');
411 if ($oembed_notice) {
412 $cff_notices->remove_notice('oembed_api_change');
413 }
414
415 $message = '<p><strong>' .
416 __('oEmbed account successfully connected. You are all set to continue creating oEmbeds.', 'custom-facebook-feed')
417 . '</strong></p>';
418 $success_args = array(
419 'class' => 'cff-admin-notices',
420 'message' => $message,
421 'dismissible' => true,
422 'dismiss' => array(
423 'class' => 'cff-notice-dismiss',
424 'icon' => CFF_PLUGIN_URL . 'admin/assets/img/cff-dismiss-icon.svg',
425 'tag' => 'a',
426 'href' => '#',
427 ),
428 'priority' => 1,
429 'page' => array(
430 'cff-oembeds-manager',
431 ),
432 'icon' => array(
433 'src' => CFF_PLUGIN_URL . 'admin/assets/img/cff-exclamation.svg',
434 'wrap' => '<span class="sb-notice-icon"><img {src}></span>',
435 ),
436 'styles' => array(
437 'display' => 'flex',
438 'justify-content' => 'space-between',
439 'gap' => '2rem',
440 ),
441 'wrap_schema' => '<div {id} {class}>{icon}<div class="cff-notice-wrap" {styles}><div class="cff-notice-body">{message}</div>{dismiss}</div></div>',
442 );
443
444 $cff_notices->add_notice('oembed_api_change_reconnect', 'information', $success_args);
445 $cff_statuses = get_option('cff_statuses', array());
446 $cff_statuses['oembed_api_change_notice'] = true;
447
448 update_option('cff_statuses', $cff_statuses);
449 } else {
450 if ($saved_access_token_data === $access_token) {
451 $return['error'] = 'Not New';
452 } else {
453 $return['error'] = 'Not Valid';
454 }
455 }
456
457 return $return;
458 }
459 /**
460 * Check if Facebook oEmbed is enabled or not
461 *
462 * @return bool
463 *
464 * @since 4.0
465 */
466 public function facebook_oembed_enabled()
467 {
468 $cff_oembed_token = get_option('cff_oembed_token');
469 if (isset($cff_oembed_token['access_token']) && isset($cff_oembed_token['disabled']) && ! $cff_oembed_token['disabled']) {
470 return true;
471 }
472 return false;
473 }
474
475 /**
476 * Determines what action for Instagram should be done in the following order
477 * and returns data used in the common "addon" installer
478 *
479 * Free or Pro active, do nothing
480 * Pro installed but not active, activate Pro
481 * Free installed but not active, activate Free
482 * Nothing installed, install and activate Free
483 *
484 * @return array
485 *
486 * @since 4.0
487 */
488 public static function instagram_installer_info()
489 {
490 $all_plugins = get_plugins();
491 $active_plugins = get_option('active_plugins');
492
493 if (
494 in_array('instagram-feed/instagram-feed.php', $active_plugins, true)
495 || in_array('instagram-feed-pro/instagram-feed.php', $active_plugins, true)
496 ) {
497 return [
498 'nextStep' => 'none',
499 'plugin' => 'none',
500 'action' => 'none'
501 ];
502 }
503
504 foreach ($all_plugins as $plugin) {
505 if (strpos($plugin['Name'], 'Instagram Feed Pro') !== false) {
506 return [
507 'nextStep' => 'pro_activate',
508 'plugin' => 'instagram-feed-pro/instagram-feed.php',
509 'action' => 'cff_activate_addon'
510 ];
511 }
512 if (strpos($plugin['Name'], 'Instagram Feed') !== false) {
513 return [
514 'nextStep' => 'free_activate',
515 'plugin' => 'instagram-feed/instagram-feed.php',
516 'action' => 'cff_activate_addon'
517 ];
518 }
519 }
520
521 return [
522 'nextStep' => 'free_install',
523 'plugin' => 'https://downloads.wordpress.org/plugin/instagram-feed.zip',
524 'action' => 'cff_install_addon'
525 ];
526 }
527
528 /**
529 * oEmbeds Manager Page View Template
530 *
531 * @since 4.0
532 */
533 public function oembeds_manager()
534 {
535 CFF_View::render('oembeds.index');
536 }
537 }
538