function wizard_form($data = null, $name = null, $data_name, $data_text, $checked = true)
{
    if (!empty($data)) {
        ?>
		<div class="stuffbox pods-package-import-group">
			<h3><label for="link_name"><?php 
        _e($data_text, 'pods');
        ?>
</label></h3>

			<div class="inside pods-manage-field pods-dependency">
				<div class="pods-field-option-group">
					<p>
						<a href="#toggle" class="button pods-wizard-toggle-all"
						   data-toggle="<?php 
        echo $data_name;
        ?>
"><?php 
        _e('Toggle all on / off', 'pods');
        ?>
</a>
					</p>

					<div class="pods-pick-values pods-pick-checkbox pods-zebra">
						<ul>
							<?php 
        $zebra = false;
        foreach ($data as $item) {
            $class = $zebra ? 'even' : 'odd';
            $zebra = !$zebra;
            ?>
								<li class="pods-zebra-<?php 
            echo $class;
            ?>
">
									<?php 
            echo PodsForm::field($data_name . '[' . $item[$name] . ']', $checked, 'boolean', array('boolean_yes_label' => $item['name'] . (!empty($item['label']) ? ' (' . $item['label'] . ')' : '')));
            ?>
								</li>
							<?php 
        }
        ?>
						</ul>
					</div>
				</div>
			</div>
		</div>
<?php 
    }
}
Example #2
0
 /**
  *
  * Generate UI for Data Management
  *
  * @param mixed $options Array or String containing Pod or Options to be used
  * @param bool $amend Whether to amend the default UI options or replace entirely
  *
  * @return PodsUI|void UI object or void if custom UI used
  *
  * @since 2.3.10
  */
 public function ui($options = null, $amend = false)
 {
     $num = '';
     if (empty($options)) {
         $options = array();
     } else {
         $num = pods_var('num', $options, '');
         if (empty($num)) {
             $num = '';
         }
     }
     if ($this->id() != pods_var('id' . $num, 'get', null, null, true)) {
         $this->fetch(pods_var('id' . $num, 'get', null, null, true));
     }
     if (!empty($options) && !$amend) {
         $this->ui = $options;
         return pods_ui($this);
     } elseif (!empty($options) || 'custom' != pods_var('ui_style', $this->pod_data['options'], 'post_type', null, true)) {
         $actions_enabled = pods_var_raw('ui_actions_enabled', $this->pod_data['options']);
         if (!empty($actions_enabled)) {
             $actions_enabled = (array) $actions_enabled;
         } else {
             $actions_enabled = array();
         }
         $available_actions = array('add', 'edit', 'duplicate', 'delete', 'reorder', 'export');
         if (!empty($actions_enabled)) {
             $actions_disabled = array('view' => 'view');
             foreach ($available_actions as $action) {
                 if (!in_array($action, $actions_enabled)) {
                     $actions_disabled[$action] = $action;
                 }
             }
         } else {
             $actions_disabled = array('duplicate' => 'duplicate', 'view' => 'view', 'export' => 'export');
             if (1 == pods_var('ui_export', $this->pod_data['options'], 0)) {
                 unset($actions_disabled['export']);
             }
         }
         if (empty($options)) {
             $author_restrict = false;
             if (isset($this->fields['author']) && 'pick' == $this->fields['author']['type'] && 'user' == $this->fields['author']['pick_object']) {
                 $author_restrict = 'author.ID';
             }
             if (!pods_is_admin(array('pods', 'pods_content'))) {
                 if (!current_user_can('pods_add_' . $this->pod)) {
                     $actions_disabled['add'] = 'add';
                     if ('add' == pods_var('action' . $num, 'get')) {
                         $_GET['action' . $num] = 'manage';
                     }
                 }
                 if (!$author_restrict && !current_user_can('pods_edit_' . $this->pod) && !current_user_can('pods_edit_others_' . $this->pod)) {
                     $actions_disabled['edit'] = 'edit';
                 }
                 if (!$author_restrict && !current_user_can('pods_delete_' . $this->pod) && !current_user_can('pods_delete_others_' . $this->pod)) {
                     $actions_disabled['delete'] = 'delete';
                 }
                 if (!current_user_can('pods_reorder_' . $this->pod)) {
                     $actions_disabled['reorder'] = 'reorder';
                 }
                 if (!current_user_can('pods_export_' . $this->pod)) {
                     $actions_disabled['export'] = 'export';
                 }
             }
         }
         $_GET['action' . $num] = pods_var('action' . $num, 'get', pods_var('action', $options, 'manage'));
         $index = $this->pod_data['field_id'];
         $label = __('ID', 'pods');
         if (isset($this->pod_data['fields'][$this->pod_data['field_index']])) {
             $index = $this->pod_data['field_index'];
             $label = $this->pod_data['fields'][$this->pod_data['field_index']];
         }
         $manage = array($index => $label);
         if (isset($this->pod_data['fields']['modified'])) {
             $manage['modified'] = $this->pod_data['fields']['modified']['label'];
         }
         $manage_fields = pods_var_raw('ui_fields_manage', $this->pod_data['options']);
         if (!empty($manage_fields)) {
             $manage_new = array();
             foreach ($manage_fields as $manage_field) {
                 if (isset($this->pod_data['fields'][$manage_field])) {
                     $manage_new[$manage_field] = $this->pod_data['fields'][$manage_field];
                 } elseif (isset($this->pod_data['object_fields'][$manage_field])) {
                     $manage_new[$manage_field] = $this->pod_data['object_fields'][$manage_field];
                 } elseif ($manage_field == $this->pod_data['field_id']) {
                     $field = array('name' => $manage_field, 'label' => 'ID', 'type' => 'number', 'width' => '8%');
                     $manage_new[$manage_field] = PodsForm::field_setup($field, null, $field['type']);
                 }
             }
             if (!empty($manage_new)) {
                 $manage = $manage_new;
             }
         }
         $manage = apply_filters('pods_admin_ui_fields_' . $this->pod, apply_filters('pods_admin_ui_fields', $manage, $this->pod, $this), $this->pod, $this);
         $icon = pods_var_raw('ui_icon', $this->pod_data['options']);
         if (!empty($icon)) {
             $icon = pods_image_url($icon, '32x32');
         }
         $filters = pods_var_raw('ui_filters', $this->pod_data['options']);
         if (!empty($filters)) {
             $filters_new = array();
             foreach ($filters as $filter_field) {
                 if (isset($this->pod_data['fields'][$filter_field])) {
                     $filters_new[$filter_field] = $this->pod_data['fields'][$filter_field];
                 } elseif (isset($this->pod_data['object_fields'][$filter_field])) {
                     $filters_new[$filter_field] = $this->pod_data['object_fields'][$filter_field];
                 }
             }
             $filters = $filters_new;
         }
         $ui = array('fields' => array('manage' => $manage, 'add' => $this->pod_data['fields'], 'edit' => $this->pod_data['fields'], 'duplicate' => $this->pod_data['fields']), 'icon' => $icon, 'actions_disabled' => $actions_disabled);
         if (!empty($filters)) {
             $ui['fields']['search'] = $filters;
             $ui['filters'] = array_keys($filters);
             $ui['filters_enhanced'] = true;
         }
         $reorder_field = pods_var_raw('ui_reorder_field', $this->pod_data['options']);
         if (in_array('reorder', $actions_enabled) && !in_array('reorder', $actions_disabled) && !empty($reorder_field) && (!empty($this->pod_data['object_fields']) && isset($this->pod_data['object_fields'][$reorder_field]) || isset($this->pod_data['fields'][$reorder_field]))) {
             $ui['reorder'] = array('on' => $reorder_field);
             $ui['orderby'] = $reorder_field;
             $ui['orderby_dir'] = 'ASC';
         }
         if (!empty($author_restrict)) {
             $ui['restrict'] = array('author_restrict' => $author_restrict);
         }
         if (!in_array('delete', $ui['actions_disabled'])) {
             $ui['actions_bulk'] = array('delete' => array('label' => __('Delete', 'pods')));
         }
         $detail_url = pods_var('detail_url', $this->pod_data['options']);
         if (0 < strlen($detail_url)) {
             $ui['actions_custom'] = array('view_url' => array('label' => 'View', 'link' => get_site_url() . '/' . $detail_url));
         }
         // @todo Customize the Add New / Manage links to point to their correct menu items
         $ui = apply_filters('pods_admin_ui_' . $this->pod, apply_filters('pods_admin_ui', $ui, $this->pod, $this), $this->pod, $this);
         // Override UI options
         foreach ($options as $option => $value) {
             $ui[$option] = $value;
         }
         $this->ui = $ui;
         return pods_ui($this);
     }
     do_action('pods_admin_ui_custom', $this);
     do_action('pods_admin_ui_custom_' . $this->pod, $this);
 }
Example #3
0
 /**
  * Get a list of all available field types and include
  *
  * @return array Registered Field Types data
  *
  * @since 2.3
  */
 public static function field_types()
 {
     $field_types = array('text', 'website', 'phone', 'email', 'password', 'paragraph', 'wysiwyg', 'code', 'datetime', 'date', 'time', 'number', 'currency', 'file', 'avatar', 'pick', 'boolean', 'color', 'slug');
     $field_types = array_merge($field_types, array_keys(self::$field_types));
     $field_types = array_filter(array_unique($field_types));
     $types = apply_filters('pods_api_field_types', $field_types);
     $field_types = pods_transient_get('pods_field_types');
     if (empty($field_types) || count($types) != count($field_types)) {
         $field_types = array();
         foreach ($types as $field_type) {
             $file = null;
             if (isset(self::$field_types[$field_type])) {
                 $file = self::$field_types[$field_type]['file'];
             }
             self::field_loader($field_type, $file);
             if (!isset(self::$loaded[$field_type]) || !is_object(self::$loaded[$field_type])) {
                 continue;
             }
             $class_vars = get_class_vars(get_class(self::$loaded[$field_type]));
             // PHP 5.2.x workaround
             $field_types[$field_type] = $class_vars;
             $field_types[$field_type]['file'] = $file;
         }
         self::$field_types = $field_types;
         pods_transient_set('pods_field_types', self::$field_types);
     } else {
         self::$field_types = array_merge($field_types, self::$field_types);
     }
     return self::$field_types;
 }
<?php

$type = 'textarea';
$attributes = array();
$attributes['tabindex'] = 2;
$attributes = PodsForm::merge_attributes($attributes, $name, $form_field_type, $options);
if (pods_var('readonly', $options, false)) {
    $attributes['readonly'] = 'READONLY';
    $attributes['class'] .= ' pods-form-ui-read-only';
}
?>
    <textarea<?php 
PodsForm::attributes($attributes, $name, $form_field_type, $options);
?>
><?php 
echo esc_textarea($value);
?>
</textarea>
<?php 
PodsForm::regex($form_field_type, $options);
<?php

wp_enqueue_script('pods-codemirror');
wp_enqueue_style('pods-codemirror');
wp_enqueue_script('pods-codemirror-loadmode');
$type = 'textarea';
$attributes = array();
$attributes['tabindex'] = 2;
$attributes = PodsForm::merge_attributes($attributes, $name, $form_field_type, $options, 'pods-ui-field-codemirror');
?>
<div class="code-toolbar"><!-- Placeholder --></div>
<textarea<?php 
PodsForm::attributes($attributes, $name, $form_field_type, $options);
?>
><?php 
echo esc_textarea($value);
?>
</textarea>
<div class="code-footer"><!-- Placeholder --></div>

<script>
    var $textarea_<?php 
echo esc_js(pods_js_name($attributes['id']));
?>
, codemirror_<?php 
echo esc_js(pods_js_name($attributes['id']));
?>
;

    jQuery( function ( $ ) {
        $textarea_<?php 
Example #6
0
    $plupload_init['filters'][0]['extensions'] = $limit_types;
}
if (is_admin() && !empty($post_ID)) {
    $plupload_init['multipart_params']['post_id'] = (int) $post_ID;
} elseif (is_object($pod) && in_array($pod->pod_data['type'], array('post_type', 'media')) && 0 < $id) {
    $plupload_init['multipart_params']['post_id'] = (int) $id;
}
$plupload_init = apply_filters('plupload_init', $plupload_init);
if (empty($value)) {
    $value = array();
} else {
    $value = (array) $value;
}
?>
<div<?php 
PodsForm::attributes(array('class' => $attributes['class'], 'id' => $attributes['id']), $name, $form_field_type, $options);
?>
>
    <ul class="pods-files pods-files-list"><?php 
// no extra space in ul or CSS:empty won't work
foreach ($value as $val) {
    $attachment = get_post($val);
    if (empty($attachment)) {
        continue;
    }
    $thumb = wp_get_attachment_image_src($val, 'thumbnail', true);
    $title = $attachment->post_title;
    if (0 == $title_editable) {
        $title = basename($attachment->guid);
    }
    echo $field_file->markup($attributes, $file_limit, $title_editable, $val, $thumb[0], $title);
Example #7
0
 /**
  * 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::simple_tableless_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;
 }
    /**
     * @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 
    }
Example #9
0
                                            <div class="pods-pick-values pods-pick-checkbox pods-zebra">
                                                <ul>
                                                    <?php 
    $zebra = false;
    foreach ($data as $item) {
        $checked = true;
        $class = $zebra ? 'even' : 'odd';
        $zebra = !$zebra;
        ?>
                                                        <li class="pods-zebra-<?php 
        echo $class;
        ?>
">
                                                            <?php 
        echo PodsForm::field($data_name . '[' . $item['id'] . ']', $checked, 'boolean', array('boolean_yes_label' => $item['name'] . (!empty($item['label']) ? ' (' . $item['label'] . ')' : '')));
        ?>
                                                        </li>
                                                    <?php 
    }
    ?>
                                                </ul>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            <?php 
}
do_action('pods_packages_export_options', $pods, $pod_templates, $pod_pages, $pod_helpers);
?>
                        </div>
Example #10
0
            <?php 
    } else {
        $option_label = (string) $option_label;
        $selected = '';
        $options['selected'] = '';
        if (!$selection_made && (!is_array($value) && (string) $option_value === (string) $value || is_array($value) && (in_array($option_value, $value) || in_array((string) $option_value, $value)))) {
            $selected = ' SELECTED';
            $options['selected'] = 'selected';
            if (!$multiple) {
                $selection_made = true;
            }
        }
        if (is_array($option_value)) {
            ?>
                <option<?php 
            PodsForm::attributes($option_value, $name, $form_field_type . '_option', $options);
            ?>
><?php 
            echo esc_html($option_label);
            ?>
</option>
                <?php 
        } else {
            ?>
                <option value="<?php 
            echo esc_attr($option_value);
            ?>
"<?php 
            echo $selected;
            ?>
><?php 
                                <?php 
        foreach ($field_option['group'] as $field_group_name => $field_group_option) {
            $field_group_option = PodsForm::field_setup($field_group_option, null, $field_group_option['type']);
            if ('boolean' != $field_group_option['type']) {
                continue;
            }
            $field_group_option['boolean_yes_label'] = $field_group_option['label'];
            $depends_option = PodsForm::dependencies($field_group_option);
            $value = pods_var_raw($field_group_name, $settings, $field_group_option['default']);
            ?>
                                    <li class="<?php 
            echo $depends_option;
            ?>
">
                                        <?php 
            echo PodsForm::field('pods_setting_' . $field_group_name, $value, $field_group_option['type'], $field_group_option);
            ?>
                                    </li>
                                <?php 
        }
        ?>
                            </ul>
                        </td>
                    </tr>
                <?php 
    }
    if (false !== $depends_on || !empty($depends)) {
        $depends_on = $depends;
    }
}
if (!empty($depends_on)) {
 /**
  * Customize output of the form field
  *
  * @param string $name
  * @param mixed $value
  * @param array $options
  * @param array $pod
  * @param int $id
  *
  * @since 2.0
  */
 public function input($name, $value = null, $options = null, $pod = null, $id = null)
 {
     $options = (array) $options;
     $form_field_type = PodsForm::$field_type;
     if (is_array($value)) {
         $value = implode("\n", $value);
     }
     if (isset($options['name']) && false === PodsForm::permission(self::$type, $options['name'], $options, null, $pod, $id)) {
         if (pods_var('read_only', $options, false)) {
             $options['readonly'] = true;
             $field_type = 'textarea';
         } else {
             return;
         }
     } elseif (!pods_has_permissions($options) && pods_var('read_only', $options, false)) {
         $options['readonly'] = true;
         $field_type = 'textarea';
     } elseif ('tinymce' == pods_var(self::$type . '_editor', $options)) {
         $field_type = 'tinymce';
     } elseif ('cleditor' == pods_var(self::$type . '_editor', $options)) {
         $field_type = 'cleditor';
     } else {
         // Support custom WYSIWYG integration
         do_action('pods_form_ui_field_wysiwyg_' . pods_var(self::$type . '_editor', $options), $name, $value, $options, $pod, $id);
         do_action('pods_form_ui_field_wysiwyg', pods_var(self::$type . '_editor', $options), $name, $value, $options, $pod, $id);
         return;
     }
     pods_view(PODS_DIR . 'ui/fields/' . $field_type . '.php', compact(array_keys(get_defined_vars())));
 }
<label<?php 
PodsForm::attributes($attributes, $name, 'label');
?>
>
    <?php 
echo $label;
if (1 == pods_var('required', $options, pods_var('options', $options, $options))) {
    echo ' <abbr title="required" class="required">*</abbr>';
}
if (0 == pods_var('grouped', $options, 0, null, true) && !empty($help) && 'help' != $help) {
    pods_help($help);
}
?>
</label>
Example #14
0
					</p>

					<div class="pods-pick-values pods-pick-checkbox pods-zebra">
						<ul>
							<?php 
$zebra = false;
foreach ($this->exportable_pods() as $this_pod) {
    $class = $zebra ? 'even' : 'odd';
    $zebra = !$zebra;
    ?>
								<li class="pods-zebra-<?php 
    echo $class;
    ?>
">
									<?php 
    echo PodsForm::field($this_pod['name'], true, 'boolean', array('boolean_yes_label' => $this_pod['name'] . (!empty($this_pod['label']) ? ' (' . $this_pod['label'] . ')' : '')));
    ?>
								</li>
							<?php 
}
?>
						</ul>
					</div>
					<div class="submit">
						<a class="button button-primary" id="export" href="#"> Export </a>
					</div>
					<textarea id="feedback"></textarea>
				</div>
			</div>
		</div>
	</form>
Example #15
0
 /**
  * Handle plupload AJAX
  *
  * @since 2.3
  */
 public function admin_ajax_upload()
 {
     if (false === headers_sent()) {
         if ('' == session_id()) {
             @session_start();
         }
     }
     // Sanitize input
     $params = stripslashes_deep((array) $_POST);
     foreach ($params as $key => $value) {
         if ('action' == $key) {
             continue;
         }
         unset($params[$key]);
         $params[str_replace('_podsfix_', '', $key)] = $value;
     }
     $params = (object) $params;
     $methods = array('upload');
     if (!isset($params->method) || !in_array($params->method, $methods) || !isset($params->pod) || !isset($params->field) || !isset($params->uri) || empty($params->uri)) {
         pods_error('Invalid AJAX request', PodsInit::$admin);
     } elseif (!empty($params->pod) && empty($params->field)) {
         pods_error('Invalid AJAX request', PodsInit::$admin);
     } elseif (empty($params->pod) && !current_user_can('upload_files')) {
         pods_error('Invalid AJAX request', PodsInit::$admin);
     }
     // Flash often fails to send cookies with the POST or upload, so we need to pass it in GET or POST instead
     if (is_ssl() && empty($_COOKIE[SECURE_AUTH_COOKIE]) && !empty($_REQUEST['auth_cookie'])) {
         $_COOKIE[SECURE_AUTH_COOKIE] = $_REQUEST['auth_cookie'];
     } elseif (empty($_COOKIE[AUTH_COOKIE]) && !empty($_REQUEST['auth_cookie'])) {
         $_COOKIE[AUTH_COOKIE] = $_REQUEST['auth_cookie'];
     }
     if (empty($_COOKIE[LOGGED_IN_COOKIE]) && !empty($_REQUEST['logged_in_cookie'])) {
         $_COOKIE[LOGGED_IN_COOKIE] = $_REQUEST['logged_in_cookie'];
     }
     global $current_user;
     unset($current_user);
     /**
      * Access Checking
      */
     $upload_disabled = false;
     if (defined('PODS_DISABLE_FILE_UPLOAD') && true === PODS_DISABLE_FILE_UPLOAD) {
         $upload_disabled = true;
     } elseif (defined('PODS_UPLOAD_REQUIRE_LOGIN') && is_bool(PODS_UPLOAD_REQUIRE_LOGIN) && true === PODS_UPLOAD_REQUIRE_LOGIN && !is_user_logged_in()) {
         $upload_disabled = true;
     } elseif (defined('PODS_UPLOAD_REQUIRE_LOGIN') && !is_bool(PODS_UPLOAD_REQUIRE_LOGIN) && (!is_user_logged_in() || !current_user_can(PODS_UPLOAD_REQUIRE_LOGIN))) {
         $upload_disabled = true;
     }
     $uid = @session_id();
     if (is_user_logged_in()) {
         $uid = 'user_' . get_current_user_id();
     }
     $nonce_check = 'pods_upload_' . (int) $params->pod . '_' . $uid . '_' . $params->uri . '_' . (int) $params->field;
     if (true === $upload_disabled || !isset($params->_wpnonce) || false === wp_verify_nonce($params->_wpnonce, $nonce_check)) {
         pods_error(__('Unauthorized request', 'pods'), PodsInit::$admin);
     }
     $pod = array();
     $field = array('type' => 'file', 'options' => array());
     $api = pods_api();
     if (!empty($params->pod)) {
         $pod = $api->load_pod(array('id' => (int) $params->pod));
         $field = $api->load_field(array('id' => (int) $params->field));
         if (empty($pod) || empty($field) || $pod['id'] != $field['pod_id'] || !isset($pod['fields'][$field['name']])) {
             pods_error(__('Invalid field request', 'pods'), PodsInit::$admin);
         }
         if (!in_array($field['type'], PodsForm::file_field_types())) {
             pods_error(__('Invalid field', 'pods'), PodsInit::$admin);
         }
     }
     $method = $params->method;
     // Cleaning up $params
     unset($params->action);
     unset($params->method);
     unset($params->_wpnonce);
     $params->post_id = pods_var('post_id', $params, 0, null, true);
     /**
      * Upload a new file (advanced - returns URL and ID)
      */
     if ('upload' == $method) {
         $file = $_FILES['Filedata'];
         $limit_size = pods_var($field['type'] . '_restrict_filesize', $field['options']);
         if (!empty($limit_size)) {
             if (false !== stripos($limit_size, 'MB')) {
                 $limit_size = (double) trim(str_ireplace('MB', '', $limit_size));
                 $limit_size = $limit_size * 1025 * 1025;
                 // convert to KB to B
             } elseif (false !== stripos($limit_size, 'KB')) {
                 $limit_size = (double) trim(str_ireplace('KB', '', $limit_size));
                 $limit_size = $limit_size * 1025 * 1025;
                 // convert to B
             } elseif (false !== stripos($limit_size, 'GB')) {
                 $limit_size = (double) trim(str_ireplace('GB', '', $limit_size));
                 $limit_size = $limit_size * 1025 * 1025 * 1025;
                 // convert to MB to KB to B
             } elseif (false !== stripos($limit_size, 'B')) {
                 $limit_size = (double) trim(str_ireplace('B', '', $limit_size));
             } else {
                 $limit_size = wp_max_upload_size();
             }
             if (0 < $limit_size && $limit_size < $file['size']) {
                 $error = __('File size too large, max size is %s', 'pods');
                 $error = sprintf($error, pods_var($field['type'] . '_restrict_filesize', $field['options']));
                 pods_error('<div style="color:#FF0000">Error: ' . $error . '</div>');
             }
         }
         $limit_file_type = pods_var($field['type'] . '_type', $field['options'], 'images');
         if ('images' == $limit_file_type) {
             $limit_types = 'jpg,png,gif';
         } elseif ('video' == $limit_file_type) {
             $limit_types = 'mpg,mov,flv,mp4';
         } elseif ('audio' == $limit_file_type) {
             $limit_types = 'mp3,m4a,wav,wma';
         } elseif ('text' == $limit_file_type) {
             $limit_types = 'txt,rtx,csv,tsv';
         } elseif ('any' == $limit_file_type) {
             $limit_types = '';
         } else {
             $limit_types = pods_var($field['type'] . '_allowed_extensions', $field['options'], '', null, true);
         }
         $limit_types = trim(str_replace(array(' ', '.', "\n", "\t", ';'), array('', ',', ',', ','), $limit_types), ',');
         if (pods_version_check('wp', '3.5')) {
             $mime_types = wp_get_mime_types();
             if (in_array($limit_file_type, array('images', 'audio', 'video'))) {
                 $new_limit_types = array();
                 foreach ($mime_types as $type => $mime) {
                     if (0 === strpos($mime, $limit_file_type)) {
                         $type = explode('|', $type);
                         $new_limit_types = array_merge($new_limit_types, $type);
                     }
                 }
                 if (!empty($new_limit_types)) {
                     $limit_types = implode(',', $new_limit_types);
                 }
             } elseif ('any' != $limit_file_type) {
                 $new_limit_types = array();
                 $limit_types = explode(',', $limit_types);
                 foreach ($limit_types as $k => $limit_type) {
                     $found = false;
                     foreach ($mime_types as $type => $mime) {
                         if (0 === strpos($mime, $limit_type)) {
                             $type = explode('|', $type);
                             foreach ($type as $t) {
                                 if (!in_array($t, $new_limit_types)) {
                                     $new_limit_types[] = $t;
                                 }
                             }
                             $found = true;
                         }
                     }
                     if (!$found) {
                         $new_limit_types[] = $limit_type;
                     }
                 }
                 if (!empty($new_limit_types)) {
                     $limit_types = implode(',', $new_limit_types);
                 }
             }
         }
         $limit_types = explode(',', $limit_types);
         $limit_types = array_filter(array_unique($limit_types));
         if (!empty($limit_types)) {
             $ok = false;
             foreach ($limit_types as $limit_type) {
                 $limit_type = '.' . trim($limit_type, ' .');
                 $pos = strlen($file['name']) - strlen($limit_type);
                 if ($pos === stripos($file['name'], $limit_type)) {
                     $ok = true;
                     break;
                 }
             }
             if (false === $ok) {
                 $error = __('File type not allowed, please use one of the following: %s', 'pods');
                 $error = sprintf($error, '.' . implode(', .', $limit_types));
                 pods_error('<div style="color:#FF0000">Error: ' . $error . '</div>');
             }
         }
         $custom_handler = apply_filters('pods_upload_handle', null, 'Filedata', $params->post_id, $params);
         if (null === $custom_handler) {
             $attachment_id = media_handle_upload('Filedata', $params->post_id);
             if (is_object($attachment_id)) {
                 $errors = array();
                 foreach ($attachment_id->errors['upload_error'] as $error_code => $error_message) {
                     $errors[] = '[' . $error_code . '] ' . $error_message;
                 }
                 pods_error('<div style="color:#FF0000">Error: ' . implode('</div><div>', $errors) . '</div>');
             } else {
                 $attachment = get_post($attachment_id, ARRAY_A);
                 $attachment['filename'] = basename($attachment['guid']);
                 $thumb = wp_get_attachment_image_src($attachment['ID'], 'thumbnail', true);
                 $attachment['thumbnail'] = $thumb[0];
                 $attachment = apply_filters('pods_upload_attachment', $attachment, $params->post_id);
                 wp_send_json($attachment);
             }
         }
     }
     die;
     // KBAI!
 }
Example #16
0
 /**
  * Get list of Pod field options
  *
  * @return array
  */
 public function admin_setup_edit_field_options($pod)
 {
     $options = array();
     $options['additional-field'] = array();
     $field_types = PodsForm::field_types();
     foreach ($field_types as $type => $field_type_data) {
         /**
          * @var $field_type PodsField
          */
         $field_type = PodsForm::field_loader($type, $field_type_data['file']);
         $field_type_vars = get_class_vars(get_class($field_type));
         if (!isset($field_type_vars['pod_types'])) {
             $field_type_vars['pod_types'] = true;
         }
         $options['additional-field'][$type] = array();
         // Only show supported field types
         if (true !== $field_type_vars['pod_types']) {
             if (empty($field_type_vars['pod_types'])) {
                 continue;
             } elseif (is_array($field_type_vars['pod_types']) && !in_array(pods_var('type', $pod), $field_type_vars['pod_types'])) {
                 continue;
             } elseif (!is_array($field_type_vars['pod_types']) && pods_var('type', $pod) != $field_type_vars['pod_types']) {
                 continue;
             }
         }
         $options['additional-field'][$type] = PodsForm::ui_options($type);
     }
     $input_helpers = array('' => '-- Select --');
     if (class_exists('Pods_Helpers')) {
         $helpers = pods_api()->load_helpers(array('options' => array('helper_type' => 'input')));
         foreach ($helpers as $helper) {
             $input_helpers[$helper['name']] = $helper['name'];
         }
     }
     $options['advanced'] = array(__('Visual', 'pods') => array('class' => array('name' => 'class', 'label' => __('Additional CSS Classes', 'pods'), 'help' => __('help', 'pods'), 'type' => 'text', 'default' => ''), 'input_helper' => array('name' => 'input_helper', 'label' => __('Input Helper', 'pods'), 'help' => __('help', 'pods'), 'type' => 'pick', 'default' => '', 'data' => $input_helpers)), __('Values', 'pods') => array('default_value' => array('name' => 'default_value', 'label' => __('Default Value', 'pods'), 'help' => __('help', 'pods'), 'type' => 'text', 'default' => ''), 'default_value_parameter' => array('name' => 'default_value_parameter', 'label' => __('Set Default Value via Parameter', 'pods'), 'help' => __('help', 'pods'), 'type' => 'text', 'default' => '')), __('Visibility', 'pods') => array('restrict_access' => array('name' => 'restrict_access', 'label' => __('Restrict Access', 'pods'), 'group' => array('admin_only' => array('name' => 'admin_only', 'label' => __('Restrict access to Admins?', 'pods'), 'default' => 0, 'type' => 'boolean', 'dependency' => true, 'help' => __('This field will only be able to be edited by users with the ability to manage_options or delete_users, or super admins of a WordPress Multisite network', 'pods')), 'restrict_role' => array('name' => 'restrict_role', 'label' => __('Restrict access by Role?', 'pods'), 'default' => 0, 'type' => 'boolean', 'dependency' => true), 'restrict_capability' => array('name' => 'restrict_capability', 'label' => __('Restrict access by Capability?', 'pods'), 'default' => 0, 'type' => 'boolean', 'dependency' => true), 'hidden' => array('name' => 'hidden', 'label' => __('Hide field from UI', 'pods'), 'default' => 0, 'type' => 'boolean', 'help' => __('This option is overriden by access restrictions. If the user does not have access to edit this field, it will be hidden. If no access restrictions are set, this field will always be hidden.', 'pods')), 'read_only' => array('name' => 'read_only', 'label' => __('Make field "Read Only" in UI', 'pods'), 'default' => 0, 'type' => 'boolean', 'help' => __('This option is overriden by access restrictions. If the user does not have access to edit this field, it will be read only. If no access restrictions are set, this field will always be read only.', 'pods'), 'depends-on' => array('type' => array('boolean', 'color', 'currency', 'date', 'datetime', 'email', 'number', 'paragraph', 'password', 'phone', 'slug', 'text', 'time', 'website'))))), 'roles_allowed' => array('name' => 'roles_allowed', 'label' => __('Role(s) Allowed', 'pods'), 'help' => __('help', 'pods'), 'type' => 'pick', 'pick_object' => 'role', 'pick_format_type' => 'multi', 'default' => 'administrator', 'depends-on' => array('restrict_role' => true)), 'capability_allowed' => array('name' => 'capability_allowed', 'label' => __('Capability Allowed', 'pods'), 'help' => __('Comma-separated list of cababilities, for example add_podname_item, please see the Roles and Capabilities component for the complete list and a way to add your own.', 'pods'), 'type' => 'text', 'default' => '', 'depends-on' => array('restrict_capability' => true))));
     if (!class_exists('Pods_Helpers')) {
         unset($options['advanced-options']['input_helper']);
     }
     $options = apply_filters('pods_admin_setup_edit_field_options', $options, $pod);
     return $options;
 }
Example #17
0
    ?>
    <div class="pods-field pods-boolean"<?php 
    echo $indent;
    ?>
>
        <input<?php 
    PodsForm::attributes($attributes, $name, $form_field_type, $options);
    ?>
 />
        <?php 
    if (0 < strlen($label)) {
        $help = pods_var_raw('help', $options);
        if (1 == pods_var('grouped', $options, 0, null, true) || empty($help)) {
            $help = '';
        }
        echo PodsForm::label($attributes['id'], $label, $help);
    }
    ?>
    </div>
    <?php 
    if (1 == pods_var('grouped', $options, 0, null, true)) {
        ?>
        </li>
<?php 
    }
    $counter++;
}
if (1 == pods_var('grouped', $options, 0, null, true)) {
    ?>
    </ul>
</div>
            if (!isset($pods_tab_form)) {
                $row_name = 'field_data[' . $pods_i . '][' . $field_group_name . ']';
            }
            $value = $field_group_option['default'];
            if (isset($field_group_option['value']) && 0 < strlen($field_group_option['value'])) {
                $value = $field_group_option['value'];
            } else {
                $value = pods_var_raw($field_group_name, $field, $value);
            }
            ?>
                        <li class="<?php 
            echo esc_attr($depends_option);
            ?>
">
                            <?php 
            echo PodsForm::field($row_name, $value, $field_group_option['type'], $field_group_option);
            ?>
                        </li>
                        <?php 
        }
        ?>
                </ul>
            </div>
        </div>
        <?php 
    }
    if (false !== $depends_on || !empty($depends)) {
        $depends_on = $depends;
    }
}
if (!empty($depends_on)) {
Example #19
0
                                    <?php 
if (!pods_tableless() && apply_filters('pods_admin_setup_add_extend_storage', false)) {
    ?>
                                        <div class="pods-depends-on pods-depends-on-extend-pod-type pods-depends-on-extend-pod-type-post-type pods-depends-on-extend-pod-type-media pods-depends-on-extend-pod-type-user pods-depends-on-extend-pod-type-comment">
                                            <p><a href="#pods-advanced" class="pods-advanced-toggle"><?php 
    _e('Advanced', 'pods');
    ?>
 +</a></p>

                                            <div class="pods-advanced">
                                                <div class="pods-field-option">
                                                    <?php 
    echo PodsForm::label('extend_storage', __('Storage Type', 'pods'), array(__('<h6>Storage Types</h6> Table based storage will operate in a way where each field you create for your content type becomes a field in a table. Meta based storage relies upon the WordPress meta storage table for all field data.', 'pods'), 'http://pods.io/docs/comparisons/compare-storage-types/'));
    $data = array('meta' => __('Meta Based (WP Default)', 'pods'), 'table' => __('Table Based', 'pods'));
    echo PodsForm::field('extend_storage', pods_var_raw('extend_storage', 'post'), 'pick', array('data' => $data));
    ?>
                                                </div>
                                            </div>
                                        </div>
                                    <?php 
}
?>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div id="pods-wizard-actions">
                        <div id="pods-wizard-toolbar">
                            <a href="#start" id="pods-wizard-start" class="button button-secondary"><?php 
 /**
  * Export a Package
  *
  * $params['pods'] string|array|bool Pod IDs to export, or set to true to export all
  * $params['templates'] string|array|bool Template IDs to export, or set to true to export all
  * $params['pages'] string|array|bool Page IDs to export, or set to true to export all
  * $params['helpers'] string|array|bool Helper IDs to export, or set to true to export all
  *
  * @param array $params Array of things to export
  *
  * @return array|bool
  *
  * @static
  * @since 2.0.5
  */
 public static function export($params)
 {
     $export = array('meta' => array('version' => PODS_VERSION, 'build' => time()));
     if (is_object($params)) {
         $params = get_object_vars($params);
     }
     $api = pods_api();
     $pod_ids = pods_var_raw('pods', $params);
     $template_ids = pods_var_raw('templates', $params);
     $page_ids = pods_var_raw('pages', $params);
     $helper_ids = pods_var_raw('helpers', $params);
     if (!empty($pod_ids)) {
         $api_params = array('export' => true);
         if (true !== $pod_ids) {
             $api_params['ids'] = (array) $pod_ids;
         }
         $export['pods'] = $api->load_pods($api_params);
         $options_ignore = array('pod_id', 'old_name', 'object_type', 'object_name', 'object_hierarchical', 'table', 'meta_table', 'pod_table', 'field_id', 'field_index', 'field_slug', 'field_type', 'field_parent', 'field_parent_select', 'meta_field_id', 'meta_field_index', 'meta_field_value', 'pod_field_id', 'pod_field_index', 'object_fields', 'join', 'where', 'where_default', 'orderby', 'pod', 'recurse', 'table_info', 'attributes', 'group', 'grouped', 'developer_mode', 'dependency', 'depends-on', 'excludes-on');
         $field_types = PodsForm::field_types();
         $field_type_options = array();
         foreach ($field_types as $type => $field_type_data) {
             $field_type_options[$type] = PodsForm::ui_options($type);
         }
         foreach ($export['pods'] as &$pod) {
             if (isset($pod['options'])) {
                 $pod = array_merge($pod, $pod['options']);
                 unset($pod['options']);
             }
             foreach ($pod as $option => $option_value) {
                 if (in_array($option, $options_ignore) || null === $option_value) {
                     unset($pod[$option]);
                 }
             }
             if (!empty($pod['fields'])) {
                 foreach ($pod['fields'] as &$field) {
                     if (isset($field['options'])) {
                         $field = array_merge($field, $field['options']);
                         unset($field['options']);
                     }
                     foreach ($field as $option => $option_value) {
                         if (in_array($option, $options_ignore) || null === $option_value) {
                             unset($field[$option]);
                         }
                     }
                     foreach ($field_type_options as $type => $options) {
                         if ($type == pods_var('type', $field)) {
                             continue;
                         }
                         foreach ($options as $option_data) {
                             if (isset($option_data['group']) && is_array($option_data['group']) && !empty($option_data['group'])) {
                                 if (isset($field[$option_data['name']])) {
                                     unset($field[$option_data['name']]);
                                 }
                                 foreach ($option_data['group'] as $group_option_data) {
                                     if (isset($field[$group_option_data['name']])) {
                                         unset($field[$group_option_data['name']]);
                                     }
                                 }
                             } elseif (isset($field[$option_data['name']])) {
                                 unset($field[$option_data['name']]);
                             }
                         }
                     }
                 }
             }
         }
     }
     if (!empty($template_ids)) {
         $api_params = array();
         if (true !== $template_ids) {
             $api_params['ids'] = (array) $template_ids;
         }
         $export['templates'] = $api->load_templates($api_params);
     }
     if (!empty($page_ids)) {
         $api_params = array();
         if (true !== $page_ids) {
             $api_params['ids'] = (array) $page_ids;
         }
         $export['pages'] = $api->load_pages($api_params);
     }
     if (!empty($helper_ids)) {
         $api_params = array();
         if (true !== $helper_ids) {
             $api_params['ids'] = (array) $helper_ids;
         }
         $export['helpers'] = $api->load_helpers($api_params);
     }
     $export = apply_filters('pods_packages_export', $export, $params);
     if (1 == count($export)) {
         return false;
     }
     $export = version_compare(PHP_VERSION, '5.4.0', '>=') ? json_encode($export, JSON_UNESCAPED_UNICODE) : json_encode($export);
     return $export;
 }
    }

    var pods_sister_field_going = {

    };

    var pods_sister_field = function ( $el ) {
        var id = $el.closest( 'tr.pods-manage-row' ).data( 'row' );

        if ( 'undefined' != typeof pods_sister_field_going[ id + '_' + $el.prop( 'id' ) ] && true == pods_sister_field_going[ id + '_' + $el.prop( 'id' ) ] )
            return;

        pods_sister_field_going[ id + '_' + $el.prop( 'id' ) ] = true;

        var default_select = '<?php 
echo str_replace(array("\n", "\r"), ' ', PodsForm::field('field_data[--1][sister_id]', '', 'pick', array('data' => pods_var_raw('sister_id', $field_settings))));
?>
';
        default_select = default_select.replace( /\-\-1/g, id );

        var related_pod_name = jQuery( '#pods-form-ui-field-data-' + id + '-pick-object' ).val();

        if ( 0 != related_pod_name.indexOf( 'pod-' ) && 0 != related_pod_name.indexOf( 'post_type-' ) && 0 != related_pod_name.indexOf( 'taxonomy-' ) && 0 != related_pod_name.indexOf( 'user' ) && 0 != related_pod_name.indexOf( 'media' ) && 0 != related_pod_name.indexOf( 'comment' ) ) {
            pods_sister_field_going[ id + '_' + $el.prop( 'id' ) ] = false;

            return;
        }

        var selected_value = jQuery( '#pods-form-ui-field-data-' + id + '-sister-id' ).val();

        var select_container = default_select.match( /<select[^<]*>/g );
Example #22
0
 /**
  * Delete Attachments from relationships
  *
  * @param int $_ID
  */
 public function delete_attachment($_ID)
 {
     global $wpdb;
     $_ID = (int) $_ID;
     do_action('pods_delete_attachment', $_ID);
     $file_types = "'" . implode("', '", PodsForm::file_field_types()) . "'";
     if (!pods_tableless()) {
         $sql = "\n                DELETE `rel`\n                FROM `@wp_podsrel` AS `rel`\n                LEFT JOIN `{$wpdb->posts}` AS `p`\n                    ON\n                        `p`.`post_type` = '_pods_field'\n                        AND ( `p`.`ID` = `rel`.`field_id` OR `p`.`ID` = `rel`.`related_field_id` )\n                LEFT JOIN `{$wpdb->postmeta}` AS `pm`\n                    ON\n                        `pm`.`post_id` = `p`.`ID`\n                        AND `pm`.`meta_key` = 'type'\n                        AND `pm`.`meta_value` IN ( {$file_types} )\n                WHERE\n                    `p`.`ID` IS NOT NULL\n                    AND `pm`.`meta_id` IS NOT NULL\n                    AND `rel`.`item_id` = {$_ID}";
         pods_query($sql, false);
     }
     // Post Meta
     if (!empty(PodsMeta::$post_types)) {
         $sql = "\n                DELETE `rel`\n                FROM `@wp_postmeta` AS `rel`\n                LEFT JOIN `{$wpdb->posts}` AS `p`\n                    ON\n                        `p`.`post_type` = '_pods_field'\n                LEFT JOIN `{$wpdb->postmeta}` AS `pm`\n                    ON\n                        `pm`.`post_id` = `p`.`ID`\n                        AND `pm`.`meta_key` = 'type'\n                        AND `pm`.`meta_value` IN ( {$file_types} )\n                WHERE\n                    `p`.`ID` IS NOT NULL\n                    AND `pm`.`meta_id` IS NOT NULL\n                    AND `rel`.`meta_key` = `p`.`post_name`\n                    AND `rel`.`meta_value` = '{$_ID}'";
         pods_query($sql, false);
     }
     // User Meta
     if (!empty(PodsMeta::$user)) {
         $sql = "\n                DELETE `rel`\n                FROM `@wp_usermeta` AS `rel`\n                LEFT JOIN `{$wpdb->posts}` AS `p`\n                    ON\n                        `p`.`post_type` = '_pods_field'\n                LEFT JOIN `{$wpdb->postmeta}` AS `pm`\n                    ON\n                        `pm`.`post_id` = `p`.`ID`\n                        AND `pm`.`meta_key` = 'type'\n                        AND `pm`.`meta_value` IN ( {$file_types} )\n                WHERE\n                    `p`.`ID` IS NOT NULL\n                    AND `pm`.`meta_id` IS NOT NULL\n                    AND `rel`.`meta_key` = `p`.`post_name`\n                    AND `rel`.`meta_value` = '{$_ID}'";
         pods_query($sql, false);
     }
     // Comment Meta
     if (!empty(PodsMeta::$comment)) {
         $sql = "\n                DELETE `rel`\n                FROM `@wp_commentmeta` AS `rel`\n                LEFT JOIN `{$wpdb->posts}` AS `p`\n                    ON\n                        `p`.`post_type` = '_pods_field'\n                LEFT JOIN `{$wpdb->postmeta}` AS `pm`\n                    ON\n                        `pm`.`post_id` = `p`.`ID`\n                        AND `pm`.`meta_key` = 'type'\n                        AND `pm`.`meta_value` IN ( {$file_types} )\n                WHERE\n                    `p`.`ID` IS NOT NULL\n                    AND `pm`.`meta_id` IS NOT NULL\n                    AND `rel`.`meta_key` = `p`.`post_name`\n                    AND `rel`.`meta_value` = '{$_ID}'";
         pods_query($sql, false);
     }
 }
Example #23
0
/**
 * 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);
}
Example #24
0
 /**
  * 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;
 }
Example #25
0
 public function admin_ajax_settings($component, $params)
 {
     if (!isset($this->components[$component])) {
         wp_die('Invalid Component');
     } elseif (!method_exists($this->components[$component]['object'], 'options')) {
         pods_error('Component options method does not exist', $this);
     }
     $options = $this->components[$component]['object']->options($this->settings['components'][$component]);
     if (empty($this->settings['components'][$component])) {
         $this->settings['components'][$component] = array();
     }
     foreach ($options as $field_name => $field_option) {
         $field_option = PodsForm::field_setup($field_option, null, $field_option['type']);
         if (!is_array($field_option['group'])) {
             $field_value = pods_var_raw('pods_setting_' . $field_name, $params);
             $this->settings['components'][$component][$field_name] = $field_value;
         } else {
             foreach ($field_option['group'] as $field_group_name => $field_group_option) {
                 $field_value = pods_var_raw('pods_setting_' . $field_group_name, $params);
                 $this->settings['components'][$component][$field_group_name] = $field_value;
             }
         }
     }
     $settings = version_compare(PHP_VERSION, '5.4.0', '>=') ? json_encode($this->settings, JSON_UNESCAPED_UNICODE) : json_encode($this->settings);
     update_option('pods_component_settings', $settings);
     return '1';
 }
/**
 * 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;
}
 /**
  * Customize output of the form field
  *
  * @param string $name
  * @param mixed $value
  * @param array $options
  * @param array $pod
  * @param int $id
  *
  * @since 2.0
  */
 public function input($name, $value = null, $options = null, $pod = null, $id = null)
 {
     $options = (array) $options;
     $form_field_type = PodsForm::$field_type;
     if (is_array($value)) {
         $value = !empty($value);
     }
     $field_type = 'checkbox';
     if ('radio' == pods_v(self::$type . '_format_type', $options)) {
         $field_type = 'radio';
     } elseif ('dropdown' == pods_v(self::$type . '_format_type', $options)) {
         $field_type = 'select';
     }
     if (isset($options['name']) && false === PodsForm::permission(self::$type, $options['name'], $options, null, $pod, $id)) {
         if (pods_v('read_only', $options, false)) {
             $options['readonly'] = true;
         } else {
             return;
         }
     } elseif (!pods_has_permissions($options) && pods_v('read_only', $options, false)) {
         $options['readonly'] = true;
     }
     if (1 === $value || '1' === $value || true === $value) {
         $value = 1;
     } else {
         $value = 0;
     }
     pods_view(PODS_DIR . 'ui/fields/' . $field_type . '.php', compact(array_keys(get_defined_vars())));
 }
Example #28
0
 /**
  * @param $object_type
  * @param null $_null
  * @param int $object_id
  * @param string $meta_key
  * @param string $meta_value
  * @param bool $delete_all
  *
  * @return null
  */
 public function delete_meta($object_type, $_null = null, $object_id = 0, $meta_key = '', $meta_value = '', $delete_all = false)
 {
     if (pods_tableless()) {
         return $_null;
     }
     $object = $this->get_object($object_type, $object_id);
     if (empty($object_id) || empty($object) || !isset($object['fields'][$meta_key])) {
         return $_null;
     }
     $pod = pods($object['name']);
     // @todo handle $delete_all (delete the field values from all pod items)
     if (!empty($meta_value) && in_array($object['fields'][$meta_key]['type'], PodsForm::tableless_field_types())) {
         $pod->fetch($object_id);
         $pod->remove_from($meta_key, $meta_value);
     } else {
         $pod->save(array($meta_key => null), null, $object_id);
     }
     return $_null;
 }
Example #29
0
 /**
  * Customize output of the form field
  *
  * @param string $name
  * @param mixed $value
  * @param array $options
  * @param array $pod
  * @param int $id
  *
  * @since 2.0
  */
 public function input($name, $value = null, $options = null, $pod = null, $id = null)
 {
     $options = (array) $options;
     $form_field_type = PodsForm::$field_type;
     if (is_array($value)) {
         $value = implode(' ', $value);
     }
     $field_type = 'email';
     if (isset($options['name']) && false === PodsForm::permission(self::$type, $options['name'], $options, null, $pod, $id)) {
         if (pods_var('read_only', $options, false)) {
             $options['readonly'] = true;
             $field_type = 'text';
         } else {
             return;
         }
     } elseif (!pods_has_permissions($options) && pods_var('read_only', $options, false)) {
         $options['readonly'] = true;
         $field_type = 'text';
     }
     pods_view(PODS_DIR . 'ui/fields/' . $field_type . '.php', compact(array_keys(get_defined_vars())));
 }
Example #30
0
        }
        ?>
                                        <tr class="form-field pods-field <?php 
        echo 'pods-form-ui-row-type-' . $field['type'] . ' pods-form-ui-row-name-' . PodsForm::clean($field['name'], true);
        ?>
">
                                            <th scope="row" valign="top"><?php 
        echo PodsForm::label('pods_field_' . $field['name'], $field['label'], $field['help'], $field);
        ?>
</th>
                                            <td>
                                                <?php 
        echo PodsForm::field('pods_field_' . $field['name'], $pod->field(array('name' => $field['name'], 'in_form' => true)), $field['type'], $field, $pod, $pod->id());
        ?>
                                                <?php 
        echo PodsForm::comment('pods_field_' . $field['name'], $field['description'], $field);
        ?>
                                            </td>
                                        </tr>
                                    <?php 
    }
    ?>
                                </table>
                            </div>
                            <!-- /.inside -->
                        </div>
                        <!-- /#pods-meta-box -->
                    </div>
                    <!-- /#normal-sortables -->

                    <?php