Example #1
0
 /**
  * Parse the default the value
  *
  * @since 2.0
  */
 public static function default_value($value, $type = 'text', $name = null, $options = null, $pod = null, $id = null)
 {
     $default_value = pods_v('default_value', $options);
     if ('' === $default_value || null === $default_value) {
         $default_value = $value;
     }
     $default = pods_v('default', $options, $default_value, true);
     $default_value = str_replace(array('{@', '}'), '', trim($default));
     if ($default != $default_value && 1 == (int) pods_v('default_evaluate_tags', $options, 1)) {
         $default = pods_evaluate_tags($default);
     }
     $default = pods_var_raw(pods_v('default_value_parameter', $options), 'request', $default, null, true);
     if ($default != $value) {
         $value = $default;
     }
     if (is_array($value)) {
         $value = pods_serial_comma($value);
     }
     return apply_filters('pods_form_field_default_value', $value, $default, $type, $options, $pod, $id);
 }
 /**
  * Get the label from a pick value
  *
  * @param string $name The name of the field
  * @param string|array $value The value of the field
  * @param array $options Field options
  * @param array $pod Pod data
  * @param int $id Item ID
  *
  * @return string
  *
  * @since 2.2
  */
 public function value_to_label($name, $value = null, $options = null, $pod = null, $id = null)
 {
     if (isset($options['options'])) {
         $options = array_merge($options, $options['options']);
         unset($options['options']);
     }
     $data = pods_var_raw('data', $options, null, null, true);
     $object_params = array('name' => $name, 'value' => $value, 'options' => $options, 'pod' => $pod, 'id' => $id, 'context' => 'value_to_label');
     if (null !== $data) {
         $data = (array) $data;
     } else {
         $data = $this->get_object_data($object_params);
     }
     $labels = array();
     foreach ($data as $v => $l) {
         if (!in_array($l, $labels) && ($value == $v || is_array($value) && in_array($v, $value))) {
             $labels[] = $l;
         }
     }
     $labels = apply_filters('pods_field_pick_value_to_label', $labels, $name, $value, $options, $pod, $id);
     $labels = pods_serial_comma($labels);
     return $labels;
 }
Example #3
0
 /**
  * Export a pod item by depth level
  *
  * @param Pods $pod Pods object
  * @param array $fields Fields to export
  * @param int $depth Depth limit
  * @param boolean $flatten Whether to flatten arrays for display
  * @param int $current_depth Current depth level
  *
  * @return array Data array
  *
  * @since 2.3
  */
 private function export_pod_item_level($pod, $fields, $depth, $flatten = false, $current_depth = 1)
 {
     $tableless_field_types = PodsForm::tableless_field_types();
     $simple_tableless_objects = PodsForm::simple_tableless_objects();
     $object_fields = (array) pods_var_raw('object_fields', $pod->pod_data, array(), null, true);
     $export_fields = array();
     foreach ($fields as $k => $field) {
         if (!is_array($field)) {
             $field = array('id' => 0, 'name' => $field);
         }
         if (isset($pod->fields[$field['name']])) {
             $field = $pod->fields[$field['name']];
             $field['lookup_name'] = $field['name'];
             if (in_array($field['type'], $tableless_field_types) && !in_array(pods_var('pick_object', $field), $simple_tableless_objects)) {
                 if ('pick' == $field['type']) {
                     if (empty($field['table_info'])) {
                         $field['table_info'] = $this->get_table_info(pods_var_raw('pick_object', $field), pods_var_raw('pick_val', $field), null, null, $field);
                     }
                     if (!empty($field['table_info'])) {
                         $field['lookup_name'] .= '.' . $field['table_info']['field_id'];
                     }
                 } elseif (in_array($field['type'], PodsForm::file_field_types())) {
                     $field['lookup_name'] .= '.guid';
                 }
             }
             $export_fields[$field['name']] = $field;
         } elseif (isset($object_fields[$field['name']])) {
             $field = $object_fields[$field['name']];
             $field['lookup_name'] = $field['name'];
             $export_fields[$field['name']] = $field;
         } elseif ($field['name'] == $pod->pod_data['field_id']) {
             $field['type'] = 'number';
             $field['lookup_name'] = $field['name'];
             $export_fields[$field['name']] = $field;
         }
     }
     $data = array();
     foreach ($export_fields as $field) {
         // Return IDs (or guid for files) if only one level deep
         if (1 == $depth) {
             $data[$field['name']] = $pod->field(array('name' => $field['lookup_name'], 'output' => 'arrays'));
         } elseif ((-1 == $depth || $current_depth < $depth) && 'pick' == $field['type'] && !in_array(pods_var('pick_object', $field), $simple_tableless_objects)) {
             $related_data = array();
             $related_ids = $pod->field(array('name' => $field['name'], 'output' => 'ids'));
             if (!empty($related_ids)) {
                 $related_ids = (array) $related_ids;
                 $pick_object = pods_var_raw('pick_object', $field);
                 $related_pod = pods(pods_var_raw('pick_val', $field), null, false);
                 // If this isn't a Pod, return data exactly as Pods does normally
                 if (empty($related_pod) || 'pod' != $pick_object && $pick_object != $related_pod->pod_data['type'] || $related_pod->pod == $pod->pod) {
                     $related_data = $pod->field(array('name' => $field['name'], 'output' => 'arrays'));
                 } else {
                     $related_object_fields = (array) pods_var_raw('object_fields', $related_pod->pod_data, array(), null, true);
                     $related_fields = array_merge($related_pod->fields, $related_object_fields);
                     foreach ($related_ids as $related_id) {
                         if ($related_pod->fetch($related_id)) {
                             $related_item = $this->export_pod_item_level($related_pod, $related_fields, $depth, $flatten, $current_depth + 1);
                             $related_data[$related_id] = $this->do_hook('export_pod_item_level', $related_item, $related_pod->pod, $related_pod->id(), $related_pod, $related_fields, $depth, $flatten, $current_depth + 1);
                         }
                     }
                     if ($flatten && !empty($related_data)) {
                         $related_data = pods_serial_comma(array_values($related_data), array('and' => '', 'field_index' => $related_pod->pod_data['field_index']));
                     }
                 }
             }
             $data[$field['name']] = $related_data;
         } else {
             $data[$field['name']] = $pod->field(array('name' => $field['name'], 'output' => 'arrays'));
         }
         if ($flatten && is_array($data[$field['name']])) {
             $data[$field['name']] = pods_serial_comma($data[$field['name']], array('field' => $field['name'], 'fields' => $export_fields, 'and' => ''));
         }
     }
     $data['id'] = (int) $pod->id();
     return $data;
 }
/**
 * Evaluate tag like magic tag but mapped through pods_v
 *
 * @param string|array $tag
 * @param bool $sanitize Whether to sanitize tags
 *
 * @return string
 *
 * @version 2.1
 */
function pods_evaluate_tag($tag, $sanitize = false)
{
    global $wpdb;
    // Handle pods_evaluate_tags
    if (is_array($tag)) {
        if (!isset($tag[2]) && strlen(trim($tag[2])) < 1) {
            return '';
        }
        $tag = $tag[2];
    }
    $tag = trim($tag, ' {@}');
    $tag = explode('.', $tag);
    if (empty($tag) || !isset($tag[0]) || strlen(trim($tag[0])) < 1) {
        return '';
    }
    // Fix formatting that may be after the first .
    if (2 < count($tag)) {
        $first_tag = $tag[0];
        unset($tag[0]);
        $tag = array($first_tag, implode('.', $tag));
    }
    foreach ($tag as $k => $v) {
        $tag[$k] = trim($v);
    }
    $value = '';
    $single_supported = array('template-url', 'stylesheet-url', 'site-url', 'home-url', 'admin-url', 'includes-url', 'content-url', 'plugins-url', 'network-site-url', 'network-home-url', 'network-admin-url', 'user-admin-url', 'prefix');
    if (in_array($tag[0], $single_supported)) {
        $value = pods_v('', $tag[0], '', true);
    } elseif (1 == count($tag)) {
        $value = pods_v($tag[0], 'get', '', true);
    } elseif (2 == count($tag)) {
        $value = pods_v($tag[1], $tag[0], '', true);
    }
    $value = apply_filters('pods_evaluate_tag', $value, $tag);
    if (is_array($value) && 1 == count($value)) {
        $value = current($value);
    }
    if (is_array($value)) {
        $value = pods_serial_comma($value);
    }
    if ($sanitize) {
        $value = pods_sanitize($value);
    }
    return $value;
}
Example #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 PODS_URL;
            ?>
/ui/images/handle.gif) no-repeat;
                background-position: 8px 8px;
                cursor: pointer;
            }

            .dragme strong {
                margin-left: 30px;
            }
        </style>
<form action="<?php 
            echo pods_var_update(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="' . $id . '"';
                }
                $width = '';
                if (isset($attributes['width']) && !empty($attributes['width'])) {
                    $width = ' style="width: ' . $attributes['width'] . '"';
                }
                if ($fields[$field]['sortable']) {
                    ?>
                                <th scope="col"<?php 
                    echo $att_id;
                    ?>
 class="manage-column column-<?php 
                    echo $id;
                    ?>
 sortable<?php 
                    echo $current_sort;
                    ?>
"<?php 
                    echo $width;
                    ?>
>
                                    <a href="<?php 
                    echo pods_var_update(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 $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: ' . $attributes['width'] . '"';
                    }
                    if ($fields[$field]['sortable']) {
                        ?>
                                    <th scope="col" class="manage-column column-<?php 
                        echo $id;
                        ?>
 sortable <?php 
                        echo $current_sort;
                        ?>
"<?php 
                        echo $width;
                        ?>
><a href="<?php 
                        echo pods_var_update(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 $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 $row[$this->sql['field_id']];
                ?>
" class="iedit<?php 
                echo $toggle_class;
                ?>
">
                            <?php 
                if (!empty($this->actions_bulk)) {
                    ?>
                                <th scope="row" class="check-column"><input type="checkbox" name="action_bulk_ids<?php 
                    echo $this->num;
                    ?>
[]" value="<?php 
                    echo $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) {
                                $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 (is_array($row_value)) {
                        $row_value = pods_serial_comma($row_value);
                    }
                    if ('title' == $attributes['field_id']) {
                        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'])) {
                            $link = pods_var_update(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 $css_classes;
                            ?>
"><strong><a class="row-title" href="<?php 
                            echo $link;
                            ?>
" title="<?php 
                            _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'])) {
                            $link = pods_var_update(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 $css_classes;
                            ?>
"><strong><a class="row-title" href="<?php 
                            echo $link;
                            ?>
" title="<?php 
                            _e('View this item', 'pods');
                            ?>
"><?php 
                            echo $row_value;
                            ?>
</a></strong>
                                        <?php 
                        } else {
                            ?>
                <td class="post-title page-title column-title<?php 
                            echo $css_classes;
                            echo 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_var_update(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="' . $link . '" title="' . __('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_var_update(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="' . $link . '" title="' . __('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_var_update(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="' . $link . '" title="' . __('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_var_update(array('action' . $this->num => 'delete', 'id' . $this->num => $row[$this->sql['field_id']]), self::$allowed, $this->exclusion());
                                if (!empty($this->action_links['delete'])) {
                                    $link = $this->do_template($this->action_links['delete'], $row);
                                }
                                $actions['delete'] = '<span class="delete"><a href="' . $link . '" title="' . __('Delete this item', 'pods') . '" class="submitdelete" onclick="if(confirm(\'' . __('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']]);
                                                if ('toggle' == $custom_action) {
                                                    $vars['toggle'] = (int) (!$row['toggle']);
                                                    $vars['toggled'] = 1;
                                                }
                                                $custom_data['link'] = pods_var_update($vars, self::$allowed, $this->exclusion());
                                                if (isset($this->action_links[$custom_action]) && !empty($this->action_links[$custom_action])) {
                                                    $custom_data['link'] = $this->do_template($this->action_links[$custom_action], $row);
                                                }
                                            }
                                            $confirm = '';
                                            if (isset($custom_data['confirm'])) {
                                                $confirm = ' onclick="if(confirm(\'' . $custom_data['confirm'] . '\')){return true;}return false;"';
                                            }
                                            if ($this->restricted($custom_action, $row)) {
                                                continue;
                                            }
                                            $actions[$custom_action] = '<span class="edit action-' . $custom_action . '"><a href="' . $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 $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 $row[$this->sql['field_id']];
                            ?>
" />
                                        <?php 
                        }
                        ?>
                </td>
<?php 
                    } elseif ('date' == $attributes['type']) {
                        ?>
                                    <td class="date column-date<?php 
                        echo $css_classes;
                        ?>
"><abbr title="<?php 
                        echo esc_attr($row_value);
                        ?>
"><?php 
                        echo $row_value;
                        ?>
</abbr></td>
                                    <?php 
                    } else {
                        ?>
                                    <td class="author<?php 
                        echo $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 
    }
Example #6
0
 /**
  * @param array $data Array of data
  * @param string $delimiter Delimiter for export type 'sv'
  *
  * @return bool
  */
 public function build_sv($data = null, $delimiter = null)
 {
     if (!empty($data)) {
         $this->set_data($data);
     }
     if (!empty($delimiter)) {
         $this->delimiter = $delimiter;
     }
     if (empty($this->data) || !is_array($this->data)) {
         return false;
     }
     $head = $lines = '';
     foreach ($this->data['columns'] as $column => $label) {
         $head .= '"' . $label . '"' . $this->delimiter;
     }
     $head = substr($head, 0, -1);
     foreach ($this->data['items'] as $item) {
         $line = '';
         foreach ($this->data['columns'] as $column => $label) {
             if (is_numeric($column) && (is_object($item) && !isset($item->{$column}) || is_array($item) && !isset($item[$column]))) {
                 $column = $label;
             }
             $value = '';
             if (is_object($item)) {
                 if (!isset($item->{$column})) {
                     $item->{$column} = '';
                 }
                 $value = $item->{$column};
             } elseif (is_array($item)) {
                 if (!isset($item[$column])) {
                     $item[$column] = '';
                 }
                 $value = $item[$column];
             }
             if (is_array($value) || is_object($value)) {
                 $value = pods_serial_comma($value, array('field' => $column, 'fields' => pods_var_raw($column, $this->data['fields']), 'and' => ''));
             }
             $value = str_replace(array('"', "\r\n", "\r", "\n"), array('\\"', "\n", "\n", '\\n'), $value);
             $line .= '"' . $value . '"' . $this->delimiter;
         }
         $lines .= substr($line, 0, -1) . "\n";
     }
     if (!empty($lines)) {
         $lines = "\n" . substr($lines, 0, -1);
     }
     $this->built = $head . $lines;
     return $this->built;
 }
Example #7
0
 /**
  * Replace magic tags with their values
  *
  * @param string $tag The magic tag to process
  * @param object $obj The Pods object
  *
  * @return string Code with Magic Tags evaluated
  *
  * @since 2.0.2
  */
 private function process_magic_tags($tag)
 {
     if (is_array($tag)) {
         if (!isset($tag[2]) && strlen(trim($tag[2])) < 1) {
             return '';
         }
         $tag = $tag[2];
     }
     $tag = trim($tag, ' {@}');
     $tag = explode(',', $tag);
     if (empty($tag) || !isset($tag[0]) || strlen(trim($tag[0])) < 1) {
         return '';
     }
     foreach ($tag as $k => $v) {
         $tag[$k] = trim($v);
     }
     $field_name = $tag[0];
     $helper_name = $before = $after = '';
     if (isset($tag[1]) && !empty($tag[1])) {
         $value = $this->field($field_name);
         $helper_name = $tag[1];
         $value = $this->helper($helper_name, $value, $field_name);
     } else {
         $value = $this->display($field_name);
     }
     if (isset($tag[2]) && !empty($tag[2])) {
         $before = $tag[2];
     }
     if (isset($tag[3]) && !empty($tag[3])) {
         $after = $tag[3];
     }
     $value = apply_filters('pods_do_magic_tags', $value, $field_name, $helper_name, $before, $after);
     if (is_array($value)) {
         $value = pods_serial_comma($value, array('field' => $field_name, 'fields' => $this->fields));
     }
     if (null !== $value && false !== $value) {
         return $before . $value . $after;
     }
     return '';
 }
<?php

$person = pods('people', 'fred-flinstone');
$all_fields = $person->export();
if (!empty($all_fields)) {
    foreach ($all_fields as $field => $value) {
        // You can use pods_serial_comma to output values,
        // even if it's an array
        ?>
		<h2><?php 
        echo $person->fields[$field]['label'];
        ?>
</h2>
		<p>Value: <?php 
        echo pods_serial_comma($value, $field, $person->fields);
        ?>
</p>
		<br />
	<?php 
    }
} else {
    echo '<strong>No data found.</strong>';
}
Example #9
0
/**
 * Return a variable (if exists)
 *
 * @param mixed $var The variable name or URI segment position
 * @param string $type (optional) get|url|post|request|server|session|cookie|constant|globals|user|option|site-option|transient|site-transient|cache|date|pods
 * @param mixed $default (optional) The default value to set if variable doesn't exist
 * @param mixed $allowed (optional) The value(s) allowed
 * @param bool $strict (optional) Only allow values (must not be empty)
 * @param bool $casting (optional) Whether to cast the value returned like provided in $default
 * @param string $context (optional) All returned values are sanitized unless this is set to 'raw'
 *
 * @return mixed The variable (if exists), or default value
 * @since 1.10.6
 */
function pods_var($var = 'last', $type = 'get', $default = null, $allowed = null, $strict = false, $casting = false, $context = 'display')
{
    $output = null;
    if (is_array($type)) {
        $output = isset($type[$var]) ? $type[$var] : $default;
    } elseif (is_object($type)) {
        $output = isset($type->{$var}) ? $type->{$var} : $default;
    } else {
        $type = strtolower((string) $type);
        if ('get' == $type && isset($_GET[$var])) {
            $output = stripslashes_deep($_GET[$var]);
        } elseif (in_array($type, array('url', 'uri'))) {
            $url = parse_url(pods_current_url());
            $uri = trim($url['path'], '/');
            $uri = array_filter(explode('/', $uri));
            if ('first' == $var) {
                $var = 0;
            } elseif ('last' == $var) {
                $var = -1;
            }
            if (is_numeric($var)) {
                $output = $var < 0 ? pods_var_raw(count($uri) + $var, $uri) : pods_var_raw($var, $uri);
            }
        } elseif ('url-relative' == $type) {
            $url_raw = pods_current_url();
            $prefix = get_site_url();
            if (substr($url_raw, 0, strlen($prefix)) == $prefix) {
                $url_raw = substr($url_raw, strlen($prefix) + 1, strlen($url_raw));
            }
            $url = parse_url($url_raw);
            $uri = trim($url['path'], '/');
            $uri = array_filter(explode('/', $uri));
            if ('first' == $var) {
                $var = 0;
            } elseif ('last' == $var) {
                $var = -1;
            }
            if (is_numeric($var)) {
                $output = $var < 0 ? pods_var_raw(count($uri) + $var, $uri) : pods_var_raw($var, $uri);
            }
        } elseif ('template-url' == $type) {
            $output = get_template_directory_uri();
        } elseif ('stylesheet-url' == $type) {
            $output = get_stylesheet_directory_uri();
        } elseif (in_array($type, array('site-url', 'home-url', 'admin-url', 'includes-url', 'content-url', 'plugins-url', 'network-site-url', 'network-home-url', 'network-admin-url', 'user-admin-url'))) {
            if ('site-url' == $type) {
                $blog_id = $scheme = null;
                $path = '';
                if (is_array($var)) {
                    if (isset($var[0])) {
                        $blog_id = $var[0];
                    } elseif (isset($var[1])) {
                        $path = $var[1];
                    } elseif (isset($var[2])) {
                        $scheme = $var[2];
                    }
                } else {
                    $blog_id = $var;
                }
                $output = get_site_url($blog_id, $path, $scheme);
            } elseif ('home-url' == $type) {
                $blog_id = $scheme = null;
                $path = '';
                if (is_array($var)) {
                    if (isset($var[0])) {
                        $blog_id = $var[0];
                    } elseif (isset($var[1])) {
                        $path = $var[1];
                    } elseif (isset($var[2])) {
                        $scheme = $var[2];
                    }
                } else {
                    $blog_id = $var;
                }
                $output = get_home_url($blog_id, $path, $scheme);
            } elseif ('admin-url' == $type) {
                $blog_id = $scheme = null;
                $path = '';
                if (is_array($var)) {
                    if (isset($var[0])) {
                        $blog_id = $var[0];
                    } elseif (isset($var[1])) {
                        $path = $var[1];
                    } elseif (isset($var[2])) {
                        $scheme = $var[2];
                    }
                } else {
                    $blog_id = $var;
                }
                $output = get_admin_url($blog_id, $path, $scheme);
            } elseif ('includes-url' == $type) {
                $output = includes_url($var);
            } elseif ('content-url' == $type) {
                $output = content_url($var);
            } elseif ('plugins-url' == $type) {
                $path = $plugin = '';
                if (is_array($var)) {
                    if (isset($var[0])) {
                        $path = $var[0];
                    } elseif (isset($var[1])) {
                        $plugin = $var[1];
                    }
                } else {
                    $path = $var;
                }
                $output = plugins_url($path, $plugin);
            } elseif ('network-site-url' == $type) {
                $path = '';
                $scheme = null;
                if (is_array($var)) {
                    if (isset($var[0])) {
                        $path = $var[0];
                    } elseif (isset($var[1])) {
                        $scheme = $var[1];
                    }
                } else {
                    $path = $var;
                }
                $output = network_site_url($path, $scheme);
            } elseif ('network-home-url' == $type) {
                $path = '';
                $scheme = null;
                if (is_array($var)) {
                    if (isset($var[0])) {
                        $path = $var[0];
                    } elseif (isset($var[1])) {
                        $scheme = $var[1];
                    }
                } else {
                    $path = $var;
                }
                $output = network_home_url($path, $scheme);
            } elseif ('network-admin-url' == $type) {
                $path = '';
                $scheme = null;
                if (is_array($var)) {
                    if (isset($var[0])) {
                        $path = $var[0];
                    } elseif (isset($var[1])) {
                        $scheme = $var[1];
                    }
                } else {
                    $path = $var;
                }
                $output = network_admin_url($path, $scheme);
            } elseif ('user-admin-url' == $type) {
                $path = '';
                $scheme = null;
                if (is_array($var)) {
                    if (isset($var[0])) {
                        $path = $var[0];
                    } elseif (isset($var[1])) {
                        $scheme = $var[1];
                    }
                } else {
                    $path = $var;
                }
                $output = user_admin_url($path, $scheme);
            }
        } elseif ('post' == $type && isset($_POST[$var])) {
            $output = stripslashes_deep($_POST[$var]);
        } elseif ('request' == $type && isset($_REQUEST[$var])) {
            $output = stripslashes_deep($_REQUEST[$var]);
        } elseif ('server' == $type) {
            if (isset($_SERVER[$var])) {
                $output = stripslashes_deep($_SERVER[$var]);
            } elseif (isset($_SERVER[strtoupper($var)])) {
                $output = stripslashes_deep($_SERVER[strtoupper($var)]);
            }
        } elseif ('session' == $type && isset($_SESSION[$var])) {
            $output = $_SESSION[$var];
        } elseif (in_array($type, array('global', 'globals')) && isset($GLOBALS[$var])) {
            $output = $GLOBALS[$var];
        } elseif ('cookie' == $type && isset($_COOKIE[$var])) {
            $output = stripslashes_deep($_COOKIE[$var]);
        } elseif ('constant' == $type && defined($var)) {
            $output = constant($var);
        } elseif ('user' == $type && is_user_logged_in()) {
            $user = get_userdata(get_current_user_id());
            if (isset($user->{$var})) {
                $value = $user->{$var};
            } else {
                $value = get_user_meta($user->ID, $var);
            }
            if (is_array($value) && !empty($value)) {
                $output = $value;
            } elseif (!is_array($value) && 0 < strlen($value)) {
                $output = $value;
            }
        } elseif ('option' == $type) {
            $output = get_option($var, $default);
        } elseif ('site-option' == $type) {
            $output = get_site_option($var, $default);
        } elseif ('transient' == $type) {
            $output = get_transient($var);
        } elseif ('site-transient' == $type) {
            $output = get_site_transient($var);
        } elseif ('cache' == $type && isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache'])) {
            $group = 'default';
            $force = false;
            if (is_array($var)) {
                if (isset($var[1])) {
                    $group = $var[1];
                }
                if (isset($var[2])) {
                    $force = $var[2];
                }
                if (isset($var[0])) {
                    $var = $var[0];
                }
            }
            $output = wp_cache_get($var, $group, $force);
        } elseif ('date' == $type) {
            $var = explode('|', $var);
            if (!empty($var)) {
                $output = date_i18n($var[0], isset($var[1]) ? strtotime($var[1]) : false);
            }
        } elseif ('pods' == $type) {
            if (isset($GLOBALS['pods']) && 'Pods' == get_class($GLOBALS['pods'])) {
                $output = $GLOBALS['pods']->field($var);
                if (is_array($output)) {
                    $output = pods_serial_comma($output, array('field' => $var, 'fields' => $GLOBALS['pods']->fields));
                }
            }
        } else {
            $output = apply_filters('pods_var_' . $type, $default, $var, $allowed, $strict, $casting, $context);
        }
    }
    if (null !== $allowed) {
        if (is_array($allowed)) {
            if (!in_array($output, $allowed)) {
                $output = $default;
            }
        } elseif ($allowed !== $output) {
            $output = $default;
        }
    }
    if (true === $strict) {
        if (empty($output)) {
            $output = $default;
        } elseif (true === $casting) {
            $output = pods_cast($output, $default);
        }
    }
    if ('raw' != $context) {
        $output = pods_sanitize($output);
    }
    return $output;
}
 /**
  * Update relationships
  *
  * @since 0.3.0 ?
  *
  * @return bool
  */
 private static function do_deploy_relationships($deploy_types = null)
 {
     $fail = false;
     $responses = array();
     $data = Pods_Deploy::get_relationships($deploy_types);
     if ($data === false) {
         // Don't try to deploy relationships if there aren't any
         return false;
     }
     $pods_api_url = trailingslashit(self::$remote_url) . 'pods-api/';
     $pod_name = pods_serial_comma(self::get_names_by_relationships($data));
     $url = $pods_api_url . "update_rel";
     $url = Pods_Deploy_Auth::add_to_url(self::$public_key, self::$token, $url);
     $responses[] = $response = wp_remote_post($url, array('method' => 'POST', 'body' => json_encode($data), 'timeout' => self::$timeout));
     if (self::check_return($response)) {
         echo self::output_message(__(sprintf('Relationships for the %1s Pod were updated.', $pod_name), 'pods-deploy'), $url);
     } else {
         $fail = true;
         echo self::output_message(__(sprintf('Relationships for the %1s Pod were not updated.', $pod_name), 'pods-deploy'), $url, true, false);
     }
     return $fail;
 }