Exemplo n.º 1
1
 /**
  * Determines if field is created with Types.
  *
  * @param type $field_key
  */
 function is_under_control($field_key)
 {
     /*
      *
      * We force checking our meta prefix
      */
     $key = $this->__get_slug_no_prefix($field_key);
     return WPCF_Fields::isUnderControl($key);
 }
Exemplo n.º 2
0
/**
 * Get fields.
 * 
 * @global type $wpcf
 * @param mixed $args Various args
 * @param string $toolset Useful in hooks
 * @return All filtered fields
 */
function types_get_fields($args = array(), $toolset = 'types')
{
    static $cache = array();
    $cache_key = md5(serialize(func_get_args()));
    if (isset($cache[$cache_key])) {
        return $cache[$cache_key];
    }
    $fields = WPCF_Fields::getFields($args, $toolset);
    $cache[$cache_key] = $fields;
    return $cache[$cache_key];
}
Exemplo n.º 3
0
 /**
  * Returns array of available (registered) field types
  * and their config data.
  * 
  * @return type
  */
 public static function getFieldsTypesData()
 {
     if (!is_null(self::$fieldTypesData)) {
         return self::$fieldTypesData;
     }
     self::$fieldTypesData = self::getFieldsTypes();
     foreach (self::$fieldTypesData as $type => $path) {
         $data = self::getFieldTypeConfig($path);
         if (!empty($data)) {
             self::$fieldTypesData[$type] = $data;
         } else {
             unset(self::$fieldTypesData[$type]);
         }
         if (isset($data['wp_version']) && wpcf_compare_wp_version($data['wp_version'], '<')) {
             unset(self::$fieldTypesData[$type]);
         }
     }
     return self::$fieldTypesData;
 }
 /**
  * Load a field type definition.
  *
  * @param string $field_type_slug Slug of the field type. If the function fails to find the field type and the slug
  * starts with a "wpcf-" prefix, it attempts to remove it and search again. This way, passing a field type ID,
  * which usually has this form, is also supported.
  * @return null|WPCF_Field_Type_Definition Field type definition or null if it can't be loaded.
  */
 public function load_field_type_definition($field_type_slug)
 {
     if (!is_string($field_type_slug)) {
         return null;
     }
     // Check if we can use cached version.
     if (!in_array($field_type_slug, $this->field_type_definitions)) {
         // now it gets hacky
         $field_types = $this->get_legacy_field_types();
         if (!in_array($field_type_slug, array_keys($field_types))) {
             // Field slug not recognized. Maybe we got a field identifier instead. Check if we can remove
             // the wpcf- prefix and try again.
             $prefix = 'wpcf-';
             if (substr($field_type_slug, 0, strlen($prefix)) == $prefix) {
                 $field_type_slug = substr($field_type_slug, strlen($prefix));
                 if (!in_array($field_type_slug, $field_types)) {
                     // Removing prefix didn't help
                     return null;
                 }
             } else {
                 // There was no prefix to remove.
                 return null;
             }
         }
         // Not using getFieldTypeData() directly to avoid unnecessary getFieldsTypes() and filter applying.
         $field_type_configuration_path = $field_types[$field_type_slug];
         $field_type_configuration = WPCF_Fields::getFieldTypeConfig($field_type_configuration_path);
         $field_type_id = wpcf_getarr($field_type_configuration, 'id', null);
         if (null == $field_type_id) {
             return null;
         }
         try {
             $field_type_definition = new WPCF_Field_Type_Definition($field_type_slug, $field_type_configuration);
         } catch (Exception $e) {
             return null;
         }
         // Save new instance to cache.
         $this->field_type_definitions[$field_type_slug] = $field_type_definition;
     }
     // Use cache.
     return $this->field_type_definitions[$field_type_slug];
 }
Exemplo n.º 5
0
 /**
  * Adds items to view dropdown.
  * 
  * @param type $items
  * @return type 
  */
 public static function editorDropdownFilter($items)
 {
     $post = wpcf_admin_get_edited_post();
     if (empty($post)) {
         $post = (object) array('ID' => -1);
     }
     $groups = wpcf_admin_fields_get_groups('wp-types-group', 'group_active');
     $all_post_types = implode(' ', get_post_types(array('public' => true)));
     $add = array();
     if (!empty($groups)) {
         // $group_id is blank therefore not equal to $group['id']
         // use array for item key and CSS class
         $item_styles = array();
         foreach ($groups as $group) {
             $fields = wpcf_admin_fields_get_fields_by_group($group['id'], 'slug', true, false, true);
             if (!empty($fields)) {
                 // code from Types used here without breaking the flow
                 // get post types list for every group or apply all
                 $post_types = get_post_meta($group['id'], '_wp_types_group_post_types', true);
                 if ($post_types == 'all') {
                     $post_types = $all_post_types;
                 }
                 $post_types = trim(str_replace(',', ' ', $post_types));
                 $item_styles[$group['name']] = $post_types;
                 foreach ($fields as $field) {
                     $callback = 'wpcfFieldsEditorCallback(\'' . $field['id'] . '\', \'postmeta\', ' . $post->ID . ')';
                     $add[$group['name']][stripslashes($field['name'])] = array(stripslashes($field['name']), trim(wpcf_fields_get_shortcode($field), '[]'), $group['name'], $callback);
                     // TODO Remove - it's not post edit screen (meta box JS and CSS)
                     WPCF_Fields::enqueueScript($field['type']);
                     WPCF_Fields::enqueueStyle($field['type']);
                 }
             }
         }
     }
     $search_key = '';
     // Iterate all items to be displayed in the "V" menu
     foreach ($items as $key => $item) {
         if ($key == __('Basic', 'wpv-views')) {
             $search_key = 'found';
             continue;
         }
         if ($search_key == 'found') {
             $search_key = $key;
         }
         if ($key == __('Field', 'wpv-views') && isset($item[trim(wpcf_types_get_meta_prefix(), '-')])) {
             unset($items[$key][trim(wpcf_types_get_meta_prefix(), '-')]);
         }
     }
     if (empty($search_key) || $search_key == 'found') {
         $search_key = count($items);
     }
     $insert_position = array_search($search_key, array_keys($items));
     $part_one = array_slice($items, 0, $insert_position);
     $part_two = array_slice($items, $insert_position);
     $items = $part_one + $add + $part_two;
     // apply CSS styles to each item based on post types
     foreach ($items as $key => $value) {
         if (isset($item_styles[$key])) {
             $items[$key]['css'] = $item_styles[$key];
         } else {
             $items[$key]['css'] = $all_post_types;
         }
     }
     return $items;
 }
Exemplo n.º 6
0
/**
 * Gets all available types and their config data.
 */
function wpcf_admin_fields_get_available_types()
{
    return WPCF_Fields::getFieldsTypesData();
}
Exemplo n.º 7
0
 /**
  * Adds items to view dropdown.
  * 
  * @param type $items
  * @return type 
  */
 public static function editorDropdownFilter($menu)
 {
     $post = wpcf_admin_get_edited_post();
     if (empty($post)) {
         $post = (object) array('ID' => -1);
     }
     $groups = wpcf_admin_fields_get_groups('wp-types-group', 'group_active');
     $all_post_types = implode(' ', get_post_types(array('public' => true)));
     $add = array();
     if (!empty($groups)) {
         // $group_id is blank therefore not equal to $group['id']
         // use array for item key and CSS class
         $item_styles = array();
         foreach ($groups as $group) {
             $fields = wpcf_admin_fields_get_fields_by_group($group['id'], 'slug', true, false, true);
             if (!empty($fields)) {
                 // code from Types used here without breaking the flow
                 // get post types list for every group or apply all
                 $post_types = get_post_meta($group['id'], '_wp_types_group_post_types', true);
                 if ($post_types == 'all') {
                     $post_types = $all_post_types;
                 }
                 $post_types = trim(str_replace(',', ' ', $post_types));
                 $item_styles[$group['name']] = $post_types;
                 foreach ($fields as $field) {
                     $callback = 'wpcfFieldsEditorCallback(\'' . $field['id'] . '\', \'postmeta\', ' . $post->ID . ')';
                     $menu[$group['name']][stripslashes($field['name'])] = array(stripslashes($field['name']), trim(wpcf_fields_get_shortcode($field), '[]'), $group['name'], $callback);
                     // TODO Remove - it's not post edit screen (meta box JS and CSS)
                     WPCF_Fields::enqueueScript($field['type']);
                     WPCF_Fields::enqueueStyle($field['type']);
                 }
             }
         }
     }
     return $menu;
 }
Exemplo n.º 8
0
 /**
  * Collect all fields and conditions.
  */
 function collect()
 {
     if (is_null($this->triggers)) {
         $this->collected = array();
         $this->triggers = array();
         $fields = WPCF_Fields::getFields();
         if (is_array($fields) && !empty($fields)) {
             foreach ($fields as $f_id => $f) {
                 if (!empty($f['data']['conditional_display']['conditions'])) {
                     foreach ($f['data']['conditional_display']['conditions'] as $condition) {
                         $this->collected[$f_id] = $condition;
                         if (!empty($condition['field'])) {
                             $this->triggers[$condition['field']][$f_id][] = $condition;
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 9
-1
 /**
  * Renders Thickbox content.
  *
  * Field should provide callback function
  * that will be called automatically.
  *
  * Function should be named like:
  * 'wpcf_fields_' . $field_type . '_editor_callback'
  * e.g. 'wpcf_fields_checkbox__editor_callback'
  *
  * Function should return array with elements:
  * 'supports' - parameters or other feature supported, e.g. 'styling' will
  *     enable 'Styling' options
  *
  * Tabs is array with elements:
  * 'menu_title' - used for menu title
  * 'title' - used for main title
  * 'content' - HTML content of tab
  *
  * @param type $field
  * @param type $meta_type
  * @param type $post_id
  * @param string $shortcode
  */
 function frame($field, $meta_type = 'postmeta', $post_id = -1, $shortcode = null, $callback = false, $views_usermeta = false)
 {
     global $wp_version, $wpcf;
     // Queue rendering JS settings
     add_action('admin_print_footer_scripts', array($this, 'renderTedSettings'), 1);
     wp_enqueue_script('types');
     wp_enqueue_script('types-knockout');
     wp_enqueue_script('types-editor');
     wp_enqueue_script('wp-pointer');
     wp_enqueue_style('types-editor');
     wp_enqueue_style('wp-pointer');
     wp_enqueue_style('toolset-font-awesome');
     // Load cloned WP Media Modal CSS
     if (version_compare($wp_version, '3.5', '<')) {
         wp_enqueue_style('types-editor-cloned');
     }
     $this->field = $field;
     $this->_meta_type = $meta_type;
     $this->_post = get_post($post_id);
     $this->_settings = is_null($shortcode) ? array() : $this->shortcodeToParameters($shortcode);
     $this->callback = $callback;
     $this->_data = array('meta_type' => $meta_type, 'field' => $field, 'field_type_data' => WPCF_Fields::getFieldTypeData($field['type']), 'settings' => array(), 'tabs' => array(), 'supports' => array(), 'post' => $this->_post, 'post_types' => get_post_types(array('show_ui' => true)), 'style' => isset($this->_settings['style']) ? $this->_settings['style'] : '', 'class' => isset($this->_settings['class']) ? $this->_settings['class'] : '', 'output' => 'html', 'user_form' => '');
     // Set title if updated
     if (!is_null($shortcode)) {
         $this->_data['title'] = sprintf(__('Update %s', 'wpcf'), $this->_data['field_type_data']['title']);
         $this->_data['submit_button_title'] = __('Update shortcode', 'wpcf');
     }
     // Exclude post types
     foreach ($wpcf->excluded_post_types as $_post_type) {
         unset($this->_data['post_types'][$_post_type]);
     }
     /*
      * Callback
      */
     $function = 'wpcf_fields_' . $field['type'] . '_editor_callback';
     if (function_exists($function)) {
         // Main callback
         $callback = call_user_func($function, $field, $this->_settings, $this->_meta_type, $this->_post);
         // Add supports
         if (!empty($callback['supports']) && is_array($callback['supports'])) {
             $this->_data['supports'] = $callback['supports'];
         }
         // Add tabs
         if (!empty($callback['tabs']) && is_array($callback['tabs'])) {
             $this->_data['tabs'] = $callback['tabs'];
         }
         // Unify settings
         if (!empty($callback['settings']) && is_array($callback['settings'])) {
             $this->_settings = array_merge($this->_settings, self::sanitizeParams($callback['settings'], 'array'));
         }
     }
     // If no tabs
     if (empty($this->_data['tabs'])) {
         $this->_data['tabs']['display'] = array('menu_title' => __('Display', 'wpcf'), 'title' => __('Display', 'wpcf'), 'content' => sprintf(__('There are no additional display options for the %s field.', 'wpcf'), $this->_data['field_type_data']['title']));
     }
     // Add User ID form
     if ($this->_meta_type == 'usermeta') {
         if (!$views_usermeta) {
             $this->_data['user_form'] = wpcf_form_simple(wpcf_get_usermeta_form_addon($this->_settings));
             $this->_data['supports'][] = 'user_id';
         }
     } else {
         // Add Post ID form
         $this->_data['supports'][] = 'post_id';
     }
     // Get parents
     if (!empty($this->_post->ID)) {
         $this->_data['parents'] = WPCF_Relationship::get_parents($this->_post);
     }
     // Set icons
     $icons = array('audio' => 'icon-music', 'checkbox' => 'icon-check', 'checkboxes' => 'icon-checkboxes', 'colorpicker' => 'icon-tint', 'date' => 'icon-calendar', 'email' => 'icon-envelope-alt', 'embed' => 'icon-youtube-play', 'file' => 'icon-file-alt', 'image' => 'icon-picture', 'map' => 'icon-map-marker', 'numeric' => 'icon-numeric', 'phone' => 'icon-phone', 'radio' => 'icon-radio-button', 'select' => 'icon-select-box', 'skype' => 'icon-skype', 'textarea' => 'icon-text-area', 'textfield' => 'icon-text-field', 'url' => 'icon-link', 'video' => 'icon-film', 'wysiwyg' => 'icon-wysiwyg');
     $this->_data['icon_class'] = isset($icons[$field['type']]) ? $icons[$field['type']] : 'icon-text-field';
     // Is repetitive
     $this->_data['is_repetitive'] = (bool) types_is_repetitive($field);
     if ($this->_data['is_repetitive']) {
         $this->_data['supports'][] = 'separator';
     }
     // Render header
     wpcf_admin_ajax_head();
     // Check if submitted
     $this->_thickbox_check_submit();
     // Render form
     echo '<form method="post" action="" id="types-editor-modal-form">';
     echo WPCF_Loader::view('editor-modal-window', $this->_data);
     wp_nonce_field('types_editor_frame', '__types_editor_nonce');
     echo '</form>';
     // Render footer
     wpcf_admin_ajax_footer();
 }