/**
  * 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;
 }
예제 #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 '';
}
예제 #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']);
 }
예제 #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;
 }
예제 #6
0
파일: class-api.php 프로젝트: roarmoser/gv1
 /**
  * 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);
 }
 function __construct()
 {
     $this->gravityview_view = GravityView_frontend::getInstance();
     $this->add_hooks();
 }
예제 #8
0
    }
    /**
     * Checks if field (column) is sortable
     *
     * @param string $field Field settings
     * @param array $form Gravity Forms form array
     *
     * @since 1.7
     *
     * @return bool True: Yes, field is sortable; False: not sortable
     */
    public function is_field_sortable($field_id = '', $form)
    {
        if (is_numeric($field_id)) {
            $field = GFFormsModel::get_field($form, $field_id);
            $field_id = $field->type;
        }
        $not_sortable = array('entry_link', 'edit_link', 'delete_link', 'custom', 'list');
        /**
         * Modify what fields should never be sortable.
         * @since 1.7
         */
        $not_sortable = apply_filters('gravityview/sortable/field_blacklist', $not_sortable, $field_id, $form);
        if (in_array($field_id, $not_sortable)) {
            return false;
        }
        return apply_filters("gravityview/sortable/formfield_{$form['id']}_{$field_id}", apply_filters("gravityview/sortable/field_{$field_id}", true, $form));
    }
}
GravityView_frontend::getInstance();
예제 #9
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);
 }
예제 #10
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;
 }
 /**
  * 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;
 }
예제 #12
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());
 }