PluginProbe ʕ •ᴥ•ʔ
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress / 4.9.0
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress v4.9.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 / CFF_Blocks.php
custom-facebook-feed / inc Last commit date
Admin 1 month ago Builder 1 month ago Helpers 1 month ago Integrations 1 month ago UsageTracking 1 month ago CFF_Autolink.php 1 month ago CFF_Blocks.php 1 month ago CFF_Cache.php 1 month ago CFF_Education.php 1 month ago CFF_Elementor_Base.php 1 month ago CFF_Elementor_Widget.php 1 month ago CFF_Error_Reporter.php 1 month ago CFF_FB_Settings.php 1 month ago CFF_Feed_Elementor_Control.php 1 month ago CFF_Feed_Locator.php 1 month ago CFF_Feed_Pro.php 1 month ago CFF_GDPR_Integrations.php 1 month ago CFF_Group_Posts.php 1 month ago CFF_HTTP_Request.php 1 month ago CFF_Oembed.php 1 month ago CFF_Parse.php 1 month ago CFF_Resizer.php 1 month ago CFF_Response.php 1 month ago CFF_Shortcode.php 1 month ago CFF_Shortcode_Display.php 1 month ago CFF_SiteHealth.php 1 month ago CFF_Utils.php 1 month ago CFF_View.php 1 month ago Custom_Facebook_Feed.php 1 month ago Email_Notification.php 1 month ago Platform_Data.php 1 month ago SB_Facebook_Data_Encryption.php 1 month ago SB_Facebook_Data_Manager.php 1 month ago index.php 1 month ago
CFF_Blocks.php
353 lines
1 <?php
2
3 /**
4 * Custom Facebook Feed block with live preview.
5 *
6 * @since 2.3
7 */
8
9 namespace CustomFacebookFeed;
10
11 use CustomFacebookFeed\Helpers\Util;
12 use CustomFacebookFeed\Builder\CFF_Db;
13 use CustomFacebookFeed\CFF_Utils;
14
15 if (!defined('ABSPATH')) {
16 exit; // Exit if accessed directly
17 }
18
19 class CFF_Blocks
20 {
21 /**
22 * Indicates if current integration is allowed to load.
23 *
24 * @since 1.8
25 *
26 * @return bool
27 */
28 public function allow_load()
29 {
30 return function_exists('register_block_type');
31 }
32
33 /**
34 * Loads an integration.
35 *
36 * @since 2.3
37 */
38 public function load()
39 {
40 $this->hooks();
41
42 require_once trailingslashit( CFF_PLUGIN_DIR ) . 'inc/Admin/Blocks/CFF_Modern_Feed_Block.php';
43 $modern_block = new \CustomFacebookFeed\Admin\Blocks\CFF_Modern_Feed_Block();
44 $modern_block->register_hooks();
45 }
46
47 /**
48 * Integration hooks.
49 *
50 * @since 2.3
51 */
52 protected function hooks()
53 {
54 add_action('init', array( $this, 'register_block' ));
55 add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_editor_assets' ), 25 );
56 // Styles enqueued on enqueue_block_assets are copied into the iframed editor
57 // canvas by core (wp_get_iframed_editor_assets), so this reaches the iframe on
58 // WP 7.0+ and the plain editor on older versions. Do NOT push raw CSS into the
59 // block_editor_settings_all `styles` array instead: entries there are treated
60 // as theme editor styles on every WP version, which suppresses core's default
61 // editor typography and drops the post title/content to the browser's serif
62 // fallback on themes that ship no editor styles.
63 add_action( 'enqueue_block_assets', array( $this, 'enqueue_block_content_assets' ) );
64
65 /*
66 * Add smashballoon category and Facebook Feed Block
67 * @since 4.1.9
68 */
69 add_filter('block_categories_all', array( $this, 'register_block_category' ), 10, 2);
70 }
71
72 /**
73 * Register Custom Facebook Feed Gutenberg block on the backend.
74 *
75 * @since 2.3
76 */
77 public function register_block()
78 {
79
80 wp_register_style(
81 'cff-blocks-styles',
82 trailingslashit(CFF_PLUGIN_URL) . 'assets/css/cff-blocks.css',
83 array( 'wp-edit-blocks' ),
84 CFFVER
85 );
86
87 $attributes = array(
88 'shortcodeSettings' => array(
89 'type' => 'string',
90 ),
91 'noNewChanges' => array(
92 'type' => 'boolean',
93 ),
94 'executed' => array(
95 'type' => 'boolean',
96 )
97 );
98
99 register_block_type(
100 'cff/cff-feed-block',
101 array(
102 'api_version' => 3,
103 'attributes' => $attributes,
104 'render_callback' => array( $this, 'get_feed_html' ),
105 'supports' => array( 'inserter' => false ),
106 )
107 );
108 }
109
110 /**
111 * Enqueue feed frontend assets so the legacy block preview renders inside
112 * the WP 6.7+ iframe block editor. Mirrors SB_Feed_Block::enqueue_block_content_assets().
113 *
114 * @since 4.5.0
115 */
116 public function enqueue_block_content_assets() {
117 if ( ! is_admin() ) {
118 return;
119 }
120 \cff_main()->enqueue_styles_assets();
121 \cff_main()->enqueue_scripts_assets();
122 // Force enqueue inside the iframe editor even when the "load assets only
123 // with shortcode" option is on — the enqueue_*_assets() methods only
124 // register the handles in that case.
125 wp_enqueue_style( 'cff' );
126 wp_enqueue_script( 'cffscripts' );
127 // Block UI rules (placeholder/settings form rendered inside the block) need
128 // to reach the iframed canvas too. Use a dedicated handle instead of the
129 // 'cff-blocks-styles' one registered for the outer editor page — that handle
130 // depends on wp-edit-blocks, which core already provides in the canvas.
131 wp_enqueue_style(
132 'cff-blocks-content',
133 trailingslashit( CFF_PLUGIN_URL ) . 'assets/css/cff-blocks.css',
134 array(),
135 CFFVER
136 );
137 }
138
139 /**
140 * Load Custom Facebook Feed Gutenberg block scripts.
141 *
142 * @since 2.3
143 */
144 public function enqueue_block_editor_assets()
145 {
146 $access_token = get_option('cff_access_token');
147
148 wp_enqueue_style('cff-blocks-styles');
149 wp_enqueue_script(
150 'cff-feed-block',
151 trailingslashit(CFF_PLUGIN_URL) . 'assets/js/cff-blocks.js',
152 array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-block-editor' ),
153 CFFVER,
154 true
155 );
156
157 $shortcodeSettings = '';
158
159 $i18n = array(
160 'addSettings' => esc_html__('Add Settings', 'custom-facebook-feed'),
161 'shortcodeSettings' => esc_html__('Shortcode Settings', 'custom-facebook-feed'),
162 'example' => esc_html__('Example', 'custom-facebook-feed'),
163 'preview' => esc_html__('Apply Changes', 'custom-facebook-feed'),
164
165 );
166
167 if (! empty($_GET['cff_wizard'])) {
168 $shortcodeSettings = 'feed="' . (int)$_GET['cff_wizard'] . '"';
169 }
170
171 // CFF's Helpers\Util does not expose isDebugging()/is_script_debug() helpers
172 // like Instagram Feed does, so fall back to the SCRIPT_DEBUG constant.
173 $is_script_debug = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;
174
175 $cff_js_file = $is_script_debug
176 ? 'assets/js/cff-scripts.js'
177 : 'assets/js/cff-scripts.min.js';
178
179 $jquery_file = 'js/jquery/jquery' . ( $is_script_debug ? '' : '.min' ) . '.js';
180
181 wp_localize_script(
182 'cff-feed-block',
183 'cff_block_editor',
184 array(
185 'wpnonce' => wp_create_nonce('facebook-blocks'),
186 'canShowFeed' => ! empty($access_token),
187 'configureLink' => get_admin_url() . '?page=cff-settings',
188 'shortcodeSettings' => $shortcodeSettings,
189 'i18n' => $i18n,
190 'iframeScriptUrl' => trailingslashit( CFF_PLUGIN_URL ) . $cff_js_file,
191 'jqueryUrl' => includes_url( $jquery_file ),
192 )
193 );
194 }
195
196 /**
197 * Get form HTML to display in a Custom Facebook Feed Gutenberg block.
198 *
199 * @param array $attr Attributes passed by Custom Facebook Feed Gutenberg block.
200 *
201 * @since 2.3
202 *
203 * @return string
204 */
205 public function get_feed_html($attr)
206 {
207 $cff_statuses = get_option('cff_statuses', array());
208
209 $return = '';
210
211 $shortcode_settings = isset($attr['shortcodeSettings']) ? $attr['shortcodeSettings'] : '';
212
213 if (empty($cff_statuses['support_legacy_shortcode'])) {
214 if (empty($shortcode_settings) || strpos($shortcode_settings, 'feed=') === false) {
215 $feeds = \CustomFacebookFeed\Builder\CFF_Feed_Builder::get_feed_list();
216 $feed_id = $feeds[0]['id'];
217 $shortcode_settings .= ' feed="' . (int)$feed_id . '"';
218 }
219 }
220
221 $shortcode_settings = str_replace(array( '[custom-facebook-feed', ']' ), '', $shortcode_settings);
222
223 $return .= do_shortcode('[custom-facebook-feed ' . $shortcode_settings . ']');
224
225 return $return;
226 }
227
228 /**
229 * Checking if is Gutenberg REST API call.
230 *
231 * @since 2.3
232 *
233 * @return bool True if is Gutenberg REST API call.
234 */
235 public static function is_gb_editor()
236 {
237 return defined( 'REST_REQUEST' ) && REST_REQUEST && ! empty( $_REQUEST['context'] ) && 'edit' === $_REQUEST['context']; // phpcs:ignore
238 }
239
240 /**
241 * Register Block Category
242 *
243 * @since 4.1.9
244 */
245 public function register_block_category($categories, $context)
246 {
247 $exists = array_search('smashballoon', array_column($categories, 'slug'));
248
249 if ($exists !== false) {
250 return $categories;
251 }
252
253 return array_merge(
254 $categories,
255 array(
256 array(
257 'slug' => 'smashballoon',
258 'title' => __('Smash Balloon', 'custom-facebook-feed'),
259 ),
260 )
261 );
262 }
263
264 /**
265 * Register Block
266 *
267 * @since 4.1.9
268 */
269 public function register_facebook_feed_block()
270 {
271 register_block_type(
272 trailingslashit(CFF_PLUGIN_DIR) . 'assets/dist/sbf-feed',
273 array(
274 'render_callback' => array( $this, 'render_facebook_feed_block' ),
275 )
276 );
277 }
278
279 /**
280 * Render Block
281 *
282 * @since 4.1.9
283 */
284 public function render_facebook_feed_block($attributes)
285 {
286 $content = '';
287
288 if (isset($attributes['feedId'])) {
289 $content = do_shortcode('[custom-facebook-feed feed=' . (int) $attributes['feedId'] . ']');
290 }
291
292 return $content;
293 }
294
295 /**
296 * Enqueue Block Assets
297 *
298 * @since 4.1.9
299 */
300 public function enqueue_facebook_feed_block_editor_assets()
301 {
302 $asset_file = include_once trailingslashit(CFF_PLUGIN_DIR) . 'assets/dist/blocks.asset.php';
303
304 wp_enqueue_script(
305 'cff-feed-block-editor',
306 trailingslashit(CFF_PLUGIN_URL) . 'assets/dist/blocks.js',
307 $asset_file['dependencies'],
308 $asset_file['version'],
309 true
310 );
311
312 wp_enqueue_style(
313 'cff-feed-block-editor',
314 trailingslashit(CFF_PLUGIN_URL) . 'assets/dist/blocks.css',
315 array(),
316 $asset_file['version']
317 );
318
319 wp_localize_script(
320 'cff-feed-block-editor',
321 'cff_feed_block_editor',
322 array(
323 'feeds' => CFF_Db::feeds_query(),
324 'feed_url' => admin_url('admin.php?page=cff-feed-builder'),
325 'plugins_info' => Util::get_smash_plugins_status_info(),
326 'has_facebook_feed_block' => $this->has_facebook_feed_block(),
327 'is_pro_active' => CFF_Utils::cff_is_pro_version(),
328 'nonce' => wp_create_nonce('cff-admin'),
329 )
330 );
331 }
332
333 /**
334 * Set Script Translations
335 *
336 * @since 4.1.9
337 */
338 public function set_script_translations()
339 {
340 wp_set_script_translations('cff-feed-block-editor', 'custom-facebook-feed', CFF_PLUGIN_DIR . 'languages');
341 }
342
343 /**
344 * Check if the post has a Facebook Feed block
345 *
346 * @since 4.1.9
347 */
348 public function has_facebook_feed_block()
349 {
350 return has_block('cff/cff-feed-block');
351 }
352 }
353