/** * Handle ajax calls for the administration */ public function admin_ajax() { if (false === headers_sent()) { pods_session_start(); header('Content-Type: text/html; charset=' . get_bloginfo('charset')); } // Sanitize input $params = pods_unslash((array) $_POST); foreach ($params as $key => $value) { if ('action' == $key) { continue; } // Fixup $_POST data $_POST[str_replace('_podsfix_', '', $key)] = $_POST[$key]; // Fixup $params with unslashed data $params[str_replace('_podsfix_', '', $key)] = $value; // Unset the _podsfix_* keys unset($params[$key]); } $params = (object) $params; $methods = array('add_pod' => array('priv' => true), 'save_pod' => array('priv' => true), 'load_sister_fields' => array('priv' => true), 'process_form' => array('custom_nonce' => true), 'upgrade' => array('priv' => true), 'migrate' => array('priv' => true)); $methods = apply_filters('pods_admin_ajax_methods', $methods, $this); if (!isset($params->method) || !isset($methods[$params->method])) { pods_error('Invalid AJAX request', $this); } $defaults = array('priv' => null, 'name' => $params->method, 'custom_nonce' => null); $method = (object) array_merge($defaults, (array) $methods[$params->method]); if (true !== $method->custom_nonce && (!isset($params->_wpnonce) || false === wp_verify_nonce($params->_wpnonce, 'pods-' . $params->method))) { pods_error(__('Unauthorized request', 'pods'), $this); } // Cleaning up $params unset($params->action); unset($params->method); if (true !== $method->custom_nonce) { unset($params->_wpnonce); } // Check permissions (convert to array to support multiple) if (!empty($method->priv) && !pods_is_admin(array('pods')) && true !== $method->priv && !pods_is_admin($method->priv)) { pods_error(__('Access denied', 'pods'), $this); } $params->method = $method->name; $params = apply_filters('pods_api_' . $method->name, $params, $method); $api = pods_api(); if ('upgrade' == $method->name) { $output = (string) pods_upgrade($params->version)->ajax($params); } elseif ('migrate' == $method->name) { $output = (string) apply_filters('pods_api_migrate_run', $params); } else { if (!method_exists($api, $method->name)) { pods_error('API method does not exist', $this); } elseif ('save_pod' == $method->name) { if (isset($params->field_data_json) && is_array($params->field_data_json)) { $params->fields = $params->field_data_json; unset($params->field_data_json); foreach ($params->fields as $k => $v) { if (empty($v)) { unset($params->fields[$k]); } elseif (!is_array($v)) { $params->fields[$k] = (array) @json_decode($v, true); } } } } // Dynamically call the API method $params = (array) $params; $output = call_user_func(array($api, $method->name), $params); } // Output in json format if (false !== $output) { if (is_array($output) || is_object($output)) { wp_send_json($output); } else { echo $output; } } else { pods_error('There was a problem with your request.'); } die; // KBAI! }
<?php global $pods_init; $monday_mode = pods_var('monday_mode', 'get', 0, null, true); if (1 == date_i18n('N') && (int) date_i18n('G') < 15) { $monday_mode = 1; } if (isset($_POST['cleanup_1x'])) { pods_upgrade('2.0.0')->cleanup(); pods_redirect(pods_var_update(array('pods_cleanup_1x' => 1), array('page', 'tab'))); } elseif (isset($_POST['reset'])) { $pods_init->reset(); $pods_init->setup(); pods_redirect(pods_var_update(array('pods_reset' => 1), array('page', 'tab'))); } elseif (isset($_POST['reset_deactivate'])) { $pods_init->reset(); deactivate_plugins(PODS_DIR . 'init.php'); pods_redirect('index.php'); } elseif (1 == pods_var('pods_reset')) { pods_message('Pods 2.x settings and data have been reset.'); } elseif (1 == pods_var('pods_cleanup_1x')) { pods_message('Pods 1.x data has been deleted.'); } elseif (pods_var('reset_weekend', 'post', pods_var('reset_weekend', 'get', 0, null, true), null, true)) { if ($monday_mode) { $html = '<br /><br /><iframe width="480" height="360" src="http://www.youtube-nocookie.com/embed/QH2-TGUlwu4?autoplay=1" frameborder="0" allowfullscreen></iframe>'; pods_message('The weekend has been reset and you have been sent back to Friday night. Unfortunately due to a tear in the fabric of time, you slipped back to Monday. We took video of the whole process and you can see it below..' . $html); } else { $html = '<br /><br /><iframe width="480" height="360" src="http://www.youtube-nocookie.com/embed/xhrBDcQq2DM?autoplay=1" frameborder="0" allowfullscreen></iframe>'; pods_message('Oops, sorry! You can only reset the weekend on a Monday before the end of the work day. Somebody call the Waaambulance!' . $html, 'error'); } }
/** * @param null $_blog_id */ public function setup($_blog_id = null) { global $wpdb; // Switch DB table prefixes if (null !== $_blog_id && $_blog_id != $wpdb->blogid) { switch_to_blog(pods_absint($_blog_id)); } else { $_blog_id = null; } // Setup DB tables $pods_version = get_option('pods_framework_version'); $pods_version_last = get_option('pods_framework_version_last'); // Install Pods if (empty($pods_version)) { pods_upgrade()->install($_blog_id); $old_version = get_option('pods_version'); if (!empty($old_version)) { if (false === strpos($old_version, '.')) { $old_version = pods_version_to_point($old_version); } delete_option('pods_framework_version_last'); add_option('pods_framework_version_last', $pods_version, '', 'yes'); self::$version_last = $old_version; } } elseif ($this->needs_upgrade($pods_version, $pods_version_last)) { // Do not do anything return; } elseif (version_compare($pods_version, PODS_VERSION, '<=')) { if (false !== apply_filters('pods_update_run', null, PODS_VERSION, $pods_version, $_blog_id) && !isset($_GET['pods_bypass_update'])) { do_action('pods_update', PODS_VERSION, $pods_version, $_blog_id); // Update 2.0 alpha / beta sites if (version_compare('2.0.0-a-1', $pods_version, '<=') && version_compare($pods_version, '2.0.0-b-15', '<=')) { include PODS_DIR . 'sql/update-2.0-beta.php'; } if (version_compare($pods_version, PODS_DB_VERSION, '<=')) { include PODS_DIR . 'sql/update.php'; } do_action('pods_update_post', PODS_VERSION, $pods_version, $_blog_id); } delete_option('pods_framework_version_last'); add_option('pods_framework_version_last', $pods_version, '', 'yes'); self::$version_last = $pods_version; } delete_option('pods_framework_version'); add_option('pods_framework_version', PODS_VERSION, '', 'yes'); delete_option('pods_framework_db_version'); add_option('pods_framework_db_version', PODS_DB_VERSION, '', 'yes'); pods_api()->cache_flush_pods(); // Restore DB table prefix (if switched) if (null !== $_blog_id) { restore_current_blog(); } }