/**
  * Update value.
  *
  * @param  Papi_Core_Property $property
  * @param  mixed  $value
  * @param  string $slug
  * @param  int    $post_id
  *
  * @return array
  */
 protected function update_value($property, $value, $slug, $post_id)
 {
     if (!is_array($value) || !$this->should_update_array($slug)) {
         return $property->import_value($value, $slug, $post_id);
     }
     $old = papi_get_field($post_id, $slug, []);
     $value = array_merge($old, $value);
     $value = $property->import_value($value, $slug, $post_id);
     if ($property->import_setting('property_array_slugs')) {
         return papi_from_property_array_slugs($value, $slug);
     }
     return $property->update_value($value, $slug, $post_id);
 }
 /**
  * Get rule slug.
  *
  * @param  Papi_Core_Conditional_Rule $rule
  * @param  Papi_Core_Property $property
  *
  * @return string
  */
 protected function get_rule_slug($rule, $property)
 {
     $arr_reg = '/\\[\\d+\\](\\[\\w+\\])$/';
     $slug = $property->get_slug();
     $page_type = papi_get_entry_type_by_meta_id();
     if ($page_type instanceof Papi_Page_Type === false) {
         return $rule->slug;
     }
     if (preg_match($arr_reg, $slug, $out)) {
         $slug = str_replace($out[1], '[' . unpapify($rule->slug) . ']', $slug);
         $property = $page_type->get_property($slug);
         if (papi_is_property($property)) {
             return $slug;
         }
     }
     return $rule->slug;
 }
 /**
  * Get rule slug.
  *
  * @param  Papi_Core_Conditional_Rule $rule
  * @param  Papi_Core_Property $property
  *
  * @return string
  */
 private function get_rule_slug($rule, $property)
 {
     $arrReg = '/\\[\\d+\\](\\[\\w+\\])$/';
     $slug = $property->get_slug();
     $page_type = papi_get_page_type_by_post_id();
     if ($page_type instanceof Papi_Page_Type === false) {
         return $rule->slug;
     }
     if (preg_match($arrReg, $slug, $out)) {
         $slug = str_replace($out[1], '[' . papi_remove_papi($rule->slug) . ']', $slug);
         $property = $page_type->get_property($slug);
         if (papi_is_property($property)) {
             return $slug;
         }
     }
     return $rule->slug;
 }
Esempio n. 4
0
 /**
  * Prepare load value.
  *
  * @param  Papi_Core_Property $property
  * @param  mixed              $value
  *
  * @return mixed
  */
 protected function prepare_load_value(Papi_Core_Property $property, $value)
 {
     if ($property->overwrite) {
         // Clear post cache to solve issue with cached post objects
         // when selecting post field.
         clean_post_cache($this->id);
         $slug = $property->get_slug(true);
         $context = is_admin() ? 'edit' : 'display';
         $value = get_post_field($slug, $this->id, $context);
     }
     return $value;
 }
Esempio n. 5
0
 /**
  * Get property html via GET.
  *
  * GET /papi-ajax/?action=get_property
  */
 public function get_property()
 {
     $default_options = Papi_Core_Property::create()->get_options();
     $keys = array_keys(get_object_vars($default_options));
     $options = papi_get_qs($keys, true);
     if ($property = papi_property($options)) {
         ob_start();
         $property->render_ajax_request();
         $html = ob_get_clean();
         wp_send_json(['html' => utf8_encode($html)]);
     } else {
         $this->render_error('No property found');
     }
 }
Esempio n. 6
0
/**
 * Render the given property.
 *
 * @param mixed $property
 */
function papi_render_property($property)
{
    $property = Papi_Core_Property::factory($property);
    if (!papi_is_property($property)) {
        return;
    }
    $property->render();
}
 /**
  * Load child properties.
  *
  * @param  array              $results
  * @param  Papi_Core_Property $property
  *
  * @return array
  */
 protected function load_child_properties(array $results, $property = null)
 {
     foreach ($results as $index => $row) {
         foreach ($row as $slug => $value) {
             if (is_array($value) && isset($value[$slug])) {
                 $child_property = $this->get_store()->get_property($this->get_slug(true), $slug);
                 if (papi_is_property($child_property) && !empty($child_property->get_child_properties())) {
                     $value = papi_from_property_array_slugs($value, unpapify($slug));
                     $results[$index][$slug] = $this->load_child_properties($value, $child_property);
                 }
             }
             $type_key = papi_get_property_type_key_f($slug);
             if ($property->match_slug($slug)) {
                 $results[$index][$type_key] = $property;
             } else {
                 $results[$index][$type_key] = $property->get_child_property($slug);
             }
         }
     }
     return $results;
 }
 /**
  * Prepare property before returning it.
  *
  * @param  Papi_Core_Property $property
  *
  * @return Papi_Core_Property
  */
 protected function prepare_property(Papi_Core_Property $property)
 {
     $property->set_store($this);
     return $property;
 }