Пример #1
0
 /**
  * Remove "Edit Page" or "Edit View" links when on single entry pages
  * @since 1.13
  * @return void
  */
 function remove_links()
 {
     // If we're on the single entry page, we don't want to cause confusion.
     if (is_admin() || $this->gravityview_view->getSingleEntry() && !$this->gravityview_view->isGravityviewPostType()) {
         remove_action('admin_bar_menu', 'wp_admin_bar_edit_menu', 80);
     }
 }
 /**
  * Tell Church Themes that GravityView has content if the current page is a GV post type or has shortcode
  *
  * @since 1.17
  *
  * @param bool $has_content Does the post have content?
  *
  * @return bool True: It is GV post type, or has shortcode, or $has_content was true.
  */
 public function if_gravityview_return_true($has_content = false)
 {
     if (!class_exists('GravityView_frontend')) {
         return $has_content;
     }
     $instance = GravityView_frontend::getInstance();
     return $instance->is_gravityview_post_type || $instance->post_has_shortcode ? true : $has_content;
 }
Пример #3
0
 /**
  * Callback function for add_shortcode()
  *
  * @since 1.13
  *
  * @access public
  * @static
  * @param mixed $atts
  * @return null|string If admin, null. Otherwise, output of $this->render_view()
  */
 function shortcode($atts, $content = null)
 {
     // Don't process when saving post.
     if (is_admin()) {
         return null;
     }
     do_action('gravityview_log_debug', __FUNCTION__ . ' $atts: ', $atts);
     // Get details about the current View
     if (!empty($atts['detail'])) {
         return $this->get_view_detail($atts['detail']);
     }
     return GravityView_frontend::getInstance()->render_view($atts);
 }
 /**
  * @param array $atts {
  *   @type string $view_id Define the ID for the View where the entry will
  *   @type string $entry_id ID of the entry to edit. If undefined, uses the current entry ID
  *   @type string $post_id ID of the base post or page to use for an embedded View
  *   @type string $link_atts Whether to open Edit Entry link in a new window or the same window
  *   @type string $return What should the shortcode return: link HTML (`html`) or the URL (`url`). Default: `html`
  *   @type string $field_values Parameters to pass in to the Edit Entry form to prefill data. Uses the same format as Gravity Forms "Allow field to be populated dynamically" {@see https://www.gravityhelp.com/documentation/article/allow-field-to-be-populated-dynamically/ }
  * }
  * @param string $content
  * @param string $context
  *
  * @return string|void
  */
 public function shortcode($atts = array(), $content = '', $context = 'gv_edit_entry')
 {
     // Make sure GV is loaded
     if (!class_exists('GravityView_frontend') || !class_exists('GravityView_View')) {
         return null;
     }
     $defaults = array('view_id' => 0, 'entry_id' => 0, 'post_id' => 0, 'link_atts' => '', 'return' => 'html', 'field_values' => '');
     $settings = shortcode_atts($defaults, $atts, $context);
     if (empty($settings['view_id'])) {
         $view_id = GravityView_View::getInstance()->getViewId();
     } else {
         $view_id = absint($settings['view_id']);
     }
     if (empty($view_id)) {
         do_action('gravityview_log_debug', __METHOD__ . ' A View ID was not defined');
         return null;
     }
     $post_id = empty($settings['post_id']) ? $view_id : absint($settings['post_id']);
     $form_id = gravityview_get_form_id($view_id);
     $backup_entry_id = GravityView_frontend::getInstance()->getSingleEntry() ? GravityView_frontend::getInstance()->getSingleEntry() : GravityView_View::getInstance()->getCurrentEntry();
     $entry_id = empty($settings['entry_id']) ? $backup_entry_id : absint($settings['entry_id']);
     if (empty($entry_id)) {
         do_action('gravityview_log_debug', __METHOD__ . ' No entry defined');
         return null;
     }
     // By default, show only current user
     $user = wp_get_current_user();
     if (!$user) {
         do_action('gravityview_log_debug', __METHOD__ . ' No user defined; edit entry requires logged in user');
         return null;
     }
     $entry = $this->get_entry($entry_id, $form_id);
     // No search results
     if (false === $entry) {
         do_action('gravityview_log_debug', __METHOD__ . ' No entries match the entry ID defined', $entry_id);
         return null;
     }
     // Check permissions
     if (false === GravityView_Edit_Entry::check_user_cap_edit_entry($entry, $view_id)) {
         do_action('gravityview_log_debug', __METHOD__ . ' User does not have the capability to edit this entry: ' . $entry_id);
         return null;
     }
     $href = GravityView_Delete_Entry::get_delete_link($entry, $view_id, $post_id, $settings);
     // Get just the URL, not the tag
     if ('url' === $settings['return']) {
         return $href;
     }
     $link_text = empty($content) ? __('Delete Entry', 'gravityview') : $content;
     return gravityview_get_link($href, $link_text, $settings['link_atts']);
 }
 /**
  * @covers GravityView_frontend::process_search_dates()
  */
 public function test_process_search_dates()
 {
     $date_range_2014 = array('start_date' => '2014-01-01', 'end_date' => '2014-12-31');
     $date_range_june_2015 = array('start_date' => '2015-06-01', 'end_date' => '2015-06-30');
     $date_range_2015 = array('start_date' => '2015-01-01', 'end_date' => '2015-12-31');
     $search_dates = GravityView_frontend::process_search_dates(array(), $date_range_2015);
     $this->assertEquals($date_range_2015, $search_dates, 'No View settings to override; use the passed array');
     $search_dates = GravityView_frontend::process_search_dates($date_range_2014, $date_range_2015);
     $this->assertEquals(array('start_date' => $date_range_2015['start_date'], 'end_date' => $date_range_2014['end_date']), $search_dates, 'The start date is after the end date, which logs a GravityView error but doesn\'t throw any exceptions. This is expected behavior.');
     $search_dates = GravityView_frontend::process_search_dates($date_range_2015, $date_range_june_2015);
     $this->assertEquals($date_range_june_2015, $search_dates, 'The 2015 June passed values are all inside 2015 View settings. Use the passed values.');
     $yesterday = date('Y-m-d H:i:s', strtotime('yesterday'));
     $three_days_ago_ymd = date('Y-m-d', strtotime('3 days ago'));
     $one_month_ago = date('Y-m-d H:i:s', strtotime('-1 month'));
     $relative_dates = array('start_date' => '-1 month', 'end_date' => 'yesterday');
     $search_dates = GravityView_frontend::process_search_dates($relative_dates);
     $this->assertEquals(array('start_date' => $one_month_ago, 'end_date' => $yesterday), $search_dates, 'Make sure the relative dates are formatted in Y-m-d H:i:s format');
     $search_dates = GravityView_frontend::process_search_dates($relative_dates, array('end_date' => $three_days_ago_ymd));
     $this->assertEquals(array('start_date' => $one_month_ago, 'end_date' => $three_days_ago_ymd), $search_dates, 'end_date overridden');
 }
Пример #6
0
 /**
  * return href for single entry
  * @param  array|int $entry   Entry array or entry ID
  * @param  int|null $post_id If wanting to define the parent post, pass a post ID
  * @param boolean $add_directory_args True: Add args to help return to directory; False: only include args required to get to entry {@since 1.7.3}
  * @return string          Link to the entry with the directory parent slug
  */
 public static function entry_link($entry, $post_id = NULL, $add_directory_args = true)
 {
     if (!empty($entry) && !is_array($entry)) {
         $entry = GVCommon::get_entry($entry);
     } else {
         if (empty($entry)) {
             $entry = GravityView_frontend::getInstance()->getEntry();
         }
     }
     // Second parameter used to be passed as $field; this makes sure it's not an array
     if (!is_numeric($post_id)) {
         $post_id = NULL;
     }
     // Get the permalink to the View
     $directory_link = self::directory_link($post_id, false);
     // No post ID? Get outta here.
     if (empty($directory_link)) {
         return '';
     }
     $query_arg_name = GravityView_Post_Types::get_entry_var_name();
     $entry_slug = self::get_entry_slug($entry['id'], $entry);
     if (get_option('permalink_structure') && !is_preview()) {
         $args = array();
         $directory_link = trailingslashit($directory_link) . $query_arg_name . '/' . $entry_slug . '/';
     } else {
         $args = array($query_arg_name => $entry_slug);
     }
     /**
      * @since 1.7.3
      */
     if ($add_directory_args) {
         if (!empty($_GET['pagenum'])) {
             $args['pagenum'] = intval($_GET['pagenum']);
         }
         /**
          * @since 1.7
          */
         if ($sort = rgget('sort')) {
             $args['sort'] = $sort;
             $args['dir'] = rgget('dir');
         }
     }
     /**
      * Check if we have multiple views embedded in the same page and in that case make sure the single entry link
      * has the view id so that Advanced Filters can be applied correctly when rendering the single view
      * @see GravityView_frontend::get_context_view_id()
      */
     if (class_exists('GravityView_View_Data') && GravityView_View_Data::getInstance()->has_multiple_views()) {
         $args['gvid'] = gravityview_get_view_id();
     }
     return add_query_arg($args, $directory_link);
 }
 /**
  * TODO: This seems to be hacky... we should remove it. Entry is set when updating the form using setup_vars()!
  * Get the current entry and set it if it's not yet set.
  * @return array Gravity Forms entry array
  */
 private function get_entry()
 {
     if (empty($this->entry)) {
         // Get the database value of the entry that's being edited
         $this->entry = gravityview_get_entry(GravityView_frontend::is_single_entry());
     }
     return $this->entry;
 }
 /**
  * Capture bulk actions - gf_entries table
  *
  * @uses  GravityView_frontend::get_search_criteria() Convert the $_POST search request into a properly formatted request.
  * @access public
  * @return void|boolean
  */
 public function process_bulk_action()
 {
     if (!class_exists('RGForms')) {
         return;
     }
     if ('bulk' === RGForms::post('action')) {
         check_admin_referer('gforms_entry_list', 'gforms_entry_list');
         // The action is formatted like: approve-16 or disapprove-16, where the first word is the name of the action and the second is the ID of the form. Bulk action 2 is the bottom bulk action select form.
         $bulk_action = !empty($_POST['bulk_action']) ? $_POST['bulk_action'] : $_POST['bulk_action2'];
         /**
          * The extra '-' is to make sure that there are at *least* two items in array.
          * @see https://github.com/katzwebservices/GravityView/issues/370
          */
         $bulk_action .= '-';
         list($approved_status, $form_id) = explode('-', $bulk_action);
         if (empty($form_id)) {
             do_action('gravityview_log_error', '[process_bulk_action] Form ID is empty from parsing bulk action.', $bulk_action);
             return false;
         }
         // All entries are set to be updated, not just the visible ones
         if (!empty($_POST['all_entries'])) {
             // Convert the current entry search into GF-formatted search criteria
             $search = array('search_field' => isset($_POST['f']) ? $_POST['f'][0] : 0, 'search_value' => isset($_POST['v'][0]) ? $_POST['v'][0] : '', 'search_operator' => isset($_POST['o'][0]) ? $_POST['o'][0] : 'contains');
             $search_criteria = GravityView_frontend::get_search_criteria($search, $form_id);
             // Get all the entry IDs for the form
             $entries = gravityview_get_entry_ids($form_id, $search_criteria);
         } else {
             $entries = $_POST['lead'];
         }
         if (empty($entries)) {
             do_action('gravityview_log_error', '[process_bulk_action] Entries are empty');
             return false;
         }
         $entry_count = count($entries) > 1 ? sprintf(__('%d entries', 'gravityview'), count($entries)) : __('1 entry', 'gravityview');
         switch ($approved_status) {
             case 'approve':
                 self::update_bulk($entries, 1, $form_id);
                 $this->bulk_update_message = sprintf(__('%s approved.', 'gravityview'), $entry_count);
                 break;
             case 'unapprove':
                 self::update_bulk($entries, 0, $form_id);
                 $this->bulk_update_message = sprintf(__('%s disapproved.', 'gravityview'), $entry_count);
                 break;
         }
     }
 }
Пример #9
0
 /**
  * Get the one true instantiated self
  * @return GravityView_frontend
  */
 public static function getInstance()
 {
     if (empty(self::$instance)) {
         self::$instance = new self();
         self::$instance->initialize();
     }
     return self::$instance;
 }
 /**
  * Get the entries that will be shown in the current widget
  *
  * @param  array $instance Settings for the current widget
  *
  * @return array $entries Multidimensional array of Gravity Forms entries
  */
 private function get_entries($instance, $form_id)
 {
     // Get the settings for the View ID
     $view_settings = gravityview_get_template_settings($instance['view_id']);
     // Set the context view ID to avoid conflicts with the Advanced Filter extension.
     $criteria['context_view_id'] = $instance['view_id'];
     $instance['limit'] = isset($instance['limit']) ? $instance['limit'] : 10;
     $view_settings['id'] = $instance['view_id'];
     $view_settings['page_size'] = $instance['limit'];
     // Prepare paging criteria
     $criteria['paging'] = array('offset' => 0, 'page_size' => $instance['limit']);
     // Prepare Search Criteria
     $criteria['search_criteria'] = array('field_filters' => array());
     $criteria['search_criteria'] = GravityView_frontend::process_search_only_approved($view_settings, $criteria['search_criteria']);
     $criteria['search_criteria']['status'] = apply_filters('gravityview_status', 'active', $view_settings);
     /**
      * Modify the search parameters before the entries are fetched
      */
     $criteria = apply_filters('gravityview/widget/recent-entries/criteria', $criteria, $instance, $form_id);
     $results = GVCommon::get_entries($form_id, $criteria);
     return $results;
 }
Пример #11
0
 /**
  * Get the search class for a search form
  *
  * @since 1.5.4
  *
  * @return string Sanitized CSS class for the search form
  */
 public static function get_search_class($custom_class = '')
 {
     $gravityview_view = GravityView_View::getInstance();
     $search_class = 'gv-search-' . $gravityview_view->search_layout;
     if (!empty($custom_class)) {
         $search_class .= ' ' . $custom_class;
     }
     /**
      * @filter `gravityview_search_class` Modify the CSS class for the search form
      * @param string $search_class The CSS class for the search form
      */
     $search_class = apply_filters('gravityview_search_class', $search_class);
     // Is there an active search being performed? Used by fe-views.js
     $search_class .= GravityView_frontend::getInstance()->isSearch() ? ' gv-is-search' : '';
     return gravityview_sanitize_html_class($search_class);
 }
Пример #12
0
 /**
  * main AJAX logic to retrieve DataTables data
  */
 function get_datatables_data()
 {
     global $gravityview_view;
     if (empty($_POST)) {
         return;
     }
     // Prevent error output
     ob_start();
     // Send correct headers
     $this->do_ajax_headers('application/javascript');
     $this->check_ajax_nonce();
     if (empty($_POST['view_id'])) {
         do_action('gravityview_log_debug', '[DataTables] AJAX request - View ID check failed');
         exit(false);
     }
     // Prevent emails from being encrypted
     add_filter('gravityview_email_prevent_encrypt', '__return_true');
     do_action('gravityview_log_debug', '[DataTables] AJAX Request ($_POST)', $_POST);
     // include some frontend logic
     if (class_exists('GravityView_Plugin') && !class_exists('GravityView_View')) {
         GravityView_Plugin::getInstance()->frontend_actions();
     }
     // Pass $_GET variables to the View functions, since they're relied on heavily
     // for searching and filtering, for example the A-Z widget
     $_GET = json_decode(stripslashes($_POST['getData']), true);
     $view_id = intval($_POST['view_id']);
     // create the view object based on the post_id
     $GravityView_View_Data = GravityView_View_Data::getInstance((int) $_POST['post_id']);
     // get the view data
     $view_data = $GravityView_View_Data->get_view($view_id);
     $view_data['atts']['id'] = $view_id;
     $atts = $view_data['atts'];
     // check for order/sorting
     if (isset($_POST['order'][0]['column'])) {
         $order_index = $_POST['order'][0]['column'];
         if (!empty($_POST['columns'][$order_index]['name'])) {
             // remove prefix 'gv_'
             $atts['sort_field'] = substr($_POST['columns'][$order_index]['name'], 3);
             $atts['sort_direction'] = !empty($_POST['order'][0]['dir']) ? strtoupper($_POST['order'][0]['dir']) : 'ASC';
         }
     }
     // check for search
     if (!empty($_POST['search']['value'])) {
         $atts['search_value'] = esc_attr(stripslashes_deep($_POST['search']['value']));
     }
     // Paging/offset
     $atts['page_size'] = isset($_POST['length']) ? intval($_POST['length']) : '';
     $atts['offset'] = isset($_POST['start']) ? intval($_POST['start']) : 0;
     // prepare to get entries
     $atts = wp_parse_args($atts, GravityView_View_Data::get_default_args());
     // check if someone requested the full filtered data (eg. TableTools print button)
     if ($atts['page_size'] == '-1') {
         $mode = 'all';
         $atts['page_size'] = PHP_INT_MAX;
     } else {
         // regular mode - get view entries
         $mode = 'page';
     }
     $view_data['atts'] = $atts;
     $gravityview_view = new GravityView_View($view_data);
     if (class_exists('GravityView_Cache')) {
         // We need to fetch the search criteria and pass it to the Cache so that the search is used when generating the cache transient key.
         $search_criteria = GravityView_frontend::get_search_criteria($atts, $view_data['form_id']);
         // make sure to allow late filter ( used on Advanced Filter extension )
         $criteria = apply_filters('gravityview_search_criteria', array('search_criteria' => $search_criteria), $view_data['form_id'], $_POST['view_id']);
         $atts['search_criteria'] = $criteria['search_criteria'];
         // Cache key should also depend on the View assigned fields
         $atts['directory_table-columns'] = !empty($view_data['fields']['directory_table-columns']) ? $view_data['fields']['directory_table-columns'] : array();
         // cache depends on user session
         $atts['user_session'] = $this->get_user_session();
         $Cache = new GravityView_Cache($view_data['form_id'], $atts);
         if ($output = $Cache->get()) {
             do_action('gravityview_log_debug', '[DataTables] Cached output found; using cache with key ' . $Cache->get_key());
             // update DRAW (mr DataTables is very sensitive!)
             $temp = json_decode($output, true);
             $temp['draw'] = intval($_POST['draw']);
             $output = json_encode($temp);
             exit($output);
         }
     }
     $view_entries = GravityView_frontend::get_view_entries($atts, $view_data['form_id']);
     $data = $this->get_output_data($view_entries, $view_data);
     // wrap all
     $output = array('draw' => intval($_POST['draw']), 'recordsTotal' => intval($view_entries['count']), 'recordsFiltered' => intval($view_entries['count']), 'data' => $data);
     do_action('gravityview_log_debug', '[DataTables] Ajax request answer', $output);
     $json = json_encode($output);
     if (class_exists('GravityView_Cache')) {
         do_action('gravityview_log_debug', '[DataTables] Setting cache');
         // Cache results
         $Cache->set($json, 'datatables_output');
     }
     // End prevent error output
     ob_end_clean();
     exit($json);
 }
Пример #13
0
 /**
  * @covers ::gv_directory_link()
  * @covers GravityView_API::directory_link()
  */
 public function test_directory_link()
 {
     $post_array = array('post_content' => 'asdasdsd', 'post_type' => 'post', 'post_status' => 'publish');
     $post_id = wp_insert_post($post_array);
     $view_post_type_id = $this->_get_new_view_id();
     $_GET['pagenum'] = 2;
     $add_pagination = false;
     $this->assertEquals(site_url('?p=' . $post_id), GravityView_API::directory_link($post_id, $add_pagination));
     $add_pagination = true;
     $this->assertEquals(site_url('?p=' . $post_id . '&pagenum=2'), GravityView_API::directory_link($post_id, $add_pagination));
     // Make sure the cache is working properly
     $this->assertEquals(site_url('?p=' . $post_id), wp_cache_get('gv_directory_link_' . $post_id));
     //
     // Use $gravityview_view data
     //
     global $gravityview_view;
     global $post;
     $post = get_post($view_post_type_id);
     GravityView_frontend::getInstance()->parse_content();
     $gravityview_view->setViewId($view_post_type_id);
     // Test post_id has been set
     $gravityview_view->setPostId($post_id);
     /* TODO - fix this assertion */
     $this->assertEquals(site_url('?p=' . $post_id . '&pagenum=2'), GravityView_API::directory_link());
     $gravityview_view->setPostId($post_id);
     //
     // TESTING AJAX
     //
     define('DOING_AJAX', true);
     // No passed post_id; use $_POST when DOING_AJAX is set
     $this->assertNull(GravityView_API::directory_link());
     $_POST['post_id'] = $post_id;
     // No passed post_id; use $_POST when DOING_AJAX is set
     $this->assertEquals(site_url('?p=' . $post_id . '&pagenum=2'), GravityView_API::directory_link());
 }
Пример #14
0
/**
 * Theme function to identify if it is a Single Entry View
 *
 * @since  1.5.4
 * @return bool|string False if not, single entry slug if true
 */
function gravityview_is_single_entry()
{
    return GravityView_frontend::is_single_entry();
}
Пример #15
0
$field = $gravityview_view->getCurrentField();
$created_by = rgar($field['entry'], 'created_by');
// There was no logged in user who created this entry.
if (empty($created_by)) {
    return;
}
//$form_id = $gravityview_view->getFormId();
$form_id = 0;
// Get the settings for the View ID
$view_settings = gravityview_get_template_settings($gravityview_view->getViewId());
$view_settings['page_size'] = $gravityview_view->getCurrentFieldSetting('page_size');
// Prepare paging criteria
$criteria['paging'] = array('offset' => 0, 'page_size' => $view_settings['page_size']);
// Prepare Search Criteria
$criteria['search_criteria'] = array('field_filters' => array(array('key' => 'created_by', 'value' => $created_by, 'operator' => 'is')));
$criteria['search_criteria'] = GravityView_frontend::process_search_only_approved($view_settings, $criteria['search_criteria']);
$criteria['search_criteria']['status'] = apply_filters('gravityview_status', 'active', $view_settings);
/**
 * Modify the search parameters before the entries are fetched
 *
 * @since 1.11
 *
 * @param array $criteria Gravity Forms search criteria array, as used by GVCommon::get_entries()
 * @param array $view_settings Associative array of settings with plugin defaults used if not set by the View
 * @param int $form_id The Gravity Forms ID
 */
$criteria = apply_filters('gravityview/field/other_entries/criteria', $criteria, $view_settings, $form_id);
$entries = GVCommon::get_entries($form_id, $criteria);
// Don't show if no entries and the setting says so
if (empty($entries) && $gravityview_view->getCurrentFieldSetting('no_entries_hide')) {
    return;
Пример #16
0
 /**
  * Parse content to determine if there is a GV shortcode to allow for enqueing necessary files in the head.
  *
  * @uses gravityview_has_shortcode_r() Check whether shortcode exists (recursively)
  * @uses shortcode_parse_atts() Parse each GV shortcode
  * @uses  gravityview_get_template_settings() Get the settings for the View ID
  * @param  string $content $post->post_content content
  * @return int|null|array ID of the View. If there are multiple views in the content, array of IDs parsed.
  */
 function parse_post_content($content)
 {
     /**
      * @hack This is so that the shortcode is registered for the oEmbed preview in the Admin
      * @since 1.6
      */
     if (!shortcode_exists('gravityview')) {
         add_shortcode('gravityview', array(GravityView_frontend::getInstance(), 'shortcode'));
     }
     $shortcodes = gravityview_has_shortcode_r($content, 'gravityview');
     if (empty($shortcodes)) {
         return NULL;
     }
     do_action('gravityview_log_debug', 'GravityView_View_Data[parse_post_content] Parsing content, found shortcodes:', $shortcodes);
     $ids = array();
     foreach ($shortcodes as $key => $shortcode) {
         $args = shortcode_parse_atts($shortcode[3]);
         if (empty($args['id'])) {
             do_action('gravityview_log_error', sprintf('GravityView_View_Data[parse_post_content] Returning; no ID defined in shortcode atts for Post #%s (Atts)', $post->ID), $shortcode);
             continue;
         }
         do_action('gravityview_log_debug', sprintf('GravityView_View_Data[parse_post_content] Adding view #%s with shortcode args', $args['id']), $args);
         // Store the View to the object for later fetching.
         $this->add_view($args['id'], $args);
         $ids[] = $args['id'];
     }
     if (empty($ids)) {
         return NULL;
     }
     // If it's just one ID, return that.
     // Otherwise, return array of IDs
     return sizeof($ids) === 1 ? $ids[0] : $ids;
 }
Пример #17
0
<?php

/**
 * Display other entries created by the entry creator field type
 *
 * @package GravityView
 * @subpackage GravityView/templates/fields
 */
$gravityview_view = GravityView_View::getInstance();
$field = $gravityview_view->getCurrentField();
$created_by = rgar($field['entry'], 'created_by');
// There was no logged in user who created this entry.
if (empty($created_by)) {
    return;
}
// Generate the search parameters
$args = array('id' => $gravityview_view->getViewId(), 'page_size' => $gravityview_view->getCurrentFieldSetting('page_size'), 'search_field' => 'created_by', 'search_value' => $created_by, 'search_operator' => 'is');
/**
 * @since 1.7.6
 */
$args = apply_filters('gravityview/field/other_entries/args', $args, $field);
// Get the entries for the search
$entries = GravityView_frontend::get_view_entries($args, $field['form']['id']);
// Don't show if no entries and the setting says so
if (empty($entries['entries']) && $gravityview_view->getCurrentFieldSetting('no_entries_hide')) {
    return;
}
// If there are search results, get the entry list object
$list = new GravityView_Entry_List($entries['entries'], $gravityview_view->getPostId(), $field['form'], $gravityview_view->getCurrentFieldSetting('link_format'), $gravityview_view->getCurrentFieldSetting('after_link'), 'other_entries');
// Generate and echo the output
$list->output();
 /**
  * Add $this->shortcode_name shortcode to output self::render_frontend()
  */
 function add_shortcode($run_on_singular = true)
 {
     global $post;
     if (GravityView_Plugin::is_admin()) {
         return;
     }
     if (empty($this->shortcode_name)) {
         return;
     }
     // If the widget shouldn't output on single entries, don't show it
     if (empty($this->show_on_single) && class_exists('GravityView_frontend') && GravityView_frontend::is_single_entry()) {
         do_action('gravityview_log_debug', sprintf('%s[add_shortcode]: Skipping; set to not run on single entry.', get_class($this)));
         add_shortcode($this->shortcode_name, '__return_null');
         return;
     }
     if (!has_gravityview_shortcode($post)) {
         do_action('gravityview_log_debug', sprintf('%s[add_shortcode]: No shortcode present; not adding render_frontend shortcode.', get_class($this)));
         add_shortcode($this->shortcode_name, '__return_null');
         return;
     }
     add_shortcode($this->shortcode_name, array($this, 'render_shortcode'));
 }
 /**
  * Get entry array from `entry_id` parameter. If no $entry_id
  *
  * @since 1.15
  * @uses GVCommon::get_entry
  * @uses GravityView_frontend::getSingleEntry
  *
  * @param int $entry_id Gravity Forms Entry ID. If not passed, current View's current entry ID will be used, if found.
  *
  * @return array|bool Gravity Forms array, if found. Otherwise, false.
  */
 private function get_entry($entry_id = 0)
 {
     $backup_entry = GravityView_frontend::getInstance()->getSingleEntry() ? GravityView_frontend::getInstance()->getEntry() : GravityView_View::getInstance()->getCurrentEntry();
     if (empty($entry_id)) {
         if (!$backup_entry) {
             do_action('gravityview_log_error', __METHOD__ . ' No entry defined (or entry id not valid number)', $this->settings);
             return false;
         }
         $entry = $backup_entry;
     } else {
         $entry = wp_cache_get('gv_entry_link_entry_' . $entry_id, 'gravityview_entry_link_shortcode');
         if (false === $entry) {
             $entry = GVCommon::get_entry($entry_id, true, false);
             wp_cache_add('gv_entry_link_entry_' . $entry_id, $entry, 'gravityview_entry_link_shortcode');
         }
     }
     // No search results
     if (false === $entry) {
         do_action('gravityview_log_error', __METHOD__ . ' No entries match the entry ID defined', $entry_id);
         return false;
     }
     return $entry;
 }
Пример #20
0
 /**
  * Calculates the Search Criteria used on the self::get_entries / self::get_entry methods
  *
  * @since 1.7.4
  *
  * @param null $passed_criteria array Input Criteria (search_criteria, sorting, paging)
  * @param null $form_ids array Gravity Forms form IDs
  * @return array|mixed|void
  */
 public static function calculate_get_entries_criteria($passed_criteria = null, $form_ids = null)
 {
     $search_criteria_defaults = array('search_criteria' => null, 'sorting' => null, 'paging' => null, 'cache' => isset($passed_criteria['cache']) ? $passed_criteria['cache'] : true);
     $criteria = wp_parse_args($passed_criteria, $search_criteria_defaults);
     if (!empty($criteria['search_criteria']['field_filters'])) {
         foreach ($criteria['search_criteria']['field_filters'] as &$filter) {
             if (!is_array($filter)) {
                 continue;
             }
             // By default, we want searches to be wildcard for each field.
             $filter['operator'] = empty($filter['operator']) ? 'contains' : $filter['operator'];
             /**
              * @filter `gravityview_search_operator` Modify the search operator for the field (contains, is, isnot, etc)
              * @param string $operator Existing search operator
              * @param array $filter array with `key`, `value`, `operator`, `type` keys
              */
             $filter['operator'] = apply_filters('gravityview_search_operator', $filter['operator'], $filter);
         }
     }
     /**
      * Prepare date formats to be in Gravity Forms DB format;
      * $passed_criteria may include date formats incompatible with Gravity Forms.
      */
     foreach (array('start_date', 'end_date') as $key) {
         if (!empty($criteria['search_criteria'][$key])) {
             // Use date_create instead of new DateTime so it returns false if invalid date format.
             $date = date_create($criteria['search_criteria'][$key]);
             if ($date) {
                 // Gravity Forms wants dates in the `Y-m-d H:i:s` format.
                 $criteria['search_criteria'][$key] = $date->format('Y-m-d H:i:s');
             } else {
                 // If it's an invalid date, unset it. Gravity Forms freaks out otherwise.
                 unset($criteria['search_criteria'][$key]);
                 do_action('gravityview_log_error', '[filter_get_entries_criteria] ' . $key . ' Date format not valid:', $criteria['search_criteria'][$key]);
             }
         }
     }
     // When multiple views are embedded, OR single entry, calculate the context view id and send it to the advanced filter
     if (class_exists('GravityView_View_Data') && GravityView_View_Data::getInstance()->has_multiple_views() || GravityView_frontend::getInstance()->single_entry) {
         $criteria['context_view_id'] = GravityView_frontend::getInstance()->get_context_view_id();
     } elseif ('delete' === RGForms::get('action')) {
         $criteria['context_view_id'] = isset($_GET['view_id']) ? $_GET['view_id'] : null;
     } elseif (!isset($criteria['context_view_id'])) {
         // Prevent overriding the Context View ID: Some widgets could set the context_view_id (e.g. Recent Entries widget)
         $criteria['context_view_id'] = null;
     }
     /**
      * @filter `gravityview_search_criteria` Apply final criteria filter (Used by the Advanced Filter extension)
      * @param array $criteria Search criteria used by GravityView
      * @param array $form_ids Forms to search
      * @param int $view_id ID of the view being used to search
      */
     $criteria = apply_filters('gravityview_search_criteria', $criteria, $form_ids, $criteria['context_view_id']);
     return $criteria;
 }
 /**
  * Capture bulk actions - gf_entries table
  *
  * @uses  GravityView_frontend::get_search_criteria() Convert the $_POST search request into a properly formatted request.
  * @access public
  * @return void|boolean
  */
 public function process_bulk_action()
 {
     if (!is_admin() || !class_exists('GFForms') || empty($_POST)) {
         return false;
     }
     // The action is formatted like: gvapprove-16 or gvunapprove-16, where the first word is the name of the action and the second is the ID of the form.
     $bulk_action = $this->get_gv_bulk_action();
     // gforms_entry_list is the nonce that confirms we're on the right page
     // gforms_update_note is sent when bulk editing entry notes. We don't want to process then.
     if ($bulk_action && rgpost('gforms_entry_list') && empty($_POST['gforms_update_note'])) {
         check_admin_referer('gforms_entry_list', 'gforms_entry_list');
         /**
          * The extra '-' is to make sure that there are at *least* two items in array.
          * @see https://github.com/katzwebservices/GravityView/issues/370
          */
         $bulk_action .= '-';
         list($approved_status, $form_id) = explode('-', $bulk_action);
         if (empty($form_id)) {
             do_action('gravityview_log_error', '[process_bulk_action] Form ID is empty from parsing bulk action.', $bulk_action);
             return false;
         }
         // All entries are set to be updated, not just the visible ones
         if (!empty($_POST['all_entries'])) {
             // Convert the current entry search into GF-formatted search criteria
             $search = array('search_field' => isset($_POST['f']) ? $_POST['f'][0] : 0, 'search_value' => isset($_POST['v'][0]) ? $_POST['v'][0] : '', 'search_operator' => isset($_POST['o'][0]) ? $_POST['o'][0] : 'contains');
             $search_criteria = GravityView_frontend::get_search_criteria($search, $form_id);
             // Get all the entry IDs for the form
             $entries = gravityview_get_entry_ids($form_id, $search_criteria);
         } else {
             // Changed from 'lead' to 'entry' in 2.0
             $entries = isset($_POST['lead']) ? $_POST['lead'] : $_POST['entry'];
         }
         if (empty($entries)) {
             do_action('gravityview_log_error', '[process_bulk_action] Entries are empty');
             return false;
         }
         $entry_count = count($entries) > 1 ? sprintf(__('%d entries', 'gravityview'), count($entries)) : __('1 entry', 'gravityview');
         switch ($approved_status) {
             case $this->bulk_action_prefixes['approve']:
                 self::update_bulk($entries, 1, $form_id);
                 $this->bulk_update_message = sprintf(__('%s approved.', 'gravityview'), $entry_count);
                 break;
             case $this->bulk_action_prefixes['unapprove']:
                 self::update_bulk($entries, 0, $form_id);
                 $this->bulk_update_message = sprintf(__('%s disapproved.', 'gravityview'), $entry_count);
                 break;
         }
     }
 }