/**
  * @covers GravityView_Entry_Link_Shortcode::edit_shortcode
  */
 function _test_edit($view, $entry, $atts)
 {
     $nonce_key = GravityView_Edit_Entry::get_nonce_key($view->ID, $entry['form_id'], $entry['id']);
     $nonce = wp_create_nonce($nonce_key);
     $gvid = GravityView_View_Data::getInstance()->has_multiple_views() ? '&gvid=' . gravityview_get_view_id() : '';
     $atts['return'] = 'html';
     $edit_link = $this->object->edit_shortcode($atts);
     $atts['action'] = 'edit';
     $edit_link_backward_compat = $this->object->read_shortcode($atts);
     $this->assertEquals($edit_link, $edit_link_backward_compat);
     $this->assertEquals('<a href="http://example.org/?p=' . $atts['post_id'] . '&amp;entry=' . $atts['entry_id'] . esc_attr($gvid) . '&amp;page=gf_entries&amp;view=entry&amp;edit=' . $nonce . '">Edit Entry</a>', $edit_link, 'edit link');
     $atts['return'] = 'url';
     $edit_link_return_url = $this->object->edit_shortcode($atts);
     $this->assertEquals('http://example.org/?p=' . $atts['post_id'] . '&entry=' . $atts['entry_id'] . $gvid . '&page=gf_entries&view=entry&edit=' . $nonce, $edit_link_return_url, 'edit link URL only');
     $atts['return'] = 'html';
     $atts['link_atts'] = 'target="_blank"&title="check me out!"';
     $edit_link_link_atts = $this->object->edit_shortcode($atts);
     $this->assertEquals('<a title="&quot;check me out!&quot;" target="&quot;_blank&quot;" href="http://example.org/?p=' . $atts['post_id'] . '&amp;entry=' . $atts['entry_id'] . esc_attr($gvid) . '&amp;page=gf_entries&amp;view=entry&amp;edit=' . $nonce . '">Edit Entry</a>', $edit_link_link_atts, 'edit link, return html, with link_atts target="_blank"&title="check me out!"');
     $atts['return'] = 'html';
     $atts['link_atts'] = 'target=_blank&title=check me out!';
     $edit_link_link_atts = $this->object->edit_shortcode($atts);
     $this->assertEquals('<a title="check me out!" target="_blank" href="http://example.org/?p=' . $atts['post_id'] . '&amp;entry=' . $atts['entry_id'] . esc_attr($gvid) . '&amp;page=gf_entries&amp;view=entry&amp;edit=' . $nonce . '">Edit Entry</a>', $edit_link_link_atts, 'edit link return html with link atts target=_blank&title=check me out!');
     $zero = $this->factory->user->create_and_set(array('role' => 'zero'));
     // User without edit entry caps should not be able to see link
     $this->assertNull($this->object->edit_shortcode($atts), 'user with no caps shouldn\'t be able to see link');
 }
Exemplo n.º 2
0
/**
 * Theme function to get a GravityView view
 *
 * @access public
 * @param string $view_id (default: '')
 * @param array $atts (default: array())
 * @return string HTML of the output. Empty string if $view_id is empty.
 */
function get_gravityview($view_id = '', $atts = array())
{
    if (!empty($view_id)) {
        $atts['id'] = $view_id;
        $args = wp_parse_args($atts, GravityView_View_Data::get_default_args());
        $GravityView_frontend = GravityView_frontend::getInstance();
        $GravityView_frontend->setGvOutputData(GravityView_View_Data::getInstance($view_id));
        $GravityView_frontend->set_context_view_id($view_id);
        $GravityView_frontend->set_entry_data();
        return $GravityView_frontend->render_view($args);
    }
    return '';
}
 /**
  * Parse tab content in Ultimate Member profile tabs
  *
  * @since 1.17.2
  *
  * @param array $args Ultimate Member profile settings array
  *
  * @return void
  */
 function parse_um_profile_post_content($args = array())
 {
     global $ultimatemember;
     if (!$ultimatemember || !is_object($ultimatemember) || !class_exists('GravityView_View_Data')) {
         return;
     }
     $active_tab_args = array('name' => $ultimatemember->profile->active_tab(), 'post_type' => 'um_tab', 'numberposts' => 1);
     $active_tab = get_posts($active_tab_args);
     if (!$active_tab) {
         return;
     }
     GravityView_View_Data::getInstance()->parse_post_content($active_tab[0]->post_content);
     wp_reset_postdata();
 }
Exemplo n.º 4
0
 /**
  * Add Edit View link when in embedded View
  *
  * @since 1.13
  * @return void
  */
 function add_edit_view_link()
 {
     /** @var WP_Admin_Bar $wp_admin_bar */
     global $wp_admin_bar;
     if (GFCommon::current_user_can_any('edit_pages')) {
         $view_data = GravityView_View_Data::getInstance();
         $views = $view_data->get_views();
         // If there is a View embed, shor Edit View link.
         // todo: Support multiple View embeds with a drop-down menu
         if (!$this->gravityview_view->isGravityviewPostType() && !empty($views) && !$view_data->has_multiple_views()) {
             $view = reset($views);
             $wp_admin_bar->add_menu(array('id' => 'edit-view', 'title' => __('Edit View', 'gravityview'), 'href' => esc_url_raw(admin_url(sprintf('post.php?post=%d&action=edit', $view['id'])))));
         }
     }
 }
Exemplo n.º 5
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;
 }
Exemplo n.º 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);
 }
Exemplo n.º 7
0
 /**
  * Set entry_id and view_id from the data sent to render_handler
  *
  * @var $entry_id
  * @var $view_id
  *
  * @see render_handler
  */
 private function set_vars($matches, $attr, $url, $rawattr)
 {
     $this->entry_id = $matches['entry_slug'];
     $post_id = $this->get_postid_from_url_and_slug($url, $matches['slug']);
     // The URL didn't have the View Custom Post Type structure.
     if (empty($matches['is_cpt']) || $matches['is_cpt'] !== 'gravityview') {
         do_action('gravityview_log_debug', 'GravityView_oEmbed[render_handler] Embedding an entry inside a post or page', $matches);
         $this->view_id = GravityView_View_Data::getInstance()->maybe_get_view_id($post_id);
     } else {
         $this->view_id = $post_id;
     }
     // The inline content has $_POST['type'] set to "embed", while the "Add Media" modal doesn't set that.
     $this->is_full_oembed_preview = isset($_POST['action']) && $_POST['action'] === 'parse-embed' && !isset($_POST['type']);
 }
 /**
  * Get the Edit Entry fields as configured in the View
  *
  * @since 1.8
  *
  * @param int $view_id
  *
  * @return array Array of fields that are configured in the Edit tab in the Admin
  */
 private function get_configured_edit_fields($form, $view_id)
 {
     // Get all fields for form
     $properties = GravityView_View_Data::getInstance()->get_fields($view_id);
     // If edit tab not yet configured, show all fields
     $edit_fields = !empty($properties['edit_edit-fields']) ? $properties['edit_edit-fields'] : NULL;
     // Show hidden fields as text fields
     $form = $this->fix_hidden_fields($form);
     // Hide fields depending on admin settings
     $fields = $this->filter_fields($form['fields'], $edit_fields);
     // If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't.
     $fields = $this->filter_admin_only_fields($fields, $edit_fields, $form, $view_id);
     return $fields;
 }
 /**
  * Add Edit View link when in embedded View
  *
  * @since 1.13
  * @return void
  */
 function add_edit_view_and_form_link()
 {
     /** @var WP_Admin_Bar $wp_admin_bar */
     global $wp_admin_bar;
     if (GVCommon::has_cap(array('edit_gravityviews', 'edit_gravityview', 'gravityforms_edit_forms'))) {
         $view_data = GravityView_View_Data::getInstance();
         $views = $view_data->get_views();
         // If there is a View embed, show Edit View link.
         if (!empty($views)) {
             $added_forms = array();
             $added_views = array();
             foreach ($views as $view) {
                 $edit_view_title = __('Edit View', 'gravityview');
                 $edit_form_title = __('Edit Form', 'gravityview');
                 if (sizeof($views) > 1) {
                     $edit_view_title = sprintf(_x('Edit View #%d', 'Edit View with the ID of %d', 'gravityview'), $view['id']);
                     $edit_form_title = sprintf(__('Edit Form #%d', 'Edit Form with the ID of %d', 'gravityview'), $view['form_id']);
                 }
                 if (GVCommon::has_cap('edit_gravityview', $view['id']) && !in_array($view['id'], $added_views)) {
                     $added_views[] = $view['id'];
                     $wp_admin_bar->add_menu(array('id' => 'edit-view-' . $view['id'], 'parent' => 'gravityview', 'title' => $edit_view_title, 'href' => esc_url_raw(admin_url(sprintf('post.php?post=%d&action=edit', $view['id'])))));
                 }
                 if (!empty($view['form_id']) && GVCommon::has_cap(array('gravityforms_edit_forms'), $view['form_id']) && !in_array($view['form_id'], $added_forms)) {
                     $added_forms[] = $view['form_id'];
                     $wp_admin_bar->add_menu(array('id' => 'edit-form-' . $view['form_id'], 'parent' => 'gravityview', 'title' => $edit_form_title, 'href' => esc_url_raw(admin_url(sprintf('admin.php?page=gf_edit_forms&id=%d', $view['form_id'])))));
                 }
             }
         }
     }
 }
Exemplo n.º 10
0
 /**
  * Read the $post and process the View data inside
  * @param  array  $wp Passed in the `wp` hook. Not used.
  * @return void
  */
 function parse_content($wp = array())
 {
     global $post;
     // If in admin and NOT AJAX request, get outta here.
     if (GravityView_Plugin::is_admin()) {
         return;
     }
     // Calculate requested Views
     $this->setGvOutputData(GravityView_View_Data::getInstance($post));
     // !important: we need to run this before getting single entry (to kick the advanced filter)
     $this->set_context_view_id();
     $this->setIsGravityviewPostType(get_post_type($post) === 'gravityview');
     $post_id = $this->getPostId() ? $this->getPostId() : (isset($post) ? $post->ID : null);
     $this->setPostId($post_id);
     $post_has_shortcode = !empty($post->post_content) ? gravityview_has_shortcode_r($post->post_content, 'gravityview') : false;
     $this->setPostHasShortcode($this->isGravityviewPostType() ? null : !empty($post_has_shortcode));
     // check if the View is showing search results (only for multiple entries View)
     $this->setIsSearch($this->is_searching());
     unset($entry, $post_id, $post_has_shortcode);
 }
Exemplo n.º 11
0
 /**
  * Checks if the passed post id has the passed View id embedded.
  *
  * Returns
  *
  * @since 1.6.1
  *
  * @param string $post_id Post ID where the View is embedded
  * @param string $view_id View ID
  *
  * @return bool|WP_Error If valid, returns true. If invalid, returns WP_Error containing error message.
  */
 public static function is_valid_embed_id($post_id = '', $view_id = '', $empty_is_valid = true)
 {
     $message = NULL;
     // Not invalid if not set!
     if (empty($post_id) || empty($view_id)) {
         if ($empty_is_valid) {
             return true;
         }
         $message = esc_html__('The ID is required.', 'gravityview');
     }
     if (!$message) {
         $status = get_post_status($post_id);
         // Nothing exists with that post ID.
         if (!is_numeric($post_id)) {
             $message = esc_html__('You did not enter a number. The value entered should be a number, representing the ID of the post or page the View is embedded on.', 'gravityview');
             // @todo Convert to generic article about Embed IDs
             $message .= ' ' . gravityview_get_link('http://docs.gravityview.co/article/222-the-search-widget', __('Learn more&hellip;', 'gravityview'), 'target=_blank');
         }
     }
     if (!$message) {
         // Nothing exists with that post ID.
         if (empty($status) || in_array($status, array('revision', 'attachment'))) {
             $message = esc_html__('There is no post or page with that ID.', 'gravityview');
         }
     }
     if (!$message) {
         $view_ids_in_post = GravityView_View_Data::getInstance()->maybe_get_view_id($post_id);
         // The post or page specified does not contain the shortcode.
         if (false === in_array($view_id, (array) $view_ids_in_post)) {
             $message = sprintf(esc_html__('The Post ID entered is not valid. You may have entered a post or page that does not contain the selected View. Make sure the post contains the following shortcode: %s', 'gravityview'), '<br /><code>[gravityview id="' . intval($view_id) . '"]</code>');
         }
     }
     if (!$message) {
         // It's a View
         if ('gravityview' === get_post_type($post_id)) {
             $message = esc_html__('The ID is already a View.', 'gravityview');
         }
     }
     if ($message) {
         return new WP_Error('invalid_embed_id', $message);
     }
     return true;
 }
Exemplo n.º 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);
 }
Exemplo n.º 13
0
 /**
  * Get the Edit Entry fields as configured in the View
  *
  * @since 1.8
  *
  * @param int $view_id
  *
  * @return array Array of fields that are configured in the Edit tab in the Admin
  */
 private function get_configured_edit_fields($form, $view_id)
 {
     // Get all fields for form
     $properties = GravityView_View_Data::getInstance()->get_fields($view_id);
     // If edit tab not yet configured, show all fields
     $edit_fields = !empty($properties['edit_edit-fields']) ? $properties['edit_edit-fields'] : NULL;
     // Show hidden fields as text fields
     $form = $this->fix_survey_fields($form);
     // Hide fields depending on admin settings
     $fields = $this->filter_fields($form['fields'], $edit_fields);
     // If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't.
     $fields = $this->filter_admin_only_fields($fields, $edit_fields, $form, $view_id);
     /**
      * @filter `gravityview/edit_entry/form_fields` Modify the fields displayed in Edit Entry form
      * @since 1.17
      * @param GF_Field[] $fields Gravity Forms form fields
      * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration
      * @param array $form GF Form array (`fields` key modified to have only fields configured to show in Edit Entry)
      * @param int $view_id View ID
      */
     $fields = apply_filters('gravityview/edit_entry/form_fields', $fields, $edit_fields, $form, $view_id);
     return $fields;
 }