本文整理汇总了PHP中pods_api函数的典型用法代码示例。如果您正苦于以下问题:PHP pods_api函数的具体用法?PHP pods_api怎么用?PHP pods_api使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pods_api函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _start_table_edit
/**
* Output something at the start of the table form
*
* @param object $form Form class
* @param bool $results
*/
function _start_table_edit($form, $results = true)
{
$api = pods_api();
$all_pods = $api->load_pods(array('names' => true));
$pod_types = array();
foreach ($all_pods as $pod_name => $pod_label) {
$pod_types[$pod_name] = $pod_label . ' (' . $pod_name . ')';
}
?>
<tr>
<td valign="top">
<label for="pod_type"><?php
_e('Pod', 'pods');
?>
</label>
</td>
<td>
<?php
if (0 < count($all_pods)) {
$form->add_drop_down('pod_type', $pod_types);
} else {
echo '<strong class="red">' . __('None Found', 'pods') . '</strong>';
}
?>
</td>
</tr>
<tr>
<td valign="top">
<label for="slug"><?php
_e('Slug or ID', 'pods');
?>
</label>
</td>
<td>
<?php
$form->add_text_box('slug');
?>
</td>
</tr>
<tr>
<td valign="top">
<label for="field"><?php
_e('Field', 'pods');
?>
</label>
</td>
<td>
<?php
$form->add_text_box('field');
?>
</td>
</tr>
<?php
}
示例2: build_menu
public static function build_menu()
{
$PodsAPI = pods_api();
$registered_pods = $PodsAPI->load_pods();
$role = get_role("administrator");
foreach ($registered_pods as $pod_info) {
if (pods_related::is_dms_pod($pod_info["name"])) {
continue;
}
// Add Custom DMS Capabilities
$role->add_cap("pods_read_others_" . $pod_info["name"]);
$role->add_cap("pods_read_bygroup_" . $pod_info["name"]);
$role->add_cap("pods_read_" . $pod_info["name"]);
$role->add_cap("pods_edit_bygroup_" . $pod_info["name"]);
$role->add_cap("pods_delete_sealed_" . $pod_info["name"]);
$role->add_cap("pods_edit_sealed_" . $pod_info["name"]);
$role->add_cap("pods_unseal_" . $pod_info["name"]);
$role->add_cap("jomiz_dms_front_settings");
$role->add_cap("show_reports_in_menu");
}
if (!is_user_logged_in()) {
return "";
}
$menu = '<div id="menu-expanded" class="list-group hidden-xs">';
$navbar_menu = "";
foreach ($registered_pods as $pod_info) {
// don't show in the main menu
if (pods_related::is_dms_pod($pod_info["name"]) || $pod_info['options']['show_in_menu'] == 0) {
continue;
}
if (dms_security::is_allowed($pod_info["name"], array("read_others", "read", "read_bygroup"))) {
$pod_label = $pod_info["label"];
$pod_link = pods_related::get_pod_url($pod_info["name"], "list");
$active_class = "";
if (isset($_GET['type']) && $_GET['type'] == $pod_info["name"]) {
$active_class = "active";
}
$listing_link = "<a class='list-group-item {$active_class}' href='{$pod_link}' title='View {$pod_label}'>{$pod_label}</a>";
$navbar_menu .= "<li class='{$active_class}'><a href='{$pod_link}'>{$pod_label}</a></li>";
$menu .= $listing_link;
}
}
//Reports Link
if (dms_security::is_allowed_cap("show_reports_in_menu")) {
$reports_link = home_url("/reports/");
$navbar_menu .= "<li class='divider'></li><li class=''><a href='{$reports_link}'>Reports</a></li>";
$menu .= "<a href='{$reports_link}' class='list-group-item'>Reports</a>";
}
$menu .= "<a href='#' id='meunitem-showhide' onclick='showhide_mainmenu()' class='list-group-item'><span class='glyphicon glyphicon-pushpin'></span></a>";
$menu .= "</div>";
return array("navbar-menu" => $navbar_menu, "vertical-menu" => $menu);
}
示例3: get_relationships
/**
* Gets relationships
*
* @since 0.2.0
*
* @return bool
*/
public static function get_relationships()
{
$relationships = false;
$api = pods_api();
$pods = $api->load_pods();
foreach ($pods as $pod) {
$pod_name = pods_v('name', $pod);
if (!is_null($local_fields = pods_v('fields', $pod))) {
foreach ($local_fields as $field_name => $field) {
if ('' !== ($sister_id = pods_v('sister_id', $field))) {
$relationships[pods_v('name', $field)] = array('from' => array('pod_name' => $pod_name, 'field_name' => pods_v('name', $field)), 'to' => self::find_by_id($sister_id, $pods));
}
}
}
}
return $relationships;
}
示例4: is_dw_pods_page
public static function is_dw_pods_page($id)
{
if (function_exists('pods_api')) {
$pod_page = pods_api()->load_page(array('id' => $id));
$pod_page_name = !empty($pod_page) ? $pod_page['name'] : '';
if (!empty($pod_page_name) && is_pod_page($pod_page_name)) {
return TRUE;
}
} else {
global $pod_page_exists;
if (is_int($id)) {
$id = array($id);
}
if (in_array($pod_page_exists['id'], $id)) {
return TRUE;
}
}
return FALSE;
}
示例5: baldrick_pods_endpoint
function baldrick_pods_endpoint()
{
if (defined('PODS_VERSION') && defined('PODS_JSON_API_VERSION')) {
//add the basic pods endpoints
$endpoints['pods'] = json_url('pods');
$endpoints['pods-api'] = json_url('pods-api');
//get name of all registered Pods
$pods = pods_api()->load_pods(array('names' => true));
//add end point foreach if there are registered Pods
if (is_array($pods) && !empty($pods)) {
$endpoint_types = array('pods', 'pods_api');
foreach ($pods as $pod) {
foreach ($endpoint_types as $type) {
$endpoints = array_merge($endpoints, array("{$type}/{$pod}" => json_url("{$type}/{$pod}")));
}
}
}
return $endpoints;
}
}
示例6: slug_post_type_breadcrumb
/**
* Basic breadcrumbs for custom post type Pod, using load_pod to get Pod labels.
*
* Someone should add handling for posts and pages as well as ACTs to this. Possibly make a plugin.
*/
function slug_post_type_breadcrumb($divider = '>>')
{
$front = slug_link(site_url(), 'Home');
if (is_home() || is_front_page()) {
return $front;
}
if (is_post_type_archive() || is_singular() && get_post_type() !== false) {
$post_type = get_post_type();
$pod = pods_api()->load_pod($post_type);
if (!is_string($pod)) {
$single = $pod->options['single_label'];
$plural = slug_link(get_post_type_archive($post_type), $pod->label, 'All ' . $single);
if (is_post_type_archive()) {
return $front . $divider . $plural;
}
global $post;
$single = slug_link(get_permalink($post->ID), get_the__title($post->ID), 'View ' . $single);
return $front . $divider . $single;
} else {
return;
}
}
}
示例7: pods_api
<?php
if (!empty($_POST)) {
if (isset($_POST['clearcache'])) {
$api = pods_api();
$api->cache_flush_pods();
if (defined('PODS_PRELOAD_CONFIG_AFTER_FLUSH') && PODS_PRELOAD_CONFIG_AFTER_FLUSH) {
$api->load_pods();
}
pods_redirect(pods_query_arg(array('pods_clearcache' => 1), array('page', 'tab')));
}
} elseif (1 == pods_var('pods_clearcache')) {
pods_message('Pods transients and cache have been cleared.');
}
?>
<h3><?php
_e('Clear Pods Cache', 'pods');
?>
</h3>
<p><?php
_e('This tool will clear all of the transients/cache that are used by Pods. ', 'pods');
?>
</p>
<p class="submit">
<input type="submit" class="button button-primary" name="clearcache" value="<?php
esc_attr_e('Clear Pods Cache', 'pods');
?>
" />
示例8: save_pod_item
/**
* Add or edit a single pod item
*
* $params['pod'] string The Pod name (pod or pod_id is required)
* $params['pod_id'] string The Pod ID (pod or pod_id is required)
* $params['id'] int The item ID
* $params['data'] array (optional) Associative array of field names + values
* $params['bypass_helpers'] bool Set to true to bypass running pre-save and post-save helpers
* $params['track_changed_fields'] bool Set to true to enable tracking of saved fields via PodsAPI::get_changed_fields()
*
* @param array|object $params An associative array of parameters
*
* @return int The item ID
*
* @since 1.7.9
*/
public function save_pod_item($params)
{
global $wpdb;
$params = (object) pods_str_replace('@wp_', '{prefix}', $params);
$tableless_field_types = PodsForm::tableless_field_types();
$repeatable_field_types = PodsForm::repeatable_field_types();
$simple_tableless_objects = PodsForm::simple_tableless_objects();
// @deprecated 2.0
if (isset($params->datatype)) {
pods_deprecated('$params->pod instead of $params->datatype', '2.0');
$params->pod = $params->datatype;
unset($params->datatype);
if (isset($params->pod_id)) {
pods_deprecated('$params->id instead of $params->pod_id', '2.0');
$params->id = $params->pod_id;
unset($params->pod_id);
}
if (isset($params->data) && !empty($params->data) && is_array($params->data)) {
$check = current($params->data);
if (is_array($check)) {
pods_deprecated('PodsAPI::save_pod_items', '2.0');
return $this->save_pod_items($params, $params->data);
}
}
}
// @deprecated 2.0
if (isset($params->tbl_row_id)) {
pods_deprecated('$params->id instead of $params->tbl_row_id', '2.0');
$params->id = $params->tbl_row_id;
unset($params->tbl_row_id);
}
// @deprecated 2.0
if (isset($params->columns)) {
pods_deprecated('$params->data instead of $params->columns', '2.0');
$params->data = $params->columns;
unset($params->columns);
}
if (!isset($params->pod)) {
$params->pod = false;
}
if (isset($params->pod_id)) {
$params->pod_id = pods_absint($params->pod_id);
} else {
$params->pod_id = 0;
}
if (isset($params->id)) {
$params->id = pods_absint($params->id);
} else {
$params->id = 0;
}
if (!isset($params->from)) {
$params->from = 'save';
}
if (!isset($params->location)) {
$params->location = null;
}
if (!isset($params->track_changed_fields)) {
$params->track_changed_fields = false;
}
/**
* Override $params['track_changed_fields']
*
* Use for globally setting field change tracking.
*
* @param bool
*
* @since 2.3.19
*/
$track_changed_fields = apply_filters('pods_api_save_pod_item_track_changed_fields_' . $params->pod, (bool) $params->track_changed_fields, $params);
$changed_fields = array();
if (!isset($params->clear_slug_cache)) {
$params->clear_slug_cache = true;
}
// Support for bulk edit
if (isset($params->id) && !empty($params->id) && is_array($params->id)) {
$ids = array();
$new_params = $params;
foreach ($params->id as $id) {
$new_params->id = $id;
$ids[] = $this->save_pod_item($new_params);
}
return $ids;
}
// Allow Helpers to know what's going on, are we adding or saving?
//.........这里部分代码省略.........
示例9: reorder
/**
* Reorder data
*/
public function reorder()
{
// loop through order
$order = (array) pods_var_raw('order', 'post', array(), null, true);
$params = array('pod' => $this->pod->pod, 'field' => $this->reorder['on'], 'order' => $order);
$reorder = pods_api()->reorder_pod_item($params);
if ($reorder) {
$this->message(sprintf(__("<strong>Success!</strong> %s reordered successfully.", 'pods'), $this->items));
} else {
$this->error(sprintf(__("<strong>Error:</strong> %s has not been reordered.", 'pods'), $this->items));
}
}
示例10: add_meta_boxes
/**
* Add meta boxes to the page
*
* @since 2.0
*/
public function add_meta_boxes()
{
$pod = array('name' => $this->object_type, 'type' => 'post_type');
if (isset(PodsMeta::$post_types[$pod['name']])) {
return;
}
if (!function_exists('get_page_templates')) {
include_once ABSPATH . 'wp-admin/includes/theme.php';
}
$page_templates = apply_filters('pods_page_templates', get_page_templates());
$page_templates[__('-- Page Template --', 'pods')] = '';
$page_templates[__('Custom (uses only Pod Page content)', 'pods')] = '_custom';
if (!in_array('pods.php', $page_templates) && locate_template(array('pods.php', false))) {
$page_templates[__('Pods (Pods Default)', 'pods')] = 'pods.php';
}
if (!in_array('page.php', $page_templates) && locate_template(array('page.php', false))) {
$page_templates[__('Page (WP Default)', 'pods')] = 'page.php';
}
if (!in_array('index.php', $page_templates) && locate_template(array('index.php', false))) {
$page_templates[__('Index (WP Fallback)', 'pods')] = 'index.php';
}
ksort($page_templates);
$page_templates = array_flip($page_templates);
$fields = array(array('name' => 'page_title', 'label' => __('Page Title', 'pods'), 'type' => 'text'), array('name' => 'code', 'label' => __('Page Code', 'pods'), 'type' => 'code', 'attributes' => array('id' => 'content'), 'label_options' => array('attributes' => array('for' => 'content'))), array('name' => 'precode', 'label' => __('Page Precode', 'pods'), 'type' => 'code', 'help' => __('Precode will run before your theme outputs the page. It is expected that this value will be a block of PHP. You must open the PHP tag here, as we do not open it for you by default.', 'pods')), array('name' => 'page_template', 'label' => __('Page Template', 'pods'), 'type' => 'pick', 'data' => $page_templates));
pods_group_add($pod, __('Page', 'pods'), $fields, 'normal', 'high');
$associated_pods = array(0 => __('-- Select a Pod --', 'pods'));
$all_pods = pods_api()->load_pods(array('names' => true));
if (!empty($all_pods)) {
foreach ($all_pods as $pod_name => $pod_label) {
$associated_pods[$pod_name] = $pod_label . ' (' . $pod_name . ')';
}
} else {
$associated_pods[0] = __('None Found', 'pods');
}
$fields = array(array('name' => 'pod', 'label' => __('Associated Pod', 'pods'), 'default' => 0, 'type' => 'pick', 'data' => $associated_pods, 'dependency' => true), array('name' => 'pod_slug', 'label' => __('Wildcard Slug', 'pods'), 'help' => __('Setting the Wildcard Slug is an easy way to setup a detail page. You can use the special tag {@url.2} to match the *third* level of the URL of a Pod Page named "first/second/*" part of the pod page. This is functionally the same as using pods_var( 2, "url" ) in PHP.', 'pods'), 'type' => 'text', 'excludes-on' => array('pod' => 0)));
pods_group_add($pod, __('Pod Association', 'pods'), $fields, 'normal', 'high');
$fields = array(array('name' => 'admin_only', 'label' => __('Restrict access to Admins?', 'pods'), 'default' => 0, 'type' => 'boolean', 'dependency' => true), array('name' => 'restrict_role', 'label' => __('Restrict access by Role?', 'pods'), 'help' => array(__('<h6>Roles</h6> Roles are assigned to users to provide them access to specific functionality in WordPress. Please see the Roles and Capabilities component in Pods for an easy tool to add your own roles and edit existing ones.', 'pods'), 'http://codex.wordpress.org/Roles_and_Capabilities'), 'default' => 0, 'type' => 'boolean', 'dependency' => true), array('name' => 'roles_allowed', 'label' => __('Role(s) Allowed', 'pods'), 'type' => 'pick', 'pick_object' => 'role', 'pick_format_type' => 'multi', 'pick_format_multi' => 'autocomplete', 'pick_ajax' => false, 'default' => '', 'depends-on' => array('restrict_role' => true)), array('name' => 'restrict_capability', 'label' => __('Restrict access by Capability?', 'pods'), 'help' => array(__('<h6>Capabilities</h6> Capabilities denote access to specific functionality in WordPress, and are assigned to specific User Roles. Please see the Roles and Capabilities component in Pods for an easy tool to add your own capabilities and roles.', 'pods'), 'http://codex.wordpress.org/Roles_and_Capabilities'), 'default' => 0, 'type' => 'boolean', 'dependency' => true), array('name' => 'capability_allowed', 'label' => __('Capability Allowed', 'pods'), 'type' => 'pick', 'pick_object' => 'capability', 'pick_format_type' => 'multi', 'pick_format_multi' => 'autocomplete', 'pick_ajax' => false, 'default' => '', 'depends-on' => array('restrict_capability' => true)), array('name' => 'restrict_redirect', 'label' => __('Redirect if Restricted?', 'pods'), 'default' => 0, 'type' => 'boolean', 'dependency' => true), array('name' => 'restrict_redirect_login', 'label' => __('Redirect to WP Login page', 'pods'), 'default' => 0, 'type' => 'boolean', 'dependency' => true, 'depends-on' => array('restrict_redirect' => true)), array('name' => 'restrict_redirect_url', 'label' => __('Redirect to a Custom URL', 'pods'), 'default' => '', 'type' => 'text', 'depends-on' => array('restrict_redirect' => true, 'restrict_redirect_login' => false)));
pods_group_add($pod, __('Restrict Access', 'pods'), $fields, 'normal', 'high');
}
示例11: pods_api
<?php
$all_pods = pods_api()->load_pods();
// or $api = pods_api(); and then $api->load_pods();
foreach ($all_pods as $pod) {
echo '<p>' . $pod['name '] . ' is awesome</p>' . "\n";
}
示例12: get_template_titles
/**
* Get titles of all Pods Templates
*
* @return string[] Array of template names
*
* @since 2.4.5
*/
public function get_template_titles()
{
static $template_titles;
if (empty($template_titles)) {
$all_templates = (array) pods_api()->load_templates(array());
$template_titles = array();
foreach ($all_templates as $template) {
$template_titles[] = $template['name'];
}
}
return $template_titles;
}
示例13: heres_the_beef
/**
* @param $import
* @param bool $output
*/
public function heres_the_beef($import, $output = true)
{
global $wpdb;
$api = pods_api();
for ($i = 0; $i < 40000; $i++) {
echo " \t";
// extra spaces
}
$default_data = array('pod' => null, 'table' => null, 'reset' => null, 'update_on' => null, 'where' => null, 'fields' => array(), 'row_filter' => null, 'pre_save' => null, 'post_save' => null, 'sql' => null, 'sort' => null, 'limit' => null, 'page' => null, 'output' => null, 'page_var' => 'ipg', 'bypass_helpers' => false);
$default_field_data = array('field' => null, 'filter' => null);
if (!is_array($import)) {
$import = array($import);
} elseif (empty($import)) {
die('<h1 style="color:red;font-weight:bold;">ERROR: No imports configured</h1>');
}
$import_counter = 0;
$total_imports = count($import);
$paginated = false;
$avg_time = -1;
$total_time = 0;
$counter = 0;
$avg_unit = 100;
$avg_counter = 0;
foreach ($import as $datatype => $data) {
$import_counter++;
flush();
@ob_end_flush();
usleep(50000);
if (!is_array($data)) {
$datatype = $data;
$data = array('table' => $data);
}
if (isset($data[0])) {
$data = array('table' => $data[0]);
}
$data = array_merge($default_data, $data);
if (null === $data['pod']) {
$data['pod'] = array('name' => $datatype);
}
if (false !== $output) {
echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - <em>" . $data['pod']['name'] . "</em> - <strong>Loading Pod: " . $data['pod']['name'] . "</strong>\n";
}
if (2 > count($data['pod'])) {
$data['pod'] = $api->load_pod(array('name' => $data['pod']['name']));
}
if (empty($data['pod']['fields'])) {
continue;
}
if (null === $data['table']) {
$data['table'] = $data['pod']['name'];
}
if ($data['reset'] === true) {
if (false !== $output) {
echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - <strong style='color:blue;'>Resetting Pod: " . $data['pod']['name'] . "</strong>\n";
}
$api->reset_pod(array('id' => $data['pod']['id'], 'name' => $data['pod']['name']));
}
if (null === $data['sort'] && null !== $data['update_on'] && isset($data['fields'][$data['update_on']])) {
if (isset($data['fields'][$data['update_on']]['field'])) {
$data['sort'] = $data['fields'][$data['update_on']]['field'];
} else {
$data['sort'] = $data['update_on'];
}
}
$page = 1;
if (false !== $data['page_var'] && isset($_GET[$data['page_var']])) {
$page = absval($_GET[$data['page_var']]);
}
if (null === $data['sql']) {
$data['sql'] = "SELECT * FROM {$data['table']}" . (null !== $data['where'] ? " WHERE {$data['where']}" : '') . (null !== $data['sort'] ? " ORDER BY {$data['sort']}" : '') . (null !== $data['limit'] ? " LIMIT " . (1 < $page ? ($page - 1) * $data['limit'] . ',' : '') . "{$data['limit']}" : '');
}
if (false !== $output) {
echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - Getting Results: " . $data['pod']['name'] . "\n";
}
if (false !== $output) {
echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - Using Query: <small><code>" . $data['sql'] . "</code></small>\n";
}
$result = $wpdb->get_results($data['sql'], ARRAY_A);
if (false !== $output) {
echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - Results Found: " . count($result) . "\n";
}
$avg_time = -1;
$total_time = 0;
$counter = 0;
$avg_unit = 100;
$avg_counter = 0;
$result_count = count($result);
$paginated = false;
if (false !== $data['page_var'] && $result_count == $data['limit']) {
$paginated = "<input type=\"button\" onclick=\"document.location=\\'" . pods_ui_var_update(array($data['page_var'] => $page + 1), false, false) . "\\';\" value=\" Continue Import » \" />";
}
if ($result_count < $avg_unit && 5 < $result_count) {
$avg_unit = number_format($result_count / 5, 0, '', '');
} elseif (2000 < $result_count && 10 < count($data['pod']['fields'])) {
$avg_unit = 40;
}
//.........这里部分代码省略.........
示例14: admin_ajax_upload
/**
* 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));
//.........这里部分代码省略.........
示例15: __construct
/**
* Constructor - Pods Framework core
*
* @param string $pod The pod name
* @param mixed $id (optional) The ID or slug, to load a single record; Provide array of $params to run 'find'
*
* @return \Pods
*
* @license http://www.gnu.org/licenses/gpl-2.0.html
* @since 1.0.0
* @link http://pods.io/docs/pods/
*/
public function __construct($pod = null, $id = null)
{
if (null === $pod) {
$queried_object = get_queried_object();
if ($queried_object) {
$id_lookup = true;
// Post Type Singular
if (isset($queried_object->post_type)) {
$pod = $queried_object->post_type;
} elseif (isset($queried_object->taxonomy)) {
$pod = $queried_object->taxonomy;
} elseif (isset($queried_object->user_login)) {
$pod = 'user';
} elseif (isset($queried_object->public) && isset($queried_object->name)) {
$pod = $queried_object->name;
$id_lookup = false;
}
if (null === $id && $id_lookup) {
$id = get_queried_object_id();
}
}
}
$this->api = pods_api($pod);
$this->api->display_errors =& $this->display_errors;
$this->data = pods_data($this->api, $id, false);
PodsData::$display_errors =& $this->display_errors;
// Set up page variable
if (pods_strict(false)) {
$this->page = 1;
$this->pagination = false;
$this->search = false;
} else {
// Get the page variable
$this->page = pods_var($this->page_var, 'get');
$this->page = empty($this->page) ? 1 : max(pods_absint($this->page), 1);
}
// Set default pagination handling to on/off
if (defined('PODS_GLOBAL_POD_PAGINATION')) {
if (!PODS_GLOBAL_POD_PAGINATION) {
$this->page = 1;
$this->pagination = false;
} else {
$this->pagination = true;
}
}
// Set default search to on/off
if (defined('PODS_GLOBAL_POD_SEARCH')) {
if (PODS_GLOBAL_POD_SEARCH) {
$this->search = true;
} else {
$this->search = false;
}
}
// Set default search mode
$allowed_search_modes = array('int', 'text', 'text_like');
if (defined('PODS_GLOBAL_POD_SEARCH_MODE') && in_array(PODS_GLOBAL_POD_SEARCH_MODE, $allowed_search_modes)) {
$this->search_mode = PODS_GLOBAL_POD_SEARCH_MODE;
}
// Sync Settings
$this->data->page =& $this->page;
$this->data->limit =& $this->limit;
$this->data->pagination =& $this->pagination;
$this->data->search =& $this->search;
$this->data->search_mode =& $this->search_mode;
// Sync Pod Data
$this->api->pod_data =& $this->data->pod_data;
$this->pod_data =& $this->api->pod_data;
$this->api->pod_id =& $this->data->pod_id;
$this->pod_id =& $this->api->pod_id;
$this->datatype_id =& $this->pod_id;
$this->api->pod =& $this->data->pod;
$this->pod =& $this->api->pod;
$this->datatype =& $this->pod;
$this->api->fields =& $this->data->fields;
$this->fields =& $this->api->fields;
$this->detail_page =& $this->data->detail_page;
$this->id =& $this->data->id;
$this->row =& $this->data->row;
$this->rows =& $this->data->data;
$this->row_number =& $this->data->row_number;
$this->sql =& $this->data->sql;
if (is_array($id) || is_object($id)) {
$this->find($id);
}
}