Admin
2 weeks ago
Builder
2 weeks ago
Helpers
2 weeks ago
Integrations
2 weeks ago
UsageTracking
2 weeks ago
CFF_Autolink.php
2 weeks ago
CFF_Blocks.php
2 weeks ago
CFF_Cache.php
2 weeks ago
CFF_Education.php
2 weeks ago
CFF_Elementor_Base.php
2 weeks ago
CFF_Elementor_Widget.php
2 weeks ago
CFF_Error_Reporter.php
2 weeks ago
CFF_FB_Settings.php
2 weeks ago
CFF_Feed_Elementor_Control.php
2 weeks ago
CFF_Feed_Locator.php
2 weeks ago
CFF_Feed_Pro.php
2 weeks ago
CFF_GDPR_Integrations.php
2 weeks ago
CFF_Group_Posts.php
2 weeks ago
CFF_HTTP_Request.php
2 weeks ago
CFF_Oembed.php
2 weeks ago
CFF_Parse.php
2 weeks ago
CFF_Resizer.php
2 weeks ago
CFF_Response.php
2 weeks ago
CFF_Shortcode.php
2 weeks ago
CFF_Shortcode_Display.php
2 weeks ago
CFF_SiteHealth.php
2 weeks ago
CFF_Utils.php
2 weeks ago
CFF_View.php
2 weeks ago
Custom_Facebook_Feed.php
2 weeks ago
Email_Notification.php
2 weeks ago
Platform_Data.php
2 weeks ago
SB_Facebook_Data_Encryption.php
2 weeks ago
SB_Facebook_Data_Manager.php
2 weeks ago
index.php
2 weeks ago
CFF_Parse.php
348 lines
| 1 | <?php |
| 2 | |
| 3 | namespace CustomFacebookFeed; |
| 4 | |
| 5 | if (! defined('ABSPATH')) { |
| 6 | exit; // Exit if accessed directly |
| 7 | } |
| 8 | |
| 9 | class CFF_Parse |
| 10 | { |
| 11 | public static function get_link($header_data) |
| 12 | { |
| 13 | $link = isset($header_data->link) ? $header_data->link : "https://facebook.com"; |
| 14 | return $link; |
| 15 | } |
| 16 | |
| 17 | public static function get_cover_source($header_data) |
| 18 | { |
| 19 | $url = isset($header_data->cover->source) ? $header_data->cover->source : ''; |
| 20 | return $url; |
| 21 | } |
| 22 | |
| 23 | public static function get_avatar($header_data) |
| 24 | { |
| 25 | $avatar = isset($header_data->picture->data->url) ? $header_data->picture->data->url : ''; |
| 26 | return $avatar; |
| 27 | } |
| 28 | |
| 29 | public static function get_name($header_data) |
| 30 | { |
| 31 | $name = isset($header_data->name) ? $header_data->name : ''; |
| 32 | return $name; |
| 33 | } |
| 34 | |
| 35 | public static function get_bio($header_data) |
| 36 | { |
| 37 | $about = isset($header_data->about) ? $header_data->about : ''; |
| 38 | return $about; |
| 39 | } |
| 40 | |
| 41 | public static function get_likes($header_data) |
| 42 | { |
| 43 | $likes = isset($header_data->fan_count) ? $header_data->fan_count : ''; |
| 44 | return $likes; |
| 45 | } |
| 46 | |
| 47 | public static function get_post_id($post) |
| 48 | { |
| 49 | if (isset($post->id)) { |
| 50 | return $post->id; |
| 51 | } elseif (! is_object($post) && isset($post['id'])) { |
| 52 | return $post['id']; |
| 53 | } |
| 54 | return ''; |
| 55 | } |
| 56 | |
| 57 | public static function get_timestamp($post) |
| 58 | { |
| 59 | if (isset($post->start_time)) { |
| 60 | return strtotime($post->start_time); |
| 61 | } elseif (! is_object($post) && isset($post['start_time'])) { |
| 62 | return strtotime($post['start_time']); |
| 63 | } elseif (isset($post->created_time)) { |
| 64 | return strtotime($post->created_time); |
| 65 | } elseif (! is_object($post) && isset($post['created_time'])) { |
| 66 | return strtotime($post['created_time']); |
| 67 | } |
| 68 | return ''; |
| 69 | } |
| 70 | public static function get_message($post) |
| 71 | { |
| 72 | |
| 73 | if (isset($post->message)) { |
| 74 | return $post->message; |
| 75 | } elseif (! is_object($post) && isset($post['message'])) { |
| 76 | return $post['message']; |
| 77 | } elseif (isset($post->description)) { |
| 78 | return $post->description; |
| 79 | } elseif (! is_object($post) && isset($post['description'])) { |
| 80 | return $post['description']; |
| 81 | } |
| 82 | return ''; |
| 83 | } |
| 84 | |
| 85 | public static function get_status_type($post) |
| 86 | { |
| 87 | |
| 88 | if (isset($post->status_type)) { |
| 89 | return $post->status_type; |
| 90 | } elseif (! is_object($post) && isset($post['status_type'])) { |
| 91 | return $post['status_type']; |
| 92 | } elseif ( |
| 93 | isset($post->start_time) |
| 94 | || (! is_object($post) && isset($post['start_time'])) |
| 95 | ) { |
| 96 | return 'event'; |
| 97 | } elseif ( |
| 98 | isset($post->images) |
| 99 | || (! is_object($post) && isset($post['images'])) |
| 100 | ) { |
| 101 | return 'photo'; |
| 102 | } elseif ( |
| 103 | isset($post->format) |
| 104 | || (! is_object($post) && isset($post['format'])) |
| 105 | ) { |
| 106 | return 'video'; |
| 107 | } elseif ( |
| 108 | isset($post->cover_photo) |
| 109 | || (! is_object($post) && isset($post['cover_photo'])) |
| 110 | ) { |
| 111 | return 'album'; |
| 112 | } |
| 113 | return ''; |
| 114 | } |
| 115 | |
| 116 | public static function get_event_name($post) |
| 117 | { |
| 118 | |
| 119 | if (isset($post->name)) { |
| 120 | return $post->name; |
| 121 | } elseif (! is_object($post) && isset($post['name'])) { |
| 122 | return $post['name']; |
| 123 | } |
| 124 | return ''; |
| 125 | } |
| 126 | |
| 127 | |
| 128 | |
| 129 | public static function get_permalink($post) |
| 130 | { |
| 131 | if (isset($post->start_time)) { |
| 132 | return 'https://www.facebook.com/events/' . $post->id; |
| 133 | } elseif (! is_object($post) && isset($post['start_time'])) { |
| 134 | return 'https://www.facebook.com/events/' . $post['id']; |
| 135 | } elseif (isset($post->id)) { |
| 136 | return 'https://www.facebook.com/' . $post->id; |
| 137 | } elseif (! is_object($post) && isset($post['id'])) { |
| 138 | return 'https://www.facebook.com/' . $post['id']; |
| 139 | } elseif (isset($post->link)) { |
| 140 | return $post->link; |
| 141 | } elseif (! is_object($post) && isset($post['link'])) { |
| 142 | return $post['link']; |
| 143 | } |
| 144 | return 'https://www.facebook.com/'; |
| 145 | } |
| 146 | |
| 147 | public static function get_from_link($post) |
| 148 | { |
| 149 | if (isset($post->from->link)) { |
| 150 | return $post->from->link; |
| 151 | } elseif (! is_object($post) && isset($post['from']['link'])) { |
| 152 | return $post['from']['link']; |
| 153 | } elseif (isset($post->owner->link)) { |
| 154 | return $post->owner->link; |
| 155 | } elseif (! is_object($post) && isset($post['owner']['link'])) { |
| 156 | return $post['owner']['link']; |
| 157 | } |
| 158 | return 'https://www.facebook.com/'; |
| 159 | } |
| 160 | |
| 161 | public static function get_item_title($data) |
| 162 | { |
| 163 | $title = ''; |
| 164 | if (isset($data->name)) { |
| 165 | $title = $data->name; |
| 166 | } elseif (! is_object($data) && isset($data['name'])) { |
| 167 | $title = $data['name']; |
| 168 | } |
| 169 | return $title; |
| 170 | } |
| 171 | |
| 172 | public static function get_attachments($post) |
| 173 | { |
| 174 | |
| 175 | if (isset($post->attachments)) { |
| 176 | return $post->attachments->data; |
| 177 | } elseif (! is_object($post) && isset($post['attachments'])) { |
| 178 | return $post['attachments']['data']; |
| 179 | } |
| 180 | return ''; |
| 181 | } |
| 182 | public static function get_sub_attachments($post) |
| 183 | { |
| 184 | |
| 185 | if (isset($post->attachments) && isset($post->attachments->data[0]->subattachments)) { |
| 186 | return $post->attachments->data[0]->subattachments->data ; |
| 187 | } elseif (! is_object($post) && isset($post['attachments']['data'][0]['subattachments'])) { |
| 188 | return $post['attachments']['data'][0]['subattachments']['data']; |
| 189 | } elseif (isset($post->subattachments)) { |
| 190 | return $post->subattachments->data ; |
| 191 | } elseif (! is_object($post) && isset($post['subattachments'])) { |
| 192 | return $post['subattachments']['data']; |
| 193 | } else { |
| 194 | return array(); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | public static function get_sub_attachment_type($sub_attachment) |
| 199 | { |
| 200 | |
| 201 | if (isset($sub_attachment->type)) { |
| 202 | return $sub_attachment->type; |
| 203 | } elseif (! is_object($sub_attachment) && isset($sub_attachment['type'])) { |
| 204 | return $sub_attachment['type']; |
| 205 | } |
| 206 | return ''; |
| 207 | } |
| 208 | |
| 209 | |
| 210 | public static function get_attachment_title($attachment) |
| 211 | { |
| 212 | |
| 213 | if (isset($attachment->title)) { |
| 214 | return $attachment->title; |
| 215 | } elseif (! is_object($attachment) && isset($attachment['title'])) { |
| 216 | return $attachment['title']; |
| 217 | } |
| 218 | return ''; |
| 219 | } |
| 220 | |
| 221 | public static function get_attachment_description($attachment) |
| 222 | { |
| 223 | |
| 224 | if (isset($attachment->description)) { |
| 225 | return $attachment->description; |
| 226 | } elseif (! is_object($attachment) && isset($attachment['description'])) { |
| 227 | return $attachment['description']; |
| 228 | } |
| 229 | return ''; |
| 230 | } |
| 231 | |
| 232 | public static function get_attachment_unshimmed_url($attachment) |
| 233 | { |
| 234 | |
| 235 | if (isset($attachment->unshimmed_url)) { |
| 236 | return $attachment->unshimmed_url; |
| 237 | } elseif (! is_object($attachment) && isset($attachment['unshimmed_url'])) { |
| 238 | return $attachment['unshimmed_url']; |
| 239 | } |
| 240 | return ''; |
| 241 | } |
| 242 | |
| 243 | public static function get_event_start_time($event) |
| 244 | { |
| 245 | $time = ''; |
| 246 | $timezone = 'UTC'; |
| 247 | |
| 248 | if (isset($event->start_time)) { |
| 249 | $time = $event->start_time; |
| 250 | $timezone = isset($event->timezone) ? $event->timezone : 'UTC'; |
| 251 | } elseif (! is_object($event) && isset($event['start_time'])) { |
| 252 | $time = $event['start_time']; |
| 253 | $timezone = isset($event['timezone']) ? $event['timezone'] : 'UTC'; |
| 254 | } |
| 255 | |
| 256 | $timestamp = CFF_Utils::cff_set_timezone(strtotime($time), $timezone); |
| 257 | |
| 258 | return $timestamp; |
| 259 | } |
| 260 | |
| 261 | public static function get_event_end_time($event) |
| 262 | { |
| 263 | $time = ''; |
| 264 | $timezone = 'UTC'; |
| 265 | |
| 266 | if (isset($event->end_time)) { |
| 267 | $time = $event->end_time; |
| 268 | $timezone = isset($event->timezone) ? $event->timezone : 'UTC'; |
| 269 | } elseif (! is_object($event) && isset($event['end_time'])) { |
| 270 | $time = $event['end_time']; |
| 271 | $timezone = isset($event['timezone']) ? $event['timezone'] : 'UTC'; |
| 272 | } |
| 273 | |
| 274 | $timestamp = CFF_Utils::cff_set_timezone(strtotime($time), $timezone); |
| 275 | |
| 276 | return $timestamp; |
| 277 | } |
| 278 | |
| 279 | public static function get_event_location_name($event) |
| 280 | { |
| 281 | if (isset($event->place->name)) { |
| 282 | return $event->place->name; |
| 283 | } elseif (! is_object($event) && isset($event['place']['name'])) { |
| 284 | return $event['place']['name']; |
| 285 | } |
| 286 | return ''; |
| 287 | } |
| 288 | |
| 289 | public static function get_event_street($event) |
| 290 | { |
| 291 | if (isset($event->place->location->street)) { |
| 292 | return $event->place->location->street; |
| 293 | } elseif (! is_object($event) && isset($event['place']['location']['street'])) { |
| 294 | return $event['place']['location']['street']; |
| 295 | } |
| 296 | return ''; |
| 297 | } |
| 298 | |
| 299 | public static function get_event_state($event) |
| 300 | { |
| 301 | if (isset($event->place->location->state)) { |
| 302 | return $event->place->location->state; |
| 303 | } elseif (! is_object($event) && isset($event['place']['location']['state'])) { |
| 304 | return $event['place']['location']['state']; |
| 305 | } |
| 306 | return ''; |
| 307 | } |
| 308 | |
| 309 | public static function get_event_city($event) |
| 310 | { |
| 311 | if (isset($event->place->location->city)) { |
| 312 | return $event->place->location->city; |
| 313 | } elseif (! is_object($event) && isset($event['place']['location']['city'])) { |
| 314 | return $event['place']['location']['city']; |
| 315 | } |
| 316 | return ''; |
| 317 | } |
| 318 | |
| 319 | public static function get_event_zip($event) |
| 320 | { |
| 321 | if (isset($event->place->location->zip)) { |
| 322 | return $event->place->location->zip; |
| 323 | } elseif (! is_object($event) && isset($event['place']['location']['zip'])) { |
| 324 | return $event['place']['location']['zip']; |
| 325 | } |
| 326 | return ''; |
| 327 | } |
| 328 | |
| 329 | public static function get_event_strings($event) |
| 330 | { |
| 331 | if (is_array($event)) { |
| 332 | $event = (object) $event; |
| 333 | } |
| 334 | return $event; |
| 335 | } |
| 336 | |
| 337 | public static function get_from_id($post) |
| 338 | { |
| 339 | if (is_object($post) && isset($post->from->id)) { |
| 340 | return $post->from->id; |
| 341 | } elseif (! is_object($post) && isset($post['from']['id'])) { |
| 342 | return $post['from']['id']; |
| 343 | } |
| 344 | |
| 345 | return 0; |
| 346 | } |
| 347 | } |
| 348 |