Exemplo n.º 1
0
    /**
     * Render the widget active areas
     * @param  string $zone    Either 'header' or 'footer'
     * @param  string $post_id Current Post ID (view)
     * @return string          html
     */
    function render_widgets_active_areas($template_id = '', $zone, $post_id = '')
    {
        $default_widget_areas = GravityView_Plugin::get_default_widget_areas();
        $widgets = array();
        if (!empty($post_id)) {
            $widgets = get_post_meta($post_id, '_gravityview_directory_widgets', true);
        }
        ob_start();
        ?>

		<div class="gv-grid gv-grid-pad gv-grid-border" id="directory-<?php 
        echo $zone;
        ?>
-widgets">
			<?php 
        $this->render_active_areas($template_id, 'widget', $zone, $default_widget_areas, $widgets);
        ?>
		</div>

		<?php 
        $output = ob_get_clean();
        echo $output;
        return $output;
    }
Exemplo n.º 2
0
    /**
     *
     * @param $view_id
     */
    public function render_widget_hooks($view_id)
    {
        if (empty($view_id) || 'single' == gravityview_get_context()) {
            return;
        }
        $view_data = gravityview_get_current_view_data($view_id);
        // TODO: Move to sep. method, use an action instead
        wp_enqueue_style('gravityview_default_style');
        // get View widget configuration
        $widgets = $view_data['widgets'];
        $rows = GravityView_Plugin::get_default_widget_areas();
        switch (current_filter()) {
            case 'gravityview_before':
                $zone = 'header';
                break;
            case 'gravityview_after':
                $zone = 'footer';
                break;
        }
        // Prevent being called twice
        if (did_action($zone . '_' . $view_id . '_widgets')) {
            return;
        }
        // TODO Convert to partials
        ?>
		<div class="gv-grid">
			<?php 
        foreach ($rows as $row) {
            foreach ($row as $col => $areas) {
                $column = $col == '2-2' ? '1-2 gv-right' : $col . ' gv-left';
                ?>
					<div class="gv-grid-col-<?php 
                echo esc_attr($column);
                ?>
">
						<?php 
                if (!empty($areas)) {
                    foreach ($areas as $area) {
                        if (!empty($widgets[$zone . '_' . $area['areaid']])) {
                            foreach ($widgets[$zone . '_' . $area['areaid']] as $widget) {
                                do_action("gravityview_render_widget_{$widget['id']}", $widget);
                            }
                        }
                    }
                }
                ?>
					</div>
				<?php 
            }
            // $row
            ?>
			<?php 
        }
        // $rows
        ?>
		</div>

		<?php 
        // Prevent being called twice
        do_action($zone . '_' . $view_id . '_widgets');
    }
Exemplo n.º 3
0
    /**
     *
     * @param $view_id
     */
    public function render_widget_hooks($view_id)
    {
        if (empty($view_id) || 'single' == gravityview_get_context()) {
            do_action('gravityview_log_debug', __METHOD__ . ' - Not rendering widgets; single entry');
            return;
        }
        $view_data = gravityview_get_current_view_data($view_id);
        // TODO: Move to sep. method, use an action instead
        wp_enqueue_style('gravityview_default_style');
        // get View widget configuration
        $widgets = $view_data['widgets'];
        $rows = GravityView_Plugin::get_default_widget_areas();
        switch (current_filter()) {
            case 'gravityview_before':
                $zone = 'header';
                break;
            case 'gravityview_after':
                $zone = 'footer';
                break;
        }
        // Prevent being called twice
        if (did_action($zone . '_' . $view_id . '_widgets')) {
            do_action('gravityview_log_debug', sprintf('%s - Not rendering %s; already rendered', __METHOD__, $zone . '_' . $view_id . '_widgets'));
            return;
        }
        // TODO Convert to partials
        ?>
		<div class="gv-grid">
			<?php 
        foreach ($rows as $row) {
            foreach ($row as $col => $areas) {
                $column = $col == '2-2' ? '1-2 gv-right' : $col . ' gv-left';
                ?>
					<div class="gv-grid-col-<?php 
                echo esc_attr($column);
                ?>
">
						<?php 
                if (!empty($areas)) {
                    foreach ($areas as $area) {
                        if (!empty($widgets[$zone . '_' . $area['areaid']])) {
                            foreach ($widgets[$zone . '_' . $area['areaid']] as $widget) {
                                do_action("gravityview_render_widget_{$widget['id']}", $widget);
                            }
                        }
                    }
                }
                ?>
					</div>
				<?php 
            }
            // $row
            ?>
			<?php 
        }
        // $rows
        ?>
		</div>

		<?php 
        /**
         * Prevent widgets from being called twice.
         * Checking for loop_start prevents themes and plugins that pre-process shortcodes from triggering the action before displaying. Like, ahem, the Divi theme and WordPress SEO plugin
         */
        if (did_action('loop_start')) {
            do_action($zone . '_' . $view_id . '_widgets');
        }
    }
Exemplo n.º 4
0
 /**
  * Fill in active areas with preset configuration according to the template selected
  * @return void
  */
 function get_preset_fields_config()
 {
     $this->check_ajax_nonce();
     if (empty($_POST['template_id'])) {
         exit(false);
     }
     // get the fields xml config file for this specific preset
     $preset_fields_path = apply_filters('gravityview_template_fieldsxml', array(), $_POST['template_id']);
     // import fields
     if (!empty($preset_fields_path)) {
         $presets = $this->import_fields($preset_fields_path);
     } else {
         $presets = array('widgets' => array(), 'fields' => array());
     }
     $template_id = esc_attr($_POST['template_id']);
     // template areas
     $template_areas_directory = apply_filters('gravityview_template_active_areas', array(), $template_id, 'directory');
     $template_areas_single = apply_filters('gravityview_template_active_areas', array(), $template_id, 'single');
     // widget areas
     $default_widget_areas = GravityView_Plugin::get_default_widget_areas();
     ob_start();
     do_action('gravityview_render_active_areas', $template_id, 'widget', 'header', $default_widget_areas, $presets['widgets']);
     $response['header'] = ob_get_clean();
     ob_start();
     do_action('gravityview_render_active_areas', $template_id, 'widget', 'footer', $default_widget_areas, $presets['widgets']);
     $response['footer'] = ob_get_clean();
     ob_start();
     do_action('gravityview_render_active_areas', $template_id, 'field', 'directory', $template_areas_directory, $presets['fields']);
     $response['directory'] = ob_get_clean();
     ob_start();
     do_action('gravityview_render_active_areas', $template_id, 'field', 'single', $template_areas_single, $presets['fields']);
     $response['single'] = ob_get_clean();
     $response = array_map('gravityview_strip_whitespace', $response);
     do_action('gravityview_log_debug', '[get_preset_fields_config] AJAX Response', $response);
     exit(json_encode($response));
 }
Exemplo n.º 5
0
    /**
     *
     * @param $view_id
     */
    public function render_widget_hooks($view_id)
    {
        if (empty($view_id) || 'single' == gravityview_get_context()) {
            do_action('gravityview_log_debug', __METHOD__ . ' - Not rendering widgets; single entry');
            return;
        }
        $view_data = gravityview_get_current_view_data($view_id);
        // get View widget configuration
        $widgets = (array) $view_data['widgets'];
        switch (current_filter()) {
            default:
            case 'gravityview_before':
                $zone = 'header';
                break;
            case 'gravityview_after':
                $zone = 'footer';
                break;
        }
        /**
         * Filter widgets not in the current zone
         * @since 1.16
         */
        foreach ($widgets as $key => $widget) {
            // The widget isn't in the current zone
            if (false === strpos($key, $zone)) {
                unset($widgets[$key]);
            }
        }
        /**
         * Prevent output if no widgets to show.
         * @since 1.16
         */
        if (empty($widgets)) {
            do_action('gravityview_log_debug', sprintf('No widgets for View #%s', $view_id));
            return;
        }
        // Prevent being called twice
        if (did_action($zone . '_' . $view_id . '_widgets')) {
            do_action('gravityview_log_debug', sprintf('%s - Not rendering %s; already rendered', __METHOD__, $zone . '_' . $view_id . '_widgets'));
            return;
        }
        $rows = GravityView_Plugin::get_default_widget_areas();
        // TODO: Move to sep. method, use an action instead
        wp_enqueue_style('gravityview_default_style');
        $default_css_class = 'gv-grid gv-widgets-' . $zone;
        if (0 === GravityView_View::getInstance()->getTotalEntries()) {
            $default_css_class .= ' gv-widgets-no-results';
        }
        /**
         * @filter `gravityview/widgets/wrapper_css_class` The CSS class applied to the widget container `<div>`.
         * @since 1.16.2
         * @param string $css_class Default: `gv-grid gv-widgets-{zone}` where `{zone}` is replaced by the current `$zone` value. If the View has no results, adds ` gv-widgets-no-results`
         * @param string $zone Current widget zone, either `header` or `footer`
         * @param array $widgets Array of widget configurations for the current zone, as set by `gravityview_get_current_view_data()['widgets']`
         */
        $css_class = apply_filters('gravityview/widgets/wrapper_css_class', $default_css_class, $zone, $widgets);
        $css_class = gravityview_sanitize_html_class($css_class);
        // TODO Convert to partials
        ?>
		<div class="<?php 
        echo $css_class;
        ?>
">
			<?php 
        foreach ($rows as $row) {
            foreach ($row as $col => $areas) {
                $column = $col == '2-2' ? '1-2 gv-right' : $col . ' gv-left';
                ?>
					<div class="gv-grid-col-<?php 
                echo esc_attr($column);
                ?>
">
						<?php 
                if (!empty($areas)) {
                    foreach ($areas as $area) {
                        if (!empty($widgets[$zone . '_' . $area['areaid']])) {
                            foreach ($widgets[$zone . '_' . $area['areaid']] as $widget) {
                                do_action("gravityview_render_widget_{$widget['id']}", $widget);
                            }
                        }
                    }
                }
                ?>
					</div>
				<?php 
            }
            // $row
            ?>
			<?php 
        }
        // $rows
        ?>
		</div>

		<?php 
        /**
         * Prevent widgets from being called twice.
         * Checking for loop_start prevents themes and plugins that pre-process shortcodes from triggering the action before displaying. Like, ahem, the Divi theme and WordPress SEO plugin
         */
        if (did_action('loop_start')) {
            do_action($zone . '_' . $view_id . '_widgets');
        }
    }