field_method() public static method

Run a method from a Field Type's class
Since: 2.0
public static field_method ( ) : mixed
return mixed
コード例 #1
0
ファイル: general.php プロジェクト: Ingenex/redesign
/**
 * Register a related object
 *
 * @param string $name Object name
 * @param string $label Object label
 * @param array $options Object options
 *
 * @return array|boolean Object array or false if unsuccessful
 * @since 2.3
 */
function pods_register_related_object($name, $label, $options = null)
{
    return PodsForm::field_method('pick', 'register_related_object', $name, $label, $options);
}
コード例 #2
0
ファイル: PodsAPI.php プロジェクト: satokora/IT354Project
 /**
  * Gets the schema definition of a field.
  *
  * @param string $type Field type to look for
  * @param array $options (optional) Options of the field to pass to the schema function.
  *
  * @return array|bool|mixed|null
  *
  * @since 2.0
  */
 private function get_field_definition($type, $options = null)
 {
     $definition = PodsForm::field_method($type, 'schema', $options);
     return $this->do_hook('field_definition', $definition, $type, $options);
 }
コード例 #3
0
        if (!isset($field_types_select[PodsForm::$field_group])) {
            $field_types_select[PodsForm::$field_group] = array();
        }
        $field_types_select[PodsForm::$field_group][$type] = $field_type_data['label'];
    } else {
        if (!isset($field_types_select[__('Other', 'pods')])) {
            $field_types_select[__('Other', 'pods')] = array();
        }
        $field_types_select[__('Other', 'pods')][$type] = $field_type_data['label'];
    }
}
$field_defaults = array('name' => 'new_field', 'label' => 'New Field', 'description' => '', 'type' => 'text', 'pick_object' => '', 'sister_id' => '', 'required' => 0, 'unique' => 0);
$pick_object = PodsForm::field_method('pick', 'related_objects', true);
$tableless_field_types = PodsForm::tableless_field_types();
$simple_tableless_objects = PodsForm::field_method('pick', 'simple_objects');
$bidirectional_objects = PodsForm::field_method('pick', 'bidirectional_objects');
foreach ($pod['options'] as $_option => $_value) {
    $pod[$_option] = $_value;
}
foreach ($pod['fields'] as $_field => $_data) {
    $_data['options'] = (array) $_data['options'];
    foreach ($_data['options'] as $_option => $_value) {
        $pod['fields'][$_field][$_option] = $_value;
    }
}
$field_defaults = apply_filters('pods_field_defaults', apply_filters('pods_field_defaults_' . $pod['name'], $field_defaults, $pod));
$pick_table = pods_transient_get('pods_tables');
if (empty($pick_table)) {
    $pick_table = array('' => __('-- Select Table --', 'pods'));
    global $wpdb;
    $tables = $wpdb->get_results("SHOW TABLES", ARRAY_N);
コード例 #4
0
ファイル: PodsMeta.php プロジェクト: centaurustech/chipin
 public function cpac_meta_values($meta, $fieldtype, $field, $type, $object_id)
 {
     $tableless_field_types = PodsForm::tableless_field_types();
     $object = $type;
     if ('wp-media' == $type) {
         $object = 'media';
     } elseif ('wp-users' == $type) {
         $object = 'user';
     } elseif ('wp-comments' == $type) {
         $object = 'comment';
     }
     $pod = pods_api()->load_pod(array('name' => $object), false);
     // Add Pods fields
     if (!empty($pod) && isset($pod['fields'][$field])) {
         if (in_array($pod['type'], array('post_type', 'user', 'comment', 'media')) && (!empty($fieldtype) || in_array($pod['fields'][$field]['type'], $tableless_field_types))) {
             $meta = get_metadata('post_type' == $pod['type'] ? 'post' : $pod['type'], $object_id, $field, true);
         }
         $meta = PodsForm::field_method($pod['fields'][$field]['type'], 'ui', $object_id, $meta, $field, array_merge($pod['fields'][$field], $pod['fields'][$field]['options']), $pod['fields'], $pod);
     }
     return $meta;
 }
コード例 #5
0
    /**
     * @param bool $reorder
     *
     * @return bool|mixed
     */
    public function table($reorder = false)
    {
        if (false !== $this->callback('table', $reorder)) {
            return null;
        }
        if (empty($this->data)) {
            ?>
        <p><?php 
            echo sprintf(__('No %s found', 'pods'), $this->items);
            ?>
</p>
        <?php 
            return false;
        }
        if (true === $reorder && !in_array('reorder', $this->actions_disabled) && false !== $this->reorder['on']) {
            ?>
        <style type="text/css">
            table.widefat.fixed tbody.reorderable tr {
                height: 50px;
            }

            .dragme {
                background: url(<?php 
            echo esc_url(PODS_URL);
            ?>
/ui/images/handle.gif) no-repeat;
                background-position: 8px 8px;
                cursor: pointer;
            }

            .dragme strong {
                margin-left: 30px;
            }
        </style>
<form action="<?php 
            echo esc_url(pods_query_arg(array('action' . $this->num => 'reorder', 'do' . $this->num => 'save', 'page' => pods_var_raw('page')), self::$allowed, $this->exclusion()));
            ?>
" method="post" class="admin_ui_reorder_form">
<?php 
        }
        $table_fields = $this->fields['manage'];
        if (true === $reorder && !in_array('reorder', $this->actions_disabled) && false !== $this->reorder['on']) {
            $table_fields = $this->fields['reorder'];
        }
        if (false === $table_fields || empty($table_fields)) {
            return $this->error(__('<strong>Error:</strong> Invalid Configuration - Missing "fields" definition.', 'pods'));
        }
        ?>
        <table class="widefat page fixed wp-list-table" cellspacing="0"<?php 
        echo 1 == $reorder && $this->reorder ? ' id="admin_ui_reorder"' : '';
        ?>
>
            <thead>
                <tr>
                    <?php 
        if (!empty($this->actions_bulk)) {
            ?>
                            <th scope="col" id="cb" class="manage-column column-cb check-column"><input type="checkbox" /></th>
            <?php 
        }
        $name_field = false;
        $fields = array();
        if (!empty($table_fields)) {
            foreach ($table_fields as $field => $attributes) {
                if (false === $attributes['display']) {
                    continue;
                }
                if (false === $name_field) {
                    $id = 'title';
                } else {
                    $id = '';
                }
                if ('other' == $attributes['type']) {
                    $id = '';
                }
                if (in_array($attributes['type'], array('date', 'datetime', 'time'))) {
                    $id = 'date';
                }
                if (false === $name_field && 'title' == $id) {
                    $name_field = true;
                }
                $fields[$field] = $attributes;
                $fields[$field]['field_id'] = $id;
                $dir = 'DESC';
                $current_sort = ' asc';
                if (isset($this->orderby['default']) && $field == $this->orderby['default']) {
                    if ('DESC' == $this->orderby_dir) {
                        $dir = 'ASC';
                        $current_sort = ' desc';
                    }
                }
                $att_id = '';
                if (!empty($id)) {
                    $att_id = ' id="' . esc_attr($id) . '"';
                }
                $width = '';
                if (isset($attributes['width']) && !empty($attributes['width'])) {
                    $width = ' style="width: ' . esc_attr($attributes['width']) . '"';
                }
                if ($fields[$field]['sortable']) {
                    ?>
                                <th scope="col"<?php 
                    echo $att_id;
                    ?>
 class="manage-column column-<?php 
                    echo esc_attr($id);
                    ?>
 sortable<?php 
                    echo esc_attr($current_sort);
                    ?>
"<?php 
                    echo $width;
                    ?>
>
                                    <a href="<?php 
                    echo esc_url_raw(pods_query_arg(array('orderby' . $this->num => $field, 'orderby_dir' . $this->num => $dir), array('limit' . $this->num, 'search' . $this->num, 'pg' . $this->num, 'page'), $this->exclusion()));
                    ?>
"> <span><?php 
                    echo $attributes['label'];
                    ?>
</span> <span class="sorting-indicator"></span> </a>
                                </th>
                                <?php 
                } else {
                    ?>
                                <th scope="col"<?php 
                    echo $att_id;
                    ?>
 class="manage-column column-<?php 
                    echo esc_attr($id);
                    ?>
"<?php 
                    echo $width;
                    ?>
><?php 
                    echo $attributes['label'];
                    ?>
</th>
                                <?php 
                }
            }
        }
        ?>
                </tr>
            </thead>
            <?php 
        if (6 < $this->total_found) {
            ?>
                <tfoot>
                    <tr>
                        <?php 
            if (!empty($this->actions_bulk)) {
                ?>
                                <th scope="col" class="manage-column column-cb check-column"><input type="checkbox" /></th>
            <?php 
            }
            if (!empty($fields)) {
                foreach ($fields as $field => $attributes) {
                    $dir = 'ASC';
                    if ($field == $this->orderby) {
                        $current_sort = 'desc';
                        if ('ASC' == $this->orderby_dir) {
                            $dir = 'DESC';
                            $current_sort = 'asc';
                        }
                    }
                    $width = '';
                    if (isset($attributes['width']) && !empty($attributes['width'])) {
                        $width = ' style="width: ' . esc_attr($attributes['width']) . '"';
                    }
                    if ($fields[$field]['sortable']) {
                        ?>
                                    <th scope="col" class="manage-column column-<?php 
                        echo esc_attr($id);
                        ?>
 sortable <?php 
                        echo esc_attr($current_sort);
                        ?>
"<?php 
                        echo $width;
                        ?>
><a href="<?php 
                        echo esc_url_raw(pods_query_arg(array('orderby' . $this->num => $field, 'orderby_dir' . $this->num => $dir), array('limit' . $this->num, 'search' . $this->num, 'pg' . $this->num, 'page'), $this->exclusion()));
                        ?>
"><span><?php 
                        echo $attributes['label'];
                        ?>
</span><span class="sorting-indicator"></span></a></th>
                                    <?php 
                    } else {
                        ?>
                                    <th scope="col" class="manage-column column-<?php 
                        echo esc_attr($id);
                        ?>
"<?php 
                        echo $width;
                        ?>
><?php 
                        echo $attributes['label'];
                        ?>
</th>
                                    <?php 
                    }
                }
            }
            ?>
                    </tr>
                </tfoot>
                <?php 
        }
        ?>
            <tbody id="the-list"<?php 
        echo true === $reorder && !in_array('reorder', $this->actions_disabled) && false !== $this->reorder['on'] ? ' class="reorderable"' : '';
        ?>
>
                <?php 
        if (!empty($this->data) && is_array($this->data)) {
            $counter = 0;
            while ($row = $this->get_row($counter, 'table')) {
                if (is_object($row)) {
                    $row = get_object_vars((object) $row);
                }
                $toggle_class = '';
                if (is_array($this->actions_custom) && isset($this->actions_custom['toggle'])) {
                    $toggle_class = ' pods-toggled-on';
                    if (!isset($row['toggle']) || empty($row['toggle'])) {
                        $toggle_class = ' pods-toggled-off';
                    }
                }
                ?>
                        <tr id="item-<?php 
                echo esc_attr($row[$this->sql['field_id']]);
                ?>
" class="iedit<?php 
                echo esc_attr($toggle_class);
                ?>
">
                            <?php 
                if (!empty($this->actions_bulk)) {
                    ?>
                                <th scope="row" class="check-column"><input type="checkbox" name="action_bulk_ids<?php 
                    echo esc_attr($this->num);
                    ?>
[]" value="<?php 
                    echo esc_attr($row[$this->sql['field_id']]);
                    ?>
"></th>
            <?php 
                }
                foreach ($fields as $field => $attributes) {
                    if (false === $attributes['display']) {
                        continue;
                    }
                    if (!isset($row[$field])) {
                        $row[$field] = $this->get_field($field);
                    }
                    $row_value = $row[$field];
                    if (!empty($attributes['custom_display'])) {
                        if (is_callable($attributes['custom_display'])) {
                            $row_value = call_user_func_array($attributes['custom_display'], array($row, &$this, $row_value, $field, $attributes));
                        } elseif (is_object($this->pod) && class_exists('Pods_Helpers')) {
                            $row_value = $this->pod->helper($attributes['custom_display'], $row_value, $field);
                        }
                    } else {
                        ob_start();
                        $field_value = PodsForm::field_method($attributes['type'], 'ui', $this->id, $row_value, $field, array_merge($attributes, pods_var_raw('options', $attributes, array(), null, true)), $fields, $this->pod);
                        $field_output = trim((string) ob_get_clean());
                        if (false === $field_value) {
                            $row_value = '';
                        } elseif (0 < strlen(trim((string) $field_value))) {
                            $row_value = trim((string) $field_value);
                        } elseif (0 < strlen($field_output)) {
                            $row_value = $field_output;
                        }
                    }
                    if (false !== $attributes['custom_relate']) {
                        global $wpdb;
                        $table = $attributes['custom_relate'];
                        $on = $this->sql['field_id'];
                        $is = $row[$this->sql['field_id']];
                        $what = array('name');
                        if (is_array($table)) {
                            if (isset($table['on'])) {
                                $on = pods_sanitize($table['on']);
                            }
                            if (isset($table['is']) && isset($row[$table['is']])) {
                                $is = pods_sanitize($row[$table['is']]);
                            }
                            if (isset($table['what'])) {
                                $what = array();
                                if (is_array($table['what'])) {
                                    foreach ($table['what'] as $wha) {
                                        $what[] = pods_sanitize($wha);
                                    }
                                } else {
                                    $what[] = pods_sanitize($table['what']);
                                }
                            }
                            if (isset($table['table'])) {
                                $table = $table['table'];
                            }
                        }
                        $table = pods_sanitize($table);
                        $wha = implode(',', $what);
                        $sql = "SELECT {$wha} FROM {$table} WHERE `{$on}`='{$is}'";
                        $value = @current($wpdb->get_results($sql, ARRAY_A));
                        if (!empty($value)) {
                            $val = array();
                            foreach ($what as $wha) {
                                if (isset($value[$wha])) {
                                    $val[] = $value[$wha];
                                }
                            }
                            if (!empty($val)) {
                                $row_value = implode(' ', $val);
                            }
                        }
                    }
                    $css_classes = ' pods-ui-col-field-' . sanitize_title($field);
                    if ($attributes['css_values']) {
                        $css_field_value = $row[$field];
                        if (is_object($css_field_value)) {
                            $css_field_value = get_object_vars($css_field_value);
                        }
                        if (is_array($css_field_value)) {
                            foreach ($css_field_value as $css_field_val) {
                                if (is_object($css_field_val)) {
                                    $css_field_val = get_object_vars($css_field_val);
                                }
                                if (is_array($css_field_val)) {
                                    foreach ($css_field_val as $css_field_v) {
                                        if (is_object($css_field_v)) {
                                            $css_field_v = get_object_vars($css_field_v);
                                        }
                                        $css_classes .= ' pods-ui-css-value-' . sanitize_title(str_replace(array("\n", "\r"), ' ', strip_tags((string) $css_field_v)));
                                    }
                                } else {
                                    $css_classes .= ' pods-ui-css-value-' . sanitize_title(str_replace(array("\n", "\r"), ' ', strip_tags((string) $css_field_val)));
                                }
                            }
                        } else {
                            $css_classes .= ' pods-ui-css-value-' . sanitize_title(str_replace(array("\n", "\r"), ' ', strip_tags((string) $css_field_value)));
                        }
                    }
                    if (is_object($this->pod)) {
                        $row_value = $this->do_hook($this->pod->pod . '_field_value', $row_value, $field, $attributes, $row);
                    }
                    $row_value = $this->do_hook('field_value', $row_value, $field, $attributes, $row);
                    if ('title' == $attributes['field_id']) {
                        $default_action = $this->do_hook('default_action', 'edit', $row);
                        if (!in_array('edit', $this->actions_disabled) && !in_array('edit', $this->actions_hidden) && (false === $reorder || in_array('reorder', $this->actions_disabled) || false === $this->reorder['on']) && 'edit' == $default_action) {
                            $link = pods_query_arg(array('action' . $this->num => 'edit', 'id' . $this->num => $row[$this->sql['field_id']]), self::$allowed, $this->exclusion());
                            if (!empty($this->action_links['edit'])) {
                                $link = $this->do_template($this->action_links['edit'], $row);
                            }
                            ?>
                <td class="post-title page-title column-title<?php 
                            echo esc_attr($css_classes);
                            ?>
"><strong><a class="row-title" href="<?php 
                            echo esc_url_raw($link);
                            ?>
" title="<?php 
                            esc_attr_e('Edit this item', 'pods');
                            ?>
"><?php 
                            echo $row_value;
                            ?>
</a></strong>
                                        <?php 
                        } elseif (!in_array('view', $this->actions_disabled) && !in_array('view', $this->actions_hidden) && (false === $reorder || in_array('reorder', $this->actions_disabled) || false === $this->reorder['on']) && 'view' == $default_action) {
                            $link = pods_query_arg(array('action' . $this->num => 'view', 'id' . $this->num => $row[$this->sql['field_id']]), self::$allowed, $this->exclusion());
                            if (!empty($this->action_links['view'])) {
                                $link = $this->do_template($this->action_links['view'], $row);
                            }
                            ?>
                <td class="post-title page-title column-title<?php 
                            echo esc_attr($css_classes);
                            ?>
"><strong><a class="row-title" href="<?php 
                            echo esc_url_raw($link);
                            ?>
" title="<?php 
                            esc_attr_e('View this item', 'pods');
                            ?>
"><?php 
                            echo $row_value;
                            ?>
</a></strong>
                                        <?php 
                        } else {
                            ?>
                <td class="post-title page-title column-title<?php 
                            echo esc_attr($css_classes);
                            echo esc_attr(1 == $reorder && $this->reorder ? ' dragme' : '');
                            ?>
"><strong><?php 
                            echo $row_value;
                            ?>
</strong>
                                        <?php 
                        }
                        if (true !== $reorder || in_array('reorder', $this->actions_disabled) || false === $this->reorder['on']) {
                            $toggle = false;
                            $actions = array();
                            if (!in_array('view', $this->actions_disabled) && !in_array('view', $this->actions_hidden)) {
                                $link = pods_query_arg(array('action' . $this->num => 'view', 'id' . $this->num => $row[$this->sql['field_id']]), self::$allowed, $this->exclusion());
                                if (!empty($this->action_links['view'])) {
                                    $link = $this->do_template($this->action_links['view'], $row);
                                }
                                $actions['view'] = '<span class="view"><a href="' . esc_url($link) . '" title="' . esc_attr__('View this item', 'pods') . '">' . __('View', 'pods') . '</a></span>';
                            }
                            if (!in_array('edit', $this->actions_disabled) && !in_array('edit', $this->actions_hidden) && !$this->restricted('edit', $row)) {
                                $link = pods_query_arg(array('action' . $this->num => 'edit', 'id' . $this->num => $row[$this->sql['field_id']]), self::$allowed, $this->exclusion());
                                if (!empty($this->action_links['edit'])) {
                                    $link = $this->do_template($this->action_links['edit'], $row);
                                }
                                $actions['edit'] = '<span class="edit"><a href="' . esc_url($link) . '" title="' . esc_attr__('Edit this item', 'pods') . '">' . __('Edit', 'pods') . '</a></span>';
                            }
                            if (!in_array('duplicate', $this->actions_disabled) && !in_array('duplicate', $this->actions_hidden) && !$this->restricted('edit', $row)) {
                                $link = pods_query_arg(array('action' . $this->num => 'duplicate', 'id' . $this->num => $row[$this->sql['field_id']]), self::$allowed, $this->exclusion());
                                if (!empty($this->action_links['duplicate'])) {
                                    $link = $this->do_template($this->action_links['duplicate'], $row);
                                }
                                $actions['duplicate'] = '<span class="edit"><a href="' . esc_url($link) . '" title="' . esc_attr__('Duplicate this item', 'pods') . '">' . __('Duplicate', 'pods') . '</a></span>';
                            }
                            if (!in_array('delete', $this->actions_disabled) && !in_array('delete', $this->actions_hidden) && !$this->restricted('delete', $row)) {
                                $link = pods_query_arg(array('action' . $this->num => 'delete', 'id' . $this->num => $row[$this->sql['field_id']], '_wpnonce' => wp_create_nonce('pods-ui-action-delete')), self::$allowed, $this->exclusion());
                                if (!empty($this->action_links['delete'])) {
                                    $link = add_query_arg(array('_wpnonce' => wp_create_nonce('pods-ui-action-delete')), $this->do_template($this->action_links['delete'], $row));
                                }
                                $actions['delete'] = '<span class="delete"><a href="' . esc_url($link) . '" title="' . esc_attr__('Delete this item', 'pods') . '" class="submitdelete" onclick="if(confirm(\'' . esc_attr__('You are about to permanently delete this item\\n Choose \\\'Cancel\\\' to stop, \\\'OK\\\' to delete.', 'pods') . '\')){return true;}return false;">' . __('Delete', 'pods') . '</a></span>';
                            }
                            if (is_array($this->actions_custom)) {
                                foreach ($this->actions_custom as $custom_action => $custom_data) {
                                    if ('add' != $custom_action && is_array($custom_data) && (isset($custom_data['link']) || isset($custom_data['callback'])) && !in_array($custom_action, $this->actions_disabled) && !in_array($custom_action, $this->actions_hidden)) {
                                        if (!in_array($custom_action, array('add', 'view', 'edit', 'duplicate', 'delete', 'save', 'export', 'reorder', 'manage', 'table'))) {
                                            if ('toggle' == $custom_action) {
                                                $toggle = true;
                                                $toggle_labels = array(__('Enable', 'pods'), __('Disable', 'pods'));
                                                $custom_data['label'] = $row['toggle'] ? $toggle_labels[1] : $toggle_labels[0];
                                            }
                                            if (!isset($custom_data['label'])) {
                                                $custom_data['label'] = ucwords(str_replace('_', ' ', $custom_action));
                                            }
                                            if (!isset($custom_data['link'])) {
                                                $vars = array('action' => $custom_action, 'id' => $row[$this->sql['field_id']], '_wpnonce' => wp_create_nonce('pods-ui-action-' . $custom_action));
                                                if ('toggle' == $custom_action) {
                                                    $vars['toggle'] = (int) (!$row['toggle']);
                                                    $vars['toggled'] = 1;
                                                }
                                                $custom_data['link'] = pods_query_arg($vars, self::$allowed, $this->exclusion());
                                                if (isset($this->action_links[$custom_action]) && !empty($this->action_links[$custom_action])) {
                                                    $custom_data['link'] = add_query_arg(array('_wpnonce' => wp_create_nonce('pods-ui-action-' . $custom_action)), $this->do_template($this->action_links[$custom_action], $row));
                                                }
                                            }
                                            $confirm = '';
                                            if (isset($custom_data['confirm'])) {
                                                $confirm = ' onclick="if(confirm(\'' . esc_js($custom_data['confirm']) . '\')){return true;}return false;"';
                                            }
                                            if ($this->restricted($custom_action, $row)) {
                                                continue;
                                            }
                                            $actions[$custom_action] = '<span class="edit action-' . esc_attr($custom_action) . '"><a href="' . esc_url($this->do_template($custom_data['link'], $row)) . '" title="' . esc_attr($custom_data['label']) . ' this item"' . $confirm . '>' . $custom_data['label'] . '</a></span>';
                                        }
                                    }
                                }
                            }
                            $actions = $this->do_hook('row_actions', $actions, $row[$this->sql['field_id']]);
                            if (!empty($actions)) {
                                ?>
                                            <div class="row-actions<?php 
                                echo esc_attr($toggle ? ' row-actions-toggle' : '');
                                ?>
">
                                                <?php 
                                $this->callback('actions_start', $row, $actions);
                                echo implode(' | ', $actions);
                                $this->callback('actions_end', $row, $actions);
                                ?>
                                            </div>
                                            <?php 
                            }
                        } else {
                            ?>
                                        <input type="hidden" name="order[]" value="<?php 
                            echo esc_attr($row[$this->sql['field_id']]);
                            ?>
" />
                                        <?php 
                        }
                        ?>
                </td>
<?php 
                    } elseif ('date' == $attributes['type']) {
                        ?>
                                    <td class="date column-date<?php 
                        echo esc_attr($css_classes);
                        ?>
"><abbr title="<?php 
                        echo esc_attr($row_value);
                        ?>
"><?php 
                        echo $row_value;
                        ?>
</abbr></td>
                                    <?php 
                    } else {
                        ?>
                                    <td class="author<?php 
                        echo esc_attr($css_classes);
                        ?>
"><span><?php 
                        echo $row_value;
                        ?>
</span></td>
                                    <?php 
                    }
                }
                ?>
                        </tr>
                        <?php 
            }
        }
        ?>
            </tbody>
        </table>
        <?php 
        if (true === $reorder && !in_array('reorder', $this->actions_disabled) && false !== $this->reorder['on']) {
            ?>
</form>
<?php 
        }
        ?>
    <script type="text/javascript">
        jQuery( 'table.widefat tbody tr:even' ).addClass( 'alternate' );
            <?php 
        if (true === $reorder && !in_array('reorder', $this->actions_disabled) && false !== $this->reorder['on']) {
            ?>
            jQuery( document ).ready( function () {
                jQuery( ".reorderable" ).sortable( {axis : "y", handle : ".dragme"} );
                jQuery( ".reorderable" ).bind( 'sortupdate', function ( event, ui ) {
                    jQuery( 'table.widefat tbody tr' ).removeClass( 'alternate' );
                    jQuery( 'table.widefat tbody tr:even' ).addClass( 'alternate' );
                } );
            } );
                <?php 
        }
        ?>
    </script>
    <?php 
    }
コード例 #6
0
ファイル: PodsData.php プロジェクト: Ingenex/redesign
 /**
  * Recursively join tables based on fields
  *
  * @param array $traverse_recurse Array of traversal options
  *
  * @return array Array of table joins
  *
  * @since 2.0
  */
 function traverse_recurse($traverse_recurse)
 {
     global $wpdb;
     $defaults = array('pod' => null, 'fields' => array(), 'joined' => 't', 'depth' => 0, 'joined_id' => 'id', 'joined_index' => 'id', 'params' => new stdClass(), 'last_table_info' => array());
     $traverse_recurse = array_merge($defaults, $traverse_recurse);
     $joins = array();
     if (0 == $traverse_recurse['depth'] && !empty($traverse_recurse['pod']) && !empty($traverse_recurse['last_table_info']) && isset($traverse_recurse['last_table_info']['id'])) {
         $pod_data = $traverse_recurse['last_table_info'];
     } elseif (empty($traverse_recurse['pod'])) {
         if (!empty($traverse_recurse['params']) && !empty($traverse_recurse['params']->table) && 0 === strpos($traverse_recurse['params']->table, $wpdb->prefix)) {
             if ($wpdb->posts == $traverse_recurse['params']->table) {
                 $traverse_recurse['pod'] = 'post_type';
             } elseif ($wpdb->terms == $traverse_recurse['params']->table) {
                 $traverse_recurse['pod'] = 'taxonomy';
             } elseif ($wpdb->users == $traverse_recurse['params']->table) {
                 $traverse_recurse['pod'] = 'user';
             } elseif ($wpdb->comments == $traverse_recurse['params']->table) {
                 $traverse_recurse['pod'] = 'comment';
             } else {
                 return $joins;
             }
             $pod_data = array();
             if (in_array($traverse_recurse['pod'], array('user', 'comment'))) {
                 $pod = $this->api->load_pod(array('name' => $traverse_recurse['pod'], 'table_info' => true));
                 if (!empty($pod) && $pod['type'] == $pod) {
                     $pod_data = $pod;
                 }
             }
             if (empty($pod_data)) {
                 $pod_data = array('id' => 0, 'name' => '_table_' . $traverse_recurse['pod'], 'type' => $traverse_recurse['pod'], 'storage' => 'taxonomy' == $traverse_recurse['pod'] ? 'none' : 'meta', 'fields' => array(), 'object_fields' => $this->api->get_wp_object_fields($traverse_recurse['pod']));
                 $pod_data = array_merge($this->api->get_table_info($traverse_recurse['pod'], ''), $pod_data);
             }
             $traverse_recurse['pod'] = $pod_data['name'];
         } else {
             return $joins;
         }
     } else {
         $pod_data = $this->api->load_pod(array('name' => $traverse_recurse['pod'], 'table_info' => true), false);
         if (empty($pod_data)) {
             return $joins;
         }
     }
     if (isset($pod_data['object_fields'])) {
         $pod_data['fields'] = array_merge($pod_data['fields'], $pod_data['object_fields']);
     }
     $tableless_field_types = PodsForm::tableless_field_types();
     $simple_tableless_objects = PodsForm::field_method('pick', 'simple_objects');
     $file_field_types = PodsForm::file_field_types();
     if (!isset($this->traversal[$traverse_recurse['pod']])) {
         $this->traversal[$traverse_recurse['pod']] = array();
     }
     if ((empty($pod_data['meta_table']) || $pod_data['meta_table'] == $pod_data['table']) && (empty($traverse_recurse['fields']) || !isset($traverse_recurse['fields'][$traverse_recurse['depth']]) || empty($traverse_recurse['fields'][$traverse_recurse['depth']]))) {
         return $joins;
     }
     $field = $traverse_recurse['fields'][$traverse_recurse['depth']];
     $ignore_aliases = array('wpml_languages', 'polylang_languages');
     $ignore_aliases = $this->do_hook('traverse_recurse_ignore_aliases', $ignore_aliases, $field, $traverse_recurse);
     if (in_array($field, $ignore_aliases)) {
         return $joins;
     }
     $meta_data_table = false;
     if (!isset($pod_data['fields'][$field]) && 'd' == $field && isset($traverse_recurse['fields'][$traverse_recurse['depth'] - 1])) {
         $field = $traverse_recurse['fields'][$traverse_recurse['depth'] - 1];
         $field_type = 'pick';
         if (isset($traverse_recurse['last_table_info']['pod']['fields'][$field])) {
             $field_type = $traverse_recurse['last_table_info']['pod']['fields'][$field]['type'];
         } elseif (isset($traverse_recurse['last_table_info']['pod']['object_fields'][$field])) {
             $field_type = $traverse_recurse['last_table_info']['pod']['object_fields'][$field]['type'];
         }
         $pod_data['fields'][$field] = array('id' => 0, 'name' => $field, 'type' => $field_type, 'pick_object' => $traverse_recurse['last_table_info']['pod']['type'], 'pick_val' => $traverse_recurse['last_table_info']['pod']['name']);
         $meta_data_table = true;
     }
     // Fallback to meta table if the pod type supports it
     if (!isset($pod_data['fields'][$field])) {
         $last = end($traverse_recurse['fields']);
         if ('post_type' == $pod_data['type'] && !isset($pod_data['object_fields'])) {
             $pod_data['object_fields'] = $this->api->get_wp_object_fields('post_type', $pod_data);
         }
         if ('post_type' == $pod_data['type'] && isset($pod_data['object_fields'][$field]) && in_array($pod_data['object_fields'][$field]['type'], $tableless_field_types)) {
             $pod_data['fields'][$field] = $pod_data['object_fields'][$field];
         } elseif (in_array($pod_data['type'], array('post_type', 'media', 'user', 'comment')) && 'meta_value' == $last) {
             $pod_data['fields'][$field] = PodsForm::field_setup(array('name' => $field));
         } else {
             if ('post_type' == $pod_data['type']) {
                 $pod_data['object_fields'] = $this->api->get_wp_object_fields('post_type', $pod_data, true);
                 if ('post_type' == $pod_data['type'] && isset($pod_data['object_fields'][$field]) && in_array($pod_data['object_fields'][$field]['type'], $tableless_field_types)) {
                     $pod_data['fields'][$field] = $pod_data['object_fields'][$field];
                 } else {
                     return $joins;
                 }
             } else {
                 return $joins;
             }
         }
     }
     $traverse = $pod_data['fields'][$field];
     if ('taxonomy' == $traverse['type']) {
         $traverse['table_info'] = $this->api->get_table_info($traverse['type'], $traverse['name']);
     } elseif (in_array($traverse['type'], $file_field_types)) {
         $traverse['table_info'] = $this->api->get_table_info('post_type', 'attachment');
     } elseif (!in_array($traverse['type'], $tableless_field_types)) {
         $traverse['table_info'] = $this->api->get_table_info($pod_data['type'], $pod_data['name'], $pod_data['name'], $pod_data);
     } elseif (empty($traverse['table_info']) || in_array($traverse['pick_object'], $simple_tableless_objects) && !empty($traverse_recurse['last_table_info'])) {
         if (in_array($traverse['pick_object'], $simple_tableless_objects) && !empty($traverse_recurse['last_table_info'])) {
             $traverse['table_info'] = $traverse_recurse['last_table_info'];
             if (!empty($traverse['table_info']['meta_table'])) {
                 $meta_data_table = true;
             }
         } elseif (!in_array($traverse['type'], $tableless_field_types) && isset($traverse_recurse['last_table_info']) && !empty($traverse_recurse['last_table_info']) && 0 == $traverse_recurse['depth']) {
             $traverse['table_info'] = $traverse_recurse['last_table_info'];
         } else {
             $traverse['table_info'] = $this->api->get_table_info($traverse['pick_object'], $traverse['pick_val'], null, $traverse['pod'], $traverse);
         }
     }
     if (isset($this->traversal[$traverse_recurse['pod']][$traverse['name']])) {
         $traverse = array_merge($traverse, (array) $this->traversal[$traverse_recurse['pod']][$traverse['name']]);
     }
     $traverse = $this->do_hook('traverse', $traverse, compact('pod', 'fields', 'joined', 'depth', 'joined_id', 'params'));
     if (empty($traverse)) {
         return $joins;
     }
     $traverse = pods_sanitize($traverse);
     $traverse['id'] = (int) $traverse['id'];
     if (empty($traverse['id'])) {
         $traverse['id'] = $field;
     }
     $table_info = $traverse['table_info'];
     $this->traversal[$traverse_recurse['pod']][$field] = $traverse;
     $field_joined = $field;
     if (0 < $traverse_recurse['depth'] && 't' != $traverse_recurse['joined']) {
         if ($meta_data_table && ('pick' != $traverse['type'] || !in_array(pods_var('pick_object', $traverse), $simple_tableless_objects))) {
             $field_joined = $traverse_recurse['joined'] . '_d';
         } else {
             $field_joined = $traverse_recurse['joined'] . '_' . $field;
         }
     }
     $rel_alias = 'rel_' . $field_joined;
     if (pods_var('search', $traverse_recurse['params'], false) && empty($traverse_recurse['params']->filters)) {
         if (0 < strlen(pods_var('filter_' . $field_joined, 'get'))) {
             $val = absint(pods_var('filter_' . $field_joined, 'get'));
             $search = "`{$field_joined}`.`{$table_info['field_id']}` = {$val}";
             if ('text' == $this->search_mode) {
                 $val = pods_var('filter_' . $field_joined, 'get');
                 $search = "`{$field_joined}`.`{$traverse['name']}` = '{$val}'";
             } elseif ('text_like' == $this->search_mode) {
                 $val = pods_sanitize(pods_sanitize_like(pods_var_raw('filter_' . $field_joined)));
                 $search = "`{$field_joined}`.`{$traverse['name']}` LIKE '%{$val}%'";
             }
             $this->search_where[] = " {$search} ";
         }
     }
     $the_join = null;
     $joined_id = $table_info['field_id'];
     $joined_index = $table_info['field_index'];
     if ('taxonomy' == $traverse['type']) {
         $rel_tt_alias = 'rel_tt_' . $field_joined;
         if ($meta_data_table) {
             $the_join = "\n                    LEFT JOIN `{$table_info['pod_table']}` AS `{$field_joined}` ON\n                        `{$field_joined}`.`{$table_info['pod_field_id']}` = `{$traverse_recurse['rel_alias']}`.`{$traverse_recurse['joined_id']}`\n                ";
         } else {
             $the_join = "\n                    LEFT JOIN `{$wpdb->term_relationships}` AS `{$rel_alias}` ON\n                        `{$rel_alias}`.`object_id` = `{$traverse_recurse['joined']}`.`ID`\n\n                    LEFT JOIN `{$wpdb->term_taxonomy}` AS `{$rel_tt_alias}` ON\n                        `{$rel_tt_alias}`.`taxonomy` = '{$traverse['name']}'\n                        AND `{$rel_tt_alias}`.`term_taxonomy_id` = `{$rel_alias}`.`term_taxonomy_id`\n\n                    LEFT JOIN `{$table_info['table']}` AS `{$field_joined}` ON\n                        `{$field_joined}`.`{$table_info['field_id']}` = `{$rel_tt_alias}`.`{$table_info['field_id']}`\n                ";
             // Override $rel_alias
             $rel_alias = $field_joined;
             $joined_id = $table_info['field_id'];
             $joined_index = $table_info['field_index'];
         }
     } elseif (in_array($traverse['type'], $tableless_field_types) && ('pick' != $traverse['type'] || !in_array(pods_var('pick_object', $traverse), $simple_tableless_objects))) {
         if (pods_tableless()) {
             $the_join = "\n                    LEFT JOIN `{$table_info['meta_table']}` AS `{$rel_alias}` ON\n                        `{$rel_alias}`.`{$table_info['meta_field_index']}` = '{$traverse['name']}'\n                        AND `{$rel_alias}`.`{$table_info['meta_field_id']}` = `{$traverse_recurse['joined']}`.`{$traverse_recurse['joined_id']}`\n\n                    LEFT JOIN `{$table_info['meta_table']}` AS `{$field_joined}` ON\n                        `{$field_joined}`.`{$table_info['meta_field_index']}` = '{$traverse['name']}'\n                        AND `{$field_joined}`.`{$table_info['meta_field_id']}` = CONVERT( `{$rel_alias}`.`{$table_info['meta_field_value']}`, SIGNED )\n                ";
             $joined_id = $table_info['meta_field_id'];
             $joined_index = $table_info['meta_field_index'];
         } elseif ($meta_data_table) {
             $the_join = "\n                    LEFT JOIN `{$table_info['pod_table']}` AS `{$field_joined}` ON\n                        `{$field_joined}`.`{$table_info['pod_field_id']}` = `{$traverse_recurse['rel_alias']}`.`{$traverse_recurse['joined_id']}`\n                ";
         } else {
             $the_join = "\n                    LEFT JOIN `@wp_podsrel` AS `{$rel_alias}` ON\n                        `{$rel_alias}`.`field_id` = {$traverse['id']}\n                        AND `{$rel_alias}`.`item_id` = `{$traverse_recurse['joined']}`.`{$traverse_recurse['joined_id']}`\n\n                    LEFT JOIN `{$table_info['table']}` AS `{$field_joined}` ON\n                        `{$field_joined}`.`{$table_info['field_id']}` = `{$rel_alias}`.`related_item_id`\n                ";
         }
     } elseif ('meta' == $pod_data['storage']) {
         if ($traverse_recurse['depth'] + 2 == count($traverse_recurse['fields']) && ('pick' != $traverse['type'] || !in_array(pods_var('pick_object', $traverse), $simple_tableless_objects)) && $table_info['meta_field_value'] == $traverse_recurse['fields'][$traverse_recurse['depth'] + 1]) {
             $the_join = "\n                    LEFT JOIN `{$table_info['meta_table']}` AS `{$field_joined}` ON\n                        `{$field_joined}`.`{$table_info['meta_field_index']}` = '{$traverse['name']}'\n                        AND `{$field_joined}`.`{$table_info['meta_field_id']}` = `{$traverse_recurse['joined']}`.`{$traverse_recurse['joined_id']}`\n                ";
             $table_info['recurse'] = false;
         } else {
             $the_join = "\n                    LEFT JOIN `{$table_info['meta_table']}` AS `{$field_joined}` ON\n                        `{$field_joined}`.`{$table_info['meta_field_index']}` = '{$traverse['name']}'\n                        AND `{$field_joined}`.`{$table_info['meta_field_id']}` = `{$traverse_recurse['joined']}`.`{$traverse_recurse['joined_id']}`\n                ";
             $joined_id = $table_info['meta_field_id'];
             $joined_index = $table_info['meta_field_index'];
         }
     }
     $traverse_recursive = array('pod' => pods_var_raw('name', pods_var_raw('pod', $table_info)), 'fields' => $traverse_recurse['fields'], 'joined' => $field_joined, 'depth' => $traverse_recurse['depth'] + 1, 'joined_id' => $joined_id, 'joined_index' => $joined_index, 'params' => $traverse_recurse['params'], 'rel_alias' => $rel_alias, 'last_table_info' => $table_info);
     $the_join = $this->do_hook('traverse_the_join', $the_join, $traverse_recurse, $traverse_recursive);
     if (empty($the_join)) {
         return $joins;
     }
     $joins[$traverse_recurse['pod'] . '_' . $traverse_recurse['depth'] . '_' . $traverse['id']] = $the_join;
     if ($traverse_recurse['depth'] + 1 < count($traverse_recurse['fields']) && !empty($traverse_recurse['pod']) && false !== $table_info['recurse']) {
         $joins = array_merge($joins, $this->traverse_recurse($traverse_recursive));
     }
     return $joins;
 }
コード例 #7
0
/**
 * Split an array into human readable text (Item, Item, and Item)
 *
 * @param array $value
 * @param string $field
 * @param array $fields
 * @param string $and
 * @param string $field_index
 *
 * @return string
 *
 * @since 2.0
 */
function pods_serial_comma($value, $field = null, $fields = null, $and = null, $field_index = null)
{
    if (is_object($value)) {
        $value = get_object_vars($value);
    }
    $defaults = array('field' => $field, 'fields' => $fields, 'and' => $and, 'field_index' => $field_index, 'separator' => ',', 'serial' => true);
    if (is_array($field)) {
        $defaults['field'] = null;
        $params = array_merge($defaults, $field);
    } else {
        $params = $defaults;
    }
    $params = (object) $params;
    $simple = false;
    if (!empty($params->fields) && is_array($params->fields) && isset($params->fields[$params->field])) {
        $params->field = $params->fields[$params->field];
        $simple_tableless_objects = PodsForm::simple_tableless_objects();
        if (!empty($params->field) && is_array($params->field) && in_array($params->field['type'], PodsForm::tableless_field_types())) {
            if (in_array($params->field['type'], PodsForm::file_field_types())) {
                if (null === $params->field_index) {
                    $params->field_index = 'guid';
                }
            } elseif (in_array($params->field['pick_object'], $simple_tableless_objects)) {
                $simple = true;
            } else {
                $table = pods_api()->get_table_info($params->field['pick_object'], $params->field['pick_val'], null, null, $params->field);
                if (!empty($table)) {
                    if (null === $params->field_index) {
                        $params->field_index = $table['field_index'];
                    }
                }
            }
        }
    } else {
        $params->field = null;
    }
    if ($simple && is_array($params->field) && !is_array($value) && '' !== $value && null !== $value) {
        $value = PodsForm::field_method('pick', 'simple_value', $params->field['name'], $value, $params->field);
    }
    if (!is_array($value)) {
        return $value;
    }
    if (null === $params->and) {
        $params->and = ' ' . __('and', 'pods') . ' ';
    }
    $last = '';
    $original_value = $value;
    if (!empty($value)) {
        $last = array_pop($value);
    }
    if ($simple && is_array($params->field) && !is_array($last) && '' !== $last && null !== $last) {
        $last = PodsForm::field_method('pick', 'simple_value', $params->field['name'], $last, $params->field);
    }
    if (is_array($last)) {
        if (null !== $params->field_index && isset($last[$params->field_index])) {
            $last = $last[$params->field_index];
        } elseif (isset($last[0])) {
            $last = $last[0];
        } elseif ($simple) {
            $last = current($last);
        } else {
            $last = '';
        }
    }
    if (!empty($value)) {
        if (null !== $params->field_index && isset($original_value[$params->field_index])) {
            return $original_value[$params->field_index];
        } elseif (null !== $params->field_index && isset($value[$params->field_index])) {
            return $value[$params->field_index];
        } elseif (!isset($value[0])) {
            $value = array($value);
        }
        foreach ($value as $k => $v) {
            if ($simple && is_array($params->field) && !is_array($v) && '' !== $v && null !== $v) {
                $v = PodsForm::field_method('pick', 'simple_value', $params->field['name'], $v, $params->field);
            }
            if (is_array($v)) {
                if (null !== $params->field_index && isset($v[$params->field_index])) {
                    $v = $v[$params->field_index];
                } elseif ($simple) {
                    $v = trim(implode($params->separator . ' ', $v), $params->separator . ' ');
                } else {
                    unset($value[$k]);
                    continue;
                }
            }
            $value[$k] = $v;
        }
        if (1 == count($value) || !$params->serial) {
            $value = trim(implode($params->separator . ' ', $value), $params->separator . ' ');
        } else {
            $value = trim(implode($params->separator . ' ', $value), $params->separator . ' ') . apply_filters('pods_serial_comma', $params->separator . ' ', $value, $original_value, $params);
        }
        $value = trim($value);
        $last = trim($last);
        if (0 < strlen($value) && 0 < strlen($last)) {
            $value = $value . $params->and . $last;
        } elseif (0 < strlen($last)) {
            $value = $last;
        } else {
            $value = '';
        }
    } else {
        $value = $last;
    }
    $value = trim($value, $params->separator . ' ');
    $value = apply_filters('pods_serial_comma_value', $value, $original_value, $params);
    return (string) $value;
}
コード例 #8
0
ファイル: Pods.php プロジェクト: erkmen/wpstartersetup
 /**
  * Remove an item from the values of a relationship field, remove a value from a number field (field-1), remove time to a date field
  *
  * @see PodsAPI::save_pod_item
  *
  * @param string $field Field name
  * @param mixed $value ID(s) to add, int|float to add to number field, string for dates (-1 week), or string for text
  * @param int $id (optional) ID of the pod item to update
  *
  * @return int The item ID
  *
  * @since 2.3.3
  */
 public function remove_from($field, $value = null, $id = null)
 {
     $pod =& $this;
     $fetch = false;
     if (null === $id) {
         $fetch = true;
         $id = $this->id();
     } elseif ($id != $this->id()) {
         $pod = pods($this->pod, $id);
     }
     $this->do_hook('remove_from', $field, $value, $id);
     if (!isset($this->fields[$field])) {
         return $id;
     }
     // Tableless fields
     if (in_array($this->fields[$field]['type'], PodsForm::tableless_field_types())) {
         if (empty($value)) {
             $value = array();
         }
         if (!empty($value)) {
             if (!is_array($value)) {
                 $value = explode(',', $value);
             }
             if ('pick' == $this->fields[$field]['type'] && in_array($this->fields[$field]['pick_object'], PodsForm::field_method('pick', 'simple_objects'))) {
                 $current_value = $pod->raw($field);
                 if (!empty($current_value)) {
                     $current_value = (array) $current_value;
                 }
                 foreach ($current_value as $k => $v) {
                     if (in_array($v, $value)) {
                         unset($current_value[$k]);
                     }
                 }
                 $value = $current_value;
             } else {
                 $related_ids = $this->api->lookup_related_items($this->fields[$field]['id'], $this->pod_data['id'], $id, $this->fields[$field], $this->pod_data);
                 foreach ($value as $k => $v) {
                     if (!preg_match('/[^0-9]/', $v)) {
                         $value[$k] = (int) $v;
                     } else {
                     }
                 }
                 foreach ($related_ids as $k => $v) {
                     if (in_array($v, $value)) {
                         unset($related_ids[$k]);
                     }
                 }
                 $value = $related_ids;
             }
             if (!empty($value)) {
                 $value = array_filter(array_unique($value));
             } else {
                 $value = array();
             }
         }
     } elseif (in_array($this->fields[$field]['type'], PodsForm::number_field_types())) {
         // Date fields don't support empty for removing
         if (empty($value)) {
             return $id;
         }
         $current_value = (double) $pod->raw($field);
         $value = $current_value - (double) $value;
     } elseif (in_array($this->fields[$field]['type'], PodsForm::date_field_types())) {
         // Date fields don't support empty for removing
         if (empty($value)) {
             return $id;
         }
         $current_value = $pod->raw($field);
         if (0 < strlen($current_value)) {
             $value = strtotime($value, strtotime($current_value));
         } else {
             $value = strtotime($value);
         }
         $value = date_i18n('Y-m-d h:i:s', $value);
     }
     // @todo handle object fields and taxonomies
     $params = array('pod' => $this->pod, 'id' => $id, 'data' => array($field => $value));
     $id = $this->api->save_pod_item($params);
     if (0 < $id && $fetch) {
         $pod->fetch($id, false);
     }
     return $id;
 }
コード例 #9
0
ファイル: date.php プロジェクト: Ingenex/redesign
$date_format = apply_filters('pods_form_ui_field_date_js_formats', $date_format);
wp_enqueue_script('jquery-ui-datepicker');
wp_enqueue_style('jquery-ui');
$attributes = array();
$type = 'text';
if (1 == pods_var($form_field_type . '_html5', $options)) {
    $type = $form_field_type;
}
$attributes['type'] = $type;
$attributes['tabindex'] = 2;
$format = PodsForm::field_method('date', 'format', $options);
$method = 'datepicker';
$args = array('dateFormat' => $date_format[pods_var($form_field_type . '_format', $options, 'mdy', null, true)], 'changeMonth' => true, 'changeYear' => true);
$html5_format = 'Y-m-d';
$date = PodsForm::field_method('date', 'createFromFormat', $format, (string) $value);
$date_default = PodsForm::field_method('date', 'createFromFormat', 'Y-m-d', (string) $value);
$formatted_date = $value;
if (1 == pods_var($form_field_type . '_allow_empty', $options, 1) && in_array($value, array('0000-00-00', '0000-00-00 00:00:00', '00:00:00'))) {
    $formatted_date = $value = '';
} elseif ('text' != $type) {
    $formatted_date = $value;
    if (false !== $date) {
        $value = $date->format($html5_format);
    } elseif (false !== $date_default) {
        $value = $date_default->format($html5_format);
    } elseif (!empty($value)) {
        $value = date_i18n($html5_format, strtotime((string) $value));
    } else {
        $value = date_i18n($html5_format);
    }
}
コード例 #10
0
ファイル: time.php プロジェクト: satokora/IT354Project
}
$attributes['type'] = $type;
$attributes['tabindex'] = 2;
$format = PodsForm::field_method('time', 'format', $options);
$method = 'timepicker';
$args = array('timeFormat' => $time_format[pods_var($form_field_type . '_format', $options, 'h_mma', null, true)]);
if (false !== stripos($args['timeFormat'], 'tt')) {
    $args['ampm'] = true;
}
$html5_format = '\\TH:i:s';
if (24 == pods_var($form_field_type . '_type', $options, 12)) {
    $args['ampm'] = false;
    $args['timeFormat'] = $time_format_24[pods_var($form_field_type . '_format_24', $options, 'hh_mm', null, true)];
}
$date = PodsForm::field_method('time', 'createFromFormat', $format, (string) $value);
$date_default = PodsForm::field_method('time', 'createFromFormat', 'H:i:s', (string) $value);
$formatted_date = $value;
if (1 == pods_var($form_field_type . '_allow_empty', $options, 1) && in_array($value, array('', '0000-00-00', '0000-00-00 00:00:00', '00:00:00'))) {
    $formatted_date = $value = '';
} elseif ('text' != $type) {
    $formatted_date = $value;
    if (false !== $date) {
        $value = $date->format($html5_format);
    } elseif (false !== $date_default) {
        $value = $date_default->format($html5_format);
    } elseif (!empty($value)) {
        $value = date_i18n($html5_format, strtotime((string) $value));
    } else {
        $value = date_i18n($html5_format);
    }
}
コード例 #11
0
ファイル: Pods.php プロジェクト: satokora/IT354Project
 /**
  * Return the value for a field.
  *
  * If you are getting a field for output in a theme, most of the time you will want to use display() instead.
  *
  * This function will return arrays for relationship and file fields.
  *
  * @param string|array $name The field name, or an associative array of parameters
  * @param boolean $single (optional) For tableless fields, to return the whole array or the just the first item, or an associative array of parameters
  * @param boolean $raw (optional) Whether to return the raw value, or to run through the field type's display method, or an associative array of parameters
  *
  * @return mixed|null Value returned depends on the field type, null if the field doesn't exist, false if no value returned for tableless fields
  * @since 2.0
  * @link http://pods.io/docs/field/
  */
 public function field($name, $single = null, $raw = false)
 {
     global $sitepress;
     $defaults = array('name' => $name, 'orderby' => null, 'single' => $single, 'params' => null, 'in_form' => false, 'raw' => $raw, 'raw_display' => false, 'display' => false, 'get_meta' => false, 'output' => null, 'deprecated' => false, 'args' => array());
     if (is_array($name) || is_object($name)) {
         $defaults['name'] = null;
         $params = (object) array_merge($defaults, (array) $name);
     } elseif (is_array($single) || is_object($single)) {
         $defaults['single'] = null;
         $params = (object) array_merge($defaults, (array) $single);
     } elseif (is_array($raw) || is_object($raw)) {
         $defaults['raw'] = false;
         $params = (object) array_merge($defaults, (array) $raw);
     } else {
         $params = (object) $defaults;
     }
     if ($params->in_form) {
         $params->output = 'ids';
     } elseif (null === $params->output) {
         /**
          * Override the way realted fields are output
          *
          * @param string $output How to output related fields. Default is 'arrays'. Options: id|name|object|array|pod
          * @param array|object $row Current row being outputted.
          * @param array $params Params array passed to field().
          * @param object|Pods   $this Current Pods object.
          */
         $params->output = apply_filters('pods_pods_field_related_output_type', 'arrays', $this->row, $params, $this);
     }
     if (in_array($params->output, array('id', 'name', 'object', 'array', 'pod'))) {
         $params->output .= 's';
     }
     // Support old $orderby variable
     if (null !== $params->single && is_string($params->single) && empty($params->orderby)) {
         if (!class_exists('Pod') || Pod::$deprecated_notice) {
             pods_deprecated('Pods::field', '2.0', 'Use $params[ \'orderby\' ] instead');
         }
         $params->orderby = $params->single;
         $params->single = false;
     }
     if (null !== $params->single) {
         $params->single = (bool) $params->single;
     }
     $params->name = trim($params->name);
     if (is_array($params->name) || strlen($params->name) < 1) {
         return null;
     }
     $params->full_name = $params->name;
     $value = null;
     if (isset($this->row_override[$params->name])) {
         $value = $this->row_override[$params->name];
     }
     if (false === $this->row()) {
         if (false !== $this->data()) {
             $this->fetch();
         } else {
             return $value;
         }
     }
     if ($this->data->field_id == $params->name) {
         if (isset($this->row[$params->name])) {
             return $this->row[$params->name];
         } elseif (null !== $value) {
             return $value;
         }
         return 0;
     }
     $tableless_field_types = PodsForm::tableless_field_types();
     $simple_tableless_objects = PodsForm::simple_tableless_objects();
     $params->traverse = array();
     if (in_array($params->name, array('_link', 'detail_url')) || in_array($params->name, array('permalink', 'the_permalink')) && in_array($this->pod_data['type'], array('post_type', 'media'))) {
         if (0 < strlen($this->detail_page)) {
             $value = get_home_url() . '/' . $this->do_magic_tags($this->detail_page);
         } elseif (in_array($this->pod_data['type'], array('post_type', 'media'))) {
             $value = get_permalink($this->id());
         } elseif ('taxonomy' == $this->pod_data['type']) {
             $value = get_term_link($this->id(), $this->pod_data['name']);
         } elseif ('user' == $this->pod_data['type']) {
             $value = get_author_posts_url($this->id());
         } elseif ('comment' == $this->pod_data['type']) {
             $value = get_comment_link($this->id());
         }
     }
     $field_data = false;
     $field_type = false;
     $first_field = explode('.', $params->name);
     $first_field = $first_field[0];
     if (isset($this->fields[$first_field])) {
         $field_data = $this->fields[$first_field];
         $field_type = 'field';
     } elseif (!empty($this->pod_data['object_fields'])) {
         if (isset($this->pod_data['object_fields'][$first_field])) {
             $field_data = $this->pod_data['object_fields'][$first_field];
             $field_type = 'object_field';
         } else {
             foreach ($this->pod_data['object_fields'] as $object_field => $object_field_opt) {
                 if (in_array($first_field, $object_field_opt['alias'])) {
                     if ($first_field == $params->name) {
                         $params->name = $object_field;
                     }
                     $first_field = $object_field;
                     $field_data = $object_field_opt;
                     $field_type = 'object_field';
                     break;
                 }
             }
         }
     }
     // Simple fields have no other output options
     if ('pick' == $field_data['type'] && in_array($field_data['pick_object'], $simple_tableless_objects)) {
         $params->output = 'arrays';
     }
     if (empty($value) && in_array($field_data['type'], $tableless_field_types)) {
         $params->raw = true;
         $value = false;
         if ('arrays' != $params->output && isset($this->row['_' . $params->output . '_' . $params->name])) {
             $value = $this->row['_' . $params->output . '_' . $params->name];
         } elseif ('arrays' == $params->output && isset($this->row[$params->name])) {
             $value = $this->row[$params->name];
         }
         if (false !== $value && !is_array($value) && 'pick' == $field_data['type'] && in_array($field_data['pick_object'], $simple_tableless_objects)) {
             $value = PodsForm::field_method('pick', 'simple_value', $params->name, $value, $field_data, $this->pod_data, $this->id(), true);
         }
     }
     if (empty($value) && isset($this->row[$params->name]) && (!in_array($field_data['type'], $tableless_field_types) || 'arrays' == $params->output)) {
         if (empty($field_data) || in_array($field_data['type'], array('boolean', 'number', 'currency'))) {
             $params->raw = true;
         }
         if (null === $params->single) {
             if (isset($this->fields[$params->name]) && !in_array($this->fields[$params->name]['type'], $tableless_field_types)) {
                 $params->single = true;
             } else {
                 $params->single = false;
             }
         }
         $value = $this->row[$params->name];
     } elseif (empty($value)) {
         $object_field_found = false;
         if ('object_field' == $field_type) {
             $object_field_found = true;
             if (isset($this->row[$first_field])) {
                 $value = $this->row[$first_field];
             } elseif (in_array($field_data['type'], $tableless_field_types)) {
                 $this->fields[$first_field] = $field_data;
                 $object_field_found = false;
             } else {
                 return null;
             }
         }
         if ('post_type' == $this->pod_data['type'] && !isset($this->fields[$params->name])) {
             if (!isset($this->fields['post_thumbnail']) && ('post_thumbnail' == $params->name || 0 === strpos($params->name, 'post_thumbnail.'))) {
                 $size = 'thumbnail';
                 if (0 === strpos($params->name, 'post_thumbnail.')) {
                     $field_names = explode('.', $params->name);
                     if (isset($field_names[1])) {
                         $size = $field_names[1];
                     }
                 }
                 // Pods will auto-get the thumbnail ID if this isn't an attachment
                 $value = pods_image($this->id(), $size, 0, null, true);
                 $object_field_found = true;
             } elseif (!isset($this->fields['post_thumbnail_url']) && ('post_thumbnail_url' == $params->name || 0 === strpos($params->name, 'post_thumbnail_url.'))) {
                 $size = 'thumbnail';
                 if (0 === strpos($params->name, 'post_thumbnail_url.')) {
                     $field_names = explode('.', $params->name);
                     if (isset($field_names[1])) {
                         $size = $field_names[1];
                     }
                 }
                 // Pods will auto-get the thumbnail ID if this isn't an attachment
                 $value = pods_image_url($this->id(), $size, 0, true);
                 $object_field_found = true;
             } elseif (0 === strpos($params->name, 'image_attachment.')) {
                 $size = 'thumbnail';
                 $image_id = 0;
                 $field_names = explode('.', $params->name);
                 if (isset($field_names[1])) {
                     $image_id = $field_names[1];
                 }
                 if (isset($field_names[2])) {
                     $size = $field_names[2];
                 }
                 if (!empty($image_id)) {
                     $value = pods_image($image_id, $size, 0, null, true);
                     if (!empty($value)) {
                         $object_field_found = true;
                     }
                 }
             } elseif (0 === strpos($params->name, 'image_attachment_url.')) {
                 $size = 'thumbnail';
                 $image_id = 0;
                 $field_names = explode('.', $params->name);
                 if (isset($field_names[1])) {
                     $image_id = $field_names[1];
                 }
                 if (isset($field_names[2])) {
                     $size = $field_names[2];
                 }
                 if (!empty($image_id)) {
                     $value = pods_image_url($image_id, $size, 0, true);
                     if (!empty($value)) {
                         $object_field_found = true;
                     }
                 }
             }
         } elseif ('user' == $this->pod_data['type'] && !isset($this->fields[$params->name])) {
             if (!isset($this->fields['avatar']) && ('avatar' == $params->name || 0 === strpos($params->name, 'avatar.'))) {
                 $size = null;
                 if (0 === strpos($params->name, 'avatar.')) {
                     $field_names = explode('.', $params->name);
                     if (isset($field_names[1])) {
                         $size = (int) $field_names[1];
                     }
                 }
                 if (!empty($size)) {
                     $value = get_avatar($this->id(), $size);
                 } else {
                     $value = get_avatar($this->id());
                 }
                 $object_field_found = true;
             }
         } elseif (0 === strpos($params->name, 'image_attachment.')) {
             $size = 'thumbnail';
             $image_id = 0;
             $field_names = explode('.', $params->name);
             if (isset($field_names[1])) {
                 $image_id = $field_names[1];
             }
             if (isset($field_names[2])) {
                 $size = $field_names[2];
             }
             if (!empty($image_id)) {
                 $value = pods_image($image_id, $size, 0, null, true);
                 if (!empty($value)) {
                     $object_field_found = true;
                 }
             }
         } elseif (0 === strpos($params->name, 'image_attachment_url.')) {
             $size = 'thumbnail';
             $image_id = 0;
             $field_names = explode('.', $params->name);
             if (isset($field_names[1])) {
                 $image_id = $field_names[1];
             }
             if (isset($field_names[2])) {
                 $size = $field_names[2];
             }
             if (!empty($image_id)) {
                 $value = pods_image_url($image_id, $size, 0, true);
                 if (!empty($value)) {
                     $object_field_found = true;
                 }
             }
         }
         if (false === $object_field_found) {
             $params->traverse = array($params->name);
             if (false !== strpos($params->name, '.')) {
                 $params->traverse = explode('.', $params->name);
                 $params->name = $params->traverse[0];
             }
             if (isset($this->fields[$params->name]) && isset($this->fields[$params->name]['type'])) {
                 /**
                  * Modify value returned by field() after its retrieved, but before its validated or formatted
                  *
                  * Filter name is set dynamically with name of field: "pods_pods_field_{field_name}"
                  *
                  * @since unknown
                  *
                  * @param array|string|null $value Value retrieved.
                  * @param array|object $row Current row being outputted.
                  * @param array $params Params array passed to field().
                  * @param object|Pods $this Current Pods object.
                  *
                  */
                 $v = apply_filters('pods_pods_field_' . $this->fields[$params->name]['type'], null, $this->fields[$params->name], $this->row, $params, $this);
                 if (null !== $v) {
                     return $v;
                 }
             }
             $simple = false;
             $simple_data = array();
             if (isset($this->fields[$params->name])) {
                 if ('meta' == $this->pod_data['storage']) {
                     if (!in_array($this->fields[$params->name]['type'], $tableless_field_types)) {
                         $simple = true;
                     }
                 }
                 if (in_array($this->fields[$params->name]['type'], $tableless_field_types)) {
                     $params->raw = true;
                     if ('pick' == $this->fields[$params->name]['type'] && in_array($this->fields[$params->name]['pick_object'], $simple_tableless_objects)) {
                         $simple = true;
                         $params->single = true;
                     }
                 } elseif (in_array($this->fields[$params->name]['type'], array('boolean', 'number', 'currency'))) {
                     $params->raw = true;
                 }
             }
             if (!isset($this->fields[$params->name]) || !in_array($this->fields[$params->name]['type'], $tableless_field_types) || $simple) {
                 if (null === $params->single) {
                     if (isset($this->fields[$params->name]) && !in_array($this->fields[$params->name]['type'], $tableless_field_types)) {
                         $params->single = true;
                     } else {
                         $params->single = false;
                     }
                 }
                 $no_conflict = pods_no_conflict_check($this->pod_data['type']);
                 if (!$no_conflict) {
                     pods_no_conflict_on($this->pod_data['type']);
                 }
                 if (in_array($this->pod_data['type'], array('post_type', 'media'))) {
                     $id = $this->id();
                     // Support for WPML 'duplicated' translation handling
                     if (is_object($sitepress) && $sitepress->is_translated_post_type($this->pod_data['name'])) {
                         $master_post_id = (int) get_post_meta($id, '_icl_lang_duplicate_of', true);
                         if (0 < $master_post_id) {
                             $id = $master_post_id;
                         }
                     }
                     $value = get_post_meta($id, $params->name, $params->single);
                     $single_multi = 'single';
                     if (isset($this->fields[$params->name])) {
                         $single_multi = pods_v($this->fields[$params->name]['type'] . '_format_type', $this->fields[$params->name]['options'], 'single');
                     }
                     if ($simple && !is_array($value) && 'single' != $single_multi) {
                         $value = get_post_meta($id, $params->name);
                     }
                 } elseif (in_array($this->pod_data['type'], array('user', 'comment'))) {
                     $value = get_metadata($this->pod_data['type'], $this->id(), $params->name, $params->single);
                     $single_multi = 'single';
                     if (isset($this->fields[$params->name])) {
                         $single_multi = pods_v($this->fields[$params->name]['type'] . '_format_type', $this->fields[$params->name]['options'], 'single');
                     }
                     if ($simple && !is_array($value) && 'single' != $single_multi) {
                         $value = get_metadata($this->pod_data['type'], $this->id(), $params->name);
                     }
                 } elseif ('settings' == $this->pod_data['type']) {
                     $value = get_option($this->pod_data['name'] . '_' . $params->name, null);
                 }
                 // Handle Simple Relationships
                 if ($simple) {
                     if (null === $params->single) {
                         $params->single = false;
                     }
                     $value = PodsForm::field_method('pick', 'simple_value', $params->name, $value, $this->fields[$params->name], $this->pod_data, $this->id(), true);
                 }
                 if (!$no_conflict) {
                     pods_no_conflict_off($this->pod_data['type']);
                 }
             } else {
                 // Dot-traversal
                 $pod = $this->pod;
                 $ids = array($this->id());
                 $all_fields = array();
                 $lookup = $params->traverse;
                 // Get fields matching traversal names
                 if (!empty($lookup)) {
                     $fields = $this->api->load_fields(array('name' => $lookup, 'type' => $tableless_field_types, 'object_fields' => true));
                     if (!empty($fields)) {
                         foreach ($fields as $field) {
                             if (!empty($field)) {
                                 if (!isset($all_fields[$field['pod']])) {
                                     $all_fields[$field['pod']] = array();
                                 }
                                 $all_fields[$field['pod']][$field['name']] = $field;
                             }
                         }
                     }
                     if (!empty($this->pod_data['object_fields'])) {
                         foreach ($this->pod_data['object_fields'] as $object_field => $object_field_opt) {
                             if (in_array($object_field_opt['type'], $tableless_field_types)) {
                                 $all_fields[$this->pod][$object_field] = $object_field_opt;
                             }
                         }
                     }
                 }
                 $last_type = $last_object = $last_pick_val = '';
                 $last_options = array();
                 $single_multi = pods_v($this->fields[$params->name]['type'] . '_format_type', $this->fields[$params->name]['options'], 'single');
                 if ('multi' == $single_multi) {
                     $limit = (int) pods_v($this->fields[$params->name]['type'] . '_limit', $this->fields[$params->name]['options'], 0);
                 } else {
                     $limit = 1;
                 }
                 $last_limit = 0;
                 // Loop through each traversal level
                 foreach ($params->traverse as $key => $field) {
                     $last_loop = false;
                     if (count($params->traverse) <= $key + 1) {
                         $last_loop = true;
                     }
                     $field_exists = isset($all_fields[$pod][$field]);
                     $simple = false;
                     $last_options = array();
                     if ($field_exists && 'pick' == $all_fields[$pod][$field]['type'] && in_array($all_fields[$pod][$field]['pick_object'], $simple_tableless_objects)) {
                         $simple = true;
                         $last_options = $all_fields[$pod][$field];
                     }
                     // Tableless handler
                     if ($field_exists && (!in_array($all_fields[$pod][$field]['type'], array('pick', 'taxonomy')) || !$simple)) {
                         $type = $all_fields[$pod][$field]['type'];
                         $pick_object = $all_fields[$pod][$field]['pick_object'];
                         $pick_val = $all_fields[$pod][$field]['pick_val'];
                         if ('table' == $pick_object) {
                             $pick_val = pods_v('pick_table', $all_fields[$pod][$field]['options'], $pick_val, true);
                         } elseif ('__current__' == $pick_val) {
                             $pick_val = $pod;
                         }
                         $last_limit = 0;
                         if (in_array($type, $tableless_field_types)) {
                             $single_multi = pods_v("{$type}_format_type", $all_fields[$pod][$field]['options'], 'single');
                             if ('multi' == $single_multi) {
                                 $last_limit = (int) pods_v("{$type}_limit", $all_fields[$pod][$field]['options'], 0);
                             } else {
                                 $last_limit = 1;
                             }
                         }
                         $last_type = $type;
                         $last_object = $pick_object;
                         $last_pick_val = $pick_val;
                         $last_options = $all_fields[$pod][$field];
                         // Temporary hack until there's some better handling here
                         $last_limit = $last_limit * count($ids);
                         // Get related IDs
                         if (!isset($all_fields[$pod][$field]['pod_id'])) {
                             $all_fields[$pod][$field]['pod_id'] = 0;
                         }
                         if (isset($all_fields[$pod][$field]['id'])) {
                             $ids = $this->api->lookup_related_items($all_fields[$pod][$field]['id'], $all_fields[$pod][$field]['pod_id'], $ids, $all_fields[$pod][$field]);
                         }
                         // No items found
                         if (empty($ids)) {
                             return false;
                         } elseif (0 < $last_limit) {
                             $ids = array_slice($ids, 0, $last_limit);
                         }
                         // Get $pod if related to a Pod
                         if (!empty($pick_object) && (!empty($pick_val) || in_array($pick_object, array('user', 'media', 'comment')))) {
                             if ('pod' == $pick_object) {
                                 $pod = $pick_val;
                             } else {
                                 $check = $this->api->get_table_info($pick_object, $pick_val);
                                 if (!empty($check) && !empty($check['pod'])) {
                                     $pod = $check['pod']['name'];
                                 }
                             }
                         }
                     } else {
                         // Invalid field
                         if (0 == $key) {
                             return false;
                         }
                         $last_loop = true;
                     }
                     if ($last_loop) {
                         $object_type = $last_object;
                         $object = $last_pick_val;
                         if (in_array($last_type, PodsForm::file_field_types())) {
                             $object_type = 'media';
                             $object = 'attachment';
                         }
                         $data = array();
                         $table = $this->api->get_table_info($object_type, $object, null, null, $last_options);
                         $join = $where = array();
                         if (!empty($table['join'])) {
                             $join = (array) $table['join'];
                         }
                         if (!empty($table['where']) || !empty($ids)) {
                             foreach ($ids as $id) {
                                 $where[$id] = '`t`.`' . $table['field_id'] . '` = ' . (int) $id;
                             }
                             if (!empty($where)) {
                                 $where = array(implode(' OR ', $where));
                             }
                             if (!empty($table['where'])) {
                                 $where = array_merge($where, array_values((array) $table['where']));
                             }
                         }
                         /**
                          * @var $related_obj Pods
                          */
                         $related_obj = false;
                         if ('pod' == $object_type) {
                             $related_obj = pods($object, null, false);
                         } elseif (!empty($table['pod'])) {
                             $related_obj = pods($table['pod']['name'], null, false);
                         }
                         if (!empty($table['table']) || !empty($related_obj)) {
                             $sql = array('select' => '*, `t`.`' . $table['field_id'] . '` AS `pod_item_id`', 'table' => $table['table'], 'join' => $join, 'where' => $where, 'orderby' => $params->orderby, 'pagination' => false, 'search' => false, 'limit' => -1, 'expires' => 180);
                             // Output types
                             if (in_array($params->output, array('ids', 'objects', 'pods'))) {
                                 $sql['select'] = '`t`.`' . $table['field_id'] . '` AS `pod_item_id`';
                             } elseif ('names' == $params->output && !empty($table['field_index'])) {
                                 $sql['select'] = '`t`.`' . $table['field_index'] . '` AS `pod_item_index`, `t`.`' . $table['field_id'] . '` AS `pod_item_id`';
                             }
                             if (!empty($params->params) && is_array($params->params)) {
                                 $where = $sql['where'];
                                 $sql = array_merge($sql, $params->params);
                                 if (isset($params->params['where'])) {
                                     $sql['where'] = array_merge((array) $where, (array) $params->params['where']);
                                 }
                             }
                             if (empty($related_obj)) {
                                 if (!is_object($this->alt_data)) {
                                     $this->alt_data = pods_data(null, 0, true, true);
                                 }
                                 $item_data = $this->alt_data->select($sql);
                             } else {
                                 $item_data = $related_obj->find($sql)->data();
                             }
                             $items = array();
                             if (!empty($item_data)) {
                                 foreach ($item_data as $item) {
                                     if (is_array($item)) {
                                         $item = (object) $item;
                                     }
                                     if (empty($item->pod_item_id)) {
                                         continue;
                                     }
                                     // Bypass pass field
                                     if (isset($item->user_pass)) {
                                         unset($item->user_pass);
                                     }
                                     // Get Item ID
                                     $item_id = $item->pod_item_id;
                                     // Output types
                                     if ('ids' == $params->output) {
                                         $item = (int) $item_id;
                                     } elseif ('names' == $params->output && !empty($table['field_index'])) {
                                         $item = $item->pod_item_index;
                                     } elseif ('objects' == $params->output) {
                                         if (in_array($object_type, array('post_type', 'media'))) {
                                             $item = get_post($item_id);
                                         } elseif ('taxonomy' == $object_type) {
                                             $item = get_term($item_id, $object);
                                         } elseif ('user' == $object_type) {
                                             $item = get_userdata($item_id);
                                             if (!empty($item)) {
                                                 // Get other vars
                                                 $roles = $item->roles;
                                                 $caps = $item->caps;
                                                 $allcaps = $item->allcaps;
                                                 $item = $item->data;
                                                 // Set other vars
                                                 $item->roles = $roles;
                                                 $item->caps = $caps;
                                                 $item->allcaps = $allcaps;
                                                 unset($item->user_pass);
                                             }
                                         } elseif ('comment' == $object_type) {
                                             $item = get_comment($item_id);
                                         } else {
                                             $item = (object) $item;
                                         }
                                     } elseif ('pods' == $params->output) {
                                         $item = pods($object, (int) $item_id);
                                     } else {
                                         // arrays
                                         $item = get_object_vars((object) $item);
                                     }
                                     // Pass item data into $data
                                     $items[$item_id] = $item;
                                 }
                                 // Cleanup
                                 unset($item_data);
                                 // Return all of the data in the order expected
                                 if (empty($params->orderby)) {
                                     foreach ($ids as $id) {
                                         if (isset($items[$id])) {
                                             $data[$id] = $items[$id];
                                         }
                                     }
                                 } else {
                                     // Use order set by orderby
                                     foreach ($items as $id => $v) {
                                         if (in_array($id, $ids)) {
                                             $data[$id] = $v;
                                         }
                                     }
                                 }
                             }
                         }
                         if (in_array($last_type, $tableless_field_types) || in_array($last_type, array('boolean', 'number', 'currency'))) {
                             $params->raw = true;
                         }
                         if (empty($data)) {
                             $value = false;
                         } else {
                             $object_type = $table['type'];
                             if (in_array($table['type'], array('post_type', 'attachment', 'media'))) {
                                 $object_type = 'post';
                             }
                             $no_conflict = true;
                             if (in_array($object_type, array('post', 'user', 'comment', 'settings'))) {
                                 $no_conflict = pods_no_conflict_check($object_type);
                                 if (!$no_conflict) {
                                     pods_no_conflict_on($object_type);
                                 }
                             }
                             // Return entire array
                             if (false !== $field_exists && (in_array($last_type, $tableless_field_types) && !$simple)) {
                                 $value = $data;
                             } else {
                                 $value = array();
                                 foreach ($data as $item_id => $item) {
                                     // $field is 123x123, needs to be _src.123x123
                                     $full_field = implode('.', array_splice($params->traverse, $key));
                                     if ((false !== strpos($full_field, '_src') || 'guid' == $field) && (in_array($table['type'], array('attachment', 'media')) || in_array($last_type, PodsForm::file_field_types())) || (in_array($field, array('_link', 'detail_url')) || in_array($field, array('permalink', 'the_permalink')) && in_array($last_type, PodsForm::file_field_types()))) {
                                         $size = 'full';
                                         if (false !== strpos($full_field, '_src.') && 5 < strlen($full_field)) {
                                             $size = substr($full_field, 5);
                                         } elseif (false !== strpos($full_field, '_src_relative.') && 14 < strlen($full_field)) {
                                             $size = substr($full_field, 14);
                                         } elseif (false !== strpos($full_field, '_src_schemeless.') && 16 < strlen($full_field)) {
                                             $size = substr($full_field, 16);
                                         }
                                         $value_url = pods_image_url($item_id, $size);
                                         if (false !== strpos($full_field, '_src_relative') && !empty($value_url)) {
                                             $value_url_parsed = parse_url($value_url);
                                             $value_url = $value_url_parsed['path'];
                                         } elseif (false !== strpos($full_field, '_src_schemeless') && !empty($value_url)) {
                                             $value_url = str_replace(array('http://', 'https://'), '//', $value_url);
                                         }
                                         if (!empty($value_url)) {
                                             $value[] = $value_url;
                                         }
                                         $params->raw_display = true;
                                     } elseif (false !== strpos($full_field, '_img') && (in_array($table['type'], array('attachment', 'media')) || in_array($last_type, PodsForm::file_field_types()))) {
                                         $size = 'full';
                                         if (false !== strpos($full_field, '_img.') && 5 < strlen($full_field)) {
                                             $size = substr($full_field, 5);
                                         }
                                         $value[] = pods_image($item_id, $size);
                                         $params->raw_display = true;
                                     } elseif (in_array($field, array('_link', 'detail_url')) || in_array($field, array('permalink', 'the_permalink')) && 'post' == $object_type) {
                                         if ('pod' == $object_type) {
                                             if (is_object($related_obj)) {
                                                 $related_obj->fetch($item_id);
                                                 $value[] = $related_obj->field('detail_url');
                                             } else {
                                                 $value[] = '';
                                             }
                                         } elseif ('post' == $object_type) {
                                             $value[] = get_permalink($item_id);
                                         } elseif ('taxonomy' == $object_type) {
                                             $value[] = get_term_link($item_id, $object);
                                         } elseif ('user' == $object_type) {
                                             $value[] = get_author_posts_url($item_id);
                                         } elseif ('comment' == $object_type) {
                                             $value[] = get_comment_link($item_id);
                                         } else {
                                             $value[] = '';
                                         }
                                         $params->raw_display = true;
                                     } elseif (is_array($item) && isset($item[$field])) {
                                         if ($table['field_id'] == $field) {
                                             $value[] = (int) $item[$field];
                                         } else {
                                             $value[] = $item[$field];
                                         }
                                     } elseif (is_object($item) && isset($item->{$field})) {
                                         if ($table['field_id'] == $field) {
                                             $value[] = (int) $item->{$field};
                                         } else {
                                             $value[] = $item->{$field};
                                         }
                                     } elseif ('post' == $object_type) {
                                         // Support for WPML 'duplicated' translation handling
                                         if (is_object($sitepress) && $sitepress->is_translated_post_type($object)) {
                                             $master_post_id = (int) get_post_meta($item_id, '_icl_lang_duplicate_of', true);
                                             if (0 < $master_post_id) {
                                                 $item_id = $master_post_id;
                                             }
                                         }
                                         $value[] = get_post_meta($item_id, $field, true);
                                     } elseif (in_array($object_type, array('post', 'user', 'comment'))) {
                                         $value[] = get_metadata($object_type, $item_id, $field, true);
                                     } elseif ('settings' == $object_type) {
                                         $value[] = get_option($object . '_' . $field);
                                     }
                                 }
                             }
                             if (in_array($object_type, array('post', 'user', 'comment', 'settings')) && !$no_conflict) {
                                 pods_no_conflict_off($object_type);
                             }
                             // Handle Simple Relationships
                             if ($simple) {
                                 if (null === $params->single) {
                                     $params->single = false;
                                 }
                                 $value = PodsForm::field_method('pick', 'simple_value', $field, $value, $last_options, $all_fields[$pod], 0, true);
                             } elseif (false === $params->in_form && !empty($value)) {
                                 $value = array_values($value);
                             }
                             // Return a single column value
                             if (false === $params->in_form && 1 == $limit && !empty($value) && is_array($value) && 1 == count($value)) {
                                 $value = current($value);
                             }
                         }
                         break;
                     }
                 }
             }
         }
     }
     if (!empty($params->traverse) && 1 < count($params->traverse)) {
         $field_names = implode('.', $params->traverse);
         $this->row[$field_names] = $value;
     } elseif ('arrays' != $params->output && in_array($field_data['type'], $tableless_field_types)) {
         $this->row['_' . $params->output . '_' . $params->full_name] = $value;
     } elseif ('arrays' == $params->output || !in_array($field_data['type'], $tableless_field_types)) {
         $this->row[$params->full_name] = $value;
     }
     if ($params->single && is_array($value) && 1 == count($value)) {
         $value = current($value);
     }
     // @todo Expand this into traversed fields too
     if (!empty($field_data) && ($params->display || !$params->raw) && !$params->in_form && !$params->raw_display) {
         if ($params->display || ($params->get_meta || $params->deprecated) && !in_array($field_data['type'], $tableless_field_types)) {
             $field_data['options'] = pods_var_raw('options', $field_data, array(), null, true);
             $post_temp = false;
             if ('post_type' == pods_v('type', $this->pod_data) && 0 < $this->id() && (!isset($GLOBALS['post']) || empty($GLOBALS['post']))) {
                 global $post_ID, $post;
                 $post_temp = true;
                 $old_post = $GLOBALS['post'];
                 $old_ID = $GLOBALS['post_ID'];
                 $post = get_post($this->id());
                 $post_ID = $this->id();
             }
             $filter = pods_var_raw('display_filter', $field_data['options']);
             if (0 < strlen($filter)) {
                 $args = array($filter, $value);
                 $filter_args = pods_var_raw('display_filter_args', $field_data['options']);
                 if (!empty($filter_args)) {
                     $args = array_merge($args, compact($filter_args));
                 }
                 $value = call_user_func_array('apply_filters', $args);
             } elseif (1 == pods_v('display_process', $field_data['options'], 1)) {
                 $value = PodsForm::display($field_data['type'], $value, $params->name, array_merge($field_data, $field_data['options']), $this->pod_data, $this->id());
             }
             if ($post_temp) {
                 $post = $old_post;
                 $post_ID = $old_ID;
             }
         } else {
             $value = PodsForm::value($field_data['type'], $value, $params->name, array_merge($field_data, $field_data['options']), $this->pod_data, $this->id());
         }
     }
     /**
      * Modify value returned by field() directly before output.
      *
      * Will not run if value was null
      *
      * @since unknown
      *
      * @param array|string|null $value Value to be returned.
      * @param array|object $row Current row being outputted.
      * @param array $params Params array passed to field().
      * @param object|Pods $this Current Pods object.
      *
      */
     $value = apply_filters('pods_pods_field', $value, $this->row, $params, $this);
     return $value;
 }
コード例 #12
0
    echo 'pods-form-ui-row-type-' . $field['type'] . ' pods-form-ui-row-name-' . PodsForm::clean($field['name'], true);
    ?>
">
									<th scope="row" valign="top">
										<strong><?php 
    echo $field['label'];
    ?>
</strong>
									</th>
									<td>
										<?php 
    if (is_array($value) || is_object($value)) {
        print_r($value, true);
    } else {
        ob_start();
        $field_value = PodsForm::field_method($field['type'], 'ui', $obj->id, $value, $field['name'], array_merge($field, pods_var_raw('options', $field, array(), null, true)), $obj->fields['view']);
        $field_output = trim((string) ob_get_clean());
        if (false === $field_value) {
            $value = '';
        } elseif (0 < strlen(trim((string) $field_value))) {
            $value = trim((string) $field_value);
        } elseif (0 < strlen($field_output)) {
            $value = $field_output;
        }
        echo $value;
    }
    ?>
									</td>
								</tr>
							<?php 
}
コード例 #13
0
ファイル: PodsObject.php プロジェクト: Ingenex/redesign
 /**
  * Return field array from $fields, a field's data, or a field option
  *
  * @param string $fields Field key name
  * @param string|null $field Field name
  * @param string|null $option Field option
  * @param bool $alt Set to true to check alternate fields array
  *
  * @return bool|mixed
  *
  * @since 2.3.10
  */
 protected function _fields($fields, $field = null, $option = null, $alt = true)
 {
     if (!$this->is_valid()) {
         if (null === $field || null === $option) {
             return array();
         }
         return false;
     }
     $alt_fields = 'object_fields';
     if ('object_fields' == $fields) {
         $alt_fields = 'fields';
     }
     // No fields found
     if (!isset($this->_object['fields']) || empty($this->_object['fields'])) {
         $field_data = array();
         // No fields and field not found, get alt field data
         if (!empty($field) && $alt) {
             $field_data = $this->_fields($alt_fields, $field, $option, false);
         }
     } elseif (empty($field)) {
         $field_data =& $this->_object['fields'];
         if (!$this->_live) {
             foreach ($field_data as $field_name => $fields) {
                 foreach ($fields as $field_option => $field_value) {
                     // i18n plugin integration
                     if ('label' == $field_option || 0 === strpos($field_option, 'label_')) {
                         $field_data[$field_name][$field_option] = __($field_value);
                     }
                 }
             }
         }
     } elseif (!isset($this->_object['fields'][$field])) {
         $field_data = array();
         // Field not found, get alt field data
         if ($alt) {
             $field_data = $this->_fields($alt_fields, $field, $option, false);
         }
     } elseif (empty($option)) {
         $field_data =& $this->_object['fields'][$field];
         if (!$this->_live) {
             foreach ($field_data as $field_option => $field_value) {
                 // i18n plugin integration
                 if ('label' == $field_option || 0 === strpos($field_option, 'label_')) {
                     $field_data[$field_option] = __($field_value);
                 }
             }
         }
     } else {
         $field_data = null;
         // Get a list of available items from a relationship field
         if ('data' == $option && in_array(pods_var_raw('type', $this->_object[$fields][$field]), PodsForm::tableless_field_types())) {
             $field_data = PodsForm::field_method('pick', 'get_field_data', $this->_object[$fields][$field]);
         } elseif (isset($this->_object[$fields][$field][$option])) {
             $field_data = $this->_object[$fields][$field][$option];
             // i18n plugin integration
             if ('label' == $option || 0 === strpos($option, 'label_')) {
                 $field_data = __($field_data);
             }
         }
     }
     return $field_data;
 }
コード例 #14
0
ファイル: PodsMeta.php プロジェクト: pods-framework/pods
 public function cpac_meta_values($meta, $field_type, $field, $type, $id)
 {
     $tableless_field_types = PodsForm::tableless_field_types();
     $object = $type;
     if ('wp-media' == $type) {
         $object = 'media';
     } elseif ('wp-users' == $type) {
         $object = 'user';
     } elseif ('wp-comments' == $type) {
         $object = 'comment';
     }
     if (empty(self::$current_pod_data) || !is_object(self::$current_pod_data) || self::$current_pod_data['name'] != $object) {
         self::$current_pod_data = pods_api()->load_pod(array('name' => $object), false);
     }
     $pod = self::$current_pod_data;
     // Add Pods fields
     if (!empty($pod) && isset($pod['fields'][$field])) {
         if (in_array($pod['type'], array('post_type', 'user', 'taxonomy', 'comment', 'media')) && (!empty($field_type) || in_array($pod['fields'][$field]['type'], $tableless_field_types))) {
             $metadata_type = $pod['type'];
             if (in_array($metadata_type, array('post_type', 'media'))) {
                 $metadata_type = 'post';
             } elseif ('taxonomy' == $metadata_type) {
                 $metadata_type = 'term';
             }
             $meta = get_metadata($metadata_type, $id, $field, true);
         }
         $meta = PodsForm::field_method($pod['fields'][$field]['type'], 'ui', $id, $meta, $field, array_merge($pod['fields'][$field], $pod['fields'][$field]['options']), $pod['fields'], $pod);
     }
     return $meta;
 }
コード例 #15
0
ファイル: PodsAPI.php プロジェクト: Ingenex/redesign
 /**
  * Import data from an array or a CSV file.
  *
  * @param mixed $import_data PHP associative array or CSV input
  * @param bool $numeric_mode Use IDs instead of the name field when matching
  * @param string $format Format of import data, options are php or csv
  *
  * @return array IDs of imported items
  *
  * @since 1.7.1
  * @todo This needs some love and use of table_info etc for relationships
  */
 public function import($import_data, $numeric_mode = false, $format = null)
 {
     /**
      * @var $wpdb wpdb
      */
     global $wpdb;
     if (null === $format && null !== $this->format) {
         $format = $this->format;
     }
     if ('csv' == $format && !is_array($import_data)) {
         $data = pods_migrate('sv', ',')->parse($import_data);
         $import_data = $data['items'];
     }
     pods_query("SET NAMES utf8");
     pods_query("SET CHARACTER SET utf8");
     // Loop through the array of items
     $ids = array();
     // Test to see if it's an array of arrays
     if (!is_array(@current($import_data))) {
         $import_data = array($import_data);
     }
     $pod = $this->load_pod(array('name' => $this->pod));
     if (false === $pod) {
         return pods_error(__('Pod not found', 'pods'), $this);
     }
     $fields = array_merge($pod['fields'], $pod['object_fields']);
     $simple_tableless_objects = PodsForm::field_method('pick', 'simple_objects');
     foreach ($import_data as $key => $data_row) {
         $data = array();
         // Loop through each field (use $fields so only valid fields get parsed)
         foreach ($fields as $field_name => $field_data) {
             if (!isset($data_row[$field_name]) && !isset($data_row[$field_data['label']])) {
                 continue;
             }
             $field_id = $field_data['id'];
             $type = $field_data['type'];
             $pick_object = isset($field_data['pick_object']) ? $field_data['pick_object'] : '';
             $pick_val = isset($field_data['pick_val']) ? $field_data['pick_val'] : '';
             if (isset($data_row[$field_name])) {
                 $field_value = $data_row[$field_name];
             } else {
                 $field_value = $data_row[$field_data['label']];
             }
             if (null !== $field_value && false !== $field_value && '' !== $field_value) {
                 if ('pick' == $type || in_array($type, PodsForm::file_field_types())) {
                     $field_values = is_array($field_value) ? $field_value : array($field_value);
                     $pick_values = array();
                     foreach ($field_values as $pick_value) {
                         if (in_array($type, PodsForm::file_field_types()) || 'media' == $pick_object) {
                             $where = "`guid` = '" . pods_sanitize($pick_value) . "'";
                             if (0 < pods_absint($pick_value) && false !== $numeric_mode) {
                                 $where = "`ID` = " . pods_absint($pick_value);
                             }
                             $result = pods_query("SELECT `ID` AS `id` FROM `{$wpdb->posts}` WHERE `post_type` = 'attachment' AND {$where} ORDER BY `ID`", $this);
                             if (!empty($result)) {
                                 $pick_values[] = $result[0]->id;
                             }
                         } elseif ('pick' == $type) {
                             $related_pod = false;
                             if ('pod' == $pick_object) {
                                 $related_pod = $this->load_pod(array('name' => $pick_val, 'table_info' => true), false);
                             }
                             if (empty($related_pod)) {
                                 $related_pod = array('id' => 0, 'type' => $pick_object);
                             }
                             if (in_array('taxonomy', array($pick_object, $related_pod['type']))) {
                                 $where = "`t`.`name` = '" . pods_sanitize($pick_value) . "'";
                                 if (0 < pods_absint($pick_value) && false !== $numeric_mode) {
                                     $where = "`tt`.`term_id` = " . pods_absint($pick_value);
                                 }
                                 $result = pods_query("SELECT `t`.`term_id` AS `id` FROM `{$wpdb->term_taxonomy}` AS `tt` LEFT JOIN `{$wpdb->terms}` AS `t` ON `t`.`term_id` = `tt`.`term_id` WHERE `taxonomy` = '{$pick_val}' AND {$where} ORDER BY `t`.`term_id`", $this);
                                 if (!empty($result)) {
                                     $pick_values[] = $result[0]->id;
                                 }
                             } elseif (in_array('post_type', array($pick_object, $related_pod['type'])) || in_array('media', array($pick_object, $related_pod['type']))) {
                                 $where = "`post_title` = '" . pods_sanitize($pick_value) . "'";
                                 if (0 < pods_absint($pick_value) && false !== $numeric_mode) {
                                     $where = "`ID` = " . pods_absint($pick_value);
                                 }
                                 $result = pods_query("SELECT `ID` AS `id` FROM `{$wpdb->posts}` WHERE `post_type` = '{$pick_val}' AND {$where} ORDER BY `ID`", $this);
                                 if (!empty($result)) {
                                     $pick_values[] = $result[0]->id;
                                 }
                             } elseif (in_array('user', array($pick_object, $related_pod['type']))) {
                                 $where = "`user_login` = '" . pods_sanitize($pick_value) . "'";
                                 if (0 < pods_absint($pick_value) && false !== $numeric_mode) {
                                     $where = "`ID` = " . pods_absint($pick_value);
                                 }
                                 $result = pods_query("SELECT `ID` AS `id` FROM `{$wpdb->users}` WHERE {$where} ORDER BY `ID`", $this);
                                 if (!empty($result)) {
                                     $pick_values[] = $result[0]->id;
                                 }
                             } elseif (in_array('comment', array($pick_object, $related_pod['type']))) {
                                 $where = "`comment_ID` = " . pods_absint($pick_value);
                                 $result = pods_query("SELECT `comment_ID` AS `id` FROM `{$wpdb->comments}` WHERE {$where} ORDER BY `ID`", $this);
                                 if (!empty($result)) {
                                     $pick_values[] = $result[0]->id;
                                 }
                             } elseif (in_array($pick_object, $simple_tableless_objects)) {
                                 $pick_values[] = $pick_value;
                             } elseif (!empty($related_pod['id'])) {
                                 $where = "`" . $related_pod['field_index'] . "` = '" . pods_sanitize($pick_value) . "'";
                                 if (0 < pods_absint($pick_value) && false !== $numeric_mode) {
                                     $where = "`" . $related_pod['field_id'] . "` = " . pods_absint($pick_value);
                                 }
                                 $result = pods_query("SELECT `" . $related_pod['field_id'] . "` AS `id` FROM `" . $related_pod['table'] . "` WHERE {$where} ORDER BY `" . $related_pod['field_id'] . "`", $this);
                                 if (!empty($result)) {
                                     $pick_values[] = $result[0]->id;
                                 }
                             }
                         }
                     }
                     $field_value = implode(',', $pick_values);
                 }
                 $data[$field_name] = $field_value;
             }
         }
         if (!empty($data)) {
             $params = array('pod' => $this->pod, 'data' => $data);
             $ids[] = $this->save_pod_item($params);
         }
     }
     return $ids;
 }
コード例 #16
0
 /**
  * Get list of available text field types
  *
  * @return array Text field types
  *
  * @since 2.3
  */
 public static function simple_tableless_objects()
 {
     static $object_types = null;
     if (null === $object_types) {
         $object_types = PodsForm::field_method('pick', 'simple_objects');
     }
     return $object_types;
 }