Skip to content

Commit

Permalink
Merge 280b8b2 into ca907ac
Browse files Browse the repository at this point in the history
  • Loading branch information
zackkatz committed Oct 2, 2015
2 parents ca907ac + 280b8b2 commit ccde741
Show file tree
Hide file tree
Showing 15 changed files with 332 additions and 91 deletions.
4 changes: 2 additions & 2 deletions gravityview.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Plugin Name: GravityView
* Plugin URI: http://gravityview.co
* Description: Create directories based on a Gravity Forms form, insert them using a shortcode, and modify how they output.
* Version: 1.14.4-beta
* Version: 1.15
* Author: Katz Web Services, Inc.
* Author URI: http://www.katzwebservices.com
* Text Domain: gravityview
Expand Down Expand Up @@ -90,7 +90,7 @@
*/
final class GravityView_Plugin {

const version = '1.14.4-beta';
const version = '1.15';

private static $instance;

Expand Down
36 changes: 23 additions & 13 deletions includes/class-frontend-views.php
Original file line number Diff line number Diff line change
Expand Up @@ -1131,12 +1131,6 @@ public function add_scripts_and_styles() {

$views = $this->getGvOutputData()->get_views();

$js_localization = array(
'cookiepath' => COOKIEPATH,
'clear' => _x( 'Clear', 'Clear all data from the form', 'gravityview' ),
'reset' => _x( 'Reset', 'Reset the search form to the state that existed on page load', 'gravityview' ),
);

foreach ( $views as $view_id => $data ) {

// By default, no thickbox
Expand All @@ -1159,6 +1153,15 @@ public function add_scripts_and_styles() {
$css_dependencies[] = apply_filters( 'gravity_view_lightbox_style', 'thickbox' );
}

/**
* If the form has checkbox fields, enqueue dashicons
* @see https://github.com/katzwebservices/GravityView/issues/536
* @since 1.15
*/
if( gravityview_view_has_single_checkbox_or_radio( $data['form'], $data['fields'] ) ) {
$css_dependencies[] = 'dashicons';
}

wp_register_script( 'gravityview-jquery-cookie', plugins_url( 'includes/lib/jquery-cookie/jquery_cookie.js', GRAVITYVIEW_FILE ), array( 'jquery' ), GravityView_Plugin::version, true );

$script_debug = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
Expand All @@ -1167,13 +1170,6 @@ public function add_scripts_and_styles() {

wp_enqueue_script( 'gravityview-fe-view' );

/**
* @filter `gravityview_js_localization` Modify the array passed to wp_localize_script()
* @param array $js_localization The data padded to the Javascript file
* @param array $data View data array with View settings
*/
$js_localization = apply_filters( 'gravityview_js_localization', $js_localization, $data );

if ( ! empty( $data['atts']['sort_columns'] ) ) {
wp_enqueue_style( 'gravityview_font', plugins_url( 'assets/css/font.css', GRAVITYVIEW_FILE ), $css_dependencies, GravityView_Plugin::version, 'all' );
}
Expand All @@ -1185,6 +1181,20 @@ public function add_scripts_and_styles() {
}

if ( 'wp_print_footer_scripts' === current_filter() ) {

$js_localization = array(
'cookiepath' => COOKIEPATH,
'clear' => _x( 'Clear', 'Clear all data from the form', 'gravityview' ),
'reset' => _x( 'Reset', 'Reset the search form to the state that existed on page load', 'gravityview' ),
);

/**
* @filter `gravityview_js_localization` Modify the array passed to wp_localize_script()
* @param array $js_localization The data padded to the Javascript file
* @param array $data View data array with View settings
*/
$js_localization = apply_filters( 'gravityview_js_localization', $js_localization, $data );

wp_localize_script( 'gravityview-fe-view', 'gvGlobals', $js_localization );
}
}
Expand Down
10 changes: 5 additions & 5 deletions includes/class-gravityview-entry-notes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* Class GravityView_Entry_Notes
* @since TODO
* @since 1.15
*/
class GravityView_Entry_Notes {

Expand All @@ -14,7 +14,7 @@ public function __construct() {
}

/**
* @since TODO
* @since 1.15
*/
private function add_hooks() {
add_filter( 'gform_notes_avatar', array( 'GravityView_Entry_Notes', 'filter_avatar' ), 10, 2 );
Expand All @@ -24,7 +24,7 @@ private function add_hooks() {
/**
* Alias for GFFormsModel::add_note() with default note_type of 'gravityview'
* @see GFFormsModel::add_note()
* @since TODO
* @since 1.15
* @param int $lead_id ID of the Entry
* @param int $user_id ID of the user creating the note
* @param string $user_name User name of the user creating the note
Expand Down Expand Up @@ -72,7 +72,7 @@ public static function get_notes( $entry_id ) {

/**
* @filter `gravityview/entry_notes/get_notes` Modify the notes array for an entry
* @since TODO
* @since 1.15
* @param stdClass[] $notes Integer-keyed array of note objects
* @param int $entry_id Entry to get notes for
*/
Expand All @@ -84,7 +84,7 @@ public static function get_notes( $entry_id ) {
/**
* Use the GravityView avatar for notes created by GravityView
* Note: The function is static so that it's easier to remove the filter: `remove_filter( 'gform_notes_avatar', array( 'GravityView_Entry_Notes', 'filter_avatar' ) );`
* @since TODO
* @since 1.15
* @param string $avatar Avatar image, if available. 48px x 48px by default.
* @param object $note Note object with id, user_id, date_created, value, note_type, user_name, user_email vars
* @return string Possibly-modified avatar
Expand Down
28 changes: 28 additions & 0 deletions includes/connector-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,31 @@ function the_gravityview( $view_id = '', $atts = array() ) {
function gravityview_is_single_entry() {
return GravityView_frontend::is_single_entry();
}

/**
* Determine whether a View has a single checkbox or single radio input
* @see GravityView_frontend::add_scripts_and_styles()
* @since 1.15
* @param array $form Gravity Forms form
* @param array $view_fields GravityView fields array
*/
function gravityview_view_has_single_checkbox_or_radio( $form, $view_fields ) {

if( $form_fields = GFFormsModel::get_fields_by_type( $form, array( 'checkbox', 'radio' ) ) ) {

/** @var GF_Field_Radio|GF_Field_Checkbox $form_field */
foreach( $form_fields as $form_field ) {
$field_id = $form_field->id;
foreach( $view_fields as $zone ) {
foreach( $zone as $field ) {
// If it's an input, not the parent and the parent ID matches a checkbox or radio
if( ( strpos( $field['id'], '.' ) > 0 ) && floor( $field['id'] ) === floor( $field_id ) ) {
return true;
}
}
}
}
}

return false;
}
6 changes: 3 additions & 3 deletions templates/fields/number.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
$gravityview_view = GravityView_View::getInstance();

/**
* @var double|int $value
* @var double|int $display_value
* @var double|int|string $value
* @var double|int|string $display_value
*/
extract( $gravityview_view->getCurrentField() );

if( !empty( $field_settings['number_format'] ) ) {
if( $value !== '' && !empty( $field_settings['number_format'] ) ) {
$decimals = ( isset( $field_settings['decimals'] ) && $field_settings['decimals'] !== '' ) ? $field_settings['decimals'] : '';
echo gravityview_number_format( $value, $decimals );
} else {
Expand Down
26 changes: 12 additions & 14 deletions templates/fields/website.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,25 @@

extract( $gravityview_view->getCurrentField() );

if( !empty( $field_settings['truncatelink'] ) && function_exists( 'gravityview_format_link' ) ) {
if( !empty( $value ) ) {
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;
/** @since 1.8 */
$anchor_text = !empty( $field_settings['anchor_text'] ) ? trim( rtrim( $field_settings['anchor_text'] ) ) : false;

// Check empty again, just incase trim removed whitespace didn't work
if( !empty( $anchor_text ) ) {
// 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 );
// Replace the variables
$anchor_text = GravityView_API::replace_variables( $anchor_text, $form, $entry );

} else {
$anchor_text = gravityview_format_link( $value );
}
} else {
$anchor_text = empty( $field_settings['truncatelink'] ) ? $value : gravityview_format_link( $value );
}

$attributes = empty( $field_settings['open_same_window'] ) ? 'target=_blank' : '';
$attributes = empty( $field_settings['open_same_window'] ) ? 'target=_blank' : '';

echo gravityview_get_link( $value, $anchor_text, $attributes );
echo gravityview_get_link( $value, $anchor_text, $attributes );

}
} else {
echo $display_value;
}
22 changes: 22 additions & 0 deletions tests/GV_UnitTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

class GV_UnitTestCase extends WP_UnitTestCase {

/**
* @var GF_UnitTest_Factory
*/
var $factory;

function setUp() {
parent::setUp();

/* Remove temporary tables which causes problems with GF */
remove_all_filters( 'query', 10 );

/* Ensure the database is correctly set up */
@GFForms::setup_database();

$this->factory = new GF_UnitTest_Factory( $this );
}

}
2 changes: 2 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public function __construct() {
// load the WP testing environment
require_once( $this->wp_tests_dir . '/includes/bootstrap.php' );

require_once $this->tests_dir . '/GV_UnitTestCase.php';

require_once $this->tests_dir . '/factory.php';

// set up GravityView
Expand Down
4 changes: 4 additions & 0 deletions tests/factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ function __construct( $factory = null ) {
}

function create_object( $args ) {

$args = wp_parse_args( $args, $this->default_generation_definitions );

$insert_post_response = parent::create_object( $args );

if( $insert_post_response && !is_wp_error( $insert_post_response ) ) {
Expand Down Expand Up @@ -155,6 +158,7 @@ function __construct( $factory = null ) {
}

function create_object( $args ) {
$args = wp_parse_args( $args, $this->default_generation_definitions );
return GFAPI::add_entry( $args );
}

Expand Down
9 changes: 2 additions & 7 deletions tests/unit-tests/GravityView_API_Test.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class GravityView_API_Test extends WP_UnitTestCase {
class GravityView_API_Test extends GV_UnitTestCase {

/**
* @var int
Expand All @@ -25,13 +25,8 @@ class GravityView_API_Test extends WP_UnitTestCase {
var $is_set_up = false;

function setUp() {
parent::setUp();

/* Remove temporary tables which causes problems with GF */
remove_all_filters( 'query', 10 );

/* Ensure the database is correctly set up */
@GFForms::setup_database();
parent::setUp();

$this->form = GV_Unit_Tests_Bootstrap::instance()->get_form();
$this->form_id = GV_Unit_Tests_Bootstrap::instance()->get_form_id();
Expand Down
19 changes: 1 addition & 18 deletions tests/unit-tests/GravityView_Edit_Entry_Test.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class GravityView_Edit_Entry_Test extends WP_UnitTestCase {
class GravityView_Edit_Entry_Test extends GV_UnitTestCase {

/**
* @var int
Expand All @@ -12,11 +12,6 @@ class GravityView_Edit_Entry_Test extends WP_UnitTestCase {
*/
var $form = array();

/**
* @var GF_UnitTest_Factory
*/
var $factory;

/**
* @var int
*/
Expand All @@ -29,18 +24,6 @@ class GravityView_Edit_Entry_Test extends WP_UnitTestCase {

var $is_set_up = false;

function setUp() {
parent::setUp();

/* Remove temporary tables which causes problems with GF */
remove_all_filters( 'query', 10 );

/* Ensure the database is correctly set up */
@GFForms::setup_database();

$this->factory = new GF_UnitTest_Factory( $this );
}

/**
* @covers GravityView_Edit_Entry::getInstance()
*/
Expand Down
10 changes: 2 additions & 8 deletions tests/unit-tests/GravityView_Merge_Tags_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@
/**
* @since 1.15
*/
class GravityView_Merge_Tags_Test extends PHPUnit_Framework_TestCase {

function setUp() {
parent::setUp();

GravityView_Plugin::getInstance();
}
class GravityView_Merge_Tags_Test extends GV_UnitTestCase {

/**
* @since 1.15
* @group merge_tags
* @covers gravityview_has_shortcode_r()
* @covers GravityView_Merge_Tags::replace_variables()
*/
function test_replace_variables() {

Expand Down

0 comments on commit ccde741

Please sign in to comment.