Controls
4 weeks ago
Tabs
4 weeks ago
CFF_Builder_Customizer.php
4 weeks ago
CFF_Db.php
4 weeks ago
CFF_Feed_Builder.php
4 weeks ago
CFF_Feed_Saver.php
4 weeks ago
CFF_Feed_Saver_Manager.php
4 weeks ago
CFF_Post_Set.php
4 weeks ago
CFF_Source.php
4 weeks ago
CFF_Theme_CSS.php
4 weeks ago
CFF_Tooltip_Wizard.php
4 weeks ago
index.php
4 weeks ago
CFF_Feed_Saver.php
867 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Custom Facebook Feed Database |
| 5 | * |
| 6 | * @since 4.0 |
| 7 | */ |
| 8 | |
| 9 | namespace CustomFacebookFeed\Builder; |
| 10 | |
| 11 | use CustomFacebookFeed\CFF_FB_Settings; |
| 12 | use CustomFacebookFeed\SB_Facebook_Data_Encryption; |
| 13 | |
| 14 | if (!defined('ABSPATH')) { |
| 15 | exit; // Exit if accessed directly |
| 16 | } |
| 17 | |
| 18 | class CFF_Feed_Saver |
| 19 | { |
| 20 | /** |
| 21 | * @var int |
| 22 | * |
| 23 | * @since 4.0 |
| 24 | */ |
| 25 | private $insert_id; |
| 26 | |
| 27 | /** |
| 28 | * @var array |
| 29 | * |
| 30 | * @since 4.0 |
| 31 | */ |
| 32 | private $data; |
| 33 | |
| 34 | /** |
| 35 | * @var array |
| 36 | * |
| 37 | * @since 4.0 |
| 38 | */ |
| 39 | private $sanitized_and_sorted_data; |
| 40 | |
| 41 | /** |
| 42 | * @var array |
| 43 | * |
| 44 | * @since 4.0 |
| 45 | */ |
| 46 | private $feed_db_data; |
| 47 | |
| 48 | |
| 49 | /** |
| 50 | * @var string |
| 51 | * |
| 52 | * @since 4.0 |
| 53 | */ |
| 54 | private $feed_name; |
| 55 | |
| 56 | /** |
| 57 | * @var bool |
| 58 | * |
| 59 | * @since 4.0 |
| 60 | */ |
| 61 | private $is_legacy; |
| 62 | |
| 63 | /** |
| 64 | * CFF_Feed_Saver constructor. |
| 65 | * |
| 66 | * @param int $insert_id |
| 67 | * |
| 68 | * @since 4.0 |
| 69 | */ |
| 70 | public function __construct($insert_id) |
| 71 | { |
| 72 | if ($insert_id === 'legacy') { |
| 73 | $this->is_legacy = true; |
| 74 | $this->insert_id = 0; |
| 75 | } else { |
| 76 | $this->is_legacy = false; |
| 77 | $this->insert_id = $insert_id; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Feed insert ID if it exists |
| 83 | * |
| 84 | * @return bool|int |
| 85 | * |
| 86 | * @since 4.0 |
| 87 | */ |
| 88 | public function get_feed_id() |
| 89 | { |
| 90 | if ($this->is_legacy) { |
| 91 | return 'legacy'; |
| 92 | } |
| 93 | if (! empty($this->insert_id)) { |
| 94 | return $this->insert_id; |
| 95 | } else { |
| 96 | return false; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * @param array $data |
| 102 | * |
| 103 | * @since 4.0 |
| 104 | */ |
| 105 | public function set_data($data) |
| 106 | { |
| 107 | $this->data = $data; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * @param string $feed_name |
| 112 | * |
| 113 | * @since 4.0 |
| 114 | */ |
| 115 | public function set_feed_name($feed_name) |
| 116 | { |
| 117 | $this->feed_name = $feed_name; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * @param array $feed_db_data |
| 122 | * |
| 123 | * @return array |
| 124 | * |
| 125 | * @since 4.0 |
| 126 | */ |
| 127 | public function get_feed_db_data() |
| 128 | { |
| 129 | return $this->feed_db_data; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Adds a new feed if there is no associated feed |
| 134 | * found. Otherwise updates the exiting feed. |
| 135 | * |
| 136 | * @return false|int |
| 137 | * |
| 138 | * @since 4.0 |
| 139 | */ |
| 140 | public function update_or_insert() |
| 141 | { |
| 142 | $this->sanitize_and_sort_data(); |
| 143 | |
| 144 | if ($this->exists_in_database()) { |
| 145 | return $this->update(); |
| 146 | } else { |
| 147 | return $this->insert(); |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * Whether or not a feed exists with the |
| 153 | * associated insert ID |
| 154 | * |
| 155 | * @return bool |
| 156 | * |
| 157 | * @since 4.0 |
| 158 | */ |
| 159 | public function exists_in_database() |
| 160 | { |
| 161 | if ($this->is_legacy) { |
| 162 | return true; |
| 163 | } |
| 164 | |
| 165 | if ($this->insert_id === false) { |
| 166 | return false; |
| 167 | } |
| 168 | |
| 169 | $args = array( |
| 170 | 'id' => $this->insert_id |
| 171 | ); |
| 172 | |
| 173 | $results = CFF_Db::feeds_query($args); |
| 174 | |
| 175 | return isset($results[0]); |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Inserts a new feed from sanitized and sorted data. |
| 180 | * Some data is saved in the cff_feeds table and some is |
| 181 | * saved in the cff_feed_settings table. |
| 182 | * |
| 183 | * @return false|int |
| 184 | * |
| 185 | * @since 4.0 |
| 186 | */ |
| 187 | public function insert() |
| 188 | { |
| 189 | if ($this->is_legacy) { |
| 190 | return $this->update(); |
| 191 | } |
| 192 | |
| 193 | if (! isset($this->sanitized_and_sorted_data)) { |
| 194 | return false; |
| 195 | } |
| 196 | |
| 197 | $settings_array = CFF_Feed_Saver::format_settings($this->sanitized_and_sorted_data['feed_settings']); |
| 198 | |
| 199 | $this->sanitized_and_sorted_data['feeds'][] = array( |
| 200 | 'key' => 'settings', |
| 201 | 'values' => array( \CustomFacebookFeed\CFF_Utils::cff_json_encode($settings_array) ) |
| 202 | ); |
| 203 | |
| 204 | if (! empty($this->feed_name)) { |
| 205 | $this->sanitized_and_sorted_data['feeds'][] = array( |
| 206 | 'key' => 'feed_name', |
| 207 | 'values' => array( $this->feed_name ) |
| 208 | ); |
| 209 | } |
| 210 | |
| 211 | $this->sanitized_and_sorted_data['feeds'][] = array( |
| 212 | 'key' => 'status', |
| 213 | 'values' => array( 'publish' ) |
| 214 | ); |
| 215 | |
| 216 | $insert_id = CFF_Db::feeds_insert($this->sanitized_and_sorted_data['feeds']); |
| 217 | |
| 218 | if ($insert_id) { |
| 219 | $this->insert_id = $insert_id; |
| 220 | |
| 221 | return $insert_id; |
| 222 | } |
| 223 | |
| 224 | return false; |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * Updates an existing feed and related settings from |
| 229 | * sanitized and sorted data. |
| 230 | * |
| 231 | * @return false|int |
| 232 | * |
| 233 | * @since 4.0 |
| 234 | */ |
| 235 | public function update() |
| 236 | { |
| 237 | $encryption = new SB_Facebook_Data_Encryption(); |
| 238 | if (! isset($this->sanitized_and_sorted_data)) { |
| 239 | return false; |
| 240 | } |
| 241 | |
| 242 | $args = array( |
| 243 | 'id' => $this->insert_id |
| 244 | ); |
| 245 | |
| 246 | $settings_array = CFF_Feed_Saver::format_settings($this->sanitized_and_sorted_data['feed_settings']); |
| 247 | |
| 248 | if ($this->is_legacy) { |
| 249 | $to_save_json = \CustomFacebookFeed\CFF_Utils::cff_json_encode($settings_array); |
| 250 | $to_save_json = $encryption->maybe_encrypt($to_save_json); |
| 251 | |
| 252 | return update_option('cff_legacy_feed_settings', $to_save_json); |
| 253 | } |
| 254 | |
| 255 | $this->sanitized_and_sorted_data['feeds'][] = array( |
| 256 | 'key' => 'settings', |
| 257 | 'values' => array( \CustomFacebookFeed\CFF_Utils::cff_json_encode($settings_array) ) |
| 258 | ); |
| 259 | |
| 260 | $this->sanitized_and_sorted_data['feeds'][] = array( |
| 261 | 'key' => 'feed_name', |
| 262 | 'values' => [sanitize_text_field($this->feed_name)] |
| 263 | ); |
| 264 | |
| 265 | $success = CFF_Db::feeds_update($this->sanitized_and_sorted_data['feeds'], $args); |
| 266 | |
| 267 | return $success; |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * Converts settings that have been sanitized into an associative array |
| 272 | * that can be saved as JSON in the database |
| 273 | * |
| 274 | * @param $raw_settings |
| 275 | * |
| 276 | * @return array |
| 277 | * |
| 278 | * @since 4.0 |
| 279 | */ |
| 280 | public static function format_settings($raw_settings) |
| 281 | { |
| 282 | $settings_array = array(); |
| 283 | foreach ($raw_settings as $single_setting) { |
| 284 | if (count($single_setting['values']) > 1) { |
| 285 | $settings_array[ $single_setting['key'] ] = $single_setting['values']; |
| 286 | } else { |
| 287 | $settings_array[ $single_setting['key'] ] = $single_setting['values'][0]; |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | return $settings_array; |
| 292 | } |
| 293 | |
| 294 | /** |
| 295 | * Retrieves and organizes feed setting data for easy use in |
| 296 | * the builder |
| 297 | * |
| 298 | * @return array|bool |
| 299 | * |
| 300 | * @since 4.0 |
| 301 | */ |
| 302 | public function get_feed_settings($is_export = false) |
| 303 | { |
| 304 | $encryption = new SB_Facebook_Data_Encryption(); |
| 305 | if ($this->is_legacy) { |
| 306 | $return = CFF_FB_Settings::get_legacy_settings(array()) ; |
| 307 | $this->feed_db_data = array( |
| 308 | 'id' => 'legacy', |
| 309 | 'feed_name' => __('Legacy Feeds', 'custom-facebook-feed'), |
| 310 | 'feed_title' => __('Legacy Feeds', 'custom-facebook-feed'), |
| 311 | 'status' => 'publish', |
| 312 | 'last_modified' => date('Y-m-d H:i:s'), |
| 313 | ); |
| 314 | } elseif (empty($this->insert_id)) { |
| 315 | return false; |
| 316 | } else { |
| 317 | $args = array( |
| 318 | 'id' => $this->insert_id, |
| 319 | ); |
| 320 | $settings_db_data = CFF_Db::feeds_query($args); |
| 321 | if (false === $settings_db_data || sizeof($settings_db_data) == 0) { |
| 322 | return false; |
| 323 | } |
| 324 | $this->feed_db_data = array( |
| 325 | 'id' => $settings_db_data[0]['id'], |
| 326 | 'feed_name' => $settings_db_data[0]['feed_name'], |
| 327 | 'feed_title' => $settings_db_data[0]['feed_title'], |
| 328 | 'status' => $settings_db_data[0]['status'], |
| 329 | 'last_modified' => $settings_db_data[0]['last_modified'], |
| 330 | ); |
| 331 | |
| 332 | $return = json_decode($settings_db_data[0]['settings'], true); |
| 333 | $return['feed_name'] = $settings_db_data[0]['feed_name']; |
| 334 | } |
| 335 | |
| 336 | $return = wp_parse_args($return, CFF_Feed_Saver::settings_defaults()); |
| 337 | |
| 338 | |
| 339 | if (empty($return['sources'])) { |
| 340 | return $return; |
| 341 | } |
| 342 | $args = array( 'id' => $return['sources'] ); |
| 343 | |
| 344 | if ( |
| 345 | ! empty($return['type']) |
| 346 | && $return['type'] === 'events' |
| 347 | && ! empty($return['eventsource']) |
| 348 | && $return['eventsource'] === 'eventspage' |
| 349 | ) { |
| 350 | $args['privilege'] = 'events'; |
| 351 | } |
| 352 | |
| 353 | if (isset($return['feedtype']) && $return['feedtype'] == 'events') { |
| 354 | $args['privilege'] = 'events'; |
| 355 | } |
| 356 | |
| 357 | $source_query = CFF_Db::source_query($args); |
| 358 | |
| 359 | $return['sources'] = array(); |
| 360 | |
| 361 | if (! empty($source_query)) { |
| 362 | foreach ($source_query as $source) { |
| 363 | $info = ! empty($source['info']) ? json_decode(stripslashes($source['info'])) : array(); |
| 364 | $avatar = \CustomFacebookFeed\CFF_Parse::get_avatar($info); |
| 365 | |
| 366 | $source['avatar_url'] = $avatar; |
| 367 | $return['sources'][] = array( |
| 368 | 'record_id' => stripslashes($source['id']), |
| 369 | 'account_id' => stripslashes($source['account_id']), |
| 370 | 'account_type' => stripslashes($source['account_type']), |
| 371 | 'privilege' => stripslashes($source['privilege']), |
| 372 | 'access_token' => $is_export === true ? stripslashes($source['access_token']) : stripslashes($encryption->decrypt($source['access_token'])), |
| 373 | 'username' => stripslashes($source['username']), |
| 374 | 'info' => stripslashes($encryption->decrypt($source['info'])), |
| 375 | 'error' => stripslashes($source['error']), |
| 376 | 'expires' => stripslashes($source['expires']), |
| 377 | 'avatar_url' => stripslashes($source['avatar_url']), |
| 378 | |
| 379 | ); |
| 380 | } |
| 381 | |
| 382 | $return['accesstoken'] = stripslashes($source_query[0]['access_token']); |
| 383 | $return['id'] = stripslashes($source_query[0]['account_id']); |
| 384 | } else { |
| 385 | if (isset($args['privilege'])) { |
| 386 | unset($args['privilege']); |
| 387 | $source_query = CFF_Db::source_query($args); |
| 388 | } else { |
| 389 | $args['privilege'] = 'events'; |
| 390 | $source_query = CFF_Db::source_query($args); |
| 391 | } |
| 392 | |
| 393 | if (empty($source_query)) { |
| 394 | $source_query = CFF_Db::source_query(); |
| 395 | } |
| 396 | if (isset($source_query[0])) { |
| 397 | $return['sources'][] = array( |
| 398 | 'record_id' => stripslashes($source_query[0]['id']), |
| 399 | 'account_id' => stripslashes($source_query[0]['account_id']), |
| 400 | 'account_type' => stripslashes($source_query[0]['account_type']), |
| 401 | 'privilege' => stripslashes($source_query[0]['privilege']), |
| 402 | 'access_token' => stripslashes($encryption->decrypt($source_query[0]['access_token'])), |
| 403 | 'username' => stripslashes($source_query[0]['username']), |
| 404 | 'info' => stripslashes($encryption->decrypt($source_query[0]['info'])), |
| 405 | 'expires' => stripslashes($source_query[0]['expires']), |
| 406 | ); |
| 407 | |
| 408 | $return['accesstoken'] = stripslashes($source_query[0]['access_token']); |
| 409 | $return['id'] = stripslashes($source_query[0]['account_id']); |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | return $return; |
| 414 | } |
| 415 | |
| 416 | /** |
| 417 | * Retrieves and organizes feed setting data for easy use in |
| 418 | * the builder |
| 419 | * It will NOT get the settings from the DB, but from the Customizer builder |
| 420 | * To be used for updating feed preview on the fly |
| 421 | * |
| 422 | * @return array|bool |
| 423 | * |
| 424 | * @since 4.0 |
| 425 | */ |
| 426 | public function get_feed_settings_preview($settings_db_data) |
| 427 | { |
| 428 | if (false === $settings_db_data || sizeof($settings_db_data) == 0) { |
| 429 | return false; |
| 430 | } |
| 431 | $return = $settings_db_data; |
| 432 | $return = wp_parse_args($return, CFF_Feed_Saver::settings_defaults()); |
| 433 | if (empty($return['sources'])) { |
| 434 | return $return; |
| 435 | } |
| 436 | $sources = []; |
| 437 | foreach ($return['sources'] as $single_source) { |
| 438 | array_push($sources, $single_source['account_id']); |
| 439 | } |
| 440 | |
| 441 | $args = array( 'id' => $sources ); |
| 442 | $source_query = CFF_Db::source_query($args); |
| 443 | $encryption = new SB_Facebook_Data_Encryption(); |
| 444 | |
| 445 | $return['sources'] = array(); |
| 446 | if (! empty($source_query)) { |
| 447 | foreach ($source_query as $source) { |
| 448 | $return['sources'][] = array( |
| 449 | 'record_id' => stripslashes($source['id']), |
| 450 | 'account_id' => stripslashes($source['account_id']), |
| 451 | 'account_type' => stripslashes($source['account_type']), |
| 452 | 'access_token' => stripslashes($encryption->decrypt($source['access_token'])), |
| 453 | 'username' => stripslashes($source['username']), |
| 454 | 'info' => stripslashes($encryption->decrypt($source['info'])), |
| 455 | 'expires' => stripslashes($source['expires']), |
| 456 | ); |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | return $return; |
| 461 | } |
| 462 | |
| 463 | |
| 464 | |
| 465 | /** |
| 466 | * Default settings, $return_array equalling false will return |
| 467 | * the settings in the general way that the "CFF_Shortcode" class, |
| 468 | * "cff_get_processed_options" method does |
| 469 | * |
| 470 | * @param bool $return_array |
| 471 | * |
| 472 | * @return array |
| 473 | * |
| 474 | * @since 4.0 |
| 475 | */ |
| 476 | public static function settings_defaults($return_array = true) |
| 477 | { |
| 478 | { |
| 479 | $translations = get_option('cff_style_settings', array()); |
| 480 | |
| 481 | $final_translations = []; |
| 482 | $final_translations['facebooklinktext'] = isset($translations['cff_facebook_link_text']) ? stripslashes(esc_attr($translations['cff_facebook_link_text'])) : __('View on Facebook', 'custom-facebook-feed'); |
| 483 | $final_translations['sharelinktext'] = isset($translations['cff_facebook_share_text']) ? stripslashes(esc_attr($translations['cff_facebook_share_text'])) : __('Share', 'custom-facebook-feed'); |
| 484 | $final_translations['buttontext'] = isset($translations[ 'cff_load_more_text' ]) ? stripslashes(esc_attr($translations[ 'cff_load_more_text' ])) : __('Load more', 'custom-facebook-feed'); |
| 485 | |
| 486 | $defaults = array( |
| 487 | 'sources' => '', |
| 488 | 'accesstoken' => '', |
| 489 | 'ownaccesstoken' => true, |
| 490 | 'pagetoken' => '', |
| 491 | 'id' => '', |
| 492 | 'pagetype' => 'page', |
| 493 | 'num' => '5', |
| 494 | 'limit' => '', |
| 495 | 'others' => '', |
| 496 | 'showpostsby' => 'me', |
| 497 | 'cachetype' => 'background', |
| 498 | 'cachetime' => '1', |
| 499 | 'cacheunit' => 'hours', |
| 500 | 'locale' => 'en_US', |
| 501 | 'storytags' => 'false', |
| 502 | 'ajax' => '', |
| 503 | 'offset' => '', |
| 504 | 'account' => '', |
| 505 | 'width' => '100%', |
| 506 | 'widthresp' => '', |
| 507 | 'height' => '', |
| 508 | 'padding' => '', |
| 509 | 'bgcolor' => '#', |
| 510 | 'showauthor' => '', |
| 511 | 'showauthornew' => true, // test this |
| 512 | 'class' => '', |
| 513 | 'type' => 'links,events,videos,photos,albums,statuses', |
| 514 | 'gdpr' => 'auto', |
| 515 | 'loadiframes' => 'false', |
| 516 | 'eventsource' => 'eventspage', |
| 517 | 'eventoffset' => '6', |
| 518 | 'eventimage' => 'full', |
| 519 | 'pastevents' => 'false', |
| 520 | 'albumsource' => 'photospage', |
| 521 | 'showalbumtitle' => 'on', |
| 522 | 'showalbumnum' => 'on', |
| 523 | 'albumcols' => '4', |
| 524 | 'photosource' => 'photospage', |
| 525 | 'photocols' => '4', |
| 526 | 'videosource' => 'videospage', |
| 527 | 'showvideoname' => 'on', |
| 528 | 'showvideodesc' => 'on', |
| 529 | 'videocols' => '4', |
| 530 | 'playlist' => '', |
| 531 | 'disablelightbox' => 'on', |
| 532 | 'filter' => '', |
| 533 | 'exfilter' => '', |
| 534 | 'layout' => 'full', |
| 535 | 'enablenarrow' => 'on', |
| 536 | 'oneimage' => '', |
| 537 | 'mediaposition' => 'below', |
| 538 | 'include' => 'author,text,desc,sharedlinks,date,medialink,eventtitle,eventdetails,link,likebox', |
| 539 | 'exclude' => '', |
| 540 | 'masonry' => '', |
| 541 | 'masonrycols' => '', |
| 542 | 'masonrycolsmobile' => '', |
| 543 | 'masonryjs' => true, |
| 544 | 'cols' => 3, |
| 545 | 'colsmobile' => 1, |
| 546 | 'colsjs' => true, |
| 547 | 'nummobile' => '', |
| 548 | 'poststyle' => 'regular', |
| 549 | 'postbgcolor' => '#', |
| 550 | 'postcorners' => '0', |
| 551 | 'boxshadow' => '', |
| 552 | 'textformat' => 'p', |
| 553 | 'textsize' => 'inherit', |
| 554 | 'textweight' => 'inherit', |
| 555 | 'textcolor' => '#', |
| 556 | 'textlinkcolor' => '#', |
| 557 | 'textlink' => '', |
| 558 | 'posttags' => 'on', |
| 559 | 'linkhashtags' => 'on', |
| 560 | 'lightboxcomments' => 'off', |
| 561 | 'authorsize' => 'inherit', |
| 562 | 'authorcolor' => '#', |
| 563 | 'descsize' => '12', |
| 564 | 'descweight' => 'inherit', |
| 565 | 'desccolor' => '#', |
| 566 | 'linktitleformat' => 'p', |
| 567 | 'linktitlesize' => 'inherit', |
| 568 | 'linkdescsize' => 'inherit', |
| 569 | 'linkurlsize' => '12', |
| 570 | 'linkdesccolor' => '#', |
| 571 | 'linktitlecolor' => '#', |
| 572 | 'linkurlcolor' => '#', |
| 573 | 'linkbgcolor' => '#', |
| 574 | 'linkbordercolor' => '#', |
| 575 | 'disablelinkbox' => 'off', |
| 576 | 'eventtitleformat' => 'p', |
| 577 | 'eventtitlesize' => 'inherit', |
| 578 | 'eventtitleweight' => 'inherit', |
| 579 | 'eventtitlecolor' => '#', |
| 580 | 'eventtitlelink' => true, |
| 581 | 'eventdatesize' => 'inherit', |
| 582 | 'eventdateweight' => 'inherit', |
| 583 | 'eventdatecolor' => '#', |
| 584 | 'eventdatepos' => 'below', |
| 585 | 'eventdateformat' => '14', |
| 586 | 'eventdatecustom' => '', |
| 587 | 'timezoneoffset' => 'false', |
| 588 | 'cff_enqueue_with_shortcode' => false, |
| 589 | 'eventdetailssize' => 'inherit', |
| 590 | 'eventdetailsweight' => 'inherit', |
| 591 | 'eventdetailscolor' => '#', |
| 592 | 'eventlinkcolor' => '#', |
| 593 | 'datepos' => 'author', |
| 594 | 'datesize' => 'inherit', |
| 595 | 'dateweight' => 'inherit', |
| 596 | 'datecolor' => '#', |
| 597 | 'dateformat' => '1', |
| 598 | 'datecustom' => '', |
| 599 | 'timezone' => 'America/Chicago', |
| 600 | 'beforedate' => '', |
| 601 | 'afterdate' => '', |
| 602 | 'linksize' => 'inherit', |
| 603 | 'linkweight' => 'inherit', |
| 604 | 'linkcolor' => '#', |
| 605 | 'linktotimeline' => false, |
| 606 | 'buttoncolor' => '', |
| 607 | 'buttonhovercolor' => '', |
| 608 | 'buttontextcolor' => '', |
| 609 | 'buttontext' => $final_translations['buttontext'], |
| 610 | 'facebooklinktext' => $final_translations['facebooklinktext'], |
| 611 | 'sharelinktext' => $final_translations['sharelinktext'], |
| 612 | 'iconstyle' => 'light', |
| 613 | 'socialtextcolor' => '#', |
| 614 | 'socialbgcolor' => '#', |
| 615 | 'sociallinkcolor' => '#', |
| 616 | 'expandcomments' => '', |
| 617 | 'commentsnum' => '4', |
| 618 | 'hidecommentimages' => '', |
| 619 | 'loadcommentsjs' => 'false', |
| 620 | 'salesposts' => 'false', |
| 621 | 'textlength' => '400', |
| 622 | 'desclength' => '200', |
| 623 | 'showlikebox' => 'on', |
| 624 | 'likeboxpos' => 'bottom', |
| 625 | 'likeboxoutside' => '', |
| 626 | 'likeboxcolor' => '', |
| 627 | 'likeboxtextcolor' => 'blue', |
| 628 | 'likeboxwidth' => '', |
| 629 | 'likeboxfaces' => '', |
| 630 | 'likeboxborder' => '', |
| 631 | 'likeboxcover' => 'on', |
| 632 | 'likeboxsmallheader' => 'off', |
| 633 | 'likeboxhidebtn' => '', |
| 634 | 'credit' => '', |
| 635 | 'textissue' => '', |
| 636 | 'disablesvgs' => '', |
| 637 | 'restrictedpage' => '', |
| 638 | 'hidesupporterposts' => '', |
| 639 | 'privategroup' => 'false', |
| 640 | 'nofollow' => 'true', |
| 641 | 'timelinepag' => 'date', |
| 642 | 'gridpag' => 'auto', |
| 643 | 'disableresize' => false, |
| 644 | 'showheader' => 'on', |
| 645 | 'headertype' => 'visual', |
| 646 | 'headercover' => 'on', |
| 647 | 'headeravatar' => '', |
| 648 | 'headername' => 'on', |
| 649 | 'headerbio' => 'on', |
| 650 | 'headercoverheight' => '300', |
| 651 | 'headerlikes' => '', |
| 652 | 'headeroutside' => 'on', |
| 653 | 'headertext' => __('Facebook Posts', 'custom-facebook-feed'), |
| 654 | 'headerbg' => '#', |
| 655 | 'headerpadding' => '', |
| 656 | 'headertextsize' => 'inherit', |
| 657 | 'headertextweight' => 'inherit', |
| 658 | 'headertextcolor' => '#', |
| 659 | 'headericon' => 'facebook-square', |
| 660 | 'headericoncolor' => '#', |
| 661 | 'headericonsize' => '28', |
| 662 | 'headerinc' => '', |
| 663 | 'headerexclude' => '', |
| 664 | 'loadmore' => 'on', |
| 665 | 'fulllinkimages' => 'on', |
| 666 | 'linkimagesize' => 'largesquare', |
| 667 | 'postimagesize' => 'large', |
| 668 | 'videoheight' => '', |
| 669 | 'videoaction' => 'post', |
| 670 | 'videoplayer' => 'facebook', |
| 671 | 'sepcolor' => '#ddd', |
| 672 | 'sepsize' => '1', |
| 673 | 'photostext' => 'photos', |
| 674 | 'showfacebooklink' => 'true', // test this |
| 675 | 'showsharelink' => 'true', // test this |
| 676 | 'multifeedactive' => false, |
| 677 | 'daterangeactive' => false, |
| 678 | 'featuredpostactive' => false, |
| 679 | 'albumactive' => false, |
| 680 | 'masonryactive' => false, |
| 681 | 'carouselactive' => false, |
| 682 | 'reviewsactive' => false, |
| 683 | // Date Range |
| 684 | 'from' => '', |
| 685 | 'until' => '', |
| 686 | 'daterangefromtype' => 'specific', |
| 687 | 'daterangefromspecific' => '', |
| 688 | 'daterangefromrelative' => '', |
| 689 | |
| 690 | 'daterangeuntiltype' => 'specific', |
| 691 | 'daterangeuntilspecific' => '', |
| 692 | 'daterangeuntilrelative' => '', |
| 693 | |
| 694 | 'featuredpost' => '', |
| 695 | 'album' => '', |
| 696 | 'daterange' => 'off', |
| 697 | 'lightbox' => 'off', |
| 698 | 'reviewsrated' => '1,2,3,4,5', |
| 699 | 'starsize' => '12', |
| 700 | 'hidenegative' => '', |
| 701 | 'reviewslinktext' => __('View all Reviews', 'custom-facebook-feed'), |
| 702 | 'reviewshidenotext' => '', |
| 703 | 'reviewsmethod' => 'all', |
| 704 | // TO BE CHECKED |
| 705 | 'feedtype' => 'timeline', // working |
| 706 | 'likeboxcustomwidth' => '', // working |
| 707 | 'colstablet' => 2, // working 400/800 |
| 708 | 'feedlayout' => 'list', // working |
| 709 | 'colorpalette' => 'inherit', // working |
| 710 | 'custombgcolor1' => '', // working |
| 711 | 'custombgcolor2' => '', // working |
| 712 | 'textcolor1' => '', // working |
| 713 | 'textcolor2' => '', // working |
| 714 | 'customlinkcolor' => '', // working |
| 715 | 'posttextcolor' => '', // working |
| 716 | 'misctextcolor' => '', // working |
| 717 | 'misclinkcolor' => '', // working |
| 718 | 'headericonenabled' => 'on', // working |
| 719 | 'lightboxbgcolor' => '', // working |
| 720 | 'lightboxtextcolor' => '', // working |
| 721 | 'lightboxlinkcolor' => '', // working |
| 722 | 'beforedateenabled' => 'off', // working |
| 723 | 'afterdateenabled' => 'off', // working |
| 724 | 'showpoststypes' => 'custom', // working |
| 725 | 'headerbiosize' => 'inherit', // working |
| 726 | 'headerbiocolor' => '#', // working |
| 727 | 'apipostlimit' => 'auto', // working |
| 728 | 'carouselheight' => 'tallest', |
| 729 | 'carouseldesktop_cols' => 1, |
| 730 | 'carouselmobile_cols' => 1, |
| 731 | 'carouselnavigation' => 'none', |
| 732 | 'carouselpagination' => 'true', |
| 733 | 'carouselautoplay' => 'false', |
| 734 | 'carouselinterval' => 5000, |
| 735 | ); |
| 736 | |
| 737 | $defaults = CFF_Feed_Saver::filter_defaults($defaults); |
| 738 | |
| 739 | // some settings are comma separated and not arrays when the feed is created |
| 740 | if ($return_array) { |
| 741 | $settings_with_multiples = array( |
| 742 | 'sources', |
| 743 | 'accesstoken', |
| 744 | 'id', |
| 745 | 'type', |
| 746 | 'include', |
| 747 | 'exclude', |
| 748 | 'filter', |
| 749 | 'exfilter' |
| 750 | ); |
| 751 | |
| 752 | foreach ($settings_with_multiples as $multiple_key) { |
| 753 | if (isset($defaults[ $multiple_key ])) { |
| 754 | $defaults[ $multiple_key ] = explode(',', $defaults[ $multiple_key ]); |
| 755 | } |
| 756 | } |
| 757 | } |
| 758 | |
| 759 | return $defaults; |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | /** |
| 764 | * Provides backwards compatibility for extensions |
| 765 | * |
| 766 | * @param array $defaults |
| 767 | * |
| 768 | * @return array |
| 769 | * |
| 770 | * @since 4.0 |
| 771 | */ |
| 772 | public static function filter_defaults($defaults) |
| 773 | { |
| 774 | |
| 775 | if (\CustomFacebookFeed\CFF_FB_Settings::check_active_extension('carousel')) { |
| 776 | $cff_carousel_options = get_option('cff_carousel_options'); |
| 777 | // If an option is set, use the saved value, otherwise use the default |
| 778 | $enabled = isset($cff_carousel_options['cff_carousel_enabled']) ? $cff_carousel_options['cff_carousel_enabled'] : false; |
| 779 | $height = isset($cff_carousel_options['cff_carousel_height']) ? $cff_carousel_options['cff_carousel_height'] : 'tallest'; |
| 780 | $desktop_cols = isset($cff_carousel_options['cff_carousel_desktop_cols']) ? $cff_carousel_options['cff_carousel_desktop_cols'] : 1; |
| 781 | $mobile_cols = isset($cff_carousel_options['cff_carousel_mobile_cols']) ? $cff_carousel_options['cff_carousel_mobile_cols'] : 1; |
| 782 | $arrows = isset($cff_carousel_options['cff_carousel_navigation']) ? $cff_carousel_options['cff_carousel_navigation'] : 'none'; |
| 783 | $pagination = isset($cff_carousel_options['cff_carousel_pagination']) ? $cff_carousel_options['cff_carousel_pagination'] : true; |
| 784 | $autoplay = isset($cff_carousel_options['cff_carousel_autoplay']) ? $cff_carousel_options['cff_carousel_autoplay'] : false; |
| 785 | $interval = isset($cff_carousel_options['cff_carousel_interval']) ? $cff_carousel_options['cff_carousel_interval'] : 5000; |
| 786 | |
| 787 | $defaults['carouselheight'] = $height; |
| 788 | $defaults['carouseldesktop_cols'] = $desktop_cols; |
| 789 | $defaults['carouselmobile_cols'] = $mobile_cols; |
| 790 | $defaults['carouselnavigation'] = $arrows; |
| 791 | $defaults['carouselpagination'] = $pagination || $pagination === 'on'; |
| 792 | $defaults['carouselautoplay'] = $autoplay || $autoplay === 'on'; |
| 793 | $defaults['carouselinterval'] = $interval; |
| 794 | |
| 795 | if ($enabled) { |
| 796 | $defaults['feedlayout'] = 'carousel'; |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | if (\CustomFacebookFeed\CFF_FB_Settings::check_active_extension('reviews')) { |
| 801 | $options = get_option('cff_style_settings', array()); |
| 802 | |
| 803 | $defaults['starsize'] = isset($options[ 'cff_star_size' ]) ? $options[ 'cff_star_size' ] : ''; |
| 804 | $defaults['hidenegative'] = isset($options[ 'cff_reviews_hide_negative' ]) ? stripslashes(esc_attr($options[ 'cff_reviews_hide_negative' ])) : ''; |
| 805 | $defaults['reviewslinktext'] = isset($options[ 'cff_reviews_link_text' ]) ? stripslashes(esc_attr($options[ 'cff_reviews_link_text' ])) : __('View all Reviews', 'custom-facebook-feed'); |
| 806 | $defaults['reviewshidenotext'] = isset($options[ 'cff_reviews_no_text' ]) ? stripslashes(esc_attr($options[ 'cff_reviews_no_text' ])) : ''; |
| 807 | $defaults['reviewsmethod'] = isset($options[ 'cff_reviews_method' ]) ? stripslashes(esc_attr($options[ 'cff_reviews_method' ])) : ''; |
| 808 | |
| 809 | $defaults['cff_reviews_rated_5'] = isset($options[ 'cff_reviews_rated_5' ]) ? $options[ 'cff_reviews_rated_5' ] : 'true'; |
| 810 | $defaults['cff_reviews_rated_4'] = isset($options[ 'cff_reviews_rated_4' ]) ? $options[ 'cff_reviews_rated_4' ] : 'true'; |
| 811 | $defaults['cff_reviews_rated_3'] = isset($options[ 'cff_reviews_rated_3' ]) ? $options[ 'cff_reviews_rated_3' ] : 'true'; |
| 812 | $defaults['cff_reviews_rated_2'] = isset($options[ 'cff_reviews_rated_2' ]) ? $options[ 'cff_reviews_rated_2' ] : 'true'; |
| 813 | $defaults['cff_reviews_rated_1'] = isset($options[ 'cff_reviews_rated_1' ]) ? $options[ 'cff_reviews_rated_1' ] : 'true'; |
| 814 | } |
| 815 | |
| 816 | return $defaults; |
| 817 | } |
| 818 | |
| 819 | public static function set_legacy_feed_settings() |
| 820 | { |
| 821 | $to_save = CFF_Post_Set::legacy_to_builder_convert(); |
| 822 | $encryption = new SB_Facebook_Data_Encryption(); |
| 823 | $to_save_json = \CustomFacebookFeed\CFF_Utils::cff_json_encode($to_save); |
| 824 | $to_save_json = $encryption->maybe_encrypt($to_save_json); |
| 825 | |
| 826 | update_option('cff_legacy_feed_settings', $to_save_json); |
| 827 | } |
| 828 | |
| 829 | /** |
| 830 | * Used for taking raw post data related to settings |
| 831 | * an sanitizing it and sorting it to easily use in |
| 832 | * the database tables |
| 833 | * |
| 834 | * @since 4.0 |
| 835 | */ |
| 836 | private function sanitize_and_sort_data() |
| 837 | { |
| 838 | $data = $this->data; |
| 839 | |
| 840 | $sanitized_and_sorted = array( |
| 841 | 'feeds' => array(), |
| 842 | 'feed_settings' => array() |
| 843 | ); |
| 844 | |
| 845 | foreach ($data as $key => $value) { |
| 846 | $data_type = CFF_Feed_Saver_Manager::get_data_type($key); |
| 847 | $sanitized_values = array(); |
| 848 | if (is_array($value)) { |
| 849 | foreach ($value as $item) { |
| 850 | $sanitized_values[] = CFF_Feed_Saver_Manager::sanitize($data_type['sanitization'], $item); |
| 851 | } |
| 852 | } else { |
| 853 | $sanitized_values[] = CFF_Feed_Saver_Manager::sanitize($data_type['sanitization'], $value); |
| 854 | } |
| 855 | |
| 856 | $single_sanitized = array( |
| 857 | 'key' => $key, |
| 858 | 'values' => $sanitized_values |
| 859 | ); |
| 860 | |
| 861 | $sanitized_and_sorted[ $data_type['table'] ][] = $single_sanitized; |
| 862 | } |
| 863 | |
| 864 | $this->sanitized_and_sorted_data = $sanitized_and_sorted; |
| 865 | } |
| 866 | } |
| 867 |