/**
  * Returns an array properly formatted for use by the Nova_Palette control.
  *
  * @param 	$palettes_nr	int		the number of palettes we want to get
  * @return array
  */
 public static function get_palettes($palettes_nr = 5)
 {
     $palettes = self::parse();
     $palettes = array_slice($palettes, 0, $palettes_nr);
     $i = 0;
     foreach ($palettes as $palette) {
         $palettes[$i] = array();
         foreach ($palette as $key => $value) {
             $palettes[$i][$key] = Nova_Color::sanitize_hex($value);
         }
         $i++;
     }
     return $palettes;
 }
 /**
  * Build the background fields.
  * Takes a single field with type = background and explodes it to multiple controls.
  *
  * @param array
  * @return null|array
  */
 public static function explode($field)
 {
     $i18n = Nova_Toolkit::i18n();
     $choices = self::background_choices();
     // Early exit if this is not a background field.
     if ('background' != $field['type']) {
         return;
     }
     // Sanitize field
     $field = Nova_Field_Sanitize::sanitize_field($field);
     // No need to proceed any further if no defaults have been set.
     // We build the array of fields based on what default values have been defined.
     if (!isset($field['default']) || !is_array($field['default'])) {
         return;
     }
     $fields = array();
     $i = 0;
     foreach ($field['default'] as $key => $value) {
         // No need to process the opacity, it is factored in the color control.
         if ('opacity' == $key) {
             continue;
         }
         $key = esc_attr($key);
         $setting = $key;
         $help = $field['help'];
         $description = isset($i18n['background-' . $key]) ? $i18n['background-' . $key] : '';
         $output_property = 'background-' . $key;
         $label = 0 === $i ? $field['label'] : '';
         $type = 'select';
         $sanitize_callback = 'esc_attr';
         switch ($key) {
             case 'color':
                 /**
                  * Use 'color-alpha' instead of 'color' if default is an rgba value
                  * or if 'opacity' is set.
                  */
                 $type = false !== strpos($field['default']['color'], 'rgba') ? 'color-alpha' : 'color';
                 $type = isset($field['default']['opacity']) ? 'color-alpha' : $type;
                 if (isset($field['default']['opacity']) && false === strpos($value, 'rgb')) {
                     $value = Nova_Color::get_rgba($value, $field['default']['opacity']);
                 }
                 $sanitize_callback = array('Nova_Sanitize_Values', 'color');
                 break;
             case 'image':
                 $type = 'image';
                 $sanitize_callback = 'esc_url_raw';
                 break;
             case 'attach':
                 /**
                  * Small hack so that background attachments properly work.
                  */
                 $output_property = 'background-attachment';
                 $description = $i18n['background-attachment'];
                 break;
             default:
                 $help = '';
                 break;
         }
         /**
          * If we're using options & option_name is set, then we need to modify the setting.
          */
         if (isset($field['option_type']) && 'option' == $field['option_type'] && isset($field['option_name']) && !empty($field['option_name'])) {
             $property_setting = str_replace(']', '', str_replace($field['option_name'] . '[', '', $field['settings']));
             $property_setting = esc_attr($field['option_name']) . '[' . esc_attr($property_setting) . '_' . $setting . ']';
         } else {
             $property_setting = esc_attr($field['settings']) . '_' . $setting;
         }
         /**
          * Build the field.
          * We're merging with the original field here, so any extra properties are inherited.
          */
         $fields[$property_setting] = array_merge($field, array('type' => $type, 'label' => $label, 'settings' => $property_setting, 'help' => $help, 'section' => $field['section'], 'priority' => $field['priority'], 'required' => $field['required'], 'description' => $description, 'default' => $value, 'id' => Nova_Field_Sanitize::sanitize_id(array('settings' => Nova_Field_Sanitize::sanitize_settings(array('settings' => $field['settings'] . '_' . $setting)))), 'choices' => isset($choices[$key]) ? $choices[$key] : array(), 'output' => '' != $field['output'] ? array(array('element' => $field['output'], 'property' => $output_property)) : '', 'sanitize_callback' => isset($sanitize_callback) ? $sanitize_callback : Nova_Field_Sanitize::fallback_callback($type)));
         $i++;
     }
     return $fields;
 }
Beispiel #3
0
 function nova_get_brightness($hex)
 {
     return Nova_Color::get_brightness($hex);
 }
 public function get_colors()
 {
     $color = $this->get_admin_colors();
     $config = apply_filters('nova/config', array());
     // Calculate the accent color
     $this->color_accent = isset($color['icon_colors']) && isset($color['icon_colos']['focus']) ? $color['icon_colors']['focus'] : '#3498DB';
     if (isset($config['color_accent'])) {
         $this->color_accent = Nova_Color::sanitize_hex($config['color_accent']);
     }
     // Calculate the background & font colors
     $this->color_back = false;
     $this->color_font = false;
     if (isset($config['color_back'])) {
         $this->color_back = Nova_Color::sanitize_hex($config['color_back']);
         $this->color_font = 170 > Nova_Color::get_brightness($this->color_back) ? '#f2f2f2' : '#222';
     }
     $this->border_color = 170 > Nova_Color::get_brightness($this->color_back) ? 'rgba(255,255,255,.2)' : 'rgba(0,0,0,.2)';
     $this->buttons_color = 170 > Nova_Color::get_brightness($this->color_back) ? Nova_Color::adjust_brightness($this->color_back, 80) : Nova_Color::adjust_brightness($this->color_back, -80);
     $this->controls_color = 170 > Nova_Color::get_brightness($this->color_accent) ? '#ffffff;' : '#333333';
     $this->arrows_color = 170 > Nova_Color::get_brightness($this->color_back) ? Nova_Color::adjust_brightness($this->color_back, 120) : Nova_Color::adjust_brightness($this->color_back, -120);
     $this->color_accent_text = 170 > Nova_Color::get_brightness($this->color_accent) ? Nova_Color::adjust_brightness($this->color_accent, 120) : Nova_Color::adjust_brightness($this->color_accent, -120);
     $this->section_background_color = Nova_Color::mix_colors($this->color_back, '#ffffff', 10);
 }
 /**
  * Sanitize colors.
  * Determine if the current value is a hex or an rgba color and call the appropriate method.
  *
  * @since 0.8.5
  * @return string
  */
 public static function color($value)
 {
     // Is this an rgba color or a hex?
     $mode = false === strpos($value, 'rgba') ? 'rgba' : 'hex';
     if ('rgba' == $mode) {
         return Nova_Color::sanitize_hex($value);
     } else {
         return self::rgba($value);
     }
 }