Пример #1
0
<?php

/**
 * Display the website field type
 *
 * @package GravityView
 * @subpackage GravityView/templates/fields
 */
$gravityview_view = GravityView_View::getInstance();
extract($gravityview_view->getCurrentField());
if (!empty($value) && function_exists('gravityview_format_link')) {
    /** @since 1.8 */
    $anchor_text = !empty($field_settings['anchor_text']) ? trim(rtrim($field_settings['anchor_text'])) : false;
    // Check empty again, just in case trim removed whitespace didn't work
    if (!empty($anchor_text)) {
        // Replace the variables
        $anchor_text = GravityView_API::replace_variables($anchor_text, $form, $entry);
    } else {
        $anchor_text = empty($field_settings['truncatelink']) ? $value : gravityview_format_link($value);
    }
    $attributes = empty($field_settings['open_same_window']) ? 'target=_blank' : '';
    echo gravityview_get_link($value, $anchor_text, $attributes);
} else {
    echo $display_value;
}
 /**
  * @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']);
 }
Пример #3
0
 /**
  * Return an array of files prepared for output.
  *
  * Processes files by file type and generates unique output for each. Returns array for each file, with the following keys:
  * - `file_path` => The file path of the file, with a line break
  * - `html` => The file output HTML formatted
  *
  * @since  1.2
  * @todo  Support `playlist` shortcode for playlist of video/audio
  * @param  string $value    Field value passed by Gravity Forms. String of file URL, or serialized string of file URL array
  * @param  string $gv_class Field class to add to the output HTML
  * @return array           Array of file output, with `file_path` and `html` keys (see comments above)
  */
 static function get_files_array($value, $gv_class)
 {
     $gravityview_view = GravityView_View::getInstance();
     extract($gravityview_view->getCurrentField());
     $output_arr = array();
     // Get an array of file paths for the field.
     $file_paths = rgar($field, 'multipleFiles') ? json_decode($value) : array($value);
     // Process each file path
     foreach ($file_paths as $file_path) {
         // If the site is HTTPS, use HTTPS
         if (function_exists('set_url_scheme')) {
             $file_path = set_url_scheme($file_path);
         }
         // This is from Gravity Forms's code
         $file_path = esc_attr(str_replace(" ", "%20", $file_path));
         // If the field is set to link to the single entry, link to it.
         $link = !empty($field_settings['show_as_link']) ? GravityView_API::entry_link($entry, $field) : $file_path;
         // Get file path information
         $file_path_info = pathinfo($file_path);
         $html_format = NULL;
         $disable_lightbox = false;
         $disable_wrapped_link = false;
         // Is this an image?
         $image = new GravityView_Image(array('src' => $file_path, 'class' => 'gv-image gv-field-id-' . $field_settings['id'], 'alt' => $field_settings['label'], 'width' => gravityview_get_context() === 'single' ? NULL : 250));
         $content = $image->html();
         // The new default content is the image, if it exists. If not, use the file name as the content.
         $content = !empty($content) ? $content : $file_path_info['basename'];
         // If pathinfo() gave us the extension of the file, run the switch statement using that.
         $extension = empty($file_path_info['extension']) ? NULL : strtolower($file_path_info['extension']);
         switch (true) {
             // Audio file
             case in_array($extension, wp_get_audio_extensions()):
                 $disable_lightbox = true;
                 if (shortcode_exists('audio')) {
                     $disable_wrapped_link = true;
                     /**
                      * @filter `gravityview_audio_settings` Modify the settings passed to the `wp_video_shortcode()` function
                      * @since  1.2
                      * @param array $audio_settings Array with `src` and `class` keys
                      */
                     $audio_settings = apply_filters('gravityview_audio_settings', array('src' => $file_path, 'class' => 'wp-audio-shortcode gv-audio gv-field-id-' . $field_settings['id']));
                     /**
                      * Generate the audio shortcode
                      * @see http://codex.wordpress.org/Audio_Shortcode
                      * @see https://developer.wordpress.org/reference/functions/wp_audio_shortcode/
                      */
                     $content = wp_audio_shortcode($audio_settings);
                 }
                 break;
                 // Video file
             // Video file
             case in_array($extension, wp_get_video_extensions()):
                 $disable_lightbox = true;
                 if (shortcode_exists('video')) {
                     $disable_wrapped_link = true;
                     /**
                      * @filter `gravityview_video_settings` Modify the settings passed to the `wp_video_shortcode()` function
                      * @since  1.2
                      * @param array $video_settings Array with `src` and `class` keys
                      */
                     $video_settings = apply_filters('gravityview_video_settings', array('src' => $file_path, 'class' => 'wp-video-shortcode gv-video gv-field-id-' . $field_settings['id']));
                     /**
                      * Generate the video shortcode
                      * @see http://codex.wordpress.org/Video_Shortcode
                      * @see https://developer.wordpress.org/reference/functions/wp_video_shortcode/
                      */
                     $content = wp_video_shortcode($video_settings);
                 }
                 break;
                 // PDF
             // PDF
             case $extension === 'pdf':
                 // PDF needs to be displayed in an IFRAME
                 $link = add_query_arg(array('TB_iframe' => 'true'), $link);
                 break;
                 // if not image, do not set the lightbox (@since 1.5.3)
             // if not image, do not set the lightbox (@since 1.5.3)
             case !in_array($extension, array('jpg', 'jpeg', 'jpe', 'gif', 'png')):
                 $disable_lightbox = true;
                 break;
         }
         // If using Link to File, override the content.
         // (We do this here so that the $disable_lightbox can be set. Yes, there's a little more processing time, but oh well.)
         if (!empty($field_settings['link_to_file'])) {
             // Force the content to be the file name
             $content = $file_path_info["basename"];
             // Restore the wrapped link
             $disable_wrapped_link = false;
         }
         // Whether to use lightbox or not
         if ($disable_lightbox || empty($gravityview_view->atts['lightbox']) || !empty($field_settings['show_as_link'])) {
             $link_atts = empty($field_settings['show_as_link']) ? array('target' => '_blank') : array();
         } else {
             $link_atts = array('rel' => sprintf("%s-%s", $gv_class, $entry['id']), 'target' => '_blank', 'class' => 'thickbox');
         }
         /**
          * @filter `gravityview/fields/fileupload/link_atts` Modify the link attributes for a file upload field
          * @param array|string $link_atts Array or attributes string
          * @param array $field Current GravityView field array
          */
         $link_atts = apply_filters('gravityview/fields/fileupload/link_atts', $link_atts, $gravityview_view->getCurrentField());
         /**
          * @filter `gravityview/fields/fileupload/disable_link` Filter to alter the default behaviour of wrapping images (or image names) with a link to the content object
          * @since 1.5.1
          * @param bool $disable_wrapped_link whether to wrap the content with a link to the content object.
          * @param array $gravityview_view->field_data
          * @see GravityView_API:field_value() for info about $gravityview_view->field_data
          */
         $disable_wrapped_link = apply_filters('gravityview/fields/fileupload/disable_link', $disable_wrapped_link, $gravityview_view->getCurrentField());
         // If the HTML output hasn't been overridden by the switch statement above, use the default format
         if (!empty($content) && empty($disable_wrapped_link)) {
             /**
              * Modify the link text (defaults to the file name)
              *
              * @since 1.7
              *
              * @param string $content The existing anchor content. Could be `<img>` tag, audio/video embed or the file name
              * @param array $field GravityView array of the current field being processed
              */
             $content = apply_filters('gravityview/fields/fileupload/link_content', $content, $gravityview_view->getCurrentField());
             $content = gravityview_get_link($link, $content, $link_atts);
         }
         $output_arr[] = array('file_path' => $file_path, 'content' => $content);
     }
     // End foreach loop
     /**
      * @filter `gravityview/fields/fileupload/files_array` Modify the files array
      * @since 1.7
      * @param array $output_arr Associative array of files \n
      *  @type string $file_path The path to the file as stored in Gravity Forms \n
      *  @type string $content The generated output for the file \n
      * @param array $field GravityView array of the current field being processed
      */
     $output_arr = apply_filters('gravityview/fields/fileupload/files_array', $output_arr, $gravityview_view->getCurrentField());
     return $output_arr;
 }
Пример #4
0
<?php

/**
 * Display the post_title field type
 *
 * @package GravityView
 * @subpackage GravityView/templates/fields
 */
$gravityview_view = GravityView_View::getInstance();
extract($gravityview_view->getCurrentField());
if (!empty($field_settings['dynamic_data']) && !empty($entry['post_id'])) {
    $output = get_the_title($entry['post_id']);
    if (empty($output)) {
        do_action('gravityview_log_debug', 'Dynamic data for post #' . $entry['post_id'] . ' doesnt exist.');
    }
} else {
    $output = $display_value;
}
// Link to the post URL?
if (!empty($field_settings['link_to_post']) && !empty($entry['post_id'])) {
    echo gravityview_get_link(get_permalink($entry['post_id']), esc_attr($output));
} else {
    echo $output;
}
Пример #5
0
 /**
  * Output the Clear Search Results button
  * @since 1.5.4
  */
 public static function the_clear_search_button()
 {
     $gravityview_view = GravityView_View::getInstance();
     if ($gravityview_view->search_clear) {
         $url = strtok(add_query_arg(array()), '?');
         echo gravityview_get_link($url, esc_html__('Clear', 'gravityview'), 'class=button gv-search-clear');
     }
 }
Пример #6
0
 /**
  * Get HTML links relating to a connected form, like Edit, Entries, Settings, Preview
  * @param  array|int $form Gravity Forms forms array, or the form ID
  * @param  boolean $include_form_link Whether to include the bold name of the form in the output
  * @return string          HTML links
  */
 public static function get_connected_form_links($form, $include_form_link = true)
 {
     // Either the form is empty or the form ID is 0, not yet set.
     if (empty($form)) {
         return '';
     }
     // The $form is passed as the form ID
     if (!is_array($form)) {
         $form = gravityview_get_form($form);
     }
     $form_id = $form['id'];
     $links = array();
     if (GVCommon::has_cap('gravityforms_edit_forms')) {
         $form_url = admin_url(sprintf('admin.php?page=gf_edit_forms&amp;id=%d', $form_id));
         $form_link = '<strong class="gv-form-title">' . gravityview_get_link($form_url, $form['title'], 'class=row-title') . '</strong>';
         $links[] = '<span>' . gravityview_get_link($form_url, __('Edit Form', 'gravityview')) . '</span>';
     } else {
         $form_link = '<strong class="gv-form-title">' . esc_html($form['title']) . '</strong>';
     }
     if (GVCommon::has_cap('gravityforms_view_entries')) {
         $entries_url = admin_url(sprintf('admin.php?page=gf_entries&amp;id=%d', $form_id));
         $links[] = '<span>' . gravityview_get_link($entries_url, __('Entries', 'gravityview')) . '</span>';
     }
     if (GVCommon::has_cap(array('gravityforms_edit_settings', 'gravityview_view_settings'))) {
         $settings_url = admin_url(sprintf('admin.php?page=gf_edit_forms&amp;view=settings&amp;id=%d', $form_id));
         $links[] = '<span>' . gravityview_get_link($settings_url, __('Settings', 'gravityview'), 'title=' . __('Edit settings for this form', 'gravityview')) . '</span>';
     }
     if (GVCommon::has_cap(array("gravityforms_edit_forms", "gravityforms_create_form", "gravityforms_preview_forms"))) {
         $preview_url = site_url(sprintf('?gf_page=preview&amp;id=%d', $form_id));
         $links[] = '<span>' . gravityview_get_link($preview_url, __('Preview Form', 'gravityview'), 'title=' . __('Preview this form', 'gravityview')) . '</span>';
     }
     $output = '';
     if (!empty($include_form_link)) {
         $output .= $form_link;
     }
     /**
      * @filter `gravityview_connected_form_links` Modify the links shown in the Connected Form links
      * @since 1.6
      * @param array $links Links to show
      * @param array $form Gravity Forms form array
      */
     $links = apply_filters('gravityview_connected_form_links', $links, $form);
     $output .= '<div class="row-actions">' . implode(' | ', $links) . '</div>';
     return $output;
 }
Пример #7
0
 /**
  * Generate an anchor tag that links to an entry.
  *
  * @since 1.6
  *
  * @param string $anchor_text The text or HTML inside the link
  * @param array $entry Gravity Forms entry array
  * @param array $field_settings Array of field settings. Optional, but passed to the `gravityview_field_entry_link` filter
  */
 public static function entry_link_html($entry = array(), $anchor_text = '', $passed_tag_atts = array(), $field_settings = array())
 {
     if (empty($entry) || !is_array($entry) || !isset($entry['id'])) {
         do_action('gravityview_log_debug', 'GravityView_API[entry_link_tag] Entry not defined; returning null', $entry);
         return NULL;
     }
     $href = self::entry_link($entry);
     $link = gravityview_get_link($href, $anchor_text, $passed_tag_atts);
     /**
      * @filter `gravityview_field_entry_link` Modify the link HTML
      * @param string $link HTML output of the link
      * @param string $href URL of the link
      * @param array  $entry The GF entry array
      * @param  array $field_settings Settings for the particular GV field
      */
     $output = apply_filters('gravityview_field_entry_link', $link, $href, $entry, $field_settings);
     return $output;
 }
Пример #8
0
<?php

/**
 * Generate output for the Source URL field
 * @package GravityView
 * @subpackage GravityView/templates/fields
 * @since 1.1.6
 */
$gravityview_view = GravityView_View::getInstance();
extract($gravityview_view->getCurrentField());
// If linking to the source URL
if (!empty($field_settings['link_to_source'])) {
    // If customizing the anchor text
    if (!empty($field_settings['source_link_text'])) {
        $link_text = GravityView_API::replace_variables($field_settings['source_link_text'], $form, $entry);
    } else {
        // Otherwise, it's just the URL
        $link_text = $value;
    }
    $output = gravityview_get_link($value, esc_html($link_text));
} else {
    // Otherwise, it's just the URL
    $output = $value;
}
echo $output;
 /**
  * Add the link to action list for post_row_actions
  *
  * @since 1.6
  * @param array $actions Row action links. Defaults are 'Edit', 'Quick Edit', 'Restore, 'Trash', 'Delete Permanently', 'Preview', and 'View'
  * @param WP_Post $post
  */
 public function make_duplicate_link_row($actions, $post)
 {
     // Only process on GravityView Views
     if (get_post_type($post) === 'gravityview' && $this->current_user_can_copy($post)) {
         $clone_link = $this->get_clone_view_link($post->ID, 'display', false);
         $clone_text = __('Clone', 'gravityview');
         $clone_title = __('Clone this View', 'gravityview');
         $actions['clone'] = gravityview_get_link($clone_link, $clone_text, 'title=' . $clone_title);
         $clone_draft_link = $this->get_clone_view_link($post->ID);
         $clone_draft_text = $this->is_all_views_page() ? __('New Draft', 'gravityview') : __('Clone View', 'gravityview');
         $clone_draft_title = __('Copy as a new draft View', 'gravityview');
         $actions['edit_as_new_draft'] = gravityview_get_link($clone_draft_link, esc_html($clone_draft_text), 'title=' . $clone_draft_title);
     }
     return $actions;
 }
 /**
  * Generate a link to an entry. The link can be an edit, delete, or standard link.
  *
  * @since 1.15
  *
  * @param array $atts {
  *    @type string $action What type of link to generate. Options: `read`, `edit`, and `delete`. Default: `read`
  *    @type string $view_id Define the ID for the View. If not set, use current View ID, if exists.
  *    @type string $entry_id ID of the entry to edit. If undefined, uses the current entry ID, if exists.
  *    @type string $post_id ID of the base post or page to use for an embedded View
  *    @type string $link_atts Pass anchor tag attributes (`target=_blank` to open Edit Entry link in a new window, for example)
  *    @type string $return What should the shortcode return: link HTML (`html`) or the URL (`url`). Default: `html`
  *    @type string $field_values Only used for `action="edit"`. Parameters to pass in to the prefill data in Edit Entry form. 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|null $content Used as link anchor text, if specified.
  * @param string $context Current shortcode being called. Not used.
  *
  * @return null|string If admin or an error occurred, returns null. Otherwise, returns entry link output. If `$atts['return']` is 'url', the entry link URL. Otherwise, entry link `<a>` HTML tag.
  */
 private function shortcode($atts, $content = null, $context = 'gv_entry_link')
 {
     // Don't process when saving post. Keep processing if it's admin-ajax.php
     if (!class_exists('GravityView_Plugin') || GravityView_Plugin::is_admin()) {
         return null;
     }
     // Make sure GV is loaded
     if (!class_exists('GravityView_frontend') || !class_exists('GravityView_View')) {
         do_action('gravityview_log_error', __METHOD__ . ' GravityView_frontend or GravityView_View do not exist.');
         return null;
     }
     $this->settings = shortcode_atts(self::$defaults, $atts, $context);
     $this->view_id = empty($this->settings['view_id']) ? GravityView_View::getInstance()->getViewId() : absint($this->settings['view_id']);
     if (empty($this->view_id)) {
         do_action('gravityview_log_error', __METHOD__ . ' A View ID was not defined and we are not inside a View');
         return null;
     }
     $this->entry = $this->get_entry($this->settings['entry_id']);
     do_action('gravityview_log_debug', __METHOD__ . ' ' . $context . ' $atts: ', $atts);
     if (!$this->has_cap()) {
         do_action('gravityview_log_error', __METHOD__ . ' User does not have the capability to ' . esc_attr($this->settings['action']) . ' this entry: ' . $this->entry['id']);
         return null;
     }
     $url = $this->get_url();
     if (!$url) {
         do_action('gravityview_log_error', __METHOD__ . ' Link returned false; View or Post may not exist.');
         return false;
     }
     // Get just the URL, not the tag
     if ('url' === $this->settings['return']) {
         return $url;
     }
     $link_atts = $this->get_link_atts();
     $link_text = $this->get_anchor_text($content);
     return gravityview_get_link($url, $link_text, $link_atts);
 }
Пример #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;
 }
Пример #12
0
<?php

$gravityview_view = GravityView_View::getInstance();
$view_id = $gravityview_view->getViewId();
extract($gravityview_view->getCurrentField());
// Only show the link to logged-in users with the rigth caps.
if (!GravityView_Delete_Entry::check_user_cap_delete_entry($entry, $field_settings)) {
    return;
}
$link_text = empty($field_settings['delete_link']) ? __('Delete Entry', 'gravityview') : $field_settings['delete_link'];
$link_text = apply_filters('gravityview_entry_link', GravityView_API::replace_variables($link_text, $form, $entry));
$href = GravityView_Delete_Entry::get_delete_link($entry, $view_id);
$attributes = array('onclick' => GravityView_Delete_Entry::get_confirm_dialog());
echo gravityview_get_link($href, $link_text, $attributes);
Пример #13
0
<?php

/**
 * Display the post_id field type
 *
 * @package GravityView
 * @subpackage GravityView/templates/fields
 */
$gravityview_view = GravityView_View::getInstance();
extract($gravityview_view->getCurrentField());
// Link to the post URL?
if ($gravityview_view->getCurrentFieldSetting('link_to_post') && !empty($entry['post_id'])) {
    echo gravityview_get_link(get_permalink($entry['post_id']), esc_attr($display_value));
} else {
    echo $display_value;
}
Пример #14
0
<?php

$gravityview_view = GravityView_View::getInstance();
$view_id = $gravityview_view->getViewId();
extract($gravityview_view->getCurrentField());
// Only show the link to logged-in users.
if (!GravityView_Edit_Entry::check_user_cap_edit_entry($entry)) {
    return;
}
$link_text = empty($field_settings['edit_link']) ? __('Edit Entry', 'gravityview') : $field_settings['edit_link'];
$link_atts = empty($field_settings['new_window']) ? '' : 'target="_blank"';
$output = apply_filters('gravityview_entry_link', GravityView_API::replace_variables($link_text, $form, $entry));
$href = GravityView_Edit_Entry::get_edit_link($entry, $view_id);
echo gravityview_get_link($href, $output, $link_atts);
    /**
     * @since 1.6
     * @see WP_Widget::form()
     */
    public function form($instance)
    {
        // Set up some default widget settings.
        $defaults = array('title' => __('Recent Entries', 'gravityview'), 'view_id' => NULL, 'post_id' => NULL, 'limit' => 10, 'link_format' => __('Entry #{entry_id}', 'gravityview'), 'after_link' => '');
        $instance = wp_parse_args((array) $instance, $defaults);
        ?>

		<!-- Title -->
		<p>
			<label for="<?php 
        echo esc_attr($this->get_field_id('title'));
        ?>
"><?php 
        _e('Title:', 'gravityview');
        ?>
</label>
			<input class="widefat" id="<?php 
        echo esc_attr($this->get_field_id('title'));
        ?>
" name="<?php 
        echo esc_attr($this->get_field_name('title'));
        ?>
" type="text" value="<?php 
        echo esc_attr($instance['title']);
        ?>
" />
		</p>

		<!-- Download -->
		<?php 
        $args = array('post_type' => 'gravityview', 'posts_per_page' => -1, 'post_status' => 'publish');
        $views = get_posts($args);
        // 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;
        }
        ?>

		<?php 
        /**
         * Display errors generated for invalid embed IDs
         * @see GravityView_View_Data::is_valid_embed_id
         */
        if (isset($instance['updated']) && empty($instance['view_id'])) {
            ?>
			<div class="error inline hide-on-view-change">
				<p><?php 
            esc_html_e('Please select a View to search.', 'gravityview');
            ?>
</p>
			</div>
			<?php 
            unset($error);
        }
        ?>

		<p>
			<label for="<?php 
        echo esc_attr($this->get_field_id('view_id'));
        ?>
"><?php 
        esc_html_e('Select a View', 'gravityview');
        ?>
</label>
			<select class="widefat gv-recent-entries-select-view" name="<?php 
        echo esc_attr($this->get_field_name('view_id'));
        ?>
" id="<?php 
        echo esc_attr($this->get_field_id('view_id'));
        ?>
">
				<option value=""><?php 
        esc_html_e('&mdash; Select a View as Entries Source &mdash;', 'gravityview');
        ?>
</option>
				<?php 
        foreach ($views as $view) {
            $title = empty($view->post_title) ? __('(no title)', 'gravityview') : $view->post_title;
            echo '<option value="' . $view->ID . '"' . selected(absint($instance['view_id']), $view->ID) . '>' . esc_html(sprintf('%s #%d', $title, $view->ID)) . '</option>';
        }
        ?>
			</select>
		</p>

		<?php 
        /**
         * Display errors generated for invalid embed IDs
         * @see GravityView_View_Data::is_valid_embed_id
         */
        if (!empty($instance['error_post_id'])) {
            ?>
			<div class="error inline">
				<p><?php 
            echo $instance['error_post_id'];
            ?>
</p>
			</div>
			<?php 
            unset($error);
        }
        ?>

		<p>
			<label for="<?php 
        echo $this->get_field_id('post_id');
        ?>
"><?php 
        esc_html_e('If Embedded, Page ID:', 'gravityview');
        ?>
</label>
			<input class="code" size="3" id="<?php 
        echo $this->get_field_id('post_id');
        ?>
" name="<?php 
        echo $this->get_field_name('post_id');
        ?>
" type="text" value="<?php 
        echo esc_attr($instance['post_id']);
        ?>
" />
			<span class="howto"><?php 
        esc_html_e('To have a search performed on an embedded View, enter the ID of the post or page where the View is embedded.', 'gravityview');
        echo ' ' . gravityview_get_link('http://docs.gravityview.co/article/222-the-search-widget', __('Learn more&hellip;', 'gravityview'), 'target=_blank');
        ?>
</span>
		</p>

		<p>
			<label for="<?php 
        echo $this->get_field_id('limit');
        ?>
">
				<span><?php 
        _e('Number of entries to show:', 'gravityview');
        ?>
</span>
			</label>
			<input class="code" id="<?php 
        echo $this->get_field_id('limit');
        ?>
" name="<?php 
        echo $this->get_field_name('limit');
        ?>
" type="number" value="<?php 
        echo intval($instance['limit']);
        ?>
" size="3" />
		</p>

		<p>
			<label for="<?php 
        echo $this->get_field_id('link_format');
        ?>
">
				<span><?php 
        _e('Entry link text (required)', 'gravityview');
        ?>
</span>
			</label>
			<input id="<?php 
        echo $this->get_field_id('link_format');
        ?>
" name="<?php 
        echo $this->get_field_name('link_format');
        ?>
" type="text" value="<?php 
        echo esc_attr($instance['link_format']);
        ?>
" class="widefat merge-tag-support mt-position-right mt-hide_all_fields" />
		</p>

		<p>
			<label for="<?php 
        echo $this->get_field_id('after_link');
        ?>
">
				<span><?php 
        _e('Text or HTML to display after the link (optional)', 'gravityview');
        ?>
</span>
			</label>
			<textarea id="<?php 
        echo $this->get_field_id('after_link');
        ?>
" name="<?php 
        echo $this->get_field_name('after_link');
        ?>
" rows="5" class="widefat code merge-tag-support mt-position-right mt-hide_all_fields"><?php 
        echo esc_textarea($instance['after_link']);
        ?>
</textarea>
		</p>

		<?php 
        /**
         * @action `gravityview_recent_entries_widget_form` Displayed at the bottom of the Recent Entries widget admin form
         * @param GravityView_Recent_Entries_Widget $this WP_Widget object
         * @param array $instance Current widget instance
         */
        do_action('gravityview_recent_entries_widget_form', $this, $instance);
        ?>

		<script>
			// When the widget is saved or added, refresh the Merge Tags (here for backward compatibility)
			// WordPress 3.9 added widget-added and widget-updated actions
			jQuery('#<?php 
        echo $this->get_field_id('view_id');
        ?>
').trigger( 'change' );
		</script>
	<?php 
    }
Пример #16
0
 /**
  * Add a Delete button to the #publishing-action section of the Delete Entry form
  *
  * @since 1.5.1
  * @param array $form    Gravity Forms form array
  * @param array $entry   Gravity Forms entry array
  * @param int $view_id GravityView View ID
  */
 function add_delete_button($form = array(), $entry = array(), $view_id = NULL)
 {
     // Only show the link to those who are allowed to see it.
     if (!self::check_user_cap_delete_entry($entry)) {
         return;
     }
     /**
      * @filter `gravityview/delete-entry/show-delete-button` Should the Delete button be shown in the Edit Entry screen?
      * @param boolean $show_entry Default: true
      */
     $show_delete_button = apply_filters('gravityview/delete-entry/show-delete-button', true);
     // If the button is hidden by the filter, don't show.
     if (!$show_delete_button) {
         return;
     }
     $attributes = array('class' => 'btn btn-sm button button-small alignright pull-right btn-danger gv-button-delete', 'tabindex' => '5', 'onclick' => self::get_confirm_dialog());
     echo gravityview_get_link(self::get_delete_link($entry, $view_id), esc_attr__('Delete', 'gravityview'), $attributes);
 }
 /**
  * Check if the user can edit the entry
  *
  * - Is the nonce valid?
  * - Does the user have the right caps for the entry
  * - Is the entry in the trash?
  *
  * @todo Move to GVCommon
  *
  * @param  boolean $echo Show error messages in the form?
  * @return boolean        True: can edit form. False: nope.
  */
 function user_can_edit_entry($echo = false)
 {
     $error = NULL;
     /**
      *  1. Permalinks are turned off
      *  2. There are two entries embedded using oEmbed
      *  3. One of the entries has just been saved
      */
     if (!empty($_POST['lid']) && !empty($_GET['entry']) && $_POST['lid'] !== $_GET['entry']) {
         $error = true;
     }
     if (!empty($_GET['entry']) && (string) $this->entry['id'] !== $_GET['entry']) {
         $error = true;
     } elseif (!$this->verify_nonce()) {
         /**
          * If the Entry is embedded, there may be two entries on the same page.
          * If that's the case, and one is being edited, the other should fail gracefully and not display an error.
          */
         if (GravityView_oEmbed::getInstance()->get_entry_id()) {
             $error = true;
         } else {
             $error = __('The link to edit this entry is not valid; it may have expired.', 'gravityview');
         }
     }
     if (!GravityView_Edit_Entry::check_user_cap_edit_entry($this->entry)) {
         $error = __('You do not have permission to edit this entry.', 'gravityview');
     }
     if ($this->entry['status'] === 'trash') {
         $error = __('You cannot edit the entry; it is in the trash.', 'gravityview');
     }
     // No errors; everything's fine here!
     if (empty($error)) {
         return true;
     }
     if ($echo && $error !== true) {
         $error = esc_html($error);
         /**
          * @since 1.9
          */
         if (!empty($this->entry)) {
             $error .= ' ' . gravityview_get_link('#', _x('Go back.', 'Link shown when invalid Edit Entry link is clicked', 'gravityview'), array('onclick' => "window.history.go(-1); return false;"));
         }
         echo GVCommon::generate_notice(wpautop($error), 'gv-error error');
     }
     do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error);
     return false;
 }
 /**
  * Get the output for a specific entry
  *
  * @param array $entry GF Entry array
  *
  * @since 1.7.2
  *
  * @uses gravityview_get_link
  * @uses GravityView_API::entry_link
  * @uses GravityView_API::replace_variables
  *
  * @return string HTML output for the entry
  */
 private function get_item_output($entry)
 {
     $link = GravityView_API::entry_link($entry, $this->post_id);
     $item_output = gravityview_get_link($link, $this->link_format);
     if (!empty($this->after_link)) {
         /**
          * Modify the item output HTML
          *
          * @since 1.7.2
          *
          * @param string $item_output The HTML output for the after_link content
          * @param array $entry Gravity Forms entry array
          * @param GravityView_Entry_List $this The current class instance
          */
         $after_link = apply_filters('gravityview/entry-list/after-link', '<div>' . $this->after_link . '</div>', $entry, $this);
         $item_output .= $after_link;
     }
     $item_output = GravityView_API::replace_variables($item_output, $this->form, $entry);
     $item_output = '<' . $this->item_tag . '>' . $item_output . '</' . $this->item_tag . '>';
     /**
      * Modify the item output HTML
      *
      * @since 1.7.2
      *
      * @param string $item_output The HTML output for the item
      * @param array $entry Gravity Forms entry array
      * @param GravityView_Entry_List $this The current class instance
      */
     $item_output = apply_filters('gravityview/entry-list/item', $item_output, $entry, $this);
     return $item_output;
 }
Пример #19
0
<?php

/**
 * Generate output for the Source URL field
 * @package GravityView
 * @subpackage GravityView/templates/fields
 * @since 1.1.6
 */
$gravityview_view = GravityView_View::getInstance();
extract($gravityview_view->getCurrentField());
// If linking to the source URL
if (!empty($field_settings['link_to_source'])) {
    // If customizing the anchor text
    if (!empty($field_settings['source_link_text'])) {
        $link_text = GravityView_API::replace_variables($field_settings['source_link_text'], $form, $entry);
    } else {
        // Otherwise, it's just the URL
        $link_text = esc_html($value);
    }
    $output = gravityview_get_link($value, $link_text);
} else {
    // Otherwise, it's just the URL
    $output = $value;
}
echo $output;
Пример #20
0
    $params = array();
    // The default link is a mailto link
    $link = 'mailto:' . $value;
    // Is the subject set?
    if (!empty($field_settings['emailsubject'])) {
        $subject = GravityView_API::replace_variables($field_settings['emailsubject'], $form, $entry);
        $params[] = 'subject=' . str_replace('+', '%20', urlencode($subject));
    }
    // Is the body set?
    if (!empty($field_settings['emailbody'])) {
        $body = GravityView_API::replace_variables($field_settings['emailbody'], $form, $entry);
        $params[] = 'body=' . str_replace('+', '%20', urlencode($body));
    }
    // If the subject and body have been set, use them
    if (!empty($params)) {
        $link .= '?' . implode('&', $params);
    }
    // Generate the link HTML
    $output = gravityview_get_link($link, $value);
}
/**
 * Prevent encrypting emails no matter what - this is handy for DataTables exports, for example
 * @since 1.1.6
 * @var boolean
 */
$prevent_encrypt = apply_filters('gravityview_email_prevent_encrypt', false);
// If encrypting the link
if (!empty($field_settings['emailencrypt']) && !$prevent_encrypt) {
    $output = GVCommon::js_encrypt($output);
}
echo $output;
    /**
     * @inheritDoc
     */
    public function form($instance)
    {
        // @todo Make compatible with Customizer
        if ($this->is_preview()) {
            $warning = sprintf(esc_html__('This widget is not configurable from this screen. Please configure it on the %sWidgets page%s.', 'gravityview'), '<a href="' . admin_url('widgets.php') . '">', '</a>');
            echo wpautop(GravityView_Admin::get_floaty() . $warning);
            return;
        }
        $defaults = array('title' => '', 'view_id' => 0, 'post_id' => '', 'search_fields' => '');
        $instance = wp_parse_args((array) $instance, $defaults);
        $title = $instance['title'];
        $view_id = $instance['view_id'];
        $post_id = $instance['post_id'];
        $search_fields = $instance['search_fields'];
        $views = GVCommon::get_all_views();
        // If there are no views set up yet, we get outta here.
        if (empty($views)) {
            ?>
			<div id="select_gravityview_view">
				<div class="wrap"><?php 
            echo GravityView_Post_Types::no_views_text();
            ?>
</div>
			</div>
			<?php 
            return;
        }
        ?>

		<p><label for="<?php 
        echo $this->get_field_id('title');
        ?>
"><?php 
        _e('Title:', 'gravityview');
        ?>
 <input class="widefat" id="<?php 
        echo $this->get_field_id('title');
        ?>
" name="<?php 
        echo $this->get_field_name('title');
        ?>
" type="text" value="<?php 
        echo esc_attr($title);
        ?>
" /></label></p>

		<?php 
        /**
         * Display errors generated for invalid embed IDs
         * @see GravityView_View_Data::is_valid_embed_id
         */
        if (isset($instance['updated']) && empty($instance['view_id'])) {
            ?>
			<div class="error inline hide-on-view-change">
				<p><?php 
            esc_html_e('Please select a View to search.', 'gravityview');
            ?>
</p>
			</div>
			<?php 
            unset($error);
        }
        ?>

		<p>
			<label for="gravityview_view_id"><?php 
        _e('View:', 'gravityview');
        ?>
</label>
			<select id="gravityview_view_id" name="<?php 
        echo $this->get_field_name('view_id');
        ?>
" class="widefat">
				<option value=""><?php 
        esc_html_e('&mdash; Select a View &mdash;', 'gravityview');
        ?>
</option>
				<?php 
        foreach ($views as $view_option) {
            $title = empty($view_option->post_title) ? __('(no title)', 'gravityview') : $view_option->post_title;
            echo '<option value="' . $view_option->ID . '" ' . selected(esc_attr($view_id), $view_option->ID, false) . '>' . esc_html(sprintf('%s #%d', $title, $view_option->ID)) . '</option>';
        }
        ?>
			</select>

		</p>

		<?php 
        /**
         * Display errors generated for invalid embed IDs
         * @see GravityView_View_Data::is_valid_embed_id
         */
        if (!empty($instance['error_post_id'])) {
            ?>
			<div class="error inline">
				<p><?php 
            echo $instance['error_post_id'];
            ?>
</p>
			</div>
			<?php 
            unset($error);
        }
        ?>

		<p>
			<label for="<?php 
        echo $this->get_field_id('post_id');
        ?>
"><?php 
        esc_html_e('If Embedded, Page ID:', 'gravityview');
        ?>
</label>
			<input class="code" size="3" id="<?php 
        echo $this->get_field_id('post_id');
        ?>
" name="<?php 
        echo $this->get_field_name('post_id');
        ?>
" type="text" value="<?php 
        echo esc_attr($post_id);
        ?>
" />
			<span class="howto"><?php 
        esc_html_e('To have a search performed on an embedded View, enter the ID of the post or page where the View is embedded.', 'gravityview');
        echo ' ' . gravityview_get_link('http://docs.gravityview.co/article/222-the-search-widget', __('Learn more&hellip;', 'gravityview'), 'target=_blank');
        ?>
</span>
		</p>

		<hr />

		<?php 
        // @todo: move style to CSS
        ?>
		<div style="margin-bottom: 1em;">
			<label class="screen-reader-text" for="<?php 
        echo $this->get_field_id('search_fields');
        ?>
"><?php 
        _e('Searchable fields:', 'gravityview');
        ?>
</label>
			<div class="gv-widget-search-fields" title="<?php 
        esc_html_e('Search Fields', 'gravityview');
        ?>
">
				<input id="<?php 
        echo $this->get_field_id('search_fields');
        ?>
" name="<?php 
        echo $this->get_field_name('search_fields');
        ?>
" type="hidden" value="<?php 
        echo esc_attr($search_fields);
        ?>
" class="gv-search-fields-value">
			</div>

		</div>

		<script>
			// When the widget is saved or added, refresh the Merge Tags (here for backward compatibility)
			// WordPress 3.9 added widget-added and widget-updated actions
			jQuery('#<?php 
        echo $this->get_field_id('view_id');
        ?>
').trigger( 'change' );
		</script>
	<?php 
    }
Пример #22
0
<?php

/**
 * Display the phone field type
 *
 * @since 1.17
 *
 * @package GravityView
 * @subpackage GravityView/templates/fields
 */
$gravityview_view = GravityView_View::getInstance();
/**
 * @var double|int|string $value
 * @var double|int|string $display_value
 */
extract($gravityview_view->getCurrentField());
$value = esc_attr($value);
if (!empty($field_settings['link_phone']) && !empty($value)) {
    echo gravityview_get_link('tel:' . $value, $value);
} else {
    echo $value;
}