/** * @covers GravityView_Ajax::import_form() * @group gvajax */ function test_import_form() { /** @define "GRAVITYVIEW_DIR" "../../" */ $forms = $this->AJAX->import_form($this->GravityView_Preset_Business_Data->settings['preset_form']); $this->assertNotEmpty($forms); $this->assertEquals('GravityView - Business Data', $forms['title']); $this->assertEquals(14, sizeof($forms['fields'])); $GravityView_Preset_Business_Listings = new GravityView_Preset_Business_Listings(); $forms = $this->AJAX->import_form($GravityView_Preset_Business_Listings->settings['preset_form']); $this->assertNotEmpty($forms); $this->assertEquals('GravityView - Business Listing', $forms['title']); $this->assertEquals(13, sizeof($forms['fields'])); }
/** * Generic function to render rows and columns of active areas for widgets & fields * @param string $template_id The current slug of the selected View template * @param string $type Either 'widget' or 'field' * @param string $zone Either 'single', 'directory', 'header', 'footer' * @param array $rows The layout structure: rows, columns and areas * @param array $values Saved objects * @return void */ function render_active_areas($template_id, $type, $zone, $rows, $values) { global $post; if ($type === 'widget') { $button_label = __('Add Widget', 'gravityview'); } else { $button_label = __('Add Field', 'gravityview'); } $available_items = array(); // if saved values, get available fields to label everyone if (!empty($values) && (!empty($post->ID) || !empty($_POST['template_id']))) { if (!empty($_POST['template_id'])) { $form = GravityView_Ajax::pre_get_form_fields($_POST['template_id']); } else { $form = gravityview_get_form_id($post->ID); } if ('field' === $type) { $available_items = $this->get_available_fields($form, $zone); } else { $available_items = $this->get_registered_widgets(); } } foreach ($rows as $row) { foreach ($row as $col => $areas) { $column = $col == '2-2' ? '1-2' : $col; ?> <div class="gv-grid-col-<?php echo esc_attr($column); ?> "> <?php foreach ($areas as $area) { ?> <div class="gv-droppable-area"> <div class="active-drop active-drop-<?php echo esc_attr($type); ?> " data-areaid="<?php echo esc_attr($zone . '_' . $area['areaid']); ?> "> <?php // render saved fields if (!empty($values[$zone . '_' . $area['areaid']])) { foreach ($values[$zone . '_' . $area['areaid']] as $uniqid => $field) { $input_type = NULL; $original_item = isset($available_items[$field['id']]) ? $available_items[$field['id']] : false; if (!$original_item) { do_action('gravityview_log_error', 'An item was not available when rendering the output; maybe it was added by a plugin that is now de-activated.', array('available_items' => $available_items, 'field' => $field)); $original_item = $field; } else { $input_type = isset($original_item['type']) ? $original_item['type'] : NULL; } // Field options dialog box $field_options = GravityView_Render_Settings::render_field_options($type, $template_id, $field['id'], $original_item['label'], $zone . '_' . $area['areaid'], $input_type, $uniqid, $field, $zone, $original_item); $item = array('input_type' => $input_type, 'settings_html' => $field_options, 'label_type' => $type); // Merge the values with the current item to pass things like widget descriptions and original field names if ($original_item) { $item = wp_parse_args($item, $original_item); } switch ($type) { case 'widget': echo new GravityView_Admin_View_Widget($item['label'], $field['id'], $item, $field); break; default: echo new GravityView_Admin_View_Field($item['label'], $field['id'], $item, $field); } //endif; } } // End if zone is not empty ?> <span class="drop-message"><?php echo sprintf(esc_attr__('"+ %s" or drag existing %ss here.', 'gravityview'), $button_label, $type); ?> </span> </div> <div class="gv-droppable-area-action"> <a href="#" class="gv-add-field button-secondary" title="" data-objecttype="<?php echo esc_attr($type); ?> " data-areaid="<?php echo esc_attr($zone . '_' . $area['areaid']); ?> " data-context="<?php echo esc_attr($zone); ?> "><?php echo '+ ' . esc_html($button_label); ?> </a> <p class="gv-droppable-area-title"><strong><?php echo esc_html($area['title']); ?> </strong><?php if (!empty($area['subtitle'])) { ?> <span class="gv-droppable-area-subtitle"> – <?php echo esc_html($area['subtitle']); ?> </span><?php } ?> </p> </div> </div> <?php } ?> </div> <?php } } }
/** * Ajax * Returns the form fields ( only the searchable ones ) * * @access public * @return void */ public static function get_searchable_fields() { if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'gravityview_ajaxsearchwidget')) { exit('0'); } $form = ''; // Fetch the form for the current View if (!empty($_POST['view_id'])) { $form = gravityview_get_form_id($_POST['view_id']); } elseif (!empty($_POST['formid'])) { $form = (int) $_POST['formid']; } elseif (!empty($_POST['template_id']) && class_exists('GravityView_Ajax')) { $form = GravityView_Ajax::pre_get_form_fields($_POST['template_id']); } // fetch form id assigned to the view $response = self::render_searchable_fields($form); exit($response); }
/** * Given a View id, calculates the assigned form, and returns the form fields (only the sortable ones ) * AJAX callback * * * @access public * @return void */ function get_sortable_fields() { $this->check_ajax_nonce(); $form = ''; // if form id is set, use it, else, get form from preset if (!empty($_POST['form_id'])) { $form = (int) $_POST['form_id']; } elseif (!empty($_POST['template_id'])) { $form = GravityView_Ajax::pre_get_form_fields($_POST['template_id']); } $response = gravityview_get_sortable_fields($form); $response = gravityview_strip_whitespace($response); exit($response); }