Initial commit
This commit is contained in:
342
includes/fields/class-field-assignee-select.php
Normal file
342
includes/fields/class-field-assignee-select.php
Normal file
@@ -0,0 +1,342 @@
|
||||
<?php
|
||||
/**
|
||||
* Gravity Flow Assignee Field
|
||||
*
|
||||
* @package GravityFlow
|
||||
* @copyright Copyright (c) 2015-2018, Steven Henty S.L.
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'GFForms' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Gravity_Flow_Field_Assignee_Select
|
||||
*/
|
||||
class Gravity_Flow_Field_Assignee_Select extends GF_Field_Select {
|
||||
|
||||
/**
|
||||
* The field type.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $type = 'workflow_assignee_select';
|
||||
|
||||
/**
|
||||
* Indicates if this field type can be used when configuring conditional logic rules.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_conditional_logic_supported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the Workflow Fields group to the form editor.
|
||||
*
|
||||
* @param array $field_groups The properties for the field groups.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_button( $field_groups ) {
|
||||
$field_groups = Gravity_Flow_Fields::maybe_add_workflow_field_group( $field_groups );
|
||||
|
||||
return parent::add_button( $field_groups );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class names of the settings which should be available on the field in the form editor.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function get_form_editor_field_settings() {
|
||||
return array(
|
||||
'conditional_logic_field_setting',
|
||||
'prepopulate_field_setting',
|
||||
'error_message_setting',
|
||||
'enable_enhanced_ui_setting',
|
||||
'label_setting',
|
||||
'label_placement_setting',
|
||||
'admin_label_setting',
|
||||
'size_setting',
|
||||
'rules_setting',
|
||||
'placeholder_setting',
|
||||
'default_value_setting',
|
||||
'visibility_setting',
|
||||
'duplicate_setting',
|
||||
'description_setting',
|
||||
'css_class_setting',
|
||||
'gravityflow_setting_assignees',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the field button properties for the form editor.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_form_editor_button() {
|
||||
return array(
|
||||
'group' => 'workflow_fields',
|
||||
'text' => $this->get_form_editor_field_title(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the field title.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_form_editor_field_title() {
|
||||
return __( 'Assignee', 'gravityflow' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the HTML markup for the field choices.
|
||||
*
|
||||
* @param string $value The field value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_choices( $value ) {
|
||||
|
||||
$include_users = (bool) $this->gravityflowAssigneeFieldShowUsers;
|
||||
$include_roles = (bool) $this->gravityflowAssigneeFieldShowRoles;
|
||||
$include_fields = (bool) $this->gravityflowAssigneeFieldShowFields;
|
||||
|
||||
$choices = $this->get_assignees_as_choices( $value, $include_users, $include_roles, $include_fields );
|
||||
|
||||
return $choices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the HTML markup for the field choices.
|
||||
*
|
||||
* @param string $value The field value.
|
||||
* @param bool $include_users Indicates if the users should be added as choices.
|
||||
* @param bool $include_roles Indicates if the roles should be added as choices.
|
||||
* @param bool $include_fields Indicates if the fields should be added as choices.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_assignees_as_choices( $value, $include_users = true, $include_roles = true, $include_fields = true ) {
|
||||
$form_id = $this->formId;
|
||||
$account_choices = $role_choices = $fields_choices = $optgroups = array();
|
||||
|
||||
if ( $include_users ) {
|
||||
$args = array(
|
||||
'number' => 1000,
|
||||
'orderby' => 'display_name',
|
||||
'role' => $this->gravityflowUsersRoleFilter,
|
||||
);
|
||||
|
||||
$args = apply_filters( 'gravityflow_get_users_args_assignee_field', $args, $form_id, $this );
|
||||
$accounts = get_users( $args );
|
||||
foreach ( $accounts as $account ) {
|
||||
$account_choices[] = array( 'value' => 'user_id|' . $account->ID, 'text' => $account->display_name );
|
||||
}
|
||||
|
||||
$account_choices = apply_filters( 'gravityflow_assignee_field_users', $account_choices, $form_id, $this );
|
||||
|
||||
if ( ! empty( $account_choices ) ) {
|
||||
$users_opt_group = new GF_Field();
|
||||
$users_opt_group->choices = $account_choices;
|
||||
|
||||
$optgroups[] = array(
|
||||
'label' => __( 'Users', 'gravityflow' ),
|
||||
'choices' => GFCommon::get_select_choices( $users_opt_group, $value ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( $include_roles ) {
|
||||
$role_choices = Gravity_Flow_Common::get_roles_as_choices( true, true, true );
|
||||
$role_choices = apply_filters( 'gravityflow_assignee_field_roles', $role_choices, $form_id, $this );
|
||||
|
||||
if ( ! empty( $role_choices ) ) {
|
||||
$roles_opt_group = new GF_Field();
|
||||
$roles_opt_group->choices = $role_choices;
|
||||
|
||||
$optgroups[] = array(
|
||||
'label' => __( 'Roles', 'gravityflow' ),
|
||||
'key' => 'roles',
|
||||
'choices' => GFCommon::get_select_choices( $roles_opt_group, $value ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ( $include_fields ) {
|
||||
$form_id = $this->formId;
|
||||
$form = GFAPI::get_form( $form_id );
|
||||
if ( rgar( $form, 'requireLogin' ) ) {
|
||||
|
||||
$fields_choices = array(
|
||||
array(
|
||||
'text' => __( 'User (Created by)', 'gravityflow' ),
|
||||
'value' => 'entry|created_by',
|
||||
),
|
||||
);
|
||||
|
||||
$fields_choices = apply_filters( 'gravityflow_assignee_field_fields', $fields_choices, $form_id, $this );
|
||||
|
||||
if ( ! empty( $fields_choices ) ) {
|
||||
$fields_opt_group = new GF_Field();
|
||||
$fields_opt_group->choices = $fields_choices;
|
||||
|
||||
$optgroups[] = array(
|
||||
'label' => __( 'Fields', 'gravityflow' ),
|
||||
'choices' => GFCommon::get_select_choices( $fields_opt_group, $value ),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$html = '';
|
||||
|
||||
if ( ! empty( $this->placeholder ) ) {
|
||||
$selected = empty( $value ) ? "selected='selected'" : '';
|
||||
$html = sprintf( "<option value='' %s class='gf_placeholder'>%s</option>", $selected, esc_html( $this->placeholder ) );
|
||||
}
|
||||
|
||||
foreach ( $optgroups as $optgroup ) {
|
||||
$html .= sprintf( '<optgroup label="%s">%s</optgroup>', $optgroup['label'], $optgroup['choices'] );
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the entry value for display on the entries list page.
|
||||
*
|
||||
* @param string|array $value The field value.
|
||||
* @param array $entry The Entry Object currently being processed.
|
||||
* @param string $field_id The field or input ID currently being processed.
|
||||
* @param array $columns The properties for the columns being displayed on the entry list page.
|
||||
* @param array $form The Form Object currently being processed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_value_entry_list( $value, $entry, $field_id, $columns, $form ) {
|
||||
$assignee = parent::get_value_entry_list( $value, $entry, $field_id, $columns, $form );
|
||||
$value = $this->get_display_name( $assignee );
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the entry value which will replace the field merge tag.
|
||||
*
|
||||
* @param string $value The field value. Depending on the location the merge tag is being used the following functions may have already been applied to the value: esc_html, nl2br, and urlencode.
|
||||
* @param string $input_id The field or input ID from the merge tag currently being processed.
|
||||
* @param array $entry The Entry Object currently being processed.
|
||||
* @param array $form The Form Object currently being processed.
|
||||
* @param string $modifier The merge tag modifier. e.g. value.
|
||||
* @param string|array $raw_value The raw field value from before any formatting was applied to $value.
|
||||
* @param bool $url_encode Indicates if the urlencode function may have been applied to the $value.
|
||||
* @param bool $esc_html Indicates if the esc_html function may have been applied to the $value.
|
||||
* @param string $format The format requested for the location the merge is being used. Possible values: html, text or url.
|
||||
* @param bool $nl2br Indicates if the nl2br function may have been applied to the $value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_value_merge_tag( $value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br ) {
|
||||
$value = $this->get_display_name( $value, $modifier, $url_encode, $esc_html );
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the entry value for display on the entry detail page and for the {all_fields} merge tag.
|
||||
*
|
||||
* @param string $value The field value.
|
||||
* @param string $currency The entry currency code.
|
||||
* @param bool|false $use_text When processing choice based fields should the choice text be returned instead of the value.
|
||||
* @param string $format The format requested for the location the merge is being used. Possible values: html, text or url.
|
||||
* @param string $media The location where the value will be displayed. Possible values: screen or email.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_value_entry_detail( $value, $currency = '', $use_text = false, $format = 'html', $media = 'screen' ) {
|
||||
$assignee = parent::get_value_entry_detail( $value, $currency, $use_text, $format, $media );
|
||||
$value = $this->get_display_name( $assignee );
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the display name for the selected choice (assignee).
|
||||
*
|
||||
* @param string $assignee The assignee key.
|
||||
* @param string $modifier The merge tag modifier.
|
||||
* @param bool $url_encode Indicates if the urlencode function may have been applied to the $value.
|
||||
* @param bool $esc_html Indicates if the esc_html function may have been applied to the $value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_display_name( $assignee, $modifier = '', $url_encode = false, $esc_html = true ) {
|
||||
if ( empty( $assignee ) ) {
|
||||
return '';
|
||||
}
|
||||
list( $type, $value ) = explode( '|', $assignee, 2 );
|
||||
switch ( $type ) {
|
||||
case 'role' :
|
||||
$value = translate_user_role( $value );
|
||||
break;
|
||||
case 'user_id' :
|
||||
$value = Gravity_Flow_Fields::get_user_variable( $value, $modifier );
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the entry value before it is used in entry exports and by framework add-ons using GFAddOn::get_field_value().
|
||||
*
|
||||
* @param array $entry The entry currently being processed.
|
||||
* @param string $input_id The field or input ID.
|
||||
* @param bool|false $use_text When processing choice based fields should the choice text be returned instead of the value.
|
||||
* @param bool|false $is_csv Indicates if the value is going to be used in the .csv entries export.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_value_export( $entry, $input_id = '', $use_text = false, $is_csv = false ) {
|
||||
if ( empty( $input_id ) ) {
|
||||
$input_id = $this->id;
|
||||
}
|
||||
|
||||
$assignee = rgar( $entry, $input_id );
|
||||
|
||||
list( $type, $value ) = explode( '|', $assignee, 2 );
|
||||
switch ( $type ) {
|
||||
case 'role':
|
||||
$value = translate_user_role( $value );
|
||||
break;
|
||||
case 'user_id':
|
||||
if ( $use_text == false && $is_csv == false ) {
|
||||
$value = $assignee;
|
||||
} else {
|
||||
$value = $this->get_display_name( $assignee );
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize the field settings when the form is saved.
|
||||
*/
|
||||
public function sanitize_settings() {
|
||||
parent::sanitize_settings();
|
||||
if ( ! empty( $this->gravityflowUsersRoleFilter ) ) {
|
||||
$this->gravityflowUsersRoleFilter = wp_strip_all_tags( $this->gravityflowUsersRoleFilter );
|
||||
}
|
||||
|
||||
$this->gravityflowAssigneeFieldShowUsers = (bool) $this->gravityflowAssigneeFieldShowUsers;
|
||||
$this->gravityflowAssigneeFieldShowRoles = (bool) $this->gravityflowAssigneeFieldShowRoles;
|
||||
$this->gravityflowAssigneeFieldShowFields = (bool) $this->gravityflowAssigneeFieldShowFields;
|
||||
}
|
||||
}
|
||||
|
||||
GF_Fields::register( new Gravity_Flow_Field_Assignee_Select() );
|
||||
598
includes/fields/class-field-discussion.php
Normal file
598
includes/fields/class-field-discussion.php
Normal file
@@ -0,0 +1,598 @@
|
||||
<?php
|
||||
/**
|
||||
* Gravity Flow Discussion Field
|
||||
*
|
||||
* @package GravityFlow
|
||||
* @copyright Copyright (c) 2015-2018, Steven Henty S.L.
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'GFForms' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Gravity_Flow_Field_Discussion
|
||||
*/
|
||||
class Gravity_Flow_Field_Discussion extends GF_Field_Textarea {
|
||||
|
||||
/**
|
||||
* The field type.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $type = 'workflow_discussion';
|
||||
|
||||
/**
|
||||
* Input values are repopulated following validation errors, which is the desired behaviour.
|
||||
* It also happened when an in progress user input step was redisplayed following a successful update, which is not desired.
|
||||
* This is set to true in get_value_save_entry() and then set back to false after the value is cleared in get_field_input().
|
||||
*
|
||||
* @var bool Should the input value be cleared?
|
||||
*/
|
||||
private $_clear_input_value = false;
|
||||
|
||||
/**
|
||||
* Adds the Workflow Fields group to the form editor.
|
||||
*
|
||||
* @param array $field_groups The properties for the field groups.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_button( $field_groups ) {
|
||||
$field_groups = Gravity_Flow_Fields::maybe_add_workflow_field_group( $field_groups );
|
||||
|
||||
return parent::add_button( $field_groups );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the field button properties for the form editor.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_form_editor_button() {
|
||||
return array(
|
||||
'group' => 'workflow_fields',
|
||||
'text' => $this->get_form_editor_field_title(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class names of the settings which should be available on the field in the form editor.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function get_form_editor_field_settings() {
|
||||
return array(
|
||||
'conditional_logic_field_setting',
|
||||
'prepopulate_field_setting',
|
||||
'error_message_setting',
|
||||
'label_setting',
|
||||
'label_placement_setting',
|
||||
'admin_label_setting',
|
||||
'maxlen_setting',
|
||||
'size_setting',
|
||||
'rules_setting',
|
||||
'visibility_setting',
|
||||
'duplicate_setting',
|
||||
'default_value_textarea_setting',
|
||||
'placeholder_textarea_setting',
|
||||
'description_setting',
|
||||
'css_class_setting',
|
||||
'gravityflow_setting_discussion_timestamp_format',
|
||||
'rich_text_editor_setting',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the field title.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_form_editor_field_title() {
|
||||
return __( 'Discussion', 'gravityflow' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the entry value for display on the entries list page.
|
||||
*
|
||||
* @param string|array $value The field value.
|
||||
* @param array $entry The Entry Object currently being processed.
|
||||
* @param string $field_id The field or input ID currently being processed.
|
||||
* @param array $columns The properties for the columns being displayed on the entry list page.
|
||||
* @param array $form The Form Object currently being processed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_value_entry_list( $value, $entry, $field_id, $columns, $form ) {
|
||||
$return = $value;
|
||||
if ( $return ) {
|
||||
$discussion = json_decode( $value, ARRAY_A );
|
||||
if ( is_array( $discussion ) ) {
|
||||
$item = array_pop( $discussion );
|
||||
$return = $item['value'];
|
||||
}
|
||||
}
|
||||
|
||||
return esc_html( $return );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the entry value which will replace the field merge tag.
|
||||
*
|
||||
* @param string $value The field value. Depending on the location the merge tag is being used the following functions may have already been applied to the value: esc_html, nl2br, and urlencode.
|
||||
* @param string $input_id The field or input ID from the merge tag currently being processed.
|
||||
* @param array $entry The Entry Object currently being processed.
|
||||
* @param array $form The Form Object currently being processed.
|
||||
* @param string $modifier The merge tag modifier. e.g. value.
|
||||
* @param string|array $raw_value The raw field value from before any formatting was applied to $value.
|
||||
* @param bool $url_encode Indicates if the urlencode function may have been applied to the $value.
|
||||
* @param bool $esc_html Indicates if the esc_html function may have been applied to the $value.
|
||||
* @param string $format The format requested for the location the merge is being used. Possible values: html, text or url.
|
||||
* @param bool $nl2br Indicates if the nl2br function may have been applied to the $value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_value_merge_tag( $value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br ) {
|
||||
$value = $this->format_discussion_value( $raw_value, $format );
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the entry value for display on the entry detail page and for the {all_fields} merge tag.
|
||||
*
|
||||
* @param string $value The field value.
|
||||
* @param string $currency The entry currency code.
|
||||
* @param bool|false $use_text When processing choice based fields should the choice text be returned instead of the value.
|
||||
* @param string $format The format requested for the location the merge is being used. Possible values: html, text or url.
|
||||
* @param string $media The location where the value will be displayed. Possible values: screen or email.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_value_entry_detail( $value, $currency = '', $use_text = false, $format = 'html', $media = 'screen' ) {
|
||||
$value = $this->format_discussion_value( $value, $format );
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the field inner markup.
|
||||
*
|
||||
* @param array $form The Form Object currently being processed.
|
||||
* @param string|array $value The field value. From default/dynamic population, $_POST, or a resumed incomplete submission.
|
||||
* @param null|array $entry Null or the Entry Object currently being edited.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_field_input( $form, $value = '', $entry = null ) {
|
||||
$input = '';
|
||||
$is_form_editor = $this->is_form_editor();
|
||||
|
||||
if ( is_array( $entry ) || $is_form_editor ) {
|
||||
if ( $is_form_editor ) {
|
||||
$entry_value = json_encode( array(
|
||||
array(
|
||||
'id' => 'example',
|
||||
'assignee_key' => 'example|John Doe',
|
||||
'timestamp' => time(),
|
||||
'value' => esc_attr__( 'Example comment.', 'gravityflow' ),
|
||||
),
|
||||
) );
|
||||
} else {
|
||||
$entry_value = rgar( $entry, $this->id );
|
||||
}
|
||||
|
||||
$input = $this->format_discussion_value( $entry_value, 'html', rgar( $entry, 'id' ) );
|
||||
|
||||
if ( $value == $entry_value || $this->_clear_input_value ) {
|
||||
$value = '';
|
||||
$this->_clear_input_value = false;
|
||||
}
|
||||
}
|
||||
|
||||
$input .= parent::get_field_input( $form, $value, $entry );
|
||||
|
||||
return $input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the field entry value for output.
|
||||
*
|
||||
* @param string $value The entry value for the current field.
|
||||
* @param string $format The requested format for the value; html or text.
|
||||
* @param int|null $entry_id The ID of the entry currently being edited or null in other locations.
|
||||
*
|
||||
* @since 1.4.2-dev Added the $entry_id param.
|
||||
* @since 1.3.2
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function format_discussion_value( $value, $format = 'html', $entry_id = null ) {
|
||||
$return = '';
|
||||
$discussion = json_decode( $value, ARRAY_A );
|
||||
if ( is_array( $discussion ) ) {
|
||||
|
||||
if ( $modifiers = $this->get_modifiers() ) {
|
||||
if ( in_array( 'first', $modifiers ) ) {
|
||||
$item = rgar( $discussion, 0 );
|
||||
|
||||
return $this->format_discussion_item( $item, $format, $entry_id );
|
||||
} elseif ( in_array( 'latest', $modifiers ) ) {
|
||||
$item = end( $discussion );
|
||||
|
||||
return $this->format_discussion_item( $item, $format, $entry_id );
|
||||
} else {
|
||||
$limit = $this->get_limit_modifier();
|
||||
$has_limit = $limit > 0;
|
||||
}
|
||||
} else {
|
||||
$limit = 0;
|
||||
$has_limit = false;
|
||||
}
|
||||
|
||||
$reverse_comment_order = false;
|
||||
|
||||
/**
|
||||
* Allow the order of the discussion field comments to be reversed.
|
||||
*
|
||||
* @param bool $reverse_comment_order Should the comment order be reversed? Default is false.
|
||||
* @param Gravity_Flow_Field_Discussion $this The field currently being processed.
|
||||
* @param string $format The requested format for the value; html or text.
|
||||
*
|
||||
* @since 1.4.2-dev
|
||||
*/
|
||||
$reverse_comment_order = apply_filters( 'gravityflow_reverse_comment_order_discussion_field', $reverse_comment_order, $this, $format );
|
||||
if ( $reverse_comment_order ) {
|
||||
$discussion = array_reverse( $discussion );
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
$recent_display_limit = 0;
|
||||
$display_items = '';
|
||||
$hidden_items = '';
|
||||
|
||||
/**
|
||||
* Whether to show / hide the toggle to display more discussion items.
|
||||
*
|
||||
* @param boolean $hide_toggle Whether to prevent the display more toggle from displaying.
|
||||
* @param Gravity_Flow_Field_Discussion $this The field currently being processed.
|
||||
*
|
||||
* @since 2.0.2
|
||||
*/
|
||||
$display_toggle = apply_filters( 'gravityflow_discussion_items_display_toggle', true, $this );
|
||||
|
||||
if ( ( rgget( 'view' ) == 'entry' && $display_toggle ) ) {
|
||||
/**
|
||||
* Set the amount of discussion items to be shown in non-print inbox / status view when toggle is active.
|
||||
*
|
||||
* @param int $max_display_limit Amount of comments to be shown. Default is 10.
|
||||
* @param Gravity_Flow_Field_Discussion $this The field currently being processed.
|
||||
*
|
||||
* @since 1.9.2-dev
|
||||
*/
|
||||
$max_display_limit = apply_filters( 'gravityflow_discussion_items_display_limit', 10, $this );
|
||||
|
||||
if ( count( $discussion ) > $max_display_limit ) {
|
||||
|
||||
$recent_display_limit = count( $discussion ) - $max_display_limit;
|
||||
|
||||
$view_more_label = esc_attr__( 'View More', 'gravityflow' );
|
||||
$view_less_label = esc_attr__( 'View Less', 'gravityflow' );
|
||||
|
||||
if ( $format === 'html' ) {
|
||||
$return .= sprintf( "<a href='javascript:void(0);' title='%s' data-title='%s' onclick='GravityFlowEntryDetail.displayDiscussionItemToggle(%d, %d, %d);' class='gravityflow-dicussion-item-toggle-display'>%s</a>", $view_more_label, $view_less_label, $this['formId'], $this['id'], $recent_display_limit, __( 'View More', 'gravityflow' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $discussion as $item ) {
|
||||
|
||||
if ( $has_limit && $count === $limit ) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ( false === $this->is_form_editor() || $recent_display_limit > 0 ) {
|
||||
if ( $format === 'html' && $count >= $recent_display_limit ) {
|
||||
$display_items .= $this->format_discussion_item( $item, $format, $entry_id );
|
||||
} else {
|
||||
$hidden_items .= $this->format_discussion_item( $item, $format, $entry_id );
|
||||
}
|
||||
} else {
|
||||
$display_items .= $this->format_discussion_item( $item, $format, $entry_id );
|
||||
}
|
||||
|
||||
$count ++;
|
||||
}
|
||||
|
||||
if ( $format === 'html' ) {
|
||||
if ( ! empty( $hidden_items ) ) {
|
||||
$return .= '<div class="gravityflow-dicussion-item-hidden" style="display: none;">' . $hidden_items . '</div>' . $display_items;
|
||||
} else {
|
||||
$return .= $display_items;
|
||||
}
|
||||
} else {
|
||||
$return .= $hidden_items . $display_items;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of the limit modifier, if specified on the merge tag.
|
||||
*
|
||||
* @since 1.7.1-dev
|
||||
*
|
||||
* @return int The number of comments to return or 0 to return them all.
|
||||
*/
|
||||
public function get_limit_modifier() {
|
||||
$modifiers = shortcode_parse_atts( implode( ' ', $this->get_modifiers() ) );
|
||||
$limit = rgar( $modifiers, 'limit', 0 );
|
||||
|
||||
return absint( $limit );
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a single discussion item for output.
|
||||
*
|
||||
* @param array $item The properties of the item to be processed.
|
||||
* @param string $format The requested format for the value; html or text.
|
||||
* @param int|null $entry_id The ID of the entry currently being edited or null in other locations.
|
||||
*
|
||||
* @since 1.7.1-dev
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function format_discussion_item( $item, $format, $entry_id ) {
|
||||
$item_datetime = date( 'Y-m-d H:i:s', $item['timestamp'] );
|
||||
$timestamp_format = empty( $this->gravityflowDiscussionTimestampFormat ) ? 'd M Y g:i a' : $this->gravityflowDiscussionTimestampFormat;
|
||||
$date = esc_html( GFCommon::format_date( $item_datetime, false, $timestamp_format, false ) );
|
||||
|
||||
if ( $item['assignee_key'] ) {
|
||||
$assignee = Gravity_Flow_Assignees::create( $item['assignee_key'] );
|
||||
$display_name = $assignee->get_display_name();
|
||||
} else {
|
||||
$display_name = '';
|
||||
}
|
||||
|
||||
$return = '';
|
||||
|
||||
$display_name = apply_filters( 'gravityflowdiscussion_display_name_discussion_field', $display_name, $item, $this );
|
||||
if ( $format === 'html' ) {
|
||||
$content = sprintf( '<div class="gravityflow-dicussion-item-header">
|
||||
<span class="gravityflow-dicussion-item-name">%s</span> <span class="gravityflow-dicussion-item-date">%s</span>
|
||||
%s</div>
|
||||
<div class="gravityflow-dicussion-item-value">
|
||||
%s
|
||||
</div>', $display_name, $date, $this->get_delete_button( $item['id'], $entry_id ), $this->format_comment_value( $item['value'] ) );
|
||||
|
||||
$return .= sprintf( '<div id="gravityflow-discussion-item-%s" class="gravityflow-discussion-item">%s</div>', sanitize_key( $item['id'] ), $content );
|
||||
|
||||
} elseif ( $format === 'text' ) {
|
||||
$return = $date . ': ' . $display_name . "\n";
|
||||
$return .= $item['value'];
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the markup for the delete comment button when on the entry detail edit page.
|
||||
*
|
||||
* @param string $item_id The ID of the comment currently being processed.
|
||||
* @param int $entry_id The ID of the entry currently being processed.
|
||||
*
|
||||
* @since 1.4.2-dev
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_delete_button( $item_id, $entry_id ) {
|
||||
if ( ! $this->is_entry_detail_edit() ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$label = esc_attr__( 'Delete Comment', 'gravityflow' );
|
||||
$file = GFCommon::get_base_url() . '/images/delete.png';
|
||||
|
||||
return sprintf( "<a href='javascript:void(0);' title='%s' onclick='deleteDiscussionItem(%d, %d, %s);'><img src='%s' alt='%s' style='margin-left:8px;'/></a>", $label, $entry_id, $this->id, json_encode( $item_id ), $file, $label );
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats an individual comment value for output in a location using the HTML format.
|
||||
*
|
||||
* @param string $value The comment value.
|
||||
*
|
||||
* @since 1.4.2-dev
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function format_comment_value( $value ) {
|
||||
$allowable_tags = $this->get_allowable_tags();
|
||||
|
||||
if ( $allowable_tags === false ) {
|
||||
// The value is unsafe so encode the value.
|
||||
$value = esc_html( $value );
|
||||
$return = nl2br( $value );
|
||||
|
||||
} else {
|
||||
// The value contains HTML but the value was sanitized before saving.
|
||||
$return = wpautop( $value );
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the value for saving to the Entry Object.
|
||||
*
|
||||
* @param array|string $value The value to be saved.
|
||||
* @param array $form The Form Object currently being processed.
|
||||
* @param string $input_name The input name used when accessing the $_POST.
|
||||
* @param int $entry_id The ID of the Entry currently being processed.
|
||||
* @param array $entry The Entry Object currently being processed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_value_save_entry( $value, $form, $input_name, $entry_id, $entry ) {
|
||||
$value = $this->sanitize_entry_value( $value, $form['id'] );
|
||||
|
||||
if ( $entry_id ) {
|
||||
$entry = GFAPI::get_entry( $entry_id );
|
||||
$previous_value_json = rgar( $entry, $this->id );
|
||||
$assignee_key = gravity_flow()->get_current_user_assignee_key();
|
||||
|
||||
$new_comment = array(
|
||||
'id' => uniqid( '', true ),
|
||||
'assignee_key' => $assignee_key,
|
||||
'timestamp' => time(),
|
||||
'value' => $value,
|
||||
);
|
||||
if ( empty( $previous_value_json ) ) {
|
||||
if ( ! empty( $value ) ) {
|
||||
$value = json_encode( array( $new_comment ) );
|
||||
}
|
||||
} else {
|
||||
$discussion = json_decode( $previous_value_json, ARRAY_A );
|
||||
if ( ! empty( $value ) ) {
|
||||
// Only add the comment to the discussion if a value was submitted.
|
||||
if ( is_array( $discussion ) ) {
|
||||
$discussion[] = $new_comment;
|
||||
} else {
|
||||
$discussion = array( $new_comment );
|
||||
}
|
||||
}
|
||||
$value = json_encode( $discussion );
|
||||
}
|
||||
|
||||
$this->_clear_input_value = true;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the entry value before it is used in entry exports and by framework add-ons using GFAddOn::get_field_value().
|
||||
*
|
||||
* @param array $entry The entry currently being processed.
|
||||
* @param string $input_id The field or input ID.
|
||||
* @param bool|false $use_text When processing choice based fields should the choice text be returned instead of the value.
|
||||
* @param bool|false $is_csv Indicates if the value is going to be used in the .csv entries export.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_value_export( $entry, $input_id = '', $use_text = false, $is_csv = false ) {
|
||||
return $this->format_discussion_value( rgar( $entry, $input_id ), 'text' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize the field settings when the form is saved.
|
||||
*/
|
||||
public function sanitize_settings() {
|
||||
parent::sanitize_settings();
|
||||
if ( ! empty( $this->gravityflowDiscussionTimestampFormat ) ) {
|
||||
$this->gravityflowDiscussionTimestampFormat = sanitize_text_field( $this->gravityflowDiscussionTimestampFormat );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the specified comment and updates the entry in the database.
|
||||
*
|
||||
* @param array $entry The entry containing the comment to be deleted.
|
||||
* @param string $item_id The ID of the comment to be deleted.
|
||||
*
|
||||
* @since 1.4.2-dev
|
||||
*
|
||||
* @return array|bool
|
||||
*/
|
||||
public function delete_discussion_item( $entry, $item_id ) {
|
||||
$discussion = json_decode( rgar( $entry, $this->id ), ARRAY_A );
|
||||
if ( ! is_array( $discussion ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$item_found = false;
|
||||
|
||||
foreach ( $discussion as $key => $item ) {
|
||||
if ( $item['id'] == $item_id ) {
|
||||
$item_found = true;
|
||||
unset( $discussion[ $key ] );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $item_found ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$discussion = ! empty( $discussion ) ? json_encode( array_values( $discussion ) ) : '';
|
||||
|
||||
return GFAPI::update_entry_field( $entry['id'], $this->id, $discussion );
|
||||
}
|
||||
|
||||
/**
|
||||
* Target of the wp_ajax_gravityflow_delete_discussion_item hook; handles the ajax request to delete a comment.
|
||||
*
|
||||
* @since 1.4.2-dev
|
||||
*/
|
||||
public static function ajax_delete_discussion_item() {
|
||||
check_ajax_referer( 'gravityflow_delete_discussion_item', 'gravityflow_delete_discussion_item' );
|
||||
|
||||
$entry_id = absint( $_POST['entry_id'] );
|
||||
$entry = GFAPI::get_entry( $entry_id );
|
||||
|
||||
if ( is_wp_error( $entry ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
$form = GFAPI::get_form( $entry['form_id'] );
|
||||
$field_id = absint( $_POST['field_id'] );
|
||||
$field = GFFormsModel::get_field( $form, $field_id );
|
||||
|
||||
if ( ! $field instanceof Gravity_Flow_Field_Discussion ) {
|
||||
die();
|
||||
}
|
||||
|
||||
$item_id = $_POST['item_id'];
|
||||
$result = $field->delete_discussion_item( $entry, $item_id );
|
||||
|
||||
die( $result === true ? sanitize_key( $item_id ) : false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Target of the gform_entry_detail hook; includes the script for the delete comment link.
|
||||
*
|
||||
* @since 1.4.2-dev
|
||||
*/
|
||||
public static function delete_discussion_item_script() {
|
||||
if ( GFCommon::is_entry_detail_edit() ) {
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
function deleteDiscussionItem(entryId, fieldId, itemId) {
|
||||
|
||||
if (!confirm(<?php echo json_encode( __( "Would you like to delete this comment? 'Cancel' to stop. 'OK' to delete", 'gravityflow' ) ); ?>))
|
||||
return;
|
||||
|
||||
jQuery.post(ajaxurl, {
|
||||
entry_id: entryId,
|
||||
field_id: fieldId,
|
||||
item_id: itemId,
|
||||
action: 'gravityflow_delete_discussion_item',
|
||||
gravityflow_delete_discussion_item: '<?php echo wp_create_nonce( 'gravityflow_delete_discussion_item' ); ?>'
|
||||
}, function (response) {
|
||||
if (response) {
|
||||
jQuery('#gravityflow-discussion-item-' + response).remove();
|
||||
} else {
|
||||
alert(<?php echo json_encode( __( 'There was an issue deleting this comment.', 'gravityflow' ) ); ?>)
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GF_Fields::register( new Gravity_Flow_Field_Discussion() );
|
||||
284
includes/fields/class-field-multi-user.php
Normal file
284
includes/fields/class-field-multi-user.php
Normal file
@@ -0,0 +1,284 @@
|
||||
<?php
|
||||
/**
|
||||
* Gravity Flow Multi-User Field
|
||||
*
|
||||
* @package GravityFlow
|
||||
* @copyright Copyright (c) 2015-2018, Steven Henty S.L.
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'GFForms' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Gravity_Flow_Field_Multi_User
|
||||
*/
|
||||
class Gravity_Flow_Field_Multi_User extends GF_Field_MultiSelect {
|
||||
|
||||
/**
|
||||
* The field type.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $type = 'workflow_multi_user';
|
||||
|
||||
/**
|
||||
* Set the storage type to json
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $storageType = 'json';
|
||||
|
||||
/**
|
||||
* Adds the Workflow Fields group to the form editor.
|
||||
*
|
||||
* @param array $field_groups The properties for the field groups.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_button( $field_groups ) {
|
||||
$field_groups = Gravity_Flow_Fields::maybe_add_workflow_field_group( $field_groups );
|
||||
|
||||
return parent::add_button( $field_groups );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the field button properties for the form editor.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_form_editor_button() {
|
||||
return array(
|
||||
'group' => 'workflow_fields',
|
||||
'text' => $this->get_form_editor_field_title(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class names of the settings which should be available on the field in the form editor.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function get_form_editor_field_settings() {
|
||||
return array(
|
||||
'conditional_logic_field_setting',
|
||||
'prepopulate_field_setting',
|
||||
'error_message_setting',
|
||||
'enable_enhanced_ui_setting',
|
||||
'label_setting',
|
||||
'label_placement_setting',
|
||||
'admin_label_setting',
|
||||
'size_setting',
|
||||
'rules_setting',
|
||||
'visibility_setting',
|
||||
'description_setting',
|
||||
'css_class_setting',
|
||||
'gravityflow_setting_users_role_filter',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the field title.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_form_editor_field_title() {
|
||||
return __( 'Multi-User', 'gravityflow' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the HTML markup for the field choices.
|
||||
*
|
||||
* @param string $value The field value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_choices( $value ) {
|
||||
if ( $this->is_form_editor() ) {
|
||||
// Prevent the choices from being stored in the form meta.
|
||||
$this->choices = array();
|
||||
}
|
||||
|
||||
return parent::get_choices( $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of choices containing the users.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_users_as_choices() {
|
||||
$form_id = $this->formId;
|
||||
|
||||
$args = array(
|
||||
'orderby' => 'display_name',
|
||||
'role' => $this->gravityflowUsersRoleFilter,
|
||||
);
|
||||
|
||||
$args = apply_filters( 'gravityflow_get_users_args_user_field', $args, $form_id, $this );
|
||||
$accounts = get_users( $args );
|
||||
$account_choices = array();
|
||||
foreach ( $accounts as $account ) {
|
||||
$account_choices[] = array( 'value' => $account->ID, 'text' => $account->display_name );
|
||||
}
|
||||
|
||||
return apply_filters( 'gravityflow_user_field', $account_choices, $form_id, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the entry value for display on the entries list page.
|
||||
*
|
||||
* @param string|array $value The field value.
|
||||
* @param array $entry The Entry Object currently being processed.
|
||||
* @param string $field_id The field or input ID currently being processed.
|
||||
* @param array $columns The properties for the columns being displayed on the entry list page.
|
||||
* @param array $form The Form Object currently being processed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_value_entry_list( $value, $entry, $field_id, $columns, $form ) {
|
||||
|
||||
$user_ids = $this->to_array( $value );
|
||||
|
||||
$display_names = $this->get_display_names( $user_ids );
|
||||
|
||||
$assignee = parent::get_value_entry_list( $display_names, $entry, $field_id, $columns, $form );
|
||||
$value = $this->get_display_name( $assignee );
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the entry value which will replace the field merge tag.
|
||||
*
|
||||
* @param string $value The field value. Depending on the location the merge tag is being used the following functions may have already been applied to the value: esc_html, nl2br, and urlencode.
|
||||
* @param string $input_id The field or input ID from the merge tag currently being processed.
|
||||
* @param array $entry The Entry Object currently being processed.
|
||||
* @param array $form The Form Object currently being processed.
|
||||
* @param string $modifier The merge tag modifier. e.g. value.
|
||||
* @param string|array $raw_value The raw field value from before any formatting was applied to $value.
|
||||
* @param bool $url_encode Indicates if the urlencode function may have been applied to the $value.
|
||||
* @param bool $esc_html Indicates if the esc_html function may have been applied to the $value.
|
||||
* @param string $format The format requested for the location the merge is being used. Possible values: html, text or url.
|
||||
* @param bool $nl2br Indicates if the nl2br function may have been applied to the $value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_value_merge_tag( $value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br ) {
|
||||
|
||||
$user_ids = $this->to_array( $raw_value );
|
||||
|
||||
$output_arr = array();
|
||||
|
||||
foreach ( $user_ids as $user_id ) {
|
||||
$output_arr[] = $modifier == 'value' ? $user_id : Gravity_Flow_Fields::get_user_variable( $user_id, $modifier, $url_encode, $esc_html );
|
||||
}
|
||||
|
||||
return GFCommon::implode_non_blank( ', ', $output_arr );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the entry value for display on the entry detail page and for the {all_fields} merge tag.
|
||||
*
|
||||
* @param string $value The field value.
|
||||
* @param string $currency The entry currency code.
|
||||
* @param bool|false $use_text When processing choice based fields should the choice text be returned instead of the value.
|
||||
* @param string $format The format requested for the location the merge is being used. Possible values: html, text or url.
|
||||
* @param string $media The location where the value will be displayed. Possible values: screen or email.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_value_entry_detail( $value, $currency = '', $use_text = false, $format = 'html', $media = 'screen' ) {
|
||||
|
||||
if ( empty( $value ) || $format == 'text' ) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$user_ids = $this->to_array( $value );
|
||||
|
||||
$display_names = $use_text ? $this->get_display_names( $user_ids ) : $user_ids;
|
||||
|
||||
return parent::get_value_entry_detail( $display_names, $currency, $use_text, $format, $media );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the display name for the selected user.
|
||||
*
|
||||
* @param int $user_id The array of user ID.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_display_name( $user_id ) {
|
||||
if ( empty( $user_id ) ) {
|
||||
return '';
|
||||
}
|
||||
$user = get_user_by( 'id', $user_id );
|
||||
$value = is_object( $user ) ? $user->display_name : $user_id;
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function get_display_names( $user_ids ) {
|
||||
$display_names = array();
|
||||
|
||||
foreach ( $user_ids as $user_id ) {
|
||||
$display_names[] = $this->get_display_name( $user_id );
|
||||
}
|
||||
|
||||
return $display_names;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the entry value before it is used in entry exports and by framework add-ons using GFAddOn::get_field_value().
|
||||
*
|
||||
* @param array $entry The entry currently being processed.
|
||||
* @param string $input_id The field or input ID.
|
||||
* @param bool|false $use_text When processing choice based fields should the choice text be returned instead of the value.
|
||||
* @param bool|false $is_csv Indicates if the value is going to be used in the .csv entries export.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_value_export( $entry, $input_id = '', $use_text = false, $is_csv = false ) {
|
||||
if ( empty( $input_id ) ) {
|
||||
$input_id = $this->id;
|
||||
}
|
||||
|
||||
$value = json_decode( rgar( $entry, $input_id ), true );
|
||||
|
||||
if ( $use_text == true || $is_csv == true ) {
|
||||
$display_names = $this->get_display_names( $value );
|
||||
|
||||
return GFCommon::implode_non_blank( ', ', $display_names );
|
||||
}
|
||||
|
||||
if ( $use_text == false && $is_csv == false ) {
|
||||
return rgar( $entry, $input_id );
|
||||
}
|
||||
|
||||
return GFCommon::implode_non_blank( ', ', $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize the field settings when the form is saved.
|
||||
*/
|
||||
public function sanitize_settings() {
|
||||
parent::sanitize_settings();
|
||||
if ( ! empty( $this->gravityflowUsersRoleFilter ) ) {
|
||||
$this->gravityflowUsersRoleFilter = wp_strip_all_tags( $this->gravityflowUsersRoleFilter );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the users as choices.
|
||||
*
|
||||
* @since 1.7.1-dev
|
||||
*/
|
||||
public function post_convert_field() {
|
||||
if ( ! $this->is_form_editor() ) {
|
||||
$this->choices = $this->get_users_as_choices();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GF_Fields::register( new Gravity_Flow_Field_Multi_User() );
|
||||
214
includes/fields/class-field-role.php
Normal file
214
includes/fields/class-field-role.php
Normal file
@@ -0,0 +1,214 @@
|
||||
<?php
|
||||
/**
|
||||
* Gravity Flow Role Field
|
||||
*
|
||||
* @package GravityFlow
|
||||
* @copyright Copyright (c) 2015-2018, Steven Henty S.L.
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'GFForms' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Gravity_Flow_Field_Role
|
||||
*/
|
||||
class Gravity_Flow_Field_Role extends GF_Field_Select {
|
||||
|
||||
/**
|
||||
* The field type.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $type = 'workflow_role';
|
||||
|
||||
/**
|
||||
* Adds the Workflow Fields group to the form editor.
|
||||
*
|
||||
* @param array $field_groups The properties for the field groups.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_button( $field_groups ) {
|
||||
$field_groups = Gravity_Flow_Fields::maybe_add_workflow_field_group( $field_groups );
|
||||
|
||||
return parent::add_button( $field_groups );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the field button properties for the form editor.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_form_editor_button() {
|
||||
return array(
|
||||
'group' => 'workflow_fields',
|
||||
'text' => $this->get_form_editor_field_title(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class names of the settings which should be available on the field in the form editor.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function get_form_editor_field_settings() {
|
||||
return array(
|
||||
'conditional_logic_field_setting',
|
||||
'prepopulate_field_setting',
|
||||
'error_message_setting',
|
||||
'enable_enhanced_ui_setting',
|
||||
'label_setting',
|
||||
'label_placement_setting',
|
||||
'admin_label_setting',
|
||||
'size_setting',
|
||||
'rules_setting',
|
||||
'placeholder_setting',
|
||||
'default_value_setting',
|
||||
'visibility_setting',
|
||||
'duplicate_setting',
|
||||
'description_setting',
|
||||
'css_class_setting',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the field title.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_form_editor_field_title() {
|
||||
return __( 'Role', 'gravityflow' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the HTML markup for the field choices.
|
||||
*
|
||||
* @param string $value The field value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_choices( $value ) {
|
||||
if ( $this->is_form_editor() ) {
|
||||
// Prevent the choices from being stored in the form meta.
|
||||
$this->choices = array();
|
||||
}
|
||||
|
||||
return parent::get_choices( $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of choices containing the user roles.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_roles_as_choices() {
|
||||
$role_choices = Gravity_Flow_Common::get_roles_as_choices( false, false, true );
|
||||
$form_id = $this->formId;
|
||||
|
||||
return apply_filters( 'gravityflow_role_field', $role_choices, $form_id, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the entry value for display on the entries list page.
|
||||
*
|
||||
* @param string|array $value The field value.
|
||||
* @param array $entry The Entry Object currently being processed.
|
||||
* @param string $field_id The field or input ID currently being processed.
|
||||
* @param array $columns The properties for the columns being displayed on the entry list page.
|
||||
* @param array $form The Form Object currently being processed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_value_entry_list( $value, $entry, $field_id, $columns, $form ) {
|
||||
$assignee = parent::get_value_entry_list( $value, $entry, $field_id, $columns, $form );
|
||||
$value = $this->get_display_name( $assignee );
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the entry value which will replace the field merge tag.
|
||||
*
|
||||
* @param string $value The field value. Depending on the location the merge tag is being used the following functions may have already been applied to the value: esc_html, nl2br, and urlencode.
|
||||
* @param string $input_id The field or input ID from the merge tag currently being processed.
|
||||
* @param array $entry The Entry Object currently being processed.
|
||||
* @param array $form The Form Object currently being processed.
|
||||
* @param string $modifier The merge tag modifier. e.g. value.
|
||||
* @param string|array $raw_value The raw field value from before any formatting was applied to $value.
|
||||
* @param bool $url_encode Indicates if the urlencode function may have been applied to the $value.
|
||||
* @param bool $esc_html Indicates if the esc_html function may have been applied to the $value.
|
||||
* @param string $format The format requested for the location the merge is being used. Possible values: html, text or url.
|
||||
* @param bool $nl2br Indicates if the nl2br function may have been applied to the $value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_value_merge_tag( $value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br ) {
|
||||
$value = $this->get_display_name( $value );
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the entry value for display on the entry detail page and for the {all_fields} merge tag.
|
||||
*
|
||||
* @param string $value The field value.
|
||||
* @param string $currency The entry currency code.
|
||||
* @param bool|false $use_text When processing choice based fields should the choice text be returned instead of the value.
|
||||
* @param string $format The format requested for the location the merge is being used. Possible values: html, text or url.
|
||||
* @param string $media The location where the value will be displayed. Possible values: screen or email.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_value_entry_detail( $value, $currency = '', $use_text = false, $format = 'html', $media = 'screen' ) {
|
||||
$assignee = parent::get_value_entry_detail( $value, $currency, $use_text, $format, $media );
|
||||
$value = $this->get_display_name( $assignee );
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the display name for the selected role.
|
||||
*
|
||||
* @param string $value The role name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_display_name( $value ) {
|
||||
$value = translate_user_role( $value );
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the entry value before it is used in entry exports and by framework add-ons using GFAddOn::get_field_value().
|
||||
*
|
||||
* @param array $entry The entry currently being processed.
|
||||
* @param string $input_id The field or input ID.
|
||||
* @param bool|false $use_text When processing choice based fields should the choice text be returned instead of the value.
|
||||
* @param bool|false $is_csv Indicates if the value is going to be used in the .csv entries export.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_value_export( $entry, $input_id = '', $use_text = false, $is_csv = false ) {
|
||||
if ( empty( $input_id ) ) {
|
||||
$input_id = $this->id;
|
||||
}
|
||||
|
||||
return $this->get_display_name( rgar( $entry, $input_id ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the roles as choices.
|
||||
*
|
||||
* @since 1.7.1-dev
|
||||
*/
|
||||
public function post_convert_field() {
|
||||
if ( ! $this->is_form_editor() ) {
|
||||
$this->choices = $this->get_roles_as_choices();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GF_Fields::register( new Gravity_Flow_Field_Role() );
|
||||
245
includes/fields/class-field-user.php
Normal file
245
includes/fields/class-field-user.php
Normal file
@@ -0,0 +1,245 @@
|
||||
<?php
|
||||
/**
|
||||
* Gravity Flow User Field
|
||||
*
|
||||
* @package GravityFlow
|
||||
* @copyright Copyright (c) 2015-2018, Steven Henty S.L.
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'GFForms' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Gravity_Flow_Field_User
|
||||
*/
|
||||
class Gravity_Flow_Field_User extends GF_Field_Select {
|
||||
|
||||
/**
|
||||
* The field type.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $type = 'workflow_user';
|
||||
|
||||
/**
|
||||
* Adds the Workflow Fields group to the form editor.
|
||||
*
|
||||
* @param array $field_groups The properties for the field groups.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_button( $field_groups ) {
|
||||
$field_groups = Gravity_Flow_Fields::maybe_add_workflow_field_group( $field_groups );
|
||||
|
||||
return parent::add_button( $field_groups );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the field button properties for the form editor.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_form_editor_button() {
|
||||
return array(
|
||||
'group' => 'workflow_fields',
|
||||
'text' => $this->get_form_editor_field_title(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class names of the settings which should be available on the field in the form editor.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function get_form_editor_field_settings() {
|
||||
return array(
|
||||
'conditional_logic_field_setting',
|
||||
'prepopulate_field_setting',
|
||||
'error_message_setting',
|
||||
'enable_enhanced_ui_setting',
|
||||
'label_setting',
|
||||
'label_placement_setting',
|
||||
'admin_label_setting',
|
||||
'size_setting',
|
||||
'rules_setting',
|
||||
'placeholder_setting',
|
||||
'default_value_setting',
|
||||
'visibility_setting',
|
||||
'duplicate_setting',
|
||||
'description_setting',
|
||||
'css_class_setting',
|
||||
'gravityflow_setting_users_role_filter',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the field title.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_form_editor_field_title() {
|
||||
return __( 'User', 'gravityflow' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the HTML markup for the field choices.
|
||||
*
|
||||
* @param string $value The field value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_choices( $value ) {
|
||||
if ( $this->is_form_editor() ) {
|
||||
// Prevent the choices from being stored in the form meta.
|
||||
$this->choices = array();
|
||||
}
|
||||
|
||||
return parent::get_choices( $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of choices containing the users.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_users_as_choices() {
|
||||
$form_id = $this->formId;
|
||||
|
||||
$args = array(
|
||||
'orderby' => 'display_name',
|
||||
'role' => $this->gravityflowUsersRoleFilter,
|
||||
);
|
||||
|
||||
$args = apply_filters( 'gravityflow_get_users_args_user_field', $args, $form_id, $this );
|
||||
$accounts = get_users( $args );
|
||||
$account_choices = array();
|
||||
foreach ( $accounts as $account ) {
|
||||
$account_choices[] = array( 'value' => $account->ID, 'text' => $account->display_name );
|
||||
}
|
||||
|
||||
return apply_filters( 'gravityflow_user_field', $account_choices, $form_id, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the entry value for display on the entries list page.
|
||||
*
|
||||
* @param string|array $value The field value.
|
||||
* @param array $entry The Entry Object currently being processed.
|
||||
* @param string $field_id The field or input ID currently being processed.
|
||||
* @param array $columns The properties for the columns being displayed on the entry list page.
|
||||
* @param array $form The Form Object currently being processed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_value_entry_list( $value, $entry, $field_id, $columns, $form ) {
|
||||
$assignee = parent::get_value_entry_list( $value, $entry, $field_id, $columns, $form );
|
||||
$value = $this->get_display_name( $assignee );
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the entry value which will replace the field merge tag.
|
||||
*
|
||||
* @param string $value The field value. Depending on the location the merge tag is being used the following functions may have already been applied to the value: esc_html, nl2br, and urlencode.
|
||||
* @param string $input_id The field or input ID from the merge tag currently being processed.
|
||||
* @param array $entry The Entry Object currently being processed.
|
||||
* @param array $form The Form Object currently being processed.
|
||||
* @param string $modifier The merge tag modifier. e.g. value.
|
||||
* @param string|array $raw_value The raw field value from before any formatting was applied to $value.
|
||||
* @param bool $url_encode Indicates if the urlencode function may have been applied to the $value.
|
||||
* @param bool $esc_html Indicates if the esc_html function may have been applied to the $value.
|
||||
* @param string $format The format requested for the location the merge is being used. Possible values: html, text or url.
|
||||
* @param bool $nl2br Indicates if the nl2br function may have been applied to the $value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_value_merge_tag( $value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br ) {
|
||||
|
||||
return Gravity_Flow_Fields::get_user_variable( $value, $modifier, $url_encode, $esc_html );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the entry value for display on the entry detail page and for the {all_fields} merge tag.
|
||||
*
|
||||
* @param string $value The field value.
|
||||
* @param string $currency The entry currency code.
|
||||
* @param bool|false $use_text When processing choice based fields should the choice text be returned instead of the value.
|
||||
* @param string $format The format requested for the location the merge is being used. Possible values: html, text or url.
|
||||
* @param string $media The location where the value will be displayed. Possible values: screen or email.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_value_entry_detail( $value, $currency = '', $use_text = false, $format = 'html', $media = 'screen' ) {
|
||||
$assignee = parent::get_value_entry_detail( $value, $currency, $use_text, $format, $media );
|
||||
$value = $this->get_display_name( $assignee );
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the display name for the selected user.
|
||||
*
|
||||
* @param int $user_id The user ID.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_display_name( $user_id ) {
|
||||
if ( empty( $user_id ) ) {
|
||||
return '';
|
||||
}
|
||||
$user = get_user_by( 'id', $user_id );
|
||||
$value = is_object( $user ) ? $user->display_name : $user_id;
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the entry value before it is used in entry exports and by framework add-ons using GFAddOn::get_field_value().
|
||||
*
|
||||
* @param array $entry The entry currently being processed.
|
||||
* @param string $input_id The field or input ID.
|
||||
* @param bool|false $use_text When processing choice based fields should the choice text be returned instead of the value.
|
||||
* @param bool|false $is_csv Indicates if the value is going to be used in the .csv entries export.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_value_export( $entry, $input_id = '', $use_text = false, $is_csv = false ) {
|
||||
if ( empty( $input_id ) ) {
|
||||
$input_id = $this->id;
|
||||
}
|
||||
|
||||
$user_id = rgar( $entry, $input_id );
|
||||
|
||||
if ( $use_text == true || $is_csv == true ) {
|
||||
return $this->get_display_name( $user_id );
|
||||
}
|
||||
|
||||
return $user_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize the field settings when the form is saved.
|
||||
*/
|
||||
public function sanitize_settings() {
|
||||
parent::sanitize_settings();
|
||||
if ( ! empty( $this->gravityflowUsersRoleFilter ) ) {
|
||||
$this->gravityflowUsersRoleFilter = wp_strip_all_tags( $this->gravityflowUsersRoleFilter );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the users as choices.
|
||||
*
|
||||
* @since 1.7.1-dev
|
||||
*/
|
||||
public function post_convert_field() {
|
||||
if ( ! $this->is_form_editor() ) {
|
||||
$this->choices = $this->get_users_as_choices();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GF_Fields::register( new Gravity_Flow_Field_User() );
|
||||
253
includes/fields/class-fields.php
Normal file
253
includes/fields/class-fields.php
Normal file
@@ -0,0 +1,253 @@
|
||||
<?php
|
||||
/**
|
||||
* Gravity Flow Fields Functions
|
||||
*
|
||||
* @package GravityFlow
|
||||
* @copyright Copyright (c) 2015-2018, Steven Henty S.L.
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 1.4.2-dev
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'GFForms' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Gravity_Flow_Fields
|
||||
*/
|
||||
class Gravity_Flow_Fields {
|
||||
|
||||
/**
|
||||
* Class constructor; if the installed Gravity Forms version is supported initialize the hooks.
|
||||
*/
|
||||
function __construct() {
|
||||
if ( ! gravity_flow()->is_gravityforms_supported() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_action( 'init', array( $this, 'init_hooks' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the hooks via the WordPress init action.
|
||||
*/
|
||||
public function init_hooks() {
|
||||
add_filter( 'gform_tooltips', array( $this, 'add_tooltips' ) );
|
||||
|
||||
add_action( 'gform_field_standard_settings', array( $this, 'field_settings' ) );
|
||||
add_action( 'gform_field_appearance_settings', array( $this, 'field_appearance_settings' ) );
|
||||
add_action( 'gform_entry_detail', array( 'Gravity_Flow_Field_Discussion', 'delete_discussion_item_script' ) );
|
||||
|
||||
add_action( 'wp_ajax_rg_delete_file', array( 'RGForms', 'delete_file' ) );
|
||||
add_action( 'wp_ajax_nopriv_rg_delete_file', array( 'RGForms', 'delete_file' ) );
|
||||
add_action( 'wp_ajax_gravityflow_delete_discussion_item', array( 'Gravity_Flow_Field_Discussion', 'ajax_delete_discussion_item' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the Workflow Fields group to the form editor.
|
||||
*
|
||||
* @param array $field_groups The properties for the field groups.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function maybe_add_workflow_field_group( $field_groups ) {
|
||||
foreach ( $field_groups as $field_group ) {
|
||||
if ( $field_group['name'] == 'workflow_fields' ) {
|
||||
return $field_groups;
|
||||
}
|
||||
}
|
||||
|
||||
$field_groups[] = array(
|
||||
'name' => 'workflow_fields',
|
||||
'label' => __( 'Workflow Fields', 'gravityflow' ),
|
||||
'fields' => array()
|
||||
);
|
||||
|
||||
return $field_groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the tooltips for the workflow fields group and any custom field settings.
|
||||
*
|
||||
* @param array $tooltips An associative array where the key is the tooltip name and the value is the tooltip.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_tooltips( $tooltips ) {
|
||||
$tooltips['form_workflow_fields'] = '<h6>' . __( 'Workflow Fields', 'gravityflow' ) . '</h6>' . __( 'Workflow Fields add advanced workflow functionality to your forms.', 'gravityflow' );
|
||||
$tooltips['gravityflow_discussion_timestamp_format'] = '<h6>' . __( 'Custom Timestamp Format', 'gravityflow' ) . '</h6>' . sprintf( __( 'If you would like to override the default format used when displaying the comment timestamps, enter your %scustom format%s here.', 'gravityflow' ), '<a href="https://codex.wordpress.org/Formatting_Date_and_Time" target="_blank">', '</a>' );
|
||||
|
||||
return $tooltips;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the assignees and role settings to the general tab.
|
||||
*
|
||||
* @param int $position The setting position.
|
||||
*/
|
||||
public function field_settings( $position ) {
|
||||
if ( $position == 20 ) {
|
||||
// After Description setting.
|
||||
$this->setting_assignees();
|
||||
$this->setting_role();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the markup for the gravityflow_setting_assignees setting to the field general tab in the form editor.
|
||||
*/
|
||||
public function setting_assignees() {
|
||||
?>
|
||||
|
||||
<li class="gravityflow_setting_assignees field_setting">
|
||||
<span class="section_label"><?php esc_html_e( 'Assignees', 'gravityflow' ); ?></span>
|
||||
<div>
|
||||
<input type="checkbox" id="gravityflow-assignee-field-show-users" onclick="SetAssigneeFieldShowUsers();"/>
|
||||
<label for="gravityflow-assignee-field-show-users" class="inline">
|
||||
<?php esc_html_e( 'Show Users', 'gravityflow' ); ?>
|
||||
<?php gform_tooltip( 'gravityflow_assignee_field_show_users' ) ?>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<input type="checkbox" id="gravityflow-assignee-field-show-roles"
|
||||
onclick="var value = jQuery(this).is(':checked'); SetFieldProperty('gravityflowAssigneeFieldShowRoles', value);"/>
|
||||
<label for="gravityflow-assignee-field-show-roles" class="inline">
|
||||
<?php esc_html_e( 'Show Roles', 'gravityflow' ); ?>
|
||||
<?php gform_tooltip( 'gravityflow_assignee_field_show_roles' ) ?>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<input type="checkbox" id="gravityflow-assignee-field-show-fields"
|
||||
onclick="var value = jQuery(this).is(':checked'); SetFieldProperty('gravityflowAssigneeFieldShowFields', value);"/>
|
||||
<label for="gravityflow-assignee-field-show-fields" class="inline">
|
||||
<?php esc_html_e( 'Show Fields', 'gravityflow' ); ?>
|
||||
<?php gform_tooltip( 'gravityflow_assignee_field_show_fields' ) ?>
|
||||
</label>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the markup for the gravityflow_setting_users_role_filter setting to the field general tab in the form editor.
|
||||
*/
|
||||
public function setting_role() {
|
||||
?>
|
||||
|
||||
<li class="gravityflow_setting_users_role_filter field_setting">
|
||||
<label for="gravityflow_users_role_filter" class="section_label">
|
||||
<?php esc_html_e( 'Users Role Filter', 'gravityflow' ); ?>
|
||||
</label>
|
||||
<?php $this->setting_role_select(); ?>
|
||||
</li>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the markup for the role select element.
|
||||
*/
|
||||
public function setting_role_select() {
|
||||
$choices = array(
|
||||
array(
|
||||
'value' => '',
|
||||
'label' => esc_html__( 'Include users from all roles', 'gravityflow' )
|
||||
)
|
||||
);
|
||||
|
||||
$role_field = array(
|
||||
'name' => 'gravityflow_users_role_filter',
|
||||
'choices' => array_merge( $choices, Gravity_Flow_Common::get_roles_as_choices( false ) ),
|
||||
'onchange' => "SetFieldProperty('gravityflowUsersRoleFilter',this.value);",
|
||||
);
|
||||
|
||||
$html = gravity_flow()->settings_select( $role_field, false );
|
||||
|
||||
echo str_replace( sprintf( 'name="_gaddon_setting_%s"', esc_attr( $role_field['name'] ) ), '', $html );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the discussion fields custom timestamp format to the appearance tab.
|
||||
*
|
||||
* @param int $position The setting position.
|
||||
*/
|
||||
public function field_appearance_settings( $position ) {
|
||||
if ( $position == 0 ) {
|
||||
?>
|
||||
<li class="gravityflow_setting_discussion_timestamp_format field_setting">
|
||||
<label for="gravityflow_discussion_timestamp_format" class="section_label">
|
||||
<?php esc_html_e( 'Custom Timestamp Format', 'gravityflow' ); ?>
|
||||
<?php gform_tooltip( 'gravityflow_discussion_timestamp_format' ) ?>
|
||||
</label>
|
||||
<input id="gravityflow_discussion_timestamp_format" type="text" class="fieldwidth-4"
|
||||
placeholder="d M Y g:i a" onkeyup="SetDiscussionTimestampFormat(jQuery(this).val());"
|
||||
onchange="SetDiscussionTimestampFormat(jQuery(this).val());"/>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the value of the specified user property/meta key for the specified user ID.
|
||||
*
|
||||
* @since 1.5.1-dev
|
||||
*
|
||||
* @param string|int $user_id The user ID.
|
||||
* @param string $property The user property to return.
|
||||
* @param bool $url_encode Indicates if the urlencode function should be applied.
|
||||
* @param bool $esc_html Indicates if the esc_html function should be applied.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_user_variable( $user_id, $property, $url_encode = false, $esc_html = true ) {
|
||||
$value = $user_id;
|
||||
|
||||
if ( $property != 'id' ) {
|
||||
$user = get_user_by( 'id', $user_id );
|
||||
|
||||
if ( is_object( $user ) ) {
|
||||
switch ( $property ) {
|
||||
case 'email' :
|
||||
$property = 'user_email';
|
||||
break;
|
||||
case '' :
|
||||
$property = 'display_name';
|
||||
}
|
||||
|
||||
if ( $property == 'roles' ) {
|
||||
$value = implode( ', ', $user->roles );
|
||||
} else {
|
||||
$value = $user->get( $property );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return self::maybe_format_user_variable( $value, $url_encode, $esc_html );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the value of invalid or special characters before output.
|
||||
*
|
||||
* @since 1.5.1-dev
|
||||
*
|
||||
* @param string|int $value The user ID or property to be filtered.
|
||||
* @param bool $url_encode Indicates if the urlencode function should be applied.
|
||||
* @param bool $esc_html Indicates if the esc_html function should be applied.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function maybe_format_user_variable( $value, $url_encode, $esc_html ) {
|
||||
if ( $url_encode ) {
|
||||
$value = urlencode( $value );
|
||||
}
|
||||
|
||||
if ( $esc_html ) {
|
||||
$value = esc_html( $value );
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
new Gravity_Flow_Fields();
|
||||
2
includes/fields/index.php
Normal file
2
includes/fields/index.php
Normal file
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
//Nothing to see here
|
||||
Reference in New Issue
Block a user