/**
  * Convert value from a property.
  *
  * @param  mixed $value
  * @param  Papi_Core_Conditional_Rule $rule
  *
  * @return mixed
  */
 private function convert_prop($value, Papi_Core_Conditional_Rule $rule)
 {
     $post_id = papi_get_post_id();
     $page_type = papi_get_page_type_by_post_id($post_id);
     if (!papi_is_empty($value) && $page_type instanceof Papi_Page_Type !== false) {
         $property = $page_type->get_property($rule->slug);
         if (papi_is_property($property)) {
             $prop_value = $property->format_value($value, $property->slug, $post_id);
             $prop_value = papi_filter_format_value($property->type, $prop_value, $property->slug, $post_id);
             $prop_value = $this->get_deep_value($rule->slug, $prop_value);
             if (gettype($prop_value) === gettype($rule->value)) {
                 return $prop_value;
             }
         }
         return $value;
     }
     return $value;
 }
 /**
  * Convert value from a property.
  *
  * @param  mixed $value
  * @param  Papi_Core_Conditional_Rule $rule
  *
  * @return mixed
  */
 protected function convert_prop($value, Papi_Core_Conditional_Rule $rule)
 {
     $meta_id = papi_get_meta_id();
     $meta_type = papi_get_meta_type();
     $entry_type = papi_get_entry_type_by_meta_id($meta_id, $meta_type);
     if (!papi_is_empty($value) && $entry_type instanceof Papi_Entry_Type !== false) {
         $property = $entry_type->get_property($rule->slug);
         if (papi_is_property($property)) {
             $prop_value = $property->format_value($value, $property->slug, $meta_id);
             $prop_value = papi_filter_format_value($property->type, $prop_value, $property->slug, $meta_id, $meta_type);
             $prop_value = $this->get_deep_value($rule->slug, $prop_value);
             if (gettype($prop_value) === gettype($rule->value)) {
                 return $prop_value;
             }
         }
         return $value;
     }
     return $value;
 }
 /**
  * Format the value of the property before it's returned
  * to WordPress admin or the site.
  *
  * @param  mixed  $values
  * @param  string $repeater_slug
  * @param  int    $post_id
  *
  * @return array
  */
 public function format_value($values, $repeater_slug, $post_id)
 {
     if (!is_array($values)) {
         return [];
     }
     foreach ($values as $index => $layout) {
         foreach ($layout as $slug => $value) {
             if (is_string($value) && preg_match($this->layout_value_regex, $value)) {
                 if (isset($values[$index][$this->layout_key])) {
                     unset($values[$index][$slug]);
                     continue;
                 }
                 $values[$index][$this->layout_key] = $value;
                 unset($values[$index][$slug]);
                 continue;
             }
             if (papi_is_property_type_key($slug)) {
                 continue;
             }
             $property_type_slug = papi_get_property_type_key_f($slug);
             if (!isset($values[$index][$property_type_slug])) {
                 continue;
             }
             $property_type_value = $values[$index][$property_type_slug];
             $property_type = papi_get_property_type($property_type_value);
             if (!is_object($property_type)) {
                 continue;
             }
             // Get property child slug.
             $child_slug = $this->get_child_slug($repeater_slug, $slug);
             // Create cache key.
             $cache_key = sprintf('%s_%d_%s', $repeater_slug, $index, $slug);
             // Get raw value from cache if enabled.
             if ($this->cache) {
                 $raw_value = papi_cache_get($cache_key, $post_id, $this->get_meta_type());
             } else {
                 $raw_value = false;
             }
             // Load the value.
             if ($raw_value === null || $raw_value === false) {
                 $values[$index][$slug] = $property_type->load_value($value, $child_slug, $post_id);
                 $values[$index][$slug] = papi_filter_load_value($property_type->type, $values[$index][$slug], $child_slug, $post_id, papi_get_meta_type());
                 if (!papi_is_empty($values[$index][$slug]) && $this->cache) {
                     papi_cache_set($cache_key, $post_id, $values[$index][$slug], $this->get_meta_type());
                 }
             } else {
                 $values[$index][$slug] = $raw_value;
             }
             if (strtolower($property_type->type) === 'repeater') {
                 $property_type->cache = false;
             }
             // Format the value from the property class.
             $values[$index][$slug] = $property_type->format_value($values[$index][$slug], $child_slug, $post_id);
             if (!is_admin()) {
                 $values[$index][$slug] = papi_filter_format_value($property_type->type, $values[$index][$slug], $child_slug, $post_id, papi_get_meta_type());
             }
             $values[$index][$property_type_slug] = $property_type_value;
         }
     }
     if (!is_admin()) {
         foreach ($values as $index => $row) {
             foreach ($row as $slug => $value) {
                 if (is_string($value) && preg_match($this->layout_value_regex, $value)) {
                     unset($values[$index][$slug]);
                     $values[$index]['_layout'] = preg_replace($this->layout_value_regex, '', $value);
                 }
                 if (papi_is_property_type_key($slug)) {
                     unset($values[$index][$slug]);
                 }
                 if (papi_is_empty($value)) {
                     unset($values[$index][$slug]);
                 }
             }
         }
     }
     return $values;
 }
 /**
  * Format the value of the property before it's returned
  * to WordPress admin or the site.
  *
  * @param  mixed  $values
  * @param  string $repeater_slug
  * @param  int    $post_id
  *
  * @return array
  */
 public function format_value($values, $repeater_slug, $post_id)
 {
     if (!is_array($values)) {
         return [];
     }
     $values = papi_to_property_array_slugs($values, $repeater_slug);
     foreach ($values as $slug => $value) {
         if (papi_is_property_type_key($slug)) {
             continue;
         }
         $property_type_slug = papi_get_property_type_key_f($slug);
         if (!isset($values[$property_type_slug])) {
             continue;
         }
         // Get property type
         $property_type_value = $values[$property_type_slug];
         $property_type = papi_get_property_type($property_type_value);
         if (!is_object($property_type)) {
             continue;
         }
         // Get property child slug.
         $child_slug = $this->get_child_slug($repeater_slug, $slug);
         // Get raw value from cache if enabled.
         if ($this->cache) {
             $raw_value = papi_cache_get($slug, $post_id, $this->get_meta_type());
         } else {
             $raw_value = false;
         }
         // Load the value.
         if ($raw_value === null || $raw_value === false) {
             $values[$slug] = $property_type->load_value($value, $child_slug, $post_id);
             $values[$slug] = papi_filter_load_value($property_type->type, $values[$slug], $child_slug, $post_id, papi_get_meta_type());
             if (!papi_is_empty($values[$slug]) && $this->cache) {
                 papi_cache_set($slug, $post_id, $values[$slug], $this->get_meta_type());
             }
         } else {
             $values[$slug] = $raw_value;
         }
         // Format the value from the property class.
         $values[$slug] = $property_type->format_value($values[$slug], $child_slug, $post_id);
         if (!is_admin()) {
             $values[$slug] = papi_filter_format_value($property_type->type, $values[$slug], $child_slug, $post_id, papi_get_meta_type());
         }
         $values[$property_type_slug] = $property_type_value;
     }
     if (!is_admin()) {
         foreach ($values as $slug => $value) {
             if (papi_is_property_type_key($slug)) {
                 unset($values[$slug]);
             }
         }
     }
     return papi_from_property_array_slugs($values, $repeater_slug);
 }
 /**
  * Format the value of the property before it's returned
  * to WordPress admin or the site.
  *
  * @param  mixed  $values
  * @param  string $repeater_slug
  * @param  int    $post_id
  *
  * @return array
  */
 public function format_value($values, $repeater_slug, $post_id)
 {
     if (!is_array($values)) {
         return [];
     }
     foreach ($values as $index => $layout) {
         foreach ($layout as $slug => $value) {
             if (is_string($value) && preg_match($this->layout_prefix_regex, $value)) {
                 if (isset($values[$index][$this->layout_key])) {
                     unset($values[$index][$slug]);
                     continue;
                 }
                 $values[$index][$this->layout_key] = $value;
                 unset($values[$index][$slug]);
                 continue;
             }
             if (papi_is_property_type_key($slug)) {
                 continue;
             }
             $property_type_slug = papi_get_property_type_key_f($slug);
             if (!isset($values[$index][$property_type_slug])) {
                 continue;
             }
             $property_type_value = $values[$index][$property_type_slug];
             $property_type = papi_get_property_type($property_type_value);
             if (!is_object($property_type)) {
                 continue;
             }
             // Get property child slug.
             $child_slug = $this->get_child_slug($repeater_slug, $slug);
             // Load the value.
             $values[$index][$slug] = $property_type->load_value($value, $child_slug, $post_id);
             $values[$index][$slug] = papi_filter_load_value($property_type->type, $values[$index][$slug], $child_slug, $post_id);
             // Format the value from the property class.
             $values[$index][$slug] = $property_type->format_value($values[$index][$slug], $child_slug, $post_id);
             if (!is_admin()) {
                 $values[$index][$slug] = papi_filter_format_value($property_type->type, $values[$index][$slug], $child_slug, $post_id);
             }
             $values[$index][$property_type_slug] = $property_type_value;
         }
     }
     if (!is_admin()) {
         foreach ($values as $index => $row) {
             foreach ($row as $slug => $value) {
                 if (is_string($value) && preg_match($this->layout_prefix_regex, $value)) {
                     $values[$index][$slug] = preg_replace($this->layout_prefix_regex, '', $value);
                 }
                 if (papi_is_property_type_key($slug)) {
                     unset($values[$index][$slug]);
                 }
             }
         }
     }
     return $values;
 }
 /**
  * Convert property value with the property type converter.
  *
  * @param  string $slug
  * @param  mixed  $value
  *
  * @return mixed
  */
 protected function convert($slug, $value)
 {
     $property = $this->get_property($slug);
     // If no property type is found, just return null.
     if (!papi_is_property($property)) {
         return;
     }
     if (papi_is_empty($value)) {
         if (!papi_is_empty($property->get_option('value'))) {
             return $property->get_option('value');
         }
         return;
     }
     // A property need to know about the page.
     $property->set_page($this);
     // Run load value method right after the value has been loaded from the database.
     $value = $property->load_value($value, $slug, $this->id);
     $value = papi_filter_load_value($property->type, $value, $slug, $this->id);
     // Format the value from the property class.
     $value = $property->format_value($value, $slug, $this->id);
     // Only fired when not in admin.
     if (!is_admin()) {
         $value = papi_filter_format_value($property->type, $value, $slug, $this->id);
     }
     if (is_array($value)) {
         $value = array_filter($value);
     }
     return $value;
 }
 /**
  * Format the value of the property before it's returned
  * to WordPress admin or the site.
  *
  * @param  mixed  $values
  * @param  string $repeater_slug
  * @param  int    $post_id
  *
  * @return array
  */
 public function format_value($values, $repeater_slug, $post_id)
 {
     if (!is_array($values)) {
         return [];
     }
     $values = papi_to_property_array_slugs($values, $repeater_slug);
     foreach ($values as $slug => $value) {
         if (papi_is_property_type_key($slug)) {
             continue;
         }
         $property_type_slug = papi_get_property_type_key_f($slug);
         if (!isset($values[$property_type_slug])) {
             continue;
         }
         // Get property type
         $property_type_value = $values[$property_type_slug];
         $property_type = papi_get_property_type($property_type_value);
         if (!is_object($property_type)) {
             continue;
         }
         // Get property child slug.
         $child_slug = $this->get_child_slug($repeater_slug, $slug);
         // Load the value.
         $values[$slug] = $property_type->load_value($value, $child_slug, $post_id);
         $values[$slug] = papi_filter_load_value($property_type->type, $values[$slug], $child_slug, $post_id);
         // Format the value from the property class.
         $values[$slug] = $property_type->format_value($values[$slug], $child_slug, $post_id);
         if (!is_admin()) {
             $values[$slug] = papi_filter_format_value($property_type->type, $values[$slug], $child_slug, $post_id);
         }
         $values[$property_type_slug] = $property_type_value;
     }
     if (!is_admin()) {
         foreach ($values as $slug => $value) {
             if (papi_is_property_type_key($slug)) {
                 unset($values[$slug]);
             }
         }
     }
     return papi_from_property_array_slugs($values, $repeater_slug);
 }
 /**
  * Format property value from the property.
  *
  * @param  string $slug
  * @param  mixed  $value
  *
  * @return mixed
  */
 public function format_value($slug, $value)
 {
     $slug = unpapify($slug);
     $property = $this->property($slug);
     // If no property type is found, just return null.
     if (!papi_is_property($property)) {
         return;
     }
     // Format the value from the property class.
     $value = $property->format_value($value, $slug, $this->id);
     // Only fired when not in admin.
     if (!is_admin()) {
         $value = papi_filter_format_value($property->type, $value, $slug, $this->id, papi_get_meta_type());
     }
     if (is_array($value)) {
         $value = array_filter($value);
     }
     return $value;
 }
 /**
  * Format property value from the property.
  *
  * @param  string $slug
  * @param  mixed  $value
  *
  * @return mixed
  */
 public function format_value($slug, $value)
 {
     $slug = strtolower(unpapify($slug));
     $property = $this->property($slug);
     // If no property type is found, just return null.
     if (!papi_is_property($property)) {
         return;
     }
     // Format the value from the property class.
     $value = $property->format_value($value, $slug, $this->id);
     // Only fired when not in admin.
     if (!is_admin()) {
         $value = papi_filter_format_value($property->type, $value, $slug, $this->id, papi_get_meta_type());
     }
     // Remove empty values from arrays.
     if (is_array($value)) {
         foreach ($value as $index => $val) {
             if (papi_is_empty($val)) {
                 unset($value[$index]);
             }
         }
     }
     return $value;
 }