Exemple #1
0
 /**
  * Setup arguments.
  *
  * @param  array $args
  */
 protected function setup_args(array $args)
 {
     foreach ($args as $key => $value) {
         if (isset($this->{$key})) {
             $this->{$key} = papi_esc_html($value);
         }
     }
     if (empty($this->id)) {
         $this->id = strtolower(papi_f(papi_underscorify(papify($this->title))));
     }
 }
Exemple #2
0
/**
 * Get Papi cache key.
 *
 * @param  string $key
 * @param  mixed  $suffix
 *
 * @return string
 */
function papi_cache_key($key, $suffix)
{
    if (!is_string($key)) {
        return '';
    }
    $key = papify($key);
    $suffix = papi_convert_to_string($suffix);
    $suffix = papi_html_name($suffix);
    $suffix = papi_remove_papi($suffix);
    return sprintf('%s_%s', $key, $suffix);
}
 /**
  * Setup arguments.
  *
  * @param  array $args
  */
 private function setup_args(array $args)
 {
     $excluded_keys = ['properties'];
     foreach ($args as $key => $value) {
         if (isset($this->{$key}) && !in_array($key, $excluded_keys)) {
             $this->{$key} = papi_esc_html($value);
         }
     }
     if (empty($this->id)) {
         $this->id = strtolower(papi_f(papi_underscorify(papify($this->title))));
     }
 }
Exemple #4
0
/**
 * Get Papi cache key.
 *
 * @param  string $key
 * @param  mixed  $suffix
 * @param  string $type
 *
 * @return string
 */
function papi_cache_key($key, $suffix, $type = 'post')
{
    if (!is_string($key)) {
        return '';
    }
    $type = empty($type) ? 'post' : $type;
    $type = $type === 'page' ? 'post' : $type;
    $key = unpapify($key);
    $key = papify($type . '_' . $key);
    $suffix = papi_convert_to_string($suffix);
    $suffix = papi_html_name($suffix);
    $suffix = unpapify($suffix);
    return sprintf('%s_%s', $key, $suffix);
}
 /**
  * Output hidden input field that cointains which property is used.
  */
 protected function render_hidden_html()
 {
     $slug = $this->get_option('slug');
     if (substr($slug, -1) === ']') {
         $slug = substr($slug, 0, -1);
         $slug = papi_get_property_type_key($slug);
         $slug .= ']';
     } else {
         $slug = papi_get_property_type_key($slug);
     }
     $slug = papify($slug);
     $options = $this->get_options();
     $property_json = base64_encode(papi_maybe_json_encode($options));
     papi_render_html_tag('input', ['data-property' => strtolower($this->get_option('type')), 'name' => $slug, 'type' => 'hidden', 'value' => $property_json]);
 }
 /**
  * Get meta box id.
  *
  * @param string $slug
  *
  * @return string
  */
 private function get_meta_box_id($slug)
 {
     return papi_f(papi_underscorify(papify($slug)));
 }
Exemple #7
0
/**
 * Get a php friendly name.
 *
 * @param  string $name
 *
 * @return string
 */
function papi_html_name($name)
{
    if (!is_string($name)) {
        return '';
    }
    if (!preg_match('/^\\_\\_papi|^\\_papi/', $name)) {
        $name = papify($name);
        if (!preg_match('/\\[.*\\]/', $name)) {
            $name = papi_slugify($name);
        }
        return papi_underscorify($name);
    }
    return $name;
}
 /**
  * Prepare properties data for saving.
  *
  * @param  array $data
  * @param  int   $post_id
  *
  * @return array
  */
 protected function prepare_properties_data(array $data = [], $post_id = 0)
 {
     // Since we are storing witch property it is in the `$data` array
     // we need to remove that and set the property type to the property
     // and make a array of the property type and the value.
     foreach ($data as $key => $value) {
         if (papi_is_property_type_key($key)) {
             continue;
         }
         $property_type_key = papify(papi_get_property_type_key($key));
         // Check if value exists.
         if (!isset($data[$key]) && !isset($data[$property_type_key])) {
             continue;
         }
         // Pair property value with property type object.
         $data[$key] = ['type' => $data[$property_type_key], 'value' => $value];
         // Remove property type object since it's not needed anymore.
         unset($data[$property_type_key]);
     }
     foreach ($data as $key => $item) {
         if (papi_is_property_type_key($key)) {
             continue;
         }
         $property = papi_get_property_type($item['type']);
         unset($data[$key]);
         if (papi_is_property($property)) {
             // Run `update_value` method on the property class.
             $data[$key] = $property->update_value($item['value'], unpapify($key), $post_id);
             // Apply `update_value` filter so this can be changed from
             // the theme for specified property type.
             $data[$key] = papi_filter_update_value($item['type']->type, $data[$key], unpapify($key), $post_id, papi_get_meta_type());
             if ($item['type']->overwrite) {
                 $slug = unpapify($key);
                 $this->overwrite[$slug] = $data[$key];
                 unset($data[$key]);
             }
         }
     }
     return $data;
 }
 /**
  * Setup the rule and assign properties with values.
  *
  * @param array  $rule
  */
 protected function setup(array $rule)
 {
     foreach ($rule as $key => $value) {
         if ($key === 'operator') {
             $value = strtoupper($value);
             $value = html_entity_decode($value);
         } else {
             if ($key === 'slug') {
                 $value = papify($value);
             } else {
                 if ($key === 'source') {
                     $value = $this->setup_source($value);
                 }
             }
         }
         $this->{$key} = $value;
     }
 }