Skip to content

Commit

Permalink
Merge pull request #25 from katzwebservices/develop
Browse files Browse the repository at this point in the history
Version 4.0
  • Loading branch information
zackkatz authored Mar 7, 2018
2 parents efe7eb1 + 119af10 commit 2e46c83
Show file tree
Hide file tree
Showing 11 changed files with 758 additions and 1,005 deletions.
157 changes: 97 additions & 60 deletions admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,51 +39,74 @@ function __construct() {
add_action( 'admin_head', array( &$this, 'admin_head' ), 1 );
}

add_action( 'gform_entries_first_column_actions', array( $this, 'add_edit_entry_link' ), 10, 5 );

add_action( 'gform_entry_list_bulk_actions', array( $this, 'add_bulk_actions' ), 10, 2 );

self::process_bulk_update();
}

/**
* Add Approve and Disapprove bulk actions to the entries dropdown
* @param array $actions
* @param int $form_id
*
* @return array
*/
public function add_bulk_actions( $actions = array(), $form_id = 0 ) {

$actions['approve-' . $form_id ] = esc_html__('Approve', 'gravity-forms-addons');
$actions['unapprove-' . $form_id ] = esc_html__('Disapprove', 'gravity-forms-addons');

return $actions;
}

public static function process_bulk_update() {
global $process_bulk_update_message;

if ( RGForms::post( "action" ) === 'bulk' ) {
check_admin_referer( 'gforms_entry_list', 'gforms_entry_list' );
if ( empty( $_POST['action'] ) && empty( $_POST['action2'] ) || empty( $_POST['gforms_entry_list'] ) ) {
return;
}

$bulk_action = ! empty( $_POST["bulk_action"] ) ? $_POST["bulk_action"] : $_POST["bulk_action2"];
$leads = $_POST["lead"];
$bulk_action = ! empty( $_POST["action"] ) ? $_POST["action"] : $_POST["action2"];

$entry_count = count( $leads ) > 1 ? sprintf( __( "%d entries", "gravityforms" ), count( $leads ) ) : __( "1 entry", "gravityforms" );
$bulk_action = explode( '-', $bulk_action );
if ( !in_array( $bulk_action[0], array( 'approve', 'unapprove' ) ) || ! isset( $bulk_action[1] ) || ! is_numeric( $bulk_action[1] ) ) {
return;
}

$bulk_action = explode( '-', $bulk_action );
if ( ! isset( $bulk_action[1] ) || empty( $leads ) ) {
return false;
}
check_admin_referer( 'gforms_entry_list', 'gforms_entry_list' );

switch ( $bulk_action[0] ) {
case "approve":
self::directory_update_bulk( $leads, 1, $bulk_action[1] );
$process_bulk_update_message = sprintf( __( "%s approved.", "gravity-forms-addons" ), $entry_count );
break;
$leads = isset( $_POST["lead"] ) ? $_POST["lead"] : $_POST["entry"];

case "unapprove":
self::directory_update_bulk( $leads, 0, $bulk_action[1] );
$process_bulk_update_message = sprintf( __( "%s disapproved.", "gravity-forms-addons" ), $entry_count );
break;
}
}
$leads = array_map( 'intval', $leads );

$entry_count = count( $leads ) > 1 ? sprintf( __( "%d entries", "gravityforms" ), count( $leads ) ) : __( "1 entry", "gravityforms" );

switch ( $bulk_action[0] ) {
case "approve":
self::directory_update_bulk( $leads, 1, $bulk_action[1] );
$process_bulk_update_message = sprintf( __( "%s approved.", "gravity-forms-addons" ), $entry_count );
break;

case "unapprove":
self::directory_update_bulk( $leads, 0, $bulk_action[1] );
$process_bulk_update_message = sprintf( __( "%s disapproved.", "gravity-forms-addons" ), $entry_count );
break;
}
}

static private function directory_update_bulk( $leads, $approved, $form_id ) {
global $_gform_directory_approvedcolumn;

if ( empty( $leads ) || ! is_array( $leads ) ) {
return false;
}

$_gform_directory_approvedcolumn = empty( $_gform_directory_approvedcolumn ) ? self::globals_get_approved_column( $_POST['form_id'] ) : $_gform_directory_approvedcolumn;
$approvedcolumn = GFDirectory::globals_get_approved_column( $form_id );

$approved = empty( $approved ) ? 0 : 'Approved';
foreach ( $leads as $lead_id ) {
GFDirectory::directory_update_approved( $lead_id, $approved, $form_id );
GFDirectory::directory_update_approved( $lead_id, $approved, $form_id, $approvedcolumn );
}
}

Expand All @@ -107,7 +130,7 @@ function gf_warning() {
If you haven\'t installed the plugin, you can %3$spurchase the plugin here%4$s. If you have, and you believe this notice is in error, %5$sstart a topic on the plugin support forum%4$s.
%6$s%7$sBuy Gravity Forms%4$s%8$s
', 'gravity-forms-addons' ), '<strong>', '</strong>', "<a href='http://katz.si/gravityforms'>", '</a>', '<a href="http://wordpress.org/tags/gravity-forms-addons?forum_id=10#postform">', '<p class="submit">', "<a href='http://katz.si/gravityforms' style='color:white!important' class='button button-primary'>", '</p>' );
', 'gravity-forms-addons' ), '<strong>', '</strong>', "<a href='https://katz.si/gravityforms'>", '</a>', '<a href="https://wordpress.org/tags/gravity-forms-addons?forum_id=10#postform">', '<p class="submit">', "<a href='https://katz.si/gravityforms' style='color:white!important' class='button button-primary'>", '</p>' );
}
}
if ( ! empty( $message ) ) {
Expand All @@ -123,10 +146,8 @@ public function activation() {
}

public function add_activation_notice() {
# if(!get_option("gf_addons_settings")) {
$message = sprintf( esc_html__( 'Congratulations - the Gravity Forms Directory & Addons plugin has been installed. %sGo to the settings page%s to read usage instructions and configure the plugin default settings. %sGo to settings page%s', 'gravity-forms-addons' ), '<a href="' . admin_url( 'admin.php?page=gf_settings&addon=Directory+%26+Addons&viewinstructions=true' ) . '">', '</a>', '<p class="submit"><a href="' . admin_url( 'admin.php?page=gf_settings&addon=Directory+%26+Addons&viewinstructions=true' ) . '" class="button button-secondary">', '</a></p>' );
$message = sprintf( esc_html__( 'Congratulations - the Gravity Forms Directory & Addons plugin has been installed. %sGo to the settings page%s to read usage instructions and configure the plugin default settings. %sGo to settings page%s', 'gravity-forms-addons' ), '<a href="' . esc_url_raw( admin_url( 'admin.php?page=gf_settings&addon=Directory+%26+Addons&viewinstructions=true' ) . '">', '</a>', '<p class="submit"><a href="' . admin_url( 'admin.php?page=gf_settings&addon=Directory+%26+Addons&viewinstructions=true' ) ) . '" class="button button-secondary">', '</a></p>' );
set_transient( 'kws_gf_activation_notice', $message, 60 * 60 );
# }
}

public function admin_head( $settings = array() ) {
Expand All @@ -148,8 +169,8 @@ public function admin_head( $settings = array() ) {
}
}

if ( isset( $_REQUEST['page'] ) && ( $_REQUEST['page'] == 'gf_edit_forms' || $_REQUEST['page'] == 'gf_entries' ) ) {
echo self::add_edit_js( isset( $_REQUEST['id'] ), $settings );
if ( GFDirectory::is_gravity_page('gf_entries') || GFDirectory::is_gravity_page('gf_edit_forms') ) {
self::add_edit_js( isset( $_REQUEST['id'] ), $settings );
}
}

Expand All @@ -158,6 +179,16 @@ static private function add_edit_js( $edit_forms = false, $settings = array() )
<script>
// Edit link for Gravity Forms entries
jQuery( document ).ready( function ( $ ) {

$('select[id^=bulk-action-selector-]').each(function() {
var $optgroup = $('<optgroup label="<?php esc_attr_e('Directory', 'gravity-forms-addons' ); ?>"></optgroup>');

$('option[value^="approve-"]', $( this ) ).remove().appendTo( $optgroup );
$('option[value^="unapprove-"]', $( this ) ).remove().appendTo( $optgroup );

$( this ).append( $optgroup );
});

<?php if(! empty( $settings['modify_admin']['expand'] ) && $edit_forms) { ?>
var onScrollScript = window.onscroll;
$( 'div.gforms_edit_form #add_fields #floatMenu' ).prepend( '<div class="gforms_expend_all_menus_form"><label for="expandAllMenus"><input type="checkbox" id="expandAllMenus" value="1" /> Expand All Menus</label></div>' );
Expand All @@ -179,41 +210,48 @@ static private function add_edit_js( $edit_forms = false, $settings = array() )

$( 'ul.menu' ).addClass( 'noaccordion' );
<?php
}
} ?>
} );
</script>
<?php
}

if(isset( $_REQUEST['page'] ) && $_REQUEST['page'] == 'gf_entries' && ! empty( $settings['modify_admin']['edit'] )) {
?>
// Changed from :contains('Delete') to :last-child to work with 1.6
$( ".row-actions span:last-child" ).each( function () {
var editLink = $( this ).parents( 'tr' ).find( '.column-title a' ).attr( 'href' );
editLink = editLink + '&screen_mode=edit';
//alert();
$( this ).after( '<span class="edit">| <a title="<?php echo esc_js( __( "Edit this entry", "gravity-forms-addons" ) ); ?>" href="' + editLink + '"><?php echo esc_js( __( "Edit", "gravity-forms-addons" ) ); ?></a></span>' );
} );
<?php
}
function add_edit_entry_link( $form_id, $field_id, $value, $entry, $query_string ) {

else if(isset( $_REQUEST['page'] ) && $_REQUEST['page'] == 'gf_edit_forms' && ! empty( $settings['modify_admin']['ids'] )) {
?>
// Changed from :contains('Delete') to :last-child for future-proofing
$( ".row-actions .trash" ).each( function () {
var formID = $( this ).parents( 'tr' ).find( '.column-id' ).text();
$settings = GFDirectory::get_settings();

var title = '<?php echo esc_js( __( "Fields for Form ID %s", "gravity-forms-addons" ) ); ?>';
title = title.replace( '%s', formID );
if( ! empty( $settings['modify_admin']['ids'] ) ) {

$( this ).after( '<span class="edit"> | <a title="' + title + '" href="<?php echo plugins_url( "field-ids.php", __FILE__ ); ?>?id=' + formID + '&amp;show_field_ids=true&amp;TB_iframe=true&amp;height=295&amp;width=370" class="thickbox form_ids"><?php echo esc_js( __( "IDs", "gravity-forms-addons" ) ); ?></a></span>' );
} );
<?php } ?>
} );
</script>
$field_id_url = plugins_url( "field-ids.php", __FILE__ );
$field_id_url = add_query_arg( array(
'id' => $form_id,
'show_field_ids' => 'true',
'TB_iframe' => 'true',
'height' => 295,
'width' => 370
), $field_id_url );
?>
<span class="edit"> | <a title="<?php esc_attr( printf( __( "Fields for Form ID %s", "gravity-forms-addons" ), $form_id ) ); ?>" href="<?php echo esc_url( $field_id_url ) ; ?>" class="thickbox form_ids"><?php esc_attr_e( "IDs", "gravity-forms-addons" ); ?></a></span>
<?php
}
}

if( ! empty( $settings['modify_admin']['edit'] ) ) {

$edit_entry_link = admin_url( 'admin.php' ) . '?screen_mode=edit&' . $query_string;
?>
<span class="edit"> | <a title="<?php esc_attr_e( "Edit this entry", "gravity-forms-addons" ); ?>" href="<?php echo esc_url( $edit_entry_link ) ; ?>"><?php esc_attr_e( "Edit", "gravity-forms-addons" ); ?></a></span>
<?php
}
}

static function show_field_ids( $form = array() ) {
if ( isset( $_REQUEST['show_field_ids'] ) ) {
$form = RGFormsModel::get_form_meta( $_GET["id"] );
$form = RGFormsModel::add_default_properties( $form );
/**
* @param array $form
*
* @return array|mixed|null
*/
public static function show_field_ids( $form = array() ) {
if ( isset( $_REQUEST['show_field_ids'] ) && isset( $_GET["id"] ) && is_numeric( $_GET["id"] ) ) {
$form = GFAPI::get_form( $_GET["id"] );

echo <<<EOD
<style>
Expand Down Expand Up @@ -461,7 +499,6 @@ static function make_popup_options( $js = false ) {
true,
esc_html__( "If there's a displayed Entry ID column, add link to each full entry", 'gravity-forms-addons' ),
),
#array('checkbox', 'wpautop' , true, sprintf( esc_html__( "Convert bulk paragraph text to paragraphs (using the WordPress function %s)", 'gravity-forms-addons'), "<code><a href='http://codex.wordpress.org/Function_Reference/wpautop'>wpautop()</a></code>" )),
array(
'checkbox',
'getimagesize',
Expand Down Expand Up @@ -1158,7 +1195,7 @@ class="description"><?php esc_html_e( 'Need help getting started?', 'gravity-for
src="http<?php echo is_ssl() ? 's' : ''; ?>://www.youtube.com/embed/PMI7Jb-RP2I?hd=1"
frameborder="0" allowfullscreen></iframe>
</div>
<h3 style="padding-top:1em;"><?php esc_html_e( 'To integrate a form with Directory:', 'gravity-forms-addons' ); ?></h3>
<h3 style="padding-top:1em; line-height: 1"><?php esc_html_e( 'To integrate a form with Directory:', 'gravity-forms-addons' ); ?></h3>
<ol class="ol-decimal">
<li><?php esc_html_e( 'Go to the post or page where you would like to add the directory.', 'gravity-forms-addons' ); ?></li>
<li><?php esc_html_e( 'Click the "Add Directory" button above the content area.', 'gravity-forms-addons' ); ?></li>
Expand Down
67 changes: 46 additions & 21 deletions edit-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public function directory_add_default_values() {

field.choices = null;
field.inputs = null;
field.gf_directory_approval = true;

if(!field.choices)
field.choices = new Array(new Choice("<?php echo esc_js( __("Approved", "gravity-forms-addons")); ?>"));
Expand All @@ -102,7 +103,7 @@ public function directory_add_default_values() {
}

public function directory_admin_head() {
global $_gform_directory_approvedcolumn, $process_bulk_update_message;
global $process_bulk_update_message;

// Entries screen shows first form's entries by default, if not specified
if( isset( $_GET['id'] ) ) {
Expand Down Expand Up @@ -146,16 +147,14 @@ public function directory_admin_head() {

<?php

//$formID = RGForms::get("id");

if(empty($formID)) {
$forms = RGFormsModel::get_forms(NULL, "title");
$forms = RGFormsModel::get_forms(null, "title");
$formID = $forms[0]->id;
}

$_gform_directory_approvedcolumn = empty($_gform_directory_approvedcolumn) ? GFDirectory::globals_get_approved_column($formID) : $_gform_directory_approvedcolumn;
$approvedcolumn = GFDirectory::globals_get_approved_column( $formID );

if(!empty($_gform_directory_approvedcolumn)) {
if(!empty($approvedcolumn)) {
echo 'formID = '.$formID.';';
?>

Expand Down Expand Up @@ -211,11 +210,9 @@ function hideMessage(container, messageQueued){
jQuery(document).ready(function($) {

<?php if(!empty($process_bulk_update_message)) { ?>
displayMessage('<?php echo esc_js($process_bulk_update_message); ?>', 'updated', '#lead_form');
displayMessage('<?php echo esc_js($process_bulk_update_message); ?>', 'updated', '.gf_entries');
<?php } ?>

$("#bulk_action,#bulk_action2").append('<optgroup label="Directory"><option value="approve-'+formID+'"><?php echo esc_js( __('Approve', 'gravity-forms-addons')); ?></option><option value="unapprove-'+formID+'"><?php echo esc_js( __('Disapprove', 'gravity-forms-addons')); ?></option></optgroup>');

var approveTitle = '<?php echo esc_js( __('Entry not approved for directory viewing. Click to approve this entry.', 'gravity-forms-addons')); ?>';
var unapproveTitle = '<?php echo esc_js( __('Entry approved for directory viewing. Click to disapprove this entry.', 'gravity-forms-addons')); ?>';

Expand All @@ -225,19 +222,22 @@ function hideMessage(container, messageQueued){
var $tr = $(this).parents('tr');
var is_approved = $tr.is(".lead_approved");

if(e.type == 'click') {
if(e.type === 'click') {
$tr.toggleClass("lead_approved");
}

// Update the title and screen-reader text
if(!is_approved) { $(this).text('X').prop('title', unapproveTitle); }
else { $(this).text('O').prop('title', approveTitle); }
if(!is_approved) {
$(this).text('X').prop('title', unapproveTitle);
} else {
$(this).text('O').prop('title', approveTitle);
}

if(e.type == 'click') {
UpdateApproved($('th input[type="checkbox"]', $tr).val(), is_approved ? 0 : 'Approved');
}

UpdateApprovedColumns($(this).parents('table'), false);
UpdateApprovedColumns($(this).parents('table.gf_entries'), false);

return false;

Expand All @@ -246,28 +246,53 @@ function hideMessage(container, messageQueued){
// We want to make sure that the checkboxes go away even if the Approved column is showing.
// They will be in sync when loaded, so only upon click will we process.
function UpdateApprovedColumns($table, onLoad) {
var colIndex = $('th:contains("Approved")', $table).index() - 1;

<?php

if( ! empty( $approvedcolumn ) ) {
/** @see https://stackoverflow.com/a/350300/480856 */
$approved_column_jquery = str_replace( '.', '\\\.', $approvedcolumn );
$approved_column_jquery = 'field_id-' . esc_html( $approved_column_jquery );
} else {
echo 'return;'; // No need to update approval columns; the only approval is the meta checkbox
}
?>

$('tr', $table).each(function() {
if($(this).is('.lead_approved') || (onLoad && $("input.lead_approved", $(this)).length > 0)) {
if(onLoad && $(this).not('.lead_approved')) { $(this).addClass('lead_approved'); }
$('td:visible:eq('+colIndex+'):has(.toggleApproved)', $(this)).html("<img src='<?php echo plugins_url('images/tick.png', __FILE__); ?>/>");

// No GF approval; don't modify things
if( 0 === $( '.toggleApproved', $( this ) ).length ) {
return;
}

if( $(this).is('.lead_approved') || (onLoad && $("input.lead_approved", $(this)).length > 0)) {

if(onLoad && $(this).not('.lead_approved')) {
$(this).addClass('lead_approved');
}

$('td.column-<?php echo $approved_column_jquery; ?>:visible', $(this)).html('<i class="fa fa-check gf_valid"></i>');

} else {
if(onLoad && $(this).is('.lead_approved')) { $(this).removeClass('lead_approved'); }
$('td:visible:eq('+colIndex+'):has(.toggleApproved)', $(this)).html('');

if(onLoad && $(this).is('.lead_approved')) {
$(this).removeClass('lead_approved');
}

$('td.column-<?php echo $approved_column_jquery; ?>:visible', $(this)).html('');
}
});
}

// Add the header column
$('thead .column-is_starred, tfoot .column-is_starred').after('<th class="manage-column column-is_starred sortable"><a href="<?php echo esc_url( add_query_arg(array('sort' => $_gform_directory_approvedcolumn)) ); ?>"><img src="<?php echo plugins_url( '/images/form-button-1.png', __FILE__); ?>" title="<?php echo esc_js( __('Show entry in directory view?', 'gravity-forms-addons')); ?>" /></span></a></th>');
$('thead .column-is_starred, tfoot .column-is_starred').after('<th class="manage-column column-is_starred sortable"><a href="<?php echo esc_url( add_query_arg(array('sort' => $approvedcolumn)) ); ?>"><img src="<?php echo plugins_url( '/images/form-button-1.png', __FILE__); ?>" title="<?php echo esc_js( __('Show entry in directory view?', 'gravity-forms-addons')); ?>" /></span></a></th>');

// Add to each row
$('tbody td:has(img[src*="star"]), tbody th:has(img[src*="star"])').after('<td><a href="#" class="toggleApproved" title="'+approveTitle+'">X</a></td>');

$('tr:has(input.lead_approved)').addClass('lead_approved').find('a.toggleApproved').prop('title', unapproveTitle).text('O');

UpdateApprovedColumns($('table'), true);
UpdateApprovedColumns($('table.gf_entries'), true);

});
<?php } // end if(!empty($_gform_directory_approvedcolumn)) check ?>
Expand Down
2 changes: 1 addition & 1 deletion entry-details.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

// Verify that the link is accessed properly
if ( false == wp_verify_nonce( $_GET['view'], sprintf('view-%d-%d', $_REQUEST['leadid'], $_REQUEST['form']) )) {
wp_die( 'Verication failed. Please return to the original page, refresh, and click on the entry again.', 'gravity-forms-addons');
wp_die( 'Verification failed. Please return to the original page, refresh, and click on the entry again.', 'gravity-forms-addons');
}

// Force a happy header
Expand Down
Loading

0 comments on commit 2e46c83

Please sign in to comment.