예제 #1
0
 /**
  * Get text for no views found.
  * @todo Move somewhere appropriate.
  * @return string HTML message with no container tags.
  */
 static function no_views_text()
 {
     if (!class_exists('GravityView_Admin')) {
         require_once GRAVITYVIEW_DIR . 'includes/class-admin.php';
     }
     // Floaty the astronaut
     $image = GravityView_Admin::get_floaty();
     $not_found = sprintf(esc_attr__("%sYou don't have any active views. Let&rsquo;s go %screate one%s!%s\n\nIf you feel like you're lost in space and need help getting started, check out the %sGetting Started%s page.", 'gravityview'), '<h3>', '<a href="' . admin_url('post-new.php?post_type=gravityview') . '">', '</a>', '</h3>', '<a href="' . admin_url('edit.php?post_type=gravityview&page=gv-getting-started') . '">', '</a>');
     return $image . wpautop($not_found);
 }
    /**
     * @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 
    }
예제 #3
0
    /**
     * Display a nice placeholder in the admin for the entry
     *
     * @param array $matches The regex matches from the provided regex when calling wp_embed_register_handler()
     * @param array $attr Embed attributes.
     * @param string $url The original URL that was matched by the regex.
     * @param array $rawattr The original unmodified attributes.
     * @return string The embed HTML.
     */
    private function render_admin($matches, $attr, $url, $rawattr)
    {
        global $wp_version;
        // Floaty the astronaut
        $image = GravityView_Admin::get_floaty();
        $embed_heading = sprintf(esc_html__('Embed Entry %d', 'gravityview'), $this->entry_id);
        $embed_text = sprintf(esc_html__('This entry will be displayed as it is configured in View %d', 'gravityview'), $this->view_id);
        return '
		<div class="loading-placeholder" style="background-color:#e6f0f5;">
			<h3 style="margin:0; padding:0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, Oxygen-Sans, Ubuntu, Cantarell, \'Helvetica Neue\', sans-serif;">' . $image . $embed_heading . '</h3>
			<p style="margin:0; padding:0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, Oxygen-Sans, Ubuntu, Cantarell, \'Helvetica Neue\', sans-serif;">
				' . $embed_text . '
			</p>
			<br style="clear: both;">
		</div>';
    }
예제 #4
0
 /**
  * Outputs the admin notices generated by the plugin
  *
  * @return void
  */
 public function admin_notice()
 {
     if (empty(self::$admin_notices)) {
         return;
     }
     if (GravityView_Plugin::is_network_activated() && !is_main_site()) {
         return;
     }
     //don't display a message if use has dismissed the message for this version
     self::$dismissed_notices = (array) get_transient('gravityview_dismissed_notices');
     foreach (self::$admin_notices as $notice) {
         if (false === $this->_maybe_show_notice($notice)) {
             continue;
         }
         echo '<div id="message" class="' . esc_attr($notice['class']) . '">';
         // Too cute to leave out.
         echo GravityView_Admin::get_floaty();
         if (!empty($notice['title'])) {
             echo '<h3>' . esc_html($notice['title']) . '</h3>';
         }
         echo wpautop($notice['message']);
         if (!empty($notice['dismiss'])) {
             $dismiss = esc_attr($notice['dismiss']);
             $url = esc_url(add_query_arg(array('gv-dismiss' => wp_create_nonce('dismiss'), 'notice' => $dismiss)));
             echo wpautop('<a href="' . $url . '" data-notice="' . $dismiss . '" class="button-small button button-secondary">' . esc_html__('Dismiss', 'gravityview') . '</a>');
         }
         echo '<div class="clear"></div>';
         echo '</div>';
     }
     //reset the notices handler
     self::$admin_notices = array();
 }