Пример #1
0
 function hoot_sanitize_font_face($value, $recognized = array())
 {
     $recognized = is_array($recognized) && !empty($recognized) ? $recognized : hoot_enum_font_faces();
     $value = stripslashes($value);
     if (array_key_exists($value, $recognized)) {
         return $value;
     }
     return apply_filters('hoot_sanitize_default_font_face', current(array_keys($recognized)));
 }
Пример #2
0
 /**
  * Create general CSS style
  *
  * @since 1.0.0
  * @access public
  * @param string $property name of the css property
  * @param string $value value of the css property
  * @param string $idtag setting id used in wp admin (may be used in live preview js)
  *                      used for fetching background and typography settings
  * @param bool|string $important
  * @param bool $typography_reset Used for 'typography' property
  * @return mixed empty if sanitization failed, else the sanitized property array
  */
 function css_rule_sanitized_array($property, $value = '', $idtag = '', $important = false, $typography_reset = false)
 {
     if (empty($property)) {
         return '';
     }
     if ($property == 'background' || $property == 'font' || $property == 'typography') {
         if (empty($value) && empty($idtag)) {
             return '';
         }
     } else {
         if (empty($value)) {
             return '';
         }
     }
     /** Load Sanitization functions if not loaded already (for frontend) **/
     if (!function_exists('hoot_sanitize_enum')) {
         require_once trailingslashit(HOOT_INCLUDES) . 'sanitization.php';
     }
     /** Sanitize CSS values **/
     switch ($property) {
         case 'color':
         case 'background-color':
         case 'border-color':
         case 'border-right-color':
         case 'border-bottom-color':
         case 'border-top-color':
         case 'border-left-color':
             if ('none' == $value || 'transparent' == $value) {
                 $value = 'transparent';
             } else {
                 // sanitize color. hoot_sanitize_hex() will return null if $value is not a formatted hex color
                 $value = hoot_sanitize_hex($value);
             }
             break;
         case 'background':
             if (!empty($value)) {
                 if ('none' == $value || 'transparent' == $value) {
                     $value = 'none';
                 } else {
                     // sanitize for background color. hoot_sanitize_hex() will return null if $value is not a formatted hex color
                     $value = hoot_sanitize_hex($value);
                 }
             } elseif (!empty($idtag)) {
                 // use the background function for multiple background properties
                 return $this->background($idtag, $important);
             }
             break;
         case 'background-image':
             $value = 'url("' . esc_url($value) . '")';
             break;
         case 'background-repeat':
             $recognized = hoot_enum_background_repeat();
             $value = array_key_exists($value, $recognized) ? $value : '';
             break;
         case 'background-position':
             $recognized = hoot_enum_background_position();
             $value = array_key_exists($value, $recognized) ? $value : '';
             break;
         case 'background-attachment':
             $recognized = hoot_enum_background_attachment();
             $value = array_key_exists($value, $recognized) ? $value : '';
             break;
         case 'box-shadow':
         case '-moz-box-shadow':
         case '-webkit-box-shadow':
             $value = esc_attr($value);
         case 'typography':
         case 'font':
             if (!empty($value)) {
                 $property = 'font-family';
                 $recognized = hoot_enum_font_faces();
                 $value = stripslashes($value);
                 $value = array_key_exists($value, $recognized) ? $value : '';
             } elseif (!empty($idtag)) {
                 // use the typography function for multiple font properties
                 return $this->typography($idtag, $important, $typography_reset);
             }
             break;
         case 'font-family':
             // Recognized font-families in hoot/options/includes/fonts{-google}.php
             $recognized = hoot_enum_font_faces();
             $value = stripslashes($value);
             $value = array_key_exists($value, $recognized) ? $value : '';
             break;
         case 'font-style':
             $recognized = array('inherit', 'initial', 'italic', 'normal', 'oblique');
             $value = in_array($value, $recognized) ? $value : '';
             break;
         case 'font-weight':
             $value_check = intval($value);
             if (!empty($value_check)) {
                 // for numerical weights like 300, 600 etc.
                 $value = $value_check;
             } else {
                 // for strings like 'bold', 'light', 'lighter' etc.
                 $recognized = array('bold', 'bolder', 'inherit', 'initial', 'lighter', 'normal');
                 $value = in_array($value, $recognized) ? $value : '';
             }
             break;
         case 'text-decoration':
             $recognized = array('blink', 'inherit', 'initial', 'line-through', 'overline', 'underline');
             $value = in_array($value, $recognized) ? $value : '';
             break;
         case 'text-transform':
             $recognized = array('capitalize', 'inherit', 'initial', 'lowercase', 'none', 'uppercase');
             $value = in_array($value, $recognized) ? $value : '';
             break;
         case 'font-size':
         case 'padding':
         case 'padding-right':
         case 'padding-bottom':
         case 'padding-left':
         case 'padding-top':
         case 'margin':
         case 'margin-right':
         case 'margin-bottom':
         case 'margin-left':
         case 'margin-top':
         case 'height':
         case 'max-height':
         case 'min-height':
         case 'width':
         case 'max-width':
         case 'min-width':
             $value_check = preg_replace('/px|em|rem/', '', $value);
             $value_check = intval($value_check);
             $value = !empty($value_check) || '0' === $value_check || 0 === $value_check ? $value : '';
             break;
         case 'opacity':
             $value_check = intval($value);
             $value = !empty($value_check) || '0' === $value_check || 0 === $value_check ? $value : '';
             break;
     }
     // Allow custom sanitization by child themes
     $value = apply_filters('hoot_style_builder_css_rule_sanitized_array', $value, $property);
     /** Return **/
     if (empty($value)) {
         // if $value is empty => failed sanitization checks
         return '';
     } else {
         return array($property => array('value' => $value, 'important' => $important, 'idtag' => $idtag));
     }
 }