/static/wp-content/plugins/facebook/social-plugins/fb-recommendations.php

https://github.com/elleeott/WPOC-boilerplate · PHP · 142 lines · 91 code · 20 blank · 31 comment · 6 complexity · c47aa56fcd791adb5acf38049bde1b8d MD5 · raw file

  1. <?php
  2. function fb_get_recommendations_box($options = array()) {
  3. if (empty($options['header'])) {
  4. $options['header'] = 'false';
  5. }
  6. $params = fb_build_social_plugin_params($options);
  7. return '<div class="fb-recommendations fb-social-plugin" ' . $params . '></div>';
  8. }
  9. /**
  10. * Adds the Recommendations Social Plugin as a WordPress Widget
  11. */
  12. class Facebook_Recommendations extends WP_Widget {
  13. /**
  14. * Register widget with WordPress
  15. */
  16. public function __construct() {
  17. parent::__construct(
  18. 'fb_recommendations', // Base ID
  19. __( 'Facebook Recommendations', 'facebook' ), // Name
  20. array( 'description' => __( 'Shows personalized recommendations to your users.', 'facebook' ), ) // Args
  21. );
  22. }
  23. /**
  24. * Front-end display of widget.
  25. *
  26. * @see WP_Widget::widget()
  27. *
  28. * @param array $args Widget arguments.
  29. * @param array $instance Saved values from database.
  30. */
  31. public function widget( $args, $instance ) {
  32. extract( $args );
  33. echo $before_widget;
  34. if ( ! empty( $instance['title'] ) )
  35. echo $before_title . esc_attr($instance['title']) . $after_title;
  36. echo fb_get_recommendations_box($instance);
  37. echo $after_widget;
  38. }
  39. /**
  40. * Sanitize widget form values as they are saved.
  41. *
  42. * @see WP_Widget::update()
  43. *
  44. * @param array $new_instance Values just sent to be saved.
  45. * @param array $old_instance Previously saved values from database.
  46. *
  47. * @return array Updated safe values to be saved.
  48. */
  49. public function update( $new_instance, $old_instance ) {
  50. $return_instance = $old_instance;
  51. $fields = fb_get_recommendations_box_fields_array('widget');
  52. foreach( $fields['children'] as $field ) {
  53. $unsafe_value = ( isset( $new_instance[$field['name']] ) ) ? $new_instance[$field['name']] : '';
  54. if ( !empty( $field['sanitization_callback'] ) && function_exists( $field['sanitization_callback'] ) )
  55. $return_instance[$field['name']] = $field['sanitization_callback']( $unsafe_value );
  56. else
  57. $return_instance[$field['name']] = sanitize_text_field( $unsafe_value );
  58. }
  59. return $return_instance;
  60. }
  61. /**
  62. * Back-end widget form.
  63. *
  64. * @see WP_Widget::form()
  65. *
  66. * @param array $instance Previously saved values from database.
  67. */
  68. public function form( $instance ) {
  69. fb_get_recommendations_box_fields('widget', $this);
  70. }
  71. }
  72. function fb_get_recommendations_box_fields($placement = 'settings', $object = null) {
  73. $fields_array = fb_get_recommendations_box_fields_array($placement);
  74. fb_construct_fields($placement, $fields_array['children'], null, $object);
  75. }
  76. function fb_get_recommendations_box_fields_array($placement) {
  77. $array['children'] = array(array('name' => 'width',
  78. 'type' => 'text',
  79. 'default' => '300',
  80. 'help_text' => __( 'The width of the plugin, in pixels.', 'facebook' ),
  81. 'sanitization_callback' => 'intval',
  82. ),
  83. array('name' => 'height',
  84. 'type' => 'text',
  85. 'default' => '300',
  86. 'help_text' => __( 'The height of the plugin, in pixels.', 'facebook' ),
  87. 'sanitization_callback' => 'intval',
  88. ),
  89. array('name' => 'colorscheme',
  90. 'label' => 'Color scheme',
  91. 'type' => 'dropdown',
  92. 'default' => 'light',
  93. 'options' => array('light' => 'light', 'dark' => 'dark'),
  94. 'help_text' => __( 'The color scheme of the plugin.', 'facebook' ),
  95. ),
  96. array('name' => 'border_color',
  97. 'type' => 'text',
  98. 'default' => '#aaa',
  99. 'help_text' => __( 'The border color scheme of the plugin (hex or text value).', 'facebook' ),
  100. ),
  101. array('name' => 'font',
  102. 'type' => 'dropdown',
  103. 'default' => 'lucida grande',
  104. 'options' => array('arial' => 'arial', 'lucida grande' => 'lucida grande', 'segoe ui' => 'segoe ui', 'tahoma' => 'tahoma', 'trebuchet ms' => 'trebuchet ms', 'verdana' => 'verdana'),
  105. 'help_text' => __( 'The font of the plugin.', 'facebook' ),
  106. ),
  107. );
  108. if ($placement == 'widget') {
  109. $title_array = array('name' => 'title',
  110. 'type' => 'text',
  111. 'help_text' => 'The title above the button.',
  112. );
  113. $header_array = array('name' => 'header',
  114. 'type' => 'checkbox',
  115. 'default' => true,
  116. 'help_text' => 'Show the default Facebook title header.',
  117. );
  118. array_unshift($array['children'], $title_array, $header_array);
  119. }
  120. return $array;
  121. }
  122. ?>