/**
  * Sanitize widget form values as they are saved.
  *
  * @see WP_Widget::update()
  *
  * @param array $new_instance Values just sent to be saved.
  * @param array $old_instance Previously saved values from database.
  *
  * @return array Updated safe values to be saved.
  */
 public function update($new_instance, $old_instance)
 {
     $instance = array();
     if (!empty($new_instance['title'])) {
         $instance['title'] = strip_tags($new_instance['title']);
     }
     if (!class_exists('Facebook_Like_Box')) {
         require_once dirname(dirname(__FILE__)) . '/class-facebook-like-box.php';
     }
     // include values when checkboxes not present
     $box = Facebook_Like_Box::fromArray(array_merge(array('show_faces' => false, 'stream' => false, 'header' => false, 'force_wall' => false), $new_instance));
     if ($box) {
         $box_options = $box->toHTMLDataArray();
         if (isset($box_options['href'])) {
             // sanitize if href has changed
             if (!isset($old_instance['href']) || $old_instance['href'] !== $box_options['href']) {
                 $box_options['href'] = self::sanitize_facebook_page_url($box_options['href']);
             }
         }
         // convert the booleans
         foreach (array('stream', 'header') as $bool_property) {
             if (isset($box_options[$bool_property])) {
                 if ($box_options[$bool_property] === 'false') {
                     $box_options[$bool_property] = false;
                 } else {
                     $box_options[$bool_property] = true;
                 }
             }
         }
         // dashes to underscores
         if (isset($box_options['border-color'])) {
             $box_options['border_color'] = $box_options['border-color'];
             unset($box_options['border-color']);
         }
         if (isset($box_options['max-age'])) {
             $box_options['max_age'] = absint($box_options['max-age']);
             unset($box_options['max-age']);
         }
         // bool with dash
         if (isset($box_options['force-wall'])) {
             if ($box_options['force-wall'] === 'true') {
                 $box_options['force_wall'] = true;
             } else {
                 $box_options['force_wall'] = false;
             }
             unset($box_options['force-wall']);
         }
         // bool with dash
         if (isset($box_options['show-faces'])) {
             if ($box_options['show-faces'] === 'false') {
                 $box_options['show_faces'] = false;
             } else {
                 $box_options['show_faces'] = true;
             }
             unset($box_options['show-faces']);
         }
         if (isset($box_options['width'])) {
             $box_options['width'] = absint($box_options['width']);
             if ($box_options['width'] > 0) {
                 // correct an invalid value to the closest allowed value
                 if ($box_options['width'] < Facebook_Like_Box::MIN_WIDTH) {
                     $box_options['width'] = Facebook_Like_Box::MIN_WIDTH;
                 }
             } else {
                 unset($box_options['width']);
             }
         }
         if (isset($box_options['height'])) {
             $box_options['height'] = absint($box_options['height']);
             // default is the same as minimum. remove invalid value
             if ($box_options['height'] < Facebook_Like_Box::MIN_HEIGHT) {
                 unset($box_options['height']);
             }
         }
         return array_merge($instance, $box_options);
     }
     return $instance;
 }
 /**
  * convert an options array into an object.
  *
  * @since 1.1.11
  *
  * @param array $values associative array
  * @return Facebook_Like_Box like box object
  */
 public static function fromArray($values)
 {
     if (!is_array($values) || empty($values)) {
         return;
     }
     $like_box = new Facebook_Like_Box();
     if (isset($values['href']) && is_string($values['href'])) {
         $like_box->setURL($values['href']);
     }
     if (isset($values['width'])) {
         $like_box->setWidth(absint($values['width']));
     }
     if (isset($values['height'])) {
         $like_box->setHeight(absint($values['height']));
     }
     if (isset($values['colorscheme'])) {
         $like_box->setColorscheme($values['colorscheme']);
     }
     if (isset($values['show_faces']) && ($values['show_faces'] === false || $values['show_faces'] === 'false' || $values['show_faces'] == 0)) {
         $like_box->hideFaces();
     } else {
         $like_box->showFaces();
     }
     if (isset($values['stream']) && ($values['stream'] === false || $values['stream'] === 'false' || $values['stream'] == 0)) {
         $like_box->hideStream();
     } else {
         $like_box->showStream();
         if (isset($values['force_wall']) && ($values['force_wall'] === true || $values['force_wall'] === 'true' || $values['force_wall'] == 1)) {
             $like_box->showWall();
         } else {
             $like_box->showCheckins();
         }
     }
     if (isset($values['header']) && ($values['header'] === false || $values['header'] === 'false' || $values['header'] == 0)) {
         $like_box->hideHeader();
     } else {
         $like_box->showHeader();
     }
     if (isset($values['show_border']) && ($values['show_border'] === false || $values['show_border'] === 'false' || $values['show_border'] == 0)) {
         $like_box->hideBorder();
     } else {
         $like_box->showBorder();
     }
     return $like_box;
 }
Example #3
0
 /**
  * Sanitize widget form values as they are saved.
  *
  * @see WP_Widget::update()
  *
  * @since 1.0
  *
  * @param array $new_instance Values just sent to be saved.
  * @param array $old_instance Previously saved values from database.
  *
  * @return array Updated safe values to be saved.
  */
 public function update($new_instance, $old_instance)
 {
     $instance = array();
     $new_instance = (array) $new_instance;
     if (!empty($new_instance['title'])) {
         $instance['title'] = strip_tags($new_instance['title']);
     }
     // set the booleans
     foreach (array('stream', 'header', 'show_border', 'force_wall', 'show_faces') as $bool_option) {
         if (isset($new_instance[$bool_option])) {
             $new_instance[$bool_option] = true;
         } else {
             $new_instance[$bool_option] = false;
         }
     }
     if (isset($new_instance['href'])) {
         // sanitize if href has changed
         if (!isset($old_instance['href']) || $old_instance['href'] !== $new_instance['href']) {
             $new_instance['href'] = self::sanitize_facebook_page_url($new_instance['href']);
         }
     }
     foreach (array('width', 'height') as $option) {
         if (isset($new_instance[$option])) {
             $new_instance[$option] = absint($new_instance[$option]);
         }
     }
     if (!class_exists('Facebook_Like_Box')) {
         require_once dirname(dirname(__FILE__)) . '/class-facebook-like-box.php';
     }
     // include values when checkboxes not present
     $box = Facebook_Like_Box::fromArray($new_instance);
     if ($box) {
         $box_options = $box->toHTMLDataArray();
         // convert dashes used to construct data-* attributes into underscore properties
         foreach (array('stream' => 'stream', 'header' => 'header', 'show-border' => 'show_border', 'force-wall' => 'force_wall', 'show-faces' => 'show_faces') as $data => $prop) {
             if (!isset($box_options[$data])) {
                 continue;
             }
             if ($box_options[$data] === 'true') {
                 $box_options[$data] = true;
             } else {
                 if ($box_options[$data] === 'false') {
                     $box_options[$data] = false;
                 }
             }
             if ($data !== $prop) {
                 $box_options[$prop] = $box_options[$data];
                 unset($box_options[$data]);
             }
         }
         // unsigned ints
         foreach (array('width', 'height') as $option) {
             if (isset($box_options[$option])) {
                 $box_options[$option] = absint($box_options[$option]);
             }
         }
         return array_merge($instance, $box_options);
     }
     return $instance;
 }