Esempio n. 1
0
 /**
  * Generate the Regular expression that matches embedded entries.
  *
  * Generates different regex if using permalinks and if not using permalinks
  *
  * @since 1.6
  *
  * @return string Regex code
  */
 private function get_handler_regex()
 {
     $entry_var_name = GravityView_Post_Types::get_entry_var_name();
     $rewrite_slug = apply_filters('gravityview_slug', 'view');
     // Only support embeds for current site
     $prefix = trailingslashit(home_url());
     // Using permalinks
     $using_permalinks = $prefix . "(?P<is_cpt>{$rewrite_slug})?/?(?P<slug>.+?)/{$entry_var_name}/(?P<entry_slug>.+?)/?\$";
     // Not using permalinks
     $not_using_permalinks = $prefix . "(?:index.php)?\\?(?P<is_cpt2>[^=]+)=(?P<slug2>[^&]+)&entry=(?P<entry_slug2>[^&]+)\$";
     // Catch either
     $match_regex = "(?:{$using_permalinks}|{$not_using_permalinks})";
     return '#' . $match_regex . '#i';
 }
Esempio n. 2
0
 /**
  * Generate the Regular expression that matches embedded entries.
  *
  * Generates different regex if using permalinks and if not using permalinks
  *
  * @since 1.6
  *
  * @return string Regex code
  */
 private function get_handler_regex()
 {
     $entry_var_name = GravityView_Post_Types::get_entry_var_name();
     /**
      * @filter `gravityview_slug` Modify the url part for a View. [Read the doc](http://docs.gravityview.co/article/62-changing-the-view-slug)
      * @param string $rewrite_slug The slug shown in the URL
      */
     $rewrite_slug = apply_filters('gravityview_slug', 'view');
     // Only support embeds for current site
     $prefix = trailingslashit(home_url());
     // Using permalinks
     $using_permalinks = $prefix . "(?P<is_cpt>{$rewrite_slug})?/?(?P<slug>.+?)/{$entry_var_name}/(?P<entry_slug>.+?)/?\$";
     // Not using permalinks
     $not_using_permalinks = $prefix . "(?:index.php)?\\?(?P<is_cpt2>[^=]+)=(?P<slug2>[^&]+)&entry=(?P<entry_slug2>[^&]+)\$";
     // Catch either
     $match_regex = "(?:{$using_permalinks}|{$not_using_permalinks})";
     return '#' . $match_regex . '#i';
 }
 /**
  * Add the GravityView menu to the Visual Composer menu
  * @uses vc_map
  * @return void
  */
 function vc_map()
 {
     global $vc_manager;
     $views = get_posts(array('post_type' => 'gravityview', 'numberposts' => -1, 'status' => 'publish'));
     if (empty($views) || is_wp_error($views)) {
         // By default, there are no Views found.
         $gravityview_array[__('No GravityView Views found.', 'gravityview-visual-composer')] = '';
         $params = array(array('type' => 'dropdown', 'heading' => __('View', 'gravityview-visual-composer'), 'param_name' => 'id', 'value' => $gravityview_array, 'description' => GravityView_Post_Types::no_views_text(), 'admin_label' => true));
     } else {
         // Overwrite the default
         $views_array = array(__('Select a View to Insert', 'gravityview-visual-composer') => '');
         // Map the title of the view to the ID
         foreach ($views as $view) {
             $title = !empty($view->post_title) ? esc_attr($view->post_title) : __('(no title)', 'gravityview-visual-composer');
             $views_array[$title] = $view->ID;
         }
         $params = $this->get_params($views_array);
     }
     vc_map(array('name' => __('GravityView', 'gravityview-visual-composer'), 'base' => 'gravityview', 'icon' => plugins_url('assets/img/icon.png', __FILE__), 'category' => __('Content', 'gravityview-visual-composer'), 'description' => __('Embed a View', 'gravityview-visual-composer'), 'params' => $params));
 }
 /**
  * Include Gravity Forms, GravityView, and GravityView Extensions
  * @since 1.3
  */
 function bootstrap_gv()
 {
     $plugins = array('gf' => '/gravityforms/gravityforms.php', 'gv' => '/gravityview/gravityview.php', 'gv_extension_advanced_filtering_load' => '/gravityview-advanced-filter/advanced-filter.php', 'gv_extension_az_entry_filtering_load' => '/gravityview-az-filters/gravityview-az-filters.php', 'gv_extension_featured_entries_load' => '/gravityview-featured-entries/featured-entries.php', 'gv_ratings_reviews_loader' => '/gravityview-ratings-reviews/ratings-reviews.php', 'gv_extension_sharing_load' => '/gravityview-sharing-seo/sharing-seo.php');
     // Load Field files automatically
     foreach ($plugins as $function_name => $plugin_file) {
         if (file_exists(WP_PLUGIN_DIR . $plugin_file)) {
             require_once WP_PLUGIN_DIR . $plugin_file;
             switch ($function_name) {
                 case 'gf':
                     break;
                 case 'gv':
                     GravityView_Plugin::getInstance();
                     GravityView_Post_Types::init_post_types();
                     GravityView_Post_Types::init_rewrite();
                     break;
                 default:
                     if (function_exists($function_name)) {
                         $function_name();
                     }
             }
         }
     }
 }
    /**
     * @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 
    }
Esempio n. 6
0
 /**
  * return href for single entry
  * @param  array|int $entry   Entry array or entry ID
  * @param  int|null $post_id If wanting to define the parent post, pass a post ID
  * @param boolean $add_directory_args True: Add args to help return to directory; False: only include args required to get to entry {@since 1.7.3}
  * @return string          Link to the entry with the directory parent slug
  */
 public static function entry_link($entry, $post_id = NULL, $add_directory_args = true)
 {
     if (!empty($entry) && !is_array($entry)) {
         $entry = GVCommon::get_entry($entry);
     } else {
         if (empty($entry)) {
             $entry = GravityView_frontend::getInstance()->getEntry();
         }
     }
     // Second parameter used to be passed as $field; this makes sure it's not an array
     if (!is_numeric($post_id)) {
         $post_id = NULL;
     }
     // Get the permalink to the View
     $directory_link = self::directory_link($post_id, false);
     // No post ID? Get outta here.
     if (empty($directory_link)) {
         return '';
     }
     $query_arg_name = GravityView_Post_Types::get_entry_var_name();
     $entry_slug = self::get_entry_slug($entry['id'], $entry);
     if (get_option('permalink_structure') && !is_preview()) {
         $args = array();
         $directory_link = trailingslashit($directory_link) . $query_arg_name . '/' . $entry_slug . '/';
     } else {
         $args = array($query_arg_name => $entry_slug);
     }
     /**
      * @since 1.7.3
      */
     if ($add_directory_args) {
         if (!empty($_GET['pagenum'])) {
             $args['pagenum'] = intval($_GET['pagenum']);
         }
         /**
          * @since 1.7
          */
         if ($sort = rgget('sort')) {
             $args['sort'] = $sort;
             $args['dir'] = rgget('dir');
         }
     }
     /**
      * Check if we have multiple views embedded in the same page and in that case make sure the single entry link
      * has the view id so that Advanced Filters can be applied correctly when rendering the single view
      * @see GravityView_frontend::get_context_view_id()
      */
     if (class_exists('GravityView_View_Data') && GravityView_View_Data::getInstance()->has_multiple_views()) {
         $args['gvid'] = gravityview_get_view_id();
     }
     return add_query_arg($args, $directory_link);
 }
    /**
     * @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 
    }
Esempio n. 8
0
 /**
  * Plugin activate function.
  *
  * @access public
  * @static
  * @param mixed $network_wide
  * @return void
  */
 public static function activate($network_wide)
 {
     // register post types
     GravityView_Post_Types::init_post_types();
     // register rewrite rules
     GravityView_Post_Types::init_rewrite();
     flush_rewrite_rules();
     // Update the current GV version
     update_option('gv_version', self::version);
     // Add the transient to redirect to configuration page
     set_transient('_gv_activation_redirect', true, 60);
     // Clear settings transient
     delete_transient('redux_edd_license_license_valid');
 }
Esempio n. 9
0
 /**
  * Plugin activate function.
  *
  * @access public
  * @static
  * @return void
  */
 public static function activate()
 {
     // register post types
     GravityView_Post_Types::init_post_types();
     // register rewrite rules
     GravityView_Post_Types::init_rewrite();
     flush_rewrite_rules();
     // Update the current GV version
     update_option('gv_version', self::version);
     // Add the transient to redirect to configuration page
     set_transient('_gv_activation_redirect', true, 60);
     // Clear settings transient
     delete_transient('gravityview_edd-activate_valid');
     GravityView_Roles_Capabilities::get_instance()->add_caps();
 }
Esempio n. 10
0
 /**
  * Verify if user requested a single entry view
  * @return boolean|string false if not, single entry slug if true
  */
 public static function is_single_entry()
 {
     $var_name = GravityView_Post_Types::get_entry_var_name();
     $single_entry = get_query_var($var_name);
     /**
      * Modify the entry that is being displayed.
      *
      * @internal Should only be used by things like the oEmbed functionality.
      * @since 1.6
      */
     $single_entry = apply_filters('gravityview/is_single_entry', $single_entry);
     if (empty($single_entry)) {
         return false;
     } else {
         return $single_entry;
     }
 }
    /**
     * 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 
    }