PluginProbe ʕ •ᴥ•ʔ
Essential Addons for Elementor – Popular Elementor Templates & Widgets / 5.8.7
Essential Addons for Elementor – Popular Elementor Templates & Widgets v5.8.7
6.6.5 6.6.4 6.6.3 5.7.3 5.7.4 5.8.0 5.8.1 5.8.10 5.8.11 5.8.12 5.8.13 5.8.14 5.8.15 5.8.16 5.8.18 5.8.2 5.8.3 5.8.4 5.8.5 5.8.6 5.8.7 5.8.8 5.8.9 5.9.0 5.9.1 5.9.10 5.9.11 5.9.12 5.9.13 5.9.14 5.9.15 5.9.16 5.9.17 5.9.18 5.9.19 5.9.2 5.9.20 5.9.21 5.9.22 5.9.23 5.9.24 5.9.25 5.9.26 5.9.27 5.9.3 5.9.4 5.9.5 5.9.6 5.9.7 5.9.8 5.9.9 6.0.0 6.0.1 6.0.10 6.0.11 6.0.12 6.0.13 6.0.14 6.0.15 6.0.2 6.0.3 6.0.4 6.0.5 6.0.6 6.0.7 6.0.8 6.0.9 6.1.0 6.1.1 6.1.10 6.1.11 trunk 6.1.12 1.0.0 6.1.13 1.0.1 6.1.14 1.1.0 6.1.15 2.0 6.1.17 2.1 6.1.18 2.10.0 6.1.19 2.10.1 6.1.2 2.10.2 6.1.20 2.10.3 6.1.3 2.10.4 6.1.4 2.10.5 6.1.5 2.2.0 6.1.6 2.2.1 6.1.7 2.2.2 6.1.8 2.2.3 6.1.9 2.2.4 6.2.0 2.2.5 6.2.1 2.3.0 6.2.2 2.3.1 6.2.3 2.4.0 6.2.4 2.4.1 6.3.0 2.4.2 6.3.1 2.4.3 6.3.2 2.5.0 6.3.3 2.6.0 6.4.0 2.7.0 6.5.0 2.7.1 6.5.1 2.7.10 6.5.10 2.7.11 6.5.11 2.7.2 6.5.12 2.7.3 6.5.13 2.7.4 6.5.2 2.7.5 6.5.3 2.7.6 6.5.4 2.7.7 6.5.5 2.7.8 6.5.6 2.7.9 6.5.7 2.8.0 6.5.8 2.8.1 6.5.9 2.8.2 6.6.0 2.8.3 6.6.1 2.8.4 6.6.2 2.8.5 2.8.6 2.8.7 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 2.9.9 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.4.1 3.1.5 3.2.0 3.3.0 3.3.1 3.3.2 3.3.3 3.4.0 3.5.0 3.5.1 3.5.2 3.6.0 3.6.1 3.6.2 3.7.0 3.7.1 3.7.2 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.3.8 4.3.9 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.5.3 4.5.4 4.5.5 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.7.5 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.9.0 4.9.1 4.9.2 4.9.3 4.9.4 4.9.5 4.9.6 4.9.7 5.0.0 5.0.1 5.0.10 5.0.11 5.0.12 5.0.13 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.0.9 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.2.0 5.2.1 5.2.2 5.2.3 5.2.4 5.3.0 5.3.1 5.3.2 5.4.6 5.5.5 5.6.5 5.7.2
essential-addons-for-elementor-lite / includes / Traits / Facebook_Feed.php
essential-addons-for-elementor-lite / includes / Traits Last commit date
Admin.php 3 years ago Ajax_Handler.php 2 years ago Controls.php 2 years ago Core.php 3 years ago Elements.php 2 years ago Enqueue.php 3 years ago Facebook_Feed.php 3 years ago Helper.php 2 years ago Library.php 3 years ago Login_Registration.php 2 years ago Shared.php 5 years ago Template_Query.php 4 years ago Twitter_Feed.php 2 years ago Woo_Product_Comparable.php 3 years ago index.php 3 years ago
Facebook_Feed.php
295 lines
1 <?php
2
3 namespace Essential_Addons_Elementor\Traits;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 } // Exit if accessed directly
8 use \Essential_Addons_Elementor\Classes\Helper as HelperClass;
9
10 trait Facebook_Feed {
11 /**
12 * Facebook Feed
13 *
14 * @param array $settings optional widget's settings
15 *
16 * @return false|string|void
17 * @since 3.4.0
18 */
19 public function facebook_feed_render_items( $settings = [] ) {
20 // check if ajax request
21 if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'facebook_feed_load_more' ) {
22 $ajax = wp_doing_ajax();
23 // check ajax referer
24 check_ajax_referer( 'essential-addons-elementor', 'security' );
25
26 // init vars
27 $page = isset( $_POST['page'] ) ? intval( $_REQUEST['page'], 10 ) : 0;
28 if ( ! empty( $_POST['post_id'] ) ) {
29 $post_id = intval( $_POST['post_id'], 10 );
30 } else {
31 $err_msg = __( 'Post ID is missing', 'essential-addons-for-elementor-lite' );
32 if ( $ajax ) {
33 wp_send_json_error( $err_msg );
34 }
35
36 return false;
37 }
38 if ( ! empty( $_POST['widget_id'] ) ) {
39 $widget_id = sanitize_text_field( $_POST['widget_id'] );
40 } else {
41 $err_msg = __( 'Widget ID is missing', 'essential-addons-for-elementor-lite' );
42 if ( $ajax ) {
43 wp_send_json_error( $err_msg );
44 }
45
46 return false;
47 }
48 $settings = HelperClass::eael_get_widget_settings( $post_id, $widget_id );
49
50 } else {
51 // init vars
52 $page = 0;
53 $settings = ! empty( $settings ) ? $settings : $this->get_settings_for_display();
54 }
55
56 $html = '';
57 $page_id = $settings['eael_facebook_feed_page_id'];
58 $token = $settings['eael_facebook_feed_access_token'];
59 $source = $settings['eael_facebook_feed_data_source'];
60 $display_comment = isset( $settings['eael_facebook_feed_comments'] ) ? $settings['eael_facebook_feed_comments'] : '';
61
62 if ( empty( $page_id ) || empty( $token ) ) {
63 return;
64 }
65
66 $key = 'eael_facebook_feed_' . md5( str_rot13( str_replace( '.', '', $source . $page_id . $token ) ) . $settings['eael_facebook_feed_cache_limit'] );
67 $facebook_data = get_transient( $key );
68
69 if ( $facebook_data == false ) {
70 $facebook_data = wp_remote_retrieve_body( wp_remote_get( $this->get_url($page_id, $token, $source, $display_comment), [
71 'timeout' => 70,
72 ] ) );
73 $facebook_data = json_decode( $facebook_data, true );
74 if ( isset( $facebook_data['data'] ) ) {
75 set_transient( $key, $facebook_data, ( $settings['eael_facebook_feed_cache_limit'] * MINUTE_IN_SECONDS ) );
76 }
77 }
78
79 if ( ! isset( $facebook_data['data'] ) ) {
80 return;
81 }
82 $facebook_data = $facebook_data['data'];
83
84 switch ( $settings['eael_facebook_feed_sort_by'] ) {
85 case 'least-recent':
86 $facebook_data = array_reverse( $facebook_data );
87 break;
88 }
89 $items = array_splice( $facebook_data, ( $page * $settings['eael_facebook_feed_image_count']['size'] ), $settings['eael_facebook_feed_image_count']['size'] );
90 $bg_style = isset( $settings['eael_facebook_feed_image_render_type'] ) && $settings['eael_facebook_feed_image_render_type'] == 'cover' ? "background-size: cover;background-position: center;background-repeat: no-repeat;" : "background-size: 100% 100%;background-repeat: no-repeat;";
91 foreach ( $items as $item ) {
92 $t = 'eael_facebook_feed_message_max_length'; // short it
93 $limit = isset( $settings[ $t ] ) && isset( $settings[ $t ]['size'] ) ? $settings[ $t ]['size'] : null;
94 $message = wp_trim_words( ( isset( $item['message'] ) ? $item['message'] : ( isset( $item['story'] ) ? $item['story'] : '' ) ), $limit, '...' );
95 $photo = ( isset( $item['full_picture'] ) ? esc_url( $item['full_picture'] ) : '' );
96 $likes = ( isset( $item['reactions'] ) ? $item['reactions']['summary']['total_count'] : 0 );
97 $comments = ( isset( $item['comments'] ) ? $item['comments']['summary']['total_count'] : 0 );
98
99 if ( empty( $photo ) ) {
100 $photo = isset( $item['attachments']['data'][0]['media']['image']['src'] ) ? esc_url( $item['attachments']['data'][0]['media']['image']['src'] ) : $photo;
101 }
102
103 if ( $settings['eael_facebook_feed_layout'] == 'card' ) {
104 $item_form_name = ! empty( $item['from']['name'] ) ? $item['from']['name'] : '';
105 $current_page_id = ! empty( $item['from']['id'] ) ? $item['from']['id'] : $page_id;
106
107 $html .= '<div class="eael-facebook-feed-item">
108 <div class="eael-facebook-feed-item-inner">
109 <header class="eael-facebook-feed-item-header clearfix">
110 <div class="eael-facebook-feed-item-user clearfix">
111 <a href="https://www.facebook.com/' . $current_page_id . '" target="' . ( $settings['eael_facebook_feed_link_target'] == 'yes' ? '_blank' : '_self' ) . '"><img src="https://graph.facebook.com/v4.0/' . $current_page_id . '/picture" alt="' . esc_attr( $item_form_name ) . '" class="eael-facebook-feed-avatar"></a>
112 <a href="https://www.facebook.com/' . $current_page_id . '" target="' . ( $settings['eael_facebook_feed_link_target'] == 'yes' ? '_blank' : '_self' ) . '"><p class="eael-facebook-feed-username">' . esc_html( $item_form_name ) . '</p></a>
113 </div>';
114
115 if ( $settings['eael_facebook_feed_date'] ) {
116 $html .= '<a href="' . esc_url( $item['permalink_url'] ) . '" target="' . ( $settings['eael_facebook_feed_link_target'] ? '_blank' : '_self' ) . '" class="eael-facebook-feed-post-time"><i class="far fa-clock" aria-hidden="true"></i> ' . date_i18n( get_option('date_format'), strtotime( $item['created_time'] ) ) . '</a>';
117 }
118 $html .= '</header>';
119
120 if ( $settings['eael_facebook_feed_message'] && ! empty( $message ) ) {
121 $html .= '<div class="eael-facebook-feed-item-content">
122 <p class="eael-facebook-feed-message">' . $this->eael_str_check( $message ) . '</p>
123 </div>';
124 }
125
126 if ( ! empty( $photo ) || isset( $item['attachments']['data'] ) ) {
127 $html .= '<div class="eael-facebook-feed-preview-wrap">';
128 if ( $item['status_type'] == 'shared_story' ) {
129
130 if ( isset( $settings['eael_facebook_feed_is_show_preview_thumbnail'] ) && 'yes' == $settings['eael_facebook_feed_is_show_preview_thumbnail'] ) {
131
132 $html .= '<a href="' . esc_url( $item['permalink_url'] ) . '" target="' . ( $settings['eael_facebook_feed_link_target'] == 'yes' ? '_blank' : '_self' ) . '" class="eael-facebook-feed-preview-img">';
133 if ( !empty($item['attachments']['data'][0]['media_type']) && $item['attachments']['data'][0]['media_type'] == 'video' ) {
134 $html .= '<div class="eael-facebook-feed-img-container" style="background:url(' . esc_url( $photo ) . ');' . esc_attr( $bg_style ) . '">
135 <img class="eael-facebook-feed-img" src="' . esc_url( $photo ) . '"></div>
136 <div class="eael-facebook-feed-preview-overlay"><i class="far fa-play-circle" aria-hidden="true"></i></div>';
137 } else {
138 $html .= '<div class="eael-facebook-feed-img-container" style="background:url(' . esc_url( $photo ) . ');' . esc_attr( $bg_style ) . '">
139 <img class="eael-facebook-feed-img" src="' . esc_url( $photo ) . '"></div>';
140 }
141 $html .= '</a>';
142 }
143
144 $html .= '<div class="eael-facebook-feed-url-preview">';
145 if ( isset( $settings['eael_facebook_feed_is_show_preview_host'] ) && 'yes' == $settings['eael_facebook_feed_is_show_preview_host'] && !empty($item['attachments']['data'][0]['unshimmed_url']) ) {
146 $html .= '<p class="eael-facebook-feed-url-host">' . parse_url( $item['attachments']['data'][0]['unshimmed_url'] )['host'] . '</p>';
147 }
148 if ( isset( $settings['eael_facebook_feed_is_show_preview_title'] ) && 'yes' == $settings['eael_facebook_feed_is_show_preview_title'] ) {
149 $html .= '<h2 class="eael-facebook-feed-url-title">' . esc_html( $item['attachments']['data'][0]['title'] ) . '</h2>';
150 }
151
152 if ( isset( $settings['eael_facebook_feed_is_show_preview_description'] ) && 'yes' == $settings['eael_facebook_feed_is_show_preview_description'] ) {
153 $description = isset( $item['attachments']['data'][0]['description'] ) ? $item['attachments']['data'][0]['description'] : '';
154 $html .= '<p class="eael-facebook-feed-url-description">' . $description . '</p>';
155 }
156 $html .= '</div>';
157
158 } else if ( $item['status_type'] == 'added_video' ) {
159 if ( isset( $settings['eael_facebook_feed_is_show_preview_thumbnail'] ) && 'yes' == $settings['eael_facebook_feed_is_show_preview_thumbnail'] ) {
160
161 $html .= '<a href="' . esc_url( $item['permalink_url'] ) . '" target="' . ( $settings['eael_facebook_feed_link_target'] == 'yes' ? '_blank' : '_self' ) . '" class="eael-facebook-feed-preview-img">
162 <div class="eael-facebook-feed-img-container" style="background:url(' . esc_url( $photo ) . '); ' . esc_attr( $bg_style ) . '">
163 <img class="eael-facebook-feed-img" src="' . esc_url( $photo ) . '">
164 </div>
165 <div class="eael-facebook-feed-preview-overlay"><i class="far fa-play-circle" aria-hidden="true"></i></div>
166 </a>';
167 }
168 } else {
169 if ( isset( $settings['eael_facebook_feed_is_show_preview_thumbnail'] ) && 'yes' == $settings['eael_facebook_feed_is_show_preview_thumbnail'] ) {
170
171 $html .= '<a href="' . esc_url( $item['permalink_url'] ) . '" target="' . ( $settings['eael_facebook_feed_link_target'] == 'yes' ? '_blank' : '_self' ) . '" class="eael-facebook-feed-preview-img">
172 <div class="eael-facebook-feed-img-container" style="background:url(' . esc_url( $photo ) . '); ' . esc_attr( $bg_style ) . '">
173 <img class="eael-facebook-feed-img" src="' . esc_url( $photo ) . '">
174 </div>
175 </a>';
176
177 }
178 }
179 $html .= '</div>';
180 }
181
182
183 if ( $settings['eael_facebook_feed_likes'] || $settings['eael_facebook_feed_comments'] ) {
184 $html .= '<footer class="eael-facebook-feed-item-footer">
185 <div class="clearfix">';
186 if ( $settings['eael_facebook_feed_likes'] ) {
187 $html .= '<span class="eael-facebook-feed-post-likes"><i class="far fa-thumbs-up" aria-hidden="true"></i> ' . esc_html( $likes ) . '</span>';
188 }
189 if ( $settings['eael_facebook_feed_comments'] ) {
190 $html .= '<span class="eael-facebook-feed-post-comments"><i class="far fa-comments" aria-hidden="true"></i> ' . esc_html( $comments ) . '</span>';
191 }
192 $html .= '</div>
193 </footer>';
194 }
195 $html .= '</div>
196 </div>';
197 } else {
198 $html .= '<a href="' . esc_url( $item['permalink_url'] ) . '" target="' . ( $settings['eael_facebook_feed_link_target'] ? '_blank' : '_self' ) . '" class="eael-facebook-feed-item">
199 <div class="eael-facebook-feed-item-inner">
200 <div class="eael-facebook-feed-img-container" style="background:url(' . ( empty( $photo ) ? EAEL_PLUGIN_URL . 'assets/front-end/img/flexia-preview.jpg' : esc_url( $photo ) ) . '); ' . esc_attr( $bg_style ) . '">
201 <img class="eael-facebook-feed-img" src="' . ( empty( $photo ) ? EAEL_PLUGIN_URL . 'assets/front-end/img/flexia-preview.jpg' : esc_url( $photo ) ) . '">
202 </div>';
203
204 if ( $settings['eael_facebook_feed_likes'] || $settings['eael_facebook_feed_comments'] ) {
205 $html .= '<div class="eael-facebook-feed-item-overlay">
206 <div class="eael-facebook-feed-item-overlay-inner">
207 <div class="eael-facebook-feed-meta">';
208 if ( $settings['eael_facebook_feed_likes'] ) {
209 $html .= '<span class="eael-facebook-feed-post-likes"><i class="far fa-thumbs-up" aria-hidden="true"></i> ' . esc_html( $likes ) . '</span>';
210 }
211 if ( $settings['eael_facebook_feed_comments'] ) {
212 $html .= '<span class="eael-facebook-feed-post-comments"><i class="far fa-comments" aria-hidden="true"></i> ' . esc_html( $comments ) . '</span>';
213 }
214 $html .= '</div>
215 </div>
216 </div>';
217 }
218 $html .= '</div>
219 </a>';
220 }
221 }
222
223 if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'facebook_feed_load_more' ) {
224 $data = [
225 'num_pages' => ceil( count( $facebook_data ) / $settings['eael_facebook_feed_image_count']['size'] ),
226 'html' => $html,
227 ];
228 while ( ob_get_status() ) {
229 ob_end_clean();
230 }
231 if ( function_exists( 'gzencode' ) ) {
232 $response = gzencode( wp_json_encode( $data ) );
233 header( 'Content-Type: application/json; charset=utf-8' );
234 header( 'Content-Encoding: gzip' );
235 header( 'Content-Length: ' . strlen( $response ) );
236
237 printf( '%1$s', $response );
238 } else {
239 wp_send_json( $data );
240 }
241 wp_die();
242
243 }
244
245 return $html;
246 }
247
248 public function eael_str_check( $textData = '' ) {
249 $stringText = '';
250 if ( strlen( $textData ) > 5 ) {
251 $explodeText = explode( ' ', trim( $textData ) );
252 for ( $st = 0; $st < count( $explodeText ); $st ++ ) {
253 $pos = stripos( trim( $explodeText[ $st ] ), '#' );
254 $pos1 = stripos( trim( $explodeText[ $st ] ), '@' );
255 $poshttp = stripos( trim( $explodeText[ $st ] ), 'http' );
256 $poshttps = stripos( trim( $explodeText[ $st ] ), 'https' );
257
258 if ( $pos !== false ) {
259 $stringText .= '<a href="https://facebook.com/hashtag/' . str_replace( '#', '', $explodeText[ $st ] ) . '?source=feed_text" target="_blank"> ' . esc_html( $explodeText[ $st ] ) . ' </a>';
260 } elseif ( $pos1 !== false ) {
261 $stringText .= '<a href="https://facebook.com/' . $explodeText[ $st ] . '/" target="_blank"> ' . esc_html( $explodeText[ $st ] ) . ' </a>';
262 } elseif ( $poshttp !== false || $poshttps !== false ) {
263 $stringText .= '<a href="' . esc_url( $explodeText[ $st ] ) . '" target="_blank"> ' . esc_html( $explodeText[ $st ] ) . ' </a>';
264 } else {
265 $stringText .= ' ' . $explodeText[ $st ];
266 }
267 }
268 }
269
270 return $stringText;
271 }
272
273 /**
274 * get_url
275 * Build and return api endpoint based on source type
276 *
277 * @param string $page_id string
278 * @param string $token string
279 * @param string $source string
280 *
281 * @return string
282 */
283 public function get_url( $page_id = '', $token = '', $source = 'posts', $display_comment = '' ) {
284 $comment_count = $display_comment == 'yes' ? ',comments.summary(total_count)' : '';
285 $post_limit = apply_filters( 'eael_facebook_feed_post_limit', 99 );
286 $post_url = "https://graph.facebook.com/v8.0/{$page_id}/posts?fields=status_type,created_time,from,message,story,full_picture,permalink_url,attachments.limit(1){type,media_type,title,description,unshimmed_url,media}{$comment_count},reactions.summary(total_count)&limit={$post_limit}&access_token={$token}";
287 $feed_url = "https://graph.facebook.com/v8.0/{$page_id}/feed?fields=id,message,full_picture,status_type,created_time,attachments{title,description,type,url,media},from,permalink_url,shares,call_to_action{$comment_count},reactions.summary(total_count),privacy&access_token={$token}&limit={$post_limit}&locale=en_US";
288
289 if ( 'posts' === $source ) {
290 return $post_url;
291 }
292 return $feed_url;
293 }
294 }
295