/**
* @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
}