コード例 #1
0
 /**
  * @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');
 }
コード例 #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();
 }
コード例 #4
0
 /**
  * Validate attributes passed to the [gravityview] shortcode. Supports {get} Merge Tags values.
  *
  * Attributes passed to the shortcode are compared to registered attributes {@see GravityView_View_Data::get_default_args}
  * Only attributes that are defined will be allowed through.
  *
  * Then, {get} merge tags are replaced with their $_GET values, if passed
  *
  * Then, attributes are sanitized based on the type of setting (number, checkbox, select, radio, text)
  *
  * @since 1.15.1
  *
  * @see GravityView_View_Data::get_default_args Only attributes defined in get_default_args() are valid to be passed via the shortcode
  *
  * @param array $passed_atts Attribute pairs defined to render the View
  *
  * @return array Valid and sanitized attribute pairs
  */
 private function parse_and_sanitize_atts($passed_atts)
 {
     $defaults = GravityView_View_Data::get_default_args(true);
     $supported_atts = array_fill_keys(array_keys($defaults), '');
     // Whittle down the attributes to only valid pairs
     $filtered_atts = shortcode_atts($supported_atts, $passed_atts, 'gravityview');
     // Only keep the passed attributes after making sure that they're valid pairs
     $filtered_atts = function_exists('array_intersect_key') ? array_intersect_key($passed_atts, $filtered_atts) : $filtered_atts;
     $atts = array();
     foreach ($filtered_atts as $key => $passed_value) {
         // Allow using GravityView merge tags in shortcode attributes, like {get} and {created_by}
         $passed_value = GravityView_Merge_Tags::replace_variables($passed_value);
         switch ($defaults[$key]['type']) {
             /**
              * Make sure number fields are numeric.
              * Also, convert mixed number strings to numbers
              * @see http://php.net/manual/en/function.is-numeric.php#107326
              */
             case 'number':
                 if (is_numeric($passed_value)) {
                     $atts[$key] = $passed_value + 0;
                 }
                 break;
                 // Checkboxes should be 1 or 0
             // Checkboxes should be 1 or 0
             case 'checkbox':
                 $atts[$key] = gv_empty($passed_value) ? 0 : 1;
                 break;
                 /**
                  * Only allow values that are defined in the settings
                  */
             /**
              * Only allow values that are defined in the settings
              */
             case 'select':
             case 'radio':
                 $options = isset($defaults[$key]['choices']) ? $defaults[$key]['choices'] : $defaults[$key]['options'];
                 if (in_array($passed_value, array_keys($options))) {
                     $atts[$key] = $passed_value;
                 }
                 break;
             case 'text':
             default:
                 $atts[$key] = $passed_value;
                 break;
         }
     }
     return $atts;
 }
コード例 #5
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'])))));
         }
     }
 }
コード例 #6
0
ファイル: factory.php プロジェクト: hansstam/makerfaire
 /**
  * @param $args
  *
  * @return int|WP_Error
  */
 function create_object($args)
 {
     $args = wp_parse_args($args, $this->default_generation_definitions);
     $form_id = $args['form_id'];
     $template_id = isset($args['template_id']) ? $args['template_id'] : 'preset_business_data';
     $settings = isset($args['settings']) ? $args['settings'] : GravityView_View_Data::get_default_args();
     $fields = isset($args['fields']) ? serialize($args['fields']) : 'a:1:{s:23:"directory_table-columns";a:3:{s:13:"535d63d1488b0";a:9:{s:2:"id";s:1:"4";s:5:"label";s:13:"Business Name";s:10:"show_label";s:1:"1";s:12:"custom_label";s:0:"";s:12:"custom_class";s:0:"";s:12:"show_as_link";s:1:"0";s:13:"search_filter";s:1:"0";s:13:"only_loggedin";s:1:"0";s:17:"only_loggedin_cap";s:4:"read";}s:13:"535d63d379a3c";a:9:{s:2:"id";s:2:"12";s:5:"label";s:20:"Business Description";s:10:"show_label";s:1:"1";s:12:"custom_label";s:0:"";s:12:"custom_class";s:0:"";s:12:"show_as_link";s:1:"0";s:13:"search_filter";s:1:"0";s:13:"only_loggedin";s:1:"0";s:17:"only_loggedin_cap";s:4:"read";}s:13:"535d63dc735a6";a:9:{s:2:"id";s:1:"2";s:5:"label";s:7:"Address";s:10:"show_label";s:1:"1";s:12:"custom_label";s:0:"";s:12:"custom_class";s:0:"";s:12:"show_as_link";s:1:"0";s:13:"search_filter";s:1:"0";s:13:"only_loggedin";s:1:"0";s:17:"only_loggedin_cap";s:4:"read";}}}';
     $insert_post_response = parent::create_object($args);
     if ($insert_post_response && !is_wp_error($insert_post_response)) {
         $view_meta = array('_gravityview_form_id' => $form_id, '_gravityview_template_settings' => $settings, '_gravityview_directory_template' => $template_id, '_gravityview_directory_widgets' => 'a:0:{}', '_gravityview_directory_fields' => $fields);
         foreach ($view_meta as $meta_key => $meta_value) {
             $meta_value = maybe_unserialize($meta_value);
             update_post_meta($insert_post_response, $meta_key, $meta_value);
         }
     }
     return $insert_post_response;
 }
 /**
  * @inheritDoc
  */
 public function update($new_instance, $old_instance)
 {
     $instance = $old_instance;
     if ($this->is_preview()) {
         //Oh! Sorry but still not fully compatible with customizer
         return $instance;
     }
     $defaults = array('title' => '', 'view_id' => 0, 'post_id' => '', 'search_fields' => '');
     $new_instance = wp_parse_args((array) $new_instance, $defaults);
     $instance['title'] = strip_tags($new_instance['title']);
     $instance['view_id'] = absint($new_instance['view_id']);
     $instance['search_fields'] = $new_instance['search_fields'];
     $instance['post_id'] = $new_instance['post_id'];
     $is_valid_embed_id = GravityView_View_Data::is_valid_embed_id($new_instance['post_id'], $instance['view_id']);
     //check if post_id is a valid post with embedded View
     $instance['error_post_id'] = is_wp_error($is_valid_embed_id) ? $is_valid_embed_id->get_error_message() : NULL;
     // Share that the widget isn't brand new
     $instance['updated'] = 1;
     return $instance;
 }
コード例 #8
0
 /**
  * @since 1.6
  * @see WP_Widget::update()
  *
  * @param array $new_instance Widget form settings after update
  * @param array $old_instance Widget form settings before update
  *
  * @return array Calculated widget settings after processing
  */
 public function update($new_instance, $old_instance)
 {
     $instance = $new_instance;
     // Force positive number
     $instance['limit'] = empty($instance['limit']) ? 10 : absint($instance['limit']);
     $instance['view_id'] = intval($instance['view_id']);
     $instance['link_format'] = trim(rtrim($instance['link_format']));
     $instance['link_format'] = empty($instance['link_format']) ? $old_instance['link_format'] : $instance['link_format'];
     $instance['post_id'] = empty($instance['post_id']) ? '' : intval($instance['post_id']);
     $is_valid_embed_id = GravityView_View_Data::is_valid_embed_id($instance['post_id'], $instance['view_id']);
     //check if post_id is a valid post with embedded View
     $instance['error_post_id'] = is_wp_error($is_valid_embed_id) ? $is_valid_embed_id->get_error_message() : NULL;
     // Share that the widget isn't brand new
     $instance['updated'] = 1;
     /**
      * Modify the updated instance. This will allow for validating any added instance settings externally.
      *
      * @param array $instance Calculated widget settings after processing
      * @param array $new_instance Widget form settings after update
      * @param array $old_instance Widget form settings before update
      */
     $instance = apply_filters('gravityview/widget/update', $instance, $new_instance, $old_instance);
     return $instance;
 }
コード例 #9
0
 /**
  * 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'])))));
                 }
             }
         }
     }
 }
コード例 #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);
 }
コード例 #11
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;
 }
コード例 #12
0
 /**
  * Add tooltip text for use throughout the UI
  * @param  array       $tooltips Array of Gravity Forms tooltips
  * @return array                Modified tooltips array
  */
 public function tooltips($tooltips = array())
 {
     $gv_tooltips = array();
     // Generate tooltips for View settings
     $default_args = GravityView_View_Data::get_default_args(true);
     foreach ($default_args as $key => $arg) {
         // If an arg has `tooltip` defined, but it's false, don't display a tooltip
         if (isset($arg['tooltip']) && empty($arg['tooltip'])) {
             continue;
         }
         // By default, use `tooltip` if defined.
         $tooltip = empty($arg['tooltip']) ? NULL : $arg['tooltip'];
         // Otherwise, use the description as a tooltip.
         if (empty($tooltip) && !empty($arg['desc'])) {
             $tooltip = $arg['desc'];
         }
         // If there's no tooltip set, continue
         if (empty($tooltip)) {
             continue;
         }
         // Add the tooltip
         $gv_tooltips['gv_' . $key] = array('title' => $arg['label'], 'value' => $tooltip);
     }
     $gv_tooltips['gv_css_merge_tags'] = array('title' => __('CSS Merge Tags', 'gravityview'), 'value' => sprintf(__('Developers: The CSS classes will be sanitized using the %ssanitize_title_with_dashes()%s function.', 'gravityview'), '<code>', '</code>'));
     /**
      * @filter `gravityview_tooltips` The tooltips GravityView adds to the Gravity Forms tooltip array
      * @param array $gv_tooltips Associative array with unique keys containing array of `title` and `value` keys, as expected by `gform_tooltips` filter
      */
     $gv_tooltips = apply_filters('gravityview_tooltips', $gv_tooltips);
     foreach ($gv_tooltips as $key => $tooltip) {
         $title = empty($tooltip['title']) ? '' : '<h6>' . esc_html($tooltip['title']) . '</h6>';
         $tooltips[$key] = $title . wpautop(esc_html($tooltip['value']));
     }
     return $tooltips;
 }
コード例 #13
0
ファイル: class-data.php プロジェクト: roarmoser/gv1
 /**
  * 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;
 }
コード例 #14
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);
 }
コード例 #15
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_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;
 }
コード例 #16
0
 /**
  * Map GravityView
  * @see GravityView_View_Data::get_default_args()
  * @param  array $views Array of Views
  * @return array                    Array of parameters
  */
 function get_params($views_array)
 {
     if (!class_exists('GravityView_View_Data')) {
         return $views_array;
     }
     $default_params = array('page_size' => GravityView_View_Data::get_default_arg('page_size', true), 'show_only_approved' => GravityView_View_Data::get_default_arg('show_only_approved', true), 'lightbox' => GravityView_View_Data::get_default_arg('lightbox', true));
     // Add the view picker first
     $params = array(array('value' => $views_array, 'heading' => __('View', 'gravityview-visual-composer'), 'description' => __('Select a View to add it to your post or page.', 'gravityview-visual-composer'), 'type' => 'dropdown', 'param_name' => 'id', 'admin_label' => true));
     foreach (array('page_size', 'lightbox', 'show_only_approved', 'user_edit') as $key) {
         $param = GravityView_View_Data::get_default_arg($key, true);
         $type = isset($param['type']) ? $param['type'] : null;
         $heading = isset($param['label']) ? $param['label'] : null;
         $value = isset($param['value']) ? $param['value'] : null;
         // Different name for dropdown
         switch ($param['type']) {
             case 'select':
                 $type = 'dropdown';
                 $value = isset($param['options']) ? $param['options'] : array();
                 break;
             case 'checkbox':
                 $heading = '';
                 $value = array($heading => $value);
                 break;
             case 'number':
             case 'text':
                 $type = 'textfield';
                 break;
         }
         $params[] = array('type' => $type, 'heading' => $heading, 'class' => !empty($param['class']) ? $param['class'] : NULL, 'param_name' => $key, 'description' => empty($param['desc']) ? NULL : $param['desc'], 'value' => $value, 'admin_label' => true);
     }
     return $params;
 }
コード例 #17
0
ファイル: class-oembed.php プロジェクト: mgratch/GravityView
 /**
  * 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']);
 }
コード例 #18
0
 /**
  * Output a table row for view settings
  * @param  string $key              The key of the input
  * @param  array  $current_settings Associative array of current settings to use as input values, if set. If not set, the defaults are used.
  * @param  [type] $override_input   [description]
  * @param  string $name             [description]
  * @param  string $id               [description]
  * @return [type]                   [description]
  */
 public static function render_setting_row($key = '', $current_settings = array(), $override_input = null, $name = 'template_settings[%s]', $id = 'gravityview_se_%s')
 {
     $setting = GravityView_View_Data::get_default_arg($key, true);
     // If the key doesn't exist, there's something wrong.
     if (empty($setting)) {
         return;
     }
     /**
      * @deprecated setting index 'name' was replaced by 'label'
      * @see GravityView_FieldType::get_field_defaults
      */
     if (isset($setting['name']) && empty($setting['label'])) {
         $setting['label'] = $setting['name'];
         _deprecated_function('GravityView_FieldType::get_field_defaults', '1.1.7', '[label] instead of [name] when defining the setting ' . $key . ' details');
     }
     $name = esc_attr(sprintf($name, $key));
     $setting['id'] = esc_attr(sprintf($id, $key));
     $setting['tooltip'] = 'gv_' . $key;
     // Use default if current setting isn't set.
     $curr_value = isset($current_settings[$key]) ? $current_settings[$key] : $setting['value'];
     // default setting type = text
     $setting['type'] = empty($setting['type']) ? 'text' : $setting['type'];
     // merge tags
     if (!isset($setting['merge_tags'])) {
         if ($setting['type'] === 'text') {
             $setting['merge_tags'] = true;
         } else {
             $setting['merge_tags'] = false;
         }
     }
     // render the setting
     $type_class = self::load_type_class($setting);
     if (class_exists($type_class)) {
         $render_type = new $type_class($name, $setting, $curr_value);
         ob_start();
         $render_type->render_setting($override_input);
         $output = ob_get_clean();
     }
     // Check if setting is specific for a template
     if (!empty($setting['show_in_template'])) {
         if (!is_array($setting['show_in_template'])) {
             $setting['show_in_template'] = array($setting['show_in_template']);
         }
         $show_if = ' data-show-if="' . implode(' ', $setting['show_in_template']) . '"';
     } else {
         $show_if = '';
     }
     // output
     echo '<tr valign="top" ' . $show_if . '>' . $output . '</tr>';
 }
コード例 #19
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);
 }
コード例 #20
0
    /**
     * Add shortcode popup div
     *
     * @access public
     * @return void
     */
    function add_shortcode_popup()
    {
        global $post;
        if (!$this->is_post_editor_screen()) {
            return;
        }
        $post_type = get_post_type_object($post->post_type);
        $views = get_posts(array('post_type' => 'gravityview', 'posts_per_page' => -1));
        // If there are no views set up yet, we get outta here.
        if (empty($views)) {
            echo '<div id="select_gravityview_view"><div class="wrap">' . GravityView_Post_Types::no_views_text() . '</div></div>';
            return;
        }
        ?>
		<div id="select_gravityview_view">
			<form action="#" method="get" id="select_gravityview_view_form">
				<div class="wrap">

					<h2 class=""><?php 
        esc_html_e('Embed a View', 'gravityview');
        ?>
</h2>
					<p class="subtitle"><?php 
        printf(esc_attr(__('Use this form to embed a View into this %s. %sLearn more about using shortcodes.%s', 'gravityview')), $post_type->labels->singular_name, '<a href="http://gravityview.co/support/documentation/202934188/" target="_blank">', '</a>');
        ?>
</p>

					<div>
						<h3><label for="gravityview_id"><?php 
        esc_html_e('Select a View', 'gravityview');
        ?>
</label></h3>

						<select name="gravityview_id" id="gravityview_id">
							<option value=""><?php 
        esc_html_e('&mdash; Select a View to Insert &mdash;', 'gravityview');
        ?>
</option>
							<?php 
        foreach ($views as $view) {
            $title = empty($view->post_title) ? __('(no title)', 'gravityview') : $view->post_title;
            echo '<option value="' . $view->ID . '">' . esc_html(sprintf('%s #%d', $title, $view->ID)) . '</option>';
        }
        ?>
						</select>
					</div>

					<table class="form-table hide-if-js">

						<caption><?php 
        esc_html_e('View Settings', 'gravityview');
        ?>
</caption>

						<?php 
        $settings = GravityView_View_Data::get_default_args(true);
        foreach ($settings as $key => $setting) {
            if (empty($setting['show_in_shortcode'])) {
                continue;
            }
            GravityView_Render_Settings::render_setting_row($key, array(), NULL, 'gravityview_%s', 'gravityview_%s');
        }
        ?>

					</table>

					<div class="submit">
						<input type="submit" class="button button-primary button-large alignleft hide-if-js" value="<?php 
        esc_attr_e('Insert View', 'gravityview');
        ?>
" id="insert_gravityview_view" />
						<input class="button button-secondary alignright" type="submit" onclick="tb_remove(); return false;" value="<?php 
        esc_attr_e("Cancel", 'gravityview');
        ?>
" />
					</div>

				</div>
			</form>
		</div>
		<?php 
    }
コード例 #21
0
ファイル: class-common.php プロジェクト: roarmoser/gv1
 /**
  * Get all the settings for a View
  *
  * @uses  GravityView_View_Data::get_default_args() Parses the settings with the plugin defaults as backups.
  * @param  int $post_id View ID
  * @return array          Associative array of settings with plugin defaults used if not set by the View
  */
 public static function get_template_settings($post_id)
 {
     $settings = get_post_meta($post_id, '_gravityview_template_settings', true);
     if (class_exists('GravityView_View_Data')) {
         $defaults = GravityView_View_Data::get_default_args();
         return wp_parse_args((array) $settings, $defaults);
     }
     // Backup, in case GravityView_View_Data isn't loaded yet.
     return $settings;
 }
コード例 #22
0
 public function _get_new_view_id()
 {
     $view_array = array('post_content' => '', 'post_type' => 'gravityview', 'post_status' => 'publish');
     // Add the View
     $view_post_type_id = wp_insert_post($view_array);
     // Set the form ID
     update_post_meta($view_post_type_id, '_gravityview_form_id', $this->form_id);
     // Set the View settigns
     update_post_meta($view_post_type_id, '_gravityview_template_settings', GravityView_View_Data::get_default_args());
     // Set the template to be table
     update_post_meta($view_post_type_id, '_gravityview_directory_template', 'default_table');
     return $view_post_type_id;
 }